35require
'../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancycategory.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
47$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy',
'loan'));
49$date_startmonth =
GETPOST(
'date_startmonth',
'int');
50$date_startday =
GETPOST(
'date_startday',
'int');
51$date_startyear =
GETPOST(
'date_startyear',
'int');
52$date_endmonth =
GETPOST(
'date_endmonth',
'int');
53$date_endday =
GETPOST(
'date_endday',
'int');
54$date_endyear =
GETPOST(
'date_endyear',
'int');
55$showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'yes';
57$limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
58$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
59$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
60$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
61if (empty($page) || $page == -1) {
64$offset = $limit * $page;
77 $year_start = $year_current;
79 $year_current = $year;
83$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
84$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
87if (empty($date_start) || empty($date_end)) {
91 $year_end = $year_start;
95 if (!$year && $month_start > $month_current) {
100 $month_end = $month_start - 1;
101 $year_end = $year_start + 1;
103 if ($month_end < 1) {
107 $month_end = $month_start;
132$year_start = $tmps[
'year'];
134$year_end = $tmpe[
'year'];
135$nbofyear = ($year_end - $year_start) + 1;
139$modecompta = $conf->global->ACCOUNTING_MODE;
140if (isModEnabled(
'accounting')) {
141 $modecompta =
'BOOKKEEPING';
143if (
GETPOST(
"modecompta",
'alpha')) {
144 $modecompta =
GETPOST(
"modecompta",
'alpha');
150$socid =
GETPOST(
'socid',
'int');
151if ($user->socid > 0) {
152 $socid = $user->socid;
154if (isModEnabled(
'comptabilite')) {
157if (isModEnabled(
'accounting')) {
158 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
160$hookmanager->initHooks([
'customersupplierreportlist']);
169$form =
new Form($db);
178if ($modecompta ==
"CREANCES-DETTES") {
179 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
180 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
181 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] - 1).
"&modecompta=".$modecompta.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] + 1).
"&modecompta=".$modecompta.
"'>".
img_next().
"</a>" :
"");
182 $description = $langs->trans(
"RulesResultDue");
184 $description .= $langs->trans(
"DepositsAreNotIncluded");
186 $description .= $langs->trans(
"DepositsAreIncluded");
189 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
193} elseif ($modecompta ==
"RECETTES-DEPENSES") {
194 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
195 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
196 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] - 1).
"&modecompta=".$modecompta.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] + 1).
"&modecompta=".$modecompta.
"'>".
img_next().
"</a>" :
"");
197 $description = $langs->trans(
"RulesResultInOut");
200} elseif ($modecompta ==
"BOOKKEEPING") {
201 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
202 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
203 $arraylist = array(
'no'=>$langs->trans(
"CustomerCode"),
'yes'=>$langs->trans(
"AccountWithNonZeroValues"),
'all'=>$langs->trans(
"All"));
204 $period .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
205 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] - 1).
"&modecompta=".$modecompta.
"&showaccountdetail=".$showaccountdetail.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] + 1).
"&modecompta=".$modecompta.
"&showaccountdetail=".$showaccountdetail.
"'>".
img_next().
"</a>" :
"");
206 $description = $langs->trans(
"RulesResultBookkeepingPredefined");
207 $description .=
' ('.$langs->trans(
"SeePageForSetup", DOL_URL_ROOT.
'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv(
"Accountancy").
' / '.$langs->transnoentitiesnoconv(
"Setup").
' / '.$langs->transnoentitiesnoconv(
"Chartofaccounts")).
')';
214if (isModEnabled(
'accounting')) {
215 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
218$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModeEngagement");
219if (isModEnabled(
'accounting')) {
220 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
222$calcmode .=
'</label>';
223$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
224if (isModEnabled(
'accounting')) {
225 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
227$calcmode .=
'</label>';
230report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta,
'showaccountdetail'=>$showaccountdetail), $calcmode);
232if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
233 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
237$param =
'&modecompta='.urlencode($modecompta).
'&showaccountdetail='.urlencode($showaccountdetail);
239 $param .=
'&date_startday='.$date_startday;
241if ($date_startmonth) {
242 $param .=
'&date_startmonth='.$date_startmonth;
244if ($date_startyear) {
245 $param .=
'&date_startyear='.$date_startyear;
248 $param .=
'&date_endday='.$date_endday;
251 $param .=
'&date_endmonth='.$date_endmonth;
254 $param .=
'&date_endyear='.$date_endyear;
257print
'<table class="liste noborder centpercent">';
258print
'<tr class="liste_titre">';
260if ($modecompta ==
'BOOKKEEPING') {
261 print_liste_field_titre(
"PredefinedGroups", $_SERVER[
"PHP_SELF"],
'f.thirdparty_code,f.rowid',
'', $param,
'', $sortfield, $sortorder,
'width200 ');
266if ($modecompta ==
'BOOKKEEPING') {
267 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
'amount',
'', $param,
'class="right"', $sortfield, $sortorder);
269 if ($modecompta ==
'CREANCES-DETTES') {
270 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
'amount_ht',
'', $param,
'class="right"', $sortfield, $sortorder);
274 print_liste_field_titre(
"AmountTTC", $_SERVER[
"PHP_SELF"],
'amount_ttc',
'', $param,
'class="right"', $sortfield, $sortorder);
279$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
282if ($modecompta ==
'BOOKKEEPING') {
283 $predefinedgroupwhere =
"(";
284 $predefinedgroupwhere .=
" (pcg_type = 'EXPENSE')";
285 $predefinedgroupwhere .=
" OR ";
286 $predefinedgroupwhere .=
" (pcg_type = 'INCOME')";
287 $predefinedgroupwhere .=
")";
292 $sql =
"SELECT -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount";
293 if ($showaccountdetail ==
'no') {
294 $sql .=
", f.thirdparty_code as name";
296 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as f";
297 $sql .=
", ".MAIN_DB_PREFIX.
"accounting_account as aa";
298 $sql .=
" WHERE f.numero_compte = aa.account_number";
299 $sql .=
" AND ".$predefinedgroupwhere;
300 $sql .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
301 $sql .=
" AND f.entity = ".$conf->entity;
302 if (!empty($date_start) && !empty($date_end)) {
303 $sql .=
" AND f.doc_date >= '".$db->idate($date_start).
"' AND f.doc_date <= '".$db->idate($date_end).
"'";
305 $sql .=
" GROUP BY pcg_type";
306 if ($showaccountdetail ==
'no') {
307 $sql .=
", name, socid";
309 $sql .= $db->order($sortfield, $sortorder);
313 dol_syslog(
"get bookkeeping entries", LOG_DEBUG);
314 $result = $db->query($sql);
316 $num = $db->num_rows($result);
320 $objp = $db->fetch_object($result);
322 if ($showaccountdetail ==
'no') {
323 if ($objp->pcg_type != $oldpcgtype) {
324 print
'<tr class="trforbreak"><td colspan="3" class="tdforbreak">'.dol_escape_htmltag($objp->pcg_type).
'</td></tr>';
325 $oldpcgtype = $objp->pcg_type;
329 if ($showaccountdetail ==
'no') {
330 print
'<tr class="oddeven">';
334 print($objp->name ?
' ('.dol_escape_htmltag($objp->name).
')' :
' ('.$langs->trans(
"Unknown").
')');
336 print
'<td class="right nowraponall"><span class="amount">'.price($objp->amount).
"</span></td>\n";
339 print
'<tr class="oddeven trforbreak">';
340 print
'<td colspan="2" class="tdforbreak">';
343 print
'<td class="right nowraponall tdforbreak"><span class="amount">'.price($objp->amount).
"</span></td>\n";
347 $total_ht += (isset($objp->amount) ? $objp->amount : 0);
348 $total_ttc += (isset($objp->amount) ? $objp->amount : 0);
350 if ($objp->pcg_type ==
'INCOME') {
351 $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
352 $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
354 if ($objp->pcg_type ==
'EXPENSE') {
355 $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
356 $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
361 if ($showaccountdetail !=
'no') {
362 $tmppredefinedgroupwhere =
"pcg_type = '".$db->escape($objp->pcg_type).
"'";
363 $tmppredefinedgroupwhere .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
367 $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
369 foreach ($cpts as $j => $cpt) {
370 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, (empty($cpt[
'dc']) ? 0 : $cpt[
'dc']));
375 $resultN = $AccCat->sdc;
379 if ($showaccountdetail ==
'all' || $resultN != 0) {
382 print
'<td class="tdoverflowmax200"> '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'].
'</td>';
383 print
'<td class="right nowraponall"><span class="amount">'.price($resultN).
'</span></td>';
392 print
'<tr><td colspan="3" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';
401 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
403 if ($modecompta ==
'CREANCES-DETTES') {
404 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
405 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
406 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
407 $sql .=
" WHERE f.fk_soc = s.rowid";
408 $sql .=
" AND f.fk_statut IN (1,2)";
410 $sql .=
" AND f.type IN (0,1,2,5)";
412 $sql .=
" AND f.type IN (0,1,2,3,5)";
414 if (!empty($date_start) && !empty($date_end)) {
415 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
417 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
422 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
423 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
424 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
425 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
426 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
427 $sql .=
" WHERE p.rowid = pf.fk_paiement";
428 $sql .=
" AND pf.fk_facture = f.rowid";
429 $sql .=
" AND f.fk_soc = s.rowid";
430 if (!empty($date_start) && !empty($date_end)) {
431 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
434 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
436 $sql .=
" AND f.fk_soc = ".((int) $socid);
438 $sql .=
" GROUP BY name, socid";
439 $sql .= $db->order($sortfield, $sortorder);
441 dol_syslog(
"get customer invoices", LOG_DEBUG);
442 $result = $db->query($sql);
444 $num = $db->num_rows($result);
447 $objp = $db->fetch_object($result);
449 print
'<tr class="oddeven">';
450 print
'<td> </td>';
451 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$objp->socid.
'">'.$objp->name.
"</td>\n";
453 print
'<td class="right">';
454 if ($modecompta ==
'CREANCES-DETTES') {
455 print
'<span class="amount">'.price($objp->amount_ht).
"</span>";
458 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
460 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
461 $total_ttc += $objp->amount_ttc;
471 if ($modecompta ==
'RECETTES-DEPENSES') {
472 $sql =
"SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc";
473 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
474 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
475 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
476 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
477 $sql .=
" WHERE pf.rowid IS NULL";
478 $sql .=
" AND p.fk_bank = b.rowid";
479 $sql .=
" AND b.fk_account = ba.rowid";
480 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
481 if (!empty($date_start) && !empty($date_end)) {
482 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
484 $sql .=
" GROUP BY name, idp";
485 $sql .=
" ORDER BY name";
487 dol_syslog(
"get old customer payments not linked to invoices", LOG_DEBUG);
488 $result = $db->query($sql);
490 $num = $db->num_rows($result);
494 $objp = $db->fetch_object($result);
497 print
'<tr class="oddeven">';
498 print
'<td> </td>';
499 print
"<td>".$langs->trans(
"Bills").
" ".$langs->trans(
"Other").
" (".$langs->trans(
"PaymentsNotLinkedToInvoice").
")\n";
501 print
'<td class="right">';
502 if ($modecompta ==
'CREANCES-DETTES') {
503 print
'<span class="amount">'.price($objp->amount_ht).
"</span></td>\n";
506 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
508 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
509 $total_ttc += $objp->amount_ttc;
521 if ($total_ttc == 0) {
522 print
'<tr class="oddeven">';
523 print
'<td> </td>';
524 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
528 $total_ht_income += $total_ht;
529 $total_ttc_income += $total_ttc;
531 print
'<tr class="liste_total">';
534 print
'<td class="right">';
535 if ($modecompta ==
'CREANCES-DETTES') {
536 print
price($total_ht);
539 print
'<td class="right">'.price($total_ttc).
'</td>';
546 if (isModEnabled(
'don')) {
547 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
549 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
550 if ($modecompta ==
'CREANCES-DETTES') {
551 $sql =
"SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
552 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
553 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
554 $sql .=
" AND fk_statut in (1,2)";
556 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
557 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
558 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
559 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
560 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
561 $sql .=
" AND fk_statut >= 2";
563 if (!empty($date_start) && !empty($date_end)) {
564 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
567 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
568 $newsortfield = $sortfield;
569 if ($newsortfield ==
's.nom, s.rowid') {
570 $newsortfield =
'p.societe, p.firstname, p.lastname, dm';
572 if ($newsortfield ==
'amount_ht') {
573 $newsortfield =
'amount';
575 if ($newsortfield ==
'amount_ttc') {
576 $newsortfield =
'amount';
578 $sql .= $db->order($newsortfield, $sortorder);
581 $result = $db->query($sql);
585 $num = $db->num_rows($result);
589 $obj = $db->fetch_object($result);
591 $total_ht += $obj->amount;
592 $total_ttc += $obj->amount;
593 $subtotal_ht += $obj->amount;
594 $subtotal_ttc += $obj->amount;
596 print
'<tr class="oddeven">';
597 print
'<td> </td>';
599 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";
601 print
'<td class="right">';
602 if ($modecompta ==
'CREANCES-DETTES') {
603 print
'<span class="amount">'.price($obj->amount).
'</span>';
606 print
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
611 print
'<tr class="oddeven"><td> </td>';
612 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
619 $total_ht_income += $subtotal_ht;
620 $total_ttc_income += $subtotal_ttc;
622 print
'<tr class="liste_total">';
625 print
'<td class="right">';
626 if ($modecompta ==
'CREANCES-DETTES') {
627 print
price($subtotal_ht);
630 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
637 if ($modecompta ==
'CREANCES-DETTES') {
638 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
639 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
640 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
641 $sql .=
" WHERE f.fk_soc = s.rowid";
642 $sql .=
" AND f.fk_statut IN (1,2)";
644 $sql .=
" AND f.type IN (0,1,2)";
646 $sql .=
" AND f.type IN (0,1,2,3)";
648 if (!empty($date_start) && !empty($date_end)) {
649 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
651 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
652 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
653 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
654 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
655 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f";
656 $sql .=
" ON pf.fk_facturefourn = f.rowid";
657 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s";
658 $sql .=
" ON f.fk_soc = s.rowid";
659 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
660 if (!empty($date_start) && !empty($date_end)) {
661 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
665 $sql .=
" AND f.entity = ".((int) $conf->entity);
667 $sql .=
" AND f.fk_soc = ".((int) $socid);
669 $sql .=
" GROUP BY name, socid";
670 $sql .= $db->order($sortfield, $sortorder);
672 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
676 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
677 $result = $db->query($sql);
679 $num = $db->num_rows($result);
683 $objp = $db->fetch_object($result);
685 print
'<tr class="oddeven">';
686 print
'<td> </td>';
687 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
"/fourn/facture/list.php?socid=".$objp->socid.
'">'.$objp->name.
'</a></td>'.
"\n";
689 print
'<td class="right">';
690 if ($modecompta ==
'CREANCES-DETTES') {
691 print
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
694 print
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
696 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
697 $total_ttc -= $objp->amount_ttc;
698 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
699 $subtotal_ttc += $objp->amount_ttc;
705 print
'<tr class="oddeven">';
706 print
'<td> </td>';
707 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
716 $total_ht_outcome += $subtotal_ht;
717 $total_ttc_outcome += $subtotal_ttc;
719 print
'<tr class="liste_total">';
722 print
'<td class="right">';
723 if ($modecompta ==
'CREANCES-DETTES') {
724 print
price(-$subtotal_ht);
727 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
735 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsNondeductibles").
'</td></tr>';
737 if ($modecompta ==
'CREANCES-DETTES') {
738 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
739 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
740 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
741 $sql .=
" WHERE cs.fk_type = c.id";
742 $sql .=
" AND c.deductible = 0";
743 if (!empty($date_start) && !empty($date_end)) {
744 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
746 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
747 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
748 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
749 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
750 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
751 $sql .=
" WHERE p.fk_charge = cs.rowid";
752 $sql .=
" AND cs.fk_type = c.id";
753 $sql .=
" AND c.deductible = 0";
754 if (!empty($date_start) && !empty($date_end)) {
755 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
758 $sql .=
" AND cs.entity = ".$conf->entity;
759 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
760 $newsortfield = $sortfield;
761 if ($newsortfield ==
's.nom, s.rowid') {
762 $newsortfield =
'c.libelle, c.id';
764 if ($newsortfield ==
'amount_ht') {
765 $newsortfield =
'amount';
767 if ($newsortfield ==
'amount_ttc') {
768 $newsortfield =
'amount';
771 $sql .= $db->order($newsortfield, $sortorder);
773 dol_syslog(
"get social contributions deductible=0", LOG_DEBUG);
774 $result = $db->query($sql);
778 $num = $db->num_rows($result);
782 $obj = $db->fetch_object($result);
784 $total_ht -= $obj->amount;
785 $total_ttc -= $obj->amount;
786 $subtotal_ht += $obj->amount;
787 $subtotal_ttc += $obj->amount;
790 if ($obj->accountancy_code) {
791 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
793 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
794 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
797 print
'<tr class="oddeven">';
798 print
'<td> </td>';
799 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
800 print
'<td class="right">';
801 if ($modecompta ==
'CREANCES-DETTES') {
802 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
805 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
810 print
'<tr class="oddeven">';
811 print
'<td> </td>';
812 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
819 $total_ht_outcome += $subtotal_ht;
820 $total_ttc_outcome += $subtotal_ttc;
822 print
'<tr class="liste_total">';
825 print
'<td class="right">';
826 if ($modecompta ==
'CREANCES-DETTES') {
827 print
price(-$subtotal_ht);
830 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
838 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsDeductibles").
'</td></tr>';
840 if ($modecompta ==
'CREANCES-DETTES') {
841 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
842 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
843 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
844 $sql .=
" WHERE cs.fk_type = c.id";
845 $sql .=
" AND c.deductible = 1";
846 if (!empty($date_start) && !empty($date_end)) {
847 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
849 $sql .=
" AND cs.entity = ".$conf->entity;
850 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
851 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
852 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
853 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
854 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
855 $sql .=
" WHERE p.fk_charge = cs.rowid";
856 $sql .=
" AND cs.fk_type = c.id";
857 $sql .=
" AND c.deductible = 1";
858 if (!empty($date_start) && !empty($date_end)) {
859 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
861 $sql .=
" AND cs.entity = ".$conf->entity;
863 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
864 $newsortfield = $sortfield;
865 if ($newsortfield ==
's.nom, s.rowid') {
866 $newsortfield =
'c.libelle, c.id';
868 if ($newsortfield ==
'amount_ht') {
869 $newsortfield =
'amount';
871 if ($newsortfield ==
'amount_ttc') {
872 $newsortfield =
'amount';
874 $sql .= $db->order($newsortfield, $sortorder);
876 dol_syslog(
"get social contributions deductible=1", LOG_DEBUG);
877 $result = $db->query($sql);
881 $num = $db->num_rows($result);
885 $obj = $db->fetch_object($result);
887 $total_ht -= $obj->amount;
888 $total_ttc -= $obj->amount;
889 $subtotal_ht += $obj->amount;
890 $subtotal_ttc += $obj->amount;
893 if ($obj->accountancy_code) {
894 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
896 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
897 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
900 print
'<tr class="oddeven">';
901 print
'<td> </td>';
902 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
903 print
'<td class="right">';
904 if ($modecompta ==
'CREANCES-DETTES') {
905 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
908 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
913 print
'<tr class="oddeven">';
914 print
'<td> </td>';
915 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
922 $total_ht_outcome += $subtotal_ht;
923 $total_ttc_outcome += $subtotal_ttc;
925 print
'<tr class="liste_total">';
928 print
'<td class="right">';
929 if ($modecompta ==
'CREANCES-DETTES') {
930 print
price(-$subtotal_ht);
933 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
941 if (isModEnabled(
'salaries')) {
942 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
944 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
945 if ($modecompta ==
'CREANCES-DETTES') {
946 $column =
's.dateep';
948 $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";
949 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
950 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
951 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
952 if (!empty($date_start) && !empty($date_end)) {
953 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
955 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, s.label, dm";
959 $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";
960 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
961 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = p.fk_salary";
962 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
963 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
964 if (!empty($date_start) && !empty($date_end)) {
965 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
967 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, p.label, dm";
970 $newsortfield = $sortfield;
971 if ($newsortfield ==
's.nom, s.rowid') {
972 $newsortfield =
'u.firstname, u.lastname';
974 if ($newsortfield ==
'amount_ht') {
975 $newsortfield =
'amount';
977 if ($newsortfield ==
'amount_ttc') {
978 $newsortfield =
'amount';
980 $sql .= $db->order($newsortfield, $sortorder);
984 $result = $db->query($sql);
988 $num = $db->num_rows($result);
992 $obj = $db->fetch_object($result);
994 $total_ht -= $obj->amount;
995 $total_ttc -= $obj->amount;
996 $subtotal_ht += $obj->amount;
997 $subtotal_ttc += $obj->amount;
999 print
'<tr class="oddeven"><td> </td>';
1001 $userstatic =
new User($db);
1002 $userstatic->fetch($obj->fk_user);
1004 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";
1005 print
'<td class="right">';
1006 if ($modecompta ==
'CREANCES-DETTES') {
1007 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1010 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1015 print
'<tr class="oddeven">';
1016 print
'<td> </td>';
1017 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1024 $total_ht_outcome += $subtotal_ht;
1025 $total_ttc_outcome += $subtotal_ttc;
1027 print
'<tr class="liste_total">';
1030 print
'<td class="right">';
1031 if ($modecompta ==
'CREANCES-DETTES') {
1032 print
price(-$subtotal_ht);
1035 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1044 if (isModEnabled(
'expensereport')) {
1045 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
1046 $langs->load(
'trips');
1047 if ($modecompta ==
'CREANCES-DETTES') {
1048 $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";
1049 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1050 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1051 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1052 $sql .=
" AND p.fk_statut>=5";
1054 $column =
'p.date_valid';
1056 $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";
1057 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1058 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1059 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
1060 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
1061 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1062 $sql .=
" AND p.fk_statut>=5";
1064 $column =
'pe.datep';
1067 if (!empty($date_start) && !empty($date_end)) {
1068 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
1071 if ($modecompta ==
'CREANCES-DETTES') {
1074 $sql .=
" GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
1076 $newsortfield = $sortfield;
1077 if ($newsortfield ==
's.nom, s.rowid') {
1078 $newsortfield =
'p.ref';
1080 $sql .= $db->order($newsortfield, $sortorder);
1083 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
1086 $result = $db->query($sql);
1090 $num = $db->num_rows($result);
1092 while ($obj = $db->fetch_object($result)) {
1093 $total_ht -= $obj->amount_ht;
1094 $total_ttc -= $obj->amount_ttc;
1095 $subtotal_ht += $obj->amount_ht;
1096 $subtotal_ttc += $obj->amount_ttc;
1098 print
'<tr class="oddeven">';
1099 print
'<td> </td>';
1100 print
"<td>".$langs->trans(
"ExpenseReport").
" <a href=\"".DOL_URL_ROOT.
"/expensereport/list.php?search_user=".$obj->userid.
"\">".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
1101 print
'<td class="right">';
1102 if ($modecompta ==
'CREANCES-DETTES') {
1103 print
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
1106 print
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
1110 print
'<tr class="oddeven">';
1111 print
'<td> </td>';
1112 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1119 $total_ht_outcome += $subtotal_ht;
1120 $total_ttc_outcome += $subtotal_ttc;
1122 print
'<tr class="liste_total">';
1125 print
'<td class="right">';
1126 if ($modecompta ==
'CREANCES-DETTES') {
1127 print
price(-$subtotal_ht);
1130 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1140 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled(
"banque") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1144 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
1147 $sql =
"SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
1148 $sql .=
' WHERE 1 = 1';
1149 if (!empty($date_start) && !empty($date_end)) {
1150 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1152 $sql .=
' GROUP BY p.sens';
1153 $sql .=
' ORDER BY p.sens';
1155 dol_syslog(
'get various payments', LOG_DEBUG);
1156 $result = $db->query($sql);
1159 $obj = $db->fetch_object($result);
1160 if (isset($obj->amount)) {
1161 $subtotal_ht += -$obj->amount;
1162 $subtotal_ttc += -$obj->amount;
1164 $total_ht_outcome += $obj->amount;
1165 $total_ttc_outcome += $obj->amount;
1167 print
'<tr class="oddeven">';
1168 print
'<td> </td>';
1169 print
"<td>".$langs->trans(
"AccountingDebit").
"</td>\n";
1170 print
'<td class="right">';
1171 if ($modecompta ==
'CREANCES-DETTES') {
1172 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1175 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1179 $obj = $db->fetch_object($result);
1180 if (isset($obj->amount)) {
1181 $subtotal_ht += $obj->amount;
1182 $subtotal_ttc += $obj->amount;
1184 $total_ht_income += $obj->amount;
1185 $total_ttc_income += $obj->amount;
1187 print
'<tr class="oddeven"><td> </td>';
1188 print
"<td>".$langs->trans(
"AccountingCredit").
"</td>\n";
1189 print
'<td class="right">';
1190 if ($modecompta ==
'CREANCES-DETTES') {
1191 print
'<span class="amount">'.price($obj->amount).
'</span>';
1194 print
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
1198 $total_ht += $subtotal_ht;
1199 $total_ttc += $subtotal_ttc;
1200 print
'<tr class="liste_total">';
1203 print
'<td class="right">';
1204 if ($modecompta ==
'CREANCES-DETTES') {
1205 print
price($subtotal_ht);
1208 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1219 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1223 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
1225 $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';
1226 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
1227 $sql .=
' WHERE 1 = 1';
1228 if (!empty($date_start) && !empty($date_end)) {
1229 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1231 $sql .=
' GROUP BY p.fk_loan';
1232 $sql .=
' ORDER BY p.fk_loan';
1235 $result = $db->query($sql);
1237 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
1238 $loan_static =
new Loan($db);
1239 while ($obj = $db->fetch_object($result)) {
1240 $loan_static->id = $obj->id;
1241 $loan_static->ref = $obj->id;
1242 $loan_static->label = $obj->label;
1243 print
'<tr class="oddeven"><td> </td>';
1244 print
"<td>".$loan_static->getNomUrl(1).
' - '.$obj->label.
"</td>\n";
1245 if ($modecompta ==
'CREANCES-DETTES') {
1246 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1248 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1250 $subtotal_ht -= $obj->amount;
1251 $subtotal_ttc -= $obj->amount;
1253 $total_ht += $subtotal_ht;
1254 $total_ttc += $subtotal_ttc;
1256 $total_ht_income += $subtotal_ht;
1257 $total_ttc_income += $subtotal_ttc;
1259 print
'<tr class="liste_total">';
1262 print
'<td class="right">';
1263 if ($modecompta ==
'CREANCES-DETTES') {
1264 print
price($subtotal_ht);
1267 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1278 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VAT").
'</td></tr>';
1282 if (isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES')) {
1283 if ($modecompta ==
'CREANCES-DETTES') {
1286 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1287 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1288 $sql .=
" WHERE f.fk_statut IN (1,2)";
1290 $sql .=
" AND f.type IN (0,1,2,5)";
1292 $sql .=
" AND f.type IN (0,1,2,3,5)";
1294 if (!empty($date_start) && !empty($date_end)) {
1295 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1297 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
1298 $sql .=
" GROUP BY dm";
1299 $newsortfield = $sortfield;
1300 if ($newsortfield ==
's.nom, s.rowid') {
1301 $newsortfield =
'dm';
1303 if ($newsortfield ==
'amount_ht') {
1304 $newsortfield =
'amount';
1306 if ($newsortfield ==
'amount_ttc') {
1307 $newsortfield =
'amount';
1309 $sql .= $db->order($newsortfield, $sortorder);
1312 $result = $db->query($sql);
1314 $num = $db->num_rows($result);
1318 $obj = $db->fetch_object($result);
1320 $amount -= $obj->amount;
1322 $total_ttc -= $obj->amount;
1324 $subtotal_ttc -= $obj->amount;
1332 $total_ht_outcome -= 0;
1333 $total_ttc_outcome -= $amount;
1335 print
'<tr class="oddeven">';
1336 print
'<td> </td>';
1337 print
"<td>".$langs->trans(
"VATToPay").
"</td>\n";
1338 print
'<td class="right"> </td>'.
"\n";
1339 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1344 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1345 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1346 $sql .=
" WHERE f.fk_statut IN (1,2)";
1348 $sql .=
" AND f.type IN (0,1,2)";
1350 $sql .=
" AND f.type IN (0,1,2,3)";
1352 if (!empty($date_start) && !empty($date_end)) {
1353 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1355 $sql .=
" AND f.entity = ".$conf->entity;
1356 $sql .=
" GROUP BY dm";
1357 $newsortfield = $sortfield;
1358 if ($newsortfield ==
's.nom, s.rowid') {
1359 $newsortfield =
'dm';
1361 if ($newsortfield ==
'amount_ht') {
1362 $newsortfield =
'amount';
1364 if ($newsortfield ==
'amount_ttc') {
1365 $newsortfield =
'amount';
1367 $sql .= $db->order($newsortfield, $sortorder);
1369 dol_syslog(
"get vat received back", LOG_DEBUG);
1370 $result = $db->query($sql);
1372 $num = $db->num_rows($result);
1376 $obj = $db->fetch_object($result);
1378 $amount += $obj->amount;
1380 $total_ttc += $obj->amount;
1382 $subtotal_ttc += $obj->amount;
1391 $total_ht_income += 0;
1392 $total_ttc_income += $amount;
1394 print
'<tr class="oddeven">';
1395 print
'<td> </td>';
1396 print
'<td>'.$langs->trans(
"VATToCollect").
"</td>\n";
1397 print
'<td class="right"> </td>'.
"\n";
1398 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1403 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1404 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1405 $sql .=
" WHERE amount > 0";
1406 if (!empty($date_start) && !empty($date_end)) {
1407 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1409 $sql .=
" AND t.entity = ".$conf->entity;
1410 $sql .=
" GROUP BY dm";
1411 $newsortfield = $sortfield;
1412 if ($newsortfield ==
's.nom, s.rowid') {
1413 $newsortfield =
'dm';
1415 if ($newsortfield ==
'amount_ht') {
1416 $newsortfield =
'amount';
1418 if ($newsortfield ==
'amount_ttc') {
1419 $newsortfield =
'amount';
1421 $sql .= $db->order($newsortfield, $sortorder);
1423 dol_syslog(
"get vat really paid", LOG_DEBUG);
1424 $result = $db->query($sql);
1426 $num = $db->num_rows($result);
1430 $obj = $db->fetch_object($result);
1432 $amount -= $obj->amount;
1433 $total_ht -= $obj->amount;
1434 $total_ttc -= $obj->amount;
1435 $subtotal_ht -= $obj->amount;
1436 $subtotal_ttc -= $obj->amount;
1446 $total_ht_outcome -= 0;
1447 $total_ttc_outcome -= $amount;
1449 print
'<tr class="oddeven">';
1450 print
'<td> </td>';
1451 print
"<td>".$langs->trans(
"VATPaid").
"</td>\n";
1452 print
'<td <class="right"></td>'.
"\n";
1453 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1458 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1459 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1460 $sql .=
" WHERE amount < 0";
1461 if (!empty($date_start) && !empty($date_end)) {
1462 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1464 $sql .=
" AND t.entity = ".$conf->entity;
1465 $sql .=
" GROUP BY dm";
1466 $newsortfield = $sortfield;
1467 if ($newsortfield ==
's.nom, s.rowid') {
1468 $newsortfield =
'dm';
1470 if ($newsortfield ==
'amount_ht') {
1471 $newsortfield =
'amount';
1473 if ($newsortfield ==
'amount_ttc') {
1474 $newsortfield =
'amount';
1476 $sql .= $db->order($newsortfield, $sortorder);
1478 dol_syslog(
"get vat really received back", LOG_DEBUG);
1479 $result = $db->query($sql);
1481 $num = $db->num_rows($result);
1485 $obj = $db->fetch_object($result);
1487 $amount += -$obj->amount;
1488 $total_ht += -$obj->amount;
1489 $total_ttc += -$obj->amount;
1490 $subtotal_ht += -$obj->amount;
1491 $subtotal_ttc += -$obj->amount;
1501 $total_ht_income += 0;
1502 $total_ttc_income += $amount;
1504 print
'<tr class="oddeven">';
1505 print
'<td> </td>';
1506 print
"<td>".$langs->trans(
"VATCollected").
"</td>\n";
1507 print
'<td class="right"></td>'.
"\n";
1508 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1513 if ($mysoc->tva_assuj !=
'0') {
1514 print
'<tr class="liste_total">';
1517 print
'<td class="right"> </td>';
1518 print
'<td class="right">'.price(
price2num($subtotal_ttc,
'MT')).
'</td>';
1523$action =
"balanceclient";
1524$object = array(&$total_ht, &$total_ttc);
1525$parameters[
"mode"] = $modecompta;
1526$parameters[
"date_start"] = $date_start;
1527$parameters[
"date_end"] = $date_end;
1529$hookmanager->initHooks(array(
'externalbalance'));
1530$reshook = $hookmanager->executeHooks(
'addBalanceLine', $parameters, $object, $action);
1531print $hookmanager->resPrint;
1537print
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
1540print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1541if ($modecompta ==
'CREANCES-DETTES') {
1542 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1543} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1546print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1548print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1549if ($modecompta ==
'CREANCES-DETTES') {
1550 print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1551} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1554print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1556print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1557if ($modecompta ==
'CREANCES-DETTES') {
1558 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht,
'MT')).
'</td>';
1559} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1562print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc,
'MT')).
'</td>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage categories of an accounting account.
Class to manage accounting accounts.
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.