36require
'../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancycategory.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
57$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy',
'loan'));
59$date_startmonth =
GETPOSTINT(
'date_startmonth');
65$showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'yes';
68$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
69$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
71if (empty($page) || $page == -1) {
74$offset = $limit * $page;
87 $year_start = $year_current;
89 $year_current = $year;
94$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
97if (empty($date_start) || empty($date_end)) {
101 $year_end = $year_start;
105 if (!$year && $month_start > $month_current) {
110 $month_end = $month_start - 1;
111 $year_end = $year_start + 1;
113 if ($month_end < 1) {
117 $month_end = $month_start;
142$year_start = $tmps[
'year'];
144$year_end = $tmpe[
'year'];
145$nbofyear = ($year_end - $year_start) + 1;
151 $modecompta =
'BOOKKEEPING';
153if (
GETPOST(
"modecompta",
'alpha')) {
154 $modecompta =
GETPOST(
"modecompta",
'alpha');
161if ($user->socid > 0) {
162 $socid = $user->socid;
166$hookmanager->initHooks([
'customersupplierreportlist']);
172 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
195if ($modecompta ==
"CREANCES-DETTES") {
196 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
197 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
198 $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>" :
"");
199 $description = $langs->trans(
"RulesResultDue");
201 $description .= $langs->trans(
"DepositsAreNotIncluded");
203 $description .= $langs->trans(
"DepositsAreIncluded");
206 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
210} elseif ($modecompta ==
"RECETTES-DEPENSES") {
211 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
212 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
213 $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>" :
"");
214 $description = $langs->trans(
"RulesResultInOut");
217} elseif ($modecompta ==
"BOOKKEEPING") {
218 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
219 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
220 $arraylist = array(
'no' => $langs->trans(
"CustomerCode"),
'yes' => $langs->trans(
"AccountWithNonZeroValues"),
'all' => $langs->trans(
"All"));
221 $period .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
222 $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>" :
"");
223 $description = $langs->trans(
"RulesResultBookkeepingPredefined");
224 $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")).
')';
232 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
235$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModePayment");
237 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
239$calcmode .=
'</label>';
240$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
242 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
244$calcmode .=
'</label>';
247report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta' => $modecompta,
'showaccountdetail' => $showaccountdetail), $calcmode);
249if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
250 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
254$param =
'&modecompta='.urlencode($modecompta).
'&showaccountdetail='.urlencode($showaccountdetail);
256 $param .=
'&date_startday='.$date_startday;
258if ($date_startmonth) {
259 $param .=
'&date_startmonth='.$date_startmonth;
261if ($date_startyear) {
262 $param .=
'&date_startyear='.$date_startyear;
265 $param .=
'&date_endday='.$date_endday;
268 $param .=
'&date_endmonth='.$date_endmonth;
271 $param .=
'&date_endyear='.$date_endyear;
274print
'<table class="liste noborder centpercent">';
275print
'<tr class="liste_titre">';
277if ($modecompta ==
'BOOKKEEPING') {
278 print_liste_field_titre(
"PredefinedGroups", $_SERVER[
"PHP_SELF"],
'f.thirdparty_code,f.rowid',
'', $param,
'', $sortfield, $sortorder,
'');
283if ($modecompta ==
'BOOKKEEPING') {
284 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
'amount',
'', $param,
'class="right"', $sortfield, $sortorder);
286 if ($modecompta ==
'CREANCES-DETTES') {
287 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
'amount_ht',
'', $param,
'class="right"', $sortfield, $sortorder);
291 print_liste_field_titre(
"AmountTTC", $_SERVER[
"PHP_SELF"],
'amount_ttc',
'', $param,
'class="right"', $sortfield, $sortorder);
296$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
299if ($modecompta ==
'BOOKKEEPING') {
300 $sanitizedpredefinedgroupwhere =
"(";
301 $sanitizedpredefinedgroupwhere .=
" (pcg_type = 'EXPENSE')";
302 $sanitizedpredefinedgroupwhere .=
" OR ";
303 $sanitizedpredefinedgroupwhere .=
" (pcg_type = 'INCOME')";
304 $sanitizedpredefinedgroupwhere .=
")";
309 $sql =
"SELECT -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount";
310 if ($showaccountdetail ==
'no') {
311 $sql .=
", f.thirdparty_code as name";
313 $sql .=
" FROM ".$db->prefix().
"accounting_bookkeeping as f";
314 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_account as aa";
315 $sql .=
" ON aa.account_number = f.numero_compte";
316 $sql .=
" AND aa.entity = f.entity";
317 $sql .=
" WHERE 1=1";
318 $sql .=
" AND ".$sanitizedpredefinedgroupwhere;
319 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
320 $sql .=
" AND f.entity = ".$conf->entity;
321 if (!empty($date_start) && !empty($date_end)) {
322 $sql .=
" AND f.doc_date >= '".$db->idate($date_start).
"'";
323 $sql .=
" AND f.doc_date <= '".$db->idate($date_end).
"'";
325 $sql .=
" GROUP BY aa.pcg_type";
326 if ($showaccountdetail ==
'no') {
327 $sql .=
", name, socid";
329 $sql .=
$db->order($sortfield, $sortorder);
333 dol_syslog(
"get bookkeeping entries", LOG_DEBUG);
334 $result =
$db->query($sql);
336 $num =
$db->num_rows($result);
340 $objp =
$db->fetch_object($result);
342 if ($showaccountdetail ==
'no') {
343 if ($objp->pcg_type != $oldpcgtype) {
344 print
'<tr class="trforbreak"><td colspan="3" class="tdforbreak">'.dol_escape_htmltag($objp->pcg_type).
'</td></tr>';
345 $oldpcgtype = $objp->pcg_type;
349 if ($showaccountdetail ==
'no') {
350 print
'<tr class="oddeven">';
354 print($objp->name ?
' ('.dol_escape_htmltag($objp->name).
')' :
' ('.$langs->trans(
"Unknown").
')');
356 print
'<td class="right nowraponall"><span class="amount">'.price($objp->amount).
"</span></td>\n";
359 print
'<tr class="oddeven trforbreak">';
360 print
'<td colspan="2" class="tdforbreak">';
363 print
'<td class="right nowraponall tdforbreak"><span class="amount">'.price($objp->amount).
"</span></td>\n";
367 $total_ht += (isset($objp->amount) ? $objp->amount : 0);
368 $total_ttc += (isset($objp->amount) ? $objp->amount : 0);
370 if ($objp->pcg_type ==
'INCOME') {
371 $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
372 $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
374 if ($objp->pcg_type ==
'EXPENSE') {
375 $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
376 $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
381 if ($showaccountdetail !=
'no') {
382 $tmppredefinedgroupwhere =
"pcg_type = '".$db->escape($objp->pcg_type).
"'";
383 $tmppredefinedgroupwhere .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
387 $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
389 foreach ($cpts as $j => $cpt) {
390 $return = $AccCat->getSumDebitCredit((
int) $cpt[
'account_number'], $date_start, $date_end, (empty($cpt[
'dc']) ? 0 : $cpt[
'dc']));
395 $resultN = $AccCat->sdc;
399 if ($showaccountdetail ==
'all' || $resultN != 0) {
402 print
'<td class="tdoverflowmax200"> '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'].
'</td>';
403 print
'<td class="right nowraponall"><span class="amount">'.price($resultN).
'</span></td>';
412 print
'<tr><td colspan="3" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';
421 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
423 if ($modecompta ==
'CREANCES-DETTES') {
424 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
425 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
426 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
427 $sql .=
" WHERE f.fk_soc = s.rowid";
428 $sql .=
" AND f.fk_statut IN (1,2)";
430 $sql .=
" AND f.type IN (0,1,2,5)";
432 $sql .=
" AND f.type IN (0,1,2,3,5)";
434 if (!empty($date_start) && !empty($date_end)) {
435 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".
$db->idate($date_end).
"'";
437 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
442 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
443 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
444 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
445 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
446 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
447 $sql .=
" WHERE p.rowid = pf.fk_paiement";
448 $sql .=
" AND pf.fk_facture = f.rowid";
449 $sql .=
" AND f.fk_soc = s.rowid";
450 if (!empty($date_start) && !empty($date_end)) {
451 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".
$db->idate($date_end).
"'";
456 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
458 $sql .=
" AND f.fk_soc = ".((int) $socid);
460 $sql .=
" GROUP BY name, socid";
461 $sql .=
$db->order($sortfield, $sortorder);
463 dol_syslog(
"get customer invoices", LOG_DEBUG);
464 $result =
$db->query($sql);
466 $num =
$db->num_rows($result);
469 $objp =
$db->fetch_object($result);
471 print
'<tr class="oddeven">';
472 print
'<td> </td>';
473 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$objp->socid.
'">'.$objp->name.
"</td>\n";
475 print
'<td class="right">';
476 if ($modecompta ==
'CREANCES-DETTES') {
477 print
'<span class="amount">'.price($objp->amount_ht).
"</span>";
480 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
482 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
483 $total_ttc += $objp->amount_ttc;
493 if ($modecompta ==
'RECETTES-DEPENSES') {
494 $sql =
"SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc";
495 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
496 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
497 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
498 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
499 $sql .=
" WHERE pf.rowid IS NULL";
500 $sql .=
" AND p.fk_bank = b.rowid";
501 $sql .=
" AND b.fk_account = ba.rowid";
502 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
503 if (!empty($date_start) && !empty($date_end)) {
504 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".
$db->idate($date_end).
"'";
506 $sql .=
" GROUP BY name, idp";
507 $sql .=
" ORDER BY name";
509 dol_syslog(
"get old customer payments not linked to invoices", LOG_DEBUG);
510 $result =
$db->query($sql);
512 $num =
$db->num_rows($result);
516 $objp =
$db->fetch_object($result);
519 print
'<tr class="oddeven">';
520 print
'<td> </td>';
521 print
"<td>".$langs->trans(
"Bills").
" ".$langs->trans(
"Other").
" (".$langs->trans(
"PaymentsNotLinkedToInvoice").
")\n";
523 print
'<td class="right">';
524 if ($modecompta ==
'CREANCES-DETTES') {
525 print
'<span class="amount">'.price($objp->amount_ht).
"</span></td>\n";
528 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
530 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
531 $total_ttc += $objp->amount_ttc;
543 if ($total_ttc == 0) {
544 print
'<tr class="oddeven">';
545 print
'<td> </td>';
546 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
550 $total_ht_income += $total_ht;
551 $total_ttc_income += $total_ttc;
553 print
'<tr class="liste_total">';
556 print
'<td class="right">';
557 if ($modecompta ==
'CREANCES-DETTES') {
558 print
price($total_ht);
561 print
'<td class="right">'.price($total_ttc).
'</td>';
569 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
571 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
572 if ($modecompta ==
'CREANCES-DETTES') {
573 $sql =
"SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
574 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
575 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
576 $sql .=
" AND fk_statut in (1,2)";
578 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(pe.amount) as amount";
579 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
580 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
581 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
582 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
583 $sql .=
" AND fk_statut >= 2";
585 if (!empty($date_start) && !empty($date_end)) {
586 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".
$db->idate($date_end).
"'";
589 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
590 $newsortfield = $sortfield;
591 if ($newsortfield ==
's.nom, s.rowid') {
592 $newsortfield =
'p.societe, p.firstname, p.lastname, dm';
594 if ($newsortfield ==
'amount_ht') {
595 $newsortfield =
'amount';
597 if ($newsortfield ==
'amount_ttc') {
598 $newsortfield =
'amount';
600 $sql .=
$db->order($newsortfield, $sortorder);
603 $result =
$db->query($sql);
607 $num =
$db->num_rows($result);
611 $obj =
$db->fetch_object($result);
613 $total_ht += $obj->amount;
614 $total_ttc += $obj->amount;
615 $subtotal_ht += $obj->amount;
616 $subtotal_ttc += $obj->amount;
618 print
'<tr class="oddeven">';
619 print
'<td> </td>';
621 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";
623 print
'<td class="right">';
624 if ($modecompta ==
'CREANCES-DETTES') {
625 print
'<span class="amount">'.price($obj->amount).
'</span>';
628 print
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
633 print
'<tr class="oddeven"><td> </td>';
634 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
641 $total_ht_income += $subtotal_ht;
642 $total_ttc_income += $subtotal_ttc;
644 print
'<tr class="liste_total">';
647 print
'<td class="right">';
648 if ($modecompta ==
'CREANCES-DETTES') {
649 print
price($subtotal_ht);
652 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
659 if ($modecompta ==
'CREANCES-DETTES') {
660 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
661 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
662 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
663 $sql .=
" WHERE f.fk_soc = s.rowid";
664 $sql .=
" AND f.fk_statut IN (1,2)";
666 $sql .=
" AND f.type IN (0,1,2)";
668 $sql .=
" AND f.type IN (0,1,2,3)";
670 if (!empty($date_start) && !empty($date_end)) {
671 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".
$db->idate($date_end).
"'";
673 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
674 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
675 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
676 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
677 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f";
678 $sql .=
" ON pf.fk_facturefourn = f.rowid";
679 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s";
680 $sql .=
" ON f.fk_soc = s.rowid";
681 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
682 if (!empty($date_start) && !empty($date_end)) {
683 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".
$db->idate($date_end).
"'";
687 $sql .=
" AND f.entity = ".((int)
$conf->entity);
689 $sql .=
" AND f.fk_soc = ".((int) $socid);
691 $sql .=
" GROUP BY name, socid";
692 $sql .=
$db->order($sortfield, $sortorder);
694 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
698 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
699 $result =
$db->query($sql);
701 $num =
$db->num_rows($result);
705 $objp =
$db->fetch_object($result);
707 print
'<tr class="oddeven">';
708 print
'<td> </td>';
709 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
"/fourn/facture/list.php?socid=".$objp->socid.
'">'.$objp->name.
'</a></td>'.
"\n";
711 print
'<td class="right">';
712 if ($modecompta ==
'CREANCES-DETTES') {
713 print
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
716 print
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
718 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
719 $total_ttc -= $objp->amount_ttc;
720 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
721 $subtotal_ttc += $objp->amount_ttc;
727 print
'<tr class="oddeven">';
728 print
'<td> </td>';
729 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
738 $total_ht_outcome += $subtotal_ht;
739 $total_ttc_outcome += $subtotal_ttc;
741 print
'<tr class="liste_total">';
744 print
'<td class="right">';
745 if ($modecompta ==
'CREANCES-DETTES') {
746 print
price(-$subtotal_ht);
749 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
757 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsNondeductibles").
'</td></tr>';
759 if ($modecompta ==
'CREANCES-DETTES') {
760 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
761 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
762 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
763 $sql .=
" WHERE cs.fk_type = c.id";
764 $sql .=
" AND c.deductible = 0";
765 if (!empty($date_start) && !empty($date_end)) {
766 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".
$db->idate($date_end).
"'";
768 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
769 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
770 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
771 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
772 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
773 $sql .=
" WHERE p.fk_charge = cs.rowid";
774 $sql .=
" AND cs.fk_type = c.id";
775 $sql .=
" AND c.deductible = 0";
776 if (!empty($date_start) && !empty($date_end)) {
777 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".
$db->idate($date_end).
"'";
780 $sql .=
" AND cs.entity = ".$conf->entity;
781 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
782 $newsortfield = $sortfield;
783 if ($newsortfield ==
's.nom, s.rowid') {
784 $newsortfield =
'c.libelle, c.id';
786 if ($newsortfield ==
'amount_ht') {
787 $newsortfield =
'amount';
789 if ($newsortfield ==
'amount_ttc') {
790 $newsortfield =
'amount';
793 $sql .=
$db->order($newsortfield, $sortorder);
795 dol_syslog(
"get social contributions deductible=0", LOG_DEBUG);
796 $result =
$db->query($sql);
800 $num =
$db->num_rows($result);
804 $obj =
$db->fetch_object($result);
806 $total_ht -= $obj->amount;
807 $total_ttc -= $obj->amount;
808 $subtotal_ht += $obj->amount;
809 $subtotal_ttc += $obj->amount;
812 if ($obj->accountancy_code) {
813 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
815 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
816 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
819 print
'<tr class="oddeven">';
820 print
'<td> </td>';
821 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
822 print
'<td class="right">';
823 if ($modecompta ==
'CREANCES-DETTES') {
824 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
827 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
832 print
'<tr class="oddeven">';
833 print
'<td> </td>';
834 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
841 $total_ht_outcome += $subtotal_ht;
842 $total_ttc_outcome += $subtotal_ttc;
844 print
'<tr class="liste_total">';
847 print
'<td class="right">';
848 if ($modecompta ==
'CREANCES-DETTES') {
849 print
price(-$subtotal_ht);
852 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
860 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsDeductibles").
'</td></tr>';
862 if ($modecompta ==
'CREANCES-DETTES') {
863 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
864 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
865 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
866 $sql .=
" WHERE cs.fk_type = c.id";
867 $sql .=
" AND c.deductible = 1";
868 if (!empty($date_start) && !empty($date_end)) {
869 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".
$db->idate($date_end).
"'";
871 $sql .=
" AND cs.entity = ".$conf->entity;
872 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
873 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
874 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
875 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
876 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
877 $sql .=
" WHERE p.fk_charge = cs.rowid";
878 $sql .=
" AND cs.fk_type = c.id";
879 $sql .=
" AND c.deductible = 1";
880 if (!empty($date_start) && !empty($date_end)) {
881 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".
$db->idate($date_end).
"'";
883 $sql .=
" AND cs.entity = ".$conf->entity;
885 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
886 $newsortfield = $sortfield;
887 if ($newsortfield ==
's.nom, s.rowid') {
888 $newsortfield =
'c.libelle, c.id';
890 if ($newsortfield ==
'amount_ht') {
891 $newsortfield =
'amount';
893 if ($newsortfield ==
'amount_ttc') {
894 $newsortfield =
'amount';
896 $sql .=
$db->order($newsortfield, $sortorder);
898 dol_syslog(
"get social contributions deductible=1", LOG_DEBUG);
899 $result =
$db->query($sql);
903 $num =
$db->num_rows($result);
907 $obj =
$db->fetch_object($result);
909 $total_ht -= $obj->amount;
910 $total_ttc -= $obj->amount;
911 $subtotal_ht += $obj->amount;
912 $subtotal_ttc += $obj->amount;
915 if ($obj->accountancy_code) {
916 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
918 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
919 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
922 print
'<tr class="oddeven">';
923 print
'<td> </td>';
924 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
925 print
'<td class="right">';
926 if ($modecompta ==
'CREANCES-DETTES') {
927 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
930 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
935 print
'<tr class="oddeven">';
936 print
'<td> </td>';
937 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
944 $total_ht_outcome += $subtotal_ht;
945 $total_ttc_outcome += $subtotal_ttc;
947 print
'<tr class="liste_total">';
950 print
'<td class="right">';
951 if ($modecompta ==
'CREANCES-DETTES') {
952 print
price(-$subtotal_ht);
955 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
964 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
966 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
967 if ($modecompta ==
'CREANCES-DETTES') {
968 $column =
's.dateep';
970 $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";
971 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
972 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
973 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
974 if (!empty($date_start) && !empty($date_end)) {
975 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".
$db->idate($date_end).
"'";
977 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, s.label, dm";
981 $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";
982 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
983 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = p.fk_salary";
984 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
985 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
986 if (!empty($date_start) && !empty($date_end)) {
987 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".
$db->idate($date_end).
"'";
989 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, p.label, dm";
992 $newsortfield = $sortfield;
993 if ($newsortfield ==
's.nom, s.rowid') {
994 $newsortfield =
'u.firstname, u.lastname';
996 if ($newsortfield ==
'amount_ht') {
997 $newsortfield =
'amount';
999 if ($newsortfield ==
'amount_ttc') {
1000 $newsortfield =
'amount';
1002 $sql .=
$db->order($newsortfield, $sortorder);
1006 $result =
$db->query($sql);
1010 $num =
$db->num_rows($result);
1014 $obj =
$db->fetch_object($result);
1016 $total_ht -= $obj->amount;
1017 $total_ttc -= $obj->amount;
1018 $subtotal_ht += $obj->amount;
1019 $subtotal_ttc += $obj->amount;
1021 print
'<tr class="oddeven"><td> </td>';
1024 $userstatic->fetch($obj->fk_user);
1026 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";
1027 print
'<td class="right">';
1028 if ($modecompta ==
'CREANCES-DETTES') {
1029 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1032 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1037 print
'<tr class="oddeven">';
1038 print
'<td> </td>';
1039 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1046 $total_ht_outcome += $subtotal_ht;
1047 $total_ttc_outcome += $subtotal_ttc;
1049 print
'<tr class="liste_total">';
1052 print
'<td class="right">';
1053 if ($modecompta ==
'CREANCES-DETTES') {
1054 print
price(-$subtotal_ht);
1057 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1067 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
1068 $langs->load(
'trips');
1069 if ($modecompta ==
'CREANCES-DETTES') {
1070 $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";
1071 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1072 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1073 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1074 $sql .=
" AND p.fk_statut>=5";
1076 $column =
'p.date_valid';
1078 $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";
1079 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1080 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1081 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
1082 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
1083 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1084 $sql .=
" AND p.fk_statut>=5";
1086 $column =
'pe.datep';
1089 if (!empty($date_start) && !empty($date_end)) {
1090 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".
$db->idate($date_end).
"'";
1093 if ($modecompta ==
'CREANCES-DETTES') {
1096 $sql .=
" GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
1098 $newsortfield = $sortfield;
1099 if ($newsortfield ==
's.nom, s.rowid') {
1100 $newsortfield =
'p.ref';
1102 $sql .=
$db->order($newsortfield, $sortorder);
1105 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
1108 $result =
$db->query($sql);
1112 $num =
$db->num_rows($result);
1114 while ($obj =
$db->fetch_object($result)) {
1115 $total_ht -= $obj->amount_ht;
1116 $total_ttc -= $obj->amount_ttc;
1117 $subtotal_ht += $obj->amount_ht;
1118 $subtotal_ttc += $obj->amount_ttc;
1120 print
'<tr class="oddeven">';
1121 print
'<td> </td>';
1122 print
"<td>".$langs->trans(
"ExpenseReport").
" <a href=\"".DOL_URL_ROOT.
"/expensereport/list.php?search_user=".$obj->userid.
"\">".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
1123 print
'<td class="right">';
1124 if ($modecompta ==
'CREANCES-DETTES') {
1125 print
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
1128 print
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
1132 print
'<tr class="oddeven">';
1133 print
'<td> </td>';
1134 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1141 $total_ht_outcome += $subtotal_ht;
1142 $total_ttc_outcome += $subtotal_ttc;
1144 print
'<tr class="liste_total">';
1147 print
'<td class="right">';
1148 if ($modecompta ==
'CREANCES-DETTES') {
1149 print
price(-$subtotal_ht);
1152 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1162 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_VARPAY') &&
isModEnabled(
"bank") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1166 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
1169 $sql =
"SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
1170 $sql .=
' WHERE 1 = 1';
1171 if (!empty($date_start) && !empty($date_end)) {
1172 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".
$db->idate($date_end).
"'";
1174 $sql .=
' GROUP BY p.sens';
1175 $sql .=
' ORDER BY p.sens';
1177 dol_syslog(
'get various payments', LOG_DEBUG);
1178 $result =
$db->query($sql);
1181 $obj =
$db->fetch_object($result);
1182 if (isset($obj->amount)) {
1183 $subtotal_ht += -$obj->amount;
1184 $subtotal_ttc += -$obj->amount;
1186 $total_ht_outcome += $obj->amount;
1187 $total_ttc_outcome += $obj->amount;
1189 $debit_amount = isset($obj->amount) ? $obj->amount : 0;
1190 print
'<tr class="oddeven">';
1191 print
'<td> </td>';
1192 print
"<td>".$langs->trans(
"AccountingDebit").
"</td>\n";
1193 print
'<td class="right">';
1194 if ($modecompta ==
'CREANCES-DETTES') {
1195 print
'<span class="amount">'.price(-$debit_amount).
'</span>';
1198 print
'<td class="right"><span class="amount">'.price(-$debit_amount).
"</span></td>\n";
1202 $obj =
$db->fetch_object($result);
1203 if (isset($obj->amount)) {
1204 $subtotal_ht += $obj->amount;
1205 $subtotal_ttc += $obj->amount;
1207 $total_ht_income += $obj->amount;
1208 $total_ttc_income += $obj->amount;
1210 $credit_amount = isset($obj->amount) ? $obj->amount : 0;
1211 print
'<tr class="oddeven"><td> </td>';
1212 print
"<td>".$langs->trans(
"AccountingCredit").
"</td>\n";
1213 print
'<td class="right">';
1214 if ($modecompta ==
'CREANCES-DETTES') {
1215 print
'<span class="amount">'.price($credit_amount).
'</span>';
1218 print
'<td class="right"><span class="amount">'.price($credit_amount).
"</span></td>\n";
1222 $total_ht += $subtotal_ht;
1223 $total_ttc += $subtotal_ttc;
1224 print
'<tr class="liste_total">';
1227 print
'<td class="right">';
1228 if ($modecompta ==
'CREANCES-DETTES') {
1229 print
price($subtotal_ht);
1232 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1243 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_LOAN') &&
isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1247 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
1249 $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';
1250 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
1251 $sql .=
' WHERE 1 = 1';
1252 if (!empty($date_start) && !empty($date_end)) {
1253 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".
$db->idate($date_end).
"'";
1255 $sql .=
' GROUP BY p.fk_loan';
1256 $sql .=
' ORDER BY p.fk_loan';
1259 $result =
$db->query($sql);
1261 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
1263 while ($obj =
$db->fetch_object($result)) {
1264 $loan_static->id = $obj->id;
1265 $loan_static->ref = $obj->id;
1266 $loan_static->label = $obj->label;
1267 print
'<tr class="oddeven"><td> </td>';
1268 print
"<td>".$loan_static->getNomUrl(1).
' - '.$obj->label.
"</td>\n";
1269 if ($modecompta ==
'CREANCES-DETTES') {
1270 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1272 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1274 $subtotal_ht -= $obj->amount;
1275 $subtotal_ttc -= $obj->amount;
1277 $total_ht += $subtotal_ht;
1278 $total_ttc += $subtotal_ttc;
1280 $total_ht_income += $subtotal_ht;
1281 $total_ttc_income += $subtotal_ttc;
1283 print
'<tr class="liste_total">';
1286 print
'<td class="right">';
1287 if ($modecompta ==
'CREANCES-DETTES') {
1288 print
price($subtotal_ht);
1291 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1302 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VAT").
'</td></tr>';
1306 if (
isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES')) {
1307 if ($modecompta ==
'CREANCES-DETTES') {
1310 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1311 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1312 $sql .=
" WHERE f.fk_statut IN (1,2)";
1314 $sql .=
" AND f.type IN (0,1,2,5)";
1316 $sql .=
" AND f.type IN (0,1,2,3,5)";
1318 if (!empty($date_start) && !empty($date_end)) {
1319 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".
$db->idate($date_end).
"'";
1321 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
1322 $sql .=
" GROUP BY dm";
1323 $newsortfield = $sortfield;
1324 if ($newsortfield ==
's.nom, s.rowid') {
1325 $newsortfield =
'dm';
1327 if ($newsortfield ==
'amount_ht') {
1328 $newsortfield =
'amount';
1330 if ($newsortfield ==
'amount_ttc') {
1331 $newsortfield =
'amount';
1333 $sql .=
$db->order($newsortfield, $sortorder);
1336 $result =
$db->query($sql);
1338 $num =
$db->num_rows($result);
1342 $obj =
$db->fetch_object($result);
1344 $amount -= $obj->amount;
1346 $total_ttc -= $obj->amount;
1348 $subtotal_ttc -= $obj->amount;
1356 $total_ht_outcome -= 0;
1357 $total_ttc_outcome -= $amount;
1359 print
'<tr class="oddeven">';
1360 print
'<td> </td>';
1361 print
"<td>".$langs->trans(
"VATToPay").
"</td>\n";
1362 print
'<td class="right"> </td>'.
"\n";
1363 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1368 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1369 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1370 $sql .=
" WHERE f.fk_statut IN (1,2)";
1372 $sql .=
" AND f.type IN (0,1,2)";
1374 $sql .=
" AND f.type IN (0,1,2,3)";
1376 if (!empty($date_start) && !empty($date_end)) {
1377 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".
$db->idate($date_end).
"'";
1379 $sql .=
" AND f.entity = ".$conf->entity;
1380 $sql .=
" GROUP BY dm";
1381 $newsortfield = $sortfield;
1382 if ($newsortfield ==
's.nom, s.rowid') {
1383 $newsortfield =
'dm';
1385 if ($newsortfield ==
'amount_ht') {
1386 $newsortfield =
'amount';
1388 if ($newsortfield ==
'amount_ttc') {
1389 $newsortfield =
'amount';
1391 $sql .=
$db->order($newsortfield, $sortorder);
1393 dol_syslog(
"get vat received back", LOG_DEBUG);
1394 $result =
$db->query($sql);
1396 $num =
$db->num_rows($result);
1400 $obj =
$db->fetch_object($result);
1402 $amount += $obj->amount;
1404 $total_ttc += $obj->amount;
1406 $subtotal_ttc += $obj->amount;
1415 $total_ht_income += 0;
1416 $total_ttc_income += $amount;
1418 print
'<tr class="oddeven">';
1419 print
'<td> </td>';
1420 print
'<td>'.$langs->trans(
"VATToCollect").
"</td>\n";
1421 print
'<td class="right"> </td>'.
"\n";
1422 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1427 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1428 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1429 $sql .=
" WHERE amount > 0";
1430 if (!empty($date_start) && !empty($date_end)) {
1431 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".
$db->idate($date_end).
"'";
1433 $sql .=
" AND t.entity = ".$conf->entity;
1434 $sql .=
" GROUP BY dm";
1435 $newsortfield = $sortfield;
1436 if ($newsortfield ==
's.nom, s.rowid') {
1437 $newsortfield =
'dm';
1439 if ($newsortfield ==
'amount_ht') {
1440 $newsortfield =
'amount';
1442 if ($newsortfield ==
'amount_ttc') {
1443 $newsortfield =
'amount';
1445 $sql .=
$db->order($newsortfield, $sortorder);
1447 dol_syslog(
"get vat really paid", LOG_DEBUG);
1448 $result =
$db->query($sql);
1450 $num =
$db->num_rows($result);
1454 $obj =
$db->fetch_object($result);
1456 $amount -= $obj->amount;
1457 $total_ht -= $obj->amount;
1458 $total_ttc -= $obj->amount;
1459 $subtotal_ht -= $obj->amount;
1460 $subtotal_ttc -= $obj->amount;
1470 $total_ht_outcome -= 0;
1471 $total_ttc_outcome -= $amount;
1473 print
'<tr class="oddeven">';
1474 print
'<td> </td>';
1475 print
"<td>".$langs->trans(
"VATPaid").
"</td>\n";
1476 print
'<td <class="right"></td>'.
"\n";
1477 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1482 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1483 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1484 $sql .=
" WHERE amount < 0";
1485 if (!empty($date_start) && !empty($date_end)) {
1486 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".
$db->idate($date_end).
"'";
1488 $sql .=
" AND t.entity = ".$conf->entity;
1489 $sql .=
" GROUP BY dm";
1490 $newsortfield = $sortfield;
1491 if ($newsortfield ==
's.nom, s.rowid') {
1492 $newsortfield =
'dm';
1494 if ($newsortfield ==
'amount_ht') {
1495 $newsortfield =
'amount';
1497 if ($newsortfield ==
'amount_ttc') {
1498 $newsortfield =
'amount';
1500 $sql .=
$db->order($newsortfield, $sortorder);
1502 dol_syslog(
"get vat really received back", LOG_DEBUG);
1503 $result =
$db->query($sql);
1505 $num =
$db->num_rows($result);
1509 $obj =
$db->fetch_object($result);
1511 $amount += -$obj->amount;
1512 $total_ht += -$obj->amount;
1513 $total_ttc += -$obj->amount;
1514 $subtotal_ht += -$obj->amount;
1515 $subtotal_ttc += -$obj->amount;
1525 $total_ht_income += 0;
1526 $total_ttc_income += $amount;
1528 print
'<tr class="oddeven">';
1529 print
'<td> </td>';
1530 print
"<td>".$langs->trans(
"VATCollected").
"</td>\n";
1531 print
'<td class="right"></td>'.
"\n";
1532 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1537 if (
$mysoc->tva_assuj !=
'0') {
1538 print
'<tr class="liste_total">';
1541 print
'<td class="right"> </td>';
1542 print
'<td class="right">'.price(
price2num($subtotal_ttc,
'MT')).
'</td>';
1547$action =
"balanceclient";
1548$object = array(&$total_ht, &$total_ttc);
1549$parameters = array();
1550$parameters[
"mode"] = $modecompta;
1552$parameters[
"date_end"] = $date_end;
1554$hookmanager->initHooks(array(
'externalbalance'));
1555$reshook = $hookmanager->executeHooks(
'addBalanceLine', $parameters, $object, $action);
1556print $hookmanager->resPrint;
1562print
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
1565print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1566if ($modecompta ==
'CREANCES-DETTES') {
1567 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1568} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1571print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1573print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1574if ($modecompta ==
'CREANCES-DETTES') {
1575 print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1576} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1579print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1581print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1582if ($modecompta ==
'CREANCES-DETTES') {
1583 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht,
'MT')).
'</td>';
1584} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1587print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc,
'MT')).
'</td>';
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
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.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.