From f1d67cba3cf08010fba1b3026f6dcb27f6a8fa7b Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 13 Mar 2010 15:52:30 +0000 Subject: [PATCH] Fix: best autonomy of modules Fix: uniformise fields and code !! not stable !! --- dev/initdata/initdemo.sql | 1 - htdocs/commonobject.class.php | 5 + htdocs/expedition/expedition.class.php | 155 +++++---- htdocs/expedition/fiche.php | 25 +- .../modules/livraison/mod_livraison_jade.php | 50 +-- .../install/mysql/tables/llx_expedition.sql | 18 +- htdocs/install/mysql/tables/llx_livraison.sql | 25 +- htdocs/install/mysql/tables/llx_propal.sql | 56 ++-- htdocs/install/upgrade2.php | 293 ++++++++++++++++++ htdocs/lib/sendings.lib.php | 90 +++++- htdocs/livraison/fiche.php | 22 +- htdocs/livraison/livraison.class.php | 173 +++++------ 12 files changed, 634 insertions(+), 279 deletions(-) diff --git a/dev/initdata/initdemo.sql b/dev/initdata/initdemo.sql index 3bfb92ec02a..704057197da 100644 --- a/dev/initdata/initdemo.sql +++ b/dev/initdata/initdemo.sql @@ -2874,7 +2874,6 @@ CREATE TABLE `llx_livraison` ( `entity` int(11) NOT NULL DEFAULT '1', `ref_client` varchar(30) DEFAULT NULL, `fk_soc` int(11) NOT NULL, - `fk_expedition` int(11) DEFAULT NULL, `date_creation` datetime DEFAULT NULL, `fk_user_author` int(11) DEFAULT NULL, `date_valid` datetime DEFAULT NULL, diff --git a/htdocs/commonobject.class.php b/htdocs/commonobject.class.php index 89e87ca5259..f9a10a7e98a 100644 --- a/htdocs/commonobject.class.php +++ b/htdocs/commonobject.class.php @@ -410,6 +410,11 @@ class CommonObject function fetch_object() { $object = $this->origin; + + // TODO uniformise code + if ($object == 'shipping') $object = 'expedition'; + if ($object == 'delivery') $object = 'livraison'; + $class = ucfirst($object); $this->$object = new $class($this->db); $this->$object->fetch($this->origin_id); diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index bdac1b3e668..da61c6f3b47 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -44,6 +44,7 @@ class Expedition extends CommonObject var $id; var $socid; + var $ref_customer; var $brouillon; var $entrepot_id; var $modelpdf; @@ -51,6 +52,10 @@ class Expedition extends CommonObject var $origin_id; var $lignes; var $meths; + + var $date_delivery; + var $date_creation; + var $date_valid; /** * Initialisation @@ -90,10 +95,12 @@ class Expedition extends CommonObject $sql = "INSERT INTO ".MAIN_DB_PREFIX."expedition ("; $sql.= "ref"; + $sql.= ", ref_customer"; $sql.= ", entity"; $sql.= ", date_creation"; $sql.= ", fk_user_author"; $sql.= ", date_expedition"; + $sql.= ", date_delivery"; $sql.= ", fk_soc"; $sql.= ", fk_adresse_livraison"; $sql.= ", fk_expedition_methode"; @@ -104,13 +111,14 @@ class Expedition extends CommonObject $sql.= ", height"; $sql.= ", weight_units"; $sql.= ", size_units"; - $sql.= ")"; - $sql.= " VALUES ("; + $sql.= ") VALUES ("; $sql.= "'(PROV)'"; + $sql.= ", '".$this->ref_customer."'"; $sql.= ", ".$conf->entity; $sql.= ", ".$this->db->idate(gmmktime()); $sql.= ", ".$user->id; $sql.= ", ".$this->db->idate($this->date_expedition); + $sql.= ", ".$this->db->idate($this->date_delivery); $sql.= ", ".$this->socid; $sql.= ", ".($this->fk_delivery_address>0?$this->fk_delivery_address:"null"); $sql.= ", ".($this->expedition_method_id>0?$this->expedition_method_id:"null"); @@ -152,15 +160,8 @@ class Expedition extends CommonObject $error++; } - if ($conf->commande->enabled) - { - $ret = $this->setStatut(2,$this->origin_id,$this->origin); - } - else - { - // TODO definir un statut - $ret = $this->setStatut(9,$this->origin_id,$this->origin); - } + // TODO uniformiser les statuts + $ret = $this->setStatut(2,$this->origin_id,$this->origin); if (! $ret) { $error++; @@ -205,9 +206,18 @@ class Expedition extends CommonObject { $error = 0; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet (fk_expedition, fk_entrepot, fk_origin_line, qty)"; - $sql .= " VALUES (".$this->id.", ".($entrepot_id?$entrepot_id:'null').", ".$origin_line_id.", ".$qty.")"; - //print 'x'.$sql; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet ("; + $sql.= "fk_expedition"; + $sql.= ", fk_entrepot"; + $sql.= ", fk_origin_line"; + $sql.= ", qty"; + $sql.= ") VALUES ("; + $sql.= $this->id; + $sql.= ", ".($entrepot_id?$entrepot_id:'null'); + $sql.= ", ".$origin_line_id; + $sql.= ", ".$qty; + $sql.= ")"; + if (! $this->db->query($sql)) { $error++; @@ -225,26 +235,13 @@ class Expedition extends CommonObject { global $conf; - $sql = "SELECT e.rowid, e.fk_soc as socid, e.date_creation, e.ref, e.fk_user_author, e.fk_statut"; + $sql = "SELECT e.rowid, e.fk_soc as socid, e.date_creation, e.ref, e.ref_customer, e.fk_user_author, e.fk_statut"; $sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height"; - $sql.= ", e.date_expedition as date_expedition, e.model_pdf, e.fk_adresse_livraison"; + $sql.= ", e.date_expedition as date_expedition, e.model_pdf, e.fk_adresse_livraison, e.date_delivery"; $sql.= ", e.fk_expedition_methode, e.tracking_number"; - $sql.= ", el.fk_source as origin_id"; - $sql.= ", ori.ref_client"; - if ($conf->livraison_bon->enabled) $sql.=", l.rowid as livraison_id"; + $sql.= ", el.fk_source as origin_id, el.sourcetype as origin"; $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target"; - if ($conf->commande->enabled) - { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as ori ON el.fk_source = ori.rowid"; - $sql.= " AND el.sourcetype = 'commande'"; - } - else - { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."propal as ori ON el.fk_source = ori.rowid"; - $sql.= " AND el.sourcetype = 'propal'"; - } - if ($conf->livraison_bon->enabled) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON e.rowid = l.fk_expedition"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->element."'"; $sql.= " WHERE e.rowid = ".$id; dol_syslog("Expedition::fetch sql=".$sql); @@ -258,17 +255,19 @@ class Expedition extends CommonObject $this->id = $obj->rowid; $this->ref = $obj->ref; $this->socid = $obj->socid; - $this->ref_client = $obj->ref_client; + $this->ref_customer = $obj->ref_customer; $this->statut = $obj->fk_statut; - $this->origin_id = $obj->origin_id; - $this->livraison_id = $obj->livraison_id; $this->user_author_id = $obj->fk_user_author; - $this->date = $this->db->jdate($obj->date_expedition); - $this->adresse_livraison_id = $obj->fk_adresse_livraison; // TODO obsolete + $this->date = $this->db->jdate($obj->date_expedition); // TODO obsolete + $this->date_shipping = $this->db->jdate($obj->date_expedition); + $this->date_delivery = $this->db->jdate($obj->date_delivery); + $this->adresse_livraison_id = $obj->fk_adresse_livraison; // TODO obsolete $this->fk_delivery_address = $obj->fk_adresse_livraison; $this->modelpdf = $obj->model_pdf; $this->expedition_method_id = $obj->fk_expedition_methode; $this->tracking_number = $obj->tracking_number; + $this->origin = $obj->origin; + $this->origin_id = $obj->origin_id; $this->trueWeight = $obj->weight; $this->weight_units = $obj->weight_units; @@ -284,15 +283,6 @@ class Expedition extends CommonObject $this->trueSize = $obj->size."x".$obj->width."x".$obj->height; $this->size_units = $obj->size_units; - if ($conf->commande->enabled) - { - $this->origin = "commande"; - } - else - { - $this->origin = "propal"; - } - $this->db->free($result); if ($this->statut == 0) $this->brouillon = 1; @@ -303,7 +293,7 @@ class Expedition extends CommonObject $this->pdf_filename = $file; /* - * Lignes + * Lines */ $result=$this->fetch_lines(); if ($result < 0) @@ -359,8 +349,8 @@ class Expedition extends CommonObject $num = "EXP".$this->id; // Validate - $sql = "UPDATE ".MAIN_DB_PREFIX."expedition"; - $sql.= " SET ref='".$num."'"; + $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET"; + $sql.= " ref='".$num."'"; $sql.= ", fk_statut = 1"; $sql.= ", date_valid = ".$this->db->idate(mktime()); $sql.= ", fk_user_valid = ".$user->id; @@ -493,15 +483,15 @@ class Expedition extends CommonObject { // Expedition validee include_once(DOL_DOCUMENT_ROOT."/livraison/livraison.class.php"); - $livraison = new Livraison($this->db); - $result=$livraison->create_from_sending($user, $this->id); + $delivery = new Livraison($this->db); + $result=$delivery->create_from_sending($user, $this->id); if ($result > 0) { return $result; } else { - $this->error=$livraison->error; + $this->error=$delivery->error; return $result; } } @@ -517,35 +507,36 @@ class Expedition extends CommonObject function addline( $entrepot_id, $id, $qty ) { $num = sizeof($this->lignes); - $ligne = new ExpeditionLigne($this->db); + $line = new ExpeditionLigne($this->db); - $ligne->entrepot_id = $entrepot_id; - $ligne->origin_line_id = $id; - $ligne->qty = $qty; + $line->entrepot_id = $entrepot_id; + $line->origin_line_id = $id; + $line->qty = $qty; - $this->lignes[$num] = $ligne; + $this->lignes[$num] = $line; } /** * * */ - function delete_line($idligne) + function delete_line($id) { if ($this->statut == 0) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet"; - $sql.= " WHERE rowid = ".$idligne; + $sql.= " WHERE rowid = ".$id; if ($this->db->query($sql) ) - { - $this->update_price(); - return 1; - } - else - { - return 0; - } + { + $this->update_price(); + + return 1; + } + else + { + return 0; + } } } @@ -647,25 +638,25 @@ class Expedition extends CommonObject $i = 0; while ($i < $num) { - $ligne = new ExpeditionLigne($this->db); + $line = new ExpeditionLigne($this->db); $obj = $this->db->fetch_object($resql); - $ligne->origin_line_id = $obj->fk_origin_line; - $ligne->entrepot_id = $obj->fk_entrepot; - $ligne->fk_product = $obj->fk_product; - $ligne->fk_product_type= $obj->fk_product_type; - $ligne->ref = $obj->ref; - $ligne->label = $obj->label; // deprecated - $ligne->libelle = $obj->label; - $ligne->description = $obj->description; - $ligne->qty_asked = $obj->qty_asked; - $ligne->qty_shipped = $obj->qty_shipped; - $ligne->weight = $obj->weight; - $ligne->weight_units = $obj->weight_units; - $ligne->volume = $obj->volume; - $ligne->volume_units = $obj->volume_units; + $line->origin_line_id = $obj->fk_origin_line; + $line->entrepot_id = $obj->fk_entrepot; + $line->fk_product = $obj->fk_product; + $line->fk_product_type = $obj->fk_product_type; + $line->ref = $obj->ref; + $line->label = $obj->label; + $line->libelle = $obj->label; // deprecated + $line->description = $obj->description; + $line->qty_asked = $obj->qty_asked; + $line->qty_shipped = $obj->qty_shipped; + $line->weight = $obj->weight; + $line->weight_units = $obj->weight_units; + $line->volume = $obj->volume; + $line->volume_units = $obj->volume_units; - $this->lignes[$i] = $ligne; + $this->lignes[$i] = $line; $i++; } $this->db->free($resql); diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index 69ec06a8720..0d87973b223 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -593,7 +593,7 @@ else { print '
'.$mesg.'
'; } - + $typeobject = $expedition->origin; $origin = $expedition->origin; $expedition->fetch_object(); @@ -606,20 +606,11 @@ else $soc = new Societe($db); $soc->fetch($expedition->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_bon->enabled && $expedition->livraison_id) - { - $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$expedition->livraison_id; - $head[$h][1] = $langs->trans("DeliveryCard"); - $h++; - } - - dol_fiche_head($head, $hselected, $langs->trans("Sending"), 0, 'sending'); + // delivery link + $expedition->load_object_linked($expedition->id,$expedition->element,-1,-1); + + $head=shipping_prepare_head($expedition); + dol_fiche_head($head, 'shipping', $langs->trans("Sending"), 0, 'sending'); if ($mesg) print $mesg; @@ -705,7 +696,7 @@ else // Ref customer print ''.$langs->trans("RefCustomer").''; - print ''.$expedition->ref_client."\n"; + print ''.$expedition->ref_customer."\n"; print ''; // Date @@ -914,7 +905,7 @@ else } } - if ($conf->livraison_bon->enabled && $expedition->statut == 1 && $user->rights->expedition->livraison->creer && !$expedition->livraison_id) + if ($conf->livraison_bon->enabled && $expedition->statut == 1 && $user->rights->expedition->livraison->creer && empty($expedition->linked_object)) { print ''.$langs->trans("DeliveryOrder").''; } diff --git a/htdocs/includes/modules/livraison/mod_livraison_jade.php b/htdocs/includes/modules/livraison/mod_livraison_jade.php index 22ebd0db858..d6ff91ae491 100644 --- a/htdocs/includes/modules/livraison/mod_livraison_jade.php +++ b/htdocs/includes/modules/livraison/mod_livraison_jade.php @@ -1,7 +1,7 @@ - * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2005-2010 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,19 +20,19 @@ */ /** - \file htdocs/includes/modules/livraison/mod_livraison_jade.php - \ingroup livraison - \brief Fichier contenant la classe du modele de numerotation de reference de bon de livraison Jade - \version $Id$ -*/ + * \file htdocs/includes/modules/livraison/mod_livraison_jade.php + * \ingroup delivery + * \brief Fichier contenant la classe du modele de numerotation de reference de bon de livraison Jade + * \version $Id$ + */ require_once(DOL_DOCUMENT_ROOT ."/includes/modules/livraison/modules_livraison.php"); /** - \class mod_livraison_jade - \brief Classe du modele de numerotation de reference de bon de livraison Jade -*/ + * \class mod_livraison_jade + * \brief Classe du modele de numerotation de reference de bon de livraison Jade + */ class mod_livraison_jade extends ModeleNumRefDeliveryOrder { @@ -41,16 +41,18 @@ class mod_livraison_jade extends ModeleNumRefDeliveryOrder var $nom = "Jade"; - /** \brief Renvoi la description du modele de numerotation - * \return string Texte descripif - */ + /** + * \brief Renvoi la description du modele de numerotation + * \return string Texte descripif + */ function info() { global $langs; return $langs->trans("NumRefModelJade"); } - - /** \brief Renvoi un exemple de numerotation + + /** + * \brief Renvoi un exemple de numerotation * \return string Example */ function getExample() @@ -58,12 +60,13 @@ class mod_livraison_jade extends ModeleNumRefDeliveryOrder return "BL0600001"; } - /** \brief Return next value - * \param objsoc Object third party - * \param livraison Object delivery - * \return string Value if OK, 0 if KO - */ - function getNextValue($objsoc=0,$livraison='') + /** + * \brief Return next value + * \param objsoc Object third party + * \param delivery Object delivery + * \return string Value if OK, 0 if KO + */ + function getNextValue($objsoc=0,$delivery='') { global $db,$conf; @@ -103,8 +106,8 @@ class mod_livraison_jade extends ModeleNumRefDeliveryOrder { $max=0; } - //$date=time(); - $date=$livraison->date_livraison; + + $date = $delivery->date_delivery; $yy = strftime("%y",$date); $num = sprintf("%05s",$max+1); @@ -112,7 +115,8 @@ class mod_livraison_jade extends ModeleNumRefDeliveryOrder } - /** \brief Renvoie la reference de commande suivante non utilisee + /** + * \brief Renvoie la reference de commande suivante non utilisee * \param objsoc Objet societe * \param livraison Objet livraison * \return string Texte descripif diff --git a/htdocs/install/mysql/tables/llx_expedition.sql b/htdocs/install/mysql/tables/llx_expedition.sql index 19d6d97fbbb..1202c0fafc8 100644 --- a/htdocs/install/mysql/tables/llx_expedition.sql +++ b/htdocs/install/mysql/tables/llx_expedition.sql @@ -1,6 +1,6 @@ -- =================================================================== -- Copyright (C) 2003-2008 Rodolphe Quiedeville --- Copyright (C) 2008-2009 Regis Houssin +-- Copyright (C) 2008-2010 Regis Houssin -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -25,17 +25,19 @@ create table llx_expedition tms timestamp, ref varchar(30) NOT NULL, entity integer DEFAULT 1 NOT NULL, -- multi company id + ref_customer varchar(30), -- customer number fk_soc integer NOT NULL, - date_creation datetime, -- date de creation - fk_user_author integer, -- createur - date_valid datetime, -- date de validation - fk_user_valid integer, -- valideur - date_expedition date, -- date de lexpedition - fk_adresse_livraison integer DEFAULT NULL, -- adresse de livraison + date_creation datetime, -- date de creation + fk_user_author integer, -- createur + date_valid datetime, -- date de validation + fk_user_valid integer, -- valideur + date_expedition date, -- shipping date + date_delivery date DEFAULT NULL, -- delivery date + fk_adresse_livraison integer DEFAULT NULL, -- adresse de livraison fk_expedition_methode integer, tracking_number varchar(50), - fk_statut smallint DEFAULT 0, + fk_statut smallint DEFAULT 0, height integer, width integer, diff --git a/htdocs/install/mysql/tables/llx_livraison.sql b/htdocs/install/mysql/tables/llx_livraison.sql index 5004b95ab50..bbccb52b025 100644 --- a/htdocs/install/mysql/tables/llx_livraison.sql +++ b/htdocs/install/mysql/tables/llx_livraison.sql @@ -1,6 +1,6 @@ -- =================================================================== -- Copyright (C) 2003 Rodolphe Quiedeville --- Copyright (C) 2008-2009 Regis Houssin +-- Copyright (C) 2008-2010 Regis Houssin -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -23,20 +23,19 @@ create table llx_livraison ( rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp, - ref varchar(30) NOT NULL, -- delivery number - entity integer DEFAULT 1 NOT NULL, -- multi company id - ref_client varchar(30), -- customer number + ref varchar(30) NOT NULL, -- delivery number + entity integer DEFAULT 1 NOT NULL, -- multi company id + ref_customer varchar(30), -- customer number fk_soc integer NOT NULL, - fk_expedition integer, -- expedition auquel est rattache le bon de livraison - date_creation datetime, -- date de creation - fk_user_author integer, -- createur du bon de livraison - date_valid datetime, -- date de validation - fk_user_valid integer, -- valideur du bon de livraison - date_livraison date default NULL, -- date de livraison - fk_adresse_livraison integer, -- adresse de livraison - fk_statut smallint default 0, - total_ht double(24,8) default 0, + date_creation datetime, -- date de creation + fk_user_author integer, -- createur du bon de livraison + date_valid datetime, -- date de validation + fk_user_valid integer, -- valideur du bon de livraison + date_delivery date DEFAULT NULL, -- delivery date + fk_adresse_livraison integer, -- adresse de livraison + fk_statut smallint DEFAULT 0, + total_ht double(24,8) DEFAULT 0, note text, note_public text, model_pdf varchar(50) diff --git a/htdocs/install/mysql/tables/llx_propal.sql b/htdocs/install/mysql/tables/llx_propal.sql index 6777ecf4f74..a57cfcf3bf2 100644 --- a/htdocs/install/mysql/tables/llx_propal.sql +++ b/htdocs/install/mysql/tables/llx_propal.sql @@ -24,36 +24,36 @@ create table llx_propal ( rowid integer AUTO_INCREMENT PRIMARY KEY, fk_soc integer, - fk_projet integer DEFAULT 0, -- projet auquel est rattache la propale - ref varchar(30) NOT NULL, -- propal number - entity integer DEFAULT 1 NOT NULL, -- multi company id - ref_client varchar(30), -- customer order number + fk_projet integer DEFAULT 0, -- projet auquel est rattache la propale + ref varchar(30) NOT NULL, -- propal number + entity integer DEFAULT 1 NOT NULL, -- multi company id + ref_client varchar(30), -- customer order number - datec datetime, -- date de creation - datep date, -- date de la propal - fin_validite datetime, -- date de fin de validite - date_valid datetime, -- date de validation - date_cloture datetime, -- date de cloture - fk_user_author integer, -- createur de la propale - fk_user_valid integer, -- valideur de la propale - fk_user_cloture integer, -- cloture de la propale signee ou non signee + datec datetime, -- date de creation + datep date, -- date de la propal + fin_validite datetime, -- date de fin de validite + date_valid datetime, -- date de validation + date_cloture datetime, -- date de cloture + fk_user_author integer, -- createur de la propale + fk_user_valid integer, -- valideur de la propale + fk_user_cloture integer, -- cloture de la propale signee ou non signee fk_statut smallint DEFAULT 0 NOT NULL, - price real DEFAULT 0, -- (obsolete) - remise_percent real DEFAULT 0, -- remise globale relative en pourcent (obsolete) - remise_absolue real DEFAULT 0, -- remise globale absolue (obsolete) - remise real DEFAULT 0, -- remise calculee (obsolete) - total_ht double(24,8) DEFAULT 0, -- montant total ht apres remise globale - tva double(24,8) DEFAULT 0, -- montant total tva apres remise globale - localtax1 double(24,8) DEFAULT 0, -- amount total localtax1 - localtax2 double(24,8) DEFAULT 0, -- amount total localtax2 - total double(24,8) DEFAULT 0, -- montant total ttc apres remise globale + price real DEFAULT 0, -- (obsolete) + remise_percent real DEFAULT 0, -- remise globale relative en pourcent (obsolete) + remise_absolue real DEFAULT 0, -- remise globale absolue (obsolete) + remise real DEFAULT 0, -- remise calculee (obsolete) + total_ht double(24,8) DEFAULT 0, -- montant total ht apres remise globale + tva double(24,8) DEFAULT 0, -- montant total tva apres remise globale + localtax1 double(24,8) DEFAULT 0, -- amount total localtax1 + localtax2 double(24,8) DEFAULT 0, -- amount total localtax2 + total double(24,8) DEFAULT 0, -- montant total ttc apres remise globale - fk_cond_reglement integer, -- condition de reglement (30 jours, fin de mois ...) - fk_mode_reglement integer, -- mode de reglement (Virement, Prelevement) + fk_cond_reglement integer, -- condition de reglement (30 jours, fin de mois ...) + fk_mode_reglement integer, -- mode de reglement (Virement, Prelevement) - note text, - note_public text, - model_pdf varchar(50), - date_livraison date default NULL, - fk_adresse_livraison integer -- adresse de livraison + note text, + note_public text, + model_pdf varchar(50), + date_livraison date DEFAULT NULL, -- delivery date + fk_adresse_livraison integer -- adresse de livraison )type=innodb; diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 548ea71aafb..47387d4f35f 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -273,6 +273,12 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"])) if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0) { migrate_project_task_time($db,$langs,$conf); + + migrate_customerorder_shipping($db,$langs,$conf); + + migrate_shipping_delivery($db,$langs,$conf); + + migrate_shipping_delivery2($db,$langs,$conf); } // On commit dans tous les cas. @@ -2829,6 +2835,293 @@ function migrate_project_task_time($db,$langs,$conf) print ''; } +/* + * Migrate order ref_customer and date_delivery fields to llx_expedition + */ +function migrate_customerorder_shipping($db,$langs,$conf) +{ + print ''; + + print '
'; + print ''.$langs->trans('MigrationCustomerOrderShipping')."
\n"; + + $error = 0; + + $result1 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition","ref_customer"); + $result2 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition","date_delivery"); + $obj1 = $db->fetch_object($result1); + $obj2 = $db->fetch_object($result2); + if (!$obj1 && !$obj2) + { + dolibarr_install_syslog("upgrade2::migrate_customerorder_shipping"); + + $db->begin(); + + $sqlAdd1 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN ref_customer varchar(30) AFTER entity"; + $sqlAdd2 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition"; + + if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) + { + $sqlSelect = "SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison"; + $sqlSelect.= " FROM ".MAIN_DB_PREFIX."expedition as e"; + $sqlSelect.= ", ".MAIN_DB_PREFIX."element_element as el"; + $sqlSelect.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'"; + $sqlSelect.= " WHERE e.rowid = el.fk_target"; + $sqlSelect.= " AND el.targettype = 'shipping'"; + + $resql = $db->query($sqlSelect); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); + + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."expedition SET"; + $sqlUpdate.= " ref_customer = '".$obj->ref_client."'"; + $sqlUpdate.= ", date_delivery = '".($obj->date_livraison?$obj->date_livraison:'null')."'"; + $sqlUpdate.= " WHERE rowid = ".$obj->shipping_id; + + $result=$db->query($sqlUpdate); + if (! $result) + { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } + else + { + print $langs->trans('AlreadyDone')."
\n"; + } + + if ($error == 0) + { + $db->commit(); + } + else + { + dol_print_error($db); + $db->rollback(); + } + } + else + { + dol_print_error($db); + $db->rollback(); + } + } + else + { + dol_print_error($db); + $db->rollback(); + } + } + else + { + print $langs->trans('AlreadyDone')."
\n"; + } + + print ''; +} + +/* + * Migrate fk_expedition to llx_element_element + */ +function migrate_shipping_delivery($db,$langs,$conf) +{ + print ''; + + print '
'; + print ''.$langs->trans('MigrationShippingDelivery')."
\n"; + + $error = 0; + + $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison","fk_expedition"); + $obj = $db->fetch_object($result); + if ($obj) + { + dolibarr_install_syslog("upgrade2::migrate_shipping_delivery"); + + $db->begin(); + + $sqlSelect = "SELECT rowid, fk_expedition"; + $sqlSelect.= " FROM ".MAIN_DB_PREFIX."livraison"; + + $resql = $db->query($sqlSelect); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); + + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + $sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; + $sqlInsert.= "fk_source"; + $sqlInsert.= ", sourcetype"; + $sqlInsert.= ", fk_target"; + $sqlInsert.= ", targettype"; + $sqlInsert.= ") VALUES ("; + $sqlInsert.= $obj->fk_expedition; + $sqlInsert.= ", 'shipping'"; + $sqlInsert.= ", ".$obj->rowid; + $sqlInsert.= ", 'delivery'"; + $sqlInsert.= ")"; + + $result=$db->query($sqlInsert); + if (! $result) + { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } + else + { + print $langs->trans('AlreadyDone')."
\n"; + } + + if ($error == 0) + { + $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_expedition"; + if ($db->query($sqlDrop)) + { + $db->commit(); + } + else + { + dol_print_error($db); + $db->rollback(); + } + } + else + { + dol_print_error($db); + $db->rollback(); + } + } + else + { + dol_print_error($db); + $db->rollback(); + } + } + else + { + print $langs->trans('AlreadyDone')."
\n"; + } + + print ''; +} + +/* + * Migrate shipping ref_customer and date_delivery fields to llx_livraison + */ +function migrate_shipping_delivery2($db,$langs,$conf) +{ + print ''; + + print '
'; + print ''.$langs->trans('MigrationShippingDelivery2')."
\n"; + + $error = 0; + + $result1 = $db->DDLDescTable(MAIN_DB_PREFIX."livraison","ref_customer"); + $result2 = $db->DDLDescTable(MAIN_DB_PREFIX."livraison","date_delivery"); + $obj1 = $db->fetch_object($result1); + $obj2 = $db->fetch_object($result2); + if (!$obj1 && !$obj2) + { + dolibarr_install_syslog("upgrade2::migrate_shipping_delivery2"); + + $db->begin(); + + $sqlAdd1 = "ALTER TABLE ".MAIN_DB_PREFIX."livraison CHANGE ref_client ref_customer varchar(30)"; + $sqlAdd2 = "ALTER TABLE ".MAIN_DB_PREFIX."livraison CHANGE date_livraison date_delivery date DEFAULT NULL"; + + if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) + { + $sqlSelect = "SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery"; + $sqlSelect.= " FROM ".MAIN_DB_PREFIX."livraison as l"; + $sqlSelect.= ", ".MAIN_DB_PREFIX."element_element as el"; + $sqlSelect.= " LEFT JOIN ".MAIN_DB_PREFIX."expedition as e ON e.rowid = el.fk_source AND el.sourcetype = 'shipping'"; + $sqlSelect.= " WHERE l.rowid = el.fk_target"; + $sqlSelect.= " AND el.targettype = 'delivery'"; + + $resql = $db->query($sqlSelect); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); + + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET"; + $sqlUpdate.= " ref_customer = '".$obj->ref_customer."'"; + $sqlUpdate.= ", date_delivery = '".($obj->date_delivery?$obj->date_delivery:'null')."'"; + $sqlUpdate.= " WHERE rowid = ".$obj->delivery_id; + + $result=$db->query($sqlUpdate); + if (! $result) + { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } + else + { + print $langs->trans('AlreadyDone')."
\n"; + } + + if ($error == 0) + { + $db->commit(); + } + else + { + dol_print_error($db); + $db->rollback(); + } + } + else + { + dol_print_error($db); + $db->rollback(); + } + } + else + { + dol_print_error($db); + $db->rollback(); + } + } + else + { + print $langs->trans('AlreadyDone')."
\n"; + } + + print ''; +} + /* * Migration directory */ diff --git a/htdocs/lib/sendings.lib.php b/htdocs/lib/sendings.lib.php index 925157d07a4..57e551a0789 100644 --- a/htdocs/lib/sendings.lib.php +++ b/htdocs/lib/sendings.lib.php @@ -25,6 +25,92 @@ require_once(DOL_DOCUMENT_ROOT."/product.class.php"); +function shipping_prepare_head($object) +{ + global $langs, $conf, $user; + + $langs->load("sendings"); + $langs->load("deliveries"); + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$object->id; + $head[$h][1] = $langs->trans("SendingCard"); + $head[$h][2] = 'shipping'; + $h++; + + if ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire && $object->linked_object[0]['linkid']) + { + $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$object->linked_object[0]['linkid']; + $head[$h][1] = $langs->trans("DeliveryCard"); + $head[$h][2] = 'delivery'; + $h++; + } + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:MyModule:@mymodule:/mymodule/mypage.php?id=__ID__'); + if (is_array($conf->tabs_modules['delivery'])) + { + $i=0; + foreach ($conf->tabs_modules['delivery'] as $value) + { + $values=explode(':',$value); + if ($values[2]) $langs->load($values[2]); + $head[$h][0] = DOL_URL_ROOT . preg_replace('/__ID__/i',$commande->id,$values[3]); + $head[$h][1] = $langs->trans($values[1]); + $head[$h][2] = 'tab'.$values[1]; + $h++; + } + } + + return $head; +} + +function delivery_prepare_head($object) +{ + global $langs, $conf, $user; + + $langs->load("sendings"); + $langs->load("deliveries"); + + $h = 0; + $head = array(); + + if ($conf->expedition_bon->enabled && $user->rights->expedition->lire) + { + $head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$object->origin_id; + $head[$h][1] = $langs->trans("SendingCard"); + $head[$h][2] = 'shipping'; + $h++; + } + + $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$object->id; + $head[$h][1] = $langs->trans("DeliveryCard"); + $head[$h][2] = 'delivery'; + $h++; + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:MyModule:@mymodule:/mymodule/mypage.php?id=__ID__'); + if (is_array($conf->tabs_modules['delivery'])) + { + $i=0; + foreach ($conf->tabs_modules['delivery'] as $value) + { + $values=explode(':',$value); + if ($values[2]) $langs->load($values[2]); + $head[$h][0] = DOL_URL_ROOT . preg_replace('/__ID__/i',$commande->id,$values[3]); + $head[$h][1] = $langs->trans($values[1]); + $head[$h][2] = 'tab'.$values[1]; + $h++; + } + } + + return $head; +} + /** * List sendings and receive receipts * @@ -41,13 +127,13 @@ function show_list_sending_receive($origin='commande',$origin_id,$filter='') $sql = "SELECT obj.rowid, obj.fk_product, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked"; $sql.= ", ed.qty as qty_shipped, ed.fk_expedition as expedition_id"; $sql.= ", e.ref as exp_ref, ".$db->pdate("e.date_expedition")." as date_expedition,"; - if ($conf->livraison_bon->enabled) $sql .= " l.rowid as livraison_id, l.ref as livraison_ref, ".$db->pdate("l.date_livraison")." as date_delivery, ld.qty as qty_received,"; + //if ($conf->livraison_bon->enabled) $sql .= " l.rowid as livraison_id, l.ref as livraison_ref, ".$db->pdate("l.date_delivery")." as date_delivery, ld.qty as qty_received,"; $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid,'; $sql.= ' p.description as product_desc'; $sql.= " FROM (".MAIN_DB_PREFIX."expeditiondet as ed,"; $sql.= " ".MAIN_DB_PREFIX.$origin."det as obj,"; $sql.= " ".MAIN_DB_PREFIX."expedition as e)"; - if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid AND obj.rowid = ld.fk_origin_line"; + //if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid AND obj.rowid = ld.fk_origin_line"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid"; $sql.= " WHERE obj.fk_".$origin." = ".$origin_id; if ($filter) $sql.=$filter; diff --git a/htdocs/livraison/fiche.php b/htdocs/livraison/fiche.php index e72cd50fffe..53d8ff65324 100644 --- a/htdocs/livraison/fiche.php +++ b/htdocs/livraison/fiche.php @@ -128,7 +128,6 @@ if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && { $delivery = new Livraison($db); $delivery->fetch($_GET["id"]); - $expedition_id = $delivery->expedition_id; $db->begin(); $result=$delivery->delete(); @@ -138,7 +137,7 @@ if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $db->commit(); if ($conf->expedition_bon->enabled) { - Header("Location: ".DOL_URL_ROOT.'/expedition/fiche.php?id='.$expedition_id); + Header("Location: ".DOL_URL_ROOT.'/expedition/fiche.php?id='.$delivery->origin_id); } else { @@ -396,7 +395,6 @@ else if ($delivery->origin_id) { - $object = $delivery->origin; $delivery->fetch_object(); } @@ -405,20 +403,8 @@ else $soc = new Societe($db); $soc->fetch($delivery->socid); - $h=0; - if ($conf->expedition_bon->enabled) - { - $head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$delivery->expedition_id; - $head[$h][1] = $langs->trans("SendingCard"); - $h++; - } - - $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$delivery->id; - $head[$h][1] = $langs->trans("DeliveryCard"); - $hselected = $h; - $h++; - - dol_fiche_head($head, $hselected, $langs->trans("Sending"), 0, 'sending'); + $head=delivery_prepare_head($delivery); + dol_fiche_head($head, 'delivery', $langs->trans("Sending"), 0, 'sending'); /* * Confirmation de la suppression @@ -480,7 +466,7 @@ else // Ref client print ''.$langs->trans("RefCustomer").''; - print ''.$delivery->ref_client."\n"; + print ''.$delivery->ref_customer."\n"; print ''; // Date diff --git a/htdocs/livraison/livraison.class.php b/htdocs/livraison/livraison.class.php index b82cd0665c7..ce1670ece74 100644 --- a/htdocs/livraison/livraison.class.php +++ b/htdocs/livraison/livraison.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2006-2007 Laurent Destailleur * Copyright (C) 2007 Franky Van Liedekerke * @@ -20,10 +20,10 @@ */ /** - \file htdocs/livraison/livraison.class.php - \ingroup livraison - \brief Fichier de la classe de gestion des bons de livraison - \version $Id$ + * \file htdocs/livraison/livraison.class.php + * \ingroup delivery + * \brief Fichier de la classe de gestion des bons de livraison + * \version $Id$ */ require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php"); @@ -34,8 +34,8 @@ if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande /** - \class Livraison - \brief Classe de gestion des bons de livraison + * \class Livraison + * \brief Classe de gestion des bons de livraison */ class Livraison extends CommonObject { @@ -50,11 +50,11 @@ class Livraison extends CommonObject var $origin; var $origin_id; var $socid; - var $ref_client; + var $ref_customer; var $expedition_id; - var $date_livraison; + var $date_delivery; var $date_creation; var $date_valid; @@ -98,21 +98,18 @@ class Livraison extends CommonObject $sql.= "ref"; $sql.= ", entity"; $sql.= ", fk_soc"; - $sql.= ", ref_client"; + $sql.= ", ref_customer"; $sql.= ", date_creation"; $sql.= ", fk_user_author"; $sql.= ", fk_adresse_livraison"; - $sql.= ", fk_expedition"; - $sql.= ")"; - $sql.= " VALUES ("; + $sql.= ") VALUES ("; $sql.= "'(PROV)'"; $sql.= ", ".$conf->entity; $sql.= ", ".$this->socid; - $sql.= ", '".$this->ref_client."'"; + $sql.= ", '".$this->ref_customer."'"; $sql.= ", ".$this->db->idate(mktime()); $sql.= ", ".$user->id; $sql.= ", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address : "null"); - $sql.= ", ".($this->expedition_id ? $this->expedition_id : "null"); $sql.= ")"; dol_syslog("Livraison::create sql=".$sql, LOG_DEBUG); @@ -131,7 +128,7 @@ class Livraison extends CommonObject $resql=$this->db->query($sql); if ($resql) { - if (! $conf->expedition->enabled) + if (! $conf->expedition_bon->enabled) { $commande = new Commande($this->db); $commande->id = $this->commande_id; @@ -163,15 +160,8 @@ class Livraison extends CommonObject if (! $conf->expedition_bon->enabled) { - if ($conf->commande->enabled) - { - $ret = $this->setStatut(2,$this->origin_id,$this->origin); - } - else - { - // TODO definir un statut - $ret = $this->setStatut(9,$this->origin_id,$this->origin); - } + // TODO uniformiser les statuts + $ret = $this->setStatut(2,$this->origin_id,$this->origin); if (! $ret) { $error++; @@ -248,12 +238,12 @@ class Livraison extends CommonObject { global $conf; - $sql = "SELECT l.rowid, l.fk_soc, l.date_creation, l.date_valid, l.ref, l.ref_client, l.fk_user_author,"; - $sql.=" l.total_ht, l.fk_statut, l.fk_expedition, l.fk_user_valid, l.note, l.note_public"; - $sql.= ", l.date_livraison as date_livraison, l.fk_adresse_livraison, l.model_pdf"; - $sql.= ", el.fk_source as origin_id"; + $sql = "SELECT l.rowid, l.fk_soc, l.date_creation, l.date_valid, l.ref, l.ref_customer, l.fk_user_author,"; + $sql.=" l.total_ht, l.fk_statut, l.fk_user_valid, l.note, l.note_public"; + $sql.= ", l.date_delivery, l.fk_adresse_livraison, l.model_pdf"; + $sql.= ", el.fk_source as origin_id, el.sourcetype as origin"; $sql.= " FROM ".MAIN_DB_PREFIX."livraison as l"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON l.rowid = el.fk_target"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = l.rowid AND el.targettype = '".$this->element."'"; $sql.= " WHERE l.rowid = ".$id; dol_syslog("Livraison::fetch sql=".$sql, LOG_DEBUG); @@ -265,15 +255,13 @@ class Livraison extends CommonObject $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; - $this->date_livraison = $this->db->jdate($obj->date_livraison); + $this->date_delivery = $this->db->jdate($obj->date_delivery); $this->date_creation = $this->db->jdate($obj->date_creation); $this->date_valid = $this->db->jdate($obj->date_valid); $this->ref = $obj->ref; - $this->ref_client = $obj->ref_client; + $this->ref_customer = $obj->ref_customer; $this->socid = $obj->fk_soc; $this->statut = $obj->fk_statut; - $this->origin_id = $obj->origin_id; - $this->expedition_id = $obj->fk_expedition; $this->user_author_id = $obj->fk_user_author; $this->user_valid_id = $obj->fk_user_valid; $this->adresse_livraison_id = $obj->fk_adresse_livraison; // TODO obsolete @@ -281,21 +269,11 @@ class Livraison extends CommonObject $this->note = $obj->note; $this->note_public = $obj->note_public; $this->modelpdf = $obj->model_pdf; + $this->origin = $obj->origin; + $this->origin_id = $obj->origin_id; $this->db->free($result); - if ($this->origin_id) - { - if ($conf->commande->enabled) - { - $this->origin = "commande"; - } - else - { - $this->origin = "propal"; - } - } - if ($this->statut == 0) $this->brouillon = 1; $file = $conf->livraison->dir_output . "/" .get_exdir($livraison->id,2) . "/" . $this->id.".pdf"; @@ -344,14 +322,14 @@ class Livraison extends CommonObject if ($user->rights->expedition->livraison->valider) { - if (defined('LIVRAISON_ADDON')) + if ($conf->global->LIVRAISON_ADDON) { - if (is_readable(DOL_DOCUMENT_ROOT .'/includes/modules/livraison/'.LIVRAISON_ADDON.'.php')) + // Definition du nom de module de numerotation de commande + $modName = $conf->global->LIVRAISON_ADDON; + + if (is_readable(DOL_DOCUMENT_ROOT .'/includes/modules/livraison/'.$modName.'.php')) { - require_once DOL_DOCUMENT_ROOT .'/includes/modules/livraison/'.LIVRAISON_ADDON.'.php'; - - // Definition du nom de module de numerotation de commande - $modName=LIVRAISON_ADDON; + require_once DOL_DOCUMENT_ROOT .'/includes/modules/livraison/'.$modName.'.php'; // Recuperation de la nouvelle reference $objMod = new $modName($this->db); @@ -367,7 +345,12 @@ class Livraison extends CommonObject // Tester si non deja au statut valide. Si oui, on arrete afin d'eviter // de decrementer 2 fois le stock. - $sql = "SELECT ref FROM ".MAIN_DB_PREFIX."livraison where ref='".$this->ref."' AND fk_statut <> 0"; + $sql = "SELECT ref"; + $sql.= " FROM ".MAIN_DB_PREFIX."livraison"; + $sql.= " WHERE ref = '".$this->ref."'"; + $sql.= " AND fk_statut <> 0"; + $sql.= " AND entity = ".$conf->entity; + $resql=$this->db->query($sql); if ($resql) { @@ -378,9 +361,14 @@ class Livraison extends CommonObject } } - $sql = "UPDATE ".MAIN_DB_PREFIX."livraison "; - $sql.= " SET ref='".addslashes($this->ref)."', fk_statut = 1, date_valid = ".$this->db->idate(mktime()).", fk_user_valid = ".$user->id; - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; + $sql = "UPDATE ".MAIN_DB_PREFIX."livraison SET"; + $sql.= " ref='".addslashes($this->ref)."'"; + $sql.= ", fk_statut = 1"; + $sql.= ", date_valid = ".$this->db->idate(mktime()); + $sql.= ", fk_user_valid = ".$user->id; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND fk_statut = 0"; + $resql=$this->db->query($sql); if ($resql) { @@ -390,7 +378,6 @@ class Livraison extends CommonObject //Enregistrement d'un mouvement de stock pour chaque produit de l'expedition - dol_syslog("livraison.class.php::valid enregistrement des mouvements"); $sql = "SELECT cd.fk_product, cd.subprice, ld.qty "; @@ -491,8 +478,6 @@ class Livraison extends CommonObject $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++) { @@ -506,15 +491,15 @@ class Livraison extends CommonObject $this->lignes[$i] = $LivraisonLigne; } - $this->origin = $expedition->origin; - $this->origin_id = $expedition->origin_id; + $this->origin = $expedition->element; + $this->origin_id = $expedition->id; $this->note = $expedition->note; $this->fk_project = $expedition->fk_project; - $this->date_livraison = $expedition->date_livraison; + $this->date_delivery = $expedition->date_delivery; $this->adresse_livraison_id = $expedition->adresse_livraison_id; // TODO obsolete $this->fk_delivery_address = $expedition->adresse_livraison_id; $this->socid = $expedition->socid; - $this->ref_client = $expedition->ref_client; + $this->ref_customer = $expedition->ref_customer; return $this->create($user); } @@ -571,46 +556,60 @@ class Livraison extends CommonObject $sql.= " WHERE fk_livraison = ".$this->id; if ( $this->db->query($sql) ) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison"; - $sql.= " WHERE rowid = ".$this->id; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; + $sql.= " WHERE fk_target = ".$this->id; + $sql.= " AND targettype = '".$this->element."'"; if ( $this->db->query($sql) ) { - $this->db->commit(); - - // On efface le repertoire de pdf provisoire - $livref = dol_sanitizeFileName($this->ref); - if ($conf->livraison->dir_output) + $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison"; + $sql.= " WHERE rowid = ".$this->id; + if ( $this->db->query($sql) ) { - $dir = $conf->livraison->dir_output . "/" . $livref ; - $file = $conf->livraison->dir_output . "/" . $livref . "/" . $livref . ".pdf"; - if (file_exists($file)) + $this->db->commit(); + + // On efface le repertoire de pdf provisoire + $livref = dol_sanitizeFileName($this->ref); + if ($conf->livraison->dir_output) { - if (!dol_delete_file($file)) + $dir = $conf->livraison->dir_output . "/" . $livref ; + $file = $conf->livraison->dir_output . "/" . $livref . "/" . $livref . ".pdf"; + if (file_exists($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; + 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->error=$this->db->lasterror()." - sql=$sql"; + $this->db->rollback(); + return -3; } - - return 1; } else { + $this->error=$this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -2; } } else { + $this->error=$this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -1; } @@ -765,7 +764,7 @@ class Livraison extends CommonObject $this->specimen=1; $socid = rand(1, $num_socs); $this->socid = $socids[$socid]; - $this->date_livraison = time(); + $this->date_delivery = time(); $this->note_public='SPECIMEN'; $i=0;