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'));
41 $modecompta =
GETPOST(
"modecompta");
45$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
46$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
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",
'aZ09');
74$date_startyear =
GETPOST(
"date_startyear",
'alpha');
75$date_startmonth =
GETPOST(
"date_startmonth",
'alpha');
76$date_startday =
GETPOST(
"date_startday",
'alpha');
77$date_endyear =
GETPOST(
"date_endyear",
'alpha');
78$date_endmonth =
GETPOST(
"date_endmonth",
'alpha');
79$date_endday =
GETPOST(
"date_endday",
'alpha');
89 $year_start = $year_current - ($nbofyear - 1);
91 $year_current = $year;
93 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
95$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
96$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
99if (empty($date_start) || empty($date_end)) {
103 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
106 if (!$year && $month_start > $month_current) {
110 $month_end = $month_start - 1;
111 if ($month_end < 1) {
115 $month_end = $month_start;
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(
"CalcModePayment");
217 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
220} elseif ($modecompta ==
"BOOKKEEPING") {
222} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
227$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
229$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
231 $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>';
238report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
240if (isModEnabled(
'accounting')) {
241 if ($modecompta !=
'BOOKKEEPING') {
242 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
246 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
247 if (empty($pcgvercode)) {
248 $pcgvercode = $pcgverid;
251 $sql =
"SELECT b.rowid ";
252 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
253 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
254 $sql .=
" WHERE b.entity = ".$conf->entity;
255 $sql .=
" AND b.numero_compte = aa.account_number";
256 $sql .=
" AND aa.entity = ".$conf->entity;
257 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
258 $sql .= $db->plimit(1);
260 $resql = $db->query($sql);
261 $nb = $db->num_rows($resql);
263 $langs->load(
"errors");
264 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0, 1);
275$address_zip = array();
276$address_town = array();
277$address_pays = array();
279if ($modecompta ==
'CREANCES-DETTES') {
280 $sql =
"SELECT DISTINCT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,";
281 $sql .=
" sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
282 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f, ".MAIN_DB_PREFIX.
"societe as s";
283 if ($selected_cat === -2) {
284 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
285 } elseif ($selected_cat) {
286 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
288 $sql .=
" WHERE f.fk_statut in (1,2)";
289 $sql .=
" AND f.type IN (0,2)";
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") {
305 $sql =
"SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc";
306 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
307 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
308 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn as p";
309 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
310 if ($selected_cat === -2) {
311 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
312 } elseif ($selected_cat) {
313 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
315 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn";
316 $sql .=
" AND pf.fk_facturefourn = 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";
332if (!empty($search_societe)) {
335if (!empty($search_zip)) {
338if (!empty($search_town)) {
341if ($search_country > 0) {
342 $sql .=
' AND s.fk_pays = '.((int) $search_country);
344$sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
346 $sql .=
" AND f.fk_soc = ".((int) $socid);
348$sql .=
" GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays";
349$sql .=
" ORDER BY s.rowid";
355dol_syslog(
"supplier_turnover_by_thirdparty", LOG_DEBUG);
356$resql = $db->query($sql);
358 $num = $db->num_rows($resql);
361 $obj = $db->fetch_object($resql);
363 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
364 $amount[$obj->socid] = $obj->amount_ttc;
365 $name[$obj->socid] = $obj->name;
367 $address_zip[$obj->socid] = $obj->zip;
368 $address_town[$obj->socid] = $obj->town;
369 $address_pays[$obj->socid] =
getCountry($obj->fk_pays);
371 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
372 $catotal += $obj->amount_ttc;
382print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
383print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
385foreach ($headerparams as $key => $value) {
386 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
391print
'<div class="div-table-responsive">';
392print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
395print
'<tr class="liste_titre">';
397print
img_picto(
'',
'category',
'class="paddingrightonly"');
398print $formother->select_categories(Categorie::TYPE_SUPPLIER, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
400print
'<label for="subcat" class="marginleftonly">'.$langs->trans(
"SubCats").
'?</label> ';
401print
'<input type="checkbox" id="subcat" name="subcat" value="yes"';
406print
'<td colspan="7" class="right">';
407print
'<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")).
'">';
411print
'<tr class="liste_titre">';
412print
'<td class="liste_titre left">';
413print
'<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'">';
415print
'<td class="liste_titre left">';
416print
'<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'">';
418print
'<td class="liste_titre left">';
419print
'<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).
'">';
421print
'<td class="liste_titre left">';
422print $form->select_country($search_country,
'search_country',
'', 0,
'maxwidth150');
425print
'<td class="liste_titre"> </td>';
426print
'<td class="liste_titre"> </td>';
427print
'<td class="liste_titre"> </td>';
428print
'<td class="liste_titre"> </td>';
432print
"<tr class='liste_titre'>";
434 $langs->trans(
"Company"),
435 $_SERVER[
"PHP_SELF"],
444 $langs->trans(
"Zip"),
445 $_SERVER[
"PHP_SELF"],
454 $langs->trans(
"Town"),
455 $_SERVER[
"PHP_SELF"],
464 $langs->trans(
"Country"),
465 $_SERVER[
"PHP_SELF"],
473if ($modecompta ==
'CREANCES-DETTES') {
475 $langs->trans(
'AmountHT'),
476 $_SERVER[
"PHP_SELF"],
488 $langs->trans(
"AmountTTC"),
489 $_SERVER[
"PHP_SELF"],
498 $langs->trans(
"Percentage"),
499 $_SERVER[
"PHP_SELF"],
508 $langs->trans(
"OtherStatistics"),
509 $_SERVER[
"PHP_SELF"],
513 'align="center" width="20%"'
519 $arrayforsort = $name;
521 if ($sortfield ==
'nom' && $sortorder ==
'asc') {
523 $arrayforsort = $name;
525 if ($sortfield ==
'nom' && $sortorder ==
'desc') {
527 $arrayforsort = $name;
529 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
531 $arrayforsort = $amount_ht;
533 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
535 $arrayforsort = $amount_ht;
537 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
539 $arrayforsort = $amount;
541 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
543 $arrayforsort = $amount;
545 if ($sortfield ==
'zip' && $sortorder ==
'asc') {
547 $arrayforsort = $address_zip;
549 if ($sortfield ==
'zip' && $sortorder ==
'desc') {
550 arsort($address_zip);
551 $arrayforsort = $address_zip;
553 if ($sortfield ==
'town' && $sortorder ==
'asc') {
554 asort($address_town);
555 $arrayforsort = $address_town;
557 if ($sortfield ==
'town' && $sortorder ==
'desc') {
558 arsort($address_town);
559 $arrayforsort = $address_town;
561 if ($sortfield ==
'country' && $sortorder ==
'asc') {
562 asort($address_pays);
563 $arrayforsort = $address_town;
565 if ($sortfield ==
'country' && $sortorder ==
'desc') {
566 arsort($address_pays);
567 $arrayforsort = $address_town;
570 foreach ($arrayforsort as $key => $value) {
571 print
'<tr class="oddeven">';
574 $fullname = $name[$key];
576 $thirdparty_static->id = $key;
577 $thirdparty_static->name = $fullname;
578 $thirdparty_static->client = 1;
579 $linkname = $thirdparty_static->getNomUrl(1,
'supplier');
581 $linkname = $langs->trans(
"PaymentsNotLinkedToInvoice");
583 print
"<td>".$linkname.
"</td>\n";
586 print $address_zip[$key];
590 print $address_town[$key];
594 print $address_pays[$key];
598 print
'<td class="right">';
599 if ($modecompta !=
'CREANCES-DETTES') {
601 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
603 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid=-1">';
607 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
609 print
'<a href="#">';
611 print
price($amount_ht[$key]);
616 print
'<td class="right">';
617 if ($modecompta !=
'CREANCES-DETTES') {
619 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
621 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?orphelins=1">';
625 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
627 print
'<a href="#">';
630 print
price($amount[$key]);
635 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
638 print
'<td class="center">';
639 if (isModEnabled(
'supplier_proposal') && $key > 0) {
640 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
642 if (isModEnabled(
"supplier_order") && $key > 0) {
643 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
645 if (isModEnabled(
"supplier_invoice") && $key > 0) {
646 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
654 print
'<tr class="liste_total">';
655 print
'<td>'.$langs->trans(
"Total").
'</td>';
659 if ($modecompta !=
'CREANCES-DETTES') {
662 print
'<td class="right">'.price($catotal_ht).
'</td>';
664 print
'<td class="right">'.price($catotal).
'</td>';
671 print
'<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
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_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
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.