PageSourceSearch

https://swus-erp.lovable.app/assets/erp.imports.index-BFksC6_6.js

js swus-erp.lovable.app collected 2026-10-03 03:41:08 UTC 10,361 bytes, 1 lines download raw bytes

1import{j as e,P,r as g,L as D}from"./index-EB60i8_b.js";import{u as C}from"./useQuery-CD633ads.js";import{u as A}from"./auth-middleware-BXg-s9l0.js";import{u as R}from"./brand-context-jy_uMzVx.js";import{C as _}from"./card-CKGYtlGw.js";import{B as L}from"./button-vMBgSq5N.js";import{B as F}from"./badge-CppVMURX.js";import{g as K,d as U}from"./imports.functions-DGqd_wf8.js";import{f as N,P as S}from"./types-kolgKixS.js";import{b as W,D as E}from"./date-range-picker-B6dEgM0U.js";import{W as H}from"./warehouse-BGA232gh.js";import{P as Q}from"./plane-BC1NBz6A.js";import{T as V}from"./truck-zATajgQD.js";import{A as G}from"./arrow-right-BkyhOXqX.js";import{C as J}from"./circle-check-BadlvWHx.js";import{P as X}from"./plus-erq3DUUs.js";import{T as Y}from"./trending-up-CKeVRNSP.js";import{W as Z}from"./wallet-BPFjTZVM.js";import{T as z}from"./triangle-alert-BXBiVDuy.js";import{C as ee}from"./container-TlEpjt0K.js";import{A as te}from"./arrow-up-right-OBA_Jewa.js";import{A as se}from"./arrow-down-right-DG0t4f7j.js";import"./use-my-access-profile-eX8ffDWv.js";import"./index-DPrYYZ34.js";import"./index-CJtd0Bml.js";import"./en-US-IVrGvTxk.js";import"./format-CdF6Rsce.js";import"./endOfMonth-DBg3kuNh.js";import"./chevron-left-BFrO02ex.js";import"./chevron-right-tHQZp40I.js";import"./chevron-down-BpeL8prt.js";import"./input-D8MgPrVN.js";import"./label-B_revbFK.js";import"./calendar-B39T2JGV.js";import"./check-BfMNAkIe.js";function re(r,i){const s=new Date(r+"T00:00:00"),x=new Date(i+"T00:00:00");return Math.max(1,Math.round((x.getTime()-s.getTime())/864e5)+1)}function q(r,i){const s=new Date(r+"T00:00:00");return s.setDate(s.getDate()+i),s.toISOString().slice(0,10)}function Le(){const{brandIds:r}=R(),i=r.join(","),[s,x]=g.useState(()=>W("30d")),n=A(K),f=A(U),m=g.useMemo(()=>{const t=re(s.from,s.to);return{from:q(s.from,-t),to:q(s.from,-1)}},[s.from,s.to]),{data:l,isLoading:p}=C({queryKey:["imp-dashboard",i,s.from,s.to],enabled:r.length>0,queryFn:()=>n({data:{brandIds:r,from:s.from,to:s.to}})}),{data:k}=C({queryKey:["imp-dashboard-prev",i,m.from,m.to],enabled:r.length>0,queryFn:()=>n({data:{brandIds:r,from:m.from,to:m.to}})}),{data:T=[]}=C({queryKey:["imp-recent-pos",i],enabled:r.length>0,queryFn:()=>f({data:{brandIds:r}}),select:t=>t.slice(0,6)}),h=l?.pos??[],$=l?.cartons??[],b=k?.pos??[],u=g.useMemo(()=>{const t=h.reduce((o,j)=>o+Number(j.grand_total_bdt||0),0),a=h.reduce((o,j)=>o+Number(j.paid_bdt||0),0),d=h.reduce((o,j)=>o+Number(j.due_bdt||0),0),c=h.filter(o=>["ordered","at_china_warehouse","in_transit","arrived_bd","partially_received"].includes(o.status)).length;return{totalSpend:t,totalPaid:a,totalDue:d,inFlight:c,poCount:h.length}},[h]),y=g.useMemo(()=>{const t=b.reduce((c,o)=>c+Number(o.grand_total_bdt||0),0),a=b.reduce((c,o)=>c+Number(o.paid_bdt||0),0),d=b.reduce((c,o)=>c+Number(o.due_bdt||0),0);return{totalSpend:t,totalPaid:a,totalDue:d,poCount:b.length}},[b]),w=(t,a)=>a?(t-a)/a*100:null,M=g.useMemo(()=>[{key:"ordered",label:"Ordered",icon:P,tone:"from-slate-500 to-slate-600"},{key:"at_china_warehouse",label:"At China WH",icon:H,tone:"from-amber-500 to-amber-600"},{key:"in_transit",label:"In Transit",icon:Q,tone:"from-blue-500 to-blue-600"},{key:"arrived_bd",label:"Arrived BD",icon:V,tone:"from-violet-500 to-violet-600"},{key:"released",label:"Released",icon:G,tone:"from-cyan-500 to-cyan-600"},{key:"in_stock",label:"In Stock",icon:J,tone:"from-emerald-500 to-emerald-600"}].map(a=>{const d=$.filter(c=>c.status===a.key);return{...a,count:d.length,pieces:d.reduce((c,o)=>c+Number(o.expected_quantity||0),0)}}),[$]),I=g.useMemo(()=>{const t={};return h.forEach(a=>{t[a.status]=(t[a.status]||0)+1}),Object.entries(t).map(([a,d])=>({status:a,count:d}))},[h]);return e.jsxs("div",{className:"p-4 md:p-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx(E,{value:s,onChange:x}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(D,{to:"/erp/imports/orders/new",children:e.jsxs(L,{children:[e.jsx(X,{className:"h-4 w-4 mr-1"}),"New Purchase Order"]})})})]}
1),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-5 gap-3",children:[e.jsx(v,{label:"Total Spend",value:N(u.totalSpend),icon:Y,tone:"text-blue-600",delta:w(u.totalSpend,y.totalSpend)}),e.jsx(v,{label:"Paid",value:N(u.totalPaid),icon:Z,tone:"text-emerald-600",delta:w(u.totalPaid,y.totalPaid)}),e.jsx(v,{label:"Outstanding Due",value:N(u.totalDue),icon:z,tone:"text-orange-600",delta:w(u.totalDue,y.totalDue),deltaInverse:!0}),e.jsx(v,{label:"Active POs",value:String(u.inFlight),icon:ee,tone:"text-violet-600"}),e.jsx(v,{label:"Total POs",value:String(u.poCount),icon:P,tone:"text-slate-600",delta:w(u.poCount,y.poCount)})]}),e.jsxs(_,{className:"p-5",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Cargo Pipeline"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Carton flow across stages"})]})}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:M.map(t=>e.jsxs("div",{className:"relative overflow-hidden rounded-lg border border-border bg-card p-4",children:[e.jsx("div",{className:`absolute -top-6 -right-6 h-20 w-20 rounded-full bg-gradient-to-br ${t.tone} opacity-10`}),e.jsx(t.icon,{className:"h-5 w-5 text-muted-foreground mb-2"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:t.label}),e.jsx("div",{className:"text-2xl font-bold tabular-nums mt-1",children:t.count}),e.jsxs("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:[t.pieces.toLocaleString()," pcs"]})]},t.key))})]}),e.jsxs("div",{className:"grid lg:grid-cols-3 gap-4",children:[e.jsxs(_,{className:"p-5 lg:col-span-2",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Recent Purchase Orders"}),e.jsx(D,{to:"/erp/imports/orders",className:"text-xs text-primary hover:underline",children:"View all →"})]}),T.length===0?e.jsx("div",{className:"text-sm text-muted-foreground py-8 text-center",children:"No purchase orders yet."}):e.jsx("div",{className:"space-y-2",children:T.map(t=>e.jsxs(D,{to:"/erp/imports/orders/$orderId",params:{orderId:t.id},className:"flex items-center justify-between gap-3 rounded-md border border-border hover:border-primary/40 hover:bg-accent/50 px-3 py-2.5 transition",children:[e.jsx(ae,{items:t.items??[]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs font-semibold",children:t.po_number}),t.brand?.name&&e.jsx(F,{variant:"outline",className:"text-[10px]",children:t.brand.name}),e.jsx(F,{variant:"secondary",className:S[t.status]?.tone,children:S[t.status]?.label??t.status})]}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:(t.items??[]).length>0?`${(t.items??[]).length} item${(t.items??[]).length>1?"s":""} · ${(t.items??[]).reduce((a,d)=>a+Number(d.quantity||0),0)} pcs`:t.agent?.name??"No agent"})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-sm font-semibold tabular-nums",children:N(t.grand_total_bdt)}),e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Due ",N(t.due_bdt)]})]})]},t.id))})]}),e.jsxs(_,{className:"p-5",children:[e.jsx("h2",{className:"text-lg font-semibold mb-3",children:"Status Breakdown"}),I.length===0?e.jsx("div",{className:"text-sm text-muted-foreground py-8 text-center",children:p?"Loading…":"No data."}):e.jsx("div",{className:"space-y-2",children:I.sort((t,a)=>a.count-t.count).map(t=>{const a=S[t.status],d=t.count/u.poCount*100;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsx("span",{className:"font-medium",children:a?.label??t.status}),e.jsx("span",{className:"tabular-nums text-muted-foreground",children:t.count})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary",style:{width:`${d}%`}})})]},t.status)})})]})]})]})}function v({label:r,value:i,icon:s,tone:x,delta:n,deltaInverse:f}){const m=n!=null&&isFinite(n),l=m&&n>0,p=m&&Math.abs(n)<.05,k=f?!l:l;return e.jsxs(_,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:r}),e.jsx(s,{className:`h-4 w-4 ${x}`})]}),e.jsx("div",{className:"text-xl font-bold tabular-nums",children:i}),m&&!p&&e.jsxs("div",{className:`mt-1 inline-flex items-center gap-0.5 text-[11px] font-medium ${k?"text-emerald-600":"text-red-600"}`,children:[l?e.jsx(te,{className:"h-3 w-3"}):e.jsx(se,{className:"h-3 w-3"}),Math.abs(n).toFixed(1),"% vs prev"]})]})}function B(r){return r.product?.image||r.image_snapshot||null}function O(r){return r.product?.title||r.name_snapshot||"Unnamed item"}function ae({items:r,max:i=4,size:s="md"}){if(!r||r.length===0)return e.jsx("div",{className:`${s==="sm"?"h-8 w-8":"h-10 w-10"} rounded-md bg-muted border border-dashed border-border flex items-center justify-center flex-shrink-0`,children:e.jsx(P,{className:s==="sm"?"h-3.5 w-3.5 text-muted-foreground
1/60":"h-4 w-4 text-muted-foreground/60"})});const x=r.slice(0,i),n=r.length-x.length,f=s==="sm"?"h-8 w-8":"h-10 w-10",m=s==="sm"?"-ml-2.5":"-ml-3";return e.jsxs("div",{className:"flex items-center flex-shrink-0",children:[x.map((l,p)=>e.jsx("div",{className:`${f} ${p===0?"":m} rounded-md border-2 border-background bg-muted overflow-hidden ring-1 ring-border`,title:`${O(l)}${l.quantity?` × ${l.quantity}`:""}`,style:{zIndex:x.length-p},children:B(l)?e.jsx("img",{src:B(l),alt:O(l),loading:"lazy",className:"h-full w-full object-cover"}):e.jsx("div",{className:"h-full w-full flex items-center justify-center",children:e.jsx(P,{className:s==="sm"?"h-3.5 w-3.5 text-muted-foreground/60":"h-4 w-4 text-muted-foreground/60"})})},p)),n>0&&e.jsxs("div",{className:`${f} ${m} rounded-md border-2 border-background bg-muted ring-1 ring-border flex items-center justify-center text-[10px] font-semibold text-muted-foreground`,title:`+${n} more`,children:["+",n]})]})}export{ae as ProductThumbStack,Le as component,B as poItemImage,O as poItemName};

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.