PageSourceSearch

https://bro-depot.com/_next/static/chunks/pages/admin/adjust-stock-in-cost-c2c7bd979f81b2d9.js

js bro-depot.com collected 2026-10-04 02:38:13 UTC 15,869 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[644],{23031:function(e,r,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/adjust-stock-in-cost",function(){return t(98130)}])},98130:function(e,r,t){"use strict";t.r(r),t.d(r,{default:function(){return $}});var n,i=t(85893),s=t(47568),c=t(14924),a=t(26042),o=t(828),l=t(70655),d=t(66252),u=t(20986),h=t(96277),x=t(4451),m=t(43085),j=t(23378),v=t(17575),g=t(9144),f=t(29630),Z=t(80562),b=t(49837),p=t(59742),y=t(91359),S=t(45135),k=t(30120),w=t(67836),C=t(54225),N=t(70754),I=t(44373),O=t(55343),P=t(41470),_=t(22841),F=t(15497),A=t(86777),z=t(90244),R=t(93978),T=t(69417),D=t(5605),W=t(39807),L=t(9041),B=t(75158),U=t(89125),E=t(67294);function K(e,r){var t=e.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2});return r?"".concat(t," ").concat(r):t}function M(e){var r=new Date(e);return Number.isNaN(r.getTime())&&/^\d+$/.test(e)&&(r=new Date(Number(e))),Number.isNaN(r.getTime())?{display:"\u2014",iso:e}:{display:r.toLocaleDateString(void 0,{day:"2-digit",month:"short",year:"numeric"}),iso:r.toISOString()}}var Q=(n={},(0,c.Z)(n,h.mrS.PurchaseOrder,"Purchase Order"),(0,c.Z)(n,h.mrS.SalesOrder,"Sales Order"),(0,c.Z)(n,h.mrS.ReturnOrder,"Return Order"),(0,c.Z)(n,h.mrS.TransferOrder,"Transfer Order"),(0,c.Z)(n,h.mrS.StockOutOrder,"Stock-Out Order"),(0,c.Z)(n,h.mrS.StockOutReturnOrder,"Stock-Out Return"),n);function V(e){var r=e.orderType;if(!r)return null;var t,n=r===h.mrS.PurchaseOrder;return(0,i.jsx)(j.Z,{label:null!==(t=Q[r])&&void 0!==t?t:r,size:"small",variant:"outlined",color:n?"primary":"default",sx:{height:20,fontSize:"0.7rem"}})}function q(e){var r=e.value,t=e.display,n=(0,E.useState)(!1),s=n[0],c=n[1],a=(0,E.useCallback)((function(e){var t;e.stopPropagation(),null===(t=navigator.clipboard)||void 0===t||t.writeText(r).catch((function(){})),c(!0),window.setTimeout((function(){return c(!1)}),1200)}),[r]);return(0,i.jsx)(v.Z,{title:s?"Copied!":r,placement:"top",arrow:!0,children:(0,i.jsxs)(g.Z,{direction:"row",alignItems:"center",spacing:.5,children:[(0,i.jsx)(f.Z,{variant:"caption",sx:{fontFamily:"monospace",color:"text.secondary"},children:t}),(0,i.jsx)(Z.Z,{size:"small",onClick:a,sx:{p:.25},children:(0,i.jsx)(u.TI,{size:12})})]})})}var X={Manual:"Manual",Repair:"Cost repair",WeightedAverage:"Re-stock-in"};function Y(e){if(!e)return"\u2014";var r=[e.firstName,e.lastName].filter(Boolean).join(" ").trim();return e.userName||r||e.email||"\u2014"}var G=function(){var e,r,t,n=(0,E.useState)(""),c=n[0],u=n[1],Z=(0,E.useState)(""),Q=Z[0],G=Z[1],H=(0,E.useState)("all"),$=H[0],J=H[1],ee=(0,E.useState)(null),re=ee[0],te=ee[1],ne=(0,E.useState)([]),ie=ne[0],se=ne[1],ce=(0,E.useState)(null),ae=ce[0],oe=ce[1],le=(0,E.useState)(0),de=le[0],ue=le[1],he=(0,E.useState)(10),xe=he[0],me=he[1],je=(0,E.useState)(!1),ve=je[0],ge=je[1],fe=(0,d.x)(),Ze=(0,x.a)().user,be=(0,o.Z)((0,h.Wc)(),2),pe=be[0],ye=be[1].loading,Se=(0,E.useMemo)((function(){var e,r;return!!(null===Ze||void 0===Ze?void 0:Ze.isSuperAdmin)||null!==(r=null===Ze||void 0===Ze||null===(e=Ze.currentUc)||void 0===e?void 0:e.ucUserRoles.some((function(e){return e.userRole.permissions.includes(h.GmF.StockInCostUpdate)})))&&void 0!==r&&r}),[Ze]),ke=(0,E.useState)(""),we=ke[0],Ce=ke[1];(0,E.useEffect)((function(){var e=setTimeout((function(){Ce(c.trim()),ue(0)}),400);return function(){return clearTimeout(e)}}),[c]);var Ne,Ie,Oe=(0,h.t2s)({variables:{sku:we||void 0,source:ve?void 0:"Manual",page:de,perPage:xe},skip:!Se,fetchPolicy:"cache-and-network",onError:function(e){return(0,m._N)(e.message||"Failed to load adjustment history")}}),Pe=Oe.data,_e=Oe.loading,Fe=Oe.refetch,Ae=null!==(Ne=null===Pe||void 0===Pe||null===(e=Pe.stockInCostAdjustmentLogs)||void 0===e?void 0:e.logs)&&void 0!==Ne?Ne:[],ze=null!==(Ie=null===Pe||void 0===Pe||null===(r=Pe.stockInCostAdjustmentLogs)||void 0===r?void 0:r.total)&&void 0!==Ie?Ie:0,Re=(0,E.useCallback)((function(){var e,r;fe.cache.evict({fieldName:"getProductVariantCostBatches"}),fe.cache.evict({fieldName:"getLatestStockInCostByBarcode"}),fe.cache.evict({fieldName:"allInventories"}),fe.cache.evict({fieldName:"allStockInOrderRecords"}),fe.cache.evict({fieldName:"allProductVariants"}),fe.cache.evict({fieldName:"allProducts"});var t=null!==(r=null===(e=fe.cache.data)||void 0===e?void 0:e.data)&&void 0!==r?r:{};Object.keys(t).forEach((function(e){e.startsWith("Price:")&&fe.cache.evict({id:e}),e.startsWith("ProductVariant:")&&fe.cache.evict({id:e,fieldName:"latestFifoCost"})})),fe.cache.gc()}),[fe]),Te=(0,E.useMemo)((function(){return 0===ie.length?null:{totalQty:ie.reduce((function(r,t){return r+(null!==(e=t.stockInQty)&&void 0!==e?e:0)}),0),currencies:Array.from(new Set(ie.map((function(e){return e.currency}
1)).filter(Boolean)))};var e}),[ie]),De=(0,E.useCallback)((0,s.Z)((function(){var e,r,t;return(0,l.__generator)(this,(function(n){switch(n.label){case 0:if(!c.trim())return(0,m._N)("Please enter a SKU"),[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,pe({variables:{input:{sku:c.trim()}}})];case 2:return e=n.sent().data,(null===(r=null===e||void 0===e?void 0:e.adjustStockInCost)||void 0===r?void 0:r.success)&&(se(r.stockInCosts),te(null),J("all"),oe(null),(0,m.x9)("Found ".concat(r.totalRecords," batch(es) for ").concat(c))),[3,4];case 3:return t=n.sent(),(0,m._N)(t.message||"Failed to check SKU"),[3,4];case 4:return[2]}}))})),[pe,c]),We=(0,E.useCallback)((0,s.Z)((function(){var e,r,t,n,i;return(0,l.__generator)(this,(function(s){switch(s.label){case 0:if(!c.trim()||!Q.trim())return(0,m._N)("SKU and new cost are required"),[2];if(e=parseFloat(Q),Number.isNaN(e)||e<0)return(0,m._N)("Invalid cost amount"),[2];if("specific"===$&&!re)return(0,m._N)("Pick a specific batch row first"),[2];r={input:(0,a.Z)({sku:c.trim(),newCost:e,recalculateFifo:!0},"specific"===$&&re?{recordId:re}:{})},s.label=1;case 1:return s.trys.push([1,3,,4]),[4,pe({variables:r})];case 2:return t=s.sent().data,(null===(n=null===t||void 0===t?void 0:t.adjustStockInCost)||void 0===n?void 0:n.success)&&(oe(n),se([]),te(null),(0,m.x9)(n.message),Re(),ue(0),Fe({sku:we||void 0,source:ve?void 0:"Manual",page:0,perPage:xe}).catch((function(){}))),[3,4];case 3:return i=s.sent(),(0,m._N)(i.message||"Failed to adjust cost"),Re(),[3,4];case 4:return[2]}}
1))})),[pe,$,c,we,Q,re,Re,Fe,xe,ve]),Le="specific"===$,Be=Le&&re?null===(t=ie.find((function(e){return e.recordId===re})))||void 0===t?void 0:t.currency:1===(null===Te||void 0===Te?void 0:Te.currencies.length)?Te.currencies[0]:void 0;return Se?(0,i.jsxs)(b.Z,{children:[(0,i.jsx)(p.Z,{title:"Adjust Stock-In Cost",subheader:"Check and adjust stock-in costs per SKU. Every adjustment is recorded below."}),(0,i.jsxs)(y.Z,{children:[(0,i.jsxs)(k.Z,{sx:{display:"flex",gap:2,mb:3,alignItems:"flex-end"},children:[(0,i.jsx)(w.Z,{label:"SKU",value:c,onChange:function(e){return u(e.target.value)},size:"small",sx:{minWidth:220},onKeyDown:function(e){return"Enter"===e.key&&De()}}),(0,i.jsx)(C.Z,{variant:"outlined",onClick:De,disabled:ye||!c.trim(),children:ye?(0,i.jsx)(N.Z,{size:20}):"Check Batches"})]}),ie.length>0&&Te&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(g.Z,{direction:{xs:"column",sm:"row"},spacing:1.5,alignItems:{xs:"flex-start",sm:"center"},sx:{mb:2,p:1.5,borderRadius:1,bgcolor:"action.hover"},children:[(0,i.jsxs)(f.Z,{variant:"subtitle2",children:[ie.length," batch",1===ie.length?"":"es"]}),(0,i.jsx)(I.Z,{flexItem:!0,orientation:"vertical"}),(0,i.jsxs)(f.Z,{variant:"body2",color:"text.secondary",children:["Total qty: ",(0,i.jsx)("strong",{children:Te.totalQty.toLocaleString()})]}),(0,i.jsx)(I.Z,{flexItem:!0,orientation:"vertical"}),(0,i.jsxs)(g.Z,{direction:"row",spacing:.5,alignItems:"center",children:[(0,i.jsx)(f.Z,{variant:"body2",color:"text.secondary",children:"Currency:"}),0===Te.currencies.length?(0,i.jsx)(f.Z,{variant:"body2",color:"text.disabled",children:"\u2014"}):Te.currencies.map((function(e){return(0,i.jsx)(j.Z,{label:e,size:"small",color:Te.currencies.length>1?"warning":"default",sx:{height:20,fontSize:"0.7rem"}},e)}))]}),Te.currencies.length>1&&(0,i.jsx)(v.Z,{title:"Different currencies detected across batches \u2014 overriding ALL will write the same numeric value into each, regardless of currency.",arrow:!0,children:(0,i.jsx)(j.Z,{label:"Mixed currencies",size:"small",color:"warning",sx:{height:20,fontSize:"0.7rem"}})})]}),(0,i.jsx)(O.Z,{sx:{mb:1},children:(0,i.jsxs)(P.Z,{row:!0,value:$,onChange:function(e,r){J(r),"all"===r&&te(null)},children:[(0,i.jsx)(_.Z,{value:"all",control:(0,i.jsx)(F.Z,{size:"small"}),label:(0,i.jsxs)(f.Z,{variant:"body2",children:["Override ",(0,i.jsxs)("strong",{children:["all ",ie.length]})," batches"]})}),(0,i.jsx)(_.Z,{value:"specific",control:(0,i.jsx)(F.Z,{size:"small"}),label:(0,i.jsx)(f.Z,{variant:"body2",children:"Override one specific batch"})})]})}),(0,i.jsx)(A.Z,{sx:{mb:2,borderRadius:1,border:1,borderColor:"divider"},children:(0,i.jsxs)(z.Z,{size:"small",children:[(0,i.jsx)(R.Z,{children:(0,i.jsxs)(T.Z,{children:[Le&&(0,i.jsx)(D.Z,{padding:"checkbox",sx:{width:40}}),(0,i.jsx)(D.Z,{sx:{minWidth:220},children:"Source order"}),(0,i.jsx)(D.Z,{align:"right",children:"Current cost"}),(0,i.jsx)(D.Z,{align:"right",children:"Qty"}),(0,i.jsx)(D.Z,{children:"Warehouse"}),(0,i.jsx)(D.Z,{children:"Stock-in date"})]})}),(0,i.jsx)(W.Z,{children:ie.map((function(e){var r=M(e.createdAt),t=Le&&re===e.recordId;return(0,i.jsxs)(T.Z,{hover:Le,selected:t,onClick:Le?function(){return te(e.recordId)}:void 0,sx:{cursor:Le?"pointer":"default"},children:[Le&&(0,i.jsx)(D.Z,{padding:"checkbox",children:(0,i.jsx)(F.Z,{checked:t,size:"small"})}),(0,i.jsx)(D.Z,{children:(0,i.jsxs)(g.Z,{spacing:.25,children:[e.purchaseOrderNumber?(0,i.jsxs)(g.Z,{direction:"row",spacing:.75,alignItems:"center",children:[(0,i.jsx)(f.Z,{variant:"body2",fontWeight:600,sx:{fontFamily:"monospace"},children:e.purchaseOrderNumber}),(0,i.jsx)(V,{orderType:e.orderType})]}):(0,i.jsx)(f.Z,{variant:"body2",color:"text.disabled",children:"\u2014 no linked order \u2014"}),(0,i.jsx)(q,{value:e.recordId,display:"OSIR ".concat(e.recordId.slice(0,8))})]})}),(0,i.jsx)(D.Z,{align:"right",children:(0,i.jsx)(f.Z,{fontWeight:600,sx:{fontVariantNumeric:"tabular-nums"},children:K(e.currentCost,e.currency)})}),(0,i.jsx)(D.Z,{align:"right",sx:{fontVariantNumeric:"tabular-nums"},children:e.stockInQty.toLocaleString()}),(0,i.jsx)(D.Z,{children:(0,i.jsx)(f.Z,{variant:"body2",children:e.warehouseName})}),(0,i.jsx)(D.Z,{children:(0,i.jsx)(v.Z,{title:r.iso,arrow:!0,children:(0,i.jsx)(f.Z,{variant:"body2",children:r.display})})})]},e.recordId)}))})]})}),(0,i.jsx)(I.Z,{sx:{my:2}}),(0,i.jsxs)(g.Z,{direction:{xs:"column",sm:"row"},spacing:2,alignItems:{xs:"stretch",sm:"flex-end"},children:[(0,i.jsx)(w.Z,{label:"New cost",value:Q,onChange:function(e){return G(e.target.value)},size:"small",type:"number",sx:{width:{xs:"100%",sm:200}}
1,InputProps:{inputProps:{min:0,step:.01},endAdornment:Be?(0,i.jsx)(L.Z,{position:"end",children:Be}):void 0},helperText:Be?"Will be saved as ".concat(Be):"No single currency in scope \u2014 value is saved as-is"}),(0,i.jsx)(C.Z,{variant:"contained",color:"error",onClick:We,disabled:ye||!Q.trim()||Le&&!re,children:ye?(0,i.jsx)(N.Z,{size:20}):Le?"Override selected batch":"Override all ".concat(ie.length," batches")})]}),!Le&&(0,i.jsxs)(S.Z,{severity:"warning",sx:{mt:1.5},children:["You are about to override ALL ",ie.length," stock-in cost",1===ie.length?"":"s"," for this SKU. FIFO will be recalculated for affected sales orders."]}),Le&&re&&(0,i.jsx)(S.Z,{severity:"info",sx:{mt:1.5},children:"Only the selected batch will be overridden. Other batches stay untouched."})]}),ae&&(0,i.jsxs)(k.Z,{sx:{mt:3},children:[(0,i.jsx)(S.Z,{severity:"success",sx:{mb:2},children:ae.message}),ae.fifoDetails&&ae.fifoDetails.length>0&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(f.Z,{variant:"subtitle2",sx:{mb:1},children:["FIFO Recalculated Orders (",ae.fifoOrdersRecalculated,")"]}),(0,i.jsx)(A.Z,{children:(0,i.jsxs)(z.Z,{size:"small",children:[(0,i.jsx)(R.Z,{children:(0,i.jsxs)(T.Z,{children:[(0,i.jsx)(D.Z,{children:"Order Number"}),(0,i.jsx)(D.Z,{align:"right",children:"Allocated Qty"}),(0,i.jsx)(D.Z,{align:"right",children:"Old Cost"}),(0,i.jsx)(D.Z,{align:"right",children:"New Cost"})]})}),(0,i.jsx)(W.Z,{children:ae.fifoDetails.map((function(e,r){return(0,i.jsxs)(T.Z,{children:[(0,i.jsx)(D.Z,{children:e.orderNumber}),(0,i.jsx)(D.Z,{align:"right",children:e.allocatedQty}),(0,i.jsx)(D.Z,{align:"right",children:e.oldCost.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}),(0,i.jsx)(D.Z,{align:"right",children:(0,i.jsx)(f.Z,{fontWeight:"bold",color:"success.main",children:e.newCost.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})})})]},r)}))})]})})]})]}),(0,i.jsx)(I.Z,{sx:{my:4}}),(0,i.jsxs)(k.Z,{children:[(0,i.jsxs)(g.Z,{direction:"row",alignItems:"center",spacing:1,sx:{mb:1},children:[(0,i.jsx)(f.Z,{variant:"subtitle1",fontWeight:"bold",children:"Cost Adjustment History"}),_e&&(0,i.jsx)(N.Z,{size:16})]}),(0,i.jsxs)(g.Z,{direction:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:"space-between",spacing:1,sx:{mb:2},children:[(0,i.jsx)(f.Z,{variant:"body2",color:"text.secondary",children:we?"Adjustments recorded for ".concat(we,"."):"All adjustments recorded for your company. Enter a SKU above to filter."}),(0,i.jsx)(_.Z,{control:(0,i.jsx)(B.Z,{size:"small",checked:ve,onChange:function(e){ge(e.target.checked),ue(0)}}),label:(0,i.jsx)(f.Z,{variant:"body2",color:"text.secondary",children:"Include automatic entries"})})]}),0!==Ae.length||_e?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(A.Z,{children:(0,i.jsxs)(z.Z,{size:"small",children:[(0,i.jsx)(R.Z,{children:(0,i.jsxs)(T.Z,{children:[(0,i.jsx)(D.Z,{children:"When"}),(0,i.jsx)(D.Z,{children:"Adjusted By"}),(0,i.jsx)(D.Z,{children:"Origin"}),(0,i.jsx)(D.Z,{children:"SKU"}),(0,i.jsx)(D.Z,{children:"Source Order"}),(0,i.jsx)(D.Z,{align:"right",children:"Cost Before"}),(0,i.jsx)(D.Z,{align:"right",children:"Cost After"})]})}),(0,i.jsx)(W.Z,{children:Ae.map((function(e){var r,t,n,s,c=M(e.createdAt),a=e.costAfter>e.costBefore,o=e.costAfter===e.costBefore;return(0,i.jsxs)(T.Z,{hover:!0,children:[(0,i.jsx)(D.Z,{children:(0,i.jsx)(v.Z,{title:c.iso,children:(0,i.jsx)("span",{children:c.display})})}),(0,i.jsx)(D.Z,{children:Y(e.adjustedBy)}),(0,i.jsx)(D.Z,{children:(0,i.jsx)(v.Z,{title:null!==(r=e.remarks)&&void 0!==r?r:"",children:(0,i.jsx)(j.Z,{size:"small",variant:"outlined",label:null!==(t=X[e.source])&&void 0!==t?t:e.source,color:"Manual"===e.source?"primary":"default"})})}),(0,i.jsx)(D.Z,{children:null!==(n=e.sku)&&void 0!==n?n:"\u2014"}),(0,i.jsx)(D.Z,{children:null!==(s=e.purchaseOrderNumber)&&void 0!==s?s:"\u2014"}),(0,i.jsx)(D.Z,{align:"right",children:K(e.costBefore,e.currency)}),(0,i.jsx)(D.Z,{align:"right",children:(0,i.jsx)(f.Z,{variant:"body2",fontWeight:"bold",color:o?"text.primary":a?"error.main":"success.main",children:K(e.costAfter,e.currency)})})]},e.id)}))})]})}),(0,i.jsx)(U.Z,{component:"div",count:ze,page:de,onPageChange:function(e,r){return ue(r)},rowsPerPage:xe,rowsPerPageOptions:[10,25,50],onRowsPerPageChange:function(e){me(parseInt(e.target.value,10)),ue(0)}})]}):(0,i.jsxs)(S.Z,{severity:"info",children:["No cost adjustments recorded",we?" for ".concat(we):""," yet."]})]})]})]}):(0,i.jsxs)(b.Z,{children:[(0,i.jsx)(p.Z,{title:"Adjust Stock-In Cost"}),(0,i.jsx)(y.Z,{children:(0,i.jsxs)(S.Z,{severity:"warning",children:["You don't have permission to view or adju
1st stock-in costs. Ask an administrator to grant your role the ",(0,i.jsx)("strong",{children:"Stock In Cost \u203a Update"})," permission."]})})]})},H=function(){return(0,i.jsx)(G,{})};H.acl={action:"manage",subject:"super_admin"};var $=H}},function(e){e.O(0,[5428,8808,9774,2888,179],(function(){return r=23031,e(e.s=r);var r}));var r=e.O();_N_E=r}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.