1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| <?phprequire_once 'connexion.php';
//On vérifie si la variable existe et sinon elle vaut NULL
$num = isset($_POST['num']) ? $_POST['num'] : NULL;
$client = isset($_POST['client']) ? $_POST['client'] : NULL;
$designation = isset($_POST['designation']) ? $_POST['designation'] : NULL;
$quantite = isset($_POST['quantite']) ? $_POST['quantite'] : NULL;
$prixht = isset($_POST['prixht']) ? $_POST['prixht'] : NULL;
$datefacture = isset($_POST['datefacture']) ? $_POST['datefacture'] : NULL;
$facturede = isset($_POST['facturede']) ? $_POST['facturede'] : NULL;
$conditions = isset($_POST['conditions']) ? $_POST['conditions'] : NULL;
//var_dump($_POST);
// generate request params
$params = [];
$values = '';
$facturation = [];
foreach ($_POST['designation'] as $key => $designation) {
$params[':designation' . $key] = $designation;
$params[':num' . $key] = $_POST['num'];
$params[':client' . $key] = $_POST['client'];
$params[':quantite' . $key] = $_POST['quantite'][$key];
$params[':prixht' . $key] = $_POST['prixht'][$key];
$params[':datefacture' . $key] = $_POST['datefacture'];
$params[':facturede' . $key] = $_POST['facturede'];
$params[':conditions' . $key] = $_POST['conditions'];
$values1 .= '(:num' . $key . ' , :client' . $key . ', :datefacture' . $key . ', :facturede' . $key . ', :conditions' . $key . '),';
// prepare facturation data
$facturation[] = [
'designation' => $designation,
'num' => $_POST['num'][$key],
'client' => $_POST['client'][$key],
'quantite' => $_POST['quantite'][$key],
'prixht' => $_POST['prixht'][$key],
'datefacture' => $_POST['datefacture'][$key],
'facturede' => $_POST['facturede'][$key],
'conditions' => $_POST['conditions'][$key]
];
}
//var_dump($_POST['num'][$key]);
// remove trailing ","
$values1 = rtrim($values1, ',');
$req1 = $base->prepare('INSERT INTO infosfacture (num, client, datefacture, facturede, conditions) VALUES '. $values1);
//$sql= $base->prepare('SELECT id FROM infosfacture WHERE id='.$fk)
$values2 .= '(:designation' . $key . ', :quantite' . $key . ', :prixht' . $key . ', LAST_INSERT_ID()),';
$values2 = rtrim($values2, ',');
$req2 = $base->prepare('INSERT INTO facturation (designation, quantite, prixht) VALUES '. $values2);
BEGIN;
$req1->execute($params);
$req2->execute($params);
COMMIT;
$base = null;
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Afficher une Facture</title>
<link rel="stylesheet" href="style.css" media="all" />
<link rel="icon" type="image/png" href="favicon.png" />
</head>
<body>
<header class="clearfix">
<div id="logo">
<img src="logo.png">
</div>
<div id="company">
<div class="to"><h2>De:</h2> <?php echo $facturede ?></div>
</div>
</header>
<main>
<div id="details" class="clearfix">
<div id="client">
<div class="to"><h2>Facture à:</h2><?php echo $client ?></div>
</div>
<div id="invoice">
<h1>FACTURE N° <?php echo $num ?></h1>
<div class="date">Date: <?php echo $datefacture ?></div>
</div>
</div>
<?php
// echo '<pre>';
// print_r($_POST['num'][$key]);
// echo '</pre>';
?>
<table>
<thead>
<tr>
<th class="desc">DESIGNATION</th>
<th class="qty">QUANTITÉ</th>
<th class="unit">PRIX HT</th>
<th class="total">Total HT</th>
</tr>
</thead>
<tbody>
<?php foreach ($facturation as $presta) : ?>
<tr>
<td class="desc"><?= $presta['designation'] ?></td>
<td class="qty"><?= $presta['quantite'] ?></td>
<td class="unit"><?= $presta['prixht'] ?></td>
<td class="total"><?= $presta['prixht'] * $presta['quantite'] ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div id="notices">
<div><h2>Conditions et moyens de paiement:</h2></div>
<div class="notice"> <?php echo $conditions ?> </div>
</div>
<?= '<a href="facturesPDF/imprimer.php?num='.$num.'" target="_blank">Imprimer</a>' ?>
</main>
<?php require_once('includes/footer.php') ?>
</body>
</html> |
Partager