@things-factory/sales-base 4.3.651 → 4.3.653
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/constants/attachment-type.js +15 -0
- package/dist-server/constants/attachment-type.js.map +1 -0
- package/dist-server/constants/index.js +24 -0
- package/dist-server/constants/index.js.map +1 -0
- package/dist-server/constants/load-type.js +8 -0
- package/dist-server/constants/load-type.js.map +1 -0
- package/dist-server/constants/order.js +235 -0
- package/dist-server/constants/order.js.map +1 -0
- package/dist-server/constants/product-group-type.js +8 -0
- package/dist-server/constants/product-group-type.js.map +1 -0
- package/dist-server/constants/release-good.js +13 -0
- package/dist-server/constants/release-good.js.map +1 -0
- package/dist-server/constants/transfer-order-type.js +9 -0
- package/dist-server/constants/transfer-order-type.js.map +1 -0
- package/dist-server/constants/validation-error-code.js +7 -0
- package/dist-server/constants/validation-error-code.js.map +1 -0
- package/dist-server/constants/vas-target-type.js +26 -0
- package/dist-server/constants/vas-target-type.js.map +1 -0
- package/dist-server/controllers/ecommerce/ecommerce-controller.js +138 -0
- package/dist-server/controllers/ecommerce/ecommerce-controller.js.map +1 -0
- package/dist-server/controllers/ecommerce/index.js +21 -0
- package/dist-server/controllers/ecommerce/index.js.map +1 -0
- package/dist-server/controllers/ecommerce/powrup-controller.js +690 -0
- package/dist-server/controllers/ecommerce/powrup-controller.js.map +1 -0
- package/dist-server/controllers/ecommerce/sellercraft-controller.js +148 -0
- package/dist-server/controllers/ecommerce/sellercraft-controller.js.map +1 -0
- package/dist-server/controllers/ecommerce/webspert-controller.js +237 -0
- package/dist-server/controllers/ecommerce/webspert-controller.js.map +1 -0
- package/dist-server/controllers/index.js +19 -0
- package/dist-server/controllers/index.js.map +1 -0
- package/dist-server/controllers/order-controller.js +244 -0
- package/dist-server/controllers/order-controller.js.map +1 -0
- package/dist-server/errors/index.js +18 -0
- package/dist-server/errors/index.js.map +1 -0
- package/dist-server/errors/validation-error.js +41 -0
- package/dist-server/errors/validation-error.js.map +1 -0
- package/dist-server/index.js +30 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/migrations/index.js +12 -0
- package/dist-server/migrations/index.js.map +1 -0
- package/dist-server/service/arrival-notice/arrival-notice-mutation.js +1085 -0
- package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -0
- package/dist-server/service/arrival-notice/arrival-notice-query.js +634 -0
- package/dist-server/service/arrival-notice/arrival-notice-query.js.map +1 -0
- package/dist-server/service/arrival-notice/arrival-notice-types.js +443 -0
- package/dist-server/service/arrival-notice/arrival-notice-types.js.map +1 -0
- package/dist-server/service/arrival-notice/arrival-notice.js +259 -0
- package/dist-server/service/arrival-notice/arrival-notice.js.map +1 -0
- package/dist-server/service/arrival-notice/index.js +25 -0
- package/dist-server/service/arrival-notice/index.js.map +1 -0
- package/dist-server/service/claim/claim-mutation.js +243 -0
- package/dist-server/service/claim/claim-mutation.js.map +1 -0
- package/dist-server/service/claim/claim-query.js +165 -0
- package/dist-server/service/claim/claim-query.js.map +1 -0
- package/dist-server/service/claim/claim-types.js +191 -0
- package/dist-server/service/claim/claim-types.js.map +1 -0
- package/dist-server/service/claim/claim.js +176 -0
- package/dist-server/service/claim/claim.js.map +1 -0
- package/dist-server/service/claim/index.js +25 -0
- package/dist-server/service/claim/index.js.map +1 -0
- package/dist-server/service/claim-detail/claim-detail-mutation.js +110 -0
- package/dist-server/service/claim-detail/claim-detail-mutation.js.map +1 -0
- package/dist-server/service/claim-detail/claim-detail-query.js +90 -0
- package/dist-server/service/claim-detail/claim-detail-query.js.map +1 -0
- package/dist-server/service/claim-detail/claim-detail-types.js +81 -0
- package/dist-server/service/claim-detail/claim-detail-types.js.map +1 -0
- package/dist-server/service/claim-detail/claim-detail.js +102 -0
- package/dist-server/service/claim-detail/claim-detail.js.map +1 -0
- package/dist-server/service/claim-detail/index.js +25 -0
- package/dist-server/service/claim-detail/index.js.map +1 -0
- package/dist-server/service/claim-order/claim-order-mutation.js +110 -0
- package/dist-server/service/claim-order/claim-order-mutation.js.map +1 -0
- package/dist-server/service/claim-order/claim-order-query.js +86 -0
- package/dist-server/service/claim-order/claim-order-query.js.map +1 -0
- package/dist-server/service/claim-order/claim-order-types.js +65 -0
- package/dist-server/service/claim-order/claim-order-types.js.map +1 -0
- package/dist-server/service/claim-order/claim-order.js +104 -0
- package/dist-server/service/claim-order/claim-order.js.map +1 -0
- package/dist-server/service/claim-order/index.js +25 -0
- package/dist-server/service/claim-order/index.js.map +1 -0
- package/dist-server/service/collection-order/collection-order-mutation.js +241 -0
- package/dist-server/service/collection-order/collection-order-mutation.js.map +1 -0
- package/dist-server/service/collection-order/collection-order-query.js +125 -0
- package/dist-server/service/collection-order/collection-order-query.js.map +1 -0
- package/dist-server/service/collection-order/collection-order-types.js +241 -0
- package/dist-server/service/collection-order/collection-order-types.js.map +1 -0
- package/dist-server/service/collection-order/collection-order.js +183 -0
- package/dist-server/service/collection-order/collection-order.js.map +1 -0
- package/dist-server/service/collection-order/index.js +25 -0
- package/dist-server/service/collection-order/index.js.map +1 -0
- package/dist-server/service/delivery-order/delivery-order-mutation.js +746 -0
- package/dist-server/service/delivery-order/delivery-order-mutation.js.map +1 -0
- package/dist-server/service/delivery-order/delivery-order-query.js +570 -0
- package/dist-server/service/delivery-order/delivery-order-query.js.map +1 -0
- package/dist-server/service/delivery-order/delivery-order-types.js +397 -0
- package/dist-server/service/delivery-order/delivery-order-types.js.map +1 -0
- package/dist-server/service/delivery-order/delivery-order.js +365 -0
- package/dist-server/service/delivery-order/delivery-order.js.map +1 -0
- package/dist-server/service/delivery-order/index.js +25 -0
- package/dist-server/service/delivery-order/index.js.map +1 -0
- package/dist-server/service/draft-release-good/draft-release-good-create.js +647 -0
- package/dist-server/service/draft-release-good/draft-release-good-create.js.map +1 -0
- package/dist-server/service/draft-release-good/draft-release-good-mutation.js +486 -0
- package/dist-server/service/draft-release-good/draft-release-good-mutation.js.map +1 -0
- package/dist-server/service/draft-release-good/draft-release-good-query.js +366 -0
- package/dist-server/service/draft-release-good/draft-release-good-query.js.map +1 -0
- package/dist-server/service/draft-release-good/draft-release-good-type.js +424 -0
- package/dist-server/service/draft-release-good/draft-release-good-type.js.map +1 -0
- package/dist-server/service/draft-release-good/draft-release-good.js +444 -0
- package/dist-server/service/draft-release-good/draft-release-good.js.map +1 -0
- package/dist-server/service/draft-release-good/index.js +29 -0
- package/dist-server/service/draft-release-good/index.js.map +1 -0
- package/dist-server/service/goods-receival-note/goods-receival-note-mutation.js +140 -0
- package/dist-server/service/goods-receival-note/goods-receival-note-mutation.js.map +1 -0
- package/dist-server/service/goods-receival-note/goods-receival-note-query.js +273 -0
- package/dist-server/service/goods-receival-note/goods-receival-note-query.js.map +1 -0
- package/dist-server/service/goods-receival-note/goods-receival-note-types.js +159 -0
- package/dist-server/service/goods-receival-note/goods-receival-note-types.js.map +1 -0
- package/dist-server/service/goods-receival-note/goods-receival-note.js +156 -0
- package/dist-server/service/goods-receival-note/goods-receival-note.js.map +1 -0
- package/dist-server/service/goods-receival-note/index.js +25 -0
- package/dist-server/service/goods-receival-note/index.js.map +1 -0
- package/dist-server/service/index.js +282 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/service/inventory-check/index.js +25 -0
- package/dist-server/service/inventory-check/index.js.map +1 -0
- package/dist-server/service/inventory-check/inventory-check-mutation.js +151 -0
- package/dist-server/service/inventory-check/inventory-check-mutation.js.map +1 -0
- package/dist-server/service/inventory-check/inventory-check-query.js +138 -0
- package/dist-server/service/inventory-check/inventory-check-query.js.map +1 -0
- package/dist-server/service/inventory-check/inventory-check-types.js +82 -0
- package/dist-server/service/inventory-check/inventory-check-types.js.map +1 -0
- package/dist-server/service/inventory-check/inventory-check.js +115 -0
- package/dist-server/service/inventory-check/inventory-check.js.map +1 -0
- package/dist-server/service/inventory-check-item/index.js +25 -0
- package/dist-server/service/inventory-check-item/index.js.map +1 -0
- package/dist-server/service/inventory-check-item/inventory-check-item-mutation.js +120 -0
- package/dist-server/service/inventory-check-item/inventory-check-item-mutation.js.map +1 -0
- package/dist-server/service/inventory-check-item/inventory-check-item-query.js +196 -0
- package/dist-server/service/inventory-check-item/inventory-check-item-query.js.map +1 -0
- package/dist-server/service/inventory-check-item/inventory-check-item-types.js +157 -0
- package/dist-server/service/inventory-check-item/inventory-check-item-types.js.map +1 -0
- package/dist-server/service/inventory-check-item/inventory-check-item.js +273 -0
- package/dist-server/service/inventory-check-item/inventory-check-item.js.map +1 -0
- package/dist-server/service/invoice/index.js +25 -0
- package/dist-server/service/invoice/index.js.map +1 -0
- package/dist-server/service/invoice/invoice-mutation.js +105 -0
- package/dist-server/service/invoice/invoice-mutation.js.map +1 -0
- package/dist-server/service/invoice/invoice-query.js +94 -0
- package/dist-server/service/invoice/invoice-query.js.map +1 -0
- package/dist-server/service/invoice/invoice-types.js +388 -0
- package/dist-server/service/invoice/invoice-types.js.map +1 -0
- package/dist-server/service/invoice/invoice.js +312 -0
- package/dist-server/service/invoice/invoice.js.map +1 -0
- package/dist-server/service/invoice-product/index.js +25 -0
- package/dist-server/service/invoice-product/index.js.map +1 -0
- package/dist-server/service/invoice-product/invoice-product-mutation.js +70 -0
- package/dist-server/service/invoice-product/invoice-product-mutation.js.map +1 -0
- package/dist-server/service/invoice-product/invoice-product-query.js +95 -0
- package/dist-server/service/invoice-product/invoice-product-query.js.map +1 -0
- package/dist-server/service/invoice-product/invoice-product-types.js +131 -0
- package/dist-server/service/invoice-product/invoice-product-types.js.map +1 -0
- package/dist-server/service/invoice-product/invoice-product.js +130 -0
- package/dist-server/service/invoice-product/invoice-product.js.map +1 -0
- package/dist-server/service/job-sheet/index.js +25 -0
- package/dist-server/service/job-sheet/index.js.map +1 -0
- package/dist-server/service/job-sheet/job-sheet-mutation.js +93 -0
- package/dist-server/service/job-sheet/job-sheet-mutation.js.map +1 -0
- package/dist-server/service/job-sheet/job-sheet-query.js +134 -0
- package/dist-server/service/job-sheet/job-sheet-query.js.map +1 -0
- package/dist-server/service/job-sheet/job-sheet-types.js +113 -0
- package/dist-server/service/job-sheet/job-sheet-types.js.map +1 -0
- package/dist-server/service/job-sheet/job-sheet.js +132 -0
- package/dist-server/service/job-sheet/job-sheet.js.map +1 -0
- package/dist-server/service/manifest/index.js +9 -0
- package/dist-server/service/manifest/index.js.map +1 -0
- package/dist-server/service/manifest/manifest-mutation.js +264 -0
- package/dist-server/service/manifest/manifest-mutation.js.map +1 -0
- package/dist-server/service/manifest/manifest-query.js +228 -0
- package/dist-server/service/manifest/manifest-query.js.map +1 -0
- package/dist-server/service/manifest/manifest-type.js +183 -0
- package/dist-server/service/manifest/manifest-type.js.map +1 -0
- package/dist-server/service/manifest/manifest.js +134 -0
- package/dist-server/service/manifest/manifest.js.map +1 -0
- package/dist-server/service/order-consignment/index.js +9 -0
- package/dist-server/service/order-consignment/index.js.map +1 -0
- package/dist-server/service/order-consignment/order-consignment-mutation.js +120 -0
- package/dist-server/service/order-consignment/order-consignment-mutation.js.map +1 -0
- package/dist-server/service/order-consignment/order-consignment-query.js +87 -0
- package/dist-server/service/order-consignment/order-consignment-query.js.map +1 -0
- package/dist-server/service/order-consignment/order-consignment-type.js +69 -0
- package/dist-server/service/order-consignment/order-consignment-type.js.map +1 -0
- package/dist-server/service/order-consignment/order-consignment.js +115 -0
- package/dist-server/service/order-consignment/order-consignment.js.map +1 -0
- package/dist-server/service/order-inventory/index.js +25 -0
- package/dist-server/service/order-inventory/index.js.map +1 -0
- package/dist-server/service/order-inventory/order-inventory-mutation.js +80 -0
- package/dist-server/service/order-inventory/order-inventory-mutation.js.map +1 -0
- package/dist-server/service/order-inventory/order-inventory-query.js +592 -0
- package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -0
- package/dist-server/service/order-inventory/order-inventory-types.js +341 -0
- package/dist-server/service/order-inventory/order-inventory-types.js.map +1 -0
- package/dist-server/service/order-inventory/order-inventory.js +785 -0
- package/dist-server/service/order-inventory/order-inventory.js.map +1 -0
- package/dist-server/service/order-package/index.js +9 -0
- package/dist-server/service/order-package/index.js.map +1 -0
- package/dist-server/service/order-package/order-package-mutation.js +120 -0
- package/dist-server/service/order-package/order-package-mutation.js.map +1 -0
- package/dist-server/service/order-package/order-package-query.js +142 -0
- package/dist-server/service/order-package/order-package-query.js.map +1 -0
- package/dist-server/service/order-package/order-package-types.js +113 -0
- package/dist-server/service/order-package/order-package-types.js.map +1 -0
- package/dist-server/service/order-package/order-package.js +229 -0
- package/dist-server/service/order-package/order-package.js.map +1 -0
- package/dist-server/service/order-package-item/index.js +9 -0
- package/dist-server/service/order-package-item/index.js.map +1 -0
- package/dist-server/service/order-package-item/order-package-item-mutation.js +120 -0
- package/dist-server/service/order-package-item/order-package-item-mutation.js.map +1 -0
- package/dist-server/service/order-package-item/order-package-item-query.js +127 -0
- package/dist-server/service/order-package-item/order-package-item-query.js.map +1 -0
- package/dist-server/service/order-package-item/order-package-item-types.js +99 -0
- package/dist-server/service/order-package-item/order-package-item-types.js.map +1 -0
- package/dist-server/service/order-package-item/order-package-item.js +162 -0
- package/dist-server/service/order-package-item/order-package-item.js.map +1 -0
- package/dist-server/service/order-product/index.js +25 -0
- package/dist-server/service/order-product/index.js.map +1 -0
- package/dist-server/service/order-product/order-product-mutation.js +74 -0
- package/dist-server/service/order-product/order-product-mutation.js.map +1 -0
- package/dist-server/service/order-product/order-product-query.js +125 -0
- package/dist-server/service/order-product/order-product-query.js.map +1 -0
- package/dist-server/service/order-product/order-product-types.js +489 -0
- package/dist-server/service/order-product/order-product-types.js.map +1 -0
- package/dist-server/service/order-product/order-product.js +559 -0
- package/dist-server/service/order-product/order-product.js.map +1 -0
- package/dist-server/service/order-tote/index.js +25 -0
- package/dist-server/service/order-tote/index.js.map +1 -0
- package/dist-server/service/order-tote/order-tote-mutation.js +56 -0
- package/dist-server/service/order-tote/order-tote-mutation.js.map +1 -0
- package/dist-server/service/order-tote/order-tote-query.js +123 -0
- package/dist-server/service/order-tote/order-tote-query.js.map +1 -0
- package/dist-server/service/order-tote/order-tote-types.js +79 -0
- package/dist-server/service/order-tote/order-tote-types.js.map +1 -0
- package/dist-server/service/order-tote/order-tote.js +92 -0
- package/dist-server/service/order-tote/order-tote.js.map +1 -0
- package/dist-server/service/order-tote-item/index.js +25 -0
- package/dist-server/service/order-tote-item/index.js.map +1 -0
- package/dist-server/service/order-tote-item/order-tote-item-mutation.js +56 -0
- package/dist-server/service/order-tote-item/order-tote-item-mutation.js.map +1 -0
- package/dist-server/service/order-tote-item/order-tote-item-query.js +100 -0
- package/dist-server/service/order-tote-item/order-tote-item-query.js.map +1 -0
- package/dist-server/service/order-tote-item/order-tote-item-types.js +91 -0
- package/dist-server/service/order-tote-item/order-tote-item-types.js.map +1 -0
- package/dist-server/service/order-tote-item/order-tote-item.js +118 -0
- package/dist-server/service/order-tote-item/order-tote-item.js.map +1 -0
- package/dist-server/service/order-tote-seal/index.js +25 -0
- package/dist-server/service/order-tote-seal/index.js.map +1 -0
- package/dist-server/service/order-tote-seal/order-tote-seal-mutation.js +56 -0
- package/dist-server/service/order-tote-seal/order-tote-seal-mutation.js.map +1 -0
- package/dist-server/service/order-tote-seal/order-tote-seal-query.js +97 -0
- package/dist-server/service/order-tote-seal/order-tote-seal-query.js.map +1 -0
- package/dist-server/service/order-tote-seal/order-tote-seal-types.js +71 -0
- package/dist-server/service/order-tote-seal/order-tote-seal-types.js.map +1 -0
- package/dist-server/service/order-tote-seal/order-tote-seal.js +71 -0
- package/dist-server/service/order-tote-seal/order-tote-seal.js.map +1 -0
- package/dist-server/service/order-vas/index.js +25 -0
- package/dist-server/service/order-vas/index.js.map +1 -0
- package/dist-server/service/order-vas/order-vas-mutation.js +148 -0
- package/dist-server/service/order-vas/order-vas-mutation.js.map +1 -0
- package/dist-server/service/order-vas/order-vas-query.js +148 -0
- package/dist-server/service/order-vas/order-vas-query.js.map +1 -0
- package/dist-server/service/order-vas/order-vas-types.js +348 -0
- package/dist-server/service/order-vas/order-vas-types.js.map +1 -0
- package/dist-server/service/order-vas/order-vas.js +476 -0
- package/dist-server/service/order-vas/order-vas.js.map +1 -0
- package/dist-server/service/order-vas-item/index.js +9 -0
- package/dist-server/service/order-vas-item/index.js.map +1 -0
- package/dist-server/service/order-vas-item/order-vas-item-mutation.js +164 -0
- package/dist-server/service/order-vas-item/order-vas-item-mutation.js.map +1 -0
- package/dist-server/service/order-vas-item/order-vas-item-query.js +99 -0
- package/dist-server/service/order-vas-item/order-vas-item-query.js.map +1 -0
- package/dist-server/service/order-vas-item/order-vas-item-type.js +131 -0
- package/dist-server/service/order-vas-item/order-vas-item-type.js.map +1 -0
- package/dist-server/service/order-vas-item/order-vas-item.js +166 -0
- package/dist-server/service/order-vas-item/order-vas-item.js.map +1 -0
- package/dist-server/service/others/index.js +21 -0
- package/dist-server/service/others/index.js.map +1 -0
- package/dist-server/service/others/other-query.js +536 -0
- package/dist-server/service/others/other-query.js.map +1 -0
- package/dist-server/service/others/other-types.js +181 -0
- package/dist-server/service/others/other-types.js.map +1 -0
- package/dist-server/service/purchase-order/index.js +25 -0
- package/dist-server/service/purchase-order/index.js.map +1 -0
- package/dist-server/service/purchase-order/purchase-order-mutation.js +398 -0
- package/dist-server/service/purchase-order/purchase-order-mutation.js.map +1 -0
- package/dist-server/service/purchase-order/purchase-order-query.js +126 -0
- package/dist-server/service/purchase-order/purchase-order-query.js.map +1 -0
- package/dist-server/service/purchase-order/purchase-order-types.js +240 -0
- package/dist-server/service/purchase-order/purchase-order-types.js.map +1 -0
- package/dist-server/service/purchase-order/purchase-order.js +236 -0
- package/dist-server/service/purchase-order/purchase-order.js.map +1 -0
- package/dist-server/service/purchase-order-other-charge/index.js +25 -0
- package/dist-server/service/purchase-order-other-charge/index.js.map +1 -0
- package/dist-server/service/purchase-order-other-charge/purchase-order-other-charge-mutation.js +56 -0
- package/dist-server/service/purchase-order-other-charge/purchase-order-other-charge-mutation.js.map +1 -0
- package/dist-server/service/purchase-order-other-charge/purchase-order-other-charge-query.js +87 -0
- package/dist-server/service/purchase-order-other-charge/purchase-order-other-charge-query.js.map +1 -0
- package/dist-server/service/purchase-order-other-charge/purchase-order-other-charge-types.js +77 -0
- package/dist-server/service/purchase-order-other-charge/purchase-order-other-charge-types.js.map +1 -0
- package/dist-server/service/purchase-order-other-charge/purchase-order-other-charge.js +101 -0
- package/dist-server/service/purchase-order-other-charge/purchase-order-other-charge.js.map +1 -0
- package/dist-server/service/release-good/index.js +25 -0
- package/dist-server/service/release-good/index.js.map +1 -0
- package/dist-server/service/release-good/release-good-mutation.js +1598 -0
- package/dist-server/service/release-good/release-good-mutation.js.map +1 -0
- package/dist-server/service/release-good/release-good-query.js +1131 -0
- package/dist-server/service/release-good/release-good-query.js.map +1 -0
- package/dist-server/service/release-good/release-good-types.js +1043 -0
- package/dist-server/service/release-good/release-good-types.js.map +1 -0
- package/dist-server/service/release-good/release-good.js +817 -0
- package/dist-server/service/release-good/release-good.js.map +1 -0
- package/dist-server/service/release-good-logs/index.js +11 -0
- package/dist-server/service/release-good-logs/index.js.map +1 -0
- package/dist-server/service/release-good-logs/release-good-logs-mutation.js +126 -0
- package/dist-server/service/release-good-logs/release-good-logs-mutation.js.map +1 -0
- package/dist-server/service/release-good-logs/release-good-logs-query.js +71 -0
- package/dist-server/service/release-good-logs/release-good-logs-query.js.map +1 -0
- package/dist-server/service/release-good-logs/release-good-logs-type.js +65 -0
- package/dist-server/service/release-good-logs/release-good-logs-type.js.map +1 -0
- package/dist-server/service/release-good-logs/release-good-logs.js +96 -0
- package/dist-server/service/release-good-logs/release-good-logs.js.map +1 -0
- package/dist-server/service/replenishment/index.js +9 -0
- package/dist-server/service/replenishment/index.js.map +1 -0
- package/dist-server/service/replenishment/replenishment-mutation.js +234 -0
- package/dist-server/service/replenishment/replenishment-mutation.js.map +1 -0
- package/dist-server/service/replenishment/replenishment-query.js +185 -0
- package/dist-server/service/replenishment/replenishment-query.js.map +1 -0
- package/dist-server/service/replenishment/replenishment-type.js +119 -0
- package/dist-server/service/replenishment/replenishment-type.js.map +1 -0
- package/dist-server/service/replenishment/replenishment.js +114 -0
- package/dist-server/service/replenishment/replenishment.js.map +1 -0
- package/dist-server/service/retail-replenishment-order/index.js +25 -0
- package/dist-server/service/retail-replenishment-order/index.js.map +1 -0
- package/dist-server/service/retail-replenishment-order/retail-replenishment-order-mutation.js +314 -0
- package/dist-server/service/retail-replenishment-order/retail-replenishment-order-mutation.js.map +1 -0
- package/dist-server/service/retail-replenishment-order/retail-replenishment-order-query.js +89 -0
- package/dist-server/service/retail-replenishment-order/retail-replenishment-order-query.js.map +1 -0
- package/dist-server/service/retail-replenishment-order/retail-replenishment-order-types.js +148 -0
- package/dist-server/service/retail-replenishment-order/retail-replenishment-order-types.js.map +1 -0
- package/dist-server/service/retail-replenishment-order/retail-replenishment-order.js +141 -0
- package/dist-server/service/retail-replenishment-order/retail-replenishment-order.js.map +1 -0
- package/dist-server/service/return-order/index.js +25 -0
- package/dist-server/service/return-order/index.js.map +1 -0
- package/dist-server/service/return-order/return-order-mutation.js +451 -0
- package/dist-server/service/return-order/return-order-mutation.js.map +1 -0
- package/dist-server/service/return-order/return-order-query.js +243 -0
- package/dist-server/service/return-order/return-order-query.js.map +1 -0
- package/dist-server/service/return-order/return-order-types.js +274 -0
- package/dist-server/service/return-order/return-order-types.js.map +1 -0
- package/dist-server/service/return-order/return-order.js +159 -0
- package/dist-server/service/return-order/return-order.js.map +1 -0
- package/dist-server/service/reverse-kitting-order/index.js +25 -0
- package/dist-server/service/reverse-kitting-order/index.js.map +1 -0
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order-mutation.js +407 -0
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order-mutation.js.map +1 -0
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order-query.js +222 -0
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order-query.js.map +1 -0
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order-type.js +230 -0
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order-type.js.map +1 -0
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order.js +145 -0
- package/dist-server/service/reverse-kitting-order/reverse-kitting-order.js.map +1 -0
- package/dist-server/service/reverse-kitting-order-inventory/index.js +25 -0
- package/dist-server/service/reverse-kitting-order-inventory/index.js.map +1 -0
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-mutation.js +130 -0
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-mutation.js.map +1 -0
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-query.js +87 -0
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-query.js.map +1 -0
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-type.js +143 -0
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-type.js.map +1 -0
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js +178 -0
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js.map +1 -0
- package/dist-server/service/shipping-order/index.js +25 -0
- package/dist-server/service/shipping-order/index.js.map +1 -0
- package/dist-server/service/shipping-order/shipping-order-mutation.js +78 -0
- package/dist-server/service/shipping-order/shipping-order-mutation.js.map +1 -0
- package/dist-server/service/shipping-order/shipping-order-query.js +96 -0
- package/dist-server/service/shipping-order/shipping-order-query.js.map +1 -0
- package/dist-server/service/shipping-order/shipping-order-types.js +137 -0
- package/dist-server/service/shipping-order/shipping-order-types.js.map +1 -0
- package/dist-server/service/shipping-order/shipping-order.js +165 -0
- package/dist-server/service/shipping-order/shipping-order.js.map +1 -0
- package/dist-server/service/transfer-order/index.js +25 -0
- package/dist-server/service/transfer-order/index.js.map +1 -0
- package/dist-server/service/transfer-order/transfer-order-mutation.js +252 -0
- package/dist-server/service/transfer-order/transfer-order-mutation.js.map +1 -0
- package/dist-server/service/transfer-order/transfer-order-query.js +104 -0
- package/dist-server/service/transfer-order/transfer-order-query.js.map +1 -0
- package/dist-server/service/transfer-order/transfer-order-types.js +148 -0
- package/dist-server/service/transfer-order/transfer-order-types.js.map +1 -0
- package/dist-server/service/transfer-order/transfer-order.js +146 -0
- package/dist-server/service/transfer-order/transfer-order.js.map +1 -0
- package/dist-server/service/vas/index.js +25 -0
- package/dist-server/service/vas/index.js.map +1 -0
- package/dist-server/service/vas/vas-mutation.js +562 -0
- package/dist-server/service/vas/vas-mutation.js.map +1 -0
- package/dist-server/service/vas/vas-query.js +114 -0
- package/dist-server/service/vas/vas-query.js.map +1 -0
- package/dist-server/service/vas/vas-types.js +113 -0
- package/dist-server/service/vas/vas-types.js.map +1 -0
- package/dist-server/service/vas/vas.js +114 -0
- package/dist-server/service/vas/vas.js.map +1 -0
- package/dist-server/service/vas-order/index.js +25 -0
- package/dist-server/service/vas-order/index.js.map +1 -0
- package/dist-server/service/vas-order/vas-order-mutation.js +241 -0
- package/dist-server/service/vas-order/vas-order-mutation.js.map +1 -0
- package/dist-server/service/vas-order/vas-order-query.js +151 -0
- package/dist-server/service/vas-order/vas-order-query.js.map +1 -0
- package/dist-server/service/vas-order/vas-order-types.js +83 -0
- package/dist-server/service/vas-order/vas-order-types.js.map +1 -0
- package/dist-server/service/vas-order/vas-order.js +104 -0
- package/dist-server/service/vas-order/vas-order.js.map +1 -0
- package/dist-server/utils/datetime-util.js +82 -0
- package/dist-server/utils/datetime-util.js.map +1 -0
- package/dist-server/utils/index.js +20 -0
- package/dist-server/utils/index.js.map +1 -0
- package/dist-server/utils/inventory-util.js +1098 -0
- package/dist-server/utils/inventory-util.js.map +1 -0
- package/dist-server/utils/order-no-generator.js +112 -0
- package/dist-server/utils/order-no-generator.js.map +1 -0
- package/package.json +8 -8
- package/server/service/vas/vas-mutation.ts +222 -225
|
@@ -0,0 +1,1098 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._composeTargetInventories = exports.switchLocationStatus = exports.InventoryUtil = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const biz_base_1 = require("@things-factory/biz-base");
|
|
6
|
+
const product_base_1 = require("@things-factory/product-base");
|
|
7
|
+
const setting_base_1 = require("@things-factory/setting-base");
|
|
8
|
+
const warehouse_base_1 = require("@things-factory/warehouse-base");
|
|
9
|
+
const constants_1 = require("../constants");
|
|
10
|
+
const errors_1 = require("../errors");
|
|
11
|
+
const service_1 = require("../service");
|
|
12
|
+
exports.InventoryUtil = {
|
|
13
|
+
/**
|
|
14
|
+
* Get all available product belonging to list of bizplaces
|
|
15
|
+
* @param {[Object]} bizplaces
|
|
16
|
+
* @param {Object} params
|
|
17
|
+
* @param {Object} context
|
|
18
|
+
* @param {Object} trxMgr
|
|
19
|
+
* @returns { object } {items, total}
|
|
20
|
+
*/
|
|
21
|
+
async bizplaceProductInventory(bizplaces, params, context, trxMgr) {
|
|
22
|
+
try {
|
|
23
|
+
let filters = params.filters;
|
|
24
|
+
const { domain } = context.state;
|
|
25
|
+
const { bizplaceIds, productWhereClause, bundleWhereClause, whereClause, batchBundle, productDetailWhereClause } = await getConditions(bizplaces, filters, trxMgr, false);
|
|
26
|
+
let productFilter = filters.find(itm => itm.name == 'productName');
|
|
27
|
+
let inventoryBizplaceFilter = filters.find(itm => itm.name == 'bizplaceId');
|
|
28
|
+
let deletedAt = filters.find(filter => filter.name == 'deleted_at');
|
|
29
|
+
let queryStrings = `
|
|
30
|
+
CREATE TEMP TABLE temp_inventory_product_group ON COMMIT DROP AS (
|
|
31
|
+
SELECT * FROM (
|
|
32
|
+
WITH oi as (
|
|
33
|
+
SELECT
|
|
34
|
+
SUM(oi.release_qty) AS release_qty,
|
|
35
|
+
SUM(oi.release_uom_value) AS release_uom_value,
|
|
36
|
+
oi.batch_id,
|
|
37
|
+
oi.batch_id_ref,
|
|
38
|
+
oi.product_id,
|
|
39
|
+
p.name AS product_name,
|
|
40
|
+
oi.packing_type,
|
|
41
|
+
oi.packing_size,
|
|
42
|
+
oi.uom
|
|
43
|
+
FROM
|
|
44
|
+
order_inventories oi
|
|
45
|
+
LEFT JOIN
|
|
46
|
+
products p
|
|
47
|
+
ON
|
|
48
|
+
oi.product_id = p.id
|
|
49
|
+
WHERE
|
|
50
|
+
(oi.status = 'PENDING' or oi.status = 'PENDING_RECEIVE' or oi.status = 'PENDING_WORKSHEET' or oi.status = 'PENDING_SPLIT')
|
|
51
|
+
AND oi.batch_id NOTNULL
|
|
52
|
+
AND oi.product_id NOTNULL
|
|
53
|
+
AND oi.packing_type NOTNULL
|
|
54
|
+
AND oi.packing_size NOTNULL
|
|
55
|
+
AND oi.inventory_id IS NULL
|
|
56
|
+
GROUP BY
|
|
57
|
+
oi.batch_id,
|
|
58
|
+
oi.batch_id_ref,
|
|
59
|
+
oi.product_id,
|
|
60
|
+
oi.packing_type,
|
|
61
|
+
oi.packing_size,
|
|
62
|
+
oi.uom,
|
|
63
|
+
p.name
|
|
64
|
+
)
|
|
65
|
+
SELECT
|
|
66
|
+
pd.packing_type AS "packingType",
|
|
67
|
+
pd.packing_size AS "packingSize",
|
|
68
|
+
pd.uom AS "uom",
|
|
69
|
+
concat(p.name, ' (', p.description, ')') AS "productName",
|
|
70
|
+
coalesce(p.sku, '') AS "productSKU",
|
|
71
|
+
coalesce(p.brand, '') AS "productBrand",
|
|
72
|
+
p.id AS "productId",
|
|
73
|
+
pd.id AS "productDetailId",
|
|
74
|
+
(
|
|
75
|
+
CASE WHEN i.lock_inventory is true THEN 0 WHEN (COALESCE(SUM(COALESCE(i.qty, 0)) - GREATEST(SUM(COALESCE(i.locked_qty, 0)), 0) - GREATEST(COALESCE(pds.unassigned_qty, 0), 0) - MAX(COALESCE(oi.release_qty, 0)) - MAX(COALESCE(bp.bundle_product_release_qty, 0)),0)) < 0 THEN 0
|
|
76
|
+
ELSE COALESCE(SUM(COALESCE(i.qty, 0)) - GREATEST(SUM(COALESCE(i.locked_qty, 0)), 0) - GREATEST(COALESCE(pds.unassigned_qty, 0), 0) - MAX(COALESCE(oi.release_qty, 0)) - MAX(COALESCE(bp.bundle_product_release_qty, 0)),0) END
|
|
77
|
+
) AS "remainQty",
|
|
78
|
+
(
|
|
79
|
+
CASE WHEN i.lock_inventory is true THEN 0 WHEN (COALESCE(SUM(COALESCE(i.uom_value, 0)) - GREATEST(SUM(COALESCE(i.locked_uom_value, 0)), 0) - GREATEST(COALESCE(pds.unassigned_uom_value, 0), 0) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)),0)) < 0 THEN 0
|
|
80
|
+
ELSE COALESCE(SUM(COALESCE(i.uom_value, 0)) - GREATEST(SUM(COALESCE(i.locked_uom_value, 0)), 0) - GREATEST(COALESCE(pds.unassigned_uom_value, 0), 0) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)),0) END
|
|
81
|
+
) AS "remainUomValue",
|
|
82
|
+
(
|
|
83
|
+
CASE WHEN i.lock_inventory is true THEN concat(0, ' ', pd.uom) WHEN (SUM(COALESCE(i.uom_value, 0)) - GREATEST(SUM(COALESCE(i.locked_uom_value, 0)), 0) - GREATEST(COALESCE(pds.unassigned_uom_value, 0), 0) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0))) < 0 THEN concat(0, ' ', pd.uom)
|
|
84
|
+
ELSE concat(SUM(COALESCE(i.uom_value, 0)) - GREATEST(SUM(COALESCE(i.locked_uom_value, 0)), 0) - GREATEST(COALESCE(pds.unassigned_uom_value, 0), 0) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)), ' ', pd.uom) END
|
|
85
|
+
) AS "remainUomValueWithUom",
|
|
86
|
+
COALESCE(SUM(COALESCE(i.transfer_qty, 0)), 0) AS "transferQty",
|
|
87
|
+
COALESCE(SUM(COALESCE(i.transfer_uom_value, 0)), 0) AS "transferUomValue",
|
|
88
|
+
'SINGLE' AS "groupType"
|
|
89
|
+
FROM products p
|
|
90
|
+
INNER join product_details pd on pd.product_id = p.id
|
|
91
|
+
LEFT JOIN product_detail_stocks pds on pds.product_detail_id = pd.id
|
|
92
|
+
LEFT JOIN (
|
|
93
|
+
SELECT i.* FROM inventories i
|
|
94
|
+
INNER JOIN locations l2 ON i.location_id = l2.id AND i.domain_id = l2.domain_id
|
|
95
|
+
WHERE l2.type NOT IN ('${warehouse_base_1.LOCATION_TYPE.QUARANTINE}', '${warehouse_base_1.LOCATION_TYPE.RESERVE}', '${warehouse_base_1.LOCATION_TYPE.DAMAGE}')
|
|
96
|
+
AND i.obsolete = false
|
|
97
|
+
AND i.domain_id = $1 AND i.status = 'STORED'
|
|
98
|
+
${inventoryBizplaceFilter ? `AND i.bizplace_id = '${inventoryBizplaceFilter.value}'` : ``}
|
|
99
|
+
) i ON i.product_detail_id = pd.id
|
|
100
|
+
LEFT JOIN oi ON i.batch_id = oi.batch_id AND p.name = oi.product_name AND i.packing_type = oi.packing_type AND i.packing_size = oi.packing_size AND i.uom = oi.uom
|
|
101
|
+
LEFT JOIN (
|
|
102
|
+
SELECT pbs.product_id, SUM(pbs.bundle_qty * src.release_qty) AS bundle_product_release_qty, SUM(pbs.bundle_qty * src.release_uom_value) AS bundle_product_release_uom_value
|
|
103
|
+
FROM product_bundle_settings pbs
|
|
104
|
+
INNER JOIN json_populate_recordset(NULL::order_inventories, '${batchBundle}') src ON src.product_id = pbs.product_bundle_id
|
|
105
|
+
GROUP BY pbs.product_id
|
|
106
|
+
) bp on i.product_id = bp.product_id
|
|
107
|
+
WHERE i.bizplace_id IN (${bizplaceIds})
|
|
108
|
+
AND i.lock_inventory is not true
|
|
109
|
+
AND case when i.expiration_date is not null and p.min_outbound_shelf_life is not null then CURRENT_DATE < i.expiration_date - p.min_outbound_shelf_life else true end
|
|
110
|
+
${productDetailWhereClause}
|
|
111
|
+
${productFilter
|
|
112
|
+
? `AND (
|
|
113
|
+
lower(p.sku) ilike '${productFilter.value}'
|
|
114
|
+
OR lower(p.name) ilike '${productFilter.value}'
|
|
115
|
+
OR lower(p.description) ilike '${productFilter.value}'
|
|
116
|
+
)
|
|
117
|
+
`
|
|
118
|
+
: ``}
|
|
119
|
+
${deletedAt && deletedAt.value == true ? `AND pd.deleted_at isnull` : ``}
|
|
120
|
+
GROUP BY
|
|
121
|
+
i.lock_inventory,
|
|
122
|
+
p.id,
|
|
123
|
+
pd.id,
|
|
124
|
+
pd.packing_type,
|
|
125
|
+
pd.packing_size,
|
|
126
|
+
pd.uom,
|
|
127
|
+
pds.unassigned_qty,
|
|
128
|
+
pds.unassigned_uom_value
|
|
129
|
+
UNION
|
|
130
|
+
SELECT packing_type, packing_size,'UNIT' AS "uom", name AS "productName", sku AS "productSKU", '-' AS "productBrand", id AS "productId", pbs.product_detail_id AS "productDetailId",
|
|
131
|
+
COALESCE(MIN(FLOOR(pbs."availableQty")),0) AS "remainQty",
|
|
132
|
+
COALESCE(MIN(FLOOR(pbs."availableUomValue")),0) AS "remainUomValue",
|
|
133
|
+
CONCAT(COALESCE(MIN(FLOOR(pbs."availableUomValue")),0),' UNIT') AS "remainUomValueWithUom",
|
|
134
|
+
COALESCE(MIN(FLOOR(pbs."transferQty")),0) AS "transferQty",
|
|
135
|
+
COALESCE(MIN(FLOOR(pbs."transferUomValue")),0) AS "transferUomValue",
|
|
136
|
+
'BUNDLE' AS "groupType"
|
|
137
|
+
FROM product_bundles pb
|
|
138
|
+
LEFT JOIN (
|
|
139
|
+
SELECT pbs.product_id, pbs.product_bundle_id, min(pbs.bundle_qty),
|
|
140
|
+
(
|
|
141
|
+
CASE WHEN ((SUM(COALESCE(i2.qty, 0)) - GREATEST(SUM(COALESCE(i2.locked_qty, 0)), 0) - GREATEST(COALESCE(pds2.unassigned_qty, 0), 0) - MAX(COALESCE(oi.release_qty, 0))) / min(pbs.bundle_qty)) < 0 THEN 0
|
|
142
|
+
ELSE (SUM(COALESCE(i2.qty, 0)) - GREATEST(SUM(COALESCE(i2.locked_qty, 0)), 0) - GREATEST(COALESCE(pds2.unassigned_qty, 0), 0) - MAX(COALESCE(oi.release_qty, 0))) / min(pbs.bundle_qty) END
|
|
143
|
+
) AS "availableQty",
|
|
144
|
+
(
|
|
145
|
+
CASE WHEN ((SUM(COALESCE(i2.uom_value, 0)) - GREATEST(SUM(COALESCE(i2.locked_uom_value, 0)), 0) - GREATEST(COALESCE(pds2.unassigned_uom_value, 0), 0) - MAX(COALESCE(oi.release_uom_value, 0))) / min(pbs.bundle_qty)) < 0 THEN 0
|
|
146
|
+
ELSE (SUM(COALESCE(i2.uom_value, 0)) - GREATEST(SUM(COALESCE(i2.locked_uom_value, 0)), 0) - GREATEST(COALESCE(pds2.unassigned_uom_value, 0), 0) - MAX(COALESCE(oi.release_uom_value, 0))) / min(pbs.bundle_qty) END
|
|
147
|
+
) AS "availableUomValue",
|
|
148
|
+
(SUM(COALESCE(i2.transfer_qty, 0)) / min(pbs.bundle_qty)) AS "transferQty",
|
|
149
|
+
(SUM(COALESCE(i2.transfer_uom_value, 0)) / min(pbs.bundle_qty)) AS "transferUomValue",
|
|
150
|
+
pbs.product_detail_id
|
|
151
|
+
FROM product_bundle_settings pbs
|
|
152
|
+
LEFT JOIN inventories i2 ON i2.product_id = pbs.product_id AND i2.domain_id = $1 AND i2.status = 'STORED'
|
|
153
|
+
LEFT JOIN product_detail_stocks pds2 ON pds2.product_detail_id = pbs.product_detail_id
|
|
154
|
+
INNER JOIN locations l2 ON i2.location_id = l2.id
|
|
155
|
+
LEFT JOIN oi ON oi.product_id = i2.product_id
|
|
156
|
+
WHERE l2.type NOT IN ('${warehouse_base_1.LOCATION_TYPE.QUARANTINE}', '${warehouse_base_1.LOCATION_TYPE.RESERVE}', '${warehouse_base_1.LOCATION_TYPE.DAMAGE}')
|
|
157
|
+
and i2.obsolete = false
|
|
158
|
+
${inventoryBizplaceFilter ? `AND i2.bizplace_id = '${inventoryBizplaceFilter.value}'` : ``}
|
|
159
|
+
GROUP BY
|
|
160
|
+
pbs.product_id,
|
|
161
|
+
pbs.product_bundle_id,
|
|
162
|
+
pbs.product_detail_id,
|
|
163
|
+
pds2.unassigned_qty,
|
|
164
|
+
pds2.unassigned_uom_value
|
|
165
|
+
) pbs ON pbs.product_bundle_id = pb.id
|
|
166
|
+
${bundleWhereClause}
|
|
167
|
+
AND pb.bizplace_id IN (${bizplaceIds})
|
|
168
|
+
${productFilter
|
|
169
|
+
? `AND (
|
|
170
|
+
lower(pb.sku) ilike '${productFilter.value}'
|
|
171
|
+
OR lower(pb.name) ilike '${productFilter.value}'
|
|
172
|
+
OR lower(pb.description) ilike '${productFilter.value}'
|
|
173
|
+
)
|
|
174
|
+
`
|
|
175
|
+
: ``}
|
|
176
|
+
GROUP BY
|
|
177
|
+
pb.packing_type,
|
|
178
|
+
pb.packing_size,
|
|
179
|
+
pb.name,
|
|
180
|
+
pb.sku,
|
|
181
|
+
pb.id,
|
|
182
|
+
pbs.product_detail_id
|
|
183
|
+
)
|
|
184
|
+
AS inv_prod_grp
|
|
185
|
+
${whereClause}
|
|
186
|
+
order by "productSKU", "productName"
|
|
187
|
+
)
|
|
188
|
+
`;
|
|
189
|
+
await trxMgr.query(queryStrings, [domain.id]);
|
|
190
|
+
const [{ total }] = await trxMgr.query(`select count(*) as total from temp_inventory_product_group`);
|
|
191
|
+
let items = [];
|
|
192
|
+
if (params === null || params === void 0 ? void 0 : params.pagination) {
|
|
193
|
+
items = await trxMgr.query(`select * from temp_inventory_product_group OFFSET $1 LIMIT $2`, [
|
|
194
|
+
(params.pagination.page - 1) * params.pagination.limit,
|
|
195
|
+
params.pagination.limit
|
|
196
|
+
]);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
items = await trxMgr.query(`select * from temp_inventory_product_group`);
|
|
200
|
+
}
|
|
201
|
+
await trxMgr.query(`drop table temp_inventory_product_group`);
|
|
202
|
+
return { items, total };
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
/**
|
|
209
|
+
* Get all available product belonging to list of bizplaces
|
|
210
|
+
* @param {[Object]} bizplaces
|
|
211
|
+
* @param {Object} params
|
|
212
|
+
* @param {Object} context
|
|
213
|
+
* @param {Object} trxMgr
|
|
214
|
+
* @returns { object } {items, total}
|
|
215
|
+
*/
|
|
216
|
+
async bizplaceInventoryProductGroup(bizplaces, params, context, trxMgr) {
|
|
217
|
+
var _a;
|
|
218
|
+
try {
|
|
219
|
+
let filters = params.filters;
|
|
220
|
+
const { domain } = context.state;
|
|
221
|
+
const { bizplaceIds, productWhereClause, bundleWhereClause, whereClause, batchBundle } = await getConditions(bizplaces, filters, trxMgr);
|
|
222
|
+
let cycleCountFilter = (_a = filters.find(filter => filter.name == 'cycleCount')) === null || _a === void 0 ? void 0 : _a.value;
|
|
223
|
+
const _groupType = filters.find(res => res.name == 'groupType');
|
|
224
|
+
let queryStrings = `
|
|
225
|
+
CREATE TEMP TABLE temp_inventory_product_group AS (
|
|
226
|
+
SELECT * FROM (
|
|
227
|
+
SELECT
|
|
228
|
+
i.batch_id AS "batchId",
|
|
229
|
+
i.batch_id_ref AS "batchIdRef",
|
|
230
|
+
i.packing_type AS "packingType",
|
|
231
|
+
i.packing_size AS "packingSize",
|
|
232
|
+
i.uom AS "uom",
|
|
233
|
+
CONCAT(p.name, ' (', p.description, ')') AS "productName",
|
|
234
|
+
COALESCE(p.sku, '') AS "productSKU",
|
|
235
|
+
COALESCE(p.brand, '') AS "productBrand",
|
|
236
|
+
p.id AS "productId",
|
|
237
|
+
p.is_inventory_decimal AS "isInventoryDecimal",
|
|
238
|
+
i.product_detail_id AS "productDetailId",
|
|
239
|
+
SUM(COALESCE(i.qty, 0)) - SUM(COALESCE(i.locked_qty, 0)) - MAX(COALESCE(bp.bundle_product_release_qty, 0)) - SUM(COALESCE(pds.unassigned_qty, 0)) AS "remainQty",
|
|
240
|
+
SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)) - SUM(COALESCE(pds.unassigned_uom_value, 0)) AS "remainUomValue",
|
|
241
|
+
SUM(COALESCE(i.locked_qty, 0)) AS "lockedQty",
|
|
242
|
+
CONCAT(SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)) - SUM(COALESCE(pds.unassigned_uom_value, 0)), ' ', i.uom) AS "remainUomValueWithUom",
|
|
243
|
+
'SINGLE' AS "groupType",
|
|
244
|
+
SUM(COALESCE(pds.unassigned_qty, 0)) AS "unassignedQty"
|
|
245
|
+
FROM inventories i
|
|
246
|
+
LEFT JOIN products p ON i.product_id = p.id
|
|
247
|
+
LEFT JOIN product_detail_stocks pds ON pds.product_detail_id = i.product_detail_id
|
|
248
|
+
LEFT JOIN (
|
|
249
|
+
SELECT
|
|
250
|
+
pbs.product_id,
|
|
251
|
+
SUM(pbs.bundle_qty * src.release_qty) AS bundle_product_release_qty,
|
|
252
|
+
SUM(pbs.bundle_qty * src.release_uom_value) AS bundle_product_release_uom_value
|
|
253
|
+
FROM product_bundle_settings pbs
|
|
254
|
+
INNER JOIN json_populate_recordset(NULL::order_inventories,'${batchBundle}') src ON src.product_id = pbs.product_bundle_id
|
|
255
|
+
GROUP BY pbs.product_id
|
|
256
|
+
) bp ON i.product_id = bp.product_id
|
|
257
|
+
LEFT JOIN locations l2 ON i.location_id = l2.id AND i.domain_id = l2.domain_id
|
|
258
|
+
WHERE i.domain_id = $1
|
|
259
|
+
AND l2.type NOT IN ('${warehouse_base_1.LOCATION_TYPE.QUARANTINE}', '${warehouse_base_1.LOCATION_TYPE.RESERVE}', '${warehouse_base_1.LOCATION_TYPE.DAMAGE}')
|
|
260
|
+
AND i.obsolete = false
|
|
261
|
+
AND i.transfer_qty <= 0
|
|
262
|
+
AND i.transfer_uom_value <= 0
|
|
263
|
+
AND i.lock_inventory is not true
|
|
264
|
+
AND CASE WHEN i.expiration_date IS NOT NULL AND p.min_outbound_shelf_life IS NOT NULL THEN CURRENT_DATE < i.expiration_date - p.min_outbound_shelf_life ELSE true END
|
|
265
|
+
${cycleCountFilter
|
|
266
|
+
? `AND i.id NOT IN (
|
|
267
|
+
SELECT DISTINCT(ici.inventory_id) FROM worksheets w
|
|
268
|
+
INNER JOIN worksheet_details wd ON wd.worksheet_id = w.id
|
|
269
|
+
INNER JOIN inventory_check_items ici ON wd.target_inventory_check_item_id = ici.id
|
|
270
|
+
WHERE w.type IN ('CYCLE_COUNT','CYCLE_COUNT_RECHECK')
|
|
271
|
+
AND w.status != 'DONE'
|
|
272
|
+
AND w.bizplace_id IN (${bizplaceIds})
|
|
273
|
+
AND w.domain_id = '${domain.id}'
|
|
274
|
+
)`
|
|
275
|
+
: `AND true`}
|
|
276
|
+
${productWhereClause}
|
|
277
|
+
GROUP BY
|
|
278
|
+
i.product_detail_id,
|
|
279
|
+
i.batch_id,
|
|
280
|
+
i.batch_id_ref,
|
|
281
|
+
p.id,
|
|
282
|
+
i.packing_type,
|
|
283
|
+
i.packing_size,
|
|
284
|
+
i.uom
|
|
285
|
+
UNION
|
|
286
|
+
SELECT
|
|
287
|
+
'BUNDLE' AS "batchId",
|
|
288
|
+
NULL AS "batchIdRef",
|
|
289
|
+
pb.packing_type,
|
|
290
|
+
pb.packing_size,
|
|
291
|
+
'UNIT' AS "uom",
|
|
292
|
+
pb.name AS "productName",
|
|
293
|
+
pb.sku AS "productSKU",
|
|
294
|
+
'brand' AS "productBrand",
|
|
295
|
+
id AS "productId",
|
|
296
|
+
false AS "isInventoryDecimal",
|
|
297
|
+
pbs.product_detail_id AS "productDetailId",
|
|
298
|
+
MIN(FLOOR(pbs."availableQty")) AS "remainQty",
|
|
299
|
+
MIN(FLOOR(pbs."availableUomValue")) AS "remainUomValue",
|
|
300
|
+
MIN(FLOOR(pbs."releaseQty")) AS "lockedQty",
|
|
301
|
+
CONCAT(MIN(FLOOR(pbs."availableUomValue")), ' UNIT') AS "remainUomValueWithUom",
|
|
302
|
+
'BUNDLE' AS "groupType",
|
|
303
|
+
0 AS "unassignedQty"
|
|
304
|
+
FROM product_bundles pb
|
|
305
|
+
INNER JOIN (
|
|
306
|
+
SELECT
|
|
307
|
+
pbs.product_id,
|
|
308
|
+
pbs.product_bundle_id,
|
|
309
|
+
MIN(pbs.bundle_qty),
|
|
310
|
+
(SUM(COALESCE(i2.qty, 0)) - GREATEST(SUM(COALESCE(i2.locked_qty, 0)), 0)) / MIN(pbs.bundle_qty) AS "availableQty",
|
|
311
|
+
(SUM(COALESCE(i2.uom_value, 0)) - GREATEST(SUM(COALESCE(i2.locked_uom_value, 0)), 0)) / MIN(pbs.bundle_qty) AS "availableUomValue",
|
|
312
|
+
(SUM(COALESCE(i2.locked_qty, 0))) / min(pbs.bundle_qty) AS "releaseQty",
|
|
313
|
+
pbs.product_detail_id
|
|
314
|
+
FROM product_bundle_settings pbs
|
|
315
|
+
LEFT JOIN inventories i2 ON i2.product_id = pbs.product_id
|
|
316
|
+
AND i2.domain_id = $1
|
|
317
|
+
AND i2.bizplace_id IN (${bizplaceIds})
|
|
318
|
+
AND i2.status = 'STORED'
|
|
319
|
+
GROUP BY pbs.product_id, pbs.product_bundle_id, pbs.product_detail_id
|
|
320
|
+
) pbs ON pbs.product_bundle_id = pb.id
|
|
321
|
+
${bundleWhereClause}
|
|
322
|
+
GROUP BY pb.packing_type, pb.packing_size, pb.name, pb.sku, pb.id, pbs.product_detail_id
|
|
323
|
+
) AS inv_prod_grp
|
|
324
|
+
${whereClause}
|
|
325
|
+
)
|
|
326
|
+
`;
|
|
327
|
+
let filterGroupTypeQuery;
|
|
328
|
+
if (_groupType) {
|
|
329
|
+
if (_groupType.value === 'SINGLE') {
|
|
330
|
+
filterGroupTypeQuery = `where "groupType"= 'SINGLE' `;
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
filterGroupTypeQuery = `where "groupType"= 'BUNDLE' `;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
let sortingArr = params.sortings || [];
|
|
337
|
+
let sortedBy = [];
|
|
338
|
+
if (sortingArr.length > 0) {
|
|
339
|
+
sortingArr.forEach(element => {
|
|
340
|
+
if (element.desc) {
|
|
341
|
+
sortedBy.push(`"${element.name}" DESC `);
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
sortedBy.push(`"${element.name}" `);
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
await trxMgr.query(queryStrings, [domain.id]);
|
|
349
|
+
const [{ total }] = await trxMgr.query(`select count(*) as total from temp_inventory_product_group ${filterGroupTypeQuery ? filterGroupTypeQuery : ''}`);
|
|
350
|
+
let items = [];
|
|
351
|
+
if (params === null || params === void 0 ? void 0 : params.pagination) {
|
|
352
|
+
items = await trxMgr.query(`select * from temp_inventory_product_group ${filterGroupTypeQuery ? filterGroupTypeQuery : ''} ${sortingArr.length > 0 ? ' Order by ' + sortedBy.toString() : ''} OFFSET $1 LIMIT $2`, [(params.pagination.page - 1) * params.pagination.limit, params.pagination.limit]);
|
|
353
|
+
}
|
|
354
|
+
await trxMgr.query(`drop table temp_inventory_product_group`);
|
|
355
|
+
return { items, total };
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
throw error;
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
async bizplaceInventoryProductGroupImport(bizplaces, params, context, trxMgr) {
|
|
362
|
+
try {
|
|
363
|
+
let filters = params.filters;
|
|
364
|
+
const { domain } = context.state;
|
|
365
|
+
const { bizplaceIds, productWhereClause, bundleWhereClause, whereClause, batchBundle } = await getConditions(bizplaces, filters, trxMgr);
|
|
366
|
+
let queryStrings = `
|
|
367
|
+
CREATE TEMP TABLE temp_inventory_product_group AS (
|
|
368
|
+
SELECT * FROM (
|
|
369
|
+
SELECT
|
|
370
|
+
i.batch_id AS "batchId",
|
|
371
|
+
i.batch_id_ref AS "batchIdRef",
|
|
372
|
+
i.packing_type AS "packingType",
|
|
373
|
+
i.packing_size AS "packingSize",
|
|
374
|
+
i.uom AS "uom",
|
|
375
|
+
CONCAT(p.name, ' (', p.description, ')') AS "productName",
|
|
376
|
+
COALESCE(p.sku, '') AS "productSKU",
|
|
377
|
+
COALESCE(p.brand, '') AS "productBrand",
|
|
378
|
+
p.id AS "productId",
|
|
379
|
+
p.is_inventory_decimal AS "isInventoryDecimal",
|
|
380
|
+
i.product_detail_id AS "productDetailId",
|
|
381
|
+
p.picking_strategy AS "pickingStrategy",
|
|
382
|
+
i.created_at AS "createdAt",
|
|
383
|
+
i.expiration_date AS "expirationDate",
|
|
384
|
+
i.manufacture_date AS "manufactureDate",
|
|
385
|
+
l2.name AS "name",
|
|
386
|
+
l2.zone AS "zone",
|
|
387
|
+
l2.row AS "row",
|
|
388
|
+
l2.column AS "column",
|
|
389
|
+
l2.shelf AS "shelf",
|
|
390
|
+
SUM(COALESCE(i.qty, 0)) - SUM(COALESCE(i.locked_qty, 0)) - MAX(COALESCE(bp.bundle_product_release_qty, 0)) - SUM(COALESCE(pds.unassigned_qty, 0)) AS "remainQty",
|
|
391
|
+
SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)) - SUM(COALESCE(pds.unassigned_uom_value, 0)) AS "remainUomValue",
|
|
392
|
+
SUM(COALESCE(i.locked_qty, 0)) AS "lockedQty",
|
|
393
|
+
CONCAT(SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)) - SUM(COALESCE(pds.unassigned_uom_value, 0)), ' ', i.uom) AS "remainUomValueWithUom",
|
|
394
|
+
SUM(COALESCE(pds.unassigned_qty, 0)) AS "unassignedQty"
|
|
395
|
+
FROM inventories i
|
|
396
|
+
LEFT JOIN products p ON i.product_id = p.id
|
|
397
|
+
LEFT JOIN product_detail_stocks pds ON pds.product_detail_id = i.product_detail_id
|
|
398
|
+
LEFT JOIN (
|
|
399
|
+
SELECT
|
|
400
|
+
pbs.product_id,
|
|
401
|
+
SUM(pbs.bundle_qty * src.release_qty) AS bundle_product_release_qty,
|
|
402
|
+
SUM(pbs.bundle_qty * src.release_uom_value) AS bundle_product_release_uom_value
|
|
403
|
+
FROM product_bundle_settings pbs
|
|
404
|
+
INNER JOIN json_populate_recordset(NULL::order_inventories,'${batchBundle}') src ON src.product_id = pbs.product_bundle_id
|
|
405
|
+
GROUP BY pbs.product_id
|
|
406
|
+
) bp ON i.product_id = bp.product_id
|
|
407
|
+
LEFT JOIN locations l2 ON i.location_id = l2.id AND i.domain_id = l2.domain_id
|
|
408
|
+
WHERE i.domain_id = $1
|
|
409
|
+
AND l2.type NOT IN ('${warehouse_base_1.LOCATION_TYPE.QUARANTINE}', '${warehouse_base_1.LOCATION_TYPE.RESERVE}', '${warehouse_base_1.LOCATION_TYPE.DAMAGE}')
|
|
410
|
+
AND i.obsolete = false
|
|
411
|
+
AND i.transfer_qty <= 0
|
|
412
|
+
AND i.transfer_uom_value <= 0
|
|
413
|
+
AND i.lock_inventory is not true
|
|
414
|
+
AND CASE WHEN i.expiration_date IS NOT NULL AND p.min_outbound_shelf_life IS NOT NULL THEN CURRENT_DATE < i.expiration_date - p.min_outbound_shelf_life ELSE true END
|
|
415
|
+
${productWhereClause}
|
|
416
|
+
GROUP BY
|
|
417
|
+
i.product_detail_id,
|
|
418
|
+
i.batch_id,
|
|
419
|
+
i.batch_id_ref,
|
|
420
|
+
p.id,
|
|
421
|
+
i.packing_type,
|
|
422
|
+
i.packing_size,
|
|
423
|
+
i.uom,
|
|
424
|
+
i.created_at,
|
|
425
|
+
i.expiration_date,
|
|
426
|
+
i.manufacture_date,
|
|
427
|
+
l2.name,
|
|
428
|
+
l2.zone,
|
|
429
|
+
l2.row,
|
|
430
|
+
l2.column,
|
|
431
|
+
l2.shelf
|
|
432
|
+
UNION
|
|
433
|
+
SELECT
|
|
434
|
+
'BUNDLE' AS "batchId",
|
|
435
|
+
NULL AS "batchIdRef",
|
|
436
|
+
pb.packing_type,
|
|
437
|
+
pb.packing_size,
|
|
438
|
+
'UNIT' AS "uom",
|
|
439
|
+
pb.name AS "productName",
|
|
440
|
+
pb.sku AS "productSKU",
|
|
441
|
+
'brand' AS "productBrand",
|
|
442
|
+
id AS "productId",
|
|
443
|
+
false AS "isInventoryDecimal",
|
|
444
|
+
pbs.product_detail_id AS "productDetailId",
|
|
445
|
+
NULL AS "pickingStrategy",
|
|
446
|
+
NULL AS "createdAt",
|
|
447
|
+
NULL AS "expirationDate",
|
|
448
|
+
NULL AS "manufactureDate",
|
|
449
|
+
NULL AS "name",
|
|
450
|
+
NULL AS "zone",
|
|
451
|
+
NULL AS "row",
|
|
452
|
+
NULL AS "column",
|
|
453
|
+
NULL AS "shelf",
|
|
454
|
+
MIN(FLOOR(pbs."availableQty")) AS "remainQty",
|
|
455
|
+
MIN(FLOOR(pbs."availableUomValue")) AS "remainUomValue",
|
|
456
|
+
MIN(FLOOR(pbs."releaseQty")) AS "lockedQty",
|
|
457
|
+
CONCAT(MIN(FLOOR(pbs."availableUomValue")), ' UNIT') AS "remainUomValueWithUom",
|
|
458
|
+
0 AS "unassignedQty"
|
|
459
|
+
FROM product_bundles pb
|
|
460
|
+
INNER JOIN (
|
|
461
|
+
SELECT
|
|
462
|
+
pbs.product_id,
|
|
463
|
+
pbs.product_bundle_id,
|
|
464
|
+
MIN(pbs.bundle_qty),
|
|
465
|
+
(SUM(COALESCE(i2.qty, 0)) - GREATEST(SUM(COALESCE(i2.locked_qty, 0)), 0)) / MIN(pbs.bundle_qty) AS "availableQty",
|
|
466
|
+
(SUM(COALESCE(i2.uom_value, 0)) - GREATEST(SUM(COALESCE(i2.locked_uom_value, 0)), 0)) / MIN(pbs.bundle_qty) AS "availableUomValue",
|
|
467
|
+
(SUM(COALESCE(i2.locked_qty, 0))) / min(pbs.bundle_qty) AS "releaseQty",
|
|
468
|
+
pbs.product_detail_id
|
|
469
|
+
FROM product_bundle_settings pbs
|
|
470
|
+
LEFT JOIN inventories i2 ON i2.product_id = pbs.product_id
|
|
471
|
+
AND i2.domain_id = $1
|
|
472
|
+
AND i2.bizplace_id IN (${bizplaceIds})
|
|
473
|
+
AND i2.status = 'STORED'
|
|
474
|
+
GROUP BY pbs.product_id, pbs.product_bundle_id, pbs.product_detail_id
|
|
475
|
+
) pbs ON pbs.product_bundle_id = pb.id
|
|
476
|
+
${bundleWhereClause}
|
|
477
|
+
GROUP BY pb.packing_type, pb.packing_size, pb.name, pb.sku, pb.id, pbs.product_detail_id
|
|
478
|
+
) AS inv_prod_grp
|
|
479
|
+
${whereClause}
|
|
480
|
+
)
|
|
481
|
+
`;
|
|
482
|
+
const inventoryAssignmentSetting = await trxMgr.getRepository(setting_base_1.Setting).findOne({
|
|
483
|
+
where: { domain, name: 'rule-for-inventory-assignment' }
|
|
484
|
+
});
|
|
485
|
+
const getLocationSortingClause = (inventoryAssignmentSetting) => {
|
|
486
|
+
let locationSortingRules = [];
|
|
487
|
+
if (inventoryAssignmentSetting) {
|
|
488
|
+
try {
|
|
489
|
+
let locationSetting = JSON.parse(inventoryAssignmentSetting.value);
|
|
490
|
+
for (const key in locationSetting) {
|
|
491
|
+
locationSortingRules.push({ name: key, desc: locationSetting[key] !== 'ASC' });
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
console.error('Invalid JSON in inventoryAssignmentSetting:', error);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (locationSortingRules.length) {
|
|
499
|
+
return locationSortingRules
|
|
500
|
+
.map(rule => `
|
|
501
|
+
CASE
|
|
502
|
+
WHEN "pickingStrategy" = 'LOCATION' THEN "${rule.name}"
|
|
503
|
+
END ${rule.desc ? 'DESC' : 'ASC'}
|
|
504
|
+
`)
|
|
505
|
+
.join(',\n');
|
|
506
|
+
}
|
|
507
|
+
return `
|
|
508
|
+
CASE
|
|
509
|
+
WHEN "pickingStrategy" = 'LOCATION' THEN "name"
|
|
510
|
+
END ASC
|
|
511
|
+
`;
|
|
512
|
+
};
|
|
513
|
+
await trxMgr.query(queryStrings, [domain.id]);
|
|
514
|
+
const total = 0;
|
|
515
|
+
let items = [];
|
|
516
|
+
if (!(params === null || params === void 0 ? void 0 : params.pagination)) {
|
|
517
|
+
const orderByClause = `
|
|
518
|
+
ORDER BY
|
|
519
|
+
${getLocationSortingClause(inventoryAssignmentSetting)},
|
|
520
|
+
CASE
|
|
521
|
+
WHEN "pickingStrategy" = 'LIFO' THEN "createdAt"
|
|
522
|
+
ELSE NULL
|
|
523
|
+
END DESC,
|
|
524
|
+
CASE
|
|
525
|
+
WHEN "pickingStrategy" = 'FIFO' THEN "createdAt"
|
|
526
|
+
WHEN "pickingStrategy" = 'FEFO' THEN "expirationDate"
|
|
527
|
+
WHEN "pickingStrategy" = 'FMFO' THEN "manufactureDate"
|
|
528
|
+
ELSE "createdAt"
|
|
529
|
+
END ASC,
|
|
530
|
+
-- Add this secondary sort for when primary sort values are equal
|
|
531
|
+
CASE
|
|
532
|
+
WHEN "pickingStrategy" = 'FEFO' THEN "createdAt"
|
|
533
|
+
WHEN "pickingStrategy" = 'FMFO' THEN "createdAt"
|
|
534
|
+
ELSE NULL
|
|
535
|
+
END ASC
|
|
536
|
+
`;
|
|
537
|
+
items = await trxMgr.query(`select * from temp_inventory_product_group ${orderByClause}`);
|
|
538
|
+
}
|
|
539
|
+
await trxMgr.query(`drop table temp_inventory_product_group`);
|
|
540
|
+
return { items, total };
|
|
541
|
+
}
|
|
542
|
+
catch (error) {
|
|
543
|
+
throw error;
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
async inventoryProductGroupOpenAPI(bizplaces, params, context, trxMgr) {
|
|
547
|
+
try {
|
|
548
|
+
let filters = params.filters;
|
|
549
|
+
const { domain } = context.state;
|
|
550
|
+
const { apiWhereClause } = await getConditions(bizplaces, filters, trxMgr);
|
|
551
|
+
let queryStrings = `
|
|
552
|
+
CREATE TEMP TABLE temp_inventory_product_group_open_api AS (
|
|
553
|
+
SELECT * FROM (
|
|
554
|
+
WITH oi as (
|
|
555
|
+
SELECT
|
|
556
|
+
SUM(oi.release_qty) AS release_qty,
|
|
557
|
+
SUM(oi.release_uom_value) AS release_uom_value,
|
|
558
|
+
oi.product_id,
|
|
559
|
+
p.name AS product_name,
|
|
560
|
+
oi.packing_type,
|
|
561
|
+
oi.packing_size,
|
|
562
|
+
oi.uom
|
|
563
|
+
FROM
|
|
564
|
+
order_inventories oi
|
|
565
|
+
LEFT JOIN
|
|
566
|
+
products p
|
|
567
|
+
ON
|
|
568
|
+
oi.product_id = p.id
|
|
569
|
+
WHERE
|
|
570
|
+
(oi.status = 'PENDING' or oi.status = 'PENDING_RECEIVE' or oi.status = 'PENDING_WORKSHEET' or oi.status = 'PENDING_SPLIT')
|
|
571
|
+
AND oi.product_id NOTNULL
|
|
572
|
+
AND oi.packing_type NOTNULL
|
|
573
|
+
AND oi.packing_size NOTNULL
|
|
574
|
+
AND oi.inventory_id IS NULL
|
|
575
|
+
GROUP BY
|
|
576
|
+
oi.product_id,
|
|
577
|
+
oi.packing_type,
|
|
578
|
+
oi.packing_size,
|
|
579
|
+
oi.uom,
|
|
580
|
+
p.name
|
|
581
|
+
)
|
|
582
|
+
SELECT
|
|
583
|
+
i.packing_type AS "packingType",
|
|
584
|
+
i.packing_size AS "packingSize",
|
|
585
|
+
i.uom AS "uom",
|
|
586
|
+
concat(p.name, ' (', p.description, ')') AS "productName",
|
|
587
|
+
coalesce(p.sku, '') AS "productSKU",
|
|
588
|
+
coalesce(p.brand, '') AS "productBrand",
|
|
589
|
+
p.id AS "productId",
|
|
590
|
+
SUM(COALESCE(i.qty, 0)) - SUM(COALESCE(i.locked_qty, 0)) - MAX(COALESCE(oi.release_qty, 0)) AS "remainQty",
|
|
591
|
+
SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) AS "remainUomValue",
|
|
592
|
+
SUM(COALESCE(i.qty, 0)) AS "totalQty",
|
|
593
|
+
SUM(COALESCE(i.uom_value, 0)) AS "totalUomValue",
|
|
594
|
+
SUM(COALESCE(i.locked_qty, 0)) + MAX(COALESCE(oi.release_qty, 0)) AS "totalLockedQty",
|
|
595
|
+
SUM(COALESCE(i.locked_uom_value, 0)) + MAX(COALESCE(oi.release_uom_value, 0)) AS "totalLockedUomValue",
|
|
596
|
+
concat(SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)), ' ', i.uom) AS "remainUomValueWithUom"
|
|
597
|
+
FROM inventories i
|
|
598
|
+
LEFT JOIN products p ON i.product_id = p.id
|
|
599
|
+
LEFT JOIN oi ON p.name = oi.product_name AND i.packing_type = oi.packing_type AND i.packing_size = oi.packing_size AND i.uom = oi.uom
|
|
600
|
+
LEFT JOIN locations l2 ON i.location_id = l2.id AND i.domain_id = l2.domain_id
|
|
601
|
+
WHERE i.domain_id = $1
|
|
602
|
+
AND l2.type NOT IN ('${warehouse_base_1.LOCATION_TYPE.QUARANTINE}', '${warehouse_base_1.LOCATION_TYPE.RESERVE}')
|
|
603
|
+
AND i.obsolete = false
|
|
604
|
+
AND case when i.expiration_date is not null and p.min_outbound_shelf_life is not null then CURRENT_DATE < i.expiration_date - p.min_outbound_shelf_life else true end
|
|
605
|
+
${apiWhereClause}
|
|
606
|
+
GROUP BY
|
|
607
|
+
p.id,
|
|
608
|
+
i.packing_type,
|
|
609
|
+
i.packing_size,
|
|
610
|
+
i.uom
|
|
611
|
+
)
|
|
612
|
+
AS inv_prod_grp
|
|
613
|
+
)
|
|
614
|
+
`;
|
|
615
|
+
await trxMgr.query(queryStrings, [domain.id]);
|
|
616
|
+
const [{ total }] = await trxMgr.query(`select count(*) as total from temp_inventory_product_group_open_api`);
|
|
617
|
+
let items = [];
|
|
618
|
+
if (params === null || params === void 0 ? void 0 : params.pagination) {
|
|
619
|
+
items = await trxMgr.query(`select * from temp_inventory_product_group_open_api OFFSET $1 LIMIT $2`, [
|
|
620
|
+
(params.pagination.page - 1) * params.pagination.limit,
|
|
621
|
+
params.pagination.limit
|
|
622
|
+
]);
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
items = await trxMgr.query(`select * from temp_inventory_product_group_open_api`);
|
|
626
|
+
}
|
|
627
|
+
await trxMgr.query(`drop table temp_inventory_product_group_open_api`);
|
|
628
|
+
return { items, total };
|
|
629
|
+
}
|
|
630
|
+
catch (error) {
|
|
631
|
+
throw error;
|
|
632
|
+
}
|
|
633
|
+
},
|
|
634
|
+
/**
|
|
635
|
+
* Validate warehouse partners product quantity
|
|
636
|
+
* @param {Object} warehouseDomain -
|
|
637
|
+
* @param {Object} partnerBizplace - {id}
|
|
638
|
+
* @param {Object} orderInventories - [{id, qty}]
|
|
639
|
+
* @param {Object} context
|
|
640
|
+
* @param {Object} trxMgr
|
|
641
|
+
*/
|
|
642
|
+
async validateWarehousePartnersProductsQuantity(warehouseDomain, partnerBizplace, orderInventories, context, trxMgr) {
|
|
643
|
+
let validOrderInventories = orderInventories.filter(oi => (oi === null || oi === void 0 ? void 0 : oi.isError) !== true);
|
|
644
|
+
if (!validOrderInventories.length) {
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
let json_oi = JSON.stringify(validOrderInventories.map(x => {
|
|
648
|
+
return {
|
|
649
|
+
product_detail_id: x.productDetail.id,
|
|
650
|
+
batch_id: x.batchId.replace(/'/g, `''`),
|
|
651
|
+
release_qty: x.releaseQty,
|
|
652
|
+
uom: x.uom
|
|
653
|
+
};
|
|
654
|
+
}));
|
|
655
|
+
let resultQb = await trxMgr.query(`
|
|
656
|
+
select joi.product_detail_id as "productDetailId", joi.batch_id as "batchId", joi.uom as "uom", joi.release_qty as "releaseQty",
|
|
657
|
+
sum(i.qty - coalesce(i.locked_qty,0)) - coalesce(
|
|
658
|
+
(
|
|
659
|
+
select sum(oi.release_qty) from order_inventories oi
|
|
660
|
+
where (oi.status = 'PENDING' or oi.status = 'PENDING_RECEIVE' or oi.status = 'PENDING_WORKSHEET' or oi.status = 'PENDING_SPLIT')
|
|
661
|
+
and oi.inventory_id IS null
|
|
662
|
+
and oi.product_detail_id = joi.product_detail_id
|
|
663
|
+
and oi.batch_id = joi.batch_id
|
|
664
|
+
and oi.uom = joi.uom
|
|
665
|
+
and oi.domain_id = $1
|
|
666
|
+
and oi.bizplace_id = $2
|
|
667
|
+
),0) as "availableQty",
|
|
668
|
+
sum(i.uom_value - coalesce(i.locked_uom_value ,0)) - coalesce(
|
|
669
|
+
(
|
|
670
|
+
select sum(oi.release_uom_value) from order_inventories oi
|
|
671
|
+
where (oi.status = 'PENDING' or oi.status = 'PENDING_RECEIVE' or oi.status = 'PENDING_WORKSHEET' or oi.status = 'PENDING_SPLIT')
|
|
672
|
+
and oi.inventory_id IS null
|
|
673
|
+
and oi.product_detail_id = joi.product_detail_id
|
|
674
|
+
and oi.batch_id = joi.batch_id
|
|
675
|
+
and oi.uom = joi.uom
|
|
676
|
+
and oi.domain_id = $1
|
|
677
|
+
and oi.bizplace_id = $2
|
|
678
|
+
),0) as "availableUomValue"
|
|
679
|
+
from json_populate_recordset(NULL::order_inventories,'${json_oi}') joi
|
|
680
|
+
left join inventories i on joi.product_detail_id = i.product_detail_id
|
|
681
|
+
and joi.batch_id = i.batch_id
|
|
682
|
+
and i.status ='STORED'
|
|
683
|
+
and i.lock_inventory is not true
|
|
684
|
+
and joi.uom = i.uom
|
|
685
|
+
and i.domain_id = $1
|
|
686
|
+
and i.bizplace_id = $2
|
|
687
|
+
group by joi.product_detail_id, joi.batch_id, joi.packing_type, joi.release_qty, joi.uom
|
|
688
|
+
`, [warehouseDomain.id, partnerBizplace.id]);
|
|
689
|
+
resultQb.forEach(itm => {
|
|
690
|
+
if (parseFloat(itm.releaseQty) > parseFloat(itm.availableQty)) {
|
|
691
|
+
throw new errors_1.ValidationError(Object.assign(Object.assign({}, errors_1.ValidationError.ERROR_CODES.RELEASE_QTY_OVER_LIMIT), { detail: { data: JSON.stringify(resultQb) } }));
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
},
|
|
695
|
+
async checkPalletDuplication(palletId, warehouseDomain, trxMgr) {
|
|
696
|
+
const duplicatedPalletCnt = await trxMgr.getRepository(warehouse_base_1.Inventory).count({
|
|
697
|
+
domain: warehouseDomain,
|
|
698
|
+
palletId,
|
|
699
|
+
status: (0, typeorm_1.Not)((0, typeorm_1.Equal)(warehouse_base_1.INVENTORY_STATUS.TERMINATED))
|
|
700
|
+
});
|
|
701
|
+
if (duplicatedPalletCnt)
|
|
702
|
+
throw new Error(palletId + ` exists`);
|
|
703
|
+
const duplicatedReusablePalletCnt = await trxMgr.getRepository(warehouse_base_1.Pallet).count({
|
|
704
|
+
where: {
|
|
705
|
+
domain: warehouseDomain,
|
|
706
|
+
name: palletId
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
if (duplicatedReusablePalletCnt)
|
|
710
|
+
throw new Error(palletId + ` exists`);
|
|
711
|
+
},
|
|
712
|
+
/**
|
|
713
|
+
* To pre-assign inventories automatically for orderInventories in Release Goods
|
|
714
|
+
* @param product
|
|
715
|
+
* @param orderInventory
|
|
716
|
+
* @param packingType
|
|
717
|
+
* @param locationSortingRules
|
|
718
|
+
* @param customerBizplace
|
|
719
|
+
* @param domain
|
|
720
|
+
* @param trxMgr
|
|
721
|
+
* @returns orderInventories
|
|
722
|
+
*/
|
|
723
|
+
async autoAssignInventoryForRelease(orderInventory, product, productDetail, locationSortingRules = [], customerBizplace, domain, trxMgr, batchId, preferLocation = null, recall = null, cartonId, expirationDate) {
|
|
724
|
+
let strictProduct = 'false';
|
|
725
|
+
if (!(customerBizplace === null || customerBizplace === void 0 ? void 0 : customerBizplace.domain)) {
|
|
726
|
+
let bizplace = await trxMgr.getRepository(biz_base_1.Bizplace).findOne({
|
|
727
|
+
where: { id: customerBizplace.id },
|
|
728
|
+
relations: ['domain']
|
|
729
|
+
});
|
|
730
|
+
customerBizplace.domain = bizplace.domain;
|
|
731
|
+
}
|
|
732
|
+
const strictProductSelectionSetting = await trxMgr.getRepository(setting_base_1.Setting).findOne({
|
|
733
|
+
where: { domain, category: 'id-rule', name: 'strict-product-selection' }
|
|
734
|
+
});
|
|
735
|
+
if (strictProductSelectionSetting)
|
|
736
|
+
strictProduct = strictProductSelectionSetting.value;
|
|
737
|
+
const partnerStrictProductSelectionSetting = await trxMgr.getRepository(setting_base_1.PartnerSetting).findOne({
|
|
738
|
+
where: { setting: strictProductSelectionSetting, domain, partnerDomain: customerBizplace === null || customerBizplace === void 0 ? void 0 : customerBizplace.domain }
|
|
739
|
+
});
|
|
740
|
+
if (partnerStrictProductSelectionSetting)
|
|
741
|
+
strictProduct = partnerStrictProductSelectionSetting.value;
|
|
742
|
+
let locationTypes = [warehouse_base_1.LOCATION_TYPE.QUARANTINE, warehouse_base_1.LOCATION_TYPE.RESERVE];
|
|
743
|
+
if (recall === false) {
|
|
744
|
+
locationTypes.push(warehouse_base_1.LOCATION_TYPE.DAMAGE);
|
|
745
|
+
}
|
|
746
|
+
let qb = trxMgr.getRepository(warehouse_base_1.Inventory).createQueryBuilder('iv');
|
|
747
|
+
qb.innerJoinAndSelect('iv.location', 'loc')
|
|
748
|
+
.innerJoin('warehouse_inventory_assignment_rankings', 'wiar', '"wiar"."location_type" = "loc"."type"')
|
|
749
|
+
.innerJoin('iv.product', 'p')
|
|
750
|
+
.andWhere('"iv"."domain_id" = :domainId')
|
|
751
|
+
.andWhere('"iv"."bizplace_id" = :bizplaceId')
|
|
752
|
+
.andWhere('"iv"."status" = :status')
|
|
753
|
+
.andWhere('"iv"."qty" - COALESCE("iv"."locked_qty", 0) > 0')
|
|
754
|
+
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
755
|
+
.andWhere('"iv"."obsolete" = false')
|
|
756
|
+
.andWhere('"iv"."transfer_qty" <= 0')
|
|
757
|
+
.andWhere('"iv"."transfer_uom_value" <= 0')
|
|
758
|
+
.andWhere('"iv"."product_id" = :productId')
|
|
759
|
+
.andWhere('case when "iv"."expiration_date" is not null and "p"."min_outbound_shelf_life" is not null then CURRENT_DATE < "iv"."expiration_date" - "p"."min_outbound_shelf_life" else true end')
|
|
760
|
+
.setParameters({
|
|
761
|
+
domainId: domain.id,
|
|
762
|
+
bizplaceId: customerBizplace.id,
|
|
763
|
+
productId: product.id,
|
|
764
|
+
status: warehouse_base_1.INVENTORY_STATUS.STORED,
|
|
765
|
+
locationTypes
|
|
766
|
+
});
|
|
767
|
+
if (batchId) {
|
|
768
|
+
qb.andWhere('"iv"."batch_id" = :batchId', { batchId });
|
|
769
|
+
}
|
|
770
|
+
if (cartonId) {
|
|
771
|
+
qb.andWhere('"iv"."carton_id" = :cartonId', { cartonId });
|
|
772
|
+
}
|
|
773
|
+
if (expirationDate) {
|
|
774
|
+
qb.andWhere('"iv"."expiration_date" = :expirationDate', { expirationDate });
|
|
775
|
+
}
|
|
776
|
+
if (preferLocation) {
|
|
777
|
+
qb.andWhere('"loc"."type" = :preferLocation', { preferLocation });
|
|
778
|
+
}
|
|
779
|
+
if (strictProduct == 'true' || preferLocation == 'STORAGE') {
|
|
780
|
+
qb.andWhere('"iv"."product_detail_id" = :productDetailId', { productDetailId: productDetail.id });
|
|
781
|
+
}
|
|
782
|
+
else {
|
|
783
|
+
qb.andWhere('"iv"."packing_type" = :packingType', { packingType: orderInventory.packingType })
|
|
784
|
+
.andWhere('"iv"."packing_size" = :packingSize', { packingSize: orderInventory.packingSize })
|
|
785
|
+
.andWhere('"iv"."uom" = :uom', { uom: orderInventory.uom });
|
|
786
|
+
}
|
|
787
|
+
let locationSorting = function (qb, locationSortingRules) {
|
|
788
|
+
if (locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) {
|
|
789
|
+
locationSortingRules.forEach((rule, idx) => {
|
|
790
|
+
idx === 0
|
|
791
|
+
? qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
|
|
792
|
+
: qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
else {
|
|
796
|
+
qb.addOrderBy('"loc"."name"', 'ASC');
|
|
797
|
+
qb.addOrderBy('"iv"."created_at"', 'ASC');
|
|
798
|
+
}
|
|
799
|
+
return qb;
|
|
800
|
+
};
|
|
801
|
+
qb.addOrderBy('"wiar"."rank"', 'ASC');
|
|
802
|
+
switch (product === null || product === void 0 ? void 0 : product.pickingStrategy) {
|
|
803
|
+
case 'FIFO':
|
|
804
|
+
qb.addOrderBy('"iv"."created_at"', 'ASC');
|
|
805
|
+
qb = locationSorting(qb, locationSortingRules);
|
|
806
|
+
break;
|
|
807
|
+
case 'LIFO':
|
|
808
|
+
qb.addOrderBy('"iv"."created_at"', 'DESC');
|
|
809
|
+
qb = locationSorting(qb, locationSortingRules);
|
|
810
|
+
break;
|
|
811
|
+
case 'FEFO':
|
|
812
|
+
qb.addOrderBy('"iv"."expiration_date"', 'ASC');
|
|
813
|
+
qb.addOrderBy('"iv"."created_at"', 'ASC');
|
|
814
|
+
qb = locationSorting(qb, locationSortingRules);
|
|
815
|
+
break;
|
|
816
|
+
case 'FMFO':
|
|
817
|
+
qb.addOrderBy('"iv"."manufacture_date"', 'ASC');
|
|
818
|
+
qb.addOrderBy('"iv"."created_at"', 'ASC');
|
|
819
|
+
qb = locationSorting(qb, locationSortingRules);
|
|
820
|
+
break;
|
|
821
|
+
case 'LOCATION':
|
|
822
|
+
qb = locationSorting(qb, locationSortingRules);
|
|
823
|
+
break;
|
|
824
|
+
default:
|
|
825
|
+
qb.addOrderBy('"iv"."created_at"', 'ASC');
|
|
826
|
+
qb = locationSorting(qb, locationSortingRules);
|
|
827
|
+
break;
|
|
828
|
+
}
|
|
829
|
+
let inventories = await qb.getMany();
|
|
830
|
+
if (!(inventories === null || inventories === void 0 ? void 0 : inventories.length))
|
|
831
|
+
throw new Error(`no inventories found for ${product.sku}`);
|
|
832
|
+
inventories = inventories.map(inventory => {
|
|
833
|
+
return Object.assign(Object.assign({}, inventory), { remainQty: inventory.qty - ((inventory === null || inventory === void 0 ? void 0 : inventory.lockedQty) || 0), remainUomValue: inventory.uomValue - ((inventory === null || inventory === void 0 ? void 0 : inventory.lockedUomValue) || 0) });
|
|
834
|
+
});
|
|
835
|
+
return _composeTargetInventories(product, productDetail, orderInventory, inventories);
|
|
836
|
+
},
|
|
837
|
+
/**
|
|
838
|
+
* @summary Do transaction on inventory record
|
|
839
|
+
* @description It will update inventory after set a temp (domain, updater)
|
|
840
|
+
* and then generate inventory history based on current changes
|
|
841
|
+
*/
|
|
842
|
+
async transactionInventory(inventory, referenceOrder, changedQty, changedWeight, transactionType, user, trxMgr) {
|
|
843
|
+
if (inventory.id) {
|
|
844
|
+
inventory = await updateInventory(inventory, trxMgr);
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
inventory = await createInventory(inventory, trxMgr);
|
|
848
|
+
}
|
|
849
|
+
await (0, warehouse_base_1.generateInventoryHistory)(inventory, referenceOrder, transactionType, changedQty, changedWeight, user, trxMgr);
|
|
850
|
+
return inventory;
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
async function getConditions(bizplaces, filters, trxMgr, hasRemainingQty = true) {
|
|
854
|
+
var _a;
|
|
855
|
+
let bizplaceIds = bizplaces.map((bizplace) => `'${bizplace.id}'`).join();
|
|
856
|
+
let productWhereClause = `
|
|
857
|
+
AND i.status = 'STORED'
|
|
858
|
+
AND i.bizplace_id IN (${bizplaceIds})
|
|
859
|
+
`;
|
|
860
|
+
let apiWhereClause = `
|
|
861
|
+
AND i.bizplace_id IN (${bizplaceIds})
|
|
862
|
+
`;
|
|
863
|
+
let bundleWhereClause = `
|
|
864
|
+
WHERE pb.status = 'ACTIVATED'
|
|
865
|
+
`;
|
|
866
|
+
// Find the showAllInventory filter
|
|
867
|
+
const showAllInventoryFilter = filters.find(filter => filter.name === 'showAllInventory');
|
|
868
|
+
const showAllInventory = showAllInventoryFilter ? showAllInventoryFilter.value : false;
|
|
869
|
+
// Set the whereClause based on the showAllInventory value
|
|
870
|
+
let whereClause = showAllInventory ? ` WHERE 1 = 1 ` : hasRemainingQty ? ` WHERE "remainQty" > 0 ` : ` WHERE 1 = 1 `;
|
|
871
|
+
let productDetailWhereClause = ``;
|
|
872
|
+
let batchBundle;
|
|
873
|
+
if (filters === null || filters === void 0 ? void 0 : filters.length) {
|
|
874
|
+
await Promise.all(filters.map(async (filter) => {
|
|
875
|
+
const name = filter.name;
|
|
876
|
+
const operator = filter.operator.toLowerCase();
|
|
877
|
+
let value = filter.value;
|
|
878
|
+
let flatValue;
|
|
879
|
+
switch (name) {
|
|
880
|
+
case 'productId':
|
|
881
|
+
if (operator == 'in')
|
|
882
|
+
flatValue = value.flat();
|
|
883
|
+
whereClause += `AND "productId" ${operator === 'in' ? 'IN' : 'NOT IN'} (${flatValue
|
|
884
|
+
.map(itm => {
|
|
885
|
+
return `'${itm}'`;
|
|
886
|
+
})
|
|
887
|
+
.join(',')})`;
|
|
888
|
+
break;
|
|
889
|
+
case 'productBundleId':
|
|
890
|
+
if (operator == 'in')
|
|
891
|
+
whereClause += `AND "productId" ${operator === 'in' ? 'IN' : 'NOT IN'} (${value
|
|
892
|
+
.map(itm => {
|
|
893
|
+
return `'${itm}'`;
|
|
894
|
+
})
|
|
895
|
+
.join(',')})`;
|
|
896
|
+
break;
|
|
897
|
+
case 'batchId':
|
|
898
|
+
let batchId = `${value}`;
|
|
899
|
+
whereClause += `AND LOWER("batchId") LIKE '${batchId.replace(`'`, `''`).toLowerCase()}'`;
|
|
900
|
+
break;
|
|
901
|
+
case 'batchIdRef':
|
|
902
|
+
whereClause += `AND LOWER("batchIdRef") LIKE '${value.toLowerCase()}'`;
|
|
903
|
+
break;
|
|
904
|
+
case 'productBrand':
|
|
905
|
+
whereClause += `AND LOWER("productBrand") LIKE '${value.toLowerCase()}'`;
|
|
906
|
+
break;
|
|
907
|
+
case 'productSKU':
|
|
908
|
+
whereClause += `AND LOWER("productSKU") LIKE '${value.toLowerCase()}'`;
|
|
909
|
+
case 'productName':
|
|
910
|
+
const products = await trxMgr.getRepository(product_base_1.Product).find({
|
|
911
|
+
select: ['id'],
|
|
912
|
+
where: [
|
|
913
|
+
{
|
|
914
|
+
bizplace: (0, typeorm_1.In)(bizplaces.map((bizplace) => bizplace.id)),
|
|
915
|
+
name: (0, typeorm_1.Raw)((alias) => `LOWER(${alias}) LIKE '${value.toLowerCase().trim().replace(/'/g, "''")}'`)
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
bizplace: (0, typeorm_1.In)(bizplaces.map((bizplace) => bizplace.id)),
|
|
919
|
+
sku: (0, typeorm_1.Raw)((alias) => `LOWER(${alias}) LIKE '${value.toLowerCase().trim().replace(/'/g, "''")}'`)
|
|
920
|
+
},
|
|
921
|
+
{
|
|
922
|
+
bizplace: (0, typeorm_1.In)(bizplaces.map((bizplace) => bizplace.id)),
|
|
923
|
+
description: (0, typeorm_1.Raw)((alias) => `LOWER(${alias}) LIKE '${value.toLowerCase().trim().replace(/'/g, "''")}'`)
|
|
924
|
+
}
|
|
925
|
+
]
|
|
926
|
+
});
|
|
927
|
+
const productIds = products
|
|
928
|
+
.map((product) => product.id)
|
|
929
|
+
.map((id) => `'${id}'`)
|
|
930
|
+
.join();
|
|
931
|
+
if (productIds.length) {
|
|
932
|
+
productWhereClause += `AND i.product_id IN (${productIds})`;
|
|
933
|
+
}
|
|
934
|
+
else {
|
|
935
|
+
productWhereClause += `AND i.product_id ISNULL`;
|
|
936
|
+
}
|
|
937
|
+
// filter product bundle as product info
|
|
938
|
+
const productBundles = await trxMgr.getRepository(product_base_1.ProductBundle).find({
|
|
939
|
+
select: ['id'],
|
|
940
|
+
where: [
|
|
941
|
+
{
|
|
942
|
+
bizplace: (0, typeorm_1.In)(bizplaces.map((bizplace) => bizplace.id)),
|
|
943
|
+
name: (0, typeorm_1.Raw)((alias) => `LOWER(${alias}) LIKE '${value.toLowerCase().trim().replace(/'/g, "''")}'`)
|
|
944
|
+
},
|
|
945
|
+
{
|
|
946
|
+
bizplace: (0, typeorm_1.In)(bizplaces.map((bizplace) => bizplace.id)),
|
|
947
|
+
sku: (0, typeorm_1.Raw)((alias) => `LOWER(${alias}) LIKE '${value.toLowerCase().trim().replace(/'/g, "''")}'`)
|
|
948
|
+
},
|
|
949
|
+
{
|
|
950
|
+
bizplace: (0, typeorm_1.In)(bizplaces.map((bizplace) => bizplace.id)),
|
|
951
|
+
description: (0, typeorm_1.Raw)((alias) => `LOWER(${alias}) LIKE '${value.toLowerCase().trim().replace(/'/g, "''")}'`)
|
|
952
|
+
}
|
|
953
|
+
]
|
|
954
|
+
});
|
|
955
|
+
const productBundleIds = productBundles
|
|
956
|
+
.map((bundle) => bundle.id)
|
|
957
|
+
.map((id) => `'${id}'`)
|
|
958
|
+
.join();
|
|
959
|
+
if (productBundleIds.length) {
|
|
960
|
+
bundleWhereClause += `AND pb.id IN (${productBundleIds})`;
|
|
961
|
+
}
|
|
962
|
+
else {
|
|
963
|
+
bundleWhereClause += `AND pb.id ISNULL`;
|
|
964
|
+
}
|
|
965
|
+
break;
|
|
966
|
+
case 'packingType':
|
|
967
|
+
whereClause += `AND LOWER("packingType") LIKE '${value.toLowerCase()}'`;
|
|
968
|
+
break;
|
|
969
|
+
case 'showBundle':
|
|
970
|
+
whereClause += `AND LOWER("groupType") LIKE 'bundle'`;
|
|
971
|
+
break;
|
|
972
|
+
case 'hideBundle':
|
|
973
|
+
whereClause += `AND LOWER("groupType") LIKE 'single'`;
|
|
974
|
+
break;
|
|
975
|
+
case 'batch_product':
|
|
976
|
+
productWhereClause += `
|
|
977
|
+
AND (i.batch_id, p.id, i.packing_type, i.packing_size) ${operator === 'in' ? 'IN' : 'NOT IN'} (${value
|
|
978
|
+
.map((v) => `('${v.batchId.replace(`'`, `''`)}', '${v.productId}', '${v.packingType}', '${v.packingSize}')`)
|
|
979
|
+
.join()})
|
|
980
|
+
`;
|
|
981
|
+
break;
|
|
982
|
+
case 'batch_bundle':
|
|
983
|
+
bundleWhereClause += `
|
|
984
|
+
${bundleWhereClause == '' ? 'WHERE' : 'AND'} pb.id ${operator === 'in' ? 'IN' : 'NOT IN'} (${value
|
|
985
|
+
.map((v) => `('${v.productId}')`)
|
|
986
|
+
.join()})
|
|
987
|
+
`;
|
|
988
|
+
break;
|
|
989
|
+
case 'product':
|
|
990
|
+
productDetailWhereClause += `
|
|
991
|
+
AND (pd.product_id, pd.packing_type, pd.packing_size, pd.uom) ${operator === 'in' ? 'IN' : 'NOT IN'} (${value
|
|
992
|
+
.map((v) => `('${v.productId}', '${v.packingType}', '${v.packingSize}', '${v.uom}')`)
|
|
993
|
+
.join()})
|
|
994
|
+
`;
|
|
995
|
+
break;
|
|
996
|
+
}
|
|
997
|
+
}));
|
|
998
|
+
batchBundle = JSON.stringify(((_a = filters
|
|
999
|
+
.find(filter => filter.name === 'batch_bundle')) === null || _a === void 0 ? void 0 : _a.value.map(itm => {
|
|
1000
|
+
return {
|
|
1001
|
+
product_id: itm.productId,
|
|
1002
|
+
release_qty: (itm === null || itm === void 0 ? void 0 : itm.releaseQty) || 0,
|
|
1003
|
+
release_uom_value: (itm === null || itm === void 0 ? void 0 : itm.releaseUomValue) || 0
|
|
1004
|
+
};
|
|
1005
|
+
})) || []);
|
|
1006
|
+
}
|
|
1007
|
+
return {
|
|
1008
|
+
bizplaceIds,
|
|
1009
|
+
productWhereClause,
|
|
1010
|
+
apiWhereClause,
|
|
1011
|
+
bundleWhereClause,
|
|
1012
|
+
whereClause,
|
|
1013
|
+
batchBundle,
|
|
1014
|
+
productDetailWhereClause
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
async function createInventory(inventory, trxMgr) {
|
|
1018
|
+
return await trxMgr.getRepository(warehouse_base_1.Inventory).save(inventory);
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* @summary Update inventory record
|
|
1022
|
+
* @description It will update inventory after set a stamp (domain, updater)
|
|
1023
|
+
* The special point of this function is that this changes won't generate inventory history
|
|
1024
|
+
* If you want to generate inventory history automatically you would better to use transactionInventory function
|
|
1025
|
+
*/
|
|
1026
|
+
async function updateInventory(inventory, trxMgr) {
|
|
1027
|
+
if (!inventory.id)
|
|
1028
|
+
throw new Error(`Target doesn't have ID`);
|
|
1029
|
+
return await trxMgr.getRepository(warehouse_base_1.Inventory).save(inventory);
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* @description: Check location emptiness and update status of location
|
|
1033
|
+
* @param domain
|
|
1034
|
+
* @param location
|
|
1035
|
+
* @param updater
|
|
1036
|
+
* @param trxMgr
|
|
1037
|
+
*/
|
|
1038
|
+
async function switchLocationStatus(domain, location, updater, trxMgr) {
|
|
1039
|
+
const invRepo = (trxMgr === null || trxMgr === void 0 ? void 0 : trxMgr.getRepository(warehouse_base_1.Inventory)) || (0, typeorm_1.getRepository)(warehouse_base_1.Inventory);
|
|
1040
|
+
const locationRepo = (trxMgr === null || trxMgr === void 0 ? void 0 : trxMgr.getRepository(warehouse_base_1.Location)) || (0, typeorm_1.getRepository)(warehouse_base_1.Location);
|
|
1041
|
+
const allocatedItemsCnt = await invRepo.count({
|
|
1042
|
+
domain,
|
|
1043
|
+
status: warehouse_base_1.INVENTORY_STATUS.STORED,
|
|
1044
|
+
location
|
|
1045
|
+
});
|
|
1046
|
+
if (!allocatedItemsCnt && location.status !== warehouse_base_1.LOCATION_STATUS.EMPTY) {
|
|
1047
|
+
location = await locationRepo.save(Object.assign(Object.assign({}, location), { status: warehouse_base_1.LOCATION_STATUS.EMPTY, updater }));
|
|
1048
|
+
}
|
|
1049
|
+
else if (allocatedItemsCnt && location.status === warehouse_base_1.LOCATION_STATUS.EMPTY) {
|
|
1050
|
+
location = await locationRepo.save(Object.assign(Object.assign({}, location), { status: warehouse_base_1.LOCATION_STATUS.OCCUPIED, updater }));
|
|
1051
|
+
}
|
|
1052
|
+
return location;
|
|
1053
|
+
}
|
|
1054
|
+
exports.switchLocationStatus = switchLocationStatus;
|
|
1055
|
+
function _composeTargetInventories(product, productDetail, record, inventories) {
|
|
1056
|
+
let leftReleaseQty = record.releaseQty;
|
|
1057
|
+
let leftReleaseUomValue = record.releaseUomValue;
|
|
1058
|
+
let compReleaseQty = 0;
|
|
1059
|
+
let compReleaseUomValue = 0;
|
|
1060
|
+
let totalInventoryQty = inventories.reduce((total, inventory) => total + inventory.remainQty, 0);
|
|
1061
|
+
if (!product)
|
|
1062
|
+
product = productDetail.product;
|
|
1063
|
+
if (totalInventoryQty < record.releaseQty) {
|
|
1064
|
+
throw new Error(`invalid release qty for ${product === null || product === void 0 ? void 0 : product.sku}`);
|
|
1065
|
+
}
|
|
1066
|
+
let orderInventories = [];
|
|
1067
|
+
let idx = 0;
|
|
1068
|
+
while (compReleaseQty < record.releaseQty) {
|
|
1069
|
+
const inventory = inventories[idx];
|
|
1070
|
+
const { packingType, packingSize, batchId, batchIdRef, uom } = inventory;
|
|
1071
|
+
let orderInventory = new service_1.OrderInventory();
|
|
1072
|
+
if (inventory.remainQty > leftReleaseQty) {
|
|
1073
|
+
const uomValuePerQty = Math.round((inventory.remainUomValue / inventory.remainQty) * 1000) / 1000;
|
|
1074
|
+
compReleaseQty += leftReleaseQty;
|
|
1075
|
+
compReleaseUomValue += leftReleaseUomValue;
|
|
1076
|
+
orderInventory = Object.assign(Object.assign({}, orderInventory), { releaseQty: leftReleaseQty, releaseUomValue: Math.round(leftReleaseQty * uomValuePerQty * 1000) / 1000 });
|
|
1077
|
+
}
|
|
1078
|
+
else {
|
|
1079
|
+
compReleaseQty += inventory.remainQty;
|
|
1080
|
+
compReleaseUomValue += inventory.remainUomValue;
|
|
1081
|
+
leftReleaseQty -= inventory.remainQty;
|
|
1082
|
+
leftReleaseUomValue -= inventory.remainUomValue;
|
|
1083
|
+
orderInventory = Object.assign(Object.assign({}, orderInventory), { releaseQty: inventory.remainQty, releaseUomValue: inventory.remainUomValue });
|
|
1084
|
+
}
|
|
1085
|
+
orderInventories.push(Object.assign(Object.assign(Object.assign({}, record), orderInventory), { inventory,
|
|
1086
|
+
packingType,
|
|
1087
|
+
packingSize,
|
|
1088
|
+
batchId,
|
|
1089
|
+
batchIdRef,
|
|
1090
|
+
uom,
|
|
1091
|
+
product,
|
|
1092
|
+
productDetail, type: constants_1.ORDER_TYPES.RELEASE_OF_GOODS }));
|
|
1093
|
+
idx++;
|
|
1094
|
+
}
|
|
1095
|
+
return orderInventories;
|
|
1096
|
+
}
|
|
1097
|
+
exports._composeTargetInventories = _composeTargetInventories;
|
|
1098
|
+
//# sourceMappingURL=inventory-util.js.map
|