@airporting/tech-app 0.0.95 → 0.0.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -78,12 +78,14 @@ export interface EtatSaisieDossierLine {
78
78
  dossier: string;
79
79
  fiscal_year_end: string | null;
80
80
  gla_active: boolean;
81
+ gla_last_sync_date: string | null;
81
82
  last_entry_date: string | null;
82
83
  last_reconciliation_date: string | null;
83
84
  logo_updated_at: string | null;
84
85
  managed: boolean;
85
86
  pending_supplier_invoices: number | null;
86
87
  reason: string | null;
88
+ refreshed_at: string | null;
87
89
  responsable: ResponsableOption | null;
88
90
  slug: string | null;
89
91
  solde_attente_eur: number;
Binary file
@@ -1 +1 @@
1
- "use strict";(globalThis["chunk_tech_app"]=globalThis["chunk_tech_app"]||[]).push([["7915"],{3437:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{D:()=>CompanyLogo});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(5893);var _mantine_core__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(207);const BASE_URL="https://s3.dualstack.eu-west-3.amazonaws.com/media.airporting/companies";function CompanyLogo({slug,updatedAt,size=20,...rest}){const base=`${BASE_URL}/${slug}.png`;const url=updatedAt?`${base}?v=${new Date(updatedAt).getTime()}`:base;return/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Image,{src:url,fallbackSrc:`${BASE_URL}/undefined.png`,alt:slug??"",w:size,h:size,fit:"contain",radius:"sm",style:{aspectRatio:1},...rest})}},1354:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{m:()=>PageHeader});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(5893);var _mantine_core__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(207);var _tabler_icons_react__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(9632);var react__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(3106);function formatRelative(now,then){const seconds=Math.max(0,Math.floor((now-then)/1e3));if(seconds<5)return"\xe0 l’instant";if(seconds<60)return`il y a ${seconds}s`;const minutes=Math.floor(seconds/60);if(minutes<60)return`il y a ${minutes} min`;const hours=Math.floor(minutes/60);return`il y a ${hours} h`}function PageHeader({title,leading,badge,updatedAt,isFetching,isError,onRefresh,actions}){const[now,setNow]=(0,react__WEBPACK_IMPORTED_MODULE_3__.useState)(()=>Date.now());(0,react__WEBPACK_IMPORTED_MODULE_3__.useEffect)(()=>{if(!updatedAt)return;const id=window.setInterval(()=>setNow(Date.now()),1e3);return()=>window.clearInterval(id)},[updatedAt]);const relative=updatedAt?formatRelative(now,updatedAt):null;const color=isError?"orange":isFetching?"teal":"dimmed";return/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Group,{justify:"space-between",align:"center",mih:48,mb:"md",children:[/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Group,{gap:"sm",align:"center",children:[leading,/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Title,{order:2,children:title}),badge]}),/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Group,{gap:"sm",align:"center",children:[relative&&/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Text,{size:"xs",c:color,fw:isFetching?600:400,"data-testid":"page-header-freshness",children:isError?"\xe9chec maj":isFetching?"maj…":relative}),onRefresh&&/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Tooltip,{label:"Rafra\xeechir",children:/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.ActionIcon,{variant:"default",size:"md",onClick:onRefresh,loading:isFetching,"aria-label":"Refresh",children:/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_tabler_icons_react__WEBPACK_IMPORTED_MODULE_2__.IconRefresh,{size:16})})}),actions]})]})}},9781:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{h:()=>QuickBooksIcon});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(5893);function QuickBooksIcon(props){const size=props.size??20;return/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("svg",{width:size,height:size,viewBox:"0 0 24 24",role:"img","aria-label":"QuickBooks",children:[/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("title",{children:"QuickBooks"}),/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("circle",{cx:"12",cy:"12",r:"12",fill:"#2CA01C"}),/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("text",{x:"12",y:"16.5",textAnchor:"middle",fontSize:"12",fontWeight:"700",fill:"#ffffff",fontFamily:"Arial, Helvetica, sans-serif",children:"qb"})]})}},243:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{j:()=>logoDevUrl});const LOGO_DEV_TOKEN="pk_BVN4OQv0Qs-bnqjdIgTppg";function logoDevUrl(domain){return`https://img.logo.dev/${domain}?token=${LOGO_DEV_TOKEN}`}},6016:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{default:()=>EtatSaisie});var jsx_runtime=__webpack_require__(5893);var index_js_=__webpack_require__(3106);var providers=__webpack_require__(7034);var index_mjs_=__webpack_require__(207);var esm_index_mjs_=__webpack_require__(3863);var modern_index_js_=__webpack_require__(6197);var useApi=__webpack_require__(4148);function useEtatSaisieLatest(){const api=(0,useApi.h)();return(0,modern_index_js_.useQuery)({queryKey:["tech","etat-saisie","latest"],queryFn:async()=>(await api.etatSaisie.getLatestV1()).data,refetchOnWindowFocus:true})}function useEtatSaisieRecompute(){const api=(0,useApi.h)();const qc=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:async()=>(await api.etatSaisie.recomputeV1()).data,onSuccess:()=>qc.invalidateQueries({queryKey:["tech","etat-saisie","latest"]})})}function DetailTable(props){const{columns,rows,onRowClick}=props;const[sortKey,setSortKey]=(0,index_js_.useState)(null);const[asc,setAsc]=(0,index_js_.useState)(false);const sorted=[...rows].sort((a,b)=>{if(!sortKey)return 0;const av=a[sortKey];const bv=b[sortKey];if("number"==typeof av&&"number"==typeof bv)return asc?av-bv:bv-av;return asc?String(av).localeCompare(String(bv)):String(bv).localeCompare(String(av))});const toggle=k=>{if(sortKey===k)setAsc(v=>!v);else{setSortKey(k);setAsc(false)}};const fmt=(v,numeric)=>{if(numeric&&"number"==typeof v)return v.toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2});if("boolean"==typeof v)return v?"✓":"";if(null==v)return"—";if("object"==typeof v)return"—";return String(v)};return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table,{striped:true,highlightOnHover:true,withTableBorder:true,stickyHeader:true,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Thead,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tr,{children:columns.map(c=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table.Th,{onClick:()=>toggle(c.key),style:{cursor:"pointer"},children:[c.label,sortKey===c.key?asc?" ▲":" ▼":""]},c.key))})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tbody,{children:0===sorted.length?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tr,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{colSpan:columns.length,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",ta:"center",children:"Aucune ligne"})})}):sorted.map((row,i)=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tr,{onClick:onRowClick?()=>onRowClick(row):void 0,style:onRowClick?{cursor:"pointer"}:void 0,children:columns.map(c=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{style:c.numeric?{textAlign:"right",fontVariantNumeric:"tabular-nums"}:void 0,children:c.render?c.render(row):fmt(row[c.key],c.numeric)},c.key))},i))})]})}function useDossiers(){const api=(0,useApi.h)();return(0,modern_index_js_.useQuery)({queryKey:["tech","etat-saisie","dossiers"],queryFn:async()=>(await api.etatSaisie.getDossiersV1()).data,refetchOnWindowFocus:true})}function useSetManaged(){const api=(0,useApi.h)();const qc=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:async variables=>(await api.etatSaisie.setManagedV1({id:variables.id},{managed:variables.managed})).data,onSuccess:()=>{qc.invalidateQueries({queryKey:["tech","etat-saisie","dossiers"]});qc.invalidateQueries({queryKey:["tech","etat-saisie","latest"]})}})}function useSetResponsable(){const api=(0,useApi.h)();const qc=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:async variables=>(await api.etatSaisie.setResponsableV1({id:variables.id},{notion_user_id:variables.notionUserId})).data,onSuccess:()=>{qc.invalidateQueries({queryKey:["tech","etat-saisie","dossiers"]})}})}var logoDev=__webpack_require__(243);var QuickBooksIcon=__webpack_require__(9781);const PROVIDER_DOMAIN={pennylane:"pennylane.com",zohobooks:"zoho.com",xero:"xero.com",odoo:"odoo.com"};function ProviderIcon(props){const{provider}=props;if(!provider)return null;if("quickbooks"===provider)return/*#__PURE__*/(0,jsx_runtime.jsx)(QuickBooksIcon.h,{size:20});const domain=PROVIDER_DOMAIN[provider];if(!domain)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"sm",variant:"light",color:"gray",title:provider,children:provider.slice(0,2).toUpperCase()});return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Image,{src:(0,logoDev.j)(domain),alt:provider,title:provider,w:20,h:20,fit:"contain",radius:"sm",style:{aspectRatio:1}})}function DossiersTab(){const isMobile=(0,esm_index_mjs_.useMediaQuery)("(max-width: 48em)",false);const dossiers=useDossiers();const setManaged=useSetManaged();const setResponsable=useSetResponsable();const[filter,setFilter]=(0,index_js_.useState)("");const options=dossiers.data?.responsable_options??[];const optionData=options.map(u=>({value:String(u.id),label:u.name}));const rows=(0,index_js_.useMemo)(()=>{const all=dossiers.data?.dossiers??[];const needle=filter.trim().toLowerCase();const filtered=needle?all.filter(dossier=>dossier.display_name.toLowerCase().includes(needle)||dossier.slug.toLowerCase().includes(needle)):all;return[...filtered].sort((a,b)=>a.display_name.localeCompare(b.display_name))},[dossiers.data,filter]);if(dossiers.isError)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"red",mt:"md",children:"Erreur de chargement des dossiers."});return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{mb:"md",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TextInput,{placeholder:"Filtrer par nom ou slug",value:filter,onChange:event=>setFilter(event.currentTarget.value),w:isMobile?"100%":320})}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Stack,{gap:"sm",children:0===rows.length?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",ta:"center",py:"xl",children:"Aucun dossier"}):rows.map(dossier=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{withBorder:true,p:"sm",radius:"md",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"sm",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:dossier.provider}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:dossier.display_name}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:dossier.slug})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Switch,{checked:dossier.managed,onChange:event=>setManaged.mutate({id:dossier.airporting_id,managed:event.currentTarget.checked})})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{placeholder:"Responsable",data:optionData,value:dossier.responsable?String(dossier.responsable.id):null,onChange:v=>setResponsable.mutate({id:dossier.airporting_id,notionUserId:v?Number(v):null}),searchable:true,clearable:true,leftSection:dossier.responsable?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:dossier.responsable.avatar_url,size:20,radius:"xl"}):void 0})]})},`${dossier.airporting_id}:${dossier.provider}`))}):/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table,{striped:true,highlightOnHover:true,withTableBorder:true,stickyHeader:true,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Thead,{children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table.Tr,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Source"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Dossier"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"G\xe9r\xe9"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Responsable"})]})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tbody,{children:0===rows.length?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tr,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{colSpan:4,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",ta:"center",children:"Aucun dossier"})})}):rows.map(dossier=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table.Tr,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:dossier.provider})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:dossier.display_name}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Switch,{checked:dossier.managed,onChange:event=>setManaged.mutate({id:dossier.airporting_id,managed:event.currentTarget.checked})})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{placeholder:"—",data:optionData,value:dossier.responsable?String(dossier.responsable.id):null,onChange:v=>setResponsable.mutate({id:dossier.airporting_id,notionUserId:v?Number(v):null}),searchable:true,clearable:true,w:220,leftSection:dossier.responsable?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:dossier.responsable.avatar_url,size:20,radius:"xl"}):void 0})})]},`${dossier.airporting_id}:${dossier.provider}`))})]})]})}function ManagedBadge(props){const{managed}=props;if(!managed)return null;return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Image,{src:(0,logoDev.j)("airporting.com"),alt:"G\xe9r\xe9 par Airporting",title:"G\xe9r\xe9 par Airporting",w:18,h:18,fit:"contain",radius:"sm",style:{aspectRatio:1}})}const BANK_DOMAINS=[["bnp paribas","bnpparibas.com"],["societe generale","societegenerale.fr"],["qonto","qonto.com"],["revolut","revolut.com"],["stripe","stripe.com"],["wise","wise.com"],["transferwise","wise.com"],["ibanfirst","ibanfirst.com"],["credit agricole","credit-agricole.fr"],["credit mutuel","creditmutuel.fr"],["banque populaire","banquepopulaire.fr"],["caisse d","caisse-epargne.fr"],["american express","americanexpress.com"],["amex","americanexpress.com"],["paypal","paypal.com"],["hsbc","hsbc.com"],["pennylane","pennylane.com"],["mercury","mercury.com"],["lcl","lcl.fr"],["boursorama","boursorama.com"],["bpce","bpce.fr"]];function normalize(value){return value.toLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu,"")}function BankLogo(props){const{label,size=20}=props;const normalized=label?normalize(label):"";const match=BANK_DOMAINS.find(([needle])=>normalized.includes(needle));if(!match)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{span:true,children:"\uD83C\uDFE6"});return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Image,{src:(0,logoDev.j)(match[1]),alt:label??"",title:label??"",w:size,h:size,fit:"contain",radius:"sm",style:{aspectRatio:1}})}var CompanyLogo=__webpack_require__(3437);var PageHeader=__webpack_require__(1354);const STALE_THRESHOLD_DAYS=30;function staleBadge(isoDate){if(!isoDate)return null;const days=Math.floor((Date.now()-new Date(isoDate).getTime())/864e5);if(days<STALE_THRESHOLD_DAYS)return null;return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Badge,{ml:6,size:"xs",color:"red",variant:"light",children:["+",days,"j"]})}function withDossierFilter(rows,dossier){if(!dossier)return rows;return rows.filter(r=>r.dossier===dossier)}function withManagedFilter(rows,managedOnly){if(!managedOnly)return rows;return rows.filter(r=>true===r.managed)}function withCategoryFilter(rows,category){if("all"===category)return rows;return rows.filter(r=>r.category===category)}function etatBadge(row){if("error"===row.status)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",color:"red",variant:"light",children:"Erreur"});if("too_large"===row.status)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",color:"orange",variant:"light",children:"Trop volumineux"});if("anomalie"===row.category)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",color:"orange",variant:"light",children:"Anomalie"});if("stale"===row.reason)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",color:"yellow",variant:"light",children:"P\xe9rim\xe9"});if("empty"===row.reason)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",color:"gray",variant:"light",children:"Vide"});return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",color:"green",variant:"light",children:"Propre"})}function formatCurrency(value){if(null==value)return"—";return value.toLocaleString("fr-FR",{style:"currency",currency:"EUR",minimumFractionDigits:0,maximumFractionDigits:2})}function formatNumber(value){if(null==value)return"—";return value.toLocaleString("fr-FR")}function formatDate(value){if(!value)return"—";return value.split("-").reverse().join("/")}function clickableCardStyle(clickable){return clickable?{cursor:"pointer"}:void 0}function MobileMetricGrid({metrics}){return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SimpleGrid,{cols:2,spacing:"xs",children:metrics.map(metric=>/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",children:metric.label}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",fw:700,c:metric.color,lineClamp:2,children:metric.value})]},metric.label))})}function MobileAccountingList(props){const{rows,emptyLabel="Aucune ligne",getKey,renderHeader,getMetrics,onRowClick}=props;if(0===rows.length)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",ta:"center",py:"xl",children:emptyLabel});return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Stack,{gap:"sm",children:rows.map((row,index)=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{withBorder:true,p:"sm",radius:"md",onClick:onRowClick?()=>onRowClick(row):void 0,style:clickableCardStyle(!!onRowClick),children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"sm",children:[renderHeader(row),/*#__PURE__*/(0,jsx_runtime.jsx)(MobileMetricGrid,{metrics:getMetrics(row)})]})},getKey(row,index)))})}function MobileDossierLineList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:row=>`${row.source}:${row.dossier}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",align:"center",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsx)(CompanyLogo.D,{slug:row.slug,updatedAt:row.logo_updated_at,size:24}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:row.dossier}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:6,wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:row.responsable?.name??"Sans responsable"})]})]})]}),etatBadge(row)]}),getMetrics:row=>[{label:"471",value:formatCurrency(row.solde_attente_eur)},{label:"58",value:formatCurrency(row.solde_virements_eur)},{label:"401",value:formatCurrency(row.total_fournisseurs_eur)},{label:"411",value:formatCurrency(row.total_clients_eur)},{label:"Derni\xe8re \xe9criture",value:/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[formatDate(row.last_entry_date),staleBadge(row.last_entry_date)]})},{label:"Rappro",value:"pennylane"!==row.source?"—":row.last_reconciliation_date?formatDate(row.last_reconciliation_date):"jamais",color:"pennylane"===row.source&&null==row.last_reconciliation_date?"red":void 0}]})}function MobileSuspenseList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:(row,index)=>`${row.dossier}:${row.date}:${row.numero_piece??index}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:row.dossier}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:2,children:row.libelle_ecriture??row.libelle_compte??"Sans libell\xe9"})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed})]}),getMetrics:row=>[{label:"Solde net",value:formatCurrency(row.solde_net)},{label:"Date",value:formatDate(row.date)},{label:"Compte",value:row.numero_compte??"—"},{label:"Pi\xe8ce",value:row.numero_piece??"—"}]})}function MobileSupplierList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:(row,index)=>`${row.dossier}:${row.fournisseur}:${index}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:row.fournisseur}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:row.dossier})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed})]}),getMetrics:row=>[{label:"Solde d\xe9biteur",value:formatCurrency(row.solde_debiteur_eur)},{label:"\xc9critures",value:formatNumber(row.nb_ecritures)},{label:"Devise",value:row.devise||"—"}]})}function MobileCustomerList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:(row,index)=>`${row.dossier}:${row.client}:${index}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:row.client}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:row.dossier})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed})]}),getMetrics:row=>[{label:"Solde cr\xe9diteur",value:formatCurrency(row.solde_crediteur_eur)},{label:"\xc9critures",value:formatNumber(row.nb_ecritures)},{label:"Devise",value:row.devise||"—"}]})}function MobileReconciliationList({rows}){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:rows,getKey:(row,index)=>`${row.dossier}:${row.bank_label??index}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(BankLogo,{label:row.bank_label,size:24}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:row.bank_label??"Banque"})]}),getMetrics:row=>[{label:"Dernier rappro",value:row.last_reconciled_period_end?formatDate(row.last_reconciled_period_end):"jamais",color:row.last_reconciled_period_end?void 0:"red"}]})}function MobileTopSuspenseList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:row=>`471:${row.rank}:${row.dossier}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:["#",row.rank," ",row.dossier]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:row.top_libelle??"Sans libell\xe9"})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed})]}),getMetrics:row=>[{label:"Solde 471",value:formatCurrency(row.solde_eur)},{label:"\xc9critures",value:formatNumber(row.nb_ecritures)},{label:"Top montant",value:formatCurrency(row.top_montant)}]})}function MobileTopSupplierList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:row=>`401:${row.rank}:${row.dossier}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:["#",row.rank," ",row.dossier]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:row.top_nom??"Sans fournisseur"})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed})]}),getMetrics:row=>[{label:"Total d\xe9biteur",value:formatCurrency(row.total_eur)},{label:"Fournisseurs",value:formatNumber(row.nb_fournisseurs)},{label:"Top montant",value:formatCurrency(row.top_montant)}]})}function MobileTopCustomerList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:row=>`411:${row.rank}:${row.dossier}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:["#",row.rank," ",row.dossier]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:row.top_nom??"Sans client"})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed})]}),getMetrics:row=>[{label:"Total cr\xe9diteur",value:formatCurrency(row.total_eur)},{label:"Clients",value:formatNumber(row.nb_clients)},{label:"Top montant",value:formatCurrency(row.top_montant)}]})}function EtatSaisieApp(){const isMobile=(0,esm_index_mjs_.useMediaQuery)("(max-width: 48em)",false);const latest=useEtatSaisieLatest();const recompute=useEtatSaisieRecompute();const[tab,setTab]=(0,index_js_.useState)("resume");const[selectedDossier,setSelectedDossier]=(0,index_js_.useState)(null);const[managedOnly,setManagedOnly]=(0,index_js_.useState)(true);const[statusFilter,setStatusFilter]=(0,index_js_.useState)("all");const[drillDossier,setDrillDossier]=(0,index_js_.useState)(null);const d=latest.data;const allDossiers=(0,index_js_.useMemo)(()=>{if(!d?.available)return[];const set=new Set;for(const r of d.suspense_rows??[])set.add(r.dossier);for(const r of d.supplier_rows??[])set.add(r.dossier);for(const r of d.customer_rows??[])set.add(r.dossier);for(const r of d.dossier_lines??[])set.add(r.dossier);for(const r of d.reconciliation_rows??[])set.add(r.dossier);for(const r of d.summary?.top_5_suspense??[])set.add(r.dossier);for(const r of d.summary?.top_5_supplier_debtors??[])set.add(r.dossier);for(const r of d.summary?.top_5_customer_creditors??[])set.add(r.dossier);return[...set].sort()},[d]);const openDrill=row=>setDrillDossier(row.dossier);const drillData=(0,index_js_.useMemo)(()=>{if(!drillDossier||!d?.available)return null;const reconciliation=(d.reconciliation_rows??[]).filter(r=>r.dossier===drillDossier).sort((a,b)=>{const av=a.last_reconciled_period_end??"0000-00-00";const bv=b.last_reconciled_period_end??"0000-00-00";return av.localeCompare(bv)});return{reconciliation,suspense:(d.suspense_rows??[]).filter(r=>r.dossier===drillDossier),internalTransfers:(d.internal_transfer_rows??[]).filter(r=>r.dossier===drillDossier),supplier:(d.supplier_rows??[]).filter(r=>r.dossier===drillDossier),customer:(d.customer_rows??[]).filter(r=>r.dossier===drillDossier)}},[drillDossier,d]);const summaryRows=(0,index_js_.useMemo)(()=>withCategoryFilter(withManagedFilter(withDossierFilter(d?.dossier_lines??[],selectedDossier),managedOnly),statusFilter),[d,selectedDossier,managedOnly,statusFilter]);const topSuspenseRows=(0,index_js_.useMemo)(()=>withDossierFilter(d?.summary?.top_5_suspense??[],selectedDossier),[d,selectedDossier]);const topSupplierRows=(0,index_js_.useMemo)(()=>withDossierFilter(d?.summary?.top_5_supplier_debtors??[],selectedDossier),[d,selectedDossier]);const topCustomerRows=(0,index_js_.useMemo)(()=>withDossierFilter(d?.summary?.top_5_customer_creditors??[],selectedDossier),[d,selectedDossier]);const suspenseRows=(0,index_js_.useMemo)(()=>withManagedFilter(withDossierFilter(d?.suspense_rows??[],selectedDossier),managedOnly),[d,selectedDossier,managedOnly]);const internalTransferRows=(0,index_js_.useMemo)(()=>withManagedFilter(withDossierFilter(d?.internal_transfer_rows??[],selectedDossier),managedOnly),[d,selectedDossier,managedOnly]);const supplierRows=(0,index_js_.useMemo)(()=>withManagedFilter(withDossierFilter(d?.supplier_rows??[],selectedDossier),managedOnly),[d,selectedDossier,managedOnly]);const customerRows=(0,index_js_.useMemo)(()=>withManagedFilter(withDossierFilter(d?.customer_rows??[],selectedDossier),managedOnly),[d,selectedDossier,managedOnly]);return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Container,{fluid:true,my:isMobile?0:"md",px:isMobile?12:void 0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(PageHeader.m,{title:"Accounting",updatedAt:d?.computed_at?new Date(d.computed_at).getTime():latest.dataUpdatedAt,isFetching:latest.isFetching,isError:latest.isError,onRefresh:()=>latest.refetch(),actions:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{loading:recompute.isPending,onClick:()=>recompute.mutate(),variant:"light",size:isMobile?"xs":"sm",children:"Recalculer"})}),d&&!d.available?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",children:"Aucun snapshot disponible — lancez \xab Recalculer \xbb ou attendez le run nocturne."}):/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{mb:"md",align:"end",gap:"sm",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{label:"Focus dossier",placeholder:"Tous les dossiers",data:allDossiers.map(dos=>({value:dos,label:dos})),value:selectedDossier,onChange:setSelectedDossier,searchable:true,clearable:true,w:isMobile?"100%":320}),selectedDossier&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"subtle",onClick:()=>setSelectedDossier(null),w:isMobile?"100%":void 0,children:"R\xe9initialiser"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SegmentedControl,{value:managedOnly?"managed":"all",onChange:v=>setManagedOnly("managed"===v),data:[{label:"G\xe9r\xe9s",value:"managed"},{label:"Tous",value:"all"}],w:isMobile?"100%":void 0})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Tabs,{value:tab,onChange:setTab,children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Tabs.List,{style:isMobile?{flexWrap:"nowrap",overflowX:"auto",overflowY:"hidden"}:void 0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Tab,{value:"resume",children:"R\xe9sum\xe9"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Tab,{value:"dossiers",children:"Dossiers"})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Tabs.Panel,{value:"resume",pt:"md",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SimpleGrid,{cols:isMobile?2:4,mb:"md",spacing:"sm",children:[{key:"all",label:"Scann\xe9s",value:d?.summary?.companies_scanned??0,color:void 0},{key:"propre",label:"Propres",value:d?.summary?.companies_clean??0,color:"green"},{key:"anomalie",label:"En anomalie",value:d?.summary?.companies_with_anomalies??0,color:"orange"},{key:"erreur",label:"En erreur",value:d?.summary?.companies_in_error??0,color:"red"}].map(tile=>{const active=statusFilter===tile.key;return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Card,{withBorder:active,style:{cursor:"pointer",borderColor:active?"var(--mantine-color-blue-5)":void 0},onClick:()=>setStatusFilter(tile.key),children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",children:tile.label}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"xl",c:tile.color,children:tile.value})]},tile.key)})}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileDossierLineList,{rows:summaryRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:UNIFIED_COLS,rows:summaryRows,onRowClick:openDrill})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Panel,{value:"top5",pt:"md",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"lg",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:4,mb:"sm",children:"Top 5 comptes d'attente (471)"}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileTopSuspenseList,{rows:topSuspenseRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:TOP_SUSPENSE_COLS,rows:topSuspenseRows,onRowClick:openDrill})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:4,mb:"sm",children:"Top 5 fournisseurs d\xe9biteurs (401)"}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileTopSupplierList,{rows:topSupplierRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:TOP_SUPPLIER_COLS,rows:topSupplierRows,onRowClick:openDrill})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:4,mb:"sm",children:"Top 5 clients cr\xe9diteurs (411)"}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileTopCustomerList,{rows:topCustomerRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:TOP_CUSTOMER_COLS,rows:topCustomerRows,onRowClick:openDrill})]})]})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Panel,{value:"s471",pt:"md",children:isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileSuspenseList,{rows:suspenseRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:SUSPENSE_COLS,rows:suspenseRows,onRowClick:openDrill})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Panel,{value:"s58",pt:"md",children:isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileSuspenseList,{rows:internalTransferRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:SUSPENSE_COLS,rows:internalTransferRows,onRowClick:openDrill})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Panel,{value:"s401",pt:"md",children:isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileSupplierList,{rows:supplierRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:SUPPLIER_COLS,rows:supplierRows,onRowClick:openDrill})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Panel,{value:"s411",pt:"md",children:isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileCustomerList,{rows:customerRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:CUSTOMER_COLS,rows:customerRows,onRowClick:openDrill})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Panel,{value:"dossiers",pt:"md",children:/*#__PURE__*/(0,jsx_runtime.jsx)(DossiersTab,{})})]})]}),latest.isError?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"red",mt:"md",children:"Erreur de chargement."}):null,/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Drawer,{opened:!!drillDossier,onClose:()=>setDrillDossier(null),position:isMobile?"bottom":"right",size:isMobile?"calc(100dvh - 88px)":"xl",title:drillDossier?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",align:"center",wrap:isMobile?"wrap":"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Title,{order:isMobile?5:4,children:["Dossier ",drillDossier]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{size:"xs",variant:"light",onClick:()=>{setSelectedDossier(drillDossier);setDrillDossier(null)},children:"Focus sur ce dossier"})]}):null,styles:isMobile?{body:{padding:12,paddingBottom:24}}:void 0,children:drillData&&/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"md",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Title,{order:5,mb:6,children:["Rappros bancaires (",drillData.reconciliation.length,")"]}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileReconciliationList,{rows:drillData.reconciliation}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:DRILL_RECO_COLS,rows:drillData.reconciliation})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Title,{order:5,mb:6,children:["Comptes d'attente 471 (",drillData.suspense.length,")"]}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileSuspenseList,{rows:drillData.suspense}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:DRILL_SUSPENSE_COLS,rows:drillData.suspense})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Title,{order:5,mb:6,children:["Virements internes 58 (",drillData.internalTransfers.length,")"]}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileSuspenseList,{rows:drillData.internalTransfers}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:DRILL_SUSPENSE_COLS,rows:drillData.internalTransfers})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Title,{order:5,mb:6,children:["Fournisseurs d\xe9biteurs 401 (",drillData.supplier.length,")"]}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileSupplierList,{rows:drillData.supplier}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:DRILL_SUPPLIER_COLS,rows:drillData.supplier})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Title,{order:5,mb:6,children:["Clients cr\xe9diteurs 411 (",drillData.customer.length,")"]}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileCustomerList,{rows:drillData.customer}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:DRILL_CUSTOMER_COLS,rows:drillData.customer})]})]})})]})}const TOP_SUSPENSE_COLS=[{key:"rank",label:"#",numeric:true},{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"G\xe9r\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"dossier",label:"Dossier"},{key:"solde_eur",label:"Solde 471 (€)",numeric:true},{key:"nb_ecritures",label:"Nb \xe9cr.",numeric:true},{key:"top_libelle",label:"Top \xe9criture"},{key:"top_montant",label:"Montant",numeric:true}];const TOP_SUPPLIER_COLS=[{key:"rank",label:"#",numeric:true},{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"Manag\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"dossier",label:"Dossier"},{key:"total_eur",label:"Total d\xe9biteur (€)",numeric:true},{key:"nb_fournisseurs",label:"Nb fourn.",numeric:true},{key:"top_nom",label:"Top fournisseur"},{key:"top_montant",label:"Montant",numeric:true}];const TOP_CUSTOMER_COLS=[{key:"rank",label:"#",numeric:true},{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"Manag\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"dossier",label:"Dossier"},{key:"total_eur",label:"Total cr\xe9diteur (€)",numeric:true},{key:"nb_clients",label:"Nb clients",numeric:true},{key:"top_nom",label:"Top client"},{key:"top_montant",label:"Montant",numeric:true}];const UNIFIED_COLS=[{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"Manag\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"status",label:"\xc9tat",render:r=>etatBadge(r)},{key:"dossier",label:"Dossier",render:r=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(CompanyLogo.D,{slug:r.slug,updatedAt:r.logo_updated_at,size:20}),/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:r.dossier})]})},{key:"responsable",label:"Responsable",render:r=>r.responsable?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:r.responsable.avatar_url,size:20,radius:"xl"}),/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:r.responsable.name})]}):/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:"—"})},{key:"fiscal_year_end",label:"Cl\xf4ture",render:r=>r.fiscal_year_end?/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:r.fiscal_year_end.split("-").reverse().join("/")}):/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:"—"})},{key:"solde_attente_eur",label:"Solde 471 (€)",numeric:true},{key:"solde_virements_eur",label:"Solde 58 (€)",numeric:true},{key:"total_fournisseurs_eur",label:"Fourn. d\xe9biteurs (€)",numeric:true},{key:"total_clients_eur",label:"Clients cr\xe9diteurs (€)",numeric:true},{key:"last_entry_date",label:"Derni\xe8re \xe9criture",render:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)("span",{children:[row.last_entry_date??"—",staleBadge(row.last_entry_date)]})},{key:"last_reconciliation_date",label:"Rappro le + en retard",render:r=>{if("pennylane"!==r.source)return/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:"—"});if(null==r.last_reconciliation_date)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{span:true,c:"red",fw:700,td:"underline",style:{cursor:"pointer"},children:"jamais"});return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{span:true,td:"underline",style:{cursor:"pointer"},children:r.last_reconciliation_date.split("-").reverse().join("/")})}},{key:"pending_supplier_invoices",label:"Fact. fourn. \xe0 traiter",numeric:true,render:r=>{if("pennylane"!==r.source||null==r.pending_supplier_invoices)return/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:"—"});return/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:r.pending_supplier_invoices})}}];const SUSPENSE_COLS=[{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"Manag\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"dossier",label:"Dossier"},{key:"date",label:"Date"},{key:"numero_compte",label:"N\xb0 Compte"},{key:"libelle_compte",label:"Libell\xe9 compte"},{key:"libelle_ecriture",label:"Libell\xe9 \xe9criture"},{key:"journal",label:"Journal"},{key:"numero_piece",label:"N\xb0 Pi\xe8ce"},{key:"debit",label:"D\xe9bit",numeric:true},{key:"credit",label:"Cr\xe9dit",numeric:true},{key:"solde_net",label:"Solde net",numeric:true},{key:"lettre",label:"Lettr\xe9"},{key:"devise",label:"Devise"}];const SUPPLIER_COLS=[{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"Manag\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"dossier",label:"Dossier"},{key:"fournisseur",label:"Fournisseur"},{key:"solde_debiteur_eur",label:"Solde d\xe9biteur (€)",numeric:true},{key:"nb_ecritures",label:"Nb \xe9cr. non lettr\xe9es",numeric:true},{key:"devise",label:"Devise"}];const CUSTOMER_COLS=[{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"Manag\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"dossier",label:"Dossier"},{key:"client",label:"Client"},{key:"solde_crediteur_eur",label:"Solde cr\xe9diteur (€)",numeric:true},{key:"nb_ecritures",label:"Nb \xe9cr. non lettr\xe9es",numeric:true},{key:"devise",label:"Devise"}];const DRILL_RECO_COLS=[{key:"bank_label",label:"Banque",render:r=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(BankLogo,{label:r.bank_label,size:20}),/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:r.bank_label??"—"})]})},{key:"last_reconciled_period_end",label:"Dernier rappro",render:r=>{if(null==r.last_reconciled_period_end)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{span:true,c:"red",fw:700,children:"jamais"});return/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:r.last_reconciled_period_end.split("-").reverse().join("/")})}}];const DRILL_SUSPENSE_COLS=[{key:"date",label:"Date"},{key:"numero_compte",label:"N\xb0 Compte"},{key:"libelle_ecriture",label:"Libell\xe9"},{key:"debit",label:"D\xe9bit",numeric:true},{key:"credit",label:"Cr\xe9dit",numeric:true},{key:"solde_net",label:"Solde net",numeric:true},{key:"lettre",label:"Lettr\xe9"}];const DRILL_SUPPLIER_COLS=[{key:"fournisseur",label:"Fournisseur"},{key:"solde_debiteur_eur",label:"Solde d\xe9biteur (€)",numeric:true},{key:"nb_ecritures",label:"Nb \xe9cr.",numeric:true},{key:"devise",label:"Devise"}];const DRILL_CUSTOMER_COLS=[{key:"client",label:"Client"},{key:"solde_crediteur_eur",label:"Solde cr\xe9diteur (€)",numeric:true},{key:"nb_ecritures",label:"Nb \xe9cr.",numeric:true},{key:"devise",label:"Devise"}];function EtatSaisie(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(index_js_.StrictMode,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(providers.C,{...props,children:/*#__PURE__*/(0,jsx_runtime.jsx)(EtatSaisieApp,{})})})}}}]);
1
+ "use strict";(globalThis["chunk_tech_app"]=globalThis["chunk_tech_app"]||[]).push([["7915"],{3437:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{D:()=>CompanyLogo});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(5893);var _mantine_core__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(207);const BASE_URL="https://s3.dualstack.eu-west-3.amazonaws.com/media.airporting/companies";function CompanyLogo({slug,updatedAt,size=20,...rest}){const base=`${BASE_URL}/${slug}.png`;const url=updatedAt?`${base}?v=${new Date(updatedAt).getTime()}`:base;return/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Image,{src:url,fallbackSrc:`${BASE_URL}/undefined.png`,alt:slug??"",w:size,h:size,fit:"contain",radius:"sm",style:{aspectRatio:1},...rest})}},1354:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{m:()=>PageHeader});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(5893);var _mantine_core__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(207);var _tabler_icons_react__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(9632);var react__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(3106);function formatRelative(now,then){const seconds=Math.max(0,Math.floor((now-then)/1e3));if(seconds<5)return"\xe0 l’instant";if(seconds<60)return`il y a ${seconds}s`;const minutes=Math.floor(seconds/60);if(minutes<60)return`il y a ${minutes} min`;const hours=Math.floor(minutes/60);return`il y a ${hours} h`}function PageHeader({title,leading,badge,updatedAt,isFetching,isError,onRefresh,actions}){const[now,setNow]=(0,react__WEBPACK_IMPORTED_MODULE_3__.useState)(()=>Date.now());(0,react__WEBPACK_IMPORTED_MODULE_3__.useEffect)(()=>{if(!updatedAt)return;const id=window.setInterval(()=>setNow(Date.now()),1e3);return()=>window.clearInterval(id)},[updatedAt]);const relative=updatedAt?formatRelative(now,updatedAt):null;const color=isError?"orange":isFetching?"teal":"dimmed";return/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Group,{justify:"space-between",align:"center",mih:48,mb:"md",children:[/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Group,{gap:"sm",align:"center",children:[leading,/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Title,{order:2,children:title}),badge]}),/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Group,{gap:"sm",align:"center",children:[relative&&/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Text,{size:"xs",c:color,fw:isFetching?600:400,"data-testid":"page-header-freshness",children:isError?"\xe9chec maj":isFetching?"maj…":relative}),onRefresh&&/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Tooltip,{label:"Rafra\xeechir",children:/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.ActionIcon,{variant:"default",size:"md",onClick:onRefresh,loading:isFetching,"aria-label":"Refresh",children:/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_tabler_icons_react__WEBPACK_IMPORTED_MODULE_2__.IconRefresh,{size:16})})}),actions]})]})}},9781:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{h:()=>QuickBooksIcon});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(5893);function QuickBooksIcon(props){const size=props.size??20;return/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("svg",{width:size,height:size,viewBox:"0 0 24 24",role:"img","aria-label":"QuickBooks",children:[/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("title",{children:"QuickBooks"}),/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("circle",{cx:"12",cy:"12",r:"12",fill:"#2CA01C"}),/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("text",{x:"12",y:"16.5",textAnchor:"middle",fontSize:"12",fontWeight:"700",fill:"#ffffff",fontFamily:"Arial, Helvetica, sans-serif",children:"qb"})]})}},243:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{j:()=>logoDevUrl});const LOGO_DEV_TOKEN="pk_BVN4OQv0Qs-bnqjdIgTppg";function logoDevUrl(domain){return`https://img.logo.dev/${domain}?token=${LOGO_DEV_TOKEN}`}},6016:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{default:()=>EtatSaisie});var jsx_runtime=__webpack_require__(5893);var index_js_=__webpack_require__(3106);var providers=__webpack_require__(7034);var index_mjs_=__webpack_require__(207);var esm_index_mjs_=__webpack_require__(3863);var modern_index_js_=__webpack_require__(6197);var useApi=__webpack_require__(4148);function useEtatSaisieLatest(){const api=(0,useApi.h)();return(0,modern_index_js_.useQuery)({queryKey:["tech","etat-saisie","latest"],queryFn:async()=>(await api.etatSaisie.getLatestV1()).data,refetchOnWindowFocus:true})}function useEtatSaisieRecompute(){const api=(0,useApi.h)();const qc=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:async()=>(await api.etatSaisie.recomputeV1()).data,onSuccess:()=>qc.invalidateQueries({queryKey:["tech","etat-saisie","latest"]})})}function DetailTable(props){const{columns,rows,onRowClick}=props;const[sortKey,setSortKey]=(0,index_js_.useState)(null);const[asc,setAsc]=(0,index_js_.useState)(false);const sorted=[...rows].sort((a,b)=>{if(!sortKey)return 0;const av=a[sortKey];const bv=b[sortKey];if("number"==typeof av&&"number"==typeof bv)return asc?av-bv:bv-av;return asc?String(av).localeCompare(String(bv)):String(bv).localeCompare(String(av))});const toggle=k=>{if(sortKey===k)setAsc(v=>!v);else{setSortKey(k);setAsc(false)}};const fmt=(v,numeric)=>{if(numeric&&"number"==typeof v)return v.toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2});if("boolean"==typeof v)return v?"✓":"";if(null==v)return"—";if("object"==typeof v)return"—";return String(v)};return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table,{striped:true,highlightOnHover:true,withTableBorder:true,stickyHeader:true,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Thead,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tr,{children:columns.map(c=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table.Th,{onClick:()=>toggle(c.key),style:{cursor:"pointer"},children:[c.label,sortKey===c.key?asc?" ▲":" ▼":""]},c.key))})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tbody,{children:0===sorted.length?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tr,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{colSpan:columns.length,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",ta:"center",children:"Aucune ligne"})})}):sorted.map((row,i)=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tr,{onClick:onRowClick?()=>onRowClick(row):void 0,style:onRowClick?{cursor:"pointer"}:void 0,children:columns.map(c=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{style:c.numeric?{textAlign:"right",fontVariantNumeric:"tabular-nums"}:void 0,children:c.render?c.render(row):fmt(row[c.key],c.numeric)},c.key))},i))})]})}function useDossiers(){const api=(0,useApi.h)();return(0,modern_index_js_.useQuery)({queryKey:["tech","etat-saisie","dossiers"],queryFn:async()=>(await api.etatSaisie.getDossiersV1()).data,refetchOnWindowFocus:true})}function useSetManaged(){const api=(0,useApi.h)();const qc=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:async variables=>(await api.etatSaisie.setManagedV1({id:variables.id},{managed:variables.managed})).data,onSuccess:()=>{qc.invalidateQueries({queryKey:["tech","etat-saisie","dossiers"]});qc.invalidateQueries({queryKey:["tech","etat-saisie","latest"]})}})}function useSetResponsable(){const api=(0,useApi.h)();const qc=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:async variables=>(await api.etatSaisie.setResponsableV1({id:variables.id},{notion_user_id:variables.notionUserId})).data,onSuccess:()=>{qc.invalidateQueries({queryKey:["tech","etat-saisie","dossiers"]})}})}var logoDev=__webpack_require__(243);var QuickBooksIcon=__webpack_require__(9781);const PROVIDER_DOMAIN={pennylane:"pennylane.com",zohobooks:"zoho.com",xero:"xero.com",odoo:"odoo.com"};function ProviderIcon(props){const{provider}=props;if(!provider)return null;if("quickbooks"===provider)return/*#__PURE__*/(0,jsx_runtime.jsx)(QuickBooksIcon.h,{size:20});const domain=PROVIDER_DOMAIN[provider];if(!domain)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"sm",variant:"light",color:"gray",title:provider,children:provider.slice(0,2).toUpperCase()});return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Image,{src:(0,logoDev.j)(domain),alt:provider,title:provider,w:20,h:20,fit:"contain",radius:"sm",style:{aspectRatio:1}})}function DossiersTab(){const isMobile=(0,esm_index_mjs_.useMediaQuery)("(max-width: 48em)",false);const dossiers=useDossiers();const setManaged=useSetManaged();const setResponsable=useSetResponsable();const[filter,setFilter]=(0,index_js_.useState)("");const options=dossiers.data?.responsable_options??[];const optionData=options.map(u=>({value:String(u.id),label:u.name}));const rows=(0,index_js_.useMemo)(()=>{const all=dossiers.data?.dossiers??[];const needle=filter.trim().toLowerCase();const filtered=needle?all.filter(dossier=>dossier.display_name.toLowerCase().includes(needle)||dossier.slug.toLowerCase().includes(needle)):all;return[...filtered].sort((a,b)=>a.display_name.localeCompare(b.display_name))},[dossiers.data,filter]);if(dossiers.isError)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"red",mt:"md",children:"Erreur de chargement des dossiers."});return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{mb:"md",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TextInput,{placeholder:"Filtrer par nom ou slug",value:filter,onChange:event=>setFilter(event.currentTarget.value),w:isMobile?"100%":320})}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Stack,{gap:"sm",children:0===rows.length?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",ta:"center",py:"xl",children:"Aucun dossier"}):rows.map(dossier=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{withBorder:true,p:"sm",radius:"md",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"sm",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:dossier.provider}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:dossier.display_name}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:dossier.slug})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Switch,{checked:dossier.managed,onChange:event=>setManaged.mutate({id:dossier.airporting_id,managed:event.currentTarget.checked})})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{placeholder:"Responsable",data:optionData,value:dossier.responsable?String(dossier.responsable.id):null,onChange:v=>setResponsable.mutate({id:dossier.airporting_id,notionUserId:v?Number(v):null}),searchable:true,clearable:true,leftSection:dossier.responsable?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:dossier.responsable.avatar_url,size:20,radius:"xl"}):void 0})]})},`${dossier.airporting_id}:${dossier.provider}`))}):/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table,{striped:true,highlightOnHover:true,withTableBorder:true,stickyHeader:true,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Thead,{children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table.Tr,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Source"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Dossier"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"G\xe9r\xe9"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Responsable"})]})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tbody,{children:0===rows.length?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tr,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{colSpan:4,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",ta:"center",children:"Aucun dossier"})})}):rows.map(dossier=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table.Tr,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:dossier.provider})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:dossier.display_name}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Switch,{checked:dossier.managed,onChange:event=>setManaged.mutate({id:dossier.airporting_id,managed:event.currentTarget.checked})})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{placeholder:"—",data:optionData,value:dossier.responsable?String(dossier.responsable.id):null,onChange:v=>setResponsable.mutate({id:dossier.airporting_id,notionUserId:v?Number(v):null}),searchable:true,clearable:true,w:220,leftSection:dossier.responsable?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:dossier.responsable.avatar_url,size:20,radius:"xl"}):void 0})})]},`${dossier.airporting_id}:${dossier.provider}`))})]})]})}function ManagedBadge(props){const{managed}=props;if(!managed)return null;return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Image,{src:(0,logoDev.j)("airporting.com"),alt:"G\xe9r\xe9 par Airporting",title:"G\xe9r\xe9 par Airporting",w:18,h:18,fit:"contain",radius:"sm",style:{aspectRatio:1}})}const BANK_DOMAINS=[["bnp paribas","bnpparibas.com"],["societe generale","societegenerale.fr"],["qonto","qonto.com"],["revolut","revolut.com"],["stripe","stripe.com"],["wise","wise.com"],["transferwise","wise.com"],["ibanfirst","ibanfirst.com"],["credit agricole","credit-agricole.fr"],["credit mutuel","creditmutuel.fr"],["banque populaire","banquepopulaire.fr"],["caisse d","caisse-epargne.fr"],["american express","americanexpress.com"],["amex","americanexpress.com"],["paypal","paypal.com"],["hsbc","hsbc.com"],["pennylane","pennylane.com"],["mercury","mercury.com"],["lcl","lcl.fr"],["boursorama","boursorama.com"],["bpce","bpce.fr"]];function normalize(value){return value.toLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu,"")}function BankLogo(props){const{label,size=20}=props;const normalized=label?normalize(label):"";const match=BANK_DOMAINS.find(([needle])=>normalized.includes(needle));if(!match)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{span:true,children:"\uD83C\uDFE6"});return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Image,{src:(0,logoDev.j)(match[1]),alt:label??"",title:label??"",w:size,h:size,fit:"contain",radius:"sm",style:{aspectRatio:1}})}var CompanyLogo=__webpack_require__(3437);var PageHeader=__webpack_require__(1354);const STALE_THRESHOLD_DAYS=30;function staleBadge(isoDate){if(!isoDate)return null;const days=Math.floor((Date.now()-new Date(isoDate).getTime())/864e5);if(days<STALE_THRESHOLD_DAYS)return null;return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Badge,{ml:6,size:"xs",color:"red",variant:"light",children:["+",days,"j"]})}function syncBadge(isoDate){if(!isoDate)return null;const days=Math.floor((Date.now()-new Date(isoDate).getTime())/864e5);let color="green";if(days>10)color="red";else if(days>4)color="orange";return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Badge,{ml:6,size:"xs",color:color,variant:"light",children:[days,"j"]})}function isStaleRefresh(refreshedAt,computedAt){if(!refreshedAt)return false;const refreshedDay=refreshedAt.slice(0,10);const referenceDay=(computedAt??new Date().toISOString()).slice(0,10);return refreshedDay<referenceDay}function refreshKoBadge(refreshedAt,computedAt){if(!isStaleRefresh(refreshedAt,computedAt))return null;return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:`Chiffres du ${formatDate(refreshedAt?.slice(0,10))} \u{2014} refresh KO ce run`,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{ml:6,size:"xs",color:"yellow",variant:"light",children:"refresh KO"})})}function withDossierFilter(rows,dossier){if(!dossier)return rows;return rows.filter(r=>r.dossier===dossier)}function withManagedFilter(rows,managedOnly){if(!managedOnly)return rows;return rows.filter(r=>true===r.managed)}function withCategoryFilter(rows,category){if("all"===category)return rows;return rows.filter(r=>r.category===category)}function etatBadge(row){if("error"===row.status)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",color:"red",variant:"light",children:"Erreur"});if("too_large"===row.status)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",color:"orange",variant:"light",children:"Trop volumineux"});if("anomalie"===row.category)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",color:"orange",variant:"light",children:"Anomalie"});if("stale"===row.reason)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",color:"yellow",variant:"light",children:"P\xe9rim\xe9"});if("empty"===row.reason)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",color:"gray",variant:"light",children:"Vide"});return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",color:"green",variant:"light",children:"Propre"})}function formatCurrency(value){if(null==value)return"—";return value.toLocaleString("fr-FR",{style:"currency",currency:"EUR",minimumFractionDigits:0,maximumFractionDigits:2})}function formatNumber(value){if(null==value)return"—";return value.toLocaleString("fr-FR")}function formatDate(value){if(!value)return"—";return value.split("-").reverse().join("/")}function clickableCardStyle(clickable){return clickable?{cursor:"pointer"}:void 0}function MobileMetricGrid({metrics}){return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SimpleGrid,{cols:2,spacing:"xs",children:metrics.map(metric=>/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",children:metric.label}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",fw:700,c:metric.color,lineClamp:2,children:metric.value})]},metric.label))})}function MobileAccountingList(props){const{rows,emptyLabel="Aucune ligne",getKey,renderHeader,getMetrics,onRowClick}=props;if(0===rows.length)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",ta:"center",py:"xl",children:emptyLabel});return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Stack,{gap:"sm",children:rows.map((row,index)=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{withBorder:true,p:"sm",radius:"md",onClick:onRowClick?()=>onRowClick(row):void 0,style:clickableCardStyle(!!onRowClick),children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"sm",children:[renderHeader(row),/*#__PURE__*/(0,jsx_runtime.jsx)(MobileMetricGrid,{metrics:getMetrics(row)})]})},getKey(row,index)))})}function MobileDossierLineList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:row=>`${row.source}:${row.dossier}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",align:"center",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsx)(CompanyLogo.D,{slug:row.slug,updatedAt:row.logo_updated_at,size:24}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:row.dossier}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:6,wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:row.responsable?.name??"Sans responsable"})]})]})]}),etatBadge(row)]}),getMetrics:row=>[{label:"471",value:formatCurrency(row.solde_attente_eur)},{label:"58",value:formatCurrency(row.solde_virements_eur)},{label:"401",value:formatCurrency(row.total_fournisseurs_eur)},{label:"411",value:formatCurrency(row.total_clients_eur)},{label:"Derni\xe8re \xe9criture",value:/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[formatDate(row.last_entry_date),staleBadge(row.last_entry_date),refreshKoBadge(row.refreshed_at,props.computedAt)]})},{label:"Rappro",value:"pennylane"!==row.source?"—":row.last_reconciliation_date?formatDate(row.last_reconciliation_date):"jamais",color:"pennylane"===row.source&&null==row.last_reconciliation_date?"red":void 0},{label:"Derni\xe8re synchro",value:"pennylane"!==row.source||null==row.gla_last_sync_date?"—":/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[formatDate(row.gla_last_sync_date.slice(0,10)),syncBadge(row.gla_last_sync_date)]})}]})}function MobileSuspenseList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:(row,index)=>`${row.dossier}:${row.date}:${row.numero_piece??index}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:row.dossier}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:2,children:row.libelle_ecriture??row.libelle_compte??"Sans libell\xe9"})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed})]}),getMetrics:row=>[{label:"Solde net",value:formatCurrency(row.solde_net)},{label:"Date",value:formatDate(row.date)},{label:"Compte",value:row.numero_compte??"—"},{label:"Pi\xe8ce",value:row.numero_piece??"—"}]})}function MobileSupplierList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:(row,index)=>`${row.dossier}:${row.fournisseur}:${index}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:row.fournisseur}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:row.dossier})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed})]}),getMetrics:row=>[{label:"Solde d\xe9biteur",value:formatCurrency(row.solde_debiteur_eur)},{label:"\xc9critures",value:formatNumber(row.nb_ecritures)},{label:"Devise",value:row.devise||"—"}]})}function MobileCustomerList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:(row,index)=>`${row.dossier}:${row.client}:${index}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:row.client}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:row.dossier})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed})]}),getMetrics:row=>[{label:"Solde cr\xe9diteur",value:formatCurrency(row.solde_crediteur_eur)},{label:"\xc9critures",value:formatNumber(row.nb_ecritures)},{label:"Devise",value:row.devise||"—"}]})}function MobileReconciliationList({rows}){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:rows,getKey:(row,index)=>`${row.dossier}:${row.bank_label??index}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(BankLogo,{label:row.bank_label,size:24}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:row.bank_label??"Banque"})]}),getMetrics:row=>[{label:"Dernier rappro",value:row.last_reconciled_period_end?formatDate(row.last_reconciled_period_end):"jamais",color:row.last_reconciled_period_end?void 0:"red"}]})}function MobileTopSuspenseList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:row=>`471:${row.rank}:${row.dossier}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:["#",row.rank," ",row.dossier]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:row.top_libelle??"Sans libell\xe9"})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed})]}),getMetrics:row=>[{label:"Solde 471",value:formatCurrency(row.solde_eur)},{label:"\xc9critures",value:formatNumber(row.nb_ecritures)},{label:"Top montant",value:formatCurrency(row.top_montant)}]})}function MobileTopSupplierList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:row=>`401:${row.rank}:${row.dossier}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:["#",row.rank," ",row.dossier]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:row.top_nom??"Sans fournisseur"})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed})]}),getMetrics:row=>[{label:"Total d\xe9biteur",value:formatCurrency(row.total_eur)},{label:"Fournisseurs",value:formatNumber(row.nb_fournisseurs)},{label:"Top montant",value:formatCurrency(row.top_montant)}]})}function MobileTopCustomerList(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(MobileAccountingList,{rows:props.rows,onRowClick:props.onRowClick,getKey:row=>`411:${row.rank}:${row.dossier}`,renderHeader:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",gap:"sm",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",miw:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:row.source}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{style:{minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{fw:700,size:"sm",lineClamp:1,children:["#",row.rank," ",row.dossier]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",lineClamp:1,children:row.top_nom??"Sans client"})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:row.managed})]}),getMetrics:row=>[{label:"Total cr\xe9diteur",value:formatCurrency(row.total_eur)},{label:"Clients",value:formatNumber(row.nb_clients)},{label:"Top montant",value:formatCurrency(row.top_montant)}]})}function EtatSaisieApp(){const isMobile=(0,esm_index_mjs_.useMediaQuery)("(max-width: 48em)",false);const latest=useEtatSaisieLatest();const recompute=useEtatSaisieRecompute();const[tab,setTab]=(0,index_js_.useState)("resume");const[selectedDossier,setSelectedDossier]=(0,index_js_.useState)(null);const[managedOnly,setManagedOnly]=(0,index_js_.useState)(true);const[statusFilter,setStatusFilter]=(0,index_js_.useState)("all");const[drillDossier,setDrillDossier]=(0,index_js_.useState)(null);const d=latest.data;const allDossiers=(0,index_js_.useMemo)(()=>{if(!d?.available)return[];const set=new Set;for(const r of d.suspense_rows??[])set.add(r.dossier);for(const r of d.supplier_rows??[])set.add(r.dossier);for(const r of d.customer_rows??[])set.add(r.dossier);for(const r of d.dossier_lines??[])set.add(r.dossier);for(const r of d.reconciliation_rows??[])set.add(r.dossier);for(const r of d.summary?.top_5_suspense??[])set.add(r.dossier);for(const r of d.summary?.top_5_supplier_debtors??[])set.add(r.dossier);for(const r of d.summary?.top_5_customer_creditors??[])set.add(r.dossier);return[...set].sort()},[d]);const openDrill=row=>setDrillDossier(row.dossier);const drillData=(0,index_js_.useMemo)(()=>{if(!drillDossier||!d?.available)return null;const reconciliation=(d.reconciliation_rows??[]).filter(r=>r.dossier===drillDossier).sort((a,b)=>{const av=a.last_reconciled_period_end??"0000-00-00";const bv=b.last_reconciled_period_end??"0000-00-00";return av.localeCompare(bv)});return{reconciliation,suspense:(d.suspense_rows??[]).filter(r=>r.dossier===drillDossier),internalTransfers:(d.internal_transfer_rows??[]).filter(r=>r.dossier===drillDossier),supplier:(d.supplier_rows??[]).filter(r=>r.dossier===drillDossier),customer:(d.customer_rows??[]).filter(r=>r.dossier===drillDossier)}},[drillDossier,d]);const summaryRows=(0,index_js_.useMemo)(()=>withCategoryFilter(withManagedFilter(withDossierFilter(d?.dossier_lines??[],selectedDossier),managedOnly),statusFilter),[d,selectedDossier,managedOnly,statusFilter]);const topSuspenseRows=(0,index_js_.useMemo)(()=>withDossierFilter(d?.summary?.top_5_suspense??[],selectedDossier),[d,selectedDossier]);const topSupplierRows=(0,index_js_.useMemo)(()=>withDossierFilter(d?.summary?.top_5_supplier_debtors??[],selectedDossier),[d,selectedDossier]);const topCustomerRows=(0,index_js_.useMemo)(()=>withDossierFilter(d?.summary?.top_5_customer_creditors??[],selectedDossier),[d,selectedDossier]);const suspenseRows=(0,index_js_.useMemo)(()=>withManagedFilter(withDossierFilter(d?.suspense_rows??[],selectedDossier),managedOnly),[d,selectedDossier,managedOnly]);const internalTransferRows=(0,index_js_.useMemo)(()=>withManagedFilter(withDossierFilter(d?.internal_transfer_rows??[],selectedDossier),managedOnly),[d,selectedDossier,managedOnly]);const supplierRows=(0,index_js_.useMemo)(()=>withManagedFilter(withDossierFilter(d?.supplier_rows??[],selectedDossier),managedOnly),[d,selectedDossier,managedOnly]);const customerRows=(0,index_js_.useMemo)(()=>withManagedFilter(withDossierFilter(d?.customer_rows??[],selectedDossier),managedOnly),[d,selectedDossier,managedOnly]);return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Container,{fluid:true,my:isMobile?0:"md",px:isMobile?12:void 0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(PageHeader.m,{title:"Accounting",updatedAt:d?.computed_at?new Date(d.computed_at).getTime():latest.dataUpdatedAt,isFetching:latest.isFetching,isError:latest.isError,onRefresh:()=>latest.refetch(),actions:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{loading:recompute.isPending,onClick:()=>recompute.mutate(),variant:"light",size:isMobile?"xs":"sm",children:"Recalculer"})}),d&&!d.available?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",children:"Aucun snapshot disponible — lancez \xab Recalculer \xbb ou attendez le run nocturne."}):/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{mb:"md",align:"end",gap:"sm",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{label:"Focus dossier",placeholder:"Tous les dossiers",data:allDossiers.map(dos=>({value:dos,label:dos})),value:selectedDossier,onChange:setSelectedDossier,searchable:true,clearable:true,w:isMobile?"100%":320}),selectedDossier&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"subtle",onClick:()=>setSelectedDossier(null),w:isMobile?"100%":void 0,children:"R\xe9initialiser"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SegmentedControl,{value:managedOnly?"managed":"all",onChange:v=>setManagedOnly("managed"===v),data:[{label:"G\xe9r\xe9s",value:"managed"},{label:"Tous",value:"all"}],w:isMobile?"100%":void 0})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Tabs,{value:tab,onChange:setTab,children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Tabs.List,{style:isMobile?{flexWrap:"nowrap",overflowX:"auto",overflowY:"hidden"}:void 0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Tab,{value:"resume",children:"R\xe9sum\xe9"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Tab,{value:"dossiers",children:"Dossiers"})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Tabs.Panel,{value:"resume",pt:"md",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SimpleGrid,{cols:isMobile?2:4,mb:"md",spacing:"sm",children:[{key:"all",label:"Scann\xe9s",value:d?.summary?.companies_scanned??0,color:void 0},{key:"propre",label:"Propres",value:d?.summary?.companies_clean??0,color:"green"},{key:"anomalie",label:"En anomalie",value:d?.summary?.companies_with_anomalies??0,color:"orange"},{key:"erreur",label:"En erreur",value:d?.summary?.companies_in_error??0,color:"red"}].map(tile=>{const active=statusFilter===tile.key;return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Card,{withBorder:active,style:{cursor:"pointer",borderColor:active?"var(--mantine-color-blue-5)":void 0},onClick:()=>setStatusFilter(tile.key),children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",children:tile.label}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:700,size:"xl",c:tile.color,children:tile.value})]},tile.key)})}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileDossierLineList,{rows:summaryRows,onRowClick:openDrill,computedAt:d?.computed_at}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:buildUnifiedCols(d?.computed_at),rows:summaryRows,onRowClick:openDrill})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Panel,{value:"top5",pt:"md",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"lg",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:4,mb:"sm",children:"Top 5 comptes d'attente (471)"}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileTopSuspenseList,{rows:topSuspenseRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:TOP_SUSPENSE_COLS,rows:topSuspenseRows,onRowClick:openDrill})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:4,mb:"sm",children:"Top 5 fournisseurs d\xe9biteurs (401)"}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileTopSupplierList,{rows:topSupplierRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:TOP_SUPPLIER_COLS,rows:topSupplierRows,onRowClick:openDrill})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:4,mb:"sm",children:"Top 5 clients cr\xe9diteurs (411)"}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileTopCustomerList,{rows:topCustomerRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:TOP_CUSTOMER_COLS,rows:topCustomerRows,onRowClick:openDrill})]})]})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Panel,{value:"s471",pt:"md",children:isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileSuspenseList,{rows:suspenseRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:SUSPENSE_COLS,rows:suspenseRows,onRowClick:openDrill})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Panel,{value:"s58",pt:"md",children:isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileSuspenseList,{rows:internalTransferRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:SUSPENSE_COLS,rows:internalTransferRows,onRowClick:openDrill})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Panel,{value:"s401",pt:"md",children:isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileSupplierList,{rows:supplierRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:SUPPLIER_COLS,rows:supplierRows,onRowClick:openDrill})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Panel,{value:"s411",pt:"md",children:isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileCustomerList,{rows:customerRows,onRowClick:openDrill}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:CUSTOMER_COLS,rows:customerRows,onRowClick:openDrill})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tabs.Panel,{value:"dossiers",pt:"md",children:/*#__PURE__*/(0,jsx_runtime.jsx)(DossiersTab,{})})]})]}),latest.isError?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"red",mt:"md",children:"Erreur de chargement."}):null,/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Drawer,{opened:!!drillDossier,onClose:()=>setDrillDossier(null),position:isMobile?"bottom":"right",size:isMobile?"calc(100dvh - 88px)":"xl",title:drillDossier?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",align:"center",wrap:isMobile?"wrap":"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Title,{order:isMobile?5:4,children:["Dossier ",drillDossier]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{size:"xs",variant:"light",onClick:()=>{setSelectedDossier(drillDossier);setDrillDossier(null)},children:"Focus sur ce dossier"})]}):null,styles:isMobile?{body:{padding:12,paddingBottom:24}}:void 0,children:drillData&&/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"md",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Title,{order:5,mb:6,children:["Rappros bancaires (",drillData.reconciliation.length,")"]}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileReconciliationList,{rows:drillData.reconciliation}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:DRILL_RECO_COLS,rows:drillData.reconciliation})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Title,{order:5,mb:6,children:["Comptes d'attente 471 (",drillData.suspense.length,")"]}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileSuspenseList,{rows:drillData.suspense}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:DRILL_SUSPENSE_COLS,rows:drillData.suspense})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Title,{order:5,mb:6,children:["Virements internes 58 (",drillData.internalTransfers.length,")"]}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileSuspenseList,{rows:drillData.internalTransfers}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:DRILL_SUSPENSE_COLS,rows:drillData.internalTransfers})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Title,{order:5,mb:6,children:["Fournisseurs d\xe9biteurs 401 (",drillData.supplier.length,")"]}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileSupplierList,{rows:drillData.supplier}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:DRILL_SUPPLIER_COLS,rows:drillData.supplier})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Title,{order:5,mb:6,children:["Clients cr\xe9diteurs 411 (",drillData.customer.length,")"]}),isMobile?/*#__PURE__*/(0,jsx_runtime.jsx)(MobileCustomerList,{rows:drillData.customer}):/*#__PURE__*/(0,jsx_runtime.jsx)(DetailTable,{columns:DRILL_CUSTOMER_COLS,rows:drillData.customer})]})]})})]})}const TOP_SUSPENSE_COLS=[{key:"rank",label:"#",numeric:true},{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"G\xe9r\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"dossier",label:"Dossier"},{key:"solde_eur",label:"Solde 471 (€)",numeric:true},{key:"nb_ecritures",label:"Nb \xe9cr.",numeric:true},{key:"top_libelle",label:"Top \xe9criture"},{key:"top_montant",label:"Montant",numeric:true}];const TOP_SUPPLIER_COLS=[{key:"rank",label:"#",numeric:true},{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"Manag\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"dossier",label:"Dossier"},{key:"total_eur",label:"Total d\xe9biteur (€)",numeric:true},{key:"nb_fournisseurs",label:"Nb fourn.",numeric:true},{key:"top_nom",label:"Top fournisseur"},{key:"top_montant",label:"Montant",numeric:true}];const TOP_CUSTOMER_COLS=[{key:"rank",label:"#",numeric:true},{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"Manag\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"dossier",label:"Dossier"},{key:"total_eur",label:"Total cr\xe9diteur (€)",numeric:true},{key:"nb_clients",label:"Nb clients",numeric:true},{key:"top_nom",label:"Top client"},{key:"top_montant",label:"Montant",numeric:true}];function buildUnifiedCols(computedAt){return[{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"Manag\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"status",label:"\xc9tat",render:r=>etatBadge(r)},{key:"dossier",label:"Dossier",render:r=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(CompanyLogo.D,{slug:r.slug,updatedAt:r.logo_updated_at,size:20}),/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:r.dossier})]})},{key:"responsable",label:"Responsable",render:r=>r.responsable?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:r.responsable.avatar_url,size:20,radius:"xl"}),/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:r.responsable.name})]}):/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:"—"})},{key:"fiscal_year_end",label:"Cl\xf4ture",render:r=>r.fiscal_year_end?/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:r.fiscal_year_end.split("-").reverse().join("/")}):/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:"—"})},{key:"solde_attente_eur",label:"Solde 471 (€)",numeric:true},{key:"solde_virements_eur",label:"Solde 58 (€)",numeric:true},{key:"total_fournisseurs_eur",label:"Fourn. d\xe9biteurs (€)",numeric:true},{key:"total_clients_eur",label:"Clients cr\xe9diteurs (€)",numeric:true},{key:"last_entry_date",label:"Derni\xe8re \xe9criture",render:row=>/*#__PURE__*/(0,jsx_runtime.jsxs)("span",{children:[row.last_entry_date??"—",staleBadge(row.last_entry_date),refreshKoBadge(row.refreshed_at,computedAt)]})},{key:"last_reconciliation_date",label:"Rappro le + en retard",render:r=>{if("pennylane"!==r.source)return/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:"—"});if(null==r.last_reconciliation_date)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{span:true,c:"red",fw:700,td:"underline",style:{cursor:"pointer"},children:"jamais"});return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{span:true,td:"underline",style:{cursor:"pointer"},children:r.last_reconciliation_date.split("-").reverse().join("/")})}},{key:"gla_last_sync_date",label:"Derni\xe8re synchro",render:r=>{if("pennylane"!==r.source||null==r.gla_last_sync_date)return/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:"—"});return/*#__PURE__*/(0,jsx_runtime.jsxs)("span",{children:[r.gla_last_sync_date.slice(0,10).split("-").reverse().join("/"),syncBadge(r.gla_last_sync_date)]})}},{key:"pending_supplier_invoices",label:"Fact. fourn. \xe0 traiter",numeric:true,render:r=>{if("pennylane"!==r.source||null==r.pending_supplier_invoices)return/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:"—"});return/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:r.pending_supplier_invoices})}}]}const SUSPENSE_COLS=[{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"Manag\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"dossier",label:"Dossier"},{key:"date",label:"Date"},{key:"numero_compte",label:"N\xb0 Compte"},{key:"libelle_compte",label:"Libell\xe9 compte"},{key:"libelle_ecriture",label:"Libell\xe9 \xe9criture"},{key:"journal",label:"Journal"},{key:"numero_piece",label:"N\xb0 Pi\xe8ce"},{key:"debit",label:"D\xe9bit",numeric:true},{key:"credit",label:"Cr\xe9dit",numeric:true},{key:"solde_net",label:"Solde net",numeric:true},{key:"lettre",label:"Lettr\xe9"},{key:"devise",label:"Devise"}];const SUPPLIER_COLS=[{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"Manag\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"dossier",label:"Dossier"},{key:"fournisseur",label:"Fournisseur"},{key:"solde_debiteur_eur",label:"Solde d\xe9biteur (€)",numeric:true},{key:"nb_ecritures",label:"Nb \xe9cr. non lettr\xe9es",numeric:true},{key:"devise",label:"Devise"}];const CUSTOMER_COLS=[{key:"source",label:"Source",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ProviderIcon,{provider:r.source})},{key:"managed",label:"Manag\xe9",render:r=>/*#__PURE__*/(0,jsx_runtime.jsx)(ManagedBadge,{managed:r.managed})},{key:"dossier",label:"Dossier"},{key:"client",label:"Client"},{key:"solde_crediteur_eur",label:"Solde cr\xe9diteur (€)",numeric:true},{key:"nb_ecritures",label:"Nb \xe9cr. non lettr\xe9es",numeric:true},{key:"devise",label:"Devise"}];const DRILL_RECO_COLS=[{key:"bank_label",label:"Banque",render:r=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(BankLogo,{label:r.bank_label,size:20}),/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:r.bank_label??"—"})]})},{key:"last_reconciled_period_end",label:"Dernier rappro",render:r=>{if(null==r.last_reconciled_period_end)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{span:true,c:"red",fw:700,children:"jamais"});return/*#__PURE__*/(0,jsx_runtime.jsx)("span",{children:r.last_reconciled_period_end.split("-").reverse().join("/")})}}];const DRILL_SUSPENSE_COLS=[{key:"date",label:"Date"},{key:"numero_compte",label:"N\xb0 Compte"},{key:"libelle_ecriture",label:"Libell\xe9"},{key:"debit",label:"D\xe9bit",numeric:true},{key:"credit",label:"Cr\xe9dit",numeric:true},{key:"solde_net",label:"Solde net",numeric:true},{key:"lettre",label:"Lettr\xe9"}];const DRILL_SUPPLIER_COLS=[{key:"fournisseur",label:"Fournisseur"},{key:"solde_debiteur_eur",label:"Solde d\xe9biteur (€)",numeric:true},{key:"nb_ecritures",label:"Nb \xe9cr.",numeric:true},{key:"devise",label:"Devise"}];const DRILL_CUSTOMER_COLS=[{key:"client",label:"Client"},{key:"solde_crediteur_eur",label:"Solde cr\xe9diteur (€)",numeric:true},{key:"nb_ecritures",label:"Nb \xe9cr.",numeric:true},{key:"devise",label:"Devise"}];function EtatSaisie(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(index_js_.StrictMode,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(providers.C,{...props,children:/*#__PURE__*/(0,jsx_runtime.jsx)(EtatSaisieApp,{})})})}}}]);
@@ -1 +1 @@
1
- "use strict";(globalThis["chunk_tech_app"]=globalThis["chunk_tech_app"]||[]).push([["509"],{466:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{U:()=>useGsheetStock});var _tanstack_react_query__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(6197);var _useApi__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(4148);function useGsheetStock(){const api=(0,_useApi__WEBPACK_IMPORTED_MODULE_1__.h)();return(0,_tanstack_react_query__WEBPACK_IMPORTED_MODULE_0__.useQuery)({queryKey:["tech","gsheet","stock"],queryFn:async()=>(await api.gsheet.getStockV1()).data,refetchInterval:3e4,refetchIntervalInBackground:false,refetchOnWindowFocus:true})}},3897:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{O:()=>BrandLogo});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(5893);var _mantine_core__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(207);var _src_components_logoDev_ts__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(243);function BrandLogo({domain,alt,size=24}){return/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Image,{src:(0,_src_components_logoDev_ts__WEBPACK_IMPORTED_MODULE_2__.j)(domain),alt:alt,title:alt,w:size,h:size,fit:"contain",radius:"sm",style:{aspectRatio:1}})}},243:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{j:()=>logoDevUrl});const LOGO_DEV_TOKEN="pk_BVN4OQv0Qs-bnqjdIgTppg";function logoDevUrl(domain){return`https://img.logo.dev/${domain}?token=${LOGO_DEV_TOKEN}`}},5080:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{default:()=>Spreadsheet});var jsx_runtime=__webpack_require__(5893);var index_js_=__webpack_require__(3106);var providers=__webpack_require__(7034);var QueueDashboard=__webpack_require__(5351);var index_mjs_=__webpack_require__(207);var gsheetStockQuery=__webpack_require__(466);var modern_index_js_=__webpack_require__(6197);var useApi=__webpack_require__(4148);function useGsheetTasks(filters){const api=(0,useApi.h)();const service=filters.service?.toLowerCase()==="all"?void 0:filters.service;const owner=filters.owner?.toLowerCase()==="all"?void 0:filters.owner;const query={...service&&{service},...owner&&{owner},...filters.state&&{state:filters.state},...void 0!==filters.take&&{take:String(filters.take)},...void 0!==filters.skip&&{skip:String(filters.skip)}};return(0,modern_index_js_.useQuery)({queryKey:["tech","gsheet","tasks",filters],queryFn:async()=>(await api.gsheet.listTasksV1(query)).data,refetchOnWindowFocus:false})}function useInvalidate(){const queryClient=(0,modern_index_js_.useQueryClient)();return()=>queryClient.invalidateQueries({queryKey:["tech","gsheet"]})}function useUnstickTask(){const api=(0,useApi.h)();const invalidate=useInvalidate();return(0,modern_index_js_.useMutation)({mutationFn:async id=>(await api.gsheet.unstickV1({id:String(id)})).data,onSuccess:invalidate})}function useDiscardTask(){const api=(0,useApi.h)();const invalidate=useInvalidate();return(0,modern_index_js_.useMutation)({mutationFn:async id=>(await api.gsheet.discardV1({id:String(id)})).data,onSuccess:invalidate})}function useSetTaskOwner(){const api=(0,useApi.h)();const invalidate=useInvalidate();return(0,modern_index_js_.useMutation)({mutationFn:async({id,owner})=>(await api.gsheet.setOwnerV1({id:String(id)},{owner})).data,onSuccess:invalidate})}function useDeleteRedisLock(){const api=(0,useApi.h)();const invalidate=useInvalidate();return(0,modern_index_js_.useMutation)({mutationFn:async id=>(await api.gsheet.deleteRedisLockV1({id:String(id)})).data,onSuccess:invalidate})}var jobLogsContext=__webpack_require__(4302);var tabler_icons_react_mjs_=__webpack_require__(9632);var esm_index_mjs_=__webpack_require__(1455);function grafanaUrl(traceId){return`https://airporting.grafana.net/d/beegyy3vsp8n4c/recipes?var-trace=${encodeURIComponent(traceId)}&orgId=1&from=now-7d&to=now&timezone=browser&showCategory=Logs&refresh=7d`}function notify(title,message,color){esm_index_mjs_.notifications.show({title,message,color})}function RowActions({taskId,currentOwner,service,spreadsheet,worksheet,githubJob,traceId,onShowLogs}){const[confirm,setConfirm]=(0,index_js_.useState)(null);const[ownerModalOpen,setOwnerModalOpen]=(0,index_js_.useState)(false);const[ownerInput,setOwnerInput]=(0,index_js_.useState)(currentOwner??"");const unstick=useUnstickTask();const discard=useDiscardTask();const setOwner=useSetTaskOwner();const deleteLock=useDeleteRedisLock();const runUnstick=()=>unstick.mutate(taskId,{onSuccess:()=>notify("Unstuck",`Task #${taskId} reset`,"green"),onError:e=>notify("Failed",e?.message??"Unstick failed","red")});const runDiscard=()=>{setConfirm(null);discard.mutate(taskId,{onSuccess:()=>notify("Discarded",`Task #${taskId} marked done`,"green"),onError:e=>notify("Failed",e?.message??"Discard failed","red")})};const runSetOwner=()=>{setOwnerModalOpen(false);setOwner.mutate({id:taskId,owner:ownerInput},{onSuccess:()=>notify("Owner updated",`Task #${taskId} \u{2192} ${ownerInput}`,"green"),onError:e=>notify("Failed",e?.message??"Set owner failed","red")})};const runDeleteLock=()=>{setConfirm(null);deleteLock.mutate(taskId,{onSuccess:data=>notify("Redis lock",data.existed?`Deleted ${data.key}`:`No lock found (${data.key})`,"green"),onError:e=>notify("Failed",e?.message??"Redis delete failed","red")})};const getWorksheetUrl=()=>{if(!spreadsheet)return null;return"excel"===service?`https://airporting.sharepoint.com/:x:/g/personal/airporting_com/ER${spreadsheet}`:`https://docs.google.com/spreadsheets/d/${spreadsheet}/edit`};const worksheetUrl=getWorksheetUrl();return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",children:[worksheetUrl&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:"Ouvrir le tableur",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{component:"a",href:worksheetUrl,target:"_blank",rel:"noopener noreferrer",variant:"subtle","aria-label":"Ouvrir le tableur",children:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconFileSpreadsheet,{size:16})})}),githubJob&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:"GitHub Actions logs",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{variant:"subtle",onClick:()=>onShowLogs(githubJob),"aria-label":"GitHub Actions logs",children:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconTerminal,{size:16})})}),traceId&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:"Grafana Loki logs",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{component:"a",href:grafanaUrl(traceId),target:"_blank",rel:"noopener noreferrer",variant:"subtle","aria-label":"Grafana Loki logs",children:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconFileText,{size:16})})}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Menu,{position:"bottom-end",withArrow:true,shadow:"md",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Target,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{variant:"default","aria-label":"Actions",children:"⋮"})}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Menu.Dropdown,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Item,{onClick:runUnstick,children:"Unstick"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Item,{onClick:()=>{setOwnerInput(currentOwner??"");setOwnerModalOpen(true)},children:"Set owner…"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Item,{onClick:()=>setConfirm("redis"),children:"Delete Redis lock"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Divider,{}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Item,{color:"red",onClick:()=>setConfirm("discard"),children:"Discard"})]})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Modal,{opened:"discard"===confirm,onClose:()=>setConfirm(null),title:"Discard task",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"sm",style:{wordBreak:"break-all"},children:["Mark task #",taskId," (",spreadsheet,worksheet?`:${worksheet}`:"",") as ",/*#__PURE__*/(0,jsx_runtime.jsx)("b",{children:"done"})," with step=",/*#__PURE__*/(0,jsx_runtime.jsx)("code",{children:"discarded"}),". The task will not be processed by the runner."]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"flex-end",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"default",onClick:()=>setConfirm(null),children:"Cancel"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{color:"red",onClick:runDiscard,loading:discard.isPending,children:"Discard"})]})]})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Modal,{opened:"redis"===confirm,onClose:()=>setConfirm(null),title:"Delete Redis lock",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"sm",style:{wordBreak:"break-all"},children:["Delete the Redis running-lock for ",spreadsheet,worksheet?`:${worksheet}`:"",". The runner will be able to pick up the worksheet again on the next iteration."]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"flex-end",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"default",onClick:()=>setConfirm(null),children:"Cancel"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{color:"orange",onClick:runDeleteLock,loading:deleteLock.isPending,children:"Delete lock"})]})]})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Modal,{opened:ownerModalOpen,onClose:()=>setOwnerModalOpen(false),title:`Set owner for task #${taskId}`,children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TextInput,{label:"Owner email",value:ownerInput,onChange:e=>setOwnerInput(e.currentTarget.value),placeholder:"bob@airporting.com"}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"flex-end",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"default",onClick:()=>setOwnerModalOpen(false),children:"Cancel"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{onClick:runSetOwner,loading:setOwner.isPending,disabled:!ownerInput.trim(),children:"Save"})]})]})})]})}var BrandLogo=__webpack_require__(3897);const SERVICE_DOMAIN={gsheet:"google.com",excel:"microsoft.com"};const SERVICE_LABEL={gsheet:"Google Sheets",excel:"Excel"};function ServiceLogo({service,size=18}){const domain=SERVICE_DOMAIN[service];const label=SERVICE_LABEL[service]??service;if(!domain)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",variant:"light",color:"gray",title:service,children:service.slice(0,2).toUpperCase()});return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:6,wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(BrandLogo.O,{domain:domain,alt:label,size:size}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",children:label})]})}const STATE_COLORS={pending:"gray",running:"blue",stuck:"orange",errored:"red",done:"green"};const STATE_LABELS={pending:"Pending",running:"Running",stuck:"Stuck",errored:"Errored",done:"Done"};function fmt(d){return d?new Date(d).toLocaleString("fr-FR"):"—"}function ageBadge(created){const h=(Date.now()-new Date(created).getTime())/36e5;if(h<1)return null;const label=h>=24?`${Math.floor(h/24)}j`:`${Math.floor(h)}h`;const color=h>=24?"red":h>=4?"orange":"gray";return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{ml:6,size:"xs",color:color,variant:"light",children:label})}function GsheetRowActions({item}){const openLogs=(0,jobLogsContext.j)();return/*#__PURE__*/(0,jsx_runtime.jsx)(RowActions,{taskId:item.id,currentOwner:item.owner,service:item.service,spreadsheet:item.spreadsheet,worksheet:item.worksheet,githubJob:item.github_job,traceId:item.trace_id,onShowLogs:openLogs})}async function runBulk(ids,fn){const results=await Promise.allSettled(ids.map(fn));const ok=results.filter(r=>"fulfilled"===r.status).length;return{ok,failed:results.length-ok}}function useGsheetConfig(){const unstick=useUnstickTask();const discard=useDiscardTask();const setOwner=useSetTaskOwner();const deleteLock=useDeleteRedisLock();return(0,index_js_.useMemo)(()=>({title:"Worksheets : \xe9tat des lieux des copies sur tableurs",source:{useStock:gsheetStockQuery.U,useTasks:({service,owner,state})=>useGsheetTasks({service:service??void 0,owner:owner??void 0,state,take:50})},initialFilters:{service:null,owner:null,state:"pending",search:""},kpis:[{key:"pending",label:"Pending",value:s=>s?.pending??0,filter:{state:"pending"}},{key:"running",label:"Running",value:s=>s?.running??0,filter:{state:"running"}},{key:"stuck",label:"Stuck",value:s=>s?.stuck??0,tone:s=>(s?.stuck??0)>0?"warn":"neutral",filter:{state:"stuck"}},{key:"errored",label:"Errored",value:s=>s?.errored??0,tone:s=>(s?.errored??0)>0?"bad":"neutral",filter:{state:"errored"}},{key:"done_today",label:"Done today",value:s=>s?.done_today??0,filter:{state:"done"}},{key:"oldest",label:"Oldest pending",value:s=>s?.oldest?`${s.oldest.ageHours}h`:"—"}],filters:[{kind:"select",key:"service",label:"Service",options:s=>["all",...(s?.byService??[]).map(e=>e.key)],width:240},{kind:"select",key:"owner",label:"Owner",options:s=>["all",...(s?.byOwner??[]).map(e=>e.key)],width:240},{kind:"select",key:"state",label:"State",options:()=>["pending","running","stuck","errored","done","all"],clearable:false,width:140},{kind:"search",key:"search",label:"Recherche",placeholder:"id, owner, spreadsheet…",width:240}],columns:[{key:"service",label:"Service",render:t=>/*#__PURE__*/(0,jsx_runtime.jsx)(ServiceLogo,{service:t.service})},{key:"spreadsheet",label:"Spreadsheet ID",render:t=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",style:{wordBreak:"break-all"},children:t.spreadsheet})},{key:"worksheet",label:"Worksheet",render:t=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",style:{wordBreak:"break-all"},children:t.worksheet??"—"})},{key:"company_display_name",label:"Entreprise",render:t=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",children:t.company_display_name??"—"})},{key:"owner",label:"Owner",render:t=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",children:t.owner??"—"})},{key:"state",label:"State",render:t=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{color:STATE_COLORS[t.state],children:STATE_LABELS[t.state]})},{key:"created",label:"Created",render:t=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",children:fmt(t.created)}),ageBadge(t.created)]})}],rowActions:[{key:"actions",render:item=>/*#__PURE__*/(0,jsx_runtime.jsx)(GsheetRowActions,{item:item})}],bulkActions:[{key:"unstick",label:"Unstick",run:ids=>runBulk(ids,id=>unstick.mutateAsync(id))},{key:"set-owner",label:"Set owner…",prompt:{label:"Owner email",placeholder:"bob@airporting.com"},run:(ids,owner)=>{if(!owner)return Promise.resolve({ok:0,failed:ids.length});return runBulk(ids,id=>setOwner.mutateAsync({id,owner}))}},{key:"delete-lock",label:"Delete Redis lock",color:"orange",confirm:{title:"Delete Redis lock for {count} task(s)",body:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:"fm-task-node-<id>",disabled:true,children:/*#__PURE__*/(0,jsx_runtime.jsxs)("span",{children:["Suppression du verrou Redis pour ","{count}"," t\xe2che(s)."]})})},run:ids=>runBulk(ids,id=>deleteLock.mutateAsync(id))},{key:"discard",label:"Discard",color:"red",confirm:{title:"Discard {count} task(s)",body:"Les t\xe2ches seront marqu\xe9es comme finished/discarded."},run:ids=>runBulk(ids,id=>discard.mutateAsync(id))}],getRowId:t=>t.id,searchMatches:(t,q)=>String(t.id).includes(q)||(t.owner??"").toLowerCase().includes(q)||(t.spreadsheet??"").toLowerCase().includes(q)||(t.worksheet??"").toLowerCase().includes(q)||(t.service??"").toLowerCase().includes(q)||(t.company_display_name??"").toLowerCase().includes(q)}),[unstick,discard,setOwner,deleteLock])}function SpreadsheetApp(){const config=useGsheetConfig();return/*#__PURE__*/(0,jsx_runtime.jsx)(QueueDashboard.r,{config:config})}function Spreadsheet(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(index_js_.StrictMode,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(providers.C,{...props,children:/*#__PURE__*/(0,jsx_runtime.jsx)(SpreadsheetApp,{})})})}}}]);
1
+ "use strict";(globalThis["chunk_tech_app"]=globalThis["chunk_tech_app"]||[]).push([["509"],{466:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{U:()=>useGsheetStock});var _tanstack_react_query__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(6197);var _useApi__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(4148);function useGsheetStock(){const api=(0,_useApi__WEBPACK_IMPORTED_MODULE_1__.h)();return(0,_tanstack_react_query__WEBPACK_IMPORTED_MODULE_0__.useQuery)({queryKey:["tech","gsheet","stock"],queryFn:async()=>(await api.gsheet.getStockV1()).data,refetchInterval:3e4,refetchIntervalInBackground:false,refetchOnWindowFocus:true})}},3897:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{O:()=>BrandLogo});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(5893);var _mantine_core__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(207);var _src_components_logoDev_ts__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(243);function BrandLogo({domain,alt,size=24}){return/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Image,{src:(0,_src_components_logoDev_ts__WEBPACK_IMPORTED_MODULE_2__.j)(domain),alt:alt,title:alt,w:size,h:size,fit:"contain",radius:"sm",style:{aspectRatio:1}})}},243:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{j:()=>logoDevUrl});const LOGO_DEV_TOKEN="pk_BVN4OQv0Qs-bnqjdIgTppg";function logoDevUrl(domain){return`https://img.logo.dev/${domain}?token=${LOGO_DEV_TOKEN}`}},5080:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{default:()=>Spreadsheet});var jsx_runtime=__webpack_require__(5893);var index_js_=__webpack_require__(3106);var providers=__webpack_require__(7034);var QueueDashboard=__webpack_require__(5351);var index_mjs_=__webpack_require__(207);var gsheetStockQuery=__webpack_require__(466);var modern_index_js_=__webpack_require__(6197);var useApi=__webpack_require__(4148);function useGsheetTasks(filters){const api=(0,useApi.h)();const service=filters.service?.toLowerCase()==="all"?void 0:filters.service;const owner=filters.owner?.toLowerCase()==="all"?void 0:filters.owner;const query={...service&&{service},...owner&&{owner},...filters.state&&{state:filters.state},...void 0!==filters.take&&{take:String(filters.take)},...void 0!==filters.skip&&{skip:String(filters.skip)}};return(0,modern_index_js_.useQuery)({queryKey:["tech","gsheet","tasks",filters],queryFn:async()=>(await api.gsheet.listTasksV1(query)).data,refetchOnWindowFocus:false})}function useInvalidate(){const queryClient=(0,modern_index_js_.useQueryClient)();return()=>queryClient.invalidateQueries({queryKey:["tech","gsheet"]})}function useUnstickTask(){const api=(0,useApi.h)();const invalidate=useInvalidate();return(0,modern_index_js_.useMutation)({mutationFn:async id=>(await api.gsheet.unstickV1({id:String(id)})).data,onSuccess:invalidate})}function useDiscardTask(){const api=(0,useApi.h)();const invalidate=useInvalidate();return(0,modern_index_js_.useMutation)({mutationFn:async id=>(await api.gsheet.discardV1({id:String(id)})).data,onSuccess:invalidate})}function useSetTaskOwner(){const api=(0,useApi.h)();const invalidate=useInvalidate();return(0,modern_index_js_.useMutation)({mutationFn:async({id,owner})=>(await api.gsheet.setOwnerV1({id:String(id)},{owner})).data,onSuccess:invalidate})}function useDeleteRedisLock(){const api=(0,useApi.h)();const invalidate=useInvalidate();return(0,modern_index_js_.useMutation)({mutationFn:async id=>(await api.gsheet.deleteRedisLockV1({id:String(id)})).data,onSuccess:invalidate})}var jobLogsContext=__webpack_require__(4302);var tabler_icons_react_mjs_=__webpack_require__(9632);var esm_index_mjs_=__webpack_require__(1455);function grafanaUrl(traceId){return`https://airporting.grafana.net/d/beegyy3vsp8n4c/recipes?var-trace=${encodeURIComponent(traceId)}&orgId=1&from=now-7d&to=now&timezone=browser&showCategory=Logs&refresh=7d`}function notify(title,message,color){esm_index_mjs_.notifications.show({title,message,color})}function RowActions({taskId,currentOwner,service,spreadsheet,worksheet,githubJob,traceId,onShowLogs}){const[confirm,setConfirm]=(0,index_js_.useState)(null);const[ownerModalOpen,setOwnerModalOpen]=(0,index_js_.useState)(false);const[ownerInput,setOwnerInput]=(0,index_js_.useState)(currentOwner??"");const unstick=useUnstickTask();const discard=useDiscardTask();const setOwner=useSetTaskOwner();const deleteLock=useDeleteRedisLock();const runUnstick=()=>unstick.mutate(taskId,{onSuccess:()=>notify("Unstuck",`Task #${taskId} reset`,"green"),onError:e=>notify("Failed",e?.message??"Unstick failed","red")});const runDiscard=()=>{setConfirm(null);discard.mutate(taskId,{onSuccess:()=>notify("Discarded",`Task #${taskId} marked done`,"green"),onError:e=>notify("Failed",e?.message??"Discard failed","red")})};const runSetOwner=()=>{setOwnerModalOpen(false);setOwner.mutate({id:taskId,owner:ownerInput},{onSuccess:()=>notify("Owner updated",`Task #${taskId} \u{2192} ${ownerInput}`,"green"),onError:e=>notify("Failed",e?.message??"Set owner failed","red")})};const runDeleteLock=()=>{setConfirm(null);deleteLock.mutate(taskId,{onSuccess:data=>notify("Redis lock",data.existed?`Deleted ${data.key}`:`No lock found (${data.key})`,"green"),onError:e=>notify("Failed",e?.message??"Redis delete failed","red")})};const getWorksheetUrl=()=>{if(!spreadsheet)return null;return"excel"===service?`https://airporting.sharepoint.com/:x:/g/personal/airporting_com/ER${spreadsheet}`:`https://docs.google.com/spreadsheets/d/${spreadsheet}/edit`};const worksheetUrl=getWorksheetUrl();return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",children:[worksheetUrl&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:"Ouvrir le tableur",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{component:"a",href:worksheetUrl,target:"_blank",rel:"noopener noreferrer",variant:"subtle","aria-label":"Ouvrir le tableur",children:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconFileSpreadsheet,{size:16})})}),githubJob&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:"GitHub Actions logs",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{variant:"subtle",onClick:()=>onShowLogs(githubJob),"aria-label":"GitHub Actions logs",children:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconTerminal,{size:16})})}),traceId&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:"Grafana Loki logs",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{component:"a",href:grafanaUrl(traceId),target:"_blank",rel:"noopener noreferrer",variant:"subtle","aria-label":"Grafana Loki logs",children:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconFileText,{size:16})})}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Menu,{position:"bottom-end",withArrow:true,shadow:"md",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Target,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{variant:"default","aria-label":"Actions",children:"⋮"})}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Menu.Dropdown,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Item,{onClick:runUnstick,children:"Unstick"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Item,{onClick:()=>{setOwnerInput(currentOwner??"");setOwnerModalOpen(true)},children:"Set owner…"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Item,{onClick:()=>setConfirm("redis"),children:"Delete Redis lock"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Divider,{}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Item,{color:"red",onClick:()=>setConfirm("discard"),children:"Discard"})]})]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Modal,{opened:"discard"===confirm,onClose:()=>setConfirm(null),title:"Discard task",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"sm",style:{wordBreak:"break-all"},children:["Mark task #",taskId," (",spreadsheet,worksheet?`:${worksheet}`:"",") as ",/*#__PURE__*/(0,jsx_runtime.jsx)("b",{children:"done"})," with step=",/*#__PURE__*/(0,jsx_runtime.jsx)("code",{children:"discarded"}),". The task will not be processed by the runner."]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"flex-end",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"default",onClick:()=>setConfirm(null),children:"Cancel"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{color:"red",onClick:runDiscard,loading:discard.isPending,children:"Discard"})]})]})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Modal,{opened:"redis"===confirm,onClose:()=>setConfirm(null),title:"Delete Redis lock",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"sm",style:{wordBreak:"break-all"},children:["Delete the Redis running-lock for ",spreadsheet,worksheet?`:${worksheet}`:"",". The runner will be able to pick up the worksheet again on the next iteration."]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"flex-end",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"default",onClick:()=>setConfirm(null),children:"Cancel"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{color:"orange",onClick:runDeleteLock,loading:deleteLock.isPending,children:"Delete lock"})]})]})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Modal,{opened:ownerModalOpen,onClose:()=>setOwnerModalOpen(false),title:`Set owner for task #${taskId}`,children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TextInput,{label:"Owner email",value:ownerInput,onChange:e=>setOwnerInput(e.currentTarget.value),placeholder:"bob@airporting.com"}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"flex-end",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"default",onClick:()=>setOwnerModalOpen(false),children:"Cancel"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{onClick:runSetOwner,loading:setOwner.isPending,disabled:!ownerInput.trim(),children:"Save"})]})]})})]})}var BrandLogo=__webpack_require__(3897);const SERVICE_DOMAIN={gsheet:"google.com",excel:"microsoft.com"};const SERVICE_LABEL={gsheet:"Google Sheets",excel:"Excel"};function ServiceLogo({service,size=18}){const domain=SERVICE_DOMAIN[service];const label=SERVICE_LABEL[service]??service;if(!domain)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",variant:"light",color:"gray",title:service,children:service.slice(0,2).toUpperCase()});return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:6,wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(BrandLogo.O,{domain:domain,alt:label,size:size}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",children:label})]})}const STATE_COLORS={pending:"gray",running:"blue",stuck:"orange",errored:"red",done:"green"};const STATE_LABELS={pending:"Pending",running:"Running",stuck:"Stuck",errored:"Errored",done:"Done"};function fmt(d){return d?new Date(d).toLocaleString("fr-FR"):"—"}function ageBadge(created){const h=(Date.now()-new Date(created).getTime())/36e5;if(h<1)return null;const label=h>=24?`${Math.floor(h/24)}j`:`${Math.floor(h)}h`;const color=h>=24?"red":h>=4?"orange":"gray";return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{ml:6,size:"xs",color:color,variant:"light",children:label})}function GsheetRowActions({item}){const openLogs=(0,jobLogsContext.j)();return/*#__PURE__*/(0,jsx_runtime.jsx)(RowActions,{taskId:item.id,currentOwner:item.owner,service:item.service,spreadsheet:item.spreadsheet,worksheet:item.worksheet,githubJob:item.github_job,traceId:item.trace_id,onShowLogs:openLogs})}async function runBulk(ids,fn){const results=await Promise.allSettled(ids.map(fn));const ok=results.filter(r=>"fulfilled"===r.status).length;return{ok,failed:results.length-ok}}function useGsheetConfig(){const unstick=useUnstickTask();const discard=useDiscardTask();const setOwner=useSetTaskOwner();const deleteLock=useDeleteRedisLock();return(0,index_js_.useMemo)(()=>({title:"Worksheets : \xe9tat des lieux des copies sur tableurs",source:{useStock:gsheetStockQuery.U,useTasks:({service,owner,state})=>useGsheetTasks({service:service??void 0,owner:owner??void 0,state,take:50})},initialFilters:{service:null,owner:null,state:"pending",search:""},kpis:[{key:"pending",label:"Pending",value:s=>s?.pending??0,filter:{state:"pending"}},{key:"running",label:"Running",value:s=>s?.running??0,filter:{state:"running"}},{key:"stuck",label:"Stuck",value:s=>s?.stuck??0,tone:s=>(s?.stuck??0)>0?"warn":"neutral",filter:{state:"stuck"}},{key:"errored",label:"Errored",value:s=>s?.errored??0,tone:s=>(s?.errored??0)>0?"bad":"neutral",filter:{state:"errored"}},{key:"done_today",label:"Done today",value:s=>s?.done_today??0,filter:{state:"done"}},{key:"oldest",label:"Oldest pending",value:s=>s?.oldest?`${s.oldest.ageHours}h`:"—"}],filters:[{kind:"select",key:"service",label:"Service",options:()=>["all","gsheet","excel"],width:240},{kind:"select",key:"owner",label:"Owner",options:s=>["all",...(s?.byOwner??[]).map(e=>e.key)],width:240},{kind:"select",key:"state",label:"State",options:()=>["pending","running","stuck","errored","done","all"],clearable:false,width:140},{kind:"search",key:"search",label:"Recherche",placeholder:"id, owner, spreadsheet…",width:240}],columns:[{key:"service",label:"Service",render:t=>/*#__PURE__*/(0,jsx_runtime.jsx)(ServiceLogo,{service:t.service})},{key:"spreadsheet",label:"Spreadsheet ID",render:t=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",style:{wordBreak:"break-all"},children:t.spreadsheet})},{key:"worksheet",label:"Worksheet",render:t=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",style:{wordBreak:"break-all"},children:t.worksheet??"—"})},{key:"company_display_name",label:"Entreprise",render:t=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",children:t.company_display_name??"—"})},{key:"owner",label:"Owner",render:t=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",children:t.owner??"—"})},{key:"state",label:"State",render:t=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{color:STATE_COLORS[t.state],children:STATE_LABELS[t.state]})},{key:"created",label:"Created",render:t=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",children:fmt(t.created)}),ageBadge(t.created)]})}],rowActions:[{key:"actions",render:item=>/*#__PURE__*/(0,jsx_runtime.jsx)(GsheetRowActions,{item:item})}],bulkActions:[{key:"unstick",label:"Unstick",run:ids=>runBulk(ids,id=>unstick.mutateAsync(id))},{key:"set-owner",label:"Set owner…",prompt:{label:"Owner email",placeholder:"bob@airporting.com"},run:(ids,owner)=>{if(!owner)return Promise.resolve({ok:0,failed:ids.length});return runBulk(ids,id=>setOwner.mutateAsync({id,owner}))}},{key:"delete-lock",label:"Delete Redis lock",color:"orange",confirm:{title:"Delete Redis lock for {count} task(s)",body:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:"fm-task-node-<id>",disabled:true,children:/*#__PURE__*/(0,jsx_runtime.jsxs)("span",{children:["Suppression du verrou Redis pour ","{count}"," t\xe2che(s)."]})})},run:ids=>runBulk(ids,id=>deleteLock.mutateAsync(id))},{key:"discard",label:"Discard",color:"red",confirm:{title:"Discard {count} task(s)",body:"Les t\xe2ches seront marqu\xe9es comme finished/discarded."},run:ids=>runBulk(ids,id=>discard.mutateAsync(id))}],getRowId:t=>t.id,searchMatches:(t,q)=>String(t.id).includes(q)||(t.owner??"").toLowerCase().includes(q)||(t.spreadsheet??"").toLowerCase().includes(q)||(t.worksheet??"").toLowerCase().includes(q)||(t.service??"").toLowerCase().includes(q)||(t.company_display_name??"").toLowerCase().includes(q)}),[unstick,discard,setOwner,deleteLock])}function SpreadsheetApp(){const config=useGsheetConfig();return/*#__PURE__*/(0,jsx_runtime.jsx)(QueueDashboard.r,{config:config})}function Spreadsheet(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(index_js_.StrictMode,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(providers.C,{...props,children:/*#__PURE__*/(0,jsx_runtime.jsx)(SpreadsheetApp,{})})})}}}]);