{"version":3,"file":"warehouse_locations-1-wf6a0R.js","sources":["../../../app/frontend/entrypoints/controllers/erp/warehouse/overview/show/warehouse_locations.ts"],"sourcesContent":["import jQuery from 'jquery/dist/jquery';\nimport Swal from 'sweetalert2';\nimport * as bootstrap from 'bootstrap'\nimport Utils from '../../../../../utils'\nimport WarehouseLocationEntity from \"../../../warehouse_location/entity\";\nimport Configurator from \"./configurator\";\nimport UtilsEntity from \"../../../../../utils/entity\";\nexport default class WarehouseWarehouseLocationsOverview{\n private parent: any;\n private tableElem: any;\n private datatable: any;\n private entity = \"erp/warehouse_locations\";\n private toastr: any;\n private editModal: bootstrap.Modal;\n private newModal: bootstrap.Modal;\n private detailModal: bootstrap.Modal;\n private configurator: any;\n\n constructor(parent: any) {\n this.parent = parent\n this.toastr = parent.toastr\n this.tableElem = jQuery('.erp_warehouse_location')\n this.editModal = new bootstrap.Modal((document.querySelector(\"#editWarehouseLocation\") as HTMLElement));\n this.newModal = new bootstrap.Modal((document.querySelector(\"#newWarehouseLocation\") as HTMLElement));\n this.detailModal = new bootstrap.Modal((document.querySelector(\"#erpWarehouseLocationModal\") as HTMLElement));\n this.configurator = new Configurator()\n this.createTable();\n this.bindListeners();\n }\n\n getEntityData(elem: any) {\n return {...WarehouseLocationEntity.getEntityData(elem), warehouse_id: this.parent.id}\n }\n\n async getSubentities() {\n const r = await UtilsEntity.getAll(\"product_attributes\");\n if (r.status === 200) {\n return r.data.concat([{name: \"order_number\"}, {name: \"external_order_number\"}, {name: \"tracking_company\"}, {name: \"tracking_number\"}])\n } else {\n return {}\n }\n }\n bindListeners() {\n (document.querySelector(\"#erp_warehouse_location_bulk_add\") as HTMLButtonElement).addEventListener(\"click\", (e) => {\n e.preventDefault();\n this.configurator.onBulkAddWarehouseLocations();\n });\n\n\n (document.querySelector(\"#erp_warehouse_location_bulk_save\") as HTMLButtonElement).addEventListener(\"click\", async (e) => {\n e.preventDefault();\n await Utils.showLoader();\n await Utils.entity.upsert({\n names: this.configurator.bulkData.calculated\n }, this.entity.replace(\"erp/\", \"\"), this.parent.id, this.parent.entity)\n this.newModal.hide();\n await this.datatable.ajax.reload();\n await Utils.hideLoader();\n this.toastr.success(`${Utils.translate('erp.warehouse_location.names')} ${Utils.translate('generic.messages.created')}`, `${Utils.translate('generic.success')}`)\n });\n\n document.addEventListener('keyup', (e) => {\n const target = e.target as HTMLElement\n if (target && target.classList.contains(\"bulk_add\")) {\n this.configurator.onBulkChangeInput(e);\n }\n });\n document.addEventListener('click', (e) => {\n const target = e.target as HTMLElement\n if (target && target.classList.contains('bulk_remove')) {\n this.configurator.onRemoveBulkElement(e);\n }\n });\n document.addEventListener('change', (e) => {\n const target = e.target as HTMLElement\n if (target && target.classList.contains('bulk_selector')) {\n this.configurator.onBulkChangeSelector(e);\n }\n });\n\n jQuery('#warehouse_locations').delegate(\".warehouse_locations_open_new_dialog\", \"click\", async (e: any) => {\n console.log(\"this.configurator\", this.configurator)\n this.configurator.onOpenConfigratorDialog();\n });\n\n this.tableElem.delegate(\".delete-record\", \"click\", async (e: any) => {const confirm = await Swal.fire({\n title: 'Are you sure?',\n text: \"You won't be able to revert this!\",\n icon: 'warning',\n showCancelButton: true,\n confirmButtonText: 'Yes, delete it!',\n customClass: {\n confirmButton: 'btn btn-primary me-3',\n cancelButton: 'btn btn-label-secondary'\n },\n buttonsStyling: false\n })\n if(confirm.value === true) {\n e.preventDefault();\n const id = e.currentTarget.getAttribute(\"data-id\")\n const r = await Utils.entity.destroy(id, this.entity.replace(\"erp/\", \"\"), this.parent.id, this.parent.entity)\n if (r.status === 200) {\n this.toastr.success(`${Utils.translate('erp.warehouse_location.name')} ${Utils.translate('generic.deleted')}`, `${Utils.translate('generic.success')}`)\n } else {\n this.toastr.error(`${Utils.translate('erp.warehouse_location.name')} ${Utils.translate('generic.messages.not_deleted')}`, `${Utils.translate('generic.error')}`)\n }\n this.datatable.ajax.reload();\n }\n });\n\n this.tableElem.delegate(\".download-record\", \"click\", async (e: any) => {\n const id = e.currentTarget.getAttribute(\"data-id\")\n const requestData = await Utils.erp.downloadLabel(id, \"warehouseLocation\")\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 this.tableElem.delegate(\".edit-record\", \"click\", async (e: any) => {\n const id = e.currentTarget.getAttribute(\"data-id\")\n const requestData = await Utils.entity.get(id, this.entity.replace(\"erp/\", \"\"), this.parent.id, this.parent.entity)\n if (requestData.status === 200) {\n const data = requestData.data[0]\n const form = (document.querySelector(\"#editWarehouseLocationForm\") as HTMLFormElement);\n form.reset()\n Object.keys(data).forEach((key) => {\n const elem = form.querySelector(`#warehouse_location_${key}`) as HTMLInputElement | null\n if (elem && data[key]) {\n elem.value = data[key]\n }\n })\n this.editModal.show();\n }\n });\n this.tableElem.delegate(\".info-record\", \"click\", async (e: any) => {\n const id = e.currentTarget.getAttribute(\"data-id\")\n await Utils.showLoader();\n const r = await UtilsEntity.request(`/api/v1/erp/warehouse_location_product_mappings/by_warehouse_location_id`, 'POST', {\n warehouse_location_id: id,\n })\n const title = e.currentTarget?.getAttribute(\"data-title\")\n let html = '
Product | `\n html += `Serial | `\n subEntries.forEach((key: any) => {\n html += `${key.name} | `\n })\n html += `
---|---|---|
${d.product ? d.product.name : \"\"} | `;\n html += `${d.serial} | `\n\n subEntries.forEach((key: any) => {\n html += `${d.payload && d.payload[key.name] ? d.payload[key.name] : ''} | `\n })\n html += `