lines.php 25 KB

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