import{r as b,bG as D,aP as U}from"./index-ktJf6c6X.js";function q(t,e,p,r,s){const c=(t??"").trim().toLowerCase(),T=(e??"").trim().toLowerCase(),g=c.length>0&&T.length>0?c===T:s==="INTRA_STATE",l=p??[],u=l.find(f=>{var n;return((n=f.name)==null?void 0:n.toUpperCase())==="IGST"}),o=l.find(f=>{var n;return((n=f.name)==null?void 0:n.toUpperCase())==="CGST"}),a=l.find(f=>{var n;return((n=f.name)==null?void 0:n.toUpperCase())==="SGST"});return g&&o&&a?{isSameState:!0,effectiveRate:o.percentage+a.percentage}:!g&&u?{isSameState:!1,effectiveRate:u.percentage}:{isSameState:g,effectiveRate:r}}function B(t,e){return t.discountType==="AMOUNT"?Math.min(Math.max(0,t.discount||0),e):e*Math.min(Math.max(0,t.discount||0),100)/100}function E(t,e){var T,g,l,u;const p=((T=t.selectedBatch)==null?void 0:T.taxRateDtoList)??[];let r=((g=p.find(o=>{var a;return((a=o.name)==null?void 0:a.toUpperCase())==="CGST"}))==null?void 0:g.percentage)??0,s=((l=p.find(o=>{var a;return((a=o.name)==null?void 0:a.toUpperCase())==="SGST"}))==null?void 0:l.percentage)??0,c=((u=p.find(o=>{var a;return((a=o.name)==null?void 0:a.toUpperCase())==="IGST"}))==null?void 0:u.percentage)??0;return r===0&&s===0&&c===0&&(r=t.cgstRate??0,s=t.sgstRate??0,c=t.igstRate??0),r===0&&s===0&&c===0&&e.effectiveRate>0&&(e.isSameState?(r=e.effectiveRate/2,s=e.effectiveRate/2):c=e.effectiveRate),{cgstRate:r,sgstRate:s,igstRate:c}}function w(t,e,p){return b.useMemo(()=>{const r=t.taxMode==="WITHOUT_GST";let s=0,c=0,T=0,g=0,l=0,u=0,o=0,a=!0,f=0;t.items.forEach(i=>{var G,m,A,M;const h=i.quantity*i.unitPrice,L=((G=i.selectedBatch)==null?void 0:G.basePurchasePrice)??0;f+=L*i.quantity;const v=B(i,h),S=Math.max(0,h-v),d=q((m=t.dispatchAddress)==null?void 0:m.state,(A=t.shippingAddress)==null?void 0:A.state,(M=i.selectedBatch)==null?void 0:M.taxRateDtoList,i.gstRate,t.transactionType);if(a=d.isSameState,!r){const R=E(i,d);d.isSameState?(l+=S*R.cgstRate/100,u+=S*R.sgstRate/100):o+=S*(R.igstRate||d.effectiveRate)/100;const P=d.isSameState?R.cgstRate+R.sgstRate:R.igstRate||d.effectiveRate;c+=S*P/100}s+=S,T+=v,g+=i.quantity});const n=D(e);r||(l+=n.cgstTotal,u+=n.sgstTotal,o+=n.igstTotal,c+=n.taxTotal);const x=p.filter(i=>i.isChargeable).reduce((i,h)=>i+U(h.charges??[],s),0),C=U(e,s),y=s+c+x+C;return{subTotal:s,taxTotal:c,totalDiscount:T,serviceChargesTotal:x,directChargesTotal:C,grandTotal:y,totalQty:g,cgstTotal:l,sgstTotal:u,igstTotal:o,isSameState:a,totalPurchaseAmount:f}},[t.items,t.dispatchAddress,t.shippingAddress,t.transactionType,t.taxMode,e,p])}export{q as a,B as g,E as r,w as u};
