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';
57$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy',
'loan'));
59$date_startmonth =
GETPOSTINT(
'date_startmonth');
65$showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'yes';
68$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
69$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
71if (empty($page) || $page == -1) {
74$offset = $limit * $page;
87 $year_start = $year_current;
89 $year_current = $year;
93$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
94$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
97if (empty($date_start) || empty($date_end)) {
101 $year_end = $year_start;
105 if (!$year && $month_start > $month_current) {
110 $month_end = $month_start - 1;
111 $year_end = $year_start + 1;
113 if ($month_end < 1) {
117 $month_end = $month_start;
142$year_start = $tmps[
'year'];
144$year_end = $tmpe[
'year'];
145$nbofyear = ($year_end - $year_start) + 1;
150if (isModEnabled(
'accounting')) {
151 $modecompta =
'BOOKKEEPING';
153if (
GETPOST(
"modecompta",
'alpha')) {
154 $modecompta =
GETPOST(
"modecompta",
'alpha');
161if ($user->socid > 0) {
162 $socid = $user->socid;
166$hookmanager->initHooks([
'customersupplierreportlist']);
168if (isModEnabled(
'comptabilite')) {
171if (isModEnabled(
'accounting')) {
172 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
181$form =
new Form($db);
194if ($modecompta ==
"CREANCES-DETTES") {
195 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
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>" :
"");
198 $description = $langs->trans(
"RulesResultDue");
200 $description .= $langs->trans(
"DepositsAreNotIncluded");
202 $description .= $langs->trans(
"DepositsAreIncluded");
205 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
209} elseif ($modecompta ==
"RECETTES-DEPENSES") {
210 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
211 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
212 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] - 1).
"&modecompta=".$modecompta.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] + 1).
"&modecompta=".$modecompta.
"'>".
img_next().
"</a>" :
"");
213 $description = $langs->trans(
"RulesResultInOut");
216} elseif ($modecompta ==
"BOOKKEEPING") {
217 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
218 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
219 $arraylist = array(
'no' => $langs->trans(
"CustomerCode"),
'yes' => $langs->trans(
"AccountWithNonZeroValues"),
'all' => $langs->trans(
"All"));
220 $period .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
221 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] - 1).
"&modecompta=".$modecompta.
"&showaccountdetail=".$showaccountdetail.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($tmps[
'year'] + 1).
"&modecompta=".$modecompta.
"&showaccountdetail=".$showaccountdetail.
"'>".
img_next().
"</a>" :
"");
222 $description = $langs->trans(
"RulesResultBookkeepingPredefined");
223 $description .=
' ('.$langs->trans(
"SeePageForSetup", DOL_URL_ROOT.
'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv(
"Accountancy").
' / '.$langs->transnoentitiesnoconv(
"Setup").
' / '.$langs->transnoentitiesnoconv(
"Chartofaccounts")).
')';
230if (isModEnabled(
'accounting')) {
231 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
234$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModePayment");
235if (isModEnabled(
'accounting')) {
236 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
238$calcmode .=
'</label>';
239$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
240if (isModEnabled(
'accounting')) {
241 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
243$calcmode .=
'</label>';
246report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta' => $modecompta,
'showaccountdetail' => $showaccountdetail), $calcmode);
248if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
249 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
253$param =
'&modecompta='.urlencode($modecompta).
'&showaccountdetail='.urlencode($showaccountdetail);
255 $param .=
'&date_startday='.$date_startday;
257if ($date_startmonth) {
258 $param .=
'&date_startmonth='.$date_startmonth;
260if ($date_startyear) {
261 $param .=
'&date_startyear='.$date_startyear;
264 $param .=
'&date_endday='.$date_endday;
267 $param .=
'&date_endmonth='.$date_endmonth;
270 $param .=
'&date_endyear='.$date_endyear;
273print
'<table class="liste noborder centpercent">';
274print
'<tr class="liste_titre">';
276if ($modecompta ==
'BOOKKEEPING') {
277 print_liste_field_titre(
"PredefinedGroups", $_SERVER[
"PHP_SELF"],
'f.thirdparty_code,f.rowid',
'', $param,
'', $sortfield, $sortorder,
'');
282if ($modecompta ==
'BOOKKEEPING') {
283 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
'amount',
'', $param,
'class="right"', $sortfield, $sortorder);
285 if ($modecompta ==
'CREANCES-DETTES') {
286 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
'amount_ht',
'', $param,
'class="right"', $sortfield, $sortorder);
290 print_liste_field_titre(
"AmountTTC", $_SERVER[
"PHP_SELF"],
'amount_ttc',
'', $param,
'class="right"', $sortfield, $sortorder);
295$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
298if ($modecompta ==
'BOOKKEEPING') {
299 $predefinedgroupwhere =
"(";
300 $predefinedgroupwhere .=
" (pcg_type = 'EXPENSE')";
301 $predefinedgroupwhere .=
" OR ";
302 $predefinedgroupwhere .=
" (pcg_type = 'INCOME')";
303 $predefinedgroupwhere .=
")";
308 $sql =
"SELECT -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount";
309 if ($showaccountdetail ==
'no') {
310 $sql .=
", f.thirdparty_code as name";
312 $sql .=
" FROM ".$db->prefix().
"accounting_bookkeeping as f";
313 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_account as aa";
314 $sql .=
" ON aa.account_number = f.numero_compte";
315 $sql .=
" AND aa.entity = f.entity";
316 $sql .=
" WHERE 1=1";
317 $sql .=
" AND ".$predefinedgroupwhere;
318 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
319 $sql .=
" AND f.entity = ".$conf->entity;
320 if (!empty($date_start) && !empty($date_end)) {
321 $sql .=
" AND f.doc_date >= '".$db->idate($date_start).
"'";
322 $sql .=
" AND f.doc_date <= '".$db->idate($date_end).
"'";
324 $sql .=
" GROUP BY aa.pcg_type";
325 if ($showaccountdetail ==
'no') {
326 $sql .=
", name, socid";
328 $sql .= $db->order($sortfield, $sortorder);
332 dol_syslog(
"get bookkeeping entries", LOG_DEBUG);
333 $result = $db->query($sql);
335 $num = $db->num_rows($result);
339 $objp = $db->fetch_object($result);
341 if ($showaccountdetail ==
'no') {
342 if ($objp->pcg_type != $oldpcgtype) {
343 print
'<tr class="trforbreak"><td colspan="3" class="tdforbreak">'.dol_escape_htmltag($objp->pcg_type).
'</td></tr>';
344 $oldpcgtype = $objp->pcg_type;
348 if ($showaccountdetail ==
'no') {
349 print
'<tr class="oddeven">';
353 print($objp->name ?
' ('.dol_escape_htmltag($objp->name).
')' :
' ('.$langs->trans(
"Unknown").
')');
355 print
'<td class="right nowraponall"><span class="amount">'.price($objp->amount).
"</span></td>\n";
358 print
'<tr class="oddeven trforbreak">';
359 print
'<td colspan="2" class="tdforbreak">';
362 print
'<td class="right nowraponall tdforbreak"><span class="amount">'.price($objp->amount).
"</span></td>\n";
366 $total_ht += (isset($objp->amount) ? $objp->amount : 0);
367 $total_ttc += (isset($objp->amount) ? $objp->amount : 0);
369 if ($objp->pcg_type ==
'INCOME') {
370 $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
371 $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
373 if ($objp->pcg_type ==
'EXPENSE') {
374 $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
375 $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
380 if ($showaccountdetail !=
'no') {
381 $tmppredefinedgroupwhere =
"pcg_type = '".$db->escape($objp->pcg_type).
"'";
382 $tmppredefinedgroupwhere .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
386 $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
388 foreach ($cpts as $j => $cpt) {
389 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, (empty($cpt[
'dc']) ? 0 : $cpt[
'dc']));
394 $resultN = $AccCat->sdc;
398 if ($showaccountdetail ==
'all' || $resultN != 0) {
401 print
'<td class="tdoverflowmax200"> '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'].
'</td>';
402 print
'<td class="right nowraponall"><span class="amount">'.price($resultN).
'</span></td>';
411 print
'<tr><td colspan="3" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';
420 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
422 if ($modecompta ==
'CREANCES-DETTES') {
423 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
424 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
425 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
426 $sql .=
" WHERE f.fk_soc = s.rowid";
427 $sql .=
" AND f.fk_statut IN (1,2)";
429 $sql .=
" AND f.type IN (0,1,2,5)";
431 $sql .=
" AND f.type IN (0,1,2,3,5)";
433 if (!empty($date_start) && !empty($date_end)) {
434 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
436 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
441 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
442 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
443 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
444 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
445 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
446 $sql .=
" WHERE p.rowid = pf.fk_paiement";
447 $sql .=
" AND pf.fk_facture = f.rowid";
448 $sql .=
" AND f.fk_soc = s.rowid";
449 if (!empty($date_start) && !empty($date_end)) {
450 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
453 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
455 $sql .=
" AND f.fk_soc = ".((int) $socid);
457 $sql .=
" GROUP BY name, socid";
458 $sql .= $db->order($sortfield, $sortorder);
460 dol_syslog(
"get customer invoices", LOG_DEBUG);
461 $result = $db->query($sql);
463 $num = $db->num_rows($result);
466 $objp = $db->fetch_object($result);
468 print
'<tr class="oddeven">';
469 print
'<td> </td>';
470 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$objp->socid.
'">'.$objp->name.
"</td>\n";
472 print
'<td class="right">';
473 if ($modecompta ==
'CREANCES-DETTES') {
474 print
'<span class="amount">'.price($objp->amount_ht).
"</span>";
477 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
479 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
480 $total_ttc += $objp->amount_ttc;
490 if ($modecompta ==
'RECETTES-DEPENSES') {
491 $sql =
"SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc";
492 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
493 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
494 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
495 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
496 $sql .=
" WHERE pf.rowid IS NULL";
497 $sql .=
" AND p.fk_bank = b.rowid";
498 $sql .=
" AND b.fk_account = ba.rowid";
499 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
500 if (!empty($date_start) && !empty($date_end)) {
501 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
503 $sql .=
" GROUP BY name, idp";
504 $sql .=
" ORDER BY name";
506 dol_syslog(
"get old customer payments not linked to invoices", LOG_DEBUG);
507 $result = $db->query($sql);
509 $num = $db->num_rows($result);
513 $objp = $db->fetch_object($result);
516 print
'<tr class="oddeven">';
517 print
'<td> </td>';
518 print
"<td>".$langs->trans(
"Bills").
" ".$langs->trans(
"Other").
" (".$langs->trans(
"PaymentsNotLinkedToInvoice").
")\n";
520 print
'<td class="right">';
521 if ($modecompta ==
'CREANCES-DETTES') {
522 print
'<span class="amount">'.price($objp->amount_ht).
"</span></td>\n";
525 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
527 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
528 $total_ttc += $objp->amount_ttc;
540 if ($total_ttc == 0) {
541 print
'<tr class="oddeven">';
542 print
'<td> </td>';
543 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
547 $total_ht_income += $total_ht;
548 $total_ttc_income += $total_ttc;
550 print
'<tr class="liste_total">';
553 print
'<td class="right">';
554 if ($modecompta ==
'CREANCES-DETTES') {
555 print
price($total_ht);
558 print
'<td class="right">'.price($total_ttc).
'</td>';
565 if (isModEnabled(
'don')) {
566 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
568 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
569 if ($modecompta ==
'CREANCES-DETTES') {
570 $sql =
"SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
571 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
572 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
573 $sql .=
" AND fk_statut in (1,2)";
575 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(pe.amount) as amount";
576 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
577 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
578 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
579 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
580 $sql .=
" AND fk_statut >= 2";
582 if (!empty($date_start) && !empty($date_end)) {
583 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
586 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
587 $newsortfield = $sortfield;
588 if ($newsortfield ==
's.nom, s.rowid') {
589 $newsortfield =
'p.societe, p.firstname, p.lastname, dm';
591 if ($newsortfield ==
'amount_ht') {
592 $newsortfield =
'amount';
594 if ($newsortfield ==
'amount_ttc') {
595 $newsortfield =
'amount';
597 $sql .= $db->order($newsortfield, $sortorder);
600 $result = $db->query($sql);
604 $num = $db->num_rows($result);
608 $obj = $db->fetch_object($result);
610 $total_ht += $obj->amount;
611 $total_ttc += $obj->amount;
612 $subtotal_ht += $obj->amount;
613 $subtotal_ttc += $obj->amount;
615 print
'<tr class="oddeven">';
616 print
'<td> </td>';
618 print
"<td>".$langs->trans(
"Donation").
" <a href=\"".DOL_URL_ROOT.
"/don/list.php?search_company=".$obj->name.
"&search_name=".$obj->firstname.
" ".$obj->lastname.
"\">".$obj->name.
" ".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
620 print
'<td class="right">';
621 if ($modecompta ==
'CREANCES-DETTES') {
622 print
'<span class="amount">'.price($obj->amount).
'</span>';
625 print
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
630 print
'<tr class="oddeven"><td> </td>';
631 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
638 $total_ht_income += $subtotal_ht;
639 $total_ttc_income += $subtotal_ttc;
641 print
'<tr class="liste_total">';
644 print
'<td class="right">';
645 if ($modecompta ==
'CREANCES-DETTES') {
646 print
price($subtotal_ht);
649 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
656 if ($modecompta ==
'CREANCES-DETTES') {
657 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
658 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
659 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
660 $sql .=
" WHERE f.fk_soc = s.rowid";
661 $sql .=
" AND f.fk_statut IN (1,2)";
663 $sql .=
" AND f.type IN (0,1,2)";
665 $sql .=
" AND f.type IN (0,1,2,3)";
667 if (!empty($date_start) && !empty($date_end)) {
668 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
670 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
671 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
672 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
673 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
674 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f";
675 $sql .=
" ON pf.fk_facturefourn = f.rowid";
676 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s";
677 $sql .=
" ON f.fk_soc = s.rowid";
678 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
679 if (!empty($date_start) && !empty($date_end)) {
680 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
684 $sql .=
" AND f.entity = ".((int)
$conf->entity);
686 $sql .=
" AND f.fk_soc = ".((int) $socid);
688 $sql .=
" GROUP BY name, socid";
689 $sql .= $db->order($sortfield, $sortorder);
691 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
695 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
696 $result = $db->query($sql);
698 $num = $db->num_rows($result);
702 $objp = $db->fetch_object($result);
704 print
'<tr class="oddeven">';
705 print
'<td> </td>';
706 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
"/fourn/facture/list.php?socid=".$objp->socid.
'">'.$objp->name.
'</a></td>'.
"\n";
708 print
'<td class="right">';
709 if ($modecompta ==
'CREANCES-DETTES') {
710 print
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
713 print
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
715 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
716 $total_ttc -= $objp->amount_ttc;
717 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
718 $subtotal_ttc += $objp->amount_ttc;
724 print
'<tr class="oddeven">';
725 print
'<td> </td>';
726 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
735 $total_ht_outcome += $subtotal_ht;
736 $total_ttc_outcome += $subtotal_ttc;
738 print
'<tr class="liste_total">';
741 print
'<td class="right">';
742 if ($modecompta ==
'CREANCES-DETTES') {
743 print
price(-$subtotal_ht);
746 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
754 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsNondeductibles").
'</td></tr>';
756 if ($modecompta ==
'CREANCES-DETTES') {
757 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
758 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
759 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
760 $sql .=
" WHERE cs.fk_type = c.id";
761 $sql .=
" AND c.deductible = 0";
762 if (!empty($date_start) && !empty($date_end)) {
763 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
765 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
766 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
767 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
768 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
769 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
770 $sql .=
" WHERE p.fk_charge = cs.rowid";
771 $sql .=
" AND cs.fk_type = c.id";
772 $sql .=
" AND c.deductible = 0";
773 if (!empty($date_start) && !empty($date_end)) {
774 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
777 $sql .=
" AND cs.entity = ".$conf->entity;
778 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
779 $newsortfield = $sortfield;
780 if ($newsortfield ==
's.nom, s.rowid') {
781 $newsortfield =
'c.libelle, c.id';
783 if ($newsortfield ==
'amount_ht') {
784 $newsortfield =
'amount';
786 if ($newsortfield ==
'amount_ttc') {
787 $newsortfield =
'amount';
790 $sql .= $db->order($newsortfield, $sortorder);
792 dol_syslog(
"get social contributions deductible=0", LOG_DEBUG);
793 $result = $db->query($sql);
797 $num = $db->num_rows($result);
801 $obj = $db->fetch_object($result);
803 $total_ht -= $obj->amount;
804 $total_ttc -= $obj->amount;
805 $subtotal_ht += $obj->amount;
806 $subtotal_ttc += $obj->amount;
809 if ($obj->accountancy_code) {
810 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
812 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
813 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
816 print
'<tr class="oddeven">';
817 print
'<td> </td>';
818 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
819 print
'<td class="right">';
820 if ($modecompta ==
'CREANCES-DETTES') {
821 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
824 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
829 print
'<tr class="oddeven">';
830 print
'<td> </td>';
831 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
838 $total_ht_outcome += $subtotal_ht;
839 $total_ttc_outcome += $subtotal_ttc;
841 print
'<tr class="liste_total">';
844 print
'<td class="right">';
845 if ($modecompta ==
'CREANCES-DETTES') {
846 print
price(-$subtotal_ht);
849 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
857 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsDeductibles").
'</td></tr>';
859 if ($modecompta ==
'CREANCES-DETTES') {
860 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
861 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
862 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
863 $sql .=
" WHERE cs.fk_type = c.id";
864 $sql .=
" AND c.deductible = 1";
865 if (!empty($date_start) && !empty($date_end)) {
866 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
868 $sql .=
" AND cs.entity = ".$conf->entity;
869 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
870 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
871 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
872 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
873 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
874 $sql .=
" WHERE p.fk_charge = cs.rowid";
875 $sql .=
" AND cs.fk_type = c.id";
876 $sql .=
" AND c.deductible = 1";
877 if (!empty($date_start) && !empty($date_end)) {
878 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
880 $sql .=
" AND cs.entity = ".$conf->entity;
882 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
883 $newsortfield = $sortfield;
884 if ($newsortfield ==
's.nom, s.rowid') {
885 $newsortfield =
'c.libelle, c.id';
887 if ($newsortfield ==
'amount_ht') {
888 $newsortfield =
'amount';
890 if ($newsortfield ==
'amount_ttc') {
891 $newsortfield =
'amount';
893 $sql .= $db->order($newsortfield, $sortorder);
895 dol_syslog(
"get social contributions deductible=1", LOG_DEBUG);
896 $result = $db->query($sql);
900 $num = $db->num_rows($result);
904 $obj = $db->fetch_object($result);
906 $total_ht -= $obj->amount;
907 $total_ttc -= $obj->amount;
908 $subtotal_ht += $obj->amount;
909 $subtotal_ttc += $obj->amount;
912 if ($obj->accountancy_code) {
913 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
915 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
916 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
919 print
'<tr class="oddeven">';
920 print
'<td> </td>';
921 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
922 print
'<td class="right">';
923 if ($modecompta ==
'CREANCES-DETTES') {
924 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
927 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
932 print
'<tr class="oddeven">';
933 print
'<td> </td>';
934 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
941 $total_ht_outcome += $subtotal_ht;
942 $total_ttc_outcome += $subtotal_ttc;
944 print
'<tr class="liste_total">';
947 print
'<td class="right">';
948 if ($modecompta ==
'CREANCES-DETTES') {
949 print
price(-$subtotal_ht);
952 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
960 if (isModEnabled(
'salaries')) {
961 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
963 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
964 if ($modecompta ==
'CREANCES-DETTES') {
965 $column =
's.dateep';
967 $sql =
"SELECT u.rowid, u.firstname, u.lastname, s.fk_user as fk_user, s.label as label, date_format($column,'%Y-%m') as dm, sum(s.amount) as amount";
968 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
969 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
970 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
971 if (!empty($date_start) && !empty($date_end)) {
972 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
974 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, s.label, dm";
978 $sql =
"SELECT u.rowid, u.firstname, u.lastname, s.fk_user as fk_user, p.label as label, date_format($column,'%Y-%m') as dm, sum(p.amount) as amount";
979 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
980 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = p.fk_salary";
981 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
982 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
983 if (!empty($date_start) && !empty($date_end)) {
984 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
986 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, p.label, dm";
989 $newsortfield = $sortfield;
990 if ($newsortfield ==
's.nom, s.rowid') {
991 $newsortfield =
'u.firstname, u.lastname';
993 if ($newsortfield ==
'amount_ht') {
994 $newsortfield =
'amount';
996 if ($newsortfield ==
'amount_ttc') {
997 $newsortfield =
'amount';
999 $sql .= $db->order($newsortfield, $sortorder);
1003 $result = $db->query($sql);
1007 $num = $db->num_rows($result);
1011 $obj = $db->fetch_object($result);
1013 $total_ht -= $obj->amount;
1014 $total_ttc -= $obj->amount;
1015 $subtotal_ht += $obj->amount;
1016 $subtotal_ttc += $obj->amount;
1018 print
'<tr class="oddeven"><td> </td>';
1020 $userstatic =
new User($db);
1021 $userstatic->fetch($obj->fk_user);
1023 print
"<td>".$langs->trans(
"Salary").
" <a href=\"".DOL_URL_ROOT.
"/salaries/list.php?search_user=".urlencode($userstatic->getFullName($langs)).
"\">".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
1024 print
'<td class="right">';
1025 if ($modecompta ==
'CREANCES-DETTES') {
1026 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1029 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1034 print
'<tr class="oddeven">';
1035 print
'<td> </td>';
1036 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1043 $total_ht_outcome += $subtotal_ht;
1044 $total_ttc_outcome += $subtotal_ttc;
1046 print
'<tr class="liste_total">';
1049 print
'<td class="right">';
1050 if ($modecompta ==
'CREANCES-DETTES') {
1051 print
price(-$subtotal_ht);
1054 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1063 if (isModEnabled(
'expensereport')) {
1064 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
1065 $langs->load(
'trips');
1066 if ($modecompta ==
'CREANCES-DETTES') {
1067 $sql =
"SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(date_valid,'%Y-%m') as dm, p.total_ht as amount_ht, p.total_ttc as amount_ttc";
1068 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1069 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1070 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1071 $sql .=
" AND p.fk_statut>=5";
1073 $column =
'p.date_valid';
1075 $sql =
"SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(pe.amount) as amount_ht, sum(pe.amount) as amount_ttc";
1076 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1077 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1078 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
1079 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
1080 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1081 $sql .=
" AND p.fk_statut>=5";
1083 $column =
'pe.datep';
1086 if (!empty($date_start) && !empty($date_end)) {
1087 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
1090 if ($modecompta ==
'CREANCES-DETTES') {
1093 $sql .=
" GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
1095 $newsortfield = $sortfield;
1096 if ($newsortfield ==
's.nom, s.rowid') {
1097 $newsortfield =
'p.ref';
1099 $sql .= $db->order($newsortfield, $sortorder);
1102 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
1105 $result = $db->query($sql);
1109 $num = $db->num_rows($result);
1111 while ($obj = $db->fetch_object($result)) {
1112 $total_ht -= $obj->amount_ht;
1113 $total_ttc -= $obj->amount_ttc;
1114 $subtotal_ht += $obj->amount_ht;
1115 $subtotal_ttc += $obj->amount_ttc;
1117 print
'<tr class="oddeven">';
1118 print
'<td> </td>';
1119 print
"<td>".$langs->trans(
"ExpenseReport").
" <a href=\"".DOL_URL_ROOT.
"/expensereport/list.php?search_user=".$obj->userid.
"\">".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
1120 print
'<td class="right">';
1121 if ($modecompta ==
'CREANCES-DETTES') {
1122 print
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
1125 print
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
1129 print
'<tr class="oddeven">';
1130 print
'<td> </td>';
1131 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1138 $total_ht_outcome += $subtotal_ht;
1139 $total_ttc_outcome += $subtotal_ttc;
1141 print
'<tr class="liste_total">';
1144 print
'<td class="right">';
1145 if ($modecompta ==
'CREANCES-DETTES') {
1146 print
price(-$subtotal_ht);
1149 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1159 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled(
"bank") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1163 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
1166 $sql =
"SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
1167 $sql .=
' WHERE 1 = 1';
1168 if (!empty($date_start) && !empty($date_end)) {
1169 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1171 $sql .=
' GROUP BY p.sens';
1172 $sql .=
' ORDER BY p.sens';
1174 dol_syslog(
'get various payments', LOG_DEBUG);
1175 $result = $db->query($sql);
1178 $obj = $db->fetch_object($result);
1179 if (isset($obj->amount)) {
1180 $subtotal_ht += -$obj->amount;
1181 $subtotal_ttc += -$obj->amount;
1183 $total_ht_outcome += $obj->amount;
1184 $total_ttc_outcome += $obj->amount;
1186 print
'<tr class="oddeven">';
1187 print
'<td> </td>';
1188 print
"<td>".$langs->trans(
"AccountingDebit").
"</td>\n";
1189 print
'<td class="right">';
1190 if ($modecompta ==
'CREANCES-DETTES') {
1191 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1194 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1198 $obj = $db->fetch_object($result);
1199 if (isset($obj->amount)) {
1200 $subtotal_ht += $obj->amount;
1201 $subtotal_ttc += $obj->amount;
1203 $total_ht_income += $obj->amount;
1204 $total_ttc_income += $obj->amount;
1206 print
'<tr class="oddeven"><td> </td>';
1207 print
"<td>".$langs->trans(
"AccountingCredit").
"</td>\n";
1208 print
'<td class="right">';
1209 if ($modecompta ==
'CREANCES-DETTES') {
1210 print
'<span class="amount">'.price($obj->amount).
'</span>';
1213 print
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
1217 $total_ht += $subtotal_ht;
1218 $total_ttc += $subtotal_ttc;
1219 print
'<tr class="liste_total">';
1222 print
'<td class="right">';
1223 if ($modecompta ==
'CREANCES-DETTES') {
1224 print
price($subtotal_ht);
1227 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1238 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1242 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
1244 $sql =
'SELECT l.rowid as id, l.label AS label, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) as amount FROM '.MAIN_DB_PREFIX.
'payment_loan as p';
1245 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
1246 $sql .=
' WHERE 1 = 1';
1247 if (!empty($date_start) && !empty($date_end)) {
1248 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1250 $sql .=
' GROUP BY p.fk_loan';
1251 $sql .=
' ORDER BY p.fk_loan';
1254 $result = $db->query($sql);
1256 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
1257 $loan_static =
new Loan($db);
1258 while ($obj = $db->fetch_object($result)) {
1259 $loan_static->id = $obj->id;
1260 $loan_static->ref = $obj->id;
1261 $loan_static->label = $obj->label;
1262 print
'<tr class="oddeven"><td> </td>';
1263 print
"<td>".$loan_static->getNomUrl(1).
' - '.$obj->label.
"</td>\n";
1264 if ($modecompta ==
'CREANCES-DETTES') {
1265 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1267 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1269 $subtotal_ht -= $obj->amount;
1270 $subtotal_ttc -= $obj->amount;
1272 $total_ht += $subtotal_ht;
1273 $total_ttc += $subtotal_ttc;
1275 $total_ht_income += $subtotal_ht;
1276 $total_ttc_income += $subtotal_ttc;
1278 print
'<tr class="liste_total">';
1281 print
'<td class="right">';
1282 if ($modecompta ==
'CREANCES-DETTES') {
1283 print
price($subtotal_ht);
1286 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1297 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VAT").
'</td></tr>';
1301 if (isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES')) {
1302 if ($modecompta ==
'CREANCES-DETTES') {
1305 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1306 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1307 $sql .=
" WHERE f.fk_statut IN (1,2)";
1309 $sql .=
" AND f.type IN (0,1,2,5)";
1311 $sql .=
" AND f.type IN (0,1,2,3,5)";
1313 if (!empty($date_start) && !empty($date_end)) {
1314 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1316 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
1317 $sql .=
" GROUP BY dm";
1318 $newsortfield = $sortfield;
1319 if ($newsortfield ==
's.nom, s.rowid') {
1320 $newsortfield =
'dm';
1322 if ($newsortfield ==
'amount_ht') {
1323 $newsortfield =
'amount';
1325 if ($newsortfield ==
'amount_ttc') {
1326 $newsortfield =
'amount';
1328 $sql .= $db->order($newsortfield, $sortorder);
1331 $result = $db->query($sql);
1333 $num = $db->num_rows($result);
1337 $obj = $db->fetch_object($result);
1339 $amount -= $obj->amount;
1341 $total_ttc -= $obj->amount;
1343 $subtotal_ttc -= $obj->amount;
1351 $total_ht_outcome -= 0;
1352 $total_ttc_outcome -= $amount;
1354 print
'<tr class="oddeven">';
1355 print
'<td> </td>';
1356 print
"<td>".$langs->trans(
"VATToPay").
"</td>\n";
1357 print
'<td class="right"> </td>'.
"\n";
1358 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1363 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1364 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1365 $sql .=
" WHERE f.fk_statut IN (1,2)";
1367 $sql .=
" AND f.type IN (0,1,2)";
1369 $sql .=
" AND f.type IN (0,1,2,3)";
1371 if (!empty($date_start) && !empty($date_end)) {
1372 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1374 $sql .=
" AND f.entity = ".$conf->entity;
1375 $sql .=
" GROUP BY dm";
1376 $newsortfield = $sortfield;
1377 if ($newsortfield ==
's.nom, s.rowid') {
1378 $newsortfield =
'dm';
1380 if ($newsortfield ==
'amount_ht') {
1381 $newsortfield =
'amount';
1383 if ($newsortfield ==
'amount_ttc') {
1384 $newsortfield =
'amount';
1386 $sql .= $db->order($newsortfield, $sortorder);
1388 dol_syslog(
"get vat received back", LOG_DEBUG);
1389 $result = $db->query($sql);
1391 $num = $db->num_rows($result);
1395 $obj = $db->fetch_object($result);
1397 $amount += $obj->amount;
1399 $total_ttc += $obj->amount;
1401 $subtotal_ttc += $obj->amount;
1410 $total_ht_income += 0;
1411 $total_ttc_income += $amount;
1413 print
'<tr class="oddeven">';
1414 print
'<td> </td>';
1415 print
'<td>'.$langs->trans(
"VATToCollect").
"</td>\n";
1416 print
'<td class="right"> </td>'.
"\n";
1417 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1422 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1423 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1424 $sql .=
" WHERE amount > 0";
1425 if (!empty($date_start) && !empty($date_end)) {
1426 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1428 $sql .=
" AND t.entity = ".$conf->entity;
1429 $sql .=
" GROUP BY dm";
1430 $newsortfield = $sortfield;
1431 if ($newsortfield ==
's.nom, s.rowid') {
1432 $newsortfield =
'dm';
1434 if ($newsortfield ==
'amount_ht') {
1435 $newsortfield =
'amount';
1437 if ($newsortfield ==
'amount_ttc') {
1438 $newsortfield =
'amount';
1440 $sql .= $db->order($newsortfield, $sortorder);
1442 dol_syslog(
"get vat really paid", LOG_DEBUG);
1443 $result = $db->query($sql);
1445 $num = $db->num_rows($result);
1449 $obj = $db->fetch_object($result);
1451 $amount -= $obj->amount;
1452 $total_ht -= $obj->amount;
1453 $total_ttc -= $obj->amount;
1454 $subtotal_ht -= $obj->amount;
1455 $subtotal_ttc -= $obj->amount;
1465 $total_ht_outcome -= 0;
1466 $total_ttc_outcome -= $amount;
1468 print
'<tr class="oddeven">';
1469 print
'<td> </td>';
1470 print
"<td>".$langs->trans(
"VATPaid").
"</td>\n";
1471 print
'<td <class="right"></td>'.
"\n";
1472 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1477 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1478 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1479 $sql .=
" WHERE amount < 0";
1480 if (!empty($date_start) && !empty($date_end)) {
1481 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1483 $sql .=
" AND t.entity = ".$conf->entity;
1484 $sql .=
" GROUP BY dm";
1485 $newsortfield = $sortfield;
1486 if ($newsortfield ==
's.nom, s.rowid') {
1487 $newsortfield =
'dm';
1489 if ($newsortfield ==
'amount_ht') {
1490 $newsortfield =
'amount';
1492 if ($newsortfield ==
'amount_ttc') {
1493 $newsortfield =
'amount';
1495 $sql .= $db->order($newsortfield, $sortorder);
1497 dol_syslog(
"get vat really received back", LOG_DEBUG);
1498 $result = $db->query($sql);
1500 $num = $db->num_rows($result);
1504 $obj = $db->fetch_object($result);
1506 $amount += -$obj->amount;
1507 $total_ht += -$obj->amount;
1508 $total_ttc += -$obj->amount;
1509 $subtotal_ht += -$obj->amount;
1510 $subtotal_ttc += -$obj->amount;
1520 $total_ht_income += 0;
1521 $total_ttc_income += $amount;
1523 print
'<tr class="oddeven">';
1524 print
'<td> </td>';
1525 print
"<td>".$langs->trans(
"VATCollected").
"</td>\n";
1526 print
'<td class="right"></td>'.
"\n";
1527 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1532 if ($mysoc->tva_assuj !=
'0') {
1533 print
'<tr class="liste_total">';
1536 print
'<td class="right"> </td>';
1537 print
'<td class="right">'.price(
price2num($subtotal_ttc,
'MT')).
'</td>';
1542$action =
"balanceclient";
1543$object = array(&$total_ht, &$total_ttc);
1544$parameters[
"mode"] = $modecompta;
1545$parameters[
"date_start"] = $date_start;
1546$parameters[
"date_end"] = $date_end;
1548$hookmanager->initHooks(array(
'externalbalance'));
1549$reshook = $hookmanager->executeHooks(
'addBalanceLine', $parameters, $object, $action);
1550print $hookmanager->resPrint;
1556print
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
1559print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1560if ($modecompta ==
'CREANCES-DETTES') {
1561 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1562} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1565print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1567print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1568if ($modecompta ==
'CREANCES-DETTES') {
1569 print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1570} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1573print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1575print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1576if ($modecompta ==
'CREANCES-DETTES') {
1577 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht,
'MT')).
'</td>';
1578} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1581print
'<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.
Class to manage accounting accounts.
Class to manage Dolibarr users.
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.