import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./react-BatatxyT.js";import{l as n}from"./api-672io9y2.js";import{r,s as i}from"./utils-BO1RPuol.js";import{t as a}from"./download-CcXpNtZ6.js";import{So as o,Wr as s,da as c,za as l}from"./index-CsuVxiRQ.js";import{a as u,i as d,r as f,t as p}from"./offer-cover-page-DADj1NAY.js";import{t as m}from"./company_stamp-CCGmsRWq.js";var h=e(t(),1),g=e(u(),1),_=i();function v(e){return Number(e).toLocaleString(`en-IN`,{minimumFractionDigits:2,maximumFractionDigits:2})}function y(e){if(e===0)return`ZERO`;let t=[``,`ONE`,`TWO`,`THREE`,`FOUR`,`FIVE`,`SIX`,`SEVEN`,`EIGHT`,`NINE`,`TEN`,`ELEVEN`,`TWELVE`,`THIRTEEN`,`FOURTEEN`,`FIFTEEN`,`SIXTEEN`,`SEVENTEEN`,`EIGHTEEN`,`NINETEEN`],n=[``,``,`TWENTY`,`THIRTY`,`FORTY`,`FIFTY`,`SIXTY`,`SEVENTY`,`EIGHTY`,`NINETY`],r=e=>e<20?t[e]:e<100?n[Math.floor(e/10)]+(e%10?` `+t[e%10]:``):e<1e3?t[Math.floor(e/100)]+` HUNDRED`+(e%100?` AND `+r(e%100):``):e<1e5?r(Math.floor(e/1e3))+` THOUSAND`+(e%1e3?` `+r(e%1e3):``):e<1e7?r(Math.floor(e/1e5))+` LAKH`+(e%1e5?` `+r(e%1e5):``):r(Math.floor(e/1e7))+` CRORE`+(e%1e7?` `+r(e%1e7):``),i=Math.floor(e),a=Math.round((e-i)*100),o=r(i)+` RUPEES`;return a>0&&(o+=` AND `+r(a)+` PAISE`),o+` ONLY`}function b({so:e}){let t=(0,h.useRef)(null),[i,u]=(0,h.useState)(!1),{data:b}=c(),{data:x}=n(),{data:S}=s(e.client,{skip:!e.client}),C=e.line_items||[],w=Math.round(Number(e.grand_total)||0),T=Number(e.total_tax)||0,E=Number(e.discount_amount)||0,D=b?.address?b.address.split(`
`).join(`, `):``,O={code:e.code,tender_code:e.source_tender_code||``,tender_name:``,created_at:e.created_at,client_name:e.client_name,project_location:``,company_name:`Sales Order`,client_address:S?.address||``};return(0,_.jsxs)(`div`,{className:`space-y-4`,children:[(0,_.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,_.jsxs)(l,{size:`sm`,variant:`outline`,onClick:async()=>{u(!0);try{let n=t.current;if(!n)return;let r=1123,i=new d({orientation:`portrait`,unit:`mm`,format:`a4`}),a=n.querySelectorAll(`.a4-page`);for(let e=0;e<a.length;e++){let t=document.createElement(`iframe`);t.style.cssText=`position:fixed;top:-9999px;left:-9999px;width:794px;height:${r}px;border:none;`,document.body.appendChild(t),await new Promise(n=>{let i=t.contentDocument;i.open(),i.write(`<!DOCTYPE html><html><head><style>
* { margin:0; padding:0; box-sizing:border-box; font-family:Calibri,Arial,sans-serif; -webkit-print-color-adjust:exact; print-color-adjust:exact; }
body { background:#fff; color:#000; font-size:14px; }
table { border-collapse:collapse; width:100%; }
.cover-page { width:100%; background:#fff; }
.inner-page { width:100%; background:#fff; display:flex; flex-direction:column; min-height:${r}px; }
.page-header { padding:10px 16px 8px 16px; border-bottom:1px solid #ddd; display:flex; justify-content:space-between; align-items:flex-start; }
.page-body { flex:1; padding:12px 16px; }
.page-footer { border-top:2px solid #1a3a5c; padding:5px 16px; text-align:center; font-size:12px; color:#555; }
.page-footer .company { font-weight:700; color:#1a3a5c; }
.dark-heading { background:#1a3a5c !important; color:#fff !important; font-weight:700; font-size:15px; padding:8px 12px; }
.dark-row td { background:#1a3a5c !important; color:#fff !important; font-weight:700; }
.thead-row th { background:#c8d0d8 !important; }
</style></head><body>${a[e].outerHTML}</body></html>`),i.close(),t.onload=()=>n(),setTimeout(n,800)});let n=t.contentDocument.body.firstElementChild,o=await(0,g.default)(n,{scale:2,useCORS:!0,allowTaint:!0,backgroundColor:`#ffffff`,width:794,height:r,windowWidth:794,windowHeight:r});document.body.removeChild(t),e>0&&i.addPage(),i.addImage(o.toDataURL(`image/jpeg`,.95),`JPEG`,0,0,210,297)}let o=URL.createObjectURL(i.output(`blob`)),s=document.createElement(`a`);s.href=o,s.download=`SalesOrder-${e.code}.pdf`,s.click(),URL.revokeObjectURL(o)}finally{u(!1)}},disabled:i,children:[(0,_.jsx)(a,{className:`mr-1 size-4`}),` `,i?`Generating PDF...`:`Download PDF`]}),(0,_.jsxs)(l,{size:`sm`,onClick:()=>{let n=t.current;if(!n)return;let r=new URL(f,window.location.origin).href,i=new URL(m,window.location.origin).href,a=n.querySelector(`.inner-page`),o=n.querySelector(`.cover-page`),s=a?.querySelector(`.page-header`),c=a?.querySelector(`.page-footer`),l=a?.querySelector(`.page-body`),u=e=>e.replace(/src="[^"]*finallogo[^"]*"/g,`src="${r}"`).replace(/src="[^"]*company_stamp[^"]*"/g,`src="${i}"`),d=u(o?.innerHTML||``),p=u(s?.innerHTML||``),h=u(c?.innerHTML||``),g=u(l?.innerHTML||``),_=`<!DOCTYPE html><html><head><title>Sales Order - ${e.code}</title>
<style>
* { margin:0; padding:0; box-sizing:border-box; -webkit-print-color-adjust:exact !important; print-color-adjust:exact !important; }
body { font-family:Calibri,Arial,sans-serif; background:#fff; font-size:14px; }
.dark-heading { background:#1a3a5c !important; color:#fff !important; font-weight:700; font-size:15px; padding:8px 12px; }
.dark-row td { background:#1a3a5c !important; color:#fff !important; font-weight:700; }
.thead-row th { background:#c8d0d8 !important; }
table { border-collapse:collapse; width:100%; font-size:14px; }
#cover { page-break-after:always; break-after:page; }
#layout { width:100%; border-collapse:collapse; table-layout:fixed; }
#layout thead { display:table-header-group; }
#layout tfoot { display:table-footer-group; }
#layout tbody { display:table-row-group; }
#layout thead td { padding:8px 16px 6px; border-bottom:1px solid #ddd; background:#fff; }
#layout tfoot td { border-top:2px solid #1a3a5c; padding:5px 16px; text-align:center; font-size:12px; color:#555; background:#fff; }
#layout tfoot .company { font-weight:700; color:#1a3a5c; }
.page-body { padding:12px 16px; }
@page { size:A4 portrait; margin:0; }
</style></head><body>
<div id="cover">${d}</div>
<table id="layout">
<thead><tr><td><div style="display:flex;justify-content:space-between;align-items:flex-start">${p}</div></td></tr></thead>
<tfoot><tr><td>${h}</td></tr></tfoot>
<tbody><tr><td><div class="page-body" style="font-size:14px;color:#000">${g}</div></td></tr></tbody>
</table>
</body></html>`,v=document.createElement(`iframe`);v.style.cssText=`position:fixed;top:-10000px;left:-10000px;width:210mm;height:297mm;border:none;`,document.body.appendChild(v);let y=v.contentDocument||v.contentWindow?.document;y&&(y.open(),y.write(_),y.close(),v.onload=()=>{setTimeout(()=>{v.contentWindow?.focus(),v.contentWindow?.print(),setTimeout(()=>document.body.removeChild(v),1e3)},500)})},children:[(0,_.jsx)(o,{className:`mr-1 size-4`}),` Print`]})]}),(0,_.jsx)(`style`,{children:`
        @media screen {
          .a4-preview-wrap { background: #e8eaed; padding: 24px; }
          .a4-page { width:210mm; min-height:297mm; background:#fff; margin:0 auto 24px auto; box-shadow:0 2px 16px rgba(0,0,0,0.15); overflow:hidden; display:flex; flex-direction:column; }
          .page-header { padding:10px 16px 8px 16px; border-bottom:1px solid #ddd; display:flex; justify-content:space-between; align-items:flex-start; }
          .page-footer { border-top:2px solid #1a3a5c; padding:5px 16px; text-align:center; font-size:12px; color:#555; }
          .page-footer .company { font-weight:700; color:#1a3a5c; }
          .page-body { flex:1; padding:12px 16px; }
        }
        @media print {
          .inner-page .page-header { position:fixed !important; top:0; left:0; right:0; width:100%; background:#fff; z-index:1000; padding:10px 16px 8px 16px; border-bottom:1px solid #ddd; display:flex; justify-content:space-between; align-items:flex-start; }
          .inner-page .page-footer { position:fixed !important; bottom:0; left:0; right:0; width:100%; background:#fff; z-index:1000; border-top:2px solid #1a3a5c; padding:5px 16px; text-align:center; font-size:12px; color:#555; }
          .inner-page .page-body { margin-top:110px; margin-bottom:60px; }
          .cover-page .page-header, .cover-page .page-footer { display:none !important; }
        }
      `}),(0,_.jsxs)(`div`,{ref:t,className:`a4-preview-wrap`,children:[(0,_.jsx)(`div`,{className:`a4-page cover-page`,children:(0,_.jsx)(p,{sq:O})}),(0,_.jsxs)(`div`,{className:`a4-page inner-page`,children:[(0,_.jsxs)(`div`,{className:`page-header`,children:[(0,_.jsxs)(`div`,{style:{fontSize:`13px`,lineHeight:`1.7`,color:`#333`},children:[(0,_.jsxs)(`div`,{children:[`Sales Order no.: `,(0,_.jsx)(`strong`,{children:e.code})]}),(0,_.jsxs)(`div`,{children:[`Reference: `,e.source_tender_code||`—`]}),(0,_.jsxs)(`div`,{children:[`Date: `,r(e.created_at)]}),(0,_.jsx)(`div`,{children:`Page no. 2`})]}),(0,_.jsx)(`div`,{style:{textAlign:`right`},children:(0,_.jsx)(`img`,{src:f,alt:`Logo`,style:{height:`80px`,objectFit:`contain`}})})]}),(0,_.jsxs)(`div`,{className:`page-body`,style:{fontFamily:`Calibri, Arial, sans-serif`,fontSize:`14px`,color:`#000`},children:[(0,_.jsxs)(`div`,{style:{display:`flex`,gap:`40px`,marginBottom:`16px`},children:[(0,_.jsxs)(`div`,{style:{flex:1},children:[(0,_.jsx)(`div`,{style:{fontWeight:700,fontSize:`13px`,marginBottom:`6px`},children:`INVOICE ADDRESS:`}),(0,_.jsxs)(`div`,{style:{fontSize:`13px`,lineHeight:`1.7`},children:[b?.company_name&&(0,_.jsx)(`div`,{children:b.company_name}),b?.address&&(0,_.jsx)(`div`,{style:{whiteSpace:`pre-line`},children:b.address}),b?.state_name&&(0,_.jsxs)(`div`,{children:[b.state_name,b?.pincode?`, ${b.pincode}`:``]})]})]}),(0,_.jsxs)(`div`,{style:{flex:1},children:[(0,_.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`},children:[(0,_.jsx)(`div`,{style:{fontWeight:700,fontSize:`13px`,marginBottom:`6px`},children:`DELIVERY ADDRESS:`}),(0,_.jsxs)(`div`,{style:{fontSize:`13px`},children:[(0,_.jsx)(`div`,{children:`Date:`}),(0,_.jsx)(`div`,{style:{fontWeight:600},children:r(e.created_at)})]})]}),(0,_.jsxs)(`div`,{style:{fontSize:`13px`,lineHeight:`1.7`},children:[(S?.name||e.client_name)&&(0,_.jsx)(`div`,{children:S?.name||e.client_name}),S?.address&&(0,_.jsx)(`div`,{style:{whiteSpace:`pre-line`},children:S.address}),S?.state_name&&(0,_.jsx)(`div`,{children:S.state_name})]})]})]}),(0,_.jsx)(`div`,{className:`dark-heading`,style:{background:`#1a3a5c`,color:`#fff`,fontWeight:700,fontSize:`15px`,padding:`8px 12px`,marginBottom:0},children:`Price Specification`}),(0,_.jsxs)(`table`,{style:{width:`100%`,borderCollapse:`collapse`,fontSize:`12px`,tableLayout:`fixed`},children:[(0,_.jsxs)(`colgroup`,{children:[(0,_.jsx)(`col`,{style:{width:`40px`}}),(0,_.jsx)(`col`,{}),(0,_.jsx)(`col`,{style:{width:`40px`}}),(0,_.jsx)(`col`,{style:{width:`100px`}}),(0,_.jsx)(`col`,{style:{width:`100px`}})]}),(0,_.jsx)(`thead`,{children:(0,_.jsxs)(`tr`,{style:{background:`#c8d0d8`},className:`thead-row`,children:[(0,_.jsx)(`th`,{style:{border:`1px solid #aaa`,padding:`5px 6px`,textAlign:`left`},children:`Pos.`}),(0,_.jsx)(`th`,{style:{border:`1px solid #aaa`,padding:`5px 6px`,textAlign:`left`},children:`Item`}),(0,_.jsx)(`th`,{style:{border:`1px solid #aaa`,padding:`5px 6px`,textAlign:`center`},children:`Qty`}),(0,_.jsxs)(`th`,{style:{border:`1px solid #aaa`,padding:`5px 6px`,textAlign:`right`},children:[`Unit Price`,(0,_.jsx)(`br`,{}),`INR`]}),(0,_.jsxs)(`th`,{style:{border:`1px solid #aaa`,padding:`5px 6px`,textAlign:`right`},children:[`Total Price`,(0,_.jsx)(`br`,{}),`INR`]})]})}),(0,_.jsx)(`tbody`,{children:C.length===0?(0,_.jsx)(`tr`,{children:(0,_.jsx)(`td`,{colSpan:5,style:{border:`1px solid #aaa`,padding:`12px`,textAlign:`center`,color:`#888`},children:`No line items`})}):C.map((e,t)=>(0,_.jsxs)(`tr`,{style:{background:t%2==0?`#fff`:`#f7f9fb`},children:[(0,_.jsx)(`td`,{style:{border:`1px solid #ccc`,padding:`5px 6px`,verticalAlign:`top`,textAlign:`center`},children:t+1}),(0,_.jsxs)(`td`,{style:{border:`1px solid #ccc`,padding:`5px 6px`,verticalAlign:`top`},children:[(0,_.jsx)(`div`,{style:{fontWeight:700,color:`#c8a000`},children:e.item_code}),(0,_.jsx)(`div`,{children:e.item_name||e.item_description})]}),(0,_.jsx)(`td`,{style:{border:`1px solid #ccc`,padding:`5px 6px`,verticalAlign:`top`,textAlign:`center`},children:Number(e.quantity).toLocaleString()}),(0,_.jsx)(`td`,{style:{border:`1px solid #ccc`,padding:`5px 6px`,verticalAlign:`top`,textAlign:`right`,fontFamily:`monospace`},children:v(e.rate||0)}),(0,_.jsx)(`td`,{style:{border:`1px solid #ccc`,padding:`5px 6px`,verticalAlign:`top`,textAlign:`right`,fontFamily:`monospace`},children:v(e.amount||e.total_amount||0)})]},e.id||t))})]}),(0,_.jsxs)(`table`,{style:{width:`100%`,borderCollapse:`collapse`,fontSize:`12px`,tableLayout:`fixed`},children:[(0,_.jsxs)(`colgroup`,{children:[(0,_.jsx)(`col`,{style:{width:`40px`}}),(0,_.jsx)(`col`,{}),(0,_.jsx)(`col`,{style:{width:`40px`}}),(0,_.jsx)(`col`,{style:{width:`100px`}}),(0,_.jsx)(`col`,{style:{width:`100px`}})]}),(0,_.jsxs)(`tbody`,{children:[E>0&&(0,_.jsxs)(`tr`,{children:[(0,_.jsx)(`td`,{colSpan:3,style:{border:`1px solid #ccc`,padding:`4px 6px`}}),(0,_.jsx)(`td`,{style:{border:`1px solid #ccc`,padding:`4px 6px`,textAlign:`right`},children:`Discount`}),(0,_.jsxs)(`td`,{style:{border:`1px solid #ccc`,padding:`4px 6px`,textAlign:`right`,fontFamily:`monospace`},children:[`- `,v(E)]})]}),T>0&&(0,_.jsxs)(`tr`,{children:[(0,_.jsx)(`td`,{colSpan:3,style:{border:`1px solid #ccc`,padding:`4px 6px`}}),(0,_.jsx)(`td`,{style:{border:`1px solid #ccc`,padding:`4px 6px`,textAlign:`right`},children:`Tax Amount`}),(0,_.jsx)(`td`,{style:{border:`1px solid #ccc`,padding:`4px 6px`,textAlign:`right`,fontFamily:`monospace`},children:v(T)})]}),(0,_.jsxs)(`tr`,{style:{background:`#1a3a5c`},className:`dark-row`,children:[(0,_.jsx)(`td`,{colSpan:3,style:{border:`1px solid #aaa`,padding:`6px`,color:`#fff`,fontWeight:700},children:y(w)}),(0,_.jsx)(`td`,{style:{border:`1px solid #aaa`,padding:`6px`,textAlign:`right`,color:`#fff`,fontWeight:700},children:`NET AMOUNT`}),(0,_.jsx)(`td`,{style:{border:`1px solid #aaa`,padding:`6px`,textAlign:`right`,color:`#fff`,fontWeight:700,fontFamily:`monospace`},children:v(w)})]})]})]}),(0,_.jsx)(`div`,{className:`dark-heading`,style:{background:`#1a3a5c`,color:`#fff`,fontWeight:700,fontSize:`15px`,padding:`8px 12px`,marginTop:`16px`},children:`Commercial Terms`}),(0,_.jsx)(`table`,{style:{width:`100%`,borderCollapse:`collapse`,marginBottom:`20px`},children:(0,_.jsxs)(`tbody`,{children:[[{icon:`🚚`,label:`Delivery Terms`,value:e.delivery_terms_name||e.delivery_terms||``},{icon:`⏩`,label:`Shipping Method`,value:``},{icon:`💳`,label:`Payment Terms`,value:e.payment_terms_name||e.payment_terms||``},{icon:`📅`,label:`Order Date`,value:r(e.created_at)},{icon:`💬`,label:`Remarks`,value:e.remarks||``}].map(e=>(0,_.jsxs)(`tr`,{children:[(0,_.jsx)(`td`,{style:{width:`40px`,textAlign:`center`,verticalAlign:`middle`,border:`1px solid #ccc`,padding:`8px 4px`,color:`#1a3a5c`,fontSize:`18px`},children:e.icon}),(0,_.jsx)(`td`,{style:{width:`160px`,fontWeight:600,fontSize:`13px`,border:`1px solid #ccc`,padding:`8px 10px`,verticalAlign:`middle`},children:e.label}),(0,_.jsx)(`td`,{style:{fontSize:`13px`,border:`1px solid #ccc`,padding:`8px 10px`,verticalAlign:`middle`},children:e.value})]},e.label)),e.tnc_items?.map((e,t)=>(0,_.jsxs)(`tr`,{children:[(0,_.jsx)(`td`,{style:{width:`40px`,textAlign:`center`,verticalAlign:`middle`,border:`1px solid #ccc`,padding:`8px 4px`}}),(0,_.jsx)(`td`,{style:{width:`160px`,fontWeight:600,fontSize:`13px`,border:`1px solid #ccc`,padding:`8px 10px`,verticalAlign:`middle`}}),(0,_.jsxs)(`td`,{style:{fontSize:`13px`,border:`1px solid #ccc`,padding:`8px 10px`,verticalAlign:`middle`,color:`#1a6bb5`},children:[t+1,`. `,e.content]})]},e.id))]})}),(0,_.jsxs)(`div`,{style:{marginTop:`16px`,fontSize:`14px`,lineHeight:`1.8`},children:[(0,_.jsx)(`div`,{children:`We trust that you find our order confirmation of interest and we look forward to your continued support.`}),(0,_.jsx)(`div`,{style:{marginTop:`12px`,color:`#1a6bb5`},children:`Best regards`}),(0,_.jsxs)(`div`,{style:{marginTop:`12px`},children:[x?.full_name&&(0,_.jsx)(`div`,{children:x.full_name}),b?.company_name&&(0,_.jsx)(`div`,{children:b.company_name}),b?.email&&(0,_.jsxs)(`div`,{children:[`E-mail: `,(0,_.jsx)(`span`,{style:{color:`#1a6bb5`},children:b.email}),b?.phone?`  /  Phone: ${b.phone}`:``]})]})]}),(0,_.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`flex-end`,marginTop:`16px`},children:[(0,_.jsxs)(`div`,{style:{textAlign:`left`},children:[(0,_.jsx)(`img`,{src:m,alt:`Stamp`,style:{height:`60px`,objectFit:`contain`,marginBottom:`8px`,display:`block`}}),(0,_.jsx)(`div`,{style:{borderTop:`1px solid #666`,paddingTop:`4px`,width:`120px`,fontSize:`13px`,fontWeight:600},children:`Client Signature`})]}),(0,_.jsxs)(`div`,{style:{textAlign:`right`},children:[x?.signature&&(0,_.jsx)(`img`,{src:x.signature.startsWith(`http`)?x.signature:`${window.location.origin}${x.signature}`,alt:`Signature`,style:{height:`40px`,objectFit:`contain`,marginBottom:`4px`,display:`block`,marginLeft:`auto`}}),(0,_.jsxs)(`div`,{style:{fontSize:`13px`,color:`#555`,marginBottom:`2px`},children:[`For `,e.client_name]}),(0,_.jsx)(`div`,{style:{borderTop:`1px solid #666`,paddingTop:`4px`,fontSize:`13px`,fontWeight:600},children:`Authorized Signatory`})]})]})]}),(0,_.jsxs)(`div`,{className:`page-footer`,children:[b?.company_name&&(0,_.jsx)(`span`,{className:`company`,children:b.company_name}),b?.address&&(0,_.jsxs)(`span`,{children:[` | `,D]}),b?.state_name&&(0,_.jsxs)(`span`,{children:[`, `,b.state_name,b?.pincode?` - ${b.pincode}`:``]}),b?.email&&(0,_.jsxs)(`span`,{children:[` | `,b.email]}),b?.phone&&(0,_.jsxs)(`span`,{children:[` | `,b.phone]})]})]})]})]})}export{b as t};