34 require
'../../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
41 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancycategory.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
46 $langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy',
'loan'));
48 $date_startmonth =
GETPOST(
'date_startmonth',
'int');
49 $date_startday =
GETPOST(
'date_startday',
'int');
50 $date_startyear =
GETPOST(
'date_startyear',
'int');
51 $date_endmonth =
GETPOST(
'date_endmonth',
'int');
52 $date_endday =
GETPOST(
'date_endday',
'int');
53 $date_endyear =
GETPOST(
'date_endyear',
'int');
54 $showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'yes';
56 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
57 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
58 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
60 if (empty($page) || $page == -1) {
63 $offset = $limit * $page;
64 $pageprev = $page - 1;
65 $pagenext = $page + 1;
76 $year_start = $year_current;
78 $year_current = $year;
82 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
83 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
86 if (empty($date_start) || empty($date_end)) {
90 $year_end = $year_start;
91 $month_start =
GETPOST(
"month") ?
GETPOST(
"month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
93 if (!
GETPOST(
"year") && $month_start > $month_current) {
97 $month_end = $month_start - 1;
104 $month_end = $month_start;
129 $year_start = $tmps[
'year'];
131 $year_end = $tmpe[
'year'];
132 $nbofyear = ($year_end - $year_start) + 1;
136 $modecompta = $conf->global->ACCOUNTING_MODE;
138 $modecompta =
'BOOKKEEPING';
140 if (
GETPOST(
"modecompta",
'alpha')) {
141 $modecompta =
GETPOST(
"modecompta",
'alpha');
147 $socid =
GETPOST(
'socid',
'int');
148 if ($user->socid > 0) {
149 $socid = $user->socid;
155 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
174 if ($modecompta ==
"CREANCES-DETTES") {
175 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
176 $calcmode = $langs->trans(
"CalcModeDebt");
177 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInInputOutputMode",
'{s1}',
'{s2}').
')';
178 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?date_startyear='.$tmps[
'year'].
'&date_startmonth='.$tmps[
'mon'].
'&date_startday='.$tmps[
'mday'].
'&date_endyear='.$tmpe[
'year'].
'&date_endmonth='.$tmpe[
'mon'].
'&date_endday='.$tmpe[
'mday'].
'&modecompta=RECETTES-DEPENSES">',
'</a>'), $calcmode);
180 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'{s1}',
'{s2}').
')';
181 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?date_startyear='.$tmps[
'year'].
'&date_startmonth='.$tmps[
'mon'].
'&date_startday='.$tmps[
'mday'].
'&date_endyear='.$tmpe[
'year'].
'&date_endmonth='.$tmpe[
'mon'].
'&date_endday='.$tmpe[
'mday'].
'&modecompta=BOOKKEEPING">',
'</a>'), $calcmode);
183 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
184 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] - 1).
"&modecompta=".$modecompta.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] + 1).
"&modecompta=".$modecompta.
"'>".
img_next().
"</a>" :
"");
185 $description = $langs->trans(
"RulesResultDue");
186 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
187 $description .= $langs->trans(
"DepositsAreNotIncluded");
189 $description .= $langs->trans(
"DepositsAreIncluded");
191 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
192 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
196 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
197 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
198 $calcmode = $langs->trans(
"CalcModeEngagement");
199 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'{s1}',
'{s2}').
')';
200 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?date_startyear='.$tmps[
'year'].
'&date_startmonth='.$tmps[
'mon'].
'&date_startday='.$tmps[
'mday'].
'&date_endyear='.$tmpe[
'year'].
'&date_endmonth='.$tmpe[
'mon'].
'&date_endday='.$tmpe[
'mday'].
'&modecompta=CREANCES-DETTES">',
'</a>'), $calcmode);
202 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'{s1}',
'{s2}').
')';
203 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?date_startyear='.$tmps[
'year'].
'&date_startmonth='.$tmps[
'mon'].
'&date_startday='.$tmps[
'mday'].
'&date_endyear='.$tmpe[
'year'].
'&date_endmonth='.$tmpe[
'mon'].
'&date_endday='.$tmpe[
'mday'].
'&modecompta=BOOKKEEPING">',
'</a>'), $calcmode);
205 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
206 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] - 1).
"&modecompta=".$modecompta.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] + 1).
"&modecompta=".$modecompta.
"'>".
img_next().
"</a>" :
"");
207 $description = $langs->trans(
"RulesResultInOut");
210 } elseif ($modecompta ==
"BOOKKEEPING") {
211 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
212 $calcmode = $langs->trans(
"CalcModeBookkeeping");
213 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInInputOutputMode",
'{s1}',
'{s2}').
')';
214 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?date_startyear='.$tmps[
'year'].
'&date_startmonth='.$tmps[
'mon'].
'&date_startday='.$tmps[
'mday'].
'&date_endyear='.$tmpe[
'year'].
'&date_endmonth='.$tmpe[
'mon'].
'&date_endday='.$tmpe[
'mday'].
'&modecompta=RECETTES-DEPENSES">',
'</a>'), $calcmode);
215 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'{s1}',
'{s2}').
')';
216 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?date_startyear='.$tmps[
'year'].
'&date_startmonth='.$tmps[
'mon'].
'&date_startday='.$tmps[
'mday'].
'&date_endyear='.$tmpe[
'year'].
'&date_endmonth='.$tmpe[
'mon'].
'&date_endday='.$tmpe[
'mday'].
'&modecompta=CREANCES-DETTES">',
'</a>'), $calcmode);
217 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
218 $arraylist = array(
'no'=>$langs->trans(
"CustomerCode"),
'yes'=>$langs->trans(
"AccountWithNonZeroValues"),
'all'=>$langs->trans(
"All"));
219 $period .=
' '.$langs->trans(
"DetailByAccount").
' '.
$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
220 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] - 1).
"&modecompta=".$modecompta.
"&showaccountdetail=".$showaccountdetail.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] + 1).
"&modecompta=".$modecompta.
"&showaccountdetail=".$showaccountdetail.
"'>".
img_next().
"</a>" :
"");
221 $description = $langs->trans(
"RulesResultBookkeepingPredefined");
222 $description .=
' ('.$langs->trans(
"SeePageForSetup", DOL_URL_ROOT.
'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv(
"Accountancy").
' / '.$langs->transnoentitiesnoconv(
"Setup").
' / '.$langs->transnoentitiesnoconv(
"Chartofaccounts")).
')';
227 $hselected =
'report';
229 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta,
'showaccountdetail'=>$showaccountdetail), $calcmode);
231 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
232 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
236 $param =
'&modecompta='.urlencode($modecompta).
'&showaccountdetail='.urlencode($showaccountdetail);
237 if ($date_startday) {
238 $param .=
'&date_startday='.$date_startday;
240 if ($date_startmonth) {
241 $param .=
'&date_startmonth='.$date_startmonth;
243 if ($date_startyear) {
244 $param .=
'&date_startyear='.$date_startyear;
247 $param .=
'&date_endday='.$date_endday;
249 if ($date_endmonth) {
250 $param .=
'&date_endmonth='.$date_endmonth;
253 $param .=
'&date_endyear='.$date_endyear;
256 print
'<table class="noborder centpercent">';
257 print
'<tr class="liste_titre">';
259 if ($modecompta ==
'BOOKKEEPING') {
260 print_liste_field_titre(
"PredefinedGroups", $_SERVER[
"PHP_SELF"],
'f.thirdparty_code,f.rowid',
'', $param,
'', $sortfield, $sortorder,
'width200 ');
265 if ($modecompta ==
'BOOKKEEPING') {
266 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
'amount',
'', $param,
'class="right"', $sortfield, $sortorder);
268 if ($modecompta ==
'CREANCES-DETTES') {
269 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
'amount_ht',
'', $param,
'class="right"', $sortfield, $sortorder);
273 print_liste_field_titre(
"AmountTTC", $_SERVER[
"PHP_SELF"],
'amount_ttc',
'', $param,
'class="right"', $sortfield, $sortorder);
278 $total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
281 if ($modecompta ==
'BOOKKEEPING') {
282 $predefinedgroupwhere =
"(";
283 $predefinedgroupwhere .=
" (pcg_type = 'EXPENSE')";
284 $predefinedgroupwhere .=
" OR ";
285 $predefinedgroupwhere .=
" (pcg_type = 'INCOME')";
286 $predefinedgroupwhere .=
")";
288 $charofaccountstring = $conf->global->CHARTOFACCOUNTS;
289 $charofaccountstring =
dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS,
'accounting_system',
'rowid',
'pcg_version');
291 $sql =
"SELECT -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount";
292 if ($showaccountdetail ==
'no') {
293 $sql .=
", f.thirdparty_code as name";
295 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as f";
296 $sql .=
", ".MAIN_DB_PREFIX.
"accounting_account as aa";
297 $sql .=
" WHERE f.numero_compte = aa.account_number";
298 $sql .=
" AND ".$predefinedgroupwhere;
299 $sql .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
300 $sql .=
" AND f.entity = ".$conf->entity;
301 if (!empty($date_start) && !empty($date_end)) {
302 $sql .=
" AND f.doc_date >= '".$db->idate($date_start).
"' AND f.doc_date <= '".$db->idate($date_end).
"'";
304 $sql .=
" GROUP BY pcg_type";
305 if ($showaccountdetail ==
'no') {
306 $sql .=
", name, socid";
308 $sql .= $db->order($sortfield, $sortorder);
312 dol_syslog(
"get bookkeeping entries", LOG_DEBUG);
313 $result = $db->query($sql);
315 $num = $db->num_rows($result);
319 $objp = $db->fetch_object($result);
321 if ($showaccountdetail ==
'no') {
322 if ($objp->pcg_type != $oldpcgtype) {
323 print
'<tr class="trforbreak"><td colspan="3" class="tdforbreak">'.$objp->pcg_type.
'</td></tr>';
324 $oldpcgtype = $objp->pcg_type;
328 if ($showaccountdetail ==
'no') {
329 print
'<tr class="oddeven">';
332 print $objp->pcg_type;
333 print ($objp->name ?
' ('.$objp->name.
')' :
' ('.$langs->trans(
"Unknown").
')');
335 print
'<td class="right"><span class="amount">'.price($objp->amount).
"</span></td>\n";
338 print
'<tr class="oddeven trforbreak">';
339 print
'<td colspan="2" class="tdforbreak">';
340 print $objp->pcg_type;
342 print
'<td class="right tdforbreak"><span class="amount">'.price($objp->amount).
"</span></td>\n";
346 $total_ht += (isset($objp->amount) ? $objp->amount : 0);
347 $total_ttc += (isset($objp->amount) ? $objp->amount : 0);
349 if ($objp->pcg_type ==
'INCOME') {
350 $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
351 $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
353 if ($objp->pcg_type ==
'EXPENSE') {
354 $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
355 $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
360 if ($showaccountdetail !=
'no') {
361 $tmppredefinedgroupwhere =
"pcg_type = '".$db->escape($objp->pcg_type).
"'";
362 $tmppredefinedgroupwhere .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
366 $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
368 foreach ($cpts as $j => $cpt) {
369 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, $cpt[
'dc']);
374 $resultN = $AccCat->sdc;
378 if ($showaccountdetail ==
'all' || $resultN <> 0) {
381 print
'<td class="tdoverflowmax200"> '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'].
'</td>';
382 print
'<td class="right"><span class="amount">'.price($resultN).
'</span></td>';
391 print
'<tr><td colspan="3" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';
400 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
402 if ($modecompta ==
'CREANCES-DETTES') {
403 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
404 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
405 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
406 $sql .=
" WHERE f.fk_soc = s.rowid";
407 $sql .=
" AND f.fk_statut IN (1,2)";
408 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
409 $sql .=
" AND f.type IN (0,1,2,5)";
411 $sql .=
" AND f.type IN (0,1,2,3,5)";
413 if (!empty($date_start) && !empty($date_end)) {
414 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
416 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
421 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
422 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
423 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
424 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
425 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
426 $sql .=
" WHERE p.rowid = pf.fk_paiement";
427 $sql .=
" AND pf.fk_facture = f.rowid";
428 $sql .=
" AND f.fk_soc = s.rowid";
429 if (!empty($date_start) && !empty($date_end)) {
430 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
433 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
435 $sql .=
" AND f.fk_soc = ".((int) $socid);
437 $sql .=
" GROUP BY name, socid";
438 $sql .= $db->order($sortfield, $sortorder);
440 dol_syslog(
"get customer invoices", LOG_DEBUG);
441 $result = $db->query($sql);
443 $num = $db->num_rows($result);
446 $objp = $db->fetch_object($result);
448 print
'<tr class="oddeven">';
449 print
'<td> </td>';
450 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$objp->socid.
'">'.$objp->name.
"</td>\n";
452 print
'<td class="right">';
453 if ($modecompta ==
'CREANCES-DETTES') {
454 print
'<span class="amount">'.price($objp->amount_ht).
"</span>";
457 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
459 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
460 $total_ttc += $objp->amount_ttc;
470 if ($modecompta ==
'RECETTES-DEPENSES') {
471 $sql =
"SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc";
472 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
473 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
474 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
475 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
476 $sql .=
" WHERE pf.rowid IS NULL";
477 $sql .=
" AND p.fk_bank = b.rowid";
478 $sql .=
" AND b.fk_account = ba.rowid";
479 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
480 if (!empty($date_start) && !empty($date_end)) {
481 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
483 $sql .=
" GROUP BY name, idp";
484 $sql .=
" ORDER BY name";
486 dol_syslog(
"get old customer payments not linked to invoices", LOG_DEBUG);
487 $result = $db->query($sql);
489 $num = $db->num_rows($result);
493 $objp = $db->fetch_object($result);
496 print
'<tr class="oddeven">';
497 print
'<td> </td>';
498 print
"<td>".$langs->trans(
"Bills").
" ".$langs->trans(
"Other").
" (".$langs->trans(
"PaymentsNotLinkedToInvoice").
")\n";
500 print
'<td class="right">';
501 if ($modecompta ==
'CREANCES-DETTES') {
502 print
'<span class="amount">'.price($objp->amount_ht).
"</span></td>\n";
505 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
507 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
508 $total_ttc += $objp->amount_ttc;
520 if ($total_ttc == 0) {
521 print
'<tr class="oddeven">';
522 print
'<td> </td>';
523 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
527 $total_ht_income += $total_ht;
528 $total_ttc_income += $total_ttc;
530 print
'<tr class="liste_total">';
533 print
'<td class="right">';
534 if ($modecompta ==
'CREANCES-DETTES') {
535 print
price($total_ht);
538 print
'<td class="right">'.price($total_ttc).
'</td>';
546 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
548 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
549 if ($modecompta ==
'CREANCES-DETTES') {
550 $sql =
"SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
551 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
552 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
553 $sql .=
" AND fk_statut in (1,2)";
555 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
556 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
557 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
558 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
559 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
560 $sql .=
" AND fk_statut >= 2";
562 if (!empty($date_start) && !empty($date_end)) {
563 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
566 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
567 $newsortfield = $sortfield;
568 if ($newsortfield ==
's.nom, s.rowid') {
569 $newsortfield =
'p.societe, p.firstname, p.lastname, dm';
571 if ($newsortfield ==
'amount_ht') {
572 $newsortfield =
'amount';
574 if ($newsortfield ==
'amount_ttc') {
575 $newsortfield =
'amount';
577 $sql .= $db->order($newsortfield, $sortorder);
580 $result = $db->query($sql);
584 $num = $db->num_rows($result);
588 $obj = $db->fetch_object($result);
590 $total_ht += $obj->amount;
591 $total_ttc += $obj->amount;
592 $subtotal_ht += $obj->amount;
593 $subtotal_ttc += $obj->amount;
595 print
'<tr class="oddeven">';
596 print
'<td> </td>';
598 print
"<td>".$langs->trans(
"Donation").
" <a href=\"".DOL_URL_ROOT.
"/don/list.php?search_company=".$obj->name.
"&search_name=".$obj->firstname.
" ".$obj->lastname.
"\">".$obj->name.
" ".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
600 print
'<td class="right">';
601 if ($modecompta ==
'CREANCES-DETTES') {
602 print
'<span class="amount">'.price($obj->amount).
'</span>';
605 print
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
610 print
'<tr class="oddeven"><td> </td>';
611 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
618 $total_ht_income += $subtotal_ht;
619 $total_ttc_income += $subtotal_ttc;
621 print
'<tr class="liste_total">';
624 print
'<td class="right">';
625 if ($modecompta ==
'CREANCES-DETTES') {
626 print
price($subtotal_ht);
629 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
636 if ($modecompta ==
'CREANCES-DETTES') {
637 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
638 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
639 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
640 $sql .=
" WHERE f.fk_soc = s.rowid";
641 $sql .=
" AND f.fk_statut IN (1,2)";
642 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
643 $sql .=
" AND f.type IN (0,1,2)";
645 $sql .=
" AND f.type IN (0,1,2,3)";
647 if (!empty($date_start) && !empty($date_end)) {
648 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
650 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
651 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
652 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
653 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
654 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f";
655 $sql .=
" ON pf.fk_facturefourn = f.rowid";
656 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s";
657 $sql .=
" ON f.fk_soc = s.rowid";
658 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
659 if (!empty($date_start) && !empty($date_end)) {
660 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
664 $sql .=
" AND f.entity = ".((int) $conf->entity);
666 $sql .=
" AND f.fk_soc = ".((int) $socid);
668 $sql .=
" GROUP BY name, socid";
669 $sql .= $db->order($sortfield, $sortorder);
671 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
675 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
676 $result = $db->query($sql);
678 $num = $db->num_rows($result);
682 $objp = $db->fetch_object($result);
684 print
'<tr class="oddeven">';
685 print
'<td> </td>';
686 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
"/fourn/facture/list.php?socid=".$objp->socid.
'">'.$objp->name.
'</a></td>'.
"\n";
688 print
'<td class="right">';
689 if ($modecompta ==
'CREANCES-DETTES') {
690 print
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
693 print
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
695 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
696 $total_ttc -= $objp->amount_ttc;
697 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
698 $subtotal_ttc += $objp->amount_ttc;
704 print
'<tr class="oddeven">';
705 print
'<td> </td>';
706 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
715 $total_ht_outcome += $subtotal_ht;
716 $total_ttc_outcome += $subtotal_ttc;
718 print
'<tr class="liste_total">';
721 print
'<td class="right">';
722 if ($modecompta ==
'CREANCES-DETTES') {
723 print
price(-$subtotal_ht);
726 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
734 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsNondeductibles").
'</td></tr>';
736 if ($modecompta ==
'CREANCES-DETTES') {
737 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
738 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
739 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
740 $sql .=
" WHERE cs.fk_type = c.id";
741 $sql .=
" AND c.deductible = 0";
742 if (!empty($date_start) && !empty($date_end)) {
743 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
745 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
746 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
747 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
748 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
749 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
750 $sql .=
" WHERE p.fk_charge = cs.rowid";
751 $sql .=
" AND cs.fk_type = c.id";
752 $sql .=
" AND c.deductible = 0";
753 if (!empty($date_start) && !empty($date_end)) {
754 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
757 $sql .=
" AND cs.entity = ".$conf->entity;
758 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
759 $newsortfield = $sortfield;
760 if ($newsortfield ==
's.nom, s.rowid') {
761 $newsortfield =
'c.libelle, c.id';
763 if ($newsortfield ==
'amount_ht') {
764 $newsortfield =
'amount';
766 if ($newsortfield ==
'amount_ttc') {
767 $newsortfield =
'amount';
770 $sql .= $db->order($newsortfield, $sortorder);
772 dol_syslog(
"get social contributions deductible=0", LOG_DEBUG);
773 $result = $db->query($sql);
777 $num = $db->num_rows($result);
781 $obj = $db->fetch_object($result);
783 $total_ht -= $obj->amount;
784 $total_ttc -= $obj->amount;
785 $subtotal_ht += $obj->amount;
786 $subtotal_ttc += $obj->amount;
789 if ($obj->accountancy_code) {
790 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
792 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
793 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
796 print
'<tr class="oddeven">';
797 print
'<td> </td>';
798 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
799 print
'<td class="right">';
800 if ($modecompta ==
'CREANCES-DETTES') {
801 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
804 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
809 print
'<tr class="oddeven">';
810 print
'<td> </td>';
811 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
818 $total_ht_outcome += $subtotal_ht;
819 $total_ttc_outcome += $subtotal_ttc;
821 print
'<tr class="liste_total">';
824 print
'<td class="right">';
825 if ($modecompta ==
'CREANCES-DETTES') {
826 print
price(-$subtotal_ht);
829 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
837 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsDeductibles").
'</td></tr>';
839 if ($modecompta ==
'CREANCES-DETTES') {
840 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
841 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
842 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
843 $sql .=
" WHERE cs.fk_type = c.id";
844 $sql .=
" AND c.deductible = 1";
845 if (!empty($date_start) && !empty($date_end)) {
846 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
848 $sql .=
" AND cs.entity = ".$conf->entity;
849 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
850 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
851 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
852 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
853 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
854 $sql .=
" WHERE p.fk_charge = cs.rowid";
855 $sql .=
" AND cs.fk_type = c.id";
856 $sql .=
" AND c.deductible = 1";
857 if (!empty($date_start) && !empty($date_end)) {
858 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
860 $sql .=
" AND cs.entity = ".$conf->entity;
862 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
863 $newsortfield = $sortfield;
864 if ($newsortfield ==
's.nom, s.rowid') {
865 $newsortfield =
'c.libelle, c.id';
867 if ($newsortfield ==
'amount_ht') {
868 $newsortfield =
'amount';
870 if ($newsortfield ==
'amount_ttc') {
871 $newsortfield =
'amount';
873 $sql .= $db->order($newsortfield, $sortorder);
875 dol_syslog(
"get social contributions deductible=1", LOG_DEBUG);
876 $result = $db->query($sql);
880 $num = $db->num_rows($result);
884 $obj = $db->fetch_object($result);
886 $total_ht -= $obj->amount;
887 $total_ttc -= $obj->amount;
888 $subtotal_ht += $obj->amount;
889 $subtotal_ttc += $obj->amount;
892 if ($obj->accountancy_code) {
893 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
895 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
896 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
899 print
'<tr class="oddeven">';
900 print
'<td> </td>';
901 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
902 print
'<td class="right">';
903 if ($modecompta ==
'CREANCES-DETTES') {
904 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
907 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
912 print
'<tr class="oddeven">';
913 print
'<td> </td>';
914 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
921 $total_ht_outcome += $subtotal_ht;
922 $total_ttc_outcome += $subtotal_ttc;
924 print
'<tr class="liste_total">';
927 print
'<td class="right">';
928 if ($modecompta ==
'CREANCES-DETTES') {
929 print
price(-$subtotal_ht);
932 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
941 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
943 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
944 if ($modecompta ==
'CREANCES-DETTES') {
945 $column =
's.dateep';
947 $sql =
"SELECT u.rowid, u.firstname, u.lastname, s.fk_user as fk_user, s.label as label, date_format($column,'%Y-%m') as dm, sum(s.amount) as amount";
948 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
949 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
950 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
951 if (!empty($date_start) && !empty($date_end)) {
952 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
954 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, s.label, dm";
958 $sql =
"SELECT u.rowid, u.firstname, u.lastname, s.fk_user as fk_user, p.label as label, date_format($column,'%Y-%m') as dm, sum(p.amount) as amount";
959 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
960 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = p.fk_salary";
961 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
962 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
963 if (!empty($date_start) && !empty($date_end)) {
964 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
966 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, p.label, dm";
969 $newsortfield = $sortfield;
970 if ($newsortfield ==
's.nom, s.rowid') {
971 $newsortfield =
'u.firstname, u.lastname';
973 if ($newsortfield ==
'amount_ht') {
974 $newsortfield =
'amount';
976 if ($newsortfield ==
'amount_ttc') {
977 $newsortfield =
'amount';
979 $sql .= $db->order($newsortfield, $sortorder);
983 $result = $db->query($sql);
987 $num = $db->num_rows($result);
991 $obj = $db->fetch_object($result);
993 $total_ht -= $obj->amount;
994 $total_ttc -= $obj->amount;
995 $subtotal_ht += $obj->amount;
996 $subtotal_ttc += $obj->amount;
998 print
'<tr class="oddeven"><td> </td>';
1000 $userstatic =
new User($db);
1001 $userstatic->fetch($obj->fk_user);
1003 print
"<td>".$langs->trans(
"Salary").
" <a href=\"".DOL_URL_ROOT.
"/salaries/list.php?search_user=".urlencode($userstatic->getFullName($langs)).
"\">".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
1004 print
'<td class="right">';
1005 if ($modecompta ==
'CREANCES-DETTES') {
1006 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1009 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1014 print
'<tr class="oddeven">';
1015 print
'<td> </td>';
1016 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1023 $total_ht_outcome += $subtotal_ht;
1024 $total_ttc_outcome += $subtotal_ttc;
1026 print
'<tr class="liste_total">';
1029 print
'<td class="right">';
1030 if ($modecompta ==
'CREANCES-DETTES') {
1031 print
price(-$subtotal_ht);
1034 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1044 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
1045 $langs->load(
'trips');
1046 if ($modecompta ==
'CREANCES-DETTES') {
1047 $sql =
"SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(date_valid,'%Y-%m') as dm, p.total_ht as amount_ht, p.total_ttc as amount_ttc";
1048 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1049 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1050 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1051 $sql .=
" AND p.fk_statut>=5";
1053 $column =
'p.date_valid';
1055 $sql =
"SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(pe.amount) as amount_ht, sum(pe.amount) as amount_ttc";
1056 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1057 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1058 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
1059 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
1060 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1061 $sql .=
" AND p.fk_statut>=5";
1063 $column =
'pe.datep';
1066 if (!empty($date_start) && !empty($date_end)) {
1067 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
1070 if ($modecompta ==
'CREANCES-DETTES') {
1073 $sql .=
" GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
1075 $newsortfield = $sortfield;
1076 if ($newsortfield ==
's.nom, s.rowid') {
1077 $newsortfield =
'p.ref';
1079 $sql .= $db->order($newsortfield, $sortorder);
1082 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
1085 $result = $db->query($sql);
1089 $num = $db->num_rows($result);
1091 while ($obj = $db->fetch_object($result)) {
1092 $total_ht -= $obj->amount_ht;
1093 $total_ttc -= $obj->amount_ttc;
1094 $subtotal_ht += $obj->amount_ht;
1095 $subtotal_ttc += $obj->amount_ttc;
1097 print
'<tr class="oddeven">';
1098 print
'<td> </td>';
1099 print
"<td>".$langs->trans(
"ExpenseReport").
" <a href=\"".DOL_URL_ROOT.
"/expensereport/list.php?search_user=".$obj->userid.
"\">".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
1100 print
'<td class="right">';
1101 if ($modecompta ==
'CREANCES-DETTES') {
1102 print
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
1105 print
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
1109 print
'<tr class="oddeven">';
1110 print
'<td> </td>';
1111 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1118 $total_ht_outcome += $subtotal_ht;
1119 $total_ttc_outcome += $subtotal_ttc;
1121 print
'<tr class="liste_total">';
1124 print
'<td class="right">';
1125 if ($modecompta ==
'CREANCES-DETTES') {
1126 print
price(-$subtotal_ht);
1129 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1139 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) &&
isModEnabled(
'banque') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1143 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
1146 $sql =
"SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
1147 $sql .=
' WHERE 1 = 1';
1148 if (!empty($date_start) && !empty($date_end)) {
1149 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1151 $sql .=
' GROUP BY p.sens';
1152 $sql .=
' ORDER BY p.sens';
1154 dol_syslog(
'get various payments', LOG_DEBUG);
1155 $result = $db->query($sql);
1158 $obj = $db->fetch_object($result);
1159 if (isset($obj->amount)) {
1160 $subtotal_ht += -$obj->amount;
1161 $subtotal_ttc += -$obj->amount;
1163 $total_ht_outcome += $obj->amount;
1164 $total_ttc_outcome += $obj->amount;
1166 print
'<tr class="oddeven">';
1167 print
'<td> </td>';
1168 print
"<td>".$langs->trans(
"Debit").
"</td>\n";
1169 print
'<td class="right">';
1170 if ($modecompta ==
'CREANCES-DETTES') {
1171 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1174 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1178 $obj = $db->fetch_object($result);
1179 if (isset($obj->amount)) {
1180 $subtotal_ht += $obj->amount;
1181 $subtotal_ttc += $obj->amount;
1183 $total_ht_income += $obj->amount;
1184 $total_ttc_income += $obj->amount;
1186 print
'<tr class="oddeven"><td> </td>';
1187 print
"<td>".$langs->trans(
"Credit").
"</td>\n";
1188 print
'<td class="right">';
1189 if ($modecompta ==
'CREANCES-DETTES') {
1190 print
'<span class="amount">'.price($obj->amount).
'</span>';
1193 print
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
1197 $total_ht += $subtotal_ht;
1198 $total_ttc += $subtotal_ttc;
1199 print
'<tr class="liste_total">';
1202 print
'<td class="right">';
1203 if ($modecompta ==
'CREANCES-DETTES') {
1204 print
price($subtotal_ht);
1207 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1218 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) &&
isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1222 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
1224 $sql =
'SELECT l.rowid as id, l.label AS label, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) as amount FROM '.MAIN_DB_PREFIX.
'payment_loan as p';
1225 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
1226 $sql .=
' WHERE 1 = 1';
1227 if (!empty($date_start) && !empty($date_end)) {
1228 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1230 $sql .=
' GROUP BY p.fk_loan';
1231 $sql .=
' ORDER BY p.fk_loan';
1234 $result = $db->query($sql);
1236 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
1237 $loan_static =
new Loan($db);
1238 while ($obj = $db->fetch_object($result)) {
1239 $loan_static->id = $obj->id;
1240 $loan_static->ref = $obj->id;
1241 $loan_static->label = $obj->label;
1242 print
'<tr class="oddeven"><td> </td>';
1243 print
"<td>".$loan_static->getNomUrl(1).
' - '.$obj->label.
"</td>\n";
1244 if ($modecompta ==
'CREANCES-DETTES') {
1245 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1247 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1249 $subtotal_ht -= $obj->amount;
1250 $subtotal_ttc -= $obj->amount;
1252 $total_ht += $subtotal_ht;
1253 $total_ttc += $subtotal_ttc;
1255 $total_ht_income += $subtotal_ht;
1256 $total_ttc_income += $subtotal_ttc;
1258 print
'<tr class="liste_total">';
1261 print
'<td class="right">';
1262 if ($modecompta ==
'CREANCES-DETTES') {
1263 print
price($subtotal_ht);
1266 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1277 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VAT").
'</td></tr>';
1281 if ($conf->tax->enabled && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES')) {
1282 if ($modecompta ==
'CREANCES-DETTES') {
1285 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1286 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1287 $sql .=
" WHERE f.fk_statut IN (1,2)";
1288 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
1289 $sql .=
" AND f.type IN (0,1,2,5)";
1291 $sql .=
" AND f.type IN (0,1,2,3,5)";
1293 if (!empty($date_start) && !empty($date_end)) {
1294 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1296 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
1297 $sql .=
" GROUP BY dm";
1298 $newsortfield = $sortfield;
1299 if ($newsortfield ==
's.nom, s.rowid') {
1300 $newsortfield =
'dm';
1302 if ($newsortfield ==
'amount_ht') {
1303 $newsortfield =
'amount';
1305 if ($newsortfield ==
'amount_ttc') {
1306 $newsortfield =
'amount';
1308 $sql .= $db->order($newsortfield, $sortorder);
1311 $result = $db->query($sql);
1313 $num = $db->num_rows($result);
1317 $obj = $db->fetch_object($result);
1319 $amount -= $obj->amount;
1321 $total_ttc -= $obj->amount;
1323 $subtotal_ttc -= $obj->amount;
1331 $total_ht_outcome -= 0;
1332 $total_ttc_outcome -= $amount;
1334 print
'<tr class="oddeven">';
1335 print
'<td> </td>';
1336 print
"<td>".$langs->trans(
"VATToPay").
"</td>\n";
1337 print
'<td class="right"> </td>'.
"\n";
1338 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1343 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1344 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1345 $sql .=
" WHERE f.fk_statut IN (1,2)";
1346 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
1347 $sql .=
" AND f.type IN (0,1,2)";
1349 $sql .=
" AND f.type IN (0,1,2,3)";
1351 if (!empty($date_start) && !empty($date_end)) {
1352 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1354 $sql .=
" AND f.entity = ".$conf->entity;
1355 $sql .=
" GROUP BY dm";
1356 $newsortfield = $sortfield;
1357 if ($newsortfield ==
's.nom, s.rowid') {
1358 $newsortfield =
'dm';
1360 if ($newsortfield ==
'amount_ht') {
1361 $newsortfield =
'amount';
1363 if ($newsortfield ==
'amount_ttc') {
1364 $newsortfield =
'amount';
1366 $sql .= $db->order($newsortfield, $sortorder);
1368 dol_syslog(
"get vat received back", LOG_DEBUG);
1369 $result = $db->query($sql);
1371 $num = $db->num_rows($result);
1375 $obj = $db->fetch_object($result);
1377 $amount += $obj->amount;
1379 $total_ttc += $obj->amount;
1381 $subtotal_ttc += $obj->amount;
1390 $total_ht_income += 0;
1391 $total_ttc_income += $amount;
1393 print
'<tr class="oddeven">';
1394 print
'<td> </td>';
1395 print
'<td>'.$langs->trans(
"VATToCollect").
"</td>\n";
1396 print
'<td class="right"> </td>'.
"\n";
1397 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1402 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1403 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1404 $sql .=
" WHERE amount > 0";
1405 if (!empty($date_start) && !empty($date_end)) {
1406 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1408 $sql .=
" AND t.entity = ".$conf->entity;
1409 $sql .=
" GROUP BY dm";
1410 $newsortfield = $sortfield;
1411 if ($newsortfield ==
's.nom, s.rowid') {
1412 $newsortfield =
'dm';
1414 if ($newsortfield ==
'amount_ht') {
1415 $newsortfield =
'amount';
1417 if ($newsortfield ==
'amount_ttc') {
1418 $newsortfield =
'amount';
1420 $sql .= $db->order($newsortfield, $sortorder);
1422 dol_syslog(
"get vat really paid", LOG_DEBUG);
1423 $result = $db->query($sql);
1425 $num = $db->num_rows($result);
1429 $obj = $db->fetch_object($result);
1431 $amount -= $obj->amount;
1432 $total_ht -= $obj->amount;
1433 $total_ttc -= $obj->amount;
1434 $subtotal_ht -= $obj->amount;
1435 $subtotal_ttc -= $obj->amount;
1445 $total_ht_outcome -= 0;
1446 $total_ttc_outcome -= $amount;
1448 print
'<tr class="oddeven">';
1449 print
'<td> </td>';
1450 print
"<td>".$langs->trans(
"VATPaid").
"</td>\n";
1451 print
'<td <class="right"></td>'.
"\n";
1452 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1457 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1458 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1459 $sql .=
" WHERE amount < 0";
1460 if (!empty($date_start) && !empty($date_end)) {
1461 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1463 $sql .=
" AND t.entity = ".$conf->entity;
1464 $sql .=
" GROUP BY dm";
1465 $newsortfield = $sortfield;
1466 if ($newsortfield ==
's.nom, s.rowid') {
1467 $newsortfield =
'dm';
1469 if ($newsortfield ==
'amount_ht') {
1470 $newsortfield =
'amount';
1472 if ($newsortfield ==
'amount_ttc') {
1473 $newsortfield =
'amount';
1475 $sql .= $db->order($newsortfield, $sortorder);
1477 dol_syslog(
"get vat really received back", LOG_DEBUG);
1478 $result = $db->query($sql);
1480 $num = $db->num_rows($result);
1484 $obj = $db->fetch_object($result);
1486 $amount += -$obj->amount;
1487 $total_ht += -$obj->amount;
1488 $total_ttc += -$obj->amount;
1489 $subtotal_ht += -$obj->amount;
1490 $subtotal_ttc += -$obj->amount;
1500 $total_ht_income += 0;
1501 $total_ttc_income += $amount;
1503 print
'<tr class="oddeven">';
1504 print
'<td> </td>';
1505 print
"<td>".$langs->trans(
"VATCollected").
"</td>\n";
1506 print
'<td class="right"></td>'.
"\n";
1507 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1512 if ($mysoc->tva_assuj !=
'0') {
1513 print
'<tr class="liste_total">';
1516 print
'<td class="right"> </td>';
1517 print
'<td class="right">'.price(
price2num($subtotal_ttc,
'MT')).
'</td>';
1522 $action =
"balanceclient";
1523 $object = array(&$total_ht, &$total_ttc);
1524 $parameters[
"mode"] = $modecompta;
1525 $parameters[
"date_start"] = $date_start;
1526 $parameters[
"date_end"] = $date_end;
1528 $hookmanager->initHooks(array(
'externalbalance'));
1529 $reshook = $hookmanager->executeHooks(
'addBalanceLine', $parameters, $object, $action);
1530 print $hookmanager->resPrint;
1536 print
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
1539 print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1540 if ($modecompta ==
'CREANCES-DETTES') {
1541 print
'<td class="liste_total right">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1542 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
1545 print
'<td class="liste_total right">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1547 print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1548 if ($modecompta ==
'CREANCES-DETTES') {
1549 print
'<td class="liste_total right">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1550 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
1553 print
'<td class="liste_total right">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1555 print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1556 if ($modecompta ==
'CREANCES-DETTES') {
1557 print
'<td class="liste_total right">'.price(
price2num($total_ht,
'MT')).
'</td>';
1558 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
1561 print
'<td class="liste_total right">'.price(
price2num($total_ttc,
'MT')).
'</td>';