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 ".MAIN_DB_PREFIX.
"accounting_bookkeeping as f";
313 $sql .=
", ".MAIN_DB_PREFIX.
"accounting_account as aa";
314 $sql .=
" WHERE f.numero_compte = aa.account_number";
315 $sql .=
" AND ".$predefinedgroupwhere;
316 $sql .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
317 $sql .=
" AND f.entity = ".$conf->entity;
318 if (!empty($date_start) && !empty($date_end)) {
319 $sql .=
" AND f.doc_date >= '".$db->idate($date_start).
"' AND f.doc_date <= '".$db->idate($date_end).
"'";
321 $sql .=
" GROUP BY pcg_type";
322 if ($showaccountdetail ==
'no') {
323 $sql .=
", name, socid";
325 $sql .= $db->order($sortfield, $sortorder);
329 dol_syslog(
"get bookkeeping entries", LOG_DEBUG);
330 $result = $db->query($sql);
332 $num = $db->num_rows($result);
336 $objp = $db->fetch_object($result);
338 if ($showaccountdetail ==
'no') {
339 if ($objp->pcg_type != $oldpcgtype) {
340 print
'<tr class="trforbreak"><td colspan="3" class="tdforbreak">'.dol_escape_htmltag($objp->pcg_type).
'</td></tr>';
341 $oldpcgtype = $objp->pcg_type;
345 if ($showaccountdetail ==
'no') {
346 print
'<tr class="oddeven">';
350 print($objp->name ?
' ('.dol_escape_htmltag($objp->name).
')' :
' ('.$langs->trans(
"Unknown").
')');
352 print
'<td class="right nowraponall"><span class="amount">'.price($objp->amount).
"</span></td>\n";
355 print
'<tr class="oddeven trforbreak">';
356 print
'<td colspan="2" class="tdforbreak">';
359 print
'<td class="right nowraponall tdforbreak"><span class="amount">'.price($objp->amount).
"</span></td>\n";
363 $total_ht += (isset($objp->amount) ? $objp->amount : 0);
364 $total_ttc += (isset($objp->amount) ? $objp->amount : 0);
366 if ($objp->pcg_type ==
'INCOME') {
367 $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
368 $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
370 if ($objp->pcg_type ==
'EXPENSE') {
371 $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
372 $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
377 if ($showaccountdetail !=
'no') {
378 $tmppredefinedgroupwhere =
"pcg_type = '".$db->escape($objp->pcg_type).
"'";
379 $tmppredefinedgroupwhere .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
383 $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
385 foreach ($cpts as $j => $cpt) {
386 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, (empty($cpt[
'dc']) ? 0 : $cpt[
'dc']));
391 $resultN = $AccCat->sdc;
395 if ($showaccountdetail ==
'all' || $resultN != 0) {
398 print
'<td class="tdoverflowmax200"> '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'].
'</td>';
399 print
'<td class="right nowraponall"><span class="amount">'.price($resultN).
'</span></td>';
408 print
'<tr><td colspan="3" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';
417 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
419 if ($modecompta ==
'CREANCES-DETTES') {
420 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
421 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
422 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
423 $sql .=
" WHERE f.fk_soc = s.rowid";
424 $sql .=
" AND f.fk_statut IN (1,2)";
426 $sql .=
" AND f.type IN (0,1,2,5)";
428 $sql .=
" AND f.type IN (0,1,2,3,5)";
430 if (!empty($date_start) && !empty($date_end)) {
431 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
433 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
438 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
439 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
440 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
441 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
442 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
443 $sql .=
" WHERE p.rowid = pf.fk_paiement";
444 $sql .=
" AND pf.fk_facture = f.rowid";
445 $sql .=
" AND f.fk_soc = s.rowid";
446 if (!empty($date_start) && !empty($date_end)) {
447 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
450 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
452 $sql .=
" AND f.fk_soc = ".((int) $socid);
454 $sql .=
" GROUP BY name, socid";
455 $sql .= $db->order($sortfield, $sortorder);
457 dol_syslog(
"get customer invoices", LOG_DEBUG);
458 $result = $db->query($sql);
460 $num = $db->num_rows($result);
463 $objp = $db->fetch_object($result);
465 print
'<tr class="oddeven">';
466 print
'<td> </td>';
467 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$objp->socid.
'">'.$objp->name.
"</td>\n";
469 print
'<td class="right">';
470 if ($modecompta ==
'CREANCES-DETTES') {
471 print
'<span class="amount">'.price($objp->amount_ht).
"</span>";
474 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
476 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
477 $total_ttc += $objp->amount_ttc;
487 if ($modecompta ==
'RECETTES-DEPENSES') {
488 $sql =
"SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc";
489 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
490 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
491 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
492 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
493 $sql .=
" WHERE pf.rowid IS NULL";
494 $sql .=
" AND p.fk_bank = b.rowid";
495 $sql .=
" AND b.fk_account = ba.rowid";
496 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
497 if (!empty($date_start) && !empty($date_end)) {
498 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
500 $sql .=
" GROUP BY name, idp";
501 $sql .=
" ORDER BY name";
503 dol_syslog(
"get old customer payments not linked to invoices", LOG_DEBUG);
504 $result = $db->query($sql);
506 $num = $db->num_rows($result);
510 $objp = $db->fetch_object($result);
513 print
'<tr class="oddeven">';
514 print
'<td> </td>';
515 print
"<td>".$langs->trans(
"Bills").
" ".$langs->trans(
"Other").
" (".$langs->trans(
"PaymentsNotLinkedToInvoice").
")\n";
517 print
'<td class="right">';
518 if ($modecompta ==
'CREANCES-DETTES') {
519 print
'<span class="amount">'.price($objp->amount_ht).
"</span></td>\n";
522 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
524 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
525 $total_ttc += $objp->amount_ttc;
537 if ($total_ttc == 0) {
538 print
'<tr class="oddeven">';
539 print
'<td> </td>';
540 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
544 $total_ht_income += $total_ht;
545 $total_ttc_income += $total_ttc;
547 print
'<tr class="liste_total">';
550 print
'<td class="right">';
551 if ($modecompta ==
'CREANCES-DETTES') {
552 print
price($total_ht);
555 print
'<td class="right">'.price($total_ttc).
'</td>';
562 if (isModEnabled(
'don')) {
563 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
565 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
566 if ($modecompta ==
'CREANCES-DETTES') {
567 $sql =
"SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
568 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
569 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
570 $sql .=
" AND fk_statut in (1,2)";
572 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
573 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
574 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
575 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
576 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
577 $sql .=
" AND fk_statut >= 2";
579 if (!empty($date_start) && !empty($date_end)) {
580 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
583 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
584 $newsortfield = $sortfield;
585 if ($newsortfield ==
's.nom, s.rowid') {
586 $newsortfield =
'p.societe, p.firstname, p.lastname, dm';
588 if ($newsortfield ==
'amount_ht') {
589 $newsortfield =
'amount';
591 if ($newsortfield ==
'amount_ttc') {
592 $newsortfield =
'amount';
594 $sql .= $db->order($newsortfield, $sortorder);
597 $result = $db->query($sql);
601 $num = $db->num_rows($result);
605 $obj = $db->fetch_object($result);
607 $total_ht += $obj->amount;
608 $total_ttc += $obj->amount;
609 $subtotal_ht += $obj->amount;
610 $subtotal_ttc += $obj->amount;
612 print
'<tr class="oddeven">';
613 print
'<td> </td>';
615 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";
617 print
'<td class="right">';
618 if ($modecompta ==
'CREANCES-DETTES') {
619 print
'<span class="amount">'.price($obj->amount).
'</span>';
622 print
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
627 print
'<tr class="oddeven"><td> </td>';
628 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
635 $total_ht_income += $subtotal_ht;
636 $total_ttc_income += $subtotal_ttc;
638 print
'<tr class="liste_total">';
641 print
'<td class="right">';
642 if ($modecompta ==
'CREANCES-DETTES') {
643 print
price($subtotal_ht);
646 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
653 if ($modecompta ==
'CREANCES-DETTES') {
654 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
655 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
656 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
657 $sql .=
" WHERE f.fk_soc = s.rowid";
658 $sql .=
" AND f.fk_statut IN (1,2)";
660 $sql .=
" AND f.type IN (0,1,2)";
662 $sql .=
" AND f.type IN (0,1,2,3)";
664 if (!empty($date_start) && !empty($date_end)) {
665 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
667 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
668 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
669 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
670 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
671 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f";
672 $sql .=
" ON pf.fk_facturefourn = f.rowid";
673 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s";
674 $sql .=
" ON f.fk_soc = s.rowid";
675 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
676 if (!empty($date_start) && !empty($date_end)) {
677 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
681 $sql .=
" AND f.entity = ".((int)
$conf->entity);
683 $sql .=
" AND f.fk_soc = ".((int) $socid);
685 $sql .=
" GROUP BY name, socid";
686 $sql .= $db->order($sortfield, $sortorder);
688 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
692 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
693 $result = $db->query($sql);
695 $num = $db->num_rows($result);
699 $objp = $db->fetch_object($result);
701 print
'<tr class="oddeven">';
702 print
'<td> </td>';
703 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
"/fourn/facture/list.php?socid=".$objp->socid.
'">'.$objp->name.
'</a></td>'.
"\n";
705 print
'<td class="right">';
706 if ($modecompta ==
'CREANCES-DETTES') {
707 print
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
710 print
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
712 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
713 $total_ttc -= $objp->amount_ttc;
714 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
715 $subtotal_ttc += $objp->amount_ttc;
721 print
'<tr class="oddeven">';
722 print
'<td> </td>';
723 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
732 $total_ht_outcome += $subtotal_ht;
733 $total_ttc_outcome += $subtotal_ttc;
735 print
'<tr class="liste_total">';
738 print
'<td class="right">';
739 if ($modecompta ==
'CREANCES-DETTES') {
740 print
price(-$subtotal_ht);
743 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
751 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsNondeductibles").
'</td></tr>';
753 if ($modecompta ==
'CREANCES-DETTES') {
754 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
755 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
756 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
757 $sql .=
" WHERE cs.fk_type = c.id";
758 $sql .=
" AND c.deductible = 0";
759 if (!empty($date_start) && !empty($date_end)) {
760 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
762 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
763 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
764 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
765 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
766 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
767 $sql .=
" WHERE p.fk_charge = cs.rowid";
768 $sql .=
" AND cs.fk_type = c.id";
769 $sql .=
" AND c.deductible = 0";
770 if (!empty($date_start) && !empty($date_end)) {
771 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
774 $sql .=
" AND cs.entity = ".$conf->entity;
775 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
776 $newsortfield = $sortfield;
777 if ($newsortfield ==
's.nom, s.rowid') {
778 $newsortfield =
'c.libelle, c.id';
780 if ($newsortfield ==
'amount_ht') {
781 $newsortfield =
'amount';
783 if ($newsortfield ==
'amount_ttc') {
784 $newsortfield =
'amount';
787 $sql .= $db->order($newsortfield, $sortorder);
789 dol_syslog(
"get social contributions deductible=0", LOG_DEBUG);
790 $result = $db->query($sql);
794 $num = $db->num_rows($result);
798 $obj = $db->fetch_object($result);
800 $total_ht -= $obj->amount;
801 $total_ttc -= $obj->amount;
802 $subtotal_ht += $obj->amount;
803 $subtotal_ttc += $obj->amount;
806 if ($obj->accountancy_code) {
807 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
809 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
810 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
813 print
'<tr class="oddeven">';
814 print
'<td> </td>';
815 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
816 print
'<td class="right">';
817 if ($modecompta ==
'CREANCES-DETTES') {
818 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
821 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
826 print
'<tr class="oddeven">';
827 print
'<td> </td>';
828 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
835 $total_ht_outcome += $subtotal_ht;
836 $total_ttc_outcome += $subtotal_ttc;
838 print
'<tr class="liste_total">';
841 print
'<td class="right">';
842 if ($modecompta ==
'CREANCES-DETTES') {
843 print
price(-$subtotal_ht);
846 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
854 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsDeductibles").
'</td></tr>';
856 if ($modecompta ==
'CREANCES-DETTES') {
857 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
858 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
859 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
860 $sql .=
" WHERE cs.fk_type = c.id";
861 $sql .=
" AND c.deductible = 1";
862 if (!empty($date_start) && !empty($date_end)) {
863 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
865 $sql .=
" AND cs.entity = ".$conf->entity;
866 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
867 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
868 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
869 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
870 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
871 $sql .=
" WHERE p.fk_charge = cs.rowid";
872 $sql .=
" AND cs.fk_type = c.id";
873 $sql .=
" AND c.deductible = 1";
874 if (!empty($date_start) && !empty($date_end)) {
875 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
877 $sql .=
" AND cs.entity = ".$conf->entity;
879 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
880 $newsortfield = $sortfield;
881 if ($newsortfield ==
's.nom, s.rowid') {
882 $newsortfield =
'c.libelle, c.id';
884 if ($newsortfield ==
'amount_ht') {
885 $newsortfield =
'amount';
887 if ($newsortfield ==
'amount_ttc') {
888 $newsortfield =
'amount';
890 $sql .= $db->order($newsortfield, $sortorder);
892 dol_syslog(
"get social contributions deductible=1", LOG_DEBUG);
893 $result = $db->query($sql);
897 $num = $db->num_rows($result);
901 $obj = $db->fetch_object($result);
903 $total_ht -= $obj->amount;
904 $total_ttc -= $obj->amount;
905 $subtotal_ht += $obj->amount;
906 $subtotal_ttc += $obj->amount;
909 if ($obj->accountancy_code) {
910 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
912 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
913 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
916 print
'<tr class="oddeven">';
917 print
'<td> </td>';
918 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
919 print
'<td class="right">';
920 if ($modecompta ==
'CREANCES-DETTES') {
921 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
924 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
929 print
'<tr class="oddeven">';
930 print
'<td> </td>';
931 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
938 $total_ht_outcome += $subtotal_ht;
939 $total_ttc_outcome += $subtotal_ttc;
941 print
'<tr class="liste_total">';
944 print
'<td class="right">';
945 if ($modecompta ==
'CREANCES-DETTES') {
946 print
price(-$subtotal_ht);
949 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
957 if (isModEnabled(
'salaries')) {
958 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
960 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
961 if ($modecompta ==
'CREANCES-DETTES') {
962 $column =
's.dateep';
964 $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";
965 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
966 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
967 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
968 if (!empty($date_start) && !empty($date_end)) {
969 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
971 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, s.label, dm";
975 $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";
976 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
977 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = p.fk_salary";
978 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
979 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
980 if (!empty($date_start) && !empty($date_end)) {
981 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
983 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, p.label, dm";
986 $newsortfield = $sortfield;
987 if ($newsortfield ==
's.nom, s.rowid') {
988 $newsortfield =
'u.firstname, u.lastname';
990 if ($newsortfield ==
'amount_ht') {
991 $newsortfield =
'amount';
993 if ($newsortfield ==
'amount_ttc') {
994 $newsortfield =
'amount';
996 $sql .= $db->order($newsortfield, $sortorder);
1000 $result = $db->query($sql);
1004 $num = $db->num_rows($result);
1008 $obj = $db->fetch_object($result);
1010 $total_ht -= $obj->amount;
1011 $total_ttc -= $obj->amount;
1012 $subtotal_ht += $obj->amount;
1013 $subtotal_ttc += $obj->amount;
1015 print
'<tr class="oddeven"><td> </td>';
1017 $userstatic =
new User($db);
1018 $userstatic->fetch($obj->fk_user);
1020 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";
1021 print
'<td class="right">';
1022 if ($modecompta ==
'CREANCES-DETTES') {
1023 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1026 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1031 print
'<tr class="oddeven">';
1032 print
'<td> </td>';
1033 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1040 $total_ht_outcome += $subtotal_ht;
1041 $total_ttc_outcome += $subtotal_ttc;
1043 print
'<tr class="liste_total">';
1046 print
'<td class="right">';
1047 if ($modecompta ==
'CREANCES-DETTES') {
1048 print
price(-$subtotal_ht);
1051 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1060 if (isModEnabled(
'expensereport')) {
1061 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
1062 $langs->load(
'trips');
1063 if ($modecompta ==
'CREANCES-DETTES') {
1064 $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";
1065 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1066 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1067 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1068 $sql .=
" AND p.fk_statut>=5";
1070 $column =
'p.date_valid';
1072 $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";
1073 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1074 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1075 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
1076 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
1077 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1078 $sql .=
" AND p.fk_statut>=5";
1080 $column =
'pe.datep';
1083 if (!empty($date_start) && !empty($date_end)) {
1084 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
1087 if ($modecompta ==
'CREANCES-DETTES') {
1090 $sql .=
" GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
1092 $newsortfield = $sortfield;
1093 if ($newsortfield ==
's.nom, s.rowid') {
1094 $newsortfield =
'p.ref';
1096 $sql .= $db->order($newsortfield, $sortorder);
1099 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
1102 $result = $db->query($sql);
1106 $num = $db->num_rows($result);
1108 while ($obj = $db->fetch_object($result)) {
1109 $total_ht -= $obj->amount_ht;
1110 $total_ttc -= $obj->amount_ttc;
1111 $subtotal_ht += $obj->amount_ht;
1112 $subtotal_ttc += $obj->amount_ttc;
1114 print
'<tr class="oddeven">';
1115 print
'<td> </td>';
1116 print
"<td>".$langs->trans(
"ExpenseReport").
" <a href=\"".DOL_URL_ROOT.
"/expensereport/list.php?search_user=".$obj->userid.
"\">".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
1117 print
'<td class="right">';
1118 if ($modecompta ==
'CREANCES-DETTES') {
1119 print
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
1122 print
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
1126 print
'<tr class="oddeven">';
1127 print
'<td> </td>';
1128 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1135 $total_ht_outcome += $subtotal_ht;
1136 $total_ttc_outcome += $subtotal_ttc;
1138 print
'<tr class="liste_total">';
1141 print
'<td class="right">';
1142 if ($modecompta ==
'CREANCES-DETTES') {
1143 print
price(-$subtotal_ht);
1146 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1156 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled(
"bank") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1160 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
1163 $sql =
"SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
1164 $sql .=
' WHERE 1 = 1';
1165 if (!empty($date_start) && !empty($date_end)) {
1166 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1168 $sql .=
' GROUP BY p.sens';
1169 $sql .=
' ORDER BY p.sens';
1171 dol_syslog(
'get various payments', LOG_DEBUG);
1172 $result = $db->query($sql);
1175 $obj = $db->fetch_object($result);
1176 if (isset($obj->amount)) {
1177 $subtotal_ht += -$obj->amount;
1178 $subtotal_ttc += -$obj->amount;
1180 $total_ht_outcome += $obj->amount;
1181 $total_ttc_outcome += $obj->amount;
1183 print
'<tr class="oddeven">';
1184 print
'<td> </td>';
1185 print
"<td>".$langs->trans(
"AccountingDebit").
"</td>\n";
1186 print
'<td class="right">';
1187 if ($modecompta ==
'CREANCES-DETTES') {
1188 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1191 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1195 $obj = $db->fetch_object($result);
1196 if (isset($obj->amount)) {
1197 $subtotal_ht += $obj->amount;
1198 $subtotal_ttc += $obj->amount;
1200 $total_ht_income += $obj->amount;
1201 $total_ttc_income += $obj->amount;
1203 print
'<tr class="oddeven"><td> </td>';
1204 print
"<td>".$langs->trans(
"AccountingCredit").
"</td>\n";
1205 print
'<td class="right">';
1206 if ($modecompta ==
'CREANCES-DETTES') {
1207 print
'<span class="amount">'.price($obj->amount).
'</span>';
1210 print
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
1214 $total_ht += $subtotal_ht;
1215 $total_ttc += $subtotal_ttc;
1216 print
'<tr class="liste_total">';
1219 print
'<td class="right">';
1220 if ($modecompta ==
'CREANCES-DETTES') {
1221 print
price($subtotal_ht);
1224 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1235 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1239 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
1241 $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';
1242 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
1243 $sql .=
' WHERE 1 = 1';
1244 if (!empty($date_start) && !empty($date_end)) {
1245 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1247 $sql .=
' GROUP BY p.fk_loan';
1248 $sql .=
' ORDER BY p.fk_loan';
1251 $result = $db->query($sql);
1253 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
1254 $loan_static =
new Loan($db);
1255 while ($obj = $db->fetch_object($result)) {
1256 $loan_static->id = $obj->id;
1257 $loan_static->ref = $obj->id;
1258 $loan_static->label = $obj->label;
1259 print
'<tr class="oddeven"><td> </td>';
1260 print
"<td>".$loan_static->getNomUrl(1).
' - '.$obj->label.
"</td>\n";
1261 if ($modecompta ==
'CREANCES-DETTES') {
1262 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1264 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1266 $subtotal_ht -= $obj->amount;
1267 $subtotal_ttc -= $obj->amount;
1269 $total_ht += $subtotal_ht;
1270 $total_ttc += $subtotal_ttc;
1272 $total_ht_income += $subtotal_ht;
1273 $total_ttc_income += $subtotal_ttc;
1275 print
'<tr class="liste_total">';
1278 print
'<td class="right">';
1279 if ($modecompta ==
'CREANCES-DETTES') {
1280 print
price($subtotal_ht);
1283 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1294 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VAT").
'</td></tr>';
1298 if (isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES')) {
1299 if ($modecompta ==
'CREANCES-DETTES') {
1302 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1303 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1304 $sql .=
" WHERE f.fk_statut IN (1,2)";
1306 $sql .=
" AND f.type IN (0,1,2,5)";
1308 $sql .=
" AND f.type IN (0,1,2,3,5)";
1310 if (!empty($date_start) && !empty($date_end)) {
1311 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1313 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
1314 $sql .=
" GROUP BY dm";
1315 $newsortfield = $sortfield;
1316 if ($newsortfield ==
's.nom, s.rowid') {
1317 $newsortfield =
'dm';
1319 if ($newsortfield ==
'amount_ht') {
1320 $newsortfield =
'amount';
1322 if ($newsortfield ==
'amount_ttc') {
1323 $newsortfield =
'amount';
1325 $sql .= $db->order($newsortfield, $sortorder);
1328 $result = $db->query($sql);
1330 $num = $db->num_rows($result);
1334 $obj = $db->fetch_object($result);
1336 $amount -= $obj->amount;
1338 $total_ttc -= $obj->amount;
1340 $subtotal_ttc -= $obj->amount;
1348 $total_ht_outcome -= 0;
1349 $total_ttc_outcome -= $amount;
1351 print
'<tr class="oddeven">';
1352 print
'<td> </td>';
1353 print
"<td>".$langs->trans(
"VATToPay").
"</td>\n";
1354 print
'<td class="right"> </td>'.
"\n";
1355 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1360 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1361 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1362 $sql .=
" WHERE f.fk_statut IN (1,2)";
1364 $sql .=
" AND f.type IN (0,1,2)";
1366 $sql .=
" AND f.type IN (0,1,2,3)";
1368 if (!empty($date_start) && !empty($date_end)) {
1369 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1371 $sql .=
" AND f.entity = ".$conf->entity;
1372 $sql .=
" GROUP BY dm";
1373 $newsortfield = $sortfield;
1374 if ($newsortfield ==
's.nom, s.rowid') {
1375 $newsortfield =
'dm';
1377 if ($newsortfield ==
'amount_ht') {
1378 $newsortfield =
'amount';
1380 if ($newsortfield ==
'amount_ttc') {
1381 $newsortfield =
'amount';
1383 $sql .= $db->order($newsortfield, $sortorder);
1385 dol_syslog(
"get vat received back", LOG_DEBUG);
1386 $result = $db->query($sql);
1388 $num = $db->num_rows($result);
1392 $obj = $db->fetch_object($result);
1394 $amount += $obj->amount;
1396 $total_ttc += $obj->amount;
1398 $subtotal_ttc += $obj->amount;
1407 $total_ht_income += 0;
1408 $total_ttc_income += $amount;
1410 print
'<tr class="oddeven">';
1411 print
'<td> </td>';
1412 print
'<td>'.$langs->trans(
"VATToCollect").
"</td>\n";
1413 print
'<td class="right"> </td>'.
"\n";
1414 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1419 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1420 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1421 $sql .=
" WHERE amount > 0";
1422 if (!empty($date_start) && !empty($date_end)) {
1423 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1425 $sql .=
" AND t.entity = ".$conf->entity;
1426 $sql .=
" GROUP BY dm";
1427 $newsortfield = $sortfield;
1428 if ($newsortfield ==
's.nom, s.rowid') {
1429 $newsortfield =
'dm';
1431 if ($newsortfield ==
'amount_ht') {
1432 $newsortfield =
'amount';
1434 if ($newsortfield ==
'amount_ttc') {
1435 $newsortfield =
'amount';
1437 $sql .= $db->order($newsortfield, $sortorder);
1439 dol_syslog(
"get vat really paid", LOG_DEBUG);
1440 $result = $db->query($sql);
1442 $num = $db->num_rows($result);
1446 $obj = $db->fetch_object($result);
1448 $amount -= $obj->amount;
1449 $total_ht -= $obj->amount;
1450 $total_ttc -= $obj->amount;
1451 $subtotal_ht -= $obj->amount;
1452 $subtotal_ttc -= $obj->amount;
1462 $total_ht_outcome -= 0;
1463 $total_ttc_outcome -= $amount;
1465 print
'<tr class="oddeven">';
1466 print
'<td> </td>';
1467 print
"<td>".$langs->trans(
"VATPaid").
"</td>\n";
1468 print
'<td <class="right"></td>'.
"\n";
1469 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1474 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1475 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1476 $sql .=
" WHERE amount < 0";
1477 if (!empty($date_start) && !empty($date_end)) {
1478 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1480 $sql .=
" AND t.entity = ".$conf->entity;
1481 $sql .=
" GROUP BY dm";
1482 $newsortfield = $sortfield;
1483 if ($newsortfield ==
's.nom, s.rowid') {
1484 $newsortfield =
'dm';
1486 if ($newsortfield ==
'amount_ht') {
1487 $newsortfield =
'amount';
1489 if ($newsortfield ==
'amount_ttc') {
1490 $newsortfield =
'amount';
1492 $sql .= $db->order($newsortfield, $sortorder);
1494 dol_syslog(
"get vat really received back", LOG_DEBUG);
1495 $result = $db->query($sql);
1497 $num = $db->num_rows($result);
1501 $obj = $db->fetch_object($result);
1503 $amount += -$obj->amount;
1504 $total_ht += -$obj->amount;
1505 $total_ttc += -$obj->amount;
1506 $subtotal_ht += -$obj->amount;
1507 $subtotal_ttc += -$obj->amount;
1517 $total_ht_income += 0;
1518 $total_ttc_income += $amount;
1520 print
'<tr class="oddeven">';
1521 print
'<td> </td>';
1522 print
"<td>".$langs->trans(
"VATCollected").
"</td>\n";
1523 print
'<td class="right"></td>'.
"\n";
1524 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1529 if ($mysoc->tva_assuj !=
'0') {
1530 print
'<tr class="liste_total">';
1533 print
'<td class="right"> </td>';
1534 print
'<td class="right">'.price(
price2num($subtotal_ttc,
'MT')).
'</td>';
1539$action =
"balanceclient";
1540$object = array(&$total_ht, &$total_ttc);
1541$parameters[
"mode"] = $modecompta;
1542$parameters[
"date_start"] = $date_start;
1543$parameters[
"date_end"] = $date_end;
1545$hookmanager->initHooks(array(
'externalbalance'));
1546$reshook = $hookmanager->executeHooks(
'addBalanceLine', $parameters, $object, $action);
1547print $hookmanager->resPrint;
1553print
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
1556print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1557if ($modecompta ==
'CREANCES-DETTES') {
1558 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1559} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1562print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1564print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1565if ($modecompta ==
'CREANCES-DETTES') {
1566 print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1567} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1570print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1572print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1573if ($modecompta ==
'CREANCES-DETTES') {
1574 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht,
'MT')).
'</td>';
1575} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1578print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc,
'MT')).
'</td>';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage categories of an accounting account.
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...
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_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
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.