Debug function getClientComplementDuAtDate avec prise en charge des complements avt saisie

Table hover dans les formulaires livraisons
Groupement des paniers d'un même client dans la feuille d'émargement
This commit is contained in:
Adrien RENARD 2024-02-01 18:11:56 +01:00
parent 23ed75e434
commit 415d04537d
10 changed files with 106 additions and 35 deletions

View File

@ -141,6 +141,25 @@ function getClientAbsences($id) { return getClientAbsencesList("fin", "DESC", $i
function getClientComplementDuAtDate($id, $date) {
$val = 0;
// CONTRATS
$sql = "SELECT"
." CASE WHEN ISNULL(`complement_avt_saisie`)"
." THEN 0.0"
." ELSE `complement_avt_saisie`"
." END as 'complement_avt_saisie'"
." FROM ".CONTRATS_TABLE
." WHERE `client`=".intval($id)
." AND `date`<'".$date."'";
$r = $GLOBALS['db_admin']['man']->select($sql,1);
if(!$r['erreur']) $val += floatval($r['datas']['complement_avt_saisie']);
else {
$er = "</br>sql: ".$sql."</br>error: ".getReadableVar($r['erreur']);
return "Une erreur est survenue durant la récupération du complement dû par le client dans le base de données !".$er;
}
// PANIERS
$sql = "SELECT"
." CASE WHEN ISNULL( SUM(`complement`) - SUM(`complement_regle`) )"
." THEN 0.00"
@ -155,10 +174,10 @@ function getClientComplementDuAtDate($id, $date) {
$r = $GLOBALS['db_admin']['man']->select($sql,1);
if(!$r['erreur']) $val = $r['datas']['complement_du'];
if(!$r['erreur']) $val += floatval($r['datas']['complement_du']);
else {
$er = "</br>sql: ".$sql."</br>error: ".getReadableVar($r['erreur']);
$GLOBALS['errors'][] = "Une erreur est survenue durant la récupération dû complement du par le client dans le base de données !".$er;
return "Une erreur est survenue durant la récupération du complement dû par le client dans le base de données !".$er;
}
return $val;

View File

@ -142,24 +142,42 @@ function getLivraisonEmargementList($paniers_eligibles, $date, $lieu=0) {
if($l["ref"] == $lieu || !$lieu>0) {
foreach($l["paniers"] as $pType) {
foreach($pType["paniers"] as $p) {
if($p["present"]) {
$du = getClientComplementDuAtDate($p["client_ref"], $date);
if($du > 0) $p["complement_du"] = "$du";
else if($du < 0) $p["complement_du"] = abs($du)." € d'avoir";
else $p["complement_du"] = "/";
if(array_key_exists($p["client_ref"], $list)) {
if($p["present"]) {
$o = $list[$p["client_ref"]];
if((float)$p["complement"]>0) $p["complement"] .= "";
else $p["complement"] = "";
// COMPLEMENT
if((float)$p["complement"]>0) $o["complement_print"] = number_format(($o["complement"] + $p["complement"]), 2, '.', ' ')."";
// COMPLEMENT REGLE
if((float)$p["complement_regle"]>0) $o["complement_regle_print"] = number_format(($o["complement_regle"] + $p["complement_regle"]), 2, '.', ' ')."";
// PANIERS
$o["paniers"][] = $p;
if((float)$p["complement_regle"]>0) $p["complement_regle"] .= "";
else $p["complement_regle"] = "";
$list[$p["client_ref"]] = $o;
}
}
else {
$p["complement_du"] = "/";
$p["complement"] = "/";
$p["complement_regle"] = "/";
$p["complement_du_print"] = "/";
$p["complement_print"] = "";
$p["complement_regle_print"] = "";
if($p["present"]) {
// COMPLEMENT DU
$p["complement_du"] = getClientComplementDuAtDate($p["client_ref"], $date);
if($p["complement_du"] > 0) $p["complement_du_print"] = number_format($p["complement_du"], 2, '.', ' ')."";
else if($p["complement_du"] < 0) $p["complement_du_print"] = number_format(abs($p["complement_du"]), 2, '.', ' ')." € d'avoir";
// COMPLEMENT
if((float)$p["complement"]>0) $p["complement_print"] = number_format($p["complement"], 2, '.', ' ')."";
// COMPLEMENT REGLE
if((float)$p["complement_regle"]>0) $p["complement_regle_print"] = number_format($p["complement_regle"], 2, '.', ' ')."";
// PANIERS
$p["paniers"] = array();
$p["paniers"][] = $p;
}
$list[$p["client_ref"]] = $p;
}
$list[] = $p;
}
}
}
@ -376,7 +394,6 @@ function getLivraisonPaniersEligibles($paniers_groupe, $date, $quinz_groupe, $pa
}
// AJOUT
$list[$lieu]["paniers"][$pType]["paniers"][] = $i;
if($i["present"]) {
$list[$lieu]["nb_paniers"]++;

View File

@ -108,6 +108,8 @@
.formLivraison table.panier tr.legume td.unite { width: 40px; }
.formLivraison table.panier tr.editing { background-color: #cdebf8; }
.formLivraison table.panier th.nb_paniers_restants,
.formLivraison table.panier td.nb_paniers_restants { width: 120px; text-align: center; }
@ -233,6 +235,12 @@ table.emargement .nb_paniers { max-width: 25px; }
table.emargement .complement { max-width: 40px; }
table.emargement .signature { max-width: 60px; }
table.emargement .type.multi_paniers,
table.emargement .nb_paniers.multi_paniers {
padding-top: 6px;
padding-bottom: 6px;
}
table.emargement tr.absent { background-color: #F0F0F0; }
table.emargement tr.absent td.nom,

View File

@ -186,6 +186,7 @@ function modalViewLivraison_loadPaniers() {
modalViewLivraison.find("div.tabPaniers tr:not(.absent) td.complement").each(function(n,e) {
$(this).addClass("editable").dblclick(function(e) {
e.preventDefault();
$(this).parent().addClass("editing");
val = parseFloat( $(this).html() );
var ipt = $("<input class='editable complement' type='text' old_value='0'>");
$(this).html("").append(ipt);
@ -199,6 +200,7 @@ function modalViewLivraison_loadPaniers() {
if(val>0) ipt.val(val).attr("old_value", val);
ipt.blur(function(e) {
$(this).parent().parent().removeClass("editing");
if( $(this).hasClass("saving") ) return;
if( parseFloat($(this).attr("old_value"))>0 ) ipt.parent().html(number_format(parseFloat($(this).attr("old_value")), 2)+" €");
else ipt.parent().html(".")
@ -211,12 +213,25 @@ function modalViewLivraison_loadPaniers() {
modalViewLivraison.find("div.tabPaniers tr:not(.absent) td.complement_regle").each(function(n,e) {
$(this).addClass("editable").dblclick(function(e) {
e.preventDefault();
$(this).parent().addClass("editing");
val = parseFloat( $(this).html() );
var ipt = $("<input class='editable complement_regle' type='text' old_value='0'>");
$(this).html("").append(ipt);
initFloatInput(ipt);
ipt.keypress( function(event) {
if(event.keyCode==13) {
$(this).addClass("saving");
modalViewLivraison_saveComplement( $(this) );
}
})
if(val>0) ipt.val(val).attr("old_value", val);
ipt.blur(function(e) { modalViewLivraison_saveComplement( $(this) ); });
ipt.blur(function(e) {
$(this).parent().parent().removeClass("editing");
if( $(this).hasClass("saving") ) return;
if( parseFloat($(this).attr("old_value"))>0 ) ipt.parent().html(number_format(parseFloat($(this).attr("old_value")), 2)+" €");
else ipt.parent().html(".")
});
ipt.select();
});
});
@ -451,7 +466,7 @@ function modalFormLivraison_udpateCompo(modal, paniersTypes) {
}
function modalFormLivraison_addPanierTypeCompo(modal, datas) {
var table = $("<table class='panier'></table>")
var table = $("<table class='panier table-hover'></table>")
.attr("ref", datas.ref)
.attr("modal", modal.attr('id'));
@ -467,6 +482,7 @@ function modalFormLivraison_addPanierTypeCompo(modal, datas) {
btnCopyCompo.click(function(e) {
e.preventDefault(); $(this).blur();
if(e.clientX==0 && e.clientY==0) return;
modalFormLivraison_copyPanierTypeCompo(modal, table, $(this));
})
@ -537,6 +553,7 @@ function modalFormLivraison_addPanierTypeCompoLegume(modal, panier, datas) {
/*** INITIALIZE ***/
tdNom.dblclick(function(e) {
$(this).parent().addClass("editing");
var ipt = $("<input class='editable legume' type='text'>").val($(this).html());
ipt.attr('ref', $(this).attr('ref'))
.attr('tarif_ref', $(this).attr('tarif_ref'))
@ -601,6 +618,7 @@ function modalFormLivraison_addPanierTypeCompoLegume(modal, panier, datas) {
val = $(this).html();
unite = $(this).attr("unite");
if(unite in legumeTarifUnitesAccronymes) {
$(this).parent().addClass("editing");
var ipt = $("<input class='editable quantite' type='number' step='0.1'>");
$(this).html("").append(ipt);
initFloatInput(ipt);
@ -609,7 +627,7 @@ function modalFormLivraison_addPanierTypeCompoLegume(modal, panier, datas) {
var td = $(this).parent();
val = parseFloat( $(this).val() );
td.html( number_format(val, 3) );
td.parent().updateCompoLegumeMontant();
td.parent().removeClass("editing").updateCompoLegumeMontant(true);
});
ipt.select();
}
@ -640,7 +658,7 @@ function modalFormLivraison_loadPanierTypeCompoLegumeTarif(row, tarif_ref, tarif
row.find("td.quantite_unite").html(unite);
row.updateCompoLegumeMontant();
row.updateCompoLegumeMontant(false);
}
function modalFormLivraison_refreshPanierTypeCompoLegumeTarif(modal, panier, row) {
@ -690,7 +708,7 @@ function modalFormLivraison_copyPanierTypeCompo(modal, panier, btn) {
}
}
$.fn.updateCompoLegumeMontant = function() {
$.fn.updateCompoLegumeMontant = function(focus) {
q = parseFloat($(this).find("td.quantite").html());
t = parseFloat($(this).find("td.tarif").html());
$(this).find("td.montant").html( number_format(q * t, 2)+" €" );
@ -698,7 +716,8 @@ $.fn.updateCompoLegumeMontant = function() {
// UPDATE TOTAL
panier = $(this).parent().parent();
modalFormLivraison_updateMontantTotalPanier(panier);
panier.find(".btnAddLegume").focus();
if(focus) panier.find(".btnAddLegume").focus();
};
function modalFormLivraison_updateMontantTotalPanier(panier) {

View File

@ -56,7 +56,7 @@
<span class="nullChild">aucun panier</span>
</div>
<div class="tab tabLegumes">
<table class="panier legumesTotal">
<table class="panier table-hover legumesTotal">
<thead>
<tr class="title">
<th class="titre" colspan="2">TOTAL :</th>

View File

@ -1,5 +1,5 @@
{foreach from=$lieux item=lieu}
<table class="table panier">
<table class="table table-hover panier">
<thead>
<tr class="lieuTitre" lieu_ref="{$lieu.ref}">
<th class="noselect" colspan="2">{$lieu.nom}</th>

View File

@ -1,5 +1,5 @@
{foreach from=$infos.legumes item=p}
<table class="panier">
<table class="panier table-hover">
<thead>
<tr class="title">
<th class="titre" colspan="2">{$p.nom} <small>(x{$p.nb})</small></th>

View File

@ -1,4 +1,4 @@
<table class="panier legumesTotal">
<table class="panier table-hover legumesTotal">
<thead>
<tr class="title">
<th class="titre">TOTAL :</th>

View File

@ -1,5 +1,5 @@
{foreach from=$infos.paniers_eligibles item=lieu}
<table class="table panier">
<table class="table table-hover panier">
<thead>
<tr class="lieuTitre">
<th colspan="2">{$lieu.nom}</th>

View File

@ -35,11 +35,19 @@
<tr class="contrat{if !$c.present} absent{/if}">
<td class="nom">{$c.client_prenom} {$c.client_nom}</td>
<td class="tel center">{$c.client_tel}</td>
<td class="type center">{$c.panier_type_nom}</td>
<td class="nb_paniers center">{$c.nb_paniers_livres} / {$c.nb_paniers}</td>
<td class="complement center">{$c.complement_du}</td>
<td class="complement center">{$c.complement}</td>
<td class="complement center">{$c.complement_regle}</td>
<td class="type center{if $c.paniers|@count>1} multi_paniers{/if}">
{foreach from=$c.paniers item=p name=paniers}
{if !$smarty.foreach.paniers.first}<br/>+ {/if}{$p.panier_type_nom}
{/foreach}
</td>
<td class="nb_paniers center multi_paniers{if $c.paniers|@count>1} multi_paniers{/if}">
{foreach from=$c.paniers item=p name=paniers}
{if !$smarty.foreach.paniers.first}<br/>{/if}{$p.nb_paniers_livres} / {$p.nb_paniers}
{/foreach}
</td>
<td class="complement center">{$c.complement_du_print}</td>
<td class="complement center">{$c.complement_print}</td>
<td class="complement center">{$c.complement_regle_print}</td>
<td class="signature center">{if !$c.present}ABSENT{/if}</td>
</tr>
{/foreach}