import{a as I}from"./chunk-4P5WKLUE.js";import{a as P,b as f}from"./chunk-VXSBHXCN.js";import{a as y}from"./chunk-JUPKAJPM.js";import{i as h}from"./chunk-Z2AWIQRI.js";import{L as d,ia as p,na as c,q as m}from"./chunk-C2QKZJOP.js";import{d as u,n as S}from"./chunk-INB5GR2I.js";S();var g=(()=>{let t=class t{constructor(e){this._http=e}getAllPrescripts(e){return this._http.post("/api/prescript/all",e,{headers:y})}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(h))},t.\u0275prov=p({token:t,factory:t.\u0275fac});let o=t;return o})();var i,A=(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),m(v=>{let l=v.positions.reduce((a,n)=>a+=n.totalCost,0);return e.length&&(l+=e.reduce((a,n)=>a+=n.cost,0)),l}))}deletePrescript(t){return this._prescriptServiceApi.deletePrescript(t).pipe(d(1))}_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(g),c(I))},i.\u0275prov=p({token:i,factory:i.\u0275fac}),i);A=u([P()],A);export{g as a,A as b};
//# sourceMappingURL=chunk-IB3EQHRW.js.map
