thirdparty_lettering_customer.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2013 Olivier Geffroy <jeff@jeffinfo.com>
  5. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2013-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
  7. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. /**
  24. * \file htdocs/accountancy/bookkeeping/thirdparty_lettering_customer.php
  25. * \ingroup accountancy
  26. * \brief Tab to manage customer lettering
  27. */
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
  31. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
  33. require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("compta","accountancy"));
  36. $action = GETPOST('action', 'aZ09');
  37. $massaction = GETPOST('massaction', 'alpha');
  38. $show_files = GETPOST('show_files', 'int');
  39. $confirm = GETPOST('confirm', 'alpha');
  40. $toselect = GETPOST('toselect', 'array');
  41. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  42. $sortfield = GETPOST("sortfield", 'alpha');
  43. $sortorder = GETPOST("sortorder", 'alpha');
  44. $page = GETPOST("page", 'int');
  45. if (empty($page) || $page == - 1) {
  46. $page = 0;
  47. } // If $page is not defined, or '' or -1
  48. $offset = $limit * $page;
  49. $pageprev = $page - 1;
  50. $pagenext = $page + 1;
  51. if ($sortorder == "")
  52. $sortorder = "DESC";
  53. if ($sortfield == "")
  54. $sortfield = "bk.doc_date";
  55. $search_year = GETPOST("search_year", 'int');
  56. $search_doc_type = GETPOST("search_doc_type", 'alpha');
  57. $search_doc_ref = GETPOST("search_doc_ref", 'alpha');
  58. $lettering = GETPOST('lettering', 'alpha');
  59. if (! empty($lettering)) {
  60. $action = $lettering;
  61. }
  62. // Did we click on purge search criteria ?
  63. // All tests are required to be compatible with all browsers
  64. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  65. $search_year = '';
  66. $search_doc_type = '';
  67. $search_doc_ref = '';
  68. }
  69. // Security check
  70. $socid = GETPOST("socid", 'int');
  71. // if ($user->societe_id) $socid=$user->societe_id;
  72. $lettering = new Lettering($db);
  73. $object = new Societe($db);
  74. $object->id = $socid;
  75. $result = $object->fetch($socid);
  76. if ($result < 0)
  77. {
  78. setEventMessages($object->error, $object->errors, 'errors');
  79. }
  80. /*
  81. * Action
  82. */
  83. if ($action == 'lettering') {
  84. $result = $lettering->updateLettering($toselect);
  85. if ($result < 0) {
  86. setEventMessages('', $lettering->errors, 'errors');
  87. $error++;
  88. }
  89. }
  90. if ($action == 'autolettrage') {
  91. $result = $lettering->letteringThirdparty($socid);
  92. if ($result < 0) {
  93. setEventMessages('', $lettering->errors, 'errors');
  94. $error++;
  95. }
  96. }
  97. /*
  98. * View
  99. */
  100. $form = new Form($db);
  101. $formaccounting = new FormAccounting($db);
  102. $title=$object->name." - ".$langs->trans('TabLetteringCustomer');
  103. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  104. llxHeader('',$title,$help_url);
  105. $head = societe_prepare_head($object);
  106. dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
  107. dol_fiche_head($head, 'lettering_customer', $langs->trans("ThirdParty"), 0, 'company');
  108. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  109. dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom', '', '', 0, '', '', 'arearefnobottom');
  110. dol_fiche_end();
  111. print '<br>';
  112. $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, ";
  113. $sql .= " bk.subledger_account, bk.numero_compte , bk.label_compte, bk.debit, ";
  114. $sql .= " bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering_code ";
  115. $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk";
  116. $sql .= " WHERE (bk.subledger_account = '" . $object->code_compta . "' AND bk.numero_compte = '" . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . "' )";
  117. if (dol_strlen($search_year)) {
  118. $date_start = dol_mktime(0, 0, 0, 1, 1, $search_year);
  119. $date_end = dol_mktime(23, 59, 59, 12, 31, $search_year);
  120. $sql .= " AND ( bk.doc_date BETWEEN '" . $db->idate($date_start) . "' AND '" . $db->idate($date_end) . "' )";
  121. }
  122. $sql .= $db->order($sortfield, $sortorder);
  123. $debit = 0;
  124. $credit = 0;
  125. $solde = 0;
  126. // Count total nb of records and calc total sum
  127. $nbtotalofrecords = '';
  128. $resql = $db->query($sql);
  129. if (! $resql) {
  130. dol_print_error($db);
  131. exit();
  132. }
  133. $nbtotalofrecords = $db->num_rows($resql);
  134. while ( $obj = $db->fetch_object($resql) ) {
  135. $debit += $obj->debit;
  136. $credit += $obj->credit;
  137. $solde += ($obj->credit - $obj->debit);
  138. }
  139. $sql .= $db->plimit($limit + 1, $offset);
  140. dol_syslog("/accountancy/bookkeeping/thirdparty_lettering_customer.php", LOG_DEBUG);
  141. $resql = $db->query($sql);
  142. if (! $resql) {
  143. dol_print_error($db);
  144. exit();
  145. }
  146. $num = $db->num_rows($resql);
  147. dol_syslog("/accountancy/bookkeeping/thirdparty_lettering_customer.php", LOG_DEBUG);
  148. if ($resql) {
  149. $i = 0;
  150. print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '" method="POST">';
  151. print '<input type="hidden" name="socid" value="' . $object->id . '">';
  152. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
  153. print "<table class=\"noborder\" width=\"100%\">";
  154. print '<tr class="liste_titre">';
  155. print_liste_field_titre("Doctype", $_SERVER["PHP_SELF"], "bk.doc_type", "", $param, "", $sortfield, $sortorder);
  156. print_liste_field_titre("Docdate", $_SERVER["PHP_SELF"], "bk.doc_date", "", $param, "", $sortfield, $sortorder);
  157. print_liste_field_titre("Docref", $_SERVER["PHP_SELF"], "bk.doc_ref", "", $param, "", $sortfield, $sortorder);
  158. print_liste_field_titre("LabelAccount", $_SERVER["PHP_SELF"], "bk.label_compte", "", $param, "", $sortfield, $sortorder);
  159. print_liste_field_titre("Debit", $_SERVER["PHP_SELF"], "bk.debit", "", $param, "", $sortfield, $sortorder);
  160. print_liste_field_titre("Credit", $_SERVER["PHP_SELF"], "bk.credit", "", $param, "", $sortfield, $sortorder);
  161. print_liste_field_titre("Balancing", $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder);
  162. print_liste_field_titre("Codejournal", $_SERVER["PHP_SELF"], "bk.code_journal", "", $param, "", $sortfield, $sortorder);
  163. print_liste_field_titre("LetteringCode", $_SERVER["PHP_SELF"], "bk.lettering_code", "", $param, "", $sortfield, $sortorder);
  164. print "</tr>\n";
  165. print '<tr class="liste_titre">';
  166. print '<td><input type="text" name="search_doc_type" value="' . $search_doc_type . '"></td>';
  167. print '<td><input type="text" name="search_year" value="' . $search_year . '"></td>';
  168. print '<td><input type="text" name="search_doc_refe" value="' . $search_doc_ref . '"></td>';
  169. print '<td colspan="5">&nbsp;</td>';
  170. print '<td class="right">';
  171. $searchpicto = $form->showFilterButtons();
  172. print $searchpicto;
  173. print '</td>';
  174. print '</tr>';
  175. $solde = 0;
  176. $tmp = '';
  177. while ( $obj = $db->fetch_object($resql) ) {
  178. if ($tmp != $obj->lettering_code || empty($tmp)) $tmp = $obj->lettering_code;
  179. /*if ($tmp != $obj->lettering_code || empty($obj->lettering_code))*/ $solde += ($obj->credit - $obj->debit);
  180. print '<tr class="oddeven">';
  181. if (empty($obj->lettering_code)) {
  182. print '<td><a href="' . dol_buildpath('/accountancy/bookkeeping/card.php', 1) . '?piece_num=' . $obj->piece_num . '">';
  183. print img_edit();
  184. print '</a>&nbsp;' . $obj->doc_type . '</td>' . "\n";
  185. } else {
  186. print '<td>' . $obj->doc_type . '</td>' . "\n";
  187. }
  188. print '<td>' . dol_print_date($db->jdate($obj->doc_date), 'day') . '</td>';
  189. print '<td>' . $obj->doc_ref . '</td>';
  190. print '<td>' . $obj->label_compte . '</td>';
  191. print '<td class="right">' . price($obj->debit) . '</td>';
  192. print '<td class="right">' . price($obj->credit) . '</td>';
  193. print '<td class="right">' . price(round($solde, 2)) . '</td>';
  194. print '<td align="center">' . $obj->code_journal . '</td>';
  195. if (empty($obj->lettering_code)) {
  196. print '<td class="nowrap" align="center"><input type="checkbox" class="flat checkforselect" name="toselect[]" id="toselect[]" value="' . $obj->rowid . '" /></td>';
  197. } else
  198. print '<td align="center">' . $obj->lettering_code . '</td>';
  199. print "</tr>\n";
  200. }
  201. print '<tr class="oddeven">';
  202. print '<td align="right" colspan="4">'.$langs->trans("Total").':</td>' . "\n";
  203. print '<td class="right"><strong>' . price($debit) . '</strong></td>';
  204. print '<td class="right"><strong>' . price($credit) . '</strong></td>';
  205. print '<td colspan="5"></td>';
  206. print "</tr>\n";
  207. print '<tr class="oddeven">';
  208. print '<td class="right" colspan="4">'.$langs->trans("Balancing").':</td>' . "\n";
  209. print '<td colspan="2">&nbsp;</td>';
  210. print '<td class="right"><strong>' . price($credit - $debit) . '</strong></td>';
  211. print '<td colspan="3"></td>';
  212. print "</tr>\n";
  213. print "</table>";
  214. print '<input class="butAction" type="submit" value="lettering" name="lettering" id="lettering">';
  215. //print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '&action=autolettering">' . $langs->trans('AccountancyAutoLettering') . '</a>';
  216. print "</form>";
  217. $db->free($resql);
  218. } else {
  219. dol_print_error($db);
  220. }
  221. // End of page
  222. llxFooter();
  223. $db->close();