import{f as O,o as H,c as Q,b as a,a as n,q as g,z as Y,a8 as K,B as C,j as A,ay as X,S as Z,F as ee,r as s,e as $}from"./vendor-BDR7yMJi.js";import{_ as te}from"./ComboDynamique-DbhbUtR4.js";import{_ as ae}from"./selectDate-Dd47YHbm.js";import{_ as le}from"./FavorisSwitch-DFHH_fud.js";import{_ as oe,u as re,a as F,s as c,S as z,h as d}from"./index-BSaHX2oa.js";const ne={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},se={class:"btns flex items-center gap-2"},ie={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},de={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-4"},ue={class:"ag-theme-quartz",style:{height:"calc(100vh - 290px)"}},ce={class:"flex justify-end gap-6 p-3 bg-gray-50 border-t"},me={class:"text-sm"},pe={class:"font-bold ml-2"},fe={class:"text-sm"},ge={class:"font-bold ml-2"},ve={class:"text-sm"},he={class:"font-bold ml-2 text-green-600"},be={class:"flex flex-col gap-4 p-4"},xe={class:"flex gap-4"},ye={class:"flex items-center gap-2"},_e={class:"flex items-center gap-2"},we={class:"flex justify-end gap-2"},Ce={__name:"ComptoireJournalCaisse",setup($e){const{showError:D,showWarn:h}=re(),p=s(!1),f=s("landscape"),u=s([]),V=s(),R=s(),b=s(""),x=s(""),y=s(0),N=s(0),_=s(""),w=s(""),k=(t,e)=>{_.value=t,w.value=e},P=$(()=>u.value.reduce((t,e)=>t+(e.ttc||0),0)),T=$(()=>u.value.reduce((t,e)=>t+(e.mtregle||0),0)),G=$(()=>{const t=[];return u.value.forEach(e=>{t.push({path:[String(e.nbl)],isParent:!0,nbl:e.nbl,date:e.date,code_client:e.code_client,nom:e.nom,ttc:e.ttc,mtregle:e.mtregle,modes_paiement:e.modes_paiement,vendeur:e.vendeur}),(e.lignes||[]).forEach((l,r)=>{t.push({path:[String(e.nbl),`${e.nbl}-${r}`],isParent:!1,code_art:l.code_art,libelle:l.libelle,reference:l.reference,qte:l.qte,pu_ttc:l.pu_ttc,remise:l.remise,total:l.total})})}),t}),I=()=>{if(!u.value?.length){h("Aucune donnée à imprimer");return}const t=window.open("","_blank","width=1200,height=800");let e="";u.value.forEach(r=>{const m=r.date?new Date(r.date).toLocaleString("fr-FR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}):"";e+=`
      <tr class="ticket-row">
        <td><strong>${r.nbl}</strong></td>
        <td>${m}</td>
        <td>${r.nom||""}</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td class="text-right"><strong>${d(r.ttc)}</strong></td>
        <td class="mode-paiement">${r.modes_paiement||""}</td>
        <td>${r.vendeur||""}</td>
      </tr>
    `,(r.lignes||[]).forEach(i=>{const v=i.remise>0?(i.remise*100).toFixed(0)+"%":"";e+=`
        <tr class="article-row">
          <td></td>
          <td></td>
          <td></td>
          <td>${i.code_art||""}</td>
          <td>${i.libelle||""}</td>
          <td class="text-right">${d(i.qte)}</td>
          <td class="text-right">${d(i.pu_ttc)}</td>
          <td class="text-right">${d(i.total)}</td>
          <td>${v}</td>
          <td></td>
        </tr>
      `})});const l=`
    <!DOCTYPE html>
    <html>
    <head>
      <title>Journal de caisse</title>
      <style>
        body {
          font-family: Arial, sans-serif;
          margin: 20px;
          font-size: 11px;
        }
        h1 {
          text-align: center;
          margin-bottom: 20px;
          font-size: 16px;
        }
        table {
          width: 100%;
          border-collapse: collapse;
          font-size: 10px;
        }
        th, td {
          padding: 4px 6px;
          border: 1px solid #ccc;
          font-size: 10px;
        }
        th {
          background-color: #f0f0f0;
          font-weight: bold;
        }
        .ticket-row {
          background-color: #f8fafc;
        }
        .ticket-row td {
          border-top: 2px solid #333;
        }
        .article-row {
          color: #555;
        }
        .text-right {
          text-align: right;
        }
        .mode-paiement {
          color: #2563eb;
          font-style: italic;
        }
        .print-btn {
          background: #4CAF50;
          color: white;
          padding: 8px 16px;
          border: none;
          cursor: pointer;
          margin: 15px 8px;
          font-size: 14px;
        }
        .totaux {
          margin-top: 20px;
          text-align: right;
          font-size: 12px;
        }
        .totaux strong {
          margin-left: 20px;
        }
        @media print {
          .no-print { display: none !important; }
          body { margin: 0; font-size: 9px; }
          h1 { font-size: 14px; }
          table { font-size: 8px; }
          th, td { padding: 3px; font-size: 8px; }
          @page {
            size: ${f.value};
            margin: 1cm;
          }
        }
      </style>
    </head>
    <body>
      <div class="no-print" style="text-align:center;">
        <button class="print-btn" onclick="window.print()">🖨️ Imprimer</button>
        <button class="print-btn" onclick="window.close()" style="background:#f44336;">❌ Fermer</button>
      </div>

      <h1>Journal de caisse</h1>

      <table>
        <thead>
          <tr>
            <th>N° Ticket</th>
            <th>Date</th>
            <th>Client</th>
            <th>Code Art.</th>
            <th>Libellé</th>
            <th>Qté</th>
            <th>P.U TTC</th>
            <th>Total</th>
            <th>Mode paiement / Rem%</th>
            <th>Vendeur</th>
          </tr>
        </thead>
        <tbody>
          ${e}
        </tbody>
      </table>

      <div class="totaux">
        <strong>Nombre de tickets: ${u.value.length}</strong>
        <strong>Total TTC: ${d(P.value)}</strong>
        <strong>Total réglé: ${d(T.value)}</strong>
      </div>
    </body>
    </html>
  `;t.document.write(l),t.document.close(),p.value=!1},J=t=>t.path,U=t=>t.data&&t.data.isParent?{backgroundColor:"#f8fafc",fontWeight:"bold"}:null,E={headerName:"N° Ticket / Article",width:280,cellRendererParams:{suppressCount:!0},valueGetter:t=>t.data.isParent?`Ticket ${t.data.nbl}`:t.data.code_art||""},q=s([{field:"date",headerName:"Date",width:140,valueFormatter:t=>!t.value||!t.data?.isParent?"":new Date(t.value).toLocaleString("fr-FR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"})},{field:"nom",headerName:"Client",width:180,valueGetter:t=>t.data?.isParent?t.data.nom:""},{field:"libelle",headerName:"Libellé article",flex:1,minWidth:200,valueGetter:t=>t.data?.isParent?"":t.data?.libelle||""},{field:"qte",headerName:"Qté",width:70,valueFormatter:t=>t.data?.isParent||!t.value?"":d(t.value),cellStyle:{textAlign:"right"}},{field:"pu_ttc",headerName:"P.U TTC",width:90,valueFormatter:t=>t.data?.isParent||!t.value?"":d(t.value),cellStyle:{textAlign:"right"}},{field:"remise",headerName:"Rem%",width:70,valueFormatter:t=>{if(t.data?.isParent)return"";const e=t.value||0;return e>0?(e*100).toFixed(0)+"%":""},cellStyle:{textAlign:"right"}},{headerName:"Total",width:100,valueGetter:t=>t.data?.isParent?t.data.ttc:t.data?.total,valueFormatter:t=>d(t.value),cellStyle:{textAlign:"right",fontWeight:"bold"}},{field:"modes_paiement",headerName:"Modes de paiement",width:220,valueGetter:t=>t.data?.isParent?t.data.modes_paiement:"",cellStyle:{fontStyle:"italic",color:"#2563eb"}},{field:"vendeur",headerName:"Vendeur",width:120,valueGetter:t=>t.data?.isParent?t.data.vendeur:""}]),B=s({sortable:!1,filter:!1,resizable:!0,suppressHeaderMenuButton:!0,suppressHeaderFilterButton:!0}),j=t=>{R.value=t.api};O(async()=>{await L();const t=new Date,e=t.getFullYear(),l=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),m=`${e}-${l}-${r}`;_.value=m,w.value=m,S()});const L=async()=>{try{const e=(await F.post(`${c.lienApi}/verifierDroit/${c.state.dbCommun6}`,{id_utilisateur:c.userId,id_page:1104,mail:c.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(h("Vous n'avez pas le droit, veuillez consulter l'administrateur"),z("ComptoireJournalCaisse")))}catch(t){D(`Une erreur s'est produite lors de la vérification des droits.
 ${t}`)}},S=async()=>{c.state.afficher_in_progress=!0;try{const t=await F.post(`${c.lienApi}/JournalDeCaisse/${c.db}`,{dateDu:_.value,dateAu:w.value,code_client:b.value||"",code_article:x.value||"",IDcommercial:y.value||0},{headers:{"Content-Type":"application/json"}});u.value=t.data}catch{D("Une erreur est survenue lors du chargement des données.")}finally{c.state.afficher_in_progress=!1}},M=()=>{if(!u.value||u.value.length===0){h("Aucune donnée à imprimer");return}p.value=!0};return(t,e)=>{const l=Y,r=le,m=ae,i=te,v=X,W=Z;return H(),Q(ee,null,[a("div",ne,[a("div",se,[n(l,{icon:"pi pi-refresh",label:"Afficher",onClick:e[0]||(e[0]=o=>S()),text:"",loading:g(c).state.afficher_in_progress},null,8,["loading"]),n(l,{icon:"pi pi-print",label:"Imprimer",text:"",onClick:e[1]||(e[1]=o=>M())}),n(l,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=o=>g(z)("ComptoireJournalCaisse"))})]),a("div",ie,[n(r,{fen:"ComptoireJournalCaisse",text:"Journal de caisse"})])]),a("div",null,[a("div",de,[a("div",null,[e[10]||(e[10]=a("label",{class:"block text-sm"},"Période",-1)),n(m,{onSelectDate:k,resetCounter:N.value,size:"small"},null,8,["resetCounter"])]),a("div",null,[e[11]||(e[11]=a("label",{class:"block text-sm"},"Client",-1)),n(i,{modelValue:b.value,"onUpdate:modelValue":e[3]||(e[3]=o=>b.value=o),placeholder:"Recherche...",table:"client",class:"w-full",size:"small"},null,8,["modelValue"])]),a("div",null,[e[12]||(e[12]=a("label",{class:"block text-sm"},"Article",-1)),n(i,{modelValue:x.value,"onUpdate:modelValue":e[4]||(e[4]=o=>x.value=o),placeholder:"Recherche...",table:"article",class:"w-full",size:"small"},null,8,["modelValue"])]),a("div",null,[e[13]||(e[13]=a("label",{class:"block text-sm"},"Commercial",-1)),n(i,{id:"commercial",table:"commercial",modelValue:y.value,"onUpdate:modelValue":e[5]||(e[5]=o=>y.value=o),placeholder:"Tout",class:"w-full",size:"small"},null,8,["modelValue"])])])]),e[20]||(e[20]=a("div",{class:"h-2"},null,-1)),a("div",ue,[n(g(K),{ref_key:"gridRef",ref:V,rowData:G.value,columnDefs:q.value,defaultColDef:B.value,treeData:!0,getDataPath:J,groupDefaultExpanded:-1,autoGroupColumnDef:E,animateRows:!0,localeText:t.$agGridLocale,getRowStyle:U,onGridReady:j,style:{width:"100%",height:"100%"}},null,8,["rowData","columnDefs","defaultColDef","localeText"])]),a("div",ce,[a("div",me,[e[14]||(e[14]=a("span",{class:"text-gray-600"},"Nombre de tickets:",-1)),a("span",pe,C(u.value.length),1)]),a("div",fe,[e[15]||(e[15]=a("span",{class:"text-gray-600"},"Total TTC:",-1)),a("span",ge,C(g(d)(P.value)),1)]),a("div",ve,[e[16]||(e[16]=a("span",{class:"text-gray-600"},"Total réglé:",-1)),a("span",he,C(g(d)(T.value)),1)])]),n(W,{visible:p.value,"onUpdate:visible":e[9]||(e[9]=o=>p.value=o),header:"Impression : Journal de caisse",modal:"",style:{width:"400px"}},{footer:A(()=>[a("div",we,[n(l,{label:"Annuler",icon:"pi pi-times",severity:"secondary",outlined:"",onClick:e[8]||(e[8]=o=>p.value=!1)}),n(l,{label:"Aperçu et Impression",icon:"pi pi-print",onClick:I})])]),default:A(()=>[a("div",be,[a("div",null,[e[19]||(e[19]=a("label",{class:"block text-sm font-medium mb-2"},"Orientation",-1)),a("div",xe,[a("div",ye,[n(v,{id:"portrait",modelValue:f.value,"onUpdate:modelValue":e[6]||(e[6]=o=>f.value=o),value:"portrait"},null,8,["modelValue"]),e[17]||(e[17]=a("label",{for:"portrait"},"Portrait",-1))]),a("div",_e,[n(v,{id:"paysage",modelValue:f.value,"onUpdate:modelValue":e[7]||(e[7]=o=>f.value=o),value:"landscape"},null,8,["modelValue"]),e[18]||(e[18]=a("label",{for:"paysage"},"Paysage",-1))])])])])]),_:1},8,["visible"])],64)}}},Fe=oe(Ce,[["__scopeId","data-v-53ec68b3"]]);export{Fe as default};
