PageSourceSearch

https://recovery-automotive.lovable.app/assets/PartsReceiving-B2_4qp0B.js

js recovery-automotive.lovable.app collected 2026-10-03 03:42:48 UTC 21,155 bytes, 1 lines download raw bytes

1import{s as I,an as te,ae as D,r as o,j as e,L as Q,B as T,b as k,p as Z,a5 as de,D as ce,a as ue,d as me,e as he,f as pe,F as xe,g as je,T as ge}from"./index-B8M9ps1T.js";import{C as B,c as z,d as H,a as K}from"./card-DzCf0Wp_.js";import{I as c}from"./input-CerV3gOV.js";import{L as x}from"./label-DF1VlBtP.js";import{T as _e}from"./textarea-DdRoT87k.js";import{S as L,a as q,b as E,c as F,d as y}from"./select-B30Rlv9Z.js";import{u as ae,b as ve,c as fe,d as be,i as Ne}from"./use-suppliers-MeLBBDYL.js";import{u as we}from"./useQuery-CPNlGgE1.js";import{u as re}from"./useMutation-BuT7tv3u.js";import{G as ye,p as ke,g as Ce,I as Se}from"./pdf.worker.min-BUhXu5fZ.js";import{C as Pe}from"./circle-check-b9HLETk4.js";import{E as De}from"./eye-DwmRuwCq.js";import{T as Ie}from"./trash-2-CY-Xk7Tz.js";import{P as Te}from"./plus-D0Ml6N8h.js";import{C as Le}from"./camera-8R-3NLe9.js";import"./index-CO7TY0pN.js";const qe=["parsing","pending_review","auto_ordered","failed"];function Ee(){return we({queryKey:["parts-inbox"],refetchInterval:6e4,queryFn:async()=>{const{data:a,error:i}=await I.from("parts_inbound_documents").select("*, suppliers(name), work_orders:matched_work_order_id(order_number)").in("status",qe).order("received_at",{ascending:!1}).limit(50);if(i)throw i;return a??[]}})}function Fe(){const a=te();return re({mutationFn:async({id:i,patch:u})=>{const{error:l}=await I.from("parts_inbound_documents").update(u).eq("id",i);if(l)throw l},onSuccess:()=>a.invalidateQueries({queryKey:["parts-inbox"]}),onError:i=>D.error(`Could not save: ${i.message}`)})}function Oe(){const a=te();return re({mutationFn:async i=>{const{data:u,error:l}=await I.rpc("confirm_inbound_parts_document",{p_doc_id:i});if(l)throw l;return u},onSuccess:()=>{a.invalidateQueries({queryKey:["parts-inbox"]}),a.invalidateQueries({queryKey:["supplier-invoices"]}),D.success("Parts received and invoice logged")},onError:i=>D.error(`Could not receive: ${i.message}`)})}ye.workerSrc=ke;const Re=({document:a,pageNumber:i})=>{const u=o.useRef(null);return o.useEffect(()=>{let l=!1,j=null;return(async()=>{var S;const d=await a.getPage(i);if(l||!u.current)return;const v=d.getViewport({scale:1}),w=Math.min(900,((S=u.current.parentElement)==null?void 0:S.clientWidth)??900),C=Math.min(window.devicePixelRatio||1,2),_=d.getViewport({scale:w/v.width*C}),n=u.current,p=n.getContext("2d");p&&(n.width=Math.floor(_.width),n.height=Math.floor(_.height),n.style.width=`${Math.floor(_.width/C)}px`,n.style.height=`${Math.floor(_.height/C)}px`,j=d.render({canvas:n,canvasContext:p,viewport:_}),await j.promise)})(),()=>{l=!0,j==null||j.cancel()}},[a,i]),e.jsx("canvas",{ref:u,className:"mx-auto max-w-full shadow-sm","aria-label":`Invoice page ${i}`})},Ve=({file:a})=>{const[i,u]=o.useState(null),[l,j]=o.useState(null);return o.useEffect(()=>{let m=!0;return(async()=>{try{const v=new Uint8Array(await a.arrayBuffer()),C=await Ce({data:v}).promise;m&&u(C)}catch{m&&j("The invoice PDF could not be displayed.")}})(),()=>{m=!1}},[a]),l?e.jsx("p",{className:"p-4 text-sm text-destructive",children:l}):i?e.jsx("div",{className:"max-h-[65vh] space-y-4 overflow-auto bg-muted p-3",children:Array.from({length:i.numPages},(m,d)=>e.jsx(Re,{document:i,pageNumber:d+1},d+1))}):e.jsxs("div",{className:"flex min-h-64 items-center justify-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Q,{className:"h-4 w-4 animate-spin"})," Preparing invoice…"]})},$e=a=>`$${(Number(a)||0).toFixed(2)}`,Me={parsing:"Reading…",pending_review:"Ready to receive",auto_ordered:"Parts marked ordered",failed:"Needs a look"},Ae=({doc:a,orders:i})=>{var J,X;const{data:u=[]}=ae(),l=Fe(),j=Oe(),m=a.parsed_data||{},[d,v]=o.useState(m.lines??[]),[w,C]=o.useState(a.supplier_id??""),[_,n]=o.useState(a.matched_work_order_id??""),[p,S]=o.useState(m.invoice_number??""),[P,$]=o.useState(String(m.total_amount??0)),[f,M]=o.useState(String(m.subtotal??0)),[A,R]=o.useState(!1),[s,t]=o.useState(null),[h,b]=o.useState(!1),O=(r,g)=>v(N=>N.map((Y,le)=>le===r?{...Y,...g}:Y)),G=async()=>l.mutateAsync({id:a.id,patch:{supplier_id:w||null,matched_work_order_id:_||null,parsed_data:{...m,invoice_number:p,subtotal:Number(f)||0,total_amount:Number(P)||0,lines:d.map(r=>({...r,work_order_id:r.parts_used_id?_||null:r.work_order_id}))}}}),ne=async()=>{w&&(await G(),await j.mutateAsync(a.id))},ie=async()=>
1{if(a.raw_storage_path){b(!0);try{const{data:r,error:g}=await I.storage.from("supplier-invoices").download(a.raw_storage_path);if(g)throw g;if(!r)throw new Error("The invoice PDF is unavailable.");t(new Blob([r],{type:"application/pdf"}))}catch(r){const g=r instanceof Error?r.message:"The invoice attachment could not be opened.";D.error(g)}finally{b(!1)}}},oe=a.document_type==="order_confirmation",V=l.isPending||j.isPending;return e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(T,{variant:a.status==="failed"?"destructive":"secondary",children:Me[a.status]??a.status}),e.jsx(T,{variant:"outline",children:oe?"Order confirmation":a.document_type==="credit_memo"?"Credit memo":"Invoice"}),e.jsx("span",{className:"font-medium",children:((J=a.suppliers)==null?void 0:J.name)??"Unknown supplier"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:new Date(a.received_at).toLocaleDateString()}),e.jsx("span",{className:"ml-auto font-semibold",children:$e(Number(m.total_amount)||0)})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a.subject||a.from_address}),a.match_notes&&e.jsx("p",{className:"text-sm",children:a.match_notes}),a.error_message&&e.jsx("p",{className:"text-sm text-destructive",children:a.error_message}),a.parts_marked_ordered>0&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:[a.parts_marked_ordered," part(s) marked as on order."]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-4",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Supplier"}),e.jsxs(L,{value:w,onValueChange:C,children:[e.jsx(q,{children:e.jsx(E,{placeholder:"Choose supplier"})}),e.jsx(F,{children:u.map(r=>e.jsx(y,{value:r.id,children:r.name},r.id))})]})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Work order"}),e.jsxs(L,{value:_||"none",onValueChange:r=>n(r==="none"?"":r),children:[e.jsx(q,{children:e.jsx(E,{placeholder:"Work order"})}),e.jsxs(F,{children:[e.jsx(y,{value:"none",children:"No work order"}),i.map(r=>e.jsxs(y,{value:r.id,children:["#",r.order_number," — ",(r.description??"").slice(0,35)]},r.id))]})]})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Invoice #"}),e.jsx(c,{value:p,onChange:r=>S(r.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Subtotal"}),e.jsx(c,{type:"number",step:"0.01",value:f,onChange:r=>M(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Total"}),e.jsx(c,{type:"number",step:"0.01",value:P,onChange:r=>$(r.target.value)})]})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted text-left",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-2",children:"Part"}),e.jsx("th",{className:"p-2",children:"Description"}),e.jsx("th",{className:"p-2 w-20",children:"Qty"}),e.jsx("th",{className:"p-2 w-28",children:"Cost"}),e.jsx("th",{className:"p-2 w-28",children:"Core"}),e.jsx("th",{className:"p-2",children:"Matched"})]})}),e.jsxs("tbody",{children:[d.length===0&&e.jsx("tr",{children:e.jsx("td",{className:"p-3 text-muted-foreground",colSpan:6,children:"No parts were read from this document."})}),d.map((r,g)=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"p-1",children:e.jsx(c,{className:"h-8",value:r.part_number,onChange:N=>O(g,{part_number:N.target.value})})}),e.jsx("td",{className:"p-1",children:e.jsx(c,{className:"h-8",value:r.description,onChange:N=>O(g,{description:N.target.value})})}),e.jsx("td",{className:"p-1",children:e.jsx(c,{className:"h-8",type:"number",step:"0.5",value:r.quantity,onChange:N=>O(g,{quantity:Number(N.target.value)})})}),e.jsx("td",{className:"p-1",children:e.jsx(c,{className:"h-8",type:"number",step:"0.01",value:r.unit_cost,onChange:N=>O(g,{unit_cost:Number(N.target.value)})})}),e.jsx("td",{className:"p-1",children:e.jsx(c,{className:"h-8",type:"number",step:"0.01",value:r.core_charge_per_unit,onChange:N=>O(g,{core_charge_per_unit:Number(N.target.value)})})}),e.jsx("td",{className:"p-2",children:r.parts_used_id?e.jsx(T,{className:"bg-green-600 hover:bg-green-600",children:"On the job"}):e.jsx(T,{variant:"outline",children:r.destination_type==="inventory"?"Shop stock":"Not matched"})})]},g))]})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(k,{onClick:ne,disabled:V||!w,children:[V?e.jsx(Q,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Pe,{className:"h-4 w-4 mr-1"}),"Confirm & receive"]}),e.jsx(k,{variant:"outline",onClick:G,disabled:V,children:"Save changes"}),e.jsxs(k,{variant:"outline",onClick:()=>R(!0),children:[e.jsx(Z,{className:"h-4 w-4 mr-1"})," View email"]}),e.jsxs(k,{variant:"ghost",onClick:()=>l.mutate({id:a.id,patch:{status:"dismissed"}}),disabled:V,children:[e.jsx(de,{className:"h-4 w-4 mr-1"})," Dismiss"]})]}),e.jsx(ce,{open:A,onOpenChange:R,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-3xl overflow-y-auto",children:[e.jsxs(me,{children:[e.jsxs(he,{className:"flex items-center gap-2 pr-8",children:[e.jsx(Z,{className:"h-5 w-5 shrink-0"})," Original email"]}),e.jsx(pe,{children:"The received message and its original invoice attachment."})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-2 border-b pb-4 text-sm sm:grid-cols-[5rem_1fr]",children:[e.jsx("dt",{className:"font-medium text-muted-foreground",children:"From"}),e.jsx("dd",{className:"break-all",children:a.from_address||"Unknown sender"}),e.jsx("dt",{className:"font-medium text-muted-foreground",children:"Received"}
1),e.jsx("dd",{children:new Date(a.received_at).toLocaleString()}),e.jsx("dt",{className:"font-medium text-muted-foreground",children:"Subject"}),e.jsx("dd",{className:"font-medium",children:a.subject||"No subject"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Message"}),e.jsx("div",{className:"max-h-80 overflow-y-auto whitespace-pre-wrap break-words rounded-md border bg-muted/40 p-4 text-sm",children:((X=m.email_body)==null?void 0:X.trim())||"This email did not include a message body."})]}),a.raw_storage_path&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-md border p-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(xe,{className:"h-5 w-5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:a.original_filename||"Supplier invoice.pdf"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"PDF attachment"})]})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:ie,disabled:h,children:[h?e.jsx(Q,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(De,{className:"h-4 w-4 mr-1"}),h?"Loading…":s?"Reload PDF":"View PDF"]})]}),s&&e.jsx("div",{className:"overflow-hidden rounded-md border",children:e.jsx(Ve,{file:s})})]})})]})},ee=({shopSupplies:a=!1})=>{const{data:i=[],isLoading:u}=Ee(),l=i.filter(d=>{var v;return!!((v=d.parsed_data)!=null&&v.shop_supply)===a}),[j,m]=o.useState([]);return o.useEffect(()=>{I.from("work_orders").select("id, order_number, description").in("status",["pending","in_progress","parts_waiting"]).is("archived_at",null).order("order_number",{ascending:!1}).limit(80).then(({data:d})=>m(d??[]))},[]),!u&&l.length===0?null:e.jsxs(B,{children:[e.jsx(z,{children:e.jsxs(H,{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-5 w-5"})," ",a?"Shop supplies (PO SHOP)":"Parts inbox",l.length>0&&e.jsx(T,{variant:"secondary",children:l.length})]})}),e.jsxs(K,{className:"space-y-4",children:[u&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Checking for supplier emails…"}),l.map(d=>e.jsx(Ae,{doc:d,orders:j},d.id))]})]})},U=a=>`$${a.toFixed(2)}`,se=()=>new Date().toISOString().slice(0,10),W=()=>({key:crypto.randomUUID(),part_number:"",description:"",quantity_received:1,unit_cost:0,core_charge_per_unit:0,destination_type:"work_order",work_order_id:null,work_order_part_id:null}),rs=()=>{const{data:a=[]}=ae(),{data:i=[]}=ve(),u=fe(),[l,j]=o.useState([]),[m,d]=o.useState({}),[v,w]=o.useState(null),[C,_]=o.useState(!1),[n,p]=o.useState({supplier_id:"",invoice_number:"",invoice_date:se(),subtotal:"",tax_amount:"",freight_amount:"",total_amount:"",notes:""}),[S,P]=o.useState([W()]);o.useEffect(()=>{I.from("work_orders").select("id, order_number, description").in("status",["pending","in_progress","parts_waiting"]).is("archived_at",null).order("order_number",{ascending:!1}).limit(60).then(({data:s})=>j(s??[]))},[]);const $=async s=>{if(m[s])return;const{data:t}=await I.from("parts_used").select("id, description, part_number, order_status").eq("work_order_id",s);d(h=>({...h,[s]:t??[]}))},f=(s,t)=>P(h=>h.map(b=>b.key===s?{...b,...t}:b)),M=S.reduce((s,t)=>s+(Number(t.quantity_received)||0)*(Number(t.unit_cost)||0),0),A=async()=>{if(!n.supplier_id)return D.error("Pick a supplier");if(!n.invoice_number.trim())return D.error("Enter the invoice number");const s=S.filter(t=>t.description.trim());if(!s.length)return D.error("Add at least one part received");_(!0);try{let t=null;v&&(t=await be(v)),await u.mutateAsync({supplier_id:n.supplier_id,invoice_number:n.invoice_number.trim(),invoice_date:n.invoice_date,subtotal:Number(n.subtotal)||0,tax_amount:Number(n.tax_amount)||0,freight_amount:Number(n.freight_amount)||0,total_amount:Number(n.total_amount)||0,notes:n.notes||null,invoice_image_path:t,items:s.map(({key:h,...b})=>({...b,quantity_received:Number(b.quantity_received)||1,unit_cost:Number(b.unit_cost)||0,core_charge_per_unit:Number(b.core_charge_per_unit)||0}))}),p({supplier_id:n.supplier_id,invoice_number:"",invoice_date:se(),subtotal:"",tax_amount:"",freight_amount:"",total_amount:"",notes:""}),P([W()]),w(null)}catch{}finally{_(!1)}},R=async s=>{const t=await Ne(s);t&&window.open(t,"_blank")};return e.jsxs("div",{className:"container max-w-5xl py-8 space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Receive Parts"}),e.jsx("p",{className:"text-muted-foreground",children:"Log what came in the door, from whom, and which job it belongs to."})]}),e.jsx(k,{asChild:!0,variant:"outline",children:e.jsxs(je,{to:"/dashboard/parts/suppliers",children:[e.jsx(ge,{className:"h-4 w-4 mr-1"})," Suppliers"]})})]}),e.jsx(ee,{shopSupplies:!0}),e.jsx(ee,{}),e.jsxs(B,{children:[e.jsx(z,{children:e.jsx(H,{children:"New invoice"})}),e.jsxs(K,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Supplier"}),e.jsxs(L,{value:n.supplier_id,onValueChange:s=>p({...n,supplier_id:s}),children:[e.jsx(q,{children:e.jsx(E,{placeholder:"Choose supplier"})}),e.jsx(F,{children:a.map(s=>e.jsx(y,{value:s.id,children:s.name},s.id))})]})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Invoice #"}),e.jsx(c,{value:n.invoice_number,onChange:s=>p({...n,invoice_number:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Invoice date"}),e.jsx(c,{type:"date",value:n.invoice_date,onChange:s=>p({...n,invoice_date:s.target.value})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{children:"Parts received"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Lines total ",U(M)]})]}),S.map(s=>e.jsxs("div",{className:"rounded-md border p-3 space-y-2",children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-6",children:[e.jsx(c,{className:"sm:col-span-2",placeholder:"Description",value:s.description,onChange:t=>f(s.key,{description:t.target.value})}),e.jsx(c,{placeholder:"Part #",value:s.part_number,onChange:t=>f(s.key,{part_number:t.target.value})}),e.jsx(c,{type:"number",min:"0",step:"0.5",placeholder:"Qty",value:s.quantity_received,onChange:t=>f(s.key,{quantity_received:Number(t.target.value)})}),e.jsx(c,{type:"number",min:"0",step:"0.01",placeholder:"Unit cost $",value:s.unit_cost,onChange:t=>f(s.key,{unit_cost:Number(t.target.value)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{type:"number",min:"0",step:"0.01",placeholder:"Core $",value:s.core_charge_per_unit,onChange:t=>f(s.key,{core_charge_per_unit:Number(t.target.value)})}),e.jsx(k,{variant:"ghost",size:"icon","aria-label":"Remove line",onClick:()=>P(t=>t.length>1?t.filter(h=>h.key!==s.key):t),children:e.jsx(Ie,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs(L,{value:s.destination_type,onValueChange:t=>f(s.key,{destination_type:t,work_order_id:null,work_order_part_id:null}),children:[e.jsx(q,{children:e.jsx(E,{})}),e.jsxs(F,{children:[e.jsx(y,{value:"work_order",children:"For a work order"}),e.jsx(y,{value:"inventory",children:"Into shop stock"})]})]}),s.destination_type==="work_order"&&e.jsxs(e.Fragment,{children:[e.jsxs(L,{value:s.work_order_id??"none",onValueChange:t=>{f(s.key,{work_order_id:t==="none"?null:t,work_order_part_id:null}),t!=="none"&&$(t)},children:[e.jsx(q,{children:e.jsx(E,{placeholder:"Work order"})}),e.jsxs(F,{children:[e.jsx(y,{value:"none",children:"No work order yet"}),l.map(t=>{var h;return e.jsxs(y,{value:t.id,children:["#",t.order_number," — ",(h=t.description)==null?void 0:h.slice(0,40)]},t.id)})]})]}),s.work_order_id&&e.jsxs(L,{value:s.work_order_part_id??"none",onValueChange:t=>f(s.key,{work_order_part_id:t==="none"?null:t}),children:[e.jsx(q,{children:e.jsx(E,{placeholder:"Match a quoted part"})}),e.jsxs(F,{children:[e.jsx(y,{value:"none",children:"Not on the estimate"}),(m[s.work_order_id]??[]).map(t=>e.jsxs(y,{value:t.id,children:[t.description," (",t.part_number,")"]},t.id))]})]})]})]})]},s.key)),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>P(s=>[...s,W()]),children:[e.jsx(Te,{className:"h-4 w-4 mr-1"})," Add another part"]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-4",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Subtotal"}),e.jsx(c,{type:"number",step:"0.01",value:n.subtotal,onChange:s=>p({...n,subtotal:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(x,{children:"GST"}),e.jsx(c,{type:"number",step:"0.01",value:n.tax_amount,onChange:s=>p({...n,tax_amount:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Freight"}),e.jsx(c,{type:"number",step:"0.01",value:n.freight_amount,onChange:s=>p({...n,freight_amount:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Invoice total"}),e.jsx(c,{type:"number",step:"0.01",value:n.total_amount,onChange:s=>p({...n,total_amount:s.target.value})})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Photo of the paper invoice (optional)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(c,{type:"file",accept:"image/*,application/pdf",capture:"environment",onChange:s=>{var t;return w(((t=s.target.files)==null?void 0:t[0])??null)}}),e.jsx(Le,{className:"h-4 w-4 text-muted-foreground"})]})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Notes"}),e.jsx(_e,{rows:2,value:n.notes,onChange:s=>p({...n,notes:s.target.value})})]})]}),e.jsx(k,{onClick:A,disabled:C||u.isPending,children:"Save invoice"})]})]}),e.jsxs(B,{children:[e.jsx(z,{children:e.jsx(H,{children:"Recent invoices"})}),e.jsx(K,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted text-left",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-2",children:"Date"}),e.jsx("th",{className:"p-2",children:"Supplier"}),e.jsx("th",{className:"p-2",children:"Invoice #"}),e.jsx("th",{className:"p-2",children:"Lines"}),e.jsx("th",{className:"p-2",children:"Subtotal"}),e.jsx("th",{className:"p-2",children:"Total"}),e.jsx("th",{className:"p-2"})]})}),e.jsxs("tbody",{children:[i.length===0&&e.jsx("tr",{children:e.jsx("td",{className:"p-3 text-muted-foreground",colSpan:7,children:"No invoices logged yet."})}),i.map(s=>{var t,h;return e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"p-2",children:s.invoice_date}),e.jsx("td",{className:"p-2",children:((t=s.suppliers)==null?void 0:t.name)??"—"}),e.jsx("td",{className:"p-2 font-mono text-xs",children:s.invoice_number}),e.jsx("td",{className:"p-2",children:e.jsx(T,{variant:"secondary",children:((h=s.supplier_invoice_items)==null?void 0:h.length)??0})}),e.jsx("td",{className:"p-2",children:U(Number(s.subtotal))}),e.jsx("td",{className:"p-2 font-medium",children:U(Number(s.total_amount))}),e.jsx("td",{className:"p-2",children:s.invoice_image_path&&e.jsx(k,{variant:"ghost",size:"sm",onClick:()=>R(s.invoice_image_path),children:"Photo"})})]},s.id)})]})]})})})]})]})};export{rs 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.