31 require
'../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
38 require_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');
62 if ($selected_cat == -1) $selected_cat =
'';
64 if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
69 if ($user->socid > 0) {
70 $socid = $user->socid;
76 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
80 $hookmanager->initHooks(array(
'casoclist'));
84 $month =
GETPOST(
"month",
'int');
85 $search_societe =
GETPOST(
"search_societe",
'alpha');
86 $search_zip =
GETPOST(
"search_zip",
'alpha');
87 $search_town =
GETPOST(
"search_town",
'alpha');
88 $search_country =
GETPOST(
"search_country",
'alpha');
89 $date_startyear =
GETPOST(
"date_startyear",
'int');
90 $date_startmonth =
GETPOST(
"date_startmonth",
'int');
91 $date_startday =
GETPOST(
"date_startday",
'int');
92 $date_endyear =
GETPOST(
"date_endyear",
'int');
93 $date_endmonth =
GETPOST(
"date_endmonth",
'int');
94 $date_endday =
GETPOST(
"date_endday",
'int');
98 $year_start = $year_current;
100 $year_current = $year;
107 if (empty($date_start) || empty($date_end)) {
111 $month_start =
GETPOST(
"month") ?
GETPOST(
"month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
112 $year_end = $year_start;
113 $month_end = $month_start;
115 if (!
GETPOST(
'year') && $month_start > $month_current) {
119 $month_end = $month_start - 1;
120 if ($month_end < 1) {
152 $year_start = $tmps[
'year'];
154 $year_end = $tmpe[
'year'];
155 $nbofyear = ($year_end - $year_start) + 1;
157 $commonparams = array();
158 $commonparams[
'modecompta'] = $modecompta;
159 $commonparams[
'sortorder'] = $sortorder;
160 $commonparams[
'sortfield'] = $sortfield;
162 $headerparams = array();
163 if (!empty($date_startyear)) {
164 $headerparams[
'date_startyear'] = $date_startyear;
166 if (!empty($date_startmonth)) {
167 $headerparams[
'date_startmonth'] = $date_startmonth;
169 if (!empty($date_startday)) {
170 $headerparams[
'date_startday'] = $date_startday;
172 if (!empty($date_endyear)) {
173 $headerparams[
'date_endyear'] = $date_endyear;
175 if (!empty($date_endmonth)) {
176 $headerparams[
'date_endmonth'] = $date_endmonth;
178 if (!empty($date_endday)) {
179 $headerparams[
'date_endday'] = $date_endday;
182 $headerparams[
'q'] = $q;
185 $tableparams = array();
186 $tableparams[
'search_categ'] = $selected_cat;
187 $tableparams[
'search_societe'] = $search_societe;
188 $tableparams[
'search_zip'] = $search_zip;
189 $tableparams[
'search_town'] = $search_town;
190 $tableparams[
'search_country'] = $search_country;
191 $tableparams[
'subcat'] = ($subcat ===
true) ?
'yes' :
'';
194 $allparams = array_merge($commonparams, $headerparams, $tableparams);
195 $headerparams = array_merge($commonparams, $headerparams);
196 $tableparams = array_merge($commonparams, $tableparams);
199 foreach ($allparams as $key => $value) {
200 $paramslink .=
'&'.$key.
'='.$value;
211 $thirdparty_static =
new Societe($db);
215 if ($modecompta ==
"BOOKKEEPING") {
216 $modecompta =
"CREANCES-DETTES";
218 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
219 $modecompta =
"RECETTES-DEPENSES";
226 if ($modecompta ==
"CREANCES-DETTES") {
227 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByThirdParties");
228 $calcmode = $langs->trans(
"CalcModeDebt");
230 $description = $langs->trans(
"RulesCADue");
231 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
232 $description .= $langs->trans(
"DepositsAreNotIncluded");
234 $description .= $langs->trans(
"DepositsAreIncluded");
238 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
239 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByThirdParties");
240 $calcmode = $langs->trans(
"CalcModeEngagement");
242 $description = $langs->trans(
"RulesCAIn");
243 $description .= $langs->trans(
"DepositsAreIncluded");
246 } elseif ($modecompta ==
"BOOKKEEPING") {
247 } elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
249 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
251 $period .=
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
253 $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>';
258 report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
260 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
261 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
271 if ($modecompta ==
'CREANCES-DETTES') {
272 $sql =
"SELECT DISTINCT s.rowid as socid, s.nom as name, s.name_alias, s.zip, s.town, s.fk_pays,";
273 $sql .=
" sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
274 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"societe as s";
275 if ($selected_cat === -2) {
276 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as cs ON s.rowid = cs.fk_soc";
277 } elseif ($selected_cat) {
278 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_societe as cs";
280 $sql .=
" WHERE f.fk_statut in (1,2)";
281 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
282 $sql .=
" AND f.type IN (0,1,2,5)";
284 $sql .=
" AND f.type IN (0,1,2,3,5)";
286 $sql .=
" AND f.fk_soc = s.rowid";
287 if ($date_start && $date_end) {
288 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
290 if ($selected_cat === -2) {
291 $sql .=
" AND cs.fk_soc is null";
292 } elseif ($selected_cat) {
293 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
295 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
298 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
300 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
305 $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";
306 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
307 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
308 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
309 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
310 if ($selected_cat === -2) {
311 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as cs ON s.rowid = cs.fk_soc";
312 } elseif ($selected_cat) {
313 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_societe as cs";
315 $sql .=
" WHERE p.rowid = pf.fk_paiement";
316 $sql .=
" AND pf.fk_facture = f.rowid";
317 $sql .=
" AND f.fk_soc = s.rowid";
318 if ($date_start && $date_end) {
319 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
321 if ($selected_cat === -2) {
322 $sql .=
" AND cs.fk_soc is null";
323 } elseif ($selected_cat) {
324 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
326 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
329 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
331 } elseif ($modecompta ==
"BOOKKEEPING") {
332 } elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
334 if (!empty($search_societe)) {
337 if (!empty($search_zip)) {
340 if (!empty($search_town)) {
343 if ($search_country > 0) {
344 $sql .=
' AND s.fk_pays = '.((int) $search_country);
346 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
348 $sql .=
" AND f.fk_soc = ".((int) $socid);
350 $sql .=
" GROUP BY s.rowid, s.nom, s.name_alias, s.zip, s.town, s.fk_pays";
351 $sql .=
" ORDER BY s.rowid";
357 $result = $db->query($sql);
359 $num = $db->num_rows($result);
362 $obj = $db->fetch_object($result);
364 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
365 $amount[$obj->socid] = $obj->amount_ttc;
366 $fullname = $obj->name;
367 if (!empty($obj->name_alias)) {
368 $fullname .=
' ('.$obj->name_alias.
')';
370 $name[$obj->socid] = $fullname;
372 $address_zip[$obj->socid] = $obj->zip;
373 $address_town[$obj->socid] = $obj->town;
374 $address_pays[$obj->socid] =
getCountry($obj->fk_pays);
376 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
377 $catotal += $obj->amount_ttc;
386 if ($modecompta ==
"RECETTES-DEPENSES") {
387 $sql =
"SELECT '0' as socid, 'Autres' as name, sum(p.amount) as amount_ttc";
388 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
389 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
390 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
391 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
392 $sql .=
" WHERE pf.rowid IS NULL";
393 $sql .=
" AND p.fk_bank = b.rowid";
394 $sql .=
" AND b.fk_account = ba.rowid";
395 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
396 if ($date_start && $date_end) {
397 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
399 $sql .=
" GROUP BY socid, name";
400 $sql .=
" ORDER BY name";
402 $result = $db->query($sql);
404 $num = $db->num_rows($result);
407 $obj = $db->fetch_object($result);
409 $amount[$obj->rowid] += $obj->amount_ttc;
411 $name[$obj->rowid] = $obj->name;
412 $address_zip[$obj->rowid] = $obj->zip;
413 $address_town[$obj->rowid] = $obj->town;
414 $address_pays[$obj->rowid] =
getCountry($obj->fk_pays);
416 $catotal += $obj->amount_ttc;
428 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
429 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
431 foreach ($headerparams as $key => $value) {
432 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
437 print
'<div class="div-table-responsive">';
438 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
441 print
'<tr class="liste_titre">';
442 print
'<td class="nowraponall">';
443 print
img_picto(
'',
'category',
'class="paddingrightonly"');
444 print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
446 print $langs->trans(
"SubCats").
'? ';
447 print
'<input type="checkbox" name="subcat" value="yes"';
452 print
'<td colspan="7" class="right">';
453 print
'<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")).
'">';
457 print
'<tr class="liste_titre">';
458 print
'<td class="liste_titre left">';
459 print
'<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'">';
461 print
'<td class="liste_titre left">';
462 print
'<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'">';
464 print
'<td class="liste_titre left">';
465 print
'<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).
'">';
467 print
'<td class="liste_titre left">';
468 print
$form->select_country($search_country,
'search_country',
'', 0,
'minwidth100imp maxwidth100');
471 print
'<td class="liste_titre"> </td>';
472 print
'<td class="liste_titre"> </td>';
473 print
'<td class="liste_titre"> </td>';
474 print
'<td class="liste_titre"> </td>';
478 print
"<tr class='liste_titre'>";
480 $langs->trans(
"Company"),
481 $_SERVER[
"PHP_SELF"],
490 $langs->trans(
"Zip"),
491 $_SERVER[
"PHP_SELF"],
500 $langs->trans(
"Town"),
501 $_SERVER[
"PHP_SELF"],
510 $langs->trans(
"Country"),
511 $_SERVER[
"PHP_SELF"],
519 if ($modecompta ==
'CREANCES-DETTES') {
521 $langs->trans(
'AmountHT'),
522 $_SERVER[
"PHP_SELF"],
534 $langs->trans(
"AmountTTC"),
535 $_SERVER[
"PHP_SELF"],
544 $langs->trans(
"Percentage"),
545 $_SERVER[
"PHP_SELF"],
554 $langs->trans(
"OtherStatistics"),
555 $_SERVER[
"PHP_SELF"],
559 'align="center" width="20%"'
564 if (count($amount)) {
565 $arrayforsort = $name;
567 if ($sortfield ==
'nom' && $sortorder ==
'asc') {
569 $arrayforsort = $name;
571 if ($sortfield ==
'nom' && $sortorder ==
'desc') {
573 $arrayforsort = $name;
575 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
577 $arrayforsort = $amount_ht;
579 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
581 $arrayforsort = $amount_ht;
583 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
585 $arrayforsort = $amount;
587 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
589 $arrayforsort = $amount;
591 if ($sortfield ==
'zip' && $sortorder ==
'asc') {
593 $arrayforsort = $address_zip;
595 if ($sortfield ==
'zip' && $sortorder ==
'desc') {
596 arsort($address_zip);
597 $arrayforsort = $address_zip;
599 if ($sortfield ==
'town' && $sortorder ==
'asc') {
600 asort($address_town);
601 $arrayforsort = $address_town;
603 if ($sortfield ==
'town' && $sortorder ==
'desc') {
604 arsort($address_town);
605 $arrayforsort = $address_town;
607 if ($sortfield ==
'country' && $sortorder ==
'asc') {
608 asort($address_pays);
609 $arrayforsort = $address_town;
611 if ($sortfield ==
'country' && $sortorder ==
'desc') {
612 arsort($address_pays);
613 $arrayforsort = $address_town;
616 foreach ($arrayforsort as $key => $value) {
617 print
'<tr class="oddeven">';
620 $fullname = $name[$key];
622 $thirdparty_static->id = $key;
623 $thirdparty_static->name = $fullname;
624 $thirdparty_static->client = 1;
625 $linkname = $thirdparty_static->getNomUrl(1,
'customer');
627 $linkname = $langs->trans(
"PaymentsNotLinkedToInvoice");
629 print
"<td>".$linkname.
"</td>\n";
632 print $address_zip[$key];
636 print $address_town[$key];
640 print $address_pays[$key];
644 print
'<td class="right">';
645 if ($modecompta !=
'CREANCES-DETTES') {
647 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid='.$key.
'">';
649 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid=-1">';
653 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$key.
'">';
655 print
'<a href="#">';
657 print
price($amount_ht[$key]);
662 print
'<td class="right">';
663 if ($modecompta !=
'CREANCES-DETTES') {
665 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid='.$key.
'">';
667 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?orphelins=1">';
671 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$key.
'">';
673 print
'<a href="#">';
676 print
price($amount[$key]);
681 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
684 print
'<td class="center">';
686 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
689 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
692 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
700 print
'<tr class="liste_total">';
701 print
'<td>'.$langs->trans(
"Total").
'</td>';
702 print
'<td> </td>';
703 print
'<td> </td>';
704 print
'<td> </td>';
705 if ($modecompta !=
'CREANCES-DETTES') {
708 print
'<td class="right">'.price($catotal_ht).
'</td>';
710 print
'<td class="right">'.price($catotal).
'</td>';
711 print
'<td> </td>';
712 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.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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.
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.
isModEnabled($module)
Is Dolibarr module enabled.
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.
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.