35require
'../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancycategory.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
47$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy',
'loan'));
49$date_startmonth =
GETPOST(
'date_startmonth',
'int');
50$date_startday =
GETPOST(
'date_startday',
'int');
51$date_startyear =
GETPOST(
'date_startyear',
'int');
52$date_endmonth =
GETPOST(
'date_endmonth',
'int');
53$date_endday =
GETPOST(
'date_endday',
'int');
54$date_endyear =
GETPOST(
'date_endyear',
'int');
55$showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'yes';
57$limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
58$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
59$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
60$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
61if (empty($page) || $page == -1) {
64$offset = $limit * $page;
77 $year_start = $year_current;
79 $year_current = $year;
83$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
84$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
87if (empty($date_start) || empty($date_end)) {
91 $year_end = $year_start;
95 if (!$year && $month_start > $month_current) {
100 $month_end = $month_start - 1;
101 $year_end = $year_start + 1;
103 if ($month_end < 1) {
107 $month_end = $month_start;
132$year_start = $tmps[
'year'];
134$year_end = $tmpe[
'year'];
135$nbofyear = ($year_end - $year_start) + 1;
139$modecompta = $conf->global->ACCOUNTING_MODE;
140if (isModEnabled(
'accounting')) {
141 $modecompta =
'BOOKKEEPING';
143if (
GETPOST(
"modecompta",
'alpha')) {
144 $modecompta =
GETPOST(
"modecompta",
'alpha');
150$socid =
GETPOST(
'socid',
'int');
151if ($user->socid > 0) {
152 $socid = $user->socid;
154if (isModEnabled(
'comptabilite')) {
157if (isModEnabled(
'accounting')) {
158 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
160$hookmanager->initHooks([
'customersupplierreportlist']);
169$form =
new Form($db);
178if ($modecompta ==
"CREANCES-DETTES") {
179 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
180 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
181 $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>" :
"");
182 $description = $langs->trans(
"RulesResultDue");
184 $description .= $langs->trans(
"DepositsAreNotIncluded");
186 $description .= $langs->trans(
"DepositsAreIncluded");
189 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
193} elseif ($modecompta ==
"RECETTES-DEPENSES") {
194 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
195 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
196 $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>" :
"");
197 $description = $langs->trans(
"RulesResultInOut");
200} elseif ($modecompta ==
"BOOKKEEPING") {
201 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
202 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
203 $arraylist = array(
'no'=>$langs->trans(
"CustomerCode"),
'yes'=>$langs->trans(
"AccountWithNonZeroValues"),
'all'=>$langs->trans(
"All"));
204 $period .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
205 $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>" :
"");
206 $description = $langs->trans(
"RulesResultBookkeepingPredefined");
207 $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")).
')';
214if (isModEnabled(
'accounting')) {
215 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
218$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModeEngagement");
219if (isModEnabled(
'accounting')) {
220 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
222$calcmode .=
'</label>';
223$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
224if (isModEnabled(
'accounting')) {
225 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
227$calcmode .=
'</label>';
230report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta,
'showaccountdetail'=>$showaccountdetail), $calcmode);
232if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
233 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
237$param =
'&modecompta='.urlencode($modecompta).
'&showaccountdetail='.urlencode($showaccountdetail);
239 $param .=
'&date_startday='.$date_startday;
241if ($date_startmonth) {
242 $param .=
'&date_startmonth='.$date_startmonth;
244if ($date_startyear) {
245 $param .=
'&date_startyear='.$date_startyear;
248 $param .=
'&date_endday='.$date_endday;
251 $param .=
'&date_endmonth='.$date_endmonth;
254 $param .=
'&date_endyear='.$date_endyear;
257print
'<table class="liste noborder centpercent">';
258print
'<tr class="liste_titre">';
260if ($modecompta ==
'BOOKKEEPING') {
261 print_liste_field_titre(
"PredefinedGroups", $_SERVER[
"PHP_SELF"],
'f.thirdparty_code,f.rowid',
'', $param,
'', $sortfield, $sortorder,
'width200 ');
266if ($modecompta ==
'BOOKKEEPING') {
267 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
'amount',
'', $param,
'class="right"', $sortfield, $sortorder);
269 if ($modecompta ==
'CREANCES-DETTES') {
270 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
'amount_ht',
'', $param,
'class="right"', $sortfield, $sortorder);
274 print_liste_field_titre(
"AmountTTC", $_SERVER[
"PHP_SELF"],
'amount_ttc',
'', $param,
'class="right"', $sortfield, $sortorder);
279$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
282if ($modecompta ==
'BOOKKEEPING') {
283 $predefinedgroupwhere =
"(";
284 $predefinedgroupwhere .=
" (pcg_type = 'EXPENSE')";
285 $predefinedgroupwhere .=
" OR ";
286 $predefinedgroupwhere .=
" (pcg_type = 'INCOME')";
287 $predefinedgroupwhere .=
")";
292 $sql =
"SELECT -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount";
293 if ($showaccountdetail ==
'no') {
294 $sql .=
", f.thirdparty_code as name";
296 $sql .=
" FROM ".$db->prefix().
"accounting_bookkeeping as f";
297 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_account as aa";
298 $sql .=
" ON aa.account_number = f.numero_compte";
299 $sql .=
" AND aa.entity = f.entity";
300 $sql .=
" WHERE 1=1";
301 $sql .=
" AND ".$predefinedgroupwhere;
302 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
303 $sql .=
" AND f.entity = ".$conf->entity;
304 if (!empty($date_start) && !empty($date_end)) {
305 $sql .=
" AND f.doc_date >= '".$db->idate($date_start).
"'";
306 $sql .=
" AND f.doc_date <= '".$db->idate($date_end).
"'";
308 $sql .=
" GROUP BY aa.pcg_type";
309 if ($showaccountdetail ==
'no') {
310 $sql .=
", name, socid";
312 $sql .= $db->order($sortfield, $sortorder);
316 dol_syslog(
"get bookkeeping entries", LOG_DEBUG);
317 $result = $db->query($sql);
319 $num = $db->num_rows($result);
323 $objp = $db->fetch_object($result);
325 if ($showaccountdetail ==
'no') {
326 if ($objp->pcg_type != $oldpcgtype) {
327 print
'<tr class="trforbreak"><td colspan="3" class="tdforbreak">'.dol_escape_htmltag($objp->pcg_type).
'</td></tr>';
328 $oldpcgtype = $objp->pcg_type;
332 if ($showaccountdetail ==
'no') {
333 print
'<tr class="oddeven">';
337 print($objp->name ?
' ('.dol_escape_htmltag($objp->name).
')' :
' ('.$langs->trans(
"Unknown").
')');
339 print
'<td class="right nowraponall"><span class="amount">'.price($objp->amount).
"</span></td>\n";
342 print
'<tr class="oddeven trforbreak">';
343 print
'<td colspan="2" class="tdforbreak">';
346 print
'<td class="right nowraponall tdforbreak"><span class="amount">'.price($objp->amount).
"</span></td>\n";
350 $total_ht += (isset($objp->amount) ? $objp->amount : 0);
351 $total_ttc += (isset($objp->amount) ? $objp->amount : 0);
353 if ($objp->pcg_type ==
'INCOME') {
354 $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
355 $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
357 if ($objp->pcg_type ==
'EXPENSE') {
358 $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
359 $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
364 if ($showaccountdetail !=
'no') {
365 $tmppredefinedgroupwhere =
"pcg_type = '".$db->escape($objp->pcg_type).
"'";
366 $tmppredefinedgroupwhere .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
370 $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
372 foreach ($cpts as $j => $cpt) {
373 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, (empty($cpt[
'dc']) ? 0 : $cpt[
'dc']));
378 $resultN = $AccCat->sdc;
382 if ($showaccountdetail ==
'all' || $resultN != 0) {
385 print
'<td class="tdoverflowmax200"> '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'].
'</td>';
386 print
'<td class="right nowraponall"><span class="amount">'.price($resultN).
'</span></td>';
395 print
'<tr><td colspan="3" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';
404 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
406 if ($modecompta ==
'CREANCES-DETTES') {
407 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
408 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
409 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
410 $sql .=
" WHERE f.fk_soc = s.rowid";
411 $sql .=
" AND f.fk_statut IN (1,2)";
413 $sql .=
" AND f.type IN (0,1,2,5)";
415 $sql .=
" AND f.type IN (0,1,2,3,5)";
417 if (!empty($date_start) && !empty($date_end)) {
418 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
420 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
425 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
426 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
427 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
428 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
429 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
430 $sql .=
" WHERE p.rowid = pf.fk_paiement";
431 $sql .=
" AND pf.fk_facture = f.rowid";
432 $sql .=
" AND f.fk_soc = s.rowid";
433 if (!empty($date_start) && !empty($date_end)) {
434 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
437 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
439 $sql .=
" AND f.fk_soc = ".((int) $socid);
441 $sql .=
" GROUP BY name, socid";
442 $sql .= $db->order($sortfield, $sortorder);
444 dol_syslog(
"get customer invoices", LOG_DEBUG);
445 $result = $db->query($sql);
447 $num = $db->num_rows($result);
450 $objp = $db->fetch_object($result);
452 print
'<tr class="oddeven">';
453 print
'<td> </td>';
454 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$objp->socid.
'">'.$objp->name.
"</td>\n";
456 print
'<td class="right">';
457 if ($modecompta ==
'CREANCES-DETTES') {
458 print
'<span class="amount">'.price($objp->amount_ht).
"</span>";
461 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
463 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
464 $total_ttc += $objp->amount_ttc;
474 if ($modecompta ==
'RECETTES-DEPENSES') {
475 $sql =
"SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc";
476 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
477 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
478 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
479 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
480 $sql .=
" WHERE pf.rowid IS NULL";
481 $sql .=
" AND p.fk_bank = b.rowid";
482 $sql .=
" AND b.fk_account = ba.rowid";
483 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
484 if (!empty($date_start) && !empty($date_end)) {
485 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
487 $sql .=
" GROUP BY name, idp";
488 $sql .=
" ORDER BY name";
490 dol_syslog(
"get old customer payments not linked to invoices", LOG_DEBUG);
491 $result = $db->query($sql);
493 $num = $db->num_rows($result);
497 $objp = $db->fetch_object($result);
500 print
'<tr class="oddeven">';
501 print
'<td> </td>';
502 print
"<td>".$langs->trans(
"Bills").
" ".$langs->trans(
"Other").
" (".$langs->trans(
"PaymentsNotLinkedToInvoice").
")\n";
504 print
'<td class="right">';
505 if ($modecompta ==
'CREANCES-DETTES') {
506 print
'<span class="amount">'.price($objp->amount_ht).
"</span></td>\n";
509 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
511 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
512 $total_ttc += $objp->amount_ttc;
524 if ($total_ttc == 0) {
525 print
'<tr class="oddeven">';
526 print
'<td> </td>';
527 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
531 $total_ht_income += $total_ht;
532 $total_ttc_income += $total_ttc;
534 print
'<tr class="liste_total">';
537 print
'<td class="right">';
538 if ($modecompta ==
'CREANCES-DETTES') {
539 print
price($total_ht);
542 print
'<td class="right">'.price($total_ttc).
'</td>';
549 if (isModEnabled(
'don')) {
550 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
552 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
553 if ($modecompta ==
'CREANCES-DETTES') {
554 $sql =
"SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
555 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
556 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
557 $sql .=
" AND fk_statut in (1,2)";
559 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
560 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
561 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
562 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
563 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
564 $sql .=
" AND fk_statut >= 2";
566 if (!empty($date_start) && !empty($date_end)) {
567 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
570 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
571 $newsortfield = $sortfield;
572 if ($newsortfield ==
's.nom, s.rowid') {
573 $newsortfield =
'p.societe, p.firstname, p.lastname, dm';
575 if ($newsortfield ==
'amount_ht') {
576 $newsortfield =
'amount';
578 if ($newsortfield ==
'amount_ttc') {
579 $newsortfield =
'amount';
581 $sql .= $db->order($newsortfield, $sortorder);
584 $result = $db->query($sql);
588 $num = $db->num_rows($result);
592 $obj = $db->fetch_object($result);
594 $total_ht += $obj->amount;
595 $total_ttc += $obj->amount;
596 $subtotal_ht += $obj->amount;
597 $subtotal_ttc += $obj->amount;
599 print
'<tr class="oddeven">';
600 print
'<td> </td>';
602 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";
604 print
'<td class="right">';
605 if ($modecompta ==
'CREANCES-DETTES') {
606 print
'<span class="amount">'.price($obj->amount).
'</span>';
609 print
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
614 print
'<tr class="oddeven"><td> </td>';
615 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
622 $total_ht_income += $subtotal_ht;
623 $total_ttc_income += $subtotal_ttc;
625 print
'<tr class="liste_total">';
628 print
'<td class="right">';
629 if ($modecompta ==
'CREANCES-DETTES') {
630 print
price($subtotal_ht);
633 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
640 if ($modecompta ==
'CREANCES-DETTES') {
641 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
642 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
643 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
644 $sql .=
" WHERE f.fk_soc = s.rowid";
645 $sql .=
" AND f.fk_statut IN (1,2)";
647 $sql .=
" AND f.type IN (0,1,2)";
649 $sql .=
" AND f.type IN (0,1,2,3)";
651 if (!empty($date_start) && !empty($date_end)) {
652 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
654 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
655 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
656 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
657 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
658 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f";
659 $sql .=
" ON pf.fk_facturefourn = f.rowid";
660 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s";
661 $sql .=
" ON f.fk_soc = s.rowid";
662 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
663 if (!empty($date_start) && !empty($date_end)) {
664 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
668 $sql .=
" AND f.entity = ".((int) $conf->entity);
670 $sql .=
" AND f.fk_soc = ".((int) $socid);
672 $sql .=
" GROUP BY name, socid";
673 $sql .= $db->order($sortfield, $sortorder);
675 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
679 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
680 $result = $db->query($sql);
682 $num = $db->num_rows($result);
686 $objp = $db->fetch_object($result);
688 print
'<tr class="oddeven">';
689 print
'<td> </td>';
690 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
"/fourn/facture/list.php?socid=".$objp->socid.
'">'.$objp->name.
'</a></td>'.
"\n";
692 print
'<td class="right">';
693 if ($modecompta ==
'CREANCES-DETTES') {
694 print
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
697 print
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
699 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
700 $total_ttc -= $objp->amount_ttc;
701 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
702 $subtotal_ttc += $objp->amount_ttc;
708 print
'<tr class="oddeven">';
709 print
'<td> </td>';
710 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
719 $total_ht_outcome += $subtotal_ht;
720 $total_ttc_outcome += $subtotal_ttc;
722 print
'<tr class="liste_total">';
725 print
'<td class="right">';
726 if ($modecompta ==
'CREANCES-DETTES') {
727 print
price(-$subtotal_ht);
730 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
738 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsNondeductibles").
'</td></tr>';
740 if ($modecompta ==
'CREANCES-DETTES') {
741 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
742 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
743 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
744 $sql .=
" WHERE cs.fk_type = c.id";
745 $sql .=
" AND c.deductible = 0";
746 if (!empty($date_start) && !empty($date_end)) {
747 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
749 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
750 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
751 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
752 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
753 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
754 $sql .=
" WHERE p.fk_charge = cs.rowid";
755 $sql .=
" AND cs.fk_type = c.id";
756 $sql .=
" AND c.deductible = 0";
757 if (!empty($date_start) && !empty($date_end)) {
758 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
761 $sql .=
" AND cs.entity = ".$conf->entity;
762 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
763 $newsortfield = $sortfield;
764 if ($newsortfield ==
's.nom, s.rowid') {
765 $newsortfield =
'c.libelle, c.id';
767 if ($newsortfield ==
'amount_ht') {
768 $newsortfield =
'amount';
770 if ($newsortfield ==
'amount_ttc') {
771 $newsortfield =
'amount';
774 $sql .= $db->order($newsortfield, $sortorder);
776 dol_syslog(
"get social contributions deductible=0", LOG_DEBUG);
777 $result = $db->query($sql);
781 $num = $db->num_rows($result);
785 $obj = $db->fetch_object($result);
787 $total_ht -= $obj->amount;
788 $total_ttc -= $obj->amount;
789 $subtotal_ht += $obj->amount;
790 $subtotal_ttc += $obj->amount;
793 if ($obj->accountancy_code) {
794 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
796 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
797 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
800 print
'<tr class="oddeven">';
801 print
'<td> </td>';
802 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
803 print
'<td class="right">';
804 if ($modecompta ==
'CREANCES-DETTES') {
805 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
808 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
813 print
'<tr class="oddeven">';
814 print
'<td> </td>';
815 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
822 $total_ht_outcome += $subtotal_ht;
823 $total_ttc_outcome += $subtotal_ttc;
825 print
'<tr class="liste_total">';
828 print
'<td class="right">';
829 if ($modecompta ==
'CREANCES-DETTES') {
830 print
price(-$subtotal_ht);
833 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
841 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsDeductibles").
'</td></tr>';
843 if ($modecompta ==
'CREANCES-DETTES') {
844 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
845 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
846 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
847 $sql .=
" WHERE cs.fk_type = c.id";
848 $sql .=
" AND c.deductible = 1";
849 if (!empty($date_start) && !empty($date_end)) {
850 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
852 $sql .=
" AND cs.entity = ".$conf->entity;
853 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
854 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
855 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
856 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
857 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
858 $sql .=
" WHERE p.fk_charge = cs.rowid";
859 $sql .=
" AND cs.fk_type = c.id";
860 $sql .=
" AND c.deductible = 1";
861 if (!empty($date_start) && !empty($date_end)) {
862 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
864 $sql .=
" AND cs.entity = ".$conf->entity;
866 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
867 $newsortfield = $sortfield;
868 if ($newsortfield ==
's.nom, s.rowid') {
869 $newsortfield =
'c.libelle, c.id';
871 if ($newsortfield ==
'amount_ht') {
872 $newsortfield =
'amount';
874 if ($newsortfield ==
'amount_ttc') {
875 $newsortfield =
'amount';
877 $sql .= $db->order($newsortfield, $sortorder);
879 dol_syslog(
"get social contributions deductible=1", LOG_DEBUG);
880 $result = $db->query($sql);
884 $num = $db->num_rows($result);
888 $obj = $db->fetch_object($result);
890 $total_ht -= $obj->amount;
891 $total_ttc -= $obj->amount;
892 $subtotal_ht += $obj->amount;
893 $subtotal_ttc += $obj->amount;
896 if ($obj->accountancy_code) {
897 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
899 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
900 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
903 print
'<tr class="oddeven">';
904 print
'<td> </td>';
905 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
906 print
'<td class="right">';
907 if ($modecompta ==
'CREANCES-DETTES') {
908 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
911 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
916 print
'<tr class="oddeven">';
917 print
'<td> </td>';
918 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
925 $total_ht_outcome += $subtotal_ht;
926 $total_ttc_outcome += $subtotal_ttc;
928 print
'<tr class="liste_total">';
931 print
'<td class="right">';
932 if ($modecompta ==
'CREANCES-DETTES') {
933 print
price(-$subtotal_ht);
936 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
944 if (isModEnabled(
'salaries')) {
945 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
947 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
948 if ($modecompta ==
'CREANCES-DETTES') {
949 $column =
's.dateep';
951 $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";
952 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
953 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
954 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
955 if (!empty($date_start) && !empty($date_end)) {
956 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
958 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, s.label, dm";
962 $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";
963 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
964 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = p.fk_salary";
965 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
966 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
967 if (!empty($date_start) && !empty($date_end)) {
968 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
970 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, p.label, dm";
973 $newsortfield = $sortfield;
974 if ($newsortfield ==
's.nom, s.rowid') {
975 $newsortfield =
'u.firstname, u.lastname';
977 if ($newsortfield ==
'amount_ht') {
978 $newsortfield =
'amount';
980 if ($newsortfield ==
'amount_ttc') {
981 $newsortfield =
'amount';
983 $sql .= $db->order($newsortfield, $sortorder);
987 $result = $db->query($sql);
991 $num = $db->num_rows($result);
995 $obj = $db->fetch_object($result);
997 $total_ht -= $obj->amount;
998 $total_ttc -= $obj->amount;
999 $subtotal_ht += $obj->amount;
1000 $subtotal_ttc += $obj->amount;
1002 print
'<tr class="oddeven"><td> </td>';
1004 $userstatic =
new User($db);
1005 $userstatic->fetch($obj->fk_user);
1007 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";
1008 print
'<td class="right">';
1009 if ($modecompta ==
'CREANCES-DETTES') {
1010 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1013 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1018 print
'<tr class="oddeven">';
1019 print
'<td> </td>';
1020 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1027 $total_ht_outcome += $subtotal_ht;
1028 $total_ttc_outcome += $subtotal_ttc;
1030 print
'<tr class="liste_total">';
1033 print
'<td class="right">';
1034 if ($modecompta ==
'CREANCES-DETTES') {
1035 print
price(-$subtotal_ht);
1038 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1047 if (isModEnabled(
'expensereport')) {
1048 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
1049 $langs->load(
'trips');
1050 if ($modecompta ==
'CREANCES-DETTES') {
1051 $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";
1052 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1053 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1054 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1055 $sql .=
" AND p.fk_statut>=5";
1057 $column =
'p.date_valid';
1059 $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";
1060 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1061 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1062 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
1063 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
1064 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1065 $sql .=
" AND p.fk_statut>=5";
1067 $column =
'pe.datep';
1070 if (!empty($date_start) && !empty($date_end)) {
1071 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
1074 if ($modecompta ==
'CREANCES-DETTES') {
1077 $sql .=
" GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
1079 $newsortfield = $sortfield;
1080 if ($newsortfield ==
's.nom, s.rowid') {
1081 $newsortfield =
'p.ref';
1083 $sql .= $db->order($newsortfield, $sortorder);
1086 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
1089 $result = $db->query($sql);
1093 $num = $db->num_rows($result);
1095 while ($obj = $db->fetch_object($result)) {
1096 $total_ht -= $obj->amount_ht;
1097 $total_ttc -= $obj->amount_ttc;
1098 $subtotal_ht += $obj->amount_ht;
1099 $subtotal_ttc += $obj->amount_ttc;
1101 print
'<tr class="oddeven">';
1102 print
'<td> </td>';
1103 print
"<td>".$langs->trans(
"ExpenseReport").
" <a href=\"".DOL_URL_ROOT.
"/expensereport/list.php?search_user=".$obj->userid.
"\">".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
1104 print
'<td class="right">';
1105 if ($modecompta ==
'CREANCES-DETTES') {
1106 print
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
1109 print
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
1113 print
'<tr class="oddeven">';
1114 print
'<td> </td>';
1115 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1122 $total_ht_outcome += $subtotal_ht;
1123 $total_ttc_outcome += $subtotal_ttc;
1125 print
'<tr class="liste_total">';
1128 print
'<td class="right">';
1129 if ($modecompta ==
'CREANCES-DETTES') {
1130 print
price(-$subtotal_ht);
1133 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1143 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled(
"banque") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1147 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
1150 $sql =
"SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
1151 $sql .=
' WHERE 1 = 1';
1152 if (!empty($date_start) && !empty($date_end)) {
1153 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1155 $sql .=
' GROUP BY p.sens';
1156 $sql .=
' ORDER BY p.sens';
1158 dol_syslog(
'get various payments', LOG_DEBUG);
1159 $result = $db->query($sql);
1162 $obj = $db->fetch_object($result);
1163 if (isset($obj->amount)) {
1164 $subtotal_ht += -$obj->amount;
1165 $subtotal_ttc += -$obj->amount;
1167 $total_ht_outcome += $obj->amount;
1168 $total_ttc_outcome += $obj->amount;
1170 print
'<tr class="oddeven">';
1171 print
'<td> </td>';
1172 print
"<td>".$langs->trans(
"AccountingDebit").
"</td>\n";
1173 print
'<td class="right">';
1174 if ($modecompta ==
'CREANCES-DETTES') {
1175 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1178 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1182 $obj = $db->fetch_object($result);
1183 if (isset($obj->amount)) {
1184 $subtotal_ht += $obj->amount;
1185 $subtotal_ttc += $obj->amount;
1187 $total_ht_income += $obj->amount;
1188 $total_ttc_income += $obj->amount;
1190 print
'<tr class="oddeven"><td> </td>';
1191 print
"<td>".$langs->trans(
"AccountingCredit").
"</td>\n";
1192 print
'<td class="right">';
1193 if ($modecompta ==
'CREANCES-DETTES') {
1194 print
'<span class="amount">'.price($obj->amount).
'</span>';
1197 print
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
1201 $total_ht += $subtotal_ht;
1202 $total_ttc += $subtotal_ttc;
1203 print
'<tr class="liste_total">';
1206 print
'<td class="right">';
1207 if ($modecompta ==
'CREANCES-DETTES') {
1208 print
price($subtotal_ht);
1211 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1222 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1226 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
1228 $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';
1229 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
1230 $sql .=
' WHERE 1 = 1';
1231 if (!empty($date_start) && !empty($date_end)) {
1232 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1234 $sql .=
' GROUP BY p.fk_loan';
1235 $sql .=
' ORDER BY p.fk_loan';
1238 $result = $db->query($sql);
1240 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
1241 $loan_static =
new Loan($db);
1242 while ($obj = $db->fetch_object($result)) {
1243 $loan_static->id = $obj->id;
1244 $loan_static->ref = $obj->id;
1245 $loan_static->label = $obj->label;
1246 print
'<tr class="oddeven"><td> </td>';
1247 print
"<td>".$loan_static->getNomUrl(1).
' - '.$obj->label.
"</td>\n";
1248 if ($modecompta ==
'CREANCES-DETTES') {
1249 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1251 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1253 $subtotal_ht -= $obj->amount;
1254 $subtotal_ttc -= $obj->amount;
1256 $total_ht += $subtotal_ht;
1257 $total_ttc += $subtotal_ttc;
1259 $total_ht_income += $subtotal_ht;
1260 $total_ttc_income += $subtotal_ttc;
1262 print
'<tr class="liste_total">';
1265 print
'<td class="right">';
1266 if ($modecompta ==
'CREANCES-DETTES') {
1267 print
price($subtotal_ht);
1270 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1281 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VAT").
'</td></tr>';
1285 if (isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES')) {
1286 if ($modecompta ==
'CREANCES-DETTES') {
1289 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1290 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1291 $sql .=
" WHERE f.fk_statut IN (1,2)";
1293 $sql .=
" AND f.type IN (0,1,2,5)";
1295 $sql .=
" AND f.type IN (0,1,2,3,5)";
1297 if (!empty($date_start) && !empty($date_end)) {
1298 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1300 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
1301 $sql .=
" GROUP BY dm";
1302 $newsortfield = $sortfield;
1303 if ($newsortfield ==
's.nom, s.rowid') {
1304 $newsortfield =
'dm';
1306 if ($newsortfield ==
'amount_ht') {
1307 $newsortfield =
'amount';
1309 if ($newsortfield ==
'amount_ttc') {
1310 $newsortfield =
'amount';
1312 $sql .= $db->order($newsortfield, $sortorder);
1315 $result = $db->query($sql);
1317 $num = $db->num_rows($result);
1321 $obj = $db->fetch_object($result);
1323 $amount -= $obj->amount;
1325 $total_ttc -= $obj->amount;
1327 $subtotal_ttc -= $obj->amount;
1335 $total_ht_outcome -= 0;
1336 $total_ttc_outcome -= $amount;
1338 print
'<tr class="oddeven">';
1339 print
'<td> </td>';
1340 print
"<td>".$langs->trans(
"VATToPay").
"</td>\n";
1341 print
'<td class="right"> </td>'.
"\n";
1342 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1347 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1348 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1349 $sql .=
" WHERE f.fk_statut IN (1,2)";
1351 $sql .=
" AND f.type IN (0,1,2)";
1353 $sql .=
" AND f.type IN (0,1,2,3)";
1355 if (!empty($date_start) && !empty($date_end)) {
1356 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1358 $sql .=
" AND f.entity = ".$conf->entity;
1359 $sql .=
" GROUP BY dm";
1360 $newsortfield = $sortfield;
1361 if ($newsortfield ==
's.nom, s.rowid') {
1362 $newsortfield =
'dm';
1364 if ($newsortfield ==
'amount_ht') {
1365 $newsortfield =
'amount';
1367 if ($newsortfield ==
'amount_ttc') {
1368 $newsortfield =
'amount';
1370 $sql .= $db->order($newsortfield, $sortorder);
1372 dol_syslog(
"get vat received back", LOG_DEBUG);
1373 $result = $db->query($sql);
1375 $num = $db->num_rows($result);
1379 $obj = $db->fetch_object($result);
1381 $amount += $obj->amount;
1383 $total_ttc += $obj->amount;
1385 $subtotal_ttc += $obj->amount;
1394 $total_ht_income += 0;
1395 $total_ttc_income += $amount;
1397 print
'<tr class="oddeven">';
1398 print
'<td> </td>';
1399 print
'<td>'.$langs->trans(
"VATToCollect").
"</td>\n";
1400 print
'<td class="right"> </td>'.
"\n";
1401 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1406 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1407 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1408 $sql .=
" WHERE amount > 0";
1409 if (!empty($date_start) && !empty($date_end)) {
1410 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1412 $sql .=
" AND t.entity = ".$conf->entity;
1413 $sql .=
" GROUP BY dm";
1414 $newsortfield = $sortfield;
1415 if ($newsortfield ==
's.nom, s.rowid') {
1416 $newsortfield =
'dm';
1418 if ($newsortfield ==
'amount_ht') {
1419 $newsortfield =
'amount';
1421 if ($newsortfield ==
'amount_ttc') {
1422 $newsortfield =
'amount';
1424 $sql .= $db->order($newsortfield, $sortorder);
1426 dol_syslog(
"get vat really paid", LOG_DEBUG);
1427 $result = $db->query($sql);
1429 $num = $db->num_rows($result);
1433 $obj = $db->fetch_object($result);
1435 $amount -= $obj->amount;
1436 $total_ht -= $obj->amount;
1437 $total_ttc -= $obj->amount;
1438 $subtotal_ht -= $obj->amount;
1439 $subtotal_ttc -= $obj->amount;
1449 $total_ht_outcome -= 0;
1450 $total_ttc_outcome -= $amount;
1452 print
'<tr class="oddeven">';
1453 print
'<td> </td>';
1454 print
"<td>".$langs->trans(
"VATPaid").
"</td>\n";
1455 print
'<td <class="right"></td>'.
"\n";
1456 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1461 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1462 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1463 $sql .=
" WHERE amount < 0";
1464 if (!empty($date_start) && !empty($date_end)) {
1465 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1467 $sql .=
" AND t.entity = ".$conf->entity;
1468 $sql .=
" GROUP BY dm";
1469 $newsortfield = $sortfield;
1470 if ($newsortfield ==
's.nom, s.rowid') {
1471 $newsortfield =
'dm';
1473 if ($newsortfield ==
'amount_ht') {
1474 $newsortfield =
'amount';
1476 if ($newsortfield ==
'amount_ttc') {
1477 $newsortfield =
'amount';
1479 $sql .= $db->order($newsortfield, $sortorder);
1481 dol_syslog(
"get vat really received back", LOG_DEBUG);
1482 $result = $db->query($sql);
1484 $num = $db->num_rows($result);
1488 $obj = $db->fetch_object($result);
1490 $amount += -$obj->amount;
1491 $total_ht += -$obj->amount;
1492 $total_ttc += -$obj->amount;
1493 $subtotal_ht += -$obj->amount;
1494 $subtotal_ttc += -$obj->amount;
1504 $total_ht_income += 0;
1505 $total_ttc_income += $amount;
1507 print
'<tr class="oddeven">';
1508 print
'<td> </td>';
1509 print
"<td>".$langs->trans(
"VATCollected").
"</td>\n";
1510 print
'<td class="right"></td>'.
"\n";
1511 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1516 if ($mysoc->tva_assuj !=
'0') {
1517 print
'<tr class="liste_total">';
1520 print
'<td class="right"> </td>';
1521 print
'<td class="right">'.price(
price2num($subtotal_ttc,
'MT')).
'</td>';
1526$action =
"balanceclient";
1527$object = array(&$total_ht, &$total_ttc);
1528$parameters[
"mode"] = $modecompta;
1529$parameters[
"date_start"] = $date_start;
1530$parameters[
"date_end"] = $date_end;
1532$hookmanager->initHooks(array(
'externalbalance'));
1533$reshook = $hookmanager->executeHooks(
'addBalanceLine', $parameters, $object, $action);
1534print $hookmanager->resPrint;
1540print
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
1543print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1544if ($modecompta ==
'CREANCES-DETTES') {
1545 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1546} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1549print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1551print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1552if ($modecompta ==
'CREANCES-DETTES') {
1553 print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1554} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1557print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1559print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1560if ($modecompta ==
'CREANCES-DETTES') {
1561 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht,
'MT')).
'</td>';
1562} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1565print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc,
'MT')).
'</td>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage categories of an accounting account.
Class to manage accounting accounts.
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
restrictedArea(User $user, $features, $object=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.