import{d as H,z as L,a as W,eC as G,r as o,eD as n,j as t,T as b,M as v,B as h,a2 as J,R as z,eE as K,eF as Q}from"./index-e6164346.js";import{C as U}from"./index-cde536dd.js";import{P as X}from"./index-d7588099.js";import{v as w}from"./View-afd49d05.js";import{T as D}from"./Tooltip-c38fd0c1.js";import{Z as S}from"./Zoom-393881cf.js";import{P as ee}from"./Select-9c2d8cd2.js";import{C as g}from"./Chip-548720b0.js";import"./Grow-306e2fd0.js";import"./componentStyles-00385170.js";import"./TableRow-bf4e60a0.js";import"./TableContainer-7ecd96ea.js";import"./TableHead-0c525f54.js";import"./TablePagination-b02830fa.js";import"./KeyboardArrowRight-73af71dd.js";import"./LastPage-b9dcf78c.js";import"./Toolbar-82d22fac.js";import"./MenuItem-8dd174fb.js";import"./dividerClasses-932c3e8b.js";import"./listItemTextClasses-6b253cb4.js";import"./listItemIconClasses-a58b491d.js";import"./Add-bc2f8db4.js";import"./Tabs-e9b670f1.js";import"./index-e5978b8b.js";import"./Badge-4f6d4e12.js";import"./yup-5fd5d57b.js";import"./index.esm-0a041314.js";import"./Breadcrumbs-1036f3e6.js";import"./Link-03330239.js";import"./Divider-6099014b.js";import"./TextField-db9cff08.js";import"./isMuiElement-5779af4f.js";import"./InputAdornment-59975edf.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)),[T,Y]=o.useState(null),[B,F]=o.useState(!1),[O,I]=o.useState(null),x=()=>{F(!1),Y(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}))},E=(e,l)=>{i(n({...a,page:l+1}))},M=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:E,handleChangeRowsPerPage:M})}),t.jsx(ee,{open:B,anchorEl:T,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(O),children:"Yes"}),t.jsx(z,{variant:"outlined",size:"small",onClick:x,sx:{ml:2},children:"No"})]})})]})}export{ke as default};
