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';
46$langs->loadLangs(array(
'companies',
'categories',
'bills',
'compta'));
51 $modecompta =
GETPOST(
"modecompta");
55$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
56$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
70if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
75$hookmanager->initHooks(array(
'supplierturnoverbythirdpartylist'));
79$search_societe =
GETPOST(
"search_societe",
'alpha');
80$search_zip =
GETPOST(
"search_zip",
'alpha');
81$search_town =
GETPOST(
"search_town",
'alpha');
82$search_country =
GETPOST(
"search_country",
'aZ09');
84$date_startyear =
GETPOST(
"date_startyear",
'alpha');
85$date_startmonth =
GETPOST(
"date_startmonth",
'alpha');
86$date_startday =
GETPOST(
"date_startday",
'alpha');
87$date_endyear =
GETPOST(
"date_endyear",
'alpha');
88$date_endmonth =
GETPOST(
"date_endmonth",
'alpha');
89$date_endday =
GETPOST(
"date_endday",
'alpha');
99 $year_start = $year_current - ($nbofyear - 1);
101 $year_current = $year;
103 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
105$date_start =
dol_mktime(0, 0, 0, (
int) $date_startmonth, (
int) $date_startday, (
int) $date_startyear,
'tzserver');
106$date_end =
dol_mktime(23, 59, 59, (
int) $date_endmonth, (
int) $date_endday, (
int) $date_endyear,
'tzserver');
109if (empty($date_start) || empty($date_end)) {
113 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
116 if (!$year && $month_start > $month_current) {
120 $month_end = $month_start - 1;
121 if ($month_end < 1) {
125 $month_end = $month_start;
150$year_start = $tmps[
'year'];
152$year_end = $tmpe[
'year'];
153$nbofyear = ($year_end - $year_start) + 1;
155$commonparams = array();
156$commonparams[
'modecompta'] = $modecompta;
157$commonparams[
'sortorder'] = $sortorder;
158$commonparams[
'sortfield'] = $sortfield;
160$headerparams = array();
161$headerparams[
'date_startyear'] = $date_startyear;
162$headerparams[
'date_startmonth'] = $date_startmonth;
163$headerparams[
'date_startday'] = $date_startday;
164$headerparams[
'date_endyear'] = $date_endyear;
165$headerparams[
'date_endmonth'] = $date_endmonth;
166$headerparams[
'date_endday'] = $date_endday;
168$tableparams = array();
169$tableparams[
'search_categ'] = $selected_cat;
170$tableparams[
'search_societe'] = $search_societe;
171$tableparams[
'search_zip'] = $search_zip;
172$tableparams[
'search_town'] = $search_town;
173$tableparams[
'search_country'] = $search_country;
174$tableparams[
'subcat'] = $subcat ?
'yes' :
'';
177$allparams = array_merge($commonparams, $headerparams, $tableparams);
178$headerparams = array_merge($commonparams, $headerparams);
179$tableparams = array_merge($commonparams, $tableparams);
182foreach ($allparams as $key => $value) {
183 $paramslink .=
'&'.$key.
'='.$value;
187if ($user->socid > 0) {
188 $socid = $user->socid;
190if (isModEnabled(
'comptabilite')) {
193if (isModEnabled(
'accounting')) {
194 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
204$form =
new Form($db);
205$thirdparty_static =
new Societe($db);
209if ($modecompta ==
"BOOKKEEPING") {
210 $modecompta =
"CREANCES-DETTES";
212if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
213 $modecompta =
"RECETTES-DEPENSES";
221if ($modecompta ==
"CREANCES-DETTES") {
222 $name = $langs->trans(
"PurchaseTurnover").
', '.$langs->trans(
"ByThirdParties");
223 $calcmode = $langs->trans(
"CalcModeDebt");
225 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
227} elseif ($modecompta ==
"RECETTES-DEPENSES") {
228 $name = $langs->trans(
"PurchaseTurnoverCollected").
', '.$langs->trans(
"ByThirdParties");
229 $calcmode = $langs->trans(
"CalcModePayment");
231 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
234} elseif ($modecompta ==
"BOOKKEEPING") {
236} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
241$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
243$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
245 $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>';
252report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
254if (isModEnabled(
'accounting')) {
255 if ($modecompta !=
'BOOKKEEPING') {
256 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
260 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
261 if (empty($pcgvercode)) {
262 $pcgvercode = $pcgverid;
265 $sql =
"SELECT b.rowid ";
266 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
267 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
268 $sql .=
" WHERE b.entity = ".$conf->entity;
269 $sql .=
" AND b.numero_compte = aa.account_number";
270 $sql .=
" AND aa.entity = ".$conf->entity;
271 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
272 $sql .= $db->plimit(1);
274 $resql = $db->query($sql);
275 $nb = $db->num_rows($resql);
277 $langs->load(
"errors");
278 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0,
'1');
289$address_zip = array();
290$address_town = array();
291$address_pays = array();
293if ($modecompta ==
'CREANCES-DETTES') {
294 $sql =
"SELECT DISTINCT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,";
295 $sql .=
" sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
296 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f, ".MAIN_DB_PREFIX.
"societe as s";
297 if ($selected_cat === -2) {
298 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
299 } elseif ($selected_cat) {
300 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
302 $sql .=
" WHERE f.fk_statut in (1,2)";
303 $sql .=
" AND f.type IN (0,2)";
304 $sql .=
" AND f.fk_soc = s.rowid";
305 if ($date_start && $date_end) {
306 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
308 if ($selected_cat === -2) {
309 $sql .=
" AND cs.fk_soc is null";
310 } elseif ($selected_cat) {
311 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
313 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
316 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
318} elseif ($modecompta ==
"RECETTES-DEPENSES") {
319 $sql =
"SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc";
320 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
321 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
322 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn as p";
323 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
324 if ($selected_cat === -2) {
325 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
326 } elseif ($selected_cat) {
327 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
329 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn";
330 $sql .=
" AND pf.fk_facturefourn = f.rowid";
331 $sql .=
" AND f.fk_soc = s.rowid";
332 if ($date_start && $date_end) {
333 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
335 if ($selected_cat === -2) {
336 $sql .=
" AND cs.fk_soc is null";
337 } elseif ($selected_cat) {
338 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
340 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
343 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
346if (!empty($search_societe)) {
349if (!empty($search_zip)) {
352if (!empty($search_town)) {
355if ($search_country > 0) {
356 $sql .=
' AND s.fk_pays = '.((int) $search_country);
358$sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
360 $sql .=
" AND f.fk_soc = ".((int) $socid);
362$sql .=
" GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays";
363$sql .=
" ORDER BY s.rowid";
369dol_syslog(
"supplier_turnover_by_thirdparty", LOG_DEBUG);
370$resql = $db->query($sql);
372 $num = $db->num_rows($resql);
375 $obj = $db->fetch_object($resql);
377 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
378 $amount[$obj->socid] = $obj->amount_ttc;
379 $name[$obj->socid] = $obj->name;
381 $address_zip[$obj->socid] = $obj->zip;
382 $address_town[$obj->socid] = $obj->town;
383 $address_pays[$obj->socid] =
getCountry($obj->fk_pays);
385 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
386 $catotal += $obj->amount_ttc;
396print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
397print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
399foreach ($headerparams as $key => $value) {
400 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
405print
'<div class="div-table-responsive">';
406print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
409print
'<tr class="liste_titre">';
411print
img_picto(
'',
'category',
'class="paddingrightonly"');
412print $formother->select_categories(Categorie::TYPE_SUPPLIER, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
414print
'<label for="subcat" class="marginleftonly">'.$langs->trans(
"SubCats").
'?</label> ';
415print
'<input type="checkbox" id="subcat" name="subcat" value="yes"';
420print
'<td colspan="7" class="right">';
421print
'<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")).
'">';
425print
'<tr class="liste_titre">';
426print
'<td class="liste_titre left">';
427print
'<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'">';
429print
'<td class="liste_titre left">';
430print
'<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'">';
432print
'<td class="liste_titre left">';
433print
'<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).
'">';
435print
'<td class="liste_titre left">';
436print $form->select_country($search_country,
'search_country',
'', 0,
'maxwidth150');
439print
'<td class="liste_titre"> </td>';
440print
'<td class="liste_titre"> </td>';
441print
'<td class="liste_titre"> </td>';
442print
'<td class="liste_titre"> </td>';
446print
"<tr class='liste_titre'>";
448 $langs->trans(
"Company"),
449 $_SERVER[
"PHP_SELF"],
458 $langs->trans(
"Zip"),
459 $_SERVER[
"PHP_SELF"],
468 $langs->trans(
"Town"),
469 $_SERVER[
"PHP_SELF"],
478 $langs->trans(
"Country"),
479 $_SERVER[
"PHP_SELF"],
487if ($modecompta ==
'CREANCES-DETTES') {
489 $langs->trans(
'AmountHT'),
490 $_SERVER[
"PHP_SELF"],
502 $langs->trans(
"AmountTTC"),
503 $_SERVER[
"PHP_SELF"],
512 $langs->trans(
"Percentage"),
513 $_SERVER[
"PHP_SELF"],
522 $langs->trans(
"OtherStatistics"),
523 $_SERVER[
"PHP_SELF"],
527 'align="center" width="20%"'
533 $arrayforsort = $name;
535 if ($sortfield ==
'nom' && $sortorder ==
'asc') {
537 $arrayforsort = $name;
539 if ($sortfield ==
'nom' && $sortorder ==
'desc') {
541 $arrayforsort = $name;
543 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
545 $arrayforsort = $amount_ht;
547 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
549 $arrayforsort = $amount_ht;
551 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
553 $arrayforsort = $amount;
555 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
557 $arrayforsort = $amount;
559 if ($sortfield ==
'zip' && $sortorder ==
'asc') {
561 $arrayforsort = $address_zip;
563 if ($sortfield ==
'zip' && $sortorder ==
'desc') {
564 arsort($address_zip);
565 $arrayforsort = $address_zip;
567 if ($sortfield ==
'town' && $sortorder ==
'asc') {
568 asort($address_town);
569 $arrayforsort = $address_town;
571 if ($sortfield ==
'town' && $sortorder ==
'desc') {
572 arsort($address_town);
573 $arrayforsort = $address_town;
575 if ($sortfield ==
'country' && $sortorder ==
'asc') {
576 asort($address_pays);
577 $arrayforsort = $address_town;
579 if ($sortfield ==
'country' && $sortorder ==
'desc') {
580 arsort($address_pays);
581 $arrayforsort = $address_town;
584 foreach ($arrayforsort as $key => $value) {
585 print
'<tr class="oddeven">';
588 $fullname = $name[$key];
590 $thirdparty_static->id = $key;
591 $thirdparty_static->name = $fullname;
592 $thirdparty_static->client = 1;
593 $linkname = $thirdparty_static->getNomUrl(1,
'supplier');
595 $linkname = $langs->trans(
"PaymentsNotLinkedToInvoice");
597 print
"<td>".$linkname.
"</td>\n";
600 print $address_zip[$key];
604 print $address_town[$key];
608 print $address_pays[$key];
612 print
'<td class="right">';
613 if ($modecompta !=
'CREANCES-DETTES') {
615 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
617 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid=-1">';
621 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
623 print
'<a href="#">';
625 print
price($amount_ht[$key]);
630 print
'<td class="right">';
631 if ($modecompta !=
'CREANCES-DETTES') {
633 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
635 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?orphelins=1">';
639 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
641 print
'<a href="#">';
644 print
price($amount[$key]);
649 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
652 print
'<td class="center">';
653 if (isModEnabled(
'supplier_proposal') && $key > 0) {
654 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
656 if (isModEnabled(
"supplier_order") && $key > 0) {
657 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
659 if (isModEnabled(
"supplier_invoice") && $key > 0) {
660 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
668 print
'<tr class="liste_total">';
669 print
'<td>'.$langs->trans(
"Total").
'</td>';
673 if ($modecompta !=
'CREANCES-DETTES') {
676 print
'<td class="right">'.price($catotal_ht).
'</td>';
678 print
'<td class="right">'.price($catotal).
'</td>';
685 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.