import{a as y}from"./chunk-YZQRUE7W.js";import{a as P,b as f}from"./chunk-KXDO3JYP.js";import{a as I}from"./chunk-7N232KV6.js";import{i as l}from"./chunk-NDLDFKR2.js";import{K as m,fa as p,ka as c,q as h}from"./chunk-PVUKHE45.js";import{d as u,n as S}from"./chunk-VD6R3735.js";S();var v=(()=>{let t=class t{constructor(e){this._http=e}getAllPrescripts(e){return this._http.post("/api/prescript/all",e,{headers:I})}getPrescriptsById(e){return this._http.get(`/api/prescript/${e}`)}createPrescript(e){return this._http.post("/api/prescript",e)}editPrescript(e,s){return this._http.put(`/api/prescript/${e}`,s)}deletePrescript(e){return this._http.delete(`/api/prescript/${e}`)}};t.\u0275fac=function(s){return new(s||t)(c(l))},t.\u0275prov=p({token:t,factory:t.\u0275fac});let a=t;return a})();var i,g=(i=class{constructor(t,r){this._prescriptServiceApi=t,this._remainsService=r,this.selectedPrescriptId=null,this.activeFilters={filter:{isActualVersion:!0},search:{name:void 0}}}getPrescripts(t){return this._prescriptServiceApi.getAllPrescripts(t)}searchPrescripts(t){let r={search:{name:t},filter:{isActualVersion:!0}};return this._prescriptServiceApi.getAllPrescripts({criteria:r,take:50,skip:0,orderBy:"id",isAscending:!1})}changeSelectedId(t){this.selectedPrescriptId=t}createPrescript(t){let r=this._migrateFormToRequestModel(t);return this._prescriptServiceApi.createPrescript(r)}editPrescript(t,r){let e=this._migrateFormToRequestModel(r);return this._prescriptServiceApi.editPrescript(t,e)}getPrescriptById(t){return this._prescriptServiceApi.getPrescriptsById(t)}calculateTotalCost(t,r,e){let s={warehouseId:r,positions:t};return this._remainsService.getCalculatedProductsCost(s).pipe(f(this),h(A=>{let d=A.positions.reduce((o,n)=>o+=n.totalCost,0);return e.length&&(d+=e.reduce((o,n)=>o+=n.cost,0)),d}))}deletePrescript(t){return this._prescriptServiceApi.deletePrescript(t).pipe(m(1))}toProductModelFromPrescript(t,r){return{name:r.name,article:r.article,barcode:[r.barcode,...r.additionalBarcodes],unitId:r.unit?.id??null,categoryId:r.category?.id??null,purchasePrice:r.purchasePrice,vatRate:r.vatRate,prices:r.prices??[],isQuick:r.isQuick,isMarked:r.isMarked,isVariative:!1,variations:[],defaultPrescriptId:t,produceInSell:!0,ntin:r.ntin}}_migrateFormToRequestModel(t){return{name:t.name,resultsWarehouseId:t.resultForm.warehouseId,componentsWarehouseId:t.componentsForm.warehouseId,results:[{nomenclatureId:t.resultForm.nomenclatureId,quantity:t.resultForm.quantity}],components:t.componentsForm.products.map(r=>({nomenclatureId:r.nomenclatureId,quantity:r.quantity})),costs:t.costs.filter(r=>r.name),comment:t.comment}}},i.\u0275fac=function(r){return new(r||i)(c(v),c(y))},i.\u0275prov=p({token:i,factory:i.\u0275fac}),i);g=u([P()],g);export{v as a,g as b};
//# sourceMappingURL=chunk-GB45TK5W.js.map
