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

933 lines
48 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once('php/inc_start_time.php');
$strLangue = 'fr';
$strPage = 'commandes.php';
if (isset($_GET['p']))
$p = $_GET['p'];
else
$p = 'list';
$strAction = $p;
if (isset($_POST['frm_action'])) {
switch ($_POST['frm_action']) {
case 'mod-commande';
require_once('php/inc_functions.php');
require_once('php/inc_fx_messages.php');
require_once('../php/inc_fx_modifierinscriptions.php');
include_once('php/inc_fx_commandes.php');
fxModCommande($_POST['ach_id']);
break;
case 'maj-commande';
include_once('../php/inc_fonctions.php');
include_once('../php/inc_fx_panier.php');
global $objDatabase;
// forcer le 'receipt_text'
$sqlUpdate = "UPDATE inscriptions_panier_acheteurs SET pai_id = 5, receipt_text = 'APPROUVEE - MERCI', ach_error_log = 'Manuel via admin par " . $_SESSION['usa_info']['com_prenom'] . "' WHERE no_panier = '" . $_POST['no_panier'] . "'";
$qryUpdate = $objDatabase->fxQuery($sqlUpdate);
fxMajCommande($_POST['no_panier'], $_POST['lang']);
header('Location: ' . fxGetReferer());
exit;
break;
}
}
require_once('php/inc_functions.php');
require_once('php/inc_fx_messages.php');
include_once('php/inc_fx_commandes.php');
require_once('../php/inc_fx_memberships.php');
require_once('../php/inc_fx_code_qr.php');
require_once('../php/inc_fx_panier.php');
$vtexte_page = obtenirTextepage($strPage, $strLangue, 2);
// activer les erreurs
global $db;
if (!empty($_GET['pg']))
$page = $_GET['pg'];
else
$page = 1;
$nb = 100;
$start = $page * $nb - $nb;
include('inc_header.php');
?>
<div class="container-fluid" id="main">
<div class="row">
<div class="col-md-9 col-lg-10 order-first order-md-last">
<?php
$recCommandes = array();
switch ($p) {
case 'add':
case 'mod':
if ($p == 'mod') {
$sqlCommandes = "SELECT *, IF(a.com_id <> 0, (SELECT c.com_login FROM inscriptions_comptes c WHERE a.com_id = c.com_id), '') AS usager FROM inscriptions_panier_acheteurs a, inscriptions_panier_statuts s WHERE s.sta_id = a.sta_id AND a.ach_id = " . intval($_GET['ach_id']);
$recCommandes = $db->fxGetRow($sqlCommandes);
if ($recCommandes == null) {
header('Location: commandes.php');
exit;
}
}
$sqlStatuts = "SELECT sta_id, sta_nom_fr FROM inscriptions_panier_statuts WHERE sta_actif = 1 AND sta_id >= 1 ORDER BY sta_nom_fr";
$recStatuts = $db->fxGetResults($sqlStatuts);
$sqlProvinces = "SELECT pro_id, pro_nom_fr FROM inscriptions_provinces ORDER BY pro_nom_fr";
$recProvinces = $db->fxGetResults($sqlProvinces);
$sqlPays = "SELECT pay_id, pay_nom_fr FROM inscriptions_pays ORDER BY pay_nom_fr";
$recPays = $db->fxGetResults($sqlPays);
?>
<script type="text/javascript">
$().ready(function() {
$("#frm_commande").validate({
rules: {
com_prenom: "required",
com_nom: "required",
com_courriel: {
required: true,
email: true
},
com_adresse: "required",
com_ville: "required",
com_codepostal: "required",
com_telephone1: "required"
},
messages: {
com_prenom: "Veuillez entrer un prénom",
com_nom: "Veuillez entrer un nom de famille",
com_courriel: {
required: "Veuillez entrer un courriel",
email: "Le courriel doit être une adresse valide"
},
com_adresse: "Veuillez entrer une adresse",
com_ville: "Veuillez entrer une ville",
com_codepostal: "Veuillez entrer un code postal",
com_telephone1: "Veuillez entrer un numéro de téléphone"
}
});
$('#ach_date_statut_cal').datetimepicker({
format: 'YYYY-MM-DD',
locale: '<?php echo $strLangue; ?>-ca'
});
$('#btn_cancel_top, #btn_cancel_bot').click(function() {
document.location.href = 'commandes.php';
});
});
</script>
<h1><?php if ($p == 'add') { ?>Ajouter<?php } else { ?>Modifier<?php } ?> une commande</h1>
<?php
if (isset($_SESSION['msg']) && $_SESSION['msg'] != 0)
echo fxMessage($_SESSION['msg'], $strLangue);
if ($recCommandes['sta_id'] == 3 && $recCommandes['no_commande'] == '') {
?>
<form action="commandes.php?p=mod&amp;ach_id=<?php echo $_GET['ach_id']; ?>" method="post" name="statuts">
<input type="hidden" name="frm_action" value="maj-commande">
<input type="hidden" name="no_panier" value="<?php echo $recCommandes['no_panier']; ?>">
<div class="form-group row">
<label class="col-form-label col-sm-3" for="lang">Langue du courriel : </label>
<div class="col-sm-9 col-lg-7">
<select id="lang" name="lang" class="form-control rounded-0">
<option value="en">Anglais</option>
<option value="fr" selected="selected">Français</option>
</select>
</div>
</div>
<div class="form-group row">
<div class="col-sm-offset-3 col-sm-9 col-lg-7">
<button class="btn btn-danger rounded-0" type="submit" name="btn_statut">Marquer cette commande comme acceptée</button>
</div>
</div>
<div class="form-group row">
<div class="col-sm-offset-3 col-sm-9 col-lg-7">
Ceci ajoutera un numéro de commande et enverra le détails de la commande au client par courriel.
</div>
</div>
</form>
<?php
}
?>
<form action="commandes.php?p=mod&amp;ach_id=<?php echo $_GET['ach_id']; ?>" class="form-horizontal" method="post" id="frm_commande" name="frm_commande">
<div class="buttons">
<?php
if ($strAction == 'mod') {
?>
<button type="submit" class="btn btn-success rounded-0" id="btn_save_bot" name="btn_save_bot"><i class="fa fa-floppy-o" aria-hidden="true"></i>&nbsp;Enregistrer</button>
<?php
} else {
?>
<button type="submit" class="btn btn-success rounded-0" id="btn_add_bot" name="btn_add_bot"><i class="fa fa-floppy-o" aria-hidden="true"></i>&nbsp;Ajouter</button>
<?php
}
?>
<a class="btn btn-danger rounded-0" href="commandes.php"><i class="fa fa-times" aria-hidden="true"></i>&nbsp;Annuler</a>
</div>
<div class="clearer"><span></span></div>
<br />
<?php
if ($p == 'mod') {
?>
<input type="hidden" name="ach_id" value="<?php echo $_GET['ach_id']; ?>">
<?php
}
?>
<fieldset>
<input type="hidden" name="frm_action" value="mod-commande">
<legend>Détails de la commande</legend>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="com_prenom">Prénom :</label>
<div class="col-sm-9 col-lg-7">
<input type="text" id="com_prenom" name="com_prenom" value="<?php echo fxUnescape($recCommandes["com_prenom"]); ?>" size="40" maxlength="50" class="form-control rounded-0">
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="com_nom">Nom :</label>
<div class="col-sm-9 col-lg-7">
<input type="text" id="com_nom" name="com_nom" value="<?php echo fxUnescape($recCommandes["com_nom"]); ?>" size="40" maxlength="50" class="form-control rounded-0">
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="com_courriel">Courriel :</label>
<div class="col-sm-9 col-lg-7">
<input type="text" id="com_courriel" name="com_courriel" value="<?php echo fxUnescape($recCommandes["com_courriel"]); ?>" size="40" maxlength="50" class="form-control rounded-0">
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="com_telephone1">Téléphone :</label>
<div class="col-sm-9 col-lg-7">
<input type="text" id="com_telephone1" name="com_telephone1" value="<?php echo fxUnescape($recCommandes["com_telephone1"]); ?>" size="20" maxlength="20" class="form-control rounded-0">
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="com_telephone2">Cellulaire :</label>
<div class="col-sm-9 col-lg-7">
<input type="text" id="com_telephone2" name="com_telephone2" value="<?php echo fxUnescape($recCommandes["com_telephone2"]); ?>" size="20" maxlength="20" class="form-control rounded-0">
</div>
</div>
<br>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="com_adresse">Adresse :</label>
<div class="col-sm-9 col-lg-7">
<input type="text" id="com_adresse" name="com_adresse" value="<?php echo fxUnescape($recCommandes["com_adresse"]); ?>" size="40" maxlength="50" class="form-control rounded-0">
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="com_ville">Ville :</label>
<div class="col-sm-9 col-lg-7">
<input type="text" id="com_ville" name="com_ville" value="<?php echo fxUnescape($recCommandes["com_ville"]); ?>" size="40" maxlength="50" class="form-control rounded-0">
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="pro_id">Province :</label>
<div class="col-sm-9 col-lg-7">
<select id="pro_id" name="pro_id" class="form-control rounded-0">
<?php
for ($intCtr = 1; $intCtr <= count($recProvinces); $intCtr++) {
?>
<option value="<?php echo $recProvinces[$intCtr]['pro_id']; ?>" <?php if ($recProvinces[$intCtr]['pro_id'] == $recCommandes['pro_id']) { ?>selected<?php } ?>><?php echo $recProvinces[$intCtr]['pro_nom_fr']; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="pay_id">Pays :</label>
<div class="col-sm-9 col-lg-7">
<select id="pay_id" name="pay_id" class="form-control rounded-0">
<?php
for ($intCtr = 1; $intCtr <= count($recPays); $intCtr++) {
?>
<option value="<?php echo $recPays[$intCtr]['pay_id']; ?>" <?php if ($recPays[$intCtr]['pay_id'] == $recCommandes['pay_id']) { ?>selected<?php } ?>><?php echo $recPays[$intCtr]['pay_nom_fr']; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="com_codepostal">Code postal :</label>
<div class="col-sm-9 col-lg-7">
<input type="text" id="com_codepostal" name="com_codepostal" value="<?php echo fxUnescape($recCommandes["com_codepostal"]); ?>" size="20" maxlength="10" class="form-control rounded-0">
</div>
</div>
<br>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="sta_id">Statut de la commande :</label>
<div class="col-sm-9 col-lg-7">
<input type="hidden" name="sta_id_old" value="<?php echo $recCommandes['sta_id']; ?>">
<?php
if ($recCommandes['sta_id'] < 0) {
?>
<input type="hidden" name="sta_id" value="<?php echo $recCommandes['sta_id']; ?>">
<?php
echo $recCommandes['sta_nom_fr'];
} else {
?>
<select id="sta_id" name="sta_id" class="form-control rounded-0">
<?php
for ($intCtr = 1; $intCtr <= count($recStatuts); $intCtr++) {
?>
<option value="<?php echo $recStatuts[$intCtr]['sta_id']; ?>" <?php if ($recStatuts[$intCtr]['sta_id'] == $recCommandes['sta_id']) { ?>selected<?php } ?>><?php echo $recStatuts[$intCtr]['sta_nom_fr']; ?></option>
<?php
}
?>
</select>
<?php
}
?>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3">Statut changé le...</label>
<div class="col-sm-9 col-lg-7">
<p><?php if ($recCommandes['ach_date_statut'] != '') { echo fxShowDate($recCommandes['ach_date_statut'], 'fr') . ' @ ' . fxShowTime($recCommandes['ach_date_statut']); } else { ?>Jamais<?php } ?></p>
<br>
<?php
/*if ($recCommandes['ach_date_statut'] != '') {
?>
<div class="form-group row">
<label class="col-form-label col-12" for="ach_date_statut">Modifier cette date :</label>
<div class="col-12">
<div class="input-group" id='ach_date_statut_cal' data-target-input="nearest">
<input type="hidden" name="ach_date_statut_old" value="<?php echo date('Y-m-d', strtotime($recCommandes['ach_date_statut'])); ?>">
<input class="form-control rounded-0" type="text" id="ach_date_statut" name="ach_date_statut" maxlength="10" value="<?php echo date('Y-m-d', strtotime($recCommandes['ach_date_statut'])); ?>">
<div class="input-group-append rounded-0" data-target="#ach_date_statut_cal" data-toggle="datetimepicker">
<span class="input-group-text rounded-0">
<i class="fa fa-calendar"></i>
</span>
</div>
</div>
</div>
</div>
<?php
}*/
?>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3">Adresse ip:</label>
<div class="col-sm-9 col-lg-7">
<p><?php echo $recCommandes['ach_ip']; ?></p>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3">Log:</label>
<div class="col-sm-9 col-lg-7">
<p><span></span></p>
<br>
<div>
<pre>
<?php echo $recCommandes['ach_error_log']; ?>
</pre>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3">Compte client utilisé:</label>
<div class="col-sm-9 col-lg-7">
<p>
<?php
if (intval($recCommandes['com_id']) > 0) {
?>
<a href="index.php?t=Mg%3D%3D&a=mod&id=<?php echo fxUnescape($recCommandes['com_id']); ?>">
<?php echo fxUnescape($recCommandes['usager']); ?>
</a>
<?php
}
?>
</p>
</div>
</div>
</fieldset>
</form>
<p> </p>
<h3><img src="images_blue/ico_commandes_big.png" alt="">Détails de la commande</h3>
<?php
echo fxShowPanier($recCommandes['no_panier'], 0, 'web', 1, 'fr');
?>
<p>&nbsp;</p>
<h3><img src="images_blue/ico_commandes_big.png" alt="">PAYPAL</h3>
<?php
// ************************************************ rembourcement
/****************************************************
* Page: remboursement.php
* Rôle : affiche le formulaire de remboursement + prépare
* les variables serveur nécessaires au front (AJAX).
****************************************************/
// Démarrer la session
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
require_once $_SERVER["DOCUMENT_ROOT"] . "/superadm/php/inc_fx_paypal.php";
// Jeton anti double clic / re-soumission
if (empty($_SESSION['refund_token'])) {
$_SESSION['refund_token'] = bin2hex(random_bytes(16));
}
$refundToken = $_SESSION['refund_token'];
// Récupération des infos commande (présentes dans ton contexte)
$CAPTURE_ID = $recCommandes["TransactionID"] ?? null;
if (!isset($CAPTURE_ID) || !is_string($CAPTURE_ID) || $CAPTURE_ID === '') {
//echo '<div style="background:#feecec;border:1px solid #f2b8b5;padding:10px;border-radius:8px;">
// ⚠️ CAPTURE_ID non fourni côté serveur.
// </div>';
return;
}
// Charger ta classe PayPal
require_once '../paypal_advanced/PaypalCheckout.class.php';
$paypal = new PayPalCheckout(); // adapte si nécessaire
// Préparation
$errors = [];
$successMsg = null;
// Devise par défaut si jamais les détails PayPal nen donnent pas
$currencyUI = 'CAD';
// ====== Calculs initiaux côté serveur ======
// Solde dispo promoteur (ton helper existant)
$solde_dispo_ms1 = statut_payement($recCommandes["eve_id"]);
// Récupérer les détails PayPal de la capture
$paypaldetails = $paypal->paypaldetails($CAPTURE_ID);
// Harmoniser avec tes remboursements locaux si besoin
$paypaldetails = reconcileRefundsWithLocal($paypaldetails);
//print_rsl($paypaldetails);
// Déterminer le max remboursable PayPal
$max_remboursement_paypal = 0.0;
//print_rsl($paypaldetails);
// 1) S'il existe au moins un refund → on prend remaining (même si cest 0)
if (isset($paypaldetails['refunds']['totals']['remaining'])) {
$max_remboursement_paypal = (float)$paypaldetails['refunds']['totals']['remaining'];
}
// 2) Sinon → fallback : montant total capturé
else {
if (!empty($paypaldetails['details']['amount']['value'])) {
$max_remboursement_paypal = (float)$paypaldetails['details']['amount']['value'];
} elseif (!empty($paypaldetails['delails']['amount']['value'])) {
$max_remboursement_paypal = (float)$paypaldetails['delails']['amount']['value'];
}
}
// Déterminer la devise daffichage si fournie par PayPal
if (!empty($paypaldetails['refunds']['totals']['currency'])) {
$currencyUI = (string)$paypaldetails['refunds']['totals']['currency'];
} elseif (!empty($paypaldetails['details']['amount']['currency_code'])) {
$currencyUI = (string)$paypaldetails['details']['amount']['currency_code'];
} elseif (!empty($paypaldetails['delails']['amount']['currency_code'])) {
$currencyUI = (string)$paypaldetails['delails']['amount']['currency_code'];
}
// Frais MS1 (selon ta structure)
$frais_ms1 = (float)($recCommandes['fra_total'] ?? 0);
// Max remboursable à lécran (ta logique actuelle)
$maxUI = $max_remboursement_paypal - $frais_ms1;
// maxblock = limite stricte dinput côté front, selon ton choix actuel
if ($max_remboursement_paypal < $solde_dispo_ms1) {
$maxblock = $max_remboursement_paypal;
} else {
$maxblock = 0;
$maxUI = 0;
}
// ******************** variable info
//print_rsl($recCommandes);
echosl( "no_commande : ".$recCommandes["no_commande"]);
echosl( "rem_ajoute_par : ".$_SESSION["usa_info"]["com_prenom"]." ".$_SESSION["usa_info"]["com_nom"]);
echosl( "eve_id : ".$recCommandes["eve_id"]) ;
echosl( "Montant remboursable : " . number_format($max_remboursement_paypal, 2) . " " . ($result['refunds']['totals']['currency'] ?? $result['delails']['amount']['currency_code'] ?? ''));
echo("solde dispo ms1 :");
echosl($solde_dispo_ms1);
echo("frais ms1 :");
$frais_ms1=$recCommandes['fra_total'];
echosl($frais_ms1);
echo("max Remboursement :");
// $maxUI le max Remboursement si on veux pas renbourcer les frais ms1
// $maxUI=$max_remboursement_paypal-$frais_ms1;
// $maxUI le max Remboursement
$maxUI=$max_remboursement_paypal;
echosl($maxUI);
$maxproposer = max(0, $maxUI - $frais_ms1);
// Helpers UI
?>
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Remboursement PayPal</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body style="font-family:system-ui,Arial,Helvetica;">
<div style="max-width:560px;border:1px solid #ddd;border-radius:10px;padding:14px;">
<div style="font-weight:700;font-size:16px;margin-bottom:8px;">Remboursement PayPal (Checkout)</div>
<!-- Zone messages AJAX -->
<div id="refund-msg" style="margin-bottom:10px;display:none;padding:10px;border-radius:8px;"></div>
<?php if ($maxUI > 0): ?>
<div style="background:#f9fbff;border:1px solid #dbe7ff;padding:10px;border-radius:8px;margin-bottom:10px;">
<div><strong>Capture:</strong> <?= h($CAPTURE_ID) ?></div>
<div><strong>Max remboursable (affiché):</strong> <span id="pp_ref_max"><?= h(money2($maxUI)) ?></span> <?= h($currencyUI) ?></div>
</div>
<form id="refund-form" method="post" style="display:grid;grid-template-columns:1fr 1fr;gap:10px;">
<input type="hidden" name="refund_token" value="<?= h($refundToken) ?>">
<input type="hidden" name="capture_id" value="<?= h($CAPTURE_ID) ?>">
<input type="hidden" name="currency" value="<?= h($currencyUI) ?>">
<input type="hidden" name="eve_id" value="<?= h($recCommandes["eve_id"]) ?>">
<input type="hidden" name="no_commande" value="<?= h($recCommandes["no_commande"]) ?>">
<div style="grid-column:1/2;">
<label style="display:block;font-size:12px;color:#333;margin-bottom:4px;">
Montant à rembourser (<?= h($currencyUI) ?>)
</label>
<input id="pp_ref_amount" type="number" name="refund_amount" step="0.01" min="0.01"
max="<?= h(money2($maxblock)) ?>"
value="<?= h(money2($maxproposer)) ?>"
style="width:100%;padding:8px;border:1px solid #ccc;border-radius:8px;">
</div>
<div style="grid-column:2/3;">
<label style="display:block;font-size:12px;color:#333;margin-bottom:4px;">Note (optionnelle)</label>
<input type="text" name="refund_note" placeholder="Raison du remboursement"
style="width:100%;padding:8px;border:1px solid #ccc;border-radius:8px;">
</div>
<div style="grid-column:1/3;text-align:right;margin-top:6px;">
<button type="submit"
style="padding:10px 14px;border:1px solid #2d6cdf;border-radius:8px;background:#2d6cdf;color:#fff;cursor:pointer;">
Rembourser
</button>
</div>
</form>
<?php else: ?>
<div style="background:#fff8e6;border:1px solid #ffe1a6;padding:10px;border-radius:8px;">
Aucun montant remboursable pour cette capture.
</div>
<?php endif; ?>
</div>
<script>
// Petit helper visuel
function showMsg(text, ok) {
const box = document.getElementById('refund-msg');
box.style.display = 'block';
box.style.background = ok ? '#e9f8ef' : '#feecec';
box.style.border = ok ? '1px solid #b8e3c5' : '1px solid #f2b8b5';
box.innerText = text;
}
document.getElementById('refund-form')?.addEventListener('submit', async (e) => {
e.preventDefault();
showMsg('⏳ Traitement en cours...', false);
const data = new FormData(e.target);
const res = await fetch( '<?php echo $vDomaine; ?>/superadm/ajax_refund.php', { method: 'POST', body: data });
// Défensif
if (!res.ok) {
showMsg('⚠️ Erreur réseau pendant le remboursement.', false);
return;
}
let json;
try { json = await res.json(); } catch (_) {
showMsg('⚠️ Réponse invalide du serveur.', false);
return;
}
if (json.success) {
showMsg('✅ ' + (json.message || 'Remboursement effectué.'), true);
// 👉 Ici, tu peux déclencher des actions UI :
// - recharger une grille des remboursements
// - rafraîchir un solde
// - etc.
// refreshTableRemboursements();
} else {
showMsg('⚠️ ' + (json.message || 'Erreur remboursement.'), false);
}
});
</script>
</body>
</html>
<h3><img src="images_blue/ico_commandes_big.png" alt="">Détails PAYPAL</h3>
<?php
// $sortie=paypaldetails($recCommandes["TransactionID"]);
echo(renderPayPalCaptureHtml($paypaldetails));
break;
case 'list';
default:
// afficher pagination
$tabQuery = $_GET;
unset($tabQuery['pg']);
$strQueryPager = http_build_query($tabQuery, '', '&amp;');
$limit = " LIMIT $start, $nb";
$where = '';
$group = 0;
if (!empty($_GET['w'])) {
$where .= " AND a.sta_id = " . intval($_GET['w']);
}
if (!empty($_GET['eve_id'])) {
$where .= " AND a.eve_id = " . intval($_GET['eve_id']);
}
if (isset($_GET['btn_search'])) {
$group = 1;
}
if (!empty($_GET['TrasactionID'])) {
$where .= " AND a.trx_id LIKE '%" . $db->fxEscape($_GET['TrasactionID']) . "%'";
}
if (!empty($_GET['txt_commande'])) {
$where .= " AND a.no_commande LIKE '%" . $db->fxEscape($_GET['txt_commande']) . "%'";
$group = 0;
}
if (!empty($_GET['txt_no_panier'])) {
$where .= " AND a.no_panier LIKE '%" . $db->fxEscape($_GET['txt_no_panier']) . "%'";
$group = 0;
}
if (!empty($_GET['txt_prenom'])) {
$where .= " AND a.com_prenom LIKE '%" . $db->fxEscape($_GET['txt_prenom']) . "%'";
}
if (!empty($_GET['txt_nom'])) {
$where .= " AND a.com_nom LIKE '%" . $db->fxEscape($_GET['txt_nom']) . "%'";
}
if (!empty($_GET['txt_courriel'])) {
$where .= " AND a.com_courriel LIKE '%" . $db->fxEscape($_GET['txt_courriel']) . "%'";
}
if (!empty($_GET['TransactionID'])) {
$where .= " AND a.TransactionID LIKE '%" . $db->fxEscape($_GET['TransactionID']) . "%'";
}
if ($group == 1){
//$group = " GROUP BY a.no_commande";
$group = '';}
else{
$group = '';}
$sqlCommandes = "SELECT SQL_CALC_FOUND_ROWS (SELECT e.eve_nom_fr FROM inscriptions_evenements e WHERE e.eve_id = a.eve_id) AS evenement,a.ach_id, a.no_commande, a.TransactionID, a.com_prenom, a.com_nom, a.com_courriel, a.no_panier, a.ach_maj, s.sta_id, s.sta_nom_fr, a.ach_total, a.pai_id, a.ach_lang, a.com_id, IF(a.com_id <> 0, (SELECT c.com_login FROM inscriptions_comptes c WHERE a.com_id = c.com_id), '') AS usager,a.paypal_source,a.paypal_card_brand,a.paypal_card_last_digits FROM inscriptions_panier_acheteurs a, inscriptions_panier_statuts s WHERE s.sta_id = a.sta_id $where $group ORDER BY a.ach_maj DESC, a.no_commande DESC";
$sqlCommandes .= $limit;
$recCommandes = $db->fxGetResults($sqlCommandes);
$nbTotal = $db->fxGetVar("SELECT FOUND_ROWS()");
//$nbTotal = 10000;
$sqlStatuts = "SELECT sta_id, sta_nom_fr FROM inscriptions_panier_statuts WHERE sta_actif = 1 ORDER BY sta_nom_fr";
$recStatuts = $db->fxGetResults($sqlStatuts);
$sqlEvenements = "SELECT eve_id, eve_nom_fr FROM inscriptions_evenements WHERE DATE_SUB(CURDATE(),INTERVAL 3 MONTH) <= eve_date_fin ORDER BY eve_nom_fr";
$recEvenements = $db->fxGetResults($sqlEvenements);
?>
<h1>Liste des commandes</h1>
<?php
/*if (isset($_SESSION['msg']) && $_SESSION['msg'] != 0)
echo fxMessage($_SESSION['msg'], $strLangue);*/
?>
<ul class="nav nav-pills">
<?php
unset($tabQuery['w']);
$strQuery = http_build_query($tabQuery, '', '&amp;');
for ($intCtr = 1; $intCtr <= count($recStatuts); $intCtr++) {
?>
<li class="nav-item" role="presentation">
<a class="nav-link<?php if (isset($_GET['w']) && $recStatuts[$intCtr]['sta_id'] == $_GET['w']) { ?> active<?php } ?>" href="commandes.php?<?php echo $strQuery; ?>&amp;w=<?php echo $recStatuts[$intCtr]['sta_id']; ?>"><?php echo $recStatuts[$intCtr]['sta_nom_fr']; ?></a>
</li>
<?php
}
?>
<li class="nav-item" role="presentation">
<a class="nav-link<?php if (empty($_GET['w'])) { ?> active<?php } ?>" href="commandes.php?<?php echo $strQuery; ?>">Toutes les commandes</a>
</li>
</ul>
<br>
<div id="recherche">
<form action="commandes.php?<?php echo $strQuery; ?>" class="form-horizontal" method="get" id="frm_search" name="frm_search">
<fieldset>
<legend>Rechercher une commande</legend>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="TransactionID">TransactionID (PayPal) :</label>
<div class="col-sm-9 col-lg-7">
<input type="text" id="TransactionID" name="TransactionID" value="<?php if (isset($_GET['TransactionID'])) { echo $_GET['TransactionID']; } ?>" size="10" maxlength="20" class="form-control rounded-0">
</div>
</div>
<div class="form-group row">
<label class="form-label col-sm-3" for="txt_commande">No commande :</label>
<div class="col-sm-9 col-lg-7">
<input type="text" id="txt_commande" name="txt_commande" value="<?php if (isset($_GET['txt_commande'])) { echo $_GET['txt_commande']; } ?>" size="10" maxlength="20" class="form-control rounded-0">
</div>
</div>
<div class="form-group row">
<label class="form-label col-sm-3" for="txt_no_panier">No panier :</label>
<div class="col-sm-9 col-lg-7">
<input type="text" id="txt_no_panier" name="txt_no_panier" value="<?php if (isset($_GET['txt_no_panier'])) { echo $_GET['txt_no_panier']; } ?>" size="10" maxlength="20" class="form-control rounded-0">
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="txt_prenom">Prénom :</label>
<div class="col-sm-9 col-lg-7">
<input type="text" id="txt_prenom" name="txt_prenom" value="<?php if (isset($_GET['txt_prenom'])) { echo $_GET['txt_prenom']; } ?>" size="30" maxlength="50" class="form-control rounded-0">
</div>
</div>
<div class="form-group row">*
<label class="col-form-label col-sm-3" for="txt_nom">Nom :</label>
<div class="col-sm-9 col-lg-7">
<input type="text" id="txt_nom" name="txt_nom" value="<?php if (isset($_GET['txt_nom'])) { echo $_GET['txt_nom']; } ?>" size="30" maxlength="50" class="form-control rounded-0">
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="txt_courriel">Courriel :</label>
<div class="col-sm-9 col-lg-7">
<input tye="text" id="txt_courriel" name="txt_courriel" value="<?php if (isset($_GET['txt_courriel'])) { echo $_GET['txt_courriel']; } ?>" size="40" maxlength="50" class="form-control rounded-0">
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-3" for="eve_id">Événement :</label>
<div class="col-sm-9 col-lg-7">
<select id="eve_id" name="eve_id" class="form-control rounded-0">
<option value=""<?php if ((isset($_GET['btn_search']) && $_GET['eve_id'] == '') || !isset($_GET['btn_search'])) { ?> selected="selected"<?php } ?>>Tous les événements</option>
<?php
for ($intCtr = 1; $intCtr <= count($recEvenements); $intCtr++) {
?>
<option value="<?php echo fxUnescape($recEvenements[$intCtr]['eve_id']); ?>"<?php if (isset($_GET['btn_search']) && isset($_GET['eve_id']) && $_GET['eve_id'] === $recEvenements[$intCtr]['eve_id']) { ?> selected="selected"<?php } ?>><?php echo fxUnescape($recEvenements[$intCtr]['eve_nom_fr']); ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group row">
<div class="col-sm-9 col-lg-7 offset-sm-3">
<button class="btn btn-primary rounded-0" type="submit" id="btn_search" name="btn_search"><i class="fa fa-search" aria-hidden="true"></i>&nbsp;Rechercher</button>
<?php
if (isset($_GET['btn_psearch']) || isset($_GET['w'])) {
?>
<a class="btn btn-danger rounded-0" href="commandes.php?p=list"><i class="fa fa-times" aria-hidden="true"></i>&nbsp;<?php if ($strLangue == 'fr') { ?>Effacer rechercher<?php } else { ?>Remove search<?php } ?></a>
<?php
}
?>
</div>
</div>
</fieldset>
</form>
</div>
<div class="table-responsive">
<table class="table table-striped">
<?php
if (count((array)$recCommandes) > 0) {
?>
<thead>
<tr>
<th style="text-align: center;">#</th>
<th style="text-align: left;">No commande</th>
<th style="text-align: left;">No panier</th>
<th style="text-align: left;">Nom, Prénom</th>
<th style="text-align: left;">Statut</th>
<th style="text-align: left;">TransactionID</th>
<th style="text-align: left;">Date de création</th>
<th style="text-align: left;">courriel</th>
<th style="text-align: right;">total</th>
<th>&nbsp;</th>
<th style="text-align: left;">usager</th>
<th style="text-align: left;">paiement</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<?php
for ($intCtr = 1; $intCtr <= count((array)$recCommandes); $intCtr++) {
?>
<tr <?php if ($intCtr % 2) { ?>class="ligne_paire"<?php } ?>>
<td style="text-align: center;"><?php echo $intCtr + $start; ?></td>
<td style="text-align: left;"><a href="commandes.php?p=mod&amp;ach_id=<?php echo $recCommandes[$intCtr]['ach_id']; ?>"><?php echo $recCommandes[$intCtr]['no_commande']; ?></a></td>
<td style="text-align: left;"><a href="commandes.php?p=mod&amp;ach_id=<?php echo $recCommandes[$intCtr]['ach_id']; ?>"><?php echo $recCommandes[$intCtr]['no_panier']; ?></a></td>
<td style="text-align: left;"><?php echo fxUnescape($recCommandes[$intCtr]['com_nom']) . ', ' . fxUnescape($recCommandes[$intCtr]['com_prenom']); ?></td>
<td style="text-align: center;">
<div id="statut_<?php echo fxUnescape($recCommandes[$intCtr]['ach_id']); ?>">
<div>
<?php echo fxUnescape($recCommandes[$intCtr]['sta_nom_fr']); ?>
</div>
<?php
if (intval($recCommandes[$intCtr]['sta_id']) == 3) {
?>
<button class="btn btn-danger rounded-0 btn_update_statut" data-ach_id="<?php echo fxUnescape($recCommandes[$intCtr]['ach_id']); ?>" type="button"><i class="fa fa-times-circle mr-2" aria-hidden="true" data-toggle="tooltip" title="Annuler/Rembourser"></i>A/R</button>
<?php
}
?>
</div>
</td>
<td style="text-align: left;"><?php echo fxUnescape($recCommandes[$intCtr]['TransactionID']); ?></td>
<td style="text-align: left;"><?php echo fxShowDate($recCommandes[$intCtr]['ach_maj'], 'fr') . ' @ ' . fxShowTime($recCommandes[$intCtr]['ach_maj']); ?></td>
<td style="text-align: left;"><?php echo fxUnescape($recCommandes[$intCtr]['com_courriel']); ?></td>
<td style="text-align: right;">
<?php
if ($recCommandes[$intCtr]['pai_id'] < 6) {
echo fxShowPrix($recCommandes[$intCtr]['ach_total'], 'fr', 1);
} else {
echo fxShowPrix(0, 'fr', 1);
}
?>
</td>
<td style="text-align: left;"><?php echo fxUnescape($recCommandes[$intCtr]['evenement']); ?></td>
<td style="text-align: left;">
<?php
if (intval($recCommandes[$intCtr]['com_id']) > 0) {
?>
<a href="index.php?t=Mg%3D%3D&a=mod&id=<?php echo fxUnescape($recCommandes[$intCtr]['com_id']); ?>">
<?php echo fxUnescape($recCommandes[$intCtr]['usager']); ?>
</a>
<?php
}
?>
</td>
<td style="text-align: center;"><?php echo $recCommandes[$intCtr]['paypal_source']." ".$recCommandes[$intCtr]['paypal_card_brand']." ".$recCommandes[$intCtr]['paypal_card_last_digits'];?>
</td>
<td style="text-align: center;"><?php if ($recCommandes[$intCtr]['sta_id'] > 1) { ?><a href="../facture.php?no_panier=<?php echo $recCommandes[$intCtr]['no_panier']; ?>" target="_blank">facture</a><?php } else { ?>&nbsp;<?php } ?></td>
<td style="text-align: center;">
<?php
if ($recCommandes[$intCtr]['sta_id'] == 3) {
?>
<a class="btn btn-secondary link_confirmation" href="#" data-no_panier="<?php echo $recCommandes[$intCtr]['no_panier']; ?>" data-no_commande="<?php echo $recCommandes[$intCtr]['no_commande']; ?>" data-lng="<?php echo $recCommandes[$intCtr]['ach_lang']; ?>">renvoyer confirmation</a>
<?php
} else {
?>
&nbsp;
<?php
}
?>
</td>
</tr>
<?php
}
?>
</tbody>
<?php /* <tr>
<th colspan="5"><?php if ($page != 1) { ?><a href="?page=<?php echo $page - 1; ?>">&laquo; précédent</a><?php } ?></th>
<th>&nbsp;</th>
<th colspan="6" style="text-align: right;"><a href="?page=<?php echo $page + 1; ?>">suivant &raquo;</a></th>
</tr>
<?php */
} else {
?>
<tr>
<td style="text-align: center;">
<p>&nbsp;</p>
<strong>Il n'y a aucune commande pour le moment.</strong>
<p>&nbsp;</p>
</td>
</tr>
<?php
}
?>
</table>
</div>
<p>&nbsp;</p>
<?php
if (count((array)$recCommandes) > 0) {
echo fxShowPaging('commandes.php?' . $strQueryPager, $nbTotal, $nb, $page);
}
}
?>
<p>&nbsp;</p>
</div>
<?php require_once('inc_droite.php'); ?>
</div>
</div>
<script type="text/javascript">
$('body').on("click", ".link_confirmation", function() {
var $no_panier = $(this).data('no_panier');
var $no_commande = $(this).data('no_commande');
var $lng = $(this).data('lng');
bootbox.dialog({
message: "Êtes-vous certain de vouloir envoyer la confirmation de la commande " + $no_commande +"?",
title: "Question",
buttons: {
success: {
label: "Oui",
className: "btn-success",
callback: function() {
$.post('<?php echo $vDomaine; ?>/ajax_confirmation.php', 'no_panier=' + $no_panier + '&lng=' + $lng, function ($result) {
alert($result.state);
}, 'json');
}
},
danger: {
label: "Non",
className: "btn-danger"
}
}
});
return false;
});
</script>
<?php require_once('inc_footer.php');