bettertend/frontend/dist/assets/usePartDisplay-DgOw31kV.js

2 lines
5.0 KiB
JavaScript

import{r as h,c as N}from"./index-QAlcqU00.js";function I(){const a=h(null),S=t=>{if(a.value=null,!t.name||t.name.trim().length===0)return a.value="Part name is required",!1;if(!t.category)return a.value="Part category is required",!1;if(!t.location||t.location.trim().length===0)return a.value="Storage location is required",!1;const o=parseFloat(t.currentStock),n=parseFloat(t.minStock),l=parseFloat(t.unitCost);return isNaN(o)||o<0||isNaN(n)||n<0?(a.value="Stock quantities must be non-negative",!1):isNaN(l)||l<0?(a.value="Unit cost must be non-negative",!1):!0},d=(t,o=[])=>{const n={isValid:!0,errors:[],warnings:[]};t.partNumber&&o.find(e=>e.partNumber===t.partNumber&&e.category===t.category&&(!t.id||e.id!==t.id))&&(n.isValid=!1,n.errors.push(`Part number ${t.partNumber} already exists in ${t.category} category`));const l=parseFloat(t.currentStock),c=parseFloat(t.minStock);return l<c&&n.warnings.push("Current stock is below minimum threshold"),n},g=t=>{var n,l,c,s,e,r;const o={...t,name:(n=t.name)==null?void 0:n.trim(),partNumber:(l=t.partNumber)==null?void 0:l.trim().toUpperCase(),manufacturer:(c=t.manufacturer)==null?void 0:c.trim(),description:(s=t.description)==null?void 0:s.trim(),supplier:(e=t.supplier)==null?void 0:e.trim(),location:(r=t.location)==null?void 0:r.trim(),currentStock:parseInt(t.currentStock)||0,minStock:parseInt(t.minStock)||0,unitCost:parseFloat(t.unitCost)||0,createdAt:t.createdAt||new Date().toISOString(),updatedAt:new Date().toISOString()};return Object.keys(o).forEach(i=>{o[i]===void 0&&delete o[i]}),o},u=t=>{const o=t.currentStock||0,n=t.minStock||0;return o<n?"low":o>n*2?"over":"normal"},y=(t,o,n)=>{if(!t||!Array.isArray(t))return[];let l=t.filter(c=>c.category===n&&(!o||c.id!==o.id));if(o){const s=((e,r)=>{const i=new Set,p=v=>{r.forEach(m=>{var P;((P=m.parentPart)==null?void 0:P.id)===v&&!i.has(m.id)&&(i.add(m.id),p(m.id))})};return p(e),i})(o.id,t);l=l.filter(e=>!s.has(e.id))}return l.map(c=>({label:c.name,value:c.id}))},b=t=>t.reduce((o,n)=>o+(n.currentStock||0)*(n.unitCost||0),0),f=t=>t.filter(o=>u(o)==="low"),k=(t,o)=>t.filter(n=>n.category===o);return{error:N(()=>a.value),validatePart:S,validatePartBusinessRules:d,processPartData:g,calculateStockLevel:u,calculateTotalValue:b,getLowStockParts:f,getPartsByCategory:k,getValidParentParts:y}}function T(){const a=e=>({PARTS:"blue",TOOLS:"green",SUPPLIES:"yellow",EQUIPMENT:"purple",CONSUMABLES:"orange"})[e]||"gray",S=e=>({low:"red",normal:"green",over:"yellow"})[e]||"gray",d=e=>({PARTS:"Parts",TOOLS:"Tools",SUPPLIES:"Supplies",EQUIPMENT:"Equipment",CONSUMABLES:"Consumables"})[e]||"General",g=e=>({low:"Low Stock",normal:"Normal",over:"Overstocked"})[e]||"Unknown",u=e=>!e&&e!==0?"$0.00":new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(e);return{getCategoryVariant:a,getStockLevelVariant:S,formatCategory:d,formatStockLevel:g,formatCurrency:u,formatPartNumber:e=>e||"No part number",formatSupplier:e=>e||"No supplier",formatLocation:e=>e||"No location",getCategoryIcon:e=>({PARTS:"cog",TOOLS:"wrench",SUPPLIES:"cube",EQUIPMENT:"desktop-computer",CONSUMABLES:"beaker"})[e]||"archive",getStockLevelIcon:e=>({low:"exclamation-triangle",normal:"check-circle",over:"information-circle"})[e]||"question-mark-circle",formatStockDisplay:e=>{const r=e.currentStock||0,i=e.minStock||0;return`${r} / ${i}`},calculatePartValue:e=>{const r=e.currentStock||0,i=e.unitCost||0;return r*i},formatInventoryStats:e=>{if(!e)return[];const r=e.totalValue||0,i=r>=1e3?`$${(r/1e3).toFixed(1)}K`:u(r);return[{label:"Total Parts",value:e.totalParts||0,variant:"blue",icon:"cube",subtitle:"All inventory items"},{label:"Total Value",value:i,variant:"green",icon:"currency-dollar",subtitle:"Inventory value"},{label:"Low Stock Items",value:e.lowStock||0,variant:"red",icon:"exclamation-triangle",subtitle:"Need restocking"},{label:"Categories",value:Object.keys(e.categories||{}).length,variant:"purple",icon:"collection",subtitle:"Part categories"}]},getCategoryTabs:e=>{const r=(e==null?void 0:e.categories)||{};return[{key:"all",label:"All Parts",count:(e==null?void 0:e.totalParts)||0},{key:"PARTS",label:"Parts",count:r.PARTS||0},{key:"TOOLS",label:"Tools",count:r.TOOLS||0},{key:"SUPPLIES",label:"Supplies",count:r.SUPPLIES||0},{key:"EQUIPMENT",label:"Equipment",count:r.EQUIPMENT||0}]},getPartTableColumns:(e=!1)=>{const r=[{key:"name",label:"Part",sortable:!0,width:"25%",essential:!0,priority:"high"},{key:"partNumber",label:"Part Number",sortable:!0,width:"15%",priority:"medium"},{key:"category",label:"Category",sortable:!0,width:"12%",priority:"medium"},{key:"stock",label:"Stock (Current/Min)",sortable:!0,width:"15%",essential:!0,priority:"high"},{key:"unitCost",label:"Unit Cost",sortable:!0,width:"10%",priority:"low"},{key:"totalValue",label:"Total Value",sortable:!0,width:"12%",priority:"low"},{key:"location",label:"Location",sortable:!0,width:"15%",priority:"medium"},{key:"actions",label:"Actions",sortable:!1,width:"12%",essential:!0,priority:"high"}];return e?r.filter(i=>i.essential||i.priority==="high"):r}}}export{T as a,I as u};