bettertend/frontend/dist/assets/parts-B3aeW8xP.js

2 lines
12 KiB
JavaScript

import{bc as h,aO as u,be as y}from"./index-BUdRbiwj.js";class g extends h{constructor(){super("/inventory")}async getStockAlerts(t={}){return this.get("/alerts",{params:t})}async createStockAlert(t){return this.post("/alerts",t)}async acknowledgeAlert(t,r){return this.post(`/alerts/${t}/acknowledge`,r)}async resolveAlert(t,r){return this.post(`/alerts/${t}/resolve`,r)}async getAlertStatistics(t={}){return this.get("/alerts/statistics",{params:t})}async getStockAdjustments(t={}){return this.get("/adjustments",{params:t})}async createStockAdjustment(t){return this.post("/adjustments",t)}async approveStockAdjustment(t,r){return this.post(`/adjustments/${t}/approve`,r)}async getAdjustmentHistory(t,r={}){return this.get(`/adjustments/part/${t}/history`,{params:r})}async getInventoryTransfers(t={}){return this.get("/transfers",{params:t})}async getTransferById(t){return this.get(`/transfers/${t}`)}async createInventoryTransfer(t){return this.post("/transfers",t)}async updateTransfer(t,r){return this.put(`/transfers/${t}`,r)}async approveTransfer(t,r){return this.post(`/transfers/${t}/approve`,r)}async cancelTransfer(t,r){return this.post(`/transfers/${t}/cancel`,{reason:r})}async shipTransfer(t,r){return this.post(`/transfers/${t}/ship`,r)}async receiveTransfer(t,r){return this.post(`/transfers/${t}/receive`,r)}async getReorderPointConfigs(t={}){return this.get("/reorder-points",{params:t})}async createReorderPointConfig(t){return this.post("/reorder-points",t)}async updateReorderPointConfig(t,r){return this.put(`/reorder-points/${t}`,r)}async deleteReorderPointConfig(t){return this.delete(`/reorder-points/${t}`)}async calculateReorderPoints(t){return this.post("/reorder-points/calculate",t)}async getStockLevelsByLocation(t,r={}){return this.get(`/stock-levels/location/${t}`,{params:r})}async getStockLevelsByPart(t,r={}){return this.get(`/stock-levels/part/${t}`,{params:r})}async updateStockLevel(t,r,s){return this.put(`/stock-levels/part/${t}/location/${r}`,s)}async getStockMovementHistory(t,r={}){return this.get(`/stock-levels/part/${t}/movements`,{params:r})}async getInventoryValuation(t={}){return this.get("/valuation",{params:t})}async updatePartCosting(t,r){return this.put(`/valuation/part/${t}/costing`,r)}async recalculateInventoryCosts(t){return this.post("/valuation/recalculate",t)}async getStockReconciliations(t={}){return this.get("/reconciliation",{params:t})}async getReconciliationById(t){return this.get(`/reconciliation/${t}`)}async createStockReconciliation(t){return this.post("/reconciliation",t)}async startReconciliation(t){return this.post(`/reconciliation/${t}/start`,{})}async completeReconciliation(t,r){return this.post(`/reconciliation/${t}/complete`,r)}async recordReconciliationDiscrepancy(t,r){return this.post(`/reconciliation/${t}/discrepancies`,r)}async getInventoryAnalytics(t={}){return this.get("/analytics",{params:t})}async getABCAnalysis(t={}){return this.get("/analytics/abc",{params:t})}async getUsageForecast(t,r={}){return this.get(`/analytics/forecast/part/${t}`,{params:r})}async getInventoryTurnover(t={}){return this.get("/analytics/turnover",{params:t})}async generateInventoryReport(t,r={}){return this.post(`/reports/${t}`,r)}async exportInventoryData(t){return this.request("/export","POST",t,{responseType:"blob"})}}let i=new y,a=new g;const f=u("parts",{state:()=>({parts:[],currentPart:null,loading:!1,error:null,initialized:!1,totalElements:0,totalPages:0,searchCriteria:{page:0,size:10,sortBy:"name",direction:"ASC",search:"",filters:{}},stockAlerts:[],stockAdjustments:[],inventoryTransfers:[],reorderPointConfigs:[],inventoryAnalytics:{}}),getters:{getPartById:e=>t=>e.parts.find(r=>r.id===t),filteredParts:e=>{let t=[...e.parts];if(e.searchCriteria.search){const r=e.searchCriteria.search.toLowerCase();t=t.filter(s=>{var n,o,l,c;return((n=s.name)==null?void 0:n.toLowerCase().includes(r))||((o=s.partNumber)==null?void 0:o.toLowerCase().includes(r))||((l=s.manufacturer)==null?void 0:l.toLowerCase().includes(r))||((c=s.description)==null?void 0:c.toLowerCase().includes(r))})}return t},inventoryStats:e=>{const t={totalParts:e.parts.length,totalValue:0,lowStock:0,categories:{}};return e.parts.forEach(r=>{const s=(r.currentStock||0)*(r.unitCost||0);t.totalValue+=s,(r.currentStock||0)<(r.minStock||0)&&t.lowStock++;const n=r.category||"UNKNOWN";t.categories[n]=(t.categories[n]||0)+1}),t},lowStockParts:e=>e.parts.filter(t=>(t.currentStock||0)<(t.minStock||0)),getPartsByCategory:e=>t=>e.parts.filter(r=>r.category===t),getPartsByLocation:e=>t=>e.parts.filter(r=>r.location===t),unresolvedAlerts:e=>e.stockAlerts.filter(t=>!t.resolved),criticalAlerts:e=>e.stockAlerts.filter(t=>t.severity==="critical"),getAdjustmentsByReason:e=>t=>e.stockAdjustments.filter(r=>r.reason===t),totalStockValue:e=>e.parts.reduce((t,r)=>t+(r.currentStock||0)*(r.unitCost||0),0),partsNeedingReorder:e=>e.parts.filter(t=>t.currentStock<=(t.reorderPoint||0)&&t.reorderPoint>0),pendingTransfers:e=>e.inventoryTransfers.filter(t=>t.status==="pending"),transferStats:e=>{const t=e.inventoryTransfers;return{total:t.length,pending:t.filter(r=>r.status==="pending").length,approved:t.filter(r=>r.status==="approved").length,completed:t.filter(r=>r.status==="completed").length,cancelled:t.filter(r=>r.status==="cancelled").length}}},actions:{async createPart(e){this.loading=!0,this.error=null;try{const t=await i.create(e);return this.parts.push(t),this.currentPart=t,t}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async updatePart(e,t){var r;this.loading=!0,this.error=null;try{const s=await i.update(e,t),n=this.parts.findIndex(o=>o.id===e);return n!==-1&&(this.parts[n]=s),((r=this.currentPart)==null?void 0:r.id)===e&&(this.currentPart=s),s}catch(s){throw this.error=s.message,s}finally{this.loading=!1}},async deletePart(e){var t;this.loading=!0,this.error=null;try{await i.delete(e);const r=this.parts.findIndex(s=>s.id===e);r!==-1&&this.parts.splice(r,1),((t=this.currentPart)==null?void 0:t.id)===e&&(this.currentPart=null)}catch(r){throw this.error=r.message,r}finally{this.loading=!1}},async fetchPartById(e){this.loading=!0,this.error=null;try{const t=await i.getById(e);return this.currentPart=t,t}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async fetchParts(e=null){this.loading=!0,this.error=null;try{const t=e||this.searchCriteria,r=await i.search(t);this.parts=r.content||r,this.totalElements=r.totalElements||this.parts.length,this.totalPages=r.totalPages||1}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async updateSearchTerm(e){this.searchCriteria.search=e,this.searchCriteria.page=0,await this.fetchParts()},async updateFilters(e){this.searchCriteria.filters={...this.searchCriteria.filters,...e},this.searchCriteria.page=0,await this.fetchParts()},async changePage(e){this.searchCriteria.page=e,await this.fetchParts()},async changeSorting(e,t){this.searchCriteria.sortBy=e,this.searchCriteria.direction=t,this.searchCriteria.page=0,await this.fetchParts()},async refreshParts(){await this.fetchParts()},async initializeParts(){this.initialized||(await this.fetchParts(),this.initialized=!0)},async updateStock(e,t,r){this.loading=!0,this.error=null;try{const s=await i.updateInventory(e,t,r),n=this.parts.findIndex(o=>o.id===e);n!==-1&&(this.parts[n]={...this.parts[n],...s})}catch(s){throw this.error=s.message,s}finally{this.loading=!1}},async reserveParts(e,t){this.loading=!0,this.error=null;try{await i.reserveParts(e,t),await this.refreshParts()}catch(r){throw this.error=r.message,r}finally{this.loading=!1}},async releaseParts(e){this.loading=!0,this.error=null;try{await i.releaseParts(e),await this.refreshParts()}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async getLowStockParts(e=10){this.loading=!0,this.error=null;try{return await i.getLowStock(e)}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async exportParts(e={}){this.loading=!0,this.error=null;try{return console.log("Exporting parts with filters:",e),"export-data"}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},clearCurrentPart(){this.currentPart=null},clearError(){this.error=null},setRepository(e){i=e},setInventoryRepository(e){a=e},async fetchStockAlerts(e={}){this.loading=!0,this.error=null;try{const t=await a.getStockAlerts(e);return this.stockAlerts=Array.isArray(t)?t:[],this.stockAlerts}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async createStockAlert(e){this.loading=!0,this.error=null;try{const t=await a.createStockAlert(e);return this.stockAlerts.push(t),t}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async acknowledgeAlert(e,t){this.loading=!0,this.error=null;try{await a.acknowledgeAlert(e,t);const r=this.stockAlerts.find(s=>s.id===e);r&&(r.acknowledged=!0,r.acknowledgedBy=t.acknowledgedBy,r.acknowledgedAt=new Date().toISOString())}catch(r){throw this.error=r.message,r}finally{this.loading=!1}},async resolveAlert(e,t){this.loading=!0,this.error=null;try{await a.resolveAlert(e,t);const r=this.stockAlerts.find(s=>s.id===e);r&&(r.resolved=!0,r.resolvedBy=t.resolvedBy,r.resolvedAt=new Date().toISOString())}catch(r){throw this.error=r.message,r}finally{this.loading=!1}},async getAlertStatistics(e={}){this.loading=!0,this.error=null;try{return await a.getStockAlerts(e)}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async fetchStockAdjustments(e={}){this.loading=!0,this.error=null;try{const t=await a.getStockAdjustments(e);return this.stockAdjustments=Array.isArray(t)?t:[],this.stockAdjustments}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async createStockAdjustment(e){this.loading=!0,this.error=null;try{const t=await a.createStockAdjustment(e);this.stockAdjustments.push(t);const r=this.parts.find(s=>s.id===e.partId);return r&&(r.currentStock=e.adjustedQuantity),t}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async getAdjustmentHistory(e){this.loading=!0,this.error=null;try{return await a.getStockAdjustments({partId:e})}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async fetchInventoryTransfers(e={}){this.loading=!0,this.error=null;try{const t=await a.getInventoryTransfers(e);return this.inventoryTransfers=Array.isArray(t)?t:[],this.inventoryTransfers}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async createInventoryTransfer(e){this.loading=!0,this.error=null;try{const t=await a.createInventoryTransfer(e);return this.inventoryTransfers.push(t),t}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async approveTransfer(e,t){this.loading=!0,this.error=null;try{await a.approveTransfer(e,t);const r=this.inventoryTransfers.find(s=>s.id===e);r&&(r.status="approved",r.approvedBy=t.approvedBy,r.approvedAt=new Date().toISOString())}catch(r){throw this.error=r.message,r}finally{this.loading=!1}},async fetchReorderPointConfigs(e={}){this.loading=!0,this.error=null;try{const t=await a.getReorderPointConfigs(e);return this.reorderPointConfigs=Array.isArray(t)?t:[],this.reorderPointConfigs}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async createReorderPointConfig(e){this.loading=!0,this.error=null;try{const t=await a.createReorderPointConfig(e);return this.reorderPointConfigs.push(t),t}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async updateReorderPointConfig(e,t){this.loading=!0,this.error=null;try{await a.updateReorderPointConfig(e,t);const r=this.reorderPointConfigs.find(s=>s.id===e);r&&Object.assign(r,t)}catch(r){throw this.error=r.message,r}finally{this.loading=!1}},async getStockLevelsByLocation(e){this.loading=!0,this.error=null;try{return await a.getStockLevelsByLocation(e)}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async updateStockLevel(e,t,r){this.loading=!0,this.error=null;try{await a.updateStockLevel(e,t,r);const s=this.parts.find(n=>n.id===e);s&&Object.assign(s,r)}catch(s){throw this.error=s.message,s}finally{this.loading=!1}},async getInventoryValuation(e={}){this.loading=!0,this.error=null;try{return await a.getInventoryValuation(e)}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async getTotalInventoryValue(e={}){try{return(await this.getInventoryValuation(e)).reduce((r,s)=>r+(s.totalCost||0),0)}catch(t){throw this.error=t.message,t}},async getInventoryAnalytics(e={}){this.loading=!0,this.error=null;try{const t=await a.getInventoryAnalytics(e);return this.inventoryAnalytics=t,t}catch(t){throw this.error=t.message,t}finally{this.loading=!1}},async getABCAnalysis(e={}){this.loading=!0,this.error=null;try{return await a.getABCAnalysis(e)}catch(t){throw this.error=t.message,t}finally{this.loading=!1}}}});export{f as u};