supplier_turnover_by_thirdparty.php 20 KB

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