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;
162if (isModEnabled(
'comptabilite')) {
165if (isModEnabled(
'accounting')) {
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");
236if (isModEnabled(
'accounting')) {
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");
241if (isModEnabled(
'accounting')) {
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 if (isModEnabled(
'don')) {
429 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
431 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
432 if ($modecompta ==
'CREANCES-DETTES') {
433 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(d.amount) as amount";
434 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as d";
435 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON d.fk_projet = p.rowid";
436 $sql .=
" WHERE d.entity IN (".getEntity(
'donation').
")";
437 $sql .=
" AND d.fk_statut in (1,2)";
439 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(d.amount) as amount";
440 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as d";
441 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = d.rowid";
442 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON d.fk_projet = p.rowid";
443 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
444 $sql .=
" WHERE d.entity IN (".getEntity(
'donation').
")";
445 $sql .=
" AND d.fk_statut >= 2";
447 if (!empty($date_start)) {
448 $sql .=
" AND d.datedon >= '".$db->idate($date_start).
"'";
450 if (!empty($date_end)) {
451 $sql .=
" AND d.datedon <= '".$db->idate($date_end).
"'";
454 $sql .=
" GROUP BY p.rowid, p.ref";
455 $newsortfield = $sortfield;
456 if ($newsortfield ==
's.nom, s.rowid') {
457 $newsortfield =
'p.ref';
459 if ($newsortfield ==
'amount_ht') {
460 $newsortfield =
'amount';
462 if ($newsortfield ==
'amount_ttc') {
463 $newsortfield =
'amount';
465 $sql .= $db->order($newsortfield, $sortorder);
468 $result = $db->query($sql);
472 $num = $db->num_rows($result);
476 $obj = $db->fetch_object($result);
478 $total_ht += $obj->amount;
479 $total_ttc += $obj->amount;
480 $subtotal_ht += $obj->amount;
481 $subtotal_ttc += $obj->amount;
483 echo
'<tr class="oddeven">';
484 echo
'<td> </td>';
485 $project_ref = empty($obj->project_ref)? $langs->trans(
"None"): $obj->project_ref;
486 echo
"<td>".$langs->trans(
"Project").
' <a href="'.DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
'">'.$project_ref.
"</a></td>\n";
488 echo
'<td class="right">';
489 if ($modecompta ==
'CREANCES-DETTES') {
490 echo
'<span class="amount">'.price($obj->amount).
'</span>';
493 echo
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
498 echo
'<tr class="oddeven"><td> </td>';
499 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
506 $total_ht_income += $subtotal_ht;
507 $total_ttc_income += $subtotal_ttc;
509 echo
'<tr class="liste_total">';
512 echo
'<td class="right">';
513 if ($modecompta ==
'CREANCES-DETTES') {
514 echo
price($subtotal_ht);
517 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
524 if ($modecompta ==
'CREANCES-DETTES') {
525 $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";
526 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
527 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
528 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON f.fk_projet = p.rowid";
529 $sql .=
" WHERE f.fk_soc = s.rowid";
530 $sql .=
" AND f.fk_statut IN (1,2)";
532 $sql .=
" AND f.type IN (0,1,2)";
534 $sql .=
" AND f.type IN (0,1,2,3)";
536 if (!empty($date_start)) {
537 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"'";
539 if (!empty($date_end)) {
540 $sql .=
" AND f.datef <= '".$db->idate($date_end).
"'";
542 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
543 $sql =
"SELECT pr.rowid as rowid, pr.ref as project_ref, sum(pf.amount) as amount_ttc";
544 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
545 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
546 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON pf.fk_facturefourn = f.rowid";
547 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pr ON f.fk_projet = pr.rowid";
548 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON f.fk_soc = s.rowid";
549 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
550 if (!empty($date_start)) {
551 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"'";
553 if (!empty($date_end)) {
554 $sql .=
" AND p.datep <= '".$db->idate($date_end).
"'";
558 $sql .=
" AND f.entity = ".((int)
$conf->entity);
560 $sql .=
" AND f.fk_soc = ".((int) $socid);
562 $sql .=
" GROUP BY rowid, project_ref";
563 $sql .= $db->order($sortfield, $sortorder);
565 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
569 dol_syslog(
"by project, get suppliers invoices", LOG_DEBUG);
570 $result = $db->query($sql);
572 $num = $db->num_rows($result);
576 $objp = $db->fetch_object($result);
578 echo
'<tr class="oddeven">';
579 echo
'<td> </td>';
581 echo
"<td>".$langs->trans(
"Project").
" ";
582 if (!empty($objp->project_ref)) {
583 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_ref.
'</a>';
585 echo $langs->trans(
"None");
587 $detailed_list_url =
'';
589 $detailed_list_url .= empty($objp->project_ref)?
"?search_project_ref=^$":
'?search_project_ref='.urlencode($objp->project_ref);
590 $detailed_list_url .= $search_date_url;
591 echo
' (<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
594 echo
'<td class="right">';
595 if ($modecompta ==
'CREANCES-DETTES') {
596 echo
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
599 echo
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
601 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
602 $total_ttc -= $objp->amount_ttc;
603 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
604 $subtotal_ttc += $objp->amount_ttc;
610 echo
'<tr class="oddeven">';
611 echo
'<td> </td>';
612 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
621 $total_ht_outcome += $subtotal_ht;
622 $total_ttc_outcome += $subtotal_ttc;
624 echo
'<tr class="liste_total">';
627 echo
'<td class="right">';
628 if ($modecompta ==
'CREANCES-DETTES') {
629 echo
price(-$subtotal_ht);
632 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
639 if (isModEnabled(
'salaries')) {
640 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
642 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
643 if ($modecompta ==
'CREANCES-DETTES') {
644 $column =
's.dateep';
646 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, sum(s.amount) as amount";
647 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
648 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
649 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON s.fk_projet = p.rowid";
650 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
651 if (!empty($date_start)) {
652 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate($date_start).
"'";
654 if (!empty($date_end)) {
655 $sql .=
" AND ".$db->sanitize($column).
" <= '".$db->idate($date_end).
"'";
658 $column =
'ps.datep';
660 $sql =
"SELECT pr.rowid as rowid, pr.ref as project_ref, sum(ps.amount) as amount";
661 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as ps";
662 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = ps.fk_salary";
663 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
664 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pr ON s.fk_projet = pr.rowid";
665 $sql .=
" WHERE ps.entity IN (".getEntity(
'payment_salary').
")";
666 if (!empty($date_start)) {
667 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate($date_start).
"'";
669 if (!empty($date_end)) {
670 $sql .=
" AND ".$db->sanitize($column).
" <= '".$db->idate($date_end).
"'";
675 $sql .=
" GROUP BY rowid, project_ref";
676 $newsortfield = $sortfield;
677 if ($newsortfield ==
's.nom, s.rowid') {
678 $newsortfield =
'project_ref';
680 if ($newsortfield ==
'amount_ht') {
681 $newsortfield =
'amount';
683 if ($newsortfield ==
'amount_ttc') {
684 $newsortfield =
'amount';
686 $sql .= $db->order($newsortfield, $sortorder);
690 $result = $db->query($sql);
694 $num = $db->num_rows($result);
698 $obj = $db->fetch_object($result);
700 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
702 $total_ht -= $obj->amount;
703 $total_ttc -= $obj->amount;
704 $subtotal_ht += $obj->amount;
705 $subtotal_ttc += $obj->amount;
707 echo
'<tr class="oddeven"><td> </td>';
708 echo
"<td>".$langs->trans(
"Project").
" ";
709 if (!empty($objp->project_ref)) {
710 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$objp->rowid.
'">'.$objp->project_ref.
'</a>';
712 echo $langs->trans(
"None");
715 echo
'<td class="right">';
716 if ($modecompta ==
'CREANCES-DETTES') {
717 echo
'<span class="amount">'.price(-$obj->amount).
'</span>';
720 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
725 echo
'<tr class="oddeven">';
726 echo
'<td> </td>';
727 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
734 $total_ht_outcome += $subtotal_ht;
735 $total_ttc_outcome += $subtotal_ttc;
737 echo
'<tr class="liste_total">';
740 echo
'<td class="right">';
741 if ($modecompta ==
'CREANCES-DETTES') {
742 echo
price(-$subtotal_ht);
745 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
754 if (isModEnabled(
'expensereport')) {
755 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
756 $langs->load(
'trips');
757 if ($modecompta ==
'CREANCES-DETTES') {
758 $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";
759 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as ed";
760 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport as e ON ed.fk_expensereport = e.rowid";
761 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON ed.fk_projet = p.rowid";
762 $sql .=
" WHERE e.entity IN (".getEntity(
'expensereport').
")";
763 $sql .=
" AND e.fk_statut >= 5";
765 $column =
'e.date_valid';
767 $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";
768 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as ed";
769 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport as e ON ed.fk_expensereport = e.rowid";
770 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = e.rowid";
771 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p ON ed.fk_projet = p.rowid";
772 $sql .=
" WHERE e.entity IN (".getEntity(
'expensereport').
")";
773 $sql .=
" AND e.fk_statut >= 5";
775 $column =
'pe.datep';
777 if (!empty($date_start)) {
778 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate($date_start).
"'";
780 if (!empty($date_end)) {
781 $sql .=
" AND ".$db->sanitize($column).
" <= '".$db->idate($date_end).
"'";
784 $sql .=
" GROUP BY ed.rowid, ed.fk_projet, p.rowid, p.ref";
785 $newsortfield = $sortfield;
786 if ($newsortfield ==
's.nom, s.rowid') {
787 $newsortfield =
'project_ref';
789 $sql .= $db->order($newsortfield, $sortorder);
792 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
794 dol_syslog(
"by project, get expense report outcome");
795 $result = $db->query($sql);
799 $num = $db->num_rows($result);
801 while ($obj = $db->fetch_object($result)) {
802 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
804 $total_ht -= $obj->amount_ht;
805 $total_ttc -= $obj->amount_ttc;
806 $subtotal_ht += $obj->amount_ht;
807 $subtotal_ttc += $obj->amount_ttc;
809 echo
'<tr class="oddeven">';
810 echo
'<td> </td>';
812 echo
"<td>".$langs->trans(
"Project").
" ";
813 if (!empty($obj->project_ref)) {
814 echo
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$obj->project_rowid.
'">'.$obj->project_ref.
'</a>';
816 echo $langs->trans(
"None");
818 $detailed_list_url =
'?id='.$obj->project_rowid;
819 $detailed_list_url .= $search_date_url;
820 echo
' (<a href="'.DOL_URL_ROOT.
'/projet/element.php'.$detailed_list_url.
'">'.$langs->trans(
"DetailedListLowercase").
"</a>)\n";
823 echo
'<td class="right">';
824 if ($modecompta ==
'CREANCES-DETTES') {
825 echo
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
828 echo
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
832 echo
'<tr class="oddeven">';
833 echo
'<td> </td>';
834 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
841 $total_ht_outcome += $subtotal_ht;
842 $total_ttc_outcome += $subtotal_ttc;
844 echo
'<tr class="liste_total">';
847 echo
'<td class="right">';
848 if ($modecompta ==
'CREANCES-DETTES') {
849 echo
price(-$subtotal_ht);
852 echo
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
864 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled(
"bank") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
868 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
871 $sql =
"SELECT p.rowid as rowid, p.ref as project_ref, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
872 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as pj ON p.fk_projet = pj.rowid";
873 $sql .=
' WHERE 1 = 1';
874 if (!empty($date_start)) {
875 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"'";
877 if (!empty($date_end)) {
878 $sql .=
" AND p.datep <= '".$db->idate($date_end).
"'";
880 $sql .=
' GROUP BY p.rowid, project_ref';
881 $sql .=
' ORDER BY project_ref';
883 dol_syslog(
'get various payments', LOG_DEBUG);
884 $result = $db->query($sql);
886 $num = $db->num_rows($result);
888 while ($obj = $db->fetch_object($result)) {
889 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
892 if (isset($obj->amount)) {
893 $subtotal_ht += -$obj->amount;
894 $subtotal_ttc += -$obj->amount;
896 $total_ht_outcome += $obj->amount;
897 $total_ttc_outcome += $obj->amount;
899 echo
'<tr class="oddeven">';
900 echo
'<td> </td>';
901 echo
"<td>".$langs->trans(
"Project").
' <a href="'.DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
'">'.$project_ref.
"</a></td>\n";
902 echo
'<td class="right">';
903 if ($modecompta ==
'CREANCES-DETTES') {
904 echo
'<span class="amount">'.price(-$obj->amount).
'</span>';
907 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
911 if (isset($obj->amount)) {
912 $subtotal_ht += $obj->amount;
913 $subtotal_ttc += $obj->amount;
915 $total_ht_income += $obj->amount;
916 $total_ttc_income += $obj->amount;
918 echo
'<tr class="oddeven"><td> </td>';
919 echo
"<td>".$langs->trans(
"Project").
" <a href=\"".DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
"\">".$project_ref.
"</a></td>\n";
920 echo
'<td class="right">';
921 if ($modecompta ==
'CREANCES-DETTES') {
922 echo
'<span class="amount">'.price($obj->amount).
'</span>';
925 echo
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
929 echo
'<tr class="oddeven">';
930 echo
'<td> </td>';
931 echo
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
936 $total_ht += $subtotal_ht;
937 $total_ttc += $subtotal_ttc;
938 echo
'<tr class="liste_total">';
941 echo
'<td class="right">';
942 if ($modecompta ==
'CREANCES-DETTES') {
943 echo
price($subtotal_ht);
946 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
957 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
961 echo
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
963 $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';
964 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
965 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet AS pj ON l.fk_projet = pj.rowid';
966 $sql .=
' WHERE 1 = 1';
967 if (!empty($date_start)) {
968 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"'";
970 if (!empty($date_end)) {
971 $sql .=
" AND p.datep <= '".$db->idate($date_end).
"'";
973 $sql .=
' GROUP BY pj.rowid, project_ref';
974 $sql .=
' ORDER BY project_ref';
977 $result = $db->query($sql);
979 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
980 $loan_static =
new Loan($db);
982 while ($obj = $db->fetch_object($result)) {
983 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans(
"None");
985 echo
'<tr class="oddeven"><td> </td>';
986 echo
"<td>".$langs->trans(
"Project").
' <a href="'.DOL_URL_ROOT.
"/projet/card.php?id=".((int) $obj->rowid).
'">'.$project_ref.
"</a></td>\n";
987 if ($modecompta ==
'CREANCES-DETTES') {
988 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
990 echo
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
992 $subtotal_ht -= $obj->amount;
993 $subtotal_ttc -= $obj->amount;
995 $total_ht += $subtotal_ht;
996 $total_ttc += $subtotal_ttc;
998 $total_ht_income += $subtotal_ht;
999 $total_ttc_income += $subtotal_ttc;
1001 echo
'<tr class="liste_total">';
1004 echo
'<td class="right">';
1005 if ($modecompta ==
'CREANCES-DETTES') {
1006 echo
price($subtotal_ht);
1009 echo
'<td class="right">'.price($subtotal_ttc).
'</td>';
1017$action =
"balanceclient";
1018$object = array(&$total_ht, &$total_ttc);
1019$parameters[
"mode"] = $modecompta;
1020$parameters[
"date_start"] = $date_start;
1021$parameters[
"date_end"] = $date_end;
1023$hookmanager->initHooks(array(
'externalbalance'));
1024$reshook = $hookmanager->executeHooks(
'addReportInfo', $parameters, $object, $action);
1025echo $hookmanager->resPrint;
1033echo
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
1036echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1037if ($modecompta ==
'CREANCES-DETTES') {
1038 echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1039} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1042echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1044echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1045if ($modecompta ==
'CREANCES-DETTES') {
1046 echo
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1047} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1050echo
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1052echo
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1053if ($modecompta ==
'CREANCES-DETTES') {
1054 echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht,
'MT')).
'</td>';
1055} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1058echo
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc,
'MT')).
'</td>';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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_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.
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).
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.