diff --git a/conf/db_struct.php b/conf/db_struct.php index 232b3ca..de994b0 100644 --- a/conf/db_struct.php +++ b/conf/db_struct.php @@ -79,8 +79,12 @@ function getClientsTableSelectBaseSQL() { .CLIENTS_TABLE.".`nom`," .CLIENTS_TABLE.".`prenom`," .CLIENTS_TABLE.".`tel`," - .CLIENTS_TABLE.".`email`" - ." FROM ".CLIENTS_TABLE; + .CLIENTS_TABLE.".`email`," + .COMPLEMENTS_CLIENTS_STATUS_VIEW.".`complements`," + .COMPLEMENTS_CLIENTS_STATUS_VIEW.".`complements_regles`," + .COMPLEMENTS_CLIENTS_STATUS_VIEW.".`complements_dus`" + ." FROM ".CLIENTS_TABLE + ." LEFT JOIN ".COMPLEMENTS_CLIENTS_STATUS_VIEW." ON ".CLIENTS_TABLE.".`ref`=".COMPLEMENTS_CLIENTS_STATUS_VIEW.".`client`"; } function buildClientsListSearchSQL($search) { @@ -186,6 +190,9 @@ function getContratsTableSelectBaseSQL() { .CONTRATS_TABLE.".`np_paniers_distrib_avt_saisie`," .CONTRATS_TABLE.".`force_eligible`," .CONTRATS_TABLE.".`archive`," + .COMPLEMENTS_CONTRATS_STATUS_VIEW.".`complements`," + .COMPLEMENTS_CONTRATS_STATUS_VIEW.".`complements_regles`," + .COMPLEMENTS_CONTRATS_STATUS_VIEW.".`complements_dus`," .CONTRATS_TABLE.".`del`" ." FROM ".CONTRATS_TABLE ." LEFT JOIN ".CLIENTS_TABLE." ON ".CONTRATS_TABLE.".`client`=".CLIENTS_TABLE.".`ref`" @@ -193,7 +200,8 @@ function getContratsTableSelectBaseSQL() { ." LEFT JOIN ".PANIERS_GROUPES_TABLE." ON ".CONTRATS_TABLE.".`groupe`=".PANIERS_GROUPES_TABLE.".`ref`" ." LEFT JOIN ".PANIERS_TYPES_TABLE." ON ".CONTRATS_TABLE.".`panier_type`=".PANIERS_TYPES_TABLE.".`ref`" ." LEFT JOIN ".LIEUX_TABLE." ON ".CONTRATS_TABLE.".`lieu_depot`=".LIEUX_TABLE.".`ref`" - ." LEFT JOIN ".CONTRATS_PANIERS_STATUT." ON ".CONTRATS_TABLE.".`ref`=".CONTRATS_PANIERS_STATUT.".`ref`"; + ." LEFT JOIN ".CONTRATS_PANIERS_STATUT." ON ".CONTRATS_TABLE.".`ref`=".CONTRATS_PANIERS_STATUT.".`ref`" + ." LEFT JOIN ".COMPLEMENTS_CONTRATS_STATUS_VIEW." ON ".CONTRATS_TABLE.".`ref`=".COMPLEMENTS_CONTRATS_STATUS_VIEW.".`contrat`"; } function buildContratsListSearchSQL($search) { @@ -409,6 +417,8 @@ define('LIVRAISONS_PANIERS_TABLE',"livraisons_paniers"); define('LIVRAISONS_PANIERS_TABLE_STRUCT', array( "livraison" => array( "type" => "int", "min" => 1, "max" => NULL, "default" => NULL, "force_default_under_min" => true ), "contrat" => array( "type" => "int", "min" => 1, "max" => NULL, "default" => NULL, "force_default_under_min" => true ), + "complement" => array( "type" => "float", "min" => 0, "max" => 999.99, "default" => 0, "force_default_under_min" => true ), + "complement_regle" => array( "type" => "float", "min" => 0, "max" => 999.99, "default" => 0, "force_default_under_min" => true ), "del" => array( "type" => "bool", "default" => 0 ) )); @@ -431,6 +441,8 @@ function getLivraisonsPaniersSelectBaseSQL() { .PANIERS_TYPES_TABLE.".`nom` as 'panier_type_nom'," .CONTRATS_TABLE.".`lieu_depot` as 'lieu_depot_ref'," .LIEUX_TABLE.".`nom` as 'lieu_depot_nom'," + .LIVRAISONS_PANIERS_TABLE.".`complement`," + .LIVRAISONS_PANIERS_TABLE.".`complement_regle`," .LIVRAISONS_PANIERS_TABLE.".`del`" ." FROM ".LIVRAISONS_PANIERS_TABLE ." LEFT JOIN ".LIVRAISONS_TABLE." ON ".LIVRAISONS_PANIERS_TABLE.".`livraison`=".LIVRAISONS_TABLE.".`ref`" @@ -440,3 +452,11 @@ function getLivraisonsPaniersSelectBaseSQL() { ." LEFT JOIN ".LIEUX_TABLE." ON ".CONTRATS_TABLE.".`lieu_depot`=".LIEUX_TABLE.".`ref`" ." LEFT JOIN ".CONTRATS_PANIERS_STATUT." ON ".CONTRATS_TABLE.".`ref`=".CONTRATS_PANIERS_STATUT.".`ref`"; } + +//////////////////////////////////////////////////////////////////////// +// COMPLEMENTS STATUS VIEWS //////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + +define('COMPLEMENTS_CONTRATS_STATUS_VIEW', "complements_contrats_status"); +define('COMPLEMENTS_CLIENTS_STATUS_VIEW', "complements_clients_status"); + diff --git a/functions/functions_clients.php b/functions/functions_clients.php index 72fd460..7a47fc4 100644 --- a/functions/functions_clients.php +++ b/functions/functions_clients.php @@ -138,6 +138,32 @@ function getClientDatas($id) { function getClientContrats($id) { return getContratsList("date","DESC", array("client" => $id)); } function getClientAbsences($id) { return getClientAbsencesList("fin", "DESC", $id); } +function getClientComplementDuAtDate($id, $date) { + $val = 0; + + $sql = "SELECT" + ." CASE WHEN ISNULL( SUM(`complement`) - SUM(`complement_regle`) )" + ." THEN 0.00" + ." ELSE SUM(`complement`) - SUM(`complement_regle`)" + ." END as 'complement_du'" + ." FROM ".LIVRAISONS_PANIERS_TABLE + ." LEFT JOIN ".LIVRAISONS_TABLE." ON ".LIVRAISONS_PANIERS_TABLE.".`livraison` = ".LIVRAISONS_TABLE.".`ref`" + ." WHERE `contrat` IN (" + ." SELECT `ref` FROM ".CONTRATS_TABLE." WHERE `client`=".intval($id) + .")" + ." AND ".LIVRAISONS_TABLE.".date<'".$date."'"; + + $r = $GLOBALS['db_admin']['man']->select($sql,1); + + if(!$r['erreur']) $val = $r['datas']['complement_du']; + else { + $er = "sql: ".$sql."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 $val; +} + // ADD / UPDATE DATAS function getClientDatasFromRequest() { return getRequestTableDatas(CLIENTS_TABLE_STRUCT); } diff --git a/functions/functions_livraisons.php b/functions/functions_livraisons.php index f3eeefb..c4f57fb 100644 --- a/functions/functions_livraisons.php +++ b/functions/functions_livraisons.php @@ -117,11 +117,13 @@ function getLivraisonDatas($id) { $i["lieux"] = getLivraisonLieux($id); $i["paniers"] = getLivraisonPaniers($id); $i["paniers_contrats"] = getLivraisonPaniersContratsList($id); + $i["contrats_list"] = getLivraisonPaniersContratsList($id, $i["paniers_contrats"]); $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"]); + $i["paniers_eligibles"] = getLivraisonPaniersEligibles($i["paniers_groupe_ref"], $i["date"], $i["quinz_groupe"], $i['paniers']); + $i["emargement_list"] = getLivraisonEmargementList($i["paniers_eligibles"], $i["date"]); } else { $er = "sql: ".$sql."error: ".getReadableVar($r['erreur']); @@ -131,6 +133,42 @@ function getLivraisonDatas($id) { return $i; } +function getLivraisonEmargementList($paniers_eligibles, $date, $lieu=0) { + $list = array(); + + foreach($paniers_eligibles as $l) { + 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((float)$p["complement"]>0) $p["complement"] .= " €"; + else $p["complement"] = ""; + + if((float)$p["complement_regle"]>0) $p["complement_regle"] .= " €"; + else $p["complement_regle"] = ""; + } + else { + $p["complement_du"] = "/"; + $p["complement"] = "/"; + $p["complement_regle"] = "/"; + } + $list[] = $p; + } + } + } + } + + // ORDER + $list = orderListByKey($list, "client_prenom", "ASC"); + + return $list; +} + // ADD / UPDATE DATAS function getLivraisonDatasFromRequest() { @@ -261,7 +299,7 @@ function getLivraisonLieux($livraison) { // LIVRAISONS - PANIERS //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -function getLivraisonPaniersEligibles($paniers_groupe, $date, $quinz_groupe, $contrats_presents=array()) { +function getLivraisonPaniersEligibles($paniers_groupe, $date, $quinz_groupe, $paniers = array()) { $list = array(); $sql = "SELECT " @@ -269,6 +307,7 @@ function getLivraisonPaniersEligibles($paniers_groupe, $date, $quinz_groupe, $co .CONTRATS_TABLE.".`client` as 'client_ref'," .CLIENTS_TABLE.".`nom` as 'client_nom'," .CLIENTS_TABLE.".`prenom` as 'client_prenom'," + .CLIENTS_TABLE.".`tel` as 'client_tel'," .CONTRATS_TABLE.".`panier_type` as 'panier_type_ref'," .PANIERS_TYPES_TABLE.".`nom` as 'panier_type_nom'," .CONTRATS_TABLE.".`frequence`," @@ -298,7 +337,18 @@ function getLivraisonPaniersEligibles($paniers_groupe, $date, $quinz_groupe, $co if($i["frequence"] == "quinz") $i["frequence_print"] .= " (groupe ".$i["quinz_groupe"].")"; $i["absence"] = getClientAbsenceAtDate($i["client_ref"], $date); - if($i["nb_paniers_restants"]>0 || (int)$i['force_eligible']>0) { + if($i["nb_paniers_restants"]>0 || (int)$i['force_eligible']>0) { + // PRESENT + $i["present"] = array_key_exists(intval($i["contrat_ref"]), $paniers); + + // COMPLEMENT + $i["complement"] = 0; + $i["complement_regle"] = 0; + if($i["present"]) { + $i["complement"] = $paniers[$i["contrat_ref"]]["complement"]; + $i["complement_regle"] = $paniers[$i["contrat_ref"]]["complement_regle"]; + } + // GROUP BY - LIEU & TYPE DE PANNIER $lieu = intval($i['lieu_depot_ref']); $pType = intval($i['panier_type_ref']); @@ -324,12 +374,13 @@ function getLivraisonPaniersEligibles($paniers_groupe, $date, $quinz_groupe, $co } // 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"]++; } + } } } @@ -365,7 +416,7 @@ function getNbLivraisonForContratAtDate($contrat, $date) { } -function getLivraisonPaniers($livraison, $lieu=0) { +function getLivraisonPaniers($livraison, $lieu=0, $group_by_type=false) { $list = array(); $sql = getLivraisonsPaniersSelectBaseSQL(); @@ -381,14 +432,17 @@ function getLivraisonPaniers($livraison, $lieu=0) { if($i["frequence"] == "quinz") $i["frequence_print"] .= " (groupe ".$i["quinz_groupe"].')'; // GROUPE PAR TYPE DE PANIER - if(!array_key_exists($i["panier_type_ref"], $list)) { - $list[$i["panier_type_ref"]] = array( - "type_ref" => $i["panier_type_ref"], - "type_nom" => $i["panier_type_nom"], - "paniers" => array() - ); + if($group_by_type) { + if(!array_key_exists($i["panier_type_ref"], $list)) { + $list[$i["panier_type_ref"]] = array( + "type_ref" => $i["panier_type_ref"], + "type_nom" => $i["panier_type_nom"], + "paniers" => array() + ); + } + $list[$i["panier_type_ref"]]["paniers"][] = $i; } - $list[$i["panier_type_ref"]]["paniers"][] = $i; + else $list[$i["contrat_ref"]] = $i; } } else { @@ -396,20 +450,33 @@ function getLivraisonPaniers($livraison, $lieu=0) { $GLOBALS['errors'][] = "Une erreur est survenue durant la récupération de la liste des paniers de la livraison dans le base de données !".$er; } - $list = orderListByKey($list, "type_nom", "ASC"); + if($group_by_type) $list = orderListByKey($list, "type_nom", "ASC"); return $list; } -function getLivraisonPaniersContratsList($livraison) { +function getLivraisonPaniersContratsList($livraison, $ref_list = false) { $list = array(); - $sql = "SELECT `contrat` FROM ".LIVRAISONS_PANIERS_TABLE." WHERE `livraison`=".intval($livraison); + if(!is_array($ref_list)) $sql = "SELECT `contrat` FROM ".LIVRAISONS_PANIERS_TABLE." WHERE `livraison`=".intval($livraison); + else { + $inList = ""; + foreach($ref_list as $key => $ref) $inList .= $ref.(($key!==array_key_last($ref_list)) ? "," : ""); + $sql = getContratsTableSelectBaseSQL() + ." WHERE ".CONTRATS_TABLE.".`ref` IN ($inList)" + ." ORDER BY ".CLIENTS_TABLE.".`prenom`, ".CLIENTS_TABLE.".`nom` ASC"; + } $r = $GLOBALS['db_admin']['man']->select($sql); if(!$r['erreur']) { - foreach($r['datas'] as $i) $list[] = intval($i['contrat']); + foreach($r['datas'] as $i) { + if(!is_array($ref_list)) $list[] = intval($i['contrat']); + else { + $i["paniers_livres"] = getContratPaniersLivres($i['ref']); + $list[] = $i; + } + } } else { $er = "sql: ".$sql."error: ".getReadableVar($r['erreur']); @@ -477,6 +544,33 @@ function clearLivraisonPaniers($livraison) { ); } +//////////////////////////////////////////////////////////////////////// +// LIVRAISONS - COMPLEMENT ///////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + +function getLivraisonComplementFromRequest() { + $datas = array(); + + if(!isset($_REQUEST["complement"]) && !isset($_REQUEST["complement_regle"])) return "ERREUR : aucune modification de complement tranmis !"; + if(isset($_REQUEST["complement"])) $datas["complement"] = floatval($_REQUEST["complement"]); + if(isset($_REQUEST["complement_regle"])) $datas["complement_regle"] = floatval($_REQUEST["complement_regle"]); + + return $datas; +} + +function updateLivraisonComplement($livraison, $contrat, $datas) { + $condition = " WHERE livraison=$livraison AND contrat=$contrat"; + return updateDatasInTableByCondition( + $GLOBALS['db_admin']['man'], // DB MANAGER + LIVRAISONS_PANIERS_TABLE, // TABLE NAME + LIVRAISONS_PANIERS_TABLE_STRUCT,// TABLE STRUCTURE + $condition, // CONDITION + $datas, // DATAS + "au complement", // NULL STRING + "du complement" // ERROR STRING + ); +} + //////////////////////////////////////////////////////////////////////// // LIVRAISONS - LEGUMES //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// @@ -575,7 +669,7 @@ function clearLivraisonLegumes($livraison) { // PRINTS ////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -function exportLivraisonTemplateToPDF($templateFile, $outputFileName) { +function exportLivraisonTemplateToPDF($templateFile, $outputFileName, $orientation='portrait') { $GLOBALS['smarty'] -> assign('logo', PUBLIC_HTML_ADMIN.'img/logo.png'); $cssFiles = array( @@ -583,13 +677,14 @@ function exportLivraisonTemplateToPDF($templateFile, $outputFileName) { PUBLIC_HTML_ADMIN.'css/livraisons.css' ); $GLOBALS['smarty'] -> assign('cssFiles',$cssFiles); + $GLOBALS['smarty'] -> assign('orientation',$orientation); $html = $GLOBALS['smarty']->fetch($templateFile); // die($html); $dompdf = new Dompdf\Dompdf(); $dompdf->loadHtml($html); - $dompdf->setPaper('A4', 'portrait'); + $dompdf->setPaper('A4', $orientation); $options = $dompdf->getOptions(); $options->setIsRemoteEnabled(true); $dompdf->setOptions($options); diff --git a/paniers.sql b/paniers.sql index e81f449..08a7983 100644 --- a/paniers.sql +++ b/paniers.sql @@ -227,8 +227,9 @@ DEFAULT CHARSET=utf8; CREATE TABLE `livraisons_paniers` ( `livraison` smallint(5) UNSIGNED NOT NULL, `contrat` smallint(5) UNSIGNED NOT NULL, - `force_not_archive` tinyint(1) UNSIGNED NOT NULL DEFAULT '0', - `del` tinyint(1) UNSIGNED NOT NULL DEFAULT '0', + `complement` float(5,2) UNSIGNED NOT NULL DEFAULT '0', + `complement_regle` float(5,2) UNSIGNED NOT NULL DEFAULT '0', + `del` tinyint(1) UNSIGNED NOT NULL DEFAULT '0', UNIQUE (`livraison`, `contrat`), CONSTRAINT `livraisons_paniers_livraison_fk` FOREIGN KEY (`livraison`) REFERENCES `livraisons`(`ref`) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT `livraisons_paniers_contrat_fk` FOREIGN KEY (`contrat`) REFERENCES `contrats`(`ref`) ON DELETE RESTRICT ON UPDATE RESTRICT, @@ -288,4 +289,32 @@ CREATE VIEW `livraisons_nb_paniers` AS FROM `livraisons_paniers` GROUP BY `livraisons_paniers`.`livraison`; -COMMIT; +-- -------------------------------------------------------- +-- STRUCTURE DE LA VIEW `complements_contrats_status` +-- -------------------------------------------------------- + +CREATE VIEW `complements_contrats_status` AS + SELECT + `contrats`.`client`, + `contrat`, + SUM(`complement`) as 'complements', + SUM(`complement_regle`) as 'complements_regles', + ( SUM(`complement`) - SUM(`complement_regle`) ) as 'complements_dus' + FROM `livraisons_paniers` + LEFT JOIN `contrats` ON `livraisons_paniers`.`contrat` = `contrats`.`ref` + GROUP BY `contrat`; + +-- -------------------------------------------------------- +-- STRUCTURE DE LA VIEW `complements_clients_status` +-- -------------------------------------------------------- + +CREATE VIEW `complements_clients_status` AS + SELECT + `client`, + SUM(`complements`) as 'complements', + SUM(`complements_regles`) as 'complements_regles', + ( SUM(`complements`) - SUM(`complements_regles`) ) as 'complements_dus' + FROM `complements_contrats_status` + GROUP BY `client`; + +COMMIT; \ No newline at end of file diff --git a/public_html_admin/css/livraisons.css b/public_html_admin/css/livraisons.css index 861016e..2125779 100644 --- a/public_html_admin/css/livraisons.css +++ b/public_html_admin/css/livraisons.css @@ -42,6 +42,8 @@ border-collapse: collapse; box-sizing: border-box; margin: 0; + page-break-inside: avoid; + break-inside: avoid; } .formLivraison table.panier { margin-top: 10px; } @@ -85,6 +87,8 @@ .formLivraison table.panier tr.head > th.nom, .formLivraison table.panier tr.head > th.frequence { width: 50%; } +.formLivraison table.panier tr.head > th.complement, +.formLivraison table.panier tr.head > th.complement_regle { min-width: 100px; } .formLivraison table.panier tr.head > th.tarif, .formLivraison table.panier tr.head > th.quantite, .formLivraison table.panier tr.head > th.montant { text-align: center; min-width: 120px; } @@ -104,6 +108,10 @@ .formLivraison table.panier input.editable.legume { width: 100%; text-align: left; } .formLivraison table.panier input.editable.quantite { width: 70px; text-align: right; } +.formLivraison table.panier input.editable.complement, +.formLivraison table.panier input.editable.complement_regle { width: 90px; text-align: center; } + +.formLivraison table.panier td.editable { cursor: pointer; } /* TAB PANIERS */ @@ -133,10 +141,45 @@ #modalViewLivraison div.btnPrint { margin-right: 10px; } body.printLivraison { font-size: 8pt; } +body.printLivraison[orientation=landscape] { margin-top: -20px; } table.printHeader { width: 100%; margin-bottom: 10px; } table.printHeader th.titre { width: 25%; font-size: 10pt; vertical-align: middle; } table.printHeader th.page { width: 50%; font-size: 16pt; text-align: center; } table.printHeader th.logo { width: 25%; text-align: right; padding: 10pt; } table.printHeader th.logo > img { height: 50pt; } -.page_break { page-break-before: always; } \ No newline at end of file +.page_break { page-break-before: always; } + +table.emargement { + width: 100%; + border-collapse: true; +} + +table.emargement thead tr { background-color: rgba(51, 122, 183, .1); } + +table.emargement th, table.emargement td { + padding: 5px; + border: 1px dotted #333333; +} +table.emargement th { + font-weight: bold; +} + +table.emargement tbody td { + padding-top: 15px; + padding-bottom: 15px; +} + +table.emargement .center { text-align: center; } +table.emargement .tel { max-width: 40px; } +table.emargement .type { max-width: 30px; } +table.emargement .nb_paniers { max-width: 25px; } +table.emargement .complement { max-width: 40px; } +table.emargement .signature { max-width: 60px; } + +table.emargement tr.absent { background-color: #F0F0F0; } + +table.emargement tr.absent td.nom, +table.emargement tr.absent td.tel, +table.emargement tr.absent td.type, +table.emargement tr.absent td.nb_paniers { text-decoration: line-through; } \ No newline at end of file diff --git a/public_html_admin/js/clients.js b/public_html_admin/js/clients.js index 3de3540..1fe2eef 100644 --- a/public_html_admin/js/clients.js +++ b/public_html_admin/js/clients.js @@ -92,10 +92,23 @@ function modalViewClient_loadDatas(modal, id) { modal.find("td.tel").html( (datas.tel!="" && datas.tel!=null) ? ''+datas.tel+'' : "." ); modal.find("td.email").html( (datas.email!="" && datas.email!=null) ? ''+datas.email+'' : "."); + // COMPLEMENTS + comp = "."; + if(datas.complements>0 || datas.complements_regles>0 || datas.complements_dus>0) { + comp = number_format(datas.complements, 2)+" €"; + if(datas.complements_regles>0) { + comp += " / "+number_format(datas.complements_regles, 2)+" € réglé"; + comp += " => "+number_format(Math.abs(datas.complements_dus), 2)+((datas.complements_dus >= 0) ? " € à régler" : " € d'avoir"); + } + else if(datas.complements_dus>0) comp += " => "+number_format(Math.abs(datas.complements_dus), 2)+((datas.complements_dus >= 0) ? " € à régler" : " € d'avoir"); + } + modal.find("td.complements").html(comp); + // CONTRATS $.post(clientsConf.baseURL, { 'ref' : id, 'action' : 'modalView_getTab', 'tab' : 'contrats' }, function(result) { modal.find("div.tabContrats").html(result); }).fail(function() { alert("ERREUR SERVEUR ! (client modal view - load tab contrats)"); }); + // ABSENCES modalViewClient_loadTabAbsences(); @@ -113,6 +126,7 @@ function modalViewClient_clear(modal) { modal.find("td.nom").html(""); modal.find("td.tel").html(""); modal.find("td.email").html(""); + modal.find("td.complements").html(""); modal.find("div.tabContrats").html(""); modal.find("div.tabAbsences").html(""); diff --git a/public_html_admin/js/contrats.js b/public_html_admin/js/contrats.js index dc99245..f441562 100644 --- a/public_html_admin/js/contrats.js +++ b/public_html_admin/js/contrats.js @@ -126,6 +126,18 @@ function modalViewContrat_loadDatas(modal, id) { modal.find("td.nb_panier_livre").html(nb_panier_livre); modal.find("td.nb_panier_restant").html(datas.nb_paniers_restants + " / " + datas.nb_paniers); + // COMPLEMENTS + comp = "."; + if(datas.complements>0 || datas.complements_regles>0 || datas.complements_dus>0) { + comp = number_format(datas.complements, 2)+" €"; + if(datas.complements_regles>0) { + comp += " / "+number_format(datas.complements_regles, 2)+" € réglé"; + comp += " => "+number_format(Math.abs(datas.complements_dus), 2)+((datas.complements_dus >= 0) ? " € à régler" : " € d'avoir"); + } + else if(datas.complements_dus>0) comp += " => "+number_format(Math.abs(datas.complements_dus), 2)+((datas.complements_dus >= 0) ? " € à régler" : " € d'avoir"); + } + modal.find("td.complements").html(comp); + // PANIERS $.post(contratsConf.baseURL, { 'ref' : id, 'action' : 'modalView_getTab', 'tab' : 'paniers' }, function(result) { modal.find("div.tabPaniers").html(result); @@ -160,6 +172,8 @@ function modalViewContrat_clear(modal) { modal.find("td.nb_panier_livre").html(""); modal.find("td.nb_panier_restant").html(""); + modal.find("td.complements").html(""); + modal.find("div.tabPaniers").html(""); } diff --git a/public_html_admin/js/functions.js b/public_html_admin/js/functions.js index 9e95d05..d6dd549 100644 --- a/public_html_admin/js/functions.js +++ b/public_html_admin/js/functions.js @@ -718,7 +718,7 @@ function initFiltreInputNumber() { function initIntInput(elem) { elem.unbind('keypress').keypress( function(event) { keys = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57]; - if(event.keyCode==13) $(this).blur(); + if(event.keyCode==13) setTimeout(function() { elem.blur(); },50); if(jQuery.inArray(event.keyCode,keys)==-1) event.preventDefault(); }); } @@ -738,7 +738,7 @@ function initIntInputWithLimits(elem, min, max) { function initFloatInput(elem) { elem.unbind('keypress').unbind('keyup').keypress( function(event) { keys = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 46, 44]; - if(event.keyCode==13) $(this).blur(); + if(event.keyCode==13) setTimeout(function() { elem.blur(); },50); if(jQuery.inArray(event.keyCode,keys)==-1) event.preventDefault(); if((event.keyCode==46 || event.keyCode==44) && $(this).val().indexOf('.')>0) event.preventDefault(); }).keyup( function(event) { diff --git a/public_html_admin/js/livraisons.js b/public_html_admin/js/livraisons.js index 9fae684..0816a28 100644 --- a/public_html_admin/js/livraisons.js +++ b/public_html_admin/js/livraisons.js @@ -92,16 +92,15 @@ function initViewLivraison() { modalForm_initTabs(modalViewLivraison); // BTN PRINT - modalViewLivraison.find("div.btnPrint a").click(function(e) { - e.preventDefault(); $(this).blur(); - id = parseInt( modalViewLivraison.attr("view_id") ); - if(!id>0) return; - url = livraisonsConf.baseURL+"?ref="+id+"&action=getPDF&type="+$(this).attr("print_type"); - window.open(url, '_blank'); - }); + modalViewLivraison_initPrintBtn(); // CANCEL - modalViewLivraison.on('hidden.bs.modal', function() { modalViewLivraison_clear(modalViewLivraison); }); + modalViewLivraison.on('hidden.bs.modal', function(e) { modalViewLivraison_clear(modalViewLivraison); }); + + // EMPECHE LA FERMETURE SI ON EST ENTRAIN D'EDITER UN COMPLEMENT + modalViewLivraison.on('hide.bs.modal', function(e) { + if(modalViewLivraison.find("input.editable").length>0) e.preventDefault(); + }); } function modalViewLivraison_loadDatas(modal, id) { @@ -109,15 +108,25 @@ function modalViewLivraison_loadDatas(modal, id) { var datas = JSON.parse(jsonTxt); modal.find("small.db_ref > span").html(datas.ref); + // PRINT EMARGEMENT PAR LIEU + if(Object.values(datas.lieux).length>1) { + for(l in datas.lieux) { + li = $('
'); + a = $(''); + a.html("Emargement - "+datas.lieux[l].nom).attr("lieu", l); + li.append(a); + li.insertAfter(modal.find("#print_emargement")); + } + modalViewLivraison_initPrintBtn(); + } + modal.find("td.groupe").html(datas.paniers_groupe_nom); modal.find("td.date").html(datas.date_print); modal.find("td.quinz_groupe").html(datas.quinz_groupe); if(datas.paniers_contrats.length>0) { // PANIERS - $.post(livraisonsConf.baseURL, { 'ref' : id, 'action' : 'modalView_getTab', 'tab' : 'paniers' }, function(result) { - modal.find("div.tabPaniers").html(result); - }).fail(function() { alert("ERREUR SERVEUR (modal view livraison - load tab paniers)"); }); + modalViewLivraison_loadPaniers(); // COMPO if(datas.legumes.length>0) { @@ -156,6 +165,8 @@ function modalViewLivraison_clear(modal) { modal.find("small.db_ref > span").html(""); + modal.find(".print_emargement_par_lieu").remove(); + modal.find("td.groupe").html(""); modal.find("td.date").html(""); modal.find("td.quinz_groupe").html(""); @@ -165,6 +176,85 @@ function modalViewLivraison_clear(modal) { modal.find("div.tabLegumes").html("aucun légume"); } +function modalViewLivraison_loadPaniers() { + $.post(livraisonsConf.baseURL, { 'ref' : modalViewLivraison.attr("view_id"), 'action' : 'modalView_getTab', 'tab' : 'paniers', 'complements' : 1 }, function(result) { + modalViewLivraison.find("div.tabPaniers").html(result); + + // COMPLEMENT + modalViewLivraison.find("div.tabPaniers td.complement").each(function(n,e) { + $(this).addClass("editable").dblclick(function(e) { + e.preventDefault(); + val = parseFloat( $(this).html() ); + var ipt = $(""); + $(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) { + 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(); + }); + }); + + // COMPLEMENT REGLE + modalViewLivraison.find("div.tabPaniers td.complement_regle").each(function(n,e) { + $(this).addClass("editable").dblclick(function(e) { + e.preventDefault(); + val = parseFloat( $(this).html() ); + var ipt = $(""); + $(this).html("").append(ipt); + initFloatInput(ipt); + if(val>0) ipt.val(val).attr("old_value", val); + ipt.blur(function(e) { modalViewLivraison_saveComplement( $(this) ); }); + ipt.select(); + }); + }); + + }).fail(function() { alert("ERREUR SERVEUR (modal view livraison - load tab paniers)"); }); +} + +function modalViewLivraison_saveComplement(ipt) { + var td = ipt.parent(); + var tr = td.parent(); + val = parseFloat( ipt.val() ); + old_value = parseFloat( ipt.attr("old_value") ); + if(val>0 || val!=old_value) { + var datas = { + action : "saveComplement", + livraison : parseInt( modalViewLivraison.attr("view_id") ), + contrat : parseInt( tr.attr("contrat") ) + } + if(ipt.hasClass("complement")) datas.complement = val; + else datas.complement_regle = val; + + $.post(livraisonsConf.baseURL, datas, function(result) { + if(parseInt(result)==1) modalViewLivraison_loadPaniers(); + else { console.error(result); alert(result); } + }).fail(function() { alert("ERREUR SERVEUR (modal view livraison - save complement)"); }); + } + else td.html("."); +} + +function modalViewLivraison_initPrintBtn() { + modalViewLivraison.find("div.btnPrint a").unbind("click").click(function(e) { + e.preventDefault(); $(this).blur(); + id = parseInt( modalViewLivraison.attr("view_id") ); + if(!id>0) return; + url = livraisonsConf.baseURL+"?ref="+id+"&action=getPDF&type="+$(this).attr("print_type"); + if(isDefined($(this).attr("lieu"))) url += "&lieu="+$(this).attr("lieu"); + window.open(url, '_blank'); + }); +} + /***** MODAL FORM ADD/EDIT *****/ function modalFormLivraison_init(modal) { modal.find("modal").on("submit", function(e) { e.preventDefault(); }); diff --git a/public_html_admin/livraisons.php b/public_html_admin/livraisons.php index ef9115c..f295274 100644 --- a/public_html_admin/livraisons.php +++ b/public_html_admin/livraisons.php @@ -25,6 +25,7 @@ require_once(FUNCTIONS_DIR_PATH.'functions_livraisons.php'); require_once(FUNCTIONS_DIR_PATH.'functions_legumes.php'); include_once(FUNCTIONS_DIR_PATH.'functions_paniers_groupes.php'); include_once(FUNCTIONS_DIR_PATH.'functions_clients.php'); +include_once(FUNCTIONS_DIR_PATH.'functions_contrats.php'); $action = false; if(isset($_REQUEST['action'])) $action = strval( $_REQUEST['action'] ); @@ -50,16 +51,29 @@ if(isset($_REQUEST["ref"]) && (int)$_REQUEST["ref"]>0 && $action) { // GET PDF case "getPDF": { $GLOBALS['smarty'] -> assign('infos', $infos); + $types = array( - "full" => array("tpl" => "livraisons/prints/livraison_print_full.tpl", "fn" => ""), - "paniers" => array("tpl" => "livraisons/prints/livraison_print_paniers.tpl", "fn" => "-liste_paniers_"), - "compo" => array("tpl" => "livraisons/prints/livraison_print_compo.tpl", "fn" => "-compo_paniers_"), - "legumes" => array("tpl" => "livraisons/prints/livraison_print_legumes.tpl", "fn" => "-total_legumes_") + "full" => array("tpl" => "livraisons/prints/livraison_print_full.tpl", "fn" => "", "orientation" => "portrait"), + "paniers" => array("tpl" => "livraisons/prints/livraison_print_paniers.tpl", "fn" => "-liste_paniers_", "orientation" => "portrait"), + "compo" => array("tpl" => "livraisons/prints/livraison_print_compo.tpl", "fn" => "-compo_paniers_", "orientation" => "portrait"), + "legumes" => array("tpl" => "livraisons/prints/livraison_print_legumes.tpl", "fn" => "-total_legumes_", "orientation" => "portrait"), + "emargement" => array("tpl" => "livraisons/prints/livraison_print_emargement.tpl", "fn" => "-emargement_", "orientation" => "landscape") ); if(isset($_REQUEST['type']) && array_key_exists($_REQUEST['type'], $types)) { $type = $types[$_REQUEST['type']]; + if($_REQUEST['type'] == "emargement") { + $lieu_ref = 0; + $lieu_nom = ""; + if(isset($_REQUEST["lieu"]) && (int)$_REQUEST["lieu"]>0 && array_key_exists(intval($_REQUEST["lieu"]), $infos["lieux"])) { + $lieu_ref = intval($_REQUEST["lieu"]); + $lieu_nom = $infos["lieux"][$lieu_ref]["nom"]; + } + $GLOBALS['smarty'] -> assign('emargement_list', getLivraisonEmargementList($infos["paniers_eligibles"], $infos["date"], $lieu_ref)); + $GLOBALS['smarty'] -> assign('lieu_ref', $lieu_ref); + $GLOBALS['smarty'] -> assign('lieu_nom', $lieu_nom); + } $filename = "Livraison-".$infos["paniers_groupe_nom"].$type["fn"]."_".$infos["date"].".pdf"; - exportLivraisonTemplateToPDF($type["tpl"], $filename); + exportLivraisonTemplateToPDF($type["tpl"], $filename, $type["orientation"]); } die("NO TYPE"); } break; @@ -75,7 +89,12 @@ if(isset($_REQUEST["ref"]) && (int)$_REQUEST["ref"]>0 && $action) { // ADD PANIERS foreach($datas['paniers'] as $i => $contrat) { - $r = addLivraisonPanier(array( 'livraison' => $id, 'contrat' => intval($contrat))); + $datas = array( 'livraison' => $id, 'contrat' => intval($contrat) ); + if(array_key_exists($contrat, $infos["paniers"])) { + $datas["complement"] = $infos["paniers"][$contrat]["complement"]; + $datas["complement_regle"] = $infos["paniers"][$contrat]["complement_regle"]; + } + $r = addLivraisonPanier($datas); if($r!==true) die("ERREUR : une erreur est survenu durant l'enregistrement du panier de la livraison ($r)"); } @@ -171,6 +190,18 @@ switch($action) { $GLOBALS['smarty'] -> assign('lieux', $list); die( $GLOBALS['smarty']->fetch("livraisons/livraison_form_tab_paniers.tpl") ); } break; + // SAVE COMPLEMENT + case "saveComplement" : { + if(isset($_REQUEST["livraison"]) && (int)$_REQUEST["livraison"]>0) $livraison = intval($_REQUEST["livraison"]); + else die("ERREUR : aucune référence de livraison tranmis !"); + + if(isset($_REQUEST["contrat"]) && (int)$_REQUEST["contrat"]>0) $contrat = intval($_REQUEST["contrat"]); + else die("ERREUR : aucune référence de contrat tranmis !"); + + $datas = getLivraisonComplementFromRequest(); + if(is_array($datas)) die( strval(updateLivraisonComplement($livraison, $contrat, $datas)) ); + else die($datas); + } break; // DEFAULT - LIST default: { // GROUPE diff --git a/public_html_admin/templates/clients/client_modal_view.tpl b/public_html_admin/templates/clients/client_modal_view.tpl index 231f7b6..1012ae2 100644 --- a/public_html_admin/templates/clients/client_modal_view.tpl +++ b/public_html_admin/templates/clients/client_modal_view.tpl @@ -22,6 +22,7 @@