Fix : Correct bank transfert when we write operation on general ledger
This commit is contained in:
parent
c651f1da45
commit
095545e8d9
@ -54,18 +54,15 @@ class BookKeeping extends CommonObject
|
|||||||
* @var string Name of table without prefix where object is stored
|
* @var string Name of table without prefix where object is stored
|
||||||
*/
|
*/
|
||||||
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
|
||||||
@ -89,10 +86,10 @@ class BookKeeping extends CommonObject
|
|||||||
public $import_key;
|
public $import_key;
|
||||||
public $code_journal;
|
public $code_journal;
|
||||||
public $piece_num;
|
public $piece_num;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -101,7 +98,7 @@ class BookKeeping extends CommonObject
|
|||||||
public function __construct(DoliDB $db) {
|
public function __construct(DoliDB $db) {
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create object into database
|
* Create object into database
|
||||||
*
|
*
|
||||||
@ -110,12 +107,12 @@ 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);
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
// 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);
|
||||||
@ -177,15 +174,14 @@ class BookKeeping extends CommonObject
|
|||||||
{
|
{
|
||||||
$this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForInvoiceLine', $this->fk_doc, $this->doc_type);
|
$this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForInvoiceLine', $this->fk_doc, $this->doc_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$this->piece_num = 0;
|
$this->piece_num = 0;
|
||||||
|
|
||||||
// First check if line not yet already in bookkeeping
|
// First check if line not yet already in bookkeeping
|
||||||
$sql = "SELECT count(*) as nb";
|
$sql = "SELECT count(*) as nb";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
||||||
@ -193,10 +189,10 @@ 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);
|
||||||
|
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$row = $this->db->fetch_object($resql);
|
$row = $this->db->fetch_object($resql);
|
||||||
if ($row->nb == 0)
|
if ($row->nb == 0)
|
||||||
@ -207,8 +203,8 @@ 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);
|
||||||
if ($resqlnum) {
|
if ($resqlnum) {
|
||||||
@ -219,8 +215,8 @@ 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);
|
||||||
if ($resqlnum) {
|
if ($resqlnum) {
|
||||||
@ -232,12 +228,12 @@ class BookKeeping extends CommonObject
|
|||||||
if (empty($this->piece_num)) {
|
if (empty($this->piece_num)) {
|
||||||
$this->piece_num = 1;
|
$this->piece_num = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$now = dol_now();
|
$now = dol_now();
|
||||||
if (empty($this->date_create)) {
|
if (empty($this->date_create)) {
|
||||||
$this->date_create = $now;
|
$this->date_create = $now;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "INSERT INTO " . MAIN_DB_PREFIX . $this->table_element . " (";
|
$sql = "INSERT INTO " . MAIN_DB_PREFIX . $this->table_element . " (";
|
||||||
$sql .= "doc_date";
|
$sql .= "doc_date";
|
||||||
$sql .= ", doc_type";
|
$sql .= ", doc_type";
|
||||||
@ -275,7 +271,7 @@ class BookKeeping extends CommonObject
|
|||||||
$sql .= "," . $this->piece_num;
|
$sql .= "," . $this->piece_num;
|
||||||
$sql .= ", " . (! isset($this->entity) ? '1' : $this->entity);
|
$sql .= ", " . (! isset($this->entity) ? '1' : $this->entity);
|
||||||
$sql .= ")";
|
$sql .= ")";
|
||||||
|
|
||||||
dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG);
|
dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
@ -308,7 +304,7 @@ class BookKeeping extends CommonObject
|
|||||||
$this->errors[] = 'Error ' . $this->db->lasterror();
|
$this->errors[] = 'Error ' . $this->db->lasterror();
|
||||||
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error) {
|
if (! $error) {
|
||||||
|
|
||||||
if (! $notrigger) {
|
if (! $notrigger) {
|
||||||
@ -321,7 +317,7 @@ class BookKeeping extends CommonObject
|
|||||||
// // End call triggers
|
// // End call triggers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit or rollback
|
// Commit or rollback
|
||||||
if ($error) {
|
if ($error) {
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
@ -331,7 +327,7 @@ class BookKeeping extends CommonObject
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create object into database
|
* Create object into database
|
||||||
*
|
*
|
||||||
@ -341,11 +337,11 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function createStd(User $user, $notrigger = false) {
|
public function createStd(User $user, $notrigger = false) {
|
||||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
@ -393,10 +389,10 @@ class BookKeeping extends CommonObject
|
|||||||
}
|
}
|
||||||
if (empty($this->debit)) $this->debit = 0;
|
if (empty($this->debit)) $this->debit = 0;
|
||||||
if (empty($this->credit)) $this->credit = 0;
|
if (empty($this->credit)) $this->credit = 0;
|
||||||
|
|
||||||
// Check parameters
|
// Check parameters
|
||||||
// Put here code to add control on parameters values
|
// Put here code to add control on parameters values
|
||||||
|
|
||||||
// Insert request
|
// Insert request
|
||||||
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
|
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
|
||||||
$sql .= 'doc_date,';
|
$sql .= 'doc_date,';
|
||||||
@ -435,19 +431,19 @@ class BookKeeping extends CommonObject
|
|||||||
$sql .= ' ' . (empty($this->piece_num) ? 'NULL' : $this->piece_num).',';
|
$sql .= ' ' . (empty($this->piece_num) ? 'NULL' : $this->piece_num).',';
|
||||||
$sql .= ' ' . (! isset($this->entity) ? '1' : $this->entity);
|
$sql .= ' ' . (! isset($this->entity) ? '1' : $this->entity);
|
||||||
$sql .= ')';
|
$sql .= ')';
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if (! $resql) {
|
if (! $resql) {
|
||||||
$error ++;
|
$error ++;
|
||||||
$this->errors[] = 'Error ' . $this->db->lasterror();
|
$this->errors[] = 'Error ' . $this->db->lasterror();
|
||||||
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error) {
|
if (! $error) {
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
|
||||||
|
|
||||||
if (! $notrigger) {
|
if (! $notrigger) {
|
||||||
// Uncomment this and change MYOBJECT to your own tag if you
|
// Uncomment this and change MYOBJECT to your own tag if you
|
||||||
// want this action to call a trigger.
|
// want this action to call a trigger.
|
||||||
@ -458,7 +454,7 @@ class BookKeeping extends CommonObject
|
|||||||
// // End call triggers
|
// // End call triggers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit or rollback
|
// Commit or rollback
|
||||||
if ($error) {
|
if ($error) {
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
@ -470,7 +466,7 @@ class BookKeeping extends CommonObject
|
|||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load object in memory from the database
|
* Load object in memory from the database
|
||||||
*
|
*
|
||||||
@ -481,9 +477,9 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function fetch($id, $ref = null) {
|
public function fetch($id, $ref = null) {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
$sql = 'SELECT';
|
$sql = 'SELECT';
|
||||||
$sql .= ' t.rowid,';
|
$sql .= ' t.rowid,';
|
||||||
$sql .= " t.doc_date,";
|
$sql .= " t.doc_date,";
|
||||||
@ -510,15 +506,15 @@ class BookKeeping extends CommonObject
|
|||||||
} else {
|
} else {
|
||||||
$sql .= ' AND t.rowid = ' . $id;
|
$sql .= ' AND t.rowid = ' . $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$numrows = $this->db->num_rows($resql);
|
$numrows = $this->db->num_rows($resql);
|
||||||
if ($numrows) {
|
if ($numrows) {
|
||||||
$obj = $this->db->fetch_object($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
|
||||||
$this->id = $obj->rowid;
|
$this->id = $obj->rowid;
|
||||||
|
|
||||||
$this->doc_date = $this->db->jdate($obj->doc_date);
|
$this->doc_date = $this->db->jdate($obj->doc_date);
|
||||||
$this->doc_type = $obj->doc_type;
|
$this->doc_type = $obj->doc_type;
|
||||||
$this->doc_ref = $obj->doc_ref;
|
$this->doc_ref = $obj->doc_ref;
|
||||||
@ -537,7 +533,7 @@ class BookKeeping extends CommonObject
|
|||||||
$this->piece_num = $obj->piece_num;
|
$this->piece_num = $obj->piece_num;
|
||||||
}
|
}
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
|
|
||||||
if ($numrows) {
|
if ($numrows) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
@ -565,9 +561,9 @@ 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,';
|
||||||
$sql .= " t.doc_date,";
|
$sql .= " t.doc_date,";
|
||||||
@ -622,16 +618,16 @@ class BookKeeping extends CommonObject
|
|||||||
$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
|
$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
|
||||||
}
|
}
|
||||||
$this->lines = array ();
|
$this->lines = array ();
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$num = $this->db->num_rows($resql);
|
$num = $this->db->num_rows($resql);
|
||||||
|
|
||||||
while ( $obj = $this->db->fetch_object($resql) ) {
|
while ( $obj = $this->db->fetch_object($resql) ) {
|
||||||
$line = new BookKeepingLine();
|
$line = new BookKeepingLine();
|
||||||
|
|
||||||
$line->id = $obj->rowid;
|
$line->id = $obj->rowid;
|
||||||
|
|
||||||
$line->doc_date = $this->db->jdate($obj->doc_date);
|
$line->doc_date = $this->db->jdate($obj->doc_date);
|
||||||
$line->doc_type = $obj->doc_type;
|
$line->doc_type = $obj->doc_type;
|
||||||
$line->doc_ref = $obj->doc_ref;
|
$line->doc_ref = $obj->doc_ref;
|
||||||
@ -648,16 +644,16 @@ class BookKeeping extends CommonObject
|
|||||||
$line->import_key = $obj->import_key;
|
$line->import_key = $obj->import_key;
|
||||||
$line->code_journal = $obj->code_journal;
|
$line->code_journal = $obj->code_journal;
|
||||||
$line->piece_num = $obj->piece_num;
|
$line->piece_num = $obj->piece_num;
|
||||||
|
|
||||||
$this->lines[] = $line;
|
$this->lines[] = $line;
|
||||||
}
|
}
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
|
|
||||||
return $num;
|
return $num;
|
||||||
} else {
|
} else {
|
||||||
$this->errors[] = 'Error ' . $this->db->lasterror();
|
$this->errors[] = 'Error ' . $this->db->lasterror();
|
||||||
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
||||||
|
|
||||||
return - 1;
|
return - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -677,9 +673,9 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') {
|
public function fetchAll($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,';
|
||||||
$sql .= " t.doc_date,";
|
$sql .= " t.doc_date,";
|
||||||
@ -723,7 +719,7 @@ class BookKeeping extends CommonObject
|
|||||||
if (count($sqlwhere) > 0) {
|
if (count($sqlwhere) > 0) {
|
||||||
$sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere);
|
$sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($sortfield)) {
|
if (! empty($sortfield)) {
|
||||||
$sql .= $this->db->order($sortfield, $sortorder);
|
$sql .= $this->db->order($sortfield, $sortorder);
|
||||||
}
|
}
|
||||||
@ -731,16 +727,16 @@ class BookKeeping extends CommonObject
|
|||||||
$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
|
$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
|
||||||
}
|
}
|
||||||
$this->lines = array ();
|
$this->lines = array ();
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$num = $this->db->num_rows($resql);
|
$num = $this->db->num_rows($resql);
|
||||||
|
|
||||||
while ( $obj = $this->db->fetch_object($resql) ) {
|
while ( $obj = $this->db->fetch_object($resql) ) {
|
||||||
$line = new BookKeepingLine();
|
$line = new BookKeepingLine();
|
||||||
|
|
||||||
$line->id = $obj->rowid;
|
$line->id = $obj->rowid;
|
||||||
|
|
||||||
$line->doc_date = $this->db->jdate($obj->doc_date);
|
$line->doc_date = $this->db->jdate($obj->doc_date);
|
||||||
$line->doc_type = $obj->doc_type;
|
$line->doc_type = $obj->doc_type;
|
||||||
$line->doc_ref = $obj->doc_ref;
|
$line->doc_ref = $obj->doc_ref;
|
||||||
@ -757,20 +753,20 @@ class BookKeeping extends CommonObject
|
|||||||
$line->import_key = $obj->import_key;
|
$line->import_key = $obj->import_key;
|
||||||
$line->code_journal = $obj->code_journal;
|
$line->code_journal = $obj->code_journal;
|
||||||
$line->piece_num = $obj->piece_num;
|
$line->piece_num = $obj->piece_num;
|
||||||
|
|
||||||
$this->lines[] = $line;
|
$this->lines[] = $line;
|
||||||
}
|
}
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
|
|
||||||
return $num;
|
return $num;
|
||||||
} else {
|
} else {
|
||||||
$this->errors[] = 'Error ' . $this->db->lasterror();
|
$this->errors[] = 'Error ' . $this->db->lasterror();
|
||||||
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
||||||
|
|
||||||
return - 1;
|
return - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load object in memory from the database
|
* Load object in memory from the database
|
||||||
*
|
*
|
||||||
@ -785,9 +781,9 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function fetchAllBalance($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') {
|
public function fetchAllBalance($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.numero_compte,";
|
$sql .= " t.numero_compte,";
|
||||||
$sql .= " SUM(t.debit) as debit,";
|
$sql .= " SUM(t.debit) as debit,";
|
||||||
@ -817,9 +813,9 @@ class BookKeeping extends CommonObject
|
|||||||
if (count($sqlwhere) > 0) {
|
if (count($sqlwhere) > 0) {
|
||||||
$sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere);
|
$sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= ' GROUP BY t.numero_compte';
|
$sql .= ' GROUP BY t.numero_compte';
|
||||||
|
|
||||||
if (! empty($sortfield)) {
|
if (! empty($sortfield)) {
|
||||||
$sql .= $this->db->order($sortfield, $sortorder);
|
$sql .= $this->db->order($sortfield, $sortorder);
|
||||||
}
|
}
|
||||||
@ -827,30 +823,30 @@ class BookKeeping extends CommonObject
|
|||||||
$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
|
$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
|
||||||
}
|
}
|
||||||
$this->lines = array ();
|
$this->lines = array ();
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$num = $this->db->num_rows($resql);
|
$num = $this->db->num_rows($resql);
|
||||||
|
|
||||||
while ( $obj = $this->db->fetch_object($resql) ) {
|
while ( $obj = $this->db->fetch_object($resql) ) {
|
||||||
$line = new BookKeepingLine();
|
$line = new BookKeepingLine();
|
||||||
|
|
||||||
$line->numero_compte = $obj->numero_compte;
|
$line->numero_compte = $obj->numero_compte;
|
||||||
$line->debit = $obj->debit;
|
$line->debit = $obj->debit;
|
||||||
$line->credit = $obj->credit;
|
$line->credit = $obj->credit;
|
||||||
$this->lines[] = $line;
|
$this->lines[] = $line;
|
||||||
}
|
}
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
|
|
||||||
return $num;
|
return $num;
|
||||||
} else {
|
} else {
|
||||||
$this->errors[] = 'Error ' . $this->db->lasterror();
|
$this->errors[] = 'Error ' . $this->db->lasterror();
|
||||||
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
||||||
|
|
||||||
return - 1;
|
return - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update object into database
|
* Update object into database
|
||||||
*
|
*
|
||||||
@ -861,11 +857,10 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function update(User $user, $notrigger = false) {
|
public function update(User $user, $notrigger = false) {
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -911,10 +906,10 @@ class BookKeeping extends CommonObject
|
|||||||
if (isset($this->piece_num)) {
|
if (isset($this->piece_num)) {
|
||||||
$this->piece_num = trim($this->piece_num);
|
$this->piece_num = trim($this->piece_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check parameters
|
// Check parameters
|
||||||
// Put here code to add a control on parameters values
|
// Put here code to add a control on parameters values
|
||||||
|
|
||||||
// Update request
|
// Update request
|
||||||
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
|
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
|
||||||
$sql .= ' doc_date = ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) != 0 ? "'" . $this->db->idate($this->doc_date) . "'" : 'null') . ',';
|
$sql .= ' doc_date = ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) != 0 ? "'" . $this->db->idate($this->doc_date) . "'" : 'null') . ',';
|
||||||
@ -934,16 +929,16 @@ class BookKeeping extends CommonObject
|
|||||||
$sql .= ' code_journal = ' . (isset($this->code_journal) ? "'" . $this->db->escape($this->code_journal) . "'" : "null") . ',';
|
$sql .= ' code_journal = ' . (isset($this->code_journal) ? "'" . $this->db->escape($this->code_journal) . "'" : "null") . ',';
|
||||||
$sql .= ' piece_num = ' . (isset($this->piece_num) ? $this->piece_num : "null");
|
$sql .= ' piece_num = ' . (isset($this->piece_num) ? $this->piece_num : "null");
|
||||||
$sql .= ' WHERE rowid=' . $this->id;
|
$sql .= ' WHERE rowid=' . $this->id;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if (! $resql) {
|
if (! $resql) {
|
||||||
$error ++;
|
$error ++;
|
||||||
$this->errors[] = 'Error ' . $this->db->lasterror();
|
$this->errors[] = 'Error ' . $this->db->lasterror();
|
||||||
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error && ! $notrigger) {
|
if (! $error && ! $notrigger) {
|
||||||
// Uncomment this and change MYOBJECT to your own tag if you
|
// Uncomment this and change MYOBJECT to your own tag if you
|
||||||
// want this action calls a trigger.
|
// want this action calls a trigger.
|
||||||
@ -953,19 +948,19 @@ class BookKeeping extends CommonObject
|
|||||||
// if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
|
// if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
|
||||||
// // End call triggers
|
// // End call triggers
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit or rollback
|
// Commit or rollback
|
||||||
if ($error) {
|
if ($error) {
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
|
|
||||||
return - 1 * $error;
|
return - 1 * $error;
|
||||||
} else {
|
} else {
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete object in database
|
* Delete object in database
|
||||||
*
|
*
|
||||||
@ -976,27 +971,27 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function delete(User $user, $notrigger = false) {
|
public function delete(User $user, $notrigger = false) {
|
||||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
if (! $error) {
|
if (! $error) {
|
||||||
if (! $notrigger) {
|
if (! $notrigger) {
|
||||||
// Uncomment this and change MYOBJECT to your own tag if you
|
// Uncomment this and change MYOBJECT to your own tag if you
|
||||||
// want this action calls a trigger.
|
// want this action calls a trigger.
|
||||||
|
|
||||||
// // Call triggers
|
// // Call triggers
|
||||||
// $result=$this->call_trigger('MYOBJECT_DELETE',$user);
|
// $result=$this->call_trigger('MYOBJECT_DELETE',$user);
|
||||||
// if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
|
// if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
|
||||||
// // End call triggers
|
// // End call triggers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error) {
|
if (! $error) {
|
||||||
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
|
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
|
||||||
$sql .= ' WHERE rowid=' . $this->id;
|
$sql .= ' WHERE rowid=' . $this->id;
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if (! $resql) {
|
if (! $resql) {
|
||||||
$error ++;
|
$error ++;
|
||||||
@ -1004,19 +999,19 @@ class BookKeeping extends CommonObject
|
|||||||
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit or rollback
|
// Commit or rollback
|
||||||
if ($error) {
|
if ($error) {
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
|
|
||||||
return - 1 * $error;
|
return - 1 * $error;
|
||||||
} else {
|
} else {
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete bookkepping by importkey
|
* Delete bookkepping by importkey
|
||||||
*
|
*
|
||||||
@ -1025,25 +1020,25 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function deleteByImportkey($importkey) {
|
function deleteByImportkey($importkey) {
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// first check if line not yet in bookkeeping
|
// first check if line not yet in bookkeeping
|
||||||
$sql = "DELETE";
|
$sql = "DELETE";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
||||||
$sql .= " WHERE import_key = '" . $importkey . "'";
|
$sql .= " WHERE import_key = '" . $importkey . "'";
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|
||||||
if (! $resql) {
|
if (! $resql) {
|
||||||
$this->errors[] = "Error " . $this->db->lasterror();
|
$this->errors[] = "Error " . $this->db->lasterror();
|
||||||
dol_syslog(get_class($this)."::delete Error " . $this->db->lasterror(), LOG_ERR);
|
dol_syslog(get_class($this)."::delete Error " . $this->db->lasterror(), LOG_ERR);
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return - 1;
|
return - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete bookkepping by year
|
* Delete bookkepping by year
|
||||||
*
|
*
|
||||||
@ -1053,14 +1048,14 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function deleteByYearAndJournal($delyear='', $journal='') {
|
function deleteByYearAndJournal($delyear='', $journal='') {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
if (empty($delyear) && empty($journal))
|
if (empty($delyear) && empty($journal))
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// first check if line not yet in bookkeeping
|
// first check if line not yet in bookkeeping
|
||||||
$sql = "DELETE";
|
$sql = "DELETE";
|
||||||
$sql.= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
$sql.= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
||||||
@ -1069,7 +1064,7 @@ class BookKeeping extends CommonObject
|
|||||||
if (! empty($journal)) $sql.= " AND code_journal = '".$journal."'";
|
if (! empty($journal)) $sql.= " AND code_journal = '".$journal."'";
|
||||||
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
|
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|
||||||
if (! $resql) {
|
if (! $resql) {
|
||||||
$this->errors[] = "Error " . $this->db->lasterror();
|
$this->errors[] = "Error " . $this->db->lasterror();
|
||||||
foreach ( $this->errors as $errmsg ) {
|
foreach ( $this->errors as $errmsg ) {
|
||||||
@ -1079,11 +1074,11 @@ class BookKeeping extends CommonObject
|
|||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete bookkepping by piece number
|
* Delete bookkepping by piece number
|
||||||
*
|
*
|
||||||
@ -1092,17 +1087,17 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function deleteMvtNum($piecenum) {
|
function deleteMvtNum($piecenum) {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// first check if line not yet in bookkeeping
|
// first check if line not yet in bookkeeping
|
||||||
$sql = "DELETE";
|
$sql = "DELETE";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
||||||
$sql .= " WHERE piece_num = " . $piecenum;
|
$sql .= " WHERE piece_num = " . $piecenum;
|
||||||
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
|
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|
||||||
if (! $resql) {
|
if (! $resql) {
|
||||||
$this->errors[] = "Error " . $this->db->lasterror();
|
$this->errors[] = "Error " . $this->db->lasterror();
|
||||||
foreach ( $this->errors as $errmsg ) {
|
foreach ( $this->errors as $errmsg ) {
|
||||||
@ -1112,11 +1107,11 @@ class BookKeeping extends CommonObject
|
|||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return - 1;
|
return - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load an object from its id and create a new one in database
|
* Load an object from its id and create a new one in database
|
||||||
*
|
*
|
||||||
@ -1126,43 +1121,43 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function createFromClone($fromid) {
|
public function createFromClone($fromid) {
|
||||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
global $user;
|
global $user;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
$object = new Accountingbookkeeping($this->db);
|
$object = new Accountingbookkeeping($this->db);
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Load source object
|
// Load source object
|
||||||
$object->fetch($fromid);
|
$object->fetch($fromid);
|
||||||
// Reset object
|
// Reset object
|
||||||
$object->id = 0;
|
$object->id = 0;
|
||||||
|
|
||||||
// Clear fields
|
// Clear fields
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
// Create clone
|
// Create clone
|
||||||
$result = $object->create($user);
|
$result = $object->create($user);
|
||||||
|
|
||||||
// Other options
|
// Other options
|
||||||
if ($result < 0) {
|
if ($result < 0) {
|
||||||
$error ++;
|
$error ++;
|
||||||
$this->errors = $object->errors;
|
$this->errors = $object->errors;
|
||||||
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// End
|
// End
|
||||||
if (! $error) {
|
if (! $error) {
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
|
|
||||||
return $object->id;
|
return $object->id;
|
||||||
} else {
|
} else {
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
|
|
||||||
return - 1;
|
return - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise object with example values
|
* Initialise object with example values
|
||||||
* Id must be 0 if object instance is a specimen
|
* Id must be 0 if object instance is a specimen
|
||||||
@ -1171,9 +1166,9 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function initAsSpecimen() {
|
public function initAsSpecimen() {
|
||||||
global $user;
|
global $user;
|
||||||
|
|
||||||
$now=dol_now();
|
$now=dol_now();
|
||||||
|
|
||||||
$this->id = 0;
|
$this->id = 0;
|
||||||
$this->doc_date = $now;
|
$this->doc_date = $now;
|
||||||
$this->doc_type = '';
|
$this->doc_type = '';
|
||||||
@ -1192,7 +1187,7 @@ class BookKeeping extends CommonObject
|
|||||||
$this->code_journal = '';
|
$this->code_journal = '';
|
||||||
$this->piece_num = '';
|
$this->piece_num = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load an accounting document into memory from database
|
* Load an accounting document into memory from database
|
||||||
*
|
*
|
||||||
@ -1201,17 +1196,17 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function fetchPerMvt($piecenum) {
|
public function fetchPerMvt($piecenum) {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type";
|
$sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
||||||
$sql .= " WHERE piece_num = " . $piecenum;
|
$sql .= " WHERE piece_num = " . $piecenum;
|
||||||
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
|
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
|
||||||
|
|
||||||
dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG);
|
dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$obj = $this->db->fetch_object($result);
|
$obj = $this->db->fetch_object($result);
|
||||||
|
|
||||||
$this->piece_num = $obj->piece_num;
|
$this->piece_num = $obj->piece_num;
|
||||||
$this->code_journal = $obj->code_journal;
|
$this->code_journal = $obj->code_journal;
|
||||||
$this->doc_date = $this->db->jdate($obj->doc_date);
|
$this->doc_date = $this->db->jdate($obj->doc_date);
|
||||||
@ -1225,7 +1220,7 @@ class BookKeeping extends CommonObject
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return next number movement
|
* Return next number movement
|
||||||
*
|
*
|
||||||
@ -1234,10 +1229,10 @@ class BookKeeping extends CommonObject
|
|||||||
public function getNextNumMvt()
|
public function getNextNumMvt()
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element;
|
$sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element;
|
||||||
$sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
|
$sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
|
||||||
|
|
||||||
dol_syslog(get_class($this) . "getNextNumMvt sql=" . $sql, LOG_DEBUG);
|
dol_syslog(get_class($this) . "getNextNumMvt sql=" . $sql, LOG_DEBUG);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
|
|
||||||
@ -1252,7 +1247,7 @@ class BookKeeping extends CommonObject
|
|||||||
return - 1;
|
return - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load all informations of accountancy document
|
* Load all informations of accountancy document
|
||||||
*
|
*
|
||||||
@ -1261,7 +1256,7 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function fetch_all_per_mvt($piecenum) {
|
function fetch_all_per_mvt($piecenum) {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$sql = "SELECT rowid, doc_date, doc_type,";
|
$sql = "SELECT rowid, doc_date, doc_type,";
|
||||||
$sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,";
|
$sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,";
|
||||||
$sql .= " numero_compte, label_compte, debit, credit,";
|
$sql .= " numero_compte, label_compte, debit, credit,";
|
||||||
@ -1269,17 +1264,17 @@ class BookKeeping extends CommonObject
|
|||||||
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
||||||
$sql .= " WHERE piece_num = " . $piecenum;
|
$sql .= " WHERE piece_num = " . $piecenum;
|
||||||
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
|
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
|
||||||
|
|
||||||
dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG);
|
dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
|
||||||
while ( $obj = $this->db->fetch_object($result) ) {
|
while ( $obj = $this->db->fetch_object($result) ) {
|
||||||
|
|
||||||
$line = new BookKeepingLine();
|
$line = new BookKeepingLine();
|
||||||
|
|
||||||
$line->id = $obj->rowid;
|
$line->id = $obj->rowid;
|
||||||
|
|
||||||
$line->doc_date = $this->db->jdate($obj->doc_date);
|
$line->doc_date = $this->db->jdate($obj->doc_date);
|
||||||
$line->doc_type = $obj->doc_type;
|
$line->doc_type = $obj->doc_type;
|
||||||
$line->doc_ref = $obj->doc_ref;
|
$line->doc_ref = $obj->doc_ref;
|
||||||
@ -1294,7 +1289,7 @@ class BookKeeping extends CommonObject
|
|||||||
$line->sens = $obj->sens;
|
$line->sens = $obj->sens;
|
||||||
$line->code_journal = $obj->code_journal;
|
$line->code_journal = $obj->code_journal;
|
||||||
$line->piece_num = $obj->piece_num;
|
$line->piece_num = $obj->piece_num;
|
||||||
|
|
||||||
$this->linesmvt[] = $line;
|
$this->linesmvt[] = $line;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1305,7 +1300,7 @@ class BookKeeping extends CommonObject
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export bookkeping
|
* Export bookkeping
|
||||||
*
|
*
|
||||||
@ -1314,27 +1309,27 @@ class BookKeeping extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function export_bookkeping($model = 'ebp') {
|
function export_bookkeping($model = 'ebp') {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$sql = "SELECT rowid, doc_date, doc_type,";
|
$sql = "SELECT rowid, doc_date, doc_type,";
|
||||||
$sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,";
|
$sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,";
|
||||||
$sql .= " numero_compte, label_compte, debit, credit,";
|
$sql .= " numero_compte, label_compte, debit, credit,";
|
||||||
$sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num";
|
$sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
|
||||||
$sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
|
$sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
|
||||||
|
|
||||||
dol_syslog(get_class($this) . "::export_bookkeping", LOG_DEBUG);
|
dol_syslog(get_class($this) . "::export_bookkeping", LOG_DEBUG);
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$this->linesexport = array ();
|
$this->linesexport = array ();
|
||||||
|
|
||||||
$num = $this->db->num_rows($resql);
|
$num = $this->db->num_rows($resql);
|
||||||
while ( $obj = $this->db->fetch_object($resql) ) {
|
while ( $obj = $this->db->fetch_object($resql) ) {
|
||||||
$line = new BookKeepingLine();
|
$line = new BookKeepingLine();
|
||||||
|
|
||||||
$line->id = $obj->rowid;
|
$line->id = $obj->rowid;
|
||||||
|
|
||||||
$line->doc_date = $this->db->jdate($obj->doc_date);
|
$line->doc_date = $this->db->jdate($obj->doc_date);
|
||||||
$line->doc_type = $obj->doc_type;
|
$line->doc_type = $obj->doc_type;
|
||||||
$line->doc_ref = $obj->doc_ref;
|
$line->doc_ref = $obj->doc_ref;
|
||||||
@ -1349,11 +1344,11 @@ class BookKeeping extends CommonObject
|
|||||||
$line->sens = $obj->sens;
|
$line->sens = $obj->sens;
|
||||||
$line->code_journal = $obj->code_journal;
|
$line->code_journal = $obj->code_journal;
|
||||||
$line->piece_num = $obj->piece_num;
|
$line->piece_num = $obj->piece_num;
|
||||||
|
|
||||||
$this->linesexport[] = $line;
|
$this->linesexport[] = $line;
|
||||||
}
|
}
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
|
|
||||||
return $num;
|
return $num;
|
||||||
} else {
|
} else {
|
||||||
$this->error = "Error " . $this->db->lasterror();
|
$this->error = "Error " . $this->db->lasterror();
|
||||||
@ -1433,8 +1428,7 @@ class BookKeeping extends CommonObject
|
|||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of a root accounting account
|
* Description of a root accounting account
|
||||||
*
|
*
|
||||||
@ -1442,10 +1436,10 @@ class BookKeeping extends CommonObject
|
|||||||
* @return string Root account
|
* @return string Root account
|
||||||
*/
|
*/
|
||||||
function get_compte_racine($account = null)
|
function get_compte_racine($account = null)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
$pcgver = $conf->global->CHARTOFACCOUNTS;
|
$pcgver = $conf->global->CHARTOFACCOUNTS;
|
||||||
|
|
||||||
$sql = "SELECT root.account_number, root.label as label";
|
$sql = "SELECT root.account_number, root.label as label";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
|
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
|
||||||
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
|
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
|
||||||
@ -1456,7 +1450,7 @@ class BookKeeping extends CommonObject
|
|||||||
$sql .= " AND parent.active = 1";
|
$sql .= " AND parent.active = 1";
|
||||||
$sql .= " AND root.active = 1";
|
$sql .= " AND root.active = 1";
|
||||||
$sql .= " AND aa.entity IN (" . getEntity("accountancy", 1) . ")";
|
$sql .= " AND aa.entity IN (" . getEntity("accountancy", 1) . ")";
|
||||||
|
|
||||||
dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG);
|
dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
@ -1464,9 +1458,9 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $obj->label;
|
return $obj->label;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->error = "Error " . $this->db->lasterror();
|
$this->error = "Error " . $this->db->lasterror();
|
||||||
dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR);
|
dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR);
|
||||||
@ -1483,9 +1477,9 @@ class BookKeeping extends CommonObject
|
|||||||
* @return string Account desc
|
* @return string Account desc
|
||||||
*/
|
*/
|
||||||
function get_compte_desc($account = null)
|
function get_compte_desc($account = null)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$pcgver = $conf->global->CHARTOFACCOUNTS;
|
$pcgver = $conf->global->CHARTOFACCOUNTS;
|
||||||
$sql = "SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
|
$sql = "SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa ";
|
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa ";
|
||||||
@ -1495,7 +1489,7 @@ class BookKeeping extends CommonObject
|
|||||||
$sql .= " AND aa.active = 1";
|
$sql .= " AND aa.active = 1";
|
||||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
|
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
|
||||||
$sql .= " WHERE aa.entity IN (" . getEntity("accountancy", 1) . ")";
|
$sql .= " WHERE aa.entity IN (" . getEntity("accountancy", 1) . ")";
|
||||||
|
|
||||||
dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG);
|
dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
@ -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();
|
||||||
|
|||||||
@ -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');
|
||||||
@ -83,9 +87,9 @@ if ($user->societe_id > 0 && empty($id_bank_account))
|
|||||||
/*
|
/*
|
||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
$year_current = strftime("%Y", dol_now());
|
$year_current = strftime("%Y", dol_now());
|
||||||
$pastmonth = strftime("%m", dol_now()) - 1;
|
$pastmonth = strftime("%m", dol_now()) - 1;
|
||||||
$pastmonthyear = $year_current;
|
$pastmonthyear = $year_current;
|
||||||
@ -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);
|
||||||
@ -179,7 +194,7 @@ if ($result) {
|
|||||||
'name' => $obj->name,
|
'name' => $obj->name,
|
||||||
'code_compta' => $compta_soc,
|
'code_compta' => $compta_soc,
|
||||||
);
|
);
|
||||||
|
|
||||||
$compta_user = (! empty($obj->accountancy_code) ? $obj->accountancy_code : $account_employee);
|
$compta_user = (! empty($obj->accountancy_code) ? $obj->accountancy_code : $account_employee);
|
||||||
|
|
||||||
$tabuser[$obj->rowid] = array (
|
$tabuser[$obj->rowid] = array (
|
||||||
@ -205,8 +220,8 @@ if ($result) {
|
|||||||
if (is_array($links)) {
|
if (is_array($links)) {
|
||||||
// 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'];
|
||||||
@ -330,11 +345,11 @@ if (! $error && $action == 'writebookkeeping') {
|
|||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
foreach ( $tabpay as $key => $val ) { // $key is rowid into llx_bank
|
foreach ( $tabpay as $key => $val ) { // $key is rowid into llx_bank
|
||||||
|
|
||||||
$errorforline = 0;
|
$errorforline = 0;
|
||||||
|
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
// Bank
|
// Bank
|
||||||
if (! $errorforline)
|
if (! $errorforline)
|
||||||
{
|
{
|
||||||
@ -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;
|
||||||
@ -705,17 +723,17 @@ if (empty($action) || $action == 'view') {
|
|||||||
$invoicestatic = new Facture($db);
|
$invoicestatic = new Facture($db);
|
||||||
$invoicesupplierstatic = new FactureFournisseur($db);
|
$invoicesupplierstatic = new FactureFournisseur($db);
|
||||||
$expensereportstatic = new ExpenseReport($db);
|
$expensereportstatic = new ExpenseReport($db);
|
||||||
|
|
||||||
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>';
|
||||||
$period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1);
|
$period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1);
|
||||||
|
|
||||||
$varlink = 'id_account=' . $id_bank_account;
|
$varlink = 'id_account=' . $id_bank_account;
|
||||||
|
|
||||||
journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
|
journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
|
||||||
|
|
||||||
/*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) {
|
/*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user