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'));
46 $modecompta =
GETPOST(
"modecompta");
49$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
50$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
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'));
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",
'aZ09');
92$date_startmonth =
GETPOSTINT(
"date_startmonth");
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(
"CalcModePayment");
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";
358$address_zip = array();
359$address_town = array();
360$address_pays = array();
363$result = $db->query($sql);
365 $num = $db->num_rows($result);
368 $obj = $db->fetch_object($result);
370 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
371 $amount[$obj->socid] = $obj->amount_ttc;
372 $fullname = $obj->name;
373 if (!empty($obj->name_alias)) {
374 $fullname .=
' ('.$obj->name_alias.
')';
376 $name[$obj->socid] = $fullname;
378 $address_zip[$obj->socid] = $obj->zip;
379 $address_town[$obj->socid] = $obj->town;
380 $address_pays[$obj->socid] =
getCountry($obj->fk_pays);
382 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
383 $catotal += $obj->amount_ttc;
392if ($modecompta ==
"RECETTES-DEPENSES") {
393 $sql =
"SELECT '0' as socid, 'Autres' as name, sum(p.amount) as amount_ttc";
394 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
395 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
396 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
397 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
398 $sql .=
" WHERE pf.rowid IS NULL";
399 $sql .=
" AND p.fk_bank = b.rowid";
400 $sql .=
" AND b.fk_account = ba.rowid";
401 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
402 if ($date_start && $date_end) {
403 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
405 $sql .=
" GROUP BY socid, name";
406 $sql .=
" ORDER BY name";
408 $result = $db->query($sql);
410 $num = $db->num_rows($result);
413 $obj = $db->fetch_object($result);
415 if (empty($amount[$obj->socid])) {
416 $amount[$obj->socid] = $obj->amount_ttc;
418 $amount[$obj->socid] += $obj->amount_ttc;
421 $name[$obj->socid] = $obj->name;
422 $address_zip[$obj->socid] =
'';
423 $address_town[$obj->socid] =
'';
424 $address_pays[$obj->socid] =
'';
426 $catotal += $obj->amount_ttc;
438print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
439print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
441foreach ($headerparams as $key => $value) {
442 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
447print
'<div class="div-table-responsive">';
448print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
451print
'<tr class="liste_titre">';
452print
'<td class="nowraponall">';
453print
img_picto(
'',
'category',
'class="paddingrightonly"');
454print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
456print $langs->trans(
"SubCats").
'? ';
457print
'<input type="checkbox" name="subcat" value="yes"';
462print
'<td colspan="7" class="right">';
463print
'<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")).
'">';
467print
'<tr class="liste_titre">';
468print
'<td class="liste_titre left">';
469print
'<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'">';
471print
'<td class="liste_titre left">';
472print
'<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'">';
474print
'<td class="liste_titre left">';
475print
'<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).
'">';
477print
'<td class="liste_titre left">';
478print $form->select_country($search_country,
'search_country',
'', 0,
'minwidth100imp maxwidth100');
481print
'<td class="liste_titre"> </td>';
482print
'<td class="liste_titre"> </td>';
483print
'<td class="liste_titre"> </td>';
484print
'<td class="liste_titre"> </td>';
488print
"<tr class='liste_titre'>";
490 $langs->trans(
"Company"),
491 $_SERVER[
"PHP_SELF"],
500 $langs->trans(
"Zip"),
501 $_SERVER[
"PHP_SELF"],
510 $langs->trans(
"Town"),
511 $_SERVER[
"PHP_SELF"],
520 $langs->trans(
"Country"),
521 $_SERVER[
"PHP_SELF"],
529if ($modecompta ==
'CREANCES-DETTES') {
531 $langs->trans(
'AmountHT'),
532 $_SERVER[
"PHP_SELF"],
544 $langs->trans(
"AmountTTC"),
545 $_SERVER[
"PHP_SELF"],
554 $langs->trans(
"Percentage"),
555 $_SERVER[
"PHP_SELF"],
564 $langs->trans(
"OtherStatistics"),
565 $_SERVER[
"PHP_SELF"],
569 'align="center" width="20%"'
575 $arrayforsort = $name;
577 if ($sortfield ==
'nom' && $sortorder ==
'asc') {
579 $arrayforsort = $name;
581 if ($sortfield ==
'nom' && $sortorder ==
'desc') {
583 $arrayforsort = $name;
585 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
587 $arrayforsort = $amount_ht;
589 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
591 $arrayforsort = $amount_ht;
593 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
595 $arrayforsort = $amount;
597 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
599 $arrayforsort = $amount;
601 if ($sortfield ==
'zip' && $sortorder ==
'asc') {
603 $arrayforsort = $address_zip;
605 if ($sortfield ==
'zip' && $sortorder ==
'desc') {
606 arsort($address_zip);
607 $arrayforsort = $address_zip;
609 if ($sortfield ==
'town' && $sortorder ==
'asc') {
610 asort($address_town);
611 $arrayforsort = $address_town;
613 if ($sortfield ==
'town' && $sortorder ==
'desc') {
614 arsort($address_town);
615 $arrayforsort = $address_town;
617 if ($sortfield ==
'country' && $sortorder ==
'asc') {
618 asort($address_pays);
619 $arrayforsort = $address_town;
621 if ($sortfield ==
'country' && $sortorder ==
'desc') {
622 arsort($address_pays);
623 $arrayforsort = $address_town;
626 foreach ($arrayforsort as $key => $value) {
627 print
'<tr class="oddeven">';
630 $fullname = $name[$key];
632 $thirdparty_static->id = $key;
633 $thirdparty_static->name = $fullname;
634 $thirdparty_static->client = 1;
635 $linkname = $thirdparty_static->getNomUrl(1,
'customer');
637 $linkname = $langs->trans(
"PaymentsNotLinkedToInvoice");
639 print
'<td class="tdoverflowmax150">'.$linkname.
"</td>\n";
642 print $address_zip[$key];
645 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_town[$key]).
'">';
646 print $address_town[$key];
649 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($address_pays[$key]).
'">';
650 print $address_pays[$key];
654 print
'<td class="right">';
655 if ($modecompta !=
'CREANCES-DETTES') {
657 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid='.$key.
'">';
659 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid=-1">';
663 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$key.
'">';
665 print
'<a href="#">';
667 print
price($amount_ht[$key]);
672 print
'<td class="right">';
673 if ($modecompta !=
'CREANCES-DETTES') {
675 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid='.$key.
'">';
677 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?orphelins=1">';
681 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$key.
'">';
683 print
'<a href="#">';
686 print
price($amount[$key]);
691 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
694 print
'<td class="center">';
695 if (isModEnabled(
"propal") && $key > 0) {
696 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
698 if (isModEnabled(
'order') && $key > 0) {
699 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
701 if (isModEnabled(
'invoice') && $key > 0) {
702 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
710 print
'<tr class="liste_total">';
711 print
'<td>'.$langs->trans(
"Total").
'</td>';
712 print
'<td> </td>';
713 print
'<td> </td>';
714 print
'<td> </td>';
715 if ($modecompta !=
'CREANCES-DETTES') {
718 print
'<td class="right">'.price($catotal_ht).
'</td>';
720 print
'<td class="right">'.price($catotal).
'</td>';
721 print
'<td> </td>';
722 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=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 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.