218 lines
10 KiB
PHP
218 lines
10 KiB
PHP
<?php
|
|
|
|
require_once('../init.php');
|
|
$GLOBALS['smarty']->assign('page','livraisons');
|
|
$GLOBALS['template'] = 'livraisons/livraisons_list.tpl';
|
|
$GLOBALS['smarty']->assign('secondbar','livraisons/livraisons_secondbar.tpl');
|
|
$jsFiles[] = PUBLIC_HTML_ADMIN.'js/livraisons.js';
|
|
$cssFiles[] = PUBLIC_HTML_ADMIN.'css/livraisons.css';
|
|
|
|
if($id>0 && $action) {
|
|
$infos = getLivraisonDatas($id);
|
|
switch($action) {
|
|
// AJAX GET DATAS
|
|
case "getDatas": die(json_encode($infos)); break;
|
|
// MODAL VIEW - GET TAB
|
|
case "modalView_getTab": {
|
|
$GLOBALS['smarty'] -> assign('infos', $infos);
|
|
$tabs = array(
|
|
"paniers" => "livraisons/livraison_modal_view_tab_paniers.tpl",
|
|
"compo" => "livraisons/livraison_modal_view_tab_compo.tpl",
|
|
"legumes" => "livraisons/livraison_modal_view_tab_legumes.tpl"
|
|
);
|
|
if(isset($_REQUEST['tab']) && array_key_exists($_REQUEST['tab'], $tabs)) die( $GLOBALS['smarty']->fetch($tabs[$_REQUEST['tab']]) );
|
|
die("NO TAB");
|
|
} break;
|
|
// GET PDF
|
|
case "getPDF": {
|
|
$GLOBALS['smarty'] -> assign('infos', $infos);
|
|
|
|
$types = array(
|
|
"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"),
|
|
"legumes_distrib" => array("tpl" => "livraisons/prints/livraison_print_legumes_distrib.tpl", "fn" => "-distribution_", "orientation" => "landscape"),
|
|
"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, $type["orientation"]);
|
|
}
|
|
die("NO TYPE");
|
|
} break;
|
|
// EDIT
|
|
case "edit": {
|
|
$datas = getLivraisonDatasFromRequest();
|
|
|
|
$r = updateLivraison($id,$datas);
|
|
|
|
if((int)$r>0) {
|
|
// CLEAR PANIERS
|
|
$r = clearLivraisonPaniers($id);
|
|
if($r!=true) die($r);
|
|
|
|
// ADD PANIERS
|
|
foreach($datas['paniers'] as $i => $contrat) {
|
|
$p = array( 'livraison' => $id, 'contrat' => intval($contrat) );
|
|
if(array_key_exists($contrat, $infos["paniers"])) {
|
|
$p["complement"] = $infos["paniers"][$contrat]["complement"];
|
|
$p["complement_regle"] = $infos["paniers"][$contrat]["complement_regle"];
|
|
}
|
|
$r = addLivraisonPanier($p);
|
|
if($r!==true) die("ERREUR : une erreur est survenu durant l'enregistrement du panier de la livraison ($r)");
|
|
}
|
|
|
|
// CLEAR LEGUMES
|
|
$r = clearLivraisonLegumes($id);
|
|
if($r!=true) die($r);
|
|
|
|
// ADD LEGUMES
|
|
foreach($datas['paniers_compo'] as $pRef => $p) {
|
|
foreach($p['legumes'] as $lRef => $l) {
|
|
$r = addLivraisonLegume(array(
|
|
'livraison' => $id,
|
|
'panier_type' => $p['ref'],
|
|
'legume' => $l['ref'],
|
|
'tarif' => $l['tarif_ref'],
|
|
'quantite' => $l['quantite']
|
|
));
|
|
if($r!==true) die("ERREUR : une erreur est survenu durant l'enregistrement du légume de la livraison ($r)");
|
|
}
|
|
}
|
|
|
|
die( "1" );
|
|
}
|
|
else die($r);
|
|
} break;
|
|
// ARCHIVE
|
|
case "archive": die( strval( archiveLivraison($id, true) ) ); break;
|
|
// UNARCHIVE
|
|
case "unarchive": die( strval( archiveLivraison($id, false) ) ); break;
|
|
// DELETE
|
|
case "delete" : {
|
|
$r = deleteLivraison($id);
|
|
if((int)$r>0) {
|
|
// DELETE PANIERS
|
|
$r = deleteLivraisonPaniers($id);
|
|
if((int)$r>0) {
|
|
// DELETE LEGUMES
|
|
$r = deleteLivraisonLegumes($id);
|
|
if((int)$r>0) die( "1" );
|
|
else die($r);
|
|
}
|
|
else die($r);
|
|
}
|
|
else die($r);
|
|
} break;
|
|
// DEFAULT
|
|
default: die("NO ACTION");
|
|
}
|
|
}
|
|
switch($action) {
|
|
// ADD
|
|
case "add": {
|
|
$datas = getLivraisonDatasFromRequest();
|
|
$r = addLivraison($datas);
|
|
|
|
if((int)$r>0) {
|
|
$id = $r;
|
|
|
|
// ADD PANIERS
|
|
foreach($datas['paniers'] as $i => $contrat) {
|
|
$r = addLivraisonPanier(array( 'livraison' => $id, 'contrat' => intval($contrat)));
|
|
if($r!==true) die("ERREUR : une erreur est survenu durant l'enregistrement du panier de la livraison ($r)");
|
|
}
|
|
|
|
// ADD LEGUMES
|
|
foreach($datas['paniers_compo'] as $pRef => $p) {
|
|
foreach($p['legumes'] as $lRef => $l) {
|
|
$r = addLivraisonLegume(array(
|
|
'livraison' => $id,
|
|
'panier_type' => $p['ref'],
|
|
'legume' => $l['ref'],
|
|
'tarif' => $l['tarif_ref'],
|
|
'quantite' => $l['quantite']
|
|
));
|
|
if($r!==true) die("ERREUR : une erreur est survenu durant l'enregistrement du légume de la livraison ($r)");
|
|
}
|
|
}
|
|
die( (string)$id );
|
|
}
|
|
else die($r);
|
|
} break;
|
|
// LAST QUINZ GROUPE
|
|
case "last_quinz_groupe": {
|
|
if(!isset($_REQUEST['groupe']) || !(int)$_REQUEST['groupe']>0) die("NO GROUPE");
|
|
if(!isset($_REQUEST['date'])) die("NO DATE");
|
|
$date = checkDateFormat($_REQUEST['date'], "mysql_date");
|
|
if(is_null($date)) die("WRONG DATE");
|
|
die( strval( getLivraisonLastQuinzGroupeAtDate(intval($_REQUEST['groupe']), $date) ) );
|
|
} break;
|
|
// PANIERS ELIGIBLES
|
|
case "paniers_eligibles": {
|
|
$list = getLivraisonPaniersEligibles(intval($_REQUEST['paniers_groupe']), $_REQUEST['date'], $_REQUEST['quinz_groupe']);
|
|
$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
|
|
$groupesList = getPaniersGroupesList();
|
|
$groupe = getRequestAndSessionSave("groupe", "livraisons_list_groupe", "groupe", "int", 0, $groupesList, true);
|
|
|
|
// ARCHIVE
|
|
$archive = getRequestAndSessionSave("archive", "livraisons_list_archive", "archive", "int", 0);
|
|
|
|
// LIMITS
|
|
$limits = array("start" => 0, "end" => LIST_NB_LIGNES_PAR_PAGE, "nbItemsByPage" => LIST_NB_LIGNES_PAR_PAGE, "max" => getNbLivraisonsInList($groupe, $archive));
|
|
if(isset($_REQUEST['startListAt']) && (int)$_REQUEST['startListAt']>0) {
|
|
$limits['start'] = intval($_REQUEST['startListAt']);
|
|
$limits['end'] = $limits['start'] + $limits['nbItemsByPage'];
|
|
if($limits['end'] > $limits['max']) $limits['end'] = $limits['max'];
|
|
}
|
|
$limits['rest'] = $limits['max'] - $limits['end'];
|
|
$GLOBALS['smarty'] -> assign('list_limits',$limits);
|
|
|
|
// LIST
|
|
$order = getListOrder('livraisons_list_order', 'livraisons_list_sens', $allowLivraisonsListOrder, "date", "DESC");
|
|
$list = getLivraisonsList($order["order"], $order["sens"], $groupe, $archive, $limits);
|
|
$GLOBALS['smarty'] -> assign('list',$list);
|
|
|
|
// LIST PART
|
|
if(isset($_REQUEST['startListAt']) && (int)$_REQUEST['startListAt']>0) {
|
|
$limits["list"] = $GLOBALS['smarty']->fetch("livraisons/livraisons_list_builder.tpl");
|
|
die(json_encode($limits));
|
|
}
|
|
|
|
// REQUIRED LIST
|
|
$GLOBALS['smarty'] -> assign('paniers_groupes_list', $groupesList);
|
|
|
|
// DISPLAY
|
|
display();
|
|
}
|
|
} |