supplier_turnover_by_thirdparty.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <?php
  2. /* Copyright (C) 2020 Maxime Kohlhaas <maxime@atm-consulting.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/compta/stats/supplier_turnover_by_thirdparty.php
  19. * \brief Page reporting purchase turnover by thirdparty
  20. */
  21. require '../../main.inc.php';
  22. require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
  23. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.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.'/categories/class/categorie.class.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array('companies', 'categories', 'bills', 'compta'));
  31. // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
  32. $modecompta = $conf->global->ACCOUNTING_MODE;
  33. if (GETPOST("modecompta")) {
  34. $modecompta = GETPOST("modecompta");
  35. }
  36. $sortorder = GETPOST("sortorder", 'aZ09comma');
  37. $sortfield = GETPOST("sortfield", 'aZ09comma');
  38. if (!$sortorder) {
  39. $sortorder = "asc";
  40. }
  41. if (!$sortfield) {
  42. $sortfield = "nom";
  43. }
  44. $socid = GETPOST('socid', 'int');
  45. // Category
  46. $selected_cat = (int) GETPOST('search_categ', 'int');
  47. $subcat = false;
  48. if (GETPOST('subcat', 'alpha') === 'yes') {
  49. $subcat = true;
  50. }
  51. // Hook
  52. $hookmanager->initHooks(array('supplierturnoverbythirdpartylist'));
  53. // Date range
  54. $year = GETPOST("year", 'int');
  55. $month = GETPOST("month", 'int');
  56. $search_societe = GETPOST("search_societe", 'alpha');
  57. $search_zip = GETPOST("search_zip", 'alpha');
  58. $search_town = GETPOST("search_town", 'alpha');
  59. $search_country = GETPOST("search_country", 'alpha');
  60. $date_startyear = GETPOST("date_startyear", 'alpha');
  61. $date_startmonth = GETPOST("date_startmonth", 'alpha');
  62. $date_startday = GETPOST("date_startday", 'alpha');
  63. $date_endyear = GETPOST("date_endyear", 'alpha');
  64. $date_endmonth = GETPOST("date_endmonth", 'alpha');
  65. $date_endday = GETPOST("date_endday", 'alpha');
  66. if (empty($year)) {
  67. $year_current = dol_print_date(dol_now(), '%Y');
  68. $month_current = dol_print_date(dol_now(), '%m');
  69. $year_start = $year_current;
  70. } else {
  71. $year_current = $year;
  72. $month_current = dol_print_date(dol_now(), '%m');
  73. $year_start = $year;
  74. }
  75. $date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"), 'tzserver'); // We use timezone of server so report is same from everywhere
  76. $date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"), 'tzserver'); // We use timezone of server so report is same from everywhere
  77. // Quarter
  78. if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
  79. $q = GETPOST("q", "int") ?GETPOST("q", "int") : 0;
  80. if (empty($q)) {
  81. // We define date_start and date_end
  82. $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
  83. $year_end = $year_start;
  84. $month_end = $month_start;
  85. if (!GETPOST("month")) { // If month not forced
  86. if (!GETPOST('year') && $month_start > $month_current) {
  87. $year_start--;
  88. $year_end--;
  89. }
  90. $month_end = $month_start - 1;
  91. if ($month_end < 1) {
  92. $month_end = 12;
  93. } else {
  94. $year_end++;
  95. }
  96. }
  97. $date_start = dol_get_first_day($year_start, $month_start, false);
  98. $date_end = dol_get_last_day($year_end, $month_end, false);
  99. }
  100. if ($q == 1) {
  101. $date_start = dol_get_first_day($year_start, 1, false);
  102. $date_end = dol_get_last_day($year_start, 3, false);
  103. }
  104. if ($q == 2) {
  105. $date_start = dol_get_first_day($year_start, 4, false);
  106. $date_end = dol_get_last_day($year_start, 6, false);
  107. }
  108. if ($q == 3) {
  109. $date_start = dol_get_first_day($year_start, 7, false);
  110. $date_end = dol_get_last_day($year_start, 9, false);
  111. }
  112. if ($q == 4) {
  113. $date_start = dol_get_first_day($year_start, 10, false);
  114. $date_end = dol_get_last_day($year_start, 12, false);
  115. }
  116. } else {
  117. // TODO We define q
  118. }
  119. // $date_start and $date_end are defined. We force $year_start and $nbofyear
  120. $tmps = dol_getdate($date_start);
  121. $year_start = $tmps['year'];
  122. $tmpe = dol_getdate($date_end);
  123. $year_end = $tmpe['year'];
  124. $nbofyear = ($year_end - $year_start) + 1;
  125. $commonparams = array();
  126. $commonparams['modecompta'] = $modecompta;
  127. $commonparams['sortorder'] = $sortorder;
  128. $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;
  137. $tableparams = array();
  138. $tableparams['search_categ'] = $selected_cat;
  139. $tableparams['search_societe'] = $search_societe;
  140. $tableparams['search_zip'] = $search_zip;
  141. $tableparams['search_town'] = $search_town;
  142. $tableparams['search_country'] = $search_country;
  143. $tableparams['subcat'] = ($subcat === true) ? 'yes' : '';
  144. // Adding common parameters
  145. $allparams = array_merge($commonparams, $headerparams, $tableparams);
  146. $headerparams = array_merge($commonparams, $headerparams);
  147. $tableparams = array_merge($commonparams, $tableparams);
  148. foreach ($allparams as $key => $value) {
  149. $paramslink .= '&'.$key.'='.$value;
  150. }
  151. // Security check
  152. if ($user->socid > 0) {
  153. $socid = $user->socid;
  154. }
  155. if (!empty($conf->comptabilite->enabled)) {
  156. $result = restrictedArea($user, 'compta', '', '', 'resultat');
  157. }
  158. if (!empty($conf->accounting->enabled)) {
  159. $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
  160. }
  161. /*
  162. * View
  163. */
  164. llxHeader();
  165. $form = new Form($db);
  166. $thirdparty_static = new Societe($db);
  167. $formother = new FormOther($db);
  168. // TODO Report from bookkeeping not yet available, so we switch on report on business events
  169. if ($modecompta == "BOOKKEEPING") {
  170. $modecompta = "CREANCES-DETTES";
  171. }
  172. if ($modecompta == "BOOKKEEPINGCOLLECTED") {
  173. $modecompta = "RECETTES-DEPENSES";
  174. }
  175. // Show report header
  176. if ($modecompta == "CREANCES-DETTES") {
  177. $name = $langs->trans("PurchaseTurnover").', '.$langs->trans("ByThirdParties");
  178. $calcmode = $langs->trans("CalcModeDebt");
  179. //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
  180. $description = $langs->trans("RulesPurchaseTurnoverDue");
  181. //$exportlink=$langs->trans("NotYetAvailable");
  182. } elseif ($modecompta == "RECETTES-DEPENSES") {
  183. $name = $langs->trans("PurchaseTurnoverCollected").', '.$langs->trans("ByThirdParties");
  184. $calcmode = $langs->trans("CalcModeEngagement");
  185. //$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
  186. $description = $langs->trans("RulesPurchaseTurnoverIn");
  187. //$exportlink=$langs->trans("NotYetAvailable");
  188. } elseif ($modecompta == "BOOKKEEPING") {
  189. // TODO
  190. } elseif ($modecompta == "BOOKKEEPINGCOLLECTED") {
  191. // TODO
  192. }
  193. $builddate = dol_now();
  194. $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
  195. $period .= ' - ';
  196. $period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
  197. if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) {
  198. $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>';
  199. } else {
  200. $periodlink = '';
  201. }
  202. report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
  203. if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') {
  204. print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
  205. }
  206. // Show Array
  207. $catotal = 0;
  208. $catotal_ht = 0;
  209. $name = array();
  210. $amount = array();
  211. $amount_ht = array();
  212. if ($modecompta == 'CREANCES-DETTES') {
  213. $sql = "SELECT DISTINCT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,";
  214. $sql .= " sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
  215. $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s";
  216. if ($selected_cat === -2) { // Without any category
  217. $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
  218. } elseif ($selected_cat) { // Into a specific category
  219. $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
  220. }
  221. $sql .= " WHERE f.fk_statut in (1,2)";
  222. $sql .= " AND f.type IN (0,2)";
  223. $sql .= " AND f.fk_soc = s.rowid";
  224. if ($date_start && $date_end) {
  225. $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
  226. }
  227. if ($selected_cat === -2) { // Without any category
  228. $sql .= " AND cs.fk_soc is null";
  229. } elseif ($selected_cat) { // Into a specific category
  230. $sql .= " AND (c.rowid = ".((int) $selected_cat);
  231. if ($subcat) {
  232. $sql .= " OR c.fk_parent = ".((int) $selected_cat);
  233. }
  234. $sql .= ")";
  235. $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
  236. }
  237. } elseif ($modecompta == "RECETTES-DEPENSES") {
  238. $sql = "SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc";
  239. $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
  240. $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
  241. $sql .= ", ".MAIN_DB_PREFIX."paiementfourn as p";
  242. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  243. if ($selected_cat === -2) { // Without any category
  244. $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc";
  245. } elseif ($selected_cat) { // Into a specific category
  246. $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs";
  247. }
  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)."'";
  253. }
  254. if ($selected_cat === -2) { // Without any category
  255. $sql .= " AND cs.fk_soc is null";
  256. } elseif ($selected_cat) { // Into a specific category
  257. $sql .= " AND (c.rowid = ".((int) $selected_cat);
  258. if ($subcat) {
  259. $sql .= " OR c.fk_parent = ".((int) $selected_cat);
  260. }
  261. $sql .= ")";
  262. $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid";
  263. }
  264. }
  265. if (!empty($search_societe)) {
  266. $sql .= natural_search('s.nom', $search_societe);
  267. }
  268. if (!empty($search_zip)) {
  269. $sql .= natural_search('s.zip', $search_zip);
  270. }
  271. if (!empty($search_town)) {
  272. $sql .= natural_search('s.town', $search_town);
  273. }
  274. if ($search_country > 0) {
  275. $sql .= ' AND s.fk_pays = '.((int) $search_country);
  276. }
  277. $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
  278. if ($socid) {
  279. $sql .= " AND f.fk_soc = ".((int) $socid);
  280. }
  281. $sql .= " GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays";
  282. $sql .= " ORDER BY s.rowid";
  283. //echo $sql;
  284. dol_syslog("supplier_turnover_by_thirdparty", LOG_DEBUG);
  285. $result = $db->query($sql);
  286. if ($result) {
  287. $num = $db->num_rows($result);
  288. $i = 0;
  289. while ($i < $num) {
  290. $obj = $db->fetch_object($result);
  291. $amount_ht[$obj->socid] = $obj->amount;
  292. $amount[$obj->socid] = $obj->amount_ttc;
  293. $name[$obj->socid] = $obj->name.' '.$obj->firstname;
  294. $address_zip[$obj->socid] = $obj->zip;
  295. $address_town[$obj->socid] = $obj->town;
  296. $address_pays[$obj->socid] = getCountry($obj->fk_pays);
  297. $catotal_ht += $obj->amount;
  298. $catotal += $obj->amount_ttc;
  299. $i++;
  300. }
  301. } else {
  302. dol_print_error($db);
  303. }
  304. // Show array
  305. $i = 0;
  306. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  307. print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
  308. // Extra parameters management
  309. foreach ($headerparams as $key => $value) {
  310. print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
  311. }
  312. $moreforfilter = '';
  313. print '<div class="div-table-responsive">';
  314. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  315. // Category filter
  316. print '<tr class="liste_titre">';
  317. print '<td>';
  318. print img_picto('', 'category', 'class="paddingrightonly"');
  319. print $formother->select_categories(Categorie::TYPE_SUPPLIER, $selected_cat, 'search_categ', 0, $langs->trans("Category"));
  320. print ' ';
  321. print $langs->trans("SubCats").'? ';
  322. print '<input type="checkbox" name="subcat" value="yes"';
  323. if ($subcat) {
  324. print ' checked';
  325. }
  326. print'></td>';
  327. print '<td colspan="7" class="right">';
  328. 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")).'">';
  329. print '</td>';
  330. print '</tr>';
  331. print '<tr class="liste_titre">';
  332. print '<td class="liste_titre left">';
  333. print '<input class="flat" size="6" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
  334. print '</td>';
  335. print '<td class="liste_titre left">';
  336. print '<input class="flat" size="6" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'">';
  337. print '</td>';
  338. print '<td class="liste_titre left">';
  339. print '<input class="flat" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'">';
  340. print '</td>';
  341. print '<td class="liste_titre left">';
  342. print $form->select_country($search_country, 'search_country');
  343. //print '<input class="flat" size="6" type="text" name="search_country" value="'.$search_country.'">';
  344. print '</td>';
  345. print '<td class="liste_titre">&nbsp;</td>';
  346. print '<td class="liste_titre">&nbsp;</td>';
  347. print '<td class="liste_titre">&nbsp;</td>';
  348. print '<td class="liste_titre">&nbsp;</td>';
  349. print '</tr>';
  350. // Array titles
  351. print "<tr class='liste_titre'>";
  352. print_liste_field_titre(
  353. $langs->trans("Company"),
  354. $_SERVER["PHP_SELF"],
  355. "nom",
  356. "",
  357. $paramslink,
  358. "",
  359. $sortfield,
  360. $sortorder
  361. );
  362. print_liste_field_titre(
  363. $langs->trans("Zip"),
  364. $_SERVER["PHP_SELF"],
  365. "zip",
  366. "",
  367. $paramslink,
  368. "",
  369. $sortfield,
  370. $sortorder
  371. );
  372. print_liste_field_titre(
  373. $langs->trans("Town"),
  374. $_SERVER["PHP_SELF"],
  375. "town",
  376. "",
  377. $paramslink,
  378. "",
  379. $sortfield,
  380. $sortorder
  381. );
  382. print_liste_field_titre(
  383. $langs->trans("Country"),
  384. $_SERVER["PHP_SELF"],
  385. "country",
  386. "",
  387. $paramslink,
  388. "",
  389. $sortfield,
  390. $sortorder
  391. );
  392. if ($modecompta == 'CREANCES-DETTES') {
  393. print_liste_field_titre(
  394. $langs->trans('AmountHT'),
  395. $_SERVER["PHP_SELF"],
  396. "amount_ht",
  397. "",
  398. $paramslink,
  399. 'class="right"',
  400. $sortfield,
  401. $sortorder
  402. );
  403. } else {
  404. print_liste_field_titre('');
  405. }
  406. print_liste_field_titre(
  407. $langs->trans("AmountTTC"),
  408. $_SERVER["PHP_SELF"],
  409. "amount_ttc",
  410. "",
  411. $paramslink,
  412. 'class="right"',
  413. $sortfield,
  414. $sortorder
  415. );
  416. print_liste_field_titre(
  417. $langs->trans("Percentage"),
  418. $_SERVER["PHP_SELF"],
  419. "amount_ttc",
  420. "",
  421. $paramslink,
  422. 'class="right"',
  423. $sortfield,
  424. $sortorder
  425. );
  426. print_liste_field_titre(
  427. $langs->trans("OtherStatistics"),
  428. $_SERVER["PHP_SELF"],
  429. "",
  430. "",
  431. "",
  432. 'align="center" width="20%"'
  433. );
  434. print "</tr>\n";
  435. if (count($amount)) {
  436. $arrayforsort = $name;
  437. // Defining array arrayforsort
  438. if ($sortfield == 'nom' && $sortorder == 'asc') {
  439. asort($name);
  440. $arrayforsort = $name;
  441. }
  442. if ($sortfield == 'nom' && $sortorder == 'desc') {
  443. arsort($name);
  444. $arrayforsort = $name;
  445. }
  446. if ($sortfield == 'amount_ht' && $sortorder == 'asc') {
  447. asort($amount_ht);
  448. $arrayforsort = $amount_ht;
  449. }
  450. if ($sortfield == 'amount_ht' && $sortorder == 'desc') {
  451. arsort($amount_ht);
  452. $arrayforsort = $amount_ht;
  453. }
  454. if ($sortfield == 'amount_ttc' && $sortorder == 'asc') {
  455. asort($amount);
  456. $arrayforsort = $amount;
  457. }
  458. if ($sortfield == 'amount_ttc' && $sortorder == 'desc') {
  459. arsort($amount);
  460. $arrayforsort = $amount;
  461. }
  462. if ($sortfield == 'zip' && $sortorder == 'asc') {
  463. asort($address_zip);
  464. $arrayforsort = $address_zip;
  465. }
  466. if ($sortfield == 'zip' && $sortorder == 'desc') {
  467. arsort($address_zip);
  468. $arrayforsort = $address_zip;
  469. }
  470. if ($sortfield == 'town' && $sortorder == 'asc') {
  471. asort($address_town);
  472. $arrayforsort = $address_town;
  473. }
  474. if ($sortfield == 'town' && $sortorder == 'desc') {
  475. arsort($address_town);
  476. $arrayforsort = $address_town;
  477. }
  478. if ($sortfield == 'country' && $sortorder == 'asc') {
  479. asort($address_pays);
  480. $arrayforsort = $address_town;
  481. }
  482. if ($sortfield == 'country' && $sortorder == 'desc') {
  483. arsort($address_pays);
  484. $arrayforsort = $address_town;
  485. }
  486. foreach ($arrayforsort as $key => $value) {
  487. print '<tr class="oddeven">';
  488. // Third party
  489. $fullname = $name[$key];
  490. if ($key > 0) {
  491. $thirdparty_static->id = $key;
  492. $thirdparty_static->name = $fullname;
  493. $thirdparty_static->client = 1;
  494. $linkname = $thirdparty_static->getNomUrl(1, 'supplier');
  495. } else {
  496. $linkname = $langs->trans("PaymentsNotLinkedToInvoice");
  497. }
  498. print "<td>".$linkname."</td>\n";
  499. print '<td>';
  500. print $address_zip[$key];
  501. print '</td>';
  502. print '<td>';
  503. print $address_town[$key];
  504. print '</td>';
  505. print '<td>';
  506. print $address_pays[$key];
  507. print '</td>';
  508. // Amount w/o VAT
  509. print '<td class="right">';
  510. if ($modecompta != 'CREANCES-DETTES') {
  511. if ($key > 0) {
  512. print '<a href="'.DOL_URL_ROOT.'/fourn/facture/paiement/list.php?socid='.$key.'">';
  513. } else {
  514. print '<a href="'.DOL_URL_ROOT.'/fourn/facture/paiement/list.php?socid=-1">';
  515. }
  516. } else {
  517. if ($key > 0) {
  518. print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$key.'">';
  519. } else {
  520. print '<a href="#">';
  521. }
  522. print price($amount_ht[$key]);
  523. }
  524. print '</td>';
  525. // Amount with VAT
  526. print '<td class="right">';
  527. if ($modecompta != 'CREANCES-DETTES') {
  528. if ($key > 0) {
  529. print '<a href="'.DOL_URL_ROOT.'/fourn/facture/paiement/list.php?socid='.$key.'">';
  530. } else {
  531. print '<a href="'.DOL_URL_ROOT.'/fourn/facture/paiement/list.php?orphelins=1">';
  532. }
  533. } else {
  534. if ($key > 0) {
  535. print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$key.'">';
  536. } else {
  537. print '<a href="#">';
  538. }
  539. }
  540. print price($amount[$key]);
  541. print '</a>';
  542. print '</td>';
  543. // Percent;
  544. print '<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : '&nbsp;').'</td>';
  545. // Other stats
  546. print '<td class="center">';
  547. if (!empty($conf->supplier_proposal->enabled) && $key > 0) {
  548. print '&nbsp;<a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$key.'">'.img_picto($langs->trans("ProposalStats"), "stats").'</a>&nbsp;';
  549. }
  550. if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled)) && $key > 0) {
  551. print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/stats/index.php?mode=supplier&socid='.$key.'">'.img_picto($langs->trans("OrderStats"), "stats").'</a>&nbsp;';
  552. }
  553. if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_invoice->enabled)) && $key > 0) {
  554. print '&nbsp;<a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?mode=supplier&socid='.$key.'">'.img_picto($langs->trans("InvoiceStats"), "stats").'</a>&nbsp;';
  555. }
  556. print '</td>';
  557. print "</tr>\n";
  558. $i++;
  559. }
  560. // Total
  561. print '<tr class="liste_total">';
  562. print '<td>'.$langs->trans("Total").'</td>';
  563. print '<td>&nbsp;</td>';
  564. print '<td>&nbsp;</td>';
  565. print '<td>&nbsp;</td>';
  566. if ($modecompta != 'CREANCES-DETTES') {
  567. print '<td></td>';
  568. } else {
  569. print '<td class="right">'.price($catotal_ht).'</td>';
  570. }
  571. print '<td class="right">'.price($catotal).'</td>';
  572. print '<td>&nbsp;</td>';
  573. print '<td>&nbsp;</td>';
  574. print '</tr>';
  575. $db->free($result);
  576. }
  577. print "</table>";
  578. print "</div>";
  579. print '</form>';
  580. // End of page
  581. llxFooter();
  582. $db->close();