28require
'../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
38$langs->loadLangs(array(
'companies',
'categories',
'bills',
'compta'));
43 $modecompta =
GETPOST(
"modecompta");
47$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
48$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
62if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
67$hookmanager->initHooks(array(
'supplierturnoverbythirdpartylist'));
71$search_societe =
GETPOST(
"search_societe",
'alpha');
72$search_zip =
GETPOST(
"search_zip",
'alpha');
73$search_town =
GETPOST(
"search_town",
'alpha');
74$search_country =
GETPOST(
"search_country",
'aZ09');
76$date_startyear =
GETPOST(
"date_startyear",
'alpha');
77$date_startmonth =
GETPOST(
"date_startmonth",
'alpha');
78$date_startday =
GETPOST(
"date_startday",
'alpha');
79$date_endyear =
GETPOST(
"date_endyear",
'alpha');
80$date_endmonth =
GETPOST(
"date_endmonth",
'alpha');
81$date_endday =
GETPOST(
"date_endday",
'alpha');
91 $year_start = $year_current - ($nbofyear - 1);
93 $year_current = $year;
95 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
97$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
98$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
101if (empty($date_start) || empty($date_end)) {
105 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
108 if (!$year && $month_start > $month_current) {
112 $month_end = $month_start - 1;
113 if ($month_end < 1) {
117 $month_end = $month_start;
142$year_start = $tmps[
'year'];
144$year_end = $tmpe[
'year'];
145$nbofyear = ($year_end - $year_start) + 1;
147$commonparams = array();
148$commonparams[
'modecompta'] = $modecompta;
149$commonparams[
'sortorder'] = $sortorder;
150$commonparams[
'sortfield'] = $sortfield;
152$headerparams = array();
153$headerparams[
'date_startyear'] = $date_startyear;
154$headerparams[
'date_startmonth'] = $date_startmonth;
155$headerparams[
'date_startday'] = $date_startday;
156$headerparams[
'date_endyear'] = $date_endyear;
157$headerparams[
'date_endmonth'] = $date_endmonth;
158$headerparams[
'date_endday'] = $date_endday;
160$tableparams = array();
161$tableparams[
'search_categ'] = $selected_cat;
162$tableparams[
'search_societe'] = $search_societe;
163$tableparams[
'search_zip'] = $search_zip;
164$tableparams[
'search_town'] = $search_town;
165$tableparams[
'search_country'] = $search_country;
166$tableparams[
'subcat'] = $subcat ?
'yes' :
'';
169$allparams = array_merge($commonparams, $headerparams, $tableparams);
170$headerparams = array_merge($commonparams, $headerparams);
171$tableparams = array_merge($commonparams, $tableparams);
174foreach ($allparams as $key => $value) {
175 $paramslink .=
'&'.$key.
'='.$value;
179if ($user->socid > 0) {
180 $socid = $user->socid;
182if (isModEnabled(
'comptabilite')) {
185if (isModEnabled(
'accounting')) {
186 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
196$form =
new Form($db);
197$thirdparty_static =
new Societe($db);
201if ($modecompta ==
"BOOKKEEPING") {
202 $modecompta =
"CREANCES-DETTES";
204if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
205 $modecompta =
"RECETTES-DEPENSES";
209if ($modecompta ==
"CREANCES-DETTES") {
210 $name = $langs->trans(
"PurchaseTurnover").
', '.$langs->trans(
"ByThirdParties");
211 $calcmode = $langs->trans(
"CalcModeDebt");
213 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
215} elseif ($modecompta ==
"RECETTES-DEPENSES") {
216 $name = $langs->trans(
"PurchaseTurnoverCollected").
', '.$langs->trans(
"ByThirdParties");
217 $calcmode = $langs->trans(
"CalcModePayment");
219 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
222} elseif ($modecompta ==
"BOOKKEEPING") {
224} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
229$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
231$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
233 $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>';
240report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
242if (isModEnabled(
'accounting')) {
243 if ($modecompta !=
'BOOKKEEPING') {
244 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
248 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
249 if (empty($pcgvercode)) {
250 $pcgvercode = $pcgverid;
253 $sql =
"SELECT b.rowid ";
254 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
255 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
256 $sql .=
" WHERE b.entity = ".$conf->entity;
257 $sql .=
" AND b.numero_compte = aa.account_number";
258 $sql .=
" AND aa.entity = ".$conf->entity;
259 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
260 $sql .= $db->plimit(1);
262 $resql = $db->query($sql);
263 $nb = $db->num_rows($resql);
265 $langs->load(
"errors");
266 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0,
'1');
277$address_zip = array();
278$address_town = array();
279$address_pays = array();
281if ($modecompta ==
'CREANCES-DETTES') {
282 $sql =
"SELECT DISTINCT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,";
283 $sql .=
" sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
284 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f, ".MAIN_DB_PREFIX.
"societe as s";
285 if ($selected_cat === -2) {
286 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
287 } elseif ($selected_cat) {
288 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
290 $sql .=
" WHERE f.fk_statut in (1,2)";
291 $sql .=
" AND f.type IN (0,2)";
292 $sql .=
" AND f.fk_soc = s.rowid";
293 if ($date_start && $date_end) {
294 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
296 if ($selected_cat === -2) {
297 $sql .=
" AND cs.fk_soc is null";
298 } elseif ($selected_cat) {
299 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
301 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
304 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
306} elseif ($modecompta ==
"RECETTES-DEPENSES") {
307 $sql =
"SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc";
308 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
309 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
310 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn as p";
311 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
312 if ($selected_cat === -2) {
313 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
314 } elseif ($selected_cat) {
315 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
317 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn";
318 $sql .=
" AND pf.fk_facturefourn = 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";
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(
'supplier_invoice').
")";
348 $sql .=
" AND f.fk_soc = ".((int) $socid);
350$sql .=
" GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays";
351$sql .=
" ORDER BY s.rowid";
357dol_syslog(
"supplier_turnover_by_thirdparty", LOG_DEBUG);
358$resql = $db->query($sql);
360 $num = $db->num_rows($resql);
363 $obj = $db->fetch_object($resql);
365 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
366 $amount[$obj->socid] = $obj->amount_ttc;
367 $name[$obj->socid] = $obj->name;
369 $address_zip[$obj->socid] = $obj->zip;
370 $address_town[$obj->socid] = $obj->town;
371 $address_pays[$obj->socid] =
getCountry($obj->fk_pays);
373 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
374 $catotal += $obj->amount_ttc;
384print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
385print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
387foreach ($headerparams as $key => $value) {
388 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
393print
'<div class="div-table-responsive">';
394print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
397print
'<tr class="liste_titre">';
399print
img_picto(
'',
'category',
'class="paddingrightonly"');
400print $formother->select_categories(Categorie::TYPE_SUPPLIER, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
402print
'<label for="subcat" class="marginleftonly">'.$langs->trans(
"SubCats").
'?</label> ';
403print
'<input type="checkbox" id="subcat" name="subcat" value="yes"';
408print
'<td colspan="7" class="right">';
409print
'<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans(
"Search"),
'search.png',
'', 0, 1).
'" value="'.
dol_escape_htmltag($langs->trans(
"Search")).
'" title="'.
dol_escape_htmltag($langs->trans(
"Search")).
'">';
413print
'<tr class="liste_titre">';
414print
'<td class="liste_titre left">';
415print
'<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'">';
417print
'<td class="liste_titre left">';
418print
'<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'">';
420print
'<td class="liste_titre left">';
421print
'<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).
'">';
423print
'<td class="liste_titre left">';
424print $form->select_country($search_country,
'search_country',
'', 0,
'maxwidth150');
427print
'<td class="liste_titre"> </td>';
428print
'<td class="liste_titre"> </td>';
429print
'<td class="liste_titre"> </td>';
430print
'<td class="liste_titre"> </td>';
434print
"<tr class='liste_titre'>";
436 $langs->trans(
"Company"),
437 $_SERVER[
"PHP_SELF"],
446 $langs->trans(
"Zip"),
447 $_SERVER[
"PHP_SELF"],
456 $langs->trans(
"Town"),
457 $_SERVER[
"PHP_SELF"],
466 $langs->trans(
"Country"),
467 $_SERVER[
"PHP_SELF"],
475if ($modecompta ==
'CREANCES-DETTES') {
477 $langs->trans(
'AmountHT'),
478 $_SERVER[
"PHP_SELF"],
490 $langs->trans(
"AmountTTC"),
491 $_SERVER[
"PHP_SELF"],
500 $langs->trans(
"Percentage"),
501 $_SERVER[
"PHP_SELF"],
510 $langs->trans(
"OtherStatistics"),
511 $_SERVER[
"PHP_SELF"],
515 'align="center" width="20%"'
521 $arrayforsort = $name;
523 if ($sortfield ==
'nom' && $sortorder ==
'asc') {
525 $arrayforsort = $name;
527 if ($sortfield ==
'nom' && $sortorder ==
'desc') {
529 $arrayforsort = $name;
531 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
533 $arrayforsort = $amount_ht;
535 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
537 $arrayforsort = $amount_ht;
539 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
541 $arrayforsort = $amount;
543 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
545 $arrayforsort = $amount;
547 if ($sortfield ==
'zip' && $sortorder ==
'asc') {
549 $arrayforsort = $address_zip;
551 if ($sortfield ==
'zip' && $sortorder ==
'desc') {
552 arsort($address_zip);
553 $arrayforsort = $address_zip;
555 if ($sortfield ==
'town' && $sortorder ==
'asc') {
556 asort($address_town);
557 $arrayforsort = $address_town;
559 if ($sortfield ==
'town' && $sortorder ==
'desc') {
560 arsort($address_town);
561 $arrayforsort = $address_town;
563 if ($sortfield ==
'country' && $sortorder ==
'asc') {
564 asort($address_pays);
565 $arrayforsort = $address_town;
567 if ($sortfield ==
'country' && $sortorder ==
'desc') {
568 arsort($address_pays);
569 $arrayforsort = $address_town;
572 foreach ($arrayforsort as $key => $value) {
573 print
'<tr class="oddeven">';
576 $fullname = $name[$key];
578 $thirdparty_static->id = $key;
579 $thirdparty_static->name = $fullname;
580 $thirdparty_static->client = 1;
581 $linkname = $thirdparty_static->getNomUrl(1,
'supplier');
583 $linkname = $langs->trans(
"PaymentsNotLinkedToInvoice");
585 print
"<td>".$linkname.
"</td>\n";
588 print $address_zip[$key];
592 print $address_town[$key];
596 print $address_pays[$key];
600 print
'<td class="right">';
601 if ($modecompta !=
'CREANCES-DETTES') {
603 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
605 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid=-1">';
609 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
611 print
'<a href="#">';
613 print
price($amount_ht[$key]);
618 print
'<td class="right">';
619 if ($modecompta !=
'CREANCES-DETTES') {
621 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
623 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?orphelins=1">';
627 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
629 print
'<a href="#">';
632 print
price($amount[$key]);
637 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
640 print
'<td class="center">';
641 if (isModEnabled(
'supplier_proposal') && $key > 0) {
642 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
644 if (isModEnabled(
"supplier_order") && $key > 0) {
645 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
647 if (isModEnabled(
"supplier_invoice") && $key > 0) {
648 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
656 print
'<tr class="liste_total">';
657 print
'<td>'.$langs->trans(
"Total").
'</td>';
661 if ($modecompta !=
'CREANCES-DETTES') {
664 print
'<td class="right">'.price($catotal_ht).
'</td>';
666 print
'<td class="right">'.price($catotal).
'</td>';
673 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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
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 a 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.