Select Shipping Method in Propal
This commit is contained in:
parent
acaca341ab
commit
f0a7cc3268
@ -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 '</td></tr>';
|
||||
|
||||
// Shipping Method
|
||||
print '<tr><td>' . $langs->trans('SendingMethod') . '</td><td colspan="2">';
|
||||
print $form->selectShippingMethod($fk_shipping_method, 'fk_shipping_method', '', 1);
|
||||
print '</td></tr>';
|
||||
|
||||
// Delivery date (or manufacturing)
|
||||
print '<tr><td>' . $langs->trans("DeliveryDate") . '</td>';
|
||||
print '<td colspan="2">';
|
||||
@ -1851,6 +1864,23 @@ if ($action == 'create') {
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Shipping Method
|
||||
print '<tr><td>';
|
||||
print '<table width="100%" class="nobordernopadding"><tr><td>';
|
||||
print $langs->trans('SendingMethod');
|
||||
print '<td>';
|
||||
if ($action != 'editshippingmethod' && $user->rights->propal->creer)
|
||||
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshippingmethod&id='.$object->id.'">'.img_edit($langs->trans('SetShippingMode'),1).'</a></td>';
|
||||
print '</tr></table>';
|
||||
print '</td><td colspan="3">';
|
||||
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 '</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Origin of demand
|
||||
print '<tr><td>';
|
||||
print '<table class="nobordernopadding" width="100%"><tr><td>';
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
*
|
||||
|
||||
@ -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 '<select id="select'.$htmlname.'" class="flat selectshippingmethod" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
|
||||
if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
|
||||
print '<option value="-1"> </option>';
|
||||
}
|
||||
while ($i < $num) {
|
||||
$obj = $this->db->fetch_object($result);
|
||||
if ($selected == $obj->rowid) {
|
||||
print '<option value="'.$obj->rowid.'" selected="selected">';
|
||||
} else {
|
||||
print '<option value="'.$obj->rowid.'">';
|
||||
}
|
||||
print $langs->trans("SendingMethod".strtoupper($obj->code));
|
||||
print '</option>';
|
||||
$i++;
|
||||
}
|
||||
print "</select>";
|
||||
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 '<form method="POST" action="'.$page.'">';
|
||||
print '<input type="hidden" name="action" value="setshippingmethod">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
|
||||
print '<tr><td>';
|
||||
$this->selectShippingMethod($selected, $htmlname, '', $addempty);
|
||||
print '</td>';
|
||||
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
|
||||
print '</tr></table></form>';
|
||||
} 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
|
||||
*
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user