Fix : Correct bank transfert when we write operation on general ledger

This commit is contained in:
Alexandre SPANGARO 2017-05-28 21:56:18 +02:00
parent c651f1da45
commit 095545e8d9
2 changed files with 192 additions and 182 deletions

View File

@ -55,17 +55,14 @@ class BookKeeping extends CommonObject
*/ */
public $table_element = 'accounting_bookkeeping'; public $table_element = 'accounting_bookkeeping';
public $entity = 1; public $entity = 1;
/** /**
* *
* @var BookKeepingLine[] Lines * @var BookKeepingLine[] Lines
*/ */
public $lines = array (); public $lines = array ();
/** /**
* *
* @var int ID * @var int ID
@ -110,7 +107,7 @@ class BookKeeping extends CommonObject
* @return int <0 if KO, Id of created object if OK * @return int <0 if KO, Id of created object if OK
*/ */
public function create(User $user, $notrigger = false) { public function create(User $user, $notrigger = false) {
global $conf, $langs; global $conf, $langs;
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
@ -181,7 +178,6 @@ class BookKeeping extends CommonObject
return -1; return -1;
} }
$this->db->begin(); $this->db->begin();
$this->piece_num = 0; $this->piece_num = 0;
@ -193,7 +189,7 @@ class BookKeeping extends CommonObject
$sql .= " AND fk_doc = " . $this->fk_doc; $sql .= " AND fk_doc = " . $this->fk_doc;
$sql .= " AND fk_docdet = " . $this->fk_docdet; // This field can be 0 is record is for several lines $sql .= " AND fk_docdet = " . $this->fk_docdet; // This field can be 0 is record is for several lines
$sql .= " AND numero_compte = '" . $this->db->escape($this->numero_compte) . "'"; $sql .= " AND numero_compte = '" . $this->db->escape($this->numero_compte) . "'";
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -207,7 +203,7 @@ class BookKeeping extends CommonObject
$sqlnum .= " WHERE doc_type = '" . $this->db->escape($this->doc_type) . "'"; // For example doc_type = 'bank' $sqlnum .= " WHERE doc_type = '" . $this->db->escape($this->doc_type) . "'"; // For example doc_type = 'bank'
$sqlnum .= " AND fk_docdet = " . $this->db->escape($this->fk_docdet); // fk_docdet is rowid into llx_bank or llx_facturedet or llx_facturefourndet, or ... $sqlnum .= " AND fk_docdet = " . $this->db->escape($this->fk_docdet); // fk_docdet is rowid into llx_bank or llx_facturedet or llx_facturefourndet, or ...
$sqlnum .= " AND doc_ref = '" . $this->db->escape($this->doc_ref) . "'"; // ref of source object $sqlnum .= " AND doc_ref = '" . $this->db->escape($this->doc_ref) . "'"; // ref of source object
$sqlnum .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; $sqlnum .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG);
$resqlnum = $this->db->query($sqlnum); $resqlnum = $this->db->query($sqlnum);
@ -219,7 +215,7 @@ class BookKeeping extends CommonObject
if (empty($this->piece_num)) { if (empty($this->piece_num)) {
$sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum"; $sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum";
$sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
$sqlnum .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")"; $sqlnum .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG);
$resqlnum = $this->db->query($sqlnum); $resqlnum = $this->db->query($sqlnum);
@ -566,7 +562,7 @@ class BookKeeping extends CommonObject
public function fetchAllByAccount($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { public function fetchAllByAccount($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') {
global $conf; global $conf;
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
$sql = 'SELECT'; $sql = 'SELECT';
$sql .= ' t.rowid,'; $sql .= ' t.rowid,';
@ -865,7 +861,6 @@ class BookKeeping extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
// Clean parameters // Clean parameters
if (isset($this->doc_type)) { if (isset($this->doc_type)) {
$this->doc_type = trim($this->doc_type); $this->doc_type = trim($this->doc_type);
} }
@ -1434,7 +1429,6 @@ class BookKeeping extends CommonObject
} }
/** /**
* Description of a root accounting account * Description of a root accounting account
* *
@ -1503,12 +1497,10 @@ class BookKeeping extends CommonObject
if ($this->db->num_rows($resql)) { if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
} }
if(empty($obj->category)){ if(empty($obj->category)){
return $obj->label; return $obj->label;
}else{ }else{
return $obj->label.' ('.$obj->category.')'; return $obj->label.' ('.$obj->category.')';
} }
} else { } else {
$this->error = "Error " . $this->db->lasterror(); $this->error = "Error " . $this->db->lasterror();

View File

@ -34,6 +34,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
@ -63,7 +64,10 @@ $langs->load("accountancy");
$langs->load("trips"); $langs->load("trips");
$langs->load("hrm"); $langs->load("hrm");
// Old system menu
$id_bank_account = GETPOST('id_account', 'int'); $id_bank_account = GETPOST('id_account', 'int');
// Multi journal
$code_journal = GETPOST('code_journal', 'alpha');
$date_startmonth = GETPOST('date_startmonth'); $date_startmonth = GETPOST('date_startmonth');
$date_startday = GETPOST('date_startday'); $date_startday = GETPOST('date_startday');
@ -134,9 +138,20 @@ $paymentsalstatic = new PaymentSalary($db);
$paymentexpensereportstatic = new PaymentExpenseReport($db); $paymentexpensereportstatic = new PaymentExpenseReport($db);
// Get code of finance journal // Get code of finance journal
$bank_code_journal = new Account($db); $journal = '';
$result = $bank_code_journal->fetch($id_bank_account); $bankstatic = new Account($db);
$journal = $bank_code_journal->accountancy_journal; $bankstatic->fetch($id_bank_account);
$bankstatic->rowid;
$bankstatic->label;
$bankstatic->fk_accountancy_journal;
$accountingjournalstatic = new AccountingJournal($db);
if(! empty($id_bank_account) {
$accountingjournalstatic->fetch($bankstatic->fk_accountancy_journal);
} else {
$accountingjournalstatic->fetch('',$code_journal);
}
$journal = $accountingjournalstatic->code;
dol_syslog("accountancy/journal/bankjournal.php", LOG_DEBUG); dol_syslog("accountancy/journal/bankjournal.php", LOG_DEBUG);
$result = $db->query($sql); $result = $db->query($sql);
@ -206,7 +221,7 @@ if ($result) {
// Now loop on each link of record in bank. // Now loop on each link of record in bank.
foreach ( $links as $key => $val ) { foreach ( $links as $key => $val ) {
if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport'))) // So we excluded 'company' here if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert'))) // So we excluded 'company' here
{ {
// We save tabtype for a future use, to remember what kind of payment it is // We save tabtype for a future use, to remember what kind of payment it is
$tabtype[$obj->rowid] = $links[$key]['type']; $tabtype[$obj->rowid] = $links[$key]['type'];
@ -473,6 +488,9 @@ if (! $error && $action == 'writebookkeeping') {
} }
$bookkeeping->code_tiers = $tabcompany[$key]['code_compta']; $bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
$bookkeeping->numero_compte = $k; $bookkeeping->numero_compte = $k;
} else if ($tabtype[$key] == 'banktransfert') {
$bookkeeping->code_tiers = '';
$bookkeeping->numero_compte = $k;
} else { } else {
// FIXME Should be a temporary account ??? // FIXME Should be a temporary account ???
$bookkeeping->doc_ref = $k; $bookkeeping->doc_ref = $k;
@ -708,7 +726,7 @@ if (empty($action) || $action == 'view') {
llxHeader('', $langs->trans("FinanceJournal")); llxHeader('', $langs->trans("FinanceJournal"));
$nom = $langs->trans("FinanceJournal") . ' - ' . $bank_code_journal->getNomUrl(1); $nom = $langs->trans("FinanceJournal") . ' - ' . $bankstatic->getNomUrl(1);
$builddate = time(); $builddate = time();
//$description = $langs->trans("DescFinanceJournal") . '<br>'; //$description = $langs->trans("DescFinanceJournal") . '<br>';
$description.= $langs->trans("DescJournalOnlyBindedVisible").'<br>'; $description.= $langs->trans("DescJournalOnlyBindedVisible").'<br>';