|
@@ -2,7 +2,7 @@
|
|
|
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
|
* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
|
|
|
* Copyright (C) 2013-2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
|
|
|
- * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
|
|
|
+ * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
|
|
|
*
|
|
|
* 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
|
|
@@ -49,7 +49,7 @@ class BookKeeping
|
|
|
var $piece_num;
|
|
|
var $linesexport = array ();
|
|
|
var $linesmvt = array ();
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Constructor
|
|
|
*
|
|
@@ -59,7 +59,7 @@ class BookKeeping
|
|
|
{
|
|
|
$this->db = $db;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Load a line into memory from database
|
|
|
*
|
|
@@ -74,14 +74,14 @@ class BookKeeping
|
|
|
$sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num ";
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping ";
|
|
|
$sql .= " WHERE rowid = '" . $id . "'";
|
|
|
-
|
|
|
+
|
|
|
dol_syslog(get_class($this) . "fetch sql=" . $sql, LOG_DEBUG);
|
|
|
$result = $this->db->query($sql);
|
|
|
if ($result) {
|
|
|
$obj = $this->db->fetch_object($result);
|
|
|
-
|
|
|
+
|
|
|
$this->id = $obj->rowid;
|
|
|
-
|
|
|
+
|
|
|
$this->doc_date = $this->db->jdate($obj->doc_date);
|
|
|
$this->doc_type = $obj->doc_type;
|
|
|
$this->doc_ref = $obj->doc_ref;
|
|
@@ -103,10 +103,10 @@ class BookKeeping
|
|
|
dol_syslog(get_class($this) . "::fetch " . $this->error, LOG_ERR);
|
|
|
return - 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Load an accounting document into memory from database
|
|
|
*
|
|
@@ -118,12 +118,12 @@ class BookKeeping
|
|
|
$sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type";
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping";
|
|
|
$sql .= " WHERE piece_num = '" . $piecenum . "'";
|
|
|
-
|
|
|
+
|
|
|
dol_syslog(get_class($this) . "fetch_per_mvt sql=" . $sql, LOG_DEBUG);
|
|
|
$result = $this->db->query($sql);
|
|
|
if ($result) {
|
|
|
$obj = $this->db->fetch_object($result);
|
|
|
-
|
|
|
+
|
|
|
$this->piece_num = $obj->piece_num;
|
|
|
$this->code_journal = $obj->code_journal;
|
|
|
$this->doc_date = $this->db->jdate($obj->doc_date);
|
|
@@ -134,10 +134,10 @@ class BookKeeping
|
|
|
dol_syslog(get_class($this) . "::fetch_per_mvt " . $this->error, LOG_ERR);
|
|
|
return - 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Return next number movement
|
|
|
*
|
|
@@ -145,14 +145,14 @@ class BookKeeping
|
|
|
*/
|
|
|
function getNextNumMvt() {
|
|
|
$sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping";
|
|
|
-
|
|
|
+
|
|
|
dol_syslog(get_class($this) . "getNextNumMvt sql=" . $sql, LOG_DEBUG);
|
|
|
$result = $this->db->query($sql);
|
|
|
-
|
|
|
+
|
|
|
if ($result)
|
|
|
{
|
|
|
$obj = $this->db->fetch_object($result);
|
|
|
-
|
|
|
+
|
|
|
return $obj->max;
|
|
|
}
|
|
|
else
|
|
@@ -162,7 +162,7 @@ class BookKeeping
|
|
|
return - 1;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Load all informations of accountancy document
|
|
|
*
|
|
@@ -177,17 +177,17 @@ class BookKeeping
|
|
|
$sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num";
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping ";
|
|
|
$sql .= " WHERE piece_num = '" . $piecenum . "'";
|
|
|
-
|
|
|
+
|
|
|
dol_syslog(get_class($this) . "fetch_all_per_mvt sql=" . $sql, LOG_DEBUG);
|
|
|
$result = $this->db->query($sql);
|
|
|
if ($result) {
|
|
|
-
|
|
|
+
|
|
|
while ( $obj = $this->db->fetch_object($result) ) {
|
|
|
-
|
|
|
+
|
|
|
$line = new BookKeepingLine();
|
|
|
-
|
|
|
+
|
|
|
$line->id = $obj->rowid;
|
|
|
-
|
|
|
+
|
|
|
$line->doc_date = $this->db->jdate($obj->doc_date);
|
|
|
$line->doc_type = $obj->doc_type;
|
|
|
$line->doc_ref = $obj->doc_ref;
|
|
@@ -202,7 +202,7 @@ class BookKeeping
|
|
|
$line->sens = $obj->sens;
|
|
|
$line->code_journal = $obj->code_journal;
|
|
|
$line->piece_num = $obj->piece_num;
|
|
|
-
|
|
|
+
|
|
|
$this->linesmvt[] = $line;
|
|
|
}
|
|
|
} else {
|
|
@@ -210,40 +210,43 @@ class BookKeeping
|
|
|
dol_syslog(get_class($this) . "::fetch_per_mvt " . $this->error, LOG_ERR);
|
|
|
return - 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * \brief Insert line into bookkeeping
|
|
|
- * \param user User who inserted operation
|
|
|
+ * Insert line into bookkeeping
|
|
|
+ *
|
|
|
+ * @param User $user User who inserted operation
|
|
|
+ * @return $result Result
|
|
|
*/
|
|
|
- function create() {
|
|
|
+ function create($user='')
|
|
|
+ {
|
|
|
global $conf, $user, $langs;
|
|
|
-
|
|
|
+
|
|
|
$this->piece_num = 0;
|
|
|
-
|
|
|
+
|
|
|
// first check if line not yet in bookkeeping
|
|
|
$sql = "SELECT count(*)";
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping ";
|
|
|
$sql .= " WHERE doc_type = '" . $this->doc_type . "'";
|
|
|
$sql .= " AND fk_docdet = " . $this->fk_docdet;
|
|
|
$sql .= " AND numero_compte = '" . $this->numero_compte . "'";
|
|
|
-
|
|
|
+
|
|
|
dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG);
|
|
|
$resql = $this->db->query($sql);
|
|
|
-
|
|
|
+
|
|
|
if ($resql) {
|
|
|
$row = $this->db->fetch_array($resql);
|
|
|
if ($row[0] == 0) {
|
|
|
-
|
|
|
+
|
|
|
// Determine piece_num
|
|
|
$sqlnum = "SELECT piece_num";
|
|
|
$sqlnum .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping ";
|
|
|
$sqlnum .= " WHERE doc_type = '" . $this->doc_type . "'";
|
|
|
$sqlnum .= " AND fk_docdet = '" . $this->fk_docdet . "'";
|
|
|
$sqlnum .= " AND doc_ref = '" . $this->doc_ref . "'";
|
|
|
-
|
|
|
+
|
|
|
dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG);
|
|
|
$resqlnum = $this->db->query($sqlnum);
|
|
|
if ($resqlnum)
|
|
@@ -256,7 +259,7 @@ class BookKeeping
|
|
|
{
|
|
|
$sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum";
|
|
|
$sqlnum .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping ";
|
|
|
-
|
|
|
+
|
|
|
dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG);
|
|
|
$resqlnum = $this->db->query($sqlnum);
|
|
|
if ($resqlnum) {
|
|
@@ -268,11 +271,11 @@ class BookKeeping
|
|
|
if (empty($this->piece_num)) {
|
|
|
$this->piece_num = 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$now = dol_now();
|
|
|
if (empty($this->date_create))
|
|
|
$this->date_create = $now();
|
|
|
-
|
|
|
+
|
|
|
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_bookkeeping (doc_date, ";
|
|
|
$sql .= "doc_type, doc_ref,fk_doc,fk_docdet,code_tiers,numero_compte,label_compte,";
|
|
|
$sql .= "debit,credit,montant,sens,fk_user_author,import_key,code_journal,piece_num)";
|
|
@@ -280,12 +283,12 @@ class BookKeeping
|
|
|
$sql .= $this->fk_docdet . ",'" . $this->code_tiers . "','" . $this->numero_compte . "','" . $this->db->escape($this->label_compte) . "',";
|
|
|
$sql .= $this->debit . "," . $this->credit . "," . $this->montant . ",'" . $this->sens . "'," . $user->id . ", '";
|
|
|
$sql .= $this->date_create . "','" . $this->code_journal . "'," . $this->piece_num . ")";
|
|
|
-
|
|
|
+
|
|
|
dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG);
|
|
|
$resql = $this->db->query($sql);
|
|
|
if ($resql) {
|
|
|
$id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_bookkeeping");
|
|
|
-
|
|
|
+
|
|
|
if ($id > 0) {
|
|
|
$this->id = $id;
|
|
|
$result = 0;
|
|
@@ -305,27 +308,30 @@ class BookKeeping
|
|
|
$result = - 5;
|
|
|
dol_syslog("BookKeeping::Create Erreur $result SELECT Mysql");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return $result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * \brief Delete bookkepping by importkey
|
|
|
+ * Delete bookkepping by importkey
|
|
|
+ *
|
|
|
+ * @param string $importkey Import key
|
|
|
+ * @return int Result
|
|
|
*/
|
|
|
function delete_by_importkey($importkey) {
|
|
|
$this->db->begin();
|
|
|
-
|
|
|
+
|
|
|
// first check if line not yet in bookkeeping
|
|
|
$sql = "DELETE";
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping ";
|
|
|
$sql .= " WHERE import_key = '" . $importkey . "'";
|
|
|
-
|
|
|
+
|
|
|
$resql = $this->db->query($sql);
|
|
|
if (! $resql) {
|
|
|
$error ++;
|
|
|
$this->errors[] = "Error " . $this->db->lasterror();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Commit or rollback
|
|
|
if ($error) {
|
|
|
foreach ( $this->errors as $errmsg ) {
|
|
@@ -339,7 +345,7 @@ class BookKeeping
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Create object into database
|
|
|
*
|
|
@@ -351,7 +357,7 @@ class BookKeeping
|
|
|
{
|
|
|
global $conf, $langs;
|
|
|
$error = 0;
|
|
|
-
|
|
|
+
|
|
|
// Clean parameters
|
|
|
if (isset($this->doc_type))
|
|
|
$this->doc_type = trim($this->doc_type);
|
|
@@ -383,10 +389,10 @@ class BookKeeping
|
|
|
$this->code_journal = trim($this->code_journal);
|
|
|
if (isset($this->piece_num))
|
|
|
$this->piece_num = trim($this->piece_num);
|
|
|
-
|
|
|
+
|
|
|
// Check parameters
|
|
|
// Put here code to add control on parameters values
|
|
|
-
|
|
|
+
|
|
|
// Insert request
|
|
|
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_bookkeeping(";
|
|
|
$sql .= "doc_date,";
|
|
@@ -405,9 +411,9 @@ class BookKeeping
|
|
|
$sql .= "import_key,";
|
|
|
$sql .= "code_journal,";
|
|
|
$sql .= "piece_num";
|
|
|
-
|
|
|
+
|
|
|
$sql .= ") VALUES (";
|
|
|
-
|
|
|
+
|
|
|
$sql .= " " . (! isset($this->doc_date) || dol_strlen($this->doc_date) == 0 ? 'NULL' : $this->db->idate($this->doc_date)) . ",";
|
|
|
$sql .= " " . (! isset($this->doc_type) ? 'NULL' : "'" . $this->db->escape($this->doc_type) . "'") . ",";
|
|
|
$sql .= " " . (! isset($this->doc_ref) ? 'NULL' : "'" . $this->db->escape($this->doc_ref) . "'") . ",";
|
|
@@ -424,25 +430,25 @@ class BookKeeping
|
|
|
$sql .= " " . (! isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'") . ",";
|
|
|
$sql .= " " . (! isset($this->code_journal) ? 'NULL' : "'" . $this->db->escape($this->code_journal) . "'") . ",";
|
|
|
$sql .= " " . (! isset($this->piece_num) ? 'NULL' : "'" . $this->piece_num . "'") . "";
|
|
|
-
|
|
|
+
|
|
|
$sql .= ")";
|
|
|
-
|
|
|
+
|
|
|
$this->db->begin();
|
|
|
-
|
|
|
+
|
|
|
dol_syslog(get_class($this) . "::create_std sql=" . $sql, LOG_DEBUG);
|
|
|
$resql = $this->db->query($sql);
|
|
|
if (! $resql) {
|
|
|
$error ++;
|
|
|
$this->errors[] = "Error " . $this->db->lasterror();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (! $error) {
|
|
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_bookkeeping");
|
|
|
-
|
|
|
+
|
|
|
if (! $notrigger) {
|
|
|
// Uncomment this and change MYOBJECT to your own tag if you
|
|
|
// want this action calls a trigger.
|
|
|
-
|
|
|
+
|
|
|
// // Call triggers
|
|
|
// include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
|
|
// $interface=new Interfaces($this->db);
|
|
@@ -451,7 +457,7 @@ class BookKeeping
|
|
|
// // End call triggers
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Commit or rollback
|
|
|
if ($error) {
|
|
|
foreach ( $this->errors as $errmsg ) {
|
|
@@ -465,7 +471,7 @@ class BookKeeping
|
|
|
return $this->id;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Update object into database
|
|
|
*
|
|
@@ -477,7 +483,7 @@ class BookKeeping
|
|
|
{
|
|
|
global $conf, $langs;
|
|
|
$error = 0;
|
|
|
-
|
|
|
+
|
|
|
// Clean parameters
|
|
|
if (isset($this->doc_type))
|
|
|
$this->doc_type = trim($this->doc_type);
|
|
@@ -509,13 +515,13 @@ class BookKeeping
|
|
|
$this->code_journal = trim($this->code_journal);
|
|
|
if (isset($this->piece_num))
|
|
|
$this->piece_num = trim($this->piece_num);
|
|
|
-
|
|
|
+
|
|
|
// Check parameters
|
|
|
// Put here code to add a control on parameters values
|
|
|
-
|
|
|
+
|
|
|
// Update request
|
|
|
$sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_bookkeeping SET";
|
|
|
-
|
|
|
+
|
|
|
$sql .= " doc_date=" . (dol_strlen($this->doc_date) != 0 ? "'" . $this->db->idate($this->doc_date) . "'" : 'null') . ",";
|
|
|
$sql .= " doc_type=" . (isset($this->doc_type) ? "'" . $this->db->escape($this->doc_type) . "'" : "null") . ",";
|
|
|
$sql .= " doc_ref=" . (isset($this->doc_ref) ? "'" . $this->db->escape($this->doc_ref) . "'" : "null") . ",";
|
|
@@ -532,23 +538,23 @@ class BookKeeping
|
|
|
$sql .= " import_key=" . (isset($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "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 .= " WHERE rowid=" . $this->id;
|
|
|
-
|
|
|
+
|
|
|
$this->db->begin();
|
|
|
-
|
|
|
+
|
|
|
dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG);
|
|
|
$resql = $this->db->query($sql);
|
|
|
if (! $resql) {
|
|
|
$error ++;
|
|
|
$this->errors[] = "Error " . $this->db->lasterror();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (! $error) {
|
|
|
if (! $notrigger) {
|
|
|
// Uncomment this and change MYOBJECT to your own tag if you
|
|
|
// want this action calls a trigger.
|
|
|
-
|
|
|
+
|
|
|
// // Call triggers
|
|
|
// include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
|
|
// $interface=new Interfaces($this->db);
|
|
@@ -557,7 +563,7 @@ class BookKeeping
|
|
|
// // End call triggers
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Commit or rollback
|
|
|
if ($error) {
|
|
|
foreach ( $this->errors as $errmsg ) {
|
|
@@ -571,7 +577,7 @@ class BookKeeping
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Delete object in database
|
|
|
*
|
|
@@ -583,24 +589,24 @@ class BookKeeping
|
|
|
{
|
|
|
global $conf, $langs;
|
|
|
$error = 0;
|
|
|
-
|
|
|
+
|
|
|
$this->db->begin();
|
|
|
-
|
|
|
+
|
|
|
if (! $error)
|
|
|
{
|
|
|
if (! $notrigger)
|
|
|
{
|
|
|
// Call trigger
|
|
|
$result=$this->call_trigger('ACCOUNTING_NUMPIECE_DELETE',$user);
|
|
|
- if ($result < 0) $error++;
|
|
|
+ if ($result < 0) $error++;
|
|
|
// End call triggers
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (! $error) {
|
|
|
$sql = "DELETE FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping";
|
|
|
$sql .= " WHERE rowid=" . $this->id;
|
|
|
-
|
|
|
+
|
|
|
dol_syslog(get_class($this) . "::delete sql=" . $sql);
|
|
|
$resql = $this->db->query($sql);
|
|
|
if (! $resql) {
|
|
@@ -608,7 +614,7 @@ class BookKeeping
|
|
|
$this->errors[] = "Error " . $this->db->lasterror();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Commit or rollback
|
|
|
if ($error) {
|
|
|
foreach ( $this->errors as $errmsg ) {
|
|
@@ -624,9 +630,12 @@ class BookKeeping
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * \brief Delete bookkepping by importkey
|
|
|
+ * Delete bookkepping by importkey
|
|
|
+ *
|
|
|
+ * @param string $model Model
|
|
|
+ * @return int Result
|
|
|
*/
|
|
|
function export_bookkeping($model = 'ebp')
|
|
|
{
|
|
@@ -635,20 +644,20 @@ class BookKeeping
|
|
|
$sql .= " numero_compte, label_compte, debit, credit,";
|
|
|
$sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num";
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping";
|
|
|
-
|
|
|
+
|
|
|
$resql = $this->db->query($sql);
|
|
|
-
|
|
|
+
|
|
|
dol_syslog(get_class($this) . "::export_bookkeping sql=" . $sql, LOG_DEBUG);
|
|
|
$resql = $this->db->query($sql);
|
|
|
if ($resql) {
|
|
|
$this->linesexport = array ();
|
|
|
-
|
|
|
+
|
|
|
$num = $this->db->num_rows($resql);
|
|
|
while ( $obj = $this->db->fetch_object($resql) ) {
|
|
|
$line = new BookKeepingLine();
|
|
|
-
|
|
|
+
|
|
|
$line->id = $obj->rowid;
|
|
|
-
|
|
|
+
|
|
|
$line->doc_date = $this->db->jdate($obj->doc_date);
|
|
|
$line->doc_type = $obj->doc_type;
|
|
|
$line->doc_ref = $obj->doc_ref;
|
|
@@ -663,11 +672,11 @@ class BookKeeping
|
|
|
$line->sens = $obj->sens;
|
|
|
$line->code_journal = $obj->code_journal;
|
|
|
$line->piece_num = $obj->piece_num;
|
|
|
-
|
|
|
+
|
|
|
$this->linesexport[] = $line;
|
|
|
}
|
|
|
$this->db->free($resql);
|
|
|
-
|
|
|
+
|
|
|
return $num;
|
|
|
}
|
|
|
else
|
|
@@ -679,6 +688,9 @@ class BookKeeping
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Class BookKeepingLine
|
|
|
+ */
|
|
|
class BookKeepingLine
|
|
|
{
|
|
|
var $id;
|