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'));
59$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,
'tzserver');
95$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
98if (empty($date_start) || empty($date_end)) {
102 $year_end = $year_start;
106 if (!$year && $month_start > $month_current) {
110 $month_end = $month_start - 1;
111 if ($month_end < 1) {
115 $month_end = $month_start;
140$year_start = $tmps[
'year'];
142$year_end = $tmpe[
'year'];
143$nbofyear = ($year_end - $year_start) + 1;
151if (
GETPOST(
"modecompta",
'alpha')) {
152 $modecompta =
GETPOST(
"modecompta",
'alpha');
159if ($user->socid > 0) {
160 $socid = $user->socid;
166 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
168$hookmanager->initHooks([
'customersupplierreportlist']);
177$form =
new Form($db);
185$name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
186$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
191if ($modecompta ==
"CREANCES-DETTES") {
192 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
193 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
194 $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>" :
"");
195 $description = $langs->trans(
"RulesAmountWithTaxExcluded");
196 $description .=
'<br>'.$langs->trans(
"RulesResultDue");
198 $description .=
"<br>".$langs->trans(
"DepositsAreNotIncluded");
200 $description .=
"<br>".$langs->trans(
"DepositsAreIncluded");
203 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
207} elseif ($modecompta ==
"RECETTES-DEPENSES") {
208 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
209 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
210 $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>" :
"");
211 $description = $langs->trans(
"RulesAmountWithTaxIncluded");
212 $description .=
'<br>'.$langs->trans(
"RulesResultInOut");
215} elseif ($modecompta ==
"BOOKKEEPING") {
216 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByProjects");
217 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
218 $arraylist = array(
'no'=>$langs->trans(
"CustomerCode"),
'yes'=>$langs->trans(
"AccountWithNonZeroValues"),
'all'=>$langs->trans(
"All"));
219 $period .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
220 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] - 1).
"&modecompta=".$modecompta.
"&showaccountdetail=".$showaccountdetail.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] + 1).
"&modecompta=".$modecompta.
"&showaccountdetail=".$showaccountdetail.
"'>".
img_next().
"</a>" :
"");
221 $description = $langs->trans(
"RulesAmountOnInOutBookkeepingRecord");
222 $description .=
' ('.$langs->trans(
"SeePageForSetup", DOL_URL_ROOT.
'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv(
"Accountancy").
' / '.$langs->transnoentitiesnoconv(
"Setup").
' / '.$langs->transnoentitiesnoconv(
"Chartofaccounts")).
')';
235$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModePayment");
237 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
239$calcmode .=
'</label>';
240$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
242 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
244$calcmode .=
'</label>';
246report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta,
'showaccountdetail'=>$showaccountdetail), $calcmode);
255$param =
'&modecompta='.urlencode($modecompta).
'&showaccountdetail='.urlencode($showaccountdetail);
256$search_date_url =
'';
258 $param .=
'&date_startday='.$date_startday;
259 $search_date_url .=
'&search_date_startday='.$date_startday;
261if ($date_startmonth) {
262 $param .=
'&date_startmonth='.$date_startmonth;
263 $search_date_url .=
'&search_date_startmonth='.$date_startmonth;
265if ($date_startyear) {
266 $param .=
'&date_startyear='.$date_startyear;
267 $search_date_url .=
'&search_date_startyear='.$date_startyear;
270 $param .=
'&date_endday='.$date_endday;
271 $search_date_url .=
'&search_date_endday='.$date_endday;
274 $param .=
'&date_endmonth='.$date_endmonth;
275 $search_date_url .=
'&search_date_endmonth='.$date_endmonth;
278 $param .=
'&date_endyear='.$date_endyear;
279 $search_date_url .=
'&search_date_endyear='.$date_endyear;
282print
'<table class="liste noborder centpercent">';
283print
'<tr class="liste_titre">';
285if ($modecompta ==
'BOOKKEEPING') {
286 print_liste_field_titre(
"ByProjects", $_SERVER[
"PHP_SELF"],
'f.thirdparty_code,f.rowid',
'', $param,
'', $sortfield, $sortorder,
'width200 ');
291if ($modecompta ==
'BOOKKEEPING') {
292 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
'amount',
'', $param,
'class="right"', $sortfield, $sortorder);
294 if ($modecompta ==
'CREANCES-DETTES') {
295 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
'amount_ht',
'', $param,
'class="right"', $sortfield, $sortorder);
299 print_liste_field_titre(
"AmountTTC", $_SERVER[
"PHP_SELF"],
'amount_ttc',
'', $param,
'class="right"', $sortfield, $sortorder);
304$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
306if ($modecompta ==
'BOOKKEEPING') {
307 echo
"<p>BOOKKEEPING mode not implemented for this report type by project.</p>";
309if (
isModEnabled(
'invoice') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
313 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
316 if ($modecompta ==
'CREANCES-DETTES') {
317 $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";
318 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
319 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
320 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON f.fk_projet = p.rowid";
321 $sql .=
" WHERE f.fk_soc = s.rowid";
322 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
323 $sql .=
" AND f.fk_statut IN (1,2)";
325 $sql .=
" AND f.type IN (0,1,2,5)";
327 $sql .=
" AND f.type IN (0,1,2,3,5)";
329 if (!empty($date_start)) {
330 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"'";
332 if (!empty($date_end)) {
333 $sql .=
" AND f.datef <= '".$db->idate($date_end).
"'";
336 $sql .=
" AND f.fk_soc = ".((int) $socid);
338 $sql .=
" GROUP BY p.rowid, project_ref";
339 $sql .= $db->order($sortfield, $sortorder);
340 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
341 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(pf.amount) as amount_ttc";
342 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
343 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
344 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON f.fk_projet = p.rowid";
345 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
346 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as pa";
347 $sql .=
" WHERE pa.rowid = pf.fk_paiement";
348 $sql .=
" AND pf.fk_facture = f.rowid";
349 $sql .=
" AND f.fk_soc = s.rowid";
350 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
351 if (!empty($date_start)) {
352 $sql .=
" AND pa.datep >= '".$db->idate($date_start).
"'";
354 if (!empty($date_start) && !empty($date_end)) {
355 $sql .=
" AND pa.datep <= '".$db->idate($date_end).
"'";
358 $sql .=
" AND f.fk_soc = ".((int) $socid);
360 $sql .=
" GROUP BY p.rowid, p.ref";
361 $sql .= $db->order($sortfield, $sortorder);
364 dol_syslog(
"by project, get customer invoices", LOG_DEBUG);
365 $result = $db->query($sql);
367 $num = $db->num_rows($result);
370 $objp = $db->fetch_object($result);
371 echo
'<tr class="oddeven">';
372 echo
'<td> </td>';
373 echo
"<td>".$langs->trans(
"Project").
" ";
374 if (!empty($objp->project_ref)) {
375 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_ref.
'</a>';
377 echo $langs->trans(
"None");
379 if ($modecompta ==
'CREANCES-DETTES') {
380 $detailed_list_url =
'';
381 $detailed_list_url .= empty($objp->project_ref)?
"?search_project_ref=^$":
"?search_project_ref=".urlencode($objp->project_ref);
382 $detailed_list_url .= $search_date_url;
383 echo
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
386 echo
'<td class="right">';
387 if ($modecompta ==
'CREANCES-DETTES') {
388 echo
'<span class="amount">'.price($objp->amount_ht).
"</span>";
391 echo
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
393 $total_ht += ($objp->amount_ht ?? 0);
394 $total_ttc += $objp->amount_ttc;
403 if ($total_ttc == 0) {
404 echo
'<tr class="oddeven">';
405 echo
'<td> </td>';
406 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
410 $total_ht_income += $total_ht;
411 $total_ttc_income += $total_ttc;
413 echo
'<tr class="liste_total">';
416 echo
'<td class="right">';
417 if ($modecompta ==
'CREANCES-DETTES') {
418 echo
price($total_ht);
421 echo
'<td class="right">'.price($total_ttc).
'</td>';
428 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
430 if ($modecompta ==
'CREANCES-DETTES') {
431 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(d.amount) as amount";
432 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as d";
433 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON d.fk_projet = p.rowid";
434 $sql .=
" WHERE d.entity IN (".getEntity(
'donation').
")";
435 $sql .=
" AND d.fk_statut in (1,2)";
437 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(d.amount) as amount";
438 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as d";
439 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = d.rowid";
440 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON d.fk_projet = p.rowid";
441 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
442 $sql .=
" WHERE d.entity IN (".getEntity(
'donation').
")";
443 $sql .=
" AND d.fk_statut >= 2";
445 if (!empty($date_start)) {
446 $sql .=
" AND d.datedon >= '".$db->idate($date_start).
"'";
448 if (!empty($date_end)) {
449 $sql .=
" AND d.datedon <= '".$db->idate($date_end).
"'";
451 $sql .=
" GROUP BY p.rowid, p.ref";
452 $newsortfield = $sortfield;
453 if ($newsortfield ==
's.nom, s.rowid') {
454 $newsortfield =
'p.ref';
456 if ($newsortfield ==
'amount_ht') {
457 $newsortfield =
'amount';
459 if ($newsortfield ==
'amount_ttc') {
460 $newsortfield =
'amount';
462 $sql .= $db->order($newsortfield, $sortorder);
465 $result = $db->query($sql);
469 $num = $db->num_rows($result);
473 $obj = $db->fetch_object($result);
475 $total_ht += $obj->amount;
476 $total_ttc += $obj->amount;
477 $subtotal_ht += $obj->amount;
478 $subtotal_ttc += $obj->amount;
480 echo
'<tr class="oddeven">';
481 echo
'<td> </td>';
482 $project_ref = empty($obj->project_ref)? $langs->trans(
"None"): $obj->project_ref;
483 echo
"<td>".$langs->trans(
"Project").
' <a href="'.DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
'">'.$project_ref.
"</a></td>\n";
485 echo
'<td class="right">';
486 if ($modecompta ==
'CREANCES-DETTES') {
487 echo
'<span class="amount">'.price($obj->amount).
'</span>';
490 echo
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
495 echo
'<tr class="oddeven"><td> </td>';
496 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
503 $total_ht_income += $subtotal_ht;
504 $total_ttc_income += $subtotal_ttc;
506 echo
'<tr class="liste_total">';
509 echo
'<td class="right">';
510 if ($modecompta ==
'CREANCES-DETTES') {
511 echo
price($subtotal_ht);
514 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
521 if ($modecompta ==
'CREANCES-DETTES') {
522 $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";
523 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
524 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
525 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON f.fk_projet = p.rowid";
526 $sql .=
" WHERE f.fk_soc = s.rowid";
527 $sql .=
" AND f.fk_statut IN (1,2)";
529 $sql .=
" AND f.type IN (0,1,2)";
531 $sql .=
" AND f.type IN (0,1,2,3)";
533 if (!empty($date_start)) {
534 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"'";
536 if (!empty($date_end)) {
537 $sql .=
" AND f.datef <= '".$db->idate($date_end).
"'";
539 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
540 $sql =
"SELECT pr.rowid as rowid, pr.ref as project_ref, sum(pf.amount) as amount_ttc";
541 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
542 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
543 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON pf.fk_facturefourn = f.rowid";
544 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pr ON f.fk_projet = pr.rowid";
545 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON f.fk_soc = s.rowid";
546 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
547 if (!empty($date_start)) {
548 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"'";
550 if (!empty($date_end)) {
551 $sql .=
" AND p.datep <= '".$db->idate($date_end).
"'";
555 $sql .=
" AND f.entity = ".((int) $conf->entity);
557 $sql .=
" AND f.fk_soc = ".((int) $socid);
559 $sql .=
" GROUP BY rowid, project_ref";
560 $sql .= $db->order($sortfield, $sortorder);
562 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
566 dol_syslog(
"by project, get suppliers invoices", LOG_DEBUG);
567 $result = $db->query($sql);
569 $num = $db->num_rows($result);
573 $objp = $db->fetch_object($result);
575 echo
'<tr class="oddeven">';
576 echo
'<td> </td>';
578 echo
"<td>".$langs->trans(
"Project").
" ";
579 if (!empty($objp->project_ref)) {
580 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_ref.
'</a>';
582 echo $langs->trans(
"None");
584 $detailed_list_url =
'';
586 $detailed_list_url .= empty($objp->project_ref)?
"?search_project_ref=^$":
'?search_project_ref='.urlencode($objp->project_ref);
587 $detailed_list_url .= $search_date_url;
588 echo
' (<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
591 echo
'<td class="right">';
592 if ($modecompta ==
'CREANCES-DETTES') {
593 echo
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
596 echo
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
598 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
599 $total_ttc -= $objp->amount_ttc;
600 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
601 $subtotal_ttc += $objp->amount_ttc;
607 echo
'<tr class="oddeven">';
608 echo
'<td> </td>';
609 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
618 $total_ht_outcome += $subtotal_ht;
619 $total_ttc_outcome += $subtotal_ttc;
621 echo
'<tr class="liste_total">';
624 echo
'<td class="right">';
625 if ($modecompta ==
'CREANCES-DETTES') {
626 echo
price(-$subtotal_ht);
629 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
636 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
638 if ($modecompta ==
'CREANCES-DETTES') {
639 $column =
's.dateep';
641 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(s.amount) as amount";
642 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
643 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
644 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON s.fk_projet = p.rowid";
645 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
646 if (!empty($date_start)) {
647 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate($date_start).
"'";
649 if (!empty($date_end)) {
650 $sql .=
" AND ".$db->sanitize($column).
" <= '".$db->idate($date_end).
"'";
653 $column =
'ps.datep';
655 $sql =
"SELECT pr.rowid as rowid, pr.ref as project_ref, sum(ps.amount) as amount";
656 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as ps";
657 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = ps.fk_salary";
658 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
659 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pr ON s.fk_projet = pr.rowid";
660 $sql .=
" WHERE ps.entity IN (".getEntity(
'payment_salary').
")";
661 if (!empty($date_start)) {
662 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate($date_start).
"'";
664 if (!empty($date_end)) {
665 $sql .=
" AND ".$db->sanitize($column).
" <= '".$db->idate($date_end).
"'";
670 $sql .=
" GROUP BY rowid, project_ref";
671 $newsortfield = $sortfield;
672 if ($newsortfield ==
's.nom, s.rowid') {
673 $newsortfield =
'project_ref';
675 if ($newsortfield ==
'amount_ht') {
676 $newsortfield =
'amount';
678 if ($newsortfield ==
'amount_ttc') {
679 $newsortfield =
'amount';
681 $sql .= $db->order($newsortfield, $sortorder);
684 $result = $db->query($sql);
688 $num = $db->num_rows($result);
692 $obj = $db->fetch_object($result);
694 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
696 $total_ht -= $obj->amount;
697 $total_ttc -= $obj->amount;
698 $subtotal_ht += $obj->amount;
699 $subtotal_ttc += $obj->amount;
701 echo
'<tr class="oddeven"><td> </td>';
702 echo
"<td>".$langs->trans(
"Project").
" ";
703 if (!empty($objp->project_ref)) {
704 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_ref.
'</a>';
706 echo $langs->trans(
"None");
709 echo
'<td class="right">';
710 if ($modecompta ==
'CREANCES-DETTES') {
711 echo
'<span class="amount">'.price(-$obj->amount).
'</span>';
714 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
719 echo
'<tr class="oddeven">';
720 echo
'<td> </td>';
721 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
728 $total_ht_outcome += $subtotal_ht;
729 $total_ttc_outcome += $subtotal_ttc;
731 echo
'<tr class="liste_total">';
734 echo
'<td class="right">';
735 if ($modecompta ==
'CREANCES-DETTES') {
736 echo
price(-$subtotal_ht);
739 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
748 $langs->load(
'trips');
749 if ($modecompta ==
'CREANCES-DETTES') {
750 $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";
751 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as ed";
752 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport as e ON ed.fk_expensereport = e.rowid";
753 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON ed.fk_projet = p.rowid";
754 $sql .=
" WHERE e.entity IN (".getEntity(
'expensereport').
")";
755 $sql .=
" AND e.fk_statut >= 5";
757 $column =
'e.date_valid';
759 $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";
760 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as ed";
761 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport as e ON ed.fk_expensereport = e.rowid";
762 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = e.rowid";
763 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON ed.fk_projet = p.rowid";
764 $sql .=
" WHERE e.entity IN (".getEntity(
'expensereport').
")";
765 $sql .=
" AND e.fk_statut >= 5";
767 $column =
'pe.datep';
769 if (!empty($date_start)) {
770 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate($date_start).
"'";
772 if (!empty($date_end)) {
773 $sql .=
" AND ".$db->sanitize($column).
" <= '".$db->idate($date_end).
"'";
776 $sql .=
" GROUP BY ed.rowid, ed.fk_projet, p.rowid, p.ref";
777 $newsortfield = $sortfield;
778 if ($newsortfield ==
's.nom, s.rowid') {
779 $newsortfield =
'project_ref';
781 $sql .= $db->order($newsortfield, $sortorder);
783 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
785 dol_syslog(
"by project, get expense report outcome");
786 $result = $db->query($sql);
790 $num = $db->num_rows($result);
792 while ($obj = $db->fetch_object($result)) {
793 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
795 $total_ht -= $obj->amount_ht;
796 $total_ttc -= $obj->amount_ttc;
797 $subtotal_ht += $obj->amount_ht;
798 $subtotal_ttc += $obj->amount_ttc;
800 echo
'<tr class="oddeven">';
801 echo
'<td> </td>';
803 echo
"<td>".$langs->trans(
"Project").
" ";
804 if (!empty($obj->project_ref)) {
805 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$obj->project_rowid.
'">'.$obj->project_ref.
'</a>';
807 echo $langs->trans(
"None");
809 $detailed_list_url =
'?id='.$obj->project_rowid;
810 $detailed_list_url .= $search_date_url;
811 echo
' (<a href="'.DOL_URL_ROOT.
'/projet/element.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
814 echo
'<td class="right">';
815 if ($modecompta ==
'CREANCES-DETTES') {
816 echo
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
819 echo
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
823 echo
'<tr class="oddeven">';
824 echo
'<td> </td>';
825 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
832 $total_ht_outcome += $subtotal_ht;
833 $total_ttc_outcome += $subtotal_ttc;
835 echo
'<tr class="liste_total">';
838 echo
'<td class="right">';
839 if ($modecompta ==
'CREANCES-DETTES') {
840 echo
price(-$subtotal_ht);
843 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
858 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
861 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
862 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pj ON p.fk_projet = pj.rowid";
863 $sql .=
' WHERE 1 = 1';
864 if (!empty($date_start)) {
865 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"'";
867 if (!empty($date_end)) {
868 $sql .=
" AND p.datep <= '".$db->idate($date_end).
"'";
870 $sql .=
' GROUP BY p.rowid, project_ref';
871 $sql .=
' ORDER BY project_ref';
873 dol_syslog(
'get various payments', LOG_DEBUG);
874 $result = $db->query($sql);
876 $num = $db->num_rows($result);
878 while ($obj = $db->fetch_object($result)) {
879 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
882 if (isset($obj->amount)) {
883 $subtotal_ht += -$obj->amount;
884 $subtotal_ttc += -$obj->amount;
886 $total_ht_outcome += $obj->amount;
887 $total_ttc_outcome += $obj->amount;
889 echo
'<tr class="oddeven">';
890 echo
'<td> </td>';
891 echo
"<td>".$langs->trans(
"Project").
' <a href="'.DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
'">'.$project_ref.
"</a></td>\n";
892 echo
'<td class="right">';
893 if ($modecompta ==
'CREANCES-DETTES') {
894 echo
'<span class="amount">'.price(-$obj->amount).
'</span>';
897 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
901 if (isset($obj->amount)) {
902 $subtotal_ht += $obj->amount;
903 $subtotal_ttc += $obj->amount;
905 $total_ht_income += $obj->amount;
906 $total_ttc_income += $obj->amount;
908 echo
'<tr class="oddeven"><td> </td>';
909 echo
"<td>".$langs->trans(
"Project").
" <a href=\"".DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
"\">".$project_ref.
"</a></td>\n";
910 echo
'<td class="right">';
911 if ($modecompta ==
'CREANCES-DETTES') {
912 echo
'<span class="amount">'.price($obj->amount).
'</span>';
915 echo
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
919 echo
'<tr class="oddeven">';
920 echo
'<td> </td>';
921 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
926 $total_ht += $subtotal_ht;
927 $total_ttc += $subtotal_ttc;
928 echo
'<tr class="liste_total">';
931 echo
'<td class="right">';
932 if ($modecompta ==
'CREANCES-DETTES') {
933 echo
price($subtotal_ht);
936 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
950 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
952 $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';
953 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
954 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet AS pj ON l.fk_projet = pj.rowid';
955 $sql .=
' WHERE 1 = 1';
956 if (!empty($date_start)) {
957 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"'";
959 if (!empty($date_end)) {
960 $sql .=
" AND p.datep <= '".$db->idate($date_end).
"'";
962 $sql .=
' GROUP BY pj.rowid, project_ref';
963 $sql .=
' ORDER BY project_ref';
966 $result = $db->query($sql);
968 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
969 $loan_static =
new Loan($db);
971 while ($obj = $db->fetch_object($result)) {
972 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
974 echo
'<tr class="oddeven"><td> </td>';
975 echo
"<td>".$langs->trans(
"Project").
' <a href="'.DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
'">'.$project_ref.
"</a></td>\n";
976 if ($modecompta ==
'CREANCES-DETTES') {
977 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
979 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
981 $subtotal_ht -= $obj->amount;
982 $subtotal_ttc -= $obj->amount;
984 $total_ht += $subtotal_ht;
985 $total_ttc += $subtotal_ttc;
987 $total_ht_income += $subtotal_ht;
988 $total_ttc_income += $subtotal_ttc;
990 echo
'<tr class="liste_total">';
993 echo
'<td class="right">';
994 if ($modecompta ==
'CREANCES-DETTES') {
995 echo
price($subtotal_ht);
998 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
1006$action =
"balanceclient";
1007$object = array(&$total_ht, &$total_ttc);
1008$parameters[
"mode"] = $modecompta;
1009$parameters[
"date_start"] = $date_start;
1010$parameters[
"date_end"] = $date_end;
1012$hookmanager->initHooks(array(
'externalbalance'));
1013$reshook = $hookmanager->executeHooks(
'addReportInfo', $parameters, $object, $action);
1014echo $hookmanager->resPrint;
1022echo
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
1025echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1026if ($modecompta ==
'CREANCES-DETTES') {
1027 echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1028} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1031echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1033echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1034if ($modecompta ==
'CREANCES-DETTES') {
1035 echo
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1036} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1039echo
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1041echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1042if ($modecompta ==
'CREANCES-DETTES') {
1043 echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht,
'MT')).
'</td>';
1044} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1047echo
'<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.
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.