32require
'../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
50$langs->loadLangs(array(
'companies',
'categories',
'bills',
'compta'));
55 $modecompta =
GETPOST(
"modecompta");
58$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
59$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
71if ($selected_cat == -1) {
75if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
80if ($user->socid > 0) {
81 $socid = $user->socid;
85$hookmanager->initHooks(array(
'casoclist'));
87if (isModEnabled(
'comptabilite')) {
90if (isModEnabled(
'accounting')) {
91 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
97$search_societe =
GETPOST(
"search_societe",
'alpha');
98$search_zip =
GETPOST(
"search_zip",
'alpha');
99$search_town =
GETPOST(
"search_town",
'alpha');
100$search_country =
GETPOST(
"search_country",
'aZ09');
101$date_startyear =
GETPOSTINT(
"date_startyear");
102$date_startmonth =
GETPOSTINT(
"date_startmonth");
110 $year_start = $year_current;
112 $year_current = $year;
119if (empty($date_start) || empty($date_end)) {
124 $year_end = $year_start;
125 $month_end = $month_start;
127 if (!
GETPOST(
'year') && $month_start > $month_current) {
131 $month_end = $month_start - 1;
132 if ($month_end < 1) {
164$year_start = $tmps[
'year'];
166$year_end = $tmpe[
'year'];
167$nbofyear = ($year_end - $year_start) + 1;
169$commonparams = array();
170$commonparams[
'modecompta'] = $modecompta;
171$commonparams[
'sortorder'] = $sortorder;
172$commonparams[
'sortfield'] = $sortfield;
174$headerparams = array();
175if (!empty($date_startyear)) {
176 $headerparams[
'date_startyear'] = $date_startyear;
178if (!empty($date_startmonth)) {
179 $headerparams[
'date_startmonth'] = $date_startmonth;
181if (!empty($date_startday)) {
182 $headerparams[
'date_startday'] = $date_startday;
184if (!empty($date_endyear)) {
185 $headerparams[
'date_endyear'] = $date_endyear;
187if (!empty($date_endmonth)) {
188 $headerparams[
'date_endmonth'] = $date_endmonth;
190if (!empty($date_endday)) {
191 $headerparams[
'date_endday'] = $date_endday;
194 $headerparams[
'q'] = $q;
197$tableparams = array();
198$tableparams[
'search_categ'] = $selected_cat;
199$tableparams[
'search_societe'] = $search_societe;
200$tableparams[
'search_zip'] = $search_zip;
201$tableparams[
'search_town'] = $search_town;
202$tableparams[
'search_country'] = $search_country;
203$tableparams[
'subcat'] = $subcat ?
'yes' :
'';
206$allparams = array_merge($commonparams, $headerparams, $tableparams);
207$headerparams = array_merge($commonparams, $headerparams);
208$tableparams = array_merge($commonparams, $tableparams);
211foreach ($allparams as $key => $value) {
212 $paramslink .=
'&'.$key.
'='.$value;
222$form =
new Form($db);
223$thirdparty_static =
new Societe($db);
227if ($modecompta ==
"BOOKKEEPING") {
228 $modecompta =
"CREANCES-DETTES";
230if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
231 $modecompta =
"RECETTES-DEPENSES";
241if ($modecompta ==
"CREANCES-DETTES") {
242 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByThirdParties");
243 $calcmode = $langs->trans(
"CalcModeDebt");
245 $description = $langs->trans(
"RulesCADue");
247 $description .= $langs->trans(
"DepositsAreNotIncluded");
249 $description .= $langs->trans(
"DepositsAreIncluded");
253} elseif ($modecompta ==
"RECETTES-DEPENSES") {
254 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByThirdParties");
255 $calcmode = $langs->trans(
"CalcModePayment");
257 $description = $langs->trans(
"RulesCAIn");
258 $description .= $langs->trans(
"DepositsAreIncluded");
264$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
266$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
268 $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>';
273report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
275if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
276 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
286if ($modecompta ==
'CREANCES-DETTES') {
287 $sql =
"SELECT DISTINCT s.rowid as socid, s.nom as name, s.name_alias, s.zip, s.town, s.fk_pays,";
288 $sql .=
" sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
289 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"societe as s";
290 if ($selected_cat === -2) {
291 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as cs ON s.rowid = cs.fk_soc";
292 } elseif ($selected_cat) {
293 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_societe as cs";
295 $sql .=
" WHERE f.fk_statut in (1,2)";
297 $sql .=
" AND f.type IN (0,1,2,5)";
299 $sql .=
" AND f.type IN (0,1,2,3,5)";
301 $sql .=
" AND f.fk_soc = s.rowid";
302 if ($date_start && $date_end) {
303 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
305 if ($selected_cat === -2) {
306 $sql .=
" AND cs.fk_soc is null";
307 } elseif ($selected_cat) {
308 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
310 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
313 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
315} elseif ($modecompta ==
"RECETTES-DEPENSES") {
320 $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";
321 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
322 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
323 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
324 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
325 if ($selected_cat === -2) {
326 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as cs ON s.rowid = cs.fk_soc";
327 } elseif ($selected_cat) {
328 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_societe as cs";
330 $sql .=
" WHERE p.rowid = pf.fk_paiement";
331 $sql .=
" AND pf.fk_facture = f.rowid";
332 $sql .=
" AND f.fk_soc = s.rowid";
333 if ($date_start && $date_end) {
334 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
336 if ($selected_cat === -2) {
337 $sql .=
" AND cs.fk_soc is null";
338 } elseif ($selected_cat) {
339 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
341 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
344 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
349if (!empty($search_societe)) {
352if (!empty($search_zip)) {
355if (!empty($search_town)) {
358if ($search_country > 0) {
359 $sql .=
' AND s.fk_pays = '.((int) $search_country);
361$sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
363 $sql .=
" AND f.fk_soc = ".((int) $socid);
365$sql .=
" GROUP BY s.rowid, s.nom, s.name_alias, s.zip, s.town, s.fk_pays";
366$sql .=
" ORDER BY s.rowid";
371$address_zip = array();
372$address_town = array();
373$address_pays = array();
376$result = $db->query($sql);
378 $num = $db->num_rows($result);
381 $obj = $db->fetch_object($result);
383 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
384 $amount[$obj->socid] = $obj->amount_ttc;
385 $fullname = $obj->name;
386 if (!empty($obj->name_alias)) {
387 $fullname .=
' ('.$obj->name_alias.
')';
389 $name[$obj->socid] = $fullname;
391 $address_zip[$obj->socid] = $obj->zip;
392 $address_town[$obj->socid] = $obj->town;
393 $address_pays[$obj->socid] =
getCountry($obj->fk_pays);
395 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
396 $catotal += $obj->amount_ttc;
405if ($modecompta ==
"RECETTES-DEPENSES") {
406 $sql =
"SELECT '0' as socid, 'Autres' as name, sum(p.amount) as amount_ttc";
407 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
408 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
409 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
410 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
411 $sql .=
" WHERE pf.rowid IS NULL";
412 $sql .=
" AND p.fk_bank = b.rowid";
413 $sql .=
" AND b.fk_account = ba.rowid";
414 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
415 if ($date_start && $date_end) {
416 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
418 $sql .=
" GROUP BY socid, name";
419 $sql .=
" ORDER BY name";
421 $result = $db->query($sql);
423 $num = $db->num_rows($result);
426 $obj = $db->fetch_object($result);
428 if (empty($amount[$obj->socid])) {
429 $amount[$obj->socid] = $obj->amount_ttc;
431 $amount[$obj->socid] += $obj->amount_ttc;
434 $name[$obj->socid] = $obj->name;
435 $address_zip[$obj->socid] =
'';
436 $address_town[$obj->socid] =
'';
437 $address_pays[$obj->socid] =
'';
439 $catotal += $obj->amount_ttc;
451print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
452print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
454foreach ($headerparams as $key => $value) {
455 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
460print
'<div class="div-table-responsive">';
461print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
464print
'<tr class="liste_titre">';
465print
'<td class="nowraponall">';
466print
img_picto(
'',
'category',
'class="paddingrightonly"');
467print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
469print $langs->trans(
"SubCats").
'? ';
470print
'<input type="checkbox" name="subcat" value="yes"';
475print
'<td colspan="7" class="right">';
476print
'<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans(
"Search"),
'search.png',
'', 0, 1).
'" value="'.
dol_escape_htmltag($langs->trans(
"Search")).
'" title="'.
dol_escape_htmltag($langs->trans(
"Search")).
'">';
480print
'<tr class="liste_titre">';
481print
'<td class="liste_titre left">';
482print
'<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'">';
484print
'<td class="liste_titre left">';
485print
'<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'">';
487print
'<td class="liste_titre left">';
488print
'<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).
'">';
490print
'<td class="liste_titre left">';
491print $form->select_country($search_country,
'search_country',
'', 0,
'minwidth100imp maxwidth100');
494print
'<td class="liste_titre"> </td>';
495print
'<td class="liste_titre"> </td>';
496print
'<td class="liste_titre"> </td>';
497print
'<td class="liste_titre"> </td>';
501print
"<tr class='liste_titre'>";
503 $langs->trans(
"Company"),
504 $_SERVER[
"PHP_SELF"],
513 $langs->trans(
"Zip"),
514 $_SERVER[
"PHP_SELF"],
523 $langs->trans(
"Town"),
524 $_SERVER[
"PHP_SELF"],
533 $langs->trans(
"Country"),
534 $_SERVER[
"PHP_SELF"],
542if ($modecompta ==
'CREANCES-DETTES') {
544 $langs->trans(
'AmountHT'),
545 $_SERVER[
"PHP_SELF"],
557 $langs->trans(
"AmountTTC"),
558 $_SERVER[
"PHP_SELF"],
567 $langs->trans(
"Percentage"),
568 $_SERVER[
"PHP_SELF"],
577 $langs->trans(
"OtherStatistics"),
578 $_SERVER[
"PHP_SELF"],
582 'align="center" width="20%"'
588 $arrayforsort = $name;
590 if ($sortfield ==
'nom' && $sortorder ==
'asc') {
592 $arrayforsort = $name;
594 if ($sortfield ==
'nom' && $sortorder ==
'desc') {
596 $arrayforsort = $name;
598 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
600 $arrayforsort = $amount_ht;
602 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
604 $arrayforsort = $amount_ht;
606 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
608 $arrayforsort = $amount;
610 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
612 $arrayforsort = $amount;
614 if ($sortfield ==
'zip' && $sortorder ==
'asc') {
616 $arrayforsort = $address_zip;
618 if ($sortfield ==
'zip' && $sortorder ==
'desc') {
619 arsort($address_zip);
620 $arrayforsort = $address_zip;
622 if ($sortfield ==
'town' && $sortorder ==
'asc') {
623 asort($address_town);
624 $arrayforsort = $address_town;
626 if ($sortfield ==
'town' && $sortorder ==
'desc') {
627 arsort($address_town);
628 $arrayforsort = $address_town;
630 if ($sortfield ==
'country' && $sortorder ==
'asc') {
631 asort($address_pays);
632 $arrayforsort = $address_town;
634 if ($sortfield ==
'country' && $sortorder ==
'desc') {
635 arsort($address_pays);
636 $arrayforsort = $address_town;
639 foreach ($arrayforsort as $key => $value) {
640 print
'<tr class="oddeven">';
643 $fullname = $name[$key];
645 $thirdparty_static->id = $key;
646 $thirdparty_static->name = $fullname;
647 $thirdparty_static->client = 1;
648 $linkname = $thirdparty_static->getNomUrl(1,
'customer');
650 $linkname = $langs->trans(
"PaymentsNotLinkedToInvoice");
652 print
'<td class="tdoverflowmax150">'.$linkname.
"</td>\n";
655 print $address_zip[$key];
658 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_town[$key]).
'">';
659 print $address_town[$key];
662 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_pays[$key]).
'">';
663 print $address_pays[$key];
667 print
'<td class="right">';
668 if ($modecompta !=
'CREANCES-DETTES') {
670 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid='.$key.
'">';
672 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid=-1">';
676 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$key.
'">';
678 print
'<a href="#">';
680 print
price($amount_ht[$key]);
685 print
'<td class="right">';
686 if ($modecompta !=
'CREANCES-DETTES') {
688 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid='.$key.
'">';
690 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?orphelins=1">';
694 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$key.
'">';
696 print
'<a href="#">';
699 print
price($amount[$key]);
704 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
707 print
'<td class="center">';
708 if (isModEnabled(
"propal") && $key > 0) {
709 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
711 if (isModEnabled(
'order') && $key > 0) {
712 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
714 if (isModEnabled(
'invoice') && $key > 0) {
715 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
723 print
'<tr class="liste_total">';
724 print
'<td>'.$langs->trans(
"Total").
'</td>';
725 print
'<td> </td>';
726 print
'<td> </td>';
727 print
'<td> </td>';
728 if ($modecompta !=
'CREANCES-DETTES') {
731 print
'<td class="right">'.price($catotal_ht).
'</td>';
733 print
'<td class="right">'.price($catotal).
'</td>';
734 print
'<td> </td>';
735 print
'<td> </td>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage third parties objects (customers, suppliers, prospects...)
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $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 information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.