lines.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  4. * Copyright (C) 2014-2015 Ari Elbaz (elarifr) <github@accedinfo.com>
  5. * Copyright (C) 2014 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 Accounting Expert
  25. * \brief Page of detail of the lines of ventilation of invoices customers
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  31. $langs->load("bills");
  32. $langs->load("compta");
  33. $langs->load("main");
  34. $langs->load("accountancy");
  35. $account_parent = GETPOST('account_parent');
  36. $changeaccount = GETPOST('changeaccount');
  37. $search_ref = GETPOST('search_ref','alpha');
  38. $search_invoice = GETPOST('search_invoice','alpha');
  39. $search_label = GETPOST('search_label','alpha');
  40. $search_desc = GETPOST('search_desc','alpha');
  41. $search_amount = GETPOST('search_amount','alpha');
  42. $search_account = GETPOST('search_account','alpha');
  43. $sortfield = GETPOST('sortfield','alpha');
  44. $sortorder = GETPOST('sortorder','alpha');
  45. $page = GETPOST('page','int');
  46. //if ($page == -1) { $page = 0; }
  47. if ($page < 0) $page = 0;
  48. $pageprev = $page - 1;
  49. $pagenext = $page + 1;
  50. //$limit = $conf->liste_limit;
  51. if (! empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)) {
  52. $limit = $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION;
  53. } else if ($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION <= 0) {
  54. $limit = $conf->liste_limit;
  55. } else {
  56. $limit = $conf->liste_limit;
  57. }
  58. //$offset = $conf->liste_limit * $page;
  59. $offset = $limit * $page;
  60. // TODO : remove comment
  61. //elarifr we can not use only
  62. //$sql .= " ORDER BY l.rowid";
  63. // f.datef will order like FA08 FA09 FA10 FA05 FA06 FA07 FA04...
  64. // f.facnumber will not order properly invoice / avoir / accompte you can have All AC then All AV and all FA
  65. // l.rowid when an invoice is edited rowid are added at end of table & facturedet.rowid are not ordered
  66. //if (! $sortfield) $sortfield="f.facnumber";
  67. if (! $sortfield) $sortfield="f.datef, f.facnumber, l.rowid";
  68. //if (! $sortorder) $sortorder="DESC";
  69. if (! $sortorder) {
  70. if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE > 0) {
  71. $sortorder = " DESC ";
  72. }
  73. }
  74. // Security check
  75. if ($user->societe_id > 0)
  76. accessforbidden();
  77. if (! $user->rights->accounting->ventilation->dispatch)
  78. accessforbidden();
  79. $formventilation = new FormVentilation($db);
  80. // Purge search criteria
  81. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
  82. {
  83. $search_ref='';
  84. $search_invoice='';
  85. $search_label='';
  86. $search_desc='';
  87. $search_amount='';
  88. $search_account='';
  89. }
  90. if (is_array($changeaccount) && count($changeaccount) > 0) {
  91. $error = 0;
  92. $db->begin();
  93. $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as l";
  94. $sql1 .= " SET l.fk_code_ventilation=" . $account_parent;
  95. $sql1 .= ' WHERE l.rowid IN (' . implode(',', $changeaccount) . ')';
  96. dol_syslog('accountancy/customer/lines.php::changeaccount sql= ' . $sql1);
  97. $resql1 = $db->query($sql1);
  98. if (! $resql1) {
  99. $error ++;
  100. setEventMessage($db->lasterror(), 'errors');
  101. }
  102. if (! $error) {
  103. $db->commit();
  104. setEventMessage($langs->trans('Save'), 'mesgs');
  105. } else {
  106. $db->rollback();
  107. setEventMessage($db->lasterror(), 'errors');
  108. }
  109. }
  110. /*
  111. * View
  112. */
  113. llxHeader('', $langs->trans("CustomersVentilation") . ' - ' . $langs->trans("Dispatched"));
  114. print '<script type="text/javascript">
  115. $(function () {
  116. $(\'#select-all\').click(function(event) {
  117. // Iterate each checkbox
  118. $(\':checkbox\').each(function() {
  119. this.checked = true;
  120. });
  121. });
  122. $(\'#unselect-all\').click(function(event) {
  123. // Iterate each checkbox
  124. $(\':checkbox\').each(function() {
  125. this.checked = false;
  126. });
  127. });
  128. });
  129. </script>';
  130. /*
  131. * Action
  132. */
  133. /*
  134. * Customer Invoice lines
  135. */
  136. $sql = "SELECT l.rowid , f.facnumber, f.rowid as facid, l.fk_product, l.description, l.total_ht, l.qty, l.tva_tx, l.fk_code_ventilation, aa.label, aa.account_number,";
  137. $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type";
  138. $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f";
  139. $sql .= " , " . MAIN_DB_PREFIX . "accountingaccount as aa";
  140. $sql .= " , " . MAIN_DB_PREFIX . "facturedet as l";
  141. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
  142. $sql .= " WHERE f.rowid = l.fk_facture AND f.fk_statut >= 1 AND l.fk_code_ventilation <> 0 ";
  143. $sql .= " AND aa.rowid = l.fk_code_ventilation";
  144. if (strlen(trim($search_invoice))) {
  145. $sql .= " AND f.facnumber like '%" . $search_invoice . "%'";
  146. }
  147. if (strlen(trim($search_ref))) {
  148. $sql .= " AND p.ref like '%" . $search_ref . "%'";
  149. }
  150. if (strlen(trim($search_label))) {
  151. $sql .= " AND p.label like '%" . $search_label . "%'";
  152. }
  153. if (strlen(trim($search_desc))) {
  154. $sql .= " AND l.description like '%" . $search_desc . "%'";
  155. }
  156. if (strlen(trim($search_amount))) {
  157. $sql .= " AND l.total_ht like '%" . $search_amount . "%'";
  158. }
  159. if (strlen(trim($search_account))) {
  160. $sql .= " AND aa.account_number like '%" . $search_account . "%'";
  161. }
  162. if (! empty($conf->multicompany->enabled)) {
  163. $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")";
  164. }
  165. $sql.= $db->order($sortfield,$sortorder);
  166. $sql.= $db->plimit($limit + 1,$offset);
  167. dol_syslog("/accountancy/customer/lines.php sql=" . $sql, LOG_DEBUG);
  168. $result = $db->query($sql);
  169. if ($result) {
  170. $num_lines = $db->num_rows($result);
  171. $i = 0;
  172. print_barre_liste($langs->trans("InvoiceLinesDone"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num_lines);
  173. print '<td align="left"><b>' . $langs->trans("DescVentilDoneCustomer") . '</b></td>';
  174. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
  175. print '<table class="noborder" width="100%">';
  176. print '<br><div class="inline-block divButAction">' . $langs->trans("ChangeAccount") . '<br>';
  177. print $formventilation->select_account($account_parent, 'account_parent', 1);
  178. print '<input type="submit" class="butAction" value="' . $langs->trans("Validate") . '"/></div>';
  179. print '<tr class="liste_titre">';
  180. print_liste_field_titre($langs->trans("Invoice"), $_SERVER["PHP_SELF"],"f.facnumber","",$param,'',$sortfield,$sortorder);
  181. print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"],"p.ref","",$param,'',$sortfield,$sortorder);
  182. print_liste_field_titre($langs->trans("Label"), $_SERVER["PHP_SELF"],"p.label","",$param,'',$sortfield,$sortorder);
  183. print_liste_field_titre($langs->trans("Description"), $_SERVER["PHP_SELF"],"l.description","",$param,'',$sortfield,$sortorder);
  184. print_liste_field_titre($langs->trans("Amount"), $_SERVER["PHP_SELF"],"l.total_ht","",$param,'align="center"',$sortfield,$sortorder);
  185. print_liste_field_titre($langs->trans("Account"), $_SERVER["PHP_SELF"],"aa.account_number","",$param,'align="center"',$sortfield,$sortorder);
  186. print_liste_field_titre('');
  187. print_liste_field_titre('');
  188. print_liste_field_titre($langs->trans("Ventilate").'<br><label id="select-all">'.$langs->trans('All').'</label>/<label id="unselect-all">'.$langs->trans('None').'</label>','','','','','align="center"');
  189. print "</tr>\n";
  190. print '<tr class="liste_titre">';
  191. print '<td class="liste_titre"><input type="text" class="flat" name="search_invoice" size="10" value="' . $search_invoice . '"></td>';
  192. print '<td class="liste_titre"><input type="text" class="flat" size="15" name="search_ref" value="' . $search_ref . '"></td>';
  193. print '<td class="liste_titre"><input type="text" class="flat" size="15" name="search_label" value="' . $search_label . '"></td>';
  194. print '<td class="liste_titre"><input type="text" class="flat" size="15" name="search_desc" value="' . $search_desc . '"></td>';
  195. print '<td class="liste_titre" align="center"><input type="text" class="flat" size="8" name="search_amount" value="' . $search_amount. '"></td>';
  196. print '<td class="liste_titre" align="center"><input type="text" class="flat" size="15" name="search_account" value="' . $search_account . '"></td>';
  197. print '<td class="liste_titre" colspan="2">&nbsp;</td>';
  198. print '<td class="liste_titre" align="center"><input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  199. print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"),'searchclear.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
  200. print "</td></tr>\n";
  201. $facture_static = new Facture($db);
  202. $product_static = new Product($db);
  203. $var = True;
  204. while ( $objp = $db->fetch_object($result) ) {
  205. $var = ! $var;
  206. $codecompta = $objp->account_number . ' ' . $objp->label;
  207. print "<tr $bc[$var]>";
  208. // Ref Invoice
  209. $facture_static->ref = $objp->facnumber;
  210. $facture_static->id = $objp->facid;
  211. print '<td>' . $facture_static->getNomUrl(1) . '</td>';
  212. // Ref Product
  213. $product_static->ref = $objp->product_ref;
  214. $product_static->id = $objp->product_id;
  215. $product_static->type = $objp->type;
  216. print '<td>';
  217. if ($product_static->id)
  218. print $product_static->getNomUrl(1);
  219. else
  220. print '&nbsp;';
  221. print '</td>';
  222. print '<td>' . dol_trunc($objp->product_label, 24) . '</td>';
  223. print '<td>' . nl2br(dol_trunc($objp->description, 32)) . '</td>';
  224. print '<td align="right">' . price($objp->total_ht) . '</td>';
  225. print '<td align="center">' . $codecompta . '</td>';
  226. print '<td align="right">' . $objp->rowid . '</td>';
  227. print '<td align="left"><a href="./card.php?id=' . $objp->rowid . '">';
  228. print img_edit();
  229. print '</a></td>';
  230. print '<td align="center"><input type="checkbox" name="changeaccount[]" value="' . $objp->rowid . '"/></td>';
  231. print "</tr>";
  232. $i ++;
  233. }
  234. } else {
  235. print $db->error();
  236. }
  237. print "</table></form>";
  238. llxFooter();
  239. $db->close();