import{b as ae,U as le,M as oe,f as re}from"./primevue-CfIk0_DY.js";import{C as ne}from"./ComboDynamique-BzWI4ISP.js";import{s as se}from"./selectDate-Dai2cu2_.js";import{_ as ie}from"./FavorisSwitch-BFqqA1tj.js";import{S as de}from"./ag-grid-B5G7j3Qp.js";import{_ as ue,u as ce,b as R,s as d,S as z,o as u}from"./index-BxIwIJfy.js";import{o as me,b as P,c as k,d as a,v as l,a7 as g,p as N,k as pe,l as U,F as fe,y as m,a as s}from"./vue-core-Di3IuVqe.js";import"./moment-BeHQNF8T.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";const ge={class:"page-wrapper w-full"},ve={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between",style:{gap:"8px",padding:"4px"}},he={class:"flex items-center",style:{gap:"8px"}},be={class:"flex items-center whitespace-nowrap",style:{gap:"12px"}},xe={class:"rounded-lg shrink-0",style:{padding:"12px","margin-bottom":"12px"}},ye={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5",style:{gap:"16px"}},we={key:0},_e={class:"flex flex-wrap items-center",style:{gap:"8px","margin-bottom":"8px"}},Ce={class:"ag-theme-quartz grille-container"},$e={class:"flex flex-col gap-4 p-4"},De={class:"flex gap-4"},Ae={class:"flex items-center gap-2"},Pe={class:"flex items-center gap-2"},Te={class:"flex justify-end gap-2"},Ve={__name:"ComptoireJournalCaisse",setup(Se){const{showError:T,showWarn:w}=ce(),v=s(!1),h=s("landscape"),c=s([]),G=s(),I=s(),_=s(""),C=s(""),$=s(0),b=s(0),J=m(()=>!!d.state.enreg_option_comm?.numerotation_par_agence),V=m(()=>d.state.userCommun6?.id_agence||0),E=m(()=>!!d.state.userCommun6?.Access_Agence),q=m(()=>V.value>0&&!E.value),B=m(()=>J.value),L=s(0),D=s(""),A=s(""),M=(t,e)=>{D.value=t,A.value=e},x=m(()=>c.value.reduce((t,e)=>t+(e.ttc||0),0)),y=m(()=>c.value.reduce((t,e)=>t+(e.mtregle||0),0)),W=m(()=>{const t=[];return c.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((o,n)=>{t.push({path:[String(e.nbl),`${e.nbl}-${n}`],isParent:!1,code_art:o.code_art,libelle:o.libelle,reference:o.reference,qte:o.qte,pu_ttc:o.pu_ttc,remise:o.remise,total:o.total})})}),t}),j=()=>{if(!c.value?.length){w("Aucune donnée à imprimer");return}const t=window.open("","_blank","width=1200,height=800");let e="";c.value.forEach(n=>{const p=n.date?new Date(n.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>${n.nbl}</strong></td>
        <td>${p}</td>
        <td>${n.nom||""}</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td class="text-right"><strong>${u(n.ttc)}</strong></td>
        <td class="mode-paiement">${n.modes_paiement||""}</td>
        <td>${n.vendeur||""}</td>
      </tr>
    `,(n.lignes||[]).forEach(i=>{const f=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">${u(i.qte)}</td>
          <td class="text-right">${u(i.pu_ttc)}</td>
          <td class="text-right">${u(i.total)}</td>
          <td>${f}</td>
          <td></td>
        </tr>
      `})});const o=`
    <!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: var(--omag-500);
          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: ${h.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: ${c.value.length}</strong>
        <strong>Total TTC: ${u(x.value)}</strong>
        <strong>Total réglé: ${u(y.value)}</strong>
      </div>
    </body>
    </html>
  `;t.document.write(o),t.document.close(),v.value=!1},O=t=>t.path,H=t=>t.data&&t.data.isParent?{backgroundColor:"#f8fafc",fontWeight:"bold"}:null,Q={headerName:"N° Ticket / Article",width:280,cellRendererParams:{suppressCount:!0},valueGetter:t=>t.data.isParent?`Ticket ${t.data.nbl}`:t.data.code_art||""},Y=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?"":u(t.value),cellStyle:{textAlign:"right"}},{field:"pu_ttc",headerName:"P.U TTC",width:90,valueFormatter:t=>t.data?.isParent||!t.value?"":u(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=>u(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:"var(--omag-500)"}},{field:"vendeur",headerName:"Vendeur",width:120,valueGetter:t=>t.data?.isParent?t.data.vendeur:""}]),K=s({sortable:!1,filter:!1,resizable:!0,suppressHeaderMenuButton:!0,suppressHeaderFilterButton:!0}),X=t=>{I.value=t.api};me(async()=>{await Z(),b.value=V.value;const t=new Date,e=t.getFullYear(),o=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),p=`${e}-${o}-${n}`;D.value=p,A.value=p,S()});const Z=async()=>{try{const e=(await R.post(`${d.lienApi}/verifierDroit/${d.state.dbCommun6}`,{id_utilisateur:d.userId,id_page:1104,mail:d.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(w("Vous n'avez pas le droit, veuillez consulter l'administrateur"),z("ComptoireJournalCaisse")))}catch(t){T(`Une erreur s'est produite lors de la vérification des droits.
 ${t}`)}},S=async()=>{d.state.afficher_in_progress=!0;try{const t=await R.post(`${d.lienApi}/JournalDeCaisse/${d.db}`,{dateDu:D.value,dateAu:A.value,code_client:_.value||"",code_article:C.value||"",IDcommercial:$.value||0,id_agence:b.value},{headers:{"Content-Type":"application/json"}});c.value=t.data}catch{T("Une erreur est survenue lors du chargement des données.")}finally{d.state.afficher_in_progress=!1}},ee=()=>{if(!c.value||c.value.length===0){w("Aucune donnée à imprimer");return}v.value=!0};return(t,e)=>{const o=ae,n=ie,p=se,i=ne,f=le,F=oe,te=re;return P(),k(fe,null,[a("div",ge,[a("div",ve,[a("div",he,[l(o,{icon:"pi pi-refresh",label:"Afficher",onClick:e[0]||(e[0]=r=>S()),text:"",loading:g(d).state.afficher_in_progress},null,8,["loading"]),l(o,{icon:"pi pi-print",label:"Imprimer",text:"",onClick:e[1]||(e[1]=r=>ee())}),l(o,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=r=>g(z)("ComptoireJournalCaisse"))})]),a("div",be,[l(n,{fen:"ComptoireJournalCaisse",text:"Journal de caisse"})])]),a("div",xe,[a("div",ye,[a("div",null,[e[11]||(e[11]=a("label",{class:"block",style:{"margin-bottom":"4px"}},"Période",-1)),l(p,{onSelectDate:M,resetCounter:L.value,size:"small"},null,8,["resetCounter"])]),a("div",null,[e[12]||(e[12]=a("label",{class:"block",style:{"margin-bottom":"4px"}},"Client",-1)),l(i,{modelValue:_.value,"onUpdate:modelValue":e[3]||(e[3]=r=>_.value=r),placeholder:"Recherche...",table:"client",class:"w-full",size:"small"},null,8,["modelValue"])]),a("div",null,[e[13]||(e[13]=a("label",{class:"block",style:{"margin-bottom":"4px"}},"Article",-1)),l(i,{modelValue:C.value,"onUpdate:modelValue":e[4]||(e[4]=r=>C.value=r),placeholder:"Recherche...",table:"article",class:"w-full",size:"small"},null,8,["modelValue"])]),a("div",null,[e[14]||(e[14]=a("label",{class:"block",style:{"margin-bottom":"4px"}},"Commercial",-1)),l(i,{id:"commercial",table:"commercial",modelValue:$.value,"onUpdate:modelValue":e[5]||(e[5]=r=>$.value=r),placeholder:"Tout",class:"w-full",size:"small"},null,8,["modelValue"])]),B.value?(P(),k("div",we,[e[15]||(e[15]=a("label",{class:"block",style:{"margin-bottom":"4px"}},"Agence",-1)),l(i,{table:"agence",modelValue:b.value,"onUpdate:modelValue":e[6]||(e[6]=r=>b.value=r),placeholder:"Toutes les agences",class:"w-full",size:"small",disabled:q.value},null,8,["modelValue","disabled"])])):N("",!0)])]),a("div",_e,[l(f,{value:`${c.value.length} ticket${c.value.length>1?"s":""}`,severity:"info",icon:"pi pi-receipt"},null,8,["value"]),l(f,{value:`TTC : ${g(u)(x.value)}`,severity:"secondary",icon:"pi pi-wallet"},null,8,["value"]),l(f,{value:`Réglé : ${g(u)(y.value)}`,severity:"success",icon:"pi pi-check-circle"},null,8,["value"]),x.value-y.value>.001?(P(),pe(f,{key:0,value:`Reste : ${g(u)(x.value-y.value)}`,severity:"warn",icon:"pi pi-exclamation-triangle"},null,8,["value"])):N("",!0)]),a("div",Ce,[l(g(de),{ref_key:"gridRef",ref:G,rowData:W.value,columnDefs:Y.value,defaultColDef:K.value,treeData:!0,getDataPath:O,groupDefaultExpanded:-1,autoGroupColumnDef:Q,animateRows:!0,localeText:t.$agGridLocale,getRowStyle:H,onGridReady:X,style:{width:"100%",height:"100%"}},null,8,["rowData","columnDefs","defaultColDef","localeText"])])]),l(te,{visible:v.value,"onUpdate:visible":e[10]||(e[10]=r=>v.value=r),header:"Impression : Journal de caisse",modal:"",style:{width:"400px"}},{footer:U(()=>[a("div",Te,[l(o,{label:"Annuler",icon:"pi pi-times",severity:"secondary",outlined:"",onClick:e[9]||(e[9]=r=>v.value=!1)}),l(o,{label:"Aperçu et Impression",icon:"pi pi-print",onClick:j})])]),default:U(()=>[a("div",$e,[a("div",null,[e[18]||(e[18]=a("label",{class:"block text-sm font-medium mb-2"},"Orientation",-1)),a("div",De,[a("div",Ae,[l(F,{id:"portrait",modelValue:h.value,"onUpdate:modelValue":e[7]||(e[7]=r=>h.value=r),value:"portrait"},null,8,["modelValue"]),e[16]||(e[16]=a("label",{for:"portrait"},"Portrait",-1))]),a("div",Pe,[l(F,{id:"paysage",modelValue:h.value,"onUpdate:modelValue":e[8]||(e[8]=r=>h.value=r),value:"landscape"},null,8,["modelValue"]),e[17]||(e[17]=a("label",{for:"paysage"},"Paysage",-1))])])])])]),_:1},8,["visible"])],64)}}},qe=ue(Ve,[["__scopeId","data-v-82f69c84"]]);export{qe as default};
