import{a as y}from"./chunk-QKPMVUCD.js";import{a as P,b as I}from"./chunk-IGFM5CCE.js";import{a as f}from"./chunk-PLVHWZTL.js";import{i as m}from"./chunk-YMOV4UGM.js";import{K as l,ga as p,la as c,q as h}from"./chunk-I3FGJX2C.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:f})}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(m))},t.\u0275prov=p({token:t,factory:t.\u0275fac});let a=t;return a})();var i,v=(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(I(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(l(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??[],characteristics:null,isQuick:r.isQuick,isMarked:r.isMarked,defaultPrescriptId:t,produceInSell:!0}}_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(y))},i.\u0275prov=p({token:i,factory:i.\u0275fac}),i);v=u([P()],v);export{g as a,v as b};
//# sourceMappingURL=chunk-26XCDHWL.js.map
