26require
'../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
36$langs->loadLangs(array(
'companies',
'categories',
'bills',
'compta'));
39$modecompta = $conf->global->ACCOUNTING_MODE;
41 $modecompta =
GETPOST(
"modecompta");
45$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
46$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
55$socid =
GETPOST(
'socid',
'int');
58$selected_cat = (int)
GETPOST(
'search_categ',
'int');
60if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
65$hookmanager->initHooks(array(
'supplierturnoverbythirdpartylist'));
69$search_societe =
GETPOST(
"search_societe",
'alpha');
70$search_zip =
GETPOST(
"search_zip",
'alpha');
71$search_town =
GETPOST(
"search_town",
'alpha');
72$search_country =
GETPOST(
"search_country",
'alpha');
77$month =
GETPOST(
"month",
'int');
78$date_startyear =
GETPOST(
"date_startyear",
'alpha');
79$date_startmonth =
GETPOST(
"date_startmonth",
'alpha');
80$date_startday =
GETPOST(
"date_startday",
'alpha');
81$date_endyear =
GETPOST(
"date_endyear",
'alpha');
82$date_endmonth =
GETPOST(
"date_endmonth",
'alpha');
83$date_endday =
GETPOST(
"date_endday",
'alpha');
87 $year_start = $year_current;
89 $year_current = $year;
96if (empty($date_start) || empty($date_end)) {
101 $year_end = $year_start;
102 $month_end = $month_start;
104 if (!
GETPOST(
'year') && $month_start > $month_current) {
108 $month_end = $month_start - 1;
109 if ($month_end < 1) {
140$year_start = $tmps[
'year'];
142$year_end = $tmpe[
'year'];
143$nbofyear = ($year_end - $year_start) + 1;
145$commonparams = array();
146$commonparams[
'modecompta'] = $modecompta;
147$commonparams[
'sortorder'] = $sortorder;
148$commonparams[
'sortfield'] = $sortfield;
150$headerparams = array();
151$headerparams[
'date_startyear'] = $date_startyear;
152$headerparams[
'date_startmonth'] = $date_startmonth;
153$headerparams[
'date_startday'] = $date_startday;
154$headerparams[
'date_endyear'] = $date_endyear;
155$headerparams[
'date_endmonth'] = $date_endmonth;
156$headerparams[
'date_endday'] = $date_endday;
158$tableparams = array();
159$tableparams[
'search_categ'] = $selected_cat;
160$tableparams[
'search_societe'] = $search_societe;
161$tableparams[
'search_zip'] = $search_zip;
162$tableparams[
'search_town'] = $search_town;
163$tableparams[
'search_country'] = $search_country;
164$tableparams[
'subcat'] = ($subcat ===
true) ?
'yes' :
'';
167$allparams = array_merge($commonparams, $headerparams, $tableparams);
168$headerparams = array_merge($commonparams, $headerparams);
169$tableparams = array_merge($commonparams, $tableparams);
172foreach ($allparams as $key => $value) {
173 $paramslink .=
'&'.$key.
'='.$value;
177if ($user->socid > 0) {
178 $socid = $user->socid;
180if (isModEnabled(
'comptabilite')) {
183if (isModEnabled(
'accounting')) {
184 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
194$form =
new Form($db);
195$thirdparty_static =
new Societe($db);
199if ($modecompta ==
"BOOKKEEPING") {
200 $modecompta =
"CREANCES-DETTES";
202if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
203 $modecompta =
"RECETTES-DEPENSES";
207if ($modecompta ==
"CREANCES-DETTES") {
208 $name = $langs->trans(
"PurchaseTurnover").
', '.$langs->trans(
"ByThirdParties");
209 $calcmode = $langs->trans(
"CalcModeDebt");
211 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
213} elseif ($modecompta ==
"RECETTES-DEPENSES") {
214 $name = $langs->trans(
"PurchaseTurnoverCollected").
', '.$langs->trans(
"ByThirdParties");
215 $calcmode = $langs->trans(
"CalcModeEngagement");
217 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
219} elseif ($modecompta ==
"BOOKKEEPING") {
221} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
225$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
227$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
229 $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>';
236report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
238if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
239 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
248if ($modecompta ==
'CREANCES-DETTES') {
249 $sql =
"SELECT DISTINCT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,";
250 $sql .=
" sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
251 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f, ".MAIN_DB_PREFIX.
"societe as s";
252 if ($selected_cat === -2) {
253 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
254 } elseif ($selected_cat) {
255 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
257 $sql .=
" WHERE f.fk_statut in (1,2)";
258 $sql .=
" AND f.type IN (0,2)";
259 $sql .=
" AND f.fk_soc = s.rowid";
260 if ($date_start && $date_end) {
261 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
263 if ($selected_cat === -2) {
264 $sql .=
" AND cs.fk_soc is null";
265 } elseif ($selected_cat) {
266 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
268 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
271 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
273} elseif ($modecompta ==
"RECETTES-DEPENSES") {
274 $sql =
"SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc";
275 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
276 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
277 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn as p";
278 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
279 if ($selected_cat === -2) {
280 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
281 } elseif ($selected_cat) {
282 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
284 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn";
285 $sql .=
" AND pf.fk_facturefourn = f.rowid";
286 $sql .=
" AND f.fk_soc = s.rowid";
287 if ($date_start && $date_end) {
288 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$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";
301if (!empty($search_societe)) {
304if (!empty($search_zip)) {
307if (!empty($search_town)) {
310if ($search_country > 0) {
311 $sql .=
' AND s.fk_pays = '.((int) $search_country);
313$sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
315 $sql .=
" AND f.fk_soc = ".((int) $socid);
317$sql .=
" GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays";
318$sql .=
" ORDER BY s.rowid";
324dol_syslog(
"supplier_turnover_by_thirdparty", LOG_DEBUG);
325$resql = $db->query($sql);
327 $num = $db->num_rows($resql);
330 $obj = $db->fetch_object($resql);
332 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
333 $amount[$obj->socid] = $obj->amount_ttc;
334 $name[$obj->socid] = $obj->name;
336 $address_zip[$obj->socid] = $obj->zip;
337 $address_town[$obj->socid] = $obj->town;
338 $address_pays[$obj->socid] =
getCountry($obj->fk_pays);
340 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
341 $catotal += $obj->amount_ttc;
351print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
352print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
354foreach ($headerparams as $key => $value) {
355 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
360print
'<div class="div-table-responsive">';
361print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
364print
'<tr class="liste_titre">';
366print
img_picto(
'',
'category',
'class="paddingrightonly"');
367print $formother->select_categories(Categorie::TYPE_SUPPLIER, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
369print $langs->trans(
"SubCats").
'? ';
370print
'<input type="checkbox" name="subcat" value="yes"';
375print
'<td colspan="7" class="right">';
376print
'<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")).
'">';
380print
'<tr class="liste_titre">';
381print
'<td class="liste_titre left">';
382print
'<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'">';
384print
'<td class="liste_titre left">';
385print
'<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'">';
387print
'<td class="liste_titre left">';
388print
'<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).
'">';
390print
'<td class="liste_titre left">';
391print $form->select_country($search_country,
'search_country');
394print
'<td class="liste_titre"> </td>';
395print
'<td class="liste_titre"> </td>';
396print
'<td class="liste_titre"> </td>';
397print
'<td class="liste_titre"> </td>';
401print
"<tr class='liste_titre'>";
403 $langs->trans(
"Company"),
404 $_SERVER[
"PHP_SELF"],
413 $langs->trans(
"Zip"),
414 $_SERVER[
"PHP_SELF"],
423 $langs->trans(
"Town"),
424 $_SERVER[
"PHP_SELF"],
433 $langs->trans(
"Country"),
434 $_SERVER[
"PHP_SELF"],
442if ($modecompta ==
'CREANCES-DETTES') {
444 $langs->trans(
'AmountHT'),
445 $_SERVER[
"PHP_SELF"],
457 $langs->trans(
"AmountTTC"),
458 $_SERVER[
"PHP_SELF"],
467 $langs->trans(
"Percentage"),
468 $_SERVER[
"PHP_SELF"],
477 $langs->trans(
"OtherStatistics"),
478 $_SERVER[
"PHP_SELF"],
482 'align="center" width="20%"'
488 $arrayforsort = $name;
490 if ($sortfield ==
'nom' && $sortorder ==
'asc') {
492 $arrayforsort = $name;
494 if ($sortfield ==
'nom' && $sortorder ==
'desc') {
496 $arrayforsort = $name;
498 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
500 $arrayforsort = $amount_ht;
502 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
504 $arrayforsort = $amount_ht;
506 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
508 $arrayforsort = $amount;
510 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
512 $arrayforsort = $amount;
514 if ($sortfield ==
'zip' && $sortorder ==
'asc') {
516 $arrayforsort = $address_zip;
518 if ($sortfield ==
'zip' && $sortorder ==
'desc') {
519 arsort($address_zip);
520 $arrayforsort = $address_zip;
522 if ($sortfield ==
'town' && $sortorder ==
'asc') {
523 asort($address_town);
524 $arrayforsort = $address_town;
526 if ($sortfield ==
'town' && $sortorder ==
'desc') {
527 arsort($address_town);
528 $arrayforsort = $address_town;
530 if ($sortfield ==
'country' && $sortorder ==
'asc') {
531 asort($address_pays);
532 $arrayforsort = $address_town;
534 if ($sortfield ==
'country' && $sortorder ==
'desc') {
535 arsort($address_pays);
536 $arrayforsort = $address_town;
539 foreach ($arrayforsort as $key => $value) {
540 print
'<tr class="oddeven">';
543 $fullname = $name[$key];
545 $thirdparty_static->id = $key;
546 $thirdparty_static->name = $fullname;
547 $thirdparty_static->client = 1;
548 $linkname = $thirdparty_static->getNomUrl(1,
'supplier');
550 $linkname = $langs->trans(
"PaymentsNotLinkedToInvoice");
552 print
"<td>".$linkname.
"</td>\n";
555 print $address_zip[$key];
559 print $address_town[$key];
563 print $address_pays[$key];
567 print
'<td class="right">';
568 if ($modecompta !=
'CREANCES-DETTES') {
570 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
572 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid=-1">';
576 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
578 print
'<a href="#">';
580 print
price($amount_ht[$key]);
585 print
'<td class="right">';
586 if ($modecompta !=
'CREANCES-DETTES') {
588 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
590 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?orphelins=1">';
594 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
596 print
'<a href="#">';
599 print
price($amount[$key]);
604 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
607 print
'<td class="center">';
608 if (isModEnabled(
'supplier_proposal') && $key > 0) {
609 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
611 if (isModEnabled(
"supplier_order") && $key > 0) {
612 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
614 if (isModEnabled(
"supplier_invoice") && $key > 0) {
615 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
623 print
'<tr class="liste_total">';
624 print
'<td>'.$langs->trans(
"Total").
'</td>';
625 print
'<td> </td>';
626 print
'<td> </td>';
627 print
'<td> </td>';
628 if ($modecompta !=
'CREANCES-DETTES') {
631 print
'<td class="right">'.price($catotal_ht).
'</td>';
633 print
'<td class="right">'.price($catotal).
'</td>';
634 print
'<td> </td>';
635 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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.