lines.php 24 KB

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