{"version":3,"file":"new-0QHfwagj.js","sources":["../../../app/frontend/entrypoints/controllers/erp/product/overview/new.ts"],"sourcesContent":["\nimport * as bootstrap from 'bootstrap'\nimport Utils from '../../../../utils'\nimport DefaultController from \"../../../defaultController\";\nimport ErpProductEntity from \"../entity\";\nimport ErpProductGeneral from \"./show/general\";\nexport default class ErpProductNew extends DefaultController {\n async init() {\n this.entity = \"erp/products\"\n this.childs = {\n general: new ErpProductGeneral(this)\n }\n await super.init();\n await this.setCurrency();\n }\n\n protected getEntityData(elem: any) {\n return ErpProductEntity.getEntityData(elem)\n }\n async setCurrency() {\n const r = await Utils.entity.getAll(\"erp/currencies\")\n if (r.status === 200) {\n r.data.forEach((currency: any) => {\n if(currency.isoCode === \"EUR\") {\n (document.querySelector(\"#erpProductAddForm #erp_product_purchasing_price_currencyId\") as HTMLInputElement).value = currency.id;\n (document.querySelector(\"#erpProductAddForm #erp_product_price_currencyId\") as HTMLInputElement).value = currency.id;\n }\n })\n }\n }\n\n bindListeners() {\n\n (document.querySelector(\"#erpProductAddForm\") as HTMLFormElement).addEventListener(\"submit\", async (e) => {\n e.preventDefault();\n const form = document.querySelector(\"#erpProductAddForm\") as HTMLFormElement;\n\n const valid = form.checkValidity();\n if (valid) {\n await Utils.showLoader();\n const data = this.getEntityData(form)\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) => {\n return f.name === data.manufacturerName\n })[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\n }\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.saved')}`, `${Utils.translate('generic.success')}`)\n setTimeout(() => {\n document.location.href = `/${(window as any).currentLocale}/erp/products/${r.data[0].uuid}`\n }, 1000)\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 }\n}"],"names":[],"mappings":";;;;;;;;;AAMA,MAAqB,sBAAsB,kBAAkB;AAAA,EACzD,MAAM,OAAO;AACT,SAAK,SAAS;AACd,SAAK,SAAS;AAAA,MACV,SAAS,IAAI,kBAAkB,IAAI;AAAA,IAAA;AAEvC,UAAM,MAAM;AACZ,UAAM,KAAK;EACf;AAAA,EAEU,cAAc,MAAW;AACxB,WAAA,iBAAiB,cAAc,IAAI;AAAA,EAC9C;AAAA,EACA,MAAM,cAAc;AAChB,UAAM,IAAI,MAAM,MAAM,OAAO,OAAO,gBAAgB;AAChD,QAAA,EAAE,WAAW,KAAK;AAChB,QAAA,KAAK,QAAQ,CAAC,aAAkB;AAC3B,YAAA,SAAS,YAAY,OAAO;AAC1B,mBAAS,cAAc,6DAA6D,EAAuB,QAAQ,SAAS;AAC5H,mBAAS,cAAc,kDAAkD,EAAuB,QAAQ,SAAS;AAAA,QACtH;AAAA,MAAA,CACH;AAAA,IACL;AAAA,EACJ;AAAA,EAEA,gBAAgB;AAEX,aAAS,cAAc,oBAAoB,EAAsB,iBAAiB,UAAU,OAAO,MAAM;AACtG,QAAE,eAAe;AACX,YAAA,OAAO,SAAS,cAAc,oBAAoB;AAElD,YAAA,QAAQ,KAAK;AACnB,UAAI,OAAO;AACP,cAAM,MAAM;AACN,cAAA,OAAO,KAAK,cAAc,IAAI;AACpC,YAAI,KAAK,kBAAkB;AACvB,gBAAM,sBAAsB,MAAM,MAAM,OAAO,OAAO,2BAA2B;AACjF,gBAAM,gBAAgB,oBAAoB;AAC1C,cAAI,uBAAuB,cAAc,OAAO,CAAC,MAAW;AACjD,mBAAA,EAAE,SAAS,KAAK;AAAA,UA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