26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
33 require_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');
60 if (
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');
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;
96 if (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);
172 foreach ($allparams as $key => $value) {
173 $paramslink .=
'&'.$key.
'='.$value;
177 if ($user->socid > 0) {
178 $socid = $user->socid;
184 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
194 $form =
new Form($db);
195 $thirdparty_static =
new Societe($db);
199 if ($modecompta ==
"BOOKKEEPING") {
200 $modecompta =
"CREANCES-DETTES";
202 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
203 $modecompta =
"RECETTES-DEPENSES";
207 if ($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");
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>';
236 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
238 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
239 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
247 $amount_ht = array();
248 $address_zip = array();
249 $address_town = array();
250 $address_pays = array();
251 if ($modecompta ==
'CREANCES-DETTES') {
252 $sql =
"SELECT DISTINCT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,";
253 $sql .=
" sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
254 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f, ".MAIN_DB_PREFIX.
"societe as s";
255 if ($selected_cat === -2) {
256 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
257 } elseif ($selected_cat) {
258 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
260 $sql .=
" WHERE f.fk_statut in (1,2)";
261 $sql .=
" AND f.type IN (0,2)";
262 $sql .=
" AND f.fk_soc = s.rowid";
263 if ($date_start && $date_end) {
264 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
266 if ($selected_cat === -2) {
267 $sql .=
" AND cs.fk_soc is null";
268 } elseif ($selected_cat) {
269 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
271 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
274 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
276 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
277 $sql =
"SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc";
278 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
279 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
280 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn as p";
281 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
282 if ($selected_cat === -2) {
283 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
284 } elseif ($selected_cat) {
285 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
287 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn";
288 $sql .=
" AND pf.fk_facturefourn = f.rowid";
289 $sql .=
" AND f.fk_soc = s.rowid";
290 if ($date_start && $date_end) {
291 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
293 if ($selected_cat === -2) {
294 $sql .=
" AND cs.fk_soc is null";
295 } elseif ($selected_cat) {
296 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
298 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
301 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
304 if (!empty($search_societe)) {
307 if (!empty($search_zip)) {
310 if (!empty($search_town)) {
313 if ($search_country > 0) {
314 $sql .=
' AND s.fk_pays = '.((int) $search_country);
316 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
318 $sql .=
" AND f.fk_soc = ".((int) $socid);
320 $sql .=
" GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays";
321 $sql .=
" ORDER BY s.rowid";
327 dol_syslog(
"supplier_turnover_by_thirdparty", LOG_DEBUG);
328 $resql = $db->query(
$sql);
330 $num = $db->num_rows($resql);
333 $obj = $db->fetch_object($resql);
335 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
336 $amount[$obj->socid] = $obj->amount_ttc;
337 $name[$obj->socid] = $obj->name;
339 $address_zip[$obj->socid] = $obj->zip;
340 $address_town[$obj->socid] = $obj->town;
341 $address_pays[$obj->socid] =
getCountry($obj->fk_pays);
343 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
344 $catotal += $obj->amount_ttc;
354 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
355 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
357 foreach ($headerparams as $key => $value) {
358 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
363 print
'<div class="div-table-responsive">';
364 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
367 print
'<tr class="liste_titre">';
369 print
img_picto(
'',
'category',
'class="paddingrightonly"');
370 print $formother->select_categories(Categorie::TYPE_SUPPLIER, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
372 print $langs->trans(
"SubCats").
'? ';
373 print
'<input type="checkbox" name="subcat" value="yes"';
378 print
'<td colspan="7" class="right">';
379 print
'<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")).
'">';
383 print
'<tr class="liste_titre">';
384 print
'<td class="liste_titre left">';
385 print
'<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'">';
387 print
'<td class="liste_titre left">';
388 print
'<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'">';
390 print
'<td class="liste_titre left">';
391 print
'<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).
'">';
393 print
'<td class="liste_titre left">';
394 print $form->select_country($search_country,
'search_country');
397 print
'<td class="liste_titre"> </td>';
398 print
'<td class="liste_titre"> </td>';
399 print
'<td class="liste_titre"> </td>';
400 print
'<td class="liste_titre"> </td>';
404 print
"<tr class='liste_titre'>";
406 $langs->trans(
"Company"),
407 $_SERVER[
"PHP_SELF"],
416 $langs->trans(
"Zip"),
417 $_SERVER[
"PHP_SELF"],
426 $langs->trans(
"Town"),
427 $_SERVER[
"PHP_SELF"],
436 $langs->trans(
"Country"),
437 $_SERVER[
"PHP_SELF"],
445 if ($modecompta ==
'CREANCES-DETTES') {
447 $langs->trans(
'AmountHT'),
448 $_SERVER[
"PHP_SELF"],
460 $langs->trans(
"AmountTTC"),
461 $_SERVER[
"PHP_SELF"],
470 $langs->trans(
"Percentage"),
471 $_SERVER[
"PHP_SELF"],
480 $langs->trans(
"OtherStatistics"),
481 $_SERVER[
"PHP_SELF"],
485 'align="center" width="20%"'
490 if (count($amount)) {
491 $arrayforsort = $name;
493 if ($sortfield ==
'nom' && $sortorder ==
'asc') {
495 $arrayforsort = $name;
497 if ($sortfield ==
'nom' && $sortorder ==
'desc') {
499 $arrayforsort = $name;
501 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
503 $arrayforsort = $amount_ht;
505 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
507 $arrayforsort = $amount_ht;
509 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
511 $arrayforsort = $amount;
513 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
515 $arrayforsort = $amount;
517 if ($sortfield ==
'zip' && $sortorder ==
'asc') {
519 $arrayforsort = $address_zip;
521 if ($sortfield ==
'zip' && $sortorder ==
'desc') {
522 arsort($address_zip);
523 $arrayforsort = $address_zip;
525 if ($sortfield ==
'town' && $sortorder ==
'asc') {
526 asort($address_town);
527 $arrayforsort = $address_town;
529 if ($sortfield ==
'town' && $sortorder ==
'desc') {
530 arsort($address_town);
531 $arrayforsort = $address_town;
533 if ($sortfield ==
'country' && $sortorder ==
'asc') {
534 asort($address_pays);
535 $arrayforsort = $address_town;
537 if ($sortfield ==
'country' && $sortorder ==
'desc') {
538 arsort($address_pays);
539 $arrayforsort = $address_town;
542 foreach ($arrayforsort as $key => $value) {
543 print
'<tr class="oddeven">';
546 $fullname = $name[$key];
548 $thirdparty_static->id = $key;
549 $thirdparty_static->name = $fullname;
550 $thirdparty_static->client = 1;
551 $linkname = $thirdparty_static->getNomUrl(1,
'supplier');
553 $linkname = $langs->trans(
"PaymentsNotLinkedToInvoice");
555 print
"<td>".$linkname.
"</td>\n";
558 print $address_zip[$key];
562 print $address_town[$key];
566 print $address_pays[$key];
570 print
'<td class="right">';
571 if ($modecompta !=
'CREANCES-DETTES') {
573 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
575 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid=-1">';
579 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
581 print
'<a href="#">';
583 print
price($amount_ht[$key]);
588 print
'<td class="right">';
589 if ($modecompta !=
'CREANCES-DETTES') {
591 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
593 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?orphelins=1">';
597 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
599 print
'<a href="#">';
602 print
price($amount[$key]);
607 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
610 print
'<td class="center">';
612 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
615 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
618 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
626 print
'<tr class="liste_total">';
627 print
'<td>'.$langs->trans(
"Total").
'</td>';
628 print
'<td> </td>';
629 print
'<td> </td>';
630 print
'<td> </td>';
631 if ($modecompta !=
'CREANCES-DETTES') {
634 print
'<td class="right">'.price($catotal_ht).
'</td>';
636 print
'<td class="right">'.price($catotal).
'</td>';
637 print
'<td> </td>';
638 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=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
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_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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information in HTML for admin users or standard users.
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.
isModEnabled($module)
Is Dolibarr module enabled.
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.