lines.php 15 KB

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