1import{n as z,u as U,r as g,aq as X,ap as G,p as y,v as n,aC as M,M as r,am as $,aD as N,s as w,an as V,as as J,x,z as I,ar as E,g as K,q as Q,c as W,w as F,T as P,o as Z,_ as tt}from"./Cji3jh9V.js";import{_ as et}from"./CbsfSqvg.js";const at={class:"max-w-3xl mx-auto p-4 sm:p-6 space-y-6"},nt={class:"bg-white rounded-lg border border-gray-200 p-5 space-y-4"},rt={class:"grid grid-cols-1 sm:grid-cols-2 gap-4"},ot=["max"],st=["min","max"],lt={class:"flex flex-wrap gap-2"},it=["onClick"],dt={key:0,class:"text-xs text-red-600"},ut={class:"pt-2 flex items-center justify-between gap-3"},ct={class:"text-xs text-gray-500"},mt=["disabled"],bt=z({__name:"export",setup(pt){const{$db:h}=U(),v=(()=>{const t=new Date;return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`})(),s=g((()=>{const t=new Date;return t.setDate(1),`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-01`})()),l=g(v),u=g(!1),d=g(null),f=g(null),c=t=>{const e=new Date(t);return e.setHours(0,0,0,0),e},m=t=>{const e=new Date(t);return e.setHours(23,59,59,999),e},_=t=>`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`,L=[{label:"Aujourd'hui",from:()=>c(new Date),to:()=>m(new Date)},{label:"7 derniers jours",from:()=>{const t=new Date;return t.setDate(t.getDate()-6),c(t)},to:()=>m(new Date)},{label:"Mois en cours",from:()=>{const t=new Date;return t.setDate(1),c(t)},to:()=>m(new Date)},{label:"Mois précédent",from:()=>{const t=new Date;return t.setMonth(t.getMonth()-1,1),c(t)},to:()=>{const t=new Date;return t.setDate(0),m(t)}},{label:"Année en cours",from:()=>c(new Date(new Date().getFullYear(),0,1)),to:()=>m(new Date)}],j=t=>{s.value=_(t.from()),l.value=_(t.to())},B=t=>{if(!t?.toDate)return"";const e=t.toDate();return new Intl.DateTimeFormat("fr-FR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(e)},H=t=>{if(!t?.toDate)return"";const e=t.toDate();return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`},O=async()=>{if(!(!h||u.value)){d.value=null,u.value=!0;try{const[t,e,D]=s.value.split("-").map(Number),[o,S,Y]=l.value.split("-").map(Number),T=new Date(t,(e||1)-1,D||1,0,0,0,0),A=new Date(o,(S||1)-1,Y||1,23,59,59,999);if(T>A){d.value="La date de début doit être antérieure ou égale à la date de fin.";return}const p=(await K(Q(W(h,"achats"),F("createdAt",">=",P.fromDate(T)),F("createdAt","<=",P.fromDate(A)),Z("createdAt","asc")))).docs.map(i=>{const a=i.data(),R=a.stripeStatus==="credit_contact"||Number(a.montantHT)===0;return{"Achat ID":i.id,"Date (Paris)":B(a.createdAt),Jour:H(a.createdAt),"Lead ID":a.leadId||"","Titre lead":a.lead?.titre||"",Activité:a.lead?.activite||"",Ville:a.lead?.ville||"",CP:a.lead?.codePostal||"",Département:a.lead?.departement||"","Client nom":a.lead?.nom||"","Client tél":a.lead?.tel||"","Client email":a.lead?.email||"","Origine lead":a.lead?.origine||"","Artisan email":a.artisanEmail||"","Montant HT (â¬)":Number(a.montantHT)||0,"TVA (â¬)":Number(a.montantTaxe)||0,"Montant TTC (â¬)":Number(a.montantTTC)||0,Devise:a.currency||"eur",Type:R?"Crédit contact (offert)":"Stripe","Stripe status":a.stripeStatus||"","Payment Intent":a.stripePaymentIntentId||"","Stripe Session":a.stripeSessionId||"","Durée avant achat (s)":a.dureeAvantAchatSecondes??"","Tarif lead (â¬)":Number(a.lead?.tarif)||0}});if(f.value=p.length,p.length===0){d.value="Aucune vente trouvée sur la période sélectionnée.";return}const b=await tt(()=>import("./CNerDvZX.js"),[],import.meta.url),C=b.utils.json_to_sheet(p),q=Object.keys(p[0]).map(i=>({wch:Math.max(i.length,...p.map(a=>String(a[i]??"").length))+2}));C["!cols"]=q.map(i=>({wch:Math.min(i.wch,45)}));const k=b.utils.book_new();b.utils.book_append_sheet(k,C,"Ventes"),b.writeFile(k,`Ventes_${s.value}_${l.value}.xlsx`)}catch(t){console.error("[export] error:",t),d.value=t?.message||"Erreur inattendue lors de l'export."}finally{u.value=!1}}};return(t,e)=>{const D=et;return y(),X(D,{name:"admin"},{default:G(()=>
1[n("div",at,[e[5]||(e[5]=n("div",null,[n("h1",{class:"text-xl sm:text-2xl font-semibold text-gray-900"},"Export des ventes"),n("p",{class:"mt-1 text-sm text-gray-600"}," Téléchargez toutes vos ventes sur la période choisie au format Excel. ")],-1)),n("div",nt,[n("div",rt,[n("div",null,[e[2]||(e[2]=n("label",{class:"block text-sm font-medium text-gray-700 mb-1.5"},"Du",-1)),M(n("input",{"onUpdate:modelValue":e[0]||(e[0]=o=>$(s)?s.value=o:null),type:"date",max:r(l)||r(v),class:"w-full px-3 py-2 bg-white border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-gray-900"},null,8,ot),[[N,r(s)]])]),n("div",null,[e[3]||(e[3]=n("label",{class:"block text-sm font-medium text-gray-700 mb-1.5"},"Au (inclus)",-1)),M(n("input",{"onUpdate:modelValue":e[1]||(e[1]=o=>$(l)?l.value=o:null),type:"date",min:r(s),max:r(v),class:"w-full px-3 py-2 bg-white border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-gray-900"},null,8,st),[[N,r(l)]])])]),n("div",lt,[(y(),w(V,null,J(L,o=>n("button",{key:o.label,type:"button",onClick:S=>j(o),class:"px-3 py-1 text-xs font-medium text-gray-700 bg-white border border-gray-300 rounded-full hover:bg-gray-50"},x(o.label),9,it)),64))]),r(d)?(y(),w("div",dt,x(r(d)),1)):I("",!0),n("div",ut,[n("p",ct,[r(f)!==null?(y(),w(V,{key:0},[E(" Dernier export : "+x(r(f))+" vente"+x(r(f)>1?"s":"")+". ",1)],64)):I("",!0)]),n("button",{type:"button",onClick:O,disabled:r(u)||!r(s)||!r(l),class:"inline-flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-gray-900 rounded-lg hover:bg-gray-800 disabled:opacity-50"},[e[4]||(e[4]=n("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[n("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})],-1)),E(" "+x(r(u)?"Générationâ¦":"Exporter en Excel"),1)],8,mt)])]),e[6]||(e[6]=n("div",{class:"rounded-lg border border-gray-200 bg-gray-50 p-3 text-xs text-gray-600"}," Le fichier contient une ligne par vente, avec les infos du lead, du client, de l'artisan acheteur et les montants (HT, TVA, TTC). ",-1))])]),_:1})}}});
1export{bt 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.