25 require
'../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
35 $langs->loadLangs(array(
'companies',
'categories',
'bills',
'compta'));
38 $modecompta = $conf->global->ACCOUNTING_MODE;
40 $modecompta =
GETPOST(
"modecompta");
44 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
45 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
54 $socid =
GETPOST(
'socid',
'int');
57 $selected_cat = (int)
GETPOST(
'search_categ',
'int');
59 if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
64 $hookmanager->initHooks(array(
'supplierturnoverbythirdpartylist'));
68 $search_societe =
GETPOST(
"search_societe",
'alpha');
69 $search_zip =
GETPOST(
"search_zip",
'alpha');
70 $search_town =
GETPOST(
"search_town",
'alpha');
71 $search_country =
GETPOST(
"search_country",
'alpha');
76 $month =
GETPOST(
"month",
'int');
77 $date_startyear =
GETPOST(
"date_startyear",
'alpha');
78 $date_startmonth =
GETPOST(
"date_startmonth",
'alpha');
79 $date_startday =
GETPOST(
"date_startday",
'alpha');
80 $date_endyear =
GETPOST(
"date_endyear",
'alpha');
81 $date_endmonth =
GETPOST(
"date_endmonth",
'alpha');
82 $date_endday =
GETPOST(
"date_endday",
'alpha');
86 $year_start = $year_current;
88 $year_current = $year;
95 if (empty($date_start) || empty($date_end)) {
99 $month_start =
GETPOST(
"month") ?
GETPOST(
"month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
100 $year_end = $year_start;
101 $month_end = $month_start;
103 if (!
GETPOST(
'year') && $month_start > $month_current) {
107 $month_end = $month_start - 1;
108 if ($month_end < 1) {
139 $year_start = $tmps[
'year'];
141 $year_end = $tmpe[
'year'];
142 $nbofyear = ($year_end - $year_start) + 1;
144 $commonparams = array();
145 $commonparams[
'modecompta'] = $modecompta;
146 $commonparams[
'sortorder'] = $sortorder;
147 $commonparams[
'sortfield'] = $sortfield;
149 $headerparams = array();
150 $headerparams[
'date_startyear'] = $date_startyear;
151 $headerparams[
'date_startmonth'] = $date_startmonth;
152 $headerparams[
'date_startday'] = $date_startday;
153 $headerparams[
'date_endyear'] = $date_endyear;
154 $headerparams[
'date_endmonth'] = $date_endmonth;
155 $headerparams[
'date_endday'] = $date_endday;
157 $tableparams = array();
158 $tableparams[
'search_categ'] = $selected_cat;
159 $tableparams[
'search_societe'] = $search_societe;
160 $tableparams[
'search_zip'] = $search_zip;
161 $tableparams[
'search_town'] = $search_town;
162 $tableparams[
'search_country'] = $search_country;
163 $tableparams[
'subcat'] = ($subcat ===
true) ?
'yes' :
'';
166 $allparams = array_merge($commonparams, $headerparams, $tableparams);
167 $headerparams = array_merge($commonparams, $headerparams);
168 $tableparams = array_merge($commonparams, $tableparams);
171 foreach ($allparams as $key => $value) {
172 $paramslink .=
'&'.$key.
'='.$value;
176 if ($user->socid > 0) {
177 $socid = $user->socid;
183 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
194 $thirdparty_static =
new Societe($db);
198 if ($modecompta ==
"BOOKKEEPING") {
199 $modecompta =
"CREANCES-DETTES";
201 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
202 $modecompta =
"RECETTES-DEPENSES";
206 if ($modecompta ==
"CREANCES-DETTES") {
207 $name = $langs->trans(
"PurchaseTurnover").
', '.$langs->trans(
"ByThirdParties");
208 $calcmode = $langs->trans(
"CalcModeDebt");
210 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
212 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
213 $name = $langs->trans(
"PurchaseTurnoverCollected").
', '.$langs->trans(
"ByThirdParties");
214 $calcmode = $langs->trans(
"CalcModeEngagement");
216 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
218 } elseif ($modecompta ==
"BOOKKEEPING") {
220 } elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
224 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
226 $period .=
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
228 $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>';
235 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
237 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
238 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
246 $amount_ht = array();
247 if ($modecompta ==
'CREANCES-DETTES') {
248 $sql =
"SELECT DISTINCT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,";
249 $sql .=
" sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
250 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f, ".MAIN_DB_PREFIX.
"societe as s";
251 if ($selected_cat === -2) {
252 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as cs ON s.rowid = cs.fk_soc";
253 } elseif ($selected_cat) {
254 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_societe as cs";
256 $sql .=
" WHERE f.fk_statut in (1,2)";
257 $sql .=
" AND f.type IN (0,2)";
258 $sql .=
" AND f.fk_soc = s.rowid";
259 if ($date_start && $date_end) {
260 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
262 if ($selected_cat === -2) {
263 $sql .=
" AND cs.fk_soc is null";
264 } elseif ($selected_cat) {
265 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
267 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
270 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
272 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
273 $sql =
"SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc";
274 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
275 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
276 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn as p";
277 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
278 if ($selected_cat === -2) {
279 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as cs ON s.rowid = cs.fk_soc";
280 } elseif ($selected_cat) {
281 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_societe as cs";
283 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn";
284 $sql .=
" AND pf.fk_facturefourn = f.rowid";
285 $sql .=
" AND f.fk_soc = s.rowid";
286 if ($date_start && $date_end) {
287 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
289 if ($selected_cat === -2) {
290 $sql .=
" AND cs.fk_soc is null";
291 } elseif ($selected_cat) {
292 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
294 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
297 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
300 if (!empty($search_societe)) {
303 if (!empty($search_zip)) {
306 if (!empty($search_town)) {
309 if ($search_country > 0) {
310 $sql .=
' AND s.fk_pays = '.((int) $search_country);
312 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
314 $sql .=
" AND f.fk_soc = ".((int) $socid);
316 $sql .=
" GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays";
317 $sql .=
" ORDER BY s.rowid";
323 dol_syslog(
"supplier_turnover_by_thirdparty", LOG_DEBUG);
324 $resql = $db->query($sql);
326 $num = $db->num_rows(
$resql);
329 $obj = $db->fetch_object(
$resql);
331 $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount);
332 $amount[$obj->socid] = $obj->amount_ttc;
335 $address_zip[$obj->socid] = $obj->zip;
336 $address_town[$obj->socid] = $obj->town;
337 $address_pays[$obj->socid] =
getCountry($obj->fk_pays);
339 $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount);
340 $catotal += $obj->amount_ttc;
350 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
351 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
353 foreach ($headerparams as $key => $value) {
354 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
359 print
'<div class="div-table-responsive">';
360 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
363 print
'<tr class="liste_titre">';
365 print
img_picto(
'',
'category',
'class="paddingrightonly"');
366 print $formother->select_categories(Categorie::TYPE_SUPPLIER, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
368 print $langs->trans(
"SubCats").
'? ';
369 print
'<input type="checkbox" name="subcat" value="yes"';
374 print
'<td colspan="7" class="right">';
375 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")).
'">';
379 print
'<tr class="liste_titre">';
380 print
'<td class="liste_titre left">';
381 print
'<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).
'">';
383 print
'<td class="liste_titre left">';
384 print
'<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'">';
386 print
'<td class="liste_titre left">';
387 print
'<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).
'">';
389 print
'<td class="liste_titre left">';
390 print
$form->select_country($search_country,
'search_country');
393 print
'<td class="liste_titre"> </td>';
394 print
'<td class="liste_titre"> </td>';
395 print
'<td class="liste_titre"> </td>';
396 print
'<td class="liste_titre"> </td>';
400 print
"<tr class='liste_titre'>";
402 $langs->trans(
"Company"),
403 $_SERVER[
"PHP_SELF"],
412 $langs->trans(
"Zip"),
413 $_SERVER[
"PHP_SELF"],
422 $langs->trans(
"Town"),
423 $_SERVER[
"PHP_SELF"],
432 $langs->trans(
"Country"),
433 $_SERVER[
"PHP_SELF"],
441 if ($modecompta ==
'CREANCES-DETTES') {
443 $langs->trans(
'AmountHT'),
444 $_SERVER[
"PHP_SELF"],
456 $langs->trans(
"AmountTTC"),
457 $_SERVER[
"PHP_SELF"],
466 $langs->trans(
"Percentage"),
467 $_SERVER[
"PHP_SELF"],
476 $langs->trans(
"OtherStatistics"),
477 $_SERVER[
"PHP_SELF"],
481 'align="center" width="20%"'
486 if (count($amount)) {
487 $arrayforsort = $name;
489 if ($sortfield ==
'nom' && $sortorder ==
'asc') {
491 $arrayforsort = $name;
493 if ($sortfield ==
'nom' && $sortorder ==
'desc') {
495 $arrayforsort = $name;
497 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
499 $arrayforsort = $amount_ht;
501 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
503 $arrayforsort = $amount_ht;
505 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
507 $arrayforsort = $amount;
509 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
511 $arrayforsort = $amount;
513 if ($sortfield ==
'zip' && $sortorder ==
'asc') {
515 $arrayforsort = $address_zip;
517 if ($sortfield ==
'zip' && $sortorder ==
'desc') {
518 arsort($address_zip);
519 $arrayforsort = $address_zip;
521 if ($sortfield ==
'town' && $sortorder ==
'asc') {
522 asort($address_town);
523 $arrayforsort = $address_town;
525 if ($sortfield ==
'town' && $sortorder ==
'desc') {
526 arsort($address_town);
527 $arrayforsort = $address_town;
529 if ($sortfield ==
'country' && $sortorder ==
'asc') {
530 asort($address_pays);
531 $arrayforsort = $address_town;
533 if ($sortfield ==
'country' && $sortorder ==
'desc') {
534 arsort($address_pays);
535 $arrayforsort = $address_town;
538 foreach ($arrayforsort as $key => $value) {
539 print
'<tr class="oddeven">';
542 $fullname = $name[$key];
544 $thirdparty_static->id = $key;
545 $thirdparty_static->name = $fullname;
546 $thirdparty_static->client = 1;
547 $linkname = $thirdparty_static->getNomUrl(1,
'supplier');
549 $linkname = $langs->trans(
"PaymentsNotLinkedToInvoice");
551 print
"<td>".$linkname.
"</td>\n";
554 print $address_zip[$key];
558 print $address_town[$key];
562 print $address_pays[$key];
566 print
'<td class="right">';
567 if ($modecompta !=
'CREANCES-DETTES') {
569 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
571 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid=-1">';
575 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
577 print
'<a href="#">';
579 print
price($amount_ht[$key]);
584 print
'<td class="right">';
585 if ($modecompta !=
'CREANCES-DETTES') {
587 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
589 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?orphelins=1">';
593 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
595 print
'<a href="#">';
598 print
price($amount[$key]);
603 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
606 print
'<td class="center">';
608 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
610 if (((
isModEnabled(
"fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) ||
isModEnabled(
"supplier_order")) && $key > 0) {
611 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
613 if (((
isModEnabled(
"fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) ||
isModEnabled(
"supplier_invoice")) && $key > 0) {
614 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
622 print
'<tr class="liste_total">';
623 print
'<td>'.$langs->trans(
"Total").
'</td>';
624 print
'<td> </td>';
625 print
'<td> </td>';
626 print
'<td> </td>';
627 if ($modecompta !=
'CREANCES-DETTES') {
630 print
'<td class="right">'.price($catotal_ht).
'</td>';
632 print
'<td class="right">'.price($catotal).
'</td>';
633 print
'<td> </td>';
634 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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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.
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.
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.
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.