dolibarr  9.0.0
bankjournal.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2007-2010 Jean Heimburger <jean@tiaris.info>
4  * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr>
7  * Copyright (C) 2013-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
8  * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
9  * Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
10  * Copyright (C) 2017-2018 Frédéric France <frederic.france@netlogic.fr>
11  * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
32 require '../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php';
34 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php';
36 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
37 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
38 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
39 require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
40 require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
41 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
42 require_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/chargesociales.class.php';
43 require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
44 require_once DOL_DOCUMENT_ROOT . '/don/class/don.class.php';
45 require_once DOL_DOCUMENT_ROOT . '/don/class/paymentdonation.class.php';
46 require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php';
47 require_once DOL_DOCUMENT_ROOT . '/compta/salaries/class/paymentsalary.class.php';
48 require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
49 require_once DOL_DOCUMENT_ROOT . '/fourn/class/paiementfourn.class.php';
50 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
51 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.class.php';
52 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
53 require_once DOL_DOCUMENT_ROOT . '/societe/class/client.class.php';
54 require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
55 require_once DOL_DOCUMENT_ROOT . '/expensereport/class/paymentexpensereport.class.php';
56 require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/paymentvarious.class.php';
57 require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
58 require_once DOL_DOCUMENT_ROOT . '/loan/class/loan.class.php';
59 require_once DOL_DOCUMENT_ROOT . '/loan/class/paymentloan.class.php';
60 require_once DOL_DOCUMENT_ROOT . '/adherents/class/subscription.class.php';
61 
62 // Load translation files required by the page
63 $langs->loadLangs(array("companies","other","compta","banks","bills","donations","loan","accountancy","trips","salaries","hrm","members"));
64 
65 // Multi journal
66 $id_journal = GETPOST('id_journal', 'int');
67 
68 $date_startmonth = GETPOST('date_startmonth','int');
69 $date_startday = GETPOST('date_startday','int');
70 $date_startyear = GETPOST('date_startyear','int');
71 $date_endmonth = GETPOST('date_endmonth','int');
72 $date_endday = GETPOST('date_endday','int');
73 $date_endyear = GETPOST('date_endyear','int');
74 $in_bookkeeping = GETPOST('in_bookkeeping','aZ09');
75 if ($in_bookkeeping == '') $in_bookkeeping = 'notyet';
76 
77 $now = dol_now();
78 
79 $action = GETPOST('action','aZ09');
80 
81 // Security check
82 if ($user->societe_id > 0 && empty($id_journal))
84 
85 
86 /*
87  * Actions
88  */
89 
90 $error = 0;
91 
92 $year_current = strftime("%Y", dol_now());
93 $pastmonth = strftime("%m", dol_now()) - 1;
94 $pastmonthyear = $year_current;
95 if ($pastmonth == 0) {
96  $pastmonth = 12;
97  $pastmonthyear --;
98 }
99 
100 $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
101 $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
102 
103 if (! GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) // We define date_start and date_end, only if we did not submit the form
104 {
105  $date_start = dol_get_first_day($pastmonthyear, $pastmonth, false);
106  $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
107 }
108 
109 $idpays = $mysoc->country_id;
110 
111 $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, b.fk_account,";
112 $sql .= " ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
113 $sql .= " soc.code_compta, soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, soc.email as email, bu1.type as typeop_company,";
114 $sql .= " u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, bu2.type as typeop_user,";
115 $sql .= " bu3.type as typeop_payment, bu4.type as typeop_payment_supplier";
116 $sql .= " FROM " . MAIN_DB_PREFIX . "bank as b";
117 $sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid";
118 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
119 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
120 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='payment'";
121 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu4 ON bu4.fk_bank = b.rowid AND bu4.type='payment_supplier'";
122 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid";
123 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u on bu2.url_id=u.rowid";
124 $sql .= " WHERE ba.fk_accountancy_journal=" . $id_journal;
125 $sql .= ' AND b.amount != 0 AND ba.entity IN ('.getEntity('bank_account', 0).')'; // We don't share object for accountancy
126 if ($date_start && $date_end)
127  $sql .= " AND b.dateo >= '" . $db->idate($date_start) . "' AND b.dateo <= '" . $db->idate($date_end) . "'";
128 // Already in bookkeeping or not
129 if ($in_bookkeeping == 'already')
130 {
131  $sql .= " AND (b.rowid IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
132 }
133 if ($in_bookkeeping == 'notyet')
134 {
135  $sql .= " AND (b.rowid NOT IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
136 }
137 $sql .= " ORDER BY b.datev";
138 //print $sql;
139 
140 $object = new Account($db);
141 $paymentstatic = new Paiement($db);
142 $paymentsupplierstatic = new PaiementFourn($db);
143 $societestatic = new Societe($db);
144 $userstatic = new User($db);
145 $bankaccountstatic = new Account($db);
146 $chargestatic = new ChargeSociales($db);
147 $paymentdonstatic = new PaymentDonation($db);
148 $paymentvatstatic = new TVA($db);
149 $paymentsalstatic = new PaymentSalary($db);
150 $paymentexpensereportstatic = new PaymentExpenseReport($db);
151 $paymentvariousstatic = new PaymentVarious($db);
152 $paymentloanstatic = new PaymentLoan($db);
153 $accountLinestatic=new AccountLine($db);
154 $paymentsubscriptionstatic = new Subscription($db);
155 
156 $accountingaccount = new AccountingAccount($db);
157 
158 // Get code of finance journal
159 $accountingjournalstatic = new AccountingJournal($db);
160 $accountingjournalstatic->fetch($id_journal);
161 $journal = $accountingjournalstatic->code;
162 $journal_label = $accountingjournalstatic->label;
163 
164 
165 dol_syslog("accountancy/journal/bankjournal.php", LOG_DEBUG);
166 $result = $db->query($sql);
167 if ($result) {
168 
169  $num = $db->num_rows($result);
170  //print $sql;
171 
172  // Variables
173  $account_supplier = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : 'NotDefined'); // NotDefined is a reserved word
174  $account_customer = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : 'NotDefined'); // NotDefined is a reserved word
175  $account_employee = (! empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : 'NotDefined'); // NotDefined is a reserved word
176  $account_pay_vat = (! empty($conf->global->ACCOUNTING_VAT_PAY_ACCOUNT) ? $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT : 'NotDefined'); // NotDefined is a reserved word
177  $account_pay_donation = (! empty($conf->global->DONATION_ACCOUNTINGACCOUNT) ? $conf->global->DONATION_ACCOUNTINGACCOUNT : 'NotDefined'); // NotDefined is a reserved word
178  $account_pay_subscription = (! empty($conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT) ? $conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT : 'NotDefined'); // NotDefined is a reserved word
179  $account_transfer = (! empty($conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH) ? $conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH : 'NotDefined'); // NotDefined is a reserved word
180 
181  $tabcompany = array();
182  $tabuser = array();
183  $tabpay = array ();
184  $tabbq = array ();
185  $tabtp = array ();
186  $tabtype = array ();
187 
188  // Loop on each line into llx_bank table. For each line, we should get:
189  // one line tabpay = line into bank
190  // one line for bank record = tabbq
191  // one line for thirdparty record = tabtp
192  $i = 0;
193  while ( $i < $num )
194  {
195  $obj = $db->fetch_object($result);
196 
197  $lineisapurchase = -1;
198  $lineisasale = -1;
199  // Old method to detect if it's a sale or purchase
200  if ($obj->label == '(SupplierInvoicePayment)' || $obj->label == '(SupplierInvoicePaymentBack)') $lineisapurchase=1;
201  if ($obj->label == '(CustomerInvoicePayment)' || $obj->label == '(CustomerInvoicePaymentBack)') $lineisasale=1;
202  // Try a more reliable method to detect if record is a supplier payment or a customer payment
203  if ($lineisapurchase < 0)
204  {
205  if ($obj->typeop_payment_supplier == 'payment_supplier') $lineisapurchase = 1;
206  }
207  if ($lineisasale < 0)
208  {
209  if ($obj->typeop_payment == 'payment') $lineisasale = 1;
210  }
211  //var_dump($obj->type_payment); var_dump($obj->type_payment_supplier);
212  //var_dump($lineisapurchase); //var_dump($lineisasale);
213 
214  // Set accountancy code for bank
215  $compta_bank = $obj->account_number;
216 
217  // Set accountancy code for thirdparty
218  $compta_soc = 'NotDefined';
219  if ($lineisapurchase > 0)
220  $compta_soc = (! empty($obj->code_compta_fournisseur) ? $obj->code_compta_fournisseur : $account_supplier);
221  if ($lineisasale > 0)
222  $compta_soc = (! empty($obj->code_compta) ? $obj->code_compta : $account_customer);
223 
224  $tabcompany[$obj->rowid] = array (
225  'id' => $obj->socid,
226  'name' => $obj->name,
227  'code_compta' => $compta_soc,
228  'email' => $obj->email
229  );
230 
231  // Set accountancy code for user
232  $compta_user = (! empty($obj->accountancy_code) ? $obj->accountancy_code : $account_employee);
233 
234  $tabuser[$obj->rowid] = array (
235  'id' => $obj->userid,
236  'name' => dolGetFirstLastname($obj->firstname, $obj->lastname),
237  'lastname' => $obj->lastname,
238  'firstname' => $obj->firstname,
239  'email' => $obj->useremail,
240  'accountancy_code' => $compta_user
241  );
242 
243  // Variable bookkeeping ($obj->rowid is Bank Id)
244  $tabpay[$obj->rowid]["date"] = $obj->do;
245  $tabpay[$obj->rowid]["type_payment"] = $obj->fk_type; // CHQ, VIR, LIQ, CB, ...
246  $tabpay[$obj->rowid]["ref"] = $obj->label; // By default. Not unique. May be changed later
247  $tabpay[$obj->rowid]["fk_bank"] = $obj->rowid;
248  $tabpay[$obj->rowid]["bank_account_ref"] = $obj->baref;
249  $tabpay[$obj->rowid]["fk_bank_account"] = $obj->fk_account;
250  if (preg_match('/^\((.*)\)$/i', $obj->label, $reg)) {
251  $tabpay[$obj->rowid]["lib"] = $langs->trans($reg[1]);
252  } else {
253  $tabpay[$obj->rowid]["lib"] = dol_trunc($obj->label, 60);
254  }
255  $links = $object->get_url($obj->rowid); // Get an array('url'=>, 'url_id'=>, 'label'=>, 'type'=> 'fk_bank'=> )
256 
257  //var_dump($i);
258  //var_dump($tabpay);
259 
260  // By default
261  $tabpay[$obj->rowid]['type'] = 'unknown'; // Can be SOLD, miscellaneous entry, payment of patient, or any old record with no links in bank_url.
262  $tabtype[$obj->rowid] = 'unknown';
263 
264  // get_url may return -1 which is not traversable
265  if (is_array($links) && count($links) > 0) {
266 
267  // Now loop on each link of record in bank.
268  foreach ($links as $key => $val) {
269 
270  if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert', 'payment_donation', 'member', 'payment_loan', 'payment_salary', 'payment_various')))
271  {
272  // So we excluded 'company' and 'user' here. We want only payment lines
273 
274  // We save tabtype for a future use, to remember what kind of payment it is
275  $tabpay[$obj->rowid]['type'] = $links[$key]['type'];
276  $tabtype[$obj->rowid] = $links[$key]['type'];
277  }
278  elseif (in_array($links[$key]['type'], array('company', 'user')))
279  {
280  if ($tabpay[$obj->rowid]['type'] == 'unknown')
281  {
282  // We can guess here it is a bank record for a thirdparty company or a user.
283  // But we won't be able to record somewhere else than into a waiting account, because there is no other journal to record the contreparty.
284  }
285  }
286 
287  if ($links[$key]['type'] == 'payment') {
288  $paymentstatic->id = $links[$key]['url_id'];
289  $paymentstatic->ref = $links[$key]['url_id'];
290  $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentstatic->getNomUrl(2, '', ''); // TODO Do not include list of invoice in tooltip, the dol_string_nohtmltag is ko with this
291  $tabpay[$obj->rowid]["paymentid"] = $paymentstatic->id;
292  } else if ($links[$key]['type'] == 'payment_supplier') {
293  $paymentsupplierstatic->id = $links[$key]['url_id'];
294  $paymentsupplierstatic->ref = $links[$key]['url_id'];
295  $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsupplierstatic->getNomUrl(2);
296  $tabpay[$obj->rowid]["paymentsupplierid"] = $paymentsupplierstatic->id;
297  } else if ($links[$key]['type'] == 'company') {
298  $societestatic->id = $links[$key]['url_id'];
299  $societestatic->name = $links[$key]['label'];
300  $societestatic->email = $tabcompany[$obj->rowid]['email'];
301  $tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30);
302  if ($compta_soc) $tabtp[$obj->rowid][$compta_soc] += $obj->amount;
303  } else if ($links[$key]['type'] == 'user') {
304  $userstatic->id = $links[$key]['url_id'];
305  $userstatic->name = $links[$key]['label'];
306  $userstatic->email = $tabuser[$obj->rowid]['email'];
307  $userstatic->firstname = $tabuser[$obj->rowid]['firstname'];
308  $userstatic->lastname = $tabuser[$obj->rowid]['lastname'];
309  if ($userstatic->id > 0) $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, '', 30);
310  else $tabpay[$obj->rowid]["soclib"] = '???'; // Should not happen, but happens with old data when id of user was not saved on expense report payment.
311  if ($compta_user) $tabtp[$obj->rowid][$compta_user] += $obj->amount;
312  } else if ($links[$key]['type'] == 'sc') {
313  $chargestatic->id = $links[$key]['url_id'];
314  $chargestatic->ref = $links[$key]['url_id'];
315 
316  $tabpay[$obj->rowid]["lib"] .= ' ' . $chargestatic->getNomUrl(2);
317  if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
318  if ($reg[1] == 'socialcontribution')
319  $reg[1] = 'SocialContribution';
320  $chargestatic->lib = $langs->trans($reg[1]);
321  } else {
322  $chargestatic->lib = $links[$key]['label'];
323  }
324  $chargestatic->ref = $chargestatic->lib;
325  $tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, 30);
326  $tabpay[$obj->rowid]["paymentscid"] = $chargestatic->id;
327 
328  $sqlmid = 'SELECT cchgsoc.accountancy_code';
329  $sqlmid .= " FROM " . MAIN_DB_PREFIX . "c_chargesociales cchgsoc ";
330  $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "chargesociales as chgsoc ON chgsoc.fk_type=cchgsoc.id";
331  $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paycharg ON paycharg.fk_charge=chgsoc.rowid";
332  $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON bkurl.url_id=paycharg.rowid";
333  $sqlmid .= " WHERE bkurl.fk_bank=" . $obj->rowid;
334 
335  dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
336  $resultmid = $db->query($sqlmid);
337  if ($resultmid) {
338  $objmid = $db->fetch_object($resultmid);
339  $tabtp[$obj->rowid][$objmid->accountancy_code] += $obj->amount;
340  }
341  } else if ($links[$key]['type'] == 'payment_donation') {
342  $paymentdonstatic->id = $links[$key]['url_id'];
343  $paymentdonstatic->ref = $links[$key]['url_id'];
344  $paymentdonstatic->fk_donation = $links[$key]['url_id'];
345  $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentdonstatic->getNomUrl(2);
346  $tabpay[$obj->rowid]["paymentdonationid"] = $paymentdonstatic->id;
347  $tabtp[$obj->rowid][$account_pay_donation] += $obj->amount;
348  } else if ($links[$key]['type'] == 'member') {
349  $paymentsubscriptionstatic->id = $links[$key]['url_id'];
350  $paymentsubscriptionstatic->ref = $links[$key]['url_id'];
351  $paymentsubscriptionstatic->label = $links[$key]['label'];
352  $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsubscriptionstatic->getNomUrl(2);
353  $tabpay[$obj->rowid]["paymentsubscriptionid"] = $paymentsubscriptionstatic->id;
354  $paymentsubscriptionstatic->fetch($paymentsubscriptionstatic->id);
355  $tabtp[$obj->rowid][$account_pay_subscription] += $obj->amount;
356  } else if ($links[$key]['type'] == 'payment_vat') { // Payment VAT
357  $paymentvatstatic->id = $links[$key]['url_id'];
358  $paymentvatstatic->ref = $links[$key]['url_id'];
359  $paymentvatstatic->label = $links[$key]['label'];
360  $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2);
361  $tabpay[$obj->rowid]["paymentvatid"] = $paymentvatstatic->id;
362  $tabtp[$obj->rowid][$account_pay_vat] += $obj->amount;
363  } else if ($links[$key]['type'] == 'payment_salary') {
364  $paymentsalstatic->id = $links[$key]['url_id'];
365  $paymentsalstatic->ref = $links[$key]['url_id'];
366  $paymentsalstatic->label = $links[$key]['label'];
367  $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsalstatic->getNomUrl(2);
368  $tabpay[$obj->rowid]["paymentsalid"] = $paymentsalstatic->id;
369  } else if ($links[$key]['type'] == 'payment_expensereport') {
370  $paymentexpensereportstatic->id = $links[$key]['url_id'];
371  $tabpay[$obj->rowid]["lib"] .= $paymentexpensereportstatic->getNomUrl(2);
372  $tabpay[$obj->rowid]["paymentexpensereport"] = $paymentexpensereportstatic->id;
373  } else if ($links[$key]['type'] == 'payment_various') {
374  $paymentvariousstatic->id = $links[$key]['url_id'];
375  $paymentvariousstatic->ref = $links[$key]['url_id'];
376  $paymentvariousstatic->label = $links[$key]['label'];
377  $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvariousstatic->getNomUrl(2);
378  $tabpay[$obj->rowid]["paymentvariousid"] = $paymentvariousstatic->id;
379  $paymentvariousstatic->fetch($paymentvariousstatic->id);
380  $account_various = (! empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code : 'NotDefined'); // NotDefined is a reserved word
381  $tabtp[$obj->rowid][$account_various] += $obj->amount;
382  } else if ($links[$key]['type'] == 'payment_loan') {
383  $paymentloanstatic->id = $links[$key]['url_id'];
384  $paymentloanstatic->ref = $links[$key]['url_id'];
385  $paymentloanstatic->fk_loan = $links[$key]['url_id'];
386  $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentloanstatic->getNomUrl(2);
387  $tabpay[$obj->rowid]["paymentloanid"] = $paymentloanstatic->id;
388  //$tabtp[$obj->rowid][$account_pay_loan] += $obj->amount;
389  $sqlmid = 'SELECT pl.amount_capital, pl.amount_insurance, pl.amount_interest, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest';
390  $sqlmid.= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl, '.MAIN_DB_PREFIX.'loan as l';
391  $sqlmid.= ' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.$obj->rowid;
392 
393  dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
394  $resultmid = $db->query($sqlmid);
395  if ($resultmid) {
396  $objmid = $db->fetch_object($resultmid);
397  $tabtp[$obj->rowid][$objmid->accountancy_account_capital] -= $objmid->amount_capital;
398  $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] -= $objmid->amount_insurance;
399  $tabtp[$obj->rowid][$objmid->accountancy_account_interest] -= $objmid->amount_interest;
400  }
401  } else if ($links[$key]['type'] == 'banktransfert') {
402  $accountLinestatic->fetch($links[$key]['url_id']);
403  $tabpay[$obj->rowid]["lib"] .= ' '.$langs->trans("BankTransfer").'- ' .$accountLinestatic ->getNomUrl(1);
404  $tabtp[$obj->rowid][$account_transfer] += $obj->amount;
405  $bankaccountstatic->fetch($tabpay[$obj->rowid]['fk_bank_account']);
406  $tabpay[$obj->rowid]["soclib"] = $bankaccountstatic->getNomUrl(2);
407  }
408  }
409  }
410 
411  $tabbq[$obj->rowid][$compta_bank] += $obj->amount;
412 
413  // If not links were found to know amount on thirdparty, we init it.
414  if (empty($tabtp[$obj->rowid])) $tabtp[$obj->rowid]['NotDefined']= $tabbq[$obj->rowid][$compta_bank];
415 
416  // Check account number is ok
417  /*if ($action == 'writebookkeeping') // Make test now in such a case
418  {
419  reset($tabbq[$obj->rowid]);
420  $first_key_tabbq = key($tabbq[$obj->rowid]);
421  if (empty($first_key_tabbq))
422  {
423  $error++;
424  setEventMessages($langs->trans('ErrorAccountancyCodeOnBankAccountNotDefined', $obj->baref), null, 'errors');
425  }
426  reset($tabtp[$obj->rowid]);
427  $first_key_tabtp = key($tabtp[$obj->rowid]);
428  if (empty($first_key_tabtp))
429  {
430  $error++;
431  setEventMessages($langs->trans('ErrorAccountancyCodeOnThirdPartyNotDefined'), null, 'errors');
432  }
433  }*/
434 
435  // if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
436 
437  $i++;
438  }
439 } else {
440  dol_print_error($db);
441 }
442 
443 /*
444 var_dump($tabpay);
445 var_dump($tabbq);
446 var_dump($tabtp);
447 */
448 
449 // Write bookkeeping
450 if (! $error && $action == 'writebookkeeping') {
451  $now = dol_now();
452 
453  $error = 0;
454  foreach ( $tabpay as $key => $val ) // $key is rowid into llx_bank
455  {
456  $date = dol_print_date($db->jdate($val["date"]), 'day');
457 
458  $ref = getSourceDocRef($val, $tabtype[$key]);
459 
460  $errorforline = 0;
461 
462  $totalcredit = 0;
463  $totaldebit = 0;
464 
465  $db->begin();
466 
467  // Introduce a protection. Total of tabtp must be total of tabbq
468  /*var_dump($tabpay);
469  var_dump($tabtp);
470  var_dump($tabbq);exit;*/
471 
472  // Bank
473  if (! $errorforline && is_array($tabbq[$key]))
474  {
475  // Line into bank account
476  foreach ( $tabbq[$key] as $k => $mt )
477  {
478  if ($mt)
479  {
480  $reflabel = '';
481  if (! empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib']) . " - ";
482  $reflabel.= $langs->trans("Bank").' '.dol_string_nohtmltag($val['bank_account_ref']);
483  if (! empty($val['soclib'])) $reflabel .= " - " . dol_string_nohtmltag($val['soclib']);
484 
485  $bookkeeping = new BookKeeping($db);
486  $bookkeeping->doc_date = $val["date"];
487  $bookkeeping->doc_ref = $ref;
488  $bookkeeping->doc_type = 'bank';
489  $bookkeeping->fk_doc = $key;
490  $bookkeeping->fk_docdet = $val["fk_bank"];
491  $bookkeeping->numero_compte = $k;
492 
493  $accountingaccount->fetch(null, $k, true);
494  $bookkeeping->label_compte = $accountingaccount->label;
495 
496  $bookkeeping->label_operation = $reflabel;
497  $bookkeeping->montant = $mt;
498  $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
499  $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
500  $bookkeeping->credit = ($mt < 0 ? - $mt : 0);
501  $bookkeeping->code_journal = $journal;
502  $bookkeeping->journal_label = $journal_label;
503  $bookkeeping->fk_user_author = $user->id;
504  $bookkeeping->date_create = $now;
505 
506  // No subledger_account value for the bank line but add a specific label_operation
507  $bookkeeping->subledger_account = '';
508  $bookkeeping->label_operation = $reflabel;
509  $bookkeeping->entity = $conf->entity;
510 
511  $totaldebit += $bookkeeping->debit;
512  $totalcredit += $bookkeeping->credit;
513 
514  $result = $bookkeeping->create($user);
515  if ($result < 0) {
516  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
517  {
518  $error++;
519  $errorforline++;
520  setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
521  }
522  else
523  {
524  $error++;
525  $errorforline++;
526  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
527  }
528  }
529  }
530  }
531  }
532 
533  // Third party
534  if (! $errorforline)
535  {
536  if (is_array($tabtp[$key]))
537  {
538  // Line into thirdparty account
539  foreach ( $tabtp[$key] as $k => $mt ) {
540  if ($mt)
541  {
542  $reflabel = '';
543  if (! empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib']) . ($val['soclib']?" - ":"");
544  $reflabel.= dol_string_nohtmltag($val['soclib']);
545 
546  $bookkeeping = new BookKeeping($db);
547  $bookkeeping->doc_date = $val["date"];
548  $bookkeeping->doc_ref = $ref;
549  $bookkeeping->doc_type = 'bank';
550  $bookkeeping->fk_doc = $key;
551  $bookkeeping->fk_docdet = $val["fk_bank"];
552  $bookkeeping->label_operation = $reflabel;
553  $bookkeeping->montant = $mt;
554  $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
555  $bookkeeping->debit = ($mt < 0 ? - $mt : 0);
556  $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
557  $bookkeeping->code_journal = $journal;
558  $bookkeeping->journal_label = $journal_label;
559  $bookkeeping->fk_user_author = $user->id;
560  $bookkeeping->date_create = $now;
561 
562  if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice
563  $bookkeeping->subledger_account = $tabcompany[$key]['code_compta'];
564  $bookkeeping->subledger_label = $tabcompany[$key]['name'];
565  $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
566 
567  $accountingaccount->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, true);
568  $bookkeeping->label_compte = $accountingaccount->label;
569  } else if ($tabtype[$key] == 'payment_supplier') { // If payment is payment of supplier invoice, we get ref of invoice
570  $bookkeeping->subledger_account = $tabcompany[$key]['code_compta'];
571  $bookkeeping->subledger_label = $tabcompany[$key]['name'];
572  $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
573 
574  $accountingaccount->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, true);
575  $bookkeeping->label_compte = $accountingaccount->label;
576  } else if ($tabtype[$key] == 'payment_expensereport') {
577  $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code'];
578  $bookkeeping->subledger_label = $tabuser[$key]['name'];
579  $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
580 
581  $accountingaccount->fetch(null, $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT, true);
582  $bookkeeping->label_compte = $accountingaccount->label;
583  } else if ($tabtype[$key] == 'payment_salary') {
584  $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code'];
585  $bookkeeping->subledger_label = $tabuser[$key]['name'];
586  $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
587 
588  $accountingaccount->fetch(null, $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT, true);
589  $bookkeeping->label_compte = $accountingaccount->label;
590  } else if (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution
591  $bookkeeping->subledger_account = '';
592  $bookkeeping->subledger_label = '';
593  $bookkeeping->numero_compte = $k;
594  $bookkeeping->label_compte = $objmid->labelc;
595  } else if ($tabtype[$key] == 'payment_vat') {
596  $bookkeeping->subledger_account = '';
597  $bookkeeping->subledger_label = '';
598  $bookkeeping->numero_compte = $k;
599 
600  $accountingaccount->fetch(null, $k, true);
601  $bookkeeping->label_compte = $accountingaccount->label;
602  } else if ($tabtype[$key] == 'payment_donation') {
603  $bookkeeping->subledger_account = '';
604  $bookkeeping->subledger_label = '';
605  $bookkeeping->numero_compte = $k;
606 
607  $accountingaccount->fetch(null, $k, true);
608  $bookkeeping->label_compte = $accountingaccount->label;
609  } else if ($tabtype[$key] == 'member') {
610  $bookkeeping->subledger_account = '';
611  $bookkeeping->subledger_label = '';
612  $bookkeeping->numero_compte = $k;
613 
614  $accountingaccount->fetch(null, $k, true);
615  $bookkeeping->label_compte = $accountingaccount->label;
616  } else if ($tabtype[$key] == 'payment_loan') {
617  $bookkeeping->subledger_account = '';
618  $bookkeeping->subledger_label = '';
619  $bookkeeping->numero_compte = $k;
620 
621  $accountingaccount->fetch(null, $k, true);
622  $bookkeeping->label_compte = $accountingaccount->label;
623  } else if ($tabtype[$key] == 'payment_various') {
624  $bookkeeping->subledger_account = '';
625  $bookkeeping->subledger_label = '';
626  $bookkeeping->numero_compte = $k;
627 
628  $accountingaccount->fetch(null, $k, true);
629  $bookkeeping->label_compte = $accountingaccount->label;
630  } else if ($tabtype[$key] == 'banktransfert') {
631  $bookkeeping->subledger_account = '';
632  $bookkeeping->subledger_label = '';
633  $bookkeeping->numero_compte = $k;
634 
635  $accountingaccount->fetch(null, $k, true);
636  $bookkeeping->label_compte = $accountingaccount->label;
637  } else {
638  if ($tabtype[$key] == 'unknown') // Unknown transaction, we will use a waiting account for thirdparty.
639  {
640  // Temporary account
641  $bookkeeping->subledger_account = '';
642  $bookkeeping->subledger_label = '';
643  $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE;
644 
645  $accountingaccount->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE, true);
646  $bookkeeping->label_compte = $accountingaccount->label;
647  }
648  }
649  $bookkeeping->label_operation = $reflabel;
650  $bookkeeping->entity = $conf->entity;
651 
652  $totaldebit += $bookkeeping->debit;
653  $totalcredit += $bookkeeping->credit;
654 
655  $result = $bookkeeping->create($user);
656  if ($result < 0) {
657  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
658  {
659  $error++;
660  $errorforline++;
661  setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
662  }
663  else
664  {
665  $error++;
666  $errorforline++;
667  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
668  }
669  }
670  }
671  }
672  }
673  else { // If thirdparty unkown, output the waiting account
674  foreach ( $tabbq[$key] as $k => $mt ) {
675  if ($mt)
676  {
677  $reflabel = '';
678  if (! empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib']) . " - ";
679  $reflabel.= dol_string_nohtmltag('WaitingAccount');
680 
681  $bookkeeping = new BookKeeping($db);
682  $bookkeeping->doc_date = $val["date"];
683  $bookkeeping->doc_ref = $ref;
684  $bookkeeping->doc_type = 'bank';
685  $bookkeeping->fk_doc = $key;
686  $bookkeeping->fk_docdet = $val["fk_bank"];
687  $bookkeeping->montant = $mt;
688  $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
689  $bookkeeping->debit = ($mt < 0 ? - $mt : 0);
690  $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
691  $bookkeeping->code_journal = $journal;
692  $bookkeeping->journal_label = $journal_label;
693  $bookkeeping->fk_user_author = $user->id;
694  $bookkeeping->date_create = $now;
695  $bookkeeping->label_compte = '';
696  $bookkeeping->label_operation = $reflabel;
697  $bookkeeping->entity = $conf->entity;
698 
699  $totaldebit += $bookkeeping->debit;
700  $totalcredit += $bookkeeping->credit;
701 
702  $result = $bookkeeping->create($user);
703  if ($result < 0) {
704  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
705  {
706  $error++;
707  $errorforline++;
708  setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
709  }
710  else
711  {
712  $error++;
713  $errorforline++;
714  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
715  }
716  }
717  }
718  }
719  }
720  }
721 
722  if (price2num($totaldebit) != price2num($totalcredit))
723  {
724  $error++;
725  $errorforline++;
726  setEventMessages('Try to insert a non balanced transaction in book for '.$ref.'. Canceled. Surely a bug.', null, 'errors');
727  }
728 
729  if (! $errorforline)
730  {
731  $db->commit();
732  }
733  else
734  {
735  //print 'KO for line '.$key.' '.$error.'<br>';
736  $db->rollback();
737 
738  $MAXNBERRORS=5;
739  if ($error >= $MAXNBERRORS)
740  {
741  setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped").' (>'.$MAXNBERRORS.')', null, 'errors');
742  break; // Break in the foreach
743  }
744  }
745  }
746 
747  if (empty($error) && count($tabpay) > 0) {
748  setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
749  }
750  elseif (count($tabpay) == $error)
751  {
752  setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
753  }
754  else
755  {
756  setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
757  }
758 
759  $action = '';
760 
761  // Must reload data, so we make a redirect
762  if (count($tabpay) != $error)
763  {
764  $param='id_journal='.$id_journal;
765  $param.='&date_startday='.$date_startday;
766  $param.='&date_startmonth='.$date_startmonth;
767  $param.='&date_startyear='.$date_startyear;
768  $param.='&date_endday='.$date_endday;
769  $param.='&date_endmonth='.$date_endmonth;
770  $param.='&date_endyear='.$date_endyear;
771  $param.='&in_bookkeeping='.$in_bookkeeping;
772  header("Location: ".$_SERVER['PHP_SELF'].($param?'?'.$param:''));
773  exit;
774  }
775 }
776 
777 
778 
779 // Export
780 if ($action == 'exportcsv') { // ISO and not UTF8 !
781  $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
782 
783  $filename = 'journal';
784  $type_export = 'journal';
785  include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
786 
787  // CSV header line
788  print '"' . $langs->trans("BankId").'"' . $sep;
789  print '"' . $langs->trans("Date") . '"' . $sep;
790  print '"' . $langs->trans("PaymentMode") . '"' . $sep;
791  print '"' . $langs->trans("AccountAccounting") . '"' . $sep;
792  print '"' . $langs->trans("LedgerAccount") . '"' . $sep;
793  print '"' . $langs->trans("SubledgerAccount") . '"' . $sep;
794  print '"' . $langs->trans("Label"). '"' . $sep;
795  print '"' . $langs->trans("Debit") . '"' . $sep;
796  print '"' . $langs->trans("Credit") . '"' . $sep;
797  print '"' . $langs->trans("Journal") . '"' . $sep;
798  print '"' . $langs->trans("Note") . '"' . $sep;
799  print "\n";
800 
801 
802  foreach ( $tabpay as $key => $val )
803  {
804  $date = dol_print_date($db->jdate($val["date"]), 'day');
805 
806  $ref = getSourceDocRef($val, $tabtype[$key]);
807 
808  // Bank
809  foreach ( $tabbq[$key] as $k => $mt ) {
810  if ($mt)
811  {
812  $reflabel = '';
813  if (! empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib']) . " - ";
814  $reflabel.= $langs->trans("Bank").' '.dol_string_nohtmltag($val['bank_account_ref']);
815  if (! empty($val['soclib'])) $reflabel .= " - " . dol_string_nohtmltag($val['soclib']);
816 
817  print '"' . $key . '"' . $sep;
818  print '"' . $date . '"' . $sep;
819  print '"' . $val["type_payment"] . '"' . $sep;
820  print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
821  print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
822  print " " . $sep;
823  print '"' . $reflabel . '"' . $sep;
824  print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
825  print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
826  print '"' . $journal . '"' . $sep;
827  print '"' . dol_string_nohtmltag($ref) . '"' . $sep;
828  print "\n";
829  }
830  }
831 
832  // Third party
833  if (is_array($tabtp[$key])) {
834  foreach ( $tabtp[$key] as $k => $mt ) {
835  if ($mt)
836  {
837  $reflabel = '';
838  if (! empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib']) . ($val['soclib']?" - ":"");
839  $reflabel.= dol_string_nohtmltag($val['soclib']);
840 
841  print '"' . $key . '"' . $sep;
842  print '"' . $date . '"' . $sep;
843  print '"' . $val["type_payment"] . '"' . $sep;
844  print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
845  if ($tabtype[$key] == 'payment_supplier') {
846  print '"' . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . '"' . $sep;
847  } else if($tabtype[$key] == 'payment') {
848  print '"' . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . '"' . $sep;
849  } else if($tabtype[$key] == 'payment_expensereport') {
850  print '"' . $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT . '"' . $sep;
851  } else if($tabtype[$key] == 'payment_salary') {
852  print '"' . $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT . '"' . $sep;
853  } else {
854  print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
855  }
856  print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
857  print '"' . $reflabel . '"' . $sep;
858  print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
859  print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
860  print '"' . $journal . '"' . $sep;
861  print '"' . dol_string_nohtmltag($ref) . '"' . $sep;
862  print "\n";
863  }
864  }
865  } else { // If thirdparty unkown, output the waiting account
866  foreach ( $tabbq[$key] as $k => $mt ) {
867  if ($mt)
868  {
869  $reflabel = '';
870  if (! empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib']) . " - ";
871  $reflabel.= dol_string_nohtmltag('WaitingAccount');
872 
873  print '"' . $key . '"' . $sep;
874  print '"' . $date . '"' . $sep;
875  print '"' . $val["type_payment"] . '"' . $sep;
876  print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep;
877  print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep;
878  print "" . $sep;
879  print '"' . $reflabel . '"' . $sep;
880  print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
881  print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
882  print '"' . $journal . '"' . $sep;
883  print '"' . dol_string_nohtmltag($ref) . '"' . $sep;
884  print "\n";
885  }
886  }
887  }
888  }
889 }
890 
891 
892 /*
893  * View
894  */
895 
896 $form = new Form($db);
897 
898 if (empty($action) || $action == 'view') {
899  $invoicestatic = new Facture($db);
900  $invoicesupplierstatic = new FactureFournisseur($db);
901  $expensereportstatic = new ExpenseReport($db);
902  $vatstatic = new Tva($db);
903  $donationstatic = new Don($db);
904  $loanstatic = new Loan($db);
905  $salarystatic = new PaymentSalary($db);
906  $variousstatic = new PaymentVarious($db);
907 
908  llxHeader('', $langs->trans("FinanceJournal"));
909 
910  $nom = $langs->trans("FinanceJournal") . ' | ' . $accountingjournalstatic->getNomUrl(0,1,1,'',1);
911  $builddate=dol_now();
912  //$description = $langs->trans("DescFinanceJournal") . '<br>';
913  $description.= $langs->trans("DescJournalOnlyBindedVisible").'<br>';
914 
915  $listofchoices=array('notyet'=>$langs->trans("NotYetInGeneralLedger"), 'already'=>$langs->trans("AlreadyInGeneralLedger"));
916  $period = $form->selectDate($date_start?$date_start:-1, 'date_start', 0, 0, 0, '', 1, 0) . ' - ' . $form->selectDate($date_end?$date_end:-1, 'date_end', 0, 0, 0, '', 1, 0);
917  $period .= ' - ' .$langs->trans("JournalizationInLedgerStatus").' '. $form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
918 
919  $varlink = 'id_journal=' . $id_journal;
920 
921  journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
922 
923 
924  // Test that setup is complete
925  $sql = 'SELECT COUNT(rowid) as nb FROM '.MAIN_DB_PREFIX.'bank_account WHERE fk_accountancy_journal IS NULL AND clos=0';
926  $resql = $db->query($sql);
927  if ($resql)
928  {
929  $obj = $db->fetch_object($resql);
930  if ($obj->nb > 0)
931  {
932  print '<br>'.img_warning().' '.$langs->trans("TheJournalCodeIsNotDefinedOnSomeBankAccount");
933  print ' : '.$langs->trans("AccountancyAreaDescBank", 9, '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("BankAccounts").'</strong>');
934  }
935  }
936  else dol_print_error($db);
937 
938 
939  // Button to write into Ledger
940  if (empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1'
941  || empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1'
942  || empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') {
943  print '<br>'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
944  print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>');
945  }
946 
947 
948  print '<div class="tabsAction tabsActionNoBottom">';
949 
950  if (! empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL)) print '<input type="button" class="butAction" name="exportcsv" value="' . $langs->trans("ExportDraftJournal") . '" onclick="launch_export();" />';
951 
952  if (empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1'
953  || empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1'
954  || empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') {
955  print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="' . $langs->trans("WriteBookKeeping") . '" />';
956  }
957  else {
958  if ($in_bookkeeping == 'notyet') print '<input type="button" class="butAction" name="writebookkeeping" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
959  else print '<a class="butActionRefused classfortooltip" name="writebookkeeping">' . $langs->trans("WriteBookKeeping") . '</a>';
960  }
961  print '</div>';
962 
963  // TODO Avoid using js. We can use a direct link with $param
964  print '
965  <script type="text/javascript">
966  function launch_export() {
967  console.log("Set value into form and submit");
968  $("div.fiche form input[name=\"action\"]").val("exportcsv");
969  $("div.fiche form input[type=\"submit\"]").click();
970  $("div.fiche form input[name=\"action\"]").val("");
971  }
972  function writebookkeeping() {
973  console.log("Set value into form and submit");
974  $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
975  $("div.fiche form input[type=\"submit\"]").click();
976  $("div.fiche form input[name=\"action\"]").val("");
977  }
978  </script>';
979 
980  /*
981  * Show result array
982  */
983  print '<br>';
984 
985  $i = 0;
986  print '<div class="div-table-responsive">';
987  print "<table class=\"noborder\" width=\"100%\">";
988  print "<tr class=\"liste_titre\">";
989  print "<td></td>";
990  print "<td>" . $langs->trans("Date") . "</td>";
991  print "<td>" . $langs->trans("Piece") . ' (' . $langs->trans("ObjectsRef") . ")</td>";
992  print "<td>" . $langs->trans("AccountAccounting") . "</td>";
993  print "<td>" . $langs->trans("SubledgerAccount") . "</td>";
994  print "<td>" . $langs->trans("LabelOperation") . "</td>";
995  print "<td>" . $langs->trans("PaymentMode") . "</td>";
996  print "<td align='right'>" . $langs->trans("Debit") . "</td>";
997  print "<td align='right'>" . $langs->trans("Credit") . "</td>";
998  print "</tr>\n";
999 
1000  $r = '';
1001 
1002  foreach ( $tabpay as $key => $val ) // $key is rowid in llx_bank
1003  {
1004  $date = dol_print_date($db->jdate($val["date"]), 'day');
1005 
1006  $ref = getSourceDocRef($val, $tabtype[$key]);
1007 
1008  // Bank
1009  foreach ( $tabbq[$key] as $k => $mt )
1010  {
1011  if ($mt)
1012  {
1013  $reflabel = '';
1014  if (! empty($val['lib'])) $reflabel .= $val['lib'] . " - ";
1015  $reflabel.= $langs->trans("Bank").' '.$val['bank_account_ref'];
1016  if (! empty($val['soclib'])) $reflabel .= " - " . $val['soclib'];
1017 
1018  //var_dump($tabpay[$key]);
1019  print '<!-- Bank bank.rowid='.$key.' type='.$tabpay[$key]['type'].' ref='.$tabpay[$key]['ref'].'-->';
1020  print '<tr class="oddeven">';
1021  print "<td></td>";
1022  print "<td>" . $date . "</td>";
1023  print "<td>" . $ref . "</td>";
1024  // Ledger account
1025  print "<td>";
1026  $accounttoshow = length_accountg($k);
1027  if (empty($accounttoshow) || $accounttoshow == 'NotDefined')
1028  {
1029  print '<span class="error">'.$langs->trans("BankAccountNotDefined").'</span>';
1030  }
1031  else print $accounttoshow;
1032  print "</td>";
1033  // Subledger account
1034  print "<td>";
1035  /*$accounttoshow = length_accountg($k);
1036  if (empty($accounttoshow) || $accounttoshow == 'NotDefined')
1037  {
1038  print '<span class="error">'.$langs->trans("BankAccountNotDefined").'</span>';
1039  }
1040  else print $accounttoshow;*/
1041  print "</td>";
1042  print "<td>";
1043  print $reflabel;
1044  print "</td>";
1045  print "<td>" . $val["type_payment"] . "</td>";
1046  print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
1047  print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
1048  print "</tr>";
1049  }
1050  }
1051 
1052  // Third party
1053  if (is_array($tabtp[$key])) {
1054  foreach ( $tabtp[$key] as $k => $mt ) {
1055  if ($mt)
1056  {
1057  $reflabel = '';
1058  if (! empty($val['lib'])) $reflabel .= $val['lib'] . ($val['soclib']?" - ":"");
1059  $reflabel.= $val['soclib'];
1060 
1061  print '<!-- Thirdparty bank.rowid='.$key.' -->';
1062  print '<tr class="oddeven">';
1063  print "<td></td>";
1064  print "<td>" . $date . "</td>";
1065  print "<td>" . $ref . "</td>";
1066  // Ledger account
1067  print "<td>";
1068  $account_ledger = $k;
1069  // Try to force general ledger account depending on type
1070  if ($tabtype[$key] == 'payment') $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
1071  if ($tabtype[$key] == 'payment_supplier') $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
1072  if ($tabtype[$key] == 'payment_expensereport') $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
1073  if ($tabtype[$key] == 'payment_salary') $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
1074  if ($tabtype[$key] == 'payment_vat') $account_ledger = $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT;
1075  if ($tabtype[$key] == 'member') $account_ledger = $conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT;
1076 
1077  $accounttoshow = length_accounta($account_ledger);
1078  if (empty($accounttoshow) || $accounttoshow == 'NotDefined')
1079  {
1080  if ($tabtype[$key] == 'unknown')
1081  {
1082  // We will accept writing, but into a waiting account
1083  if (empty($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) || $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE == '-1')
1084  {
1085  print '<span class="error">'.$langs->trans('UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').'</span>';
1086  }
1087  else
1088  {
1089  print '<span class="warning">'.$langs->trans('UnknownAccountForThirdparty', length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE)).'</span>'; // We will a waiting account
1090  }
1091  }
1092  else
1093  {
1094  // We will refuse writing
1095  $errorstring='UnknownAccountForThirdpartyBlocking';
1096  if ($tabtype[$key] == 'payment') $errorstring='MainAccountForCustomersNotDefined';
1097  if ($tabtype[$key] == 'payment_supplier') $errorstring='MainAccountForSuppliersNotDefined';
1098  if ($tabtype[$key] == 'payment_expensereport') $errorstring='MainAccountForUsersNotDefined';
1099  if ($tabtype[$key] == 'payment_salary') $errorstring='MainAccountForUsersNotDefined';
1100  if ($tabtype[$key] == 'payment_vat') $errorstring='MainAccountForVatPaymentNotDefined';
1101  if ($tabtype[$key] == 'member') $errorstring='MainAccountForSubscriptionPaymentNotDefined';
1102  print '<span class="error">'.$langs->trans($errorstring).'</span>';
1103  }
1104  }
1105  else print $accounttoshow;
1106  print "</td>";
1107  // Subledger account
1108  print "<td>";
1109  if (in_array($tabtype[$key], array('payment', 'payment_supplier', 'payment_expensereport', 'payment_salary'))) // Type of payment with subledger
1110  {
1111  $accounttoshowsubledger = length_accounta($k);
1112  if ($accounttoshow != $accounttoshowsubledger)
1113  {
1114  if (empty($accounttoshowsubledger) || $accounttoshowsubledger == 'NotDefined')
1115  {
1116  /*var_dump($tabpay[$key]);
1117  var_dump($tabtype[$key]);
1118  var_dump($tabbq[$key]);*/
1119  //print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
1120  print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknown").'</span>';
1121  }
1122  else print $accounttoshowsubledger;
1123  }
1124  }
1125  print "</td>";
1126  print "<td>" . $reflabel . "</td>";
1127  print "<td>" . $val["type_payment"] . "</td>";
1128  print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
1129  print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
1130  print "</tr>";
1131  }
1132  }
1133  } else { // Waiting account
1134  foreach ( $tabbq[$key] as $k => $mt ) {
1135  if ($mt)
1136  {
1137  $reflabel = '';
1138  if (! empty($val['lib'])) $reflabel .= $val['lib'] . " - ";
1139  $reflabel.= 'WaitingAccount';
1140 
1141  print '<!-- Wait bank.rowid='.$key.' -->';
1142  print '<tr class="oddeven">';
1143  print "<td></td>";
1144  print "<td>" . $date . "</td>";
1145  print "<td>" . $ref . "</td>";
1146  // Ledger account
1147  print "<td>";
1148  /*if (empty($accounttoshow) || $accounttoshow == 'NotDefined')
1149  {
1150  print '<span class="error">'.$langs->trans("WaitAccountNotDefined").'</span>';
1151  }
1152  else */ print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE);
1153  print "</td>";
1154  // Subledger account
1155  print "<td>";
1156  /*if (empty($accounttoshowsubledger) || $accounttoshowsubledger == 'NotDefined')
1157  {
1158  print '<span class="error">'.$langs->trans("WaitAccountNotDefined").'</span>';
1159  }
1160  else print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE);
1161  */
1162  print "</td>";
1163  print "<td>" . $reflabel . "</td>";
1164  print "<td>" . $val["type_payment"] . "</td>";
1165  print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
1166  print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
1167  print "</tr>";
1168  }
1169  }
1170  }
1171  }
1172 
1173  print "</table>";
1174  print '</div>';
1175 
1176  llxFooter();
1177 }
1178 
1179 $db->close();
1180 
1181 
1182 
1190 function getSourceDocRef($val, $typerecord)
1191 {
1192  global $db, $langs;
1193 
1194  // Defined the docref into $ref (We start with $val['ref'] by default and we complete according to other data)
1195  // WE MUST HAVE SAME REF FOR ALL LINES WE WILL RECORD INTO THE BOOKKEEPING
1196  $ref = $val['ref'];
1197  if ($ref == '(SupplierInvoicePayment)' || $ref == '(SupplierInvoicePaymentBack)') {
1198  $ref = $langs->transnoentitiesnoconv('Supplier');
1199  }
1200  if ($ref == '(CustomerInvoicePayment)' || $ref == '(CustomerInvoicePaymentBack)') {
1201  $ref = $langs->transnoentitiesnoconv('Customer');
1202  }
1203  if ($ref == '(SocialContributionPayment)') {
1204  $ref = $langs->transnoentitiesnoconv('SocialContribution');
1205  }
1206  if ($ref == '(DonationPayment)') {
1207  $ref = $langs->transnoentitiesnoconv('Donation');
1208  }
1209  if ($ref == '(SubscriptionPayment)') {
1210  $ref = $langs->transnoentitiesnoconv('Subscription');
1211  }
1212  if ($ref == '(ExpenseReportPayment)') {
1213  $ref = $langs->transnoentitiesnoconv('Employee');
1214  }
1215  if ($ref == '(LoanPayment)') {
1216  $ref = $langs->transnoentitiesnoconv('Loan');
1217  }
1218  if ($ref == '(payment_salary)') {
1219  $ref = $langs->transnoentitiesnoconv('Employee');
1220  }
1221 
1222  $sqlmid = '';
1223  if ($typerecord == 'payment')
1224  {
1225  $sqlmid = 'SELECT payfac.fk_facture as id, f.facnumber as ref';
1226  $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiement_facture as payfac, ".MAIN_DB_PREFIX."facture as f";
1227  $sqlmid .= " WHERE payfac.fk_facture = f.rowid AND payfac.fk_paiement=" . $val["paymentid"];
1228  $ref = $langs->transnoentitiesnoconv("Invoice");
1229  }
1230  elseif ($typerecord == 'payment_supplier')
1231  {
1232  $sqlmid = 'SELECT payfac.fk_facturefourn as id, f.ref';
1233  $sqlmid .= " FROM " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX."facture_fourn as f";
1234  $sqlmid .= " WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=" . $val["paymentsupplierid"];
1235  $ref = $langs->transnoentitiesnoconv("SupplierInvoice");
1236  }
1237  elseif ($typerecord == 'payment_expensereport')
1238  {
1239  $sqlmid = 'SELECT e.rowid as id, e.ref';
1240  $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_expensereport as pe, " . MAIN_DB_PREFIX . "expensereport as e";
1241  $sqlmid .= " WHERE pe.rowid=" . $val["paymentexpensereport"]." AND pe.fk_expensereport = e.rowid";
1242  $ref = $langs->transnoentitiesnoconv("ExpenseReport");
1243  }
1244  elseif ($typerecord == 'payment_salary')
1245  {
1246  $sqlmid = 'SELECT s.rowid as ref';
1247  $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_salary as s";
1248  $sqlmid .= " WHERE s.rowid=" . $val["paymentsalid"];
1249  $ref = $langs->transnoentitiesnoconv("SalaryPayment");
1250  }
1251  elseif ($typerecord == 'sc')
1252  {
1253  $sqlmid = 'SELECT sc.rowid as ref';
1254  $sqlmid .= " FROM " . MAIN_DB_PREFIX . "paiementcharge as sc";
1255  $sqlmid .= " WHERE sc.rowid=" . $val["paymentscid"];
1256  $ref = $langs->transnoentitiesnoconv("SocialContribution");
1257  }
1258  elseif ($typerecord == 'payment_vat')
1259  {
1260  $sqlmid = 'SELECT v.rowid as ref';
1261  $sqlmid .= " FROM " . MAIN_DB_PREFIX . "tva as v";
1262  $sqlmid .= " WHERE v.rowid=" . $val["paymentvatid"];
1263  $ref = $langs->transnoentitiesnoconv("PaymentVat");
1264  }
1265  elseif ($typerecord == 'payment_donation')
1266  {
1267  $sqlmid = 'SELECT payd.fk_donation as ref';
1268  $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_donation as payd";
1269  $sqlmid .= " WHERE payd.fk_donation=" . $val["paymentdonationid"];
1270  $ref = $langs->transnoentitiesnoconv("Donation");
1271  }
1272  elseif ($typerecord == 'payment_loan')
1273  {
1274  $sqlmid = 'SELECT l.rowid as ref';
1275  $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_loan as l";
1276  $sqlmid .= " WHERE l.rowid=" . $val["paymentloanid"];
1277  $ref = $langs->transnoentitiesnoconv("LoanPayment");
1278  }
1279  elseif ($typerecord == 'payment_various')
1280  {
1281  $sqlmid = 'SELECT v.rowid as ref';
1282  $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_various as v";
1283  $sqlmid .= " WHERE v.rowid=" . $val["paymentvariousid"];
1284  $ref = $langs->transnoentitiesnoconv("VariousPayment");
1285  }
1286  // Add warning
1287  if (empty($sqlmid))
1288  {
1289  dol_syslog("Found a typerecord=".$typerecord." not supported", LOG_WARNING);
1290  }
1291 
1292  if ($sqlmid)
1293  {
1294  dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG);
1295  $resultmid = $db->query($sqlmid);
1296  if ($resultmid)
1297  {
1298  while ($objmid = $db->fetch_object($resultmid))
1299  {
1300  $ref.=' '.$objmid->ref;
1301  }
1302  }
1303  else dol_print_error($db);
1304  }
1305 
1306  $ref = dol_trunc($langs->transnoentitiesnoconv("BankId").' '.$val['fk_bank'].' - '.$ref, 295); // 295 + 3 dots (...) is < than max size of 300
1307  return $ref;
1308 }
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Loan.
Definition: loan.class.php:30
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
Class to manage various payments.
Class to manage salary payments.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:453
Class to manage bank transaction lines.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage suppliers invoices.
Class to manage bank accounts.
Put here description of your class.
Definition: tva.class.php:35
Class to manage Ledger (General Ledger and Subledger)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting a parameter.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage payments of loans.
Class to manage payments of customer invoices.
llxHeader()
Empty header.
Definition: wrapper.php:44
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
getSourceDocRef($val, $typerecord)
Return source for doc_ref of a bank transaction.
dol_now($mode='gmt')
Return date for now.
Class to manage Trips and Expenses.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0)
Clean a string from all HTML tags and entities.
Class to manage subscriptions of foundation members.
Class to manage payments of donations.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:467
Class to manage donations.
Definition: don.class.php:35
Class to manage payments of expense report.
Class to manage accounting accounts.
Class to manage accounting accounts.
Class to manage invoices.
Class to manage payments for supplier invoices.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
Classe permettant la gestion des paiements des charges La tva collectee n&#39;est calculee que sur les fa...
journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a VAT report.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.