';
+ print '
';
- if ($account->type == Account::TYPE_SAVINGS || $account->type == Account::TYPE_CURRENT)
+
+ print '
';
+
+ // Accountancy code
+ print ''.$langs->trans("AccountancyCode").' ';
+ print '';
+ if (! empty($conf->accounting->enabled)) {
+ print length_accountg($object->account_number).' ';
+ } else {
+ print $object->account_number;
+ }
+ print '';
+
+ // Accountancy journal
+ if (! empty($conf->accounting->enabled))
{
- print '';
+ print ''.$langs->trans("AccountancyJournal").' ';
+ print ''.$object->accountancy_journal.' ';
+ }
+
+ print '
';
+
+
+ if ($object->type == Account::TYPE_SAVINGS || $object->type == Account::TYPE_CURRENT)
+ {
+ print ' ';
+
+ print '';
- print ''.$langs->trans("BankName").' ';
- print ''.$account->bank.' ';
+ print ''.$langs->trans("BankName").' ';
+ print ''.$object->bank.' ';
// Show fields of bank account
- foreach ($account->getFieldsToShow() as $val) {
+ foreach ($object->getFieldsToShow() as $val) {
if ($val == 'BankCode') {
- $content = $account->code_banque;
+ $content = $object->code_banque;
} elseif ($val == 'DeskCode') {
- $content = $account->code_guichet;
+ $content = $object->code_guichet;
} elseif ($val == 'BankAccountNumber') {
- $content = $account->number;
+ $content = $object->number;
} elseif ($val == 'BankAccountNumberKey') {
- $content = $account->cle_rib;
+ $content = $object->cle_rib;
}
print ''.$langs->trans($val).' ';
@@ -666,14 +726,14 @@ else
print ' ';
}
- $ibankey = FormBank::getIBANLabel($account);
+ $ibankey = FormBank::getIBANLabel($object);
$bickey="BICNumber";
- if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
+ if ($object->getCountryCode() == 'IN') $bickey="SWIFT";
print ''.$langs->trans($ibankey).' ';
- print ''.$account->iban.' ';
- if (! empty($account->iban)) {
- if (! checkIbanForAccount($account)) {
+ print ' '.$object->iban.' ';
+ if (! empty($object->iban)) {
+ if (! checkIbanForAccount($object)) {
print img_picto($langs->trans("IbanNotValid"),'warning');
} else {
print img_picto($langs->trans("IbanValid"),'info');
@@ -682,9 +742,9 @@ else
print ' ';
print ''.$langs->trans($bickey).' ';
- print ''.$account->bic.' ';
- if (! empty($account->bic)) {
- if (! checkSwiftForAccount($account)) {
+ print ' '.$object->bic.' ';
+ if (! empty($object->bic)) {
+ if (! checkSwiftForAccount($object)) {
print img_picto($langs->trans("SwiftNotValid"),'warning');
} else {
print img_picto($langs->trans("SwiftValid"),'info');
@@ -692,44 +752,28 @@ else
}
print ' ';
- print ''.$langs->trans("BankAccountDomiciliation").' ';
- print nl2br($account->domiciliation);
+ print ' '.$langs->trans("BankAccountDomiciliation").' ';
+ print nl2br($object->domiciliation);
print " \n";
- print ''.$langs->trans("BankAccountOwner").' ';
- print $account->proprio;
+ print ' '.$langs->trans("BankAccountOwner").' ';
+ print $object->proprio;
print " \n";
- print ''.$langs->trans("BankAccountOwnerAddress").' ';
- print nl2br($account->owner_address);
+ print ' '.$langs->trans("BankAccountOwnerAddress").' ';
+ print nl2br($object->owner_address);
print " \n";
print '
';
- print ' ';
}
- print '';
- // Accountancy code
- print ''.$langs->trans("AccountancyCode").' ';
- print '';
- if (! empty($conf->accounting->enabled)) {
- print length_accountg($account->account_number).' ';
- } else {
- print $account->account_number;
- }
- print '';
-
- // Accountancy journal
- if (! empty($conf->accounting->enabled))
- {
- print ''.$langs->trans("AccountancyJournal").' ';
- print ''.$account->accountancy_journal.' ';
- }
-
- print '
';
-
+ print '';
+ print '';
print '';
+ print '
';
+
+ dol_fiche_end();
/*
* Barre d'actions
@@ -738,13 +782,13 @@ else
if ($user->rights->banque->configurer)
{
- print 'id.'">'.$langs->trans("Modify").' ';
+ print 'id.'">'.$langs->trans("Modify").' ';
}
- $canbedeleted=$account->can_be_deleted(); // Renvoi vrai si compte sans mouvements
+ $canbedeleted=$object->can_be_deleted(); // Renvoi vrai si compte sans mouvements
if ($user->rights->banque->configurer && $canbedeleted)
{
- print 'id.'">'.$langs->trans("Delete").' ';
+ print 'id.'">'.$langs->trans("Delete").' ';
}
print '';
@@ -759,8 +803,8 @@ else
if (GETPOST('id','int') && $action == 'edit' && $user->rights->banque->configurer)
{
- $account = new Account($db);
- $account->fetch(GETPOST('id','int'));
+ $object = new Account($db);
+ $object->fetch(GETPOST('id','int'));
print load_fiche_titre($langs->trans("EditFinancialAccount"), '', 'title_bank.png');
@@ -783,7 +827,7 @@ else
print ''."\n";
}
- print '
';
print '
';
@@ -909,27 +953,27 @@ else
// If bank account
print '
'.$langs->trans("BankName").' ';
- print ' ';
+ print ' ';
print '';
// Show fields of bank account
- foreach ($account->getFieldsToShow() as $val) {
+ foreach ($object->getFieldsToShow() as $val) {
if ($val == 'BankCode') {
$name = 'code_banque';
$size = 8;
- $content = $account->code_banque;
+ $content = $object->code_banque;
} elseif ($val == 'DeskCode') {
$name = 'code_guichet';
$size = 8;
- $content = $account->code_guichet;
+ $content = $object->code_guichet;
} elseif ($val == 'BankAccountNumber') {
$name = 'number';
$size = 18;
- $content = $account->number;
+ $content = $object->number;
} elseif ($val == 'BankAccountNumberKey') {
$name = 'cle_rib';
$size = 3;
- $content = $account->cle_rib;
+ $content = $object->cle_rib;
}
print '
'.$langs->trans($val).' ';
@@ -937,29 +981,29 @@ else
print '';
}
- $ibankey = FormBank::getIBANLabel($account);
+ $ibankey = FormBank::getIBANLabel($object);
$bickey="BICNumber";
- if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
+ if ($object->getCountryCode() == 'IN') $bickey="SWIFT";
// IBAN
print '
'.$langs->trans($ibankey).' ';
- print '';
+ print '
';
print '
'.$langs->trans($bickey).' ';
- print '';
+ print '
';
print '
'.$langs->trans("BankAccountDomiciliation").' ';
print " ";
print '
'.$langs->trans("BankAccountOwner").' ';
- print ' ';
+ print ' ';
print '';
print '
'.$langs->trans("BankAccountOwnerAddress").' ';
print " ";
print '';
@@ -978,9 +1022,9 @@ else
print '
'.$langs->trans("AccountancyCode").' ';
print '';
if (!empty($conf->accounting->enabled)) {
- print $formaccountancy->select_account($account->account_number, 'account_number', 1, '', 1, 1);
+ print $formaccountancy->select_account($object->account_number, 'account_number', 1, '', 1, 1);
} else {
- print ' account_number).'">';
+ print ' account_number).'">';
}
print ' ';
@@ -988,7 +1032,7 @@ else
if (! empty($conf->accounting->enabled))
{
print '
'.$langs->trans("AccountancyJournal").' ';
- print ' accountancy_journal).'">';
+ print '
accountancy_journal).'">';
}
print '';
diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php
index 922f2636767..dfeea54c510 100644
--- a/htdocs/compta/bank/class/account.class.php
+++ b/htdocs/compta/bank/class/account.class.php
@@ -38,7 +38,8 @@ class Account extends CommonObject
{
public $element = 'bank_account';
public $table_element = 'bank_account';
-
+ public $picto = 'account';
+
/**
* @var int Use id instead of rowid
* @deprecated
@@ -500,9 +501,10 @@ class Account extends CommonObject
* Create bank account into database
*
* @param User $user Object user making creation
+ * @param int $notrigger 1=Disable triggers
* @return int < 0 if KO, > 0 if OK
*/
- function create(User $user = null)
+ function create(User $user = null, $notrigger=0)
{
global $langs,$conf, $hookmanager;
@@ -537,6 +539,8 @@ class Account extends CommonObject
$now=dol_now();
+ $this->db->begin();
+
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_account (";
$sql.= "datec";
$sql.= ", ref";
@@ -593,7 +597,7 @@ class Account extends CommonObject
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_account");
- $result=$this->update($user);
+ $result=$this->update($user, 1);
if ($result > 0)
{
$accline = new AccountLine($this->db);
@@ -606,52 +610,68 @@ class Account extends CommonObject
$accline->fk_type = 'SOLD';
if ($accline->insert() < 0) {
- return -3;
+ $error++;
}
- // Actions on extra fields (by external module or standard code)
- $hookmanager->initHooks(array('bankdao'));
- $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 (empty($reshook))
+ if (! $error)
+ {
+ $result=$this->insertExtraFields();
+ if ($result < 0) $error++;
+ }
+
+ if (! $error && ! $notrigger)
{
- if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
- {
- $result=$this->insertExtraFields();
- if ($result < 0)
- {
- return -4;
- }
- }
- }
- else if ($reshook < 0) return -5;
+ // Call trigger
+ $result=$this->call_trigger('BANKACCOUNT_CREATE',$user);
+ if ($result < 0) $error++;
+ // End call triggers
+ }
+ }
+ else
+ {
+ $error++;
}
- return $this->id;
}
else
{
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$this->error=$langs->trans("ErrorBankLabelAlreadyExists");
- return -1;
+ $error++;
}
else {
$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
*
* @param User $user Object user making action
+ * @param int $notrigger 1=Disable triggers
* @return int <0 si ko, >0 si ok
*/
- function update(User $user = null)
+ function update(User $user = null, $notrigger = 0)
{
global $langs,$conf, $hookmanager;
+ $error=0;
+
+ $this->db->begin();
+
// Clean parameters
$this->state_id = ($this->state_id?$this->state_id:$this->state_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);
if ($result)
{
-
// Actions on extra fields (by external module or standard code)
- $hookmanager->initHooks(array('bankdao'));
- $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 (empty($reshook))
- {
- if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
- {
- $result=$this->insertExtraFields();
- if ($result < 0)
- {
- return -1;
- }
- }
- }
- else if ($reshook < 0) return -1;
-
-
- return 1;
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+ {
+ if (! $error)
+ {
+ $result=$this->insertExtraFields();
+ if ($result < 0) $error++;
+ }
+ }
+
+ if (! $error && ! $notrigger)
+ {
+ // Call trigger
+ $result=$this->call_trigger('BANKACCOUNT_UPDATE',$user);
+ if ($result < 0) $error++;
+ // End call triggers
+ }
}
else
{
+ $error++;
$this->error=$this->db->lasterror();
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
- * @return string Libelle
+ * @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 Label
*/
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 $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
- * @return string Libelle du statut
+ * @param int $statut Id statut
+ * @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 Label
*/
function LibStatut($statut, $mode = 0)
{
@@ -1018,6 +1046,8 @@ class Account extends CommonObject
return $picto.' '.$label;
} elseif ($mode == 5) {
return $label.' '.$picto;
+ } elseif ($mode == 6) {
+ return $label.' '.$picto;
}
//There is no short mode for this label
@@ -1368,11 +1398,12 @@ class Account extends CommonObject
* - DeskCode
*
* 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
* @see useDetailedBBAN
*/
- public function getFieldsToShow()
+ public function getFieldsToShow($includeibanbic=0)
{
//Get the required properties depending on the country
$detailedBBAN = $this->useDetailedBBAN();
@@ -1391,8 +1422,11 @@ class Account extends CommonObject
}
//if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
+ if ($includeibanbic)
+ {
$fieldarray[]='IBAN';
$fieldarray[]='BIC';
+ }
//}
//Get the order the properties are shown
@@ -1621,7 +1655,7 @@ class AccountLine extends CommonObject
$sql .= ", '".$this->db->idate($this->datev)."'";
$sql .= ", '".$this->db->escape($this->label)."'";
$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->fk_account."'";
$sql .= ", '".$this->db->escape($this->fk_type)."'";
diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php
index c08d645cf53..99c425778e6 100644
--- a/htdocs/core/class/commoninvoice.class.php
+++ b/htdocs/core/class/commoninvoice.class.php
@@ -217,7 +217,7 @@ abstract class CommonInvoice extends CommonObject
/**
* 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)
* @return string Label
*/