casoc.php 23 KB

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