';
print '';
-print ' ';
+print ' ';
print ' ';
print '';
-print ' ';
+print ' ';
print ' ';
print '';
-print $form->select_date($search_doc_date,'doc_date',0, 0, 1);
+print $form->select_date($search_doc_date, 'doc_date', 0, 0, 1);
print ' ';
print '';
-print ' ';
+print ' ';
print ' ';
print '';
-print ' ';
+print ' ';
print ' ';
print '';
-print ' ';
+print ' ';
print ' ';
print '';
-print ' ';
+print ' ';
print ' ';
print '';
@@ -250,11 +250,11 @@ print ' ';
print ' ';
print '';
-print ' ';
+print ' ';
print ' ';
print '';
-print ' ';
+print ' ';
print ' ';
print '';
diff --git a/htdocs/accountancy/class/accountancysystem.class.php b/htdocs/accountancy/class/accountancysystem.class.php
index 86c2e5ed3f2..8a6e1d239d8 100644
--- a/htdocs/accountancy/class/accountancysystem.class.php
+++ b/htdocs/accountancy/class/accountancysystem.class.php
@@ -18,9 +18,9 @@
*/
/**
- * \file htdocs/accountancy/class/accountancysystem.class.php
- * \ingroup Accounting Expert
- * \brief File of class to manage accountancy systems
+ * \file htdocs/accountancy/class/accountancysystem.class.php
+ * \ingroup Accounting Expert
+ * \brief File of class to manage accountancy systems
*/
/**
@@ -37,7 +37,7 @@ class AccountancySystem
var $label;
var $account_number;
var $account_parent;
-
+
/**
* Constructor
*
@@ -46,7 +46,7 @@ class AccountancySystem
function __construct($db) {
$this->db = $db;
}
-
+
/**
* Insert accountancy system name into database
*
@@ -55,16 +55,16 @@ class AccountancySystem
*/
function create($user) {
$now = dol_now();
-
+
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_system";
$sql .= " (date_creation, fk_user_author, numero, label)";
$sql .= " VALUES (" . $this->db->idate($now) . "," . $user->id . ",'" . $this->numero . "','" . $this->label . "')";
-
+
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_system");
-
+
if ($id > 0) {
$this->rowid = $id;
$result = $this->rowid;
@@ -78,7 +78,7 @@ class AccountancySystem
$this->error = "AccountancySystem::Create Erreur $result";
dol_syslog($this->error, LOG_ERR);
}
-
+
return $result;
}
}
\ No newline at end of file
diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php
index 856306c3304..df45f027259 100644
--- a/htdocs/accountancy/class/accountingaccount.class.php
+++ b/htdocs/accountancy/class/accountingaccount.class.php
@@ -20,9 +20,9 @@
*/
/**
- * \file htdocs/accountancy/class/accountingaccount.class.php
- * \ingroup Accounting Expert
- * \brief Fichier de la classe des comptes comptable
+ * \file htdocs/accountancy/class/accountingaccount.class.php
+ * \ingroup Accounting Expert
+ * \brief Fichier de la classe des comptes comptable
*/
/**
@@ -33,10 +33,8 @@ class AccountingAccount extends CommonObject
var $db;
var $error;
var $errors;
-
var $id;
var $rowid;
-
var $datec; // Creation date
var $fk_pcg_version;
var $pcg_type;
@@ -47,45 +45,43 @@ class AccountingAccount extends CommonObject
var $fk_user_author;
var $fk_user_modif;
var $active;
-
+
/**
* Constructor
*
- * @param DoliDB $db Database handle
+ * @param DoliDB $db Database handle
*/
- function __construct($db)
- {
+ function __construct($db) {
$this->db = $db;
}
-
+
/**
* Load record in memory
*
- * @param int $rowid Id
- * @param string $account_number Account number
- * @param int $limittocurentchart 1=Do not load record if it is into another accounting system
- * @return int <0 if KO, >0 if OK
+ * @param int $rowid Id
+ * @param string $account_number Account number
+ * @param int $limittocurentchart 1=Do not load record if it is into another accounting system
+ * @return int <0 if KO, >0 if OK
*/
- function fetch($rowid = null, $account_number = null, $limittocurentchart=0)
- {
+ function fetch($rowid = null, $account_number = null, $limittocurentchart = 0) {
global $conf;
-
+
if ($rowid || $account_number) {
$sql = "SELECT rowid, datec, tms, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, fk_user_author, fk_user_modif, active";
- $sql.= " FROM " . MAIN_DB_PREFIX . "accounting_account WHERE";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account WHERE";
if ($rowid) {
$sql .= " rowid = '" . $rowid . "'";
} elseif ($account_number) {
$sql .= " account_number = '" . $account_number . "'";
}
- if (!empty($limittocurentchart)) {
- $sql .=' AND fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.'accounting_system WHERE rowid='.$conf->global->CHARTOFACCOUNTS.')';
+ if (! empty($limittocurentchart)) {
+ $sql .= ' AND fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS . ')';
}
dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result) {
$obj = $this->db->fetch_object($result);
-
+
if ($obj) {
$this->id = $obj->rowid;
$this->rowid = $obj->rowid;
@@ -100,32 +96,31 @@ class AccountingAccount extends CommonObject
$this->fk_user_author = $obj->fk_user_author;
$this->fk_user_modif = $obj->fk_user_modif;
$this->active = $obj->active;
-
+
return $this->id;
} else {
return 0;
}
} else {
- $this->error="Error " . $this->db->lasterror();
+ $this->error = "Error " . $this->db->lasterror();
$this->errors[] = "Error " . $this->db->lasterror();
}
}
- return -1;
+ return - 1;
}
-
+
/**
* Insert line in accounting_account
*
- * @param User $user Use making action
- * @param int $notrigger Disable triggers
- * @return int <0 if KO, >0 if OK
+ * @param User $user Use making action
+ * @param int $notrigger Disable triggers
+ * @return int <0 if KO, >0 if OK
*/
- function create($user, $notrigger = 0)
- {
+ function create($user, $notrigger = 0) {
global $conf;
$error = 0;
$now = dol_now();
-
+
// Clean parameters
if (isset($this->fk_pcg_version))
$this->fk_pcg_version = trim($this->fk_pcg_version);
@@ -143,13 +138,13 @@ class AccountingAccount extends CommonObject
$this->fk_user_author = trim($this->fk_user_author);
if (isset($this->active))
$this->active = trim($this->active);
-
- // Check parameters
- // Put here code to add control on parameters values
-
+
+ // Check parameters
+ // Put here code to add control on parameters values
+
// Insert request
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_account(";
-
+
$sql .= "datec";
$sql .= ", entity";
$sql .= ", fk_pcg_version";
@@ -160,9 +155,9 @@ class AccountingAccount extends CommonObject
$sql .= ", label";
$sql .= ", fk_user_author";
$sql .= ", active";
-
+
$sql .= ") VALUES (";
-
+
$sql .= " '" . $this->db->idate($now) . "'";
$sql .= ", " . $conf->entity;
$sql .= ", " . (! isset($this->fk_pcg_version) ? 'NULL' : "'" . $this->db->escape($this->fk_pcg_version) . "'");
@@ -173,34 +168,34 @@ class AccountingAccount extends CommonObject
$sql .= ", " . (! isset($this->label) ? 'NULL' : "'" . $this->db->escape($this->label) . "'");
$sql .= ", " . $user->id;
$sql .= ", " . (! isset($this->active) ? 'NULL' : "'" . $this->db->escape($this->active) . "'");
-
+
$sql .= ")";
-
+
$this->db->begin();
-
+
dol_syslog(get_class($this) . "::create 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_account");
-
-// 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);
- // $result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
- // if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // // End call triggers
-// }
+
+ // 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);
+ // $result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
+ // if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ // // End call triggers
+ // }
}
-
+
// Commit or rollback
if ($error) {
foreach ( $this->errors as $errmsg ) {
@@ -214,17 +209,16 @@ class AccountingAccount extends CommonObject
return $this->id;
}
}
-
+
/**
* Update record
*
- * @param User $user Use making update
- * @return int <0 if KO, >0 if OK
+ * @param User $user Use making update
+ * @return int <0 if KO, >0 if OK
*/
- function update($user)
- {
+ function update($user) {
$this->db->begin();
-
+
$sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account ";
$sql .= " SET fk_pcg_version = " . ($this->fk_pcg_version ? "'" . $this->db->escape($this->fk_pcg_version) . "'" : "null");
$sql .= " , pcg_type = " . ($this->pcg_type ? "'" . $this->db->escape($this->pcg_type) . "'" : "null");
@@ -234,9 +228,9 @@ class AccountingAccount extends CommonObject
$sql .= " , label = " . ($this->label ? "'" . $this->db->escape($this->label) . "'" : "null");
$sql .= " , fk_user_modif = " . $user->id;
$sql .= " , active = '" . $this->active . "'";
-
+
$sql .= " WHERE rowid = " . $this->id;
-
+
dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result) {
@@ -248,25 +242,24 @@ class AccountingAccount extends CommonObject
return - 1;
}
}
-
+
/**
* Check usage of accounting code
*
- * @return int <0 if KO, >0 if OK
+ * @return int <0 if KO, >0 if OK
*/
- function checkUsage()
- {
+ function checkUsage() {
global $langs;
-
+
$sql = "(SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facturedet";
$sql .= " WHERE fk_code_ventilation=" . $this->id . ")";
$sql .= "UNION";
$sql .= "(SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facture_fourn_det";
$sql .= " WHERE fk_code_ventilation=" . $this->id . ")";
-
+
dol_syslog(get_class($this) . "::checkUsage sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);
-
+
if ($resql) {
$num = $this->db->num_rows($resql);
if ($num > 0) {
@@ -280,42 +273,41 @@ class AccountingAccount extends CommonObject
return - 1;
}
}
-
+
/**
* Delete object in database
*
- * @param User $user User that deletes
- * @param int $notrigger 0=triggers after, 1=disable triggers
- * @return int <0 if KO, >0 if OK
+ * @param User $user User that deletes
+ * @param int $notrigger 0=triggers after, 1=disable triggers
+ * @return int <0 if KO, >0 if OK
*/
- function delete($user, $notrigger = 0)
- {
+ function delete($user, $notrigger = 0) {
$error = 0;
-
+
$result = $this->checkUsage();
-
+
if ($result > 0) {
-
+
$this->db->begin();
-
-// 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);
- // $result=$interface->run_triggers('ACCOUNTANCY_ACCOUNT_DELETE',$this,$user,$langs,$conf);
- // if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // // End call triggers
-// }
-// }
-
+
+ // 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);
+ // $result=$interface->run_triggers('ACCOUNTANCY_ACCOUNT_DELETE',$this,$user,$langs,$conf);
+ // if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ // // End call triggers
+ // }
+ // }
+
if (! $error) {
$sql = "DELETE FROM " . MAIN_DB_PREFIX . "accounting_account";
$sql .= " WHERE rowid=" . $this->id;
-
+
dol_syslog(get_class($this) . "::delete sql=" . $sql);
$resql = $this->db->query($sql);
if (! $resql) {
@@ -323,7 +315,7 @@ class AccountingAccount extends CommonObject
$this->errors[] = "Error " . $this->db->lasterror();
}
}
-
+
// Commit or rollback
if ($error) {
foreach ( $this->errors as $errmsg ) {
@@ -340,47 +332,48 @@ class AccountingAccount extends CommonObject
return - 1;
}
}
-
+
/**
- * Return clicable name (with picto eventually)
+ * Return clicable name (with picto eventually)
*
- * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
- * @return string Chaine avec URL
+ * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
+ * @return string Chaine avec URL
*/
- function getNomUrl($withpicto=0)
- {
+ function getNomUrl($withpicto = 0) {
global $langs;
-
- $result='';
-
- $link = '';
- $linkend=' ';
-
- $picto='billr';
-
- $label=$langs->trans("Show").': '.$this->account_number.' - '.$this->label;
-
- if ($withpicto) $result.=($link.img_object($label,$picto).$linkend);
- if ($withpicto && $withpicto != 2) $result.=' ';
- if ($withpicto != 2) $result.=$link.$this->account_number.$linkend;
+
+ $result = '';
+
+ $link = '';
+ $linkend = ' ';
+
+ $picto = 'billr';
+
+ $label = $langs->trans("Show") . ': ' . $this->account_number . ' - ' . $this->label;
+
+ if ($withpicto)
+ $result .= ($link . img_object($label, $picto) . $linkend);
+ if ($withpicto && $withpicto != 2)
+ $result .= ' ';
+ if ($withpicto != 2)
+ $result .= $link . $this->account_number . $linkend;
return $result;
}
-
+
/**
* Information on record
*
* @param int $id of record
* @return void
*/
- function info($id)
- {
+ function info($id) {
$sql = 'SELECT a.rowid, a.datec, a.fk_user_author, a.fk_user_modif, a.tms';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as a';
$sql .= ' WHERE a.rowid = ' . $id;
-
+
dol_syslog(get_class($this) . '::info sql=' . $sql);
$result = $this->db->query($sql);
-
+
if ($result) {
if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
@@ -403,27 +396,26 @@ class AccountingAccount extends CommonObject
dol_print_error($this->db);
}
}
-
+
/**
* Account desactivate
*
- * @param int $id Id
- * @return int <0 if KO, >0 if OK
+ * @param int $id Id
+ * @return int <0 if KO, >0 if OK
*/
- function account_desactivate($id)
- {
+ function account_desactivate($id) {
$result = $this->checkUsage();
-
+
if ($result > 0) {
$this->db->begin();
-
+
$sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account ";
$sql .= "SET active = '0'";
- $sql .= " WHERE rowid = ".$this->db->escape($id);
-
+ $sql .= " WHERE rowid = " . $this->db->escape($id);
+
dol_syslog(get_class($this) . "::desactivate sql=" . $sql, LOG_DEBUG);
$result = $this->db->query($sql);
-
+
if ($result) {
$this->db->commit();
return 1;
@@ -436,21 +428,20 @@ class AccountingAccount extends CommonObject
return - 1;
}
}
-
+
/**
* Account activate
*
- * @param int $id Id
- * @return int <0 if KO, >0 if OK
+ * @param int $id Id
+ * @return int <0 if KO, >0 if OK
*/
- function account_activate($id)
- {
+ function account_activate($id) {
$this->db->begin();
-
+
$sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account ";
$sql .= "SET active = '1'";
- $sql .= " WHERE rowid = ".$this->db->escape($id);
-
+ $sql .= " WHERE rowid = " . $this->db->escape($id);
+
dol_syslog(get_class($this) . "::activate sql=" . $sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result) {
diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php
index 58c13686d1c..dbca9aeddd9 100644
--- a/htdocs/accountancy/class/bookkeeping.class.php
+++ b/htdocs/accountancy/class/bookkeeping.class.php
@@ -218,7 +218,7 @@ class BookKeeping extends CommonObject
$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_type";
@@ -291,7 +291,6 @@ class BookKeeping extends CommonObject
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
}
-
if (! $error) {
if (! $notrigger) {
@@ -320,19 +319,18 @@ class BookKeeping extends CommonObject
/**
* Create object into database
*
- * @param User $user User that creates
- * @param bool $notrigger false=launch triggers after, true=disable triggers
- *
+ * @param User $user User that creates
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ *
* @return int <0 if KO, Id of created object if OK
*/
- public function createStd(User $user, $notrigger = false)
- {
+ public function createStd(User $user, $notrigger = false) {
dol_syslog(__METHOD__, LOG_DEBUG);
-
+
$error = 0;
-
+
// Clean parameters
-
+
if (isset($this->doc_type)) {
$this->doc_type = trim($this->doc_type);
}
@@ -378,86 +376,82 @@ class BookKeeping extends CommonObject
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 . $this->table_element . '(';
-
- $sql.= 'doc_date,';
- $sql.= 'doc_type,';
- $sql.= 'doc_ref,';
- $sql.= 'fk_doc,';
- $sql.= 'fk_docdet,';
- $sql.= 'code_tiers,';
- $sql.= 'numero_compte,';
- $sql.= 'label_compte,';
- $sql.= 'debit,';
- $sql.= 'credit,';
- $sql.= 'montant,';
- $sql.= 'sens,';
- $sql.= 'fk_user_author,';
- $sql.= 'import_key,';
- $sql.= 'code_journal,';
- $sql.= 'piece_num';
-
-
+
+ $sql .= 'doc_date,';
+ $sql .= 'doc_type,';
+ $sql .= 'doc_ref,';
+ $sql .= 'fk_doc,';
+ $sql .= 'fk_docdet,';
+ $sql .= 'code_tiers,';
+ $sql .= 'numero_compte,';
+ $sql .= 'label_compte,';
+ $sql .= 'debit,';
+ $sql .= 'credit,';
+ $sql .= 'montant,';
+ $sql .= 'sens,';
+ $sql .= 'fk_user_author,';
+ $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)."'").',';
- $sql .= ' '.(empty($this->fk_doc)?'0':$this->fk_doc).',';
- $sql .= ' '.(empty($this->fk_docdet)?'0':$this->fk_docdet).',';
- $sql .= ' '.(! isset($this->code_tiers)?'NULL':"'".$this->db->escape($this->code_tiers)."'").',';
- $sql .= ' '.(! isset($this->numero_compte)?'NULL':"'".$this->db->escape($this->numero_compte)."'").',';
- $sql .= ' '.(! isset($this->label_compte)?'NULL':"'".$this->db->escape($this->label_compte)."'").',';
- $sql .= ' '.(! isset($this->debit)?'NULL':"'".$this->debit."'").',';
- $sql .= ' '.(! isset($this->credit)?'NULL':"'".$this->credit."'").',';
- $sql .= ' '.(! isset($this->montant)?'NULL':"'".$this->montant."'").',';
- $sql .= ' '.(! isset($this->sens)?'NULL':"'".$this->db->escape($this->sens)."'").',';
- $sql .= ' '.$user->id.',';
- $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 .= ' ' . (! 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) . "'") . ',';
+ $sql .= ' ' . (empty($this->fk_doc) ? '0' : $this->fk_doc) . ',';
+ $sql .= ' ' . (empty($this->fk_docdet) ? '0' : $this->fk_docdet) . ',';
+ $sql .= ' ' . (! isset($this->code_tiers) ? 'NULL' : "'" . $this->db->escape($this->code_tiers) . "'") . ',';
+ $sql .= ' ' . (! isset($this->numero_compte) ? 'NULL' : "'" . $this->db->escape($this->numero_compte) . "'") . ',';
+ $sql .= ' ' . (! isset($this->label_compte) ? 'NULL' : "'" . $this->db->escape($this->label_compte) . "'") . ',';
+ $sql .= ' ' . (! isset($this->debit) ? 'NULL' : "'" . $this->debit . "'") . ',';
+ $sql .= ' ' . (! isset($this->credit) ? 'NULL' : "'" . $this->credit . "'") . ',';
+ $sql .= ' ' . (! isset($this->montant) ? 'NULL' : "'" . $this->montant . "'") . ',';
+ $sql .= ' ' . (! isset($this->sens) ? 'NULL' : "'" . $this->db->escape($this->sens) . "'") . ',';
+ $sql .= ' ' . $user->id . ',';
+ $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();
-
+
$resql = $this->db->query($sql);
- if (!$resql) {
+ if (! $resql) {
$error ++;
$this->errors[] = 'Error ' . $this->db->lasterror();
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);
-
- if (!$notrigger) {
+
+ if (! $notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you
// want this action to call a trigger.
-
- //// Call triggers
- //$result=$this->call_trigger('MYOBJECT_CREATE',$user);
- //if ($result < 0) $error++;
- //// End call triggers
+
+ // // Call triggers
+ // $result=$this->call_trigger('MYOBJECT_CREATE',$user);
+ // if ($result < 0) $error++;
+ // // End call triggers
}
}
-
+
// Commit or rollback
if ($error) {
$this->db->rollback();
-
+
return - 1 * $error;
} else {
$this->db->commit();
-
+
return $this->id;
}
}
@@ -581,12 +575,16 @@ class BookKeeping extends CommonObject
$sqlwhere = array ();
if (count($filter) > 0) {
foreach ( $filter as $key => $value ) {
- if ($key=='t.doc_date') {
+ if ($key == 't.doc_date') {
$sqlwhere[] = $key . '=\'' . $this->db->idate($value) . '\'';
- } elseif($key=='t.doc_date>=' || $key=='t.doc_date<=') {
+ } elseif ($key == 't.doc_date>=' || $key == 't.doc_date<=') {
$sqlwhere[] = $key . '\'' . $this->db->idate($value) . '\'';
- } elseif($key=='t.fk_doc' || $key=='t.fk_docdet' ||$key=='t.piece_num') {
+ } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.code_tiers>=' || $key == 't.code_tiers<=') {
+ $sqlwhere[] = $key . '\'' . $this->db->escape($value) . '\'';
+ } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') {
$sqlwhere[] = $key . '=' . $value;
+ } elseif ($key == 't.code_tiers' || $key == 't.numero_compte') {
+ $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\'';
} else {
$sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
}
@@ -815,19 +813,19 @@ class BookKeeping extends CommonObject
/**
* Delete bookkepping by importkey
*
- * @param string $importkey Import key
- * @return int Result
+ * @param string $importkey Import key
+ * @return int Result
*/
function deleteByImportkey($importkey) {
$this->db->begin();
-
+
// first check if line not yet in bookkeeping
$sql = "DELETE";
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
$sql .= " WHERE import_key = '" . $importkey . "'";
-
+
$resql = $this->db->query($sql);
-
+
if (! $resql) {
$this->errors[] = "Error " . $this->db->lasterror();
foreach ( $this->errors as $errmsg ) {
@@ -837,7 +835,7 @@ class BookKeeping extends CommonObject
$this->db->rollback();
return - 1;
}
-
+
$this->db->commit();
return 1;
}
@@ -845,19 +843,19 @@ class BookKeeping extends CommonObject
/**
* Delete bookkepping by year
*
- * @param string $delyear year to delete
- * @return int Result
+ * @param string $delyear year to delete
+ * @return int Result
*/
function deleteByYear($delyear) {
$this->db->begin();
-
+
// first check if line not yet in bookkeeping
$sql = "DELETE";
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
- $sql .= " WHERE YEAR(doc_date) = ".$delyear;
-
+ $sql .= " WHERE YEAR(doc_date) = " . $delyear;
+
$resql = $this->db->query($sql);
-
+
if (! $resql) {
$this->errors[] = "Error " . $this->db->lasterror();
foreach ( $this->errors as $errmsg ) {
@@ -867,7 +865,7 @@ class BookKeeping extends CommonObject
$this->db->rollback();
return - 1;
}
-
+
$this->db->commit();
return 1;
}
@@ -875,19 +873,19 @@ class BookKeeping extends CommonObject
/**
* Delete bookkepping by piece number
*
- * @param int $piecenum peicenum to delete
- * @return int Result
+ * @param int $piecenum peicenum to delete
+ * @return int Result
*/
function deleteMvtNum($piecenum) {
$this->db->begin();
-
+
// first check if line not yet in bookkeeping
$sql = "DELETE";
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
- $sql .= " WHERE piece_num = ".$piecenum;
-
+ $sql .= " WHERE piece_num = " . $piecenum;
+
$resql = $this->db->query($sql);
-
+
if (! $resql) {
$this->errors[] = "Error " . $this->db->lasterror();
foreach ( $this->errors as $errmsg ) {
@@ -897,7 +895,7 @@ class BookKeeping extends CommonObject
$this->db->rollback();
return - 1;
}
-
+
$this->db->commit();
return 1;
}
@@ -997,7 +995,7 @@ class BookKeeping extends CommonObject
$this->doc_type = $obj->doc_type;
} else {
$this->error = "Error " . $this->db->lasterror();
- dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR);
+ dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR);
return - 1;
}
@@ -1069,7 +1067,7 @@ class BookKeeping extends CommonObject
}
} else {
$this->error = "Error " . $this->db->lasterror();
- dol_syslog(get_class($this) . "::fetch_per_mvt " . $this->error, LOG_ERR);
+ dol_syslog(get_class($this) . "::fetch_all_per_mvt " . $this->error, LOG_ERR);
return - 1;
}
@@ -1079,30 +1077,29 @@ class BookKeeping extends CommonObject
/**
* Export bookkeping
*
- * @param string $model Model
- * @return int Result
+ * @param string $model Model
+ * @return int Result
*/
- function export_bookkeping($model = 'ebp')
- {
+ function export_bookkeping($model = 'ebp') {
$sql = "SELECT rowid, doc_date, doc_type,";
$sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,";
$sql .= " numero_compte, label_compte, debit, credit,";
$sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num";
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
-
+
dol_syslog(get_class($this) . "::export_bookkeping", 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;
@@ -1117,15 +1114,13 @@ class BookKeeping extends CommonObject
$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
- {
+ } else {
$this->error = "Error " . $this->db->lasterror();
dol_syslog(get_class($this) . "::export_bookkeping " . $this->error, LOG_ERR);
return - 1;
diff --git a/htdocs/accountancy/class/html.formventilation.class.php b/htdocs/accountancy/class/html.formventilation.class.php
index f2fb6caea48..9ac6f2e0102 100644
--- a/htdocs/accountancy/class/html.formventilation.class.php
+++ b/htdocs/accountancy/class/html.formventilation.class.php
@@ -19,57 +19,57 @@
*/
/**
- * \file htdocs/accountancy/class/html.formventilation.class.php
- * \ingroup Accounting Expert
- * \brief File of class with all html predefined components
+ * \file htdocs/accountancy/class/html.formventilation.class.php
+ * \ingroup Accounting Expert
+ * \brief File of class with all html predefined components
*/
/**
- * Class to manage generation of HTML components for bank module
+ * Class to manage generation of HTML components for bank module
*/
class FormVentilation extends Form
{
var $db;
var $error;
-
+
/**
- * Constructor
- *
- * @param DoliDB $db Database handler
- */
- public function __construct($db) {
- $this->db = $db;
- }
-
- /**
- * Return select filter with date of transaction
+ * Constructor
*
- * @param string $htmlname Name of select field
- * @param string $selectedkey Value
- * @return string HTML edit field
+ * @param DoliDB $db Database handler
+ */
+ public function __construct($db) {
+ $this->db = $db;
+ }
+
+ /**
+ * Return select filter with date of transaction
+ *
+ * @param string $htmlname Name of select field
+ * @param string $selectedkey Value
+ * @return string HTML edit field
*/
function select_bookkeeping_importkey($htmlname = 'importkey', $selectedkey = '') {
- $sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping';
+ $sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping';
$sql .= ' ORDER BY import_key DESC';
-
+
$out = '';
-
+
dol_syslog(get_class($this) . "::select_bookkeeping_importkey sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$i = 0;
$num = $this->db->num_rows($resql);
-
+
while ( $i < $num ) {
$obj = $this->db->fetch_object($resql);
-
+
$selected = '';
if ($selectedkey == $obj->import_key) {
$selected = ' selected ';
}
-
- $out .= '' . dol_print_date($obj->import_key,'dayhourtext') . ' ';
-
+
+ $out .= '' . dol_print_date($obj->import_key, 'dayhourtext') . ' ';
+
$i ++;
}
} else {
@@ -77,48 +77,48 @@ class FormVentilation extends Form
dol_syslog(get_class($this) . "::select_bookkeeping_importkey " . $this->error, LOG_ERR);
return - 1;
}
-
+
$out .= ' ';
-
+
return $out;
}
-
+
/**
- * Return list of accounts with label by chart of accounts
+ * Return list of accounts with label by chart of accounts
*
- * @param string $selectid Preselected chart of accounts
- * @param string $htmlname Name of field in html form
- * @param int $showempty Add an empty field
- * @param array $event Event options
- * @param int $select_in $selectid value is a aa.rowid (0 default) or aa.account_number (1)
- * @param int $select_out set value returned by select 0=rowid (default), 1=account_number
+ * @param string $selectid Preselected chart of accounts
+ * @param string $htmlname Name of field in html form
+ * @param int $showempty Add an empty field
+ * @param array $event Event options
+ * @param int $select_in $selectid value is a aa.rowid (0 default) or aa.account_number (1)
+ * @param int $select_out set value returned by select 0=rowid (default), 1=account_number
* @param int $aabase set accountingaccount base class to display empty=all or from 1 to 8 will display only account beginning by
- *
- * @return string String with HTML select
+ *
+ * @return string String with HTML select
*/
function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase = '') {
global $conf;
-
+
$out = '';
-
+
$sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version";
$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 .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
$sql .= " AND aa.active = 1";
$sql .= " ORDER BY aa.account_number";
-
+
dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
-
+
$out .= ajax_combobox($htmlname, $event);
$out .= '';
if ($showempty)
$out .= ' ';
$num = $this->db->num_rows($resql);
- $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT') ? $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT : '50';
-
+ $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT') ? $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT : '50';
+
$i = 0;
if ($num) {
while ( $i < $num ) {
@@ -133,8 +133,8 @@ class FormVentilation extends Form
$select_value_out = $obj->rowid;
if ($select_out == 1)
$select_value_out = $obj->account_number;
- // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number
- // Because same account_number can be share between different accounting_system and do have the same meaning
+ // Remember guy's we store in database llx_facturedet the rowid of accountingaccount and not the account_number
+ // Because same account_number can be share between different accounting_system and do have the same meaning
if (($selectid != '') && $selectid == $select_value_in) {
// $out .= '' . $label . ' ';
$out .= '' . $label . ' ';
@@ -154,34 +154,34 @@ class FormVentilation extends Form
$this->db->free($resql);
return $out;
}
-
+
/**
- * Return list of accounts with label by class of accounts
+ * Return list of accounts with label by class of accounts
*
- * @param string $selectid Preselected pcg_type
- * @param string $htmlname Name of field in html form
- * @param int $showempty Add an empty field
- * @param array $event Event options
- *
- * @return string String with HTML select
+ * @param string $selectid Preselected pcg_type
+ * @param string $htmlname Name of field in html form
+ * @param int $showempty Add an empty field
+ * @param array $event Event options
+ *
+ * @return string String with HTML select
*/
function select_pcgtype($selectid, $htmlname = 'pcg_type', $showempty = 0, $event = array()) {
global $conf;
-
+
$out = '';
-
+
$sql = "SELECT DISTINCT pcg_type ";
$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 .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
$sql .= " ORDER BY pcg_type";
-
+
dol_syslog(get_class($this) . "::select_pcgtype sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
-
+
$out .= ajax_combobox($htmlname, $event);
-
+
$out .= '';
if ($showempty)
$out .= ' ';
@@ -191,7 +191,7 @@ class FormVentilation extends Form
while ( $i < $num ) {
$obj = $this->db->fetch_object($resql);
$label = $obj->pcg_type;
-
+
if (($selectid != '') && $selectid == $obj->pcg_type) {
$out .= '' . $label . ' ';
} else {
@@ -209,34 +209,34 @@ class FormVentilation extends Form
$this->db->free($resql);
return $out;
}
-
+
/**
- * Return list of accounts with label by sub_class of accounts
+ * Return list of accounts with label by sub_class of accounts
*
- * @param string $selectid Preselected pcg_type
- * @param string $htmlname Name of field in html form
- * @param int $showempty Add an empty field
- * @param array $event Event options
- *
- * @return string String with HTML select
+ * @param string $selectid Preselected pcg_type
+ * @param string $htmlname Name of field in html form
+ * @param int $showempty Add an empty field
+ * @param array $event Event options
+ *
+ * @return string String with HTML select
*/
function select_pcgsubtype($selectid, $htmlname = 'pcg_subtype', $showempty = 0, $event = array()) {
global $conf;
-
+
$out = '';
-
+
$sql = "SELECT DISTINCT pcg_subtype ";
$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 .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
$sql .= " ORDER BY pcg_subtype";
-
+
dol_syslog(get_class($this) . "::select_pcgsubtype sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
-
+
$out .= ajax_combobox($htmlname, $event);
-
+
$out .= '';
if ($showempty)
$out .= ' ';
@@ -246,7 +246,7 @@ class FormVentilation extends Form
while ( $i < $num ) {
$obj = $this->db->fetch_object($resql);
$label = $obj->pcg_subtype;
-
+
if (($selectid != '') && $selectid == $obj->pcg_subtype) {
$out .= '' . $label . ' ';
} else {
@@ -320,8 +320,7 @@ class FormVentilation extends Form
}
$this->db->free($resql);
-
- //Build select
+ // Build select
if (count($aux_account) > 0) {
$out .= ajax_combobox($htmlname, $event);
@@ -354,7 +353,7 @@ class FormVentilation extends Form
function selectyear_accountancy_bookkepping($selected = '', $htmlname = 'yearid', $useempty = 0, $output_format = 'html') {
$out = '';
$out_array = array ();
-
+
if ($output_format == 'html') {
$out .= '';
}
@@ -369,34 +368,34 @@ class FormVentilation extends Form
$out_array[''] = '';
}
}
-
+
$sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping";
$sql .= " ORDER BY doc_date";
- dol_syslog(get_class($this) . "::".__METHOD__, LOG_DEBUG);
+ dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
while ( $obj = $this->db->fetch_object($resql) ) {
$selected_html = '';
if ($selected > 0 && $obj->dtyear == $selected)
$selected_html = ' selected';
- if ($output_format == 'html' || $output_format == 'options') {
- $out .= '' . $obj->dtyear . ' ';
- } elseif ($output_format == 'array') {
- $out_array[$obj->dtyear] = $obj->dtyear;
- }
+ if ($output_format == 'html' || $output_format == 'options') {
+ $out .= '' . $obj->dtyear . ' ';
+ } elseif ($output_format == 'array') {
+ $out_array[$obj->dtyear] = $obj->dtyear;
+ }
}
} else {
$this->error = "Error " . $this->db->lasterror();
- dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR);
+ dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR);
return - 1;
}
$this->db->free($resql);
-
+
if ($output_format == 'html') {
$out .= " \n";
}
-
+
if ($output_format == 'html' || $output_format == 'options') {
return $out;
} elseif ($output_format == 'array') {
diff --git a/htdocs/accountancy/customer/card.php b/htdocs/accountancy/customer/card.php
index 964e39efebf..c49dd7ce78a 100644
--- a/htdocs/accountancy/customer/card.php
+++ b/htdocs/accountancy/customer/card.php
@@ -18,16 +18,15 @@
*/
/**
- * \file htdocs/accountancy/customer/card.php
- * \ingroup Accountancy
- * \brief Card customer ventilation
+ * \file htdocs/accountancy/customer/card.php
+ * \ingroup Accountancy
+ * \brief Card customer ventilation
*/
-
require '../../main.inc.php';
// Class
-require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
-require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
+require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
// Langs
$langs->load("bills");
@@ -40,17 +39,16 @@ $id = GETPOST('id');
// Security check
if ($user->societe_id > 0)
accessforbidden();
-
-/*
+
+ /*
* Actions
*/
if ($action == 'ventil' && $user->rights->accounting->ventilation->dispatch) {
- if (! GETPOST('cancel', 'alpha'))
- {
+ if (! GETPOST('cancel', 'alpha')) {
$sql = " UPDATE " . MAIN_DB_PREFIX . "facturedet";
$sql .= " SET fk_code_ventilation = " . $codeventil;
$sql .= " WHERE rowid = " . $id;
-
+
dol_syslog("/accounting/customer/card.php sql=" . $sql, LOG_DEBUG);
$resql = $db->query($sql);
if (! $resql) {
@@ -91,35 +89,35 @@ if (! empty($id)) {
if (! empty($conf->multicompany->enabled)) {
$sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")";
}
-
+
dol_syslog("/accounting/customer/card.php sql=" . $sql, LOG_DEBUG);
$result = $db->query($sql);
-
+
if ($result) {
$num_lines = $db->num_rows($result);
$i = 0;
-
+
if ($num_lines) {
-
+
$objp = $db->fetch_object($result);
-
+
print '';
} else {
print "Error";
diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php
index 0b8b842bb99..06446fdc908 100644
--- a/htdocs/accountancy/customer/index.php
+++ b/htdocs/accountancy/customer/index.php
@@ -21,16 +21,15 @@
*/
/**
- * \file htdocs/accountancy/customer/index.php
- * \ingroup Accounting Expert
- * \brief Home customer ventilation
+ * \file htdocs/accountancy/customer/index.php
+ * \ingroup Accounting Expert
+ * \brief Home customer ventilation
*/
-
require '../../main.inc.php';
// Class
-require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
// Langs
$langs->load("compta");
@@ -44,8 +43,8 @@ if ($user->societe_id > 0)
accessforbidden();
if (! $user->rights->accounting->ventilation->read)
accessforbidden();
-
-// Filter
+
+ // Filter
$year = $_GET["year"];
if ($year == 0) {
$year_current = strftime("%Y", time());
@@ -58,10 +57,10 @@ if ($year == 0) {
// Validate History
$action = GETPOST('action');
if ($action == 'validatehistory') {
-
+
$error = 0;
$db->begin();
-
+
if ($db->type == 'pgsql') {
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd";
$sql1 .= " SET fd.fk_code_ventilation = accnt.rowid";
@@ -78,7 +77,7 @@ if ($action == 'validatehistory') {
}
dol_syslog("htdocs/accountancy/customer/index.php sql=" . $sql, LOG_DEBUG);
-
+
$resql1 = $db->query($sql1);
if (! $resql1) {
$error ++;
@@ -88,6 +87,50 @@ if ($action == 'validatehistory') {
$db->commit();
setEventMessages($langs->trans('Dispatched'), null, 'mesgs');
}
+} elseif ($action == 'fixaccountancycode') {
+ $error = 0;
+ $db->begin();
+
+ $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd";
+ $sql1 .= " SET fd.fk_code_ventilation = 0";
+ $sql1 .= ' WHERE fd.fk_code_ventilation NOT IN ';
+ $sql1 .= ' (SELECT accnt.rowid ';
+ $sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accountingaccount as accnt';
+ $sql1 .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst';
+ $sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')';
+
+ dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
+
+ $resql1 = $db->query($sql1);
+ if (! $resql1) {
+ $error ++;
+ $db->rollback();
+ setEventMessage($db->lasterror(), 'errors');
+ } else {
+ $db->commit();
+ setEventMessage($langs->trans('Done'), 'mesgs');
+ }
+} elseif ($action == 'cleanaccountancycode') {
+ $error = 0;
+ $db->begin();
+
+ $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd";
+ $sql1 .= " SET fd.fk_code_ventilation = 0";
+ $sql1 .= " WHERE fd.fk_facture IN ( SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture as f";
+ $sql1 .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($year_current, 1, false)) . "'";
+ $sql1 .= " AND f.datef <= '" . $db->idate(dol_get_last_day($year_current, 12, false)) . "')";
+
+ dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
+
+ $resql1 = $db->query($sql1);
+ if (! $resql1) {
+ $error ++;
+ $db->rollback();
+ setEventMessage($db->lasterror(), 'errors');
+ } else {
+ $db->commit();
+ setEventMessage($langs->trans('Done'), 'mesgs');
+ }
}
/*
@@ -101,7 +144,11 @@ $textnextyear = ' trans("CustomersVentilation") . " " . $textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear);
print '' . $langs->trans("DescVentilCustomer") . ' ';
-print '';
+print '';
$sql = "SELECT count(*) FROM " . MAIN_DB_PREFIX . "facturedet as fd";
$sql .= " , " . MAIN_DB_PREFIX . "facture as f";
@@ -169,11 +216,11 @@ $resql = $db->query($sql);
if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
-
+
while ( $i < $num ) {
$row = $db->fetch_row($resql);
- $var=!$var;
- print '' . length_accountg($row[0]) . ' ';
+ $var = ! $var;
+ print '' . length_accountg($row[0]) . ' ';
print '' . $row[1] . ' ';
print '' . price($row[2]) . ' ';
print '' . price($row[3]) . ' ';
@@ -242,10 +289,10 @@ $resql = $db->query($sql);
if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
-
+
while ( $i < $num ) {
$row = $db->fetch_row($resql);
-
+
print '' . $row[0] . ' ';
print '' . price($row[1]) . ' ';
print '' . price($row[2]) . ' ';
@@ -286,7 +333,7 @@ if (! empty($conf->margin->enabled)) {
print '' . $langs->trans("NovemberMin") . ' ';
print '' . $langs->trans("DecemberMin") . ' ';
print '' . $langs->trans("Total") . ' ';
-
+
$sql = "SELECT '" . $langs->trans("Vide") . "' AS 'Marge',";
$sql .= " ROUND(SUM(IF(MONTH(f.datef)=1,(fd.total_ht-(fd.qty * fd.buy_price_ht)),0)),2) AS 'Janvier',";
$sql .= " ROUND(SUM(IF(MONTH(f.datef)=2,(fd.total_ht-(fd.qty * fd.buy_price_ht)),0)),2) AS 'Fevrier',";
@@ -305,7 +352,7 @@ if (! empty($conf->margin->enabled)) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture";
$sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'";
$sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'";
-
+
if (! empty($conf->multicompany->enabled)) {
$sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")";
}
@@ -315,10 +362,10 @@ if (! empty($conf->margin->enabled)) {
if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
-
+
while ( $i < $num ) {
$row = $db->fetch_row($resql);
-
+
print '' . $row[0] . ' ';
print '' . price($row[1]) . ' ';
print '' . price($row[2]) . ' ';
@@ -346,4 +393,4 @@ print "