dolibarr  16.0.5
clientfourn.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
6  * Copyright (C) 2012-2014 Raphaël Dourseanud <rdoursenaud@gpcsolutions.fr>
7  * Copyright (C) 2014-2106 Ferran Marcet <fmarcet@2byte.es>
8  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
10  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
11  * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
12  * Copyright (C) 2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <https://www.gnu.org/licenses/>.
26  */
27 
34 require '../../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
41 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
44 
45 // Load translation files required by the page
46 $langs->loadLangs(array('compta', 'bills', 'donation', 'salaries', 'accountancy', 'loan'));
47 
48 $date_startmonth = GETPOST('date_startmonth', 'int');
49 $date_startday = GETPOST('date_startday', 'int');
50 $date_startyear = GETPOST('date_startyear', 'int');
51 $date_endmonth = GETPOST('date_endmonth', 'int');
52 $date_endday = GETPOST('date_endday', 'int');
53 $date_endyear = GETPOST('date_endyear', 'int');
54 $showaccountdetail = GETPOST('showaccountdetail', 'aZ09') ? GETPOST('showaccountdetail', 'aZ09') : 'yes';
55 
56 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
57 $sortfield = GETPOST('sortfield', 'aZ09comma');
58 $sortorder = GETPOST('sortorder', 'aZ09comma');
59 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
60 if (empty($page) || $page == -1) {
61  $page = 0;
62 } // If $page is not defined, or '' or -1
63 $offset = $limit * $page;
64 $pageprev = $page - 1;
65 $pagenext = $page + 1;
66 //if (! $sortfield) $sortfield='s.nom, s.rowid';
67 if (!$sortorder) {
68  $sortorder = 'ASC';
69 }
70 
71 // Date range
72 $year = GETPOST('year', 'int');
73 if (empty($year)) {
74  $year_current = dol_print_date(dol_now(), "%Y");
75  $month_current = dol_print_date(dol_now(), "%m");
76  $year_start = $year_current;
77 } else {
78  $year_current = $year;
79  $month_current = dol_print_date(dol_now(), "%m");
80  $year_start = $year;
81 }
82 $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
83 $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
84 
85 // We define date_start and date_end
86 if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
87  $q = GETPOST("q") ?GETPOST("q") : 0;
88  if ($q == 0) {
89  // We define date_start and date_end
90  $year_end = $year_start;
91  $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
92  if (!GETPOST('month')) {
93  if (!GETPOST("year") && $month_start > $month_current) {
94  $year_start--;
95  $year_end--;
96  }
97  $month_end = $month_start - 1;
98  if ($month_end < 1) {
99  $month_end = 12;
100  } else {
101  $year_end++;
102  }
103  } else {
104  $month_end = $month_start;
105  }
106  $date_start = dol_get_first_day($year_start, $month_start, false);
107  $date_end = dol_get_last_day($year_end, $month_end, false);
108  }
109  if ($q == 1) {
110  $date_start = dol_get_first_day($year_start, 1, false);
111  $date_end = dol_get_last_day($year_start, 3, false);
112  }
113  if ($q == 2) {
114  $date_start = dol_get_first_day($year_start, 4, false);
115  $date_end = dol_get_last_day($year_start, 6, false);
116  }
117  if ($q == 3) {
118  $date_start = dol_get_first_day($year_start, 7, false);
119  $date_end = dol_get_last_day($year_start, 9, false);
120  }
121  if ($q == 4) {
122  $date_start = dol_get_first_day($year_start, 10, false);
123  $date_end = dol_get_last_day($year_start, 12, false);
124  }
125 }
126 
127 // $date_start and $date_end are defined. We force $year_start and $nbofyear
128 $tmps = dol_getdate($date_start);
129 $year_start = $tmps['year'];
130 $tmpe = dol_getdate($date_end);
131 $year_end = $tmpe['year'];
132 $nbofyear = ($year_end - $year_start) + 1;
133 //var_dump("year_start=".$year_start." year_end=".$year_end." nbofyear=".$nbofyear." date_start=".dol_print_date($date_start, 'dayhour')." date_end=".dol_print_date($date_end, 'dayhour'));
134 
135 // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
136 $modecompta = $conf->global->ACCOUNTING_MODE;
137 if (isModEnabled('accounting')) {
138  $modecompta = 'BOOKKEEPING';
139 }
140 if (GETPOST("modecompta", 'alpha')) {
141  $modecompta = GETPOST("modecompta", 'alpha');
142 }
143 
144 $AccCat = new AccountancyCategory($db);
145 
146 // Security check
147 $socid = GETPOST('socid', 'int');
148 if ($user->socid > 0) {
149  $socid = $user->socid;
150 }
151 if (isModEnabled('comptabilite')) {
152  $result = restrictedArea($user, 'compta', '', '', 'resultat');
153 }
154 if (isModEnabled('accounting')) {
155  $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
156 }
157 
158 
159 /*
160  * View
161  */
162 
163 llxHeader();
164 
165 $form = new Form($db);
166 
167 $periodlink = '';
168 $exportlink = '';
169 
170 $total_ht = 0;
171 $total_ttc = 0;
172 
173 // Affiche en-tete de rapport
174 if ($modecompta == "CREANCES-DETTES") {
175  $name = $langs->trans("ReportInOut").', '.$langs->trans("ByPredefinedAccountGroups");
176  $calcmode = $langs->trans("CalcModeDebt");
177  $calcmode .= '<br>('.$langs->trans("SeeReportInInputOutputMode", '{s1}', '{s2}').')';
178  $calcmode = str_replace(array('{s1}', '{s2}'), array('<a href="'.$_SERVER["PHP_SELF"].'?date_startyear='.$tmps['year'].'&date_startmonth='.$tmps['mon'].'&date_startday='.$tmps['mday'].'&date_endyear='.$tmpe['year'].'&date_endmonth='.$tmpe['mon'].'&date_endday='.$tmpe['mday'].'&modecompta=RECETTES-DEPENSES">', '</a>'), $calcmode);
179  if (isModEnabled('accounting')) {
180  $calcmode .= '<br>('.$langs->trans("SeeReportInBookkeepingMode", '{s1}', '{s2}').')';
181  $calcmode = str_replace(array('{s1}', '{s2}'), array('<a href="'.$_SERVER["PHP_SELF"].'?date_startyear='.$tmps['year'].'&date_startmonth='.$tmps['mon'].'&date_startday='.$tmps['mday'].'&date_endyear='.$tmpe['year'].'&date_endmonth='.$tmpe['mon'].'&date_endday='.$tmpe['mday'].'&modecompta=BOOKKEEPING">', '</a>'), $calcmode);
182  }
183  $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
184  $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] - 1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] + 1)."&modecompta=".$modecompta."'>".img_next()."</a>" : "");
185  $description = $langs->trans("RulesResultDue");
186  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
187  $description .= $langs->trans("DepositsAreNotIncluded");
188  } else {
189  $description .= $langs->trans("DepositsAreIncluded");
190  }
191  if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
192  $description .= $langs->trans("SupplierDepositsAreNotIncluded");
193  }
194  $builddate = dol_now();
195  //$exportlink=$langs->trans("NotYetAvailable");
196 } elseif ($modecompta == "RECETTES-DEPENSES") {
197  $name = $langs->trans("ReportInOut").', '.$langs->trans("ByPredefinedAccountGroups");
198  $calcmode = $langs->trans("CalcModeEngagement");
199  $calcmode .= '<br>('.$langs->trans("SeeReportInDueDebtMode", '{s1}', '{s2}').')';
200  $calcmode = str_replace(array('{s1}', '{s2}'), array('<a href="'.$_SERVER["PHP_SELF"].'?date_startyear='.$tmps['year'].'&date_startmonth='.$tmps['mon'].'&date_startday='.$tmps['mday'].'&date_endyear='.$tmpe['year'].'&date_endmonth='.$tmpe['mon'].'&date_endday='.$tmpe['mday'].'&modecompta=CREANCES-DETTES">', '</a>'), $calcmode);
201  if (isModEnabled('accounting')) {
202  $calcmode .= '<br>('.$langs->trans("SeeReportInBookkeepingMode", '{s1}', '{s2}').')';
203  $calcmode = str_replace(array('{s1}', '{s2}'), array('<a href="'.$_SERVER["PHP_SELF"].'?date_startyear='.$tmps['year'].'&date_startmonth='.$tmps['mon'].'&date_startday='.$tmps['mday'].'&date_endyear='.$tmpe['year'].'&date_endmonth='.$tmpe['mon'].'&date_endday='.$tmpe['mday'].'&modecompta=BOOKKEEPING">', '</a>'), $calcmode);
204  }
205  $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
206  $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] - 1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] + 1)."&modecompta=".$modecompta."'>".img_next()."</a>" : "");
207  $description = $langs->trans("RulesResultInOut");
208  $builddate = dol_now();
209  //$exportlink=$langs->trans("NotYetAvailable");
210 } elseif ($modecompta == "BOOKKEEPING") {
211  $name = $langs->trans("ReportInOut").', '.$langs->trans("ByPredefinedAccountGroups");
212  $calcmode = $langs->trans("CalcModeBookkeeping");
213  $calcmode .= '<br>('.$langs->trans("SeeReportInInputOutputMode", '{s1}', '{s2}').')';
214  $calcmode = str_replace(array('{s1}', '{s2}'), array('<a href="'.$_SERVER["PHP_SELF"].'?date_startyear='.$tmps['year'].'&date_startmonth='.$tmps['mon'].'&date_startday='.$tmps['mday'].'&date_endyear='.$tmpe['year'].'&date_endmonth='.$tmpe['mon'].'&date_endday='.$tmpe['mday'].'&modecompta=RECETTES-DEPENSES">', '</a>'), $calcmode);
215  $calcmode .= '<br>('.$langs->trans("SeeReportInDueDebtMode", '{s1}', '{s2}').')';
216  $calcmode = str_replace(array('{s1}', '{s2}'), array('<a href="'.$_SERVER["PHP_SELF"].'?date_startyear='.$tmps['year'].'&date_startmonth='.$tmps['mon'].'&date_startday='.$tmps['mday'].'&date_endyear='.$tmpe['year'].'&date_endmonth='.$tmpe['mon'].'&date_endday='.$tmpe['mday'].'&modecompta=CREANCES-DETTES">', '</a>'), $calcmode);
217  $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
218  $arraylist = array('no'=>$langs->trans("CustomerCode"), 'yes'=>$langs->trans("AccountWithNonZeroValues"), 'all'=>$langs->trans("All"));
219  $period .= ' &nbsp; &nbsp; '.$langs->trans("DetailByAccount").' '.$form->selectarray('showaccountdetail', $arraylist, $showaccountdetail, 0);
220  $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] - 1)."&modecompta=".$modecompta."&showaccountdetail=".$showaccountdetail."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] + 1)."&modecompta=".$modecompta."&showaccountdetail=".$showaccountdetail."'>".img_next()."</a>" : "");
221  $description = $langs->trans("RulesResultBookkeepingPredefined");
222  $description .= ' ('.$langs->trans("SeePageForSetup", DOL_URL_ROOT.'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv("Accountancy").' / '.$langs->transnoentitiesnoconv("Setup").' / '.$langs->transnoentitiesnoconv("Chartofaccounts")).')';
223  $builddate = dol_now();
224  //$exportlink=$langs->trans("NotYetAvailable");
225 }
226 
227 $hselected = 'report';
228 
229 report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array('modecompta'=>$modecompta, 'showaccountdetail'=>$showaccountdetail), $calcmode);
230 
231 if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
232  print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
233 }
234 
235 // Show report array
236 $param = '&modecompta='.urlencode($modecompta).'&showaccountdetail='.urlencode($showaccountdetail);
237 if ($date_startday) {
238  $param .= '&date_startday='.$date_startday;
239 }
240 if ($date_startmonth) {
241  $param .= '&date_startmonth='.$date_startmonth;
242 }
243 if ($date_startyear) {
244  $param .= '&date_startyear='.$date_startyear;
245 }
246 if ($date_endday) {
247  $param .= '&date_endday='.$date_endday;
248 }
249 if ($date_endmonth) {
250  $param .= '&date_endmonth='.$date_endmonth;
251 }
252 if ($date_endyear) {
253  $param .= '&date_endyear='.$date_endyear;
254 }
255 
256 print '<table class="noborder centpercent">';
257 print '<tr class="liste_titre">';
258 
259 if ($modecompta == 'BOOKKEEPING') {
260  print_liste_field_titre("PredefinedGroups", $_SERVER["PHP_SELF"], 'f.thirdparty_code,f.rowid', '', $param, '', $sortfield, $sortorder, 'width200 ');
261 } else {
262  print_liste_field_titre("", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'width200 ');
263 }
265 if ($modecompta == 'BOOKKEEPING') {
266  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], 'amount', '', $param, 'class="right"', $sortfield, $sortorder);
267 } else {
268  if ($modecompta == 'CREANCES-DETTES') {
269  print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], 'amount_ht', '', $param, 'class="right"', $sortfield, $sortorder);
270  } else {
271  print_liste_field_titre(''); // Make 4 columns in total whatever $modecompta is
272  }
273  print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], 'amount_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
274 }
275 print "</tr>\n";
276 
277 
278 $total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
279 
280 
281 if ($modecompta == 'BOOKKEEPING') {
282  $predefinedgroupwhere = "(";
283  $predefinedgroupwhere .= " (pcg_type = 'EXPENSE')";
284  $predefinedgroupwhere .= " OR ";
285  $predefinedgroupwhere .= " (pcg_type = 'INCOME')";
286  $predefinedgroupwhere .= ")";
287 
288  $charofaccountstring = $conf->global->CHARTOFACCOUNTS;
289  $charofaccountstring = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
290 
291  $sql = "SELECT -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount";
292  if ($showaccountdetail == 'no') {
293  $sql .= ", f.thirdparty_code as name";
294  }
295  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as f";
296  $sql .= ", ".MAIN_DB_PREFIX."accounting_account as aa";
297  $sql .= " WHERE f.numero_compte = aa.account_number";
298  $sql .= " AND ".$predefinedgroupwhere;
299  $sql .= " AND fk_pcg_version = '".$db->escape($charofaccountstring)."'";
300  $sql .= " AND f.entity = ".$conf->entity;
301  if (!empty($date_start) && !empty($date_end)) {
302  $sql .= " AND f.doc_date >= '".$db->idate($date_start)."' AND f.doc_date <= '".$db->idate($date_end)."'";
303  }
304  $sql .= " GROUP BY pcg_type";
305  if ($showaccountdetail == 'no') {
306  $sql .= ", name, socid"; // group by "accounting group" (INCOME/EXPENSE), then "customer".
307  }
308  $sql .= $db->order($sortfield, $sortorder);
309 
310  $oldpcgtype = '';
311 
312  dol_syslog("get bookkeeping entries", LOG_DEBUG);
313  $result = $db->query($sql);
314  if ($result) {
315  $num = $db->num_rows($result);
316  $i = 0;
317  if ($num > 0) {
318  while ($i < $num) {
319  $objp = $db->fetch_object($result);
320 
321  if ($showaccountdetail == 'no') {
322  if ($objp->pcg_type != $oldpcgtype) {
323  print '<tr class="trforbreak"><td colspan="3" class="tdforbreak">'.$objp->pcg_type.'</td></tr>';
324  $oldpcgtype = $objp->pcg_type;
325  }
326  }
327 
328  if ($showaccountdetail == 'no') {
329  print '<tr class="oddeven">';
330  print '<td></td>';
331  print '<td>';
332  print $objp->pcg_type;
333  print ($objp->name ? ' ('.$objp->name.')' : ' ('.$langs->trans("Unknown").')');
334  print "</td>\n";
335  print '<td class="right"><span class="amount">'.price($objp->amount)."</span></td>\n";
336  print "</tr>\n";
337  } else {
338  print '<tr class="oddeven trforbreak">';
339  print '<td colspan="2" class="tdforbreak">';
340  print $objp->pcg_type;
341  print "</td>\n";
342  print '<td class="right tdforbreak"><span class="amount">'.price($objp->amount)."</span></td>\n";
343  print "</tr>\n";
344  }
345 
346  $total_ht += (isset($objp->amount) ? $objp->amount : 0);
347  $total_ttc += (isset($objp->amount) ? $objp->amount : 0);
348 
349  if ($objp->pcg_type == 'INCOME') {
350  $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
351  $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
352  }
353  if ($objp->pcg_type == 'EXPENSE') {
354  $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
355  $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
356  }
357 
358  // Loop on detail of all accounts
359  // This make 14 calls for each detail of account (NP, N and month m)
360  if ($showaccountdetail != 'no') {
361  $tmppredefinedgroupwhere = "pcg_type = '".$db->escape($objp->pcg_type)."'";
362  $tmppredefinedgroupwhere .= " AND fk_pcg_version = '".$db->escape($charofaccountstring)."'";
363  //$tmppredefinedgroupwhere .= " AND thirdparty_code = '".$db->escape($objp->name)."'";
364 
365  // Get cpts of category/group
366  $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
367 
368  foreach ($cpts as $j => $cpt) {
369  $return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, $cpt['dc']);
370  if ($return < 0) {
371  setEventMessages(null, $AccCat->errors, 'errors');
372  $resultN = 0;
373  } else {
374  $resultN = $AccCat->sdc;
375  }
376 
377 
378  if ($showaccountdetail == 'all' || $resultN <> 0) {
379  print '<tr>';
380  print '<td></td>';
381  print '<td class="tdoverflowmax200"> &nbsp; &nbsp; '.length_accountg($cpt['account_number']).' - '.$cpt['account_label'].'</td>';
382  print '<td class="right"><span class="amount">'.price($resultN).'</span></td>';
383  print "</tr>\n";
384  }
385  }
386  }
387 
388  $i++;
389  }
390  } else {
391  print '<tr><td colspan="3" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
392  }
393  } else {
394  dol_print_error($db);
395  }
396 } else {
397  /*
398  * Customer invoices
399  */
400  print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("CustomersInvoices").'</td></tr>';
401 
402  if ($modecompta == 'CREANCES-DETTES') {
403  $sql = "SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
404  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
405  $sql .= ", ".MAIN_DB_PREFIX."facture as f";
406  $sql .= " WHERE f.fk_soc = s.rowid";
407  $sql .= " AND f.fk_statut IN (1,2)";
408  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
409  $sql .= " AND f.type IN (0,1,2,5)";
410  } else {
411  $sql .= " AND f.type IN (0,1,2,3,5)";
412  }
413  if (!empty($date_start) && !empty($date_end)) {
414  $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
415  }
416  } elseif ($modecompta == 'RECETTES-DEPENSES') {
417  /*
418  * List of payments (old payments are not seen by this query because, on older versions, they were not linked via payment_invoice.
419  * old versions, they were not linked via payment_invoice. They are added later)
420  */
421  $sql = "SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
422  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
423  $sql .= ", ".MAIN_DB_PREFIX."facture as f";
424  $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
425  $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
426  $sql .= " WHERE p.rowid = pf.fk_paiement";
427  $sql .= " AND pf.fk_facture = f.rowid";
428  $sql .= " AND f.fk_soc = s.rowid";
429  if (!empty($date_start) && !empty($date_end)) {
430  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
431  }
432  }
433  $sql .= " AND f.entity IN (".getEntity('invoice').")";
434  if ($socid) {
435  $sql .= " AND f.fk_soc = ".((int) $socid);
436  }
437  $sql .= " GROUP BY name, socid";
438  $sql .= $db->order($sortfield, $sortorder);
439 
440  dol_syslog("get customer invoices", LOG_DEBUG);
441  $result = $db->query($sql);
442  if ($result) {
443  $num = $db->num_rows($result);
444  $i = 0;
445  while ($i < $num) {
446  $objp = $db->fetch_object($result);
447 
448  print '<tr class="oddeven">';
449  print '<td>&nbsp;</td>';
450  print "<td>".$langs->trans("Bills").' <a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$objp->socid.'">'.$objp->name."</td>\n";
451 
452  print '<td class="right">';
453  if ($modecompta == 'CREANCES-DETTES') {
454  print '<span class="amount">'.price($objp->amount_ht)."</span>";
455  }
456  print "</td>\n";
457  print '<td class="right"><span class="amount">'.price($objp->amount_ttc)."</span></td>\n";
458 
459  $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
460  $total_ttc += $objp->amount_ttc;
461  print "</tr>\n";
462  $i++;
463  }
464  $db->free($result);
465  } else {
466  dol_print_error($db);
467  }
468 
469  // We add the old customer payments, not linked by payment_invoice
470  if ($modecompta == 'RECETTES-DEPENSES') {
471  $sql = "SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc";
472  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
473  $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
474  $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
475  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
476  $sql .= " WHERE pf.rowid IS NULL";
477  $sql .= " AND p.fk_bank = b.rowid";
478  $sql .= " AND b.fk_account = ba.rowid";
479  $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
480  if (!empty($date_start) && !empty($date_end)) {
481  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
482  }
483  $sql .= " GROUP BY name, idp";
484  $sql .= " ORDER BY name";
485 
486  dol_syslog("get old customer payments not linked to invoices", LOG_DEBUG);
487  $result = $db->query($sql);
488  if ($result) {
489  $num = $db->num_rows($result);
490  $i = 0;
491  if ($num) {
492  while ($i < $num) {
493  $objp = $db->fetch_object($result);
494 
495 
496  print '<tr class="oddeven">';
497  print '<td>&nbsp;</td>';
498  print "<td>".$langs->trans("Bills")." ".$langs->trans("Other")." (".$langs->trans("PaymentsNotLinkedToInvoice").")\n";
499 
500  print '<td class="right">';
501  if ($modecompta == 'CREANCES-DETTES') {
502  print '<span class="amount">'.price($objp->amount_ht)."</span></td>\n";
503  }
504  print '</td>';
505  print '<td class="right"><span class="amount">'.price($objp->amount_ttc)."</span></td>\n";
506 
507  $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
508  $total_ttc += $objp->amount_ttc;
509 
510  print "</tr>\n";
511  $i++;
512  }
513  }
514  $db->free($result);
515  } else {
516  dol_print_error($db);
517  }
518  }
519 
520  if ($total_ttc == 0) {
521  print '<tr class="oddeven">';
522  print '<td>&nbsp;</td>';
523  print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
524  print '</tr>';
525  }
526 
527  $total_ht_income += $total_ht;
528  $total_ttc_income += $total_ttc;
529 
530  print '<tr class="liste_total">';
531  print '<td></td>';
532  print '<td></td>';
533  print '<td class="right">';
534  if ($modecompta == 'CREANCES-DETTES') {
535  print price($total_ht);
536  }
537  print '</td>';
538  print '<td class="right">'.price($total_ttc).'</td>';
539  print '</tr>';
540 
541  /*
542  * Donations
543  */
544 
545  if (isModEnabled('don')) {
546  print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("Donations").'</td></tr>';
547 
548  if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES') {
549  if ($modecompta == 'CREANCES-DETTES') {
550  $sql = "SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
551  $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
552  $sql .= " WHERE p.entity IN (".getEntity('donation').")";
553  $sql .= " AND fk_statut in (1,2)";
554  } else {
555  $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
556  $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
557  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid";
558  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
559  $sql .= " WHERE p.entity IN (".getEntity('donation').")";
560  $sql .= " AND fk_statut >= 2";
561  }
562  if (!empty($date_start) && !empty($date_end)) {
563  $sql .= " AND p.datedon >= '".$db->idate($date_start)."' AND p.datedon <= '".$db->idate($date_end)."'";
564  }
565  }
566  $sql .= " GROUP BY p.societe, p.firstname, p.lastname, dm";
567  $newsortfield = $sortfield;
568  if ($newsortfield == 's.nom, s.rowid') {
569  $newsortfield = 'p.societe, p.firstname, p.lastname, dm';
570  }
571  if ($newsortfield == 'amount_ht') {
572  $newsortfield = 'amount';
573  }
574  if ($newsortfield == 'amount_ttc') {
575  $newsortfield = 'amount';
576  }
577  $sql .= $db->order($newsortfield, $sortorder);
578 
579  dol_syslog("get dunning");
580  $result = $db->query($sql);
581  $subtotal_ht = 0;
582  $subtotal_ttc = 0;
583  if ($result) {
584  $num = $db->num_rows($result);
585  $i = 0;
586  if ($num) {
587  while ($i < $num) {
588  $obj = $db->fetch_object($result);
589 
590  $total_ht += $obj->amount;
591  $total_ttc += $obj->amount;
592  $subtotal_ht += $obj->amount;
593  $subtotal_ttc += $obj->amount;
594 
595  print '<tr class="oddeven">';
596  print '<td>&nbsp;</td>';
597 
598  print "<td>".$langs->trans("Donation")." <a href=\"".DOL_URL_ROOT."/don/list.php?search_company=".$obj->name."&search_name=".$obj->firstname." ".$obj->lastname."\">".$obj->name." ".$obj->firstname." ".$obj->lastname."</a></td>\n";
599 
600  print '<td class="right">';
601  if ($modecompta == 'CREANCES-DETTES') {
602  print '<span class="amount">'.price($obj->amount).'</span>';
603  }
604  print '</td>';
605  print '<td class="right"><span class="amount">'.price($obj->amount).'</span></td>';
606  print '</tr>';
607  $i++;
608  }
609  } else {
610  print '<tr class="oddeven"><td>&nbsp;</td>';
611  print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
612  print '</tr>';
613  }
614  } else {
615  dol_print_error($db);
616  }
617 
618  $total_ht_income += $subtotal_ht;
619  $total_ttc_income += $subtotal_ttc;
620 
621  print '<tr class="liste_total">';
622  print '<td></td>';
623  print '<td></td>';
624  print '<td class="right">';
625  if ($modecompta == 'CREANCES-DETTES') {
626  print price($subtotal_ht);
627  }
628  print '</td>';
629  print '<td class="right">'.price($subtotal_ttc).'</td>';
630  print '</tr>';
631  }
632 
633  /*
634  * Suppliers invoices
635  */
636  if ($modecompta == 'CREANCES-DETTES') {
637  $sql = "SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
638  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
639  $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
640  $sql .= " WHERE f.fk_soc = s.rowid";
641  $sql .= " AND f.fk_statut IN (1,2)";
642  if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
643  $sql .= " AND f.type IN (0,1,2)";
644  } else {
645  $sql .= " AND f.type IN (0,1,2,3)";
646  }
647  if (!empty($date_start) && !empty($date_end)) {
648  $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
649  }
650  } elseif ($modecompta == 'RECETTES-DEPENSES') {
651  $sql = "SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
652  $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p";
653  $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
654  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f";
655  $sql .= " ON pf.fk_facturefourn = f.rowid";
656  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s";
657  $sql .= " ON f.fk_soc = s.rowid";
658  $sql .= " WHERE p.rowid = pf.fk_paiementfourn ";
659  if (!empty($date_start) && !empty($date_end)) {
660  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
661  }
662  }
663 
664  $sql .= " AND f.entity = ".((int) $conf->entity);
665  if ($socid) {
666  $sql .= " AND f.fk_soc = ".((int) $socid);
667  }
668  $sql .= " GROUP BY name, socid";
669  $sql .= $db->order($sortfield, $sortorder);
670 
671  print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("SuppliersInvoices").'</td></tr>';
672 
673  $subtotal_ht = 0;
674  $subtotal_ttc = 0;
675  dol_syslog("get suppliers invoices", LOG_DEBUG);
676  $result = $db->query($sql);
677  if ($result) {
678  $num = $db->num_rows($result);
679  $i = 0;
680  if ($num > 0) {
681  while ($i < $num) {
682  $objp = $db->fetch_object($result);
683 
684  print '<tr class="oddeven">';
685  print '<td>&nbsp;</td>';
686  print "<td>".$langs->trans("Bills").' <a href="'.DOL_URL_ROOT."/fourn/facture/list.php?socid=".$objp->socid.'">'.$objp->name.'</a></td>'."\n";
687 
688  print '<td class="right">';
689  if ($modecompta == 'CREANCES-DETTES') {
690  print '<span class="amount">'.price(-$objp->amount_ht)."</span>";
691  }
692  print "</td>\n";
693  print '<td class="right"><span class="amount">'.price(-$objp->amount_ttc)."</span></td>\n";
694 
695  $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
696  $total_ttc -= $objp->amount_ttc;
697  $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
698  $subtotal_ttc += $objp->amount_ttc;
699 
700  print "</tr>\n";
701  $i++;
702  }
703  } else {
704  print '<tr class="oddeven">';
705  print '<td>&nbsp;</td>';
706  print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
707  print '</tr>';
708  }
709 
710  $db->free($result);
711  } else {
712  dol_print_error($db);
713  }
714 
715  $total_ht_outcome += $subtotal_ht;
716  $total_ttc_outcome += $subtotal_ttc;
717 
718  print '<tr class="liste_total">';
719  print '<td></td>';
720  print '<td></td>';
721  print '<td class="right">';
722  if ($modecompta == 'CREANCES-DETTES') {
723  print price(-$subtotal_ht);
724  }
725  print '</td>';
726  print '<td class="right">'.price(-$subtotal_ttc).'</td>';
727  print '</tr>';
728 
729 
730  /*
731  * Social / Fiscal contributions who are not deductible
732  */
733 
734  print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("SocialContributionsNondeductibles").'</td></tr>';
735 
736  if ($modecompta == 'CREANCES-DETTES') {
737  $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
738  $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
739  $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
740  $sql .= " WHERE cs.fk_type = c.id";
741  $sql .= " AND c.deductible = 0";
742  if (!empty($date_start) && !empty($date_end)) {
743  $sql .= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'";
744  }
745  } elseif ($modecompta == 'RECETTES-DEPENSES') {
746  $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
747  $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
748  $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
749  $sql .= ", ".MAIN_DB_PREFIX."paiementcharge as p";
750  $sql .= " WHERE p.fk_charge = cs.rowid";
751  $sql .= " AND cs.fk_type = c.id";
752  $sql .= " AND c.deductible = 0";
753  if (!empty($date_start) && !empty($date_end)) {
754  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
755  }
756  }
757  $sql .= " AND cs.entity = ".$conf->entity;
758  $sql .= " GROUP BY c.libelle, c.id, c.accountancy_code";
759  $newsortfield = $sortfield;
760  if ($newsortfield == 's.nom, s.rowid') {
761  $newsortfield = 'c.libelle, c.id';
762  }
763  if ($newsortfield == 'amount_ht') {
764  $newsortfield = 'amount';
765  }
766  if ($newsortfield == 'amount_ttc') {
767  $newsortfield = 'amount';
768  }
769 
770  $sql .= $db->order($newsortfield, $sortorder);
771 
772  dol_syslog("get social contributions deductible=0", LOG_DEBUG);
773  $result = $db->query($sql);
774  $subtotal_ht = 0;
775  $subtotal_ttc = 0;
776  if ($result) {
777  $num = $db->num_rows($result);
778  $i = 0;
779  if ($num) {
780  while ($i < $num) {
781  $obj = $db->fetch_object($result);
782 
783  $total_ht -= $obj->amount;
784  $total_ttc -= $obj->amount;
785  $subtotal_ht += $obj->amount;
786  $subtotal_ttc += $obj->amount;
787 
788  $titletoshow = '';
789  if ($obj->accountancy_code) {
790  $titletoshow = $langs->trans("AccountingCode").': '.$obj->accountancy_code;
791  $tmpaccountingaccount = new AccountingAccount($db);
792  $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
793  $titletoshow .= ' - '.$langs->trans("AccountingCategory").': '.$tmpaccountingaccount->pcg_type;
794  }
795 
796  print '<tr class="oddeven">';
797  print '<td>&nbsp;</td>';
798  print '<td'.($obj->accountancy_code ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>'.dol_escape_htmltag($obj->label).'</td>';
799  print '<td class="right">';
800  if ($modecompta == 'CREANCES-DETTES') {
801  print '<span class="amount">'.price(-$obj->amount).'</span>';
802  }
803  print '</td>';
804  print '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
805  print '</tr>';
806  $i++;
807  }
808  } else {
809  print '<tr class="oddeven">';
810  print '<td>&nbsp;</td>';
811  print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
812  print '</tr>';
813  }
814  } else {
815  dol_print_error($db);
816  }
817 
818  $total_ht_outcome += $subtotal_ht;
819  $total_ttc_outcome += $subtotal_ttc;
820 
821  print '<tr class="liste_total">';
822  print '<td></td>';
823  print '<td></td>';
824  print '<td class="right">';
825  if ($modecompta == 'CREANCES-DETTES') {
826  print price(-$subtotal_ht);
827  }
828  print '</td>';
829  print '<td class="right">'.price(-$subtotal_ttc).'</td>';
830  print '</tr>';
831 
832 
833  /*
834  * Social / Fiscal contributions who are deductible
835  */
836 
837  print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("SocialContributionsDeductibles").'</td></tr>';
838 
839  if ($modecompta == 'CREANCES-DETTES') {
840  $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
841  $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
842  $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
843  $sql .= " WHERE cs.fk_type = c.id";
844  $sql .= " AND c.deductible = 1";
845  if (!empty($date_start) && !empty($date_end)) {
846  $sql .= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'";
847  }
848  $sql .= " AND cs.entity = ".$conf->entity;
849  } elseif ($modecompta == 'RECETTES-DEPENSES') {
850  $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
851  $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
852  $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
853  $sql .= ", ".MAIN_DB_PREFIX."paiementcharge as p";
854  $sql .= " WHERE p.fk_charge = cs.rowid";
855  $sql .= " AND cs.fk_type = c.id";
856  $sql .= " AND c.deductible = 1";
857  if (!empty($date_start) && !empty($date_end)) {
858  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
859  }
860  $sql .= " AND cs.entity = ".$conf->entity;
861  }
862  $sql .= " GROUP BY c.libelle, c.id, c.accountancy_code";
863  $newsortfield = $sortfield;
864  if ($newsortfield == 's.nom, s.rowid') {
865  $newsortfield = 'c.libelle, c.id';
866  }
867  if ($newsortfield == 'amount_ht') {
868  $newsortfield = 'amount';
869  }
870  if ($newsortfield == 'amount_ttc') {
871  $newsortfield = 'amount';
872  }
873  $sql .= $db->order($newsortfield, $sortorder);
874 
875  dol_syslog("get social contributions deductible=1", LOG_DEBUG);
876  $result = $db->query($sql);
877  $subtotal_ht = 0;
878  $subtotal_ttc = 0;
879  if ($result) {
880  $num = $db->num_rows($result);
881  $i = 0;
882  if ($num) {
883  while ($i < $num) {
884  $obj = $db->fetch_object($result);
885 
886  $total_ht -= $obj->amount;
887  $total_ttc -= $obj->amount;
888  $subtotal_ht += $obj->amount;
889  $subtotal_ttc += $obj->amount;
890 
891  $titletoshow = '';
892  if ($obj->accountancy_code) {
893  $titletoshow = $langs->trans("AccountingCode").': '.$obj->accountancy_code;
894  $tmpaccountingaccount = new AccountingAccount($db);
895  $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
896  $titletoshow .= ' - '.$langs->trans("AccountingCategory").': '.$tmpaccountingaccount->pcg_type;
897  }
898 
899  print '<tr class="oddeven">';
900  print '<td>&nbsp;</td>';
901  print '<td'.($obj->accountancy_code ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>'.dol_escape_htmltag($obj->label).'</td>';
902  print '<td class="right">';
903  if ($modecompta == 'CREANCES-DETTES') {
904  print '<span class="amount">'.price(-$obj->amount).'</span>';
905  }
906  print '</td>';
907  print '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
908  print '</tr>';
909  $i++;
910  }
911  } else {
912  print '<tr class="oddeven">';
913  print '<td>&nbsp;</td>';
914  print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
915  print '</tr>';
916  }
917  } else {
918  dol_print_error($db);
919  }
920 
921  $total_ht_outcome += $subtotal_ht;
922  $total_ttc_outcome += $subtotal_ttc;
923 
924  print '<tr class="liste_total">';
925  print '<td></td>';
926  print '<td></td>';
927  print '<td class="right">';
928  if ($modecompta == 'CREANCES-DETTES') {
929  print price(-$subtotal_ht);
930  }
931  print '</td>';
932  print '<td class="right">'.price(-$subtotal_ttc).'</td>';
933  print '</tr>';
934 
935 
936  /*
937  * Salaries
938  */
939 
940  if (isModEnabled('salaries')) {
941  print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("Salaries").'</td></tr>';
942 
943  if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES') {
944  if ($modecompta == 'CREANCES-DETTES') {
945  $column = 's.dateep'; // We use the date of end of period of salary
946 
947  $sql = "SELECT u.rowid, u.firstname, u.lastname, s.fk_user as fk_user, s.label as label, date_format($column,'%Y-%m') as dm, sum(s.amount) as amount";
948  $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
949  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = s.fk_user";
950  $sql .= " WHERE s.entity IN (".getEntity('salary').")";
951  if (!empty($date_start) && !empty($date_end)) {
952  $sql .= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'";
953  }
954  $sql .= " GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, s.label, dm";
955  } else {
956  $column = 'p.datep';
957 
958  $sql = "SELECT u.rowid, u.firstname, u.lastname, s.fk_user as fk_user, p.label as label, date_format($column,'%Y-%m') as dm, sum(p.amount) as amount";
959  $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
960  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as s ON s.rowid = p.fk_salary";
961  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = s.fk_user";
962  $sql .= " WHERE p.entity IN (".getEntity('payment_salary').")";
963  if (!empty($date_start) && !empty($date_end)) {
964  $sql .= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'";
965  }
966  $sql .= " GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, p.label, dm";
967  }
968 
969  $newsortfield = $sortfield;
970  if ($newsortfield == 's.nom, s.rowid') {
971  $newsortfield = 'u.firstname, u.lastname';
972  }
973  if ($newsortfield == 'amount_ht') {
974  $newsortfield = 'amount';
975  }
976  if ($newsortfield == 'amount_ttc') {
977  $newsortfield = 'amount';
978  }
979  $sql .= $db->order($newsortfield, $sortorder);
980  }
981 
982  dol_syslog("get salaries");
983  $result = $db->query($sql);
984  $subtotal_ht = 0;
985  $subtotal_ttc = 0;
986  if ($result) {
987  $num = $db->num_rows($result);
988  $i = 0;
989  if ($num) {
990  while ($i < $num) {
991  $obj = $db->fetch_object($result);
992 
993  $total_ht -= $obj->amount;
994  $total_ttc -= $obj->amount;
995  $subtotal_ht += $obj->amount;
996  $subtotal_ttc += $obj->amount;
997 
998  print '<tr class="oddeven"><td>&nbsp;</td>';
999 
1000  $userstatic = new User($db);
1001  $userstatic->fetch($obj->fk_user);
1002 
1003  print "<td>".$langs->trans("Salary")." <a href=\"".DOL_URL_ROOT."/salaries/list.php?search_user=".urlencode($userstatic->getFullName($langs))."\">".$obj->firstname." ".$obj->lastname."</a></td>\n";
1004  print '<td class="right">';
1005  if ($modecompta == 'CREANCES-DETTES') {
1006  print '<span class="amount">'.price(-$obj->amount).'</span>';
1007  }
1008  print '</td>';
1009  print '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
1010  print '</tr>';
1011  $i++;
1012  }
1013  } else {
1014  print '<tr class="oddeven">';
1015  print '<td>&nbsp;</td>';
1016  print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
1017  print '</tr>';
1018  }
1019  } else {
1020  dol_print_error($db);
1021  }
1022 
1023  $total_ht_outcome += $subtotal_ht;
1024  $total_ttc_outcome += $subtotal_ttc;
1025 
1026  print '<tr class="liste_total">';
1027  print '<td></td>';
1028  print '<td></td>';
1029  print '<td class="right">';
1030  if ($modecompta == 'CREANCES-DETTES') {
1031  print price(-$subtotal_ht);
1032  }
1033  print '</td>';
1034  print '<td class="right">'.price(-$subtotal_ttc).'</td>';
1035  print '</tr>';
1036  }
1037 
1038 
1039  /*
1040  * Expense report
1041  */
1042 
1043  if (isModEnabled('expensereport')) {
1044  if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES') {
1045  $langs->load('trips');
1046  if ($modecompta == 'CREANCES-DETTES') {
1047  $sql = "SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(date_valid,'%Y-%m') as dm, p.total_ht as amount_ht, p.total_ttc as amount_ttc";
1048  $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p";
1049  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
1050  $sql .= " WHERE p.entity IN (".getEntity('expensereport').")";
1051  $sql .= " AND p.fk_statut>=5";
1052 
1053  $column = 'p.date_valid';
1054  } else {
1055  $sql = "SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(pe.amount) as amount_ht, sum(pe.amount) as amount_ttc";
1056  $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p";
1057  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
1058  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
1059  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
1060  $sql .= " WHERE p.entity IN (".getEntity('expensereport').")";
1061  $sql .= " AND p.fk_statut>=5";
1062 
1063  $column = 'pe.datep';
1064  }
1065 
1066  if (!empty($date_start) && !empty($date_end)) {
1067  $sql .= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'";
1068  }
1069 
1070  if ($modecompta == 'CREANCES-DETTES') {
1071  //No need of GROUP BY
1072  } else {
1073  $sql .= " GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
1074  }
1075  $newsortfield = $sortfield;
1076  if ($newsortfield == 's.nom, s.rowid') {
1077  $newsortfield = 'p.ref';
1078  }
1079  $sql .= $db->order($newsortfield, $sortorder);
1080  }
1081 
1082  print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("ExpenseReport").'</td></tr>';
1083 
1084  dol_syslog("get expense report outcome");
1085  $result = $db->query($sql);
1086  $subtotal_ht = 0;
1087  $subtotal_ttc = 0;
1088  if ($result) {
1089  $num = $db->num_rows($result);
1090  if ($num) {
1091  while ($obj = $db->fetch_object($result)) {
1092  $total_ht -= $obj->amount_ht;
1093  $total_ttc -= $obj->amount_ttc;
1094  $subtotal_ht += $obj->amount_ht;
1095  $subtotal_ttc += $obj->amount_ttc;
1096 
1097  print '<tr class="oddeven">';
1098  print '<td>&nbsp;</td>';
1099  print "<td>".$langs->trans("ExpenseReport")." <a href=\"".DOL_URL_ROOT."/expensereport/list.php?search_user=".$obj->userid."\">".$obj->firstname." ".$obj->lastname."</a></td>\n";
1100  print '<td class="right">';
1101  if ($modecompta == 'CREANCES-DETTES') {
1102  print '<span class="amount">'.price(-$obj->amount_ht).'</span>';
1103  }
1104  print '</td>';
1105  print '<td class="right"><span class="amount">'.price(-$obj->amount_ttc).'</span></td>';
1106  print '</tr>';
1107  }
1108  } else {
1109  print '<tr class="oddeven">';
1110  print '<td>&nbsp;</td>';
1111  print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
1112  print '</tr>';
1113  }
1114  } else {
1115  dol_print_error($db);
1116  }
1117 
1118  $total_ht_outcome += $subtotal_ht;
1119  $total_ttc_outcome += $subtotal_ttc;
1120 
1121  print '<tr class="liste_total">';
1122  print '<td></td>';
1123  print '<td></td>';
1124  print '<td class="right">';
1125  if ($modecompta == 'CREANCES-DETTES') {
1126  print price(-$subtotal_ht);
1127  }
1128  print '</td>';
1129  print '<td class="right">'.price(-$subtotal_ttc).'</td>';
1130  print '</tr>';
1131  }
1132 
1133 
1134  /*
1135  * Various Payments
1136  */
1137  //$conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY = 1;
1138 
1139  if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && isModEnabled('banque') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
1140  $subtotal_ht = 0;
1141  $subtotal_ttc = 0;
1142 
1143  print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("VariousPayment").'</td></tr>';
1144 
1145  // Debit
1146  $sql = "SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various as p";
1147  $sql .= ' WHERE 1 = 1';
1148  if (!empty($date_start) && !empty($date_end)) {
1149  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
1150  }
1151  $sql .= ' GROUP BY p.sens';
1152  $sql .= ' ORDER BY p.sens';
1153 
1154  dol_syslog('get various payments', LOG_DEBUG);
1155  $result = $db->query($sql);
1156  if ($result) {
1157  // Debit (payment of suppliers for example)
1158  $obj = $db->fetch_object($result);
1159  if (isset($obj->amount)) {
1160  $subtotal_ht += -$obj->amount;
1161  $subtotal_ttc += -$obj->amount;
1162 
1163  $total_ht_outcome += $obj->amount;
1164  $total_ttc_outcome += $obj->amount;
1165  }
1166  print '<tr class="oddeven">';
1167  print '<td>&nbsp;</td>';
1168  print "<td>".$langs->trans("Debit")."</td>\n";
1169  print '<td class="right">';
1170  if ($modecompta == 'CREANCES-DETTES') {
1171  print '<span class="amount">'.price(-$obj->amount).'</span>';
1172  }
1173  print '</td>';
1174  print '<td class="right"><span class="amount">'.price(-$obj->amount)."</span></td>\n";
1175  print "</tr>\n";
1176 
1177  // Credit (payment received from customer for example)
1178  $obj = $db->fetch_object($result);
1179  if (isset($obj->amount)) {
1180  $subtotal_ht += $obj->amount;
1181  $subtotal_ttc += $obj->amount;
1182 
1183  $total_ht_income += $obj->amount;
1184  $total_ttc_income += $obj->amount;
1185  }
1186  print '<tr class="oddeven"><td>&nbsp;</td>';
1187  print "<td>".$langs->trans("Credit")."</td>\n";
1188  print '<td class="right">';
1189  if ($modecompta == 'CREANCES-DETTES') {
1190  print '<span class="amount">'.price($obj->amount).'</span>';
1191  }
1192  print '</td>';
1193  print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
1194  print "</tr>\n";
1195 
1196  // Total
1197  $total_ht += $subtotal_ht;
1198  $total_ttc += $subtotal_ttc;
1199  print '<tr class="liste_total">';
1200  print '<td></td>';
1201  print '<td></td>';
1202  print '<td class="right">';
1203  if ($modecompta == 'CREANCES-DETTES') {
1204  print price($subtotal_ht);
1205  }
1206  print '</td>';
1207  print '<td class="right">'.price($subtotal_ttc).'</td>';
1208  print '</tr>';
1209  } else {
1210  dol_print_error($db);
1211  }
1212  }
1213 
1214  /*
1215  * Payment Loan
1216  */
1217 
1218  if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) && isModEnabled('don') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
1219  $subtotal_ht = 0;
1220  $subtotal_ttc = 0;
1221 
1222  print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("PaymentLoan").'</td></tr>';
1223 
1224  $sql = 'SELECT l.rowid as id, l.label AS label, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) as amount FROM '.MAIN_DB_PREFIX.'payment_loan as p';
1225  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'loan AS l ON l.rowid = p.fk_loan';
1226  $sql .= ' WHERE 1 = 1';
1227  if (!empty($date_start) && !empty($date_end)) {
1228  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
1229  }
1230  $sql .= ' GROUP BY p.fk_loan';
1231  $sql .= ' ORDER BY p.fk_loan';
1232 
1233  dol_syslog('get loan payments', LOG_DEBUG);
1234  $result = $db->query($sql);
1235  if ($result) {
1236  require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
1237  $loan_static = new Loan($db);
1238  while ($obj = $db->fetch_object($result)) {
1239  $loan_static->id = $obj->id;
1240  $loan_static->ref = $obj->id;
1241  $loan_static->label = $obj->label;
1242  print '<tr class="oddeven"><td>&nbsp;</td>';
1243  print "<td>".$loan_static->getNomUrl(1).' - '.$obj->label."</td>\n";
1244  if ($modecompta == 'CREANCES-DETTES') {
1245  print '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
1246  }
1247  print '<td class="right"><span class="amount">'.price(-$obj->amount)."</span></td>\n";
1248  print "</tr>\n";
1249  $subtotal_ht -= $obj->amount;
1250  $subtotal_ttc -= $obj->amount;
1251  }
1252  $total_ht += $subtotal_ht;
1253  $total_ttc += $subtotal_ttc;
1254 
1255  $total_ht_income += $subtotal_ht;
1256  $total_ttc_income += $subtotal_ttc;
1257 
1258  print '<tr class="liste_total">';
1259  print '<td></td>';
1260  print '<td></td>';
1261  print '<td class="right">';
1262  if ($modecompta == 'CREANCES-DETTES') {
1263  print price($subtotal_ht);
1264  }
1265  print '</td>';
1266  print '<td class="right">'.price($subtotal_ttc).'</td>';
1267  print '</tr>';
1268  } else {
1269  dol_print_error($db);
1270  }
1271  }
1272 
1273  /*
1274  * VAT
1275  */
1276 
1277  print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("VAT").'</td></tr>';
1278  $subtotal_ht = 0;
1279  $subtotal_ttc = 0;
1280 
1281  if ($conf->tax->enabled && ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES')) {
1282  if ($modecompta == 'CREANCES-DETTES') {
1283  // VAT to pay
1284  $amount = 0;
1285  $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1286  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
1287  $sql .= " WHERE f.fk_statut IN (1,2)";
1288  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
1289  $sql .= " AND f.type IN (0,1,2,5)";
1290  } else {
1291  $sql .= " AND f.type IN (0,1,2,3,5)";
1292  }
1293  if (!empty($date_start) && !empty($date_end)) {
1294  $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
1295  }
1296  $sql .= " AND f.entity IN (".getEntity('invoice').")";
1297  $sql .= " GROUP BY dm";
1298  $newsortfield = $sortfield;
1299  if ($newsortfield == 's.nom, s.rowid') {
1300  $newsortfield = 'dm';
1301  }
1302  if ($newsortfield == 'amount_ht') {
1303  $newsortfield = 'amount';
1304  }
1305  if ($newsortfield == 'amount_ttc') {
1306  $newsortfield = 'amount';
1307  }
1308  $sql .= $db->order($newsortfield, $sortorder);
1309 
1310  dol_syslog("get vat to pay", LOG_DEBUG);
1311  $result = $db->query($sql);
1312  if ($result) {
1313  $num = $db->num_rows($result);
1314  $i = 0;
1315  if ($num) {
1316  while ($i < $num) {
1317  $obj = $db->fetch_object($result);
1318 
1319  $amount -= $obj->amount;
1320  //$total_ht -= $obj->amount;
1321  $total_ttc -= $obj->amount;
1322  //$subtotal_ht -= $obj->amount;
1323  $subtotal_ttc -= $obj->amount;
1324  $i++;
1325  }
1326  }
1327  } else {
1328  dol_print_error($db);
1329  }
1330 
1331  $total_ht_outcome -= 0;
1332  $total_ttc_outcome -= $amount;
1333 
1334  print '<tr class="oddeven">';
1335  print '<td>&nbsp;</td>';
1336  print "<td>".$langs->trans("VATToPay")."</td>\n";
1337  print '<td class="right">&nbsp;</td>'."\n";
1338  print '<td class="right"><span class="amount">'.price($amount)."</span></td>\n";
1339  print "</tr>\n";
1340 
1341  // VAT to retrieve
1342  $amount = 0;
1343  $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1344  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
1345  $sql .= " WHERE f.fk_statut IN (1,2)";
1346  if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
1347  $sql .= " AND f.type IN (0,1,2)";
1348  } else {
1349  $sql .= " AND f.type IN (0,1,2,3)";
1350  }
1351  if (!empty($date_start) && !empty($date_end)) {
1352  $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
1353  }
1354  $sql .= " AND f.entity = ".$conf->entity;
1355  $sql .= " GROUP BY dm";
1356  $newsortfield = $sortfield;
1357  if ($newsortfield == 's.nom, s.rowid') {
1358  $newsortfield = 'dm';
1359  }
1360  if ($newsortfield == 'amount_ht') {
1361  $newsortfield = 'amount';
1362  }
1363  if ($newsortfield == 'amount_ttc') {
1364  $newsortfield = 'amount';
1365  }
1366  $sql .= $db->order($newsortfield, $sortorder);
1367 
1368  dol_syslog("get vat received back", LOG_DEBUG);
1369  $result = $db->query($sql);
1370  if ($result) {
1371  $num = $db->num_rows($result);
1372  $i = 0;
1373  if ($num) {
1374  while ($i < $num) {
1375  $obj = $db->fetch_object($result);
1376 
1377  $amount += $obj->amount;
1378  //$total_ht += $obj->amount;
1379  $total_ttc += $obj->amount;
1380  //$subtotal_ht += $obj->amount;
1381  $subtotal_ttc += $obj->amount;
1382 
1383  $i++;
1384  }
1385  }
1386  } else {
1387  dol_print_error($db);
1388  }
1389 
1390  $total_ht_income += 0;
1391  $total_ttc_income += $amount;
1392 
1393  print '<tr class="oddeven">';
1394  print '<td>&nbsp;</td>';
1395  print '<td>'.$langs->trans("VATToCollect")."</td>\n";
1396  print '<td class="right">&nbsp;</td>'."\n";
1397  print '<td class="right"><span class="amount">'.price($amount)."</span></td>\n";
1398  print "</tr>\n";
1399  } else {
1400  // VAT really already paid
1401  $amount = 0;
1402  $sql = "SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1403  $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
1404  $sql .= " WHERE amount > 0";
1405  if (!empty($date_start) && !empty($date_end)) {
1406  $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
1407  }
1408  $sql .= " AND t.entity = ".$conf->entity;
1409  $sql .= " GROUP BY dm";
1410  $newsortfield = $sortfield;
1411  if ($newsortfield == 's.nom, s.rowid') {
1412  $newsortfield = 'dm';
1413  }
1414  if ($newsortfield == 'amount_ht') {
1415  $newsortfield = 'amount';
1416  }
1417  if ($newsortfield == 'amount_ttc') {
1418  $newsortfield = 'amount';
1419  }
1420  $sql .= $db->order($newsortfield, $sortorder);
1421 
1422  dol_syslog("get vat really paid", LOG_DEBUG);
1423  $result = $db->query($sql);
1424  if ($result) {
1425  $num = $db->num_rows($result);
1426  $i = 0;
1427  if ($num) {
1428  while ($i < $num) {
1429  $obj = $db->fetch_object($result);
1430 
1431  $amount -= $obj->amount;
1432  $total_ht -= $obj->amount;
1433  $total_ttc -= $obj->amount;
1434  $subtotal_ht -= $obj->amount;
1435  $subtotal_ttc -= $obj->amount;
1436 
1437  $i++;
1438  }
1439  }
1440  $db->free($result);
1441  } else {
1442  dol_print_error($db);
1443  }
1444 
1445  $total_ht_outcome -= 0;
1446  $total_ttc_outcome -= $amount;
1447 
1448  print '<tr class="oddeven">';
1449  print '<td>&nbsp;</td>';
1450  print "<td>".$langs->trans("VATPaid")."</td>\n";
1451  print '<td <class="right"></td>'."\n";
1452  print '<td class="right"><span class="amount">'.price($amount)."</span></td>\n";
1453  print "</tr>\n";
1454 
1455  // VAT really received
1456  $amount = 0;
1457  $sql = "SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1458  $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
1459  $sql .= " WHERE amount < 0";
1460  if (!empty($date_start) && !empty($date_end)) {
1461  $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
1462  }
1463  $sql .= " AND t.entity = ".$conf->entity;
1464  $sql .= " GROUP BY dm";
1465  $newsortfield = $sortfield;
1466  if ($newsortfield == 's.nom, s.rowid') {
1467  $newsortfield = 'dm';
1468  }
1469  if ($newsortfield == 'amount_ht') {
1470  $newsortfield = 'amount';
1471  }
1472  if ($newsortfield == 'amount_ttc') {
1473  $newsortfield = 'amount';
1474  }
1475  $sql .= $db->order($newsortfield, $sortorder);
1476 
1477  dol_syslog("get vat really received back", LOG_DEBUG);
1478  $result = $db->query($sql);
1479  if ($result) {
1480  $num = $db->num_rows($result);
1481  $i = 0;
1482  if ($num) {
1483  while ($i < $num) {
1484  $obj = $db->fetch_object($result);
1485 
1486  $amount += -$obj->amount;
1487  $total_ht += -$obj->amount;
1488  $total_ttc += -$obj->amount;
1489  $subtotal_ht += -$obj->amount;
1490  $subtotal_ttc += -$obj->amount;
1491 
1492  $i++;
1493  }
1494  }
1495  $db->free($result);
1496  } else {
1497  dol_print_error($db);
1498  }
1499 
1500  $total_ht_income += 0;
1501  $total_ttc_income += $amount;
1502 
1503  print '<tr class="oddeven">';
1504  print '<td>&nbsp;</td>';
1505  print "<td>".$langs->trans("VATCollected")."</td>\n";
1506  print '<td class="right"></td>'."\n";
1507  print '<td class="right"><span class="amount">'.price($amount)."</span></td>\n";
1508  print "</tr>\n";
1509  }
1510  }
1511 
1512  if ($mysoc->tva_assuj != '0') { // Assujetti
1513  print '<tr class="liste_total">';
1514  print '<td></td>';
1515  print '<td></td>';
1516  print '<td class="right">&nbsp;</td>';
1517  print '<td class="right">'.price(price2num($subtotal_ttc, 'MT')).'</td>';
1518  print '</tr>';
1519  }
1520 }
1521 
1522 $action = "balanceclient";
1523 $object = array(&$total_ht, &$total_ttc);
1524 $parameters["mode"] = $modecompta;
1525 $parameters["date_start"] = $date_start;
1526 $parameters["date_end"] = $date_end;
1527 // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
1528 $hookmanager->initHooks(array('externalbalance'));
1529 $reshook = $hookmanager->executeHooks('addBalanceLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1530 print $hookmanager->resPrint;
1531 
1532 
1533 
1534 // Total
1535 print '<tr>';
1536 print '<td colspan="'.($modecompta == 'BOOKKEEPING' ? 3 : 4).'">&nbsp;</td>';
1537 print '</tr>';
1538 
1539 print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Income").'</td>';
1540 if ($modecompta == 'CREANCES-DETTES') {
1541  print '<td class="liste_total right">'.price(price2num($total_ht_income, 'MT')).'</td>';
1542 } elseif ($modecompta == 'RECETTES-DEPENSES') {
1543  print '<td></td>';
1544 }
1545 print '<td class="liste_total right">'.price(price2num($total_ttc_income, 'MT')).'</td>';
1546 print '</tr>';
1547 print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Outcome").'</td>';
1548 if ($modecompta == 'CREANCES-DETTES') {
1549  print '<td class="liste_total right">'.price(price2num(-$total_ht_outcome, 'MT')).'</td>';
1550 } elseif ($modecompta == 'RECETTES-DEPENSES') {
1551  print '<td></td>';
1552 }
1553 print '<td class="liste_total right">'.price(price2num(-$total_ttc_outcome, 'MT')).'</td>';
1554 print '</tr>';
1555 print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Profit").'</td>';
1556 if ($modecompta == 'CREANCES-DETTES') {
1557  print '<td class="liste_total right">'.price(price2num($total_ht, 'MT')).'</td>';
1558 } elseif ($modecompta == 'RECETTES-DEPENSES') {
1559  print '<td></td>';
1560 }
1561 print '<td class="liste_total right">'.price(price2num($total_ttc, 'MT')).'</td>';
1562 print '</tr>';
1563 
1564 print "</table>";
1565 print '<br>';
1566 
1567 // End of page
1568 llxFooter();
1569 $db->close();
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2713
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
AccountancyCategory
Class to manage categories of an accounting account.
Definition: accountancycategory.class.php:32
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
Loan
Loan.
Definition: loan.class.php:30
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_next
img_next($titlealt='default', $moreatt='')
Show next logo.
Definition: functions.lib.php:4557
dol_getIdFromCode
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
Definition: functions.lib.php:8535
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
dol_get_first_day
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:551
dol_get_last_day
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:570
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4800
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
AccountingAccount
Class to manage accounting accounts.
Definition: accountingaccount.class.php:36
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
price
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.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
img_previous
img_previous($titlealt='default', $moreatt='')
Show previous logo.
Definition: functions.lib.php:4576
report_header
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
Definition: report.lib.php:41
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59