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 =
GETPOST(
'date_startmonth',
'int');
50$date_startday =
GETPOST(
'date_startday',
'int');
51$date_startyear =
GETPOST(
'date_startyear',
'int');
52$date_endmonth =
GETPOST(
'date_endmonth',
'int');
53$date_endday =
GETPOST(
'date_endday',
'int');
54$date_endyear =
GETPOST(
'date_endyear',
'int');
55$showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'yes';
57$limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
58$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
59$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
60$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
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;
94 if (!$year && $month_start > $month_current) {
99 $month_end = $month_start - 1;
100 $year_end = $year_start + 1;
102 if ($month_end < 1) {
106 $month_end = $month_start;
131$year_start = $tmps[
'year'];
133$year_end = $tmpe[
'year'];
134$nbofyear = ($year_end - $year_start) + 1;
138$modecompta = $conf->global->ACCOUNTING_MODE;
139if (isModEnabled(
'accounting')) {
140 $modecompta =
'BOOKKEEPING';
142if (
GETPOST(
"modecompta",
'alpha')) {
143 $modecompta =
GETPOST(
"modecompta",
'alpha');
149$socid =
GETPOST(
'socid',
'int');
150if ($user->socid > 0) {
151 $socid = $user->socid;
153if (isModEnabled(
'comptabilite')) {
156if (isModEnabled(
'accounting')) {
157 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
159$hookmanager->initHooks([
'customersupplierreportlist']);
168$form =
new Form($db);
177if ($modecompta ==
"CREANCES-DETTES") {
178 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
179 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
180 $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>" :
"");
181 $description = $langs->trans(
"RulesResultDue");
182 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
183 $description .= $langs->trans(
"DepositsAreNotIncluded");
185 $description .= $langs->trans(
"DepositsAreIncluded");
187 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
188 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
192} elseif ($modecompta ==
"RECETTES-DEPENSES") {
193 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
194 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
195 $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>" :
"");
196 $description = $langs->trans(
"RulesResultInOut");
199} elseif ($modecompta ==
"BOOKKEEPING") {
200 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPredefinedAccountGroups");
201 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
202 $arraylist = array(
'no'=>$langs->trans(
"CustomerCode"),
'yes'=>$langs->trans(
"AccountWithNonZeroValues"),
'all'=>$langs->trans(
"All"));
203 $period .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
204 $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>" :
"");
205 $description = $langs->trans(
"RulesResultBookkeepingPredefined");
206 $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")).
')';
213if (isModEnabled(
'accounting')) {
214 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
217$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModeEngagement");
218if (isModEnabled(
'accounting')) {
219 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
221$calcmode .=
'</label>';
222$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
223if (isModEnabled(
'accounting')) {
224 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
226$calcmode .=
'</label>';
229report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta,
'showaccountdetail'=>$showaccountdetail), $calcmode);
231if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
232 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
236$param =
'&modecompta='.urlencode($modecompta).
'&showaccountdetail='.urlencode($showaccountdetail);
238 $param .=
'&date_startday='.$date_startday;
240if ($date_startmonth) {
241 $param .=
'&date_startmonth='.$date_startmonth;
243if ($date_startyear) {
244 $param .=
'&date_startyear='.$date_startyear;
247 $param .=
'&date_endday='.$date_endday;
250 $param .=
'&date_endmonth='.$date_endmonth;
253 $param .=
'&date_endyear='.$date_endyear;
256print
'<table class="liste noborder centpercent">';
257print
'<tr class="liste_titre">';
259if ($modecompta ==
'BOOKKEEPING') {
260 print_liste_field_titre(
"PredefinedGroups", $_SERVER[
"PHP_SELF"],
'f.thirdparty_code,f.rowid',
'', $param,
'', $sortfield, $sortorder,
'width200 ');
265if ($modecompta ==
'BOOKKEEPING') {
266 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
'amount',
'', $param,
'class="right"', $sortfield, $sortorder);
268 if ($modecompta ==
'CREANCES-DETTES') {
269 print_liste_field_titre(
"AmountHT", $_SERVER[
"PHP_SELF"],
'amount_ht',
'', $param,
'class="right"', $sortfield, $sortorder);
273 print_liste_field_titre(
"AmountTTC", $_SERVER[
"PHP_SELF"],
'amount_ttc',
'', $param,
'class="right"', $sortfield, $sortorder);
278$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
281if ($modecompta ==
'BOOKKEEPING') {
282 $predefinedgroupwhere =
"(";
283 $predefinedgroupwhere .=
" (pcg_type = 'EXPENSE')";
284 $predefinedgroupwhere .=
" OR ";
285 $predefinedgroupwhere .=
" (pcg_type = 'INCOME')";
286 $predefinedgroupwhere .=
")";
291 $sql =
"SELECT -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount";
292 if ($showaccountdetail ==
'no') {
293 $sql .=
", f.thirdparty_code as name";
295 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as f";
296 $sql .=
", ".MAIN_DB_PREFIX.
"accounting_account as aa";
297 $sql .=
" WHERE f.numero_compte = aa.account_number";
298 $sql .=
" AND ".$predefinedgroupwhere;
299 $sql .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
300 $sql .=
" AND f.entity = ".$conf->entity;
301 if (!empty($date_start) && !empty($date_end)) {
302 $sql .=
" AND f.doc_date >= '".$db->idate($date_start).
"' AND f.doc_date <= '".$db->idate($date_end).
"'";
304 $sql .=
" GROUP BY pcg_type";
305 if ($showaccountdetail ==
'no') {
306 $sql .=
", name, socid";
308 $sql .= $db->order($sortfield, $sortorder);
312 dol_syslog(
"get bookkeeping entries", LOG_DEBUG);
313 $result = $db->query($sql);
315 $num = $db->num_rows($result);
319 $objp = $db->fetch_object($result);
321 if ($showaccountdetail ==
'no') {
322 if ($objp->pcg_type != $oldpcgtype) {
323 print
'<tr class="trforbreak"><td colspan="3" class="tdforbreak">'.dol_escape_htmltag($objp->pcg_type).
'</td></tr>';
324 $oldpcgtype = $objp->pcg_type;
328 if ($showaccountdetail ==
'no') {
329 print
'<tr class="oddeven">';
333 print ($objp->name ?
' ('.dol_escape_htmltag($objp->name).
')' :
' ('.$langs->trans(
"Unknown").
')');
335 print
'<td class="right nowraponall"><span class="amount">'.price($objp->amount).
"</span></td>\n";
338 print
'<tr class="oddeven trforbreak">';
339 print
'<td colspan="2" class="tdforbreak">';
342 print
'<td class="right nowraponall tdforbreak"><span class="amount">'.price($objp->amount).
"</span></td>\n";
346 $total_ht += (isset($objp->amount) ? $objp->amount : 0);
347 $total_ttc += (isset($objp->amount) ? $objp->amount : 0);
349 if ($objp->pcg_type ==
'INCOME') {
350 $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
351 $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
353 if ($objp->pcg_type ==
'EXPENSE') {
354 $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
355 $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
360 if ($showaccountdetail !=
'no') {
361 $tmppredefinedgroupwhere =
"pcg_type = '".$db->escape($objp->pcg_type).
"'";
362 $tmppredefinedgroupwhere .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
366 $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
368 foreach ($cpts as $j => $cpt) {
369 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, (empty($cpt[
'dc']) ? 0 : $cpt[
'dc']));
374 $resultN = $AccCat->sdc;
378 if ($showaccountdetail ==
'all' || $resultN <> 0) {
381 print
'<td class="tdoverflowmax200"> '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'].
'</td>';
382 print
'<td class="right nowraponall"><span class="amount">'.price($resultN).
'</span></td>';
391 print
'<tr><td colspan="3" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';
400 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"CustomersInvoices").
'</td></tr>';
402 if ($modecompta ==
'CREANCES-DETTES') {
403 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
404 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
405 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
406 $sql .=
" WHERE f.fk_soc = s.rowid";
407 $sql .=
" AND f.fk_statut IN (1,2)";
408 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
409 $sql .=
" AND f.type IN (0,1,2,5)";
411 $sql .=
" AND f.type IN (0,1,2,3,5)";
413 if (!empty($date_start) && !empty($date_end)) {
414 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
416 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
421 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
422 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
423 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
424 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
425 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
426 $sql .=
" WHERE p.rowid = pf.fk_paiement";
427 $sql .=
" AND pf.fk_facture = f.rowid";
428 $sql .=
" AND f.fk_soc = s.rowid";
429 if (!empty($date_start) && !empty($date_end)) {
430 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
433 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
435 $sql .=
" AND f.fk_soc = ".((int) $socid);
437 $sql .=
" GROUP BY name, socid";
438 $sql .= $db->order($sortfield, $sortorder);
440 dol_syslog(
"get customer invoices", LOG_DEBUG);
441 $result = $db->query($sql);
443 $num = $db->num_rows($result);
446 $objp = $db->fetch_object($result);
448 print
'<tr class="oddeven">';
449 print
'<td> </td>';
450 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$objp->socid.
'">'.$objp->name.
"</td>\n";
452 print
'<td class="right">';
453 if ($modecompta ==
'CREANCES-DETTES') {
454 print
'<span class="amount">'.price($objp->amount_ht).
"</span>";
457 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
459 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
460 $total_ttc += $objp->amount_ttc;
470 if ($modecompta ==
'RECETTES-DEPENSES') {
471 $sql =
"SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc";
472 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
473 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
474 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
475 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
476 $sql .=
" WHERE pf.rowid IS NULL";
477 $sql .=
" AND p.fk_bank = b.rowid";
478 $sql .=
" AND b.fk_account = ba.rowid";
479 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
480 if (!empty($date_start) && !empty($date_end)) {
481 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
483 $sql .=
" GROUP BY name, idp";
484 $sql .=
" ORDER BY name";
486 dol_syslog(
"get old customer payments not linked to invoices", LOG_DEBUG);
487 $result = $db->query($sql);
489 $num = $db->num_rows($result);
493 $objp = $db->fetch_object($result);
496 print
'<tr class="oddeven">';
497 print
'<td> </td>';
498 print
"<td>".$langs->trans(
"Bills").
" ".$langs->trans(
"Other").
" (".$langs->trans(
"PaymentsNotLinkedToInvoice").
")\n";
500 print
'<td class="right">';
501 if ($modecompta ==
'CREANCES-DETTES') {
502 print
'<span class="amount">'.price($objp->amount_ht).
"</span></td>\n";
505 print
'<td class="right"><span class="amount">'.price($objp->amount_ttc).
"</span></td>\n";
507 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
508 $total_ttc += $objp->amount_ttc;
520 if ($total_ttc == 0) {
521 print
'<tr class="oddeven">';
522 print
'<td> </td>';
523 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
527 $total_ht_income += $total_ht;
528 $total_ttc_income += $total_ttc;
530 print
'<tr class="liste_total">';
533 print
'<td class="right">';
534 if ($modecompta ==
'CREANCES-DETTES') {
535 print
price($total_ht);
538 print
'<td class="right">'.price($total_ttc).
'</td>';
545 if (isModEnabled(
'don')) {
546 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Donations").
'</td></tr>';
548 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
549 if ($modecompta ==
'CREANCES-DETTES') {
550 $sql =
"SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
551 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
552 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
553 $sql .=
" AND fk_statut in (1,2)";
555 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
556 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
557 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
558 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
559 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
560 $sql .=
" AND fk_statut >= 2";
562 if (!empty($date_start) && !empty($date_end)) {
563 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
566 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
567 $newsortfield = $sortfield;
568 if ($newsortfield ==
's.nom, s.rowid') {
569 $newsortfield =
'p.societe, p.firstname, p.lastname, dm';
571 if ($newsortfield ==
'amount_ht') {
572 $newsortfield =
'amount';
574 if ($newsortfield ==
'amount_ttc') {
575 $newsortfield =
'amount';
577 $sql .= $db->order($newsortfield, $sortorder);
580 $result = $db->query($sql);
584 $num = $db->num_rows($result);
588 $obj = $db->fetch_object($result);
590 $total_ht += $obj->amount;
591 $total_ttc += $obj->amount;
592 $subtotal_ht += $obj->amount;
593 $subtotal_ttc += $obj->amount;
595 print
'<tr class="oddeven">';
596 print
'<td> </td>';
598 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";
600 print
'<td class="right">';
601 if ($modecompta ==
'CREANCES-DETTES') {
602 print
'<span class="amount">'.price($obj->amount).
'</span>';
605 print
'<td class="right"><span class="amount">'.price($obj->amount).
'</span></td>';
610 print
'<tr class="oddeven"><td> </td>';
611 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
618 $total_ht_income += $subtotal_ht;
619 $total_ttc_income += $subtotal_ttc;
621 print
'<tr class="liste_total">';
624 print
'<td class="right">';
625 if ($modecompta ==
'CREANCES-DETTES') {
626 print
price($subtotal_ht);
629 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
636 if ($modecompta ==
'CREANCES-DETTES') {
637 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
638 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
639 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
640 $sql .=
" WHERE f.fk_soc = s.rowid";
641 $sql .=
" AND f.fk_statut IN (1,2)";
642 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
643 $sql .=
" AND f.type IN (0,1,2)";
645 $sql .=
" AND f.type IN (0,1,2,3)";
647 if (!empty($date_start) && !empty($date_end)) {
648 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
650 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
651 $sql =
"SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
652 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
653 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
654 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f";
655 $sql .=
" ON pf.fk_facturefourn = f.rowid";
656 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s";
657 $sql .=
" ON f.fk_soc = s.rowid";
658 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn ";
659 if (!empty($date_start) && !empty($date_end)) {
660 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
664 $sql .=
" AND f.entity = ".((int) $conf->entity);
666 $sql .=
" AND f.fk_soc = ".((int) $socid);
668 $sql .=
" GROUP BY name, socid";
669 $sql .= $db->order($sortfield, $sortorder);
671 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SuppliersInvoices").
'</td></tr>';
675 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
676 $result = $db->query($sql);
678 $num = $db->num_rows($result);
682 $objp = $db->fetch_object($result);
684 print
'<tr class="oddeven">';
685 print
'<td> </td>';
686 print
"<td>".$langs->trans(
"Bills").
' <a href="'.DOL_URL_ROOT.
"/fourn/facture/list.php?socid=".$objp->socid.
'">'.$objp->name.
'</a></td>'.
"\n";
688 print
'<td class="right">';
689 if ($modecompta ==
'CREANCES-DETTES') {
690 print
'<span class="amount">'.price(-$objp->amount_ht).
"</span>";
693 print
'<td class="right"><span class="amount">'.price(-$objp->amount_ttc).
"</span></td>\n";
695 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
696 $total_ttc -= $objp->amount_ttc;
697 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
698 $subtotal_ttc += $objp->amount_ttc;
704 print
'<tr class="oddeven">';
705 print
'<td> </td>';
706 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
715 $total_ht_outcome += $subtotal_ht;
716 $total_ttc_outcome += $subtotal_ttc;
718 print
'<tr class="liste_total">';
721 print
'<td class="right">';
722 if ($modecompta ==
'CREANCES-DETTES') {
723 print
price(-$subtotal_ht);
726 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
734 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsNondeductibles").
'</td></tr>';
736 if ($modecompta ==
'CREANCES-DETTES') {
737 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
738 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
739 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
740 $sql .=
" WHERE cs.fk_type = c.id";
741 $sql .=
" AND c.deductible = 0";
742 if (!empty($date_start) && !empty($date_end)) {
743 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
745 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
746 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
747 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
748 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
749 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
750 $sql .=
" WHERE p.fk_charge = cs.rowid";
751 $sql .=
" AND cs.fk_type = c.id";
752 $sql .=
" AND c.deductible = 0";
753 if (!empty($date_start) && !empty($date_end)) {
754 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
757 $sql .=
" AND cs.entity = ".$conf->entity;
758 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
759 $newsortfield = $sortfield;
760 if ($newsortfield ==
's.nom, s.rowid') {
761 $newsortfield =
'c.libelle, c.id';
763 if ($newsortfield ==
'amount_ht') {
764 $newsortfield =
'amount';
766 if ($newsortfield ==
'amount_ttc') {
767 $newsortfield =
'amount';
770 $sql .= $db->order($newsortfield, $sortorder);
772 dol_syslog(
"get social contributions deductible=0", LOG_DEBUG);
773 $result = $db->query($sql);
777 $num = $db->num_rows($result);
781 $obj = $db->fetch_object($result);
783 $total_ht -= $obj->amount;
784 $total_ttc -= $obj->amount;
785 $subtotal_ht += $obj->amount;
786 $subtotal_ttc += $obj->amount;
789 if ($obj->accountancy_code) {
790 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
792 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
793 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
796 print
'<tr class="oddeven">';
797 print
'<td> </td>';
798 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
799 print
'<td class="right">';
800 if ($modecompta ==
'CREANCES-DETTES') {
801 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
804 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
809 print
'<tr class="oddeven">';
810 print
'<td> </td>';
811 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
818 $total_ht_outcome += $subtotal_ht;
819 $total_ttc_outcome += $subtotal_ttc;
821 print
'<tr class="liste_total">';
824 print
'<td class="right">';
825 if ($modecompta ==
'CREANCES-DETTES') {
826 print
price(-$subtotal_ht);
829 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
837 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"SocialContributionsDeductibles").
'</td></tr>';
839 if ($modecompta ==
'CREANCES-DETTES') {
840 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
841 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
842 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
843 $sql .=
" WHERE cs.fk_type = c.id";
844 $sql .=
" AND c.deductible = 1";
845 if (!empty($date_start) && !empty($date_end)) {
846 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
848 $sql .=
" AND cs.entity = ".$conf->entity;
849 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
850 $sql =
"SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
851 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
852 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
853 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
854 $sql .=
" WHERE p.fk_charge = cs.rowid";
855 $sql .=
" AND cs.fk_type = c.id";
856 $sql .=
" AND c.deductible = 1";
857 if (!empty($date_start) && !empty($date_end)) {
858 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
860 $sql .=
" AND cs.entity = ".$conf->entity;
862 $sql .=
" GROUP BY c.libelle, c.id, c.accountancy_code";
863 $newsortfield = $sortfield;
864 if ($newsortfield ==
's.nom, s.rowid') {
865 $newsortfield =
'c.libelle, c.id';
867 if ($newsortfield ==
'amount_ht') {
868 $newsortfield =
'amount';
870 if ($newsortfield ==
'amount_ttc') {
871 $newsortfield =
'amount';
873 $sql .= $db->order($newsortfield, $sortorder);
875 dol_syslog(
"get social contributions deductible=1", LOG_DEBUG);
876 $result = $db->query($sql);
880 $num = $db->num_rows($result);
884 $obj = $db->fetch_object($result);
886 $total_ht -= $obj->amount;
887 $total_ttc -= $obj->amount;
888 $subtotal_ht += $obj->amount;
889 $subtotal_ttc += $obj->amount;
892 if ($obj->accountancy_code) {
893 $titletoshow = $langs->trans(
"AccountingCode").
': '.$obj->accountancy_code;
895 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
896 $titletoshow .=
' - '.$langs->trans(
"AccountingCategory").
': '.$tmpaccountingaccount->pcg_type;
899 print
'<tr class="oddeven">';
900 print
'<td> </td>';
901 print
'<td'.($obj->accountancy_code ?
' title="'.dol_escape_htmltag($titletoshow).
'"' :
'').
'>'.
dol_escape_htmltag($obj->label).
'</td>';
902 print
'<td class="right">';
903 if ($modecompta ==
'CREANCES-DETTES') {
904 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
907 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
912 print
'<tr class="oddeven">';
913 print
'<td> </td>';
914 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
921 $total_ht_outcome += $subtotal_ht;
922 $total_ttc_outcome += $subtotal_ttc;
924 print
'<tr class="liste_total">';
927 print
'<td class="right">';
928 if ($modecompta ==
'CREANCES-DETTES') {
929 print
price(-$subtotal_ht);
932 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
940 if (isModEnabled(
'salaries')) {
941 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"Salaries").
'</td></tr>';
943 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
944 if ($modecompta ==
'CREANCES-DETTES') {
945 $column =
's.dateep';
947 $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";
948 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
949 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
950 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
951 if (!empty($date_start) && !empty($date_end)) {
952 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
954 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, s.label, dm";
958 $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";
959 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
960 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON s.rowid = p.fk_salary";
961 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = s.fk_user";
962 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
963 if (!empty($date_start) && !empty($date_end)) {
964 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
966 $sql .=
" GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, p.label, dm";
969 $newsortfield = $sortfield;
970 if ($newsortfield ==
's.nom, s.rowid') {
971 $newsortfield =
'u.firstname, u.lastname';
973 if ($newsortfield ==
'amount_ht') {
974 $newsortfield =
'amount';
976 if ($newsortfield ==
'amount_ttc') {
977 $newsortfield =
'amount';
979 $sql .= $db->order($newsortfield, $sortorder);
983 $result = $db->query($sql);
987 $num = $db->num_rows($result);
991 $obj = $db->fetch_object($result);
993 $total_ht -= $obj->amount;
994 $total_ttc -= $obj->amount;
995 $subtotal_ht += $obj->amount;
996 $subtotal_ttc += $obj->amount;
998 print
'<tr class="oddeven"><td> </td>';
1000 $userstatic =
new User($db);
1001 $userstatic->fetch($obj->fk_user);
1003 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";
1004 print
'<td class="right">';
1005 if ($modecompta ==
'CREANCES-DETTES') {
1006 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1009 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1014 print
'<tr class="oddeven">';
1015 print
'<td> </td>';
1016 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1023 $total_ht_outcome += $subtotal_ht;
1024 $total_ttc_outcome += $subtotal_ttc;
1026 print
'<tr class="liste_total">';
1029 print
'<td class="right">';
1030 if ($modecompta ==
'CREANCES-DETTES') {
1031 print
price(-$subtotal_ht);
1034 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1043 if (isModEnabled(
'expensereport')) {
1044 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES') {
1045 $langs->load(
'trips');
1046 if ($modecompta ==
'CREANCES-DETTES') {
1047 $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";
1048 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1049 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1050 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1051 $sql .=
" AND p.fk_statut>=5";
1053 $column =
'p.date_valid';
1055 $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";
1056 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
1057 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
1058 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
1059 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
1060 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
1061 $sql .=
" AND p.fk_statut>=5";
1063 $column =
'pe.datep';
1066 if (!empty($date_start) && !empty($date_end)) {
1067 $sql .=
" AND $column >= '".$db->idate($date_start).
"' AND $column <= '".$db->idate($date_end).
"'";
1070 if ($modecompta ==
'CREANCES-DETTES') {
1073 $sql .=
" GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
1075 $newsortfield = $sortfield;
1076 if ($newsortfield ==
's.nom, s.rowid') {
1077 $newsortfield =
'p.ref';
1079 $sql .= $db->order($newsortfield, $sortorder);
1082 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"ExpenseReport").
'</td></tr>';
1085 $result = $db->query($sql);
1089 $num = $db->num_rows($result);
1091 while ($obj = $db->fetch_object($result)) {
1092 $total_ht -= $obj->amount_ht;
1093 $total_ttc -= $obj->amount_ttc;
1094 $subtotal_ht += $obj->amount_ht;
1095 $subtotal_ttc += $obj->amount_ttc;
1097 print
'<tr class="oddeven">';
1098 print
'<td> </td>';
1099 print
"<td>".$langs->trans(
"ExpenseReport").
" <a href=\"".DOL_URL_ROOT.
"/expensereport/list.php?search_user=".$obj->userid.
"\">".$obj->firstname.
" ".$obj->lastname.
"</a></td>\n";
1100 print
'<td class="right">';
1101 if ($modecompta ==
'CREANCES-DETTES') {
1102 print
'<span class="amount">'.price(-$obj->amount_ht).
'</span>';
1105 print
'<td class="right"><span class="amount">'.price(-$obj->amount_ttc).
'</span></td>';
1109 print
'<tr class="oddeven">';
1110 print
'<td> </td>';
1111 print
'<td colspan="3"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1118 $total_ht_outcome += $subtotal_ht;
1119 $total_ttc_outcome += $subtotal_ttc;
1121 print
'<tr class="liste_total">';
1124 print
'<td class="right">';
1125 if ($modecompta ==
'CREANCES-DETTES') {
1126 print
price(-$subtotal_ht);
1129 print
'<td class="right">'.price(-$subtotal_ttc).
'</td>';
1139 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && isModEnabled(
"banque") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1143 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VariousPayment").
'</td></tr>';
1146 $sql =
"SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
1147 $sql .=
' WHERE 1 = 1';
1148 if (!empty($date_start) && !empty($date_end)) {
1149 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1151 $sql .=
' GROUP BY p.sens';
1152 $sql .=
' ORDER BY p.sens';
1154 dol_syslog(
'get various payments', LOG_DEBUG);
1155 $result = $db->query($sql);
1158 $obj = $db->fetch_object($result);
1159 if (isset($obj->amount)) {
1160 $subtotal_ht += -$obj->amount;
1161 $subtotal_ttc += -$obj->amount;
1163 $total_ht_outcome += $obj->amount;
1164 $total_ttc_outcome += $obj->amount;
1166 print
'<tr class="oddeven">';
1167 print
'<td> </td>';
1168 print
"<td>".$langs->trans(
"AccountingDebit").
"</td>\n";
1169 print
'<td class="right">';
1170 if ($modecompta ==
'CREANCES-DETTES') {
1171 print
'<span class="amount">'.price(-$obj->amount).
'</span>';
1174 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1178 $obj = $db->fetch_object($result);
1179 if (isset($obj->amount)) {
1180 $subtotal_ht += $obj->amount;
1181 $subtotal_ttc += $obj->amount;
1183 $total_ht_income += $obj->amount;
1184 $total_ttc_income += $obj->amount;
1186 print
'<tr class="oddeven"><td> </td>';
1187 print
"<td>".$langs->trans(
"AccountingCredit").
"</td>\n";
1188 print
'<td class="right">';
1189 if ($modecompta ==
'CREANCES-DETTES') {
1190 print
'<span class="amount">'.price($obj->amount).
'</span>';
1193 print
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
1197 $total_ht += $subtotal_ht;
1198 $total_ttc += $subtotal_ttc;
1199 print
'<tr class="liste_total">';
1202 print
'<td class="right">';
1203 if ($modecompta ==
'CREANCES-DETTES') {
1204 print
price($subtotal_ht);
1207 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1218 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) && isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
1222 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"PaymentLoan").
'</td></tr>';
1224 $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';
1225 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'loan AS l ON l.rowid = p.fk_loan';
1226 $sql .=
' WHERE 1 = 1';
1227 if (!empty($date_start) && !empty($date_end)) {
1228 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
1230 $sql .=
' GROUP BY p.fk_loan';
1231 $sql .=
' ORDER BY p.fk_loan';
1234 $result = $db->query($sql);
1236 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
1237 $loan_static =
new Loan($db);
1238 while ($obj = $db->fetch_object($result)) {
1239 $loan_static->id = $obj->id;
1240 $loan_static->ref = $obj->id;
1241 $loan_static->label = $obj->label;
1242 print
'<tr class="oddeven"><td> </td>';
1243 print
"<td>".$loan_static->getNomUrl(1).
' - '.$obj->label.
"</td>\n";
1244 if ($modecompta ==
'CREANCES-DETTES') {
1245 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
'</span></td>';
1247 print
'<td class="right"><span class="amount">'.price(-$obj->amount).
"</span></td>\n";
1249 $subtotal_ht -= $obj->amount;
1250 $subtotal_ttc -= $obj->amount;
1252 $total_ht += $subtotal_ht;
1253 $total_ttc += $subtotal_ttc;
1255 $total_ht_income += $subtotal_ht;
1256 $total_ttc_income += $subtotal_ttc;
1258 print
'<tr class="liste_total">';
1261 print
'<td class="right">';
1262 if ($modecompta ==
'CREANCES-DETTES') {
1263 print
price($subtotal_ht);
1266 print
'<td class="right">'.price($subtotal_ttc).
'</td>';
1277 print
'<tr class="trforbreak"><td colspan="4">'.$langs->trans(
"VAT").
'</td></tr>';
1281 if (isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'RECETTES-DEPENSES')) {
1282 if ($modecompta ==
'CREANCES-DETTES') {
1285 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1286 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1287 $sql .=
" WHERE f.fk_statut IN (1,2)";
1288 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
1289 $sql .=
" AND f.type IN (0,1,2,5)";
1291 $sql .=
" AND f.type IN (0,1,2,3,5)";
1293 if (!empty($date_start) && !empty($date_end)) {
1294 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1296 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
1297 $sql .=
" GROUP BY dm";
1298 $newsortfield = $sortfield;
1299 if ($newsortfield ==
's.nom, s.rowid') {
1300 $newsortfield =
'dm';
1302 if ($newsortfield ==
'amount_ht') {
1303 $newsortfield =
'amount';
1305 if ($newsortfield ==
'amount_ttc') {
1306 $newsortfield =
'amount';
1308 $sql .= $db->order($newsortfield, $sortorder);
1311 $result = $db->query($sql);
1313 $num = $db->num_rows($result);
1317 $obj = $db->fetch_object($result);
1319 $amount -= $obj->amount;
1321 $total_ttc -= $obj->amount;
1323 $subtotal_ttc -= $obj->amount;
1331 $total_ht_outcome -= 0;
1332 $total_ttc_outcome -= $amount;
1334 print
'<tr class="oddeven">';
1335 print
'<td> </td>';
1336 print
"<td>".$langs->trans(
"VATToPay").
"</td>\n";
1337 print
'<td class="right"> </td>'.
"\n";
1338 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1343 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1344 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1345 $sql .=
" WHERE f.fk_statut IN (1,2)";
1346 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
1347 $sql .=
" AND f.type IN (0,1,2)";
1349 $sql .=
" AND f.type IN (0,1,2,3)";
1351 if (!empty($date_start) && !empty($date_end)) {
1352 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
1354 $sql .=
" AND f.entity = ".$conf->entity;
1355 $sql .=
" GROUP BY dm";
1356 $newsortfield = $sortfield;
1357 if ($newsortfield ==
's.nom, s.rowid') {
1358 $newsortfield =
'dm';
1360 if ($newsortfield ==
'amount_ht') {
1361 $newsortfield =
'amount';
1363 if ($newsortfield ==
'amount_ttc') {
1364 $newsortfield =
'amount';
1366 $sql .= $db->order($newsortfield, $sortorder);
1368 dol_syslog(
"get vat received back", LOG_DEBUG);
1369 $result = $db->query($sql);
1371 $num = $db->num_rows($result);
1375 $obj = $db->fetch_object($result);
1377 $amount += $obj->amount;
1379 $total_ttc += $obj->amount;
1381 $subtotal_ttc += $obj->amount;
1390 $total_ht_income += 0;
1391 $total_ttc_income += $amount;
1393 print
'<tr class="oddeven">';
1394 print
'<td> </td>';
1395 print
'<td>'.$langs->trans(
"VATToCollect").
"</td>\n";
1396 print
'<td class="right"> </td>'.
"\n";
1397 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1402 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1403 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1404 $sql .=
" WHERE amount > 0";
1405 if (!empty($date_start) && !empty($date_end)) {
1406 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1408 $sql .=
" AND t.entity = ".$conf->entity;
1409 $sql .=
" GROUP BY dm";
1410 $newsortfield = $sortfield;
1411 if ($newsortfield ==
's.nom, s.rowid') {
1412 $newsortfield =
'dm';
1414 if ($newsortfield ==
'amount_ht') {
1415 $newsortfield =
'amount';
1417 if ($newsortfield ==
'amount_ttc') {
1418 $newsortfield =
'amount';
1420 $sql .= $db->order($newsortfield, $sortorder);
1422 dol_syslog(
"get vat really paid", LOG_DEBUG);
1423 $result = $db->query($sql);
1425 $num = $db->num_rows($result);
1429 $obj = $db->fetch_object($result);
1431 $amount -= $obj->amount;
1432 $total_ht -= $obj->amount;
1433 $total_ttc -= $obj->amount;
1434 $subtotal_ht -= $obj->amount;
1435 $subtotal_ttc -= $obj->amount;
1445 $total_ht_outcome -= 0;
1446 $total_ttc_outcome -= $amount;
1448 print
'<tr class="oddeven">';
1449 print
'<td> </td>';
1450 print
"<td>".$langs->trans(
"VATPaid").
"</td>\n";
1451 print
'<td <class="right"></td>'.
"\n";
1452 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1457 $sql =
"SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1458 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1459 $sql .=
" WHERE amount < 0";
1460 if (!empty($date_start) && !empty($date_end)) {
1461 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
1463 $sql .=
" AND t.entity = ".$conf->entity;
1464 $sql .=
" GROUP BY dm";
1465 $newsortfield = $sortfield;
1466 if ($newsortfield ==
's.nom, s.rowid') {
1467 $newsortfield =
'dm';
1469 if ($newsortfield ==
'amount_ht') {
1470 $newsortfield =
'amount';
1472 if ($newsortfield ==
'amount_ttc') {
1473 $newsortfield =
'amount';
1475 $sql .= $db->order($newsortfield, $sortorder);
1477 dol_syslog(
"get vat really received back", LOG_DEBUG);
1478 $result = $db->query($sql);
1480 $num = $db->num_rows($result);
1484 $obj = $db->fetch_object($result);
1486 $amount += -$obj->amount;
1487 $total_ht += -$obj->amount;
1488 $total_ttc += -$obj->amount;
1489 $subtotal_ht += -$obj->amount;
1490 $subtotal_ttc += -$obj->amount;
1500 $total_ht_income += 0;
1501 $total_ttc_income += $amount;
1503 print
'<tr class="oddeven">';
1504 print
'<td> </td>';
1505 print
"<td>".$langs->trans(
"VATCollected").
"</td>\n";
1506 print
'<td class="right"></td>'.
"\n";
1507 print
'<td class="right"><span class="amount">'.price($amount).
"</span></td>\n";
1512 if ($mysoc->tva_assuj !=
'0') {
1513 print
'<tr class="liste_total">';
1516 print
'<td class="right"> </td>';
1517 print
'<td class="right">'.price(
price2num($subtotal_ttc,
'MT')).
'</td>';
1522$action =
"balanceclient";
1523$object = array(&$total_ht, &$total_ttc);
1524$parameters[
"mode"] = $modecompta;
1525$parameters[
"date_start"] = $date_start;
1526$parameters[
"date_end"] = $date_end;
1528$hookmanager->initHooks(array(
'externalbalance'));
1529$reshook = $hookmanager->executeHooks(
'addBalanceLine', $parameters, $object, $action);
1530print $hookmanager->resPrint;
1536print
'<td colspan="'.($modecompta ==
'BOOKKEEPING' ? 3 : 4).
'"> </td>';
1539print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Income").
'</td>';
1540if ($modecompta ==
'CREANCES-DETTES') {
1541 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht_income,
'MT')).
'</td>';
1542} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1545print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc_income,
'MT')).
'</td>';
1547print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Outcome").
'</td>';
1548if ($modecompta ==
'CREANCES-DETTES') {
1549 print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ht_outcome,
'MT')).
'</td>';
1550} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1553print
'<td class="liste_total right nowraponall">'.price(
price2num(-$total_ttc_outcome,
'MT')).
'</td>';
1555print
'<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans(
"Profit").
'</td>';
1556if ($modecompta ==
'CREANCES-DETTES') {
1557 print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ht,
'MT')).
'</td>';
1558} elseif ($modecompta ==
'RECETTES-DEPENSES') {
1561print
'<td class="liste_total right nowraponall">'.price(
price2num($total_ttc,
'MT')).
'</td>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
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 informations (by default a local PHP server timestamp) Re...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return 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.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
img_next($titlealt='default', $moreatt='')
Show next logo.
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.