From f0a7cc3268076f5b2097ec6a68408fb26bd6162c Mon Sep 17 00:00:00 2001 From: frederic34 Date: Thu, 24 Jul 2014 18:08:08 +0200 Subject: [PATCH 1/5] Select Shipping Method in Propal --- htdocs/comm/propal.php | 30 +++++++ htdocs/comm/propal/class/propal.class.php | 5 ++ htdocs/core/class/commonobject.class.php | 31 +++++++ htdocs/core/class/html.form.class.php | 89 +++++++++++++++++++ .../install/mysql/migration/3.6.0-3.7.0.sql | 3 + htdocs/install/mysql/tables/llx_propal.sql | 1 + 6 files changed, 159 insertions(+) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 64a3475572e..7b735e5e926 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -51,6 +51,7 @@ $langs->load('bills'); $langs->load('orders'); $langs->load('products'); $langs->load("deliveries"); +$langs->load('sendings'); if (! empty($conf->margin->enabled)) $langs->load('margins'); @@ -251,6 +252,7 @@ else if ($action == 'add' && $user->rights->propal->creer) { $object->availability_id = GETPOST('availability_id'); $object->demand_reason_id = GETPOST('demand_reason_id'); $object->fk_delivery_address = GETPOST('fk_address'); + $object->fk_shipping_method = GETPOST('fk_shipping_method', 'int'); $object->duree_validite = $duration; $object->cond_reglement_id = GETPOST('cond_reglement_id'); $object->mode_reglement_id = GETPOST('mode_reglement_id'); @@ -277,6 +279,7 @@ else if ($action == 'add' && $user->rights->propal->creer) { $object->availability_id = GETPOST('availability_id'); $object->demand_reason_id = GETPOST('demand_reason_id'); $object->fk_delivery_address = GETPOST('fk_address'); + $object->fk_shipping_method = GETPOST('fk_shipping_method', 'int'); $object->duree_validite = GETPOST('duree_validite'); $object->cond_reglement_id = GETPOST('cond_reglement_id'); $object->mode_reglement_id = GETPOST('mode_reglement_id'); @@ -1110,6 +1113,11 @@ else if ($action == 'setbankaccount' && $user->rights->propal->creer) { $result=$object->setBankAccount(GETPOST('fk_account', 'int')); } +// shipping method +else if ($action == 'setshippingmethod' && $user->rights->propal->creer) { + $result=$object->setShippingMethod(GETPOST('fk_shipping_method', 'int')); +} + /* * Ordonnancement des lignes */ @@ -1389,6 +1397,11 @@ if ($action == 'create') { $form->selectAvailabilityDelay('', 'availability_id', '', 1); print ''; + // Shipping Method + print '' . $langs->trans('SendingMethod') . ''; + print $form->selectShippingMethod($fk_shipping_method, 'fk_shipping_method', '', 1); + print ''; + // Delivery date (or manufacturing) print '' . $langs->trans("DeliveryDate") . ''; print ''; @@ -1851,6 +1864,23 @@ if ($action == 'create') { print ''; print ''; + // Shipping Method + print ''; + print ''; + print '
'; + print $langs->trans('SendingMethod'); + print ''; + if ($action != 'editshippingmethod' && $user->rights->propal->creer) + print 'id.'">'.img_edit($langs->trans('SetShippingMode'),1).'
'; + print ''; + if ($action == 'editshippingmethod') { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_shipping_method, 'fk_shipping_method', 1); + } else { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_shipping_method, 'none'); + } + print ''; + print ''; + // Origin of demand print ''; print ''; + // Shipping Method + print ''; + // What trigger creation print ''; print ''; + // Shipping Method + print ''; + print ''; + // Terms of payment print ''; print ''; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 9d2a8fbd256..1b7f50b8339 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -92,7 +92,7 @@ class Propal extends CommonObject var $fk_address; var $address_type; var $address; - var $fk_shipping_method; + var $shipping_method_id; var $availability_id; var $availability_code; var $demand_reason_id; @@ -746,7 +746,7 @@ class Propal extends CommonObject $sql.= ", ".($this->fk_account>0?$this->fk_account:'NULL'); $sql.= ", '".$this->db->escape($this->ref_client)."'"; $sql.= ", ".($this->date_livraison!=''?"'".$this->db->idate($this->date_livraison)."'":"null"); - $sql.= ", ".($this->fk_shipping_method>0?$this->fk_shipping_method:'NULL'); + $sql.= ", ".($this->shipping_method_id>0?$this->shipping_method_id:'NULL'); $sql.= ", ".$this->availability_id; $sql.= ", ".$this->demand_reason_id; $sql.= ", ".($this->fk_project?$this->fk_project:"null"); @@ -1110,7 +1110,7 @@ class Propal extends CommonObject $this->datep = $this->db->jdate($obj->dp); // deprecated $this->fin_validite = $this->db->jdate($obj->dfv); $this->date_livraison = $this->db->jdate($obj->date_livraison); - $this->fk_shipping_method = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null; + $this->shipping_method_id = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null; $this->availability_id = $obj->fk_availability; $this->availability_code = $obj->availability_code; $this->availability = $obj->availability; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 1eef43edda7..e7177879ae3 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -72,7 +72,7 @@ class Commande extends CommonOrder var $date; // Date commande var $date_commande; // Date commande (deprecated) var $date_livraison; // Date livraison souhaitee - var $fk_shipping_method; + var $shipping_method_id; var $fk_remise_except; var $remise_percent; var $total_ht; // Total net of tax @@ -677,7 +677,7 @@ class Commande extends CommonOrder $sql.= ", ".($this->demand_reason_id>0?"'".$this->demand_reason_id."'":"null"); $sql.= ", ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null"); $sql.= ", ".($this->fk_delivery_address>0?$this->fk_delivery_address:'NULL'); - $sql.= ", ".($this->fk_shipping_method>0?$this->fk_shipping_method:'NULL'); + $sql.= ", ".($this->shipping_method_id>0?$this->shipping_method_id:'NULL'); $sql.= ", ".($this->remise_absolue>0?$this->remise_absolue:'NULL'); $sql.= ", ".($this->remise_percent>0?$this->remise_percent:0); $sql.= ", ".$conf->entity; @@ -987,7 +987,7 @@ class Commande extends CommonOrder $this->availability_id = $object->availability_id; $this->demand_reason_id = $object->demand_reason_id; $this->date_livraison = $object->date_livraison; - $this->fk_shipping_method = $object->fk_shipping_method; + $this->shipping_method_id = $object->shipping_method_id; $this->fk_delivery_address = $object->fk_delivery_address; $this->contact_id = $object->contactid; $this->ref_client = $object->ref_client; @@ -1395,7 +1395,7 @@ class Commande extends CommonOrder $this->demand_reason_id = $obj->fk_input_reason; $this->demand_reason_code = $obj->demand_reason_code; $this->date_livraison = $this->db->jdate($obj->date_livraison); - $this->fk_shipping_method = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null; + $this->shipping_method_id = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null; $this->fk_delivery_address = $obj->fk_delivery_address; $this->extraparams = (array) json_decode($obj->extraparams, true); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index a78867e371d..cc7666515b9 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -229,7 +229,7 @@ else if ($action == 'add' && $user->rights->commande->creer) { $object->availability_id = GETPOST('availability_id'); $object->demand_reason_id = GETPOST('demand_reason_id'); $object->date_livraison = $datelivraison; - $object->fk_shipping_method = GETPOST('fk_shipping_method', 'int'); + $object->shipping_method_id = GETPOST('shipping_method_id', 'int'); $object->fk_delivery_address = GETPOST('fk_address'); $object->contactid = GETPOST('contactidp'); @@ -494,7 +494,7 @@ else if ($action == 'setbankaccount' && $user->rights->commande->creer) { // shipping method else if ($action == 'setshippingmethod' && $user->rights->commande->creer) { - $result = $object->setShippingMethod(GETPOST('fk_shipping_method', 'int')); + $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int')); } else if ($action == 'setremisepercent' && $user->rights->commande->creer) { @@ -1402,7 +1402,7 @@ if ($action == 'create' && $user->rights->commande->creer) { $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); $fk_account = (! empty($objectsrc->fk_account)?$objectsrc->fk_account:(! empty($soc->fk_account)?$soc->fk_account:0)); $availability_id = (!empty($objectsrc->availability_id)?$objectsrc->availability_id:(!empty($soc->availability_id)?$soc->availability_id:0)); - $fk_shipping_method = (! empty($objectsrc->fk_shipping_method)?$objectsrc->fk_shipping_method:(! empty($soc->fk_shipping_method)?$soc->fk_shipping_method:0)); + $shipping_method_id = (! empty($objectsrc->shipping_method_id)?$objectsrc->shipping_method_id:(! empty($soc->shipping_method_id)?$soc->shipping_method_id:0)); $demand_reason_id = (!empty($objectsrc->demand_reason_id)?$objectsrc->demand_reason_id:(!empty($soc->demand_reason_id)?$soc->demand_reason_id:0)); $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0)); $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0)); @@ -1423,7 +1423,7 @@ if ($action == 'create' && $user->rights->commande->creer) { $mode_reglement_id = $soc->mode_reglement_id; $fk_account = $soc->fk_account; $availability_id = $soc->availability_id; - $fk_shipping_method = $soc->fk_shipping_method; + $shipping_method_id = $soc->shipping_method_id; $demand_reason_id = $soc->demand_reason_id; $remise_percent = $soc->remise_percent; $remise_absolue = 0; @@ -1530,7 +1530,7 @@ if ($action == 'create' && $user->rights->commande->creer) { // Shipping Method print ''; // What trigger creation @@ -1998,9 +1998,9 @@ if ($action == 'create' && $user->rights->commande->creer) { print '
'; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 5a70aa99cbc..9d2a8fbd256 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -92,6 +92,7 @@ class Propal extends CommonObject var $fk_address; var $address_type; var $address; + var $fk_shipping_method; var $availability_id; var $availability_code; var $demand_reason_id; @@ -718,6 +719,7 @@ class Propal extends CommonObject $sql.= ", fk_account"; $sql.= ", ref_client"; $sql.= ", date_livraison"; + $sql.= ", fk_shipping_method"; $sql.= ", fk_availability"; $sql.= ", fk_input_reason"; $sql.= ", fk_projet"; @@ -744,6 +746,7 @@ class Propal extends CommonObject $sql.= ", ".($this->fk_account>0?$this->fk_account:'NULL'); $sql.= ", '".$this->db->escape($this->ref_client)."'"; $sql.= ", ".($this->date_livraison!=''?"'".$this->db->idate($this->date_livraison)."'":"null"); + $sql.= ", ".($this->fk_shipping_method>0?$this->fk_shipping_method:'NULL'); $sql.= ", ".$this->availability_id; $sql.= ", ".$this->demand_reason_id; $sql.= ", ".($this->fk_project?$this->fk_project:"null"); @@ -1053,6 +1056,7 @@ class Propal extends CommonObject $sql.= ", p.fk_cond_reglement"; $sql.= ", p.fk_mode_reglement"; $sql.= ', p.fk_account'; + $sql.= ", p.fk_shipping_method"; $sql.= ", c.label as statut_label"; $sql.= ", ca.code as availability_code, ca.label as availability"; $sql.= ", dr.code as demand_reason_code, dr.label as demand_reason"; @@ -1106,6 +1110,7 @@ class Propal extends CommonObject $this->datep = $this->db->jdate($obj->dp); // deprecated $this->fin_validite = $this->db->jdate($obj->dfv); $this->date_livraison = $this->db->jdate($obj->date_livraison); + $this->fk_shipping_method = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null; $this->availability_id = $obj->fk_availability; $this->availability_code = $obj->availability_code; $this->availability = $obj->availability; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 307164556c7..55922d0b096 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1042,6 +1042,37 @@ abstract class CommonObject } } + + /** + * Change the shipping method + * + * @param int $fk_shipping_method Id of shipping method + * @return int 1 if OK, 0 if KO + */ + function setShippingMethod($fk_shipping_method) + { + if (! $this->table_element) { + dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); + return -1; + } + if ($fk_shipping_method<0) $fk_shipping_method='NULL'; + dol_syslog(get_class($this).'::setShippingMethod('.$fk_shipping_method.')'); + + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql.= " SET fk_shipping_method = ".$fk_shipping_method; + $sql.= " WHERE rowid=".$this->id; + + if ($this->db->query($sql)) { + $this->fk_shipping_method = ($fk_shipping_method=='NULL')?null:$fk_shipping_method; + return 1; + } else { + dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); + $this->error=$this->db->error(); + return 0; + } + } + + /** * Set last model used by doc generator * diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 010e023b285..3960df5abd4 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2419,6 +2419,95 @@ class Form return $return; } + /** + * Return a HTML select list of shipping mode + * + * @param string $selected Id shipping mode pre-selected + * @param string $htmlname Name of select zone + * @param string $filtre To filter list + * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. + * @param string $moreattrib To add more attribute on select + * @return void + */ + function selectShippingMethod($selected='',$htmlname='fk_shipping_method',$filtre='',$useempty=0,$moreattrib='') + { + global $langs, $conf, $user; + + $langs->load("admin"); + $langs->load("deliveries"); + + $sql = "SELECT rowid, code, libelle"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode"; + $sql.= " WHERE active = 1"; + if ($filtre) $sql.=" AND ".$filtre; + $sql.= " ORDER BY libelle ASC"; + + dol_syslog(get_class($this)."::selectShippingMode", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) { + $num = $this->db->num_rows($result); + $i = 0; + if ($num) { + print '"; + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); + } else { + print $langs->trans("NoShippingMethodDefined"); + } + } else { + dol_print_error($this->db); + } + } + + /** + * Display form to select shipping mode + * + * @param string $page Page + * @param int $selected Id of shipping mode + * @param string $htmlname Name of select html field + * @param int $addempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. + * @return void + */ + function formSelectShippingMethod($page, $selected='', $htmlname='fk_shipping_method', $addempty=0) + { + global $langs, $db; + + $langs->load("deliveries"); + + if ($htmlname != "none") { + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + $this->selectShippingMethod($selected, $htmlname, '', $addempty); + print '
'; + } else { + if ($selected) { + $code=$langs->getLabelFromKey($db, $selected, 'c_shipment_mode', 'rowid', 'code'); + print $langs->trans("SendingMethod".strtoupper($code)); + } else { + print " "; + } + } + } + /** * Return a HTML select list of bank accounts * diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index 30e010431cc..de2c2de3f7f 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -122,3 +122,6 @@ create table llx_accounting_fiscalyear )ENGINE=innodb; ALTER TABLE llx_contrat ADD COLUMN ref_ext varchar(30) after ref; + +ALTER TABLE llx_propal ADD COLUMN fk_shipping_method integer AFTER date_livraison; + diff --git a/htdocs/install/mysql/tables/llx_propal.sql b/htdocs/install/mysql/tables/llx_propal.sql index 0ca800c9bca..c9ab3ecd138 100644 --- a/htdocs/install/mysql/tables/llx_propal.sql +++ b/htdocs/install/mysql/tables/llx_propal.sql @@ -61,6 +61,7 @@ create table llx_propal note_public text, model_pdf varchar(255), date_livraison date DEFAULT NULL, -- delivery date + fk_shipping_method integer, -- shipping method id fk_availability integer NULL, fk_input_reason integer, import_key varchar(14), From 4fcff3e2e5d7956533c90f608f29e7d1abd3c311 Mon Sep 17 00:00:00 2001 From: frederic34 Date: Fri, 25 Jul 2014 17:20:42 +0200 Subject: [PATCH 2/5] Select delivery method for order --- htdocs/comm/propal.php | 2 +- htdocs/commande/class/commande.class.php | 6 ++++ htdocs/commande/fiche.php | 30 +++++++++++++++++++ .../install/mysql/migration/3.6.0-3.7.0.sql | 1 + htdocs/install/mysql/tables/llx_commande.sql | 1 + 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 7b735e5e926..9920b7bcb0f 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1868,7 +1868,7 @@ if ($action == 'create') { print '
'; print ''; if ($action != 'editshippingmethod' && $user->rights->propal->creer) print ''; print '
'; print $langs->trans('SendingMethod'); - print ''; + print 'id.'">'.img_edit($langs->trans('SetShippingMode'),1).'
'; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 6c1b5eeed90..1eef43edda7 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -72,6 +72,7 @@ class Commande extends CommonOrder var $date; // Date commande var $date_commande; // Date commande (deprecated) var $date_livraison; // Date livraison souhaitee + var $fk_shipping_method; var $fk_remise_except; var $remise_percent; var $total_ht; // Total net of tax @@ -656,6 +657,7 @@ class Commande extends CommonOrder $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande ("; $sql.= " ref, fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note_private, note_public, ref_client, ref_int"; $sql.= ", model_pdf, fk_cond_reglement, fk_mode_reglement, fk_account, fk_availability, fk_input_reason, date_livraison, fk_delivery_address"; + $sql.= ", fk_shipping_method"; $sql.= ", remise_absolue, remise_percent"; $sql.= ", entity"; $sql.= ")"; @@ -675,6 +677,7 @@ class Commande extends CommonOrder $sql.= ", ".($this->demand_reason_id>0?"'".$this->demand_reason_id."'":"null"); $sql.= ", ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null"); $sql.= ", ".($this->fk_delivery_address>0?$this->fk_delivery_address:'NULL'); + $sql.= ", ".($this->fk_shipping_method>0?$this->fk_shipping_method:'NULL'); $sql.= ", ".($this->remise_absolue>0?$this->remise_absolue:'NULL'); $sql.= ", ".($this->remise_percent>0?$this->remise_percent:0); $sql.= ", ".$conf->entity; @@ -984,6 +987,7 @@ class Commande extends CommonOrder $this->availability_id = $object->availability_id; $this->demand_reason_id = $object->demand_reason_id; $this->date_livraison = $object->date_livraison; + $this->fk_shipping_method = $object->fk_shipping_method; $this->fk_delivery_address = $object->fk_delivery_address; $this->contact_id = $object->contactid; $this->ref_client = $object->ref_client; @@ -1327,6 +1331,7 @@ class Commande extends CommonOrder $sql.= ', c.fk_account'; $sql.= ', c.date_commande'; $sql.= ', c.date_livraison'; + $sql.= ", c.fk_shipping_method"; $sql.= ', c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture as billed'; $sql.= ', c.note_private, c.note_public, c.ref_client, c.ref_ext, c.ref_int, c.model_pdf, c.fk_delivery_address, c.extraparams'; $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; @@ -1390,6 +1395,7 @@ class Commande extends CommonOrder $this->demand_reason_id = $obj->fk_input_reason; $this->demand_reason_code = $obj->demand_reason_code; $this->date_livraison = $this->db->jdate($obj->date_livraison); + $this->fk_shipping_method = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null; $this->fk_delivery_address = $obj->fk_delivery_address; $this->extraparams = (array) json_decode($obj->extraparams, true); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 52cc27a42ef..a78867e371d 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -229,6 +229,7 @@ else if ($action == 'add' && $user->rights->commande->creer) { $object->availability_id = GETPOST('availability_id'); $object->demand_reason_id = GETPOST('demand_reason_id'); $object->date_livraison = $datelivraison; + $object->fk_shipping_method = GETPOST('fk_shipping_method', 'int'); $object->fk_delivery_address = GETPOST('fk_address'); $object->contactid = GETPOST('contactidp'); @@ -491,6 +492,11 @@ else if ($action == 'setbankaccount' && $user->rights->commande->creer) { $result=$object->setBankAccount(GETPOST('fk_account', 'int')); } +// shipping method +else if ($action == 'setshippingmethod' && $user->rights->commande->creer) { + $result = $object->setShippingMethod(GETPOST('fk_shipping_method', 'int')); +} + else if ($action == 'setremisepercent' && $user->rights->commande->creer) { $result = $object->set_remise($user, GETPOST('remise_percent')); } @@ -1396,6 +1402,7 @@ if ($action == 'create' && $user->rights->commande->creer) { $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); $fk_account = (! empty($objectsrc->fk_account)?$objectsrc->fk_account:(! empty($soc->fk_account)?$soc->fk_account:0)); $availability_id = (!empty($objectsrc->availability_id)?$objectsrc->availability_id:(!empty($soc->availability_id)?$soc->availability_id:0)); + $fk_shipping_method = (! empty($objectsrc->fk_shipping_method)?$objectsrc->fk_shipping_method:(! empty($soc->fk_shipping_method)?$soc->fk_shipping_method:0)); $demand_reason_id = (!empty($objectsrc->demand_reason_id)?$objectsrc->demand_reason_id:(!empty($soc->demand_reason_id)?$soc->demand_reason_id:0)); $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0)); $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0)); @@ -1416,6 +1423,7 @@ if ($action == 'create' && $user->rights->commande->creer) { $mode_reglement_id = $soc->mode_reglement_id; $fk_account = $soc->fk_account; $availability_id = $soc->availability_id; + $fk_shipping_method = $soc->fk_shipping_method; $demand_reason_id = $soc->demand_reason_id; $remise_percent = $soc->remise_percent; $remise_absolue = 0; @@ -1520,6 +1528,11 @@ if ($action == 'create' && $user->rights->commande->creer) { $form->selectAvailabilityDelay($availability_id, 'availability_id', '', 1); print '
' . $langs->trans('SendingMethod') . ''; + print $form->selectShippingMethod($fk_shipping_method, 'fk_shipping_method', '', 1); + print '
' . $langs->trans('Source') . ''; $form->selectInputReason($demand_reason_id, 'demand_reason_id', '', 1); @@ -1975,6 +1988,23 @@ if ($action == 'create' && $user->rights->commande->creer) { print '
'; + print ''; + if ($action != 'editshippingmethod' && $user->rights->commande->creer) + print ''; + print '
'; + print $langs->trans('SendingMethod'); + print 'id.'">'.img_edit($langs->trans('SetShippingMode'),1).'
'; + print '
'; + if ($action == 'editshippingmethod') { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_shipping_method, 'fk_shipping_method', 1); + } else { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_shipping_method, 'none'); + } + print '
'; print ''; // Delivery date (or manufacturing) @@ -1874,9 +1874,9 @@ if ($action == 'create') { print '
'; diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index de2c2de3f7f..2d8630b1501 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -124,4 +124,5 @@ create table llx_accounting_fiscalyear ALTER TABLE llx_contrat ADD COLUMN ref_ext varchar(30) after ref; ALTER TABLE llx_propal ADD COLUMN fk_shipping_method integer AFTER date_livraison; +ALTER TABLE llx_commande ADD COLUMN fk_shipping_method integer AFTER date_livraison; diff --git a/htdocs/install/mysql/tables/llx_commande.sql b/htdocs/install/mysql/tables/llx_commande.sql index f1c12a6741f..3cf3fdac226 100644 --- a/htdocs/install/mysql/tables/llx_commande.sql +++ b/htdocs/install/mysql/tables/llx_commande.sql @@ -61,6 +61,7 @@ create table llx_commande fk_mode_reglement integer, -- mode de reglement date_livraison date default NULL, + fk_shipping_method integer, -- shipping method id fk_availability integer NULL, fk_input_reason integer, fk_delivery_address integer, -- delivery address (deprecated) From 2df2c12cfd455129407efa6c46b783d434bcbe82 Mon Sep 17 00:00:00 2001 From: frederic34 Date: Fri, 25 Jul 2014 21:50:21 +0200 Subject: [PATCH 3/5] The delivery method is transmited in shipment --- htdocs/comm/propal.php | 12 +++++------ htdocs/comm/propal/class/propal.class.php | 6 +++--- htdocs/commande/class/commande.class.php | 8 ++++---- htdocs/commande/fiche.php | 14 ++++++------- htdocs/core/class/commonobject.class.php | 12 +++++------ htdocs/expedition/shipment.php | 25 +++++++++++++++++++++++ 6 files changed, 51 insertions(+), 26 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 9920b7bcb0f..8b38ffc9459 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -252,7 +252,7 @@ else if ($action == 'add' && $user->rights->propal->creer) { $object->availability_id = GETPOST('availability_id'); $object->demand_reason_id = GETPOST('demand_reason_id'); $object->fk_delivery_address = GETPOST('fk_address'); - $object->fk_shipping_method = GETPOST('fk_shipping_method', 'int'); + $object->shipping_method_id = GETPOST('shipping_method_id', 'int'); $object->duree_validite = $duration; $object->cond_reglement_id = GETPOST('cond_reglement_id'); $object->mode_reglement_id = GETPOST('mode_reglement_id'); @@ -279,7 +279,7 @@ else if ($action == 'add' && $user->rights->propal->creer) { $object->availability_id = GETPOST('availability_id'); $object->demand_reason_id = GETPOST('demand_reason_id'); $object->fk_delivery_address = GETPOST('fk_address'); - $object->fk_shipping_method = GETPOST('fk_shipping_method', 'int'); + $object->shipping_method_id = GETPOST('shipping_method_id', 'int'); $object->duree_validite = GETPOST('duree_validite'); $object->cond_reglement_id = GETPOST('cond_reglement_id'); $object->mode_reglement_id = GETPOST('mode_reglement_id'); @@ -1115,7 +1115,7 @@ else if ($action == 'setbankaccount' && $user->rights->propal->creer) { // shipping method else if ($action == 'setshippingmethod' && $user->rights->propal->creer) { - $result=$object->setShippingMethod(GETPOST('fk_shipping_method', 'int')); + $result=$object->setShippingMethod(GETPOST('shipping_method_id', 'int')); } /* @@ -1399,7 +1399,7 @@ if ($action == 'create') { // Shipping Method print '
' . $langs->trans('SendingMethod') . ''; - print $form->selectShippingMethod($fk_shipping_method, 'fk_shipping_method', '', 1); + print $form->selectShippingMethod($shipping_method_id, 'shipping_method_id', '', 1); print '
'; print '
'; if ($action == 'editshippingmethod') { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_shipping_method, 'fk_shipping_method', 1); + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1); } else { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_shipping_method, 'none'); + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none'); } print '
' . $langs->trans('SendingMethod') . ''; - print $form->selectShippingMethod($fk_shipping_method, 'fk_shipping_method', '', 1); + print $form->selectShippingMethod($shipping_method_id, 'shipping_method_id', '', 1); print '
'; print ''; if ($action == 'editshippingmethod') { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_shipping_method, 'fk_shipping_method', 1); + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1); } else { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_shipping_method, 'none'); + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none'); } print ''; print ''; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 55922d0b096..73dc9211000 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1046,24 +1046,24 @@ abstract class CommonObject /** * Change the shipping method * - * @param int $fk_shipping_method Id of shipping method + * @param int $shipping_method_id Id of shipping method * @return int 1 if OK, 0 if KO */ - function setShippingMethod($fk_shipping_method) + function setShippingMethod($shipping_method_id) { if (! $this->table_element) { dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); return -1; } - if ($fk_shipping_method<0) $fk_shipping_method='NULL'; - dol_syslog(get_class($this).'::setShippingMethod('.$fk_shipping_method.')'); + if ($shipping_method_id<0) $shipping_method_id='NULL'; + dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET fk_shipping_method = ".$fk_shipping_method; + $sql.= " SET fk_shipping_method = ".$shipping_method_id; $sql.= " WHERE rowid=".$this->id; if ($this->db->query($sql)) { - $this->fk_shipping_method = ($fk_shipping_method=='NULL')?null:$fk_shipping_method; + $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; return 1; } else { dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php index d44a7d5f4a4..0ad306ef8a3 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -116,6 +116,13 @@ if ($action == 'setconditions' && $user->rights->commande->creer) if ($result < 0) dol_print_error($db,$commande->error); } +// shipping method +if ($action == 'setshippingmethod' && $user->rights->commande->creer) { + $commande = new Commande($db); + $commande->fetch($id); + $result=$commande->setShippingMethod(GETPOST('shipping_method_id', 'int')); +} + /* @@ -262,6 +269,23 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; + // Shipping Method + print ''; + print ''; + if ($action != 'editshippingmethod' && $user->rights->expedition->creer) + print ''; + print '
'; + print $langs->trans('SendingMethod'); + print 'id.'">'.img_edit($langs->trans('SetShippingMode'),1).'
'; + print ''; + if ($action == 'editshippingmethod') { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->shipping_method_id, 'shipping_method_id', 1); + } else { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->shipping_method_id, 'none'); + } + print ''; + print ''; + // Terms of payment print ''; print '
'; @@ -607,6 +631,7 @@ if ($id > 0 || ! empty($ref)) print '
'; print ''; print ''; + print ''; print ''; print ''; print ''; From 5258c522ce58339a7cd93e6db9dd84edc4536571 Mon Sep 17 00:00:00 2001 From: frederic34 Date: Fri, 25 Jul 2014 23:20:19 +0200 Subject: [PATCH 4/5] Some cleaning --- htdocs/commande/class/commande.class.php | 2 +- htdocs/commande/fiche.php | 1 + htdocs/core/class/html.form.class.php | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index e7177879ae3..71419dfc1a3 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1331,7 +1331,7 @@ class Commande extends CommonOrder $sql.= ', c.fk_account'; $sql.= ', c.date_commande'; $sql.= ', c.date_livraison'; - $sql.= ", c.fk_shipping_method"; + $sql.= ', c.fk_shipping_method'; $sql.= ', c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture as billed'; $sql.= ', c.note_private, c.note_public, c.ref_client, c.ref_ext, c.ref_int, c.model_pdf, c.fk_delivery_address, c.extraparams'; $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index cc7666515b9..89b2674cb26 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -52,6 +52,7 @@ $langs->load('companies'); $langs->load('bills'); $langs->load('propal'); $langs->load('deliveries'); +$langs->load('sendings'); $langs->load('products'); if (! empty($conf->margin->enabled)) $langs->load('margins'); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 3960df5abd4..082d3336a75 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2429,7 +2429,7 @@ class Form * @param string $moreattrib To add more attribute on select * @return void */ - function selectShippingMethod($selected='',$htmlname='fk_shipping_method',$filtre='',$useempty=0,$moreattrib='') + function selectShippingMethod($selected='',$htmlname='shipping_method_id',$filtre='',$useempty=0,$moreattrib='') { global $langs, $conf, $user; @@ -2482,7 +2482,7 @@ class Form * @param int $addempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. * @return void */ - function formSelectShippingMethod($page, $selected='', $htmlname='fk_shipping_method', $addempty=0) + function formSelectShippingMethod($page, $selected='', $htmlname='shipping_method_id', $addempty=0) { global $langs, $db; From 0450498e2b4b52254daecc0350008ec4334c963c Mon Sep 17 00:00:00 2001 From: frederic34 Date: Sat, 26 Jul 2014 17:17:40 +0200 Subject: [PATCH 5/5] Add restriction to combo box --- htdocs/comm/propal.php | 38 +++++++++++++++++++++----------------- htdocs/commande/fiche.php | 38 +++++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 8b38ffc9459..2efb03baac8 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1398,9 +1398,11 @@ if ($action == 'create') { print ''; // Shipping Method - print ''; + if (! empty($conf->expedition->enabled)) { + print ''; + } // Delivery date (or manufacturing) print ''; @@ -1865,21 +1867,23 @@ if ($action == 'create') { print ''; // Shipping Method - print ''; + print ''; } - print ''; - print ''; // Origin of demand print ''; // Shipping Method - print ''; + if (! empty($conf->expedition->enabled)) { + print ''; + } // What trigger creation print ''; // Shipping Method - print ''; + print ''; } - print ''; - print ''; // Terms of payment print '
' . $langs->trans('SendingMethod') . ''; - print $form->selectShippingMethod($shipping_method_id, 'shipping_method_id', '', 1); - print '
' . $langs->trans('SendingMethod') . ''; + print $form->selectShippingMethod($shipping_method_id, 'shipping_method_id', '', 1); + print '
' . $langs->trans("DeliveryDate") . '
'; - print ''; - if ($action != 'editshippingmethod' && $user->rights->propal->creer) - print ''; - print '
'; - print $langs->trans('SendingMethod'); - print 'id.'">'.img_edit($langs->trans('SetShippingMode'),1).'
'; - print '
'; - if ($action == 'editshippingmethod') { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1); - } else { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none'); + if (! empty($conf->expedition->enabled)) { + print '
'; + print ''; + if ($action != 'editshippingmethod' && $user->rights->propal->creer) + print ''; + print '
'; + print $langs->trans('SendingMethod'); + print 'id.'">'.img_edit($langs->trans('SetShippingMode'),1).'
'; + print '
'; + if ($action == 'editshippingmethod') { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1); + } else { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none'); + } + print '
'; diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 89b2674cb26..c54e2f187e4 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1530,9 +1530,11 @@ if ($action == 'create' && $user->rights->commande->creer) { print '
' . $langs->trans('SendingMethod') . ''; - print $form->selectShippingMethod($shipping_method_id, 'shipping_method_id', '', 1); - print '
' . $langs->trans('SendingMethod') . ''; + print $form->selectShippingMethod($shipping_method_id, 'shipping_method_id', '', 1); + print '
' . $langs->trans('Source') . ''; @@ -1990,21 +1992,23 @@ if ($action == 'create' && $user->rights->commande->creer) { print '
'; - print ''; - if ($action != 'editshippingmethod' && $user->rights->commande->creer) - print ''; - print '
'; - print $langs->trans('SendingMethod'); - print 'id.'">'.img_edit($langs->trans('SetShippingMode'),1).'
'; - print '
'; - if ($action == 'editshippingmethod') { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1); - } else { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none'); + if (! empty($conf->expedition->enabled)) { + print '
'; + print ''; + if ($action != 'editshippingmethod' && $user->rights->commande->creer) + print ''; + print '
'; + print $langs->trans('SendingMethod'); + print 'id.'">'.img_edit($langs->trans('SetShippingMode'),1).'
'; + print '
'; + if ($action == 'editshippingmethod') { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1); + } else { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none'); + } + print '
';