31require
'../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
41$langs->loadLangs(array(
'companies',
'categories',
'bills',
'compta'));
44$modecompta = $conf->global->ACCOUNTING_MODE;
46 $modecompta =
GETPOST(
"modecompta");
49$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
50$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
58$socid =
GETPOST(
'socid',
'int');
61$selected_cat = (int)
GETPOST(
'search_categ',
'int');
62if ($selected_cat == -1) {
66if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
71if ($user->socid > 0) {
72 $socid = $user->socid;
74if (isModEnabled(
'comptabilite')) {
77if (isModEnabled(
'accounting')) {
78 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
82$hookmanager->initHooks(array(
'casoclist'));
86$month =
GETPOST(
"month",
'int');
87$search_societe =
GETPOST(
"search_societe",
'alpha');
88$search_zip =
GETPOST(
"search_zip",
'alpha');
89$search_town =
GETPOST(
"search_town",
'alpha');
90$search_country =
GETPOST(
"search_country",
'alpha');
91$date_startyear =
GETPOST(
"date_startyear",
'int');
92$date_startmonth =
GETPOST(
"date_startmonth",
'int');
93$date_startday =
GETPOST(
"date_startday",
'int');
94$date_endyear =
GETPOST(
"date_endyear",
'int');
95$date_endmonth =
GETPOST(
"date_endmonth",
'int');
96$date_endday =
GETPOST(
"date_endday",
'int');
100 $year_start = $year_current;
102 $year_current = $year;
109if (empty($date_start) || empty($date_end)) {
114 $year_end = $year_start;
115 $month_end = $month_start;
117 if (!
GETPOST(
'year') && $month_start > $month_current) {
121 $month_end = $month_start - 1;
122 if ($month_end < 1) {
154$year_start = $tmps[
'year'];
156$year_end = $tmpe[
'year'];
157$nbofyear = ($year_end - $year_start) + 1;
159$commonparams = array();
160$commonparams[
'modecompta'] = $modecompta;
161$commonparams[
'sortorder'] = $sortorder;
162$commonparams[
'sortfield'] = $sortfield;
164$headerparams = array();
165if (!empty($date_startyear)) {
166 $headerparams[
'date_startyear'] = $date_startyear;
168if (!empty($date_startmonth)) {
169 $headerparams[
'date_startmonth'] = $date_startmonth;
171if (!empty($date_startday)) {
172 $headerparams[
'date_startday'] = $date_startday;
174if (!empty($date_endyear)) {
175 $headerparams[
'date_endyear'] = $date_endyear;
177if (!empty($date_endmonth)) {
178 $headerparams[
'date_endmonth'] = $date_endmonth;
180if (!empty($date_endday)) {
181 $headerparams[
'date_endday'] = $date_endday;
184 $headerparams[
'q'] = $q;
187$tableparams = array();
188$tableparams[
'search_categ'] = $selected_cat;
189$tableparams[
'search_societe'] = $search_societe;
190$tableparams[
'search_zip'] = $search_zip;
191$tableparams[
'search_town'] = $search_town;
192$tableparams[
'search_country'] = $search_country;
193$tableparams[
'subcat'] = ($subcat ===
true) ?
'yes' :
'';
196$allparams = array_merge($commonparams, $headerparams, $tableparams);
197$headerparams = array_merge($commonparams, $headerparams);
198$tableparams = array_merge($commonparams, $tableparams);
201foreach ($allparams as $key => $value) {
202 $paramslink .=
'&'.$key.
'='.$value;
212$form =
new Form($db);
213$thirdparty_static =
new Societe($db);
217if ($modecompta ==
"BOOKKEEPING") {
218 $modecompta =
"CREANCES-DETTES";
220if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
221 $modecompta =
"RECETTES-DEPENSES";
228if ($modecompta ==
"CREANCES-DETTES") {
229 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByThirdParties");
230 $calcmode = $langs->trans(
"CalcModeDebt");
232 $description = $langs->trans(
"RulesCADue");
234 $description .= $langs->trans(
"DepositsAreNotIncluded");
236 $description .= $langs->trans(
"DepositsAreIncluded");
240} elseif ($modecompta ==
"RECETTES-DEPENSES") {
241 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByThirdParties");
242 $calcmode = $langs->trans(
"CalcModeEngagement");
244 $description = $langs->trans(
"RulesCAIn");
245 $description .= $langs->trans(
"DepositsAreIncluded");
248} elseif ($modecompta ==
"BOOKKEEPING") {
249} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
251$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
253$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
255 $periodlink =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_start - 1).
'&modecompta='.$modecompta.
'">'.
img_previous().
'</a> <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_start + 1).
'&modecompta='.$modecompta.
'">'.
img_next().
'</a>';
260report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
262if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
263 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
273if ($modecompta ==
'CREANCES-DETTES') {
274 $sql =
"SELECT DISTINCT s.rowid as socid, s.nom as name, s.name_alias, s.zip, s.town, s.fk_pays,";
275 $sql .=
" sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
276 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"societe as s";
277 if ($selected_cat === -2) {
278 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as cs ON s.rowid = cs.fk_soc";
279 } elseif ($selected_cat) {
280 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_societe as cs";
282 $sql .=
" WHERE f.fk_statut in (1,2)";
284 $sql .=
" AND f.type IN (0,1,2,5)";
286 $sql .=
" AND f.type IN (0,1,2,3,5)";
288 $sql .=
" AND f.fk_soc = s.rowid";
289 if ($date_start && $date_end) {
290 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
292 if ($selected_cat === -2) {
293 $sql .=
" AND cs.fk_soc is null";
294 } elseif ($selected_cat) {
295 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
297 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
300 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
302} elseif ($modecompta ==
"RECETTES-DEPENSES") {
307 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc";
308 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
309 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
310 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
311 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
312 if ($selected_cat === -2) {
313 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as cs ON s.rowid = cs.fk_soc";
314 } elseif ($selected_cat) {
315 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_societe as cs";
317 $sql .=
" WHERE p.rowid = pf.fk_paiement";
318 $sql .=
" AND pf.fk_facture = f.rowid";
319 $sql .=
" AND f.fk_soc = s.rowid";
320 if ($date_start && $date_end) {
321 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
323 if ($selected_cat === -2) {
324 $sql .=
" AND cs.fk_soc is null";
325 } elseif ($selected_cat) {
326 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
328 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
331 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
333} elseif ($modecompta ==
"BOOKKEEPING") {
334} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
336if (!empty($search_societe)) {
339if (!empty($search_zip)) {
342if (!empty($search_town)) {
345if ($search_country > 0) {
346 $sql .=
' AND s.fk_pays = '.((int) $search_country);
348$sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
350 $sql .=
" AND f.fk_soc = ".((int) $socid);
352$sql .=
" GROUP BY s.rowid, s.nom, s.name_alias, s.zip, s.town, s.fk_pays";
353$sql .=
" ORDER BY s.rowid";
359$result = $db->query($sql);
361 $num = $db->num_rows($result);
364 $obj = $db->fetch_object($result);
366 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
367 $amount[$obj->socid] = $obj->amount_ttc;
368 $fullname = $obj->name;
369 if (!empty($obj->name_alias)) {
370 $fullname .=
' ('.$obj->name_alias.
')';
372 $name[$obj->socid] = $fullname;
374 $address_zip[$obj->socid] = $obj->zip;
375 $address_town[$obj->socid] = $obj->town;
376 $address_pays[$obj->socid] =
getCountry($obj->fk_pays);
378 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
379 $catotal += $obj->amount_ttc;
388if ($modecompta ==
"RECETTES-DEPENSES") {
389 $sql =
"SELECT '0' as socid, 'Autres' as name, sum(p.amount) as amount_ttc";
390 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
391 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
392 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
393 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
394 $sql .=
" WHERE pf.rowid IS NULL";
395 $sql .=
" AND p.fk_bank = b.rowid";
396 $sql .=
" AND b.fk_account = ba.rowid";
397 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
398 if ($date_start && $date_end) {
399 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
401 $sql .=
" GROUP BY socid, name";
402 $sql .=
" ORDER BY name";
404 $result = $db->query($sql);
406 $num = $db->num_rows($result);
409 $obj = $db->fetch_object($result);
411 if (empty($amount[$obj->socid])) {
412 $amount[$obj->socid] = $obj->amount_ttc;
414 $amount[$obj->socid] += $obj->amount_ttc;
417 $name[$obj->socid] = $obj->name;
418 $address_zip[$obj->socid] =
'';
419 $address_town[$obj->socid] =
'';
420 $address_pays[$obj->socid] =
'';
422 $catotal += $obj->amount_ttc;
434print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
435print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
437foreach ($headerparams as $key => $value) {
438 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
443print
'<div class="div-table-responsive">';
444print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
447print
'<tr class="liste_titre">';
448print
'<td class="nowraponall">';
449print
img_picto(
'',
'category',
'class="paddingrightonly"');
450print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
452print $langs->trans(
"SubCats").
'? ';
453print
'<input type="checkbox" name="subcat" value="yes"';
458print
'<td colspan="7" class="right">';
459print
'<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans(
"Search"),
'search.png',
'',
'', 1).
'" value="'.
dol_escape_htmltag($langs->trans(
"Search")).
'" title="'.
dol_escape_htmltag($langs->trans(
"Search")).
'">';
463print
'<tr class="liste_titre">';
464print
'<td class="liste_titre left">';
465print
'<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'">';
467print
'<td class="liste_titre left">';
468print
'<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'">';
470print
'<td class="liste_titre left">';
471print
'<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).
'">';
473print
'<td class="liste_titre left">';
474print $form->select_country($search_country,
'search_country',
'', 0,
'minwidth100imp maxwidth100');
477print
'<td class="liste_titre"> </td>';
478print
'<td class="liste_titre"> </td>';
479print
'<td class="liste_titre"> </td>';
480print
'<td class="liste_titre"> </td>';
484print
"<tr class='liste_titre'>";
486 $langs->trans(
"Company"),
487 $_SERVER[
"PHP_SELF"],
496 $langs->trans(
"Zip"),
497 $_SERVER[
"PHP_SELF"],
506 $langs->trans(
"Town"),
507 $_SERVER[
"PHP_SELF"],
516 $langs->trans(
"Country"),
517 $_SERVER[
"PHP_SELF"],
525if ($modecompta ==
'CREANCES-DETTES') {
527 $langs->trans(
'AmountHT'),
528 $_SERVER[
"PHP_SELF"],
540 $langs->trans(
"AmountTTC"),
541 $_SERVER[
"PHP_SELF"],
550 $langs->trans(
"Percentage"),
551 $_SERVER[
"PHP_SELF"],
560 $langs->trans(
"OtherStatistics"),
561 $_SERVER[
"PHP_SELF"],
565 'align="center" width="20%"'
571 $arrayforsort = $name;
573 if ($sortfield ==
'nom' && $sortorder ==
'asc') {
575 $arrayforsort = $name;
577 if ($sortfield ==
'nom' && $sortorder ==
'desc') {
579 $arrayforsort = $name;
581 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
583 $arrayforsort = $amount_ht;
585 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
587 $arrayforsort = $amount_ht;
589 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
591 $arrayforsort = $amount;
593 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
595 $arrayforsort = $amount;
597 if ($sortfield ==
'zip' && $sortorder ==
'asc') {
599 $arrayforsort = $address_zip;
601 if ($sortfield ==
'zip' && $sortorder ==
'desc') {
602 arsort($address_zip);
603 $arrayforsort = $address_zip;
605 if ($sortfield ==
'town' && $sortorder ==
'asc') {
606 asort($address_town);
607 $arrayforsort = $address_town;
609 if ($sortfield ==
'town' && $sortorder ==
'desc') {
610 arsort($address_town);
611 $arrayforsort = $address_town;
613 if ($sortfield ==
'country' && $sortorder ==
'asc') {
614 asort($address_pays);
615 $arrayforsort = $address_town;
617 if ($sortfield ==
'country' && $sortorder ==
'desc') {
618 arsort($address_pays);
619 $arrayforsort = $address_town;
622 foreach ($arrayforsort as $key => $value) {
623 print
'<tr class="oddeven">';
626 $fullname = $name[$key];
628 $thirdparty_static->id = $key;
629 $thirdparty_static->name = $fullname;
630 $thirdparty_static->client = 1;
631 $linkname = $thirdparty_static->getNomUrl(1,
'customer');
633 $linkname = $langs->trans(
"PaymentsNotLinkedToInvoice");
635 print
'<td class="tdoverflowmax150">'.$linkname.
"</td>\n";
638 print $address_zip[$key];
641 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_town[$key]).
'">';
642 print $address_town[$key];
645 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_pays[$key]).
'">';
646 print $address_pays[$key];
650 print
'<td class="right">';
651 if ($modecompta !=
'CREANCES-DETTES') {
653 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid='.$key.
'">';
655 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid=-1">';
659 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$key.
'">';
661 print
'<a href="#">';
663 print
price($amount_ht[$key]);
668 print
'<td class="right">';
669 if ($modecompta !=
'CREANCES-DETTES') {
671 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid='.$key.
'">';
673 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?orphelins=1">';
677 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$key.
'">';
679 print
'<a href="#">';
682 print
price($amount[$key]);
687 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
690 print
'<td class="center">';
691 if (isModEnabled(
"propal") && $key > 0) {
692 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
694 if (isModEnabled(
'commande') && $key > 0) {
695 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
697 if (isModEnabled(
'facture') && $key > 0) {
698 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
706 print
'<tr class="liste_total">';
707 print
'<td>'.$langs->trans(
"Total").
'</td>';
708 print
'<td> </td>';
709 print
'<td> </td>';
710 print
'<td> </td>';
711 if ($modecompta !=
'CREANCES-DETTES') {
714 print
'<td class="right">'.price($catotal_ht).
'</td>';
716 print
'<td class="right">'.price($catotal).
'</td>';
717 print
'<td> </td>';
718 print
'<td> </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 third parties objects (customers, suppliers, prospects...)
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
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...
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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 a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.