Uniformize code

This commit is contained in:
Laurent Destailleur 2016-10-05 21:49:04 +02:00
parent 9ad96c2be3
commit e79a84a89b
4 changed files with 369 additions and 364 deletions

View File

@ -60,13 +60,13 @@ $langs->load('deliveries');
$langs->load('sendings'); $langs->load('sendings');
$langs->load('products'); $langs->load('products');
if (!empty($conf->incoterm->enabled)) $langs->load('incoterm'); if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
if (! empty($conf->margin->enabled)) if (! empty($conf->margin->enabled)) $langs->load('margins');
$langs->load('margins');
$id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('orderid', 'int')); $id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('orderid', 'int'));
$ref = GETPOST('ref', 'alpha'); $ref = GETPOST('ref', 'alpha');
$socid = GETPOST('socid', 'int'); $socid = GETPOST('socid', 'int');
$action = GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
$cancel = GETPOST('cancel', 'alpha');
$confirm = GETPOST('confirm', 'alpha'); $confirm = GETPOST('confirm', 'alpha');
$lineid = GETPOST('lineid', 'int'); $lineid = GETPOST('lineid', 'int');
$origin = GETPOST('origin', 'alpha'); $origin = GETPOST('origin', 'alpha');
@ -1765,16 +1765,12 @@ if ($action == 'create' && $user->rights->commande->creer)
$formconfirm = ''; $formconfirm = '';
/* // Confirmation to delete
* Confirmation de la suppression de la commande
*/
if ($action == 'delete') { if ($action == 'delete') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
} }
/* // Confirmation of validation
* Confirmation de la validation
*/
if ($action == 'validate') if ($action == 'validate')
{ {
// on verifie si l'objet est en numerotation provisoire // on verifie si l'objet est en numerotation provisoire
@ -1981,52 +1977,6 @@ if ($action == 'create' && $user->rights->commande->creer)
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Ref
/*
print '<tr><td class="titlefield">' . $langs->trans('Ref') . '</td>';
print '<td colspan="3">';
print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
print '</td>';
print '</tr>';
// Ref commande client
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">';
print $langs->trans('RefCustomer') . '</td><td align="left">';
print '</td>';
if ($action != 'refcustomer' && $object->brouillon)
print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=refcustomer&amp;id=' . $object->id . '">' . img_edit($langs->trans('Modify')) . '</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
if ($user->rights->commande->creer && $action == 'refcustomer') {
print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
print '<input type="hidden" name="action" value="set_ref_client">';
print '<input type="text" class="flat" size="20" name="ref_client" value="' . $object->ref_client . '">';
print ' <input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
print '</form>';
} else {
print $object->ref_client;
}
print '</td>';
print '</tr>';
// Third party
print '<tr><td>';
print '<table class="nobordernopadding" width="100%">';
print '<tr><td>' . $langs->trans('Company') . '</td>';
print '</td><td colspan="5">';
if (! empty($conf->global->COMMANDE_CHANGE_THIRDPARTY) && $action != 'editthirdparty' && $object->brouillon && $user->rights->commande->creer)
print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editthirdparty&amp;id=' . $object->id . '">' . img_edit($langs->trans('SetLinkToThirdParty'), 1) . '</a></td>';
print '</tr></table>';
print '</td><td colspan="5">';
if ($action == 'editthirdparty') {
$form->form_thirdparty($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, 'socid','client>0');
} else {
print $soc->getNomUrl(1, 'compta');
}
print '</tr>';*/
if ($soc->outstanding_limit) if ($soc->outstanding_limit)
{ {
// Outstanding Bill // Outstanding Bill
@ -2295,29 +2245,6 @@ if ($action == 'create' && $user->rights->commande->creer)
// TODO How record was recorded OrderMode (llx_c_input_method) // TODO How record was recorded OrderMode (llx_c_input_method)
// Project
/*
if (! empty($conf->projet->enabled))
{
$langs->load('projects');
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Project');
print '</td>';
if ($action != 'classify')
print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->trans('SetProject')) . '</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
// print "$object->id, $object->socid, $object->fk_project";
if ($action == 'classify') {
$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1);
} else {
$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0);
}
print '</td></tr>';
}
*/
// Incoterms // Incoterms
if (!empty($conf->incoterm->enabled)) if (!empty($conf->incoterm->enabled))
{ {

File diff suppressed because it is too large Load Diff

View File

@ -38,6 +38,7 @@ class Account extends CommonObject
{ {
public $element = 'bank_account'; public $element = 'bank_account';
public $table_element = 'bank_account'; public $table_element = 'bank_account';
public $picto = 'account';
/** /**
* @var int Use id instead of rowid * @var int Use id instead of rowid
@ -500,9 +501,10 @@ class Account extends CommonObject
* Create bank account into database * Create bank account into database
* *
* @param User $user Object user making creation * @param User $user Object user making creation
* @param int $notrigger 1=Disable triggers
* @return int < 0 if KO, > 0 if OK * @return int < 0 if KO, > 0 if OK
*/ */
function create(User $user = null) function create(User $user = null, $notrigger=0)
{ {
global $langs,$conf, $hookmanager; global $langs,$conf, $hookmanager;
@ -537,6 +539,8 @@ class Account extends CommonObject
$now=dol_now(); $now=dol_now();
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_account ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_account (";
$sql.= "datec"; $sql.= "datec";
$sql.= ", ref"; $sql.= ", ref";
@ -593,7 +597,7 @@ class Account extends CommonObject
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_account"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_account");
$result=$this->update($user); $result=$this->update($user, 1);
if ($result > 0) if ($result > 0)
{ {
$accline = new AccountLine($this->db); $accline = new AccountLine($this->db);
@ -606,52 +610,68 @@ class Account extends CommonObject
$accline->fk_type = 'SOLD'; $accline->fk_type = 'SOLD';
if ($accline->insert() < 0) { if ($accline->insert() < 0) {
return -3; $error++;
} }
// Actions on extra fields (by external module or standard code) if (! $error)
$hookmanager->initHooks(array('bankdao')); {
$parameters=array('id'=>$this->id); $result=$this->insertExtraFields();
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks if ($result < 0) $error++;
if (empty($reshook)) }
if (! $error && ! $notrigger)
{ {
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used // Call trigger
{ $result=$this->call_trigger('BANKACCOUNT_CREATE',$user);
$result=$this->insertExtraFields(); if ($result < 0) $error++;
if ($result < 0) // End call triggers
{
return -4;
}
}
} }
else if ($reshook < 0) return -5;
} }
return $this->id; else
{
$error++;
}
} }
else else
{ {
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{ {
$this->error=$langs->trans("ErrorBankLabelAlreadyExists"); $this->error=$langs->trans("ErrorBankLabelAlreadyExists");
return -1; $error++;
} }
else { else {
$this->error=$this->db->error()." sql=".$sql; $this->error=$this->db->error()." sql=".$sql;
return -2; $error++;
} }
} }
if (! $error)
{
$this->db->commit();
return $this->id;
}
else
{
$this->db->rollback();
return -1*$error;
}
} }
/** /**
* Update bank account card * Update bank account card
* *
* @param User $user Object user making action * @param User $user Object user making action
* @param int $notrigger 1=Disable triggers
* @return int <0 si ko, >0 si ok * @return int <0 si ko, >0 si ok
*/ */
function update(User $user = null) function update(User $user = null, $notrigger = 0)
{ {
global $langs,$conf, $hookmanager; global $langs,$conf, $hookmanager;
$error=0;
$this->db->begin();
// Clean parameters // Clean parameters
$this->state_id = ($this->state_id?$this->state_id:$this->state_id); $this->state_id = ($this->state_id?$this->state_id:$this->state_id);
$this->country_id = ($this->country_id?$this->country_id:$this->country_id); $this->country_id = ($this->country_id?$this->country_id:$this->country_id);
@ -710,33 +730,41 @@ class Account extends CommonObject
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
$hookmanager->initHooks(array('bankdao')); if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
$parameters=array('id'=>$this->id); {
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks if (! $error)
if (empty($reshook)) {
{ $result=$this->insertExtraFields();
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used if ($result < 0) $error++;
{ }
$result=$this->insertExtraFields(); }
if ($result < 0)
{
return -1;
}
}
}
else if ($reshook < 0) return -1;
if (! $error && ! $notrigger)
return 1; {
// Call trigger
$result=$this->call_trigger('BANKACCOUNT_UPDATE',$user);
if ($result < 0) $error++;
// End call triggers
}
} }
else else
{ {
$error++;
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
dol_print_error($this->db); dol_print_error($this->db);
return -1;
} }
if (! $error)
{
$this->db->commit();
return $this->id;
}
else
{
$this->db->rollback();
return -1*$error;
}
} }
@ -980,10 +1008,10 @@ class Account extends CommonObject
/** /**
* Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) * Return label of object status
* *
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto
* @return string Libelle * @return string Label
*/ */
function getLibStatut($mode=0) function getLibStatut($mode=0)
{ {
@ -991,11 +1019,11 @@ class Account extends CommonObject
} }
/** /**
* Renvoi le libelle d'un statut donne * Return label of given object status
* *
* @param int $statut Id statut * @param int $statut Id statut
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto
* @return string Libelle du statut * @return string Label
*/ */
function LibStatut($statut, $mode = 0) function LibStatut($statut, $mode = 0)
{ {
@ -1018,6 +1046,8 @@ class Account extends CommonObject
return $picto.' '.$label; return $picto.' '.$label;
} elseif ($mode == 5) { } elseif ($mode == 5) {
return $label.' '.$picto; return $label.' '.$picto;
} elseif ($mode == 6) {
return $label.' '.$picto;
} }
//There is no short mode for this label //There is no short mode for this label
@ -1369,10 +1399,11 @@ class Account extends CommonObject
* *
* Some countries show less or more bank account properties to the user * Some countries show less or more bank account properties to the user
* *
* @param int $includeibanbic 1=Return also key for IBAN and BIC
* @return array * @return array
* @see useDetailedBBAN * @see useDetailedBBAN
*/ */
public function getFieldsToShow() public function getFieldsToShow($includeibanbic=0)
{ {
//Get the required properties depending on the country //Get the required properties depending on the country
$detailedBBAN = $this->useDetailedBBAN(); $detailedBBAN = $this->useDetailedBBAN();
@ -1391,8 +1422,11 @@ class Account extends CommonObject
} }
//if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour) //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
if ($includeibanbic)
{
$fieldarray[]='IBAN'; $fieldarray[]='IBAN';
$fieldarray[]='BIC'; $fieldarray[]='BIC';
}
//} //}
//Get the order the properties are shown //Get the order the properties are shown
@ -1621,7 +1655,7 @@ class AccountLine extends CommonObject
$sql .= ", '".$this->db->idate($this->datev)."'"; $sql .= ", '".$this->db->idate($this->datev)."'";
$sql .= ", '".$this->db->escape($this->label)."'"; $sql .= ", '".$this->db->escape($this->label)."'";
$sql .= ", ".price2num($this->amount); $sql .= ", ".price2num($this->amount);
$sql .= ", '".$this->fk_user_author."'"; $sql .= ", ".($this->fk_user_author > 0 ? "'".$this->fk_user_author."'":"null");
$sql .= ", ".($this->num_chq ? "'".$this->num_chq."'" : "null"); $sql .= ", ".($this->num_chq ? "'".$this->num_chq."'" : "null");
$sql .= ", '".$this->fk_account."'"; $sql .= ", '".$this->fk_account."'";
$sql .= ", '".$this->db->escape($this->fk_type)."'"; $sql .= ", '".$this->db->escape($this->fk_type)."'";

View File

@ -217,7 +217,7 @@ abstract class CommonInvoice extends CommonObject
/** /**
* Return label of object status * Return label of object status
* *
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto
* @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
* @return string Label * @return string Label
*/ */