From 269f4ed225f8d13ef8d41c618bff06b221994f3f Mon Sep 17 00:00:00 2001 From: Kostyanaya Date: Wed, 18 Dec 2024 13:09:46 +0300 Subject: [PATCH] chore: good settings --- .../src/screens/Cells/CellsViewScreen.tsx | 8 +++--- .../FreeShipment/FreeShipmentViewScreen.tsx | 19 +++++++++++--- .../screens/Inventory/InventoryViewScreen.tsx | 8 ++++-- .../Laboratory/LaboratoryViewScreen.tsx | 16 +++++++++--- .../screens/MovementTo/MoveToViewScreen.tsx | 20 ++++++++++++--- .../src/screens/Movements/MoveViewScreen.tsx | 19 +++++++++++--- .../src/screens/Receipt/ReceiptViewScreen.tsx | 19 +++++++++++--- .../src/screens/Return/ReturnViewScreen.tsx | 8 ++++-- .../screens/Shipment/ShipmentViewScreen.tsx | 21 +++++++++++++--- apps/app-fp-movement/src/utils/constants.ts | 1 + apps/app-fp-movement/src/utils/helpers.ts | 25 ++++++++++++------- 11 files changed, 129 insertions(+), 35 deletions(-) diff --git a/apps/app-fp-movement/src/screens/Cells/CellsViewScreen.tsx b/apps/app-fp-movement/src/screens/Cells/CellsViewScreen.tsx index 504c2fa49..fb48dece7 100644 --- a/apps/app-fp-movement/src/screens/Cells/CellsViewScreen.tsx +++ b/apps/app-fp-movement/src/screens/Cells/CellsViewScreen.tsx @@ -33,7 +33,7 @@ import { FlashList } from '@shopify/flash-list'; import { barcodeSettings, ICell, ICellRef, IMoveDocument, IMoveLine } from '../../store/types'; import { CellsStackParamList } from '../../navigation/Root/types'; -import { getBarcode, getCellList, getCellListRef } from '../../utils/helpers'; +import { getBarcode, getCellList, getCellListRef, getCodeForCheck } from '../../utils/helpers'; import { ICellRefList, ICodeEntity, IGood } from '../../store/app/types'; import { Group } from '../../components/Group'; @@ -150,7 +150,7 @@ export const CellsViewScreen = () => { id: i.name, barcode: i.barcode, name: i.name, - good: goods.find((g) => `0000${g.shcode}`.slice(-4) === shcode), + good: goods.find((g) => getCodeForCheck(g.shcode, goodBarcodeSettings?.countCode || 4) === shcode), workDate, weight, numReceived, @@ -235,7 +235,9 @@ export const CellsViewScreen = () => { (brc: string, cell: string) => { const barc = getBarcode(brc, goodBarcodeSettings); - const good = goods.find((item) => `0000${item.shcode}`.slice(-4) === barc.shcode); + const good = goods.find( + (item) => getCodeForCheck(item.shcode, goodBarcodeSettings?.countCode || 4) === barc.shcode, + ); const newLine: IMoveLine = { good: { id: good?.id || '', name: good?.name || '', shcode: good?.shcode || '' }, diff --git a/apps/app-fp-movement/src/screens/FreeShipment/FreeShipmentViewScreen.tsx b/apps/app-fp-movement/src/screens/FreeShipment/FreeShipmentViewScreen.tsx index a20cacb6e..815e9a3de 100644 --- a/apps/app-fp-movement/src/screens/FreeShipment/FreeShipmentViewScreen.tsx +++ b/apps/app-fp-movement/src/screens/FreeShipment/FreeShipmentViewScreen.tsx @@ -46,6 +46,7 @@ import { alertWithSound, alertWithSoundMulti, getBarcode, + getCodeForCheck, getDocToSend, getLineGood, getNextDocNumber, @@ -175,7 +176,11 @@ export const FreeShipmentViewScreen = () => { const good = remainsUse && goodRemains.length - ? goodRemains.find((item) => `0000${item.good.shcode}`.slice(-4) === `0000${line.good.shcode}`.slice(-4)) + ? goodRemains.find( + (item) => + getCodeForCheck(item.good.shcode, goodBarcodeSettings?.countCode || 4) === + getCodeForCheck(line.good.shcode, goodBarcodeSettings?.countCode || 4), + ) : undefined; if (remainsUse && goodRemains.length) { @@ -191,6 +196,7 @@ export const FreeShipmentViewScreen = () => { } const newLine: IFreeShipmentLine = getUpdatedLine( + goodBarcodeSettings, remainsUse, lineBarcode, line, @@ -200,7 +206,7 @@ export const FreeShipmentViewScreen = () => { dispatch(documentActions.updateDocumentLine({ docId: id, line: newLine })); }, - [dispatch, goodBarcodeSettings?.boxWeight, goodRemains, id, lines, remainsUse], + [dispatch, goodBarcodeSettings, goodRemains, id, lines, remainsUse], ); const handleEditQuantPack = useCallback(() => { @@ -552,7 +558,14 @@ export const FreeShipmentViewScreen = () => { const barc = getBarcode(brc, goodBarcodeSettings); - const lineGood = getLineGood(barc.shcode, barc.weight, goods, goodRemains, remainsUse); + const lineGood = getLineGood( + barc.shcode, + barc.weight, + goods, + goodRemains, + remainsUse, + goodBarcodeSettings?.countCode || 4, + ); if (!lineGood.good) { setVisibleRequestDialog(true); diff --git a/apps/app-fp-movement/src/screens/Inventory/InventoryViewScreen.tsx b/apps/app-fp-movement/src/screens/Inventory/InventoryViewScreen.tsx index c63827648..a6a4d182f 100644 --- a/apps/app-fp-movement/src/screens/Inventory/InventoryViewScreen.tsx +++ b/apps/app-fp-movement/src/screens/Inventory/InventoryViewScreen.tsx @@ -39,6 +39,7 @@ import { alertWithSound, alertWithSoundMulti, getBarcode, + getCodeForCheck, getDocToSend, getNextDocNumber, getUpdatedLine, @@ -155,6 +156,7 @@ export const InventoryViewScreen = () => { : round(line?.weight * quantity, 3); const newLine: IInventoryLine = getUpdatedLine( + goodBarcodeSettings, false, lineBarcode, line, @@ -165,7 +167,7 @@ export const InventoryViewScreen = () => { dispatch(documentActions.updateDocumentLine({ docId: id, line: newLine })); } }, - [dispatch, goodBarcodeSettings?.boxWeight, id, isAddressedDoc, lines], + [dispatch, goodBarcodeSettings, id, isAddressedDoc, lines], ); const handleEditQuantPack = useCallback(() => { @@ -485,7 +487,9 @@ export const InventoryViewScreen = () => { const barc = getBarcode(brc, goodBarcodeSettings); - const good = goods.find((item) => `0000${item.shcode}`.slice(-4) === barc.shcode); + const good = goods.find( + (item) => getCodeForCheck(item.shcode, goodBarcodeSettings?.countCode || 4) === barc.shcode, + ); if (!good) { handleErrorMessage(visibleDialog, 'Товар не найден!'); diff --git a/apps/app-fp-movement/src/screens/Laboratory/LaboratoryViewScreen.tsx b/apps/app-fp-movement/src/screens/Laboratory/LaboratoryViewScreen.tsx index 7da68ec1c..7bd68f0b8 100644 --- a/apps/app-fp-movement/src/screens/Laboratory/LaboratoryViewScreen.tsx +++ b/apps/app-fp-movement/src/screens/Laboratory/LaboratoryViewScreen.tsx @@ -37,6 +37,7 @@ import { alertWithSound, alertWithSoundMulti, getBarcode, + getCodeForCheck, getDocToSend, getLineGood, getNextDocNumber, @@ -149,7 +150,9 @@ export const LaboratoryViewScreen = () => { if (remainsUse && goodRemains.length) { const good = goodRemains.find( - (item) => `0000${item.good.shcode}`.slice(-4) === `0000${line.good.shcode}`.slice(-4), + (item) => + getCodeForCheck(item.good.shcode, goodBarcodeSettings?.countCode || 4) === + getCodeForCheck(line.good.shcode, goodBarcodeSettings?.countCode || 4), ); if (good) { @@ -186,7 +189,7 @@ export const LaboratoryViewScreen = () => { } } }, - [dispatch, goodRemains, id, lines, remainsUse], + [dispatch, goodBarcodeSettings?.countCode, goodRemains, id, lines, remainsUse], ); const handleEditWeight = () => { @@ -507,7 +510,14 @@ export const LaboratoryViewScreen = () => { const barc = getBarcode(brc, goodBarcodeSettings); - const lineGood = getLineGood(barc.shcode, barc.weight, goods, goodRemains, remainsUse); + const lineGood = getLineGood( + barc.shcode, + barc.weight, + goods, + goodRemains, + remainsUse, + goodBarcodeSettings?.countCode || 4, + ); if (!lineGood.good) { handleErrorMessage(visibleDialog, 'Товар не найден!'); diff --git a/apps/app-fp-movement/src/screens/MovementTo/MoveToViewScreen.tsx b/apps/app-fp-movement/src/screens/MovementTo/MoveToViewScreen.tsx index 2312066db..32fcff310 100644 --- a/apps/app-fp-movement/src/screens/MovementTo/MoveToViewScreen.tsx +++ b/apps/app-fp-movement/src/screens/MovementTo/MoveToViewScreen.tsx @@ -44,6 +44,7 @@ import { alertWithSound, alertWithSoundMulti, getBarcode, + getCodeForCheck, getDocToSend, getLineGood, getNextDocNumber, @@ -230,7 +231,11 @@ export const MoveToViewScreen = () => { const good = remainsUse && goodRemains.length - ? goodRemains.find((item) => `0000${item.good.shcode}`.slice(-4) === `0000${line.good.shcode}`.slice(-4)) + ? goodRemains.find( + (item) => + getCodeForCheck(item.good.shcode, goodBarcodeSettings?.countCode || 4) === + getCodeForCheck(line.good.shcode, goodBarcodeSettings?.countCode || 4), + ) : undefined; if (remainsUse && goodRemains.length) { @@ -245,13 +250,13 @@ export const MoveToViewScreen = () => { } } - const newLine: IMoveLine = getUpdatedLine(remainsUse, lineBarcode, line, quantity, weight); + const newLine: IMoveLine = getUpdatedLine(goodBarcodeSettings, remainsUse, lineBarcode, line, quantity, weight); navigation.navigate('SelectCell', { docId: id, item: newLine, mode: 0 }); // dispatch(documentActions.updateDocumentLine({ docId: id, line: newLine })); }, - [goodRemains, id, navigation, newwLine, remainsUse], + [goodBarcodeSettings, goodRemains, id, navigation, newwLine, remainsUse], ); const handleEditQuantPack = useCallback(() => { @@ -583,7 +588,14 @@ export const MoveToViewScreen = () => { const barc = getBarcode(brc, goodBarcodeSettings); - const lineGood = getLineGood(barc.shcode, barc.weight, goods, goodRemains, remainsUse); + const lineGood = getLineGood( + barc.shcode, + barc.weight, + goods, + goodRemains, + remainsUse, + goodBarcodeSettings?.countCode || 4, + ); if (!lineGood.good) { handleErrorMessage(visibleDialog, 'Товар не найден!'); diff --git a/apps/app-fp-movement/src/screens/Movements/MoveViewScreen.tsx b/apps/app-fp-movement/src/screens/Movements/MoveViewScreen.tsx index 1a0f69eab..06691ab5f 100644 --- a/apps/app-fp-movement/src/screens/Movements/MoveViewScreen.tsx +++ b/apps/app-fp-movement/src/screens/Movements/MoveViewScreen.tsx @@ -45,6 +45,7 @@ import { alertWithSound, alertWithSoundMulti, getBarcode, + getCodeForCheck, getDocToSend, getLineGood, getNextDocNumber, @@ -202,7 +203,11 @@ export const MoveViewScreen = () => { const good = remainsUse && goodRemains.length - ? goodRemains.find((item) => `0000${item.good.shcode}`.slice(-4) === `0000${line.good.shcode}`.slice(-4)) + ? goodRemains.find( + (item) => + getCodeForCheck(item.good.shcode, goodBarcodeSettings?.countCode || 4) === + getCodeForCheck(line.good.shcode, goodBarcodeSettings?.countCode || 4), + ) : undefined; if (remainsUse && goodRemains.length) { @@ -217,6 +222,7 @@ export const MoveViewScreen = () => { } } const newLine: IMoveLine = getUpdatedLine( + goodBarcodeSettings, remainsUse, lineBarcode, line, @@ -227,7 +233,7 @@ export const MoveViewScreen = () => { dispatch(documentActions.updateDocumentLine({ docId: id, line: newLine })); } }, - [dispatch, goodBarcodeSettings?.boxWeight, goodRemains, id, isAddressedDoc, lines, remainsUse], + [dispatch, goodBarcodeSettings, goodRemains, id, isAddressedDoc, lines, remainsUse], ); const handleEditQuantPack = useCallback(() => { @@ -580,7 +586,14 @@ export const MoveViewScreen = () => { const barc = getBarcode(brc, goodBarcodeSettings); - const lineGood = getLineGood(barc.shcode, barc.weight, goods, goodRemains, remainsUse); + const lineGood = getLineGood( + barc.shcode, + barc.weight, + goods, + goodRemains, + remainsUse, + goodBarcodeSettings?.countCode || 4, + ); if (!lineGood.good) { handleErrorMessage(visibleDialog, 'Товар не найден!'); diff --git a/apps/app-fp-movement/src/screens/Receipt/ReceiptViewScreen.tsx b/apps/app-fp-movement/src/screens/Receipt/ReceiptViewScreen.tsx index a8f15b125..b5b567b8f 100644 --- a/apps/app-fp-movement/src/screens/Receipt/ReceiptViewScreen.tsx +++ b/apps/app-fp-movement/src/screens/Receipt/ReceiptViewScreen.tsx @@ -45,6 +45,7 @@ import { alertWithSound, alertWithSoundMulti, getBarcode, + getCodeForCheck, getDocToSend, getLineGood, getNextDocNumber, @@ -180,7 +181,11 @@ export const ReceiptViewScreen = () => { const good = remainsUse && goodRemains.length - ? goodRemains.find((item) => `0000${item.good.shcode}`.slice(-4) === `0000${line.good.shcode}`.slice(-4)) + ? goodRemains.find( + (item) => + getCodeForCheck(item.good.shcode, goodBarcodeSettings?.countCode || 4) === + getCodeForCheck(line.good.shcode, goodBarcodeSettings?.countCode || 4), + ) : undefined; if (remainsUse && goodRemains.length) { @@ -195,6 +200,7 @@ export const ReceiptViewScreen = () => { } } const newLine: IReceiptLine = getUpdatedLine( + goodBarcodeSettings, remainsUse, lineBarcode, line, @@ -204,7 +210,7 @@ export const ReceiptViewScreen = () => { dispatch(documentActions.updateDocumentLine({ docId: id, line: newLine })); }, - [dispatch, goodBarcodeSettings?.boxWeight, goodRemains, id, lines, remainsUse], + [dispatch, goodBarcodeSettings, goodRemains, id, lines, remainsUse], ); const handleEditQuantPack = useCallback(() => { @@ -524,7 +530,14 @@ export const ReceiptViewScreen = () => { const barc = getBarcode(brc, goodBarcodeSettings); - const lineGood = getLineGood(barc.shcode, barc.weight, goods, goodRemains, remainsUse); + const lineGood = getLineGood( + barc.shcode, + barc.weight, + goods, + goodRemains, + remainsUse, + goodBarcodeSettings?.countCode || 4, + ); if (!lineGood.good) { handleErrorMessage(visibleDialog, 'Товар не найден!'); diff --git a/apps/app-fp-movement/src/screens/Return/ReturnViewScreen.tsx b/apps/app-fp-movement/src/screens/Return/ReturnViewScreen.tsx index 77f79bf58..4205dc69d 100644 --- a/apps/app-fp-movement/src/screens/Return/ReturnViewScreen.tsx +++ b/apps/app-fp-movement/src/screens/Return/ReturnViewScreen.tsx @@ -37,6 +37,7 @@ import { alertWithSound, alertWithSoundMulti, getBarcode, + getCodeForCheck, getDocToSend, getNextDocNumber, getUpdatedLine, @@ -146,6 +147,7 @@ export const ReturnViewScreen = () => { : round(line?.weight * quantity, 3); const newLine: IReturnLine = getUpdatedLine( + goodBarcodeSettings, false, lineBarcode, line, @@ -155,7 +157,7 @@ export const ReturnViewScreen = () => { dispatch(documentActions.updateDocumentLine({ docId: id, line: newLine })); }, - [dispatch, goodBarcodeSettings?.boxWeight, id, lines], + [dispatch, goodBarcodeSettings, id, lines], ); const handleEditQuantPack = useCallback(() => { @@ -483,7 +485,9 @@ export const ReturnViewScreen = () => { const barc = getBarcode(brc, goodBarcodeSettings); - const good = goods.find((item) => `0000${item.shcode}`.slice(-4) === barc.shcode); + const good = goods.find( + (item) => getCodeForCheck(item.shcode, goodBarcodeSettings?.countCode || 4) === barc.shcode, + ); if (!good) { handleErrorMessage(visibleDialog, 'Товар не найден!'); diff --git a/apps/app-fp-movement/src/screens/Shipment/ShipmentViewScreen.tsx b/apps/app-fp-movement/src/screens/Shipment/ShipmentViewScreen.tsx index 75e0a7e67..3df344456 100644 --- a/apps/app-fp-movement/src/screens/Shipment/ShipmentViewScreen.tsx +++ b/apps/app-fp-movement/src/screens/Shipment/ShipmentViewScreen.tsx @@ -55,6 +55,7 @@ import { alertWithSound, alertWithSoundMulti, getBarcode, + getCodeForCheck, getDocToSend, getLineGood, getRemGoodListByContact, @@ -197,7 +198,11 @@ const ShipmentViewScreen = () => { const good = remainsUse && goodRemains.length - ? goodRemains.find((item) => `0000${item.good.shcode}`.slice(-4) === `0000${line.good.shcode}`.slice(-4)) + ? goodRemains.find( + (item) => + getCodeForCheck(item.good.shcode, goodBarcodeSettings?.countCode || 4) === + getCodeForCheck(line.good.shcode, goodBarcodeSettings?.countCode || 4), + ) : undefined; if (remainsUse && goodRemains.length) { @@ -222,6 +227,7 @@ const ShipmentViewScreen = () => { }), ); const newLine: IShipmentLine = getUpdatedLine( + goodBarcodeSettings, remainsUse, lineBarcode, line, @@ -242,6 +248,7 @@ const ShipmentViewScreen = () => { }), ); const newLine: IShipmentLine = getUpdatedLine( + goodBarcodeSettings, remainsUse, lineBarcode, line, @@ -256,6 +263,7 @@ const ShipmentViewScreen = () => { } } else { const newLine: IShipmentLine = getUpdatedLine( + goodBarcodeSettings, remainsUse, lineBarcode, line, @@ -266,7 +274,7 @@ const ShipmentViewScreen = () => { dispatch(documentActions.updateDocumentLine({ docId: id, line: newLine })); } }, - [dispatch, fpDispatch, goodBarcodeSettings?.boxWeight, goodRemains, id, remainsUse, shipmentLines, tempOrder], + [dispatch, fpDispatch, goodBarcodeSettings, goodRemains, id, remainsUse, shipmentLines, tempOrder], ); const handleEditQuantPack = useCallback(() => { @@ -581,7 +589,14 @@ const ShipmentViewScreen = () => { } const barc = getBarcode(brc, goodBarcodeSettings); - const lineGood = getLineGood(barc.shcode, barc.weight, goods, goodRemains, remainsUse); + const lineGood = getLineGood( + barc.shcode, + barc.weight, + goods, + goodRemains, + remainsUse, + goodBarcodeSettings?.countCode || 4, + ); if (!lineGood.good) { setVisibleRequestDialog(true); diff --git a/apps/app-fp-movement/src/utils/constants.ts b/apps/app-fp-movement/src/utils/constants.ts index 19b18b1c0..1f72fe03e 100644 --- a/apps/app-fp-movement/src/utils/constants.ts +++ b/apps/app-fp-movement/src/utils/constants.ts @@ -351,6 +351,7 @@ export const lineTypes: IListItem[] = [ ]; export const barCodeTypes = [ + BarCodeScanner.Constants.BarCodeType.qr, BarCodeScanner.Constants.BarCodeType.code128, BarCodeScanner.Constants.BarCodeType.ean13, BarCodeScanner.Constants.BarCodeType.ean8, diff --git a/apps/app-fp-movement/src/utils/helpers.ts b/apps/app-fp-movement/src/utils/helpers.ts index 0a97645f2..7927352de 100644 --- a/apps/app-fp-movement/src/utils/helpers.ts +++ b/apps/app-fp-movement/src/utils/helpers.ts @@ -79,18 +79,18 @@ export const getBarcode = (barcode: string, settings: barcodeSettings) => { return barcodeObj; }; -export const getBarcodeString = (barcodeObj: IBarcode) => { +export const getBarcodeString = (barcodeObj: IBarcode, settings: barcodeSettings) => { const day = `00${new Date(barcodeObj.workDate).getDate().toLocaleString()}`.slice(-2); const month = `00${(new Date(barcodeObj.workDate).getMonth() + 1).toLocaleString()}`.slice(-2); const year = `00${new Date(barcodeObj.workDate).getFullYear().toLocaleString().slice(2)}`.slice(-2); - const shcode = `0000${barcodeObj.shcode}`.slice(-4); - const quantPack = `0000${barcodeObj.quantPack.toLocaleString()}`.slice(-4); + const shcode = getCodeForCheck(barcodeObj.shcode, settings?.countCode || 4); + const quantPack = getCodeForCheck(barcodeObj.quantPack.toLocaleString(), settings?.countQuantPack || 4); const weight = barcodeObj.weight < ONE_T_IN_KG - ? `000000${round(barcodeObj.weight * ONE_KG_IN_G, 3).toString()}`.slice(-6) - : `000000${round(barcodeObj.weight * ONE_KG_IN_G, 3).toString()}`.slice(6); + ? getCodeForCheck(round(barcodeObj.weight * ONE_KG_IN_G, 3).toString(), settings?.countWeight || 6) + : getCodeForCheck(round(barcodeObj.weight * ONE_KG_IN_G, 3).toString(), -(settings?.countWeight || 6)); const barcode = weight + day + month + year + (barcodeObj.time || '0000') + shcode + quantPack + barcodeObj.numReceived; @@ -227,10 +227,13 @@ export const getLineGood = ( goods: IGood[], goodRemains: IRemGood[], remainsUse: boolean, + countCode: number, ) => { if (remainsUse) { if (goodRemains.length) { - const good = goodRemains.find((item) => item.good && `0000${item.good.shcode}`.slice(-4) === shcode); + const good = goodRemains.find( + (item) => item.good && getCodeForCheck(item.good.shcode, countCode || 4) === shcode, + ); if (good) { const isRightWeight = good.remains >= weight; @@ -252,7 +255,7 @@ export const getLineGood = ( return { good: undefined, isRightWeight: false }; } } else { - const good = goods.find((item) => `0000${item.shcode}`.slice(-4) === shcode); + const good = goods.find((item) => getCodeForCheck(item.shcode, countCode || 4) === shcode); return { good: good ? { id: good.id, name: good.name, shcode: good.shcode, isCattle: good.isCattle, goodGroupId: good.goodGroupId } @@ -290,6 +293,7 @@ export const getTotalLines = (docList: IShipmentDocument[], departId: string) => }, {}); export const getUpdatedLine = ( + settings: barcodeSettings, usedRemains: boolean, lineBarcode: IBarcode, line: IBasedLine, @@ -297,8 +301,8 @@ export const getUpdatedLine = ( weight?: number, ) => { const newBarcode = weight - ? getBarcodeString({ ...lineBarcode, quantPack: quantity, weight }) - : getBarcodeString({ ...lineBarcode, quantPack: quantity }); + ? getBarcodeString({ ...lineBarcode, quantPack: quantity, weight }, settings) + : getBarcodeString({ ...lineBarcode, quantPack: quantity }, settings); return { ...line, @@ -440,3 +444,6 @@ export const alertWithSoundMulti = (label: string, text: string, onOk: () => voi }, ]); }; + +export const getCodeForCheck = (value: string, count: number) => + `${'0'.repeat(count || 4)}${value}`.slice(-(count || 4));