lines.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <?php
  2. /* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  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 <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/accountancy/supplier/lines.php
  23. * \ingroup Advanced accountancy
  24. * \brief Page of detail of the lines of ventilation of invoices suppliers
  25. */
  26. require '../../main.inc.php';
  27. // Class
  28. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  29. require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  31. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  32. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  33. // Langs
  34. $langs->load("compta");
  35. $langs->load("bills");
  36. $langs->load("other");
  37. $langs->load("main");
  38. $langs->load("accountancy");
  39. $langs->load("productbatch");
  40. $account_parent = GETPOST('account_parent');
  41. $changeaccount = GETPOST('changeaccount');
  42. // Search Getpost
  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. // Load variable for pagination
  52. $limit = GETPOST('limit') ? GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  53. $sortfield = GETPOST('sortfield', 'alpha');
  54. $sortorder = GETPOST('sortorder', 'alpha');
  55. $page = GETPOST('page', 'int');
  56. if ($page < 0) $page = 0;
  57. $offset = $conf->liste_limit * $page;
  58. $pageprev = $page - 1;
  59. $pagenext = $page + 1;
  60. if (! $sortfield)
  61. $sortfield = "f.datef, f.ref, l.rowid";
  62. if (! $sortorder) {
  63. if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE > 0) {
  64. $sortorder = "DESC";
  65. }
  66. }
  67. // Security check
  68. if ($user->societe_id > 0)
  69. accessforbidden();
  70. if (! $user->rights->accounting->bind->write)
  71. accessforbidden();
  72. $formaccounting = new FormAccounting($db);
  73. /*
  74. * Actions
  75. */
  76. // Purge search criteria
  77. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers
  78. {
  79. $search_lineid = '';
  80. $search_ref = '';
  81. $search_invoice = '';
  82. $search_label = '';
  83. $search_desc = '';
  84. $search_amount = '';
  85. $search_account = '';
  86. $search_vat = '';
  87. }
  88. if (is_array($changeaccount) && count($changeaccount) > 0) {
  89. $error = 0;
  90. $db->begin();
  91. $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as l";
  92. $sql1 .= " SET l.fk_code_ventilation=" . GETPOST('account_parent');
  93. $sql1 .= ' WHERE l.rowid IN (' . implode(',', $changeaccount) . ')';
  94. dol_syslog('accountancy/supplier/lines.php::changeaccount sql= ' . $sql1);
  95. $resql1 = $db->query($sql1);
  96. if (! $resql1) {
  97. $error ++;
  98. setEventMessages($db->lasterror(), null, 'errors');
  99. }
  100. if (! $error) {
  101. $db->commit();
  102. setEventMessages($langs->trans('Save'), null, 'mesgs');
  103. } else {
  104. $db->rollback();
  105. setEventMessages($db->lasterror(), null, 'errors');
  106. }
  107. $account_parent = ''; // Protection to avoid to mass apply it a second time
  108. }
  109. /*
  110. * View
  111. */
  112. llxHeader('', $langs->trans("SuppliersVentilation") . ' - ' . $langs->trans("Dispatched"));
  113. print '<script type="text/javascript">
  114. $(function () {
  115. $(\'#select-all\').click(function(event) {
  116. // Iterate each checkbox
  117. $(\':checkbox\').each(function() {
  118. this.checked = true;
  119. });
  120. });
  121. $(\'#unselect-all\').click(function(event) {
  122. // Iterate each checkbox
  123. $(\':checkbox\').each(function() {
  124. this.checked = false;
  125. });
  126. });
  127. });
  128. </script>';
  129. /*
  130. * Supplier Invoice lines
  131. */
  132. $sql = "SELECT f.rowid as facid, f.ref as facnumber, f.ref_supplier, f.libelle as invoice_label, f.datef,";
  133. $sql.= " l.rowid, l.fk_product, l.description, l.total_ht , l.qty, l.tva_tx, aa.label, aa.account_number, ";
  134. $sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type";
  135. $sql.= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f";
  136. $sql.= " , " . MAIN_DB_PREFIX . "accounting_account as aa";
  137. $sql.= " , " . MAIN_DB_PREFIX . "facture_fourn_det as l";
  138. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
  139. $sql.= " WHERE f.rowid = l.fk_facture_fourn and f.fk_statut >= 1 AND l.fk_code_ventilation <> 0 ";
  140. $sql.= " AND aa.rowid = l.fk_code_ventilation";
  141. if ($search_lineid) {
  142. $sql .= natural_search("l.rowid", $search_lineid, 1);
  143. }
  144. if (strlen(trim($search_invoice))) {
  145. $sql .= natural_search("f.ref", $search_invoice);
  146. }
  147. if (strlen(trim($search_ref))) {
  148. $sql .= natural_search("p.ref", $search_ref);
  149. }
  150. if (strlen(trim($search_label))) {
  151. $sql .= natural_search("p.label", $search_label);
  152. }
  153. if (strlen(trim($search_desc))) {
  154. $sql .= natural_search("l.description", $search_desc);
  155. }
  156. if (strlen(trim($search_amount))) {
  157. $sql .= natural_search("l.total_ht", $search_amount, 1);
  158. }
  159. if (strlen(trim($search_account))) {
  160. $sql .= natural_search("aa.account_number", $search_account, 1);
  161. }
  162. if (strlen(trim($search_vat))) {
  163. $sql .= natural_search("l.tva_tx", $search_vat, 1);
  164. }
  165. $sql .= " AND f.entity IN (" . getEntity("facture_fourn", 0) . ")"; // We don't share object for accountancy
  166. $sql .= $db->order($sortfield, $sortorder);
  167. // Count total nb of records
  168. $nbtotalofrecords = '';
  169. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  170. {
  171. $result = $db->query($sql);
  172. $nbtotalofrecords = $db->num_rows($result);
  173. }
  174. $sql .= $db->plimit($limit + 1, $offset);
  175. dol_syslog('accountancy/supplier/lines.php::list');
  176. $result = $db->query($sql);
  177. if ($result) {
  178. $num_lines = $db->num_rows($result);
  179. $i = 0;
  180. $param='';
  181. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  182. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  183. if ($search_invoice)
  184. $param .= "&search_invoice=" . $search_invoice;
  185. if ($search_ref)
  186. $param .= "&search_ref=" . $search_ref;
  187. if ($search_label)
  188. $param .= "&search_label=" . $search_label;
  189. if ($search_desc)
  190. $param .= "&search_desc=" . $search_desc;
  191. if ($search_account)
  192. $param .= "&search_account=" . $search_account;
  193. if ($search_vat)
  194. $param .= "&search_vat=" . $search_vat;
  195. if ($search_country)
  196. $param .= "&search_country=" . $search_country;
  197. if ($search_tvaintra)
  198. $param .= "&search_tvaintra=" . $search_tvaintra;
  199. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">' . "\n";
  200. print '<input type="hidden" name="action" value="ventil">';
  201. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  202. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  203. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  204. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  205. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  206. print '<input type="hidden" name="page" value="'.$page.'">';
  207. print_barre_liste($langs->trans("InvoiceLinesDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
  208. print $langs->trans("DescVentilDoneSupplier") . '<br>';
  209. print '<br><div class="inline-block divButAction">' . $langs->trans("ChangeAccount") . '<br>';
  210. print $formaccounting->select_account(GETPOST('account_parent'), 'account_parent', 1);
  211. print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("ChangeBinding") . '" /></div>';
  212. $moreforfilter = '';
  213. print '<div class="div-table-responsive">';
  214. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  215. print '<tr class="liste_titre_filter">';
  216. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_lineid" value="' . dol_escape_htmltag($search_lineid) . '""></td>';
  217. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>';
  218. print '<td class="liste_titre"></td>';
  219. print '<td class="liste_titre"></td>';
  220. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="' . dol_escape_htmltag($search_ref) . '"></td>';
  221. //print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
  222. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>';
  223. print '<td class="liste_titre" align="right"><input type="text" class="right flat maxwidth50" name="search_amount" value="' . dol_escape_htmltag($search_amount) . '"></td>';
  224. print '<td class="liste_titre" align="center"><input type="text" class="right flat maxwidth50" name="search_vat" placeholder="%" size="1" value="' . dol_escape_htmltag($search_vat) . '"></td>';
  225. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_account" value="' . dol_escape_htmltag($search_account) . '"></td>';
  226. print '<td class="liste_titre" align="center">';
  227. $searchpicto=$form->showFilterButtons();
  228. print $searchpicto;
  229. print '</td>';
  230. print "</tr>\n";
  231. print '<tr class="liste_titre">';
  232. print_liste_field_titre($langs->trans("LineId"), $_SERVER["PHP_SELF"], "l.rowid", "", $param, '', $sortfield, $sortorder);
  233. print_liste_field_titre($langs->trans("Invoice"), $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
  234. print_liste_field_titre($langs->trans("InvoiceLabel"), $_SERVER["PHP_SELF"], "f.libelle", "", $param, '', $sortfield, $sortorder);
  235. print_liste_field_titre($langs->trans("Date"), $_SERVER["PHP_SELF"], "f.datef, f.ref, l.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
  236. print_liste_field_titre($langs->trans("ProductRef"), $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
  237. //print_liste_field_titre($langs->trans("ProductLabel"), $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
  238. print_liste_field_titre($langs->trans("Description"), $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder);
  239. print_liste_field_titre($langs->trans("Amount"), $_SERVER["PHP_SELF"], "l.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
  240. print_liste_field_titre($langs->trans("VATRate"), $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, 'align="center"', $sortfield, $sortorder);
  241. print_liste_field_titre($langs->trans("Account"), $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
  242. $checkpicto=$form->showCheckAddButtons();
  243. print_liste_field_titre($checkpicto, '', '', '', '', 'align="center"');
  244. print "</tr>\n";
  245. $facturefournisseur_static = new FactureFournisseur($db);
  246. $product_static = new Product($db);
  247. while ($i < min($num_lines, $limit)) {
  248. $objp = $db->fetch_object($result);
  249. $codecompta = length_accountg($objp->account_number) . ' - ' . $objp->label;
  250. $facturefournisseur_static->ref = $objp->facnumber;
  251. $facturefournisseur_static->id = $objp->facid;
  252. $product_static->ref = $objp->product_ref;
  253. $product_static->id = $objp->product_id;
  254. $product_static->type = $objp->type;
  255. $product_static->label = $objp->product_label;
  256. print '<tr class="oddeven">';
  257. print '<td>' . $objp->rowid . '</td>';
  258. // Ref Invoice
  259. print '<td>' . $facturefournisseur_static->getNomUrl(1) . '</td>';
  260. print '<td>';
  261. print $objp->invoice_label;
  262. print '</td>';
  263. print '<td align="center">' . dol_print_date($db->jdate($objp->datef), 'day') . '</td>';
  264. // Ref Product
  265. print '<td>';
  266. if ($product_static->id)
  267. print $product_static->getNomUrl(1);
  268. if ($objp->product_label) print '<br>'.$objp->product_label;
  269. print '</td>';
  270. print '<td>';
  271. $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
  272. $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32;
  273. print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->description);
  274. print '</td>';
  275. print '<td align="right">' . price($objp->total_ht) . '</td>';
  276. print '<td align="center">' . price($objp->tva_tx) . '</td>';
  277. print '<td align="left">';
  278. print $codecompta . ' <a href="./card.php?id=' . $objp->rowid . '">';
  279. print img_edit();
  280. print '</a></td>';
  281. print '<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="' . $objp->rowid . '"/></td>';
  282. print "</tr>";
  283. $i ++;
  284. }
  285. print "</table>";
  286. print "</div>";
  287. if ($nbtotalofrecords > $limit) {
  288. print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1);
  289. }
  290. print '</form>';
  291. } else {
  292. print $db->error();
  293. }
  294. llxFooter();
  295. $db->close();