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) $selected_cat =
'';
64if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
69if ($user->socid > 0) {
70 $socid = $user->socid;
72if (isModEnabled(
'comptabilite')) {
75if (isModEnabled(
'accounting')) {
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;
107if (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();
163if (!empty($date_startyear)) {
164 $headerparams[
'date_startyear'] = $date_startyear;
166if (!empty($date_startmonth)) {
167 $headerparams[
'date_startmonth'] = $date_startmonth;
169if (!empty($date_startday)) {
170 $headerparams[
'date_startday'] = $date_startday;
172if (!empty($date_endyear)) {
173 $headerparams[
'date_endyear'] = $date_endyear;
175if (!empty($date_endmonth)) {
176 $headerparams[
'date_endmonth'] = $date_endmonth;
178if (!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);
199foreach ($allparams as $key => $value) {
200 $paramslink .=
'&'.$key.
'='.$value;
210$form =
new Form($db);
211$thirdparty_static =
new Societe($db);
215if ($modecompta ==
"BOOKKEEPING") {
216 $modecompta =
"CREANCES-DETTES";
218if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
219 $modecompta =
"RECETTES-DEPENSES";
226if ($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>';
258report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
260if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
261 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
271if ($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") {
334if (!empty($search_societe)) {
337if (!empty($search_zip)) {
340if (!empty($search_town)) {
343if ($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;
386if ($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 if (empty($amount[$obj->socid])) {
410 $amount[$obj->socid] = $obj->amount_ttc;
412 $amount[$obj->socid] += $obj->amount_ttc;
415 $name[$obj->socid] = $obj->name;
416 $address_zip[$obj->socid] =
'';
417 $address_town[$obj->socid] =
'';
418 $address_pays[$obj->socid] = 0;
420 $catotal += $obj->amount_ttc;
432print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
433print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
435foreach ($headerparams as $key => $value) {
436 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
441print
'<div class="div-table-responsive">';
442print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
445print
'<tr class="liste_titre">';
446print
'<td class="nowraponall">';
447print
img_picto(
'',
'category',
'class="paddingrightonly"');
448print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
450print $langs->trans(
"SubCats").
'? ';
451print
'<input type="checkbox" name="subcat" value="yes"';
456print
'<td colspan="7" class="right">';
457print
'<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")).
'">';
461print
'<tr class="liste_titre">';
462print
'<td class="liste_titre left">';
463print
'<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'">';
465print
'<td class="liste_titre left">';
466print
'<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'">';
468print
'<td class="liste_titre left">';
469print
'<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).
'">';
471print
'<td class="liste_titre left">';
472print $form->select_country($search_country,
'search_country',
'', 0,
'minwidth100imp maxwidth100');
475print
'<td class="liste_titre"> </td>';
476print
'<td class="liste_titre"> </td>';
477print
'<td class="liste_titre"> </td>';
478print
'<td class="liste_titre"> </td>';
482print
"<tr class='liste_titre'>";
484 $langs->trans(
"Company"),
485 $_SERVER[
"PHP_SELF"],
494 $langs->trans(
"Zip"),
495 $_SERVER[
"PHP_SELF"],
504 $langs->trans(
"Town"),
505 $_SERVER[
"PHP_SELF"],
514 $langs->trans(
"Country"),
515 $_SERVER[
"PHP_SELF"],
523if ($modecompta ==
'CREANCES-DETTES') {
525 $langs->trans(
'AmountHT'),
526 $_SERVER[
"PHP_SELF"],
538 $langs->trans(
"AmountTTC"),
539 $_SERVER[
"PHP_SELF"],
548 $langs->trans(
"Percentage"),
549 $_SERVER[
"PHP_SELF"],
558 $langs->trans(
"OtherStatistics"),
559 $_SERVER[
"PHP_SELF"],
563 'align="center" width="20%"'
569 $arrayforsort = $name;
571 if ($sortfield ==
'nom' && $sortorder ==
'asc') {
573 $arrayforsort = $name;
575 if ($sortfield ==
'nom' && $sortorder ==
'desc') {
577 $arrayforsort = $name;
579 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
581 $arrayforsort = $amount_ht;
583 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
585 $arrayforsort = $amount_ht;
587 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
589 $arrayforsort = $amount;
591 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
593 $arrayforsort = $amount;
595 if ($sortfield ==
'zip' && $sortorder ==
'asc') {
597 $arrayforsort = $address_zip;
599 if ($sortfield ==
'zip' && $sortorder ==
'desc') {
600 arsort($address_zip);
601 $arrayforsort = $address_zip;
603 if ($sortfield ==
'town' && $sortorder ==
'asc') {
604 asort($address_town);
605 $arrayforsort = $address_town;
607 if ($sortfield ==
'town' && $sortorder ==
'desc') {
608 arsort($address_town);
609 $arrayforsort = $address_town;
611 if ($sortfield ==
'country' && $sortorder ==
'asc') {
612 asort($address_pays);
613 $arrayforsort = $address_town;
615 if ($sortfield ==
'country' && $sortorder ==
'desc') {
616 arsort($address_pays);
617 $arrayforsort = $address_town;
620 foreach ($arrayforsort as $key => $value) {
621 print
'<tr class="oddeven">';
624 $fullname = $name[$key];
626 $thirdparty_static->id = $key;
627 $thirdparty_static->name = $fullname;
628 $thirdparty_static->client = 1;
629 $linkname = $thirdparty_static->getNomUrl(1,
'customer');
631 $linkname = $langs->trans(
"PaymentsNotLinkedToInvoice");
633 print
"<td>".$linkname.
"</td>\n";
636 print $address_zip[$key];
640 print $address_town[$key];
644 print $address_pays[$key];
648 print
'<td class="right">';
649 if ($modecompta !=
'CREANCES-DETTES') {
651 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid='.$key.
'">';
653 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid=-1">';
657 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$key.
'">';
659 print
'<a href="#">';
661 print
price($amount_ht[$key]);
666 print
'<td class="right">';
667 if ($modecompta !=
'CREANCES-DETTES') {
669 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?socid='.$key.
'">';
671 print
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?orphelins=1">';
675 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$key.
'">';
677 print
'<a href="#">';
680 print
price($amount[$key]);
685 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
688 print
'<td class="center">';
689 if (isModEnabled(
"propal") && $key > 0) {
690 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
692 if (isModEnabled(
'commande') && $key > 0) {
693 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
695 if (isModEnabled(
'facture') && $key > 0) {
696 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
704 print
'<tr class="liste_total">';
705 print
'<td>'.$langs->trans(
"Total").
'</td>';
706 print
'<td> </td>';
707 print
'<td> </td>';
708 print
'<td> </td>';
709 if ($modecompta !=
'CREANCES-DETTES') {
712 print
'<td class="right">'.price($catotal_ht).
'</td>';
714 print
'<td class="right">'.price($catotal).
'</td>';
715 print
'<td> </td>';
716 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.
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.
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.