35 require
'../../main.inc.php';
36 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
42 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancycategory.class.php';
44 require_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');
61 if (empty($page) || $page == -1) {
64 $offset = $limit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
77 $year_start = $year_current - ($nbofyear - 1);
79 $year_current = $year;
81 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
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);
87 if (empty($date_start) || empty($date_end)) {
91 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
94 if (!$year && $month_start > $month_current) {
98 $month_end = $month_start - 1;
103 $month_end = $month_start;
128 $year_start = $tmps[
'year'];
130 $year_end = $tmpe[
'year'];
131 $nbofyear = ($year_end - $year_start) + 1;
135 $modecompta = $conf->global->ACCOUNTING_MODE;
137 $modecompta =
'BOOKKEEPING';
139 if (
GETPOST(
"modecompta",
'alpha')) {
140 $modecompta =
GETPOST(
"modecompta",
'alpha');
146 $socid =
GETPOST(
'socid',
'int');
147 if ($user->socid > 0) {
148 $socid = $user->socid;
154 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
156 $hookmanager->initHooks([
'customersupplierreportlist']);
174 if ($modecompta ==
"CREANCES-DETTES") {
175 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
176 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
177 $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>" :
"");
178 $description = $langs->trans(
"RulesResultDue");
179 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
180 $description .= $langs->trans(
"DepositsAreNotIncluded");
182 $description .= $langs->trans(
"DepositsAreIncluded");
184 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
185 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
189 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
190 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
191 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
192 $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>" :
"");
193 $description = $langs->trans(
"RulesResultInOut");
196 } elseif ($modecompta ==
"BOOKKEEPING") {
197 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
198 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
199 $arraylist = array(
'no'=>$langs->trans(
"CustomerCode"),
'yes'=>$langs->trans(
"AccountWithNonZeroValues"),
'all'=>$langs->trans(
"All"));
200 $period .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.
$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
201 $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>" :
"");
202 $description = $langs->trans(
"RulesResultBookkeepingPredefined");
203 $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")).
')';
211 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
214 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModeDebt");
216 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
218 $calcmode .=
'</label>';
219 $calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeEngagement");
221 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
223 $calcmode .=
'</label>';
226 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta,
'showaccountdetail'=>$showaccountdetail), $calcmode);
228 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
229 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
233 $param =
'&modecompta='.urlencode($modecompta).
'&showaccountdetail='.urlencode($showaccountdetail);
234 if ($date_startday) {
235 $param .=
'&date_startday='.$date_startday;
237 if ($date_startmonth) {
238 $param .=
'&date_startmonth='.$date_startmonth;
240 if ($date_startyear) {
241 $param .=
'&date_startyear='.$date_startyear;
244 $param .=
'&date_endday='.$date_endday;
246 if ($date_endmonth) {
247 $param .=
'&date_endmonth='.$date_endmonth;
250 $param .=
'&date_endyear='.$date_endyear;
253 print
'<table class="liste noborder centpercent">';
254 print
'<tr class="liste_titre">';
256 if ($modecompta ==
'BOOKKEEPING') {
257 print_liste_field_titre(
"PredefinedGroups", $_SERVER[
"PHP_SELF"],
'f.thirdparty_code,f.rowid',
'', $param,
'', $sortfield, $sortorder,
'width200 ');
262 if ($modecompta ==
'BOOKKEEPING') {
263 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
'amount',
'', $param,
'class="right"', $sortfield, $sortorder);
265 if ($modecompta ==
'CREANCES-DETTES') {
266 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
'amount_ht',
'', $param,
'class="right"', $sortfield, $sortorder);
270 print_liste_field_titre(
"AmountTTC", $_SERVER[
"PHP_SELF"],
'amount_ttc',
'', $param,
'class="right"', $sortfield, $sortorder);
275 $total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
278 if ($modecompta ==
'BOOKKEEPING') {
279 $predefinedgroupwhere =
"(";
280 $predefinedgroupwhere .=
" (pcg_type = 'EXPENSE')";
281 $predefinedgroupwhere .=
" OR ";
282 $predefinedgroupwhere .=
" (pcg_type = 'INCOME')";
283 $predefinedgroupwhere .=
")";
288 $sql =
"SELECT -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount";
289 if ($showaccountdetail ==
'no') {
290 $sql .=
", f.thirdparty_code as name";
292 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as f";
293 $sql .=
", ".MAIN_DB_PREFIX.
"accounting_account as aa";
294 $sql .=
" WHERE f.numero_compte = aa.account_number";
295 $sql .=
" AND ".$predefinedgroupwhere;
296 $sql .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
297 $sql .=
" AND f.entity = ".$conf->entity;
298 if (!empty($date_start) && !empty($date_end)) {
299 $sql .=
" AND f.doc_date >= '".$db->idate($date_start).
"' AND f.doc_date <= '".$db->idate($date_end).
"'";
301 $sql .=
" GROUP BY pcg_type";
302 if ($showaccountdetail ==
'no') {
303 $sql .=
", name, socid";
305 $sql .= $db->order($sortfield, $sortorder);
309 dol_syslog(
"get bookkeeping entries", LOG_DEBUG);
310 $result = $db->query(
$sql);
312 $num = $db->num_rows($result);
316 $objp = $db->fetch_object($result);
318 if ($showaccountdetail ==
'no') {
319 if ($objp->pcg_type != $oldpcgtype) {
320 print
'<tr class="trforbreak"><td colspan="3" class="tdforbreak">'.dol_escape_htmltag($objp->pcg_type).
'</td></tr>';
321 $oldpcgtype = $objp->pcg_type;
325 if ($showaccountdetail ==
'no') {
326 print
'<tr class="oddeven">';
330 print ($objp->name ?
' ('.dol_escape_htmltag($objp->name).
')' :
' ('.$langs->trans(
"Unknown").
')');
332 print
'<td class="right nowraponall"><span class="amount">'.price($objp->amount).
"</span></td>\n";
335 print
'<tr class="oddeven trforbreak">';
336 print
'<td colspan="2" class="tdforbreak">';
339 print
'<td class="right nowraponall tdforbreak"><span class="amount">'.price($objp->amount).
"</span></td>\n";
343 $total_ht += (isset($objp->amount) ? $objp->amount : 0);
344 $total_ttc += (isset($objp->amount) ? $objp->amount : 0);
346 if ($objp->pcg_type ==
'INCOME') {
347 $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
348 $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
350 if ($objp->pcg_type ==
'EXPENSE') {
351 $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
352 $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
357 if ($showaccountdetail !=
'no') {
358 $tmppredefinedgroupwhere =
"pcg_type = '".$db->escape($objp->pcg_type).
"'";
359 $tmppredefinedgroupwhere .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
363 $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
365 foreach ($cpts as $j => $cpt) {
366 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, (empty($cpt[
'dc']) ? 0 : $cpt[
'dc']));
371 $resultN = $AccCat->sdc;
375 if ($showaccountdetail ==
'all' || $resultN <> 0) {
378 print
'<td class="tdoverflowmax200"> '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'].
'</td>';
379 print
'<td class="right nowraponall"><span class="amount">'.price($resultN).
'</span></td>';
388 print
'<tr><td colspan="3" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';
397 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
399 if ($modecompta ==
'CREANCES-DETTES') {
400 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
401 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
402 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
403 $sql .=
" WHERE f.fk_soc = s.rowid";
404 $sql .=
" AND f.fk_statut IN (1,2)";
405 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
406 $sql .=
" AND f.type IN (0,1,2,5)";
408 $sql .=
" AND f.type IN (0,1,2,3,5)";
410 if (!empty($date_start) && !empty($date_end)) {
411 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
413 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
418 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
419 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
420 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
421 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
422 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
423 $sql .=
" WHERE p.rowid = pf.fk_paiement";
424 $sql .=
" AND pf.fk_facture = f.rowid";
425 $sql .=
" AND f.fk_soc = s.rowid";
426 if (!empty($date_start) && !empty($date_end)) {
427 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
430 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
432 $sql .=
" AND f.fk_soc = ".((int) $socid);
434 $sql .=
" GROUP BY name, socid";
435 $sql .= $db->order($sortfield, $sortorder);
437 dol_syslog(
"get customer invoices", LOG_DEBUG);
438 $result = $db->query(
$sql);
440 $num = $db->num_rows($result);
443 $objp = $db->fetch_object($result);
445 print
'<tr class="oddeven">';
446 print
'<td> </td>';
447 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$objp->socid.
'">'.$objp->name.
"</td>\n";
449 print
'<td class="right">';
450 if ($modecompta ==
'CREANCES-DETTES') {
451 print
'<span class="amount">'.price($objp->amount_ht).
"</span>";
454 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
456 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
457 $total_ttc += $objp->amount_ttc;
467 if ($modecompta ==
'RECETTES-DEPENSES') {
468 $sql =
"SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc";
469 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
470 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
471 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
472 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
473 $sql .=
" WHERE pf.rowid IS NULL";
474 $sql .=
" AND p.fk_bank = b.rowid";
475 $sql .=
" AND b.fk_account = ba.rowid";
476 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
477 if (!empty($date_start) && !empty($date_end)) {
478 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
480 $sql .=
" GROUP BY name, idp";
481 $sql .=
" ORDER BY name";
483 dol_syslog(
"get old customer payments not linked to invoices", LOG_DEBUG);
484 $result = $db->query(
$sql);
486 $num = $db->num_rows($result);
490 $objp = $db->fetch_object($result);
493 print
'<tr class="oddeven">';
494 print
'<td> </td>';
495 print
"<td>".$langs->trans(
"Bills").
" ".$langs->trans(
"Other").
" (".$langs->trans(
"PaymentsNotLinkedToInvoice").
")\n";
497 print
'<td class="right">';
498 if ($modecompta ==
'CREANCES-DETTES') {
499 print
'<span class="amount">'.price($objp->amount_ht).
"</span></td>\n";
502 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
504 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
505 $total_ttc += $objp->amount_ttc;
517 if ($total_ttc == 0) {
518 print
'<tr class="oddeven">';
519 print
'<td> </td>';
520 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
524 $total_ht_income += $total_ht;
525 $total_ttc_income += $total_ttc;
527 print
'<tr class="liste_total">';
530 print
'<td class="right">';
531 if ($modecompta ==
'CREANCES-DETTES') {
532 print
price($total_ht);
535 print
'<td class="right">'.price($total_ttc).
'</td>';
543 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
545 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
546 if ($modecompta ==
'CREANCES-DETTES') {
547 $sql =
"SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
548 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
549 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
550 $sql .=
" AND fk_statut in (1,2)";
552 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
553 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
554 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
555 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
556 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
557 $sql .=
" AND fk_statut >= 2";
559 if (!empty($date_start) && !empty($date_end)) {
560 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
563 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
564 $newsortfield = $sortfield;
565 if ($newsortfield ==
's.nom, s.rowid') {
566 $newsortfield =
'p.societe, p.firstname, p.lastname, dm';
568 if ($newsortfield ==
'amount_ht') {
569 $newsortfield =
'amount';
571 if ($newsortfield ==
'amount_ttc') {
572 $newsortfield =
'amount';
574 $sql .= $db->order($newsortfield, $sortorder);
577 $result = $db->query(
$sql);
581 $num = $db->num_rows($result);
585 $obj = $db->fetch_object($result);
587 $total_ht += $obj->amount;
588 $total_ttc += $obj->amount;
589 $subtotal_ht += $obj->amount;
590 $subtotal_ttc += $obj->amount;
592 print
'<tr class="oddeven">';
593 print
'<td> </td>';
595 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";
597 print
'<td class="right">';
598 if ($modecompta ==
'CREANCES-DETTES') {
599 print
'<span class="amount">'.price($obj->amount).
'</span>';
602 print
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
607 print
'<tr class="oddeven"><td> </td>';
608 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
615 $total_ht_income += $subtotal_ht;
616 $total_ttc_income += $subtotal_ttc;
618 print
'<tr class="liste_total">';
621 print
'<td class="right">';
622 if ($modecompta ==
'CREANCES-DETTES') {
623 print
price($subtotal_ht);
626 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
633 if ($modecompta ==
'CREANCES-DETTES') {
634 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
635 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
636 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
637 $sql .=
" WHERE f.fk_soc = s.rowid";
638 $sql .=
" AND f.fk_statut IN (1,2)";
639 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
640 $sql .=
" AND f.type IN (0,1,2)";
642 $sql .=
" AND f.type IN (0,1,2,3)";
644 if (!empty($date_start) && !empty($date_end)) {
645 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
647 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
648 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
649 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
650 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
651 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f";
652 $sql .=
" ON pf.fk_facturefourn = f.rowid";
653 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s";
654 $sql .=
" ON f.fk_soc = s.rowid";
655 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
656 if (!empty($date_start) && !empty($date_end)) {
657 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
661 $sql .=
" AND f.entity = ".((int) $conf->entity);
663 $sql .=
" AND f.fk_soc = ".((int) $socid);
665 $sql .=
" GROUP BY name, socid";
666 $sql .= $db->order($sortfield, $sortorder);
668 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
672 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
673 $result = $db->query(
$sql);
675 $num = $db->num_rows($result);
679 $objp = $db->fetch_object($result);
681 print
'<tr class="oddeven">';
682 print
'<td> </td>';
683 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
"/fourn/facture/list.php?socid=".$objp->socid.
'">'.$objp->name.
'</a></td>'.
"\n";
685 print
'<td class="right">';
686 if ($modecompta ==
'CREANCES-DETTES') {
687 print
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
690 print
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
692 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
693 $total_ttc -= $objp->amount_ttc;
694 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
695 $subtotal_ttc += $objp->amount_ttc;
701 print
'<tr class="oddeven">';
702 print
'<td> </td>';
703 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
712 $total_ht_outcome += $subtotal_ht;
713 $total_ttc_outcome += $subtotal_ttc;
715 print
'<tr class="liste_total">';
718 print
'<td class="right">';
719 if ($modecompta ==
'CREANCES-DETTES') {
720 print
price(-$subtotal_ht);
723 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
731 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsNondeductibles").
'</td></tr>';
733 if ($modecompta ==
'CREANCES-DETTES') {
734 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
735 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
736 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
737 $sql .=
" WHERE cs.fk_type = c.id";
738 $sql .=
" AND c.deductible = 0";
739 if (!empty($date_start) && !empty($date_end)) {
740 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
742 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
743 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
744 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
745 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
746 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
747 $sql .=
" WHERE p.fk_charge = cs.rowid";
748 $sql .=
" AND cs.fk_type = c.id";
749 $sql .=
" AND c.deductible = 0";
750 if (!empty($date_start) && !empty($date_end)) {
751 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
754 $sql .=
" AND cs.entity = ".$conf->entity;
755 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
756 $newsortfield = $sortfield;
757 if ($newsortfield ==
's.nom, s.rowid') {
758 $newsortfield =
'c.libelle, c.id';
760 if ($newsortfield ==
'amount_ht') {
761 $newsortfield =
'amount';
763 if ($newsortfield ==
'amount_ttc') {
764 $newsortfield =
'amount';
767 $sql .= $db->order($newsortfield, $sortorder);
769 dol_syslog(
"get social contributions deductible=0", LOG_DEBUG);
770 $result = $db->query(
$sql);
774 $num = $db->num_rows($result);
778 $obj = $db->fetch_object($result);
780 $total_ht -= $obj->amount;
781 $total_ttc -= $obj->amount;
782 $subtotal_ht += $obj->amount;
783 $subtotal_ttc += $obj->amount;
786 if ($obj->accountancy_code) {
787 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
789 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
790 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
793 print
'<tr class="oddeven">';
794 print
'<td> </td>';
795 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
796 print
'<td class="right">';
797 if ($modecompta ==
'CREANCES-DETTES') {
798 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
801 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
806 print
'<tr class="oddeven">';
807 print
'<td> </td>';
808 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
815 $total_ht_outcome += $subtotal_ht;
816 $total_ttc_outcome += $subtotal_ttc;
818 print
'<tr class="liste_total">';
821 print
'<td class="right">';
822 if ($modecompta ==
'CREANCES-DETTES') {
823 print
price(-$subtotal_ht);
826 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
834 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsDeductibles").
'</td></tr>';
836 if ($modecompta ==
'CREANCES-DETTES') {
837 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
838 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
839 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
840 $sql .=
" WHERE cs.fk_type = c.id";
841 $sql .=
" AND c.deductible = 1";
842 if (!empty($date_start) && !empty($date_end)) {
843 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
845 $sql .=
" AND cs.entity = ".$conf->entity;
846 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
847 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
848 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
849 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
850 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
851 $sql .=
" WHERE p.fk_charge = cs.rowid";
852 $sql .=
" AND cs.fk_type = c.id";
853 $sql .=
" AND c.deductible = 1";
854 if (!empty($date_start) && !empty($date_end)) {
855 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
857 $sql .=
" AND cs.entity = ".$conf->entity;
859 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
860 $newsortfield = $sortfield;
861 if ($newsortfield ==
's.nom, s.rowid') {
862 $newsortfield =
'c.libelle, c.id';
864 if ($newsortfield ==
'amount_ht') {
865 $newsortfield =
'amount';
867 if ($newsortfield ==
'amount_ttc') {
868 $newsortfield =
'amount';
870 $sql .= $db->order($newsortfield, $sortorder);
872 dol_syslog(
"get social contributions deductible=1", LOG_DEBUG);
873 $result = $db->query(
$sql);
877 $num = $db->num_rows($result);
881 $obj = $db->fetch_object($result);
883 $total_ht -= $obj->amount;
884 $total_ttc -= $obj->amount;
885 $subtotal_ht += $obj->amount;
886 $subtotal_ttc += $obj->amount;
889 if ($obj->accountancy_code) {
890 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
892 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
893 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
896 print
'<tr class="oddeven">';
897 print
'<td> </td>';
898 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
899 print
'<td class="right">';
900 if ($modecompta ==
'CREANCES-DETTES') {
901 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
904 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
909 print
'<tr class="oddeven">';
910 print
'<td> </td>';
911 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
918 $total_ht_outcome += $subtotal_ht;
919 $total_ttc_outcome += $subtotal_ttc;
921 print
'<tr class="liste_total">';
924 print
'<td class="right">';
925 if ($modecompta ==
'CREANCES-DETTES') {
926 print
price(-$subtotal_ht);
929 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
938 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
940 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
941 if ($modecompta ==
'CREANCES-DETTES') {
942 $column =
's.dateep';
944 $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";
945 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
946 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
947 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
948 if (!empty($date_start) && !empty($date_end)) {
949 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
951 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, s.label, dm";
955 $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";
956 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
957 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = p.fk_salary";
958 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
959 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
960 if (!empty($date_start) && !empty($date_end)) {
961 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
963 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, p.label, dm";
966 $newsortfield = $sortfield;
967 if ($newsortfield ==
's.nom, s.rowid') {
968 $newsortfield =
'u.firstname, u.lastname';
970 if ($newsortfield ==
'amount_ht') {
971 $newsortfield =
'amount';
973 if ($newsortfield ==
'amount_ttc') {
974 $newsortfield =
'amount';
976 $sql .= $db->order($newsortfield, $sortorder);
980 $result = $db->query(
$sql);
984 $num = $db->num_rows($result);
988 $obj = $db->fetch_object($result);
990 $total_ht -= $obj->amount;
991 $total_ttc -= $obj->amount;
992 $subtotal_ht += $obj->amount;
993 $subtotal_ttc += $obj->amount;
995 print
'<tr class="oddeven"><td> </td>';
997 $userstatic =
new User($db);
998 $userstatic->fetch($obj->fk_user);
1000 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";
1001 print
'<td class="right">';
1002 if ($modecompta ==
'CREANCES-DETTES') {
1003 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1006 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1011 print
'<tr class="oddeven">';
1012 print
'<td> </td>';
1013 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1020 $total_ht_outcome += $subtotal_ht;
1021 $total_ttc_outcome += $subtotal_ttc;
1023 print
'<tr class="liste_total">';
1026 print
'<td class="right">';
1027 if ($modecompta ==
'CREANCES-DETTES') {
1028 print
price(-$subtotal_ht);
1031 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1041 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
1042 $langs->load(
'trips');
1043 if ($modecompta ==
'CREANCES-DETTES') {
1044 $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";
1045 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1046 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1047 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1048 $sql .=
" AND p.fk_statut>=5";
1050 $column =
'p.date_valid';
1052 $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";
1053 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1054 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1055 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
1056 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
1057 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1058 $sql .=
" AND p.fk_statut>=5";
1060 $column =
'pe.datep';
1063 if (!empty($date_start) && !empty($date_end)) {
1064 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
1067 if ($modecompta ==
'CREANCES-DETTES') {
1070 $sql .=
" GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
1072 $newsortfield = $sortfield;
1073 if ($newsortfield ==
's.nom, s.rowid') {
1074 $newsortfield =
'p.ref';
1076 $sql .= $db->order($newsortfield, $sortorder);
1079 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
1082 $result = $db->query(
$sql);
1086 $num = $db->num_rows($result);
1088 while ($obj = $db->fetch_object($result)) {
1089 $total_ht -= $obj->amount_ht;
1090 $total_ttc -= $obj->amount_ttc;
1091 $subtotal_ht += $obj->amount_ht;
1092 $subtotal_ttc += $obj->amount_ttc;
1094 print
'<tr class="oddeven">';
1095 print
'<td> </td>';
1096 print
"<td>".$langs->trans(
"ExpenseReport").
" <a href=\"".DOL_URL_ROOT.
"/expensereport/list.php?search_user=".$obj->userid.
"\">".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
1097 print
'<td class="right">';
1098 if ($modecompta ==
'CREANCES-DETTES') {
1099 print
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
1102 print
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
1106 print
'<tr class="oddeven">';
1107 print
'<td> </td>';
1108 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1115 $total_ht_outcome += $subtotal_ht;
1116 $total_ttc_outcome += $subtotal_ttc;
1118 print
'<tr class="liste_total">';
1121 print
'<td class="right">';
1122 if ($modecompta ==
'CREANCES-DETTES') {
1123 print
price(-$subtotal_ht);
1126 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1136 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) &&
isModEnabled(
"banque") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1140 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
1143 $sql =
"SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
1144 $sql .=
' WHERE 1 = 1';
1145 if (!empty($date_start) && !empty($date_end)) {
1146 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1148 $sql .=
' GROUP BY p.sens';
1149 $sql .=
' ORDER BY p.sens';
1151 dol_syslog(
'get various payments', LOG_DEBUG);
1152 $result = $db->query(
$sql);
1155 $obj = $db->fetch_object($result);
1156 if (isset($obj->amount)) {
1157 $subtotal_ht += -$obj->amount;
1158 $subtotal_ttc += -$obj->amount;
1160 $total_ht_outcome += $obj->amount;
1161 $total_ttc_outcome += $obj->amount;
1163 print
'<tr class="oddeven">';
1164 print
'<td> </td>';
1165 print
"<td>".$langs->trans(
"AccountingDebit").
"</td>\n";
1166 print
'<td class="right">';
1167 if ($modecompta ==
'CREANCES-DETTES') {
1168 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1171 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1175 $obj = $db->fetch_object($result);
1176 if (isset($obj->amount)) {
1177 $subtotal_ht += $obj->amount;
1178 $subtotal_ttc += $obj->amount;
1180 $total_ht_income += $obj->amount;
1181 $total_ttc_income += $obj->amount;
1183 print
'<tr class="oddeven"><td> </td>';
1184 print
"<td>".$langs->trans(
"AccountingCredit").
"</td>\n";
1185 print
'<td class="right">';
1186 if ($modecompta ==
'CREANCES-DETTES') {
1187 print
'<span class="amount">'.price($obj->amount).
'</span>';
1190 print
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
1194 $total_ht += $subtotal_ht;
1195 $total_ttc += $subtotal_ttc;
1196 print
'<tr class="liste_total">';
1199 print
'<td class="right">';
1200 if ($modecompta ==
'CREANCES-DETTES') {
1201 print
price($subtotal_ht);
1204 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1215 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) &&
isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1219 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
1221 $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';
1222 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
1223 $sql .=
' WHERE 1 = 1';
1224 if (!empty($date_start) && !empty($date_end)) {
1225 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1227 $sql .=
' GROUP BY p.fk_loan';
1228 $sql .=
' ORDER BY p.fk_loan';
1231 $result = $db->query(
$sql);
1233 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
1234 $loan_static =
new Loan($db);
1235 while ($obj = $db->fetch_object($result)) {
1236 $loan_static->id = $obj->id;
1237 $loan_static->ref = $obj->id;
1238 $loan_static->label = $obj->label;
1239 print
'<tr class="oddeven"><td> </td>';
1240 print
"<td>".$loan_static->getNomUrl(1).
' - '.$obj->label.
"</td>\n";
1241 if ($modecompta ==
'CREANCES-DETTES') {
1242 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1244 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1246 $subtotal_ht -= $obj->amount;
1247 $subtotal_ttc -= $obj->amount;
1249 $total_ht += $subtotal_ht;
1250 $total_ttc += $subtotal_ttc;
1252 $total_ht_income += $subtotal_ht;
1253 $total_ttc_income += $subtotal_ttc;
1255 print
'<tr class="liste_total">';
1258 print
'<td class="right">';
1259 if ($modecompta ==
'CREANCES-DETTES') {
1260 print
price($subtotal_ht);
1263 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1274 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VAT").
'</td></tr>';
1278 if (
isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES')) {
1279 if ($modecompta ==
'CREANCES-DETTES') {
1282 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1283 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1284 $sql .=
" WHERE f.fk_statut IN (1,2)";
1285 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
1286 $sql .=
" AND f.type IN (0,1,2,5)";
1288 $sql .=
" AND f.type IN (0,1,2,3,5)";
1290 if (!empty($date_start) && !empty($date_end)) {
1291 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1293 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
1294 $sql .=
" GROUP BY dm";
1295 $newsortfield = $sortfield;
1296 if ($newsortfield ==
's.nom, s.rowid') {
1297 $newsortfield =
'dm';
1299 if ($newsortfield ==
'amount_ht') {
1300 $newsortfield =
'amount';
1302 if ($newsortfield ==
'amount_ttc') {
1303 $newsortfield =
'amount';
1305 $sql .= $db->order($newsortfield, $sortorder);
1308 $result = $db->query(
$sql);
1310 $num = $db->num_rows($result);
1314 $obj = $db->fetch_object($result);
1316 $amount -= $obj->amount;
1318 $total_ttc -= $obj->amount;
1320 $subtotal_ttc -= $obj->amount;
1328 $total_ht_outcome -= 0;
1329 $total_ttc_outcome -= $amount;
1331 print
'<tr class="oddeven">';
1332 print
'<td> </td>';
1333 print
"<td>".$langs->trans(
"VATToPay").
"</td>\n";
1334 print
'<td class="right"> </td>'.
"\n";
1335 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1340 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1341 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1342 $sql .=
" WHERE f.fk_statut IN (1,2)";
1343 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
1344 $sql .=
" AND f.type IN (0,1,2)";
1346 $sql .=
" AND f.type IN (0,1,2,3)";
1348 if (!empty($date_start) && !empty($date_end)) {
1349 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1351 $sql .=
" AND f.entity = ".$conf->entity;
1352 $sql .=
" GROUP BY dm";
1353 $newsortfield = $sortfield;
1354 if ($newsortfield ==
's.nom, s.rowid') {
1355 $newsortfield =
'dm';
1357 if ($newsortfield ==
'amount_ht') {
1358 $newsortfield =
'amount';
1360 if ($newsortfield ==
'amount_ttc') {
1361 $newsortfield =
'amount';
1363 $sql .= $db->order($newsortfield, $sortorder);
1365 dol_syslog(
"get vat received back", LOG_DEBUG);
1366 $result = $db->query(
$sql);
1368 $num = $db->num_rows($result);
1372 $obj = $db->fetch_object($result);
1374 $amount += $obj->amount;
1376 $total_ttc += $obj->amount;
1378 $subtotal_ttc += $obj->amount;
1387 $total_ht_income += 0;
1388 $total_ttc_income += $amount;
1390 print
'<tr class="oddeven">';
1391 print
'<td> </td>';
1392 print
'<td>'.$langs->trans(
"VATToCollect").
"</td>\n";
1393 print
'<td class="right"> </td>'.
"\n";
1394 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1399 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1400 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1401 $sql .=
" WHERE amount > 0";
1402 if (!empty($date_start) && !empty($date_end)) {
1403 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1405 $sql .=
" AND t.entity = ".$conf->entity;
1406 $sql .=
" GROUP BY dm";
1407 $newsortfield = $sortfield;
1408 if ($newsortfield ==
's.nom, s.rowid') {
1409 $newsortfield =
'dm';
1411 if ($newsortfield ==
'amount_ht') {
1412 $newsortfield =
'amount';
1414 if ($newsortfield ==
'amount_ttc') {
1415 $newsortfield =
'amount';
1417 $sql .= $db->order($newsortfield, $sortorder);
1419 dol_syslog(
"get vat really paid", LOG_DEBUG);
1420 $result = $db->query(
$sql);
1422 $num = $db->num_rows($result);
1426 $obj = $db->fetch_object($result);
1428 $amount -= $obj->amount;
1429 $total_ht -= $obj->amount;
1430 $total_ttc -= $obj->amount;
1431 $subtotal_ht -= $obj->amount;
1432 $subtotal_ttc -= $obj->amount;
1442 $total_ht_outcome -= 0;
1443 $total_ttc_outcome -= $amount;
1445 print
'<tr class="oddeven">';
1446 print
'<td> </td>';
1447 print
"<td>".$langs->trans(
"VATPaid").
"</td>\n";
1448 print
'<td <class="right"></td>'.
"\n";
1449 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1454 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1455 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1456 $sql .=
" WHERE amount < 0";
1457 if (!empty($date_start) && !empty($date_end)) {
1458 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1460 $sql .=
" AND t.entity = ".$conf->entity;
1461 $sql .=
" GROUP BY dm";
1462 $newsortfield = $sortfield;
1463 if ($newsortfield ==
's.nom, s.rowid') {
1464 $newsortfield =
'dm';
1466 if ($newsortfield ==
'amount_ht') {
1467 $newsortfield =
'amount';
1469 if ($newsortfield ==
'amount_ttc') {
1470 $newsortfield =
'amount';
1472 $sql .= $db->order($newsortfield, $sortorder);
1474 dol_syslog(
"get vat really received back", LOG_DEBUG);
1475 $result = $db->query(
$sql);
1477 $num = $db->num_rows($result);
1481 $obj = $db->fetch_object($result);
1483 $amount += -$obj->amount;
1484 $total_ht += -$obj->amount;
1485 $total_ttc += -$obj->amount;
1486 $subtotal_ht += -$obj->amount;
1487 $subtotal_ttc += -$obj->amount;
1497 $total_ht_income += 0;
1498 $total_ttc_income += $amount;
1500 print
'<tr class="oddeven">';
1501 print
'<td> </td>';
1502 print
"<td>".$langs->trans(
"VATCollected").
"</td>\n";
1503 print
'<td class="right"></td>'.
"\n";
1504 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1509 if ($mysoc->tva_assuj !=
'0') {
1510 print
'<tr class="liste_total">';
1513 print
'<td class="right"> </td>';
1514 print
'<td class="right">'.price(
price2num($subtotal_ttc,
'MT')).
'</td>';
1519 $action =
"balanceclient";
1520 $object = array(&$total_ht, &$total_ttc);
1521 $parameters[
"mode"] = $modecompta;
1522 $parameters[
"date_start"] = $date_start;
1523 $parameters[
"date_end"] = $date_end;
1525 $hookmanager->initHooks(array(
'externalbalance'));
1526 $reshook = $hookmanager->executeHooks(
'addBalanceLine', $parameters, $object, $action);
1527 print $hookmanager->resPrint;
1533 print
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
1536 print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1537 if ($modecompta ==
'CREANCES-DETTES') {
1538 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1539 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
1542 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1544 print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1545 if ($modecompta ==
'CREANCES-DETTES') {
1546 print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1547 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
1550 print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1552 print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1553 if ($modecompta ==
'CREANCES-DETTES') {
1554 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht,
'MT')).
'</td>';
1555 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
1558 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc,
'MT')).
'</td>';