Files
ms1inscription-v5/superadm/maj_rapports.php
2026-05-13 09:43:32 -04:00

69 lines
4.8 KiB
PHP
Raw Blame History

<?php
require_once 'php/inc_functions.php';
require_once '../php/inc_fx_panier.php';
$tabOutput = array();
// Trouver les commandes de l'<27>v<EFBFBD>nement 102
$sqlCommandes = "SELECT no_commande, no_panier FROM inscriptions_panier_acheteurs WHERE sta_id = 3 ORDER BY no_commande DESC, ach_maj DESC";
$tabCommandes = $db->fxGetResults($sqlCommandes);
if ($tabCommandes != null) {
for ($intCtr = 1; $intCtr <= count($tabCommandes); $intCtr++) {
$tabOutput[] = $tabCommandes[$intCtr];
$tabTotal = fxTotalPanier($tabCommandes[$intCtr]['no_panier'], 'fr');
// update
$sqlUpdate = "UPDATE inscriptions_panier_acheteurs SET depot_total = " . floatval($tabTotal['depot_total']) . ", rabais_total = " . floatval($tabTotal['rabais_total']) . " WHERE no_panier = '" . $tabCommandes[$intCtr]['no_panier'] . "'";
$qryUpadte = $GLOBALS['db']->fxQuery($sqlUpdate);
// Boucler parmi les rabais
$sqlRabais = "SELECT r.pra_id, a.prac_id, r.rab_montant, r.rab_pourcent, r.rab_epreuves, r.rab_produits FROM inscriptions_panier_rabais r, inscriptions_panier_rabais_acheteurs a WHERE a.pra_id = r.pra_id AND r.pra_depot = 0 AND a.no_panier = '" . $GLOBALS['db']->fxEscape($tabCommandes[$intCtr]['no_panier']) . "' ORDER BY r.rab_priorite, r.rab_code, r.pra_maj";
$tabRabais = $GLOBALS['db']->fxGetResults($sqlRabais);
if ($tabRabais != null) {
foreach ($tabRabais as $tab) {
if ($tab['rab_montant'] > 0)
$fltRabais = $tab['rab_montant'];
else {
if ($tab['rab_epreuves'] != '' || $tab['rab_produits'] != '') {
// Calculer le rabais
$sqlMontant = "
SELECT
(SELECT COALESCE(SUM(rab_montant), 0) FROM inscriptions_panier_epreuves_commandees WHERE pra_id = " . intval($tab['pra_id']) . " AND no_panier = '" . $GLOBALS['db']->fxEscape($tabCommandes[$intCtr]['no_panier']) . "') +
(SELECT COALESCE(SUM(rab_montant), 0) FROM inscriptions_panier_produits_new WHERE pra_id = " . intval($tab['pra_id']) . " AND no_panier = '" . $GLOBALS['db']->fxEscape($tabCommandes[$intCtr]['no_panier']) . "') AS rabais
FROM DUAL
";
$fltRabais = $GLOBALS['db']->fxGetVar($sqlMontant);
}
else {
// Calculer le rabais
$sqlPourcent = "
SELECT
(
(
(SELECT COALESCE(SUM(pec_prix), 0) FROM inscriptions_panier_epreuves_commandees WHERE no_panier = '" . $GLOBALS['db']->fxEscape($_SESSION['no_panier']) . "') +
(SELECT COALESCE(SUM(pro_prix), 0) FROM inscriptions_panier_produits_new WHERE no_panier = '" . $GLOBALS['db']->fxEscape($_SESSION['no_panier']) . "') +
(SELECT COALESCE(SUM(md_montant), 0) FROM inscriptions_panier_montants_dus WHERE no_panier = '" . $GLOBALS['db']->fxEscape($_SESSION['no_panier']) . "')
) -
(
(SELECT COALESCE(SUM(e.rab_montant), 0) FROM inscriptions_panier_epreuves_commandees e, inscriptions_panier_rabais r WHERE r.pra_id = e.pra_id AND r.pra_depot = 0 AND e.no_panier = '" . $GLOBALS['db']->fxEscape($_SESSION['no_panier']) . "') +
(SELECT COALESCE(SUM(p.rab_montant), 0) FROM inscriptions_panier_produits_new p, inscriptions_panier_rabais r WHERE r.pra_id = p.pra_id AND r.pra_depot = 0 AND p.no_panier = '" . $GLOBALS['db']->fxEscape($_SESSION['no_panier']) . "') +
(SELECT COALESCE(SUM(r.rab_montant), 0) FROM inscriptions_panier_rabais r, inscriptions_panier_rabais_acheteurs a WHERE r.pra_id = a.pra_id AND r.pra_depot = 0 AND a.no_panier = '" . $GLOBALS['db']->fxEscape($_SESSION['no_panier']) . "' AND r.rab_pourcent = 0 AND r.rab_epreuves = '' AND r.rab_produits = '')
)
) *
((SELECT COALESCE(SUM(rab_pourcent), 0) FROM inscriptions_panier_rabais WHERE pra_id = " . intval($tab['pra_id']) . ") / 100)
FROM DUAL
";
$fltRabais = $GLOBALS['db']->fxGetVar($sqlPourcent);
}
}
// update
$sqlUpdate = "UPDATE inscriptions_panier_rabais_acheteurs SET rab_montant = " . floatval($fltRabais) . " WHERE prac_id = " . intval($tab['prac_id']);
$qryUpadte = $GLOBALS['db']->fxQuery($sqlUpdate);
}
}
}
}