lines.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <?php
  2. /* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. * Copyright (C) 2014-2015 Ari Elbaz (elarifr) <github@accedinfo.com>
  5. * Copyright (C) 2014-2016 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/accountancy/customer/lines.php
  23. * \ingroup Accountancy (Double entries)
  24. * \brief Page of detail of the lines of ventilation of invoices customers
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  36. // Load translation files required by the page
  37. $langs->loadLangs(array("bills", "compta", "accountancy", "productbatch", "products"));
  38. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  39. $account_parent = GETPOST('account_parent');
  40. $changeaccount = GETPOST('changeaccount');
  41. // Search Getpost
  42. $search_societe = GETPOST('search_societe', 'alpha');
  43. $search_lineid = GETPOST('search_lineid', 'int');
  44. $search_ref = GETPOST('search_ref', 'alpha');
  45. $search_invoice = GETPOST('search_invoice', 'alpha');
  46. $search_label = GETPOST('search_label', 'alpha');
  47. $search_desc = GETPOST('search_desc', 'alpha');
  48. $search_amount = GETPOST('search_amount', 'alpha');
  49. $search_account = GETPOST('search_account', 'alpha');
  50. $search_vat = GETPOST('search_vat', 'alpha');
  51. $search_date_startday = GETPOST('search_date_startday', 'int');
  52. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  53. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  54. $search_date_endday = GETPOST('search_date_endday', 'int');
  55. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  56. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  57. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
  58. $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
  59. $search_country = GETPOST('search_country', 'alpha');
  60. $search_tvaintra = GETPOST('search_tvaintra', 'alpha');
  61. // Load variable for pagination
  62. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  63. $sortfield = GETPOST('sortfield', 'aZ09comma');
  64. $sortorder = GETPOST('sortorder', 'aZ09comma');
  65. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  66. if (empty($page) || $page < 0) {
  67. $page = 0;
  68. }
  69. $offset = $limit * $page;
  70. $pageprev = $page - 1;
  71. $pagenext = $page + 1;
  72. if (!$sortfield) {
  73. $sortfield = "f.datef, f.ref, fd.rowid";
  74. }
  75. if (!$sortorder) {
  76. if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE > 0) {
  77. $sortorder = "DESC";
  78. }
  79. }
  80. // Security check
  81. if (empty($conf->accounting->enabled)) {
  82. accessforbidden();
  83. }
  84. if ($user->socid > 0) {
  85. accessforbidden();
  86. }
  87. if (empty($user->rights->accounting->mouvements->lire)) {
  88. accessforbidden();
  89. }
  90. $formaccounting = new FormAccounting($db);
  91. /*
  92. * Actions
  93. */
  94. // Purge search criteria
  95. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  96. $search_societe = '';
  97. $search_lineid = '';
  98. $search_ref = '';
  99. $search_invoice = '';
  100. $search_label = '';
  101. $search_desc = '';
  102. $search_amount = '';
  103. $search_account = '';
  104. $search_vat = '';
  105. $search_date_startday = '';
  106. $search_date_startmonth = '';
  107. $search_date_startyear = '';
  108. $search_date_endday = '';
  109. $search_date_endmonth = '';
  110. $search_date_endyear = '';
  111. $search_date_start = '';
  112. $search_date_end = '';
  113. $search_country = '';
  114. $search_tvaintra = '';
  115. }
  116. if (is_array($changeaccount) && count($changeaccount) > 0 && $user->rights->accounting->bind->write) {
  117. $error = 0;
  118. if (!(GETPOST('account_parent', 'int') >= 0)) {
  119. $error++;
  120. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Account")), null, 'errors');
  121. }
  122. if (!$error) {
  123. $db->begin();
  124. $sql1 = "UPDATE ".MAIN_DB_PREFIX."facturedet as l";
  125. $sql1 .= " SET l.fk_code_ventilation=".(GETPOST('account_parent', 'int') > 0 ? GETPOST('account_parent', 'int') : '0');
  126. $sql1 .= ' WHERE l.rowid IN ('.$db->sanitize(implode(',', $changeaccount)).')';
  127. dol_syslog('accountancy/customer/lines.php::changeaccount sql= '.$sql1);
  128. $resql1 = $db->query($sql1);
  129. if (!$resql1) {
  130. $error++;
  131. setEventMessages($db->lasterror(), null, 'errors');
  132. }
  133. if (!$error) {
  134. $db->commit();
  135. setEventMessages($langs->trans("Save"), null, 'mesgs');
  136. } else {
  137. $db->rollback();
  138. setEventMessages($db->lasterror(), null, 'errors');
  139. }
  140. $account_parent = ''; // Protection to avoid to mass apply it a second time
  141. }
  142. }
  143. /*
  144. * View
  145. */
  146. $form = new Form($db);
  147. $formother = new FormOther($db);
  148. llxHeader('', $langs->trans("CustomersVentilation").' - '.$langs->trans("Dispatched"));
  149. print '<script type="text/javascript">
  150. $(function () {
  151. $(\'#select-all\').click(function(event) {
  152. // Iterate each checkbox
  153. $(\':checkbox\').each(function() {
  154. this.checked = true;
  155. });
  156. });
  157. $(\'#unselect-all\').click(function(event) {
  158. // Iterate each checkbox
  159. $(\':checkbox\').each(function() {
  160. this.checked = false;
  161. });
  162. });
  163. });
  164. </script>';
  165. /*
  166. * Customer Invoice lines
  167. */
  168. $sql = "SELECT f.rowid as facid, f.ref as ref, f.type, f.datef, f.ref_client,";
  169. $sql .= " fd.rowid, fd.description, fd.product_type as line_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.vat_src_code, fd.total_ttc,";
  170. $sql .= " s.rowid as socid, s.nom as name, s.code_client,";
  171. if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
  172. $sql .= ", spe.accountancy_code_customer as code_compta_client";
  173. $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
  174. } else {
  175. $sql .= ", s.code_compta as code_compta_client";
  176. $sql .= ", s.code_compta_fournisseur";
  177. }
  178. $sql .= " p.rowid as product_id, p.fk_product_type as product_type, p.ref as product_ref, p.label as product_label,";
  179. if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  180. $sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export,";
  181. } else {
  182. $sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
  183. }
  184. $sql .= " aa.rowid as fk_compte, aa.account_number, aa.label as label_account, aa.labelshort as labelshort_account,";
  185. $sql .= " fd.situation_percent,";
  186. $sql .= " co.code as country_code, co.label as country,";
  187. $sql .= " s.rowid as socid, s.nom as name, s.tva_intra, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
  188. $parameters = array();
  189. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  190. $sql .= $hookmanager->resPrint;
  191. $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
  192. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
  193. if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  194. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
  195. }
  196. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
  197. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
  198. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
  199. if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
  200. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
  201. }
  202. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays ";
  203. $sql .= " WHERE fd.fk_code_ventilation > 0";
  204. $sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
  205. $sql .= " AND f.fk_statut > 0";
  206. if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  207. $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_SITUATION.")";
  208. } else {
  209. $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_DEPOSIT.",".Facture::TYPE_SITUATION.")";
  210. }
  211. // Add search filter like
  212. if ($search_societe) {
  213. $sql .= natural_search('s.nom', $search_societe);
  214. }
  215. if ($search_lineid) {
  216. $sql .= natural_search("fd.rowid", $search_lineid, 1);
  217. }
  218. if (strlen(trim($search_invoice))) {
  219. $sql .= natural_search("f.ref", $search_invoice);
  220. }
  221. if (strlen(trim($search_ref))) {
  222. $sql .= natural_search("p.ref", $search_ref);
  223. }
  224. if (strlen(trim($search_label))) {
  225. $sql .= natural_search("p.label", $search_label);
  226. }
  227. if (strlen(trim($search_desc))) {
  228. $sql .= natural_search("fd.description", $search_desc);
  229. }
  230. if (strlen(trim($search_amount))) {
  231. $sql .= natural_search("fd.total_ht", $search_amount, 1);
  232. }
  233. if (strlen(trim($search_account))) {
  234. $sql .= natural_search("aa.account_number", $search_account);
  235. }
  236. if (strlen(trim($search_vat))) {
  237. $sql .= natural_search("fd.tva_tx", price2num($search_vat), 1);
  238. }
  239. if ($search_date_start) {
  240. $sql .= " AND f.datef >= '".$db->idate($search_date_start)."'";
  241. }
  242. if ($search_date_end) {
  243. $sql .= " AND f.datef <= '".$db->idate($search_date_end)."'";
  244. }
  245. if (strlen(trim($search_country))) {
  246. $arrayofcode = getCountriesInEEC();
  247. $country_code_in_EEC = $country_code_in_EEC_without_me = '';
  248. foreach ($arrayofcode as $key => $value) {
  249. $country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
  250. if ($value != $mysoc->country_code) {
  251. $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
  252. }
  253. }
  254. if ($search_country == 'special_allnotme') {
  255. $sql .= " AND co.code <> '".$db->escape($mysoc->country_code)."'";
  256. } elseif ($search_country == 'special_eec') {
  257. $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC, 1).")";
  258. } elseif ($search_country == 'special_eecnotme') {
  259. $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).")";
  260. } elseif ($search_country == 'special_noteec') {
  261. $sql .= " AND co.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).")";
  262. } else {
  263. $sql .= natural_search("co.code", $search_country);
  264. }
  265. }
  266. if (strlen(trim($search_tvaintra))) {
  267. $sql .= natural_search("s.tva_intra", $search_tvaintra);
  268. }
  269. $sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
  270. $sql .= $db->order($sortfield, $sortorder);
  271. // Count total nb of records
  272. $nbtotalofrecords = '';
  273. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  274. $result = $db->query($sql);
  275. $nbtotalofrecords = $db->num_rows($result);
  276. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  277. $page = 0;
  278. $offset = 0;
  279. }
  280. }
  281. $sql .= $db->plimit($limit + 1, $offset);
  282. dol_syslog("/accountancy/customer/lines.php", LOG_DEBUG);
  283. $result = $db->query($sql);
  284. if ($result) {
  285. $num_lines = $db->num_rows($result);
  286. $i = 0;
  287. $param = '';
  288. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  289. $param .= '&contextpage='.urlencode($contextpage);
  290. }
  291. if ($limit > 0 && $limit != $conf->liste_limit) {
  292. $param .= '&limit='.urlencode($limit);
  293. }
  294. if ($search_societe) {
  295. $param .= "&search_societe=".urlencode($search_societe);
  296. }
  297. if ($search_invoice) {
  298. $param .= "&search_invoice=".urlencode($search_invoice);
  299. }
  300. if ($search_ref) {
  301. $param .= "&search_ref=".urlencode($search_ref);
  302. }
  303. if ($search_label) {
  304. $param .= "&search_label=".urlencode($search_label);
  305. }
  306. if ($search_desc) {
  307. $param .= "&search_desc=".urlencode($search_desc);
  308. }
  309. if ($search_account) {
  310. $param .= "&search_account=".urlencode($search_account);
  311. }
  312. if ($search_vat) {
  313. $param .= "&search_vat=".urlencode($search_vat);
  314. }
  315. if ($search_date_startday) {
  316. $param .= '&search_date_startday='.urlencode($search_date_startday);
  317. }
  318. if ($search_date_startmonth) {
  319. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  320. }
  321. if ($search_date_startyear) {
  322. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  323. }
  324. if ($search_date_endday) {
  325. $param .= '&search_date_endday='.urlencode($search_date_endday);
  326. }
  327. if ($search_date_endmonth) {
  328. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  329. }
  330. if ($search_date_endyear) {
  331. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  332. }
  333. if ($search_country) {
  334. $param .= "&search_country=".urlencode($search_country);
  335. }
  336. if ($search_tvaintra) {
  337. $param .= "&search_tvaintra=".urlencode($search_tvaintra);
  338. }
  339. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'."\n";
  340. print '<input type="hidden" name="action" value="ventil">';
  341. if ($optioncss != '') {
  342. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  343. }
  344. print '<input type="hidden" name="token" value="'.newToken().'">';
  345. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  346. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  347. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  348. print '<input type="hidden" name="page" value="'.$page.'">';
  349. print_barre_liste($langs->trans("InvoiceLinesDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
  350. print '<span class="opacitymedium">'.$langs->trans("DescVentilDoneCustomer").'</span><br>';
  351. print '<br><div class="inline-block divButAction paddingbottom">'.$langs->trans("ChangeAccount").' ';
  352. print $formaccounting->select_account($account_parent, 'account_parent', 2, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone valignmiddle');
  353. print '<input type="submit" class="button small valignmiddle" value="'.$langs->trans("ChangeBinding").'"/></div>';
  354. $moreforfilter = '';
  355. print '<div class="div-table-responsive">';
  356. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  357. print '<tr class="liste_titre_filter">';
  358. print '<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).'"></td>';
  359. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).'"></td>';
  360. print '<td class="liste_titre center">';
  361. print '<div class="nowrap">';
  362. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  363. print '</div>';
  364. print '<div class="nowrap">';
  365. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  366. print '</div>';
  367. print '</td>';
  368. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
  369. //print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
  370. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="'.dol_escape_htmltag($search_desc).'"></td>';
  371. print '<td class="liste_titre right"><input type="text" class="right flat maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
  372. print '<td class="liste_titre right"><input type="text" class="right flat maxwidth50" placeholder="%" name="search_vat" size="1" value="'.dol_escape_htmltag($search_vat).'"></td>';
  373. print '<td class="liste_titre"><input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
  374. print '<td class="liste_titre">';
  375. print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth150', 'code2', 1, 0, 1);
  376. //print '<input type="text" class="flat maxwidth50" name="search_country" value="' . dol_escape_htmltag($search_country) . '">';
  377. print '</td>';
  378. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).'"></td>';
  379. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_account" value="'.dol_escape_htmltag($search_account).'"></td>';
  380. print '<td class="liste_titre center">';
  381. $searchpicto = $form->showFilterButtons();
  382. print $searchpicto;
  383. print "</td></tr>\n";
  384. print '<tr class="liste_titre">';
  385. print_liste_field_titre("LineId", $_SERVER["PHP_SELF"], "fd.rowid", "", $param, '', $sortfield, $sortorder);
  386. print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
  387. print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "f.datef, f.ref, fd.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
  388. print_liste_field_titre("ProductRef", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
  389. //print_liste_field_titre("ProductLabel", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
  390. print_liste_field_titre("ProductDescription", $_SERVER["PHP_SELF"], "fd.description", "", $param, '', $sortfield, $sortorder);
  391. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "fd.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
  392. print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "fd.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ');
  393. print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
  394. print_liste_field_titre("Country", $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
  395. print_liste_field_titre("VATIntra", $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
  396. print_liste_field_titre("AccountAccounting", $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
  397. $checkpicto = $form->showCheckAddButtons();
  398. print_liste_field_titre($checkpicto, '', '', '', '', '', '', '', 'center ');
  399. print "</tr>\n";
  400. $thirdpartystatic = new Societe($db);
  401. $facturestatic = new Facture($db);
  402. $productstatic = new Product($db);
  403. $accountingaccountstatic = new AccountingAccount($db);
  404. $i = 0;
  405. while ($i < min($num_lines, $limit)) {
  406. $objp = $db->fetch_object($result);
  407. $facturestatic->ref = $objp->ref;
  408. $facturestatic->id = $objp->facid;
  409. $facturestatic->type = $objp->ftype;
  410. $thirdpartystatic->id = $objp->socid;
  411. $thirdpartystatic->name = $objp->name;
  412. $thirdpartystatic->client = $objp->client;
  413. $thirdpartystatic->fournisseur = $objp->fournisseur;
  414. $thirdpartystatic->code_client = $objp->code_client;
  415. $thirdpartystatic->code_compta_client = $objp->code_compta_client;
  416. $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
  417. $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  418. $thirdpartystatic->email = $objp->email;
  419. $thirdpartystatic->country_code = $objp->country_code;
  420. $productstatic->ref = $objp->product_ref;
  421. $productstatic->id = $objp->product_id;
  422. $productstatic->label = $objp->product_label;
  423. $productstatic->type = $objp->line_type;
  424. $productstatic->status = $objp->tosell;
  425. $productstatic->status_buy = $objp->tobuy;
  426. $productstatic->accountancy_code_sell = $objp->accountancy_code_sell;
  427. $productstatic->accountancy_code_sell_intra = $objp->accountancy_code_sell_intra;
  428. $productstatic->accountancy_code_sell_export = $objp->accountancy_code_sell_export;
  429. $accountingaccountstatic->rowid = $objp->fk_compte;
  430. $accountingaccountstatic->label = $objp->label_account;
  431. $accountingaccountstatic->labelshort = $objp->labelshort_account;
  432. $accountingaccountstatic->account_number = $objp->account_number;
  433. print '<tr class="oddeven">';
  434. // Line id
  435. print '<td>'.$objp->rowid.'</td>';
  436. // Ref Invoice
  437. print '<td class="nowraponall">'.$facturestatic->getNomUrl(1).'</td>';
  438. // Date invoice
  439. print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day').'</td>';
  440. // Ref Product
  441. print '<td class="tdoverflowmax100">';
  442. if ($productstatic->id > 0) {
  443. print $productstatic->getNomUrl(1);
  444. }
  445. if ($productstatic->id > 0 && $objp->product_label) {
  446. print '<br>';
  447. }
  448. if ($objp->product_label) {
  449. print '<span class="opacitymedium">'.$objp->product_label.'</span>';
  450. }
  451. print '</td>';
  452. print '<td class="tdoverflowonsmartphone">';
  453. $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
  454. $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
  455. print $form->textwithtooltip(dol_trunc($text, $trunclength), $objp->description);
  456. print '</td>';
  457. print '<td class="right nowraponall amount">'.price($objp->total_ht).'</td>';
  458. print '<td class="right">'.vatrate($objp->tva_tx.($objp->vat_src_code ? ' ('.$objp->vat_src_code.')' : '')).'</td>';
  459. // Thirdparty
  460. print '<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1, 'customer').'</td>';
  461. // Country
  462. print '<td>';
  463. if ($objp->country_code) {
  464. print $langs->trans("Country".$objp->country_code).' ('.$objp->country_code.')';
  465. }
  466. print '</td>';
  467. print '<td>'.$objp->tva_intra.'</td>';
  468. print '<td>';
  469. print $accountingaccountstatic->getNomUrl(0, 1, 1, '', 1);
  470. print ' <a class="editfielda" href="./card.php?id='.$objp->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($param ? '?'.$param : '')).'">';
  471. print img_edit();
  472. print '</a></td>';
  473. print '<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="'.$objp->rowid.'"/></td>';
  474. print '</tr>';
  475. $i++;
  476. }
  477. print '</table>';
  478. print "</div>";
  479. if ($nbtotalofrecords > $limit) {
  480. print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1);
  481. }
  482. print '</form>';
  483. } else {
  484. print $db->lasterror();
  485. }
  486. // End of page
  487. llxFooter();
  488. $db->close();