--- /tmp/dsg/dolibarr/htdocs/compta/bank/class/github_account.class.php
+++ /tmp/dsg/dolibarr/htdocs/compta/bank/class/client_account.class.php
@@ -173,8 +173,8 @@
public $account_number;
/**
- * @var int ID
- */
+ * @var int ID
+ */
public $fk_accountancy_journal;
/**
@@ -305,7 +305,7 @@
*
* @param DoliDB $db Database handler
*/
- public function __construct(DoliDB $db)
+ public function __construct(DoliDB $db)
{
global $langs;
@@ -342,9 +342,9 @@
$string .= $this->code_guichet.' ';
} elseif ($val == 'BankAccountNumberKey') {
$string .= $this->cle_rib.' ';
- } elseif ($val == 'BIC') {
+ }elseif ($val == 'BIC') {
$string .= $this->bic.' ';
- } elseif ($val == 'IBAN') {
+ }elseif ($val == 'IBAN') {
$string .= $this->iban.' ';
}
}
@@ -358,7 +358,7 @@
*
* @return int 1 if need to be concialiated, < 0 otherwise.
*/
- public function canBeConciliated()
+ public function canBeConciliated()
{
global $conf;
@@ -369,7 +369,7 @@
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Add a link between bank line record and its source
*
@@ -380,9 +380,9 @@
* @param string $type Type of link ('payment', 'company', 'member', ...)
* @return int <0 if KO, id line if OK
*/
- public function add_url_line($line_id, $url_id, $url, $label, $type)
- {
- // phpcs:enable
+ public function add_url_line($line_id, $url_id, $url, $label, $type)
+ {
+ // phpcs:enable
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url (";
$sql .= "fk_bank";
$sql .= ", url_id";
@@ -390,11 +390,11 @@
$sql .= ", label";
$sql .= ", type";
$sql .= ") VALUES (";
- $sql .= " ".((int) $line_id);
- $sql .= ", '".$this->db->escape($url_id)."'";
- $sql .= ", '".$this->db->escape($url)."'";
+ $sql .= "'".$line_id."'";
+ $sql .= ", '".$url_id."'";
+ $sql .= ", '".$url."'";
$sql .= ", '".$this->db->escape($label)."'";
- $sql .= ", '".$this->db->escape($type)."'";
+ $sql .= ", '".$type."'";
$sql .= ")";
dol_syslog(get_class($this)."::add_url_line", LOG_DEBUG);
@@ -402,13 +402,15 @@
{
$rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_url");
return $rowid;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
return -1;
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* TODO Move this into AccountLine
* Return array with links from llx_bank_url
@@ -418,9 +420,9 @@
* @param string $type To search using type
* @return array|int Array of links array('url'=>, 'url_id'=>, 'label'=>, 'type'=> 'fk_bank'=> ) or -1 on error
*/
- public function get_url($fk_bank = '', $url_id = '', $type = '')
- {
- // phpcs:enable
+ public function get_url($fk_bank = '', $url_id = '', $type = '')
+ {
+ // phpcs:enable
$lines = array();
// Check parameters
@@ -434,7 +436,8 @@
$sql .= " FROM ".MAIN_DB_PREFIX."bank_url";
if ($fk_bank > 0) {
$sql .= " WHERE fk_bank = ".$fk_bank;
- } else { $sql .= " WHERE url_id = ".$url_id." AND type = '".$this->db->escape($type)."'";
+ }
+ else { $sql .= " WHERE url_id = ".$url_id." AND type = '".$type."'";
}
$sql .= " ORDER BY type, label";
@@ -460,7 +463,8 @@
$lines[$i]['fk_bank'] = $obj->fk_bank;
$i++;
}
- } else dol_print_error($this->db);
+ }
+ else dol_print_error($this->db);
return $lines;
}
@@ -469,10 +473,10 @@
* Add an entry into table ".MAIN_DB_PREFIX."bank
*
* @param int $date Date operation
- * @param string $oper 'VIR','PRE','LIQ','VAD','CB','CHQ'...
+ * @param string $oper 1,2,3,4... (deprecated) or 'TYP','VIR','PRE','LIQ','VAD','CB','CHQ'...
* @param string $label Descripton
* @param float $amount Amount
- * @param string $num_chq Numero cheque or transfer
+ * @param string $num_chq Numero cheque ou virement
* @param int $categorie Category id (optionnal)
* @param User $user User that create
* @param string $emetteur Name of cheque writer
@@ -481,7 +485,7 @@
* @param int $datev Date value
* @return int Rowid of added entry, <0 if KO
*/
- public function addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur = '', $banque = '', $accountancycode = '', $datev = null)
+ public function addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur = '', $banque = '', $accountancycode = '', $datev = null)
{
// Deprecation warning
if (is_numeric($oper)) {
@@ -504,7 +508,9 @@
{
$obj = $this->db->fetch_object($resql);
$oper = $obj->code;
- } else {
+ }
+ else
+ {
dol_print_error($this->db, 'Failed to get payment type code');
return -1;
}
@@ -566,19 +572,15 @@
if (!$result) {
$this->error = $this->db->lasterror();
$this->db->rollback();
-
return -3;
}
}
$this->db->commit();
-
return $accline->id;
} else {
- $this->error = $accline->error;
- $this->errors = $accline->errors;
+ $this->error = $this->db->lasterror();
$this->db->rollback();
-
return -2;
}
}
@@ -590,7 +592,7 @@
* @param int $notrigger 1=Disable triggers
* @return int < 0 if KO, > 0 if OK
*/
- public function create(User $user, $notrigger = 0)
+ public function create(User $user, $notrigger = 0)
{
global $langs, $conf, $hookmanager;
@@ -717,15 +719,20 @@
if ($result < 0) $error++;
// End call triggers
}
- } else {
+ }
+ else
+ {
$error++;
}
- } else {
+ }
+ else
+ {
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$this->error = $langs->trans("ErrorBankLabelAlreadyExists");
$error++;
- } else {
+ }
+ else {
$this->error = $this->db->error()." sql=".$sql;
$error++;
}
@@ -735,7 +742,9 @@
{
$this->db->commit();
return $this->id;
- } else {
+ }
+ else
+ {
$this->db->rollback();
return -1 * $error;
}
@@ -748,7 +757,7 @@
* @param int $notrigger 1=Disable triggers
* @return int <0 if KO, >0 if OK
*/
- public function update(User $user, $notrigger = 0)
+ public function update(User $user, $notrigger = 0)
{
global $langs, $conf, $hookmanager;
@@ -826,7 +835,9 @@
if ($result < 0) $error++;
// End call triggers
}
- } else {
+ }
+ else
+ {
$error++;
$this->error = $this->db->lasterror();
dol_print_error($this->db);
@@ -836,23 +847,25 @@
{
$this->db->commit();
return $this->id;
- } else {
+ }
+ else
+ {
$this->db->rollback();
return -1 * $error;
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Update BBAN (RIB) account fields
*
* @param User $user Object user making update
* @return int <0 if KO, >0 if OK
*/
- public function update_bban(User $user = null)
- {
- // phpcs:enable
+ public function update_bban(User $user = null)
+ {
+ // phpcs:enable
global $conf, $langs;
// Clean parameters
@@ -893,7 +906,9 @@
if ($result)
{
return 1;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
dol_print_error($this->db);
return -1;
@@ -908,7 +923,7 @@
* @param string $ref Ref of bank account to get
* @return int <0 if KO, >0 if OK
*/
- public function fetch($id, $ref = '')
+ public function fetch($id, $ref = '')
{
global $conf;
@@ -926,11 +941,11 @@
$sql .= " ba.datec as date_creation, ba.tms as date_update,";
$sql .= ' c.code as country_code, c.label as country,';
$sql .= ' d.code_departement as state_code, d.nom as state';
- $sql .= ' , aj.code as accountancy_journal';
+ $sql .= ' , aj.code as accountancy_journal';
$sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON ba.fk_pays = c.rowid';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON ba.state_id = d.rowid';
- $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
+ $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
$sql .= " WHERE ba.entity IN (".getEntity($this->element).")";
if ($id) $sql .= " AND ba.rowid = ".$id;
if ($ref) $sql .= " AND ba.ref = '".$this->db->escape($ref)."'";
@@ -985,15 +1000,19 @@
$this->date_creation = $this->db->jdate($obj->date_creation);
$this->date_update = $this->db->jdate($obj->date_update);
- // Retrieve all extrafield
+ // Retreive all extrafield
// fetch optionals attributes and labels
$this->fetch_optionals();
return 1;
- } else {
+ }
+ else
+ {
return 0;
}
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror;
$this->errors[] = $this->error;
return -1;
@@ -1008,10 +1027,10 @@
* Existing categories are left untouch.
*
* @param int[]|int $categories Category or categories IDs
- * @return void
- */
- public function setCategories($categories)
- {
+ * @return void
+ */
+ public function setCategories($categories)
+ {
// Handle single category
if (!is_array($categories)) {
$categories = array($categories);
@@ -1052,7 +1071,7 @@
* @param User $user User deleting
* @return int <0 if KO, >0 if OK
*/
- public function delete(User $user = null)
+ public function delete(User $user = null)
{
global $conf;
@@ -1093,7 +1112,9 @@
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
}
}
- } else {
+ }
+ else
+ {
$error++;
$this->error = "Error ".$this->db->lasterror();
}
@@ -1103,7 +1124,9 @@
{
$this->db->commit();
return 1;
- } else {
+ }
+ else
+ {
$this->db->rollback();
return -1;
}
@@ -1116,12 +1139,12 @@
* @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
*/
- public function getLibStatut($mode = 0)
+ public function getLibStatut($mode = 0)
{
return $this->LibStatut($this->clos, $mode);
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return label of given object status
*
@@ -1129,9 +1152,9 @@
* @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
*/
- public function LibStatut($status, $mode = 0)
- {
- // phpcs:enable
+ public function LibStatut($status, $mode = 0)
+ {
+ // phpcs:enable
global $langs;
$langs->load('banks');
@@ -1149,15 +1172,15 @@
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Renvoi si un compte peut etre supprimer ou non (sans mouvements)
*
* @return boolean vrai si peut etre supprime, faux sinon
*/
- public function can_be_deleted()
- {
- // phpcs:enable
+ public function can_be_deleted()
+ {
+ // phpcs:enable
$can_be_deleted = false;
$sql = "SELECT COUNT(rowid) as nb";
@@ -1168,7 +1191,8 @@
if ($resql) {
$obj = $this->db->fetch_object($resql);
if ($obj->nb <= 1) $can_be_deleted = true; // Juste le solde
- } else {
+ }
+ else {
dol_print_error($this->db);
}
return $can_be_deleted;
@@ -1180,7 +1204,7 @@
*
* @return string Error string
*/
- public function error()
+ public function error()
{
return $this->error;
}
@@ -1191,7 +1215,7 @@
* @param int $option 1=Exclude future operation date (this is to exclude input made in advance and have real account sold)
* @return int Current sold (value date <= today)
*/
- public function solde($option = 0)
+ public function solde($option = 0)
{
$solde = 0;
@@ -1217,7 +1241,7 @@
return price2num($solde, 'MU');
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Load indicators for dashboard (this->nbtodo and this->nbtodolate)
*
@@ -1225,9 +1249,9 @@
* @param int $filteraccountid To get info for a particular account id
* @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK
*/
- public function load_board(User $user, $filteraccountid = 0)
- {
- // phpcs:enable
+ public function load_board(User $user, $filteraccountid = 0)
+ {
+ // phpcs:enable
global $conf, $langs;
if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe
@@ -1266,22 +1290,24 @@
}
return $response;
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
$this->error = $this->db->error();
return -1;
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Charge indicateurs this->nb de tableau de bord
* @param int $filteraccountid To get info for a particular account id
* @return int <0 if ko, >0 if ok
*/
- public function load_state_board($filteraccountid = 0)
- {
- // phpcs:enable
+ public function load_state_board($filteraccountid = 0)
+ {
+ // phpcs:enable
global $user;
if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe
@@ -1303,7 +1329,9 @@
$this->nb["banklines"] = $obj->nb;
}
$this->db->free($resql);
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
$this->error = $this->db->error();
return -1;
@@ -1316,7 +1344,7 @@
*
* @return int Nb of account we can reconciliate
*/
- public function countAccountToReconcile()
+ public static function countAccountToReconcile()
{
global $db, $conf, $user;
@@ -1332,12 +1360,13 @@
$sql .= " WHERE ba.rappro > 0 and ba.clos = 0";
$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
if (empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) $sql .= " AND ba.courant != 2";
- $resql = $this->db->query($sql);
+ $resql = $db->query($sql);
if ($resql)
{
- $obj = $this->db->fetch_object($resql);
+ $obj = $db->fetch_object($resql);
$nb = $obj->nb;
- } else dol_print_error($this->db);
+ }
+ else dol_print_error($db);
return $nb;
}
@@ -1349,18 +1378,15 @@
* @param string $mode ''=Link to card, 'transactions'=Link to transactions card
* @param string $option ''=Show ref, 'reflabel'=Show ref+label
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
- * @param int $notooltip 1=Disable tooltip
+ * @param int $notooltip 1=Disable tooltip
* @return string Chaine avec URL
*/
- public function getNomUrl($withpicto = 0, $mode = '', $option = '', $save_lastsearch_value = -1, $notooltip = 0)
+ public function getNomUrl($withpicto = 0, $mode = '', $option = '', $save_lastsearch_value = -1, $notooltip = 0)
{
global $conf, $langs, $user;
$result = '';
- $label = img_picto('', $this->picto).' '.$langs->trans("BankAccount").'';
- if (isset($this->status)) {
- $label .= ' '.$this->getLibStatut(5);
- }
+ $label = ''.$langs->trans("BankAccount").'';
$label .= '
'.$langs->trans('Label').': '.$this->label;
$label .= '
'.$langs->trans('AccountNumber').': '.$this->number;
$label .= '
'.$langs->trans('IBAN').': '.$this->iban;
@@ -1379,6 +1405,9 @@
$label .= '
'.$langs->trans('AccountAccounting').': '.length_accountg($this->account_number);
$label .= '
'.$langs->trans('AccountancyJournal').': '.$this->accountancy_journal;
}
+ if (isset($this->status)) {
+ $label .= '
'.$langs->trans("Status").": ".$this->getLibStatut(5);
+ }
$linkclose = '" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
@@ -1386,7 +1415,8 @@
if ($mode == 'transactions')
{
$url = DOL_URL_ROOT.'/compta/bank/bankentries_list.php?id='.$this->id;
- } elseif ($mode == 'receipts')
+ }
+ elseif ($mode == 'receipts')
{
$url = DOL_URL_ROOT.'/compta/bank/releve.php?account='.$this->id;
}
@@ -1402,10 +1432,10 @@
$linkstart = 'error_number == 0)
{
return 1;
- } else {
+ }
+ else
+ {
return 0;
}
}
@@ -1456,7 +1488,7 @@
*
* @return string country code
*/
- public function getCountryCode()
+ public function getCountryCode()
{
global $mysoc;
@@ -1494,7 +1526,7 @@
* 1=Need 2 fields for bank code: Bank, Desk (France, Spain, ...) + Account number and key
* 2=Need 1 field for bank code: Bank only (Sort code for Great Britain, BSB for Australia) + Account number
*/
- public function useDetailedBBAN()
+ public function useDetailedBBAN()
{
$country_code = $this->getCountryCode();
@@ -1508,7 +1540,7 @@
*
* @return int 1 = mandatory / 0 = Not mandatory
*/
- public function needIBAN()
+ public function needIBAN()
{
$country_code = $this->getCountryCode();
@@ -1558,7 +1590,7 @@
* @param int $id Id of object to load
* @return void
*/
- public function info($id)
+ public function info($id)
{
}
@@ -1641,7 +1673,7 @@
//Replace the old AccountNumber key with the new BankAccountNumber key
$fieldlists = explode(
' ',
- preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
+ preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
);
}
}
@@ -1657,7 +1689,7 @@
*
* @return void
*/
- public function initAsSpecimen()
+ public function initAsSpecimen()
{
$this->specimen = 1;
$this->ref = 'MBA';
@@ -1689,10 +1721,10 @@
*/
public $error = '';
- /**
- * @var DoliDB Database handler.
- */
- public $db;
+ /**
+ * @var DoliDB Database handler.
+ */
+ public $db;
/**
* @var string ID to identify managed object
@@ -1707,85 +1739,62 @@
/**
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
*/
- public $picto = 'accountline';
+ public $picto = 'generic';
/**
* @var int ID
*/
public $id;
- /**
- * @var string Ref
- */
- public $ref;
-
- /**
- * Date creation record (datec)
- *
- * @var integer
- */
- public $datec;
-
- /**
- * Date (dateo)
- *
- * @var integer
- */
+ /**
+ * @var string Ref
+ */
+ public $ref;
+
+ /**
+ * Date creation record (datec)
+ *
+ * @var integer
+ */
+ public $datec;
+
+ /**
+ * Date (dateo)
+ *
+ * @var integer
+ */
public $dateo;
/**
- * Date value (datev)
- *
- * @var integer
- */
+ * Date value (datev)
+ *
+ * @var integer
+ */
public $datev;
public $amount;
- /**
- * @var int ID
- */
+ /**
+ * @var string bank transaction lines label
+ */
+ public $label;
+
+ public $note;
+
+ /**
+ * @var int ID
+ */
public $fk_user_author;
/**
- * @var int ID
- */
+ * @var int ID
+ */
public $fk_user_rappro;
/**
- * @var int ID
- */
+ * @var int ID
+ */
public $fk_type;
-
- /**
- * @var int ID of cheque receipt
- */
- public $fk_bordereau;
-
- /**
- * @var int ID of bank account
- */
- public $fk_account;
-
- /**
- * @var string Ref of bank account
- */
- public $bank_account_ref;
-
- /**
- * @var string Label of bank account
- */
- public $bank_account_label;
-
- /**
- * @var string Bank account numero
- */
- public $numero_compte;
-
- /**
- * @var string Name of check issuer
- */
- public $emetteur;
public $rappro; // Is it conciliated
public $num_releve; // If conciliated, what is bank statement
@@ -1793,20 +1802,31 @@
public $bank_chq; // Bank of cheque
/**
- * @var string bank transaction lines label
- */
- public $label;
-
- public $note;
-
-
+ * @var int ID of cheque receipt
+ */
+ public $fk_bordereau;
+
+ /**
+ * @var int ID of bank account
+ */
+ public $fk_account;
+
+ /**
+ * @var string Label of bank account
+ */
+ public $bank_account_label;
+
+ /**
+ * @var string Name of check issuer
+ */
+ public $emetteur;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
- public function __construct(DoliDB $db)
+ public function __construct(DoliDB $db)
{
$this->db = $db;
}
@@ -1819,7 +1839,7 @@
* @param string $num External num to load (ex: num of transaction for paypal fee)
* @return int <0 if KO, 0 if OK but not found, >0 if OK and found
*/
- public function fetch($rowid, $ref = '', $num = '')
+ public function fetch($rowid, $ref = '', $num = '')
{
global $conf;
@@ -1838,7 +1858,7 @@
$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
if ($num) $sql .= " AND b.num_chq='".$this->db->escape($num)."'";
elseif ($ref) $sql .= " AND b.rowid='".$this->db->escape($ref)."'";
- else $sql .= " AND b.rowid = ".((int) $rowid);
+ else $sql .= " AND b.rowid=".$rowid;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$result = $this->db->query($sql);
@@ -1879,7 +1899,9 @@
}
$this->db->free($result);
return $ret;
- } else {
+ }
+ else
+ {
return -1;
}
}
@@ -1939,9 +1961,9 @@
* @param User $user User object that delete
* @return int <0 if KO, >0 if OK
*/
- public function delete(User $user = null)
- {
- global $conf;
+ public function delete(User $user = null)
+ {
+ global $conf;
$nbko = 0;
@@ -1966,7 +1988,8 @@
$this->db->rollback();
return -1;
}
- } else {
+ }
+ else {
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
@@ -1994,23 +2017,25 @@
{
$this->db->commit();
return 1;
- } else {
+ }
+ else
+ {
$this->db->rollback();
return -$nbko;
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Delete bank line records
*
* @param User $user User object that delete
* @return int <0 if KO, >0 if OK
*/
- public function delete_urls(User $user = null)
- {
- // phpcs:enable
+ public function delete_urls(User $user = null)
+ {
+ // phpcs:enable
$nbko = 0;
if ($this->rappro)
@@ -2031,7 +2056,9 @@
{
$this->db->commit();
return 1;
- } else {
+ }
+ else
+ {
$this->db->rollback();
return -$nbko;
}
@@ -2045,7 +2072,7 @@
* @param int $notrigger 0=Disable all triggers
* @return int <0 if KO, >0 if OK
*/
- public function update(User $user, $notrigger = 0)
+ public function update(User $user, $notrigger = 0)
{
$this->db->begin();
@@ -2061,7 +2088,9 @@
{
$this->db->commit();
return 1;
- } else {
+ }
+ else
+ {
$this->db->rollback();
$this->error = $this->db->error();
return -1;
@@ -2069,7 +2098,7 @@
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Update conciliation field
*
@@ -2078,9 +2107,9 @@
* @param int $conciliated 1=Set transaction to conciliated, 0=Keep transaction non conciliated
* @return int <0 if KO, >0 if OK
*/
- public function update_conciliation(User $user, $cat, $conciliated = 1)
- {
- // phpcs:enable
+ public function update_conciliation(User $user, $cat, $conciliated = 1)
+ {
+ // phpcs:enable
global $conf, $langs;
$this->db->begin();
@@ -2125,14 +2154,16 @@
$this->db->commit();
return 1;
- } else {
+ }
+ else
+ {
$this->db->rollback();
return -1;
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Increase/decrease value date of a rowid
*
@@ -2140,9 +2171,9 @@
* @param int $sign 1 or -1
* @return int >0 if OK, 0 if KO
*/
- public function datev_change($rowid, $sign = 1)
- {
- // phpcs:enable
+ public function datev_change($rowid, $sign = 1)
+ {
+ // phpcs:enable
$sql = "SELECT datev FROM ".MAIN_DB_PREFIX."bank WHERE rowid = ".$rowid;
$resql = $this->db->query($sql);
if ($resql)
@@ -2161,42 +2192,45 @@
{
return 1;
}
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
return 0;
}
- } else dol_print_error($this->db);
+ }
+ else dol_print_error($this->db);
return 0;
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Increase value date of a rowid
*
* @param int $id Id of line to change
* @return int >0 if OK, 0 if KO
*/
- public function datev_next($id)
- {
- // phpcs:enable
+ public function datev_next($id)
+ {
+ // phpcs:enable
return $this->datev_change($id, 1);
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Decrease value date of a rowid
*
* @param int $id Id of line to change
* @return int >0 if OK, 0 if KO
*/
- public function datev_previous($id)
- {
- // phpcs:enable
+ public function datev_previous($id)
+ {
+ // phpcs:enable
return $this->datev_change($id, -1);
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Increase/decrease operation date of a rowid
*
@@ -2204,9 +2238,9 @@
* @param int $sign 1 or -1
* @return int >0 if OK, 0 if KO
*/
- public function dateo_change($rowid, $sign = 1)
- {
- // phpcs:enable
+ public function dateo_change($rowid, $sign = 1)
+ {
+ // phpcs:enable
$sql = "SELECT dateo FROM ".MAIN_DB_PREFIX."bank WHERE rowid = ".$rowid;
$resql = $this->db->query($sql);
if ($resql)
@@ -2225,37 +2259,40 @@
{
return 1;
}
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
return 0;
}
- } else dol_print_error($this->db);
+ }
+ else dol_print_error($this->db);
return 0;
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Increase operation date of a rowid
*
* @param int $id Id of line to change
* @return int >0 if OK, 0 if KO
*/
- public function dateo_next($id)
- {
- // phpcs:enable
+ public function dateo_next($id)
+ {
+ // phpcs:enable
return $this->dateo_change($id, 1);
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Decrease operation date of a rowid
*
* @param int $id Id of line to change
* @return int >0 if OK, 0 if KO
*/
- public function dateo_previous($id)
- {
- // phpcs:enable
+ public function dateo_previous($id)
+ {
+ // phpcs:enable
return $this->dateo_change($id, -1);
}
@@ -2266,7 +2303,7 @@
* @param int $id Id of object to load
* @return void
*/
- public function info($id)
+ public function info($id)
{
$sql = 'SELECT b.rowid, b.datec, b.tms as datem,';
$sql .= ' b.fk_user_author, b.fk_user_rappro';
@@ -2299,7 +2336,9 @@
//$this->date_rappro = $obj->daterappro; // Not yet managed
}
$this->db->free($result);
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
}
}
@@ -2314,21 +2353,18 @@
* @param int $notooltip 1=Disable tooltip
* @return string Chaine avec URL
*/
- public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
+ public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
{
global $langs;
$result = '';
-
- $label = img_picto('', $this->picto).' '.$langs->trans("Transaction").':
';
- $label .= ''.$langs->trans("Ref").': '.$this->ref;
-
- $linkstart = '';
+ $label = $langs->trans("ShowTransaction").': '.$this->rowid;
+ $linkstart = '';
$linkend = '';
$result .= $linkstart;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'account'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
- if ($withpicto != 2) $result .= ($this->ref ? $this->ref : $this->id);
+ if ($withpicto != 2) $result .= ($this->ref ? $this->ref : $this->rowid);
$result .= $linkend;
if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') $result .= ' (';
@@ -2371,12 +2407,12 @@
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
* @return string Libelle
*/
- public function getLibStatut($mode = 0)
+ public function getLibStatut($mode = 0)
{
return $this->LibStatut($this->status, $mode);
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Renvoi le libelle d'un statut donne
*
@@ -2384,9 +2420,9 @@
* @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
*/
- public function LibStatut($status, $mode = 0)
- {
- // phpcs:enable
+ public function LibStatut($status, $mode = 0)
+ {
+ // phpcs:enable
global $langs;
//$langs->load('companies');
/*
@@ -2434,7 +2470,7 @@
$type = 'bank';
- $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".$this->id;
+ $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$type."' AND ab.fk_doc = ".$this->id;
$resql = $this->db->query($sql);
if ($resql)
{
@@ -2443,7 +2479,9 @@
{
$alreadydispatched = $obj->nb;
}
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
return -1;
}
--- /tmp/dsg/dolibarr/htdocs/compta/bank/class/github_api_bankaccounts.class.php
+++ /tmp/dsg/dolibarr/htdocs/compta/bank/class/client_api_bankaccounts.class.php
@@ -30,56 +30,414 @@
class BankAccounts extends DolibarrApi
{
- /**
- * array $FIELDS Mandatory fields, checked when creating an object
- */
- static $FIELDS = array(
- 'ref',
- 'label',
- 'type',
- 'currency_code',
- 'country_id'
- );
-
- /**
- * Constructor
- */
- public function __construct()
- {
- global $db;
- $this->db = $db;
- }
-
- /**
- * Get the list of accounts.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Limit for list
- * @param int $page Page number
+ /**
+ * array $FIELDS Mandatory fields, checked when creating an object
+ */
+ static $FIELDS = array(
+ 'ref',
+ 'label',
+ 'type',
+ 'currency_code',
+ 'country_id'
+ );
+
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ global $db;
+ $this->db = $db;
+ }
+
+ /**
+ * Get the list of accounts.
+ *
+ * @param string $sortfield Sort field
+ * @param string $sortorder Sort order
+ * @param int $limit Limit for list
+ * @param int $page Page number
* @param int $category Use this param to filter list by category
+ * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.import_key:<:'20160101')"
+ * @return array List of account objects
+ *
+ * @throws RestException
+ */
+ public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $category = 0, $sqlfilters = '')
+ {
+ $list = array();
+
+ if (!DolibarrApiAccess::$user->rights->banque->lire) {
+ throw new RestException(401);
+ }
+
+ $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."bank_account as t";
+ if ($category > 0) {
+ $sql .= ", ".MAIN_DB_PREFIX."categorie_account as c";
+ }
+ $sql .= ' WHERE t.entity IN ('.getEntity('bank_account').')';
+ // Select accounts of given category
+ if ($category > 0) {
+ $sql .= " AND c.fk_categorie = ".$this->db->escape($category)." AND c.fk_account = t.rowid ";
+ }
+ // Add sql filters
+ if ($sqlfilters)
+ {
+ if (!DolibarrApi::_checkFilters($sqlfilters))
+ {
+ throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
+ }
+ $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
+ $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
+ }
+
+ $sql .= $this->db->order($sortfield, $sortorder);
+ if ($limit) {
+ if ($page < 0)
+ {
+ $page = 0;
+ }
+ $offset = $limit * $page;
+
+ $sql .= $this->db->plimit($limit + 1, $offset);
+ }
+
+ dol_syslog("API Rest request");
+ $result = $this->db->query($sql);
+
+ if ($result) {
+ $num = $this->db->num_rows($result);
+ $min = min($num, ($limit <= 0 ? $num : $limit));
+ for ($i = 0; $i < $min; $i++) {
+ $obj = $this->db->fetch_object($result);
+ $account = new Account($this->db);
+ if ($account->fetch($obj->rowid) > 0) {
+ $list[] = $this->_cleanObjectDatas($account);
+ }
+ }
+ } else {
+ throw new RestException(503, 'Error when retrieving list of accounts: '.$this->db->lasterror());
+ }
+
+ return $list;
+ }
+
+ /**
+ * Get account by ID.
+ *
+ * @param int $id ID of account
+ * @return array Account object
+ *
+ * @throws RestException
+ */
+ public function get($id)
+ {
+ if (!DolibarrApiAccess::$user->rights->banque->lire) {
+ throw new RestException(401);
+ }
+
+ $account = new Account($this->db);
+ $result = $account->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'account not found');
+ }
+
+ return $this->_cleanObjectDatas($account);
+ }
+
+ /**
+ * Create account object
+ *
+ * @param array $request_data Request data
+ * @return int ID of account
+ */
+ public function post($request_data = null)
+ {
+ if (!DolibarrApiAccess::$user->rights->banque->configurer) {
+ throw new RestException(401);
+ }
+ // Check mandatory fields
+ $result = $this->_validate($request_data);
+
+ $account = new Account($this->db);
+ foreach ($request_data as $field => $value) {
+ $account->$field = $value;
+ }
+ // Date of the initial balance (required to create an account).
+ $account->date_solde = time();
+ // courant and type are the same thing but the one used when
+ // creating an account is courant
+ $account->courant = $account->type;
+
+ if ($account->create(DolibarrApiAccess::$user) < 0) {
+ throw new RestException(500, 'Error creating bank account', array_merge(array($account->error), $account->errors));
+ }
+ return $account->id;
+ }
+
+ /**
+ * Create an internal wire transfer between two bank accounts
+ *
+ * @param int $bankaccount_from_id BankAccount ID to use as the source of the internal wire transfer {@from body}{@required true}
+ * @param int $bankaccount_to_id BankAccount ID to use as the destination of the internal wire transfer {@from body}{@required true}
+ * @param string $date Date of the internal wire transfer (UNIX timestamp) {@from body}{@required true}{@type timestamp}
+ * @param string $description Description of the internal wire transfer {@from body}{@required true}
+ * @param float $amount Amount to transfer from the source to the destination BankAccount {@from body}{@required true}
+ * @param float $amount_to Amount to transfer to the destination BankAccount (only when accounts does not share the same currency) {@from body}{@required false}
+ *
+ * @url POST /transfer
+ *
+ * @return array
+ *
+ * @status 201
+ *
+ * @throws RestException 401 Unauthorized: User does not have permission to configure bank accounts
+ * @throws RestException 404 Not Found: Either the source or the destination bankaccount for the provided id does not exist
+ * @throws RestException 422 Unprocessable Entity: Refer to detailed exception message for the cause
+ * @throws RestException 500 Internal Server Error: Error(s) returned by the RDBMS
+ */
+ public function transfer($bankaccount_from_id = 0, $bankaccount_to_id = 0, $date = null, $description = "", $amount = 0.0, $amount_to = 0.0)
+ {
+ if (!DolibarrApiAccess::$user->rights->banque->configurer) {
+ throw new RestException(401);
+ }
+
+ if ($bankaccount_from_id === $bankaccount_to_id) {
+ throw new RestException(422, 'bankaccount_from_id and bankaccount_to_id must be different !');
+ }
+
+ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
+
+ $accountfrom = new Account($this->db);
+ $resultAccountFrom = $accountfrom->fetch($bankaccount_from_id);
+
+ if ($resultAccountFrom === 0) {
+ throw new RestException(404, 'The BankAccount for bankaccount_from_id provided does not exist.');
+ }
+
+ $accountto = new Account($this->db);
+ $resultAccountTo = $accountto->fetch($bankaccount_to_id);
+
+ if ($resultAccountTo === 0) {
+ throw new RestException(404, 'The BankAccount for bankaccount_to_id provided does not exist.');
+ }
+
+ if ($accountto->currency_code == $accountfrom->currency_code)
+ {
+ $amount_to = $amount;
+ }
+ else
+ {
+ if (!$amount_to || empty($amount_to))
+ {
+ throw new RestException(422, 'You must provide amount_to value since bankaccount_from and bankaccount_to does not share the same currency.');
+ }
+ }
+
+ $this->db->begin();
+
+ $error = 0;
+ $bank_line_id_from = 0;
+ $bank_line_id_to = 0;
+ $result = 0;
+ $user = DolibarrApiAccess::$user;
+
+ // By default, electronic transfert from bank to bank
+ $typefrom = 'PRE';
+ $typeto = 'VIR';
+
+ if ($accountto->courant == Account::TYPE_CASH || $accountfrom->courant == Account::TYPE_CASH)
+ {
+ // This is transfer of change
+ $typefrom = 'LIQ';
+ $typeto = 'LIQ';
+ }
+
+ /**
+ * Creating bank line records
+ */
+
+ if (!$error) {
+ $bank_line_id_from = $accountfrom->addline($date, $typefrom, $description, -1 * price2num($amount), '', '', $user);
+ }
+ if (!($bank_line_id_from > 0)) {
+ $error++;
+ }
+
+ if (!$error) {
+ $bank_line_id_to = $accountto->addline($date, $typeto, $description, price2num($amount_to), '', '', $user);
+ }
+ if (!($bank_line_id_to > 0)) {
+ $error++;
+ }
+
+ /**
+ * Creating links between bank line record and its source
+ */
+
+ $url = DOL_URL_ROOT.'/compta/bank/line.php?rowid=';
+ $label = '(banktransfert)';
+ $type = 'banktransfert';
+
+ if (!$error) {
+ $result = $accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, $url, $label, $type);
+ }
+ if (!($result > 0)) {
+ $error++;
+ }
+
+ if (!$error) {
+ $result = $accountto->add_url_line($bank_line_id_to, $bank_line_id_from, $url, $label, $type);
+ }
+ if (!($result > 0)) {
+ $error++;
+ }
+
+ if (!$error)
+ {
+ $this->db->commit();
+
+ return array(
+ 'success' => array(
+ 'code' => 201,
+ 'message' => 'Internal wire transfer created successfully.'
+ )
+ );
+ }
+ else
+ {
+ $this->db->rollback();
+ throw new RestException(500, $accountfrom->error.' '.$accountto->error);
+ }
+ }
+
+ /**
+ * Update account
+ *
+ * @param int $id ID of account
+ * @param array $request_data data
+ * @return int
+ */
+ public function put($id, $request_data = null)
+ {
+ if (!DolibarrApiAccess::$user->rights->banque->configurer) {
+ throw new RestException(401);
+ }
+
+ $account = new Account($this->db);
+ $result = $account->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'account not found');
+ }
+
+ foreach ($request_data as $field => $value) {
+ if ($field == 'id') continue;
+ $account->$field = $value;
+ }
+
+ if ($account->update(DolibarrApiAccess::$user) > 0)
+ {
+ return $this->get($id);
+ }
+ else
+ {
+ throw new RestException(500, $account->error);
+ }
+ }
+
+ /**
+ * Delete account
+ *
+ * @param int $id ID of account
+ * @return array
+ */
+ public function delete($id)
+ {
+ if (!DolibarrApiAccess::$user->rights->banque->configurer) {
+ throw new RestException(401);
+ }
+ $account = new Account($this->db);
+ $result = $account->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'account not found');
+ }
+
+ if ($account->delete(DolibarrApiAccess::$user) < 0) {
+ throw new RestException(401, 'error when deleting account');
+ }
+
+ return array(
+ 'success' => array(
+ 'code' => 200,
+ 'message' => 'account deleted'
+ )
+ );
+ }
+
+ /**
+ * Validate fields before creating an object
+ *
+ * @param array|null $data Data to validate
+ * @return array
+ *
+ * @throws RestException
+ */
+ private function _validate($data)
+ {
+ $account = array();
+ foreach (BankAccounts::$FIELDS as $field) {
+ if (!isset($data[$field]))
+ throw new RestException(400, "$field field missing");
+ $account[$field] = $data[$field];
+ }
+ return $account;
+ }
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
+ /**
+ * Clean sensible object datas
+ *
+ * @param object $object Object to clean
+ * @return array Array of cleaned object properties
+ */
+ protected function _cleanObjectDatas($object)
+ {
+ // phpcs:enable
+ $object = parent::_cleanObjectDatas($object);
+
+ unset($object->rowid);
+
+ return $object;
+ }
+
+ /**
+ * Get the list of lines of the account.
+ *
+ * @param int $id ID of account
+ * @return array Array of AccountLine objects
+ *
+ * @throws RestException
+ *
+ * @url GET {id}/lines
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.import_key:<:'20160101')"
- * @return array List of account objects
- *
- * @throws RestException
- */
- public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $category = 0, $sqlfilters = '')
- {
- $list = array();
-
- if (!DolibarrApiAccess::$user->rights->banque->lire) {
- throw new RestException(401);
- }
-
- $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."bank_account as t";
- if ($category > 0) {
- $sql .= ", ".MAIN_DB_PREFIX."categorie_account as c";
- }
- $sql .= ' WHERE t.entity IN ('.getEntity('bank_account').')';
- // Select accounts of given category
- if ($category > 0) {
- $sql .= " AND c.fk_categorie = ".$this->db->escape($category)." AND c.fk_account = t.rowid ";
- }
+ */
+ public function getLines($id, $sqlfilters = '')
+ {
+ $list = array();
+
+ if (!DolibarrApiAccess::$user->rights->banque->lire) {
+ throw new RestException(401);
+ }
+
+ $account = new Account($this->db);
+ $result = $account->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'account not found');
+ }
+
+ $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."bank ";
+ $sql .= " WHERE fk_account = ".$id;
+
// Add sql filters
if ($sqlfilters)
{
@@ -91,457 +449,105 @@
$sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0)
- {
- $page = 0;
- }
- $offset = $limit * $page;
-
- $sql .= $this->db->plimit($limit + 1, $offset);
- }
-
- dol_syslog("API Rest request");
- $result = $this->db->query($sql);
-
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $obj = $this->db->fetch_object($result);
- $account = new Account($this->db);
- if ($account->fetch($obj->rowid) > 0) {
- $list[] = $this->_cleanObjectDatas($account);
- }
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of accounts: '.$this->db->lasterror());
- }
-
- return $list;
- }
-
- /**
- * Get account by ID.
- *
- * @param int $id ID of account
- * @return array Account object
- *
- * @throws RestException
- */
- public function get($id)
- {
- if (!DolibarrApiAccess::$user->rights->banque->lire) {
- throw new RestException(401);
- }
-
- $account = new Account($this->db);
- $result = $account->fetch($id);
- if (!$result) {
- throw new RestException(404, 'account not found');
- }
-
- return $this->_cleanObjectDatas($account);
- }
-
- /**
- * Create account object
- *
- * @param array $request_data Request data
- * @return int ID of account
- */
- public function post($request_data = null)
- {
- if (!DolibarrApiAccess::$user->rights->banque->configurer) {
- throw new RestException(401);
- }
- // Check mandatory fields
- $result = $this->_validate($request_data);
-
- $account = new Account($this->db);
- foreach ($request_data as $field => $value) {
- $account->$field = $value;
- }
- // Date of the initial balance (required to create an account).
- $account->date_solde = time();
- // courant and type are the same thing but the one used when
- // creating an account is courant
- $account->courant = $account->type;
-
- if ($account->create(DolibarrApiAccess::$user) < 0) {
- throw new RestException(500, 'Error creating bank account', array_merge(array($account->error), $account->errors));
- }
- return $account->id;
- }
-
- /**
- * Create an internal wire transfer between two bank accounts
- *
- * @param int $bankaccount_from_id BankAccount ID to use as the source of the internal wire transfer {@from body}{@required true}
- * @param int $bankaccount_to_id BankAccount ID to use as the destination of the internal wire transfer {@from body}{@required true}
- * @param string $date Date of the internal wire transfer (UNIX timestamp) {@from body}{@required true}{@type timestamp}
- * @param string $description Description of the internal wire transfer {@from body}{@required true}
- * @param float $amount Amount to transfer from the source to the destination BankAccount {@from body}{@required true}
- * @param float $amount_to Amount to transfer to the destination BankAccount (only when accounts does not share the same currency) {@from body}{@required false}
- *
- * @url POST /transfer
- *
- * @return array
- *
- * @status 201
- *
- * @throws RestException 401 Unauthorized: User does not have permission to configure bank accounts
- * @throws RestException 404 Not Found: Either the source or the destination bankaccount for the provided id does not exist
- * @throws RestException 422 Unprocessable Entity: Refer to detailed exception message for the cause
- * @throws RestException 500 Internal Server Error: Error(s) returned by the RDBMS
- */
- public function transfer($bankaccount_from_id = 0, $bankaccount_to_id = 0, $date = null, $description = "", $amount = 0.0, $amount_to = 0.0)
- {
- if (!DolibarrApiAccess::$user->rights->banque->configurer) {
- throw new RestException(401);
- }
-
- if ($bankaccount_from_id === $bankaccount_to_id) {
- throw new RestException(422, 'bankaccount_from_id and bankaccount_to_id must be different !');
- }
-
- require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
-
- $accountfrom = new Account($this->db);
- $resultAccountFrom = $accountfrom->fetch($bankaccount_from_id);
-
- if ($resultAccountFrom === 0) {
- throw new RestException(404, 'The BankAccount for bankaccount_from_id provided does not exist.');
- }
-
- $accountto = new Account($this->db);
- $resultAccountTo = $accountto->fetch($bankaccount_to_id);
-
- if ($resultAccountTo === 0) {
- throw new RestException(404, 'The BankAccount for bankaccount_to_id provided does not exist.');
- }
-
- if ($accountto->currency_code == $accountfrom->currency_code)
- {
- $amount_to = $amount;
- } else {
- if (!$amount_to || empty($amount_to))
- {
- throw new RestException(422, 'You must provide amount_to value since bankaccount_from and bankaccount_to does not share the same currency.');
- }
- }
-
- $this->db->begin();
-
- $error = 0;
- $bank_line_id_from = 0;
- $bank_line_id_to = 0;
- $result = 0;
- $user = DolibarrApiAccess::$user;
-
- // By default, electronic transfert from bank to bank
- $typefrom = 'PRE';
- $typeto = 'VIR';
-
- if ($accountto->courant == Account::TYPE_CASH || $accountfrom->courant == Account::TYPE_CASH)
- {
- // This is transfer of change
- $typefrom = 'LIQ';
- $typeto = 'LIQ';
- }
-
- /**
- * Creating bank line records
- */
-
- if (!$error) {
- $bank_line_id_from = $accountfrom->addline($date, $typefrom, $description, -1 * price2num($amount), '', '', $user);
- }
- if (!($bank_line_id_from > 0)) {
- $error++;
- }
-
- if (!$error) {
- $bank_line_id_to = $accountto->addline($date, $typeto, $description, price2num($amount_to), '', '', $user);
- }
- if (!($bank_line_id_to > 0)) {
- $error++;
- }
-
- /**
- * Creating links between bank line record and its source
- */
-
- $url = DOL_URL_ROOT.'/compta/bank/line.php?rowid=';
- $label = '(banktransfert)';
- $type = 'banktransfert';
-
- if (!$error) {
- $result = $accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, $url, $label, $type);
- }
- if (!($result > 0)) {
- $error++;
- }
-
- if (!$error) {
- $result = $accountto->add_url_line($bank_line_id_to, $bank_line_id_from, $url, $label, $type);
- }
- if (!($result > 0)) {
- $error++;
- }
-
- if (!$error)
- {
- $this->db->commit();
-
- return array(
- 'success' => array(
- 'code' => 201,
- 'message' => 'Internal wire transfer created successfully.'
- )
- );
- } else {
- $this->db->rollback();
- throw new RestException(500, $accountfrom->error.' '.$accountto->error);
- }
- }
-
- /**
- * Update account
- *
- * @param int $id ID of account
- * @param array $request_data data
- * @return int
- */
- public function put($id, $request_data = null)
- {
- if (!DolibarrApiAccess::$user->rights->banque->configurer) {
- throw new RestException(401);
- }
-
- $account = new Account($this->db);
- $result = $account->fetch($id);
- if (!$result) {
- throw new RestException(404, 'account not found');
- }
-
- foreach ($request_data as $field => $value) {
- if ($field == 'id') continue;
- $account->$field = $value;
- }
-
- if ($account->update(DolibarrApiAccess::$user) > 0)
- {
- return $this->get($id);
- } else {
- throw new RestException(500, $account->error);
- }
- }
-
- /**
- * Delete account
- *
- * @param int $id ID of account
- * @return array
- */
- public function delete($id)
- {
- if (!DolibarrApiAccess::$user->rights->banque->configurer) {
- throw new RestException(401);
- }
- $account = new Account($this->db);
- $result = $account->fetch($id);
- if (!$result) {
- throw new RestException(404, 'account not found');
- }
-
- if ($account->delete(DolibarrApiAccess::$user) < 0) {
- throw new RestException(401, 'error when deleting account');
- }
-
- return array(
- 'success' => array(
- 'code' => 200,
- 'message' => 'account deleted'
- )
- );
- }
-
- /**
- * Validate fields before creating an object
- *
- * @param array|null $data Data to validate
- * @return array
- *
- * @throws RestException
- */
- private function _validate($data)
- {
- $account = array();
- foreach (BankAccounts::$FIELDS as $field) {
- if (!isset($data[$field]))
- throw new RestException(400, "$field field missing");
- $account[$field] = $data[$field];
- }
- return $account;
- }
-
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
- /**
- * Clean sensible object datas
- *
- * @param Object $object Object to clean
- * @return Object Object with cleaned properties
- */
- protected function _cleanObjectDatas($object)
- {
- // phpcs:enable
- $object = parent::_cleanObjectDatas($object);
-
- unset($object->rowid);
-
- return $object;
- }
-
- /**
- * Get the list of lines of the account.
- *
- * @param int $id ID of account
- * @return array Array of AccountLine objects
- *
- * @throws RestException
- *
- * @url GET {id}/lines
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.import_key:<:'20160101')"
- */
- public function getLines($id, $sqlfilters = '')
- {
- $list = array();
-
- if (!DolibarrApiAccess::$user->rights->banque->lire) {
- throw new RestException(401);
- }
-
- $account = new Account($this->db);
- $result = $account->fetch($id);
- if (!$result) {
- throw new RestException(404, 'account not found');
- }
-
- $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."bank ";
- $sql .= " WHERE fk_account = ".$id;
-
- // Add sql filters
- if ($sqlfilters)
- {
- if (!DolibarrApi::_checkFilters($sqlfilters))
- {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
-
- $sql .= " ORDER BY rowid";
-
- $result = $this->db->query($sql);
-
- if ($result) {
- $num = $this->db->num_rows($result);
- for ($i = 0; $i < $num; $i++) {
- $obj = $this->db->fetch_object($result);
- $accountLine = new AccountLine($this->db);
- if ($accountLine->fetch($obj->rowid) > 0) {
- $list[] = $this->_cleanObjectDatas($accountLine);
- }
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of account lines: '.$accountLine->error);
- }
-
- return $list;
- }
-
- /**
- * Add a line to an account
- *
- * @param int $id ID of account
- * @param int $date Payment date (timestamp) {@from body} {@type timestamp}
- * @param string $type Payment mode (TYP,VIR,PRE,LIQ,VAD,CB,CHQ...) {@from body}
- * @param string $label Label {@from body}
- * @param float $amount Amount (may be 0) {@from body}
- * @param int $category Category
- * @param string $cheque_number Cheque numberl {@from body}
- * @param string $cheque_writer Name of cheque writer {@from body}
- * @param string $cheque_bank Bank of cheque writer {@from body}
- * @return int ID of line
- *
- * @url POST {id}/lines
- */
- public function addLine($id, $date, $type, $label, $amount, $category = 0, $cheque_number = '', $cheque_writer = '', $cheque_bank = '')
- {
- if (!DolibarrApiAccess::$user->rights->banque->modifier) {
- throw new RestException(401);
- }
-
- $account = new Account($this->db);
- $result = $account->fetch($id);
- if (!$result) {
- throw new RestException(404, 'account not found');
- }
-
- $result = $account->addline(
- $date,
- $type,
- $label,
- $amount,
- $cheque_number,
- $category,
- DolibarrApiAccess::$user,
- $cheque_writer, $cheque_bank
- );
- if ($result < 0) {
- throw new RestException(503, 'Error when adding line to account: '.$account->error);
- }
- return $result;
- }
-
- /**
- * Add a link to an account line
- *
- * @param int $id ID of account
- * @param int $line_id ID of account line
- * @param int $url_id ID to set in the URL {@from body}
- * @param string $url URL of the link {@from body}
- * @param string $label Label {@from body}
- * @param string $type Type of link ('payment', 'company', 'member', ...) {@from body}
- * @return int ID of link
- *
- * @url POST {id}/lines/{line_id}/links
- */
- public function addLink($id, $line_id, $url_id, $url, $label, $type)
- {
- if (!DolibarrApiAccess::$user->rights->banque->modifier) {
- throw new RestException(401);
- }
-
- $account = new Account($this->db);
- $result = $account->fetch($id);
- if (!$result) {
- throw new RestException(404, 'account not found');
- }
-
- $accountLine = new AccountLine($this->db);
- $result = $accountLine->fetch($line_id);
- if (!$result) {
- throw new RestException(404, 'account line not found');
- }
-
- $result = $account->add_url_line($line_id, $url_id, $url, $label, $type);
- if ($result < 0) {
- throw new RestException(503, 'Error when adding link to account line: '.$account->error);
- }
- return $result;
- }
+ $sql .= " ORDER BY rowid";
+
+ $result = $this->db->query($sql);
+
+ if ($result) {
+ $num = $this->db->num_rows($result);
+ for ($i = 0; $i < $num; $i++) {
+ $obj = $this->db->fetch_object($result);
+ $accountLine = new AccountLine($this->db);
+ if ($accountLine->fetch($obj->rowid) > 0) {
+ $list[] = $this->_cleanObjectDatas($accountLine);
+ }
+ }
+ } else {
+ throw new RestException(503, 'Error when retrieving list of account lines: '.$accountLine->error);
+ }
+
+ return $list;
+ }
+
+ /**
+ * Add a line to an account
+ *
+ * @param int $id ID of account
+ * @param int $date Payment date (timestamp) {@from body} {@type timestamp}
+ * @param string $type Payment mode (TYP,VIR,PRE,LIQ,VAD,CB,CHQ...) {@from body}
+ * @param string $label Label {@from body}
+ * @param float $amount Amount (may be 0) {@from body}
+ * @param int $category Category
+ * @param string $cheque_number Cheque numberl {@from body}
+ * @param string $cheque_writer Name of cheque writer {@from body}
+ * @param string $cheque_bank Bank of cheque writer {@from body}
+ * @return int ID of line
+ *
+ * @url POST {id}/lines
+ */
+ public function addLine($id, $date, $type, $label, $amount, $category = 0, $cheque_number = '', $cheque_writer = '', $cheque_bank = '')
+ {
+ if (!DolibarrApiAccess::$user->rights->banque->modifier) {
+ throw new RestException(401);
+ }
+
+ $account = new Account($this->db);
+ $result = $account->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'account not found');
+ }
+
+ $result = $account->addline(
+ $date,
+ $type,
+ $label,
+ $amount,
+ $cheque_number,
+ $category,
+ DolibarrApiAccess::$user,
+ $cheque_writer, $cheque_bank
+ );
+ if ($result < 0) {
+ throw new RestException(503, 'Error when adding line to account: '.$account->error);
+ }
+ return $result;
+ }
+
+ /**
+ * Add a link to an account line
+ *
+ * @param int $id ID of account
+ * @param int $line_id ID of account line
+ * @param int $url_id ID to set in the URL {@from body}
+ * @param string $url URL of the link {@from body}
+ * @param string $label Label {@from body}
+ * @param string $type Type of link ('payment', 'company', 'member', ...) {@from body}
+ * @return int ID of link
+ *
+ * @url POST {id}/lines/{line_id}/links
+ */
+ public function addLink($id, $line_id, $url_id, $url, $label, $type)
+ {
+ if (!DolibarrApiAccess::$user->rights->banque->modifier) {
+ throw new RestException(401);
+ }
+
+ $account = new Account($this->db);
+ $result = $account->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'account not found');
+ }
+
+ $accountLine = new AccountLine($this->db);
+ $result = $accountLine->fetch($line_id);
+ if (!$result) {
+ throw new RestException(404, 'account line not found');
+ }
+
+ $result = $account->add_url_line($line_id, $url_id, $url, $label, $type);
+ if ($result < 0) {
+ throw new RestException(503, 'Error when adding link to account line: '.$account->error);
+ }
+ return $result;
+ }
}
--- /tmp/dsg/dolibarr/htdocs/compta/bank/class/github_bankcateg.class.php
+++ /tmp/dsg/dolibarr/htdocs/compta/bank/class/client_bankcateg.class.php
@@ -30,20 +30,20 @@
{
//public $element='bank_categ'; //!< Id that identify managed objects
//public $table_element='bank_categ'; //!< Name of table without prefix where object is stored
- /**
+ /**
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
*/
public $picto = 'generic';
/**
- * @var int ID
- */
- public $id;
-
- /**
- * @var string bank categories label
- */
- public $label;
+ * @var int ID
+ */
+ public $id;
+
+ /**
+ * @var string bank categories label
+ */
+ public $label;
/**
@@ -213,46 +213,46 @@
// Delete link between tag and bank account
if (!$error)
{
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account";
- $sql .= " WHERE fk_categorie = ".$this->id;
-
- $resql = $this->db->query($sql);
- if (!$resql)
- {
- $error++;
- $this->errors[] = "Error ".$this->db->lasterror();
- }
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account";
+ $sql .= " WHERE fk_categorie = ".$this->id;
+
+ $resql = $this->db->query($sql);
+ if (!$resql)
+ {
+ $error++;
+ $this->errors[] = "Error ".$this->db->lasterror();
+ }
}
// Delete link between tag and bank lines
if (!$error)
{
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class";
- $sql .= " WHERE fk_categ = ".$this->id;
-
- $resql = $this->db->query($sql);
- if (!$resql)
- {
- $error++;
- $this->errors[] = "Error ".$this->db->lasterror();
- }
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class";
+ $sql .= " WHERE fk_categ = ".$this->id;
+
+ $resql = $this->db->query($sql);
+ if (!$resql)
+ {
+ $error++;
+ $this->errors[] = "Error ".$this->db->lasterror();
+ }
}
// Delete bank categ
if (!$error)
{
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ";
- $sql .= " WHERE rowid=".$this->id;
-
- $resql = $this->db->query($sql);
- if (!$resql)
- {
- $error++;
- $this->errors[] = "Error ".$this->db->lasterror();
- }
- }
-
- // Commit or rollback
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ";
+ $sql .= " WHERE rowid=".$this->id;
+
+ $resql = $this->db->query($sql);
+ if (!$resql)
+ {
+ $error++;
+ $this->errors[] = "Error ".$this->db->lasterror();
+ }
+ }
+
+ // Commit or rollback
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
--- /tmp/dsg/dolibarr/htdocs/compta/bank/class/github_paymentvarious.class.php
+++ /tmp/dsg/dolibarr/htdocs/compta/bank/class/client_paymentvarious.class.php
@@ -1,6 +1,6 @@
- * Copyright (C) 2018-2020 Frédéric France
+/* Copyright (C) 2017-2019 Alexandre Spangaro
+ * Copyright (C) 2018 Frédéric France
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -56,116 +56,51 @@
*/
public $ref;
- /**
- * @var int timestamp
- */
public $tms;
public $datep;
public $datev;
-
- /**
- * @var int sens of operation
- */
public $sens;
public $amount;
public $type_payment;
public $num_payment;
- public $chqemetteur;
- public $chqbank;
- public $category_transaction;
-
- /**
- * @var string various payments label
- */
- public $label;
-
- /**
- * @var string accountancy code
- */
+ public $category_transaction;
+
+ /**
+ * @var string various payments label
+ */
+ public $label;
+
public $accountancy_code;
- /**
- * @var string subledger account
- */
- public $subledger_account;
-
- /**
- * @var int ID
- */
+ public $subledger_account;
+
+ /**
+ * @var int ID
+ */
public $fk_project;
/**
- * @var int Bank account ID
- */
- public $fk_account;
-
- /**
- * @var int Bank account ID
- * @deprecated See fk_account
- */
- public $accountid;
-
- /**
- * @var int ID record into llx_bank
- */
+ * @var int ID
+ */
public $fk_bank;
/**
- * @var int transaction category
- */
- public $categorie_transaction;
-
- /**
- * @var int ID
- */
+ * @var int ID
+ */
public $fk_user_author;
/**
- * @var int ID
- */
+ * @var int ID
+ */
public $fk_user_modif;
/**
- * 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
- * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
- * 'label' the translation key.
- * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
- * 'position' is the sort order of field.
- * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
- * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
- * 'noteditable' says if field is not editable (1 or 0)
- * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
- * 'index' if we want an index in database.
- * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
- * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
- * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
- * 'css' is the CSS style to use on field. For example: 'maxwidth200'
- * 'help' is a string visible as a tooltip on field
- * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
- * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
- * 'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel")
- * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
- * 'comment' is not used. You can store here any text of your choice. It is not used by application.
- *
- * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
- */
-
- // BEGIN MODULEBUILDER PROPERTIES
- /**
- * @var array fields definition
- */
- public $fields = array(
- // TODO: fill this array
- );
- // END MODULEBUILDER PROPERTIES
-
- /**
* Constructor
*
* @param DoliDB $db Database handler
*/
- public function __construct($db)
+ public function __construct($db)
{
$this->db = $db;
$this->element = 'payment_various';
@@ -179,7 +114,7 @@
* @param int $notrigger 0=no, 1=yes (no update trigger)
* @return int <0 if KO, >0 if OK
*/
- public function update($user = null, $notrigger = 0)
+ public function update($user = null, $notrigger = 0)
{
global $conf, $langs;
@@ -202,12 +137,12 @@
$sql .= " datev='".$this->db->idate($this->datev)."',";
$sql .= " sens=".(int) $this->sens.",";
$sql .= " amount=".price2num($this->amount).",";
- $sql .= " fk_typepayment=".(int) $this->type_payment.",";
+ $sql .= " fk_typepayment=".(int) $this->fk_typepayment.",";
$sql .= " num_payment='".$this->db->escape($this->num_payment)."',";
$sql .= " label='".$this->db->escape($this->label)."',";
$sql .= " note='".$this->db->escape($this->note)."',";
$sql .= " accountancy_code='".$this->db->escape($this->accountancy_code)."',";
- $sql .= " subledger_account='".$this->db->escape($this->subledger_account)."',";
+ $sql .= " subledger_account='".$this->db->escape($this->subledger_account)."',";
$sql .= " fk_projet='".$this->db->escape($this->fk_project)."',";
$sql .= " fk_bank=".($this->fk_bank > 0 ? $this->fk_bank : "null").",";
$sql .= " fk_user_author=".(int) $this->fk_user_author.",";
@@ -216,22 +151,27 @@
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql) {
+ if (!$resql)
+ {
$this->error = "Error ".$this->db->lasterror();
return -1;
}
- if (!$notrigger) {
+ if (!$notrigger)
+ {
// Call trigger
$result = $this->call_trigger('PAYMENT_VARIOUS_MODIFY', $user);
if ($result < 0) $error++;
// End call triggers
}
- if (!$error) {
+ if (!$error)
+ {
$this->db->commit();
return 1;
- } else {
+ }
+ else
+ {
$this->db->rollback();
return -1;
}
@@ -245,7 +185,7 @@
* @param User $user User that load
* @return int <0 if KO, >0 if OK
*/
- public function fetch($id, $user = null)
+ public function fetch($id, $user = null)
{
global $langs;
$sql = "SELECT";
@@ -304,7 +244,9 @@
$this->db->free($resql);
return 1;
- } else {
+ }
+ else
+ {
$this->error = "Error ".$this->db->lasterror();
return -1;
}
@@ -317,7 +259,7 @@
* @param User $user User that delete
* @return int <0 if KO, >0 if OK
*/
- public function delete($user)
+ public function delete($user)
{
global $conf, $langs;
@@ -334,7 +276,8 @@
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql) {
+ if (!$resql)
+ {
$this->error = "Error ".$this->db->lasterror();
return -1;
}
@@ -350,7 +293,7 @@
*
* @return void
*/
- public function initAsSpecimen()
+ public function initAsSpecimen()
{
$this->id = 0;
@@ -361,7 +304,7 @@
$this->amount = '';
$this->label = '';
$this->accountancy_code = '';
- $this->subledger_account = '';
+ $this->subledger_account = '';
$this->note = '';
$this->fk_bank = '';
$this->fk_user_author = '';
@@ -369,29 +312,12 @@
}
/**
- * Check if a miscellaneous payment can be created into database
- *
- * @return boolean True or false
- */
- public function check()
- {
- $newamount = price2num($this->amount, 'MT');
-
- // Validation of parameters
- if (!($newamount) > 0 || empty($this->datep)) {
- return false;
- }
-
- return true;
- }
-
- /**
* Create in database
*
* @param User $user User that create
* @return int <0 if KO, >0 if OK
*/
- public function create($user)
+ public function create($user)
{
global $conf, $langs;
@@ -405,10 +331,6 @@
$this->fk_bank = (int) $this->fk_bank;
$this->fk_user_author = (int) $this->fk_user_author;
$this->fk_user_modif = (int) $this->fk_user_modif;
- $this->fk_account = (int) $this->fk_account;
- if (empty($this->fk_account) && isset($this->accountid)) { // For compatibility
- $this->fk_account = $this->accountid;
- }
// Check parameters
if (!$this->label)
@@ -421,12 +343,12 @@
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
return -5;
}
- if (!empty($conf->banque->enabled) && (empty($this->fk_account) || $this->fk_account <= 0))
- {
- $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("BankAccount"));
+ if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0))
+ {
+ $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account"));
return -6;
}
- if (!empty($conf->banque->enabled) && (empty($this->type_payment)))
+ if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0))
{
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
return -7;
@@ -466,7 +388,7 @@
$sql .= ", ".($this->fk_project > 0 ? $this->fk_project : 0);
$sql .= ", ".$user->id;
$sql .= ", '".$this->db->idate($now)."'";
- $sql .= ", NULL"; // Filled later
+ $sql .= ", NULL";
$sql .= ", ".$conf->entity;
$sql .= ")";
@@ -485,7 +407,7 @@
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$acc = new Account($this->db);
- $result = $acc->fetch($this->fk_account);
+ $result = $acc->fetch($this->accountid);
if ($result <= 0) dol_print_error($this->db);
// Insert payment into llx_bank
@@ -493,25 +415,28 @@
$sign = 1;
if ($this->sens == '0') $sign = -1;
- $bank_line_id = $acc->addline(
+ $bank_line_id = $acc->addline(
$this->datep,
$this->type_payment,
$this->label,
$sign * abs($this->amount),
$this->num_payment,
- ($this->category_transaction > 0 ? $this->category_transaction : 0),
+ ($this->category_transaction > 0 ? $this->category_transaction : 0),
$user,
- $this->chqemetteur,
- $this->chqbank,
+ '',
+ '',
'',
$this->datev
);
- // Update fk_bank into llx_payment_various
+ // Update fk_bank into llx_paiement.
// So we know the payment which has generate the banking ecriture
- if ($bank_line_id > 0) {
+ if ($bank_line_id > 0)
+ {
$this->update_fk_bank($bank_line_id);
- } else {
+ }
+ else
+ {
$this->error = $acc->error;
$error++;
}
@@ -540,40 +465,47 @@
$result = $this->call_trigger('PAYMENT_VARIOUS_CREATE', $user);
if ($result < 0) $error++;
// End call triggers
- } else $error++;
+ }
+ else $error++;
if (!$error)
{
$this->db->commit();
return $this->id;
- } else {
+ }
+ else
+ {
$this->db->rollback();
return -2;
}
- } else {
+ }
+ else
+ {
$this->error = $this->db->error();
$this->db->rollback();
return -1;
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Update link between payment various and line generate into llx_bank
*
* @param int $id_bank Id bank account
* @return int <0 if KO, >0 if OK
*/
- public function update_fk_bank($id_bank)
- {
- // phpcs:enable
+ public function update_fk_bank($id_bank)
+ {
+ // phpcs:enable
$sql = 'UPDATE '.MAIN_DB_PREFIX.'payment_various SET fk_bank = '.$id_bank;
$sql .= ' WHERE rowid = '.$this->id;
$result = $this->db->query($sql);
if ($result)
{
return 1;
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
return -1;
}
@@ -586,12 +518,12 @@
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
* @return string Libelle
*/
- public function getLibStatut($mode = 0)
+ public function getLibStatut($mode = 0)
{
return $this->LibStatut($this->statut, $mode);
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Renvoi le libelle d'un statut donne
*
@@ -599,28 +531,39 @@
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
* @return string Libelle
*/
- public function LibStatut($status, $mode = 0)
- {
- // phpcs:enable
+ public function LibStatut($status, $mode = 0)
+ {
+ // phpcs:enable
global $langs;
- if ($mode == 0) {
+ if ($mode == 0)
+ {
return $langs->trans($this->statuts[$status]);
- } elseif ($mode == 1) {
+ }
+ elseif ($mode == 1)
+ {
return $langs->trans($this->statuts_short[$status]);
- } elseif ($mode == 2) {
+ }
+ elseif ($mode == 2)
+ {
if ($status == 0) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts_short[$status]);
elseif ($status == 1) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts_short[$status]);
elseif ($status == 2) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts_short[$status]);
- } elseif ($mode == 3) {
+ }
+ elseif ($mode == 3)
+ {
if ($status == 0 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0');
elseif ($status == 1 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4');
elseif ($status == 2 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
- } elseif ($mode == 4) {
+ }
+ elseif ($mode == 4)
+ {
if ($status == 0 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts[$status]);
elseif ($status == 1 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts[$status]);
elseif ($status == 2 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]);
- } elseif ($mode == 5) {
+ }
+ elseif ($mode == 5)
+ {
if ($status == 0 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut0');
elseif ($status == 1 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut4');
elseif ($status == 2 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
@@ -634,11 +577,10 @@
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
* @param string $option link option
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
- * @param int $notooltip 1=Disable tooltip
- * @param string $morecss morecss string
+ * @param int $notooltip 1=Disable tooltip
* @return string String with URL
*/
- public function getNomUrl($withpicto = 0, $option = '', $save_lastsearch_value = -1, $notooltip = 0, $morecss = '')
+ public function getNomUrl($withpicto = 0, $option = '', $save_lastsearch_value = -1, $notooltip = 0)
{
global $db, $conf, $langs, $hookmanager;
global $langs;
@@ -678,7 +620,8 @@
$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) $linkclose = $hookmanager->resPrint;
*/
- } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
+ }
+ else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
$linkstart = '';
@@ -706,8 +649,8 @@
* @param int $id Id of record
* @return void
*/
- public function info($id)
- {
+ public function info($id)
+ {
$sql = 'SELECT v.rowid, v.datec, v.fk_user_author';
$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_various as v';
$sql .= ' WHERE v.rowid = '.$id;
@@ -737,7 +680,9 @@
$this->date_modif = $this->db->jdate($obj->tms);
}
$this->db->free($result);
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
}
}
@@ -755,7 +700,7 @@
$type = 'bank';
- $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".$banklineid;
+ $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$type."' AND ab.fk_doc = ".$banklineid;
$resql = $this->db->query($sql);
if ($resql)
{
@@ -764,7 +709,9 @@
{
$alreadydispatched = $obj->nb;
}
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
return -1;
}