import{a as f}from"./chunk-HECH75A2.js";import{a as P}from"./chunk-KXX3UDJ3.js";import{j as m,z as l}from"./chunk-GQAU5ACB.js";import{Ea as h,S as d,la as c,pa as i,qa as u,x as n}from"./chunk-ISMRT7VU.js";var y=(()=>{class e{constructor(t){this._http=t}getAllPrescripts(t){return this._http.post("/api/prescript/all",t,{headers:P})}getPrescriptsById(t){return this._http.get(`/api/prescript/${t}`)}createPrescript(t){return this._http.post("/api/prescript",t)}editPrescript(t,r){return this._http.put(`/api/prescript/${t}`,r)}deletePrescript(t){return this._http.delete(`/api/prescript/${t}`)}static{this.\u0275fac=function(r){return new(r||e)(i(m))}}static{this.\u0275prov=c({token:e,factory:e.\u0275fac})}}return e})();var M=(()=>{class e{constructor(t,r){this._prescriptServiceApi=t,this._remainsService=r,this.destroyRef=u(h),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 s=this._migrateFormToRequestModel(r);return this._prescriptServiceApi.editPrescript(t,s)}getPrescriptById(t){return this._prescriptServiceApi.getPrescriptsById(t)}calculateTotalCost(t,r,s){let I={warehouseId:r,positions:t};return this._remainsService.getCalculatedProductsCost(I).pipe(l(this.destroyRef),n(v=>{let o=v.positions.reduce((p,a)=>p+=a.totalCost,0);return s.length&&(o+=s.reduce((p,a)=>p+=a.cost,0)),o}))}deletePrescript(t){return this._prescriptServiceApi.deletePrescript(t).pipe(d(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}}static{this.\u0275fac=function(r){return new(r||e)(i(y),i(f))}}static{this.\u0275prov=c({token:e,factory:e.\u0275fac})}}return e})();export{y as a,M as b};
//# sourceMappingURL=chunk-3L64GC5L.js.map
