33 require
'../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancycategory.class.php';
42 $langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy',
'loan'));
44 $date_startmonth =
GETPOST(
'date_startmonth',
'int');
45 $date_startday =
GETPOST(
'date_startday',
'int');
46 $date_startyear =
GETPOST(
'date_startyear',
'int');
47 $date_endmonth =
GETPOST(
'date_endmonth',
'int');
48 $date_endday =
GETPOST(
'date_endday',
'int');
49 $date_endyear =
GETPOST(
'date_endyear',
'int');
50 $showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'no';
53 $socid =
GETPOST(
'socid',
'int');
54 if ($user->socid > 0) $socid = $user->socid;
55 if (!empty($conf->comptabilite->enabled)) $result =
restrictedArea($user,
'compta',
'',
'',
'resultat');
56 if (!empty($conf->accounting->enabled)) $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
58 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
59 $sortfield =
GETPOST(
"sortfield",
'alpha');
60 $sortorder =
GETPOST(
"sortorder",
'alpha');
62 if (empty($page) || $page == -1) { $page = 0; }
63 $offset = $limit * $page;
64 $pageprev = $page - 1;
65 $pagenext = $page + 1;
67 if (!$sortorder) $sortorder =
'ASC';
72 $year_current = strftime(
"%Y",
dol_now());
73 $month_current = strftime(
"%m",
dol_now());
74 $year_start = $year_current;
76 $year_current = $year;
77 $month_current = strftime(
"%m",
dol_now());
80 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
81 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
84 if (empty($date_start) || empty($date_end))
90 $year_end = $year_start;
91 $month_start =
GETPOST(
"month") ?
GETPOST(
"month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
94 if (!
GETPOST(
"year") && $month_start > $month_current)
99 $month_end = $month_start - 1;
100 if ($month_end < 1) $month_end = 12;
102 }
else $month_end = $month_start;
113 $year_start = $tmps[
'year'];
115 $year_end = $tmpe[
'year'];
116 $nbofyear = ($year_end - $year_start) + 1;
120 $modecompta = $conf->global->ACCOUNTING_MODE;
121 if (!empty($conf->accounting->enabled)) $modecompta =
'BOOKKEEPING';
122 if (
GETPOST(
"modecompta",
'alpha')) $modecompta =
GETPOST(
"modecompta",
'alpha');
134 $form =
new Form($db);
143 if ($modecompta ==
"CREANCES-DETTES")
145 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
146 $calcmode = $langs->trans(
"CalcModeDebt");
147 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInInputOutputMode",
'{s1}',
'{s2}').
')';
148 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.
$_SERVER[
"PHP_SELF"].
'?date_startyear='.$tmps[
'year'].
'&date_startmonth='.$tmps[
'mon'].
'&date_startday='.$tmps[
'mday'].
'&date_endyear='.$tmpe[
'year'].
'&date_endmonth='.$tmpe[
'mon'].
'&date_endday='.$tmpe[
'mday'].
'&modecompta=RECETTES-DEPENSES">',
'</a>'), $calcmode);
149 if (!empty($conf->accounting->enabled)) {
150 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'{s1}',
'{s2}').
')';
151 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.
$_SERVER[
"PHP_SELF"].
'?date_startyear='.$tmps[
'year'].
'&date_startmonth='.$tmps[
'mon'].
'&date_startday='.$tmps[
'mday'].
'&date_endyear='.$tmpe[
'year'].
'&date_endmonth='.$tmpe[
'mon'].
'&date_endday='.$tmpe[
'mday'].
'&modecompta=BOOKKEEPING">',
'</a>'), $calcmode);
153 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
154 $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>" :
"");
155 $description = $langs->trans(
"RulesResultDue");
156 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= $langs->trans(
"DepositsAreNotIncluded");
157 else $description .= $langs->trans(
"DepositsAreIncluded");
160 } elseif ($modecompta ==
"RECETTES-DEPENSES")
162 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
163 $calcmode = $langs->trans(
"CalcModeEngagement");
164 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'{s1}',
'{s2}').
')';
165 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.
$_SERVER[
"PHP_SELF"].
'?date_startyear='.$tmps[
'year'].
'&date_startmonth='.$tmps[
'mon'].
'&date_startday='.$tmps[
'mday'].
'&date_endyear='.$tmpe[
'year'].
'&date_endmonth='.$tmpe[
'mon'].
'&date_endday='.$tmpe[
'mday'].
'&modecompta=CREANCES-DETTES">',
'</a>'), $calcmode);
166 if (!empty($conf->accounting->enabled)) {
167 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'{s1}',
'{s2}').
')';
168 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.
$_SERVER[
"PHP_SELF"].
'?date_startyear='.$tmps[
'year'].
'&date_startmonth='.$tmps[
'mon'].
'&date_startday='.$tmps[
'mday'].
'&date_endyear='.$tmpe[
'year'].
'&date_endmonth='.$tmpe[
'mon'].
'&date_endday='.$tmpe[
'mday'].
'&modecompta=BOOKKEEPING">',
'</a>'), $calcmode);
170 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
171 $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>" :
"");
172 $description = $langs->trans(
"RulesResultInOut");
175 } elseif ($modecompta ==
"BOOKKEEPING")
177 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
178 $calcmode = $langs->trans(
"CalcModeBookkeeping");
179 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInInputOutputMode",
'{s1}',
'{s2}').
')';
180 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.
$_SERVER[
"PHP_SELF"].
'?date_startyear='.$tmps[
'year'].
'&date_startmonth='.$tmps[
'mon'].
'&date_startday='.$tmps[
'mday'].
'&date_endyear='.$tmpe[
'year'].
'&date_endmonth='.$tmpe[
'mon'].
'&date_endday='.$tmpe[
'mday'].
'&modecompta=RECETTES-DEPENSES">',
'</a>'), $calcmode);
181 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'{s1}',
'{s2}').
')';
182 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.
$_SERVER[
"PHP_SELF"].
'?date_startyear='.$tmps[
'year'].
'&date_startmonth='.$tmps[
'mon'].
'&date_startday='.$tmps[
'mday'].
'&date_endyear='.$tmpe[
'year'].
'&date_endmonth='.$tmpe[
'mon'].
'&date_endday='.$tmpe[
'mday'].
'&modecompta=CREANCES-DETTES">',
'</a>'), $calcmode);
183 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
184 $arraylist = array(
'no'=>$langs->trans(
"No"),
'yes'=>$langs->trans(
"AccountWithNonZeroValues"),
'all'=>$langs->trans(
"All"));
185 $period .=
' '.$langs->trans(
"DetailByAccount").
' '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
186 $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>" :
"");
187 $description = $langs->trans(
"RulesResultBookkeepingPredefined");
188 $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")).
')';
193 $hselected =
'report';
195 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta), $calcmode);
197 if (!empty($conf->accounting->enabled) && $modecompta !=
'BOOKKEEPING')
203 $param =
'&modecompta='.urlencode($modecompta).
'&showaccountdetail='.urlencode($showaccountdetail);
204 if ($date_startday) $param .=
'&date_startday='.$date_startday;
205 if ($date_startmonth) $param .=
'&date_startmonth='.$date_startmonth;
206 if ($date_startyear) $param .=
'&date_startyear='.$date_startyear;
207 if ($date_endday) $param .=
'&date_endday='.$date_endday;
208 if ($date_endmonth) $param .=
'&date_endmonth='.$date_endmonth;
209 if ($date_endyear) $param .=
'&date_endyear='.$date_endyear;
211 print '<table class="noborder centpercent">';
212 print '<tr class="liste_titre">';
213 if ($modecompta ==
'BOOKKEEPING') {
219 if ($modecompta ==
'BOOKKEEPING')
223 if ($modecompta ==
'CREANCES-DETTES')
232 $total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
235 if ($modecompta ==
'BOOKKEEPING')
237 $predefinedgroupwhere =
"(";
238 $predefinedgroupwhere .=
" (pcg_type = 'EXPENSE')";
239 $predefinedgroupwhere .=
" OR ";
240 $predefinedgroupwhere .=
" (pcg_type = 'INCOME')";
241 $predefinedgroupwhere .=
")";
243 $charofaccountstring = $conf->global->CHARTOFACCOUNTS;
244 $charofaccountstring =
dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS,
'accounting_system',
'rowid',
'pcg_version');
246 $sql =
"SELECT f.thirdparty_code as name, -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount";
247 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as f";
248 $sql .=
", ".MAIN_DB_PREFIX.
"accounting_account as aa";
249 $sql .=
" WHERE f.numero_compte = aa.account_number";
250 $sql .=
" AND ".$predefinedgroupwhere;
251 $sql .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
252 $sql .=
" AND f.entity = ".$conf->entity;
253 if (!empty($date_start) && !empty($date_end))
254 $sql .=
" AND f.doc_date >= '".$db->idate($date_start).
"' AND f.doc_date <= '".$db->idate($date_end).
"'";
255 $sql .=
" GROUP BY pcg_type DESC, name, socid";
256 $sql .= $db->order($sortfield, $sortorder);
261 dol_syslog(
"get bookkeeping entries", LOG_DEBUG);
262 $result = $db->query($sql);
264 $num = $db->num_rows($result);
270 $objp = $db->fetch_object($result);
272 if ($objp->pcg_type != $oldpcgtype)
274 print '<tr><td colspan="4">'.$objp->pcg_type.
'</td></tr>';
275 $oldpcgtype = $objp->pcg_type;
278 print '<tr class="oddeven">';
279 print '<td> </td>';
280 print '<td>'.$objp->pcg_type.($objp->name ?
' ('.$objp->name.
')' :
'').
"</td>\n";
281 print '<td class="right">'.price($objp->amount).
"</td>\n";
284 $total_ht += (isset($objp->amount) ? $objp->amount : 0);
285 $total_ttc += (isset($objp->amount) ? $objp->amount : 0);
287 if ($objp->pcg_type ==
'INCOME') {
288 $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
289 $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
291 if ($objp->pcg_type ==
'EXPENSE') {
292 $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
293 $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
298 if ($showaccountdetail !=
'no')
300 $tmppredefinedgroupwhere =
"pcg_type = '".$db->escape($objp->pcg_type).
"'";
301 $tmppredefinedgroupwhere .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
305 $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
307 foreach ($cpts as $j => $cpt)
309 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, $cpt[
'dc']);
314 $resultN = $AccCat->sdc;
318 if ($showaccountdetail ==
'all' || $resultN <> 0)
322 print '<td class="tdoverflowmax200"> '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'].
'</td>';
323 print '<td class="right">'.price($resultN).
'</td>';
332 print '<tr><td colspan="4" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';
339 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
341 if ($modecompta ==
'CREANCES-DETTES')
343 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc";
344 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
345 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
346 $sql .=
" WHERE f.fk_soc = s.rowid";
347 $sql .=
" AND f.fk_statut IN (1,2)";
348 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
349 $sql .=
" AND f.type IN (0,1,2,5)";
350 else $sql .=
" AND f.type IN (0,1,2,3,5)";
351 if (!empty($date_start) && !empty($date_end))
352 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
353 } elseif ($modecompta ==
'RECETTES-DEPENSES')
359 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
360 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
361 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
362 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
363 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
364 $sql .=
" WHERE p.rowid = pf.fk_paiement";
365 $sql .=
" AND pf.fk_facture = f.rowid";
366 $sql .=
" AND f.fk_soc = s.rowid";
367 if (!empty($date_start) && !empty($date_end))
368 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
370 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
371 if ($socid) $sql .=
" AND f.fk_soc = ".$socid;
372 $sql .=
" GROUP BY name, socid";
373 $sql .= $db->order($sortfield, $sortorder);
375 dol_syslog(
"get customer invoices", LOG_DEBUG);
376 $result = $db->query($sql);
378 $num = $db->num_rows($result);
382 $objp = $db->fetch_object($result);
384 print '<tr class="oddeven"><td> </td>';
385 print "<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$objp->socid.
'">'.$objp->name.
"</td>\n";
387 if ($modecompta ==
'CREANCES-DETTES')
388 print '<td class="right">'.price($objp->amount_ht).
"</td>\n";
389 print '<td class="right">'.price($objp->amount_ttc).
"</td>\n";
391 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
392 $total_ttc += $objp->amount_ttc;
402 if ($modecompta ==
'RECETTES-DEPENSES')
404 $sql =
"SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc";
405 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
406 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
407 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
408 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
409 $sql .=
" WHERE pf.rowid IS NULL";
410 $sql .=
" AND p.fk_bank = b.rowid";
411 $sql .=
" AND b.fk_account = ba.rowid";
412 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
413 if (!empty($date_start) && !empty($date_end))
414 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
415 $sql .=
" GROUP BY name, idp";
416 $sql .=
" ORDER BY name";
418 dol_syslog(
"get old customer payments not linked to invoices", LOG_DEBUG);
419 $result = $db->query($sql);
421 $num = $db->num_rows($result);
426 $objp = $db->fetch_object($result);
429 print '<tr class="oddeven"><td> </td>';
430 print "<td>".$langs->trans(
"Bills").
" ".$langs->trans(
"Other").
" (".$langs->trans(
"PaymentsNotLinkedToInvoice").
")\n";
432 if ($modecompta ==
'CREANCES-DETTES')
433 print '<td class="right">'.price($objp->amount_ht).
"</td>\n";
434 print '<td class="right">'.price($objp->amount_ttc).
"</td>\n";
436 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
437 $total_ttc += $objp->amount_ttc;
451 print '<tr class="oddeven"><td> </td>';
452 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
456 $total_ht_income += $total_ht;
457 $total_ttc_income += $total_ttc;
459 print '<tr class="liste_total">';
460 if ($modecompta ==
'CREANCES-DETTES')
461 print '<td colspan="3" class="right">'.price($total_ht).
'</td>';
462 print '<td colspan="3" class="right">'.price($total_ttc).
'</td>';
469 if (!empty($conf->don->enabled))
471 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
473 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES')
475 if ($modecompta ==
'CREANCES-DETTES')
477 $sql =
"SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
478 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
479 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
480 $sql .=
" AND fk_statut in (1,2)";
482 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
483 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
484 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
485 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
486 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
487 $sql .=
" AND fk_statut >= 2";
489 if (!empty($date_start) && !empty($date_end))
490 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
492 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
493 $newsortfield = $sortfield;
494 if ($newsortfield ==
's.nom, s.rowid') $newsortfield =
'p.societe, p.firstname, p.lastname, dm';
495 if ($newsortfield ==
'amount_ht') $newsortfield =
'amount';
496 if ($newsortfield ==
'amount_ttc') $newsortfield =
'amount';
497 $sql .= $db->order($newsortfield, $sortorder);
500 $result = $db->query($sql);
505 $num = $db->num_rows($result);
511 $obj = $db->fetch_object($result);
513 $total_ht += $obj->amount;
514 $total_ttc += $obj->amount;
515 $subtotal_ht += $obj->amount;
516 $subtotal_ttc += $obj->amount;
518 print '<tr class="oddeven"><td> </td>';
520 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";
522 if ($modecompta ==
'CREANCES-DETTES')
print '<td class="right">'.price($obj->amount).
'</td>';
523 print '<td class="right">'.price($obj->amount).
'</td>';
528 print '<tr class="oddeven"><td> </td>';
529 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
536 $total_ht_income += $subtotal_ht;
537 $total_ttc_income += $subtotal_ttc;
539 print '<tr class="liste_total">';
540 if ($modecompta ==
'CREANCES-DETTES')
541 print '<td colspan="3" class="right">'.price($subtotal_ht).
'</td>';
542 print '<td colspan="3" class="right">'.price($subtotal_ttc).
'</td>';
549 if ($modecompta ==
'CREANCES-DETTES')
551 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
552 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
553 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
554 $sql .=
" WHERE f.fk_soc = s.rowid";
555 $sql .=
" AND f.fk_statut IN (1,2)";
556 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
557 $sql .=
" AND f.type IN (0,1,2)";
558 else $sql .=
" AND f.type IN (0,1,2,3)";
559 if (!empty($date_start) && !empty($date_end))
560 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
561 } elseif ($modecompta ==
'RECETTES-DEPENSES')
563 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
564 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
565 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
566 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f";
567 $sql .=
" ON pf.fk_facturefourn = f.rowid";
568 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s";
569 $sql .=
" ON f.fk_soc = s.rowid";
570 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
571 if (!empty($date_start) && !empty($date_end))
572 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
575 $sql .=
" AND f.entity = ".$conf->entity;
576 if ($socid) $sql .=
" AND f.fk_soc = ".$socid;
577 $sql .=
" GROUP BY name, socid";
578 $sql .= $db->order($sortfield, $sortorder);
580 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
584 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
585 $result = $db->query($sql);
587 $num = $db->num_rows($result);
593 $objp = $db->fetch_object($result);
595 print '<tr class="oddeven"><td> </td>';
596 print "<td>".$langs->trans(
"Bills").
" <a href=\"".DOL_URL_ROOT.
"/fourn/facture/list.php?socid=".$objp->socid.
"\">".$objp->name.
"</a></td>\n";
598 if ($modecompta ==
'CREANCES-DETTES')
599 print '<td class="right">'.price(-$objp->amount_ht).
"</td>\n";
600 print '<td class="right">'.price(-$objp->amount_ttc).
"</td>\n";
602 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
603 $total_ttc -= $objp->amount_ttc;
604 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
605 $subtotal_ttc += $objp->amount_ttc;
611 print '<tr class="oddeven"><td> </td>';
612 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
621 $total_ht_outcome += $subtotal_ht;
622 $total_ttc_outcome += $subtotal_ttc;
624 print '<tr class="liste_total">';
625 if ($modecompta ==
'CREANCES-DETTES')
626 print '<td colspan="3" class="right">'.price(-$subtotal_ht).
'</td>';
627 print '<td colspan="3" class="right">'.price(-$subtotal_ttc).
'</td>';
635 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsNondeductibles").
'</td></tr>';
637 if ($modecompta ==
'CREANCES-DETTES')
639 $sql =
"SELECT c.id, c.libelle as label, sum(cs.amount) as amount";
640 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
641 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
642 $sql .=
" WHERE cs.fk_type = c.id";
643 $sql .=
" AND c.deductible = 0";
644 if (!empty($date_start) && !empty($date_end))
645 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
646 } elseif ($modecompta ==
'RECETTES-DEPENSES')
648 $sql =
"SELECT c.id, c.libelle as label, sum(p.amount) as amount";
649 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
650 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
651 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
652 $sql .=
" WHERE p.fk_charge = cs.rowid";
653 $sql .=
" AND cs.fk_type = c.id";
654 $sql .=
" AND c.deductible = 0";
655 if (!empty($date_start) && !empty($date_end))
656 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
658 $sql .=
" AND cs.entity = ".$conf->entity;
659 $sql .=
" GROUP BY c.libelle, c.id";
660 $newsortfield = $sortfield;
661 if ($newsortfield ==
's.nom, s.rowid') $newsortfield =
'c.libelle, c.id';
662 if ($newsortfield ==
'amount_ht') $newsortfield =
'amount';
663 if ($newsortfield ==
'amount_ttc') $newsortfield =
'amount';
665 $sql .= $db->order($newsortfield, $sortorder);
667 dol_syslog(
"get social contributions deductible=0", LOG_DEBUG);
668 $result = $db->query($sql);
672 $num = $db->num_rows($result);
676 $obj = $db->fetch_object($result);
678 $total_ht -= $obj->amount;
679 $total_ttc -= $obj->amount;
680 $subtotal_ht += $obj->amount;
681 $subtotal_ttc += $obj->amount;
683 print '<tr class="oddeven"><td> </td>';
684 print '<td>'.$obj->label.
'</td>';
685 if ($modecompta ==
'CREANCES-DETTES')
print '<td class="right">'.price(-$obj->amount).
'</td>';
686 print '<td class="right">'.price(-$obj->amount).
'</td>';
691 print '<tr class="oddeven"><td> </td>';
692 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
699 $total_ht_outcome += $subtotal_ht;
700 $total_ttc_outcome += $subtotal_ttc;
702 print '<tr class="liste_total">';
703 if ($modecompta ==
'CREANCES-DETTES')
704 print '<td colspan="3" class="right">'.price(-$subtotal_ht).
'</td>';
705 print '<td colspan="3" class="right">'.price(-$subtotal_ttc).
'</td>';
713 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsDeductibles").
'</td></tr>';
715 if ($modecompta ==
'CREANCES-DETTES')
717 $sql =
"SELECT c.id, c.libelle as label, sum(cs.amount) as amount";
718 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
719 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
720 $sql .=
" WHERE cs.fk_type = c.id";
721 $sql .=
" AND c.deductible = 1";
722 if (!empty($date_start) && !empty($date_end))
723 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
724 $sql .=
" AND cs.entity = ".$conf->entity;
725 } elseif ($modecompta ==
'RECETTES-DEPENSES')
727 $sql =
"SELECT c.id, c.libelle as label, sum(p.amount) as amount";
728 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
729 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
730 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
731 $sql .=
" WHERE p.fk_charge = cs.rowid";
732 $sql .=
" AND cs.fk_type = c.id";
733 $sql .=
" AND c.deductible = 1";
734 if (!empty($date_start) && !empty($date_end))
735 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
736 $sql .=
" AND cs.entity = ".$conf->entity;
738 $sql .=
" GROUP BY c.libelle, c.id";
739 $newsortfield = $sortfield;
740 if ($newsortfield ==
's.nom, s.rowid') $newsortfield =
'c.libelle, c.id';
741 if ($newsortfield ==
'amount_ht') $newsortfield =
'amount';
742 if ($newsortfield ==
'amount_ttc') $newsortfield =
'amount';
743 $sql .= $db->order($newsortfield, $sortorder);
745 dol_syslog(
"get social contributions deductible=1", LOG_DEBUG);
746 $result = $db->query($sql);
750 $num = $db->num_rows($result);
754 $obj = $db->fetch_object($result);
756 $total_ht -= $obj->amount;
757 $total_ttc -= $obj->amount;
758 $subtotal_ht += $obj->amount;
759 $subtotal_ttc += $obj->amount;
761 print '<tr class="oddeven"><td> </td>';
762 print '<td>'.$obj->label.
'</td>';
763 if ($modecompta ==
'CREANCES-DETTES')
764 print '<td class="right">'.price(-$obj->amount).
'</td>';
765 print '<td class="right">'.price(-$obj->amount).
'</td>';
770 print '<tr class="oddeven"><td> </td>';
771 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
778 $total_ht_outcome += $subtotal_ht;
779 $total_ttc_outcome += $subtotal_ttc;
781 print '<tr class="liste_total">';
782 if ($modecompta ==
'CREANCES-DETTES')
783 print '<td colspan="3" class="right">'.price(-$subtotal_ht).
'</td>';
784 print '<td colspan="3" class="right">'.price(-$subtotal_ttc).
'</td>';
792 if (!empty($conf->salaries->enabled))
794 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
796 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES')
798 if ($modecompta ==
'CREANCES-DETTES') {
804 $sql =
"SELECT u.rowid, u.firstname, u.lastname, p.fk_user, p.label as label, date_format($column,'%Y-%m') as dm, sum(p.amount) as amount";
805 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
806 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user";
807 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
808 if (!empty($date_start) && !empty($date_end))
809 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
811 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, p.fk_user, p.label, dm";
812 $newsortfield = $sortfield;
813 if ($newsortfield ==
's.nom, s.rowid') $newsortfield =
'u.firstname, u.lastname';
814 if ($newsortfield ==
'amount_ht') $newsortfield =
'amount';
815 if ($newsortfield ==
'amount_ttc') $newsortfield =
'amount';
816 $sql .= $db->order($newsortfield, $sortorder);
820 $result = $db->query($sql);
825 $num = $db->num_rows($result);
831 $obj = $db->fetch_object($result);
833 $total_ht -= $obj->amount;
834 $total_ttc -= $obj->amount;
835 $subtotal_ht += $obj->amount;
836 $subtotal_ttc += $obj->amount;
838 print '<tr class="oddeven"><td> </td>';
840 print "<td>".$langs->trans(
"Salary").
" <a href=\"".DOL_URL_ROOT.
"/salaries/list.php?filtre=s.fk_user=".$obj->fk_user.
"\">".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
842 if ($modecompta ==
'CREANCES-DETTES')
print '<td class="right">'.price(-$obj->amount).
'</td>';
843 print '<td class="right">'.price(-$obj->amount).
'</td>';
848 print '<tr class="oddeven"><td> </td>';
849 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
856 $total_ht_outcome += $subtotal_ht;
857 $total_ttc_outcome += $subtotal_ttc;
859 print '<tr class="liste_total">';
860 if ($modecompta ==
'CREANCES-DETTES')
861 print '<td colspan="3" class="right">'.price(-$subtotal_ht).
'</td>';
862 print '<td colspan="3" class="right">'.price(-$subtotal_ttc).
'</td>';
871 if (!empty($conf->expensereport->enabled))
873 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES')
875 $langs->load(
'trips');
876 if ($modecompta ==
'CREANCES-DETTES') {
877 $sql =
"SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
878 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
879 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
880 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
881 $sql .=
" AND p.fk_statut>=5";
883 $column =
'p.date_valid';
885 $sql =
"SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht, sum(p.total_ttc) as amount_ttc";
886 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
887 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
888 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
889 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
890 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
891 $sql .=
" AND p.fk_statut>=5";
893 $column =
'pe.datep';
896 if (!empty($date_start) && !empty($date_end))
898 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
901 $sql .=
" GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
902 $newsortfield = $sortfield;
903 if ($newsortfield ==
's.nom, s.rowid') $newsortfield =
'p.ref';
904 $sql .= $db->order($newsortfield, $sortorder);
907 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
910 $result = $db->query($sql);
915 $num = $db->num_rows($result);
918 while ($obj = $db->fetch_object($result))
920 $total_ht -= $obj->amount_ht;
921 $total_ttc -= $obj->amount_ttc;
922 $subtotal_ht += $obj->amount_ht;
923 $subtotal_ttc += $obj->amount_ttc;
925 print '<tr class="oddeven"><td> </td>';
927 print "<td>".$langs->trans(
"ExpenseReport").
" <a href=\"".DOL_URL_ROOT.
"/expensereport/list.php?search_user=".$obj->userid.
"\">".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
929 if ($modecompta ==
'CREANCES-DETTES')
print '<td class="right">'.price(-$obj->amount_ht).
'</td>';
930 print '<td class="right">'.price(-$obj->amount_ttc).
'</td>';
934 print '<tr class="oddeven"><td> </td>';
935 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
942 $total_ht_outcome += $subtotal_ht;
943 $total_ttc_outcome += $subtotal_ttc;
945 print '<tr class="liste_total">';
946 if ($modecompta ==
'CREANCES-DETTES')
print '<td colspan="3" class="right">'.price(-$subtotal_ht).
'</td>';
947 print '<td colspan="3" class="right">'.price(-$subtotal_ttc).
'</td>';
957 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->banque->enabled) && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES"))
962 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
965 $sql =
"SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
966 $sql .=
' WHERE 1 = 1';
967 if (!empty($date_start) && !empty($date_end))
968 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
969 $sql .=
' GROUP BY p.sens';
970 $sql .=
' ORDER BY p.sens';
972 dol_syslog(
'get various payments', LOG_DEBUG);
973 $result = $db->query($sql);
977 $obj = $db->fetch_object($result);
978 if (isset($obj->amount))
980 $subtotal_ht += -$obj->amount;
981 $subtotal_ttc += -$obj->amount;
983 $total_ht_outcome += $obj->amount;
984 $total_ttc_outcome += $obj->amount;
986 print '<tr class="oddeven"><td> </td>';
987 print "<td>".$langs->trans(
"Debit").
"</td>\n";
988 if ($modecompta ==
'CREANCES-DETTES')
print '<td class="right">'.price(-$obj->amount).
'</td>';
989 print '<td class="right">'.price(-$obj->amount).
"</td>\n";
993 $obj = $db->fetch_object($result);
994 if (isset($obj->amount))
996 $subtotal_ht += $obj->amount;
997 $subtotal_ttc += $obj->amount;
999 $total_ht_income += $obj->amount;
1000 $total_ttc_income += $obj->amount;
1002 print '<tr class="oddeven"><td> </td>';
1003 print "<td>".$langs->trans(
"Credit").
"</td>\n";
1004 if ($modecompta ==
'CREANCES-DETTES')
print '<td class="right">'.price($obj->amount).
'</td>';
1005 print '<td class="right">'.price($obj->amount).
"</td>\n";
1009 $total_ht += $subtotal_ht;
1010 $total_ttc += $subtotal_ttc;
1011 print '<tr class="liste_total">';
1012 if ($modecompta ==
'CREANCES-DETTES')
1013 print '<td colspan="3" class="right">'.price($subtotal_ht).
'</td>';
1014 print '<td colspan="3" class="right">'.price($subtotal_ttc).
'</td>';
1023 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) && !empty($conf->loan->enabled) && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES"))
1028 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
1030 $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';
1031 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
1032 $sql .=
' WHERE 1 = 1';
1033 if (!empty($date_start) && !empty($date_end))
1034 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1035 $sql .=
' GROUP BY p.fk_loan';
1036 $sql .=
' ORDER BY p.fk_loan';
1039 $result = $db->query($sql);
1042 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
1043 $loan_static =
new Loan($db);
1044 while ($obj = $db->fetch_object($result))
1046 $loan_static->id = $obj->id;
1047 $loan_static->ref = $obj->id;
1048 $loan_static->label = $obj->label;
1049 print '<tr class="oddeven"><td> </td>';
1050 print "<td>".$loan_static->getNomUrl(1).
' - '.$obj->label.
"</td>\n";
1051 if ($modecompta ==
'CREANCES-DETTES')
print '<td class="right">'.price(-$obj->amount).
'</td>';
1052 print '<td class="right">'.price(-$obj->amount).
"</td>\n";
1054 $subtotal_ht -= $obj->amount;
1055 $subtotal_ttc -= $obj->amount;
1057 $total_ht += $subtotal_ht;
1058 $total_ttc += $subtotal_ttc;
1060 $total_ht_income += $subtotal_ht;
1061 $total_ttc_income += $subtotal_ttc;
1063 print '<tr class="liste_total">';
1064 if ($modecompta ==
'CREANCES-DETTES')
1065 print '<td colspan="3" class="right">'.price($subtotal_ht).
'</td>';
1066 print '<td colspan="3" class="right">'.price($subtotal_ttc).
'</td>';
1075 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VAT").
'</td></tr>';
1079 if ($conf->tax->enabled && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES'))
1081 if ($modecompta ==
'CREANCES-DETTES')
1085 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.tva) as amount";
1086 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1087 $sql .=
" WHERE f.fk_statut IN (1,2)";
1088 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
1089 $sql .=
" AND f.type IN (0,1,2,5)";
1090 else $sql .=
" AND f.type IN (0,1,2,3,5)";
1091 if (!empty($date_start) && !empty($date_end))
1092 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1093 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
1094 $sql .=
" GROUP BY dm";
1095 $newsortfield = $sortfield;
1096 if ($newsortfield ==
's.nom, s.rowid') $newsortfield =
'dm';
1097 if ($newsortfield ==
'amount_ht') $newsortfield =
'amount';
1098 if ($newsortfield ==
'amount_ttc') $newsortfield =
'amount';
1099 $sql .= $db->order($newsortfield, $sortorder);
1102 $result = $db->query($sql);
1105 $num = $db->num_rows($result);
1111 $obj = $db->fetch_object($result);
1113 $amount -= $obj->amount;
1115 $total_ttc -= $obj->amount;
1117 $subtotal_ttc -= $obj->amount;
1125 $total_ht_outcome -= 0;
1126 $total_ttc_outcome -= $amount;
1128 print '<tr class="oddeven"><td> </td>';
1129 print "<td>".$langs->trans(
"VATToPay").
"</td>\n";
1130 print '<td class="right"> </td>'.
"\n";
1131 print '<td class="right">'.price($amount).
"</td>\n";
1136 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1137 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1138 $sql .=
" WHERE f.fk_statut IN (1,2)";
1139 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
1140 $sql .=
" AND f.type IN (0,1,2)";
1141 else $sql .=
" AND f.type IN (0,1,2,3)";
1142 if (!empty($date_start) && !empty($date_end))
1143 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1144 $sql .=
" AND f.entity = ".$conf->entity;
1145 $sql .=
" GROUP BY dm";
1146 $newsortfield = $sortfield;
1147 if ($newsortfield ==
's.nom, s.rowid') $newsortfield =
'dm';
1148 if ($newsortfield ==
'amount_ht') $newsortfield =
'amount';
1149 if ($newsortfield ==
'amount_ttc') $newsortfield =
'amount';
1150 $sql .= $db->order($newsortfield, $sortorder);
1152 dol_syslog(
"get vat received back", LOG_DEBUG);
1153 $result = $db->query($sql);
1156 $num = $db->num_rows($result);
1162 $obj = $db->fetch_object($result);
1164 $amount += $obj->amount;
1166 $total_ttc += $obj->amount;
1168 $subtotal_ttc += $obj->amount;
1177 $total_ht_income += 0;
1178 $total_ttc_income += $amount;
1180 print '<tr class="oddeven"><td> </td>';
1181 print '<td>'.$langs->trans(
"VATToCollect").
"</td>\n";
1182 print '<td class="right"> </td>'.
"\n";
1183 print '<td class="right">'.price($amount).
"</td>\n";
1188 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1189 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1190 $sql .=
" WHERE amount > 0";
1191 if (!empty($date_start) && !empty($date_end))
1192 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1193 $sql .=
" AND t.entity = ".$conf->entity;
1194 $sql .=
" GROUP BY dm";
1195 $newsortfield = $sortfield;
1196 if ($newsortfield ==
's.nom, s.rowid') $newsortfield =
'dm';
1197 if ($newsortfield ==
'amount_ht') $newsortfield =
'amount';
1198 if ($newsortfield ==
'amount_ttc') $newsortfield =
'amount';
1199 $sql .= $db->order($newsortfield, $sortorder);
1201 dol_syslog(
"get vat really paid", LOG_DEBUG);
1202 $result = $db->query($sql);
1204 $num = $db->num_rows($result);
1208 $obj = $db->fetch_object($result);
1210 $amount -= $obj->amount;
1211 $total_ht -= $obj->amount;
1212 $total_ttc -= $obj->amount;
1213 $subtotal_ht -= $obj->amount;
1214 $subtotal_ttc -= $obj->amount;
1224 $total_ht_outcome -= 0;
1225 $total_ttc_outcome -= $amount;
1227 print '<tr class="oddeven"><td> </td>';
1228 print "<td>".$langs->trans(
"VATPaid").
"</td>\n";
1229 if ($modecompta ==
'CREANCES-DETTES')
1230 print '<td <class="right"></td>'.
"\n";
1231 print '<td class="right">'.price($amount).
"</td>\n";
1236 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1237 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1238 $sql .=
" WHERE amount < 0";
1239 if (!empty($date_start) && !empty($date_end))
1240 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1241 $sql .=
" AND t.entity = ".$conf->entity;
1242 $sql .=
" GROUP BY dm";
1243 $newsortfield = $sortfield;
1244 if ($newsortfield ==
's.nom, s.rowid') $newsortfield =
'dm';
1245 if ($newsortfield ==
'amount_ht') $newsortfield =
'amount';
1246 if ($newsortfield ==
'amount_ttc') $newsortfield =
'amount';
1247 $sql .= $db->order($newsortfield, $sortorder);
1249 dol_syslog(
"get vat really received back", LOG_DEBUG);
1250 $result = $db->query($sql);
1252 $num = $db->num_rows($result);
1256 $obj = $db->fetch_object($result);
1258 $amount += -$obj->amount;
1259 $total_ht += -$obj->amount;
1260 $total_ttc += -$obj->amount;
1261 $subtotal_ht += -$obj->amount;
1262 $subtotal_ttc += -$obj->amount;
1272 $total_ht_income += 0;
1273 $total_ttc_income += $amount;
1275 print '<tr class="oddeven"><td> </td>';
1276 print "<td>".$langs->trans(
"VATCollected").
"</td>\n";
1277 if ($modecompta ==
'CREANCES-DETTES')
1278 print '<td class="right"></td>'.
"\n";
1279 print '<td class="right">'.price($amount).
"</td>\n";
1284 if ($mysoc->tva_assuj !=
'0')
1286 print '<tr class="liste_total">';
1287 if ($modecompta ==
'CREANCES-DETTES')
1288 print '<td colspan="3" class="right"> </td>';
1289 print '<td colspan="3" class="right">'.price(
price2num($subtotal_ttc,
'MT')).
'</td>';
1294 $action =
"balanceclient";
1295 $object = array(&$total_ht, &$total_ttc);
1296 $parameters[
"mode"] = $modecompta;
1297 $parameters[
"date_start"] = $date_start;
1298 $parameters[
"date_end"] = $date_end;
1300 $hookmanager->initHooks(array(
'externalbalance'));
1301 $reshook = $hookmanager->executeHooks(
'addBalanceLine', $parameters, $object, $action);
1302 print $hookmanager->resPrint;
1306 print '<td colspan="4"> </td>';
1309 print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1310 if ($modecompta ==
'CREANCES-DETTES') {
1311 print '<td class="liste_total right">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1313 print '<td class="liste_total right">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1315 print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1316 if ($modecompta ==
'CREANCES-DETTES') {
1317 print '<td class="liste_total right">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1319 print '<td class="liste_total right">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1321 print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1322 if ($modecompta ==
'CREANCES-DETTES') {
1323 print '<td class="liste_total right">'.price(
price2num($total_ht,
'MT')).
'</td>';
1325 print '<td class="liste_total right">'.price(
price2num($total_ttc,
'MT')).
'</td>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_now($mode= 'auto')
Return date for now.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Class to manage categories of an accounting account.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
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.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
print
Draft customers invoices.
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.