PageSourceSearch

https://luxuryleasing.de/assets/AngeboteList-B2ZrZ4Aa.js

js luxuryleasing.de collected 2026-10-08 07:12:48 UTC 11,017 bytes, 1 lines download raw bytes

1import{a as X,u as Y,b as Z,j as e}from"./query-vendor-DVmmQ-ki.js";import{f as ee,r as v}from"./react-vendor-BURXZ51T.js";import{supabase as b}from"./client-BXzYhP5O.js";import{L as te}from"./Layout-BVzN5no9.js";import{B as a,T as se,L as y,R as re}from"./index-DpP3iEYK.js";import{C as ae,a as ie}from"./card-DwBoygcx.js";import{T as ne,a as le,b as S,c as i,d as ce,e as n}from"./table-DGTNs8pb.js";import{T as q,a as B,b as p}from"./tabs-CH4KCsyR.js";import{B as l}from"./badge-BrFuXnAq.js";import{A as oe,a as de}from"./alert-CpDtCbP7.js";import{t as c}from"./use-toast-j8LH5fHs.js";import{e as _,i as j,g as M,f as N,h as me}from"./date-vendor-sl2uXp01.js";import{P as ue}from"./plus-B0QqRDRs.js";import{C as he}from"./clock-achFCw6v.js";import{D as pe}from"./download-BqrsYkRJ.js";import{R as xe}from"./rotate-ccw-0EpcwqCL.js";import{A as ge}from"./archive-C_HcnhoG.js";import{T as ve}from"./trash-2-B9W2MJEE.js";import{d as R}from"./de-C5AT29KS.js";import"./supabase-DxfZiqN5.js";import"./radix-slot-BTvEbTmE.js";import"./use-mobile-AOcHjMvg.js";import"./input-Bx2apBJb.js";import"./separator-DkK0XzuW.js";import"./ui-radix-LBOF5AHa.js";import"./sheet-BeJtqytd.js";import"./x-CrVVxRiw.js";import"./skeleton-CbBeDtzP.js";import"./tooltip-Bh6NQA4e.js";import"./AuthContext-3XEtQ2Z5.js";import"./collapsible-DY850U3t.js";import"./adminNav-C-7plEjm.js";import"./car-DDzoQZ-u.js";import"./clipboard-list-Cor7K-Hm.js";import"./upload-B6QS-LUa.js";import"./rocket-2b0VX7AK.js";import"./users-ZV8T42f1.js";import"./crown-D-XLG-jH.js";import"./chart-column-BDYqO4Le.js";import"./activity-DCJtbnml.js";import"./gauge-Becitn9n.js";import"./file-text-UJur6P3r.js";import"./image-plus-BQduicMz.js";import"./settings-B8D67Utk.js";import"./mail-B34Ue2PM.js";import"./search-gwTUQi-V.js";import"./globe-cUt2UJxp.js";import"./megaphone-Jr7rAmxU.js";import"./user-cog-CgHwPb5X.js";import"./shield-alert-DgTalkzx.js";import"./shield-check-DJ8fUK0H.js";import"./gavel-BaVj0ktT.js";import"./dropdown-menu-CexBKmu0.js";import"./chevron-right-CEZ7PbYu.js";import"./check-Dwauox-g.js";import"./circle-BqCuy5sH.js";import"./external-link-Dq9xh9iT.js";import"./user-CZ-Nb2LJ.js";import"./log-out-zST2G2k3.js";function Nt(){const A=ee(),k=X(),[o,D]=v.useState("aktiv"),[w,P]=v.useState("alle"),[f,T]=v.useState(null),[C,E]=v.useState(null),{data:d,isLoading:K}=Y({queryKey:["customer-offers"],queryFn:async()=>{const{data:t,error:s}=await b.from("customer_offers").select("*").order("created_at",{ascending:!1});if(s)throw s;return t}}),m=new Date,L=_(m,7),z=(d==null?void 0:d.filter(t=>{const s=new Date(t.expires_at),r=j(s,m),h=M(s,m)&&j(s,L);if(w!=="alle"&&t.offer_type!==w)return!1;switch(o){case"aktiv":return t.status==="aktiv"&&!r&&!h;case"ablaufend":return t.status==="aktiv"&&h;case"archiv":return t.status==="archiviert"||r;default:return!0}}))||[],x=(d==null?void 0:d.filter(t=>{const s=new Date(t.expires_at);return t.status==="aktiv"&&M(s,m)&&j(s,L)}).length)||0,u=Z({mutationFn:async({id:t,updates:s})=>{const{error:r}=await b.from("customer_offers").update(s).eq("id",t);if(r)throw r},onSuccess:()=>{k.invalidateQueries({queryKey:["customer-offers"]})}}),I=async t=>{const s=_(new Date,30);await u.mutateAsync({id:t,updates:{expires_at:s.toISOString(),status:"aktiv"}}),c({title:"Angebot verlängert",description:"Gültigkeit um 30 Tage verlängert."})},U=async t=>{await u.mutateAsync({id:t,updates:{status:"archiviert"}}),c({title:"Angebot archiviert",description:"Das Angebot wurde ins Archiv verschoben."})},H=async t=>{const s=_(new Date,30);await u.mutateAsync({id:t,updates:{status:"aktiv",expires_at:s.toISOString()}}),c({title:"Angebot reaktiviert",description:"Das Angebot ist wieder aktiv für 30 Tage."})},Q=async t=>{if(confirm("Möchten Sie dieses Angebot wirklich endgültig löschen?")){T(t);try{const{error:s}=await b.from("customer_offers").delete().eq("id",t);if(s)throw s;c({title:"Angebot gelöscht",description:"Das Angebot wurde endgültig entfernt."}),k.invalidateQueries({queryKey:["customer-offers"]})}catch(s){console.error("Error deleting offer:",s),c({title:"Fehler",description:"Das Angebot konnte nicht gelöscht werden.",variant:"destructive"})}finally{T(null)}}},$=async t=>{E(t.id);try{const{data:s,error:r}=await b.functions.invoke("generate-offer-pdf",{body:{make:t.make,model:t.model,model_variant:t.model_variant,color_exterior:t.color_exterior,first_registration:t.first_registration,mileage_km:null,interior_desc:t.interior_desc,equipment:t.equipment,equipment_highlights:t.equipment_highlights,purchase_price_gross:t.purchase_price_gross,purchase_price_net:t.purchase_price_net,down_payment:t.down_payment,broker_fee:t.broker_fee,rates:t.rates,customer_name:t.customer_name,customer_email:t.customer_email,customer_phone:t.customer_phone}});if(r)throw r;const h=new Blob([Uint8Array.from(atob(s.pdf),J=>J.charCodeAt(0))],{type:"application/pdf"}),O=URL.createObjectURL(h),g=document.createElement("a");g.href=O,g.download=`Angebot_${t.make}_${t.model}_${N(new Date,"yyyy-MM-dd")}.pdf`,document.body.appendChild(g),g.click(),document.body.removeChild(g),URL.revokeObjectURL(O),c({title:"PDF erstellt",description:"Der Download wird gestartet."})}catch(s){console.error("Error generating PDF:",s),c({title:"Fehler",description:"PDF konnte nicht erstellt werden.",variant:"destructive"})}finally{E(null)}},F=t=>me(new Date(t),m),G=t=>{const s=F(t.expires_at);return t.status==="archiviert"?e.jsx(l,{variant:"secondary",children:"Archiviert"}):s<0?e.jsx(l,{variant:"destructive",children:"Abgelaufen"}):s<=7?e.jsxs(l,{variant:"destructive",className:"bg-amber-500 hover:bg-amber-600",children:[e.jsx(he,{className:"h-3 w-3 mr-1"}),s===0?"Heute":`${s} Tage`]}):e.jsx(l,{variant:"outline",className:"text-muted-foreground",children:N(new Date(t.expires_at),"dd.MM.yyyy",{locale:R})})},V=t=>{const s=t.status==="archiviert",r=j(new Date(t.expires_at),m),h=F(t.expires_at)<=7&&!r;return e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx(a,{size:"sm",variant:"ghost",onClick:()=>$(t),disabled:C===t.id,title:"PDF herunterladen",children:C===t.id?e.jsx(y,{className:"h-4 w-4 animate-spin"}):e.jsx(pe,{className:"h-4 w-4"})}),s||r?e.jsx(a,{size:"sm",variant:"ghost",onClick:()=>H(t.id),disabled:u.isPending,title:"Reaktivieren (30 Tage)",children:e.jsx(xe,{className:"h-4 w-4"})}):e.jsxs(e.Fragment,{children:[h&&e.jsx(a,{size:"sm",variant:"ghost",onClick:()=>I(t.id),disabled:u.isPending,title:"Um 30 Tage verlängern",children:e.jsx(re,{className:"h-4 w-4"})}),e.jsx(a,{size:"sm",variant:"ghost",onClick:()=>U(t.id),disabled:u.isPending,title:"Archivieren",children:e.jsx(ge,{className:"h-4 w-4"})})]}),e.jsx(a,{size:"sm",variant:"ghost",onClick:()=>Q(t.id),disabled:f===t.id,title:"Endgültig löschen",className:"text-destructive hover:text-destructive",children:f===t.id?e.jsx(y,{className:"h-4 w-4 animate-spin"}):e.jsx(ve,{className:"h-4 w-4"})})]})},W=t=>t.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsxs("p",{className:"text-muted-foreground",children:[o==="aktiv"&&"Keine aktiven Angebote vorhanden.",o==="ablaufend"&&"Keine ablaufenden Angebote.",o==="archiv"&&"Keine archivierten Angebote."]}),o==="aktiv"&&e.jsx(a,{onClick:()=>A("/angebotserstellung"),variant:"outline",className:"mt-4",children:"Erstes Angebot erstellen"})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ne,{children:[e.jsx(le,{children:e.jsxs(S,{children:[e.jsx(i,{children:"Datum"}),e.jsx(i,{children:"Typ"}),e.jsx(i,{children:"Fahrzeug"}),e.jsx(i,{children:"Kunde"}),e.jsx(i,{className:"text-right",children:"Kaufpreis"}),e.jsx(i,{className:"text-center",children:"Leasingraten"}),e.jsx(i,{className:"text-center",children:"Gültig bis"}),e.jsx(i,{className:"text-right",children:"Aktionen"})]})}),e.jsx(ce,{children:t.map(s=>e.jsxs(S,{children:[e.jsx(n,{className:"whitespace-nowrap",children:N(new Date(s.created_at),"dd.MM.yyyy HH:mm",{locale:R})}),e.jsx(n,{children:s.offer_type==="bmw"?e.jsx(l,{className:"bg-blue-500 hover:bg-blue-600 text-white",children:"BMW"}):e.jsx(l,{className:"bg-amber-600 hover:bg-amber-700 text-white",children:"Luxus"})}),e.jsxs(n,{children:[e.jsxs("div",{className:"font-medium",children:[s.make," ",s.model]}),s.model_variant&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s.model_variant})]}),e.jsx(n,{children:s.customer_name?e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.customer_name}),s.customer_email&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s.customer_email})]}):e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsxs(n,{className:"text-right whitespace-nowrap",children:[s.purchase_price_gross.toLocaleStr
1ing("de-DE")," €"]}),e.jsx(n,{className:"text-center",children:e.jsxs(l,{variant:"outline",className:"bg-primary/10 text-primary border-0",children:[Array.isArray(s.rates)?s.rates.length:0," Optionen"]})}),e.jsx(n,{className:"text-center",children:G(s)}),e.jsx(n,{className:"text-right",children:V(s)})]},s.id))})]})});return e.jsx(te,{children:e.jsxs("div",{className:"container mx-auto py-8 space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Angebote"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Alle erstellten Kundenangebote verwalten"})]}),e.jsxs(a,{onClick:()=>A("/angebotserstellung"),children:[e.jsx(ue,{className:"h-4 w-4 mr-2"}),"Neues Angebot"]})]}),x>0&&e.jsxs(oe,{className:"border-amber-500/50 bg-amber-500/10",children:[e.jsx(se,{className:"h-4 w-4 text-amber-500"}),e.jsxs(de,{className:"text-amber-700 dark:text-amber-400",children:[e.jsxs("strong",{children:[x," ",x===1?"Angebot läuft":"Angebote laufen"]})," in den nächsten 7 Tagen ab –",e.jsx(a,{variant:"link",className:"text-amber-700 dark:text-amber-400 p-0 h-auto ml-1",onClick:()=>D("ablaufend"),children:"jetzt prüfen"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 items-center justify-between",children:[e.jsx(q,{value:w,onValueChange:t=>P(t),children:e.jsxs(B,{children:[e.jsx(p,{value:"alle",children:"Alle Angebote"}),e.jsxs(p,{value:"luxus",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-600 mr-2"}),"Luxusangebote"]}),e.jsxs(p,{value:"bmw",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-blue-500 mr-2"}),"BMW-Angebote"]})]})}),e.jsx(q,{value:o,onValueChange:t=>D(t),children:e.jsxs(B,{children:[e.jsx(p,{value:"aktiv",children:"Aktiv"}),e.jsxs(p,{value:"ablaufend",className:"relative",children:["Ablaufend",x>0&&e.jsx(l,{variant:"destructive",className:"ml-2 h-5 w-5 p-0 flex items-center justify-center text-xs bg-amber-500",children:x})]}),e.jsx(p,{value:"archiv",children:"Archiv"})]})})]}),e.jsx(ae,{className:"mt-4",children:e.jsx(ie,{className:"p-0",children:K?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(y,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):W(z)})})]})})}export{Nt 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.