1import{u as U,r as N,m as E,j as e,e as u}from"./vendor-CjDHlqhy.js";import{P as L}from"./page-template-DZDekKmP.js";import{I as W}from"./InvoiceProSubNav-dPLcKvUp.js";/* empty css */import{aj as z}from"./ui-CNs-pDNo.js";import"./utils-nrJLb57x.js";import"./app-layout-VqcNefif.js";import"./app-shared-BRksQZ7A.js";import"./app-D7gEHbXj.js";/* empty css *//* empty css */import"./language-switcher-DIr2GLrQ.js";import"./language-DZ9KMQZW.js";import"./motion-Bvx8bI_5.js";import"./CompanySupportChatWidget-DjUg0DKq.js";import"./recharts-B3sRJ26l.js";import"./input-error-CB2dSVrq.js";import"./theme-DClJHNB7.js";import"./WatilySiteWebPushProvider-D_666GSH.js";import"./WebPushOptIn-CHvvL7UY.js";import"./watily-ui-shell-CFP-EonI.js";const d=i=>new Intl.NumberFormat("en-US",{minimumFractionDigits:2,maximumFractionDigits:2}).format(Number(i)||0),A=(i,n)=>{const[v,c]=i.split("-").map(Number),r=new Date(v,c-1+n,1);return"".concat(r.getFullYear(),"-").concat(String(r.getMonth()+1).padStart(2,"0"))};function ue({selectedMonth:i,summary:n,allPayments:v,partners:c=[],employees:r=[],prefillPartnerId:m=null,isSuperAdmin:D=!1}){var w,k;const{t:a}=U(),[T,p]=N.useState(!!m),[y,g]=N.useState(!1),h=N.useRef(null),P=m!=null?m:c.length===1?c[0].id:null,[b,f]=i.split("-").map(Number),{data:t,setData:l,post:R,processing:Z,reset:$,errors:_}=E({type:m?"commission":"vat",partner_id:P,account_type:"bank",employee_rate_id:r.length===1?r[0].rate_id:null,amount:"",payment_date:new Date().toISOString().split("T")[0],month_for:i,note:"",reference:"",year:b,quarter:Math.ceil(f/3)}),o=D?"admin.invoice-pro":"invoice-pro",q=new Date(b,(f||1)-1,1).toLocaleDateString("en-US",{month:"long",year:"numeric"}),S=s=>u.get(route("".concat(o,".payments")),{month:s}),V=s=>{var M;s.preventDefault();const j=()=>{p(!1),$()};if(t.type==="vat"){if(y)return;g(!0),(M=h.current)!=null||(h.current=crypto.randomUUID()),u.post(route("invoice-pro.reports.payments.store"),{year:t.year,quarter:t.quarter,account_type:t.account_type,amount:t.amount,paid_at:t.payment_date,reference:t.reference,notes:t.note,request_key:h.current},{preserveScroll:!0,onSuccess:()=>{h.current=null,j()},onFinish:()=>g(!1)});return}if(t.type==="employee"){const x=r.find(B=>B.rate_id===t.employee_rate_id);if(!x)return;u.post(route("".concat(o,".employee-commissions.payouts.store")),{user_id:x.user_id,rate_id:x.user_id?null:x.rate_id,month:t.month_for,amount:t.amount,payment_date:t.payment_date,note:t.note},{preserveScroll:!0,onSuccess:j});return}R(route("".concat(o,".payments.store")),{onSuccess:j})},F=s=>{if(confirm(a("Do you want to delete this payment?"))){if(s.type==="employee"){u.delete(route("".concat(o,".employee-commissions.payouts.destroy"),s.id),{preserveScroll:!0});return}u.delete(route("".concat(o,".payments.destroy"),s.id))}},H=[{label:a("Record Payment"),icon:e.jsx(z,{className:"h-4 w-4"}),variant:"default",onClick:()=>p(!0)}],C=Number(n.vat_remaining_cumulative)<0;return e.jsxs(L,{title:a("Manage Payments"),description:a("Manage your VAT and commission payments"),url:route("".concat(o,".payments")),actions:H,breadcrumbs:[{title:a("Dashboard"),href:route("dashboard")},{title:a("Invoice Pro"),href:route("".concat(o,".index"))},{title:a("Manage Payments"),href:route("".concat(o,".payments"))}],children:[e.jsx(W,{section:"payments",active:"payments"}),e.jsxs("div",{className:"ipa",dir:"ltr","data-accent":"classic",children:[e.jsxs("div",{className:"grid-12 grid",children:[e.jsxs("div",{className:"card span-6",children:[e.jsx("div",{className:"card-head",children:e.jsxs("h3",{children:[e.jsx("span",{className:"ico",style:{background:"var(--bad-soft)",color:"var(--bad)"},children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M21 7H3v10h18V7Zm-2 8H5V9h14v6ZM7 11h2v2H7v-2Zm8 0h2v2h-2v-2Z"})})}),a("VAT")]})}),e.jsxs("div",{className:"net-row",children:[e.jsx("div",{className:"nm",children:a("Due")}),e.jsxs("div",{className:"v",children:[d(n.vat_total_due)," SAR"]})]}),e.jsxs("div",{className:"net-row",children:[e.jsx("div",{className:"nm",children:a("Paid")}),e.jsxs("div",{className:"v",style:{color:"var(--good)"},children:[d(n.vat_paid)," SAR"]})]}),e.jsxs("div",{className:"net-row total",style:{borderTop:"1px dashed var(--line)"},children:[e.jsx("div",{className:"nm",children:a(C?"VAT Credit":"Remaining")}),e.jsxs("div",{className:"v",style:{fontSize:18,color:C?"var(--good)":"var(--bad)"},children:[d(Math.abs(Number(n.vat_remaining_cumulative)))," SAR"]})]})]}),e.jsxs("div",{className:"card span-6",children:[e.jsx("div",{className:"card-head",children:e.jsxs("h3",{children:[e.jsx("span",{className:"ico",style:{background:"var(--violet-soft)",color:"var(--violet)"}
1,children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M19 5 5 19l-1.4-1.4L17.6 3.6 19 5ZM6.5 9a2.5 2.5 0 1 1 0-5 2.5 2.5 0 0 1 0 5Zm11 11a2.5 2.5 0 1 1 0-5 2.5 2.5 0 0 1 0 5Z"})})}),a("Commission")]})}),e.jsxs("div",{className:"net-row",children:[e.jsx("div",{className:"nm",children:a("Due")}),e.jsxs("div",{className:"v",children:[d(n.commission)," SAR"]})]}),e.jsxs("div",{className:"net-row",children:[e.jsx("div",{className:"nm",children:a("Paid")}),e.jsxs("div",{className:"v",style:{color:"var(--good)"},children:[d(n.commission_paid)," SAR"]})]}),e.jsxs("div",{className:"net-row total",style:{borderTop:"1px dashed var(--line)"},children:[e.jsx("div",{className:"nm",children:a("Remaining")}),e.jsxs("div",{className:"v",style:{fontSize:18,color:"var(--violet)"},children:[d(n.commission_remaining_cumulative)," SAR"]})]})]})]}),e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"card-head",children:[e.jsxs("h3",{children:[e.jsx("span",{className:"ico",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M3 6h18v3H3V6Zm0 5h18v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-7Zm3 4h6v2H6v-2Z"})})}),a("Payments History")]}),e.jsxs("div",{className:"month-nav",children:[e.jsx("button",{title:a("Previous month"),onClick:()=>S(A(i,-1)),children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M15 6 9 12l6 6"})})}),e.jsx("div",{className:"v",children:q.toUpperCase()}),e.jsx("button",{title:a("Next month"),onClick:()=>S(A(i,1)),children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M9 6l6 6-6 6"})})})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:a("Type")}),e.jsx("th",{style:{textAlign:"right"},children:a("Amount")}),e.jsx("th",{children:a("Payment Date")}),e.jsx("th",{children:a("For Month")}),e.jsx("th",{children:a("Note")}),e.jsx("th",{style:{textAlign:"right"},children:a("Actions")})]})}),e.jsx("tbody",{children:v.map(s=>e.jsxs("tr",{children:[e.jsxs("td",{children:[e.jsxs("span",{className:"badge",style:s.type==="vat"?{background:"var(--bad-soft)",color:"var(--bad)"}:s.type==="employee"?{background:"var(--good-soft)",color:"var(--good)"}:{background:"var(--violet-soft)",color:"var(--violet)"},children:[e.jsx("span",{className:"dot"}),s.type_label]}),s.partner_name&&e.jsx("div",{className:"date",style:{marginTop:2},children:s.partner_name}),s.quarter_label&&e.jsx("div",{className:"date",style:{marginTop:2},children:s.quarter_label})]}),e.jsxs("td",{className:"amount",style:{textAlign:"right"},children:[d(s.amount),e.jsx("span",{className:"unit",children:"SAR"})]}),e.jsx("td",{className:"date",children:s.payment_date}),e.jsx("td",{className:"date",children:s.month_for}),e.jsx("td",{children:s.note||"â"}),e.jsx("td",{children:e.jsx("div",{className:"actions-cell",children:e.jsx("button",{className:"icon-mini del",title:a("Delete"),onClick:()=>F(s),children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2m-3 5v6m-4-6v6M5 6l1 14a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2l1-14"})})})})})]},"".concat(s.type,"-").concat(s.id)))})]})}),v.length===0&&e.jsxs("div",{className:"empty",children:[e.jsx("div",{className:"ei",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M3 6h18v3H3V6Zm0 5h18v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-7Z"})})}),e.jsx("div",{className:"et",children:a("No payments found")})]})]}),T&&e.jsx("div",{className:"ipa-modal",children:e.jsxs("div",{className:"box",children:[e.jsx("h3",{children:a("Record New Payment")}),e.jsxs("form",{onSubmit:V,children:[e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:a("Type")}),e.jsxs("select",{className:"ctl",value:t.type,onChange:s=>l("type",s.target.value),children:[e.jsx("option",{value:"vat",children:a("VAT")}),e.jsx("option",{value:"commission",children:a("Partner commission")}),e.jsx("option",{value:"employee",children:a("Employee commission")})]})]}),t.type==="employee"&&e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:a("Employee")}),e.jsxs("select",{className:"ctl",value:(w=t.employee_rate_id)!=null?w:"",onCh
1ange:s=>l("employee_rate_id",s.target.value?Number(s.target.value):null),required:!0,children:[r.length!==1&&e.jsx("option",{value:"",children:a("Select employee")}),r.map(s=>e.jsx("option",{value:s.rate_id,children:s.name},s.rate_id))]}),r.length===0&&e.jsx("p",{className:"ferr",children:a("No employees with a commission rate yet")})]}),t.type==="commission"&&c.length>0&&e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:a("Partner")}),e.jsxs("select",{className:"ctl",value:(k=t.partner_id)!=null?k:"",onChange:s=>l("partner_id",s.target.value?Number(s.target.value):null),required:!0,children:[c.length>1&&e.jsx("option",{value:"",children:a("Select partner")}),c.map(s=>e.jsx("option",{value:s.id,children:s.name},s.id))]}),_.partner_id&&e.jsx("p",{className:"ferr",children:_.partner_id})]}),t.type==="vat"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:a("Year")}),e.jsx("input",{className:"ctl",type:"number",min:"2018",max:"2100",value:t.year,onChange:s=>l("year",Number(s.target.value)),required:!0})]}),e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:a("Quarter")}),e.jsx("select",{className:"ctl",value:t.quarter,onChange:s=>l("quarter",Number(s.target.value)),children:[1,2,3,4].map(s=>e.jsxs("option",{value:s,children:["Q",s]},s))})]})]}),e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:a("Payment reference / SADAD")}),e.jsx("input",{className:"ctl",type:"text",maxLength:100,value:t.reference,onChange:s=>l("reference",s.target.value)})]})]}),e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:a("Amount")}),e.jsx("input",{className:"ctl",type:"number",step:"0.01",value:t.amount,onChange:s=>l("amount",s.target.value),required:!0})]}),e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:a("Payment account")}),e.jsxs("select",{className:"ctl",value:t.account_type,onChange:s=>l("account_type",s.target.value),children:[e.jsx("option",{value:"bank",children:a("Bank")}),e.jsx("option",{value:"cash",children:a("Cashbox")})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:a("Payment Date")}),e.jsx("input",{className:"ctl",type:"date",value:t.payment_date,onChange:s=>l("payment_date",s.target.value),required:!0})]}),t.type!=="vat"&&e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:a("For Month")}),e.jsx("input",{className:"ctl",type:"month",value:t.month_for,onChange:s=>l("month_for",s.target.value),required:!0})]})]}),e.jsxs("div",{className:"field",children:[e.jsx("label",{className:"flbl",children:a("Note")}),e.jsx("input",{className:"ctl",type:"text",value:t.note,onChange:s=>l("note",s.target.value)})]}),e.jsxs("div",{className:"actions",children:[e.jsx("button",{type:"button",className:"btn ghost",onClick:()=>p(!1),children:a("Cancel")}),e.jsx("button",{type:"submit",className:"btn accent",disabled:Z||y,children:a("Save")})]})]})]})})]})]})}export{ue as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.