import{r as a,c as T,E as A,a as d,b as t}from"./app-DTeOhhdM.js";import{A as V,a as $}from"./AuthenticatedLayout-DNj-hWy1.js";import{T as H}from"./toast.esm-CLj0hUIX.js";import{C as f}from"./calendar.esm-DqUk2xOX.js";import"./html2canvas.esm-CBrSDip1.js";import{a as M}from"./helper-Gzy5oJm-.js";import"./index-CL55CtA3.js";import{A as P}from"./autocomplete.esm-wKYwH1zm.js";import"./createLucideIcon-0QtVMxKe.js";import"./defualtLogo-C0dU5cUD.js";import"./index.esm-xhUioO7y.js";import"./index.esm-DydXoyuW.js";import"./index.esm-BlFJNgmX.js";import"./inputtext.esm-DvYkLvTo.js";import"./asyncToGenerator-BfWTt6ZC.js";function me({auth:u}){var b;const{permission:n,warehouseList:g}=a.useContext(T),[w,U]=a.useState("All"),[o,j]=a.useState(),[r,N]=a.useState(),[m,p]=a.useState([]),[l,q]=a.useState([]),[i,W]=a.useState([]),[B,S]=a.useState([]),[D,v]=a.useState([]);a.useRef();const[y,x]=a.useState(null),_=a.useRef(null);new A;const[C,R]=a.useState({customer:"",supplier:""}),[G,O]=a.useState([]),[F,z]=a.useState(null),[J,K]=a.useState(!1),[c,h]=a.useState(!1);a.useEffect(()=>{d.get(route("sales.report.shop")).then(e=>{S(e.data.shop)}),n.includes("report_super_admin_access")||p(u.user.shop_id)},[]);const L=async()=>{h(!0);let e=new FormData;e.append("type",w),e.append("start",o),e.append("end",r),e.append("supplier_id",F),e.append("customer_id",y),e.append("location_id",m);let s=await d.post("disocuntsearch",e);return[...s.data.details,...s.data.master]},k=async()=>{const e=await L(),s=await window.generatePDFView(e,window.reportModes.saleDiscountReport,!1,"Sales Discount Report",o,r);M(s,"saleDiscountReport.pdf"),h(!1)};`${new Date(o).toLocaleDateString("en-US")}`,r&&`${new Date(r).toLocaleDateString("en-US")}`;const E=e=>{setTimeout(()=>{d.post(route("customer-search"),{data:e.query}).then(s=>{v(s.data.customer)})},250)},I=e=>t.jsx("div",{className:"country-item",children:t.jsxs("div",{children:[e.name," (",e.code,") (",e.user_type,")"]})});return l.reduce((e,s)=>e+Number(s.price)*Number(s.qty),0),l.reduce((e,s)=>e+Number(s.after_discount),0),l.reduce((e,s)=>e+Number(s.total),0),i.reduce((e,s)=>e+Number(s.total),0),i.reduce((e,s)=>e+Number(s.after_discount),0),i.reduce((e,s)=>e+Number(s.grand_total),0),t.jsxs(V,{user:u.user,header:t.jsxs(t.Fragment,{children:[t.jsx("h2",{className:"text-skin-header font-medium ",children:"Sales Discount Report"})," ",t.jsxs("p",{className:"text-skin-sub-header font-semibold text-xs",children:[" ","Home - SalesDiscountReport"]})]}),headerButton:t.jsx(t.Fragment,{}),children:[t.jsx(H,{ref:_}),t.jsx("div",{className:"card min-h-screen ",children:t.jsx("div",{className:"bg-gray-100  flex items-center justify-center py-12 px-2 sm:px-6 lg:px-8",children:t.jsxs("div",{className:"w-full max-w-5xl bg-white rounded-2xl shadow-lg border border-gray-200 p-4 sm:p-8 md:p-10",children:[t.jsx("h2",{className:"text-2xl md:text-3xl font-bold text-center text-gray-800 mb-8 md:mb-10 tracking-tight",children:"Filter Report Criteria"}),t.jsxs("div",{className:"grid grid-cols-12 gap-6",children:[t.jsxs("div",{className:"col-span-12 sm:col-span-4",children:[t.jsx("label",{htmlFor:"start-date",className:"block text-sm font-medium text-gray-600 mb-2",children:"Starting Date"}),t.jsx(f,{value:o,onChange:e=>j(e.value),className:"w-full h-[41px] text-[14px] rounded-lg shadow-sm"})]}),t.jsxs("div",{className:"col-span-12 sm:col-span-4",children:[t.jsx("label",{htmlFor:"end-date",className:"block text-sm font-medium text-gray-600 mb-2",children:"End Date"}),t.jsx(f,{value:r,onChange:e=>N(e.value),className:"w-full h-[41px] text-[14px] rounded-lg shadow-sm"})]}),[1,2,3,4,5,6].includes((b=window==null?void 0:window.setting)==null?void 0:b.business_id)&&t.jsxs("div",{className:"col-span-12 sm:col-span-4",children:[t.jsx("label",{htmlFor:"search-customer",className:"block text-sm font-medium text-gray-600 mb-2",children:"Search Customer/Retailer"}),t.jsx(P,{value:C.customer,suggestions:D,completeMethod:E,"aria-label":"customer_id",itemTemplate:I,onChange:e=>{e.value.name?x(e.value.id):x(null),R(s=>({...s,customer:e.value.name?`${e.value.name} (${e.value.code})`:e.value}))},dropdownAriaLabel:"Select Customer",className:"w-full h-10"})]}),n.includes("report_super_admin_access")&&t.jsxs("div",{className:"col-span-12 sm:col-span-4",children:[t.jsx("label",{className:"block text-sm font-medium text-gray-600 mb-2",children:"Warehouse/Shop"}),t.jsx($,{value:m,options:g,optionLabel:"name",optionValue:"id",placeholder:"Select a Warehouse",showClear:!0,disabled:!n.includes("report_super_admin_access"),onChange:e=>p(e.target.value??null),className:"w-full rounded-lg shadow-sm",inputClassName:"h-11 px-4 text-sm"})]})]}),t.jsx("div",{className:"mt-10 flex justify-center",children:t.jsx("button",{type:"button",onClick:k,disabled:c,className:`px-6 py-3 rounded-xl font-semibold text-sm min-w-[160px] flex items-center justify-center gap-2 transition duration-200
                    ${c?"bg-blue-400 cursor-not-allowed":"bg-blue-600 hover:bg-blue-700"}
                    text-white shadow-md`,children:c?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin","aria-hidden":"true"}),t.jsx("span",{className:"text-xs font-medium",children:"Generating..."})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{role:"img","aria-label":"View Report",children:"🔍"}),"View Report"]})})})]})})})]})}export{me as default};
