Merge pull request #6109 from atm-florian/develop

fix : Bug when updating availability and demand reason on proposal because $user is not passed to trigger.
This commit is contained in:
Laurent Destailleur 2016-12-10 13:15:08 +01:00 committed by GitHub
commit 3a05bc4537
3 changed files with 248 additions and 228 deletions

View File

@ -1070,17 +1070,17 @@ if (empty($reshook))
// Set project
else if ($action == 'classin' && $user->rights->propal->creer) {
$object->setProject($_POST['projectid']);
$object->setProject(GETPOST('projectid','int'));
}
// Delai de livraison
else if ($action == 'setavailability' && $user->rights->propal->creer) {
$result = $object->availability($_POST['availability_id']);
$result = $object->set_availability($user, GETPOST('availability_id','int'));
}
// Origine de la propale
else if ($action == 'setdemandreason' && $user->rights->propal->creer) {
$result = $object->demand_reason($_POST['demand_reason_id']);
$result = $object->set_demand_reason($user, GETPOST('demand_reason_id','int'));
}
// Conditions de reglement
@ -1701,10 +1701,10 @@ if ($action == 'create')
// Proposal card
$linkback = '<a href="' . DOL_URL_ROOT . '/comm/propal/list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
$morehtmlref='<div class="refidno">';
// Ref customer
$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->propal->creer, 'string', '', 0, 1);
@ -1744,17 +1744,17 @@ if ($action == 'create')
}
}
$morehtmlref.='</div>';
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border" width="100%">';
// Ref
/*
print '<tr><td>' . $langs->trans('Ref') . '</td><td colspan="5">';
@ -1784,7 +1784,7 @@ if ($action == 'create')
print '</td>';
print '</tr>';
*/
// Company
/*
print '<tr><td>' . $langs->trans('Company') . '</td><td colspan="5">' . $soc->getNomUrl(1) . '</td>';
@ -2107,42 +2107,42 @@ if ($action == 'create')
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print '</table>';
print '</div>';
print '<div class="fichehalfright">';
print '<div class="ficheaddleft">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent">';
if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency))
{
// Multicurrency Amount HT
print '<tr><td class="titlefieldmiddle">' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . '</td>';
print '<td class="nowrap">' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
print '</tr>';
// Multicurrency Amount VAT
print '<tr><td>' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . '</td>';
print '<td class="nowrap">' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
print '</tr>';
// Multicurrency Amount TTC
print '<tr><td>' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . '</td>';
print '<td class="nowrap">' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
print '</tr>';
}
// Amount HT
print '<tr><td class="titlefieldmiddle">' . $langs->trans('AmountHT') . '</td>';
print '<td class="nowrap">' . price($object->total_ht, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
print '</tr>';
// Amount VAT
print '<tr><td>' . $langs->trans('AmountVAT') . '</td>';
print '<td class="nowrap">' . price($object->total_tva, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
print '</tr>';
// Amount Local Taxes
if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) // Localtax1
{
@ -2156,27 +2156,27 @@ if ($action == 'create')
print '<td class="nowrap">' . price($object->total_localtax2, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
print '</tr>';
}
// Amount TTC
print '<tr><td>' . $langs->trans('AmountTTC') . '</td>';
print '<td class="nowrap">' . price($object->total_ttc, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
print '</tr>';
// Statut
//print '<tr><td height="10">' . $langs->trans('Status') . '</td><td align="left" colspan="2">' . $object->getLibStatut(4) . '</td></tr>';
print '</table>';
// Margin Infos
if (! empty($conf->margin->enabled))
{
$formmargin->displayMarginInfos($object);
}
print '</div>';
print '</div>';
print '</div>';
print '<div class="clearboth"></div><br>';
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
@ -2232,7 +2232,7 @@ if ($action == 'create')
print '</table>';
print '</div>';
print "</form>\n";
dol_fiche_end();
@ -2391,7 +2391,7 @@ if ($action == 'create')
// Show links to link elements
$linktoelem = $form->showLinkToObjectBlock($object, null, array('propal'));
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
print '</div><div class="fichehalfright"><div class="ficheaddleft">';

View File

@ -50,7 +50,7 @@ class Propal extends CommonObject
public $fk_element='fk_propal';
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
public $picto='propal';
/**
* {@inheritdoc}
*/
@ -503,7 +503,7 @@ class Propal extends CommonObject
$this->line->label=$label;
$this->line->desc=$desc;
$this->line->qty=$qty;
$this->line->vat_src_code=$vat_src_code;
$this->line->tva_tx=$txtva;
$this->line->localtax1_tx=$txlocaltax1;
@ -638,7 +638,7 @@ class Propal extends CommonObject
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
// Clean vat code
$vat_src_code='';
if (preg_match('/\((.*)\)/', $txtva, $reg))
@ -1180,7 +1180,7 @@ class Propal extends CommonObject
$clonedObj->ref = $modPropale->getNextValue($objsoc,$clonedObj);
// Create clone
$result=$clonedObj->create($user);
if ($result < 0) $error++;
else
@ -1541,7 +1541,7 @@ class Propal extends CommonObject
dol_syslog(get_class($this)."::valid action abandonned: already validated", LOG_WARNING);
return 0;
}
if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->propal->creer))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->propal->propal_advance->validate))))
{
@ -1551,7 +1551,7 @@ class Propal extends CommonObject
}
$now=dol_now();
$this->db->begin();
// Numbering module definition
@ -1839,7 +1839,7 @@ class Propal extends CommonObject
*/
function set_availability($user, $id, $notrigger=0)
{
if (! empty($user->rights->propal->creer))
if (! empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT)
{
$error=0;
@ -1849,7 +1849,7 @@ class Propal extends CommonObject
$sql.= " SET fk_availability = '".$id."'";
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(__METHOD__, LOG_DEBUG);
dol_syslog(__METHOD__.' availability('.$availability_id.')', LOG_DEBUG);
$resql=$this->db->query($sql);
if (!$resql)
{
@ -1861,6 +1861,7 @@ class Propal extends CommonObject
{
$this->oldcopy= clone $this;
$this->fk_availability = $id;
$this->availability_id = $availability_id;
}
if (! $notrigger && empty($error))
@ -1887,6 +1888,14 @@ class Propal extends CommonObject
return -1*$error;
}
}
else
{
$error_str='Propal status do not meet requirement '.$this->statut;
dol_syslog(__METHOD__.$error_str, LOG_ERR);
$this->error=$error_str;
$this->errors[]= $this->error;
return -2;
}
}
/**
@ -1899,14 +1908,14 @@ class Propal extends CommonObject
*/
function set_demand_reason($user, $id, $notrigger=0)
{
if (! empty($user->rights->propal->creer))
if (! empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT)
{
$error=0;
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
$sql.= " SET fk_input_reason = '".$id."'";
$sql.= " SET fk_input_reason = ".$id;
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(__METHOD__, LOG_DEBUG);
@ -1922,6 +1931,7 @@ class Propal extends CommonObject
{
$this->oldcopy= clone $this;
$this->fk_input_reason = $id;
$this->demand_reason_id = $id;
}
@ -1949,6 +1959,14 @@ class Propal extends CommonObject
return -1*$error;
}
}
else
{
$error_str='Propal status do not meet requirement '.$this->statut;
dol_syslog(__METHOD__.$error_str, LOG_ERR);
$this->error=$error_str;
$this->errors[]= $this->error;
return -2;
}
}
/**
@ -2406,7 +2424,7 @@ class Propal extends CommonObject
$this->statut = self::STATUS_DRAFT;
$this->brouillon = 1;
}
if (! $notrigger && empty($error))
{
// Call trigger
@ -2733,6 +2751,7 @@ class Propal extends CommonObject
* @param int $availability_id Id of new delivery time
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int >0 if OK, <0 if KO
* @deprecated use set_availability
*/
function availability($availability_id, $notrigger=0)
{
@ -2753,7 +2772,7 @@ class Propal extends CommonObject
$this->errors[]=$this->db->error();
$error++;
}
if (! $error)
{
$this->oldcopy= clone $this;
@ -2800,6 +2819,7 @@ class Propal extends CommonObject
* @param int $demand_reason_id Id of new source demand
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int >0 si ok, <0 si ko
* @deprecated use set_demand_reason
*/
function demand_reason($demand_reason_id, $notrigger=0)
{
@ -2820,7 +2840,7 @@ class Propal extends CommonObject
$this->errors[]=$this->db->error();
$error++;
}
if (! $error)
{
$this->oldcopy= clone $this;
@ -3241,7 +3261,7 @@ class Propal extends CommonObject
global $langs, $conf, $user;
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
$result='';
$label='';
$url='';
@ -3272,7 +3292,7 @@ class Propal extends CommonObject
$url = DOL_URL_ROOT.'/comm/propal/document.php?id='.$this->id. $get_params;
}
}
$linkclose='';
if (empty($notooltip) && $user->rights->propal->lire)
{
@ -3284,9 +3304,9 @@ class Propal extends CommonObject
$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose.=' class="classfortooltip"';
}
$linkstart = '<a href="'.$url.'"';
$linkstart.=$linkclose.'>';
$linkstart.=$linkclose.'>';
$linkend='</a>';
if ($withpicto)
@ -3350,7 +3370,7 @@ class Propal extends CommonObject
$this->lines[$i]->fk_remise_except = $obj->fk_remise_except;
$this->lines[$i]->remise_percent = $obj->remise_percent;
$this->lines[$i]->vat_src_code = $obj->vat_src_code;
$this->lines[$i]->vat_src_code = $obj->vat_src_code;
$this->lines[$i]->tva_tx = $obj->tva_tx;
$this->lines[$i]->info_bits = $obj->info_bits;
$this->lines[$i]->total_ht = $obj->total_ht;
@ -3684,7 +3704,7 @@ class PropaleLigne extends CommonObjectLine
if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht=0;
if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva=0;
if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc=0;
// if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0 && $pa_ht_isemptystring)
{

File diff suppressed because it is too large Load Diff