diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php
index 28b7b177860..9be65e7261a 100644
--- a/htdocs/accountancy/bookkeeping/card.php
+++ b/htdocs/accountancy/bookkeeping/card.php
@@ -37,7 +37,7 @@ $id = GETPOST('id', 'int');
if ($user->societe_id > 0) {
accessforbidden();
}
-$action = GETPOST('action');
+$action = GETPOST('action','aZ09');
$mode = GETPOST('mode');
$piece_num = GETPOST("piece_num");
diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php
index db75947771e..7668756a046 100644
--- a/htdocs/accountancy/class/accountancycategory.class.php
+++ b/htdocs/accountancy/class/accountancycategory.class.php
@@ -429,4 +429,158 @@ class AccountancyCategory
return - 1;
}
}
+
+ public function getCats() {
+ global $db, $langs, $user, $mysoc;
+
+ if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
+ dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
+ exit();
+ }
+
+ if (! empty($mysoc->country_id)) {
+ $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c";
+ $sql .= " WHERE c.active = 1 ";
+ $sql .= " AND c.fk_country = " . $mysoc->country_id;
+ $sql .= " ORDER BY c.position ASC";
+ } else {
+ $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c, " . MAIN_DB_PREFIX . "c_country as co";
+ $sql .= " WHERE c.active = 1 AND c.fk_country = co.rowid";
+ $sql .= " AND co.code = '" . $mysoc->country_code . "'";
+ $sql .= " ORDER BY c.position ASC";
+ }
+
+ dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $i = 0;
+ $obj = '';
+ $num = $this->db->num_rows($resql);
+ $data = array ();
+ if ($num) {
+ while ( $i < $num ) {
+ $obj = $this->db->fetch_object($resql);
+
+ $data[] = array (
+ 'rowid' => $obj->rowid,
+ 'code' => $obj->code,
+ 'position' => $obj->position,
+ 'label' => $obj->label,
+ 'formula' => $obj->formula,
+ 'category_type' => $obj->category_type
+ );
+ $i ++;
+ }
+ }
+ return $data;
+ } else {
+ $this->error = "Error " . $this->db->lasterror();
+ $this->errors[] = $this->error;
+ dol_syslog(__METHOD__ . " " . implode(',', $this->errors), LOG_ERR);
+
+ return - 1;
+ }
+ }
+
+
+ // calcule
+
+ const PATTERN = '/(?:\-?\d+(?:\.?\d+)?[\+\-\*\/])+\-?\d+(?:\.?\d+)?/';
+
+ const PARENTHESIS_DEPTH = 10;
+
+ public function calculate($input){
+ if(strpos($input, '+') != null || strpos($input, '-') != null || strpos($input, '/') != null || strpos($input, '*') != null){
+ // Remove white spaces and invalid math chars
+ $input = str_replace(',', '.', $input);
+ $input = preg_replace('[^0-9\.\+\-\*\/\(\)]', '', $input);
+
+ // Calculate each of the parenthesis from the top
+ $i = 0;
+ while(strpos($input, '(') || strpos($input, ')')){
+ $input = preg_replace_callback('/\(([^\(\)]+)\)/', 'self::callback', $input);
+
+ $i++;
+ if($i > self::PARENTHESIS_DEPTH){
+ break;
+ }
+ }
+
+ // Calculate the result
+ if(preg_match(self::PATTERN, $input, $match)){
+ return $this->compute($match[0]);
+ }
+
+ return 0;
+ }
+
+ return $input;
+ }
+
+ private function compute($input){
+ $compute = create_function('', 'return '.$input.';');
+
+ return 0 + $compute();
+ }
+
+ private function callback($input){
+ if(is_numeric($input[1])){
+ return $input[1];
+ }
+ elseif(preg_match(self::PATTERN, $input[1], $match)){
+ return $this->compute($match[0]);
+ }
+
+ return 0;
+ }
+
+ /**
+ * get cpts of category
+ *
+ * @return array Result in table
+ */
+ public function getCptsCat($cat_id) {
+ global $mysoc;
+ $sql = "";
+
+ if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
+ dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
+ exit();
+ }
+
+ $sql = "SELECT t.rowid, t.account_number, t.label as name_cpt";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t";
+ $sql .= " WHERE t.fk_accounting_category = ".$cat_id;
+ $sql .= " ORDER BY t.account_number ";
+
+ //echo $sql;
+
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $i = 0;
+ $obj = '';
+ $num = $this->db->num_rows($resql);
+ $data = array ();
+ if ($num) {
+ while ( $obj = $this->db->fetch_object($resql) ) {
+ $name_cat = $obj->name_cat;
+ $data[] = array (
+ 'id' => $obj->rowid,
+ 'account_number' => $obj->account_number,
+ 'name_cpt' => $obj->name_cpt,
+ );
+ $i ++;
+ }
+ }
+ return $data;
+ } else {
+ $this->error = "Error " . $this->db->lasterror();
+ dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR);
+
+ return -1;
+ }
+ }
+
}
diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php
index 843e15a5dd7..51ef317e917 100644
--- a/htdocs/accountancy/class/bookkeeping.class.php
+++ b/htdocs/accountancy/class/bookkeeping.class.php
@@ -270,7 +270,7 @@ class BookKeeping extends CommonObject
$sql .= ", montant";
$sql .= ", sens";
$sql .= ", fk_user_author";
- $sql .= ", import_key";
+ $sql .= ", date_creation";
$sql .= ", code_journal";
$sql .= ", journal_label";
$sql .= ", piece_num";
@@ -430,6 +430,11 @@ class BookKeeping extends CommonObject
if (empty($this->debit)) $this->debit = 0;
if (empty($this->credit)) $this->credit = 0;
+ $now = dol_now();
+ if (empty($this->date_create)) {
+ $this->date_create = $now;
+ }
+
// Check parameters
// Put here code to add control on parameters values
@@ -451,7 +456,7 @@ class BookKeeping extends CommonObject
$sql .= 'montant,';
$sql .= 'sens,';
$sql .= 'fk_user_author,';
- $sql .= 'import_key,';
+ $sql .= 'date_creation,';
$sql .= 'code_journal,';
$sql .= 'journal_label,';
$sql .= 'piece_num,';
@@ -473,7 +478,7 @@ class BookKeeping extends CommonObject
$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 .= ' ' . "'" . $this->db->idate($this->date_create) . "',";
$sql .= ' ' . (empty($this->code_journal) ? 'NULL' : "'" . $this->db->escape($this->code_journal) . "'") . ',';
$sql .= ' ' . (empty($this->journal_label) ? 'NULL' : "'" . $this->db->escape($this->journal_label) . "'") . ',';
$sql .= ' ' . (empty($this->piece_num) ? 'NULL' : $this->db->escape($this->piece_num)).',';
diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php
index bc27ebfa24f..ed8d1d7501a 100644
--- a/htdocs/accountancy/journal/bankjournal.php
+++ b/htdocs/accountancy/journal/bankjournal.php
@@ -72,10 +72,10 @@ $date_startyear = GETPOST('date_startyear');
$date_endmonth = GETPOST('date_endmonth');
$date_endday = GETPOST('date_endday');
$date_endyear = GETPOST('date_endyear');
-$action = GETPOST('action','aZ09');
+$in_bookkeeping = GETPOST('in_bookkeeping');
$now = dol_now();
-$action = GETPOST('action','aZ09');
+$action = GETPOST('action','alpha');
// Security check
if ($user->societe_id > 0 && empty($id_journal))
@@ -121,6 +121,8 @@ $sql .= " WHERE ba.fk_accountancy_journal=" . $id_journal;
$sql .= ' AND ba.entity IN ('.getEntity('bank_account', 0).')'; // We don't share object for accountancy
if ($date_start && $date_end)
$sql .= " AND b.dateo >= '" . $db->idate($date_start) . "' AND b.dateo <= '" . $db->idate($date_end) . "'";
+if ($in_bookkeeping == 'yes')
+ $sql .= " AND (b.rowid NOT IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
$sql .= " ORDER BY b.datev";
$object = new Account($db);
@@ -366,6 +368,7 @@ if (! $error && $action == 'writebookkeeping') {
$bookkeeping->fk_docdet = $val["fk_bank"];
$bookkeeping->numero_compte = $k;
$bookkeeping->label_operation = $val["label"];
+ $bookkeeping->label_compte = $langs->trans("Bank");
$bookkeeping->montant = ($mt < 0 ? - $mt : $mt);
$bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
$bookkeeping->debit = ($mt >= 0 ? $mt : 0);
@@ -473,6 +476,18 @@ if (! $error && $action == 'writebookkeeping') {
$bookkeeping->date_create = $now;
if (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution
+ $sqlmid = 'SELECT ch.libelle, t.libelle as labelc';
+ $sqlmid .= " FROM " . MAIN_DB_PREFIX . "chargesociales ch ";
+ $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paych ON paych.fk_charge=ch.rowid";
+ $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "c_chargesociales as t ON ch.fk_type=t.id";
+ $sqlmid .= " WHERE paych.fk_bank=" . $key;
+ dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
+ $resultmid = $db->query($sqlmid);
+ if ($resultmid) {
+ $objmid = $db->fetch_object($resultmid);
+ $bookkeeping->label_compte = $objmid->labelc;
+ $bookkeeping->doc_ref = $objmid->libelle ;
+ }
$bookkeeping->subledger_account = '';
$bookkeeping->numero_compte = $k;
} else if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice
@@ -597,7 +612,6 @@ if (! $error && $action == 'writebookkeeping') {
}
// Export
-/*
if ($action == 'export_csv') {
$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
@@ -606,165 +620,101 @@ if ($action == 'export_csv') {
$companystatic = new Client($db);
$userstatic = new User($db);
- // Model Cegid Expert Export
- if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2)
- {
- $sep = ";";
+ // Bank
+ foreach ( $tabpay as $key => $val ) {
+ $date = dol_print_date($db->jdate($val["date"]), 'day');
- foreach ( $tabpay as $key => $val ) {
- $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
-
- $reflabel = $val["ref"];
- if ($reflabel == '(SupplierInvoicePayment)') {
- $reflabel = $langs->trans('Supplier');
- }
- if ($reflabel == '(CustomerInvoicePayment)') {
- $reflabel = $langs->trans('Customer');
- }
- if ($reflabel == '(SocialContributionPayment)') {
- $reflabel = $langs->trans('SocialContribution');
- }
- if ($reflabel == '(DonationPayment)') {
- $reflabel = $langs->trans('Donation');
- }
- if ($reflabel == '(SubscriptionPayment)') {
- $reflabel = $langs->trans('Subscription');
- }
- if ($reflabel == '(ExpenseReportPayment)') {
- $reflabel = $langs->trans('Employee');
- }
-
- $companystatic->id = $tabcompany[$key]['id'];
- $companystatic->name = $tabcompany[$key]['name'];
-
- $userstatic->id = $tabuser[$key]['id'];
- $userstatic->lastname = $tabuser[$key]['lastname'];
- $userstatic->firstname = $tabuser[$key]['firstname'];
-
- // Bank
- foreach ( $tabbq[$key] as $k => $mt ) {
- print $date . $sep;
- print $journal . $sep;
- print length_accountg(html_entity_decode($k)) . $sep;
- print $sep;
- print ($mt < 0 ? 'C' : 'D') . $sep;
- print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
- if ($companystatic->name == '') {
- print $langs->trans('Bank')." - ". utf8_decode($val["ref"]) . $sep;
- } else {
- print $langs->trans("Bank") .' - '.utf8_decode($companystatic->name) . $sep;
- }
- print utf8_decode($reflabel) . $sep;
- print "\n";
- }
-
- // Third party
- if (is_array($tabtp[$key])) {
- foreach ( $tabtp[$key] as $k => $mt ) {
- if ($mt) {
- print $date . $sep;
- print $journal . $sep;
- if ($tabtype[$key] == 'payment') {
- print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep;
- print length_accounta(html_entity_decode($k)) . $sep;
- } else if ($tabtype[$key] == 'payment_supplier') {
- print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep;
- print length_accounta(html_entity_decode($k)) . $sep;
- } else {
- print length_accountg(html_entity_decode($k)) . $sep;
- print $sep;
- }
- print ($mt < 0 ? 'D' : 'C') . $sep;
- print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
- if ($companystatic->name == '') {
- print $langs->trans('ThirdParty')." - ". utf8_decode($val["ref"]) . $sep;
- } else {
- print $langs->trans('ThirdParty')." - ". utf8_decode($companystatic->name) . $sep;
- }
- print utf8_decode($reflabel) . $sep;
- print "\n";
- }
- }
- } else {
- foreach ( $tabbq[$key] as $k => $mt ) {
- print $date . $sep;
- print $journal . $sep;
- print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . $sep;
- print $sep;
- print ($mt < 0 ? 'D' : 'C') . $sep;
- print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
- if ($companystatic->name == '') {
- print $langs->trans('ThirdParty')." - ". utf8_decode($val["ref"]) . $sep;
- } else {
- print $langs->trans('ThirdParty')." - ". utf8_decode($companystatic->name) . $sep;
- }
- print utf8_decode($reflabel) . $sep;
- print "\n";
- }
- }
+ $reflabel = $val["ref"];
+ if ($reflabel == '(SupplierInvoicePayment)') {
+ $reflabel = $langs->trans('Supplier');
+ }
+ if ($reflabel == '(CustomerInvoicePayment)') {
+ $reflabel = $langs->trans('Customer');
+ }
+ if ($reflabel == '(SocialContributionPayment)') {
+ $reflabel = $langs->trans('SocialContribution');
+ }
+ if ($reflabel == '(DonationPayment)') {
+ $reflabel = $langs->trans('Donation');
+ }
+ if ($reflabel == '(SubscriptionPayment)') {
+ $reflabel = $langs->trans('Subscription');
+ }
+ if ($reflabel == '(ExpenseReportPayment)') {
+ $reflabel = $langs->trans('Employee');
}
- } else {
- // Model Classic Export
- foreach ( $tabpay as $key => $val ) {
- $date = dol_print_date($db->jdate($val["date"]), 'day');
- $companystatic->id = $tabcompany[$key]['id'];
- $companystatic->name = $tabcompany[$key]['name'];
+ $companystatic->id = $tabcompany[$key]['id'];
+ $companystatic->name = $tabcompany[$key]['name'];
- // Bank
- foreach ( $tabbq[$key] as $k => $mt ) {
- print '"' . $journal . '"' . $sep;
- print '"' . $date . '"' . $sep;
- print '"' . $val["type_payment"] . '"' . $sep;
- print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
- if ($companystatic->name == '') {
- print '"' . $langs->trans('Bank') . " - " . utf8_decode($val["ref"]) . '"' . $sep;
- } else {
- print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep;
- }
- print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
- print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
- print "\n";
- }
-
- // Third party
- if (is_array($tabtp[$key])) {
- foreach ( $tabtp[$key] as $k => $mt ) {
- if ($mt) {
- print '"' . $journal . '"' . $sep;
- print '"' . $date . '"' . $sep;
- print '"' . $val["type_payment"] . '"' . $sep;
- print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
- if ($companystatic->name == '') {
- print '"' . $langs->trans('ThirdParty') . " - " . utf8_decode($val["ref"]) . '"' . $sep;
- } else {
- print '"' . $langs->trans('ThirdParty') . " - " . utf8_decode($companystatic->name) . '"' . $sep;
- }
- print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
- print '"' . ($mt >= 0 ? price($mt) : '') . '"';
- print "\n";
- }
- }
+ // Bank
+ foreach ( $tabbq[$key] as $k => $mt ) {
+ print '"' . $journal . '"' . $sep;
+ print '"' . $date . '"' . $sep;
+ print '"' . $val["type_payment"] . '"' . $sep;
+ print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+ print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+ print " " . $sep;
+ if ($companystatic->name == '') {
+ print '"' . $langs->trans('Bank') . " - " . utf8_decode($reflabel) . '"' . $sep;
} else {
- foreach ( $tabbq[$key] as $k => $mt ) {
+ print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep;
+ }
+ print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
+ print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
+ print "\n";
+ }
+
+ // Third party
+ if (is_array($tabtp[$key])) {
+ foreach ( $tabtp[$key] as $k => $mt ) {
+ if ($mt) {
print '"' . $journal . '"' . $sep;
print '"' . $date . '"' . $sep;
- print '"' . $val["ref"] . '"' . $sep;
- print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep;
- if ($companystatic->name == '') {
- print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($val["ref"]) . '"' . $sep;
+ print '"' . $val["type_payment"] . '"' . $sep;
+ print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
+
+ if ($tabtype[$key] == 'payment_supplier') {
+ print '"' . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . '"' . $sep;
+ } else if($tabtype[$key] == 'payment') {
+ print '"' . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . '"' . $sep;
} else {
- print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep;
+ print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
+ }
+
+
+
+ print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
+ if ($companystatic->name == '') {
+ print '"' . $langs->trans('ThirdParty') . " - " . utf8_decode($reflabel) . '"' . $sep;
+ } else {
+ print '"' . $langs->trans('ThirdParty') . " - " . utf8_decode($companystatic->name) . '"' . $sep;
}
print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
print '"' . ($mt >= 0 ? price($mt) : '') . '"';
print "\n";
}
}
+ } else {
+ foreach ( $tabbq[$key] as $k => $mt ) {
+ print '"' . $journal . '"' . $sep;
+ print '"' . $date . '"' . $sep;
+ print '"' . $val["ref"] . '"' . $sep;
+ print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep;
+ print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep;
+ print " " . $sep;
+ if ($companystatic->name == '') {
+ print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($reflabel) . '"' . $sep;
+ } else {
+ print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep;
+ }
+ print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
+ print '"' . ($mt >= 0 ? price($mt) : '') . '"';
+ print "\n";
+ }
}
}
}
-*/
/*
@@ -788,7 +738,7 @@ if (empty($action) || $action == 'view') {
$builddate = time();
//$description = $langs->trans("DescFinanceJournal") . '
';
$description.= $langs->trans("DescJournalOnlyBindedVisible").'
';
- $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). ' - ' .$langs->trans("AlreadyInGeneralLedger").' '. $form->selectyesno('in_bookkeeping',$in_bookkeeping,0);
$varlink = 'id_journal=' . $id_journal;
@@ -802,6 +752,7 @@ if (empty($action) || $action == 'view') {
print '
';
print '';
+ print '';
print '
';
// TODO Avoid using js. We can use a direct link with $param
@@ -863,6 +814,9 @@ if (empty($action) || $action == 'view') {
if ($reflabel == '(ExpenseReportPayment)') {
$reflabel = $langs->trans('Employee');
}
+ if ($reflabel == '(payment_salary)') {
+ $reflabel = $langs->trans('Employee');
+ }
$ref=$reflabel;
if ($tabtype[$key] == 'payment')
diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php
index cbe793deb63..e023e14a817 100644
--- a/htdocs/accountancy/journal/purchasesjournal.php
+++ b/htdocs/accountancy/journal/purchasesjournal.php
@@ -43,7 +43,7 @@ $langs->load("main");
$langs->load("accountancy");
$id_journal = GETPOST('id_journal', 'int');
-$action = GETPOST('action','aZ09');
+$action = GETPOST('action','alpha');
$date_startmonth = GETPOST('date_startmonth');
$date_startday = GETPOST('date_startday');
@@ -51,6 +51,7 @@ $date_startyear = GETPOST('date_startyear');
$date_endmonth = GETPOST('date_endmonth');
$date_endday = GETPOST('date_endday');
$date_endyear = GETPOST('date_endyear');
+$in_bookkeeping = GETPOST('in_bookkeeping');
$now = dol_now();
@@ -108,6 +109,8 @@ if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
}
if ($date_start && $date_end)
$sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'";
+if ($in_bookkeeping == 'yes')
+ $sql .= " AND (f.rowid NOT IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='supplier_invoice') )";
$sql .= " ORDER BY f.datef";
dol_syslog('accountancy/journal/purchasesjournal.php:: $sql=' . $sql);
@@ -385,69 +388,15 @@ if ($action == 'writebookkeeping') {
$form = new Form($db);
$companystatic = new Fournisseur($db);
+$invoicestatic = new FactureFournisseur($db);
// Export
-/*if ($action == 'export_csv') {
+if ($action == 'export_csv') {
$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
$journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
- // Model Cegid Expert Export
- if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) {
- $sep = ";";
-
- foreach ( $tabfac as $key => $val ) {
- $date = dol_print_date($val["date"], '%d%m%Y');
-
- // Product / Service
- foreach ( $tabht[$key] as $k => $mt ) {
- $companystatic->id = $tabcompany[$key]['id'];
- $companystatic->name = $tabcompany[$key]['name'];
- $companystatic->client = $tabcompany[$key]['code_client'];
-
- if ($mt) {
- print $date . $sep;
- print $purchase_journal . $sep;
- print length_accountg(html_entity_decode($k)) . $sep;
- print $sep;
- print ($mt < 0 ? 'C' : 'D') . $sep;
- print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
- print dol_trunc($val["description"], 32) . $sep;
- print $val["ref"];
- print "\n";
- }
- }
-
- // VAT
- foreach ( $tabtva[$key] as $k => $mt ) {
- if ($mt) {
- print $date . $sep;
- print $purchase_journal . $sep;
- print length_accountg(html_entity_decode($k)) . $sep;
- print $sep;
- print ($mt < 0 ? 'C' : 'D') . $sep;
- print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
- print $langs->trans("VAT") . $sep;
- print $val["ref"];
- print "\n";
- }
- }
-
- foreach ( $tabttc[$key] as $k => $mt ) {
- print $date . $sep;
- print $purchase_journal . $sep;
- print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep;
- print length_accounta(html_entity_decode($k)) . $sep;
- print ($mt < 0 ? 'D' : 'C') . $sep;
- print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
- print $companystatic->name . $sep;
- print $val["ref"];
- print "\n";
- }
- }
- } elseif ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) {
- // Model Classic Export
foreach ( $tabfac as $key => $val ) {
$invoicestatic->id = $key;
@@ -468,44 +417,60 @@ $companystatic = new Fournisseur($db);
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(null, $k, true);
if ($mt) {
+ print '"' . $key . '"' . $sep;
print '"' . $date . '"' . $sep;
- print '"' . $val["ref"] . '"' . $sep;
+ print '"' . $val["refsuppliersologest"] . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ) . '"' . $sep;
print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
- print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
- // print '"' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
+ print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+ print " " . $sep;
+ print '"' . utf8_decode ( dol_trunc($accountingaccount->label, 32) ) . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
- print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
+ print '"' . ($mt < 0 ? price(- $mt) : '') . '"'. $sep;
+ print '"' . $journal_label . '"' ;
print "\n";
}
}
// VAT
foreach ( $tabtva[$key] as $k => $mt ) {
if ($mt) {
+ print '"' . $key . '"' . $sep;
print '"' . $date . '"' . $sep;
- print '"' . $val["ref"] . '"' . $sep;
+ print '"' . $val["refsuppliersologest"] . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ) . '"' . $sep;
print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
- // print '"' . $langs->trans("VAT") . '"' . $sep;
- print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("VAT") . '"' . $sep;
+ print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+ print " " . $sep;
+ print '"' . $langs->trans("VAT") . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("VAT") . '"' . $sep;
print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
- print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
+ print '"' . ($mt < 0 ? price(- $mt) : '') . '"'. $sep;
+ print '"' . $journal_label . '"' ;
print "\n";
}
}
// Third party
foreach ( $tabttc[$key] as $k => $mt ) {
+ print '"' . $key . '"' . $sep;
print '"' . $date . '"' . $sep;
- print '"' . $val["ref"] . '"' . $sep;
+ print '"' . $val["refsuppliersologest"] . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ). '"' . $sep;
print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
- print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("subledger_account") . '"' . $sep;
+ print '"' . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . '"' . $sep;
+ print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
+ print '"' . $langs->trans("Code_tiers") . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("Code_tiers") . '"' . $sep;
print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
- print '"' . ($mt >= 0 ? price($mt) : '') . '"';
+ print '"' . ($mt >= 0 ? price($mt) : '') . '"'. $sep;
+ print '"' . $journal_label . '"' ;
+ print "\n";
}
- print "\n";
+
}
}
-}
-*/
+
if (empty($action) || $action == 'view') {
@@ -524,7 +489,7 @@ if (empty($action) || $action == 'view') {
$description .= $langs->trans("DepositsAreIncluded");
}
- $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). ' - ' .$langs->trans("AlreadyInGeneralLedger").' '. $form->selectyesno('in_bookkeeping',$in_bookkeeping,0);
$varlink = 'id_journal=' . $id_journal;
@@ -548,6 +513,7 @@ if (empty($action) || $action == 'view') {
else {
print '';
}
+ print '';
print '';
print '
diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php
index cf92905e041..edaf3a87f27 100644
--- a/htdocs/accountancy/journal/sellsjournal.php
+++ b/htdocs/accountancy/journal/sellsjournal.php
@@ -46,7 +46,7 @@ $langs->load("main");
$langs->load("accountancy");
$id_journal = GETPOST('id_journal', 'int');
-$action = GETPOST('action','aZ09');
+$action = GETPOST('action','alpha');
$date_startmonth = GETPOST('date_startmonth');
$date_startday = GETPOST('date_startday');
@@ -54,6 +54,7 @@ $date_startyear = GETPOST('date_startyear');
$date_endmonth = GETPOST('date_endmonth');
$date_endday = GETPOST('date_endday');
$date_endyear = GETPOST('date_endyear');
+$in_bookkeeping = GETPOST('in_bookkeeping');
$now = dol_now();
@@ -113,6 +114,8 @@ if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$sql .= " AND fd.product_type IN (0,1)";
if ($date_start && $date_end)
$sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'";
+if ($in_bookkeeping == 'yes')
+ $sql .= " AND (f.rowid NOT IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice') )";
$sql .= " ORDER BY f.datef";
dol_syslog('accountancy/journal/sellsjournal.php', LOG_DEBUG);
@@ -401,76 +404,18 @@ if ($action == 'writebookkeeping') {
$form = new Form($db);
// Export
-/*if ($action == 'export_csv') {
+if ($action == 'export_csv') {
$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
$sell_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
+
include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
$companystatic = new Client($db);
+ $invoicestatic = new Facture($db);
- // Model Cegid Expert Export
- if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) {
- $sep = ";";
-
- foreach ( $tabfac as $key => $val ) {
- $companystatic->id = $tabcompany[$key]['id'];
- $companystatic->name = $tabcompany[$key]['name'];
- $companystatic->client = $tabcompany[$key]['code_client'];
-
- $invoicestatic->id = $key;
- $invoicestatic->ref = $val["ref"];
-
- $date = dol_print_date($val["date"], '%d%m%Y');
-
- foreach ( $tabttc[$key] as $k => $mt ) {
- print $date . $sep;
- print $sell_journal . $sep;
- print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep;
- print length_accounta(html_entity_decode($k)) . $sep;
- print ($mt < 0 ? 'C' : 'D') . $sep;
- print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
- print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("subledger_account") . $sep;
- print $val["ref"];
- print "\n";
- }
-
- // Product / Service
- foreach ( $tabht[$key] as $k => $mt ) {
- $accountingaccount_static = new AccountingAccount($db);
- if ($accountingaccount_static->fetch(null, $k, true)) {
- print $date . $sep;
- print $sell_journal . $sep;
- print length_accountg(html_entity_decode($k)) . $sep;
- print $sep;
- print ($mt < 0 ? 'D' : 'C') . $sep;
- print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
- print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount_static->label . $sep;
- print $val["ref"];
- print "\n";
- }
- }
-
- // TVA
- foreach ( $tabtva[$key] as $k => $mt ) {
- if ($mt) {
- print $date . $sep;
- print $sell_journal . $sep;
- print length_accountg(html_entity_decode($k)) . $sep;
- print $sep;
- print ($mt < 0 ? 'D' : 'C') . $sep;
- print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
- print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . $sep;
- // print $langs->trans("VAT") . $sep;
- print $val["ref"];
- print "\n";
- }
- }
- }
- } elseif ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) {
- // Model Classic Export
- foreach ( $tabfac as $key => $val ) {
+ foreach ( $tabfac as $key => $val ) {
$companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name'];
$companystatic->client = $tabcompany[$key]['code_client'];
@@ -481,13 +426,19 @@ $form = new Form($db);
$date = dol_print_date($val["date"], 'day');
foreach ( $tabttc[$key] as $k => $mt ) {
- print '"' . $date . '"' . $sep;
- print '"' . $val["ref"] . '"' . $sep;
- print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
- print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("subledger_account") . '"' . $sep;
- print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
- print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
- print "\n";
+ print '"' . $key . '"' . $sep;
+ print '"' . $date . '"' . $sep;
+ print '"' . $val["ref"] . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ) . '"' . $sep;
+ print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
+ print '"' . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . '"' . $sep;
+ print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
+ print '"' . $langs->trans("Code_tiers") . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep;
+ print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
+ print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
+ print '"' . $sell_journal . '"' ;
+ print "\n";
}
// Product / Service
@@ -495,33 +446,48 @@ $form = new Form($db);
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(null, $k, true);
+
if ($mt) {
- print '"' . $date . '"' . $sep;
- print '"' . $val["ref"] . '"' . $sep;
- print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
- print '"' . dol_trunc($companystatic->name, 16) . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
- print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
- print '"' . ($mt >= 0 ? price($mt) : '') . '"';
- print "\n";
+ print '"' . $key . '"' . $sep;
+ print '"' . $date . '"' . $sep;
+ print '"' . $val["ref"] . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ) . '"' . $sep;
+ print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+ print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+ print " " . $sep;
+ print '"' . utf8_decode ( dol_trunc($accountingaccount->label, 32) ) . '"' . $sep;
+ print '"' . utf8_decode (dol_trunc($companystatic->name, 16) ) . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
+ print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
+ print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
+ print '"' . $sell_journal . '"' ;
+ print "\n";
}
}
// VAT
foreach ( $tabtva[$key] as $k => $mt ) {
+
+
+
if ($mt) {
- print '"' . $date . '"' . $sep;
- print '"' . $val["ref"] . '"' . $sep;
- print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
- print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . '"' . $sep;
- print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
- print '"' . ($mt >= 0 ? price($mt) : '') . '"';
- print "\n";
+ print '"' . $key . '"' . $sep;
+ print '"' . $date . '"' . $sep;
+ print '"' . $val["ref"] . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ). '"' . $sep;
+ print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+ print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+ print " " . $sep;
+ print '"' . $langs->trans("VAT") . ' - ' . $def_tva[$key]. '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ). ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . '"' . $sep;
+ print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
+ print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
+ print '"' . $sell_journal . '"' ;
+ print "\n";
}
}
- }
}
-}
-*/
+ }
+
if (empty($action) || $action == 'view') {
@@ -539,18 +505,12 @@ if (empty($action) || $action == 'view') {
$description .= $langs->trans("DepositsAreNotIncluded");
else
$description .= $langs->trans("DepositsAreIncluded");
- $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). ' - ' .$langs->trans("AlreadyInGeneralLedger").' '. $form->selectyesno('in_bookkeeping',$in_bookkeeping,0);
$varlink = 'id_journal=' . $id_journal;
journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
- /*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) {
- print '';
- } else {
- print '';
- }*/
-
// Button to write into Ledger
if (empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') {
print img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
@@ -563,6 +523,7 @@ if (empty($action) || $action == 'view') {
else {
print '';
}
+ print '';
print '';
print '
diff --git a/htdocs/accountancy/report/result.php b/htdocs/accountancy/report/result.php
index 801ba0a2007..b8335e2d8f7 100644
--- a/htdocs/accountancy/report/result.php
+++ b/htdocs/accountancy/report/result.php
@@ -1,6 +1,6 @@
- * Copyright (C) 2016 Alexandre Spangaro
+/* Copyright (C) 2016/17 Jamal Elbaz
+ * Copyright (C) 2016 Alexandre Spangaro
*
* 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
@@ -25,6 +25,7 @@ require '../../main.inc.php';
// Class
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php';
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancycategory.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
@@ -41,6 +42,8 @@ $selectcpt = GETPOST('cpt_bk');
$id = GETPOST('id', 'int');
$rowid = GETPOST('rowid', 'int');
$cancel = GETPOST('cancel');
+$simple_report = GETPOST('simple_report');
+
// Filter
$year = GETPOST('year','int');
@@ -77,7 +80,16 @@ $form = new Form($db);
$textprevyear = '' . img_previous() . '';
$textnextyear = ' ' . img_next() . '';
-print load_fiche_titre($langs->trans('ReportInOut'), $textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear, 'title_accountancy');
+ $nom = $langs->trans("ReportInOut");
+ $nomlink = '';
+ $periodlink = '';
+ $exportlink = '';
+ $builddate = time();
+ $description = '';
+ $period = $langs->trans("Detail").' '. $form->selectyesno('simple_report',$simple_report,0) . " " .$textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear ;
+report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array (
+ 'action' => ''
+ ));
$moreforfilter='';
@@ -108,37 +120,97 @@ foreach($months as $k => $v){
}
print '';
-$cats = $AccCat->getCatsCpts();
-if ($cats < 0) dol_print_error($db, $AccCat->error, $AccCat->errors);
-$catsCalcule = $AccCat->getCatsCal();
+
+//All categories
+$cats = $AccCat->getCats();
if ($catsCalcule < 0) dol_print_error($db, $AccCat->error, $AccCat->errors);
$j=1;
$sommes = array();
-if (!empty($cats))
-{
- foreach ($cats as $name_cat => $cpts)
- {
+foreach($cats as $cat ){
+ if(!empty($cat['category_type'])){ // category calculed
+
+ $formula = $cat['formula'];
+
print "";
- print '| ' . $name_cat . ' | ';
+ print '' . $cat['label'] . ' | ';
+
+ $vars = array();
+
+ // Previous Fiscal year (N-1)
+ foreach($sommes as $code => $det){
+ $vars[$code] = $det['NP'];
+ }
+
+
+ $result = strtr($formula, $vars);
+
+
+ $r = $AccCat->calculate($result);
+
+ print '' . price($r) . ' | ';
+ $code = $cat['code']; // code categorie de calcule
+ $sommes[$code]['NP'] += $r;
+
+ // Current fiscal year (N)
+ if (is_array($sommes) && ! empty($sommes)){
+ foreach($sommes as $code => $det){
+ $vars[$code] = $det['N'];
+ }
+ }
+
+ $result = strtr($formula, $vars);
+
+ $r = $AccCat->calculate($result);
+
+ print '' . price($r) . ' | ';
+ $sommes[$code]['N'] += $r;
+
+ // Detail by month
+ foreach($months as $k => $v){
+ foreach($sommes as $code => $det){
+ $vars[$code] = $det['M'][$k];
+ }
+ $result = strtr($formula, $vars);
+ $r = $AccCat->calculate($result);
+ print '' . price($r) . ' | ';
+ $sommes[$code]['M'][$k] += $r;
+ }
+
+
print "
\n";
- $position = -1;
- $code = -1;
+
+
+ }else{ // normal category
+
+ $totCat = array();
+ $totCat['M'] = array();
+
+ // get cpts of category
+ $cpts = $AccCat->getCptsCat($cat['rowid']);
+
+
+ print "";
+ print '| ' . $cat['label'] . ' | ';
+
foreach($cpts as $i => $cpt){
+ $var = ! $var;
- $position = $cpt['position'];
- $code = $cpt['code'];
-
+ $code = $cat['code'];
+
+ // N-1
$return = $AccCat->getResult($cpt['account_number'], 0, $year_current -1, $cpt['dc']);
+
if ($return < 0) {
setEventMessages(null, $AccCat->errors, 'errors');
$resultNP=0;
} else {
$resultNP=$AccCat->sdc;
}
-
+
+ //N
$return = $AccCat->getResult($cpt['account_number'], 0, $year_current, $cpt['dc']);
if ($return < 0) {
setEventMessages(null, $AccCat->errors, 'errors');
@@ -146,13 +218,64 @@ if (!empty($cats))
} else {
$resultN=$AccCat->sdc;
}
+
+ $totCat['NP'] += $resultNP;
+ $totCat['N'] += $resultN;
+
+ foreach($months as $k => $v){
+ $return = $AccCat->getResult($cpt['account_number'], $k+1, $year_current, $cpt['dc']);
+ if ($return < 0) {
+ setEventMessages(null, $AccCat->errors, 'errors');
+ $resultM=0;
+ } else {
+ $resultM=$AccCat->sdc;
+ }
+ $totCat['M'][$k] += $resultM;
+
+ }
+ }
+
+ print '' . price($totCat['NP']) . ' | ';
+ print '' . price($totCat['N']) . ' | ';
+
+ foreach($totCat['M'] as $k => $v){
+ print '' . price($v) . ' | ';
+ }
+ print "
\n";
+
+ foreach($cpts as $i => $cpt){
+ $var = ! $var;
+
+ $code = $cat['code'];
+
+ // N-1
+ $return = $AccCat->getResult($cpt['account_number'], 0, $year_current -1, $cpt['dc']);
+
+ if ($return < 0) {
+ setEventMessages(null, $AccCat->errors, 'errors');
+ $resultNP=0;
+ } else {
+ $resultNP=$AccCat->sdc;
+ }
+
+ //N
+ $return = $AccCat->getResult($cpt['account_number'], 0, $year_current, $cpt['dc']);
+ if ($return < 0) {
+ setEventMessages(null, $AccCat->errors, 'errors');
+ $resultN=0;
+ } else {
+ $resultN=$AccCat->sdc;
+ }
+
$sommes[$code]['NP'] += $resultNP;
$sommes[$code]['N'] += $resultN;
- print '';
- print '| ' . $cpt['account_number'] . ' | ';
+ print '
';
+ if ($simple_report == 'yes') {
+ print '| ' . length_accountg($cpt['account_number']) . ' | ';
print '' . $cpt['name_cpt'] . ' | ';
- print '' . price($resultNP) . ' | ';
- print '' . price($resultN) . ' | ';
+ print '' . price($resultNP) . ' | ';
+ print '' . price($resultN) . ' | ';
+ }
foreach($months as $k => $v){
$return = $AccCat->getResult($cpt['account_number'], $k+1, $year_current, $cpt['dc']);
@@ -163,102 +286,15 @@ if (!empty($cats))
$resultM=$AccCat->sdc;
}
$sommes[$code]['M'][$k] += $resultM;
+ if ($simple_report == 'yes') {
print '' . price($resultM) . ' | ';
- }
-
- print "
\n";
- }
-
- // If it's a calculated catgory
- $p = $position + 1;
- if(array_key_exists($p, $catsCalcule)){
- $formula = $catsCalcule[$p]['formula'];
-
- print "";
- print '| ' . $catsCalcule[$p]['label'] . ' | ';
-
- $vars = array();
-
- // Previous Fiscal year (N-1)
- foreach($sommes as $code => $det){
- $vars[$code] = $det['NP'];
- }
- $result = strtr($formula, $vars);
- eval( '$result = (' . $result . ');' );
- print '' . price($result) . ' | ';
- $code = $catsCalcule[$p]['code']; // code categorie de calcule
- $sommes[$code]['NP'] += $result;
-
- // Current fiscal year (N)
- foreach($sommes as $code => $det){
- $vars[$code] = $det['N'];
- }
- $result = strtr($formula, $vars);
- eval( '$result = (' . $result . ');' );
- print '' . price($result) . ' | ';
- $sommes[$code]['N'] += $result;
-
- // Detail by month
- foreach($months as $k => $v){
- foreach($sommes as $code => $det){
- $vars[$code] = $det['M'][$k];
}
- $result = strtr($formula, $vars);
- eval( '$result = (' . $result . ');' );
- print '' . price($result) . ' | ';
- $sommes[$code]['M'][$k] += $result;
}
- //print '' . $catsCalcule[$p]['formula'] . ' | ';
print "
\n";
- unset($catsCalcule[$p]); // j'élimine la catégorie calculée après affichage
}
- $j++;
- }
-
- // Others calculed category
- foreach($catsCalcule as $p => $catc)
- {
- $formula = $catsCalcule[$p]['formula'];
-
- print "";
- print '| ' . $catsCalcule[$p]['label'] . ' | ';
-
- $vars = array();
-
- // Previous Fiscal year (N-1)
- foreach($sommes as $code => $det){
- $vars[$code] = $det['NP'];
- }
- $result = strtr($formula, $vars);
- eval( '$result = (' . $result . ');' );
- print '' . price($result) . ' | ';
- $code = $catsCalcule[$p]['code']; // code categorie de calcule
- $sommes[$code]['NP'] += $result;
-
- // Current fiscal year (N)
- foreach($sommes as $code => $det){
- $vars[$code] = $det['N'];
- }
- $result = strtr($formula, $vars);
- eval( '$result = (' . $result . ');' );
- print '' . price($result) . ' | ';
- $sommes[$code]['N'] += $result;
-
- // Detail by month
- foreach($months as $k => $v){
- foreach($sommes as $code => $det){
- $vars[$code] = $det['M'][$k];
- }
- $result = strtr($formula, $vars);
- eval( '$result = (' . $result . ');' );
- print '' . price($result) . ' | ';
- $sommes[$code]['M'][$k] += $result;
- }
-
- //print '' . $catsCalcule[$p]['formula'] . ' | ';
- print "
\n";
}
+
}
print "";
diff --git a/htdocs/accountancy/supplier/lines.php b/htdocs/accountancy/supplier/lines.php
index 9c7a72cb94c..398d12503ab 100644
--- a/htdocs/accountancy/supplier/lines.php
+++ b/htdocs/accountancy/supplier/lines.php
@@ -52,6 +52,8 @@ $search_desc = GETPOST('search_desc', 'alpha');
$search_amount = GETPOST('search_amount', 'alpha');
$search_account = GETPOST('search_account', 'alpha');
$search_vat = GETPOST('search_vat', 'alpha');
+$search_country = GETPOST('search_country', 'alpha');
+$search_tvaintra = GETPOST('search_tvaintra', 'alpha');
// Load variable for pagination
$limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
@@ -94,6 +96,8 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP
$search_amount = '';
$search_account = '';
$search_vat = '';
+ $search_country = '';
+ $search_tvaintra = '';
}
if (is_array($changeaccount) && count($changeaccount) > 0) {
@@ -149,13 +153,15 @@ print '