{"version":3,"file":"show-Eb_Nbfvk.js","sources":["../../../app/frontend/entrypoints/controllers/erp/product/overview/show.ts"],"sourcesContent":["\nimport * as bootstrap from 'bootstrap'\nimport Utils from '../../../../utils'\nimport DefaultController from \"../../../defaultController\";\nimport ErpProductEntity from \"../entity\";\nimport ErpProductGeneral from \"./show/general\";\nimport ErpProductErp from \"./show/erp\";\nimport ErpProductStock from \"./show/stock\";\nimport ErpProductSupplier from \"./show/supplier\";\n\n\nexport default class ErpProductShow extends DefaultController {\n private dragElements: any[] = []\n private multiMoveModal: any;\n async init() {\n this.entity = \"erp/products\"\n this.multiMoveModal = bootstrap.Modal.getOrCreateInstance((document.querySelector(\"#erpProductMultiMoveModal\") as HTMLElement))\n this.childs = {\n general: new ErpProductGeneral(this),\n erp: new ErpProductErp(this),\n stock: new ErpProductStock(this),\n supplier: new ErpProductSupplier(this)\n }\n await super.init();\n }\n\n protected getEntityData(elem: any) {\n return ErpProductEntity.getEntityData(elem)\n }\n bindListeners() {\n window.addEventListener(\"dragstart\", (e) => {\n if (e.dataTransfer) {\n const target = e.target as HTMLElement\n e.dataTransfer.dropEffect = \"copy\";\n const customerId = target.getAttribute(\"data-customer-id\");\n const warehouseLocationId = target.getAttribute(\"data-warehouse-location-id\");\n const warehousePalletId = target.getAttribute(\"data-warehouse-location-pallet-id\");\n const serial = target.getAttribute(\"data-serial\")\n const title = serial && serial.length > 0 ? serial : target.getAttribute(\"data-title\")\n e.dataTransfer.setData(\"text/plain\",JSON.stringify({\n title, customerId, warehouseLocationId, warehousePalletId, serial\n }));\n }\n });\n (document.querySelector(\".dropzone\") as HTMLElement).addEventListener(\"dragover\", (e) => {\n e.preventDefault();\n if (e.dataTransfer) {\n e.dataTransfer.dropEffect = \"move\";\n }\n });\n (document.querySelector(\".dropzone\") as HTMLElement).addEventListener(\"drop\", (e) => {\n if (e.dataTransfer) {\n const data = JSON.parse(e.dataTransfer.getData(\"text/plain\"));\n let dragElements = JSON.parse(localStorage.getItem(\"tickware_erp_product_multi_move\") as string)\n if (!dragElements) {\n dragElements = {}\n }\n // @ts-ignore\n if (!dragElements[this.id]) {\n // @ts-ignore\n dragElements[this.id] = {\n name: `${this.data.name}, ${this.data.number}`,\n elements: []\n }\n }\n // @ts-ignore\n dragElements[this.id].elements.push(data)\n // @ts-ignore\n dragElements[this.id].elements = dragElements[this.id].elements.filter((value, index, self) =>\n index === self.findIndex((t) => (\n t.serial === value.serial && t.customerId === value.customerId && t.warehouseLocationId === value.warehouseLocationId && t.warehousePalletId === value.warehousePalletId\n ))\n )\n localStorage.setItem(\"tickware_erp_product_multi_move\", JSON.stringify(dragElements))\n this.generateDragTable()\n }\n });\n (document.querySelector(\"#erp_product_save\") as HTMLElement).addEventListener(\"click\", async (e) => {\n e.preventDefault();\n const parent = document.querySelector(\".row[data-entity-id]\");\n await Utils.showLoader();\n const data = this.getEntityData(parent)\n if (data.manufacturerName) {\n const manufacturersResult = await Utils.entity.getAll('erp/product_manufacturers')\n const manufacturers = manufacturersResult.data\n let existingManufacturer = manufacturers.filter((f: any) => {return f.name === data.manufacturerName})[0]\n if (!existingManufacturer) {\n existingManufacturer = await Utils.entity.upsert({\n id: null,\n name: data.manufacturerName\n }, 'erp/product_manufacturers')\n existingManufacturer = existingManufacturer.data\n }\n data.manufacturerId = existingManufacturer.id\n console.log(\"existingManufacturer\", existingManufacturer)\n\n }\n const r = await Utils.entity.upsert(data, this.entity)\n if (r.status === 200) {\n await this.getEntity()\n this.toastr.success(`${Utils.translate('erp.product.name')} ${Utils.translate('generic.saved')}`, `${Utils.translate('generic.success')}`)\n } else {\n const errors: any = [];\n r.data.errors.forEach((err: any) => {\n errors.push(`${Utils.translate(`erp.product.messages.${err.code}`)}`)\n })\n this.toastr.error(`${errors.join(\", \")}`, `${Utils.translate('generic.error')}`)\n await Utils.hideLoader();\n }\n });\n\n (document.querySelector(\"#erp_product_duplicate\") as HTMLElement).addEventListener(\"click\", async (e) => {\n e.preventDefault();\n const parent = document.querySelector(\".row[data-entity-id]\");\n await Utils.showLoader();\n const data = this.getEntityData(parent)\n if (data.manufacturerName) {\n const manufacturersResult = await Utils.entity.getAll('erp/product_manufacturers')\n const manufacturers = manufacturersResult.data\n let existingManufacturer = manufacturers.filter((f: any) => {return f.name === data.manufacturerName})[0]\n if (!existingManufacturer) {\n existingManufacturer = await Utils.entity.upsert({\n id: null,\n name: data.manufacturerName\n }, 'erp/product_manufacturers')\n existingManufacturer = existingManufacturer.data\n }\n data.manufacturerId = existingManufacturer.id\n console.log(\"existingManufacturer\", existingManufacturer)\n\n }\n await Utils.entity.upsert(data, this.entity)\n data.uuid = null;\n data.number = `${data.number}_1`\n const r = await Utils.entity.upsert(data, this.entity)\n if (r.status === 200) {\n this.toastr.success(`${Utils.translate('erp.product.name')} ${Utils.translate('generic.messages.duplicated')}`, `${Utils.translate('generic.success')}`)\n setTimeout(() => {\n document.location.href = `/${(window as any).currentLocale}/erp/products/${r.data[0].uuid}`\n }, 1000)\n }\n });\n\n (document.querySelector(\"#erp_product_print\") as HTMLButtonElement).addEventListener(\"click\", async (e: any) => {\n e.preventDefault();\n const requestData = await Utils.erp.downloadLabel(this.data.id, \"product\")\n if (requestData.status === 200) {\n const pdf = requestData.data.pdf\n const arrayBuffer = Utils.base64ToArrayBuffer(pdf);\n Utils.createAndDownloadBlobFile(arrayBuffer, 'labels');\n }\n });\n\n (document.querySelector(\"#erp_product_delete\") as HTMLElement).addEventListener(\"click\", async (e) => {\n e.preventDefault();\n const parent = document.querySelector(\".row[data-entity-id]\");\n await Utils.showLoader();\n const data = this.getEntityData(parent)\n\n const r = await Utils.entity.destroy(data.id, this.entity)\n if (r.status === 200) {\n\n this.toastr.success(`${Utils.translate('erp.product.name')} ${Utils.translate('generic.deleted')}`, `${Utils.translate('generic.success')}`)\n setTimeout(() => {\n window.history.back()\n }, 1000)\n }\n });\n jQuery(\"body\").delegate(\".delete_drop_row\", \"click\", (e: any) => {\n const data = JSON.parse(e.currentTarget.closest(\"tr\").getAttribute(\"data-data\"));\n const dragElements = JSON.parse(localStorage.getItem(\"tickware_erp_product_multi_move\") as string)\n const productId = e.currentTarget.getAttribute(\"data-product-id\");\n dragElements[productId].elements = dragElements[productId].elements.filter((e) => {\n if(e.warehousePalletId === data.warehousePalletId &&\n e.warehouseLocationId === data.warehouseLocationId &&\n e.customerId === data.customerId &&\n e.serial === data.serial) {\n return false\n } else {\n return true\n }\n })\n if (dragElements[productId].elements.length === 0) {\n delete dragElements[productId]\n }\n localStorage.setItem(\"tickware_erp_product_multi_move\", JSON.stringify(dragElements))\n this.generateDragTable()\n })\n jQuery(\"body\").delegate(\"#erp_product_process_action\", \"click\", (e: any) => {\n const dragElements = JSON.parse(localStorage.getItem(\"tickware_erp_product_multi_move\") as string)\n if(Object.keys(dragElements).length > 0) {\n this.multiMoveModal.show();\n }\n });\n\n (document.querySelector(\"#erp_product_multi_move_form\") as HTMLFormElement).addEventListener(\"submit\", async (e) => {\n e.preventDefault();\n console.log(\"save\")\n const warehouseId = (document.querySelector(\"#erp_product_multi_move_warehouse_id option:checked\") as HTMLSelectElement)?.value;\n const warehouseLocationId = (document.querySelector(\"#erp_product_multi_move_warehouse_location_id option:checked\") as HTMLSelectElement)?.value\n const warehousePalletId = (document.querySelector(\"#erp_product_multi_move_warehouse_location_pallet_id option:checked\") as HTMLSelectElement)?.value\n const customerId = (document.querySelector(\"#erp_product_multi_move_customer_id option:checked\") as HTMLSelectElement)?.value\n Utils.showLoader()\n const dragElements = JSON.parse(localStorage.getItem(\"tickware_erp_product_multi_move\") as string)\n // @ts-ignore\n for (const productId of Object.keys(dragElements)) {\n const dragElement = dragElements[productId]\n await Utils.erp.multiMove(productId, dragElement.elements, warehouseId, warehouseLocationId, warehousePalletId, customerId)\n }\n await this.getEntity()\n this.multiMoveModal.hide()\n localStorage.setItem(\"tickware_erp_product_multi_move\", \"{}\")\n this.generateDragTable()\n Utils.hideLoader()\n });\n\n jQuery(\"#erp_product_multi_move_warehouse_location_id\").on(\"select2:select\", (e: any) => {\n (document.querySelector(\"#erp_product_multi_move_warehouse_location_pallet_id\") as HTMLSelectElement).disabled = false\n });\n }\n onSelectGetFilterOptions(elem: any) {\n if (elem.getAttribute(\"id\") === \"erp_product_multi_move_warehouse_location_id\") {\n return {\n warehouse_id: (document.querySelector(\"#erp_product_multi_move_warehouse_id option:checked\") as HTMLSelectElement)?.value\n }\n } else if (elem.getAttribute(\"id\") === \"erp_product_multi_move_warehouse_location_pallet_id\") {\n return {\n warehouse_location_id: (document.querySelector(\"#erp_product_multi_move_warehouse_location_id option:checked\") as HTMLSelectElement)?.value\n }\n }\n return {}\n }\n\n generateDragTable() {\n let html = \"\"\n const dragElements = JSON.parse(localStorage.getItem(\"tickware_erp_product_multi_move\") as string)\n if (dragElements && Object.keys(dragElements).length > 0) {\n for (const productId of Object.keys(dragElements)) {\n const dragElement = dragElements[productId]\n html += `${dragElement.name}`\n html += '
${elem.title} |