37require
'../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
44require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancycategory.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
57$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy',
'loan'));
60$date_startmonth =
GETPOSTINT(
'date_startmonth');
65$showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'yes';
67$search_project_ref =
GETPOST(
'search_project_ref',
'alpha');
70$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
71$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
73if (empty($page) || $page == -1) {
76$offset = $limit * $page;
89 $year_start = $year_current;
91 $year_current = $year;
96$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
99if (empty($date_start) || empty($date_end)) {
103 $year_end = $year_start;
107 if (!$year && $month_start > $month_current) {
111 $month_end = $month_start - 1;
112 if ($month_end < 1) {
116 $month_end = $month_start;
141$year_start = $tmps[
'year'];
143$year_end = $tmpe[
'year'];
144$nbofyear = ($year_end - $year_start) + 1;
152if (
GETPOST(
"modecompta",
'alpha')) {
153 $modecompta =
GETPOST(
"modecompta",
'alpha');
160if ($user->socid > 0) {
161 $socid = $user->socid;
167 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
169$hookmanager->initHooks([
'customersupplierreportlist']);
186$name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
187$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
192if ($modecompta ==
"CREANCES-DETTES") {
193 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
194 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
195 $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>" :
"");
196 $description = $langs->trans(
"RulesAmountWithTaxExcluded");
197 $description .=
'<br>'.$langs->trans(
"RulesResultDue");
199 $description .=
"<br>".$langs->trans(
"DepositsAreNotIncluded");
201 $description .=
"<br>".$langs->trans(
"DepositsAreIncluded");
204 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
208} elseif ($modecompta ==
"RECETTES-DEPENSES") {
209 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
210 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
211 $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>" :
"");
212 $description = $langs->trans(
"RulesAmountWithTaxIncluded");
213 $description .=
'<br>'.$langs->trans(
"RulesResultInOut");
216} elseif ($modecompta ==
"BOOKKEEPING") {
217 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
218 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
219 $arraylist = array(
'no' => $langs->trans(
"CustomerCode"),
'yes' => $langs->trans(
"AccountWithNonZeroValues"),
'all' => $langs->trans(
"All"));
220 $period .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
221 $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>" :
"");
222 $description = $langs->trans(
"RulesAmountOnInOutBookkeepingRecord");
223 $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")).
')';
236$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModePayment");
238 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
240$calcmode .=
'</label>';
241$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
243 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
245$calcmode .=
'</label>';
247report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta' => $modecompta,
'showaccountdetail' => $showaccountdetail), $calcmode);
256$param =
'&modecompta='.urlencode($modecompta).
'&showaccountdetail='.urlencode($showaccountdetail);
257$search_date_url =
'';
259 $param .=
'&date_startday='.$date_startday;
260 $search_date_url .=
'&search_date_startday='.$date_startday;
262if ($date_startmonth) {
263 $param .=
'&date_startmonth='.$date_startmonth;
264 $search_date_url .=
'&search_date_startmonth='.$date_startmonth;
266if ($date_startyear) {
267 $param .=
'&date_startyear='.$date_startyear;
268 $search_date_url .=
'&search_date_startyear='.$date_startyear;
271 $param .=
'&date_endday='.$date_endday;
272 $search_date_url .=
'&search_date_endday='.$date_endday;
275 $param .=
'&date_endmonth='.$date_endmonth;
276 $search_date_url .=
'&search_date_endmonth='.$date_endmonth;
279 $param .=
'&date_endyear='.$date_endyear;
280 $search_date_url .=
'&search_date_endyear='.$date_endyear;
283print
'<table class="liste noborder centpercent">';
284print
'<tr class="liste_titre">';
286if ($modecompta ==
'BOOKKEEPING') {
287 print_liste_field_titre(
"ByProjects", $_SERVER[
"PHP_SELF"],
'f.thirdparty_code,f.rowid',
'', $param,
'', $sortfield, $sortorder,
'width200 ');
292if ($modecompta ==
'BOOKKEEPING') {
293 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
'amount',
'', $param,
'class="right"', $sortfield, $sortorder);
295 if ($modecompta ==
'CREANCES-DETTES') {
296 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
'amount_ht',
'', $param,
'class="right"', $sortfield, $sortorder);
300 print_liste_field_titre(
"AmountTTC", $_SERVER[
"PHP_SELF"],
'amount_ttc',
'', $param,
'class="right"', $sortfield, $sortorder);
305$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
307if ($modecompta ==
'BOOKKEEPING') {
308 echo
"<p>BOOKKEEPING mode not implemented for this report type by project.</p>";
310if (
isModEnabled(
'invoice') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
314 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
317 if ($modecompta ==
'CREANCES-DETTES') {
318 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
319 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
320 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
321 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON f.fk_projet = p.rowid";
322 $sql .=
" WHERE f.fk_soc = s.rowid";
323 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
324 $sql .=
" AND f.fk_statut IN (1,2)";
326 $sql .=
" AND f.type IN (0,1,2,5)";
328 $sql .=
" AND f.type IN (0,1,2,3,5)";
330 if (!empty($date_start)) {
331 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"'";
333 if (!empty($date_end)) {
334 $sql .=
" AND f.datef <= '".$db->idate($date_end).
"'";
337 $sql .=
" AND f.fk_soc = ".((int) $socid);
339 $sql .=
" GROUP BY p.rowid, project_ref";
340 $sql .=
$db->order($sortfield, $sortorder);
341 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
342 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(pf.amount) as amount_ttc";
343 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
344 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
345 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON f.fk_projet = p.rowid";
346 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
347 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as pa";
348 $sql .=
" WHERE pa.rowid = pf.fk_paiement";
349 $sql .=
" AND pf.fk_facture = f.rowid";
350 $sql .=
" AND f.fk_soc = s.rowid";
351 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
352 if (!empty($date_start)) {
353 $sql .=
" AND pa.datep >= '".$db->idate($date_start).
"'";
355 if (!empty($date_start) && !empty($date_end)) {
356 $sql .=
" AND pa.datep <= '".$db->idate($date_end).
"'";
359 $sql .=
" AND f.fk_soc = ".((int) $socid);
361 $sql .=
" GROUP BY p.rowid, p.ref";
362 $sql .=
$db->order($sortfield, $sortorder);
365 dol_syslog(
"by project, get customer invoices", LOG_DEBUG);
366 $result =
$db->query($sql);
368 $num =
$db->num_rows($result);
371 $objp =
$db->fetch_object($result);
372 echo
'<tr class="oddeven">';
373 echo
'<td> </td>';
374 echo
"<td>".$langs->trans(
"Project").
" ";
375 if (!empty($objp->project_ref)) {
376 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_ref.
'</a>';
378 echo $langs->trans(
"None");
380 if ($modecompta ==
'CREANCES-DETTES') {
381 $detailed_list_url =
'';
382 $detailed_list_url .= empty($objp->project_ref) ?
"?search_project_ref=^$" :
"?search_project_ref=".urlencode($objp->project_ref);
383 $detailed_list_url .= $search_date_url;
384 echo
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
387 echo
'<td class="right">';
388 if ($modecompta ==
'CREANCES-DETTES') {
389 echo
'<span class="amount">'.price($objp->amount_ht).
"</span>";
392 echo
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
394 $total_ht += ($objp->amount_ht ?? 0);
395 $total_ttc += $objp->amount_ttc;
404 if ($total_ttc == 0) {
405 echo
'<tr class="oddeven">';
406 echo
'<td> </td>';
407 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
411 $total_ht_income += $total_ht;
412 $total_ttc_income += $total_ttc;
414 echo
'<tr class="liste_total">';
417 echo
'<td class="right">';
418 if ($modecompta ==
'CREANCES-DETTES') {
419 echo
price($total_ht);
422 echo
'<td class="right">'.price($total_ttc).
'</td>';
429 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
431 if ($modecompta ==
'CREANCES-DETTES') {
432 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(d.amount) as amount";
433 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as d";
434 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON d.fk_projet = p.rowid";
435 $sql .=
" WHERE d.entity IN (".getEntity(
'donation').
")";
436 $sql .=
" AND d.fk_statut in (1,2)";
438 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(d.amount) as amount";
439 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as d";
440 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = d.rowid";
441 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON d.fk_projet = p.rowid";
442 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
443 $sql .=
" WHERE d.entity IN (".getEntity(
'donation').
")";
444 $sql .=
" AND d.fk_statut >= 2";
446 if (!empty($date_start)) {
447 $sql .=
" AND d.datedon >= '".$db->idate($date_start).
"'";
449 if (!empty($date_end)) {
450 $sql .=
" AND d.datedon <= '".$db->idate($date_end).
"'";
452 $sql .=
" GROUP BY p.rowid, p.ref";
453 $newsortfield = $sortfield;
454 if ($newsortfield ==
's.nom, s.rowid') {
455 $newsortfield =
'p.ref';
457 if ($newsortfield ==
'amount_ht') {
458 $newsortfield =
'amount';
460 if ($newsortfield ==
'amount_ttc') {
461 $newsortfield =
'amount';
463 $sql .=
$db->order($newsortfield, $sortorder);
466 $result =
$db->query($sql);
470 $num =
$db->num_rows($result);
474 $obj =
$db->fetch_object($result);
476 $total_ht += $obj->amount;
477 $total_ttc += $obj->amount;
478 $subtotal_ht += $obj->amount;
479 $subtotal_ttc += $obj->amount;
481 echo
'<tr class="oddeven">';
482 echo
'<td> </td>';
483 $project_ref = empty($obj->project_ref) ? $langs->trans(
"None") : $obj->project_ref;
484 echo
"<td>".$langs->trans(
"Project").
' <a href="'.DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
'">'.$project_ref.
"</a></td>\n";
486 echo
'<td class="right">';
487 if ($modecompta ==
'CREANCES-DETTES') {
488 echo
'<span class="amount">'.price($obj->amount).
'</span>';
491 echo
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
496 echo
'<tr class="oddeven"><td> </td>';
497 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
504 $total_ht_income += $subtotal_ht;
505 $total_ttc_income += $subtotal_ttc;
507 echo
'<tr class="liste_total">';
510 echo
'<td class="right">';
511 if ($modecompta ==
'CREANCES-DETTES') {
512 echo
price($subtotal_ht);
515 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
522 if ($modecompta ==
'CREANCES-DETTES') {
523 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
524 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
525 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
526 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON f.fk_projet = p.rowid";
527 $sql .=
" WHERE f.fk_soc = s.rowid";
528 $sql .=
" AND f.fk_statut IN (1,2)";
530 $sql .=
" AND f.type IN (0,1,2)";
532 $sql .=
" AND f.type IN (0,1,2,3)";
534 if (!empty($date_start)) {
535 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"'";
537 if (!empty($date_end)) {
538 $sql .=
" AND f.datef <= '".$db->idate($date_end).
"'";
540 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
541 $sql =
"SELECT pr.rowid as rowid, pr.ref as project_ref, sum(pf.amount) as amount_ttc";
542 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
543 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
544 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON pf.fk_facturefourn = f.rowid";
545 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pr ON f.fk_projet = pr.rowid";
546 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON f.fk_soc = s.rowid";
547 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
548 if (!empty($date_start)) {
549 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"'";
551 if (!empty($date_end)) {
552 $sql .=
" AND p.datep <= '".$db->idate($date_end).
"'";
556 $sql .=
" AND f.entity = ".((int)
$conf->entity);
558 $sql .=
" AND f.fk_soc = ".((int) $socid);
560 $sql .=
" GROUP BY rowid, project_ref";
561 $sql .=
$db->order($sortfield, $sortorder);
563 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
567 dol_syslog(
"by project, get suppliers invoices", LOG_DEBUG);
568 $result =
$db->query($sql);
570 $num =
$db->num_rows($result);
574 $objp =
$db->fetch_object($result);
576 echo
'<tr class="oddeven">';
577 echo
'<td> </td>';
579 echo
"<td>".$langs->trans(
"Project").
" ";
580 if (!empty($objp->project_ref)) {
581 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_ref.
'</a>';
583 echo $langs->trans(
"None");
585 $detailed_list_url =
'';
587 $detailed_list_url .= empty($objp->project_ref) ?
"?search_project_ref=^$" :
'?search_project_ref='.urlencode($objp->project_ref);
588 $detailed_list_url .= $search_date_url;
589 echo
' (<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
592 echo
'<td class="right">';
593 if ($modecompta ==
'CREANCES-DETTES') {
594 echo
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
597 echo
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
599 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
600 $total_ttc -= $objp->amount_ttc;
601 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
602 $subtotal_ttc += $objp->amount_ttc;
608 echo
'<tr class="oddeven">';
609 echo
'<td> </td>';
610 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
619 $total_ht_outcome += $subtotal_ht;
620 $total_ttc_outcome += $subtotal_ttc;
622 echo
'<tr class="liste_total">';
625 echo
'<td class="right">';
626 if ($modecompta ==
'CREANCES-DETTES') {
627 echo
price(-$subtotal_ht);
630 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
637 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
639 if ($modecompta ==
'CREANCES-DETTES') {
640 $column =
's.dateep';
642 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(s.amount) as amount";
643 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
644 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
645 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON s.fk_projet = p.rowid";
646 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
647 if (!empty($date_start)) {
648 $sql .=
" AND ".$db->sanitize($column).
" >= '".
$db->idate($date_start).
"'";
650 if (!empty($date_end)) {
651 $sql .=
" AND ".$db->sanitize($column).
" <= '".
$db->idate($date_end).
"'";
654 $column =
'ps.datep';
656 $sql =
"SELECT pr.rowid as rowid, pr.ref as project_ref, sum(ps.amount) as amount";
657 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as ps";
658 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = ps.fk_salary";
659 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
660 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pr ON s.fk_projet = pr.rowid";
661 $sql .=
" WHERE ps.entity IN (".getEntity(
'payment_salary').
")";
662 if (!empty($date_start)) {
663 $sql .=
" AND ".$db->sanitize($column).
" >= '".
$db->idate($date_start).
"'";
665 if (!empty($date_end)) {
666 $sql .=
" AND ".$db->sanitize($column).
" <= '".
$db->idate($date_end).
"'";
671 $sql .=
" GROUP BY rowid, project_ref";
672 $newsortfield = $sortfield;
673 if ($newsortfield ==
's.nom, s.rowid') {
674 $newsortfield =
'project_ref';
676 if ($newsortfield ==
'amount_ht') {
677 $newsortfield =
'amount';
679 if ($newsortfield ==
'amount_ttc') {
680 $newsortfield =
'amount';
682 $sql .=
$db->order($newsortfield, $sortorder);
685 $result =
$db->query($sql);
689 $num =
$db->num_rows($result);
693 $obj =
$db->fetch_object($result);
695 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
697 $total_ht -= $obj->amount;
698 $total_ttc -= $obj->amount;
699 $subtotal_ht += $obj->amount;
700 $subtotal_ttc += $obj->amount;
702 echo
'<tr class="oddeven"><td> </td>';
703 echo
"<td>".$langs->trans(
"Project").
" ";
704 if (!empty($objp->project_ref)) {
705 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_ref.
'</a>';
707 echo $langs->trans(
"None");
710 echo
'<td class="right">';
711 if ($modecompta ==
'CREANCES-DETTES') {
712 echo
'<span class="amount">'.price(-$obj->amount).
'</span>';
715 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
720 echo
'<tr class="oddeven">';
721 echo
'<td> </td>';
722 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
729 $total_ht_outcome += $subtotal_ht;
730 $total_ttc_outcome += $subtotal_ttc;
732 echo
'<tr class="liste_total">';
735 echo
'<td class="right">';
736 if ($modecompta ==
'CREANCES-DETTES') {
737 echo
price(-$subtotal_ht);
740 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
749 $langs->load(
'trips');
750 if ($modecompta ==
'CREANCES-DETTES') {
751 $sql =
"SELECT ed.rowid as rowid, ed.fk_projet, p.rowid as project_rowid, p.ref as project_ref, sum(ed.total_ht) as amount_ht, sum(ed.total_ttc) as amount_ttc";
752 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as ed";
753 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport as e ON ed.fk_expensereport = e.rowid";
754 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON ed.fk_projet = p.rowid";
755 $sql .=
" WHERE e.entity IN (".getEntity(
'expensereport').
")";
756 $sql .=
" AND e.fk_statut >= 5";
758 $column =
'e.date_valid';
760 $sql =
"SELECT ed.rowid as rowid, ed.fk_projet, p.rowid as project_rowid, p.ref as project_ref, sum(DISTINCT pe.amount) as amount_ht, sum(DISTINCT pe.amount) as amount_ttc";
761 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as ed";
762 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport as e ON ed.fk_expensereport = e.rowid";
763 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = e.rowid";
764 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON ed.fk_projet = p.rowid";
765 $sql .=
" WHERE e.entity IN (".getEntity(
'expensereport').
")";
766 $sql .=
" AND e.fk_statut >= 5";
768 $column =
'pe.datep';
770 if (!empty($date_start)) {
771 $sql .=
" AND ".$db->sanitize($column).
" >= '".
$db->idate($date_start).
"'";
773 if (!empty($date_end)) {
774 $sql .=
" AND ".$db->sanitize($column).
" <= '".
$db->idate($date_end).
"'";
777 $sql .=
" GROUP BY ed.rowid, ed.fk_projet, p.rowid, p.ref";
778 $newsortfield = $sortfield;
779 if ($newsortfield ==
's.nom, s.rowid') {
780 $newsortfield =
'project_ref';
782 $sql .=
$db->order($newsortfield, $sortorder);
784 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
786 dol_syslog(
"by project, get expense report outcome");
787 $result =
$db->query($sql);
791 $num =
$db->num_rows($result);
793 while ($obj =
$db->fetch_object($result)) {
794 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
796 $total_ht -= $obj->amount_ht;
797 $total_ttc -= $obj->amount_ttc;
798 $subtotal_ht += $obj->amount_ht;
799 $subtotal_ttc += $obj->amount_ttc;
801 echo
'<tr class="oddeven">';
802 echo
'<td> </td>';
804 echo
"<td>".$langs->trans(
"Project").
" ";
805 if (!empty($obj->project_ref)) {
806 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$obj->project_rowid.
'">'.$obj->project_ref.
'</a>';
808 echo $langs->trans(
"None");
810 $detailed_list_url =
'?id='.$obj->project_rowid;
811 $detailed_list_url .= $search_date_url;
812 echo
' (<a href="'.DOL_URL_ROOT.
'/projet/element.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
815 echo
'<td class="right">';
816 if ($modecompta ==
'CREANCES-DETTES') {
817 echo
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
820 echo
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
824 echo
'<tr class="oddeven">';
825 echo
'<td> </td>';
826 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
833 $total_ht_outcome += $subtotal_ht;
834 $total_ttc_outcome += $subtotal_ttc;
836 echo
'<tr class="liste_total">';
839 echo
'<td class="right">';
840 if ($modecompta ==
'CREANCES-DETTES') {
841 echo
price(-$subtotal_ht);
844 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
859 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
862 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
863 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pj ON p.fk_projet = pj.rowid";
864 $sql .=
' WHERE 1 = 1';
865 if (!empty($date_start)) {
866 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"'";
868 if (!empty($date_end)) {
869 $sql .=
" AND p.datep <= '".$db->idate($date_end).
"'";
871 $sql .=
' GROUP BY p.rowid, project_ref';
872 $sql .=
' ORDER BY project_ref';
874 dol_syslog(
'get various payments', LOG_DEBUG);
875 $result =
$db->query($sql);
877 $num =
$db->num_rows($result);
879 while ($obj =
$db->fetch_object($result)) {
880 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
883 if (isset($obj->amount)) {
884 $subtotal_ht += -$obj->amount;
885 $subtotal_ttc += -$obj->amount;
887 $total_ht_outcome += $obj->amount;
888 $total_ttc_outcome += $obj->amount;
890 echo
'<tr class="oddeven">';
891 echo
'<td> </td>';
892 echo
"<td>".$langs->trans(
"Project").
' <a href="'.DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
'">'.$project_ref.
"</a></td>\n";
893 echo
'<td class="right">';
894 if ($modecompta ==
'CREANCES-DETTES') {
895 echo
'<span class="amount">'.price(-$obj->amount).
'</span>';
898 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
902 if (isset($obj->amount)) {
903 $subtotal_ht += $obj->amount;
904 $subtotal_ttc += $obj->amount;
906 $total_ht_income += $obj->amount;
907 $total_ttc_income += $obj->amount;
909 echo
'<tr class="oddeven"><td> </td>';
910 echo
"<td>".$langs->trans(
"Project").
" <a href=\"".DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
"\">".$project_ref.
"</a></td>\n";
911 echo
'<td class="right">';
912 if ($modecompta ==
'CREANCES-DETTES') {
913 echo
'<span class="amount">'.price($obj->amount).
'</span>';
916 echo
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
920 echo
'<tr class="oddeven">';
921 echo
'<td> </td>';
922 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
927 $total_ht += $subtotal_ht;
928 $total_ttc += $subtotal_ttc;
929 echo
'<tr class="liste_total">';
932 echo
'<td class="right">';
933 if ($modecompta ==
'CREANCES-DETTES') {
934 echo
price($subtotal_ht);
937 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
951 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
953 $sql =
'SELECT pj.rowid as rowid, pj.ref as project_ref, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) as amount FROM '.MAIN_DB_PREFIX.
'payment_loan as p';
954 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
955 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet AS pj ON l.fk_projet = pj.rowid';
956 $sql .=
' WHERE 1 = 1';
957 if (!empty($date_start)) {
958 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"'";
960 if (!empty($date_end)) {
961 $sql .=
" AND p.datep <= '".$db->idate($date_end).
"'";
963 $sql .=
' GROUP BY pj.rowid, project_ref';
964 $sql .=
' ORDER BY project_ref';
967 $result =
$db->query($sql);
969 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
972 while ($obj =
$db->fetch_object($result)) {
973 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
975 echo
'<tr class="oddeven"><td> </td>';
976 echo
"<td>".$langs->trans(
"Project").
' <a href="'.DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
'">'.$project_ref.
"</a></td>\n";
977 if ($modecompta ==
'CREANCES-DETTES') {
978 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
980 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
982 $subtotal_ht -= $obj->amount;
983 $subtotal_ttc -= $obj->amount;
985 $total_ht += $subtotal_ht;
986 $total_ttc += $subtotal_ttc;
988 $total_ht_income += $subtotal_ht;
989 $total_ttc_income += $subtotal_ttc;
991 echo
'<tr class="liste_total">';
994 echo
'<td class="right">';
995 if ($modecompta ==
'CREANCES-DETTES') {
996 echo
price($subtotal_ht);
999 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
1007$action =
"balanceclient";
1008$object = array(&$total_ht, &$total_ttc);
1009$parameters = array();
1010$parameters[
"mode"] = $modecompta;
1012$parameters[
"date_end"] = $date_end;
1014$hookmanager->initHooks(array(
'externalbalance'));
1015$reshook = $hookmanager->executeHooks(
'addReportInfo', $parameters, $object, $action);
1016echo $hookmanager->resPrint;
1024echo
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
1027echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1028if ($modecompta ==
'CREANCES-DETTES') {
1029 echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1030} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1033echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1035echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1036if ($modecompta ==
'CREANCES-DETTES') {
1037 echo
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1038} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1041echo
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1043echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1044if ($modecompta ==
'CREANCES-DETTES') {
1045 echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht,
'MT')).
'</td>';
1046} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1049echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc,
'MT')).
'</td>';
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage categories of an accounting account.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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.