PageSourceSearch

https://www.zr3i.com/assets/PartnerLoans-DHnXX66t.js

js zr3i.com collected 2026-09-25 19:37:37 UTC 10,284 bytes, 1 lines download raw bytes

1import{r as d,j as t}from"./vendor-react-DnPnnzcV.js";import{u as T,r as B,s as N,l as $,p as a,b as G,t as P}from"./index-BWFVt2sG.js";import{s as U,b as Y,f as z,a as W,u as H,v as J}from"./loans-Ckwl4JXe.js";import{E as K,a as Q}from"./ExportCsvButton-Brr4npAw.js";import"./vendor-query-CvVCWwM3.js";import"./vendor-supabase-2Rdar6Gf.js";import"./loader-circle-D9bK8qqy.js";import"./download-IgN3g1Fl.js";const X="id, partner_id, farm_id, reference, purpose, requested_amount, approved_amount, currency, term_months, monitoring_interval_days, status, decision_note, decided_at, monitoring_starts_on, created_at";function ie(){const{lang:s}=T(),{userId:A,isLoading:S}=B(),[v,y]=d.useState("loading"),[h,O]=d.useState([]),[f,R]=d.useState("open"),[m,F]=d.useState(null),[L,Z]=d.useState({}),[E,M]=d.useState({}),[D,_]=d.useState(null),j=d.useCallback(async()=>{if(!A)return;y("loading");const{data:e,error:n}=await N.from("finance_loan_cases").select(X).order("created_at",{ascending:!1}).limit(300);if(n){$.warn("partner loan cases load failed",n),y(n.code==="42501"?"denied":"error");return}const o=e??[],x=o.map(i=>i.id);let p=[];if(x.length>0){const{data:i}=await N.from("finance_disbursements").select("id, loan_case_id, amount, currency, disbursed_on, method, reference").in("loan_case_id",x);p=i??[]}const b=[...new Set(o.map(i=>i.farm_id))];let g={};if(b.length>0){const{data:i}=await N.from("farms").select("id, name").in("id",b);g=Object.fromEntries((i??[]).map(I=>[I.id,I.name]))}O(U(Y(o,p,g))),y("ready")},[A]);d.useEffect(()=>{S||j()},[S,j]);const c=d.useMemo(()=>z(h,f),[h,f]),l=d.useMemo(()=>W(h),[h]),r={title:a({en:"Loan cases",ar:"ملفات التمويل"},s),sub:a({en:"Your institution's cases on shared farms. Zr3i shows field evidence only — the decision is yours.",ar:"ملفات مؤسستك على المزارع المشاركة. Zr3i بتعرض أدلة الحقل بس — القرار قرارك."},s),loading:a({en:"Loading…",ar:"جارٍ التحميل…"},s),denied:a({en:"You don't have partner access.",ar:"مالكش صلاحية شريك."},s),error:a({en:"Couldn't load the cases.",ar:"تعذّر تحميل الملفات."},s),retry:a({en:"Try again",ar:"حاول تاني"},s),empty:a({en:"No cases in this view.",ar:"مفيش ملفات في العرض ده."},s),open:a({en:"Under review",ar:"تحت المراجعة"},s),approved:a({en:"Approved",ar:"موافق عليه"},s),due:a({en:"Re-check due",ar:"مراجعة مستحقة"},s),all:a({en:"All",ar:"الكل"},s),total:a({en:"Cases",ar:"الملفات"},s),approvedValue:a({en:"Approved value",ar:"قيمة الموافقات"},s),disbursed:a({en:"Paid out",ar:"المصروف"},s),outstanding:a({en:"Not yet paid",ar:"لسه ما اتصرفش"},s),farm:a({en:"Farm",ar:"المزرعة"},s),requested:a({en:"Requested",ar:"المطلوب"},s),nextCheck:a({en:"Next farm re-check",ar:"المراجعة الجاية للمزرعة"},s),overdue:a({en:"Re-check overdue",ar:"المراجعة متأخرة"},s),every:a({en:"Every",ar:"كل"},s),days:a({en:"days",ar:"يوم"},s),amount:a({en:"Approved amount",ar:"المبلغ الموافق عليه"},s),note:a({en:"Decision note",ar:"ملاحظة القرار"},s),approve:a({en:"Record approval",ar:"تسجيل الموافقة"},s),decline:a({en:"Record decline",ar:"تسجيل الرفض"},s),close:a({en:"Close case",ar:"إغلاق الملف"},s),saving:a({en:"Saving…",ar:"جارٍ الحفظ…"},s),saveFailed:a({en:"Couldn't save that.",ar:"تعذّر الحفظ."},s),needAmount:a({en:"Enter an approved amount above zero.",ar:"اكتب مبلغ موافقة أكبر من صفر."},s),needNote:a({en:"Add a note explaining the decline.",ar:"اكتب سبب الرفض."},s),governance:a({en:"Zr3i never recommends approving or declining. Field signals are evidence to check.",ar:"Zr3i عمرها ما بتوصي بالموافقة أو الرفض. إشارات الحقل دليل للمراجعة بس."},s)},w=s==="ar"?"ar-EG":"en-GB",q=new Intl.DateTimeFormat(w,{dateStyle:"medium"}),k=new Intl.NumberFormat(w,{maximumFractionDigits:0}
1),u=(e,n)=>new Intl.NumberFormat(w,{style:"currency",currency:n,maximumFractionDigits:0}).format(e),V={under_review:r.open,approved:r.approved,declined:a({en:"Declined",ar:"مرفوض"},s),withdrawn:a({en:"Withdrawn",ar:"منسحب"},s),closed:a({en:"Closed",ar:"مغلق"},s)};async function C(e,n){const o=E[e.id],x=n==="approved"?o?Number(o):e.approvedAmount??e.requestedAmount??null:null,p=L[e.id]??e.decisionNote??"",b=J({status:n,approvedAmount:x,note:p});if(b.length>0){_(b.includes("note_required")?r.needNote:r.needAmount);return}_(null),F(e.id);const{error:g}=await N.rpc("finance_record_decision",{_case:e.id,_status:n,_approved_amount:x,_note:p.trim()||null,_monitoring_interval_days:null});if(F(null),g){$.warn("loan decision failed",g),_(r.saveFailed);return}P("partner_loan_decision",{case_id:e.id}),await j()}return t.jsxs("div",{className:"mx-auto w-full max-w-4xl px-4 py-6",children:[t.jsx(G,{title:`${r.title} | Zr3i`,description:r.sub,noIndex:!0}),t.jsx("h1",{className:"text-2xl font-semibold",children:r.title}),t.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:r.sub}),v==="loading"&&t.jsx("p",{className:"mt-6 text-sm text-muted-foreground",children:r.loading}),v==="denied"&&t.jsx("p",{className:"mt-6 rounded-2xl border bg-card p-4 text-sm",children:r.denied}),v==="error"&&t.jsxs("div",{className:"mt-6 rounded-2xl border bg-card p-4",children:[t.jsx("p",{className:"text-sm",children:r.error}),t.jsx("button",{type:"button",onClick:()=>void j(),className:"mt-3 h-11 rounded-xl bg-primary px-5 text-sm font-semibold text-primary-foreground",children:r.retry})]}),v==="ready"&&t.jsxs(t.Fragment,{children:[t.jsx("dl",{className:"mt-4 grid grid-cols-2 gap-3 sm:grid-cols-4",children:[{k:r.total,v:k.format(l.total)},{k:r.due,v:k.format(l.overdueChecks)},{k:r.approvedValue,v:u(l.approvedAmount,l.currency)},{k:r.disbursed,v:u(l.disbursedAmount,l.currency)}].map(e=>t.jsxs("div",{className:"rounded-2xl border bg-card p-4",children:[t.jsx("dt",{className:"text-xs text-muted-foreground",children:e.k}),t.jsx("dd",{className:"mt-1 text-lg font-semibold",children:e.v})]},e.k))}),t.jsx("div",{className:"mt-4",children:t.jsx(K,{kind:"loan-book",build:()=>Q(c),partnerId:c[0]?.partnerId??null,purpose:"loan_monitoring",disabled:c.length===0,label:{en:"Download loan book (CSV)",ar:"تنزيل دفتر القروض (CSV)"}})}),t.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:["open","approved","due","all"].map(e=>t.jsx("button",{type:"button",onClick:()=>R(e),"aria-pressed":f===e,className:`h-11 rounded-xl px-4 text-sm font-medium ${f===e?"bg-primary text-primary-foreground":"border border-border"}`,children:e==="open"?r.open:e==="approved"?r.approved:e==="due"?r.due:r.all},e))}),D&&t.jsx("p",{className:"mt-3 text-sm text-destructive",children:D}),c.length===0?t.jsx("p",{className:"mt-6 rounded-2xl border bg-card p-4 text-sm text-muted-foreground",children:r.empty}):t.jsx("ul",{className:"mt-4 space-y-3",children:c.map(e=>t.jsxs("li",{className:"rounded-2xl border bg-card p-4",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsxs("div",{children:[t.jsx("p",{className:"font-semibold",children:e.farmName??r.farm}),t.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.reference??e.id.slice(0,8)," · ",q.format(new Date(e.createdAt))]})]}),t.jsx("span",{className:"rounded-full bg-muted px-3 py-1 text-xs font-medium",children:V[e.status]})]}),t.jsxs("dl",{className:"mt-3 grid grid-cols-2 gap-3 text-sm sm:grid-cols-4",children:[t.jsxs("div",{children:[t.jsx("dt",{className:"text-xs text-muted-foreground",children:r.requested}),t.jsx("dd",{children:e.requestedAmount==null?"—":u(e.requestedAmount,e.currency)})]}),t.jsxs("div",{children:[t.jsx("dt",{className:"text-xs text-muted-foreground",children:r.disbursed}),t.jsx("dd",{children:u(e.disbursedAmount,e.currency)})]}),t.jsxs("div",{children:[t.jsx("dt",{className:"text-xs text-muted-foreground",children:r.outstanding}),t.jsx("dd",{children:u(H(e),e.currency)})]}),t.jsxs("div",{children:[t.jsx("dt",{className:"text-xs text-muted-foreground",children:r.nextCheck}),t.jsxs("dd",{children:[e.nextCheckOn?q.format(new Date(`${e.nextCheckOn}T00:00:00Z`)):"—",t.jsxs("span",{className:"block text-xs text-muted-foreground",children:[r.every," ",k.format(e.monitoringIntervalDays)," ",r.days]})]})]})]}),e.checkOverdue&&t.jsx("p",{className:"mt-3 rounded-xl bg-destructive/10 px-3 py-2 text-xs text-destructive",children:r.overdue}),e.status==="under_review"&&t.jsxs("div",{className:"mt-4 space-y-3",children:[t.jsx("label",{className:"block text-xs text-muted-foreground",htmlFor:`amt-${e.id}`,children:r.amount}),t.jsx("input",{id:`amt-${e.id}`,inputMode:"decimal",value:E[e.id]??(e.requestedAmount??"").toString(),onChange:n=>M(o=>({...o,[e.id]:n.target.value})),className:"h-11 w-full rounded-xl border border-border bg-background px-3 text-sm"}),t.jsx("label",{className:"block text-xs text-muted-foreground",htmlFor:`note-${e.id}`,children:r.note}),t.jsx("textarea",{id:`note-${e.id}`,rows:2,value:L[e.id]??"",onChange:n=>Z(o=>({...o,[e.id]:n.target.value})),className:"w-full rounded-xl border border-border bg-background p-3 text-sm"}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx("button",{type:"button",disabled:m===e.id,onClick:()=>void C(e,"approved"),className:"h-11 rounded-xl bg-primary px-4 text-sm font-semibold text-primary-foreground disabled:opacity-60",children:m===e.id?r.saving:r.approve}),t.jsx("button",{type:"button",disabled:m===e.id,onClick:()=>void C(e,"declined"),className:"h-11 rounded-xl border border-border px-4 text-sm font-medium disabled:opacity-60",children:r.decline})]})]}),e.status==="approved"&&t.jsx("button",{type:"button",disabled:m===e.id,onClick:()=>void C(e,"closed"),className:"mt-4 h-11 rounded-xl border border-border px-4 text-sm font-medium disabled:opacity-60",children:m===e.id?r.saving:r.close}),e.decisionNote&&t.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:e.decisionNote})]},e.id))}),t.jsx("p",{className:"mt-6 text-xs text-muted-foreground",children:r.governance})]})]})}export{ie 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.