PageSourceSearch

https://pulsecars.co.uk/assets/admin.sold-DIR2lmsw.js

js pulsecars.co.uk collected 2026-10-08 06:12:37 UTC 15,372 bytes, 1 lines download raw bytes

1import{k as B,l as z,r as u,j as e,L as P,B as j,T as F,s as L,t as y,e as G}from"./main-BGPPHxHM.js";import{I as n}from"./input-D0ZnlPy7.js";import{L as A}from"./label-Cs-fnIPW.js";import{T as M}from"./textarea-C1GjMsvY.js";import{D as O,b as V,c as $,d as q,f as H,e as U}from"./dialog-BWqNwiPR.js";import{S as W,a as Q,b as Y,c as J,d as K}from"./select-9BnniKoU.js";import{A as X}from"./arrow-left-CFvWDBUx.js";import{S as Z}from"./search-DQkFYzwY.js";import{P as T}from"./pencil-z0E0LyrK.js";import{F as R}from"./file-text-DseSLw0G.js";import"./index-D3F3hwE6.js";import"./index-Q-HDVsyn.js";import"./index-CDLVY2j6.js";import"./check-Cx29d-FE.js";const p=i=>typeof i=="number"?new Intl.NumberFormat("en-GB",{style:"currency",currency:"GBP",maximumFractionDigits:0}).format(i):"—";function pe(){const{user:i,isAdmin:d,loading:h,roleChecked:_}=B(),s=z(),[f,N]=u.useState([]),[w,l]=u.useState(!0),[x,D]=u.useState(""),[t,m]=u.useState(null),[v,C]=u.useState(null);u.useEffect(()=>{h||!_||(!i||!d)&&s({to:"/admin/login"})},[h,_,i,d,s]);async function b(){l(!0);const{data:a,error:c}=await L.from("sold_cars").select("*").order("sold_at",{ascending:!1});c&&y.error(c.message),N(a??[]),l(!1)}u.useEffect(()=>{i&&d&&b()},[i,d]);const S=u.useMemo(()=>{const a=x.trim().toLowerCase();return a?f.filter(c=>[c.make,c.model,c.variant,c.registration,c.stock_number,c.customer_name].filter(Boolean).some(I=>I.toLowerCase().includes(a))):f},[f,x]);async function E(a){if(!confirm("Permanently delete this sold record? Analytics will lose this entry."))return;const{error:c}=await L.from("sold_cars").delete().eq("id",a);if(c){y.error(c.message);return}y.success("Removed"),b()}function o(a,c){m(a),C(c??null)}return h||!_||!i||!d?e.jsx("div",{className:"flex min-h-screen items-center justify-center text-muted-foreground",children:"Loading…"}):e.jsxs("div",{className:"min-h-screen bg-surface",children:[e.jsx("header",{className:"border-b border-border bg-card",children:e.jsxs("div",{className:"mx-auto flex h-16 max-w-7xl items-center justify-between px-4 sm:px-6 lg:px-8",children:[e.jsxs(P,{to:"/admin",className:"inline-flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground",children:[e.jsx(X,{className:"h-4 w-4"})," Back to admin"]}),e.jsx("h1",{className:"font-display text-lg font-bold",children:"Sold Inventory"}),e.jsx("div",{})]})}),e.jsxs("main",{className:"mx-auto max-w-7xl px-4 py-8 sm:px-6 lg:px-8",children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsx(Z,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(n,{value:x,onChange:a=>D(a.target.value),placeholder:"Search make, model, reg, stock #, customer…",className:"pl-9"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[S.length," of ",f.length," records"]})]}),e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Tap any field to amend it."}),w?e.jsx("p",{className:"py-12 text-center text-muted-foreground",children:"Loading…"}):S.length===0?e.jsx("p",{className:"py-12 text-center text-muted-foreground",children:"No sold cars yet."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-3 md:hidden",children:S.map(a=>e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-4 shadow-card",children:[e.jsxs("button",{type:"button",onClick:()=>o(a,"make"),className:"flex w-full items-start gap-3 text-left",children:[a.image_url&&e.jsx("img",{src:a.image_url,alt:"",className:"h-16 w-24 shrink-0 rounded-md object-cover"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"truncate font-semibold",children:[a.year," ",a.make," ",a.model]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:a.variant??""}),e.jsxs("div",{className:"mt-1 font-mono text-[11px] text-muted-foreground",children:[a.registration??"—"," · ",a.stock_number??"—"]})]})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2 text-sm",children:[e.jsx(g,{label:"Sold",onClick:()=>
1o(a,"sold_price"),value:e.jsx("span",{className:"font-semibold text-primary",children:p(a.sold_price)})}),e.jsx(g,{label:"Purchase",onClick:()=>o(a,"purchase_price"),value:p(a.purchase_price)}),e.jsx(g,{label:"Prep cost",onClick:()=>o(a,"prep_cost"),value:p(a.prep_cost)}),e.jsx(g,{label:"Part-ex",onClick:()=>o(a,"part_ex_value"),value:a.part_ex_taken?p(a.part_ex_value):"—"}),e.jsx(g,{label:"Customer",onClick:()=>o(a,"customer_name"),value:a.customer_name??"—"}),e.jsx(g,{label:"Postcode",onClick:()=>o(a,"customer_postcode"),value:a.customer_postcode??"—"}),e.jsx(g,{label:"Date",onClick:()=>o(a,"sold_at"),value:new Date(a.sold_at).toLocaleDateString()}),e.jsx(g,{label:"Lead source",onClick:()=>o(a,"lead_source"),value:a.lead_source??"—"})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(j,{size:"sm",variant:"outline",className:"flex-1",onClick:()=>o(a),children:[e.jsx(T,{className:"mr-2 h-4 w-4"})," Edit"]}),e.jsx(j,{asChild:!0,size:"sm",className:"flex-1 bg-gradient-hero shadow-elegant",children:e.jsxs(P,{to:"/admin/receipt/$id",params:{id:a.id},children:[e.jsx(R,{className:"mr-2 h-4 w-4"})," Receipt"]})}),e.jsx(j,{size:"icon",variant:"ghost",onClick:()=>E(a.id),title:"Delete record",children:e.jsx(F,{className:"h-4 w-4 text-destructive"})})]})]},a.id))}),e.jsx("div",{className:"hidden overflow-hidden rounded-2xl border border-border bg-card shadow-card md:block",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-left text-xs uppercase tracking-wide text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3",children:"Car"}),e.jsx("th",{className:"p-3",children:"Reg / Stock"}),e.jsx("th",{className:"p-3",children:"Listed"}),e.jsx("th",{className:"p-3",children:"Sold"}),e.jsx("th",{className:"p-3",children:"Purchase"}),e.jsx("th",{className:"p-3",children:"Prep"}),e.jsx("th",{className:"p-3",children:"Days"}),e.jsx("th",{className:"p-3",children:"Customer"}),e.jsx("th",{className:"p-3 text-right",children:"Actions"})]})}),e.jsx("tbody",{children:S.map(a=>e.jsxs("tr",{className:"border-t border-border align-top",children:[e.jsx("td",{className:"cursor-pointer p-3 hover:bg-muted/40",onClick:()=>o(a,"make"),children:e.jsxs("div",{className:"flex items-start gap-3",children:[a.image_url&&e.jsx("img",{src:a.image_url,alt:"",className:"h-14 w-20 rounded-md object-cover"}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-medium",children:[a.year," ",a.make," ",a.model,a.variant?` ${a.variant}`:""]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:[a.body_type,a.color].filter(
1Boolean).join(" · ")}),a.description&&e.jsx("div",{className:"mt-1 line-clamp-2 max-w-md text-xs text-muted-foreground",children:a.description})]})]})}),e.jsxs("td",{className:"cursor-pointer p-3 hover:bg-muted/40",onClick:()=>o(a,"registration"),children:[e.jsx("div",{className:"font-mono text-xs",children:a.registration??"—"}),e.jsx("div",{className:"font-mono text-[11px] text-muted-foreground",children:a.stock_number??"—"})]}),e.jsx("td",{className:"cursor-pointer p-3 hover:bg-muted/40",onClick:()=>o(a,"listed_price"),children:p(a.listed_price)}),e.jsx("td",{className:"cursor-pointer p-3 font-semibold text-primary hover:bg-muted/40",onClick:()=>o(a,"sold_price"),children:p(a.sold_price)}),e.jsx("td",{className:"cursor-pointer p-3 hover:bg-muted/40",onClick:()=>o(a,"purchase_price"),children:p(a.purchase_price)}),e.jsx("td",{className:"cursor-pointer p-3 hover:bg-muted/40",onClick:()=>o(a,"prep_cost"),children:p(a.prep_cost)}),e.jsx("td",{className:"p-3",children:a.days_in_stock??"—"}),e.jsxs("td",{className:"cursor-pointer p-3 hover:bg-muted/40",onClick:()=>o(a,"customer_name"),children:[e.jsx("div",{children:a.customer_name??"—"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(a.sold_at).toLocaleDateString()})]}),e.jsx("td",{className:"p-3 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsxs(j,{size:"sm",variant:"outline",onClick:()=>o(a),title:"Edit record",children:[e.jsx(T,{className:"mr-1 h-4 w-4"})," Edit"]}),e.jsx(j,{asChild:!0,size:"sm",variant:"outline",title:"Open sales receipt",children:e.jsxs(P,{to:"/admin/receipt/$id",params:{id:a.id},children:[e.jsx(R,{className:"mr-1 h-4 w-4"})," Receipt"]})}),e.jsx(j,{size:"icon",variant:"ghost",onClick:()=>E(a.id),title:"Delete record",children:e.jsx(F,{className:"h-4 w-4 text-destructive"})})]})})]},a.id))})]})})})]})]}),e.jsx(ee,{row:t,focusField:v,onClose:()=>{m(null),C(null)},onSaved:()=>{m(null),C(null),b()}})]})}function g({label:i,value:d,onClick:h}){return e.jsxs("button",{type:"button",onClick:h,className:"rounded-md p-1 text-left -m-1 hover:bg-muted/50",children:[e.jsx("div",{className:"text-[11px] uppercase text-muted-foreground",children:i}),e.jsx("div",{className:"truncate",children:d})]})}function ee({row:i,focusField:d,onClose:h,onSaved:_}){const[s,f]=u.useState(null),[N,w]=u.useState(!1);if(u.useEffect(()=>{f(i)},[i]),u.useEffect(()=>{if(!i||!d)return;const t=setTimeout(()=>{const m=document.querySelector(`[data-field="${d}"]`);m&&(m.scrollIntoView({behavior:"smooth",block:"center"}),(m instanceof HTMLInputElement||m instanceof HTMLTextAreaElement)&&m.focus())},120);return()=>clearTimeout(t)},[i,d]),!s)return null;const l=(t,m)=>f(v=>v&&{...v,[t]:m}),x=t=>t===""?null:Number(t);async function D(){if(!s)return;w(!0);const{id:t,created_at:m,days_in_stock:v,...C}=s,{error:b}=await L.from("sold_cars").update(C).eq("id",t);if(w(!1),b){y.error(b.message);return}y.success("Record updated"),_()}return e.jsx(O,{open:!!i,onOpenChange:t=>{t||h()},children:e.jsxs(V,{className:"max-h-[90vh] max-w-3xl overflow-y-auto",children:[e.jsxs($,{children:[e.jsx(q,{children:"Edit sold record"}
1),e.jsxs(H,{children:[s.year," ",s.make," ",s.model,s.variant?` ${s.variant}`:""," — ",s.registration??"no reg"]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(k,{title:"Vehicle"}),e.jsx(r,{label:"Make",children:e.jsx(n,{"data-field":"make",value:s.make??"",onChange:t=>l("make",t.target.value)})}),e.jsx(r,{label:"Model",children:e.jsx(n,{"data-field":"model",value:s.model??"",onChange:t=>l("model",t.target.value)})}),e.jsx(r,{label:"Variant",children:e.jsx(n,{"data-field":"variant",value:s.variant??"",onChange:t=>l("variant",t.target.value||null)})}),e.jsx(r,{label:"Year",children:e.jsx(n,{"data-field":"year",type:"number",value:s.year??"",onChange:t=>l("year",x(t.target.value))})}),e.jsx(r,{label:"Registration",children:e.jsx(n,{"data-field":"registration",value:s.registration??"",onChange:t=>l("registration",t.target.value.toUpperCase()||null)})}),e.jsx(r,{label:"Stock number",children:e.jsx(n,{"data-field":"stock_number",value:s.stock_number??"",onChange:t=>l("stock_number",t.target.value||null)})}),e.jsx(r,{label:"Body type",children:e.jsx(n,{"data-field":"body_type",value:s.body_type??"",onChange:t=>l("body_type",t.target.value||null)})}),e.jsx(r,{label:"Colour",children:e.jsx(n,{"data-field":"color",value:s.color??"",onChange:t=>l("color",t.target.value||null)})}),e.jsx(k,{title:"Sale"}),e.jsx(r,{label:"Sold price (£)",children:e.jsx(n,{"data-field":"sold_price",type:"number",value:s.sold_price??"",onChange:t=>l("sold_price",x(t.target.value))})}),e.jsx(r,{label:"Sold date",children:e.jsx(n,{"data-field":"sold_at",type:"date",value:s.sold_at?new Date(s.sold_at).toISOString().slice(0,10):"",onChange:t=>l("sold_at",new Date(t.target.value).toISOString())})}),e.jsx(r,{label:"Listed price (£)",children:e.jsx(n,{"data-field":"listed_price",type:"number",value:s.listed_price??"",onChange:t=>l("listed_price",x(t.target.value))})}),e.jsx(r,{label:"Purchase price (£)",children:e.jsx(n,{"data-field":"purchase_price",type:"number",value:s.purchase_price??"",onChange:t=>l("purchase_price",x(t.target.value))})}),e.jsx(r,{label:"Prep / reconditioning (£)",children:e.jsx(n,{"data-field":"prep_cost",type:"number",value:s.prep_cost??"",onChange:t=>l("prep_cost",x(t.target.value))})}),e.jsx(r,{label:"Payment method",children:e.jsx(n,{"data-field":"payment_method",value:s.payment_method??"",onChange:t=>l("payment_method",t.target.value||null),placeholder:"e.g. Cash, Card, Bank transfer, Finance"})}),e.jsx(r,{label:"Lead source",children:e.jsxs(W,{value:s.lead_source??"",onValueChange:t=>l("lead_source",t||null),children:[e.jsx(Q,{"data-field":"lead_source",children:e.jsx(Y,{placeholder:"Select"})}),e.jsx(J,{children:["Website","Walk-in","AutoTrader","CarGurus","AA Cars","Facebook","Instagram","Google","Referral","Phone","Repeat customer","Other"].map(t=>e.jsx(K,{value:t,children:t},t))})]})}),e.jsx(r,{label:"Salesperson",children:e.jsx(n,{"data-field":"salesperson",value:s.salesperson??"",onChange:t=>l("salesperson",t.target.value||null)})}),e.jsx(k,{title:"Customer"}),e.jsx(r,{label:"Customer name",children:e.jsx(n,{"data-field":"customer_name",value:s.customer_name??"",onChange:t=>l("customer_name",t.target.value||null)})}),e.jsx(r,{label:"Phone",children:e.jsx(n,{"data-field":"customer_phone",value:s.customer_phone??"",onChange:t=>l("customer_phone",t.target.value||null)})}),e.jsx(r,{label:"Email",children:e.jsx(n,{"data-field":"customer_email",type:"email",value:s.customer_email??"",onChange:t=>l("customer_email",t.target.value||null)})}),e.jsx(r,{label:"Postcode",children:e.jsx(n,{"data-field":"customer_postcode",value:s.customer_postcode??"",onChange:t=>l("customer_postcode",t.target.value.toUpperCase()||null)})}),e.jsx(k,{title:"Part-exchange"}),e.jsxs("div",{className:"sm:col-span-2 flex items-center gap-2",children:[e.jsx("input",{id:"px-taken-edit",type:"checkbox",checked:!!s.part_ex_taken,onChange:t=>l("part_ex_taken",t.target.checked),className:"h-4 w-4","data-field":"part_ex_taken"}),e.jsx(A,{htmlFor:"px-taken-edit",className:"cursor-pointer",children:"Customer part-exchanged a vehicle"})]}),s.part_ex_taken&&e.jsxs(e.Fragment,{children:[e.jsx(r,{label:"Part-ex value (£)",children:e.jsx(n,{"data-field":"part_ex_value",type:"number",value:s.part_ex_value??"",onChange:t=>l("part_ex_value",x(t.target.value))})}),e.jsx(r,{label:"Part-ex registration",children:e.jsx(n,{"data-field":"part_ex_registration",value:s.part_ex_registration??"",onChange:t=>l("part_ex_registration",t.target.value.toUpperCase()||null)})})]}),e.jsx(k,{title:"Notes"}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(M,{"data-field":"notes",rows:4,value:s.notes??"",onChange:t=>l("notes",t.target.value||null),placeholder:"Any internal notes about this sale"})})]}),e.jsxs(U,{className:"mt-4",children:[e.jsx(j,{variant:"outline",onClick:h,disabled:N,children:"Cancel"}),e.jsxs(j,{onClick:D,disabled:N,className:"bg-gradient-hero",children:[N?e.jsx(G,{className:"mr-2 h-4 w-4 animate-spin"}):null," Save changes"]})]})]})})}function k({title:i}){return e.jsx("div",{className:"sm:col-span-2 mt-2 border-t border-border pt-3 first:mt-0 first:border-0 first:pt-0",children:e.jsx("h3",{className:"font-display text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:i})})}function r({label:i,children:d}){return e.jsxs("div",{children:[e.jsx(A,{children:i}),d]})}export{pe as component};

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.