From 9e8991f7fa47218a7d0dfb260285ba5bb860046e Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Sat, 10 Dec 2016 12:21:48 +0100 Subject: [PATCH] FIX : Bug when updateing availability and demand reason because $user is not passed to trigger. --- htdocs/comm/propal/card.php | 56 +++++++++++----------- htdocs/comm/propal/class/propal.class.php | 58 +++++++++++++++-------- 2 files changed, 67 insertions(+), 47 deletions(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 71e687e2168..37a60507d01 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -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 = '' . $langs->trans("BackToList") . ''; - + $morehtmlref='
'; // 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.='
'; - - + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - + + print '
'; print '
'; print '
'; - + print ''; - + // Ref /* print ''; print ''; */ - + // Company /* print ''; @@ -2107,42 +2107,42 @@ if ($action == 'create') include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; print '
' . $langs->trans('Ref') . ''; @@ -1784,7 +1784,7 @@ if ($action == 'create') print '
' . $langs->trans('Company') . '' . $soc->getNomUrl(1) . '
'; - + print '
'; print '
'; print '
'; print '
'; - + print ''; - + if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) { // Multicurrency Amount HT print ''; print ''; print ''; - + // Multicurrency Amount VAT print ''; print ''; print ''; - + // Multicurrency Amount TTC print ''; print ''; print ''; } - + // Amount HT print ''; print ''; print ''; - + // Amount VAT print ''; print ''; print ''; - + // Amount Local Taxes if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) // Localtax1 { @@ -2156,27 +2156,27 @@ if ($action == 'create') print ''; print ''; } - + // Amount TTC print ''; print ''; print ''; - + // Statut //print ''; - + print '
' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . '' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '
' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . '' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '
' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . '' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '
' . $langs->trans('AmountHT') . '' . price($object->total_ht, '', $langs, 0, - 1, - 1, $conf->currency) . '
' . $langs->trans('AmountVAT') . '' . price($object->total_tva, '', $langs, 0, - 1, - 1, $conf->currency) . '
' . price($object->total_localtax2, '', $langs, 0, - 1, - 1, $conf->currency) . '
' . $langs->trans('AmountTTC') . '' . price($object->total_ttc, '', $langs, 0, - 1, - 1, $conf->currency) . '
' . $langs->trans('Status') . '' . $object->getLibStatut(4) . '
'; - + // Margin Infos if (! empty($conf->margin->enabled)) { $formmargin->displayMarginInfos($object); } - + print '
'; print '
'; print '
'; - + print '

'; if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { @@ -2232,7 +2232,7 @@ if ($action == 'create') print ''; print ''; - + print "\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 '
'; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index f03242a8868..b9f5e3be6eb 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -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 = ''; + $linkstart.=$linkclose.'>'; $linkend=''; 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) {