JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php require_once __DIR__ . '/../lib/EntrepriseLegalFields.php'; $legalLines = EntrepriseLegalFields::collectVisibleLines($infos_entreprise); ?>
<style>
@media print {
.no-print { display: none !important; }
body * { visibility: hidden !important; }
.crm-apercu-devis-pdf, .crm-apercu-devis-pdf * { visibility: visible !important; }
.crm-apercu-devis-pdf {
position: absolute !important;
left: 0; top: 0;
width: 210mm !important;
min-height: 297mm !important;
max-height: 297mm !important;
margin: 0 !important;
box-shadow: none !important;
background: #fff !important;
overflow: hidden !important;
page-break-after: avoid !important;
page-break-before: avoid !important;
page-break-inside: avoid !important;
}
@page {
size: A4 portrait;
margin: 0;
}
}
</style>
<div class="crm-apercu-devis-pdf" style="width: 210mm; min-height: 297mm; height: 297mm; margin: 0 auto; background: #fff; padding: 32px 40px 24px 40px; box-sizing: border-box; border-radius: 12px; box-shadow: 0 4px 24px #0002; font-size: 0.9em; display: flex; flex-direction: column; justify-content: flex-start;">
<!-- Boutons sticky centrés en haut -->
<div class="no-print crm-apercu-devis-actions-sticky">
<button type="button" onclick="window.print();" class="button">Imprimer</button>
<a href="index.php?page=devis&action=pdf&id=<?= htmlspecialchars((string) ($devis['id'] ?? '')) ?>" class="button" target="_blank" rel="noopener">Exporter en PDF</a>
<a href="index.php?page=devis" class="button">Fermer</a>
</div>
<!-- En-tête A4 -->
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 32px;">
<!-- Logo et coordonnées entreprise à gauche -->
<div style="display: flex; flex-direction: column; align-items: flex-start; max-width: 50%; border-radius:8px; padding:12px 18px 12px 0; margin-bottom:0; justify-content: flex-start; background:none;">
<?php if (!empty($infos_entreprise['logo'])): ?>
<img src="<?= htmlspecialchars($infos_entreprise['logo']) ?>" alt="Logo entreprise" style="height: 75px; max-width: 150px; object-fit: contain; border-radius: 8px; padding: 0; margin-bottom: 10px; display:block; align-self:flex-start; background:none;">
<?php endif; ?>
<!-- Nom de l'entreprise masqué sur l'aperçu du devis -->
<div style="margin-bottom: 2px;">
<?= htmlspecialchars($infos_entreprise['adresse'] ?? '') ?><?php if (!empty($infos_entreprise['code_postal']) || !empty($infos_entreprise['ville'])): ?><br><?= htmlspecialchars($infos_entreprise['code_postal'] ?? '') ?> <?= htmlspecialchars($infos_entreprise['ville'] ?? '') ?><?php endif; ?>
</div>
<?php if (!empty($infos_entreprise['email'])): ?>
<div style="margin-bottom: 2px;">Email : <?= htmlspecialchars($infos_entreprise['email']) ?></div>
<?php endif; ?>
<?php if (!empty($infos_entreprise['telephone'])): ?>
<div>Tél : <?= htmlspecialchars($infos_entreprise['telephone']) ?></div>
<?php endif; ?>
<?php foreach ($legalLines as $line): ?>
<div><?= htmlspecialchars($line['label']) ?> : <?= htmlspecialchars($line['value']) ?></div>
<?php endforeach; ?>
</div>
<!-- Date et infos client à droite -->
<div style="text-align: right; max-width: 45%;">
<div style="font-size: 1.1em; font-weight: 600; margin-bottom: 10px;">Date : <?= date('d/m/Y') ?></div>
<div style="background: #f7f7f7; border-radius: 7px; padding: 12px 16px; border:1px solid #b0b4bb;">
<div style="font-weight: bold; font-size: 1.08em; margin-bottom: 4px;">Client</div>
<?php $displayMode = $devis['client_display'] ?? 'name_company'; ?>
<?php if ($displayMode === 'name_only'): ?>
<div><?= htmlspecialchars(trim(($devis['client_prenom'] ?? '') . ' ' . ($devis['client_nom'] ?? ''))) ?></div>
<?php elseif ($displayMode === 'company_only'): ?>
<div><?= htmlspecialchars($devis['entreprise'] ?? trim(($devis['client_prenom'] ?? '') . ' ' . ($devis['client_nom'] ?? ''))) ?></div>
<?php else: /* name_company */ ?>
<div><?= htmlspecialchars(trim(($devis['client_prenom'] ?? '') . ' ' . ($devis['client_nom'] ?? ''))) ?></div>
<div><?= htmlspecialchars($devis['entreprise'] ?? '') ?></div>
<?php endif; ?>
<?php if (!empty($devis['email']) && empty($infos_entreprise['hide_client_email_on_documents'])): ?><div><?= htmlspecialchars($devis['email'] ?? '') ?></div><?php endif; ?>
<?php if (!empty($devis['telephone']) && empty($infos_entreprise['hide_client_phone_on_documents'])): ?><div><?= htmlspecialchars($devis['telephone'] ?? '') ?></div><?php endif; ?>
<?php if (!empty($devis['rue'])): ?>
<div><?= htmlspecialchars($devis['rue'] ?? '') ?></div>
<?php endif; ?>
<?php if (!empty($devis['code_postal']) || !empty($devis['ville'])): ?>
<div><?= htmlspecialchars($devis['code_postal'] ?? '') ?> <?= htmlspecialchars($devis['ville'] ?? '') ?></div>
<?php if (!empty($devis['siret'])): ?>
<div>SIRET : <?= htmlspecialchars((string) $devis['siret']) ?></div>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
</div>
<!-- Corps du devis (à compléter avec autres champs) -->
<?php
$numeroDevis = $devis['numero'] ?? '';
if ($numeroDevis === '' || $numeroDevis === null) {
$fallbackYear = date('Y', strtotime($devis['date_devis'] ?? 'now'));
$prefix = isset($infos_gestion['prefixe_devis']) && $infos_gestion['prefixe_devis'] !== '' ? $infos_gestion['prefixe_devis'] : 'D-{year}-00';
$resolved = str_replace('{year}', $fallbackYear, $prefix);
$numeroDevis = $resolved . (string) ($devis['id'] ?? '');
}
?>
<h2 style="font-family:'Albert Sans',Arial,sans-serif;font-size:1.3em;margin:0 0 18px 0;">
Devis n°<?= htmlspecialchars((string) $numeroDevis) ?>
</h2>
<?php if (isset($signature_info) && is_array($signature_info) && !empty($signature_info['has_data']) && $signature_info['global_status'] !== 'none'): ?>
<div style="margin-bottom:10px;">
<?php
$global = $signature_info['global_status'];
$choice = $signature_info['last_client_choice'] ?? '';
$choiceLabel = '';
if ($choice === 'bank') {
$choiceLabel = ' (mode de paiement choisi : banque)';
} elseif ($choice === 'online') {
$choiceLabel = ' (mode de paiement choisi : en ligne)';
}
$dateSigned = $signature_info['last_signed_at'] ?? null;
$dateLabel = '';
if ($dateSigned) {
$ts = strtotime($dateSigned);
if ($ts) {
$dateLabel = ' le ' . date('d/m/Y H:i', $ts);
}
}
if ($global === 'signe') {
echo '<span style="display:inline-block;padding:4px 10px;border-radius:999px;background:#e8f7ee;color:#186a3b;font-size:0.9em;font-weight:600;">Devis signé'.$dateLabel.$choiceLabel.'</span>';
} elseif ($global === 'en_attente') {
$pending = (int) ($signature_info['pending_count'] ?? 0);
$label = 'Signature en attente';
if ($pending > 1) {
$label .= ' ('.$pending.' demandes)';
}
echo '<span style="display:inline-block;padding:4px 10px;border-radius:999px;background:#fff3cd;color:#856404;font-size:0.9em;font-weight:600;">'.$label.'</span>';
}
?>
</div>
<?php else: ?>
<div style="margin-bottom:18px;"></div>
<?php endif; ?>
<?php
// Affichage des lignes de devis :
// - Si on vient du formulaire (POST), on affiche les lignes du POST
// - Sinon, on affiche les lignes de la base
// Correction : utiliser $devis_lignes si présent (transmis par le contrôleur)
$lignes = $_POST['lignes'] ?? ($devis_lignes ?? null);
?>
<?php
?>
<div style="flex:1;display:flex;flex-direction:column;">
<?php if ($lignes && count($lignes)): ?>
<table style="width:100%;border-collapse:collapse;margin-bottom:18px;">
<thead>
<tr style="background:#f7f7f7;">
<th style="padding:6px;border:1px solid #e0e0e0;">Intitulé</th>
<th style="padding:6px;border:1px solid #e0e0e0;">Quantité</th>
<th style="padding:6px;border:1px solid #e0e0e0;">Prix unitaire HT</th>
<th style="padding:6px;border:1px solid #e0e0e0;">Remise</th>
<th style="padding:6px;border:1px solid #e0e0e0;">Type</th>
<th style="padding:6px;border:1px solid #e0e0e0;">Total</th>
</tr>
</thead>
<tbody>
<?php foreach ($lignes as $ligne): ?>
<tr>
<td><?= nl2br(htmlspecialchars((string)($ligne['intitule'] ?? ''))) ?></td>
<td style="text-align:right;"><?= htmlspecialchars($ligne['quantite']) ?></td>
<td style="text-align:right;"><?= number_format($ligne['prix_unitaire'], 2, ',', ' ') ?> €</td>
<td style="text-align:right;">
<?php
if (isset($ligne['remise']) && floatval($ligne['remise']) != 0) {
echo number_format($ligne['remise'], 2, ',', ' ');
} else {
echo '';
}
?>
</td>
<td>
<?php
if (isset($ligne['remise']) && floatval($ligne['remise']) != 0) {
echo (isset($ligne['type_remise']) && $ligne['type_remise'] === 'euro') ? '€' : '%';
} else {
echo '';
}
?>
</td>
<td style="text-align:right;">
<?php
$q = floatval($ligne['quantite'] ?? 1);
$pu = floatval($ligne['prix_unitaire'] ?? 0);
$rem = floatval($ligne['remise'] ?? 0);
$type_rem = $ligne['type_remise'] ?? 'euro';
$total_ligne = $q * $pu;
if ($type_rem === 'euro') {
$total_ligne -= $rem;
} else {
$total_ligne -= ($total_ligne * $rem / 100);
}
if ($total_ligne < 0) $total_ligne = 0;
echo number_format($total_ligne, 2, ',', ' ');
?> €
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<div style="color:#888;">Aucune ligne de devis</div>
<?php endif; ?>
<!-- Espace pour pousser le bas -->
<div style="flex:1 1 auto;"></div>
<!-- Bas de page : description, montants, mention -->
<div style="display: flex; flex-direction: row; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 18px;">
<div style="flex:1; max-width: 50%; min-width: 220px;">
<strong>Description :</strong><br>
<div style="background:#f7f7f7;padding:10px 14px;border-radius:7px;min-height:40px;max-width:480px;"> <?= nl2br(htmlspecialchars($devis['description'] ?? '')) ?> </div>
</div>
<div style="flex:1; max-width: 50%; min-width: 220px; display: flex; justify-content: flex-end;">
<div style="background: #f7f7f7; border-radius: 7px; padding: 18px 28px; min-width: 260px; text-align: right; border:1px solid #b0b4bb;">
<div style="font-weight: bold; font-size: 1.08em; margin-bottom: 8px;">Net à payer</div>
<?php
$montant_ht = $devis['montant'] ?? 0;
// On attend que le contrôleur passe $infos_gestion (tva_active, taux_tva)
$tva_active = !empty($infos_gestion['tva_active']);
$taux_tva = isset($infos_gestion['taux_tva']) ? floatval($infos_gestion['taux_tva']) : 20.00;
$montant_ttc = $tva_active ? ($montant_ht * (1 + $taux_tva / 100)) : $montant_ht;
$acompte_enabled = !empty($devis['acompte_enabled']);
$acompte_show_net_after = !empty($devis['acompte_show_net_after']);
$acompte_type = $devis['acompte_type'] ?? 'euro';
$acompte_valeur = max(0, (float) ($devis['acompte_valeur'] ?? 0));
$acompte_ht = 0.0;
if ($acompte_enabled) {
if ($acompte_type === 'pourcent') {
$acompte_ht = $montant_ht * $acompte_valeur / 100;
} else {
$acompte_ht = $acompte_valeur;
}
if ($acompte_ht > $montant_ht) {
$acompte_ht = $montant_ht;
}
}
$acompte_ttc = $tva_active ? ($acompte_ht * (1 + $taux_tva / 100)) : $acompte_ht;
$net_a_payer_ttc = max(0, $montant_ttc - $acompte_ttc);
?>
<div><strong>Montant HT :</strong> <?= number_format($montant_ht, 2, ',', ' ') ?> €</div>
<?php if ($tva_active): ?>
<div><strong>TVA (<?= number_format($taux_tva, 2, ',', ' ') ?>%) :</strong> <?= number_format($montant_ht * $taux_tva / 100, 2, ',', ' ') ?> €</div>
<div><strong>Montant TTC :</strong> <?= number_format($montant_ttc, 2, ',', ' ') ?> €</div>
<?php endif; ?>
<?php if ($acompte_enabled): ?>
<div><strong>Acompte <?= $acompte_type === 'pourcent' ? '(' . number_format($acompte_valeur, 2, ',', ' ') . '%)' : '' ?> :</strong> <?= number_format($acompte_ttc, 2, ',', ' ') ?> €</div>
<?php endif; ?>
<?php if (!empty($devis['montant_facture']) && floatval($devis['montant_facture']) > 0): ?>
<div><strong>Montant déjà facturé :</strong> <?= number_format($devis['montant_facture'], 2, ',', ' ') ?> €</div>
<?php endif; ?>
<?php if ($acompte_show_net_after): ?>
<div style="margin-top:8px;padding-top:8px;border-top:1px solid #d1d5db;"><strong>Total net à payer :</strong> <?= number_format($net_a_payer_ttc, 2, ',', ' ') ?> €</div>
<?php endif; ?>
</div>
</div>
</div>
<?php if (!empty($infos_entreprise['mention_devis'])): ?>
<div style="margin-top: 0; margin-bottom: 0; font-size: 0.98em; color: #444; text-align: center; width: 100%;">
<?= nl2br(htmlspecialchars($infos_entreprise['mention_devis'])) ?>
</div>
<?php endif; ?>
</div>
<!-- Les boutons sont désormais en haut, sticky -->
</div>