35require
'../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancycategory.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
47$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy',
'loan'));
49$date_startmonth =
GETPOSTINT(
'date_startmonth');
55$showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'yes';
58$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
59$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
61if (empty($page) || $page == -1) {
64$offset = $limit * $page;
77 $year_start = $year_current;
79 $year_current = $year;
83$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
84$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
87if (empty($date_start) || empty($date_end)) {
91 $year_end = $year_start;
95 if (!$year && $month_start > $month_current) {
100 $month_end = $month_start - 1;
101 $year_end = $year_start + 1;
103 if ($month_end < 1) {
107 $month_end = $month_start;
132$year_start = $tmps[
'year'];
134$year_end = $tmpe[
'year'];
135$nbofyear = ($year_end - $year_start) + 1;
140if (isModEnabled(
'accounting')) {
141 $modecompta =
'BOOKKEEPING';
143if (
GETPOST(
"modecompta",
'alpha')) {
144 $modecompta =
GETPOST(
"modecompta",
'alpha');
151if ($user->socid > 0) {
152 $socid = $user->socid;
156$hookmanager->initHooks([
'customersupplierreportlist']);
158if (isModEnabled(
'comptabilite')) {
161if (isModEnabled(
'accounting')) {
162 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
171$form =
new Form($db);
180if ($modecompta ==
"CREANCES-DETTES") {
181 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
182 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
183 $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>" :
"");
184 $description = $langs->trans(
"RulesResultDue");
186 $description .= $langs->trans(
"DepositsAreNotIncluded");
188 $description .= $langs->trans(
"DepositsAreIncluded");
191 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
195} elseif ($modecompta ==
"RECETTES-DEPENSES") {
196 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
197 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
198 $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>" :
"");
199 $description = $langs->trans(
"RulesResultInOut");
202} elseif ($modecompta ==
"BOOKKEEPING") {
203 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
204 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
205 $arraylist = array(
'no'=>$langs->trans(
"CustomerCode"),
'yes'=>$langs->trans(
"AccountWithNonZeroValues"),
'all'=>$langs->trans(
"All"));
206 $period .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
207 $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>" :
"");
208 $description = $langs->trans(
"RulesResultBookkeepingPredefined");
209 $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")).
')';
216if (isModEnabled(
'accounting')) {
217 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
220$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModePayment");
221if (isModEnabled(
'accounting')) {
222 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
224$calcmode .=
'</label>';
225$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
226if (isModEnabled(
'accounting')) {
227 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
229$calcmode .=
'</label>';
232report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta,
'showaccountdetail'=>$showaccountdetail), $calcmode);
234if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
235 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
239$param =
'&modecompta='.urlencode($modecompta).
'&showaccountdetail='.urlencode($showaccountdetail);
241 $param .=
'&date_startday='.$date_startday;
243if ($date_startmonth) {
244 $param .=
'&date_startmonth='.$date_startmonth;
246if ($date_startyear) {
247 $param .=
'&date_startyear='.$date_startyear;
250 $param .=
'&date_endday='.$date_endday;
253 $param .=
'&date_endmonth='.$date_endmonth;
256 $param .=
'&date_endyear='.$date_endyear;
259print
'<table class="liste noborder centpercent">';
260print
'<tr class="liste_titre">';
262if ($modecompta ==
'BOOKKEEPING') {
263 print_liste_field_titre(
"PredefinedGroups", $_SERVER[
"PHP_SELF"],
'f.thirdparty_code,f.rowid',
'', $param,
'', $sortfield, $sortorder,
'width200 ');
268if ($modecompta ==
'BOOKKEEPING') {
269 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
'amount',
'', $param,
'class="right"', $sortfield, $sortorder);
271 if ($modecompta ==
'CREANCES-DETTES') {
272 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
'amount_ht',
'', $param,
'class="right"', $sortfield, $sortorder);
276 print_liste_field_titre(
"AmountTTC", $_SERVER[
"PHP_SELF"],
'amount_ttc',
'', $param,
'class="right"', $sortfield, $sortorder);
281$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
284if ($modecompta ==
'BOOKKEEPING') {
285 $predefinedgroupwhere =
"(";
286 $predefinedgroupwhere .=
" (pcg_type = 'EXPENSE')";
287 $predefinedgroupwhere .=
" OR ";
288 $predefinedgroupwhere .=
" (pcg_type = 'INCOME')";
289 $predefinedgroupwhere .=
")";
294 $sql =
"SELECT -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount";
295 if ($showaccountdetail ==
'no') {
296 $sql .=
", f.thirdparty_code as name";
298 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as f";
299 $sql .=
", ".MAIN_DB_PREFIX.
"accounting_account as aa";
300 $sql .=
" WHERE f.numero_compte = aa.account_number";
301 $sql .=
" AND ".$predefinedgroupwhere;
302 $sql .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
303 $sql .=
" AND f.entity = ".$conf->entity;
304 if (!empty($date_start) && !empty($date_end)) {
305 $sql .=
" AND f.doc_date >= '".$db->idate($date_start).
"' AND f.doc_date <= '".$db->idate($date_end).
"'";
307 $sql .=
" GROUP BY pcg_type";
308 if ($showaccountdetail ==
'no') {
309 $sql .=
", name, socid";
311 $sql .= $db->order($sortfield, $sortorder);
315 dol_syslog(
"get bookkeeping entries", LOG_DEBUG);
316 $result = $db->query($sql);
318 $num = $db->num_rows($result);
322 $objp = $db->fetch_object($result);
324 if ($showaccountdetail ==
'no') {
325 if ($objp->pcg_type != $oldpcgtype) {
326 print
'<tr class="trforbreak"><td colspan="3" class="tdforbreak">'.dol_escape_htmltag($objp->pcg_type).
'</td></tr>';
327 $oldpcgtype = $objp->pcg_type;
331 if ($showaccountdetail ==
'no') {
332 print
'<tr class="oddeven">';
336 print($objp->name ?
' ('.dol_escape_htmltag($objp->name).
')' :
' ('.$langs->trans(
"Unknown").
')');
338 print
'<td class="right nowraponall"><span class="amount">'.price($objp->amount).
"</span></td>\n";
341 print
'<tr class="oddeven trforbreak">';
342 print
'<td colspan="2" class="tdforbreak">';
345 print
'<td class="right nowraponall tdforbreak"><span class="amount">'.price($objp->amount).
"</span></td>\n";
349 $total_ht += (isset($objp->amount) ? $objp->amount : 0);
350 $total_ttc += (isset($objp->amount) ? $objp->amount : 0);
352 if ($objp->pcg_type ==
'INCOME') {
353 $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
354 $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
356 if ($objp->pcg_type ==
'EXPENSE') {
357 $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
358 $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
363 if ($showaccountdetail !=
'no') {
364 $tmppredefinedgroupwhere =
"pcg_type = '".$db->escape($objp->pcg_type).
"'";
365 $tmppredefinedgroupwhere .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
369 $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
371 foreach ($cpts as $j => $cpt) {
372 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, (empty($cpt[
'dc']) ? 0 : $cpt[
'dc']));
377 $resultN = $AccCat->sdc;
381 if ($showaccountdetail ==
'all' || $resultN != 0) {
384 print
'<td class="tdoverflowmax200"> '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'].
'</td>';
385 print
'<td class="right nowraponall"><span class="amount">'.price($resultN).
'</span></td>';
394 print
'<tr><td colspan="3" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';
403 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
405 if ($modecompta ==
'CREANCES-DETTES') {
406 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
407 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
408 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
409 $sql .=
" WHERE f.fk_soc = s.rowid";
410 $sql .=
" AND f.fk_statut IN (1,2)";
412 $sql .=
" AND f.type IN (0,1,2,5)";
414 $sql .=
" AND f.type IN (0,1,2,3,5)";
416 if (!empty($date_start) && !empty($date_end)) {
417 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
419 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
424 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
425 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
426 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
427 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
428 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
429 $sql .=
" WHERE p.rowid = pf.fk_paiement";
430 $sql .=
" AND pf.fk_facture = f.rowid";
431 $sql .=
" AND f.fk_soc = s.rowid";
432 if (!empty($date_start) && !empty($date_end)) {
433 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
436 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
438 $sql .=
" AND f.fk_soc = ".((int) $socid);
440 $sql .=
" GROUP BY name, socid";
441 $sql .= $db->order($sortfield, $sortorder);
443 dol_syslog(
"get customer invoices", LOG_DEBUG);
444 $result = $db->query($sql);
446 $num = $db->num_rows($result);
449 $objp = $db->fetch_object($result);
451 print
'<tr class="oddeven">';
452 print
'<td> </td>';
453 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$objp->socid.
'">'.$objp->name.
"</td>\n";
455 print
'<td class="right">';
456 if ($modecompta ==
'CREANCES-DETTES') {
457 print
'<span class="amount">'.price($objp->amount_ht).
"</span>";
460 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
462 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
463 $total_ttc += $objp->amount_ttc;
473 if ($modecompta ==
'RECETTES-DEPENSES') {
474 $sql =
"SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc";
475 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
476 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
477 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
478 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
479 $sql .=
" WHERE pf.rowid IS NULL";
480 $sql .=
" AND p.fk_bank = b.rowid";
481 $sql .=
" AND b.fk_account = ba.rowid";
482 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
483 if (!empty($date_start) && !empty($date_end)) {
484 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
486 $sql .=
" GROUP BY name, idp";
487 $sql .=
" ORDER BY name";
489 dol_syslog(
"get old customer payments not linked to invoices", LOG_DEBUG);
490 $result = $db->query($sql);
492 $num = $db->num_rows($result);
496 $objp = $db->fetch_object($result);
499 print
'<tr class="oddeven">';
500 print
'<td> </td>';
501 print
"<td>".$langs->trans(
"Bills").
" ".$langs->trans(
"Other").
" (".$langs->trans(
"PaymentsNotLinkedToInvoice").
")\n";
503 print
'<td class="right">';
504 if ($modecompta ==
'CREANCES-DETTES') {
505 print
'<span class="amount">'.price($objp->amount_ht).
"</span></td>\n";
508 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
510 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
511 $total_ttc += $objp->amount_ttc;
523 if ($total_ttc == 0) {
524 print
'<tr class="oddeven">';
525 print
'<td> </td>';
526 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
530 $total_ht_income += $total_ht;
531 $total_ttc_income += $total_ttc;
533 print
'<tr class="liste_total">';
536 print
'<td class="right">';
537 if ($modecompta ==
'CREANCES-DETTES') {
538 print
price($total_ht);
541 print
'<td class="right">'.price($total_ttc).
'</td>';
548 if (isModEnabled(
'don')) {
549 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
551 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
552 if ($modecompta ==
'CREANCES-DETTES') {
553 $sql =
"SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
554 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
555 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
556 $sql .=
" AND fk_statut in (1,2)";
558 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
559 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
560 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
561 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
562 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
563 $sql .=
" AND fk_statut >= 2";
565 if (!empty($date_start) && !empty($date_end)) {
566 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
569 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
570 $newsortfield = $sortfield;
571 if ($newsortfield ==
's.nom, s.rowid') {
572 $newsortfield =
'p.societe, p.firstname, p.lastname, dm';
574 if ($newsortfield ==
'amount_ht') {
575 $newsortfield =
'amount';
577 if ($newsortfield ==
'amount_ttc') {
578 $newsortfield =
'amount';
580 $sql .= $db->order($newsortfield, $sortorder);
583 $result = $db->query($sql);
587 $num = $db->num_rows($result);
591 $obj = $db->fetch_object($result);
593 $total_ht += $obj->amount;
594 $total_ttc += $obj->amount;
595 $subtotal_ht += $obj->amount;
596 $subtotal_ttc += $obj->amount;
598 print
'<tr class="oddeven">';
599 print
'<td> </td>';
601 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";
603 print
'<td class="right">';
604 if ($modecompta ==
'CREANCES-DETTES') {
605 print
'<span class="amount">'.price($obj->amount).
'</span>';
608 print
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
613 print
'<tr class="oddeven"><td> </td>';
614 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
621 $total_ht_income += $subtotal_ht;
622 $total_ttc_income += $subtotal_ttc;
624 print
'<tr class="liste_total">';
627 print
'<td class="right">';
628 if ($modecompta ==
'CREANCES-DETTES') {
629 print
price($subtotal_ht);
632 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
639 if ($modecompta ==
'CREANCES-DETTES') {
640 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
641 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
642 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
643 $sql .=
" WHERE f.fk_soc = s.rowid";
644 $sql .=
" AND f.fk_statut IN (1,2)";
646 $sql .=
" AND f.type IN (0,1,2)";
648 $sql .=
" AND f.type IN (0,1,2,3)";
650 if (!empty($date_start) && !empty($date_end)) {
651 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
653 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
654 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
655 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
656 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
657 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f";
658 $sql .=
" ON pf.fk_facturefourn = f.rowid";
659 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s";
660 $sql .=
" ON f.fk_soc = s.rowid";
661 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
662 if (!empty($date_start) && !empty($date_end)) {
663 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
667 $sql .=
" AND f.entity = ".((int) $conf->entity);
669 $sql .=
" AND f.fk_soc = ".((int) $socid);
671 $sql .=
" GROUP BY name, socid";
672 $sql .= $db->order($sortfield, $sortorder);
674 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
678 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
679 $result = $db->query($sql);
681 $num = $db->num_rows($result);
685 $objp = $db->fetch_object($result);
687 print
'<tr class="oddeven">';
688 print
'<td> </td>';
689 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
"/fourn/facture/list.php?socid=".$objp->socid.
'">'.$objp->name.
'</a></td>'.
"\n";
691 print
'<td class="right">';
692 if ($modecompta ==
'CREANCES-DETTES') {
693 print
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
696 print
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
698 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
699 $total_ttc -= $objp->amount_ttc;
700 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
701 $subtotal_ttc += $objp->amount_ttc;
707 print
'<tr class="oddeven">';
708 print
'<td> </td>';
709 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
718 $total_ht_outcome += $subtotal_ht;
719 $total_ttc_outcome += $subtotal_ttc;
721 print
'<tr class="liste_total">';
724 print
'<td class="right">';
725 if ($modecompta ==
'CREANCES-DETTES') {
726 print
price(-$subtotal_ht);
729 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
737 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsNondeductibles").
'</td></tr>';
739 if ($modecompta ==
'CREANCES-DETTES') {
740 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
741 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
742 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
743 $sql .=
" WHERE cs.fk_type = c.id";
744 $sql .=
" AND c.deductible = 0";
745 if (!empty($date_start) && !empty($date_end)) {
746 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
748 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
749 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
750 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
751 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
752 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
753 $sql .=
" WHERE p.fk_charge = cs.rowid";
754 $sql .=
" AND cs.fk_type = c.id";
755 $sql .=
" AND c.deductible = 0";
756 if (!empty($date_start) && !empty($date_end)) {
757 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
760 $sql .=
" AND cs.entity = ".$conf->entity;
761 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
762 $newsortfield = $sortfield;
763 if ($newsortfield ==
's.nom, s.rowid') {
764 $newsortfield =
'c.libelle, c.id';
766 if ($newsortfield ==
'amount_ht') {
767 $newsortfield =
'amount';
769 if ($newsortfield ==
'amount_ttc') {
770 $newsortfield =
'amount';
773 $sql .= $db->order($newsortfield, $sortorder);
775 dol_syslog(
"get social contributions deductible=0", LOG_DEBUG);
776 $result = $db->query($sql);
780 $num = $db->num_rows($result);
784 $obj = $db->fetch_object($result);
786 $total_ht -= $obj->amount;
787 $total_ttc -= $obj->amount;
788 $subtotal_ht += $obj->amount;
789 $subtotal_ttc += $obj->amount;
792 if ($obj->accountancy_code) {
793 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
795 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
796 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
799 print
'<tr class="oddeven">';
800 print
'<td> </td>';
801 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
802 print
'<td class="right">';
803 if ($modecompta ==
'CREANCES-DETTES') {
804 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
807 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
812 print
'<tr class="oddeven">';
813 print
'<td> </td>';
814 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
821 $total_ht_outcome += $subtotal_ht;
822 $total_ttc_outcome += $subtotal_ttc;
824 print
'<tr class="liste_total">';
827 print
'<td class="right">';
828 if ($modecompta ==
'CREANCES-DETTES') {
829 print
price(-$subtotal_ht);
832 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
840 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsDeductibles").
'</td></tr>';
842 if ($modecompta ==
'CREANCES-DETTES') {
843 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
844 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
845 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
846 $sql .=
" WHERE cs.fk_type = c.id";
847 $sql .=
" AND c.deductible = 1";
848 if (!empty($date_start) && !empty($date_end)) {
849 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
851 $sql .=
" AND cs.entity = ".$conf->entity;
852 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
853 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
854 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
855 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
856 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
857 $sql .=
" WHERE p.fk_charge = cs.rowid";
858 $sql .=
" AND cs.fk_type = c.id";
859 $sql .=
" AND c.deductible = 1";
860 if (!empty($date_start) && !empty($date_end)) {
861 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
863 $sql .=
" AND cs.entity = ".$conf->entity;
865 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
866 $newsortfield = $sortfield;
867 if ($newsortfield ==
's.nom, s.rowid') {
868 $newsortfield =
'c.libelle, c.id';
870 if ($newsortfield ==
'amount_ht') {
871 $newsortfield =
'amount';
873 if ($newsortfield ==
'amount_ttc') {
874 $newsortfield =
'amount';
876 $sql .= $db->order($newsortfield, $sortorder);
878 dol_syslog(
"get social contributions deductible=1", LOG_DEBUG);
879 $result = $db->query($sql);
883 $num = $db->num_rows($result);
887 $obj = $db->fetch_object($result);
889 $total_ht -= $obj->amount;
890 $total_ttc -= $obj->amount;
891 $subtotal_ht += $obj->amount;
892 $subtotal_ttc += $obj->amount;
895 if ($obj->accountancy_code) {
896 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
898 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
899 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
902 print
'<tr class="oddeven">';
903 print
'<td> </td>';
904 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
905 print
'<td class="right">';
906 if ($modecompta ==
'CREANCES-DETTES') {
907 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
910 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
915 print
'<tr class="oddeven">';
916 print
'<td> </td>';
917 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
924 $total_ht_outcome += $subtotal_ht;
925 $total_ttc_outcome += $subtotal_ttc;
927 print
'<tr class="liste_total">';
930 print
'<td class="right">';
931 if ($modecompta ==
'CREANCES-DETTES') {
932 print
price(-$subtotal_ht);
935 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
943 if (isModEnabled(
'salaries')) {
944 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
946 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
947 if ($modecompta ==
'CREANCES-DETTES') {
948 $column =
's.dateep';
950 $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";
951 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
952 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
953 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
954 if (!empty($date_start) && !empty($date_end)) {
955 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
957 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, s.label, dm";
961 $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";
962 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
963 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = p.fk_salary";
964 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
965 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
966 if (!empty($date_start) && !empty($date_end)) {
967 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
969 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, p.label, dm";
972 $newsortfield = $sortfield;
973 if ($newsortfield ==
's.nom, s.rowid') {
974 $newsortfield =
'u.firstname, u.lastname';
976 if ($newsortfield ==
'amount_ht') {
977 $newsortfield =
'amount';
979 if ($newsortfield ==
'amount_ttc') {
980 $newsortfield =
'amount';
982 $sql .= $db->order($newsortfield, $sortorder);
986 $result = $db->query($sql);
990 $num = $db->num_rows($result);
994 $obj = $db->fetch_object($result);
996 $total_ht -= $obj->amount;
997 $total_ttc -= $obj->amount;
998 $subtotal_ht += $obj->amount;
999 $subtotal_ttc += $obj->amount;
1001 print
'<tr class="oddeven"><td> </td>';
1003 $userstatic =
new User($db);
1004 $userstatic->fetch($obj->fk_user);
1006 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";
1007 print
'<td class="right">';
1008 if ($modecompta ==
'CREANCES-DETTES') {
1009 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1012 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1017 print
'<tr class="oddeven">';
1018 print
'<td> </td>';
1019 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1026 $total_ht_outcome += $subtotal_ht;
1027 $total_ttc_outcome += $subtotal_ttc;
1029 print
'<tr class="liste_total">';
1032 print
'<td class="right">';
1033 if ($modecompta ==
'CREANCES-DETTES') {
1034 print
price(-$subtotal_ht);
1037 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1046 if (isModEnabled(
'expensereport')) {
1047 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
1048 $langs->load(
'trips');
1049 if ($modecompta ==
'CREANCES-DETTES') {
1050 $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";
1051 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1052 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1053 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1054 $sql .=
" AND p.fk_statut>=5";
1056 $column =
'p.date_valid';
1058 $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";
1059 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1060 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1061 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
1062 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
1063 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1064 $sql .=
" AND p.fk_statut>=5";
1066 $column =
'pe.datep';
1069 if (!empty($date_start) && !empty($date_end)) {
1070 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
1073 if ($modecompta ==
'CREANCES-DETTES') {
1076 $sql .=
" GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
1078 $newsortfield = $sortfield;
1079 if ($newsortfield ==
's.nom, s.rowid') {
1080 $newsortfield =
'p.ref';
1082 $sql .= $db->order($newsortfield, $sortorder);
1085 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
1088 $result = $db->query($sql);
1092 $num = $db->num_rows($result);
1094 while ($obj = $db->fetch_object($result)) {
1095 $total_ht -= $obj->amount_ht;
1096 $total_ttc -= $obj->amount_ttc;
1097 $subtotal_ht += $obj->amount_ht;
1098 $subtotal_ttc += $obj->amount_ttc;
1100 print
'<tr class="oddeven">';
1101 print
'<td> </td>';
1102 print
"<td>".$langs->trans(
"ExpenseReport").
" <a href=\"".DOL_URL_ROOT.
"/expensereport/list.php?search_user=".$obj->userid.
"\">".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
1103 print
'<td class="right">';
1104 if ($modecompta ==
'CREANCES-DETTES') {
1105 print
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
1108 print
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
1112 print
'<tr class="oddeven">';
1113 print
'<td> </td>';
1114 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1121 $total_ht_outcome += $subtotal_ht;
1122 $total_ttc_outcome += $subtotal_ttc;
1124 print
'<tr class="liste_total">';
1127 print
'<td class="right">';
1128 if ($modecompta ==
'CREANCES-DETTES') {
1129 print
price(-$subtotal_ht);
1132 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1142 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled(
"bank") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1146 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
1149 $sql =
"SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
1150 $sql .=
' WHERE 1 = 1';
1151 if (!empty($date_start) && !empty($date_end)) {
1152 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1154 $sql .=
' GROUP BY p.sens';
1155 $sql .=
' ORDER BY p.sens';
1157 dol_syslog(
'get various payments', LOG_DEBUG);
1158 $result = $db->query($sql);
1161 $obj = $db->fetch_object($result);
1162 if (isset($obj->amount)) {
1163 $subtotal_ht += -$obj->amount;
1164 $subtotal_ttc += -$obj->amount;
1166 $total_ht_outcome += $obj->amount;
1167 $total_ttc_outcome += $obj->amount;
1169 print
'<tr class="oddeven">';
1170 print
'<td> </td>';
1171 print
"<td>".$langs->trans(
"AccountingDebit").
"</td>\n";
1172 print
'<td class="right">';
1173 if ($modecompta ==
'CREANCES-DETTES') {
1174 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1177 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1181 $obj = $db->fetch_object($result);
1182 if (isset($obj->amount)) {
1183 $subtotal_ht += $obj->amount;
1184 $subtotal_ttc += $obj->amount;
1186 $total_ht_income += $obj->amount;
1187 $total_ttc_income += $obj->amount;
1189 print
'<tr class="oddeven"><td> </td>';
1190 print
"<td>".$langs->trans(
"AccountingCredit").
"</td>\n";
1191 print
'<td class="right">';
1192 if ($modecompta ==
'CREANCES-DETTES') {
1193 print
'<span class="amount">'.price($obj->amount).
'</span>';
1196 print
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
1200 $total_ht += $subtotal_ht;
1201 $total_ttc += $subtotal_ttc;
1202 print
'<tr class="liste_total">';
1205 print
'<td class="right">';
1206 if ($modecompta ==
'CREANCES-DETTES') {
1207 print
price($subtotal_ht);
1210 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1221 if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1225 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
1227 $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';
1228 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
1229 $sql .=
' WHERE 1 = 1';
1230 if (!empty($date_start) && !empty($date_end)) {
1231 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1233 $sql .=
' GROUP BY p.fk_loan';
1234 $sql .=
' ORDER BY p.fk_loan';
1237 $result = $db->query($sql);
1239 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
1240 $loan_static =
new Loan($db);
1241 while ($obj = $db->fetch_object($result)) {
1242 $loan_static->id = $obj->id;
1243 $loan_static->ref = $obj->id;
1244 $loan_static->label = $obj->label;
1245 print
'<tr class="oddeven"><td> </td>';
1246 print
"<td>".$loan_static->getNomUrl(1).
' - '.$obj->label.
"</td>\n";
1247 if ($modecompta ==
'CREANCES-DETTES') {
1248 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1250 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1252 $subtotal_ht -= $obj->amount;
1253 $subtotal_ttc -= $obj->amount;
1255 $total_ht += $subtotal_ht;
1256 $total_ttc += $subtotal_ttc;
1258 $total_ht_income += $subtotal_ht;
1259 $total_ttc_income += $subtotal_ttc;
1261 print
'<tr class="liste_total">';
1264 print
'<td class="right">';
1265 if ($modecompta ==
'CREANCES-DETTES') {
1266 print
price($subtotal_ht);
1269 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1280 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VAT").
'</td></tr>';
1284 if (isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES')) {
1285 if ($modecompta ==
'CREANCES-DETTES') {
1288 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1289 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1290 $sql .=
" WHERE f.fk_statut IN (1,2)";
1292 $sql .=
" AND f.type IN (0,1,2,5)";
1294 $sql .=
" AND f.type IN (0,1,2,3,5)";
1296 if (!empty($date_start) && !empty($date_end)) {
1297 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1299 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
1300 $sql .=
" GROUP BY dm";
1301 $newsortfield = $sortfield;
1302 if ($newsortfield ==
's.nom, s.rowid') {
1303 $newsortfield =
'dm';
1305 if ($newsortfield ==
'amount_ht') {
1306 $newsortfield =
'amount';
1308 if ($newsortfield ==
'amount_ttc') {
1309 $newsortfield =
'amount';
1311 $sql .= $db->order($newsortfield, $sortorder);
1314 $result = $db->query($sql);
1316 $num = $db->num_rows($result);
1320 $obj = $db->fetch_object($result);
1322 $amount -= $obj->amount;
1324 $total_ttc -= $obj->amount;
1326 $subtotal_ttc -= $obj->amount;
1334 $total_ht_outcome -= 0;
1335 $total_ttc_outcome -= $amount;
1337 print
'<tr class="oddeven">';
1338 print
'<td> </td>';
1339 print
"<td>".$langs->trans(
"VATToPay").
"</td>\n";
1340 print
'<td class="right"> </td>'.
"\n";
1341 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1346 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1347 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1348 $sql .=
" WHERE f.fk_statut IN (1,2)";
1350 $sql .=
" AND f.type IN (0,1,2)";
1352 $sql .=
" AND f.type IN (0,1,2,3)";
1354 if (!empty($date_start) && !empty($date_end)) {
1355 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1357 $sql .=
" AND f.entity = ".$conf->entity;
1358 $sql .=
" GROUP BY dm";
1359 $newsortfield = $sortfield;
1360 if ($newsortfield ==
's.nom, s.rowid') {
1361 $newsortfield =
'dm';
1363 if ($newsortfield ==
'amount_ht') {
1364 $newsortfield =
'amount';
1366 if ($newsortfield ==
'amount_ttc') {
1367 $newsortfield =
'amount';
1369 $sql .= $db->order($newsortfield, $sortorder);
1371 dol_syslog(
"get vat received back", LOG_DEBUG);
1372 $result = $db->query($sql);
1374 $num = $db->num_rows($result);
1378 $obj = $db->fetch_object($result);
1380 $amount += $obj->amount;
1382 $total_ttc += $obj->amount;
1384 $subtotal_ttc += $obj->amount;
1393 $total_ht_income += 0;
1394 $total_ttc_income += $amount;
1396 print
'<tr class="oddeven">';
1397 print
'<td> </td>';
1398 print
'<td>'.$langs->trans(
"VATToCollect").
"</td>\n";
1399 print
'<td class="right"> </td>'.
"\n";
1400 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1405 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1406 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1407 $sql .=
" WHERE amount > 0";
1408 if (!empty($date_start) && !empty($date_end)) {
1409 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1411 $sql .=
" AND t.entity = ".$conf->entity;
1412 $sql .=
" GROUP BY dm";
1413 $newsortfield = $sortfield;
1414 if ($newsortfield ==
's.nom, s.rowid') {
1415 $newsortfield =
'dm';
1417 if ($newsortfield ==
'amount_ht') {
1418 $newsortfield =
'amount';
1420 if ($newsortfield ==
'amount_ttc') {
1421 $newsortfield =
'amount';
1423 $sql .= $db->order($newsortfield, $sortorder);
1425 dol_syslog(
"get vat really paid", LOG_DEBUG);
1426 $result = $db->query($sql);
1428 $num = $db->num_rows($result);
1432 $obj = $db->fetch_object($result);
1434 $amount -= $obj->amount;
1435 $total_ht -= $obj->amount;
1436 $total_ttc -= $obj->amount;
1437 $subtotal_ht -= $obj->amount;
1438 $subtotal_ttc -= $obj->amount;
1448 $total_ht_outcome -= 0;
1449 $total_ttc_outcome -= $amount;
1451 print
'<tr class="oddeven">';
1452 print
'<td> </td>';
1453 print
"<td>".$langs->trans(
"VATPaid").
"</td>\n";
1454 print
'<td <class="right"></td>'.
"\n";
1455 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1460 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1461 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1462 $sql .=
" WHERE amount < 0";
1463 if (!empty($date_start) && !empty($date_end)) {
1464 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1466 $sql .=
" AND t.entity = ".$conf->entity;
1467 $sql .=
" GROUP BY dm";
1468 $newsortfield = $sortfield;
1469 if ($newsortfield ==
's.nom, s.rowid') {
1470 $newsortfield =
'dm';
1472 if ($newsortfield ==
'amount_ht') {
1473 $newsortfield =
'amount';
1475 if ($newsortfield ==
'amount_ttc') {
1476 $newsortfield =
'amount';
1478 $sql .= $db->order($newsortfield, $sortorder);
1480 dol_syslog(
"get vat really received back", LOG_DEBUG);
1481 $result = $db->query($sql);
1483 $num = $db->num_rows($result);
1487 $obj = $db->fetch_object($result);
1489 $amount += -$obj->amount;
1490 $total_ht += -$obj->amount;
1491 $total_ttc += -$obj->amount;
1492 $subtotal_ht += -$obj->amount;
1493 $subtotal_ttc += -$obj->amount;
1503 $total_ht_income += 0;
1504 $total_ttc_income += $amount;
1506 print
'<tr class="oddeven">';
1507 print
'<td> </td>';
1508 print
"<td>".$langs->trans(
"VATCollected").
"</td>\n";
1509 print
'<td class="right"></td>'.
"\n";
1510 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1515 if ($mysoc->tva_assuj !=
'0') {
1516 print
'<tr class="liste_total">';
1519 print
'<td class="right"> </td>';
1520 print
'<td class="right">'.price(
price2num($subtotal_ttc,
'MT')).
'</td>';
1525$action =
"balanceclient";
1526$object = array(&$total_ht, &$total_ttc);
1527$parameters[
"mode"] = $modecompta;
1528$parameters[
"date_start"] = $date_start;
1529$parameters[
"date_end"] = $date_end;
1531$hookmanager->initHooks(array(
'externalbalance'));
1532$reshook = $hookmanager->executeHooks(
'addBalanceLine', $parameters, $object, $action);
1533print $hookmanager->resPrint;
1539print
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
1542print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1543if ($modecompta ==
'CREANCES-DETTES') {
1544 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1545} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1548print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1550print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1551if ($modecompta ==
'CREANCES-DETTES') {
1552 print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1553} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1556print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1558print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1559if ($modecompta ==
'CREANCES-DETTES') {
1560 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht,
'MT')).
'</td>';
1561} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1564print
'<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...
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.