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 '
'; 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),