import{r as ie,c as de,d,b as r,I as X}from"./app-DTeOhhdM.js";import{B as ce}from"./react-barcode-DkieryVx.js";import{l as le}from"./defualtLogo-C0dU5cUD.js";import{n as ee}from"./numberToWords.min-02Sh2OYb.js";import"./index-Chjiymov.js";function me({sales:g,auth:c}){var D,F,I,A,S,q,z,T,E,P,$;const{permission:re}=ie.useContext(de),s=g&&typeof g=="object"&&!Array.isArray(g)?g:null;if(!s)return null;const v=e=>{var i,p,x,b,h,u,m,L,O,B,C,U,W,V,G,K,H,J,Q,R,Y,Z,M;const t=((i=e==null?void 0:e.product)==null?void 0:i.name)??((x=(p=e==null?void 0:e.attribute)==null?void 0:p.product)==null?void 0:x.name)??(e==null?void 0:e.product_name)??(e==null?void 0:e.name)??"",a=(h=(b=e==null?void 0:e.arribute)==null?void 0:b.gold_unit)!=null&&h.name||(m=(u=e==null?void 0:e.attribute)==null?void 0:u.gold_unit)!=null&&m.name?` | G: ${((L=e==null?void 0:e.arribute)==null?void 0:L.gold_weight)??((O=e==null?void 0:e.attribute)==null?void 0:O.gold_weight)??0} ${((C=(B=e==null?void 0:e.arribute)==null?void 0:B.gold_unit)==null?void 0:C.name)||((W=(U=e==null?void 0:e.attribute)==null?void 0:U.gold_unit)==null?void 0:W.name)}`:"",o=(G=(V=e==null?void 0:e.arribute)==null?void 0:V.diamond_unit)!=null&&G.name||(H=(K=e==null?void 0:e.attribute)==null?void 0:K.diamond_unit)!=null&&H.name?` | D: ${((J=e==null?void 0:e.arribute)==null?void 0:J.diamond_weight)??((Q=e==null?void 0:e.attribute)==null?void 0:Q.diamond_weight)??0} ${((Y=(R=e==null?void 0:e.arribute)==null?void 0:R.diamond_unit)==null?void 0:Y.name)||((M=(Z=e==null?void 0:e.attribute)==null?void 0:Z.diamond_unit)==null?void 0:M.name)}`:"";return`${t}${a}${o}`},se=Array.isArray(s.details)?s.details:[],N=typeof(s==null?void 0:s.pos_table_parcel_json)=="string"?(()=>{try{return JSON.parse(s.pos_table_parcel_json)}catch{return null}})():s==null?void 0:s.pos_table_parcel_json,f=(N==null?void 0:N.table_or_parcel)??"",_=String(f||"").toLowerCase(),ne=_==="table"?"Dine In":_==="parcel"?"Parcel":f,te={invoiceNumber:s.invoice_no??"",date:s.created_at?new Date(s.created_at).toLocaleDateString("en-GB",{day:"2-digit",month:"2-digit",year:"numeric",timeZone:"UTC"}):"",company:{name:d.name,address:d.address,email:d.email,provider:(D=c==null?void 0:c.shop_info)==null?void 0:D.provider,manager:(F=c==null?void 0:c.shop_info)==null?void 0:F.manager,phone:d.phone,slogan:d.slogan},customer:{name:(I=s==null?void 0:s.customer)==null?void 0:I.name,address:(A=s==null?void 0:s.customer)==null?void 0:A.address,phone:(S=s==null?void 0:s.customer)==null?void 0:S.number,email:(q=s==null?void 0:s.customer)==null?void 0:q.email,code:(z=s==null?void 0:s.customer)==null?void 0:z.code},items:se.map(e=>{var p,x,b,h,u,m;const t=Number(e.qty??e.quantity??1)||1,a=Number(e.price??e.mrp_price??e.tp_price??0),o=Number(e.total),i=Number.isFinite(o)?o:a*t;return{description:v(e),sku:((p=e==null?void 0:e.arribute)==null?void 0:p.sku)??((x=e==null?void 0:e.attribute)==null?void 0:x.sku)??"",quantity:t,warranty_code:e.warranty_code,after_discount_amount:e.after_discount??0,price:a,total:i,size:((h=(b=e==null?void 0:e.arribute)==null?void 0:b.size)==null?void 0:h.name)??((m=(u=e==null?void 0:e.attribute)==null?void 0:u.size)==null?void 0:m.name)??"N/A",fqty:e.fqty??0,allData:e}}),exchangeItems:Array.isArray((T=s==null?void 0:s.exchange_return)==null?void 0:T.details)?s.exchange_return.details.map(e=>{var t;return{description:v(e),sku:((t=e==null?void 0:e.attribute)==null?void 0:t.sku)??"",quantity:e.return_qty??0,price:Number(e.return_price??e.sales_price??0),total:Number(e.total??0)}}):[],totals:{subtotal:Number(s.total??0),discount:Number(s.discount??0),discount_2nd:Number(s.discount_second??0),after_discount:Number(s.after_discount??0),total:Number(s.grand_total??s.total??0),previous_due:Number(s.previous_due??0),payment:Number(s.current_payment??0),order:s.order_no??"N/A",transition_location:((E=s==null?void 0:s.transition_location)==null?void 0:E.name)??"N/A",createdBy:((P=s==null?void 0:s.user)==null?void 0:P.name)??(($=s==null?void 0:s.User)==null?void 0:$.name)??"N/A",tableOrParcel:f}},{invoiceNumber:j,date:ae,company:l,customer:y,items:oe,exchangeItems:w,totals:n}=te,k=w.length>0;return r.jsxs("div",{className:"print-2inch mx-auto break-after-avoid-page hidden print:!block print:bg-white print:relative",style:{width:"58mm",maxWidth:"58mm"},children:[r.jsx("style",{children:`
        @media print {
          @page { size: 58mm auto; margin: 0; padding: 0; }
          body { margin: 0; padding: 0; }
          .print-2inch { width: 220px !important; max-width: 220px !important; min-width: 220px !important; font-size: 13px !important; overflow: visible !important; color: #000 !important; }
          .print-2inch * { overflow: visible !important; color: inherit !important; }
          .print-2inch p, .print-2inch span, .print-2inch div { color: #000 !important; font-weight: 500 !important; }
          .print-2inch .font-semibold, .print-2inch .font-bold { font-weight: 700 !important; }
          .print-2inch .font-medium { font-weight: 600 !important; }
          .print-2inch .truncate { overflow: visible !important; text-overflow: clip !important; white-space: normal !important; }
          .print-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 2px; }
          .print-invoice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 4px; align-items: baseline; }
        }
        @media print and (max-width: 768px) {
          .print-2inch { width: 220px !important; max-width: 220px !important; min-width: 220px !important; box-sizing: border-box !important; }
        }
      `}),r.jsxs("div",{className:"print-2inch text-center py-1.5 border-b-2 border-gray-800",children:[d.companyLogo&&r.jsx("img",{src:d.companyLogo||le,alt:"Logo",className:"w-10 h-10 mx-auto mb-1 object-contain"}),r.jsx("h2",{className:"text-[14px] font-bold uppercase tracking-wide leading-tight",children:l.name}),l.slogan&&r.jsx("p",{className:"text-[13px] font-semibold text-gray-900 mt-0.5",children:l.slogan}),r.jsx("p",{className:"text-[13px] font-semibold text-gray-900 leading-tight mt-0.5",children:l.address}),r.jsxs("p",{className:"text-[13px] font-semibold text-gray-900 mt-0.5",children:["Ph: ",l.phone," | ",l.email]})]}),r.jsxs("div",{className:"print-2inch py-1 border-b border-gray-400",children:[r.jsx("h3",{className:"text-[13px] font-bold uppercase tracking-wider text-center",children:"INVOICE"}),r.jsxs("div",{className:"text-[13px] print-invoice-grid mt-0.5",children:[r.jsxs("div",{className:"print-row",children:[r.jsx("span",{className:"font-semibold text-gray-900",children:"Date"}),r.jsx("span",{className:"font-semibold",children:ae})]}),r.jsxs("div",{className:"print-row",children:[r.jsx("span",{className:"font-semibold text-gray-900",children:"Inv#"}),r.jsx("span",{className:"font-semibold",children:j})]}),r.jsxs("div",{className:"print-row",children:[r.jsx("span",{className:"font-semibold text-gray-900",children:"By"}),r.jsx("span",{className:"font-semibold",children:n.createdBy})]}),r.jsxs("div",{className:"print-row",children:[r.jsx("span",{className:"font-semibold text-gray-900",children:"Cust"}),r.jsx("span",{className:"font-semibold",children:(y==null?void 0:y.phone)||"—"})]}),n.tableOrParcel?r.jsxs("div",{className:"print-row",children:[r.jsx("span",{className:"font-semibold text-gray-900",children:"Service"}),r.jsx("span",{className:"font-semibold",children:ne||"-"})]}):null]})]}),k&&r.jsxs("div",{className:"print-2inch py-1 border-b-2 border-amber-500 bg-amber-50/50",children:[r.jsx("p",{className:"text-[12px] font-bold uppercase text-amber-800 mb-0.5",children:"Exchanged Out"}),w.map((e,t)=>r.jsxs("div",{className:"text-[13px] py-0.5 border-b border-amber-200 last:border-0 flex justify-between items-baseline gap-1",children:[r.jsxs("div",{className:"min-w-0 overflow-visible",children:[r.jsx("p",{className:"font-semibold leading-tight break-words",children:e.description}),e.sku&&r.jsxs("p",{className:"text-[13px] font-semibold text-gray-900",children:["SKU: ",e.sku]})]}),r.jsxs("span",{className:"shrink-0 whitespace-nowrap",children:[e.quantity,"×",e.price.toFixed(2),"=",e.total.toFixed(2)]})]},t))]}),r.jsxs("div",{className:"print-2inch py-1",children:[r.jsx("p",{className:"text-[12px] font-bold uppercase mb-0.5 border-b border-gray-400 pb-0.5",children:k?"Exchanged In":"Items"}),r.jsxs("div",{className:"text-[13px] font-semibold grid grid-cols-12 gap-0.5 py-0.5 border-b border-gray-400",children:[r.jsx("div",{className:"col-span-5",children:"Item"}),r.jsx("div",{className:"col-span-2 text-center",children:"Qty"}),r.jsx("div",{className:"col-span-2 text-center",children:"Pr"}),r.jsx("div",{className:"col-span-3 text-right",children:"Total"})]}),oe.map((e,t)=>{var a,o,i;return r.jsxs("div",{className:"border-b border-gray-200 py-0.5 text-[12px]",children:[r.jsxs("div",{className:"grid grid-cols-12 gap-x-0.5 items-baseline",children:[r.jsxs("div",{className:"col-span-5 min-w-0 overflow-visible",children:[r.jsx("p",{className:"font-semibold leading-tight break-words",children:e.description}),r.jsxs("div",{className:"text-[13px] font-semibold text-gray-900 leading-tight",children:[e.sku&&`SKU: ${e.sku}`,((i=(o=(a=e==null?void 0:e.allData)==null?void 0:a.arribute)==null?void 0:o.size)==null?void 0:i.name)&&` | ${e.size}`]})]}),r.jsx("div",{className:"col-span-2 text-center",children:e.quantity}),r.jsx("div",{className:"col-span-2 text-center",children:e.price.toFixed(2)}),r.jsx("div",{className:"col-span-3 text-right font-semibold",children:e.total.toFixed(2)})]}),(e==null?void 0:e.after_discount_amount)>0&&r.jsxs("p",{className:"text-[13px] font-semibold text-gray-900",children:["Disc: ",Number(e.after_discount_amount||0).toFixed(2)]})]},t)})]}),r.jsx("div",{className:"print-2inch border-t-2 border-gray-600 pt-1 mt-1",children:r.jsxs("div",{className:"text-[12px] space-y-0.5",children:[r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{children:"Sub-Total:"}),r.jsx("span",{className:"font-semibold",children:n.subtotal.toFixed(2)})]}),(Number(n.discount)||0)+(Number(n.discount_2nd)||0)>0&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{children:"Discount:"}),r.jsx("span",{children:((Number(n.discount)||0)+(Number(n.discount_2nd)||0)).toFixed(2)})]}),n.after_discount>0&&n.after_discount!==Number(n.total)&&r.jsxs("div",{className:"flex justify-between text-[13px] font-semibold text-gray-900",children:[r.jsx("span",{children:"After Disc:"}),r.jsx("span",{children:n.after_discount.toFixed(2)})]}),r.jsxs("div",{className:"flex justify-between border-t border-gray-400 pt-0.5 mt-0.5 font-bold text-[13px]",children:[r.jsx("span",{children:"Total:"}),r.jsx("span",{children:n.total.toFixed(2)})]}),r.jsxs("div",{className:"flex justify-between border-t border-gray-300 pt-0.5",children:[r.jsx("span",{children:"Payment:"}),r.jsx("span",{children:n.payment.toFixed(2)})]}),r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{children:"Due:"}),r.jsx("span",{className:"font-semibold",children:(n.total-n.payment).toFixed(2)})]}),re.includes("sales_invoice_due_view")&&n.previous_due>0&&r.jsxs("div",{className:"flex justify-between text-[13px] font-semibold text-gray-900",children:[r.jsx("span",{children:"Prev Due:"}),r.jsx("span",{children:n.previous_due.toFixed(2)})]})]})}),r.jsx("div",{className:"print-2inch border-t border-gray-300 pt-1 mt-1",children:r.jsxs("p",{className:"text-[13px] font-semibold leading-tight text-gray-900",children:[r.jsx("span",{className:"font-bold",children:"In Words:"})," ",n.total?ee.toWords(n.total.toFixed(2))[0].toUpperCase()+ee.toWords(n.total.toFixed(2)).slice(1):""]})}),X.footerNote&&r.jsx("div",{className:"print-2inch border-t border-gray-300 pt-1 mt-1",children:r.jsxs("p",{className:"text-[13px] font-semibold text-gray-900 leading-tight text-center",children:[r.jsx("span",{className:"font-bold",children:"NB:"})," ",X.footerNote]})}),j&&r.jsx("div",{className:"print-2inch border-t border-gray-300 pt-1 mt-1 flex flex-col items-center",children:r.jsx(ce,{value:String(j),width:1,height:22,fontSize:12,margin:0,displayValue:!0})}),r.jsxs("div",{className:"print-2inch text-center py-1.5 mt-1 border-t border-gray-300",children:[r.jsx("p",{className:"text-[13px] font-bold",children:"Thank You!"}),r.jsx("p",{className:"text-[13px] font-semibold text-gray-900 mt-0.5",children:"Powered by DATA DSS LTD"})]})]})}export{me as default};
