36require
'../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancycategory.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
56$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy',
'loan'));
58$date_startmonth =
GETPOSTINT(
'date_startmonth');
64$showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'yes';
66$search_project_ref =
GETPOST(
'search_project_ref',
'alpha');
69$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
70$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
72if (empty($page) || $page == -1) {
75$offset = $limit * $page;
88 $year_start = $year_current;
90 $year_current = $year;
94$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
95$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
98if (empty($date_start) || empty($date_end)) {
102 $year_end = $year_start;
106 if (!$year && $month_start > $month_current) {
111 $month_end = $month_start - 1;
112 $year_end = $year_start + 1;
114 if ($month_end < 1) {
118 $month_end = $month_start;
143$year_start = $tmps[
'year'];
145$year_end = $tmpe[
'year'];
146$nbofyear = ($year_end - $year_start) + 1;
151if (isModEnabled(
'accounting')) {
153 $modecompta =
'CREANCES-DETTES';
155if (
GETPOST(
"modecompta",
'alpha')) {
156 $modecompta =
GETPOST(
"modecompta",
'alpha');
163if ($user->socid > 0) {
164 $socid = $user->socid;
166if (isModEnabled(
'comptabilite')) {
169if (isModEnabled(
'accounting')) {
170 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
172$hookmanager->initHooks([
'customersupplierreportlist']);
181$form =
new Form($db);
189$name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
190$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
194if ($modecompta ==
"CREANCES-DETTES") {
195 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
196 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
197 $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>" :
"");
200} elseif ($modecompta ==
"RECETTES-DEPENSES") {
201 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
202 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
203 $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>" :
"");
206} elseif ($modecompta ==
"BOOKKEEPING") {
207 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
208 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
209 $arraylist = array(
'no'=>$langs->trans(
"CustomerCode"),
'yes'=>$langs->trans(
"AccountWithNonZeroValues"),
'all'=>$langs->trans(
"All"));
210 $period .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
211 $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>" :
"");
224$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModePayment");
225if (isModEnabled(
'accounting')) {
226 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
228$calcmode .=
'</label>';
229$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
230if (isModEnabled(
'accounting')) {
231 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
233$calcmode .=
'</label>';
235report_header($name,
'', $period, $periodlink,
"", $builddate, $exportlink, array(
'modecompta'=>$modecompta,
'showaccountdetail'=>$showaccountdetail), $calcmode);
238$param =
'&modecompta='.urlencode($modecompta).
'&showaccountdetail='.urlencode($showaccountdetail);
239$search_date_url =
'';
241 $param .=
'&date_startday='.$date_startday;
242 $search_date_url .=
'&search_date_startday='.$date_startday;
244if ($date_startmonth) {
245 $param .=
'&date_startmonth='.$date_startmonth;
246 $search_date_url .=
'&search_date_startmonth='.$date_startmonth;
248if ($date_startyear) {
249 $param .=
'&date_startyear='.$date_startyear;
250 $search_date_url .=
'&search_date_startyear='.$date_startyear;
253 $param .=
'&date_endday='.$date_endday;
254 $search_date_url .=
'&search_date_endday='.$date_endday;
257 $param .=
'&date_endmonth='.$date_endmonth;
258 $search_date_url .=
'&search_date_endmonth='.$date_endmonth;
261 $param .=
'&date_endyear='.$date_endyear;
262 $search_date_url .=
'&search_date_endyear='.$date_endyear;
265print
'<table class="liste noborder centpercent">';
266print
'<tr class="liste_titre">';
268if ($modecompta ==
'BOOKKEEPING') {
269 print_liste_field_titre(
"ByProjects", $_SERVER[
"PHP_SELF"],
'f.thirdparty_code,f.rowid',
'', $param,
'', $sortfield, $sortorder,
'width200 ');
274if ($modecompta ==
'BOOKKEEPING') {
275 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
'amount',
'', $param,
'class="right"', $sortfield, $sortorder);
277 if ($modecompta ==
'CREANCES-DETTES') {
278 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
'amount_ht',
'', $param,
'class="right"', $sortfield, $sortorder);
282 print_liste_field_titre(
"AmountTTC", $_SERVER[
"PHP_SELF"],
'amount_ttc',
'', $param,
'class="right"', $sortfield, $sortorder);
287$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
289if ($modecompta ==
'BOOKKEEPING') {
290 echo
"<p>BOOKKEEPING mode not implemented for this report type by project.</p>";
295 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
298 if ($modecompta ==
'CREANCES-DETTES') {
299 $sql =
"SELECT p.rowid as rowid, p.ref as project_name, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
300 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
301 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
302 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON f.fk_projet = p.rowid";
303 $sql .=
" WHERE f.fk_soc = s.rowid";
304 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
305 $sql .=
" AND f.fk_statut IN (1,2)";
307 $sql .=
" AND f.type IN (0,1,2,5)";
309 $sql .=
" AND f.type IN (0,1,2,3,5)";
311 if (!empty($date_start) && !empty($date_end)) {
312 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
315 $sql .=
" AND f.fk_soc = ".((int) $socid);
317 $sql .=
" GROUP BY p.rowid, project_name";
318 $sql .= $db->order($sortfield, $sortorder);
319 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
320 $sql =
"SELECT p.rowid as rowid, p.ref as project_name, sum(pf.amount) as amount_ttc";
321 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
322 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
323 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON f.fk_projet = p.rowid";
324 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
325 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as pa";
326 $sql .=
" WHERE pa.rowid = pf.fk_paiement";
327 $sql .=
" AND pf.fk_facture = f.rowid";
328 $sql .=
" AND f.fk_soc = s.rowid";
329 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
330 if (!empty($date_start) && !empty($date_end)) {
331 $sql .=
" AND pa.datep >= '".$db->idate($date_start).
"' AND pa.datep <= '".$db->idate($date_end).
"'";
334 $sql .=
" AND f.fk_soc = ".((int) $socid);
336 $sql .=
" GROUP BY p.rowid, project_name";
337 $sql .= $db->order($sortfield, $sortorder);
340 dol_syslog(
"by project, get customer invoices", LOG_DEBUG);
341 $result = $db->query($sql);
343 $num = $db->num_rows($result);
346 $objp = $db->fetch_object($result);
347 echo
'<tr class="oddeven">';
348 echo
'<td> </td>';
349 echo
"<td>".$langs->trans(
"Project").
" ";
350 if (!empty($objp->project_name)) {
351 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_name.
'</a>';
353 echo $langs->trans(
"None");
355 $detailed_list_url =
'';
357 $detailed_list_url .= empty($objp->project_name)?
"!*": $objp->project_name;
358 $detailed_list_url .= $search_date_url;
359 echo
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
361 echo
'<td class="right">';
362 if ($modecompta ==
'CREANCES-DETTES') {
363 echo
'<span class="amount">'.price($objp->amount_ht).
"</span>";
366 echo
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
368 $total_ht += ($objp->amount_ht ?? 0);
369 $total_ttc += $objp->amount_ttc;
378 if ($total_ttc == 0) {
379 echo
'<tr class="oddeven">';
380 echo
'<td> </td>';
381 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
385 $total_ht_income += $total_ht;
386 $total_ttc_income += $total_ttc;
388 echo
'<tr class="liste_total">';
391 echo
'<td class="right">';
392 if ($modecompta ==
'CREANCES-DETTES') {
393 echo
price($total_ht);
396 echo
'<td class="right">'.price($total_ttc).
'</td>';
403 if (isModEnabled(
'don')) {
404 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
406 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
407 if ($modecompta ==
'CREANCES-DETTES') {
408 $sql =
"SELECT p.rowid as rowid, p.ref as project_name, sum(d.amount) as amount";
409 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as d";
410 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON d.fk_projet = p.rowid";
411 $sql .=
" WHERE d.entity IN (".getEntity(
'donation').
")";
412 $sql .=
" AND d.fk_statut in (1,2)";
414 $sql =
"SELECT p.rowid as rowid, p.ref as project_name, sum(d.amount) as amount";
415 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as d";
416 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = d.rowid";
417 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON d.fk_projet = p.rowid";
418 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
419 $sql .=
" WHERE d.entity IN (".getEntity(
'donation').
")";
420 $sql .=
" AND d.fk_statut >= 2";
422 if (!empty($date_start) && !empty($date_end)) {
423 $sql .=
" AND d.datedon >= '".$db->idate($date_start).
"' AND d.datedon <= '".$db->idate($date_end).
"'";
426 $sql .=
" GROUP BY p.rowid, p.ref";
427 $newsortfield = $sortfield;
428 if ($newsortfield ==
's.nom, s.rowid') {
429 $newsortfield =
'p.ref';
431 if ($newsortfield ==
'amount_ht') {
432 $newsortfield =
'amount';
434 if ($newsortfield ==
'amount_ttc') {
435 $newsortfield =
'amount';
437 $sql .= $db->order($newsortfield, $sortorder);
440 $result = $db->query($sql);
444 $num = $db->num_rows($result);
448 $obj = $db->fetch_object($result);
450 $total_ht += $obj->amount;
451 $total_ttc += $obj->amount;
452 $subtotal_ht += $obj->amount;
453 $subtotal_ttc += $obj->amount;
455 echo
'<tr class="oddeven">';
456 echo
'<td> </td>';
457 $project_name = empty($obj->project_name)? $langs->trans(
"None"): $obj->project_name;
458 echo
"<td>".$langs->trans(
"Project").
" <a href=\"".DOL_URL_ROOT.
"/projet/card.php?id=".$obj->ref.
"\">".$project_name.
"</a></td>\n";
460 echo
'<td class="right">';
461 if ($modecompta ==
'CREANCES-DETTES') {
462 echo
'<span class="amount">'.price($obj->amount).
'</span>';
465 echo
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
470 echo
'<tr class="oddeven"><td> </td>';
471 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
478 $total_ht_income += $subtotal_ht;
479 $total_ttc_income += $subtotal_ttc;
481 echo
'<tr class="liste_total">';
484 echo
'<td class="right">';
485 if ($modecompta ==
'CREANCES-DETTES') {
486 echo
price($subtotal_ht);
489 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
496 if ($modecompta ==
'CREANCES-DETTES') {
497 $sql =
"SELECT p.rowid as rowid, p.ref as project_name, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
498 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
499 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
500 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON f.fk_projet = p.rowid";
501 $sql .=
" WHERE f.fk_soc = s.rowid";
502 $sql .=
" AND f.fk_statut IN (1,2)";
504 $sql .=
" AND f.type IN (0,1,2)";
506 $sql .=
" AND f.type IN (0,1,2,3)";
508 if (!empty($date_start) && !empty($date_end)) {
509 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
511 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
512 $sql =
"SELECT pr.rowid as rowid, pr.ref as project_name, sum(pf.amount) as amount_ttc";
513 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
514 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
515 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON pf.fk_facturefourn = f.rowid";
516 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pr ON f.fk_projet = pr.rowid";
517 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON f.fk_soc = s.rowid";
518 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
519 if (!empty($date_start) && !empty($date_end)) {
520 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
524 $sql .=
" AND f.entity = ".((int)
$conf->entity);
526 $sql .=
" AND f.fk_soc = ".((int) $socid);
528 $sql .=
" GROUP BY rowid, project_name";
529 $sql .= $db->order($sortfield, $sortorder);
531 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
535 dol_syslog(
"by project, get suppliers invoices", LOG_DEBUG);
536 $result = $db->query($sql);
538 $num = $db->num_rows($result);
542 $objp = $db->fetch_object($result);
544 echo
'<tr class="oddeven">';
545 echo
'<td> </td>';
547 echo
"<td>".$langs->trans(
"Project").
" ";
548 if (!empty($objp->project_name)) {
549 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_name.
'</a>';
551 echo $langs->trans(
"None");
553 $detailed_list_url =
'';
555 $detailed_list_url .= empty($objp->project_name)?
"!*": $objp->project_name;
556 $detailed_list_url .= $search_date_url;
557 echo
' (<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
560 echo
'<td class="right">';
561 if ($modecompta ==
'CREANCES-DETTES') {
562 echo
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
565 echo
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
567 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
568 $total_ttc -= $objp->amount_ttc;
569 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
570 $subtotal_ttc += $objp->amount_ttc;
576 echo
'<tr class="oddeven">';
577 echo
'<td> </td>';
578 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
587 $total_ht_outcome += $subtotal_ht;
588 $total_ttc_outcome += $subtotal_ttc;
590 echo
'<tr class="liste_total">';
593 echo
'<td class="right">';
594 if ($modecompta ==
'CREANCES-DETTES') {
595 echo
price(-$subtotal_ht);
598 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
605 if (isModEnabled(
'salaries')) {
606 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
608 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
609 if ($modecompta ==
'CREANCES-DETTES') {
610 $column =
's.dateep';
612 $sql =
"SELECT p.rowid as rowid, p.ref as project_name, sum(s.amount) as amount";
613 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
614 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
615 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON s.fk_projet = p.rowid";
616 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
617 if (!empty($date_start) && !empty($date_end)) {
618 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
621 $column =
'ps.datep';
623 $sql =
"SELECT pr.rowid as rowid, pr.ref as project_name, sum(ps.amount) as amount";
624 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as ps";
625 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = ps.fk_salary";
626 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
627 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pr ON s.fk_projet = pr.rowid";
628 $sql .=
" WHERE ps.entity IN (".getEntity(
'payment_salary').
")";
629 if (!empty($date_start) && !empty($date_end)) {
630 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
635 $sql .=
" GROUP BY rowid, project_name";
636 $newsortfield = $sortfield;
637 if ($newsortfield ==
's.nom, s.rowid') {
638 $newsortfield =
'project_name';
640 if ($newsortfield ==
'amount_ht') {
641 $newsortfield =
'amount';
643 if ($newsortfield ==
'amount_ttc') {
644 $newsortfield =
'amount';
646 $sql .= $db->order($newsortfield, $sortorder);
650 $result = $db->query($sql);
654 $num = $db->num_rows($result);
658 $obj = $db->fetch_object($result);
660 $project_name = !empty($obj->project_name) ? $obj->project_name : $langs->trans(
"None");
662 $total_ht -= $obj->amount;
663 $total_ttc -= $obj->amount;
664 $subtotal_ht += $obj->amount;
665 $subtotal_ttc += $obj->amount;
667 echo
'<tr class="oddeven"><td> </td>';
668 echo
"<td>".$langs->trans(
"Project").
" ";
669 if (!empty($objp->project_name)) {
670 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_name.
'</a>';
672 echo $langs->trans(
"None");
675 echo
'<td class="right">';
676 if ($modecompta ==
'CREANCES-DETTES') {
677 echo
'<span class="amount">'.price(-$obj->amount).
'</span>';
680 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
685 echo
'<tr class="oddeven">';
686 echo
'<td> </td>';
687 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
694 $total_ht_outcome += $subtotal_ht;
695 $total_ttc_outcome += $subtotal_ttc;
697 echo
'<tr class="liste_total">';
700 echo
'<td class="right">';
701 if ($modecompta ==
'CREANCES-DETTES') {
702 echo
price(-$subtotal_ht);
705 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
714 if (isModEnabled(
'expensereport')) {
715 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
716 $langs->load(
'trips');
717 if ($modecompta ==
'CREANCES-DETTES') {
718 $sql =
"SELECT ed.rowid as rowid, ed.fk_projet, p.rowid as project_rowid, p.ref as project_name, sum(ed.total_ht) as amount_ht, sum(ed.total_ttc) as amount_ttc";
719 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as ed";
720 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport as e ON ed.fk_expensereport = e.rowid";
721 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON ed.fk_projet = p.rowid";
722 $sql .=
" WHERE e.entity IN (".getEntity(
'expensereport').
")";
723 $sql .=
" AND e.fk_statut >= 5";
725 $column =
'e.date_valid';
727 $sql =
"SELECT ed.rowid as rowid, ed.fk_projet, p.rowid as project_rowid, p.ref as project_name, sum(DISTINCT pe.amount) as amount_ht, sum(DISTINCT pe.amount) as amount_ttc";
728 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as ed";
729 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport as e ON ed.fk_expensereport = e.rowid";
730 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = e.rowid";
731 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON ed.fk_projet = p.rowid";
732 $sql .=
" WHERE e.entity IN (".getEntity(
'expensereport').
")";
733 $sql .=
" AND e.fk_statut >= 5";
735 $column =
'pe.datep';
738 if (!empty($date_start) && !empty($date_end)) {
739 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
742 $sql .=
" GROUP BY ed.rowid, ed.fk_projet, p.rowid, p.ref";
743 $newsortfield = $sortfield;
744 if ($newsortfield ==
's.nom, s.rowid') {
745 $newsortfield =
'project_name';
747 $sql .= $db->order($newsortfield, $sortorder);
750 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
752 dol_syslog(
"by project, get expense report outcome");
753 $result = $db->query($sql);
757 $num = $db->num_rows($result);
759 while ($obj = $db->fetch_object($result)) {
760 $project_name = !empty($obj->project_name) ? $obj->project_name : $langs->trans(
"None");
762 $total_ht -= $obj->amount_ht;
763 $total_ttc -= $obj->amount_ttc;
764 $subtotal_ht += $obj->amount_ht;
765 $subtotal_ttc += $obj->amount_ttc;
767 echo
'<tr class="oddeven">';
768 echo
'<td> </td>';
770 echo
"<td>".$langs->trans(
"Project").
" ";
771 if (!empty($obj->project_name)) {
772 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$obj->project_rowid.
'">'.$obj->project_name.
'</a>';
774 echo $langs->trans(
"None");
776 $detailed_list_url =
'?id='.$obj->project_rowid;
777 $detailed_list_url .= $search_date_url;
778 echo
' (<a href="'.DOL_URL_ROOT.
'/projet/element.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
781 echo
'<td class="right">';
782 if ($modecompta ==
'CREANCES-DETTES') {
783 echo
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
786 echo
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
790 echo
'<tr class="oddeven">';
791 echo
'<td> </td>';
792 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
799 $total_ht_outcome += $subtotal_ht;
800 $total_ttc_outcome += $subtotal_ttc;
802 echo
'<tr class="liste_total">';
805 echo
'<td class="right">';
806 if ($modecompta ==
'CREANCES-DETTES') {
807 echo
price(-$subtotal_ht);
810 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
822 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled(
"bank") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
826 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
829 $sql =
"SELECT p.rowid as rowid, p.ref as project_name, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
830 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pj ON p.fk_projet = pj.rowid";
831 $sql .=
' WHERE 1 = 1';
832 if (!empty($date_start) && !empty($date_end)) {
833 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
835 $sql .=
' GROUP BY p.rowid, project_name';
836 $sql .=
' ORDER BY project_name';
838 dol_syslog(
'get various payments', LOG_DEBUG);
839 $result = $db->query($sql);
841 $num = $db->num_rows($result);
843 while ($obj = $db->fetch_object($result)) {
844 $project_name = !empty($obj->project_name) ? $obj->project_name : $langs->trans(
"None");
847 if (isset($obj->amount)) {
848 $subtotal_ht += -$obj->amount;
849 $subtotal_ttc += -$obj->amount;
851 $total_ht_outcome += $obj->amount;
852 $total_ttc_outcome += $obj->amount;
854 echo
'<tr class="oddeven">';
855 echo
'<td> </td>';
856 echo
"<td>".$langs->trans(
"Project").
" <a href=\"".DOL_URL_ROOT.
"/projet/card.php?id=".urlencode($obj->project_id).
"\">".$project_name.
"</a></td>\n";
857 echo
'<td class="right">';
858 if ($modecompta ==
'CREANCES-DETTES') {
859 echo
'<span class="amount">'.price(-$obj->amount).
'</span>';
862 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
866 if (isset($obj->amount)) {
867 $subtotal_ht += $obj->amount;
868 $subtotal_ttc += $obj->amount;
870 $total_ht_income += $obj->amount;
871 $total_ttc_income += $obj->amount;
873 echo
'<tr class="oddeven"><td> </td>';
874 echo
"<td>".$langs->trans(
"Project").
" <a href=\"".DOL_URL_ROOT.
"/projet/card.php?id=".urlencode($obj->project_id).
"\">".$project_name.
"</a></td>\n";
875 echo
'<td class="right">';
876 if ($modecompta ==
'CREANCES-DETTES') {
877 echo
'<span class="amount">'.price($obj->amount).
'</span>';
880 echo
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
884 echo
'<tr class="oddeven">';
885 echo
'<td> </td>';
886 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
891 $total_ht += $subtotal_ht;
892 $total_ttc += $subtotal_ttc;
893 echo
'<tr class="liste_total">';
896 echo
'<td class="right">';
897 if ($modecompta ==
'CREANCES-DETTES') {
898 echo
price($subtotal_ht);
901 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
912 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
916 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
918 $sql =
'SELECT pj.rowid as rowid, pj.ref as project_name, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) as amount FROM '.MAIN_DB_PREFIX.
'payment_loan as p';
919 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
920 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet AS pj ON l.fk_projet = pj.rowid';
921 $sql .=
' WHERE 1 = 1';
922 if (!empty($date_start) && !empty($date_end)) {
923 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
925 $sql .=
' GROUP BY pj.rowid, project_name';
926 $sql .=
' ORDER BY project_name';
929 $result = $db->query($sql);
931 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
932 $loan_static =
new Loan($db);
933 while ($obj = $db->fetch_object($result)) {
934 $project_name = !empty($obj->project_name) ? $obj->project_name : $langs->trans(
"None");
936 echo
'<tr class="oddeven"><td> </td>';
937 echo
"<td>".$langs->trans(
"Project").
" <a href=\"".DOL_URL_ROOT.
"/projet/card.php?id=".urlencode($obj->project_id).
"\">".$project_name.
"</a></td>\n";
938 if ($modecompta ==
'CREANCES-DETTES') {
939 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
941 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
943 $subtotal_ht -= $obj->amount;
944 $subtotal_ttc -= $obj->amount;
946 $total_ht += $subtotal_ht;
947 $total_ttc += $subtotal_ttc;
949 $total_ht_income += $subtotal_ht;
950 $total_ttc_income += $subtotal_ttc;
952 echo
'<tr class="liste_total">';
955 echo
'<td class="right">';
956 if ($modecompta ==
'CREANCES-DETTES') {
957 echo
price($subtotal_ht);
960 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
968$action =
"balanceclient";
969$object = array(&$total_ht, &$total_ttc);
970$parameters[
"mode"] = $modecompta;
971$parameters[
"date_start"] = $date_start;
972$parameters[
"date_end"] = $date_end;
974$hookmanager->initHooks(array(
'externalbalance'));
975$reshook = $hookmanager->executeHooks(
'addBalanceLine', $parameters, $object, $action);
976echo $hookmanager->resPrint;
982echo
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
985echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
986if ($modecompta ==
'CREANCES-DETTES') {
987 echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
988} elseif ($modecompta ==
'RECETTES-DEPENSES') {
991echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
993echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
994if ($modecompta ==
'CREANCES-DETTES') {
995 echo
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
996} elseif ($modecompta ==
'RECETTES-DEPENSES') {
999echo
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1001echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1002if ($modecompta ==
'CREANCES-DETTES') {
1003 echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht,
'MT')).
'</td>';
1004} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1007echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc,
'MT')).
'</td>';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
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...
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.