All files / source/labels/ZPL serialGroup.js

79.54% Statements 35/44
66.66% Branches 18/27
100% Functions 1/1
82.92% Lines 34/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98                    6x 6x 6x 6x 6x 6x 6x 6x 6x   6x     6x 59x 6x 6x       6x 5x   1x 1x       6x 1x 1x       1x   1x 1x                                   6x 6x 6x   6x 1x     6x 6x               6x 6x                       6x    
/* eslint-disable for-direction */
import moment from 'moment-timezone';
import labelInformation from '../information';
import stringToStringLiteral from '../../../helpers/conversion/stringToStringLiteral';
 
export default async function serialGroupLabel(
  serialGroup,
  zplSimulation,
  languageCode = 'ZPL'
) {
  const productName = serialGroup.product.name;
  const sizeName = productName.length;
  const maxLine = 30;
  let Desc1 = '';
  let Desc2 = '';
  let Desc3 = '';
  let posEnd1 = 0;
  let posEnd2 = 0;
  let posEnd3 = 0;
 
  Iif (sizeName <= maxLine) {
    posEnd1 = sizeName;
  } else {
    for (let nPos = maxLine; nPos < sizeName; nPos -= 1) {
      if (productName[nPos] === ' ') {
        posEnd1 = nPos;
        break;
      }
    }
 
    if (sizeName <= posEnd1 + maxLine) {
      posEnd2 = sizeName;
    } else {
      for (
        let nPos2 = posEnd1 + maxLine;
        nPos2 < productName.length;
        nPos2 -= 1
      ) {
        if (productName[nPos2] === ' ') {
          posEnd2 = nPos2;
          break;
        }
      }
 
      Iif (!posEnd2) posEnd2 = posEnd1 + maxLine;
 
      if (sizeName <= posEnd2 + maxLine) {
        posEnd3 = sizeName;
      } else E{
        for (
          let nPos3 = posEnd2 + maxLine;
          nPos3 < productName.length;
          nPos3 -= 1
        ) {
          if (productName[nPos3] === ' ') {
            posEnd3 = nPos3;
            break;
          }
        }
 
        if (!posEnd3) posEnd3 = posEnd2 + maxLine;
      }
    }
  }
 
  Desc1 = productName.substring(0, posEnd1);
  Eif (posEnd2) {
    Desc2 = productName.substring(posEnd1 + 1, posEnd2);
  }
  if (posEnd3) {
    Desc3 = productName.substring(posEnd2 + 1, posEnd3);
  }
 
  let ZPL = '';
  const modelLabel = await labelInformation.getLabel(
    {
      trigger: `serialGroup`,
      active: true,
    },
    { attributes: [`label${languageCode}`], raw: true, nest: true }
  );
 
  Eif (zplSimulation || modelLabel) {
    ZPL += stringToStringLiteral(
      zplSimulation || modelLabel[`label${languageCode}`],
      {
        serialGroup,
        Desc1,
        Desc2,
        Desc3,
        moment,
      }
    );
  }
 
  return ZPL;
}