import{d as H,z as L,a as W,eA as G,r as o,eB as n,j as t,T as b,M as v,B as h,a2 as J,R as z,eC as K,eD as Q}from"./index-c121b02d.js";import{C as U}from"./index-ae3694f0.js";import{P as X}from"./index-3854e5c3.js";import{v as w}from"./View-afd49d05.js";import{T as D}from"./Tooltip-4b00e924.js";import{Z as S}from"./Zoom-7d897850.js";import{P as ee}from"./Select-dd7adaf8.js";import{C as g}from"./Chip-6d6ae04e.js";import"./Grow-9a484472.js";import"./componentStyles-2d610038.js";import"./TableRow-0b65a5b3.js";import"./TableContainer-be48ac32.js";import"./TableHead-9a25be14.js";import"./TablePagination-6fddb4ff.js";import"./KeyboardArrowRight-87bf88d8.js";import"./LastPage-df7292bf.js";import"./Toolbar-600c82f3.js";import"./MenuItem-0f1fc7f8.js";import"./dividerClasses-81752629.js";import"./listItemTextClasses-27b4ea1b.js";import"./listItemIconClasses-b2c374f0.js";import"./Add-ecd3d0c0.js";import"./Tabs-e031f9f3.js";import"./index-e5978b8b.js";import"./Badge-fa1b30d0.js";import"./yup-1361ecb6.js";import"./index.esm-0c6778ff.js";import"./Breadcrumbs-77d32fc3.js";import"./Link-58b976d6.js";import"./Divider-6da4bf5c.js";import"./TextField-f9d2a024.js";import"./isMuiElement-d52f64c2.js";import"./InputAdornment-ae4c2625.js";import"./popper-f3391c26.js";function te(i,m){const s=m??"--";return i===1?t.jsx(g,{label:s,color:"warning",size:"small"}):i===2?t.jsx(g,{label:s,color:"info",size:"small"}):i===3?t.jsx(g,{label:s,color:"success",size:"small"}):t.jsx(g,{label:s,size:"small"})}function ke(){const i=H(),m=L(),{payments:{paymentsList:s,pageParams:a,paymentsCount:P,loading:A}}=W(e=>G(e)),[B,T]=o.useState(null),[Y,O]=o.useState(!1),[F,I]=o.useState(null),x=()=>{O(!1),T(null),I(null)},N=e=>{e&&i(K({id:e,params:a})),x()};o.useEffect(()=>{i(n({...a,search:"",page:1,page_size:10}))},[]);const k=({search:e})=>{i(n({...a,search:e??"",page:1,page_size:10}))},M=(e,l)=>{i(n({...a,page:l+1}))},E=e=>{i(n({...a,page:1,page_size:parseInt(e.target.value)}))},R=e=>{i(n({...a,ordering:a.ordering===`-${e}`?e:`-${e}`,page:1}))},q=e=>{i(Q(e))},$=[{title:"S.No",width:60},{title:"Code",width:120,sortable:!0,field:"code"},{title:"PO / SO",width:120},{title:"Payment Term",width:160},{title:"Vendor",width:160},{title:"Amount",width:110},{title:"Paid Amount",width:120},{title:"Balance Amount",width:130},{title:"Due Date",width:110},{title:"Status",width:110},{title:"Created On",width:120,sortable:!0,field:"created_on"},{title:"Actions",width:80}];function V(e,l,f,y,_,C,j,r,p,c,d,u){return{index:e,code:l,poSo:f,paymentTerm:y,vendor:_,amount:C,paidAmount:j,balanceAmount:r,dueDate:p,status:c,createdOn:d,actions:u}}const Z=o.useMemo(()=>s==null?void 0:s.map((e,l)=>{var r,p,c,d,u;const f=(a.page-1)*a.page_size+(l+1),y=((r=e==null?void 0:e.purchaseorder)==null?void 0:r.code)??((p=e==null?void 0:e.serviceorder)==null?void 0:p.code)??"--",_=((c=e==null?void 0:e.po_payment_term)==null?void 0:c.payment_term)??((d=e==null?void 0:e.so_payment_term)==null?void 0:d.payment_term)??"--",C=t.jsx(D,{TransitionComponent:S,title:"Click to view details",children:t.jsx(b,{sx:{color:"primary.main",cursor:"pointer",fontWeight:500},onClick:()=>m(`/pages/sidemenu/payment_request/view/${e.id}`),children:(e==null?void 0:e.code)??(e==null?void 0:e.id)})}),j=t.jsx(h,{sx:{display:"flex",gap:1,alignItems:"center"},children:t.jsx(D,{TransitionComponent:S,title:"View",children:t.jsx(h,{sx:{cursor:"pointer",display:"flex",alignItems:"center"},onClick:()=>m(`/pages/sidemenu/payment_request/view/${e.id}`),children:t.jsx("img",{src:w,alt:"view",style:{width:18,height:18}})})})});return V(f,C,y,_,((u=e==null?void 0:e.vendor)==null?void 0:u.name)??"--",e!=null&&e.amount?Number(e.amount).toFixed(2):"--",e!=null&&e.paid_amount?Number(e.paid_amount).toFixed(2):"--",e!=null&&e.balance_amount?Number(e.balance_amount).toFixed(2):"--",e!=null&&e.due_date?v(e.due_date).format("DD-MM-YYYY"):"--",te(e==null?void 0:e.status,e==null?void 0:e.status_name),e!=null&&e.created_on?v(e.created_on).format("DD-MM-YYYY"):"--",j)}),[s,a]);return t.jsxs(h,{sx:{display:"grid",gap:.5,mt:-1.7},children:[t.jsx(X,{title:"Payment Requests",addButtonLabel:"",breadcrumbs:[],showAddButton:!1,applabel:"Payments",model:"payment",count:P,handleSearch:k,fetchapi:n,showFilterButton:!1,openFilter:q,pageParams:a,buttons:{list:!0,thumbnail:!1,grid:!1}}),t.jsx(J,{children:t.jsx(U,{showPagination:!0,columns:$,rows:Z??[],count:P,page:a.page,pageSize:a.page_size,loading:A,handleSort:R,handleChangePage:M,handleChangeRowsPerPage:E})}),t.jsx(ee,{open:Y,anchorEl:B,onClose:x,anchorOrigin:{vertical:"top",horizontal:"right"},transformOrigin:{vertical:"bottom",horizontal:"left"},children:t.jsxs(h,{sx:{p:2},children:[t.jsx(b,{variant:"subtitle1",gutterBottom:!0,children:"Are you sure you want to delete this record?"}),t.jsx(z,{variant:"contained",color:"primary",onClick:()=>N(F),children:"Yes"}),t.jsx(z,{variant:"outlined",size:"small",onClick:x,sx:{ml:2},children:"No"})]})})]})}export{ke as default};
