From ae14bfd662f6b16960f9ea5c6d1926de908d6089 Mon Sep 17 00:00:00 2001 From: Adrien RENARD Date: Sun, 21 Jan 2024 16:56:10 +0100 Subject: [PATCH] =?UTF-8?q?Gestion=20multi-tarifs=20l=C3=A9gumes=20Afficha?= =?UTF-8?q?ge=20absence=20dans=20la=20listes=20des=20paniers=20d'une=20liv?= =?UTF-8?q?raison?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/db_struct.php | 18 +- functions/functions.php | 2 + functions/functions_legumes.php | 204 +++++++++++++----- functions/functions_livraisons.php | 12 +- public_html_admin/css/admin.css | 52 +++-- public_html_admin/css/livraisons.css | 3 +- public_html_admin/js/functions.js | 3 +- public_html_admin/js/legumes.js | 135 +++++++++--- public_html_admin/js/livraisons.js | 71 +++--- public_html_admin/legumes.php | 57 +++-- .../templates/legumes/legume_form.tpl | 35 +-- .../templates/legumes/legume_modal_view.tpl | 21 +- .../templates/legumes/legumes_list.tpl | 18 +- .../legumes/legumes_list_builder.tpl | 6 +- .../livraison_modal_view_tab_paniers.tpl | 8 +- .../livraisons/livraisons_list_builder.tpl | 2 +- 16 files changed, 453 insertions(+), 194 deletions(-) diff --git a/conf/db_struct.php b/conf/db_struct.php index d9cbcb0..232b3ca 100644 --- a/conf/db_struct.php +++ b/conf/db_struct.php @@ -264,7 +264,6 @@ function getContratsTypesTableSelectBaseSQL() { define('LEGUMES_TABLE',"legumes"); define('LEGUMES_TABLE_STRUCT', array( "nom" => array( "type" => "txt", "length" => 64, "default" => "" ), - "tarif" => array( "type" => "int", "min" => 1, "max" => NULL, "default" => NULL, "force_default_under_min" => true ), "del" => array( "type" => "bool", "default" => 0 ) )); @@ -275,13 +274,8 @@ function getCountLegumesListSelectBaseSQL() { function getLegumesTableSelectBaseSQL() { return "SELECT " .LEGUMES_TABLE.".`ref`," - .LEGUMES_TABLE.".`nom`," - .LEGUMES_TABLE.".`tarif` as 'tarif_ref'," - .LEGUMES_TARIFS_TABLE.".`prix` as 'tarif_prix'," - .LEGUMES_TARIFS_TABLE.".`unite` as 'tarif_unite'," - .LEGUMES_TARIFS_TABLE.".`date` as 'tarif_date'" - ." FROM ".LEGUMES_TABLE - ." LEFT JOIN ".LEGUMES_TARIFS_TABLE." ON ".LEGUMES_TABLE.".`tarif`=".LEGUMES_TARIFS_TABLE.".`ref`"; + .LEGUMES_TABLE.".`nom`" + ." FROM ".LEGUMES_TABLE; } function buildLegumesListSearchSQL($search) { return LEGUMES_TABLE.".`nom` LIKE '%".$search."%'"; } @@ -300,7 +294,6 @@ define('LEGUMES_TARIFS_TABLE_STRUCT', array( "prix" => array( "type" => "float", "min" => 0, "max" => 999.99, "default" => 0, "force_default_under_min" => true ), "unite" => array( "type" => "set", "values" => LEGUMES_TARIFS_UNITES, "default" => "poids" ), "date" => array( "type" => "date", "default" => "today" ), - "archive" => array( "type" => "bool", "default" => 0 ), "del" => array( "type" => "bool", "default" => 0 ) )); @@ -311,10 +304,9 @@ function getLegumesTarifsTableSelectBaseSQL() { .LEGUMES_TABLE.".`nom` as 'legume_nom'," .LEGUMES_TARIFS_TABLE.".`groupe` as 'groupe_ref'," .PANIERS_GROUPES_TABLE.".`nom` as 'groupe_nom'," - .LEGUMES_TARIFS_TABLE.".`prix` as 'tarif_prix'," - .LEGUMES_TARIFS_TABLE.".`unite` as 'tarif_unite'," - .LEGUMES_TARIFS_TABLE.".`date` as 'tarif_date'," - .LEGUMES_TARIFS_TABLE.".`archive`" + .LEGUMES_TARIFS_TABLE.".`prix` as 'prix'," + .LEGUMES_TARIFS_TABLE.".`unite` as 'unite'," + .LEGUMES_TARIFS_TABLE.".`date` as 'date'" ." FROM ".LEGUMES_TARIFS_TABLE ." LEFT JOIN ".LEGUMES_TABLE." ON ".LEGUMES_TARIFS_TABLE.".`legume`=".LEGUMES_TABLE.".`ref`" ." LEFT JOIN ".PANIERS_GROUPES_TABLE." ON ".LEGUMES_TARIFS_TABLE.".`groupe`=".PANIERS_GROUPES_TABLE.".`ref`"; diff --git a/functions/functions.php b/functions/functions.php index 5380210..c9e16c2 100644 --- a/functions/functions.php +++ b/functions/functions.php @@ -468,6 +468,7 @@ function strtoupperFirstLetter($str) { if(strlen($str)==0) return $str; return strtoupper(substr($str,0,1)).substr($str,1); } + // DATE function getTime($date,$moment='start',$format=DATE_FORMAT) { // Retourne un timestamp à partir d'une date jj/mm/aaaa @@ -576,6 +577,7 @@ function checkDateFormat($date, $format = 'mysql_datetime', $default = NULL) { } function isValidDate($date, $format = 'mysql_datetime') { + if(!$date || is_null($date)) return false; $f = "Y-m-d"; switch($format) { case 'date': $f = "d/m/Y"; break; diff --git a/functions/functions_legumes.php b/functions/functions_legumes.php index 25d8656..66feb87 100644 --- a/functions/functions_legumes.php +++ b/functions/functions_legumes.php @@ -8,9 +8,7 @@ $allowLegumesListOrder = array( 'ref' => "réf.", - 'nom' => "nom", - 'tarif' => "tarif", - 'date' => "date" + 'nom' => "nom" ); function getNbLegumesInList($search=false) { @@ -25,6 +23,11 @@ function getNbLegumesInList($search=false) { } function getLegumesList($order='nom',$sens='ASC', $search=false, $limits=false) { + // TARIF & DATE ORDRE + $grps = getPaniersGroupesList(); + $tarif_date_orders = array(); + foreach($grps as $g) { $tarif_date_orders[] = "tarif_".$g["ref"]; $orders[] = "date_".$g["ref"]; } + $list = array(); $sql = getLegumesTableSelectBaseSQL()." WHERE ".LEGUMES_TABLE.".`del`=0"; @@ -37,8 +40,6 @@ function getLegumesList($order='nom',$sens='ASC', $search=false, $limits=false) if($order=='ref') $sql .= LEGUMES_TABLE.".`ref`"; else if($order=='nom') $sql .= LEGUMES_TABLE.".`nom`"; - else if($order=='tarif') $sql .= LEGUMES_TARIFS_TABLE.".`prix`"; - else if($order=='date') $sql .= LEGUMES_TARIFS_TABLE.".`date`"; else $sql .= LEGUMES_TABLE.".`nom`"; // SENS @@ -46,15 +47,24 @@ function getLegumesList($order='nom',$sens='ASC', $search=false, $limits=false) else $sql .= ' ASC'; // LIMITS - if(is_array($limits)) $sql .= " LIMIT ".$limits['start'].", ".$limits['nbItemsByPage']; - + if(is_array($limits) && !in_array($order, $tarif_date_orders)) $sql .= " LIMIT ".$limits['start'].", ".$limits['nbItemsByPage']; + $r = $GLOBALS['db_admin']['man']->select($sql); if(!$r['erreur']) { foreach($r['datas'] as $i) { - $i["tarif_print"] = $i["tarif_prix"]." €/".$i["tarif_unite"]; - $i["tarif_date_print"] = formatDate($i["tarif_date"], "mysql_date", "print_date"); - + $i["tarifs"] = getLegumeTarifs($i['ref']); + foreach($i["tarifs"] as $g => $t) { + if($t["ref"] >0) { + $i["tarif_".$g] = $t["prix"]; + $i["date_".$g] = $t["dateObj"]; + } + else { + $i["tarif_".$g] = false; + $i["date_".$g] = false; + } + } + $i["next_tarifs"] = getLegumeTarifs($i['ref'], 'next'); $list[$i['ref']] = $i; } } @@ -63,6 +73,11 @@ function getLegumesList($order='nom',$sens='ASC', $search=false, $limits=false) $GLOBALS['errors'][] = "Une erreur est survenue durant la récupération de la liste des légumes dans le base de données !".$er; } + if(in_array($order, $tarif_date_orders)) { + $list = orderListByKey($list, $order, $sens); + if(is_array($limits)) $list = array_slice($list, $limits['start'], $limits['nbItemsByPage']); + } + return $list; } @@ -76,21 +91,30 @@ function getLegumesAutocompleteList() { $sql = getLegumesTableSelectBaseSQL()." WHERE ".LEGUMES_TABLE.".`del`=0"; foreach($parts as $p) $sql .= " AND (".buildLegumesListSearchSQL($p).")"; + $groupe = false; + if(isset($_REQUEST['groupe']) && (int)$_REQUEST['groupe']>0) $groupe = intval($_REQUEST['groupe']); + $date = false; + if(isset($_REQUEST['date']) && isValidDate($_REQUEST['date'], "mysql_date")) $date = $_REQUEST['date']; + $r = $GLOBALS['db_admin']['man']->select($sql); if(!$r['erreur']) { foreach($r['datas'] as $l) { - $row = array( - "id" => $l['ref'], - "value" => $l['nom'], - "label" => $l['nom'], - - "ref" => $l['ref'], - "tarif_ref" => $l['tarif_ref'], - "tarif_prix" => $l['tarif_prix'], - "tarif_unite" => $l['tarif_unite'] - ); - array_push($list, $row); + // TARIF + $t = getLegumeTarif($l['ref'], $groupe, $date, false); + if($t) { + $row = array( + "id" => $l['ref'], + "value" => $l['nom'], + "label" => $l['nom'], + + "ref" => $l['ref'], + "tarif_ref" => $t['ref'], + "tarif_prix" => $t['prix'], + "tarif_unite" => $t['unite'] + ); + array_push($list, $row); + } } $a_json = apply_highlight($list, $parts); // highlight search parts @@ -114,10 +138,9 @@ function getLegumeDatas($id) { if(!$r['erreur']) { $i = $r['datas']; - $i["tarif_print"] = $i["tarif_prix"]." €/".$i["tarif_unite"]; - $i["tarif_date_print"] = formatDate($i["tarif_date"], "mysql_date", "print_date"); - - $i["historique_tarif"] = getLegumeTarifHistorique($id, $i["tarif_ref"]); + $i["tarifs_list"] = getLegumeTarifsList($i['ref']); + $i["tarifs"] = getLegumeTarifs($i['ref']); + $i["next_tarifs"] = getLegumeTarifs($i['ref'], 'next'); } else { $er = "
sql: ".$sql."
error: ".getReadableVar($r['erreur']); @@ -132,16 +155,9 @@ function getLegumeDatas($id) { function getLegumeDatasFromRequest() { $datas = getRequestTableDatas(LEGUMES_TABLE_STRUCT); - // NEW TARIF - if(isset($_REQUEST["tarif_ref"]) && $_REQUEST["tarif_ref"] == "new" && isset($_REQUEST["tarif_prix"]) && isset($_REQUEST["tarif_unite"])) { - $date = formatDate('', 'mysql_date'); - if(isset($_REQUEST["tarif_date"])) $date = checkDateFormat($_REQUEST["tarif_date"], 'mysql_date', "now"); - $datas["new_tarif"] = array( - "prix" => floatval($_REQUEST["tarif_prix"]), - "unite" => in_array($_REQUEST["tarif_unite"], LEGUMES_TARIFS_UNITES) ? $_REQUEST["tarif_unite"] : "kg", - "date" => $date - ); - } + // TARIFS + $datas["tarifs"] = array(); + if(isset($_REQUEST["tarifs"])) $datas["tarifs"] = json_decode($_REQUEST["tarifs"], true); return $datas; } @@ -190,38 +206,119 @@ function eraseLegume($id) { // LEGUMES - TARIFS //////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -function getLegumeTarifs($legume) { +function getLegumeTarifsList($legume) { $list = array(); + $sql = getLegumesTarifsTableSelectBaseSQL() + ." WHERE ".LEGUMES_TARIFS_TABLE.".`legume`=".intval($legume) + ." AND ".LEGUMES_TARIFS_TABLE.".`del`=0" + ." ORDER BY ".LEGUMES_TARIFS_TABLE.".`date` DESC"; + $r = $GLOBALS['db_admin']['man']->select($sql); + + if(!$r['erreur']) { + foreach($r['datas'] as $i) { + $i["print"] = $i["prix"]." €/".$i["unite"]; + $i["date_print"] = formatDate($i["date"], "mysql_date", "print_date"); + $list[] = $i; + } + } + else { + $er = "
sql: ".$sql."
error: ".getReadableVar($r['erreur']); + $GLOBALS['errors'][] = "Une erreur est survenue durant la récupération de la liste des tarifs du légume dans le base de données !".$er; + } return $list; } -function getLegumeTarif($legume, $groupe) { - $i = array(); +function getLegumeTarifs($legume, $date=false) { + $groupes = getPaniersGroupesList(); + $list = []; + + $tarifToutGrp = getLegumeTarif($legume, 0, $date); + + foreach($groupes as $g) { + $tarif = array( + "groupe_ref" => $g['ref'], + "groupe_nom" => $g['nom'], + "ref" => 0 + ); + + // TARIF TOUT GROUPE + if(is_array($tarifToutGrp)) { + $tarif["ref"] = intval($tarifToutGrp["ref"]); + $tarif["prix"] = $tarifToutGrp["prix"]; + $tarif["unite"] = $tarifToutGrp["unite"]; + $tarif["print"] = $tarifToutGrp["print"]; + $tarif["date"] = $tarifToutGrp["date"]; + $tarif["date_print"] = $tarifToutGrp["date_print"]; + $tarif["tarif_groupe"] = 0; + } + + // TARIF SPECIFIQUE + $tarifGrp = getLegumeTarif($legume, $g['ref'], $date); + if(is_array($tarifGrp)) { + if(!is_array($tarifToutGrp) || (is_array($tarifToutGrp) && $tarifToutGrp["dateObj"] < $tarifGrp["dateObj"])) { + $tarif["ref"] = intval($tarifGrp["ref"]); + $tarif["prix"] = $tarifGrp["prix"]; + $tarif["unite"] = $tarifGrp["unite"]; + $tarif["print"] = $tarifGrp["print"]; + $tarif["date"] = $tarifGrp["date"]; + $tarif["date_print"] = $tarifGrp["date_print"]; + $tarif["tarif_groupe"] = $g['ref']; + } + } + + $list[$g['ref']] = $tarif; + } + + return $list; +} + +function getLegumeTarif($legume, $groupe, $date=false, $groupe_exclusif=true) { + $i = false; $sql = getLegumesTarifsTableSelectBaseSQL() - ." WHERE ".LEGUMES_TARIFS_TABLE.".`legume`=".intval($legume); + ." WHERE ".LEGUMES_TARIFS_TABLE.".`legume`=".intval($legume) + ." AND ".LEGUMES_TARIFS_TABLE.".`del`=0"; - if($groupe>0) $sql .= " AND ".LEGUMES_TARIFS_TABLE.".`groupe`=".intval($groupe); - else $sql .= " AND ".LEGUMES_TARIFS_TABLE.".`groupe` IS NULL"; - - $r = $GLOBALS['db_admin']['man']->select($sql,1); + // GROUPE + if($groupe>0) { + if($groupe_exclusif) $sql .= " AND ".LEGUMES_TARIFS_TABLE.".`groupe`=".intval($groupe); + else $sql .= " AND (".LEGUMES_TARIFS_TABLE.".`groupe`=".intval($groupe) + ." OR ".LEGUMES_TARIFS_TABLE.".`groupe`=0" + ." OR ".LEGUMES_TARIFS_TABLE.".`groupe` IS NULL)"; + } + else $sql .= " AND (".LEGUMES_TARIFS_TABLE.".`groupe` IS NULL OR ".LEGUMES_TARIFS_TABLE.".`groupe`=0)"; + + // DATE + if($date == 'next') { + $date = formatDate('', '', 'mysql_date'); + $sql .= " AND ".LEGUMES_TARIFS_TABLE.".`date`>'".$date."'"; + } + else { + if(!isValidDate($date, "mysql_date")) $date = formatDate('', '', 'mysql_date'); + $sql .= " AND ".LEGUMES_TARIFS_TABLE.".`date`<='".$date."'"; + } + + $sql .= " ORDER BY ".LEGUMES_TARIFS_TABLE.".`date` DESC"; + + $r = $GLOBALS['db_admin']['man']->select($sql); if(!$r['erreur']) { - $i = $r['datas']; - - $i["tarif_print"] = $i["tarif_prix"]." €/".$i["tarif_unite"]; - $i["tarif_date_print"] = formatDate($i["tarif_date"], "mysql_date", "print_date"); + if(count($r['datas'])>0) { + $i = $r['datas'][0]; + $i["dateObj"] = new DateTime($i["date"]); + $i["print"] = $i["prix"]." €/".$i["unite"]; + $i["date_print"] = formatDate($i["date"], "mysql_date", "print_date"); + } } else { $er = "
sql: ".$sql."
error: ".getReadableVar($r['erreur']); - $GLOBALS['errors'][] = "Une erreur est survenue durant la récupération des informations du légume dans le base de données !".$er; + $GLOBALS['errors'][] = "Une erreur est survenue durant la récupération des informations du tarif du légume dans le base de données !".$er; } return $i; - } function addLegumeTarif($datas) { @@ -243,6 +340,15 @@ function deleteLegumeTarif($id) { ); } +function eraseLegumeTarif($id) { + return eraseItemInTable( + $GLOBALS['db_admin']['man'], // DB MANAGER + LEGUMES_TARIFS_TABLE, // TABLE NAME + $id, // ID + "du tarif" // ERROR STRING + ); +} + function getLegumeTarifHistorique($id, $current = 0) { $list = array(); diff --git a/functions/functions_livraisons.php b/functions/functions_livraisons.php index ecf51c1..f3eeefb 100644 --- a/functions/functions_livraisons.php +++ b/functions/functions_livraisons.php @@ -55,7 +55,7 @@ function getLivraisonsList($order='id',$sens='ASC', $groupe=0, $archive=0, $limi // LIMITS if(is_array($limits)) $sql .= " LIMIT ".$limits['start'].", ".$limits['nbItemsByPage']; - + $r = $GLOBALS['db_admin']['man']->select($sql); if(!$r['erreur']) { @@ -120,6 +120,8 @@ function getLivraisonDatas($id) { $i["nb_paniers"] = getLivraisonNbPaniers($id); $i["legumes"] = getLivraisonLegumes($id, $i["nb_paniers"]); $i["total_legumes"] = calcLivraisonTotalLegumes($i["legumes"]); + + $i["paniers_eligibles"] = getLivraisonPaniersEligibles($i["paniers_groupe_ref"], $i["date"], $i["quinz_groupe"], $i["paniers_contrats"]); } else { $er = "
sql: ".$sql."
error: ".getReadableVar($r['erreur']); @@ -259,7 +261,7 @@ function getLivraisonLieux($livraison) { // LIVRAISONS - PANIERS //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -function getLivraisonPaniersEligibles($paniers_groupe, $date, $quinz_groupe) { +function getLivraisonPaniersEligibles($paniers_groupe, $date, $quinz_groupe, $contrats_presents=array()) { $list = array(); $sql = "SELECT " @@ -316,12 +318,18 @@ function getLivraisonPaniersEligibles($paniers_groupe, $date, $quinz_groupe) { $list[$lieu]["paniers"][$pType] = array( "type_ref" => $pType, "type_nom" => $i['panier_type_nom'], + "nb_paniers" => 0, "paniers" => array() ); } // AJOUT + $i["present"] = in_array(intval($i["contrat_ref"]), $contrats_presents); $list[$lieu]["paniers"][$pType]["paniers"][] = $i; + if($i["present"]) { + $list[$lieu]["nb_paniers"]++; + $list[$lieu]["paniers"][$pType]["nb_paniers"]++; + } } } } diff --git a/public_html_admin/css/admin.css b/public_html_admin/css/admin.css index 8c8979a..8c3186a 100644 --- a/public_html_admin/css/admin.css +++ b/public_html_admin/css/admin.css @@ -1,23 +1,15 @@ -div.mainPage { - padding: 0; -} +div.mainPage { padding: 0; } -.icon { - height: 16px; -} +.icon { height: 16px; } th.icon, -td.icon { - width: 24px; -} +td.icon { width: 24px; } -.center { - text-align: center; -} +.center { text-align: center; } +.right { text-align: right; } -.right { - text-align: right; -} +.border-left { border-left: 1px solid #ddd; } +.border-right { border-right: 1px solid #ddd; } tr.subLine > td { padding-top: 3px !important; @@ -135,7 +127,7 @@ table.scrollingTableList ::-webkit-scrollbar-thumb { table.scrollingTableList tbody { display: block; overflow: auto; margin: 0; } -table.scrollingTableList tbody tr:first-child td { border: none; } +table.scrollingTableList tbody tr:first-child td { border-top: none; } table.scrollingTableList thead, table.scrollingTableList tbody tr { display: table; @@ -143,9 +135,10 @@ table.scrollingTableList thead, table.scrollingTableList tbody tr { table-layout: fixed; } -table.scrollingTableList:not(.no-scroll) thead { width: calc( 100% - 16px ); } +table.scrollingTableList:not(.no-scroll) thead { width: calc( 100% - 15px ); } table.scrollingTableList th.id, table.scrollingTableList td.id { width: 45px; } +table.scrollingTableList th.tarif, table.scrollingTableList td.tarif { width: 140px; } table.scrollingTableList th.groupe, table.scrollingTableList td.groupe { width: 100px; } table.scrollingTableList th.valeur, table.scrollingTableList td.valeur { width: 130px; } table.scrollingTableList th.tel, table.scrollingTableList td.tel { width: 150px; } @@ -550,8 +543,29 @@ div.formTabs table.modal-body tr:first-child td { border-top: none; } /* MODAL VIEW LEGUME */ -#modalViewLegume table.modal-body tbody th { width: 100px; } -#modalViewLegume table.modal-body tfoot { background-color: #f2f2f2; } +.has-next-tarif { background-color: azure; } + +#modalViewLegume tr.tarifs_titre { background-color: #f2f2f2; border-top: 3px solid #ddd; } +#modalViewLegume tr.tarifs_titre th.groupe { border-left: 1px solid #999999; border-right: 1px solid #999999; } +#modalViewLegume tr.tarif td { border: 1px solid #999999; } + +#modalViewLegume td.tarif { text-align: center; } +#modalViewLegume tr.tarif.courant td { + background-color: rgba(51, 122, 183, .2); + border-color: #999999; +} +#modalViewLegume td.tarif.groupe-null { background-color: #ddd!important; } + +/* FORM LEGUME */ +.formLegume div.tarif { margin-bottom: 5px; } +.formLegume div.tarifs:last-child { margin-bottom: 0; } + +.formLegume div.input-group.deleted select.form-control, +.formLegume div.input-group.deleted input.form-control, +.formLegume div.input-group.deleted span.input-group-addon { + text-decoration: line-through; + color: #d9534f; +} /* MODAL ADMIN CONSOLE */ diff --git a/public_html_admin/css/livraisons.css b/public_html_admin/css/livraisons.css index 2aa813d..861016e 100644 --- a/public_html_admin/css/livraisons.css +++ b/public_html_admin/css/livraisons.css @@ -48,7 +48,8 @@ .formLivraison table.panier th, .formLivraison table.panier td { padding: 4px !important; } -.formLivraison table.panier tr.absent { background-color: #f3f3f3; } +.formLivraison table.panier tr.absent { background-color: #f3f3f3; color: #8f8f8f; } +.formLivraison table.panier tr.absent td.nom { text-decoration: line-through; } .formLivraison table.panier tr.lieuTitre { cursor: pointer; } .formLivraison table.panier tr.lieuTitre th { diff --git a/public_html_admin/js/functions.js b/public_html_admin/js/functions.js index 6ecbbec..9e95d05 100644 --- a/public_html_admin/js/functions.js +++ b/public_html_admin/js/functions.js @@ -143,7 +143,6 @@ function modalForm_initBtnUnarchive(btn, archiveType, modal, saveURL) { }); } - function modalForm_initBtnDelete(btn, modal, clearFormFct, loadFormDatasFct) { btn.unbind('click').click( function(e) { e.preventDefault(); $(this).blur(); @@ -1064,7 +1063,7 @@ function getTodayDate(format) { function parseDate(dateStr, format) { date = false; - if(dateStr == "") return date; + if(dateStr == "" || dateStr.length<10) return date; switch(format) { case 'yyyy-mm-dd' : { d=dateStr.split("-"); if(d.length==3) date = new Date(d[0], d[1] - 1, d[2]); } break; case 'yyyy-dd-mm' : { d=dateStr.split("-"); if(d.length==3) date = new Date(d[0], d[2] - 1, d[1]); } break; diff --git a/public_html_admin/js/legumes.js b/public_html_admin/js/legumes.js index 810c339..10d1368 100644 --- a/public_html_admin/js/legumes.js +++ b/public_html_admin/js/legumes.js @@ -82,11 +82,13 @@ function modalViewLegume_loadDatas(modal, id) { modal.find("small.db_ref > span").html(datas.ref); modal.find("td.nom").html(datas.nom); - modal.find("td.tarif").html(datas.tarif_print+" (depuis le "+datas.tarif_date_print+")"); - if(datas.historique_tarif.length>0) { - modal.find("table.modal-body tfoot").removeClass("hide"); - $.each(datas.historique_tarif, function(n,e) { addTarifLegumeHist(e); }); + // TARIFS + if(Object.keys(datas.tarifs_list).length>0) { + modal.find("table.modal-body tbody tr.nullchild").addClass("hide"); + var tarifs_courant = {}; + $.each(datas.tarifs, function(n,e) { tarifs_courant[e.ref] = e.print }); + $.each(datas.tarifs_list, function(n,e) { modalViewLegume_addTarif(modal, e, tarifs_courant); }); } modal.modal('show'); @@ -97,11 +99,34 @@ function modalViewLegume_clear(modal) { modal.find("small.db_ref > span").html(""); modal.find("td.nom").html(""); - modal.find("td.tarif").html(""); + modal.find("table.modal-body tbody tr.nullchild").removeClass("hide"); + modal.find("table.modal-body tbody tr.tarif").remove(); modal.find("table.modal-body tfoot").addClass("hide").find("tr:not(.header)").remove(); } +function modalViewLegume_addTarif(modal, datas, tarifs_courant) { + var tr = $("") + .append( $("").html(datas.date_print) ); + + if(tarifs_courant.hasOwnProperty(datas.ref)) tr.addClass("courant"); + + var grps = modal.find("table.modal-body tbody th.titre.groupe"); + + if(parseInt(datas.groupe_ref)>0) { + grps.each(function(n,e) { + if(parseInt($(this).attr('ref')) == parseInt(datas.groupe_ref)) { + tr.append( $("").html(datas.print) ); + } + else tr.append( $(".") ); + }); + } + else { + tr.append( $("").attr("colspan", grps.length).html(datas.print) ); + } + modal.find("table.modal-body tbody").append(tr); +} + function modalViewLegume_addTarifLegumeHist(modal, datas) { var tr = $("").attr("ref", datas.ref); tr.append($("").html(datas.tarif_print)); @@ -133,13 +158,11 @@ function modalViewLegume_addTarifLegumeHist(modal, datas) { function modalFormLegume_init(modal) { modal.find("form").on("submit", function(e) { e.preventDefault(); }); - // BTN EDIT TARIF - modal.find("button.btnEditTarif").click(function(e) { + // BTN ADD TARIF + modal.find("button.btnAddTarif").click(function(e) { e.preventDefault(); - $(this).blur().addClass('hide'); - modal.find("input[name=prix]").attr('ref', 'new').prop('disabled', false); - modal.find("select[name=unite]").prop('disabled', false); - modal.find("input[name=date]").prop('disabled', false).val(getTodayDate("yyyy-mm-dd")); + iptGrp = modalFormLegume_addTarif(modal, false); + iptGrp.find("input[name=prix]").focus(); }); // PRIX @@ -151,9 +174,18 @@ function modalFormLegume_loadDatas(modal,id) { var datas = JSON.parse(jsonTxt); modal.find("input[name=nom]").val(datas.nom); - modal.find("input[name=prix]").val(datas.tarif_prix).attr('ref', datas.tarif_ref); - modal.find("select[name=unite]").val(datas.tarif_unite); - modal.find("input[name=date]").val(datas.tarif_date); + $.each(datas.tarifs, function(n,e) { + if(e.ref>0) { + e.is_next = false; + modalFormLegume_addTarif(modal, e); + } + }); + $.each(datas.next_tarifs, function(n,e) { + if(e.ref>0) { + e.is_next = true; + modalFormLegume_addTarif(modal, e); + } + }); if(modal) modal.modal('show'); }).fail(function() { alert("("+legumesConf.type+" - load datas in modal form)"); }); @@ -162,31 +194,78 @@ function modalFormLegume_loadDatas(modal,id) { function modalFormLegume_clear(modal) { modal.removeAttr("edit_id"); modal.find("div.modaLoader").removeClass("show"); - - add = modal.hasClass("add"); modal.find("input[name=nom]").val(""); - if(add) modal.find("button.btnEditTarif").addClass('hide'); - else modal.find("button.btnEditTarif").removeClass('hide'); - modal.find("input[name=prix]").val("").attr('ref', "new").prop('disabled', !add); - modal.find("select[name=unite]").val("kg").prop('disabled', !add); - modal.find("input[name=date]").val(getTodayDate("yyyy-mm-dd")).prop('disabled', !add); + modal.find("div.tarifs div.tarif").remove(); +} + +function modalFormLegume_addTarif(modal, datas) { + if(modal.find("div.tarifs div.tarif[ref="+datas.ref+"]").length>0) return; + + var iptGrp = $( modal.find("div.tarif_template").html() ).addClass("tarif").attr('ref', 'new'); + + if(isDefined(datas) && typeof(datas)==="object") { + iptGrp.attr('ref', datas.ref); + iptGrp.find("select[name=groupe]").val(datas.tarif_groupe).prop("disabled", true); + iptGrp.find("input[name=prix]").val(datas.prix).prop("disabled", true); + iptGrp.find("select[name=unite]").val(datas.unite).prop("disabled", true); + iptGrp.find("input[name=date]").val(datas.date).prop("disabled", true); + if(datas.is_next) iptGrp.find("button.btnDel").prop("disabled", false); + } + else { + iptGrp.find("input[name=date]").val(getTodayDate("yyyy-mm-dd")); + iptGrp.find("button.btnDel").prop("disabled", false); + } + + modal.find("div.tarifs").append(iptGrp); + + // INIT + initFloatInput( iptGrp.find("input[name=prix]") ); + + iptGrp.find("button.btnDel").click(function(e) { + e.preventDefault(); $(this).blur(); + if(parseInt(iptGrp.attr("ref"))>0) { + if(iptGrp.hasClass("deleted")) { + iptGrp.removeClass("deleted"); + $(this).removeClass("btn-info").addClass("btn-danger") + .find("i").removeClass("glyphicon-refresh").addClass("glyphicon-trash"); + } + else { + iptGrp.addClass("deleted"); + $(this).removeClass("btn-danger").addClass("btn-info") + .find("i").removeClass("glyphicon-trash").addClass("glyphicon-refresh"); + } + } + else iptGrp.remove(); + }); + + return iptGrp; } function modalFormLegume_getDatas(modal) { var datas = { - 'nom' : modal.find("input[name=nom]").val(), - 'tarif_ref' : (modal.find("input[name=prix]").attr('ref')=="new") ? "new" : parseInt(modal.find("input[name=prix]").attr('ref')), - 'tarif_prix' : parseFloat( modal.find("input[name=prix]").val() ), - 'tarif_unite' : modal.find("select[name=unite]").val(), - 'tarif_date' : modal.find("input[name=date]").val() + 'nom' : modal.find("input[name=nom]").val() }; + + // TARIFS + var tarifs = []; + modal.find("div.tarifs div.input-group.tarif").each(function(n,e) { + tarifs.push({ + 'ref' : $(this).attr('ref'), + 'groupe' : parseInt( $(this).find("select[name=groupe]").val() ), + 'prix' : parseFloat( $(this).find("input[name=prix]").val() ), + 'unite' : $(this).find("select[name=unite]").val(), + 'date' : $(this).find("input[name=date]").val(), + 'del' : $(this).hasClass("deleted") ? 1 : 0 + }); + }); + datas.tarifs = JSON.stringify(tarifs); return datas; } function modalFormLegume_checkDatas(datas) { - if(datas.nom=="") { - alert("ERREUR : au minimum, un nom doit être renseigné !"); + if(datas.nom=="" || JSON.parse(datas.tarifs).length==0) { + alert("ERREUR : au minimum, un nom et un tarif doivent être renseigné !"); return false; } return true; diff --git a/public_html_admin/js/livraisons.js b/public_html_admin/js/livraisons.js index b5dac37..9fae684 100644 --- a/public_html_admin/js/livraisons.js +++ b/public_html_admin/js/livraisons.js @@ -107,7 +107,6 @@ function initViewLivraison() { function modalViewLivraison_loadDatas(modal, id) { $.post(livraisonsConf.baseURL, { 'ref' : id, 'action' : 'getDatas' }, function(jsonTxt) { var datas = JSON.parse(jsonTxt); - modal.find("small.db_ref > span").html(datas.ref); modal.find("td.groupe").html(datas.paniers_groupe_nom); @@ -177,9 +176,9 @@ function modalFormLivraison_init(modal) { modalFormLivraison_loadPaniers(modal, []); modalFormLivraison_loadNextGroupe(modal); }); - modal.find("input[name=date]").on("blur change", function(e) { - modalFormLivraison_loadPaniers(modal, []); - modalFormLivraison_loadNextGroupe(modal); + modal.find("input[name=date]").on("blur change", function(e) { + modalFormLivraison_loadPaniers(modal, []); + modalFormLivraison_loadNextGroupe(modal); }); modal.find("input[name=date]").keydown(function(e) { if(e.keyCode==13) { e.preventDefault(); $(this).blur(); } }) modal.find("select[name=quinz_groupe]").change(function(e) { @@ -271,7 +270,7 @@ function modalFormLivraison_loadPaniers(modal, paniers) { }); // INIT CHECKBOX - modal.find("div.tabPaniers table.panier input[name=status]").click(function(e) { $(this).blur(); modalFormLivraison_updateNbPaniersType(modal); }); + modal.find("div.tabPaniers table.panier input[name=status]").click(function(e) { e.stopPropagation(); $(this).blur(); modalFormLivraison_updateNbPaniersType(modal); }); // INIT TR CLICK modal.find("div.tabPaniers table.panier tr.panier").click(function(e) { $(this).find("input[name=status]").click(); }); @@ -443,6 +442,8 @@ function modalFormLivraison_addPanierTypeCompoLegume(modal, panier, datas) { tdQunit.html(unite); tdMontant.html(number_format(datas.tarif_prix * datas.quantite, 2)); + + modalFormLivraison_refreshPanierTypeCompoLegumeTarif(modal, panier, trL); } panier.find("tbody").append(trL); @@ -463,7 +464,8 @@ function modalFormLivraison_addPanierTypeCompoLegume(modal, panier, datas) { "(modal form livraison - compo legume autocomplete)", // ERROR CONTEXT // REQUEST DATAS function(modal, ipt, datas) { - datas.paniers_groupe = modal.find("select[name=paniers_groupe]").val(); + datas.groupe = modal.find("select[name=paniers_groupe]").val(); + datas.date = modal.find("input[name=date]").val(); return datas; }, // SELECT @@ -494,26 +496,9 @@ function modalFormLivraison_addPanierTypeCompoLegume(modal, panier, datas) { if(ref>0 && tarif_ref>0) { var td = ipt.parent(); var tr = td.parent(); - tr.attr("ref", ref); - - td.html( val ) - .attr('ref', ref) - .attr('tarif_ref', tarif_ref) - .attr('tarif_prix', tarif_prix) - .attr('tarif_unite', tarif_unite); - - tr.find("td.tarif").html(number_format(tarif_prix,2)).attr("ref", tarif_ref); - tr.find("td.tarif_unite").html("€/"+unite); - - q = tr.find("td.quantite").attr('unite', tarif_unite).html(); - if(tarif_unite=="kg") tr.find("td.quantite").html( number_format(q,3) ); - else tr.find("td.quantite").html( parseInt(q) ); - - tr.find("td.quantite_unite").html(unite); - - tr.updateCompoLegumeMontant(); - + td.html( val ).attr('ref', ref); + modalFormLivraison_loadPanierTypeCompoLegumeTarif(tr, tarif_ref, tarif_prix, tarif_unite); tr.find("td.quantite").dblclick(); } else { @@ -552,6 +537,42 @@ function modalFormLivraison_addPanierTypeCompoLegume(modal, panier, datas) { if(datas == "new") tdNom.dblclick(); } +function modalFormLivraison_loadPanierTypeCompoLegumeTarif(row, tarif_ref, tarif_prix, tarif_unite) { + unite = legumeTarifUnitesAccronymes[tarif_unite]; + + row.find("td.nom").attr('tarif_ref', tarif_ref) + .attr('tarif_prix', tarif_prix) + .attr('tarif_unite', tarif_unite); + + row.find("td.tarif").html(number_format(tarif_prix,2)).attr("ref", tarif_ref); + row.find("td.tarif_unite").html("€/"+unite); + + q = row.find("td.quantite").attr('unite', tarif_unite).html(); + if(tarif_unite=="kg") row.find("td.quantite").html( number_format(q,3) ); + else row.find("td.quantite").html( parseInt(q) ); + + row.find("td.quantite_unite").html(unite); + + row.updateCompoLegumeMontant(); +} + +function modalFormLivraison_refreshPanierTypeCompoLegumeTarif(modal, panier, row) { + return; + var datas = { + ref : parseInt(row.attr('ref')), + action : 'getTarif', + groupe : modal.find("select[name=paniers_groupe]").val(), + date : modal.find("input[name=date]").val() + } + $.post("legumes.php", datas, function(result) { + tarif = JSON.parse(result); + tdNom = row.find("td.nom"); + if(typeof(tarif)=== "object" && tdNom.length>0) { + if(parseInt(tarif.ref) != parseInt(tdNom.attr('tarif_ref'))) modalFormLivraison_loadPanierTypeCompoLegumeTarif(row, tarif.ref, tarif.prix, tarif.unite); + } + }).fail(function() { alert("ERREUR SERVEUR (modal form livraison - get next groupe)"); }); +} + function modalFormLivraison_copyPanierTypeCompo(modal, panier, btn) { // COPY if(!modalFormLivraison_copyCompoOrigin>0) { diff --git a/public_html_admin/legumes.php b/public_html_admin/legumes.php index 0819556..ea256d3 100644 --- a/public_html_admin/legumes.php +++ b/public_html_admin/legumes.php @@ -21,6 +21,7 @@ $GLOBALS['racine'] = 'legumes.php'; $GLOBALS['smarty']->assign('page','legumes'); $GLOBALS['smarty']->assign('secondbar','legumes/legumes_secondbar.tpl'); +include_once(FUNCTIONS_DIR_PATH.'functions_paniers_groupes.php'); include_once(FUNCTIONS_DIR_PATH.'functions_legumes.php'); $action = false; @@ -33,18 +34,32 @@ if(isset($_REQUEST["ref"]) && (int)$_REQUEST["ref"]>0 && $action) { switch($action) { // AJAX GET DATAS case "getDatas": die(json_encode($infos)); break; + // AJAX GET TARIF + case "getTarif": { + $groupe = false; + if(isset($_REQUEST['groupe']) && (int)$_REQUEST['groupe']>0) $groupe = intval($_REQUEST['groupe']); + $date = false; + if(isset($_REQUEST['date']) && isValidDate($_REQUEST['date'], "mysql_date")) $date = $_REQUEST['date']; + $t = getLegumeTarif($id, $groupe, $date, false); + die(json_encode($t)); + } break; // EDIT case "edit": { $datas = getLegumeDatasFromRequest(); - // TARIF - if(isset($datas["new_tarif"])) { - $datas["new_tarif"]['legume'] = $id; - $r = addLegumeTarif($datas["new_tarif"]); - if((int)$r>0) $datas["tarif"] = $r; - else die("ERREUR : une errreur est survenue durant l'enregistrement du nouveau tarif du légume. ($r)"); + // TARIFS + foreach($datas["tarifs"] as $t) { + if($t['ref'] == "new") { + $t['legume'] = $id; + $r = addLegumeTarif($t); + if(!(int)$r>0) die("ERREUR : une errreur est survenue durant l'enregistrement du nouveau tarif du légume. ($r)"); + } + else if((int)$t['ref']>0 && (int)$t['del']>0) { + $r = eraseLegumeTarif(intval($t['ref'])); + if(!(int)$r>0) die("ERREUR : une errreur est survenue durant la suppression du tarif du légume. ($r)"); + } } - + die( strval( updateLegume($id,$datas) ) ); } break; // DELETE @@ -62,18 +77,13 @@ switch($action) { if((int)$r>0) { $id = $r; - // TARIF - if(isset($datas["new_tarif"])) { - $datas["new_tarif"]['legume'] = $id; - $r = addLegumeTarif($datas["new_tarif"]); - if((int)$r>0) { - $tarif_id = $r; - - // UPDATE CURRENT TARIF - $r = updateLegume($id, array("tarif" => $tarif_id)); - if(!(int)$r>0) die("ERREUR : une errreur est survenue durant l'enregistrement du tarif dans la fiche légume. ($r)"); + // TARIFS + foreach($datas["tarifs"] as $t) { + if($t['ref'] == "new") { + $t['legume'] = $id; + $r = addLegumeTarif($t); + if(!(int)$r>0) die("ERREUR : une errreur est survenue durant l'enregistrement du tarif du légume. ($r)"); } - else die("ERREUR : une errreur est survenue durant l'enregistrement du tarif du légume. ($r)"); } die( (string)$id ); @@ -103,6 +113,17 @@ switch($action) { $GLOBALS['smarty'] -> assign('list_limits',$limits); // LIST + $grps = getPaniersGroupesList(); + $groupes = array(); + foreach($grps as $g) { + $g["tarif"] = "tarif_".$g['ref']; + $g["date"] = "date_".$g['ref']; + $groupes[] = $g; + + $allowLegumesListOrder[ $g["tarif"] ] = "tarif ".$g['nom']; + $allowLegumesListOrder[ $g["date"] ] = "date ".$g['nom']; + } + $GLOBALS['smarty'] -> assign('groupes',$groupes); $order = getListOrder('legumes_list_order', 'legumes_list_sens', $allowLegumesListOrder, 'prenom'); $list = getLegumesList($order["order"], $order["sens"], $search, $limits); $GLOBALS['smarty'] -> assign('list',$list); diff --git a/public_html_admin/templates/legumes/legume_form.tpl b/public_html_admin/templates/legumes/legume_form.tpl index 922438c..cd42e76 100644 --- a/public_html_admin/templates/legumes/legume_form.tpl +++ b/public_html_admin/templates/legumes/legume_form.tpl @@ -5,19 +5,30 @@ -
- +
+ -
- - unité : - - date : - +
+
+ groupe : + + prix : + + unité : + + date : + + +
diff --git a/public_html_admin/templates/legumes/legume_modal_view.tpl b/public_html_admin/templates/legumes/legume_modal_view.tpl index e068565..c9994a6 100644 --- a/public_html_admin/templates/legumes/legume_modal_view.tpl +++ b/public_html_admin/templates/legumes/legume_modal_view.tpl @@ -13,19 +13,20 @@ - - + + - - - + + + {foreach from=$groupes item=g} + + {/foreach} + + + + - - - - -
diff --git a/public_html_admin/templates/legumes/legumes_list.tpl b/public_html_admin/templates/legumes/legumes_list.tpl index 8a1e33d..1837aea 100644 --- a/public_html_admin/templates/legumes/legumes_list.tpl +++ b/public_html_admin/templates/legumes/legumes_list.tpl @@ -14,18 +14,20 @@ nom{if $order=="nom"} {/if} - - - tarif{if $order=="tarif"} {/if} + {foreach from=$groupes item=g} + + + tarif {$g.nom}{if $order==$g.tarif} {/if} - - - date{if $order=="date"} {/if} + + + date {$g.nom}{if $order==$g.date} {/if} + {/foreach} diff --git a/public_html_admin/templates/legumes/legumes_list_builder.tpl b/public_html_admin/templates/legumes/legumes_list_builder.tpl index a5805ef..142e016 100644 --- a/public_html_admin/templates/legumes/legumes_list_builder.tpl +++ b/public_html_admin/templates/legumes/legumes_list_builder.tpl @@ -2,8 +2,10 @@ {$i.ref} {$i.nom} - {if $i.tarif_print}{$i.tarif_print}{else}.{/if} - {$i.tarif_date_print} + {foreach from=$groupes item=g} + {if $i.tarifs[$g.ref].ref>0}{$i.tarifs[$g.ref].print}{else}.{/if} + {if $i.tarifs[$g.ref].ref>0}{$i.tarifs[$g.ref].date_print}{else}.{/if} + {/foreach} diff --git a/public_html_admin/templates/livraisons/livraison_modal_view_tab_paniers.tpl b/public_html_admin/templates/livraisons/livraison_modal_view_tab_paniers.tpl index 15a4d64..8fe108a 100644 --- a/public_html_admin/templates/livraisons/livraison_modal_view_tab_paniers.tpl +++ b/public_html_admin/templates/livraisons/livraison_modal_view_tab_paniers.tpl @@ -1,4 +1,4 @@ -{foreach from=$infos.lieux item=lieu} +{foreach from=$infos.paniers_eligibles item=lieu} @@ -14,12 +14,12 @@ {foreach from=$lieu.paniers item=pType} - + {foreach from=$pType.paniers item=p} - + - + {/foreach} diff --git a/public_html_admin/templates/livraisons/livraisons_list_builder.tpl b/public_html_admin/templates/livraisons/livraisons_list_builder.tpl index 0dde6ac..1492e73 100644 --- a/public_html_admin/templates/livraisons/livraisons_list_builder.tpl +++ b/public_html_admin/templates/livraisons/livraisons_list_builder.tpl @@ -5,7 +5,7 @@ - + {if $i.nb_paniers>0} {if $i.archive>0}
{$pType.type_nom} (x{$pType.paniers|@count}){$pType.type_nom} (x{$pType.nb_paniers})
{$p.client_prenom} {$p.client_nom}{$p.frequence_print}{if $p.present}{$p.frequence_print}{else}absent{/if} {$p.nb_paniers_restants}
{$i.date_print} {if $i.quinz_groupe!=""}groupe {$i.quinz_groupe}{else}.{/if} {$i.nb_paniers} panier{if $i.nb_paniers>1}s{/if}{if $i.archive==0}{/if}