38require
'../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
45require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancycategory.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
58$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy',
'loan'));
61$date_startmonth =
GETPOSTINT(
'date_startmonth');
66$showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'yes';
68$search_project_ref =
GETPOST(
'search_project_ref',
'alpha');
71$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
72$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
74if (empty($page) || $page == -1) {
77$offset = $limit * $page;
90 $year_start = $year_current;
92 $year_current = $year;
97$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
100if (empty($date_start) || empty($date_end)) {
104 $year_end = $year_start;
108 if (!$year && $month_start > $month_current) {
112 $month_end = $month_start - 1;
113 if ($month_end < 1) {
117 $month_end = $month_start;
142$year_start = $tmps[
'year'];
144$year_end = $tmpe[
'year'];
145$nbofyear = ($year_end - $year_start) + 1;
153if (
GETPOST(
"modecompta",
'alpha')) {
154 $modecompta =
GETPOST(
"modecompta",
'alpha');
161if ($user->socid > 0) {
162 $socid = $user->socid;
168 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
170$hookmanager->initHooks([
'customersupplierreportlist']);
179$form =
new Form($db);
187$name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
188$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
193if ($modecompta ==
"CREANCES-DETTES") {
194 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
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(
"RulesAmountWithTaxExcluded");
198 $description .=
'<br>'.$langs->trans(
"RulesResultDue");
200 $description .=
"<br>".$langs->trans(
"DepositsAreNotIncluded");
202 $description .=
"<br>".$langs->trans(
"DepositsAreIncluded");
205 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
209} elseif ($modecompta ==
"RECETTES-DEPENSES") {
210 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
211 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
212 $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>" :
"");
213 $description = $langs->trans(
"RulesAmountWithTaxIncluded");
214 $description .=
'<br>'.$langs->trans(
"RulesResultInOut");
217} elseif ($modecompta ==
"BOOKKEEPING") {
218 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
219 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
220 $arraylist = array(
'no' => $langs->trans(
"CustomerCode"),
'yes' => $langs->trans(
"AccountWithNonZeroValues"),
'all' => $langs->trans(
"All"));
221 $period .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
222 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] - 1).
"&modecompta=".$modecompta.
"&showaccountdetail=".$showaccountdetail.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] + 1).
"&modecompta=".$modecompta.
"&showaccountdetail=".$showaccountdetail.
"'>".
img_next().
"</a>" :
"");
223 $description = $langs->trans(
"RulesAmountOnInOutBookkeepingRecord");
224 $description .=
' ('.$langs->trans(
"SeePageForSetup", DOL_URL_ROOT.
'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv(
"Accountancy").
' / '.$langs->transnoentitiesnoconv(
"Setup").
' / '.$langs->transnoentitiesnoconv(
"Chartofaccounts")).
')';
237$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModePayment");
239 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
241$calcmode .=
'</label>';
242$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
244 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
246$calcmode .=
'</label>';
248report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta' => $modecompta,
'showaccountdetail' => $showaccountdetail), $calcmode);
257$param =
'&modecompta='.urlencode($modecompta).
'&showaccountdetail='.urlencode($showaccountdetail);
258$search_date_url =
'';
260 $param .=
'&date_startday='.$date_startday;
261 $search_date_url .=
'&search_date_startday='.$date_startday;
263if ($date_startmonth) {
264 $param .=
'&date_startmonth='.$date_startmonth;
265 $search_date_url .=
'&search_date_startmonth='.$date_startmonth;
267if ($date_startyear) {
268 $param .=
'&date_startyear='.$date_startyear;
269 $search_date_url .=
'&search_date_startyear='.$date_startyear;
272 $param .=
'&date_endday='.$date_endday;
273 $search_date_url .=
'&search_date_endday='.$date_endday;
276 $param .=
'&date_endmonth='.$date_endmonth;
277 $search_date_url .=
'&search_date_endmonth='.$date_endmonth;
280 $param .=
'&date_endyear='.$date_endyear;
281 $search_date_url .=
'&search_date_endyear='.$date_endyear;
284print
'<table class="liste noborder centpercent">';
285print
'<tr class="liste_titre">';
287if ($modecompta ==
'BOOKKEEPING') {
288 print_liste_field_titre(
"ByProjects", $_SERVER[
"PHP_SELF"],
'f.thirdparty_code,f.rowid',
'', $param,
'', $sortfield, $sortorder,
'width200 ');
293if ($modecompta ==
'BOOKKEEPING') {
294 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
'amount',
'', $param,
'class="right"', $sortfield, $sortorder);
296 if ($modecompta ==
'CREANCES-DETTES') {
297 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
'amount_ht',
'', $param,
'class="right"', $sortfield, $sortorder);
301 print_liste_field_titre(
"AmountTTC", $_SERVER[
"PHP_SELF"],
'amount_ttc',
'', $param,
'class="right"', $sortfield, $sortorder);
306$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
308if ($modecompta ==
'BOOKKEEPING') {
309 echo
"<p>BOOKKEEPING mode not implemented for this report type by project.</p>";
311if (
isModEnabled(
'invoice') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
315 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
318 if ($modecompta ==
'CREANCES-DETTES') {
319 $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";
320 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
321 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
322 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON f.fk_projet = p.rowid";
323 $sql .=
" WHERE f.fk_soc = s.rowid";
324 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
325 $sql .=
" AND f.fk_statut IN (1,2)";
327 $sql .=
" AND f.type IN (0,1,2,5)";
329 $sql .=
" AND f.type IN (0,1,2,3,5)";
332 $hookmanager->initHooks(array(
'turnoverreport'));
333 $parameters = array(
'invoicealias' =>
'f',
'issupplier' => 0,
'datefield' =>
'datef');
334 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
335 $sql .= $hookmanager->resPrint;
336 if (!empty($date_start)) {
337 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"'";
339 if (!empty($date_end)) {
340 $sql .=
" AND f.datef <= '".$db->idate($date_end).
"'";
343 $sql .=
" AND f.fk_soc = ".((int) $socid);
345 $sql .=
" GROUP BY p.rowid, project_ref";
346 $sql .= $db->order($sortfield, $sortorder);
347 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
348 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(pf.amount) as amount_ttc";
349 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
350 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
351 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON f.fk_projet = p.rowid";
352 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
353 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as pa";
354 $sql .=
" WHERE pa.rowid = pf.fk_paiement";
355 $sql .=
" AND pf.fk_facture = f.rowid";
356 $sql .=
" AND f.fk_soc = s.rowid";
357 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
358 if (!empty($date_start)) {
359 $sql .=
" AND pa.datep >= '".$db->idate($date_start).
"'";
361 if (!empty($date_start) && !empty($date_end)) {
362 $sql .=
" AND pa.datep <= '".$db->idate($date_end).
"'";
365 $sql .=
" AND f.fk_soc = ".((int) $socid);
367 $sql .=
" GROUP BY p.rowid, p.ref";
368 $sql .= $db->order($sortfield, $sortorder);
371 dol_syslog(
"by project, get customer invoices", LOG_DEBUG);
372 $result = $db->query($sql);
374 $num = $db->num_rows($result);
377 $objp = $db->fetch_object($result);
378 echo
'<tr class="oddeven">';
379 echo
'<td> </td>';
380 echo
"<td>".$langs->trans(
"Project").
" ";
381 if (!empty($objp->project_ref)) {
382 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_ref.
'</a>';
384 echo $langs->trans(
"None");
386 if ($modecompta ==
'CREANCES-DETTES') {
387 $detailed_list_url =
'';
388 $detailed_list_url .= empty($objp->project_ref) ?
"?search_project_ref=^$" :
"?search_project_ref=".urlencode($objp->project_ref);
389 $detailed_list_url .= $search_date_url;
390 echo
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
393 echo
'<td class="right">';
394 if ($modecompta ==
'CREANCES-DETTES') {
395 echo
'<span class="amount">'.price($objp->amount_ht).
"</span>";
398 echo
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
400 $total_ht += ($objp->amount_ht ?? 0);
401 $total_ttc += $objp->amount_ttc;
407 dol_print_error($db);
410 if ($total_ttc == 0) {
411 echo
'<tr class="oddeven">';
412 echo
'<td> </td>';
413 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
417 $total_ht_income += $total_ht;
418 $total_ttc_income += $total_ttc;
420 echo
'<tr class="liste_total">';
423 echo
'<td class="right">';
424 if ($modecompta ==
'CREANCES-DETTES') {
425 echo
price($total_ht);
428 echo
'<td class="right">'.price($total_ttc).
'</td>';
435 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
437 if ($modecompta ==
'CREANCES-DETTES') {
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 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON d.fk_projet = p.rowid";
441 $sql .=
" WHERE d.entity IN (".getEntity(
'donation').
")";
442 $sql .=
" AND d.fk_statut in (1,2)";
444 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(d.amount) as amount";
445 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as d";
446 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = d.rowid";
447 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON d.fk_projet = p.rowid";
448 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
449 $sql .=
" WHERE d.entity IN (".getEntity(
'donation').
")";
450 $sql .=
" AND d.fk_statut >= 2";
452 if (!empty($date_start)) {
453 $sql .=
" AND d.datedon >= '".$db->idate($date_start).
"'";
455 if (!empty($date_end)) {
456 $sql .=
" AND d.datedon <= '".$db->idate($date_end).
"'";
458 $sql .=
" GROUP BY p.rowid, p.ref";
459 $sqlNewSortField = $sortfield;
460 if ($sqlNewSortField ==
's.nom, s.rowid') {
461 $sqlNewSortField =
'p.ref';
463 if ($sqlNewSortField ==
'amount_ht') {
464 $sqlNewSortField =
'amount';
466 if ($sqlNewSortField ==
'amount_ttc') {
467 $sqlNewSortField =
'amount';
469 $sql .= $db->order($sqlNewSortField, $sortorder);
472 $result = $db->query($sql);
476 $num = $db->num_rows($result);
480 $obj = $db->fetch_object($result);
482 $total_ht += $obj->amount;
483 $total_ttc += $obj->amount;
484 $subtotal_ht += $obj->amount;
485 $subtotal_ttc += $obj->amount;
487 echo
'<tr class="oddeven">';
488 echo
'<td> </td>';
489 $project_ref = empty($obj->project_ref) ? $langs->trans(
"None") : $obj->project_ref;
490 echo
"<td>".$langs->trans(
"Project").
' <a href="'.DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
'">'.$project_ref.
"</a></td>\n";
492 echo
'<td class="right">';
493 if ($modecompta ==
'CREANCES-DETTES') {
494 echo
'<span class="amount">'.price($obj->amount).
'</span>';
497 echo
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
502 echo
'<tr class="oddeven"><td> </td>';
503 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
507 dol_print_error($db);
510 $total_ht_income += $subtotal_ht;
511 $total_ttc_income += $subtotal_ttc;
513 echo
'<tr class="liste_total">';
516 echo
'<td class="right">';
517 if ($modecompta ==
'CREANCES-DETTES') {
518 echo
price($subtotal_ht);
521 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
528 if ($modecompta ==
'CREANCES-DETTES') {
529 $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";
530 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
531 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
532 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON f.fk_projet = p.rowid";
533 $sql .=
" WHERE f.fk_soc = s.rowid";
534 $sql .=
" AND f.fk_statut IN (1,2)";
536 $sql .=
" AND f.type IN (0,1,2)";
538 $sql .=
" AND f.type IN (0,1,2,3)";
541 $hookmanager->initHooks(array(
'turnoverreport'));
542 $parameters = array(
'invoicealias' =>
'f',
'issupplier' => 1,
'datefield' =>
'datef');
543 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
544 $sql .= $hookmanager->resPrint;
545 if (!empty($date_start)) {
546 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"'";
548 if (!empty($date_end)) {
549 $sql .=
" AND f.datef <= '".$db->idate($date_end).
"'";
551 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
552 $sql =
"SELECT pr.rowid as rowid, pr.ref as project_ref, sum(pf.amount) as amount_ttc";
553 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
554 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
555 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON pf.fk_facturefourn = f.rowid";
556 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pr ON f.fk_projet = pr.rowid";
557 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON f.fk_soc = s.rowid";
558 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
559 if (!empty($date_start)) {
560 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"'";
562 if (!empty($date_end)) {
563 $sql .=
" AND p.datep <= '".$db->idate($date_end).
"'";
567 $sql .=
" AND f.entity = ".((int)
$conf->entity);
569 $sql .=
" AND f.fk_soc = ".((int) $socid);
571 $sql .=
" GROUP BY rowid, project_ref";
572 $sql .= $db->order($sortfield, $sortorder);
574 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
578 dol_syslog(
"by project, get suppliers invoices", LOG_DEBUG);
579 $result = $db->query($sql);
581 $num = $db->num_rows($result);
585 $objp = $db->fetch_object($result);
587 echo
'<tr class="oddeven">';
588 echo
'<td> </td>';
590 echo
"<td>".$langs->trans(
"Project").
" ";
591 if (!empty($objp->project_ref)) {
592 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_ref.
'</a>';
594 echo $langs->trans(
"None");
596 $detailed_list_url =
'';
598 $detailed_list_url .= empty($objp->project_ref) ?
"?search_project_ref=^$" :
'?search_project_ref='.urlencode($objp->project_ref);
599 $detailed_list_url .= $search_date_url;
600 echo
' (<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
603 echo
'<td class="right">';
604 if ($modecompta ==
'CREANCES-DETTES') {
605 echo
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
608 echo
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
610 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
611 $total_ttc -= $objp->amount_ttc;
612 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
613 $subtotal_ttc += $objp->amount_ttc;
619 echo
'<tr class="oddeven">';
620 echo
'<td> </td>';
621 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
627 dol_print_error($db);
630 $total_ht_outcome += $subtotal_ht;
631 $total_ttc_outcome += $subtotal_ttc;
633 echo
'<tr class="liste_total">';
636 echo
'<td class="right">';
637 if ($modecompta ==
'CREANCES-DETTES') {
638 echo
price(-$subtotal_ht);
641 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
648 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
650 if ($modecompta ==
'CREANCES-DETTES') {
651 $column =
's.dateep';
653 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(s.amount) as amount";
654 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
655 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
656 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON s.fk_projet = p.rowid";
657 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
658 if (!empty($date_start)) {
659 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate($date_start).
"'";
661 if (!empty($date_end)) {
662 $sql .=
" AND ".$db->sanitize($column).
" <= '".$db->idate($date_end).
"'";
665 $column =
'ps.datep';
667 $sql =
"SELECT pr.rowid as rowid, pr.ref as project_ref, sum(ps.amount) as amount";
668 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as ps";
669 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = ps.fk_salary";
670 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
671 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pr ON s.fk_projet = pr.rowid";
672 $sql .=
" WHERE ps.entity IN (".getEntity(
'payment_salary').
")";
673 if (!empty($date_start)) {
674 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate($date_start).
"'";
676 if (!empty($date_end)) {
677 $sql .=
" AND ".$db->sanitize($column).
" <= '".$db->idate($date_end).
"'";
682 $sql .=
" GROUP BY rowid, project_ref";
683 $sqlNewSortField = $sortfield;
684 if ($sqlNewSortField ==
's.nom, s.rowid') {
685 $sqlNewSortField =
'project_ref';
687 if ($sqlNewSortField ==
'amount_ht') {
688 $sqlNewSortField =
'amount';
690 if ($sqlNewSortField ==
'amount_ttc') {
691 $sqlNewSortField =
'amount';
693 $sql .= $db->order($sqlNewSortField, $sortorder);
696 $result = $db->query($sql);
700 $num = $db->num_rows($result);
704 $obj = $db->fetch_object($result);
706 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
708 $total_ht -= $obj->amount;
709 $total_ttc -= $obj->amount;
710 $subtotal_ht += $obj->amount;
711 $subtotal_ttc += $obj->amount;
713 echo
'<tr class="oddeven"><td> </td>';
714 echo
"<td>".$langs->trans(
"Project").
" ";
715 if (!empty($objp->project_ref)) {
716 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_ref.
'</a>';
718 echo $langs->trans(
"None");
721 echo
'<td class="right">';
722 if ($modecompta ==
'CREANCES-DETTES') {
723 echo
'<span class="amount">'.price(-$obj->amount).
'</span>';
726 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
731 echo
'<tr class="oddeven">';
732 echo
'<td> </td>';
733 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
737 dol_print_error($db);
740 $total_ht_outcome += $subtotal_ht;
741 $total_ttc_outcome += $subtotal_ttc;
743 echo
'<tr class="liste_total">';
746 echo
'<td class="right">';
747 if ($modecompta ==
'CREANCES-DETTES') {
748 echo
price(-$subtotal_ht);
751 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
760 $langs->load(
'trips');
761 if ($modecompta ==
'CREANCES-DETTES') {
762 $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";
763 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as ed";
764 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport as e ON ed.fk_expensereport = e.rowid";
765 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON ed.fk_projet = p.rowid";
766 $sql .=
" WHERE e.entity IN (".getEntity(
'expensereport').
")";
767 $sql .=
" AND e.fk_statut >= 5";
769 $column =
'e.date_valid';
771 $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";
772 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as ed";
773 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport as e ON ed.fk_expensereport = e.rowid";
774 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = e.rowid";
775 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON ed.fk_projet = p.rowid";
776 $sql .=
" WHERE e.entity IN (".getEntity(
'expensereport').
")";
777 $sql .=
" AND e.fk_statut >= 5";
779 $column =
'pe.datep';
781 if (!empty($date_start)) {
782 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate($date_start).
"'";
784 if (!empty($date_end)) {
785 $sql .=
" AND ".$db->sanitize($column).
" <= '".$db->idate($date_end).
"'";
788 $sql .=
" GROUP BY ed.rowid, ed.fk_projet, p.rowid, p.ref";
789 $sqlNewSortField = $sortfield;
790 if ($sqlNewSortField ==
's.nom, s.rowid') {
791 $sqlNewSortField =
'project_ref';
793 $sql .= $db->order($sqlNewSortField, $sortorder);
795 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
797 dol_syslog(
"by project, get expense report outcome");
798 $result = $db->query($sql);
802 $num = $db->num_rows($result);
804 while ($obj = $db->fetch_object($result)) {
805 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
807 $total_ht -= $obj->amount_ht;
808 $total_ttc -= $obj->amount_ttc;
809 $subtotal_ht += $obj->amount_ht;
810 $subtotal_ttc += $obj->amount_ttc;
812 echo
'<tr class="oddeven">';
813 echo
'<td> </td>';
815 echo
"<td>".$langs->trans(
"Project").
" ";
816 if (!empty($obj->project_ref)) {
817 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$obj->project_rowid.
'">'.$obj->project_ref.
'</a>';
819 echo $langs->trans(
"None");
821 $detailed_list_url =
'?id='.$obj->project_rowid;
822 $detailed_list_url .= $search_date_url;
823 echo
' (<a href="'.DOL_URL_ROOT.
'/projet/element.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
826 echo
'<td class="right">';
827 if ($modecompta ==
'CREANCES-DETTES') {
828 echo
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
831 echo
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
835 echo
'<tr class="oddeven">';
836 echo
'<td> </td>';
837 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
841 dol_print_error($db);
844 $total_ht_outcome += $subtotal_ht;
845 $total_ttc_outcome += $subtotal_ttc;
847 echo
'<tr class="liste_total">';
850 echo
'<td class="right">';
851 if ($modecompta ==
'CREANCES-DETTES') {
852 echo
price(-$subtotal_ht);
855 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
870 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
873 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
874 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pj ON p.fk_projet = pj.rowid";
875 $sql .=
' WHERE 1 = 1';
876 if (!empty($date_start)) {
877 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"'";
879 if (!empty($date_end)) {
880 $sql .=
" AND p.datep <= '".$db->idate($date_end).
"'";
882 $sql .=
' GROUP BY p.rowid, project_ref';
883 $sql .=
' ORDER BY project_ref';
885 dol_syslog(
'get various payments', LOG_DEBUG);
886 $result = $db->query($sql);
888 $num = $db->num_rows($result);
890 while ($obj = $db->fetch_object($result)) {
891 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
894 if (isset($obj->amount)) {
895 $subtotal_ht += -$obj->amount;
896 $subtotal_ttc += -$obj->amount;
898 $total_ht_outcome += $obj->amount;
899 $total_ttc_outcome += $obj->amount;
901 echo
'<tr class="oddeven">';
902 echo
'<td> </td>';
903 echo
"<td>".$langs->trans(
"Project").
' <a href="'.DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
'">'.$project_ref.
"</a></td>\n";
904 echo
'<td class="right">';
905 if ($modecompta ==
'CREANCES-DETTES') {
906 echo
'<span class="amount">'.price(-$obj->amount).
'</span>';
909 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
913 if (isset($obj->amount)) {
914 $subtotal_ht += $obj->amount;
915 $subtotal_ttc += $obj->amount;
917 $total_ht_income += $obj->amount;
918 $total_ttc_income += $obj->amount;
920 echo
'<tr class="oddeven"><td> </td>';
921 echo
"<td>".$langs->trans(
"Project").
" <a href=\"".DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
"\">".$project_ref.
"</a></td>\n";
922 echo
'<td class="right">';
923 if ($modecompta ==
'CREANCES-DETTES') {
924 echo
'<span class="amount">'.price($obj->amount).
'</span>';
927 echo
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
931 echo
'<tr class="oddeven">';
932 echo
'<td> </td>';
933 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
938 $total_ht += $subtotal_ht;
939 $total_ttc += $subtotal_ttc;
940 echo
'<tr class="liste_total">';
943 echo
'<td class="right">';
944 if ($modecompta ==
'CREANCES-DETTES') {
945 echo
price($subtotal_ht);
948 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
951 dol_print_error($db);
962 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
964 $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';
965 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
966 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet AS pj ON l.fk_projet = pj.rowid';
967 $sql .=
' WHERE 1 = 1';
968 if (!empty($date_start)) {
969 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"'";
971 if (!empty($date_end)) {
972 $sql .=
" AND p.datep <= '".$db->idate($date_end).
"'";
974 $sql .=
' GROUP BY pj.rowid, project_ref';
975 $sql .=
' ORDER BY project_ref';
978 $result = $db->query($sql);
980 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
981 $loan_static =
new Loan($db);
983 while ($obj = $db->fetch_object($result)) {
984 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
986 echo
'<tr class="oddeven"><td> </td>';
987 echo
"<td>".$langs->trans(
"Project").
' <a href="'.DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
'">'.$project_ref.
"</a></td>\n";
988 if ($modecompta ==
'CREANCES-DETTES') {
989 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
991 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
993 $subtotal_ht -= $obj->amount;
994 $subtotal_ttc -= $obj->amount;
996 $total_ht += $subtotal_ht;
997 $total_ttc += $subtotal_ttc;
999 $total_ht_income += $subtotal_ht;
1000 $total_ttc_income += $subtotal_ttc;
1002 echo
'<tr class="liste_total">';
1005 echo
'<td class="right">';
1006 if ($modecompta ==
'CREANCES-DETTES') {
1007 echo
price($subtotal_ht);
1010 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
1013 dol_print_error($db);
1018$action =
"balanceclient";
1019$object = array(&$total_ht, &$total_ttc);
1020$parameters = array();
1021$parameters[
"mode"] = $modecompta;
1023$parameters[
"date_end"] = $date_end;
1025$hookmanager->initHooks(array(
'externalbalance'));
1026$reshook = $hookmanager->executeHooks(
'addReportInfo', $parameters, $object, $action);
1027echo $hookmanager->resPrint;
1035echo
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
1038echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1039if ($modecompta ==
'CREANCES-DETTES') {
1040 echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1041} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1044echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1046echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1047if ($modecompta ==
'CREANCES-DETTES') {
1048 echo
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1049} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1052echo
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1054echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1055if ($modecompta ==
'CREANCES-DETTES') {
1056 echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht,
'MT')).
'</td>';
1057} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1060echo
'<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...
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
img_next($titlealt='default', $moreatt='')
Show next logo.
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, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.