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';
42$langs->loadLangs(array(
'companies',
'categories',
'bills',
'compta'));
47 $modecompta =
GETPOST(
"modecompta");
50$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
51$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
63if ($selected_cat == -1) {
67if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
72if ($user->socid > 0) {
73 $socid = $user->socid;
77$hookmanager->initHooks(array(
'casoclist'));
79if (isModEnabled(
'comptabilite')) {
82if (isModEnabled(
'accounting')) {
83 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
89$search_societe =
GETPOST(
"search_societe",
'alpha');
90$search_zip =
GETPOST(
"search_zip",
'alpha');
91$search_town =
GETPOST(
"search_town",
'alpha');
92$search_country =
GETPOST(
"search_country",
'aZ09');
94$date_startmonth =
GETPOSTINT(
"date_startmonth");
102 $year_start = $year_current;
104 $year_current = $year;
111if (empty($date_start) || empty($date_end)) {
116 $year_end = $year_start;
117 $month_end = $month_start;
119 if (!
GETPOST(
'year') && $month_start > $month_current) {
123 $month_end = $month_start - 1;
124 if ($month_end < 1) {
156$year_start = $tmps[
'year'];
158$year_end = $tmpe[
'year'];
159$nbofyear = ($year_end - $year_start) + 1;
161$commonparams = array();
162$commonparams[
'modecompta'] = $modecompta;
163$commonparams[
'sortorder'] = $sortorder;
164$commonparams[
'sortfield'] = $sortfield;
166$headerparams = array();
167if (!empty($date_startyear)) {
168 $headerparams[
'date_startyear'] = $date_startyear;
170if (!empty($date_startmonth)) {
171 $headerparams[
'date_startmonth'] = $date_startmonth;
173if (!empty($date_startday)) {
174 $headerparams[
'date_startday'] = $date_startday;
176if (!empty($date_endyear)) {
177 $headerparams[
'date_endyear'] = $date_endyear;
179if (!empty($date_endmonth)) {
180 $headerparams[
'date_endmonth'] = $date_endmonth;
182if (!empty($date_endday)) {
183 $headerparams[
'date_endday'] = $date_endday;
186 $headerparams[
'q'] = $q;
189$tableparams = array();
190$tableparams[
'search_categ'] = $selected_cat;
191$tableparams[
'search_societe'] = $search_societe;
192$tableparams[
'search_zip'] = $search_zip;
193$tableparams[
'search_town'] = $search_town;
194$tableparams[
'search_country'] = $search_country;
195$tableparams[
'subcat'] = $subcat ?
'yes' :
'';
198$allparams = array_merge($commonparams, $headerparams, $tableparams);
199$headerparams = array_merge($commonparams, $headerparams);
200$tableparams = array_merge($commonparams, $tableparams);
203foreach ($allparams as $key => $value) {
204 $paramslink .=
'&'.$key.
'='.$value;
214$form =
new Form($db);
215$thirdparty_static =
new Societe($db);
219if ($modecompta ==
"BOOKKEEPING") {
220 $modecompta =
"CREANCES-DETTES";
222if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
223 $modecompta =
"RECETTES-DEPENSES";
230if ($modecompta ==
"CREANCES-DETTES") {
231 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByThirdParties");
232 $calcmode = $langs->trans(
"CalcModeDebt");
234 $description = $langs->trans(
"RulesCADue");
236 $description .= $langs->trans(
"DepositsAreNotIncluded");
238 $description .= $langs->trans(
"DepositsAreIncluded");
242} elseif ($modecompta ==
"RECETTES-DEPENSES") {
243 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByThirdParties");
244 $calcmode = $langs->trans(
"CalcModePayment");
246 $description = $langs->trans(
"RulesCAIn");
247 $description .= $langs->trans(
"DepositsAreIncluded");
250} elseif ($modecompta ==
"BOOKKEEPING") {
251} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
253$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
255$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
257 $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>';
262report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
264if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
265 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
275if ($modecompta ==
'CREANCES-DETTES') {
276 $sql =
"SELECT DISTINCT s.rowid as socid, s.nom as name, s.name_alias, s.zip, s.town, s.fk_pays,";
277 $sql .=
" sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
278 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"societe as s";
279 if ($selected_cat === -2) {
280 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as cs ON s.rowid = cs.fk_soc";
281 } elseif ($selected_cat) {
282 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_societe as cs";
284 $sql .=
" WHERE f.fk_statut in (1,2)";
286 $sql .=
" AND f.type IN (0,1,2,5)";
288 $sql .=
" AND f.type IN (0,1,2,3,5)";
290 $sql .=
" AND f.fk_soc = s.rowid";
291 if ($date_start && $date_end) {
292 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
294 if ($selected_cat === -2) {
295 $sql .=
" AND cs.fk_soc is null";
296 } elseif ($selected_cat) {
297 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
299 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
302 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
304} elseif ($modecompta ==
"RECETTES-DEPENSES") {
309 $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";
310 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
311 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
312 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
313 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
314 if ($selected_cat === -2) {
315 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as cs ON s.rowid = cs.fk_soc";
316 } elseif ($selected_cat) {
317 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_societe as cs";
319 $sql .=
" WHERE p.rowid = pf.fk_paiement";
320 $sql .=
" AND pf.fk_facture = f.rowid";
321 $sql .=
" AND f.fk_soc = s.rowid";
322 if ($date_start && $date_end) {
323 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
325 if ($selected_cat === -2) {
326 $sql .=
" AND cs.fk_soc is null";
327 } elseif ($selected_cat) {
328 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
330 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
333 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
335} elseif ($modecompta ==
"BOOKKEEPING") {
336} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
338if (!empty($search_societe)) {
341if (!empty($search_zip)) {
344if (!empty($search_town)) {
347if ($search_country > 0) {
348 $sql .=
' AND s.fk_pays = '.((int) $search_country);
350$sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
352 $sql .=
" AND f.fk_soc = ".((int) $socid);
354$sql .=
" GROUP BY s.rowid, s.nom, s.name_alias, s.zip, s.town, s.fk_pays";
355$sql .=
" ORDER BY s.rowid";
360$address_zip = array();
361$address_town = array();
362$address_pays = array();
365$result = $db->query($sql);
367 $num = $db->num_rows($result);
370 $obj = $db->fetch_object($result);
372 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
373 $amount[$obj->socid] = $obj->amount_ttc;
374 $fullname = $obj->name;
375 if (!empty($obj->name_alias)) {
376 $fullname .=
' ('.$obj->name_alias.
')';
378 $name[$obj->socid] = $fullname;
380 $address_zip[$obj->socid] = $obj->zip;
381 $address_town[$obj->socid] = $obj->town;
382 $address_pays[$obj->socid] =
getCountry($obj->fk_pays);
384 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
385 $catotal += $obj->amount_ttc;
394if ($modecompta ==
"RECETTES-DEPENSES") {
395 $sql =
"SELECT '0' as socid, 'Autres' as name, sum(p.amount) as amount_ttc";
396 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
397 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
398 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
399 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
400 $sql .=
" WHERE pf.rowid IS NULL";
401 $sql .=
" AND p.fk_bank = b.rowid";
402 $sql .=
" AND b.fk_account = ba.rowid";
403 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
404 if ($date_start && $date_end) {
405 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
407 $sql .=
" GROUP BY socid, name";
408 $sql .=
" ORDER BY name";
410 $result = $db->query($sql);
412 $num = $db->num_rows($result);
415 $obj = $db->fetch_object($result);
417 if (empty($amount[$obj->socid])) {
418 $amount[$obj->socid] = $obj->amount_ttc;
420 $amount[$obj->socid] += $obj->amount_ttc;
423 $name[$obj->socid] = $obj->name;
424 $address_zip[$obj->socid] =
'';
425 $address_town[$obj->socid] =
'';
426 $address_pays[$obj->socid] =
'';
428 $catotal += $obj->amount_ttc;
440print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
441print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
443foreach ($headerparams as $key => $value) {
444 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
449print
'<div class="div-table-responsive">';
450print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
453print
'<tr class="liste_titre">';
454print
'<td class="nowraponall">';
455print
img_picto(
'',
'category',
'class="paddingrightonly"');
456print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
458print $langs->trans(
"SubCats").
'? ';
459print
'<input type="checkbox" name="subcat" value="yes"';
464print
'<td colspan="7" class="right">';
465print
'<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")).
'">';
469print
'<tr class="liste_titre">';
470print
'<td class="liste_titre left">';
471print
'<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'">';
473print
'<td class="liste_titre left">';
474print
'<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'">';
476print
'<td class="liste_titre left">';
477print
'<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).
'">';
479print
'<td class="liste_titre left">';
480print $form->select_country($search_country,
'search_country',
'', 0,
'minwidth100imp maxwidth100');
483print
'<td class="liste_titre"> </td>';
484print
'<td class="liste_titre"> </td>';
485print
'<td class="liste_titre"> </td>';
486print
'<td class="liste_titre"> </td>';
490print
"<tr class='liste_titre'>";
492 $langs->trans(
"Company"),
493 $_SERVER[
"PHP_SELF"],
502 $langs->trans(
"Zip"),
503 $_SERVER[
"PHP_SELF"],
512 $langs->trans(
"Town"),
513 $_SERVER[
"PHP_SELF"],
522 $langs->trans(
"Country"),
523 $_SERVER[
"PHP_SELF"],
531if ($modecompta ==
'CREANCES-DETTES') {
533 $langs->trans(
'AmountHT'),
534 $_SERVER[
"PHP_SELF"],
546 $langs->trans(
"AmountTTC"),
547 $_SERVER[
"PHP_SELF"],
556 $langs->trans(
"Percentage"),
557 $_SERVER[
"PHP_SELF"],
566 $langs->trans(
"OtherStatistics"),
567 $_SERVER[
"PHP_SELF"],
571 'align="center" width="20%"'
577 $arrayforsort = $name;
579 if ($sortfield ==
'nom' && $sortorder ==
'asc') {
581 $arrayforsort = $name;
583 if ($sortfield ==
'nom' && $sortorder ==
'desc') {
585 $arrayforsort = $name;
587 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
589 $arrayforsort = $amount_ht;
591 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
593 $arrayforsort = $amount_ht;
595 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
597 $arrayforsort = $amount;
599 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
601 $arrayforsort = $amount;
603 if ($sortfield ==
'zip' && $sortorder ==
'asc') {
605 $arrayforsort = $address_zip;
607 if ($sortfield ==
'zip' && $sortorder ==
'desc') {
608 arsort($address_zip);
609 $arrayforsort = $address_zip;
611 if ($sortfield ==
'town' && $sortorder ==
'asc') {
612 asort($address_town);
613 $arrayforsort = $address_town;
615 if ($sortfield ==
'town' && $sortorder ==
'desc') {
616 arsort($address_town);
617 $arrayforsort = $address_town;
619 if ($sortfield ==
'country' && $sortorder ==
'asc') {
620 asort($address_pays);
621 $arrayforsort = $address_town;
623 if ($sortfield ==
'country' && $sortorder ==
'desc') {
624 arsort($address_pays);
625 $arrayforsort = $address_town;
628 foreach ($arrayforsort as $key => $value) {
629 print
'<tr class="oddeven">';
632 $fullname = $name[$key];
634 $thirdparty_static->id = $key;
635 $thirdparty_static->name = $fullname;
636 $thirdparty_static->client = 1;
637 $linkname = $thirdparty_static->getNomUrl(1,
'customer');
639 $linkname = $langs->trans(
"PaymentsNotLinkedToInvoice");
641 print
'<td class="tdoverflowmax150">'.$linkname.
"</td>\n";
644 print $address_zip[$key];
647 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_town[$key]).
'">';
648 print $address_town[$key];
651 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_pays[$key]).
'">';
652 print $address_pays[$key];
656 print
'<td class="right">';
657 if ($modecompta !=
'CREANCES-DETTES') {
659 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid='.$key.
'">';
661 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid=-1">';
665 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$key.
'">';
667 print
'<a href="#">';
669 print
price($amount_ht[$key]);
674 print
'<td class="right">';
675 if ($modecompta !=
'CREANCES-DETTES') {
677 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid='.$key.
'">';
679 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?orphelins=1">';
683 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$key.
'">';
685 print
'<a href="#">';
688 print
price($amount[$key]);
693 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
696 print
'<td class="center">';
697 if (isModEnabled(
"propal") && $key > 0) {
698 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
700 if (isModEnabled(
'order') && $key > 0) {
701 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
703 if (isModEnabled(
'invoice') && $key > 0) {
704 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
712 print
'<tr class="liste_total">';
713 print
'<td>'.$langs->trans(
"Total").
'</td>';
714 print
'<td> </td>';
715 print
'<td> </td>';
716 print
'<td> </td>';
717 if ($modecompta !=
'CREANCES-DETTES') {
720 print
'<td class="right">'.price($catotal_ht).
'</td>';
722 print
'<td class="right">'.price($catotal).
'</td>';
723 print
'<td> </td>';
724 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.