23 require
'../../main.inc.php';
24 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
25 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
33 $langs->loadLangs(array(
'companies',
'categories',
'bills',
'compta'));
36 $modecompta = $conf->global->ACCOUNTING_MODE;
39 $sortorder = isset($_GET[
"sortorder"]) ? $_GET[
"sortorder"] : $_POST[
"sortorder"];
40 $sortfield = isset($_GET[
"sortfield"]) ? $_GET[
"sortfield"] : $_POST[
"sortfield"];
41 if (!$sortorder) $sortorder =
"asc";
42 if (!$sortfield) $sortfield =
"nom";
44 $socid =
GETPOST(
'socid',
'int');
47 $selected_cat = (int)
GETPOST(
'search_categ',
'int');
49 if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
54 $hookmanager->initHooks(array(
'supplierturnoverbythirdpartylist'));
57 if ($user->socid > 0) $socid = $user->socid;
58 if (!empty($conf->comptabilite->enabled)) $result =
restrictedArea($user,
'compta',
'',
'',
'resultat');
59 if (!empty($conf->accounting->enabled)) $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
63 $month =
GETPOST(
"month",
'int');
64 $search_societe =
GETPOST(
"search_societe",
'alpha');
65 $search_zip =
GETPOST(
"search_zip",
'alpha');
66 $search_town =
GETPOST(
"search_town",
'alpha');
67 $search_country =
GETPOST(
"search_country",
'alpha');
68 $date_startyear =
GETPOST(
"date_startyear",
'alpha');
69 $date_startmonth =
GETPOST(
"date_startmonth",
'alpha');
70 $date_startday =
GETPOST(
"date_startday",
'alpha');
71 $date_endyear =
GETPOST(
"date_endyear",
'alpha');
72 $date_endmonth =
GETPOST(
"date_endmonth",
'alpha');
73 $date_endday =
GETPOST(
"date_endday",
'alpha');
76 $year_current = strftime(
"%Y",
dol_now());
77 $month_current = strftime(
"%m",
dol_now());
78 $year_start = $year_current;
80 $year_current = $year;
81 $month_current = strftime(
"%m",
dol_now());
87 if (empty($date_start) || empty($date_end))
93 $month_start =
GETPOST(
"month") ?
GETPOST(
"month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
94 $year_end = $year_start;
95 $month_end = $month_start;
98 if (!
GETPOST(
'year') && $month_start > $month_current)
103 $month_end = $month_start - 1;
104 if ($month_end < 1) $month_end = 12;
119 $year_start = $tmps[
'year'];
121 $year_end = $tmpe[
'year'];
122 $nbofyear = ($year_end - $year_start) + 1;
124 $commonparams = array();
125 $commonparams[
'modecompta'] = $modecompta;
126 $commonparams[
'sortorder'] = $sortorder;
127 $commonparams[
'sortfield'] = $sortfield;
129 $headerparams = array();
130 $headerparams[
'date_startyear'] = $date_startyear;
131 $headerparams[
'date_startmonth'] = $date_startmonth;
132 $headerparams[
'date_startday'] = $date_startday;
133 $headerparams[
'date_endyear'] = $date_endyear;
134 $headerparams[
'date_endmonth'] = $date_endmonth;
135 $headerparams[
'date_endday'] = $date_endday;
136 $headerparams[
'q'] = $q;
138 $tableparams = array();
139 $tableparams[
'search_categ'] = $selected_cat;
140 $tableparams[
'search_societe'] = $search_societe;
141 $tableparams[
'search_zip'] = $search_zip;
142 $tableparams[
'search_town'] = $search_town;
143 $tableparams[
'search_country'] = $search_country;
144 $tableparams[
'subcat'] = ($subcat ===
true) ?
'yes' :
'';
147 $allparams = array_merge($commonparams, $headerparams, $tableparams);
148 $headerparams = array_merge($commonparams, $headerparams);
149 $tableparams = array_merge($commonparams, $tableparams);
151 foreach ($allparams as $key => $value) {
152 $paramslink .=
'&'.$key.
'='.$value;
162 $form =
new Form($db);
163 $thirdparty_static =
new Societe($db);
167 if ($modecompta ==
"BOOKKEEPING") $modecompta =
"CREANCES-DETTES";
168 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") $modecompta =
"RECETTES-DEPENSES";
171 if ($modecompta ==
"CREANCES-DETTES")
173 $name = $langs->trans(
"PurchaseTurnover").
', '.$langs->trans(
"ByThirdParties");
174 $calcmode = $langs->trans(
"CalcModeDebt");
176 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
179 } elseif ($modecompta ==
"RECETTES-DEPENSES")
181 $name = $langs->trans(
"PurchaseTurnoverCollected").
', '.$langs->trans(
"ByThirdParties");
182 $calcmode = $langs->trans(
"CalcModeEngagement");
184 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
187 } elseif ($modecompta ==
"BOOKKEEPING")
189 } elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED")
192 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
193 if ($date_end ==
dol_time_plus_duree($date_start, 1,
'y') - 1) $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>';
194 else $periodlink =
'';
196 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
198 if (!empty($conf->accounting->enabled) && $modecompta !=
'BOOKKEEPING')
208 $amount_ht = array();
209 if ($modecompta ==
'CREANCES-DETTES') {
210 $sql =
"SELECT DISTINCT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,";
211 $sql .=
" sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
212 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f, ".MAIN_DB_PREFIX.
"societe as s";
213 if ($selected_cat === -2)
215 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as cs ON s.rowid = cs.fk_soc";
216 } elseif ($selected_cat)
218 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_societe as cs";
220 $sql .=
" WHERE f.fk_statut in (1,2)";
221 $sql .=
" AND f.type IN (0,2)";
222 $sql .=
" AND f.fk_soc = s.rowid";
223 if ($date_start && $date_end) {
224 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
226 if ($selected_cat === -2)
228 $sql .=
" AND cs.fk_soc is null";
229 } elseif ($selected_cat) {
230 $sql .=
" AND (c.rowid = ".$db->escape($selected_cat);
231 if ($subcat) $sql .=
" OR c.fk_parent = ".$db->escape($selected_cat);
233 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
236 $sql =
"SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc";
237 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
238 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
239 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn as p";
240 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
241 if ($selected_cat === -2)
243 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as cs ON s.rowid = cs.fk_soc";
244 } elseif ($selected_cat)
246 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_societe as cs";
248 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn";
249 $sql .=
" AND pf.fk_facturefourn = f.rowid";
250 $sql .=
" AND f.fk_soc = s.rowid";
251 if ($date_start && $date_end) {
252 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
254 if ($selected_cat === -2)
256 $sql .=
" AND cs.fk_soc is null";
257 } elseif ($selected_cat) {
258 $sql .=
" AND (c.rowid = ".$selected_cat;
259 if ($subcat) $sql .=
" OR c.fk_parent = ".$selected_cat;
261 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
264 if (!empty($search_societe)) $sql .=
natural_search(
's.nom', $search_societe);
265 if (!empty($search_zip)) $sql .=
natural_search(
's.zip', $search_zip);
266 if (!empty($search_town)) $sql .=
natural_search(
's.town', $search_town);
267 if ($search_country > 0) $sql .=
' AND s.fk_pays = '.$search_country.
'';
268 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
269 if ($socid) $sql .=
" AND f.fk_soc = ".$socid;
270 $sql .=
" GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays";
271 $sql .=
" ORDER BY s.rowid";
274 dol_syslog(
"supplier_turnover_by_thirdparty", LOG_DEBUG);
275 $result = $db->query($sql);
277 $num = $db->num_rows($result);
280 $obj = $db->fetch_object($result);
281 $amount_ht[$obj->socid] = $obj->amount;
282 $amount[$obj->socid] = $obj->amount_ttc;
283 $name[$obj->socid] = $obj->name.
' '.$obj->firstname;
284 $address_zip[$obj->socid] = $obj->zip;
285 $address_town[$obj->socid] = $obj->town;
286 $address_pays[$obj->socid] =
getCountry($obj->fk_pays);
287 $catotal_ht += $obj->amount;
288 $catotal += $obj->amount_ttc;
297 print '<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
298 print '<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
300 foreach ($headerparams as $key => $value)
302 print '<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
307 print '<div class="div-table-responsive">';
308 print '<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
311 print '<tr class="liste_titre">';
313 print $langs->trans(
"Category").
': '.$formother->select_categories(Categorie::TYPE_SUPPLIER, $selected_cat,
'search_categ',
true);
315 print $langs->trans(
"SubCats").
'? ';
316 print
'<input type="checkbox" name="subcat" value="yes"';
321 print
'<td colspan="7" class="right">';
322 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")).
'">';
326 print
'<tr class="liste_titre">';
327 print
'<td class="liste_titre left">';
328 print
'<input class="flat" size="6" type="text" name="search_societe" value="'.$search_societe.
'">';
330 print
'<td class="liste_titre left">';
331 print
'<input class="flat" size="6" type="text" name="search_zip" value="'.$search_zip.
'">';
333 print
'<td class="liste_titre left">';
334 print
'<input class="flat" size="6" type="text" name="search_town" value="'.$search_town.
'">';
336 print
'<td class="liste_titre left">';
337 print $form->select_country($search_country,
'search_country');
340 print
'<td class="liste_titre"> </td>';
341 print
'<td class="liste_titre"> </td>';
342 print
'<td class="liste_titre"> </td>';
343 print
'<td class="liste_titre"> </td>';
347 print
"<tr class='liste_titre'>";
349 $langs->trans(
"Company"),
355 $sortfield, $sortorder
358 $langs->trans(
"Zip"),
364 $sortfield, $sortorder
367 $langs->trans(
"Town"),
373 $sortfield, $sortorder
376 $langs->trans(
"Country"),
382 $sortfield, $sortorder
384 if ($modecompta ==
'CREANCES-DETTES') {
386 $langs->trans(
'AmountHT'),
399 $langs->trans(
"AmountTTC"),
409 $langs->trans(
"Percentage"),
419 $langs->trans(
"OtherStatistics"),
424 'align="center" width="20%"'
429 if (count($amount)) {
430 $arrayforsort = $name;
432 if ($sortfield ==
'nom' && $sortorder ==
'asc') {
434 $arrayforsort = $name;
436 if ($sortfield ==
'nom' && $sortorder ==
'desc') {
438 $arrayforsort = $name;
440 if ($sortfield ==
'amount_ht' && $sortorder ==
'asc') {
442 $arrayforsort = $amount_ht;
444 if ($sortfield ==
'amount_ht' && $sortorder ==
'desc') {
446 $arrayforsort = $amount_ht;
448 if ($sortfield ==
'amount_ttc' && $sortorder ==
'asc') {
450 $arrayforsort = $amount;
452 if ($sortfield ==
'amount_ttc' && $sortorder ==
'desc') {
454 $arrayforsort = $amount;
456 if ($sortfield ==
'zip' && $sortorder ==
'asc') {
458 $arrayforsort = $address_zip;
460 if ($sortfield ==
'zip' && $sortorder ==
'desc') {
461 arsort($address_zip);
462 $arrayforsort = $address_zip;
464 if ($sortfield ==
'town' && $sortorder ==
'asc') {
465 asort($address_town);
466 $arrayforsort = $address_town;
468 if ($sortfield ==
'town' && $sortorder ==
'desc') {
469 arsort($address_town);
470 $arrayforsort = $address_town;
472 if ($sortfield ==
'country' && $sortorder ==
'asc') {
473 asort($address_pays);
474 $arrayforsort = $address_town;
476 if ($sortfield ==
'country' && $sortorder ==
'desc') {
477 arsort($address_pays);
478 $arrayforsort = $address_town;
481 foreach ($arrayforsort as $key=>$value) {
482 print
'<tr class="oddeven">';
485 $fullname = $name[$key];
487 $thirdparty_static->id = $key;
488 $thirdparty_static->name = $fullname;
489 $thirdparty_static->client = 1;
490 $linkname = $thirdparty_static->getNomUrl(1,
'supplier');
492 $linkname = $langs->trans(
"PaymentsNotLinkedToInvoice");
494 print
"<td>".$linkname.
"</td>\n";
497 print $address_zip[$key];
501 print $address_town[$key];
505 print $address_pays[$key];
509 print
'<td class="right">';
510 if ($modecompta !=
'CREANCES-DETTES') {
512 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
514 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid=-1">';
518 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
520 print
'<a href="#">';
522 print
price($amount_ht[$key]);
527 print
'<td class="right">';
528 if ($modecompta !=
'CREANCES-DETTES') {
530 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?socid='.$key.
'">';
532 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/paiement/list.php?orphelins=1">';
536 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$key.
'">';
538 print
'<a href="#">';
541 print
price($amount[$key]);
546 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
549 print
'<td class="center">';
550 if (!empty($conf->supplier_proposal->enabled) && $key > 0) {
551 print
' <a href="'.DOL_URL_ROOT.
'/comm/propal/stats/index.php?socid='.$key.
'">'.
img_picto($langs->trans(
"ProposalStats"),
"stats").
'</a> ';
553 if (!empty($conf->fournisseur->enabled) && $key > 0) {
554 print
' <a href="'.DOL_URL_ROOT.
'/commande/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"OrderStats"),
"stats").
'</a> ';
556 if (!empty($conf->fournisseur->enabled) && $key > 0) {
557 print
' <a href="'.DOL_URL_ROOT.
'/compta/facture/stats/index.php?mode=supplier&socid='.$key.
'">'.
img_picto($langs->trans(
"InvoiceStats"),
"stats").
'</a> ';
565 print
'<tr class="liste_total">';
566 print
'<td>'.$langs->trans(
"Total").
'</td>';
567 print
'<td> </td>';
568 print
'<td> </td>';
569 print
'<td> </td>';
570 if ($modecompta !=
'CREANCES-DETTES') {
573 print
'<td class="right">'.price($catotal_ht).
'</td>';
575 print
'<td class="right">'.price($catotal).
'</td>';
576 print
'<td> </td>';
577 print
'<td> </td>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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_now($mode= 'auto')
Return date for now.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
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...
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
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...
print $_SERVER["PHP_SELF"]
Edit parameters.
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
print
Draft customers invoices.
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...