PageSourceSearch

https://arvin-bookstore.com/_next/static/chunks/pages/admin/accounting/expenses-fad028ce126bf105.js

js arvin-bookstore.com collected 2026-10-02 22:34:04 UTC 30,407 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7623],{40327:function(e,t,a){(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/accounting/expenses",function(){return a(12122)}])},12122:function(e,t,a){"use strict";a.r(t);var l=a(85893),s=a(41664),r=a.n(s),n=a(67294),i=a(91444),c=a(90723),d=a(2881),o=a(16053),u=a(67827),x=a(21168);let m="bg-white text-slate-900 placeholder:text-slate-400 border border-slate-300 rounded-xl px-3 py-2 text-sm",p={category:"",company:"",method:"",payment_status:"",status:"",q:"",from:"",to:"",min_amount:"",max_amount:""};function h(){let{can:e,site:t}=(0,c.uu)(),[a,s]=(0,n.useState)([]),[h,b]=(0,n.useState)([]),[j,g]=(0,n.useState)(p),[v,y]=(0,n.useState)({}),[f,N]=(0,n.useState)(1),[_,k]=(0,n.useState)([]),[w,C]=(0,n.useState)(0),[S,O]=(0,n.useState)(null),[A,E]=(0,n.useState)(""),[q,M]=(0,n.useState)({doc_date:t.today_jalali,title:"",category:"",amount:"",payer:"",method:"bank",company:t.brand,payment_status:"paid",description:""}),[V,P]=(0,n.useState)({}),[Z,z]=(0,n.useState)(!1),[Y,D]=(0,n.useState)(null),[J,F]=(0,n.useState)(null),[R,X]=(0,n.useState)(null),[G,I]=(0,n.useState)(""),T=(0,n.useRef)(null),$=e("manage_expenses"),B=(0,n.useCallback)(async()=>{let e=await (0,o.Og)({...v,page:f,page_size:50});e.ok?(k(e.data.results),C(e.data.count),O(e.data.totals),b(e.data.allowed_companies||[]),E("")):(k([]),E(e.error.detail))},[v,f]);(0,n.useEffect)(()=>{B()},[B]),(0,n.useEffect)(()=>{(0,o.If)().then(e=>{e.ok&&s(e.data)})},[]);let Q=async e=>{let t=await (0,o.f4)(e);t.ok&&D(t.data)},W=async()=>{let e=(0,x.NR)(q);if(!e.ok){P(e.errors);return}P({}),z(!0);let t=await (0,o._Q)(e.body);if(z(!1),t.ok){i.Am.success("هزینهٔ ".concat(t.data.display_number," ثبت شد.")),M({...q,title:"",amount:"",description:""}),B(),D(t.data);return}i.Am.error(t.error.detail)},H=async()=>{if(!Y||!J)return;let e=(0,x.Y0)(J);if(!e.ok){P(e.errors);return}P({}),z(!0);let t=await (0,o.So)(Y.id,e.body);z(!1),t.ok?(i.Am.success("سند به‌روز شد."),D(t.data),F(null),B()):i.Am.error(t.error.detail)},K=async e=>{if(!Y||!e)return;let t=(0,x.ai)(e);if(t){i.Am.error(t);return}z(!0);let a=await (0,o.tJ)(Y.id,e);z(!1),T.current&&(T.current.value=""),a.ok?(i.Am.success("پیوست ثبت شد."),Q(Y.id),B()):i.Am.error(a.error.detail)},L=async e=>{if(!Y)return;z(!0);let t=await (0,o.C6)(Y.id,e);z(!1),t.ok?(i.Am.success("پیوست حذف شد (فایل برای سابقه نگه داشته می‌شود)."),Q(Y.id),B()):i.Am.error(t.error.detail)},U=async()=>{if(!R)return;z(!0);let e=await (0,o.yw)(R.id,G);z(!1),e.ok?(i.Am.success("سند ".concat(R.display_number," ابطال شد.")),X(null),I(""),(null==Y?void 0:Y.id)===R.id&&D(e.data),B()):i.Am.error(e.error.detail)},ee=e=>{e.preventDefault();let t=(0,x.Mz)(j);if(!t.ok){i.Am.error(t.error);return}N(1),y(t.params)},et=Math.max(1,Math.ceil(w/50)),ea=h.length?h:[{value:t.brand,label:x.Zq[t.brand]||t.brand_label}];return(0,l.jsxs)(c.D2,{title:"هزینه‌ها",subtitle:"ثبت ریز و روزانهٔ هزینه‌ها با پیوست مستندات؛ تاریخ، مبلغ، دسته و شرکت سند پس از ثبت تغییر نمی‌کنند",actions:(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(r(),{href:"/admin/accounting/reports/expenses",className:"px-4 py-2 rounded-xl border border-slate-300 text-sm",children:"گزارش تفکیکی"}),(0,l.jsx)(r(),{href:"/admin/accounting/expense-categories",className:"px-4 py-2 rounded-xl border border-slate-300 text-sm",children:"دسته‌بندی‌ها"})]}),children:[$&&(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200 p-4 space-y-3","data-testid":"expense-form",children:[(0,l.jsx)("h2",{className:"font-bold",children:"ثبت هزینهٔ جدید"}),(0,l.jsxs)("div",{className:"grid gap-2 md:grid-cols-4",children:[(0,l.jsx)("input",{className:m,value:q.title,placeholder:"عنوان هزینه","aria-label":"عنوان هزینه",onChange:e=>M({...q,title:e.target.value})}),(0,l.jsxs)("select",{className:m,value:q.category,"aria-label":"دسته‌بندی",onChange:e=>M({...q,category:e.target.value}),children:[(0,l.jsx)("option",{value:"",children:"دسته‌بندی هزینه"}),a.filter(e=>e.is_active).map(e=>(0,l.jsx)("option",{value:e.id,children:e.name},e.id))]}),(0,l.jsx)("input",{className:m,value:q.amount,inputMode:"numeric",placeholder:"مبلغ (تومان)","aria-label":"مبلغ",onChange:e=>M({...q,amount:e.target.value})}),(0,l.jsx)("input",{className:m,value:q.doc_date,placeholder:"تاریخ ۱۴۰۵/۰۶/۲۵","aria-label":"تاریخ هزینه",onChange:e=>M({...q,doc_date:e.target.value})}),(0,l.jsx)("input",{className:m,value:q.payer,placeholder:"پرداخت‌کننده","aria-label":"پرداخت‌کننده",onChange:e=>M({...q,payer:e.target.value})}),(0,l.jsx)("select",{className:m,value:q.method,"aria-label":"روش پرداخت",onChange:e=>M({...q,method:e.target.value}),children:Object.entries(x.Jg).map(e=>
1{let[t,a]=e;return(0,l.jsx)("option",{value:t,children:a},t)})}),(0,l.jsx)("select",{className:m,value:q.payment_status,"aria-label":"وضعیت پرداخت",onChange:e=>M({...q,payment_status:e.target.value}),children:Object.entries(x.tV).map(e=>{let[t,a]=e;return(0,l.jsx)("option",{value:t,children:a},t)})}),(0,l.jsx)("select",{className:m,value:q.company,"aria-label":"شرکت مرتبط",onChange:e=>M({...q,company:e.target.value}),children:ea.map(e=>(0,l.jsx)("option",{value:e.value,children:e.label},e.value))}),(0,l.jsx)("input",{className:"".concat(m," md:col-span-4"),value:q.description,placeholder:"شرح و توضیحات (اختیاری)","aria-label":"توضیحات",onChange:e=>M({...q,description:e.target.value})})]}),Object.entries(V).map(e=>{let[t,a]=e;return(0,l.jsx)("div",{className:"text-xs text-rose-700",role:"alert",children:a},t)}),(0,l.jsx)("button",{className:"px-4 py-2 rounded-xl bg-slate-900 text-white text-sm disabled:opacity-50",disabled:Z,onClick:W,children:"ثبت هزینه"})]}),(0,l.jsxs)("form",{onSubmit:ee,className:"bg-white rounded-2xl border border-slate-200 p-4 grid gap-2 md:grid-cols-5",children:[(0,l.jsxs)("select",{className:m,value:j.category,"aria-label":"فیلتر دسته",onChange:e=>g({...j,category:e.target.value}),children:[(0,l.jsx)("option",{value:"",children:"همهٔ دسته‌ها"}),a.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name},e.id))]}),(0,l.jsxs)("select",{className:m,value:j.company,"aria-label":"فیلتر شرکت",onChange:e=>g({...j,company:e.target.value}),children:[(0,l.jsx)("option",{value:"",children:"همهٔ شرکت‌ها"}),Object.entries(x.Zq).map(e=>{let[t,a]=e;return(0,l.jsx)("option",{value:t,children:a},t)})]}),(0,l.jsxs)("select",{className:m,value:j.method,"aria-label":"فیلتر روش",onChange:e=>g({...j,method:e.target.value}),children:[(0,l.jsx)("option",{value:"",children:"همهٔ روش‌ها"}),Object.entries(x.Jg).map(e=>{let[t,a]=e;return(0,l.jsx)("option",{value:t,children:a},t)})]}),(0,l.jsxs)("select",{className:m,value:j.payment_status,"aria-label":"فیلتر وضعیت پرداخت",onChange:e=>g({...j,payment_status:e.target.value}),children:[(0,l.jsx)("option",{value:"",children:"پرداخت‌شده و نشده"}),Object.entries(x.tV).map(e=>{let[t,a]=e;return(0,l.jsx)("option",{value:t,children:a},t)})]}),(0,l.jsxs)("select",{className:m,value:j.status,"aria-label":"فیلتر وضعیت سند",onChange:e=>g({...j,status:e.target.value}),children:[(0,l.jsx)("option",{value:"",children:"اسناد ثبت‌شده"}),(0,l.jsx)("option",{value:"active",children:"فقط ثبت‌شده"}),(0,l.jsx)("option",{value:"cancelled",children:"فقط ابطال‌شده"})]}),(0,l.jsx)("input",{className:m,value:j.from,placeholder:"از تاریخ","aria-label":"از تاریخ",onChange:e=>g({...j,from:e.target.value})}),(0,l.jsx)("input",{className:m,value:j.to,placeholder:"تا تاریخ","aria-label":"تا تاریخ",onChange:e=>g({...j,to:e.target.value})}),(0,l.jsx)("input",{className:m,value:j.min_amount,inputMode:"numeric",placeholder:"از مبلغ","aria-label":"از مبلغ",onChange:e=>g({...j,min_amount:e.target.value})}),(0,l.jsx)("input",{className:m,value:j.max_amount,inputMode:"numeric",placeholder:"تا مبلغ","aria-label":"تا مبلغ",onChange:e=>g({...j,max_amount:e.target.value})}),(0,l.jsx)("input",{className:m,value:j.q,placeholder:"جستجو در عنوان، شرح، پرداخت‌کننده یا شمارهٔ سند","aria-label":"جستجو",onChange:e=>g({...j,q:e.target.value})}),(0,l.jsx)("button",{type:"submit",className:"px-4 py-2 rounded-xl bg-slate-900 text-white text-sm",children:"اعمال فیلتر"})]}),A&&(0,l.jsx)(c.qX,{tone:"error",children:A}),S&&(0,l.jsxs)("div",{className:"text-sm text-slate-700","data-testid":"expense-totals",children:[(0,u.YS)(S.count)," سند \xb7 جمع: ",(0,l.jsx)("b",{children:(0,u.dw)(S.total)})," تومان",S.unpaid>0&&(0,l.jsxs)(l.Fragment,{children:[" \xb7 پرداخت‌نشده: ",(0,l.jsx)("b",{className:"text-rose-700",children:(0,u.dw)(S.unpaid)})," تومان"]})]}),(0,l.jsx)("div",{className:"bg-white rounded-2xl border border-slate-200 overflow-x-auto",children:(0,l.jsxs)("table",{className:"w-full text-sm",children:[(0,l.jsx)("thead",{className:"bg-slate-50 text-slate-600",children:(0,l.jsxs)("tr",{children:[(0,l.jsx)("th",{className:"p-3 text-right",children:"سند"}),(0,l.jsx)("th",{className:"p-3 text-right",children:"عنوان"}),(0,l.jsx)("th",{className:"p-3 text-right",children:"دسته"}),(0,l.jsx)("th",{className:"p-3",children:"مبلغ (تومان)"}),(0,l.jsx)("th",{className:"p-3",children:"تاریخ"}),(0,l.jsx)("th",{className:"p-3",children:"شرکت"}),(0,l.jsx)("th",{className:"p-3",children:"پرداخت"}),(0,l.jsx)("th",{className:"p-3"})]})}),(0,l.jsxs)("tbody",{children:[_.map(e=>(0,l.jsxs)("tr",{className:"border-t border-slate-100","data-testid":"expense-".concat(e.id),children:[(0,l.jsxs)("td",{className:"p-3",children:[(0,l.jsx)("span",{dir:"ltr",className:"whitespace-nowrap",children:e.display_number}),"cancelled"===e.status&&(0,l.jsx)("div",{className:"text-[11px] text-rose-700",children:"ابطال‌شده"})]}),(0,l.jsxs)("td",{className:"p-3",children:[(0,l.jsx)("button",{className:"text-sky-800 hover:underline",onClick:()=>{D(e),F(null),Q(e.id)},children:e.title}),(0,l.jsx)("div",{className:"text-xs text-slate-500",children:e.payer})]}),(0,l.jsx)("td",{className:"p-3",children:e.category.name}),(0,l.jsx)("td",{className:"p-3 text-center font-bold",children:(0,u.dw)(e.amount)}),(0,l.jsx)("td",{className:"p-3 text-center",children:(0,u.YS)(e.doc_date_jalali)}),(0,l.jsx)("td",{className:"p-3 text-center",children:e.company_label}),(0,l.jsxs)("td",{className:"p-3 text-center",children:[(0,l.jsx)("span",{className:"unpaid"===e.payment_status?"text-rose-700":"",children:e.payment_status_label}),(0,l.jsx)("div",{className:"text-xs text-slate-500",children:e.method_label})]}),(0,l.jsxs)("td",{className:"p-3 text-center whitespace-nowrap",children:[e.attachment_count>0&&(0,l.jsxs)("span",{className:"text-xs text-slate-500",children:["\uD83D\uDCCE ",(0,u.YS)(e.attachment_count)]}),"active"===e.status&&(0,l.jsx)(d.Z,{compact:!0,kind:"expense",id:e.id,displayNumber:e.display_number,onSaved:B,fields:[{key:"doc_date",label:"تاریخ",type:"date",value:e.doc_date_jalali},{key:"amount",label:"مبلغ (تومان)",type:"amount",value:e.amount},{key:"category",label:"دسته",type:"select",value:String(e.category.id),numeric:!0,options:a.filter(t=>t.is_active||t.id===e.category.id).map(e=>[String(e.id),e.name])},{key:"company",label:"شرکت",type:"select",value:e.company,options:ea.map(e=>[e.value,e.label])},{key:"title",label:"عنوان",type:"text",value:e.title},{key:"payer",label:"پرداخت‌کننده",type:"text",value:e.payer},{key:"method",label:"روش پرداخت",type:"select",value:e.method,options:Object.entries(x.Jg)},{key:"payment_status",label:"وضعیت پرداخت",type:"select",value:e.payment_status,options:Object.entries(x.tV)},{key:"description",label:"توضیحات",type:"text",value:e.description}]}),$&&"active"===e.status&&(0,l.jsx)("button",{className:"text-xs text-rose-700 mr-2",onClick:()=>{X(e),I("")},children:"ابطال"})]})]},e.id)),0===_.length&&!A&&(0,l.jsx)("tr",{children:(0,l.jsx)("td",{colSpan:8,className:"p-6 text-center text-slate-500",children:"هزینه‌ای یافت نشد."})})]})]})}),et>1&&(0,l.jsxs)("div",{className:"flex items-center justify-center gap-3 text-sm",children:[(0,l.jsx)("button",{className:"px-3 py-1 rounded-lg border border-slate-300 disabled:opacity-40",disabled:f<=1,onClick:()=>N(f-1),children:"قبلی"}),(0,l.jsxs)("span",{children:["صفحهٔ ",(0,u.YS)(f)," از ",(0,u.YS)(et)]}),(0,l.jsx)("button",{className:"px-3 py-1 rounded-lg border border-slate-300 disabled:opacity-40",disabled:f>=et,onClick:()=>N(f+1),children:"بعدی"})]}),Y&&(0,l.jsx)("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50 p-4",children:(0,l.jsxs)("div",{className:"bg-white rounded-2xl p-6 w-full max-w-2xl space-y-3 max-h-[90vh] overflow-y-auto",dir:"rtl",children:[(0,l.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h2",{className:"font-bold text-lg",children:Y.title}),(0,l.jsx)("div",{className:"text-xs text-slate-500",dir:"ltr",children:Y.display_number})]}),(0,l.jsx)("button",{className:"text-sm text-slate-500",onClick:()=>{D(null),F(null)},children:"بستن"})]}),"cancelled"===Y.status&&(0,l.jsxs)(c.qX,{tone:"warn",children:["این سند ابطال شده است: ",Y.cancel_reason]}),(0,l.jsxs)("dl",{className:"grid grid-cols-2 gap-2 text-sm",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("dt",{className:"text-xs text-slate-500",children:"مبلغ"}),(0,l.jsxs)("dd",{className:"font-bold",children:[(0,u.dw)(Y.amount)," تومان"]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("dt",{className:"text-xs text-slate-500",children:"تاریخ"}),(0,l.jsx)("dd",{children:(0,u.YS)(Y.doc_date_jalali)})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("dt",{className:"text-xs text-slate-500",children:"دسته"}),(0,l.jsx)("dd",{children:Y.category.name})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("dt",{className:"text-xs text-slate-500",children:"شرکت"}),(0,l.jsx)("dd",{children:Y.company_label})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("dt",{className:"text-xs text-slate-500",children:"ثبت‌کننده"}),(0,l.jsx)("dd",{children:Y.created_by})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("dt",{className:"text-xs text-slate-500",children:"وضعیت پرداخت"}),(0,l.jsxs)("dd",{children:[Y.payment_status_label," (",Y.method_label,")"]})]})]}),J?(0,l.jsxs)("div",{className:"space-y-2 border-t border-slate-100 pt-3",children:[(0,l.jsxs)("div",{className:"grid gap-2 md:grid-cols-2",children:[(0,l.jsx)("input",{className:m,value:J.title,"aria-label":"ویرایش عنوان",onChange:e=>F({...J,title:e.target.value})}),(0,l.jsx)("input",{className:m,value:J.payer,"aria-label":"ویرایش پرداخت‌کننده",onChange:e=>F({...J,payer:e.target.value})}),(0,l.jsx)("select",{className:m,value:J.method,"aria-label":"ویرایش روش پرداخت",onChange:e=>F({...J,method:e.target.value}),children:Object.entries(x.Jg).map(e=>
1{let[t,a]=e;return(0,l.jsx)("option",{value:t,children:a},t)})}),(0,l.jsx)("select",{className:m,value:J.payment_status,"aria-label":"ویرایش وضعیت پرداخت",onChange:e=>F({...J,payment_status:e.target.value}),children:Object.entries(x.tV).map(e=>{let[t,a]=e;return(0,l.jsx)("option",{value:t,children:a},t)})}),(0,l.jsx)("textarea",{className:"".concat(m," md:col-span-2"),rows:2,value:J.description,"aria-label":"ویرایش توضیحات",onChange:e=>F({...J,description:e.target.value})})]}),(0,l.jsx)("p",{className:"text-xs text-slate-500",children:"تاریخ، مبلغ، دسته و شرکت تغییر نمی‌کنند؛ برای اصلاح آن‌ها سند را ابطال و دوباره ثبت کنید."}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)("button",{className:"px-4 py-2 rounded-xl bg-slate-900 text-white text-sm disabled:opacity-50",disabled:Z,onClick:H,children:"ذخیره"}),(0,l.jsx)("button",{className:"px-4 py-2 rounded-xl border border-slate-300 text-sm",onClick:()=>F(null),children:"انصراف"})]})]}):(0,l.jsxs)(l.Fragment,{children:[Y.description&&(0,l.jsx)("p",{className:"text-sm text-slate-700",children:Y.description}),$&&"active"===Y.status&&(0,l.jsx)("button",{className:"text-sm text-sky-800",onClick:()=>F({title:Y.title,payer:Y.payer,method:Y.method,payment_status:Y.payment_status,description:Y.description}),children:"ویرایش عنوان، پرداخت‌کننده، روش و وضعیت"})]}),(0,l.jsxs)("div",{className:"border-t border-slate-100 pt-3 space-y-2",children:[(0,l.jsx)("h3",{className:"font-bold text-sm",children:"مستندات"}),(0,l.jsxs)("ul",{className:"text-sm space-y-1",children:[(Y.attachments||[]).map(e=>(0,l.jsxs)("li",{className:"flex items-center justify-between gap-2",children:[e.url?(0,l.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",className:"text-sky-800 hover:underline",children:e.name}):(0,l.jsx)("span",{children:e.name}),(0,l.jsxs)("span",{className:"text-xs text-slate-500",children:[(0,u.YS)(Math.max(1,Math.round(e.size/1024)))," کیلوبایت"]}),$&&"active"===Y.status&&(0,l.jsx)("button",{className:"text-xs text-rose-700",disabled:Z,onClick:()=>L(e.id),children:"حذف"})]},e.id)),0===(Y.attachments||[]).length&&(0,l.jsx)("li",{className:"text-slate-500",children:"پیوستی ثبت نشده است."})]}),$&&"active"===Y.status&&(0,l.jsx)("input",{ref:T,type:"file","aria-label":"افزودن پیوست",className:"text-sm",accept:"image/jpeg,image/png,image/webp,application/pdf",onChange:e=>{var t;return K(null===(t=e.target.files)||void 0===t?void 0:t[0])}})]})]})}),R&&(0,l.jsx)("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50 p-4",children:(0,l.jsxs)("div",{className:"bg-white rounded-2xl p-6 w-full max-w-lg space-y-3",dir:"rtl",children:[(0,l.jsxs)("h2",{className:"font-bold text-lg",children:["ابطال سند ",R.display_number]}),(0,l.jsx)("p",{className:"text-sm text-slate-700",children:"سند حذف نمی‌شود و شمارهٔ خود را نگه می‌دارد؛ فقط از گزارش‌ها کنار گذاشته می‌شود."}),(0,l.jsx)("textarea",{className:"".concat(m," w-full"),rows:2,value:G,"aria-label":"دلیل ابطال",placeholder:"دلیل ابطال (الزامی)",onChange:e=>I(e.target.value)}),(0,l.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,l.jsx)("button",{className:"px-4 py-2 rounded-xl border border-slate-300 text-sm",disabled:Z,onClick:()=>X(null),children:"انصراف"}),(0,l.jsx)("button",{className:"px-4 py-2 rounded-xl bg-rose-700 text-white text-sm disabled:opacity-50",disabled:Z,onClick:U,children:"ابطال سند"})]})]})})]})}let b=()=>(0,l.jsx)(c.ZP,{require:["view_expenses"],children:(0,l.jsx)(h,{})});b.layout="accounting",t.default=b},90723:function(e,t,a){"use strict";a.d(t,{D2:function(){return o},ZP:function(){return x},qX:function(){return u},uu:function(){return d}});var l=a(85893),s=a(67294),r=a(41664),n=a.n(r),i=a(16053);let c=(0,s.createContext)(null);function d(){let e=(0,s.useContext)(c);if(!e)throw Error("useAccounting must be used inside <AccountingGate>");return e}function o(e){let{title:t,subtitle:a,actions:s,children:r}=e;return(0,l.jsxs)("div",{dir:"rtl",className:"space-y-6 [color-scheme:light]",children:[(0,l.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h1",{className:"text-2xl font-bold text-slate-900",children:t}),a&&(0,l.jsx)("p",{className:"text-sm text-slate-500 mt-1",children:a})]}),s&&(0,l.jsx)("div",{className:"flex flex-wrap gap-2",children:s})]}),r]})}function u(e){let{tone:t="info",children:a}=e;return(0,l.jsx)("div",{className:"border rounded-xl px-4 py-3 text-sm ".concat({info:"bg-sky-50 border-sky-200 text-sky-900",warn:"bg-amber-50 border-amber-200 text-amber-900",error:"bg-rose-50 border-rose-200 text-rose-900"}[t]),children:a})}function x(e){let{require:t=[],requireAny:a=[],children:r}
1=e,[d,o]=(0,s.useState)({phase:"loading"}),x=(0,s.useCallback)(async()=>{let[e,t]=await Promise.all([(0,i.Mg)(),(0,i.Mf)()]);if(!e.ok){o({phase:"error",message:e.error.detail,code:e.error.code});return}if(!t.ok){o({phase:"error",message:t.error.detail,code:t.error.code});return}o({phase:"ready",site:e.data,isSuperuser:!!t.data.is_superuser,permissions:t.data.permissions||[]})},[]);if((0,s.useEffect)(()=>{x()},[x]),"loading"===d.phase)return(0,l.jsx)("div",{className:"flex justify-center py-20",role:"status","aria-label":"در حال بارگذاری",children:(0,l.jsx)("div",{className:"w-8 h-8 border-2 border-slate-300 border-t-slate-700 rounded-full animate-spin"})});if("error"===d.phase)return(0,l.jsx)("div",{dir:"rtl",className:"[color-scheme:light] max-w-xl mx-auto py-16",children:(0,l.jsx)(u,{tone:"error",children:d.message})});let m=function(){for(var e=arguments.length,t=Array(e),a=0;a<e;a++)t[a]=arguments[a];return d.isSuperuser||t.every(e=>d.permissions.includes(e))};return m(...t)&&(!(a.length>0)||a.some(e=>m(e)))?(0,l.jsx)(c.Provider,{value:{site:d.site,isSuperuser:d.isSuperuser,permissions:d.permissions,can:m,reload:x},children:r}):(0,l.jsxs)("div",{dir:"rtl",className:"[color-scheme:light] max-w-xl mx-auto py-16 space-y-4",children:[(0,l.jsx)(u,{tone:"warn",children:"شما دسترسی لازم برای مشاهدهٔ این بخش را ندارید."}),(0,l.jsx)(n(),{href:"/admin/accounting",className:"text-sm text-sky-700 underline",children:"بازگشت به حسابداری"})]})}},2881:function(e,t,a){"use strict";a.d(t,{Z:function(){return m}});var l=a(85893),s=a(67294),r=a(91444),n=a(90723),i=a(16053),c=a(67827);let d="bg-white text-slate-900 border border-slate-300 rounded-lg px-2 py-1 text-sm w-full",o=e=>null==e?"":String(e);function u(e,t){let a=(0,c.eZ)(t).trim();if("amount"===e.type){let t=a.replace(/[,٬\s]/g,"");return/^\d+$/.test(t)?{value:Number(t)}:{error:"\xab".concat(e.label,"\xbb باید عدد صحیح (تومان) باشد.")}}if("date"===e.type){let e=(0,c.yg)(a);return e?{value:e}:{error:"تاریخ را به شکل ۱۴۰۵/۰۷/۰۲ وارد کنید."}}return"percent"===e.type?/^\d{1,3}(\.\d{1,2})?$/.test(a)?{value:a}:{error:"\xab".concat(e.label,"\xbb درصد نامعتبر است.")}:"select"===e.type&&e.numeric?{value:Number(t)}:{value:t.trim()}}function x(e,t){let a=(0,c.eZ)(t).trim().replace(/[,٬]/g,""),l=(0,c.eZ)(o(e.value)).trim().replace(/[,٬]/g,"");return"percent"===e.type?Number(a)===Number(l):a===l}function m(e){var t,a;let{kind:c,id:m,displayNumber:p,fields:h,lines:b=[],onSaved:j,note:g,compact:v}=e,{isSuperuser:y}=(0,n.uu)(),[f,N]=(0,s.useState)(!1),[_,k]=(0,s.useState)({}),[w,C]=(0,s.useState)(""),[S,O]=(0,s.useState)(!1),[A,E]=(0,s.useState)("");if(!y)return null;let q=()=>{let e={};h.forEach(t=>{e[t.key]=o(t.value)}),b.forEach(t=>t.fields.forEach(a=>{e["".concat(t.id,".").concat(a.key)]=o(a.value)})),k(e),C(""),E(""),N(!0)},M=()=>{var e,t,a;let l={};for(let a of h){if(x(a,null!==(e=_[a.key])&&void 0!==e?e:""))continue;let s=u(a,null!==(t=_[a.key])&&void 0!==t?t:"");if(s.error)return{error:s.error};l[a.key]=s.value}let s=[];for(let e of b){let t={};for(let l of e.fields){let s=null!==(a=_["".concat(e.id,".").concat(l.key)])&&void 0!==a?a:"";if(x(l,s))continue;let r=u(l,s);if(r.error)return{error:"".concat(e.label,": ").concat(r.error)};t[l.key]=r.value}Object.keys(t).length&&s.push({id:e.id,...t})}return s.length&&(l.lines=s),{changes:l}},V=async()=>{let e=M();if(e.error){E(e.error);return}if(!e.changes||!Object.keys(e.changes).length){E("چیزی تغییر نکرده است.");return}O(!0);let t=await (0,i.NR)(c,m,w,e.changes);O(!1),t.ok?(r.Am.success("".concat(p," ویرایش شد.")),N(!1),j()):E(t.error.detail)},P=(e,s)=>(0,l.jsxs)("label",{className:"text-xs text-slate-600 space-y-1 block",children:[(0,l.jsx)("span",{children:e.label}),"select"===e.type?(0,l.jsx)("select",{className:d,"aria-label":e.label,value:null!==(t=_[s])&&void 0!==t?t:"",onChange:e=>k({..._,[s]:e.target.value}),children:(e.options||[]).map(e=>{let[t,a]=e;return(0,l.jsx)("option",{value:t,children:a},t)})}):(0,l.jsx)("input",{className:d,"aria-label":e.label,value:null!==(a=_[s])&&void 0!==a?a:"",dir:"text"===e.type?void 0:"ltr",onChange:e=>k({..._,[s]:e.target.value})})]},s);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("button",{type:"button",onClick:q,"aria-label":"ویرایش ".concat(p),className:v?"text-xs text-violet-800 ml-3":"px-4 py-2 rounded-xl border border-violet-300 text-violet-800 text-sm",children:"ویرایش (سوپرادمین)"}),f&&(0,l.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"ویرایش ".concat(p),className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50 p-4",children:(0,l.jsxs)("div",{className:"bg-white rounded-2xl p-6 w-full max-w-2xl max-h-[90vh] overflow-y-auto space-y-4",dir:"rtl",children:[(0,l.jsxs)("h2",{className:"font-bold text-lg",children:["ویرایش مستقیم ",(0,l.jsx)("span",{dir:"ltr",children:p})]}),(0,l.jsxs)("p",{className:"text-xs text-slate-600",children:["جمع‌ها، سود و حساب طرف‌حساب از روی همین اعداد دوباره حساب می‌شوند و نسخهٔ قبل و بعد در گزارش ممیزی می‌ماند.",g?" ".concat(g):""]}),h.length>0&&(0,l.jsx)("div",{className:"grid gap-3 sm:grid-cols-2",children:h.map(e=>P(e,e.key))}),b.map(e=>(0,l.jsxs)("fieldset",{className:"border border-slate-200 rounded-xl p-3",children:[(0,l.jsx)("legend",{className:"px-1 text-sm font-semibold",children:e.label}),(0,l.jsx)("div",{className:"grid gap-3 sm:grid-cols-4",children:e.fields.map(t=>P(t,"".concat(e.id,".").concat(t.key)))})]},e.id)),(0,l.jsx)("textarea",{className:d,rows:2,value:w,"aria-label":"دلیل ویرایش",placeholder:"دلیل ویرایش (الزامی)",onChange:e=>C(e.target.value)}),A&&(0,l.jsx)("div",{className:"text-sm text-rose-700",role:"alert",children:A}),(0,l.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,l.jsx)("button",{className:"px-4 py-2 rounded-xl border border-slate-300 text-sm",disabled:S,onClick:()=>N(!1),children:"انصراف"}),(0,l.jsx)("button",{className:"px-4 py-2 rounded-xl bg-violet-700 text-white text-sm disabled:opacity-50",disabled:S||!w.trim(),onClick:V,children:"ذخیرهٔ ویرایش"})]})]})})]})}},21168:function(e,t,a){"use strict";a.d(t,{Jg:function(){return s},Mz:function(){return x},NR:function(){return o},RI:function(){return i},Y0:function(){return u},Zq:function(){return n},ai:function(){return d},tV:function(){return r}});var l=a(67827);let s={cash:"نقدی",bank:"انتقال بانکی",card:"کارت به کارت",cheque:"چک",online:"پرداخت اینترنتی",other:"سایر"},r={paid:"پرداخت شده",unpaid:"پرداخت نشده"},n={arvin:"آروین",babaketab:"باباکتاب",tikbooks:"تیک‌بوک",group:"گروه (مشترک)"},i={day:"روزانه",week:"هفتگی",month:"ماهانه",year:"سالانه"},c=["image/jpeg","image/png","image/webp","application/pdf"];function d(e){return e?c.includes(e.type)?e.size?e.size>5242880?"حجم فایل بیشتر از ۵ مگابایت است.":"":"فایل خالی است.":"فقط تصویر (JPG، PNG، WEBP) یا PDF پذیرفته می‌شود.":"فایلی انتخاب نشده است."}function o(e){var t,a,i,c,d,o;let u={},x=String(null!==(t=e.title)&&void 0!==t?t:"").trim();x||(u.title="عنوان هزینه را وارد کنید.");let m=String(null!==(a=e.payer)&&void 0!==a?a:"").trim();m||(u.payer="پرداخت‌کننده را وارد کنید.");let p=(0,l.VV)(String(null!==(i=e.category)&&void 0!==i?i:"").trim());p||(u.category="دستهٔ هزینه را انتخاب کنید.");let h=(0,l.VV)(String(null!==(c=e.amount)&&void 0!==c?c:"").trim());(null===h||h<=0)&&(u.amount="مبلغ باید عدد صحیح مثبت (تومان) باشد."),s[e.method]||(u.method="روش پرداخت را انتخاب کنید."),r[e.payment_status]||(u.payment_status="وضعیت پرداخت را انتخاب کنید."),n[e.company]||(u.company="شرکت مرتبط را انتخاب کنید.");let b=(0,l.yg)(String(null!==(d=e.doc_date)&&void 0!==d?d:"").trim());if(b||(u.doc_date="تاریخ را به شکل ۱۴۰۵/۰۶/۲۳ وارد کنید."),Object.keys(u).length)return{ok:!1,errors:u};let j={doc_date:b,title:x,category:p,amount:h,payer:m,method:e.method,company:e.company,payment_status:e.payment_status},g=String(null!==(o=e.description)&&void 0!==o?o:"").trim();return g&&(j.description=g),{ok:!0,body:j}}function u(e){var t,a,l;let n={},i=String(null!==(t=e.title)&&void 0!==t?t:"").trim();i||(n.title="عنوان هزینه را وارد کنید.");let c=String(null!==(a=e.payer)&&void 0!==a?a:"").trim();return(c||(n.payer="پرداخت‌کننده را وارد کنید."),s[e.method]||(n.method="روش پرداخت را انتخاب کنید."),r[e.payment_status]||(n.payment_status="وضعیت پرداخت را انتخاب کنید."),Object.keys(n).length)?{ok:!1,errors:n}:{ok:!0,body:{title:i,payer:c,description:String(null!==(l=e.description)&&void 0!==l?l:"").trim(),method:e.method,payment_status:e.payment_status}}}function x(e){var t,a,s;let r={};for(let a of["category","company","method","payment_status","status","q"]){let l=String(null!==(t=e[a])&&void 0!==t?t:"").trim();l&&(r[a]=l)}for(let t of["min_amount","max_amount"]){let s=String(null!==(a=e[t])&&void 0!==a?a:"").trim();if(!s)continue;let n=(0,l.VV)(s);if(null===n||n<0)return{ok:!1,error:"مبلغ فیلتر باید عدد صحیح باشد."};r[t]=String(n)}for(let t of["from","to"]){let a=String(null!==(s=e[t])&&void 0!==s?s:"").trim();if(!a)continue;let n=(0,l.yg)(a);if(!n)return{ok:!1,error:"تاریخ را به شکل ۱۴۰۵/۰۶/۲۳ وارد کنید."};r[t]=n}return{ok:!0,params:r}}}},function(e){e.O(0,[9774,2888,179],function(){return e(e.s=40327)}),_N_E=e.O()}]);

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.