diff --git a/htdocs/compta/stats/supplier_turnover_by_thirdparty.php b/htdocs/compta/stats/supplier_turnover_by_thirdparty.php
new file mode 100644
index 00000000000..341c86fbd20
--- /dev/null
+++ b/htdocs/compta/stats/supplier_turnover_by_thirdparty.php
@@ -0,0 +1,595 @@
+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
('.$langs->trans("SeeReportInInputOutputMode",'','').')';
+ $description = $langs->trans("RulesPurchaseTurnoverDue");
+ $builddate = dol_now();
+ //$exportlink=$langs->trans("NotYetAvailable");
+}
+elseif ($modecompta == "RECETTES-DEPENSES")
+{
+ $name = $langs->trans("PurchaseTurnoverCollected").', '.$langs->trans("ByThirdParties");
+ $calcmode = $langs->trans("CalcModeEngagement");
+ //$calcmode.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')';
+ $description = $langs->trans("RulesPurchaseTurnoverIn");
+ $description .= $langs->trans("DepositsAreIncluded");
+ $builddate = dol_now();
+ //$exportlink=$langs->trans("NotYetAvailable");
+}
+elseif ($modecompta == "BOOKKEEPING")
+{
+}
+elseif ($modecompta == "BOOKKEEPINGCOLLECTED")
+{
+}
+$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
+if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) $periodlink = ''.img_previous().' '.img_next().'';
+else $periodlink = '';
+
+report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
+
+if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING')
+{
+ print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
+}
+
+
+$name = array();
+
+// Show Array
+$catotal = 0;
+if ($modecompta == 'CREANCES-DETTES') {
+ $sql = "SELECT DISTINCT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,";
+ $sql .= " sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
+ $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s";
+ if ($selected_cat === -2) // Without any category
+ {
+ $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
+ }
+ elseif ($selected_cat) // Into a specific category
+ {
+ $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
+ }
+ $sql .= " WHERE f.fk_statut in (1,2)";
+ $sql .= " AND f.type IN (0,2)";
+ $sql .= " AND f.fk_soc = s.rowid";
+ if ($date_start && $date_end) {
+ $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
+ }
+ if ($selected_cat === -2) // Without any category
+ {
+ $sql .= " AND cs.fk_soc is null";
+ }
+ elseif ($selected_cat) { // Into a specific category
+ $sql .= " AND (c.rowid = ".$db->escape($selected_cat);
+ if ($subcat) $sql .= " OR c.fk_parent = ".$db->escape($selected_cat);
+ $sql .= ")";
+ $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
+ }
+} else {
+ $sql = "SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc";
+ $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
+ $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
+ $sql .= ", ".MAIN_DB_PREFIX."paiementfourn as p";
+ $sql .= ", ".MAIN_DB_PREFIX."societe as s";
+ if ($selected_cat === -2) // Without any category
+ {
+ $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
+ }
+ elseif ($selected_cat) // Into a specific category
+ {
+ $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
+ }
+ $sql .= " WHERE p.rowid = pf.fk_paiementfourn";
+ $sql .= " AND pf.fk_facturefourn = f.rowid";
+ $sql .= " AND f.fk_soc = s.rowid";
+ if ($date_start && $date_end) {
+ $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
+ }
+ if ($selected_cat === -2) // Without any category
+ {
+ $sql .= " AND cs.fk_soc is null";
+ }
+ elseif ($selected_cat) { // Into a specific category
+ $sql .= " AND (c.rowid = ".$selected_cat;
+ if ($subcat) $sql .= " OR c.fk_parent = ".$selected_cat;
+ $sql .= ")";
+ $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
+ }
+}
+if (!empty($search_societe)) $sql .= natural_search('s.nom', $search_societe);
+if (!empty($search_zip)) $sql .= natural_search('s.zip', $search_zip);
+if (!empty($search_town)) $sql .= natural_search('s.town', $search_town);
+if ($search_country > 0) $sql .= ' AND s.fk_pays = '.$search_country.'';
+$sql .= " AND f.entity IN (".getEntity('invoice').")";
+if ($socid) $sql .= " AND f.fk_soc = ".$socid;
+$sql .= " GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays";
+$sql .= " ORDER BY s.rowid";
+//echo $sql;
+
+dol_syslog("supplier_turnover_by_thirdparty", LOG_DEBUG);
+$result = $db->query($sql);
+if ($result) {
+ $num = $db->num_rows($result);
+ $i = 0;
+ while ($i < $num) {
+ $obj = $db->fetch_object($result);
+ $amount_ht[$obj->socid] = $obj->amount;
+ $amount[$obj->socid] = $obj->amount_ttc;
+ $name[$obj->socid] = $obj->name.' '.$obj->firstname;
+ $address_zip[$obj->socid] = $obj->zip;
+ $address_town[$obj->socid] = $obj->town;
+ $address_pays[$obj->socid] = getCountry($obj->fk_pays);
+ $catotal_ht += $obj->amount;
+ $catotal += $obj->amount_ttc;
+ $i++;
+ }
+} else {
+ dol_print_error($db);
+}
+
+// Show array
+$i = 0;
+print '