From 1d5b45e5e1d62504fe84528fcd47ba40cf751298 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 11 Nov 2006 00:46:15 +0000 Subject: [PATCH] =?UTF-8?q?New:=20Ajout=20page=20admin=20pour=20purger=20l?= =?UTF-8?q?es=20fichiers=20de=20documents=20New:=20Quelques=20am=E9liorati?= =?UTF-8?q?ons=20mineures=20sur=20exp=E9ditions=20Trad:=20Un=20peu=20plus?= =?UTF-8?q?=20de=20traduction=20sur=20exp=E9ditions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/admin/tools/dolibarr_export.php | 2 +- htdocs/admin/tools/dolibarr_import.php | 28 +- htdocs/admin/tools/export.php | 2 +- htdocs/admin/tools/index.php | 1 + htdocs/admin/tools/pre.inc.php | 1 + htdocs/expedition/expedition.class.php | 29 +- htdocs/expedition/fiche.php | 204 ++-- htdocs/html.form.class.php | 11 +- .../menus/barre_left/eldy_backoffice.php | 1 + htdocs/langs/en_US/admin.lang | 7 + htdocs/langs/en_US/sendings.lang | 2 +- htdocs/langs/en_US/stocks.lang | 5 + htdocs/langs/fr_BE/sendings.lang | 2 +- htdocs/langs/fr_FR/admin.lang | 7 + htdocs/langs/fr_FR/sendings.lang | 2 +- htdocs/langs/fr_FR/stocks.lang | 5 + htdocs/lib/functions.inc.php | 78 +- htdocs/livraison/fiche.php | 49 +- htdocs/livraison/livraison.class.php | 1031 +++++++++-------- 19 files changed, 805 insertions(+), 662 deletions(-) diff --git a/htdocs/admin/tools/dolibarr_export.php b/htdocs/admin/tools/dolibarr_export.php index 74fd46d9c7d..1efb88a323d 100644 --- a/htdocs/admin/tools/dolibarr_export.php +++ b/htdocs/admin/tools/dolibarr_export.php @@ -570,6 +570,6 @@ if (window.parent.frames[1]) { \ No newline at end of file diff --git a/htdocs/admin/tools/dolibarr_import.php b/htdocs/admin/tools/dolibarr_import.php index 190e85db83f..35bd03c4ef4 100644 --- a/htdocs/admin/tools/dolibarr_import.php +++ b/htdocs/admin/tools/dolibarr_import.php @@ -23,8 +23,8 @@ \file htdocs/admin/tools/dolibarr_import.php \brief Page import de la base \version $Revision$ -*/ - +*/ + require("./pre.inc.php"); include_once $dolibarr_main_document_root."/lib/databases/".$conf->db->type.".lib.php"; @@ -36,16 +36,16 @@ if (! $user->admin) llxHeader(); -print_fiche_titre($langs->trans("Restore"),'','setup'); -print '
'; - -print $langs->trans("DatabaseName").' : '.$dolibarr_main_db_name.'
'; -print '
'; - - -print $langs->trans("FeatureNotYetAvailable"); - - -llxFooter(); - +print_fiche_titre($langs->trans("Restore"),'','setup'); +print '
'; + +print $langs->trans("DatabaseName").' : '.$dolibarr_main_db_name.'
'; +print '
'; + + +print $langs->trans("FeatureNotYetAvailable"); + + +llxFooter('$Date$ - $Revision$'); + ?> \ No newline at end of file diff --git a/htdocs/admin/tools/export.php b/htdocs/admin/tools/export.php index 7440f9a8271..db6a117e6db 100644 --- a/htdocs/admin/tools/export.php +++ b/htdocs/admin/tools/export.php @@ -196,5 +196,5 @@ print '
'; $time_end = time(); -llxFooter(); +llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/admin/tools/index.php b/htdocs/admin/tools/index.php index d88be9c6c72..6ee91c46e0a 100644 --- a/htdocs/admin/tools/index.php +++ b/htdocs/admin/tools/index.php @@ -52,6 +52,7 @@ print "
"; if ($message) print $message.'
'; +print $langs->trans("SystemToolsAreaDesc").'
'; diff --git a/htdocs/admin/tools/pre.inc.php b/htdocs/admin/tools/pre.inc.php index 23f30f33f46..9d0cc805992 100644 --- a/htdocs/admin/tools/pre.inc.php +++ b/htdocs/admin/tools/pre.inc.php @@ -41,6 +41,7 @@ function llxHeader($head = "", $urlp = "") $menu->add(DOL_URL_ROOT."/admin/tools/index.php", "SystemTools"); $menu->add_submenu(DOL_URL_ROOT."/admin/tools/dolibarr_export.php", $langs->trans("Backup")); $menu->add_submenu(DOL_URL_ROOT."/admin/tools/dolibarr_import.php", $langs->trans("Restore")); + $menu->add_submenu(DOL_URL_ROOT."/admin/tools/purge.php", $langs->trans("Purge")); left_menu($menu->liste); } diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index 9de805c4cb3..dd653f03c47 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -50,20 +50,16 @@ class Expedition extends CommonObject */ function Expedition($DB) { - $this->db = $DB; - $this->lignes = array(); + global $langs; - $this->sources[0] = "Proposition commerciale"; - $this->sources[1] = "Internet"; - $this->sources[2] = "Courrier"; - $this->sources[3] = "Téléphone"; - $this->sources[4] = "Fax"; - - $this->statuts[-1] = "Annulée"; - $this->statuts[0] = "Brouillon"; - $this->statuts[1] = "Validée"; - - $this->products = array(); + $this->db = $DB; + $this->lignes = array(); + + $this->statuts[-1] = $langs->trans("Canceled"); + $this->statuts[0] = $langs->trans("Draft"); + $this->statuts[1] = $langs->trans("Validated"); + + $this->products = array(); } /** @@ -729,6 +725,10 @@ class Expedition extends CommonObject } +/** + \class ExpeditionLigne + \brief Classe de gestion des lignes de bons d'expedition +*/ class ExpeditionLigne { var $db; @@ -743,7 +743,8 @@ class ExpeditionLigne var $libelle; // Label produit var $product_desc; // Description produit var $ref; - + + function ExpeditionLigne($DB) { $this->db=$DB; diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index e7c596ac973..d971c8e516f 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -48,7 +48,7 @@ if (!$user->rights->expedition->lire) // Sécurité accés client -if ($user->societe_id > 0) +if ($user->societe_id > 0) { $action = ''; $socid = $user->societe_id; @@ -59,20 +59,20 @@ if ($user->societe_id > 0) * Actions */ -if ($_POST["action"] == 'add') +if ($_POST["action"] == 'add') { // \todo Mettre id entrepot sur ligne detail expedition et non sur fiche expedition - + $db->begin(); - + // Creation de l'objet expedition $expedition = new Expedition($db); - + $expedition->date_expedition = time(); $expedition->note = $_POST["note"]; $expedition->commande_id = $_POST["commande_id"]; $expedition->entrepot_id = $_POST["entrepot_id"]; - + // On boucle sur chaque ligne de commande pour compléter objet expedition // avec qté à livrer $commande = new Commande($db); @@ -87,7 +87,7 @@ if ($_POST["action"] == 'add') $expedition->addline($_POST[$idl],$_POST[$qty]); } } - + $ret=$expedition->create($user); if ($ret > 0) { @@ -125,7 +125,7 @@ if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user-> if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') { - if ($user->rights->expedition->supprimer ) + if ($user->rights->expedition->supprimer ) { $expedition = new Expedition($db); $expedition->fetch($_GET["id"]); @@ -158,7 +158,7 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post { dolibarr_print_error($db,$result); exit; - } + } } @@ -175,7 +175,7 @@ $html = new Form($db); * Mode creation * *********************************************************************/ -if ($_GET["action"] == 'create') +if ($_GET["action"] == 'create') { print_titre($langs->trans("CreateASending")); @@ -382,11 +382,11 @@ if ($_GET["action"] == 'create') else { $this->error=$db->error(); - return -1; + return -1; } print ''; - $html->select_array('warehouse'.$i,$array,'',1,0,0); + $html->select_array('warehouse'.$i,$array,'',1,0,0); print ''; } } @@ -418,62 +418,62 @@ if ($_GET["action"] == 'create') dolibarr_print_error($db); } } -else +else /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ -{ +{ if ($_GET["id"] > 0) { $expedition = New Expedition($db); $result = $expedition->fetch($_GET["id"]); - + if ($expedition->id > 0) { $author = new User($db); $author->id = $expedition->user_author_id; $author->fetch(); - + $commande = New Commande($db); $commande->fetch($expedition->commande_id); - + $soc = new Societe($db); $soc->fetch($commande->socid); - + $h=0; $head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$expedition->id; $head[$h][1] = $langs->trans("SendingCard"); $hselected = $h; $h++; - + if ($conf->livraison->enabled && $expedition->livraison_id) { $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$expedition->livraison_id; $head[$h][1] = $langs->trans("DeliveryCard"); $h++; } - + dolibarr_fiche_head($head, $hselected, $langs->trans("Sending")); - + /* * Confirmation de la suppression * */ if ($_GET["action"] == 'delete') { - $html->form_confirm("fiche.php?id=$expedition->id","Supprimer l'expedition","Etes-vous sûr de vouloir supprimer cette expedition ?","confirm_delete"); + $html->form_confirm("fiche.php?id=$expedition->id",$langs->trans("DeleteSending"),"Etes-vous sûr de vouloir supprimer cette expedition ?","confirm_delete"); print '
'; } - + /* * Confirmation de la validation * */ if ($_GET["action"] == 'valid') { - $html->form_confirm("fiche.php?id=$expedition->id","Valider l'expédition","Etes-vous sûr de vouloir valider cette expédition ?","confirm_valid"); + $html->form_confirm("fiche.php?id=$expedition->id",$langs->trans("ValidateSending"),"Etes-vous sûr de vouloir valider cette expédition ?","confirm_valid"); print '
'; } /* @@ -482,10 +482,10 @@ else */ if ($_GET["action"] == 'annuler') { - $html->form_confirm("fiche.php?id=$expedition->id",$langs->trans("Cancel"),"Etes-vous sûr de vouloir annuler cette commande ?","confirm_cancel"); + $html->form_confirm("fiche.php?id=$expedition->id",$langs->trans("CancelSending"),"Etes-vous sûr de vouloir annuler cette commande ?","confirm_cancel"); print '
'; } - + /* * Commande */ @@ -494,67 +494,57 @@ else print '
'; print ''; } - + print ''; - + // Ref print ''; print ''; - + // Client print ''; print ''; print ""; - + // Commande liée print ''; print '\n"; print ''; - + // Commande liée print ''; print '\n"; print ''; - + // Date print ''; print '\n"; - print ''; + print ''; // Statut print ''; print '\n"; - print ''; - - if (!$conf->expedition->enabled && $conf->stock->enabled) - { - // Entrepot - $entrepot = new Entrepot($db); - $entrepot->fetch($expedition->entrepot_id); - print ''; - print ''; - print ''; - } - + print ''; + print "
'.$langs->trans("Ref").''.$expedition->ref.'
'.$langs->trans("Customer").''.$soc->getNomUrl(1).'
'.$langs->trans("RefOrder").''.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref."
'.$langs->trans("RefCustomerOrderShort").''.$commande->ref_client."
'.$langs->trans("Date").''.dolibarr_print_date($expedition->date,"%A %d %B %Y")."
'.$langs->trans("Status").''.$expedition->getLibStatut(4)."
'.$langs->trans("Warehouse").''.$entrepot->libelle.'
\n"; - + /* * Lignes produits */ echo '
'; - + $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande,"; $sql .= " e.fk_statut, ed.qty as qty_livre"; $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e"; $sql .= " WHERE e.rowid = ".$expedition->id." AND e.rowid = ed.fk_expedition AND cd.rowid = ed.fk_commande_ligne"; - + $resql = $db->query($sql); - + if ($resql) { $num_prod = $db->num_rows($resql); $i = 0; - + print ''; print ''; print ''; @@ -566,20 +556,24 @@ else { print ''; } + if ($conf->stock->enabled) + { + print ''; + } print "\n"; - + $var=true; while ($i < $num_prod) { $objp = $db->fetch_object($resql); - + $var=!$var; print ""; if ($objp->fk_product > 0) { $product = new Product($db); $product->fetch($objp->fk_product); - + print '\n"; + print "\n"; } + + // Qte commandé print ''; + + // Qte a expedier ou expedier print ''; - + + // Entrepot source + if ($conf->stock->enabled) + { + $entrepot = new Entrepot($db); + $entrepot->fetch($expedition->entrepot_id); + print ''; + } + + print ""; - + $i++; $var=!$var; } @@ -603,63 +610,66 @@ else { dolibarr_print_error($db); } - + print "
'.$langs->trans("Products").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyShipped").''.$langs->trans("WarehouseSource").'
'; print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; if ($objp->description) print '
'.nl2br($objp->description); @@ -587,13 +581,26 @@ else } else { - print "
".stripslashes(nl2br($objp->description))."".nl2br($objp->description)."'.$objp->qty_commande.''.$objp->qty_livre.''.$entrepot->getNomUrl(1).'
\n"; - + print "\n\n"; - - + + /* * Boutons actions */ - + if ($user->societe_id == 0) { print '
'; - - if ($expedition->statut == 0 && $user->rights->expedition->valider && $num_prod > 0) + + if (! eregi('^(valid|delete)',$_REQUEST["action"])) { - print ''.$langs->trans("Validate").''; - } - - if ($conf->livraison->enabled && $expedition->statut == 1 && $user->rights->expedition->livraison->creer && !$expedition->livraison_id) - { - print ''.$langs->trans("DeliveryOrder").''; - } - - if ($user->rights->expedition->lire && ($expedition->statut > 0)) - { - print ''.$langs->trans('BuildPDF').''; - } - - if ($expedition->brouillon && $user->rights->expedition->supprimer) - { - print ''.$langs->trans("Delete").''; - } - + if ($expedition->statut == 0 && $user->rights->expedition->valider && $num_prod > 0) + { + print ''.$langs->trans("Validate").''; + } + + if ($conf->livraison->enabled && $expedition->statut == 1 && $user->rights->expedition->livraison->creer && !$expedition->livraison_id) + { + print ''.$langs->trans("DeliveryOrder").''; + } + + if ($user->rights->expedition->lire && ($expedition->statut > 0)) + { + print ''.$langs->trans('BuildPDF').''; + } + + if ($expedition->brouillon && $user->rights->expedition->supprimer) + { + print ''.$langs->trans("Delete").''; + } + } + print '
'; } - print "\n"; + print "\n"; print "
"; - + /* * Documents générés */ - + $expeditionref = sanitize_string($expedition->ref); $filedir = $conf->expedition->dir_output . "/" .$expeditionref; - + $urlsource = $_SERVER["PHP_SELF"]."?id=".$expedition->id; - + $genallowed=$user->rights->expedition->lire && ($expedition->statut > 0); $delallowed=$user->rights->expedition->supprimer; //$genallowed=1; //$delallowed=0; - + $somethingshown=$html->show_documents('expedition',$expeditionref,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf); if ($genallowed && ! $somethingshown) $somethingshown=1; - + /* * Autres expeditions */ @@ -673,17 +683,17 @@ else $sql .= " AND cd.rowid = ed.fk_commande_ligne"; $sql .= " AND ed.fk_expedition = e.rowid"; $sql .= " ORDER BY cd.fk_product"; - + $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; - + if ($num) { if ($somethingshown) print '
'; - + print_titre($langs->trans("OtherSendingsForSameOrder")); print ''; print ''; @@ -692,7 +702,7 @@ else print ''; print ''; print "\n"; - + $var=True; while ($i < $num) { @@ -704,7 +714,7 @@ else { $product = new Product($db); $product->fetch($objp->fk_product); - + print ''; $i++; } - + print '
'.$langs->trans("Qty").''.$langs->trans("Date").'
'; print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.dolibarr_trunc($product->libelle,20); if ($objp->description) print nl2br(dolibarr_trunc($objp->description,24)); @@ -719,7 +729,7 @@ else print '
'; } $db->free($resql); @@ -727,14 +737,14 @@ else else { dolibarr_print_error($db); } - + print '
'; // Rien a droite - + print '
'; - + } else { diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index fdd35623c18..72c2f63b496 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -1563,11 +1563,14 @@ class Form print ''; - foreach ($formquestion as $key => $input) - { - if ($input['type'] == 'hidden') print ''; + if (is_array($formquestion)) + { + foreach ($formquestion as $key => $input) + { + if ($input['type'] == 'hidden') print ''; + } } - + print "
\n"; } diff --git a/htdocs/includes/menus/barre_left/eldy_backoffice.php b/htdocs/includes/menus/barre_left/eldy_backoffice.php index fa9ee27de6b..869aff12994 100644 --- a/htdocs/includes/menus/barre_left/eldy_backoffice.php +++ b/htdocs/includes/menus/barre_left/eldy_backoffice.php @@ -147,6 +147,7 @@ class MenuLeft { $newmenu->add(DOL_URL_ROOT."/admin/tools/index.php?leftmenu=admintools", $langs->trans("SystemTools")); if ($leftmenu=="admintools") $newmenu->add_submenu(DOL_URL_ROOT."/admin/tools/dolibarr_export.php", $langs->trans("Backup"),1); if ($leftmenu=="admintools") $newmenu->add_submenu(DOL_URL_ROOT."/admin/tools/dolibarr_import.php", $langs->trans("Restore"),1); + if ($leftmenu=="admintools") $newmenu->add_submenu(DOL_URL_ROOT."/admin/tools/purge.php", $langs->trans("Purge"),1); } $langs->load("users"); diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 32929c0ed02..33edcdb33e0 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -47,6 +47,13 @@ System=System SystemInfo=System informations SystemTools=System tools SystemToolsArea=System tools area +SystemToolsAreaDesc=This area provides administration features. Use menu to choose feature you're looking for. +PurgeAreaDesc=This page allow you to delete all files built or stored by Dolibarr (temporary files or all files in %s directory). Using this feature is not necessary. It is provided for users whose Dolibarr is hosted by a provider that does not offer permissions to delete files built by the web server. +PurgeDeleteTemporaryFiles=Delete all temporary files (no risk to loose data) +PurgeDeleteAllFilesInDocumentsDir=Delete all files in directory %s. Temporary files but also files attached to elements (third parties, invoices, ...) will be deleted. +PurgeRunNow=Run purge now +PurgeNothingToDelete=no directory to delete. +PurgeNDirectoriesDeleted=%s files or directories deleted. NewBackup=New backup Backup=Backup Restore=Restore diff --git a/htdocs/langs/en_US/sendings.lang b/htdocs/langs/en_US/sendings.lang index eea49995e79..f1edc6afc23 100644 --- a/htdocs/langs/en_US/sendings.lang +++ b/htdocs/langs/en_US/sendings.lang @@ -25,7 +25,7 @@ SendingsForSameOrder=Sendings for this order SendingsAndReceivingForSameOrder=Sendings and receivings for this order SendingsToValidate=Sending to validate StatusSendingDraft=Draft -StatusSendingValidated=Validated (products to ship or already received) +StatusSendingValidated=Validated (products to ship or already shipped) StatusSendingDraftShort=Draft StatusSendingValidatedShort=Validated SendingSheet=Sending sheet \ No newline at end of file diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 6c97c9732fd..1dca669bf35 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -5,6 +5,11 @@ NewWarehouse=New warehouse / Stock area MenuNewWarehouse=New warehouse WarehouseOpened=Warehouse opened WarehouseClosed=Warehouse closed +WarehouseSource=Source warehouse +WarehouseTarget=Target warehouse +ValidateSending=Delete sending +CancelSending=Cancel sending +DeleteSending=Delete sending Stock=Stock Stocks=Stocks Movement=Movement diff --git a/htdocs/langs/fr_BE/sendings.lang b/htdocs/langs/fr_BE/sendings.lang index 6adc7a43492..8bd6d0f9507 100644 --- a/htdocs/langs/fr_BE/sendings.lang +++ b/htdocs/langs/fr_BE/sendings.lang @@ -25,7 +25,7 @@ SendingsForSameOrder=Exp SendingsAndReceivingForSameOrder=Expéditions et réceptions pour cette commande SendingsToValidate=Expéditions à valider StatusSendingDraft=Brouillon -StatusSendingValidated=Validée (produits à envoyer ou reçus) +StatusSendingValidated=Validée (produits à envoyer ou envoyés) StatusSendingDraftShort=Brouillon StatusSendingValidatedShort=Validée SendingSheet=Bordereau d'expédition diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 83f89b5590a..8aa9fd84737 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -47,6 +47,13 @@ System=Syst SystemInfo=Infos Système SystemTools=Outils Système SystemToolsArea=Espace outils systèmes +SystemToolsAreaDesc=Cet espace offre des fonctions d'administration diverses. Utilisez le menu pour choisir la fonctionalité recherchée. +PurgeAreaDesc=Cette page vous permet d'effacer tous les fichiers construits ou stockés par Dolibarr (fichiers temporaires ou tous les fichiers du répertoire %s). L'utilisation de cette fonction n'est pas nécessaire. Elle est fourni pour les utilisateurs qui héberge Dolibarr chez un hébergeur qui n'offre pas les permissions de supprimer les fichiers sauvegardés par le serveur Web. +PurgeDeleteTemporaryFiles=Effacer tous les fichiers temporaires (pas de risque de perte de données) +PurgeDeleteAllFilesInDocumentsDir=Effacer tous les fichiers du répertoire %s. Les fichiers temporaires mais aussi les fichiers joints aux éléments (tiers, factures, ...) seront effacées. +PurgeRunNow=Lancer la purge maintenant +PurgeNothingToDelete=Aucun répertoire à supprimer. +PurgeNDirectoriesDeleted=%s fichiers ou répertoires supprimés. NewBackup=Nouvelle sauvegarde Backup=Sauvegarde Restore=Restauration diff --git a/htdocs/langs/fr_FR/sendings.lang b/htdocs/langs/fr_FR/sendings.lang index ce05fb80d71..9ebee54ff48 100644 --- a/htdocs/langs/fr_FR/sendings.lang +++ b/htdocs/langs/fr_FR/sendings.lang @@ -25,7 +25,7 @@ SendingsForSameOrder=Exp SendingsAndReceivingForSameOrder=Expéditions et réceptions pour cette commande SendingsToValidate=Expéditions à valider StatusSendingDraft=Brouillon -StatusSendingValidated=Validée (produits à envoyer ou reçus) +StatusSendingValidated=Validée (produits à envoyer ou envoyés) StatusSendingDraftShort=Brouillon StatusSendingValidatedShort=Validée SendingSheet=Bordereau d'expédition \ No newline at end of file diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index d1a4d51be45..7bc94cd81e1 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -5,6 +5,11 @@ NewWarehouse=Nouvel entrep MenuNewWarehouse=Nouvel entrepôt WarehouseOpened=Entrepôt ouvert WarehouseClosed=Entrepôt fermé +WarehouseSource=Entrepôt source +WarehouseTarget=Entrepôt cible +ValidateSending=Valider expédition +CancelSending=Annuler expédition +DeleteSending=Supprimer expédition Stock=Stock Stocks=Stocks Movement=Mouvement diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index 090f69b695e..c15111925c8 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -1613,12 +1613,49 @@ function dol_delete_file($file) } /** - \brief Effacement d'un répertoire - \param file Répertoire a effacer + \brief Effacement d'un répertoire + \param file Répertoire a effacer */ function dol_delete_dir($dir) { - return rmdir($dir); + return rmdir($dir); +} + +/** + \brief Effacement d'un répertoire et son arborescence + \param file Répertoire a effacer + \return int Nombre de fichier+repértoires supprimés +*/ +function dol_delete_dir_recursive($dir) +{ + $count=0; + + if ($handle = opendir("$dir")) + { + while (false !== ($item = readdir($handle))) + { + if ($item != "." && $item != "..") + { + if (is_dir("$dir/$item")) + { + dol_delete_dir_recursive("$dir/$item"); + } + else + { + unlink("$dir/$item"); + $count++; + //echo " removing $dir/$item
\n"; + } + } + } + closedir($handle); + rmdir($dir); + $count++; + //echo "removing $dir
\n"; + } + + //echo "return=".$count; + return $count; } @@ -1984,22 +2021,29 @@ function dolibarr_dir_list($path, $types="all", $recursive=0, $filter="", $exclu // Check if file is qualified if (eregi('^\.',$file)) $qualified=0; - if ($filter && ! eregi($filter,$file)) $qualified=0; if ($excludefilter && eregi($excludefilter,$file)) $qualified=0; +// print "path=$path file=$file
\n"; + if ($qualified) { // Check whether this is a file or directory and whether we're interested in that type if ((is_dir($path."/".$file)) && (($types=="directories") || ($types=="all"))) { - // Add file into file_list array + // Add entry into file_list array if ($sortcriteria == 'date') $filedate=filemtime($path."/".$file); if ($sortcriteria == 'size') $filesize=filesize($path."/".$file); - $file_list[] = array( - "name" => $file, - "date" => $filedate, - "size" => $filesize - ); + + if (! $filter || eregi($filter,$path.'/'.$file)) + { + $file_list[] = array( + "name" => $file, + "fullname" => $path.'/'.$file, + "date" => $filedate, + "size" => $filesize + ); + } + // if we're in a directory and we want recursive behavior, call this function again if ($recursive) { @@ -2011,11 +2055,15 @@ function dolibarr_dir_list($path, $types="all", $recursive=0, $filter="", $exclu // Add file into file_list array if ($sortcriteria == 'date') $filedate=filemtime($path."/".$file); if ($sortcriteria == 'size') $filesize=filesize($path."/".$file); - $file_list[] = array( - "name" => $file, - "date" => $filedate, - "size" => $filesize - ); + if (! $filter || eregi($filter,$path.'/'.$file)) + { + $file_list[] = array( + "name" => $file, + "fullname" => $path.'/'.$file, + "date" => $filedate, + "size" => $filesize + ); + } } } } diff --git a/htdocs/livraison/fiche.php b/htdocs/livraison/fiche.php index 7e7b70aeb0c..a80d397ff2f 100644 --- a/htdocs/livraison/fiche.php +++ b/htdocs/livraison/fiche.php @@ -30,8 +30,9 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); -require_once(DOL_DOCUMENT_ROOT."/livraison/mods/modules_livraison.php"); require_once(DOL_DOCUMENT_ROOT."/expedition/expedition.class.php"); +require_once(DOL_DOCUMENT_ROOT."/livraison/livraison.class.php"); +require_once(DOL_DOCUMENT_ROOT."/livraison/mods/modules_livraison.php"); if ($conf->stock->enabled) require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php"); $langs->load("sendings"); @@ -347,7 +348,7 @@ else { if ($_GET["id"] > 0) { - $livraison = New Livraison($db); + $livraison = new Livraison($db); $result = $livraison->fetch($_GET["id"]); if ( $livraison->id > 0) @@ -435,6 +436,11 @@ else print ''.dolibarr_print_date($livraison->date_creation,'%A %d %B %Y')."\n"; print ''; + // Statut + print ''.$langs->trans("Status").''; + print ''.$livraison->getLibStatut(4)."\n"; + print ''; + if (!$conf->expedition->enabled && $conf->stock->enabled) { // Entrepot @@ -519,25 +525,28 @@ else { print '
'; - if ($livraison->statut == 0 && $user->rights->expedition->livraison->valider && $num_prod > 0) + if (! eregi('^(valid|delete)',$_REQUEST["action"])) { - print ''.$langs->trans("Validate").''; - } - - print ''.$langs->trans('BuildPDF').''; - - if ($livraison->brouillon && $user->rights->expedition->livraison->supprimer) - { - if ($conf->expedition->enabled) - { - print ''.$langs->trans("Delete").''; - } - else - { - print ''.$langs->trans("Delete").''; - } - } - + if ($livraison->statut == 0 && $user->rights->expedition->livraison->valider && $num_prod > 0) + { + print ''.$langs->trans("Validate").''; + } + + print ''.$langs->trans('BuildPDF').''; + + if ($livraison->brouillon && $user->rights->expedition->livraison->supprimer) + { + if ($conf->expedition->enabled) + { + print ''.$langs->trans("Delete").''; + } + else + { + print ''.$langs->trans("Delete").''; + } + } + } + print '
'; } print "\n"; diff --git a/htdocs/livraison/livraison.class.php b/htdocs/livraison/livraison.class.php index 945a78d51f1..d054bccc5bc 100644 --- a/htdocs/livraison/livraison.class.php +++ b/htdocs/livraison/livraison.class.php @@ -30,6 +30,7 @@ require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT."/expedition/expedition.class.php"); +require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php"); /** @@ -51,313 +52,449 @@ class Livraison extends CommonObject */ function Livraison($DB) { - $this->db = $DB; - $this->lignes = array(); + global $langs; - $this->statuts[-1] = "Annulée"; - $this->statuts[0] = "Brouillon"; - $this->statuts[1] = "Validée"; - - $this->products = array(); + $this->db = $DB; + $this->lignes = array(); + + $this->statuts[-1] = $langs->trans("Canceled"); + $this->statuts[0] = $langs->trans("Draft"); + $this->statuts[1] = $langs->trans("Validated"); + + $this->products = array(); } - /** - * \brief Créé bon de livraison en base - * \param user Objet du user qui crée - * \return int <0 si erreur, id livraison créée si ok - */ - function create($user) - { - global $conf; - - dolibarr_syslog("Livraison::create "); - - require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php"; - $error = 0; - - /* On positionne en mode brouillon le bon de livraison */ - $this->brouillon = 1; - - $this->user = $user; - - $this->db->begin(); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."livraison (date_creation, fk_user_author, fk_adresse_livraison"; - if ($this->commande_id) $sql.= ", fk_commande"; - if ($this->expedition_id) $sql.= ", fk_expedition"; - $sql.= ")"; - $sql.= " VALUES (now(), $user->id, $this->adresse_livraison_id"; - if ($this->commande_id) $sql.= ", $this->commande_id"; - if ($this->expedition_id) $sql.= ", $this->expedition_id"; - $sql.= ")"; - - $resql=$this->db->query($sql); - if ($resql) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."livraison"); - - $numref="(PROV".$this->id.")"; - $sql = "UPDATE ".MAIN_DB_PREFIX."livraison "; - $sql.= "SET ref='".addslashes($numref)."' WHERE rowid=".$this->id; - $resql=$this->db->query($sql); - if ($resql) - { - if (! $conf->expedition->enabled) - { - $commande = new Commande($this->db); - $commande->id = $this->commande_id; - $this->lignes = $commande->fetch_lignes(); - } - - - /* - * Insertion des produits dans la base - */ - for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) - { - if (! $this->create_line(0, $this->lignes[$i]->commande_ligne_id, $this->lignes[$i]->qty)) - { - $error++; - } - } - - if (! $conf->expedition->enabled) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; - $sql.= " SET fk_statut = 2"; - $sql.= " WHERE rowid=".$this->commande_id; - $resql=$this->db->query($sql); - if (! $resql) - { - $error++; - } - } - - if ($error==0) - { - $this->db->commit(); - return $this->id; - } - else - { - $error++; - $this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; - dolibarr_syslog("Livraison::create Error -3 ".$this->error); - $this->db->rollback(); - return -3; - } - } - else - { - $error++; - $this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; - dolibarr_syslog("Livraison::create Error -2 ".$this->error); - $this->db->rollback(); - return -2; - } - } - else - { - $error++; - $this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; - dolibarr_syslog("Livraison::create Error -1 ".$this->error); - $this->db->rollback(); - return -1; - } - } - - /** - * - * - */ - function create_line($transaction, $commande_ligne_id, $qty) - { - $error = 0; - $idprod = 0; - $j = 0; - - while (($j < sizeof($this->commande->lignes)) && idprod == 0) - { - if ($this->commande->lignes[$j]->id == $commande_ligne_id) - { - $idprod = $this->commande->lignes[$j]->fk_product; - } - $j++; - } - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."livraisondet (fk_livraison, fk_commande_ligne, qty)"; - $sql .= " VALUES ($this->id,".$commande_ligne_id.",".$qty.")"; - - if (! $this->db->query($sql) ) - { - $error++; - } - - if ($error == 0 ) - { - return 1; - } - } - - /** - * - * Lit un bon de livraison - * - */ - function fetch ($id) - { - global $conf; - - $sql = "SELECT l.rowid, l.date_creation, l.date_valid, l.ref, l.fk_user_author,"; - $sql .=" l.fk_statut, l.fk_commande, l.fk_expedition, l.fk_user_valid, l.note, l.note_public"; - $sql .= ", ".$this->db->pdate("l.date_livraison")." as date_livraison, l.fk_adresse_livraison, l.model_pdf"; - $sql .= ", c.fk_soc"; - $sql .= " FROM ".MAIN_DB_PREFIX."livraison as l, ".MAIN_DB_PREFIX."commande as c"; - $sql .= " WHERE l.rowid = ".$id." AND c.rowid = l.fk_commande"; - - $result = $this->db->query($sql) ; - - if ( $result ) - { - $obj = $this->db->fetch_object($result); - - $this->id = $obj->rowid; - $this->date_creation = $obj->date_creation; - $this->date_valid = $obj->date_valid; - $this->ref = $obj->ref; - $this->socid = $obj->fk_soc; - $this->statut = $obj->fk_statut; - $this->commande_id = $obj->fk_commande; - $this->expedition_id = $obj->fk_expedition; - $this->user_author_id = $obj->fk_user_author; - $this->user_valid_id = $obj->fk_user_valid; - $this->date_livraison = $obj->date_livraison; - $this->adresse_livraison_id = $obj->fk_adresse_livraison; - $this->note = $obj->note; - $this->note_public = $obj->note_public; - $this->modelpdf = $obj->model_pdf; - $this->db->free(); - - if ($this->statut == 0) $this->brouillon = 1; - - $file = $conf->livraison->dir_output . "/" .get_exdir($livraison->id,2) . "/" . $this->id.".pdf"; - $this->pdf_filename = $file; - - return 1; - } - else - { - $this->error=$this->db->error(); - return -1; - } - } - - /** - * \brief Valide l'expedition, et met a jour le stock si stock géré - * \param user Objet de l'utilisateur qui valide - * \return int - */ - function valid($user) - { - global $conf; - - require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php"; - - dolibarr_syslog("livraison.class.php::valid begin"); - - $this->db->begin(); - - $error = 0; - - if ($user->rights->expedition->livraison->valider) - { - if (defined('LIVRAISON_ADDON')) - { - if (is_readable(DOL_DOCUMENT_ROOT .'/livraison/mods/'.LIVRAISON_ADDON.'.php')) - { - require_once DOL_DOCUMENT_ROOT .'/livraison/mods/'.LIVRAISON_ADDON.'.php'; - - // Definition du nom de module de numerotation de commande - $modName=LIVRAISON_ADDON; - - // Recuperation de la nouvelle reference - $objMod = new $modName($this->db); - $soc = new Societe($this->db); - $soc->fetch($this->socid); - - // on vérifie si le bon de livraison est en numérotation provisoire - $livref = substr($this->ref, 1, 4); - if ($livref == PROV) - { - $num = $objMod->livraison_get_num($soc); - } - else - { - $num = $this->ref; - } - - // \todo Tester si non dejà au statut validé. Si oui, on arrete afin d'éviter - // de décrémenter 2 fois le stock. - - $sql = "UPDATE ".MAIN_DB_PREFIX."livraison "; - $sql.= " SET ref='".addslashes($num)."', fk_statut = 1, date_valid=now(), fk_user_valid=".$user->id; - $sql.= " WHERE rowid = $this->id AND fk_statut = 0"; - $resql=$this->db->query($sql); + /** + * \brief Créé bon de livraison en base + * \param user Objet du user qui crée + * \return int <0 si erreur, id livraison créée si ok + */ + function create($user) + { + global $conf; + + dolibarr_syslog("Livraison::create "); + + $error = 0; + + /* On positionne en mode brouillon le bon de livraison */ + $this->brouillon = 1; + + $this->user = $user; + + $this->db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."livraison (date_creation, fk_user_author, fk_adresse_livraison"; + if ($this->commande_id) $sql.= ", fk_commande"; + if ($this->expedition_id) $sql.= ", fk_expedition"; + $sql.= ")"; + $sql.= " VALUES (now(), $user->id, $this->adresse_livraison_id"; + if ($this->commande_id) $sql.= ", $this->commande_id"; + if ($this->expedition_id) $sql.= ", $this->expedition_id"; + $sql.= ")"; + + $resql=$this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."livraison"); + + $numref="(PROV".$this->id.")"; + $sql = "UPDATE ".MAIN_DB_PREFIX."livraison "; + $sql.= "SET ref='".addslashes($numref)."' WHERE rowid=".$this->id; + $resql=$this->db->query($sql); if ($resql) { - // Si module stock géré et que expedition faite depuis un entrepot - if (!$conf->expedition->enabled && $conf->stock->enabled && $this->entrepot_id) + if (! $conf->expedition->enabled) { - - //Enregistrement d'un mouvement de stock pour chaque produit de l'expedition - - - dolibarr_syslog("livraison.class.php::valid enregistrement des mouvements"); - - $sql = "SELECT cd.fk_product, ld.qty "; - $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld"; - $sql.= " WHERE ld.fk_livraison = $this->id AND cd.rowid = ld.fk_commande_ligne"; - + $commande = new Commande($this->db); + $commande->id = $this->commande_id; + $this->lignes = $commande->fetch_lignes(); + } + + + /* + * Insertion des produits dans la base + */ + for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) + { + if (! $this->create_line(0, $this->lignes[$i]->commande_ligne_id, $this->lignes[$i]->qty)) + { + $error++; + } + } + + if (! $conf->expedition->enabled) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; + $sql.= " SET fk_statut = 2"; + $sql.= " WHERE rowid=".$this->commande_id; + $resql=$this->db->query($sql); + if (! $resql) + { + $error++; + } + } + + if ($error==0) + { + $this->db->commit(); + return $this->id; + } + else + { + $error++; + $this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; + dolibarr_syslog("Livraison::create Error -3 ".$this->error); + $this->db->rollback(); + return -3; + } + } + else + { + $error++; + $this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; + dolibarr_syslog("Livraison::create Error -2 ".$this->error); + $this->db->rollback(); + return -2; + } + } + else + { + $error++; + $this->error=$this->db->error()." - sql=".$this->db->lastqueryerror; + dolibarr_syslog("Livraison::create Error -1 ".$this->error); + $this->db->rollback(); + return -1; + } + } + + /** + * + * + */ + function create_line($transaction, $commande_ligne_id, $qty) + { + $error = 0; + $idprod = 0; + $j = 0; + + while (($j < sizeof($this->commande->lignes)) && idprod == 0) + { + if ($this->commande->lignes[$j]->id == $commande_ligne_id) + { + $idprod = $this->commande->lignes[$j]->fk_product; + } + $j++; + } + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."livraisondet (fk_livraison, fk_commande_ligne, qty)"; + $sql .= " VALUES ($this->id,".$commande_ligne_id.",".$qty.")"; + + if (! $this->db->query($sql) ) + { + $error++; + } + + if ($error == 0 ) + { + return 1; + } + } + + /** + * + * Lit un bon de livraison + * + */ + function fetch ($id) + { + global $conf; + + $sql = "SELECT l.rowid, l.date_creation, l.date_valid, l.ref, l.fk_user_author,"; + $sql .=" l.fk_statut, l.fk_commande, l.fk_expedition, l.fk_user_valid, l.note, l.note_public"; + $sql .= ", ".$this->db->pdate("l.date_livraison")." as date_livraison, l.fk_adresse_livraison, l.model_pdf"; + $sql .= ", c.fk_soc"; + $sql .= " FROM ".MAIN_DB_PREFIX."livraison as l, ".MAIN_DB_PREFIX."commande as c"; + $sql .= " WHERE l.rowid = ".$id." AND c.rowid = l.fk_commande"; + + $result = $this->db->query($sql) ; + + if ( $result ) + { + $obj = $this->db->fetch_object($result); + + $this->id = $obj->rowid; + $this->date_creation = $obj->date_creation; + $this->date_valid = $obj->date_valid; + $this->ref = $obj->ref; + $this->socid = $obj->fk_soc; + $this->statut = $obj->fk_statut; + $this->commande_id = $obj->fk_commande; + $this->expedition_id = $obj->fk_expedition; + $this->user_author_id = $obj->fk_user_author; + $this->user_valid_id = $obj->fk_user_valid; + $this->date_livraison = $obj->date_livraison; + $this->adresse_livraison_id = $obj->fk_adresse_livraison; + $this->note = $obj->note; + $this->note_public = $obj->note_public; + $this->modelpdf = $obj->model_pdf; + $this->db->free(); + + if ($this->statut == 0) $this->brouillon = 1; + + $file = $conf->livraison->dir_output . "/" .get_exdir($livraison->id,2) . "/" . $this->id.".pdf"; + $this->pdf_filename = $file; + + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } + + /** + * \brief Valide l'expedition, et met a jour le stock si stock gér + * \param user Objet de l'utilisateur qui valide + * \return int + */ + function valid($user) + { + global $conf; + + dolibarr_syslog("livraison.class.php::valid begin"); + + $this->db->begin(); + + $error = 0; + + if ($user->rights->expedition->livraison->valider) + { + if (defined('LIVRAISON_ADDON')) + { + if (is_readable(DOL_DOCUMENT_ROOT .'/livraison/mods/'.LIVRAISON_ADDON.'.php')) + { + require_once DOL_DOCUMENT_ROOT .'/livraison/mods/'.LIVRAISON_ADDON.'.php'; + + // Definition du nom de module de numerotation de commande + $modName=LIVRAISON_ADDON; + + // Recuperation de la nouvelle reference + $objMod = new $modName($this->db); + $soc = new Societe($this->db); + $soc->fetch($this->socid); + + // on vérifie si le bon de livraison est en numérotation provisoire + $livref = substr($this->ref, 1, 4); + if ($livref == PROV) + { + $num = $objMod->livraison_get_num($soc); + } + else + { + $num = $this->ref; + } + + // \todo Tester si non dejà au statut validé. Si oui, on arrete afin d'éviter + // de décrémenter 2 fois le stock. + + $sql = "UPDATE ".MAIN_DB_PREFIX."livraison "; + $sql.= " SET ref='".addslashes($num)."', fk_statut = 1, date_valid=now(), fk_user_valid=".$user->id; + $sql.= " WHERE rowid = $this->id AND fk_statut = 0"; $resql=$this->db->query($sql); if ($resql) { - $num = $this->db->num_rows($resql); - $i=0; - while($i < $num) + // Si module stock géré et que expedition faite depuis un entrepot + if (!$conf->expedition->enabled && $conf->stock->enabled && $this->entrepot_id) { - dolibarr_syslog("livraison.class.php::valid movment $i"); - - $obj = $this->db->fetch_object($resql); - - $mouvS = new MouvementStock($this->db); - $result=$mouvS->livraison($user, $obj->fk_product, $this->entrepot_id, $obj->qty); - if ($result < 0) + + //Enregistrement d'un mouvement de stock pour chaque produit de l'expedition + + + dolibarr_syslog("livraison.class.php::valid enregistrement des mouvements"); + + $sql = "SELECT cd.fk_product, ld.qty "; + $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld"; + $sql.= " WHERE ld.fk_livraison = $this->id AND cd.rowid = ld.fk_commande_ligne"; + + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i=0; + while($i < $num) + { + dolibarr_syslog("livraison.class.php::valid movment $i"); + + $obj = $this->db->fetch_object($resql); + + $mouvS = new MouvementStock($this->db); + $result=$mouvS->livraison($user, $obj->fk_product, $this->entrepot_id, $obj->qty); + if ($result < 0) + { + $this->db->rollback(); + $this->error=$this->db->error()." - sql=$sql"; + dolibarr_syslog("livraison.class.php::valid ".$this->error); + return -3; + } + $i++; + } + + } + else { $this->db->rollback(); $this->error=$this->db->error()." - sql=$sql"; dolibarr_syslog("livraison.class.php::valid ".$this->error); - return -3; + return -2; + } - $i++; } - + + // On efface le répertoire de pdf provisoire + $livraisonref = sanitize_string($this->ref); + if ($conf->expedition->dir_output) + { + $dir = $conf->livraison->dir_output . "/" . $livraisonref ; + $file = $dir . "/" . $livraisonref . ".pdf"; + if (file_exists($file)) + { + if (!dol_delete_file($file)) + { + $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); + return 0; + } + } + if (file_exists($dir)) + { + if (!dol_delete_dir($dir)) + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + return 0; + } + } + } + + dolibarr_syslog("livraison.class.php::valid ok"); } else { $this->db->rollback(); $this->error=$this->db->error()." - sql=$sql"; dolibarr_syslog("livraison.class.php::valid ".$this->error); - return -2; - + return -1; } } - + } + } + else + { + $this->error="Non autorise"; + dolibarr_syslog("livraison.class.php::valid ".$this->error); + return -1; + } + + $this->db->commit(); + dolibarr_syslog("livraison.class.php::valid commit"); + return 1; + } + + /** \brief Créé le bon de livraison depuis une expédition existante + \param user Utilisateur qui crée + \param sending_id Id de l'expédition qui sert de modèle + */ + function create_from_sending($user, $sending_id) + { + $expedition = new Expedition($this->db); + $result=$expedition->fetch($sending_id); + + $this->lignes = array(); + $this->date_livraison = time(); + $this->expedition_id = $sending_id; + + for ($i = 0 ; $i < sizeof($expedition->lignes) ; $i++) + { + $LivraisonLigne = new LivraisonLigne($this->db); + $LivraisonLigne->commande_ligne_id = $expedition->lignes[$i]->commande_ligne_id; + $LivraisonLigne->libelle = $expedition->lignes[$i]->libelle; + $LivraisonLigne->description = $expedition->lignes[$i]->product_desc; + $LivraisonLigne->qty = $expedition->lignes[$i]->qty_expedition; + $LivraisonLigne->fk_product = $expedition->lignes[$i]->fk_product; + $LivraisonLigne->ref = $expedition->lignes[$i]->ref; + $this->lignes[$i] = $LivraisonLigne; + } + + $this->commande_id = $expedition->commande_id; + $this->note = $expedition->note; + $this->projetid = $expedition->projetidp; + $this->date_livraison = $expedition->date_livraison; + $this->adresse_livraison_id = $expedition->adresse_livraison_id; + + return $this->create($user); + } + + + /** + * Ajoute une ligne + * + */ + function addline( $id, $qty ) + { + $num = sizeof($this->lignes); + $ligne = new livraisonLigne($this->db); + + $ligne->commande_ligne_id = $id; + $ligne->qty = $qty; + + $this->lignes[$num] = $ligne; + } + + /** + * + * + */ + function delete_line($idligne) + { + if ($this->statut == 0) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet WHERE rowid = $idligne"; + + if ($this->db->query($sql) ) + { + $this->update_price(); + + return 1; + } + else + { + return 0; + } + } + } + + /** + * Supprime la fiche + * + */ + function delete() + { + $this->db->begin(); + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraisondet WHERE fk_livraison = $this->id ;"; + if ( $this->db->query($sql) ) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison WHERE rowid = $this->id;"; + if ( $this->db->query($sql) ) + { + $this->db->commit(); + // On efface le répertoire de pdf provisoire - $livraisonref = sanitize_string($this->ref); - if ($conf->expedition->dir_output) + $livref = sanitize_string($this->ref); + if ($conf->livraison->dir_output) { - $dir = $conf->livraison->dir_output . "/" . $livraisonref ; - $file = $dir . "/" . $livraisonref . ".pdf"; + $dir = $conf->livraison->dir_output . "/" . $livref ; + $file = $conf->livraison->dir_output . "/" . $livref . "/" . $livref . ".pdf"; if (file_exists($file)) { if (!dol_delete_file($file)) @@ -375,229 +512,137 @@ class Livraison extends CommonObject } } } - - dolibarr_syslog("livraison.class.php::valid ok"); + + return 1; + } + else + { + $this->db->rollback(); + return -2; } - else - { - $this->db->rollback(); - $this->error=$this->db->error()." - sql=$sql"; - dolibarr_syslog("livraison.class.php::valid ".$this->error); - return -1; - } - } - } - } - else - { - $this->error="Non autorise"; - dolibarr_syslog("livraison.class.php::valid ".$this->error); - return -1; - } - - $this->db->commit(); - dolibarr_syslog("livraison.class.php::valid commit"); - return 1; - } - - /** \brief Créé le bon de livraison depuis une expédition existante - \param user Utilisateur qui crée - \param sending_id Id de l'expédition qui sert de modèle - */ - function create_from_sending($user, $sending_id) - { - $expedition = new Expedition($this->db); - $result=$expedition->fetch($sending_id); - - $this->lignes = array(); - $this->date_livraison = time(); - $this->expedition_id = $sending_id; - - for ($i = 0 ; $i < sizeof($expedition->lignes) ; $i++) - { - $LivraisonLigne = new LivraisonLigne($this->db); - $LivraisonLigne->commande_ligne_id = $expedition->lignes[$i]->commande_ligne_id; - $LivraisonLigne->libelle = $expedition->lignes[$i]->libelle; - $LivraisonLigne->description = $expedition->lignes[$i]->product_desc; - $LivraisonLigne->qty = $expedition->lignes[$i]->qty_expedition; - $LivraisonLigne->fk_product = $expedition->lignes[$i]->fk_product; - $LivraisonLigne->ref = $expedition->lignes[$i]->ref; - $this->lignes[$i] = $LivraisonLigne; } - - $this->commande_id = $expedition->commande_id; - $this->note = $expedition->note; - $this->projetid = $expedition->projetidp; - $this->date_livraison = $expedition->date_livraison; - $this->adresse_livraison_id = $expedition->adresse_livraison_id; - - return $this->create($user); - } - - - /** - * Ajoute une ligne - * - */ - function addline( $id, $qty ) - { - $num = sizeof($this->lignes); - $ligne = new livraisonLigne($this->db); - - $ligne->commande_ligne_id = $id; - $ligne->qty = $qty; - - $this->lignes[$num] = $ligne; - } - - /** - * - * - */ - function delete_line($idligne) - { - if ($this->statut == 0) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet WHERE rowid = $idligne"; - - if ($this->db->query($sql) ) - { - $this->update_price(); - - return 1; - } - else - { - return 0; - } - } - } - /** - * Supprime la fiche - * - */ - function delete() - { - $this->db->begin(); - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraisondet WHERE fk_livraison = $this->id ;"; - if ( $this->db->query($sql) ) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison WHERE rowid = $this->id;"; - if ( $this->db->query($sql) ) - { - $this->db->commit(); - - // On efface le répertoire de pdf provisoire - $livref = sanitize_string($this->ref); - if ($conf->livraison->dir_output) + else { - $dir = $conf->livraison->dir_output . "/" . $livref ; - $file = $conf->livraison->dir_output . "/" . $livref . "/" . $livref . ".pdf"; - if (file_exists($file)) - { - if (!dol_delete_file($file)) - { - $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); - return 0; - } - } - if (file_exists($dir)) - { - if (!dol_delete_dir($dir)) - { - $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); - return 0; - } - } - } - - return 1; - } - else - { - $this->db->rollback(); - return -2; - } - } - else - { - $this->db->rollback(); - return -1; - } - } + $this->db->rollback(); + return -1; + } + } + + + /* + * Lit la commande associée + * + */ + function fetch_commande() + { + $this->commande =& new Commande($this->db); + $this->commande->fetch($this->commande_id); + } + + /** + * + * + */ + + function fetch_adresse_livraison($id) + { + $idadresse = $id; + $adresse = new Societe($this->db); + $adresse->fetch_adresse_livraison($idadresse); + $this->adresse = $adresse; + } + + + function fetch_lignes() + { + $this->lignes = array(); + + $sql = "SELECT p.label, c.description, c.qty as qtycom, l.qty as qtyliv"; + $sql .= ", c.fk_product, c.price, p.ref"; + $sql .= " FROM ".MAIN_DB_PREFIX."livraisondet as l"; + $sql .= " , ".MAIN_DB_PREFIX."commandedet as c"; + $sql .= " , ".MAIN_DB_PREFIX."product as p"; + + $sql .= " WHERE l.fk_livraison = ".$this->id; + $sql .= " AND l.fk_commande_ligne = c.rowid"; + $sql .= " AND c.fk_product = p.rowid"; + + + $resql = $this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $ligne = new LivraisonLigne($this->db); + + $obj = $this->db->fetch_object($resql); + + $ligne->fk_product = $obj->fk_product; + $ligne->qty_commande = $obj->qtycom; + $ligne->qty_livre = $obj->qtyliv; + $ligne->ref = $obj->ref; + $ligne->label = stripslashes($obj->label); + $ligne->description = stripslashes($obj->description); + $ligne->price = $obj->price; + + $this->lignes[$i] = $ligne; + $i++; + } + $this->db->free($resql); + } + + return $this->lignes; + } - /* - * Lit la commande associée - * - */ - function fetch_commande() - { - $this->commande =& new Commande($this->db); - $this->commande->fetch($this->commande_id); - } - - /** - * - * - */ - - function fetch_adresse_livraison($id) + /** + * \brief Retourne le libellé du statut d'une expedition + * \return string Libellé + */ + function getLibStatut($mode=0) { - $idadresse = $id; - $adresse = new Societe($this->db); - $adresse->fetch_adresse_livraison($idadresse); - $this->adresse = $adresse; + return $this->LibStatut($this->statut,$mode); } + + /** + * \brief Renvoi le libellé d'un statut donné + * \param statut Id statut + * \param mode 0=libellé long, 1=libellé court, 2=Picto + Libellé court, 3=Picto, 4=Picto + Libellé long, 5=Libellé court + Picto + * \return string Libellé + */ + function LibStatut($statut,$mode) + { + global $langs; - - function fetch_lignes() - { - $this->lignes = array(); - - $sql = "SELECT p.label, c.description, c.qty as qtycom, l.qty as qtyliv"; - $sql .= ", c.fk_product, c.price, p.ref"; - $sql .= " FROM ".MAIN_DB_PREFIX."livraisondet as l"; - $sql .= " , ".MAIN_DB_PREFIX."commandedet as c"; - $sql .= " , ".MAIN_DB_PREFIX."product as p"; - - $sql .= " WHERE l.fk_livraison = ".$this->id; - $sql .= " AND l.fk_commande_ligne = c.rowid"; - $sql .= " AND c.fk_product = p.rowid"; - - - $resql = $this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $ligne = new LivraisonLigne($this->db); - - $obj = $this->db->fetch_object($resql); - - $ligne->fk_product = $obj->fk_product; - $ligne->qty_commande = $obj->qtycom; - $ligne->qty_livre = $obj->qtyliv; - $ligne->ref = $obj->ref; - $ligne->label = stripslashes($obj->label); - $ligne->description = stripslashes($obj->description); - $ligne->price = $obj->price; - - $this->lignes[$i] = $ligne; - $i++; - } - $this->db->free($resql); - } - - return $this->lignes; - } - + if ($mode==0) + { + if ($statut==-1) return $this->statuts[$statut]; + if ($statut==0) return $this->statuts[$statut]; + if ($statut==1) return $this->statuts[$statut]; + } + if ($mode==1) + { + if ($statut==-1) return $this->statuts[$statut]; + if ($statut==0) return $this->statuts[$statut]; + if ($statut==1) return $this->statuts[$statut]; + } + if ($mode == 4) + { + if ($statut==-1) return img_picto($langs->trans('StatusSendingCanceled'),'statut5').' '.$langs->trans('StatusSendingDraft'); + if ($statut==0) return img_picto($langs->trans('StatusSendingDraft'),'statut0').' '.$langs->trans('StatusSendingDraft'); + if ($statut==1) return img_picto($langs->trans('StatusSendingValidated'),'statut4').' '.$langs->trans('StatusSendingValidated'); + } + } + } +/** + \class LivraisonLigne + \brief Classe de gestion des lignes de bons de livraison +*/ class LivraisonLigne { var $db;