<?php use App\Core\Csrf;$errors=$_SESSION['form_errors']??[];unset($_SESSION['form_errors']);?>
<link rel="stylesheet" href="/public/assets/css/cda-billing-959.css"><main class="billing"><a class="back" href="/public/facturation">← Retour à la facturation</a><h1>Nouveau document</h1><?php foreach($errors as $e):?><p class="alert"><?=htmlspecialchars($e)?></p><?php endforeach?><form method="post" action="/public/facturation" id="invoice-form"><input type="hidden" name="_csrf" value="<?=Csrf::token()?>"><div class="panel grid"><label>Type<select name="document_type"><option value="invoice">Facture</option><option value="proforma">Pro forma</option></select></label><label>Adhérent / compte client<select name="client_id" required><option value="">Choisir…</option><?php foreach($clients as $c):?><option value="<?=$c['id']?>"><?=htmlspecialchars($c['code_client'].' — '.$c['nom'].' '.$c['prenom'])?></option><?php endforeach?></select></label></div><div id="lines"><div class="line"><label>Libellé<input name="description[]" required></label><label>Pôle / projet<select name="assignment_id[]" required><?php foreach($assignments as $a):?><option value="<?=$a['id']?>"><?=htmlspecialchars($a['label'].' — '.$a['revenue_account'])?></option><?php endforeach?></select></label><label>Qté<input type="number" step="0.01" min="0.01" name="quantity[]" value="1"></label><label>Prix unitaire<input type="number" step="0.01" name="unit_price[]" required></label><label>Réduction affectée<input type="number" step="0.01" min="0" name="discount[]" value="0"></label><label>Répartition<select name="allocation_mode[]"><option value="current_year">100 % année de facture</option><option value="period">Prorata sur la période</option></select></label><label>Début prestation<input type="date" name="service_start[]"></label><label>Fin prestation<input type="date" name="service_end[]"></label><button type="button" class="remove">Retirer</button></div></div><p><button type="button" class="btn secondary" id="add-line">+ Ajouter une ligne</button></p><button class="btn">Enregistrer le brouillon</button></form></main><script src="/public/assets/js/cda-billing-959.js"></script>
