thirdparty_lettering_customer.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
  7. * Copyright (C) 2018-2020 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 <https://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.'/accountancy/class/accountingjournal.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("compta", "accountancy"));
  37. $action = GETPOST('action', 'aZ09');
  38. $massaction = GETPOST('massaction', 'alpha');
  39. $show_files = GETPOST('show_files', 'int');
  40. $confirm = GETPOST('confirm', 'alpha');
  41. $toselect = GETPOST('toselect', 'array');
  42. // $socid = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : GETPOST('id', 'int');
  43. // Security check
  44. $socid = GETPOSTINT("socid");
  45. // if ($user->socid) $socid=$user->socid;
  46. $limit = GETPOSTISSET('limit') ? GETPOST('limit', 'int') : $conf->liste_limit;
  47. $sortfield = GETPOST('sortfield', 'aZ09comma');
  48. $sortorder = GETPOST('sortorder', 'aZ09comma');
  49. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  50. if (empty($page) || $page == - 1) {
  51. $page = 0;
  52. } // If $page is not defined, or '' or -1
  53. $offset = $limit * $page;
  54. $pageprev = $page - 1;
  55. $pagenext = $page + 1;
  56. if ($sortorder == "") {
  57. $sortorder = "ASC";
  58. }
  59. if ($sortfield == "") {
  60. $sortfield = "bk.doc_date";
  61. }
  62. /*
  63. $search_date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
  64. $search_date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'));
  65. //$search_doc_type = GETPOST("search_doc_type", 'alpha');
  66. $search_doc_ref = GETPOST("search_doc_ref", 'alpha');
  67. */
  68. $lettering = GETPOST('lettering', 'alpha');
  69. if (!empty($lettering)) {
  70. $action = $lettering;
  71. }
  72. /*
  73. 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
  74. {
  75. $search_date_start = '';
  76. $search_date_end = '';
  77. //$search_doc_type = '';
  78. $search_doc_ref = '';
  79. }
  80. */
  81. $lettering = new Lettering($db);
  82. $object = new Societe($db);
  83. $object->id = $socid;
  84. $result = $object->fetch($socid);
  85. if ($result < 0) {
  86. setEventMessages($object->error, $object->errors, 'errors');
  87. }
  88. if (empty($conf->accounting->enabled)) {
  89. accessforbidden();
  90. }
  91. if ($user->socid > 0) {
  92. accessforbidden();
  93. }
  94. if (empty($user->rights->accounting->mouvements->lire)) {
  95. accessforbidden();
  96. }
  97. /*
  98. * Action
  99. */
  100. if ($action == 'lettering') {
  101. $result = $lettering->updateLettering($toselect);
  102. if ($result < 0) {
  103. setEventMessages('', $lettering->errors, 'errors');
  104. $error++;
  105. }
  106. }
  107. /*
  108. if ($action == 'autolettrage') {
  109. $result = $lettering->letteringThirdparty($socid);
  110. if ($result < 0) {
  111. setEventMessages('', $lettering->errors, 'errors');
  112. $error++;
  113. }
  114. }
  115. */
  116. /*
  117. * View
  118. */
  119. $form = new Form($db);
  120. $formaccounting = new FormAccounting($db);
  121. $title = $object->name." - ".$langs->trans('TabLetteringCustomer');
  122. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas|DE:Modul_Geschäftspartner';
  123. llxHeader('', $title, $help_url);
  124. $head = societe_prepare_head($object);
  125. dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
  126. print dol_get_fiche_head($head, 'lettering_customer', $langs->trans("ThirdParty"), 0, 'company');
  127. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  128. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', '', '', 0, '', '', 'arearefnobottom');
  129. print dol_get_fiche_end();
  130. $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, ";
  131. $sql .= " bk.subledger_account, bk.numero_compte , bk.label_compte, bk.debit, ";
  132. $sql .= " bk.credit, bk.montant, bk.sens, bk.code_journal, bk.piece_num, bk.lettering_code";
  133. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as bk";
  134. $sql .= " WHERE (bk.subledger_account = '".$db->escape($object->code_compta)."' AND bk.numero_compte = '".$db->escape($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER)."' )";
  135. /*
  136. if (dol_strlen($search_date_start) || dol_strlen($search_date_end)) {
  137. $sql .= " AND ( bk.doc_date BETWEEN '" . $db->idate($search_date_start) . "' AND '" . $db->idate($search_date_end) . "' )";
  138. }
  139. */
  140. $sql .= ' AND bk.entity IN ('.getEntity('accountingbookkeeping').')';
  141. $sql .= $db->order($sortfield, $sortorder);
  142. $debit = 0;
  143. $credit = 0;
  144. $solde = 0;
  145. // Count total nb of records and calc total sum
  146. $nbtotalofrecords = '';
  147. $resql = $db->query($sql);
  148. if (!$resql) {
  149. dol_print_error($db);
  150. exit();
  151. }
  152. $nbtotalofrecords = $db->num_rows($resql);
  153. while ($obj = $db->fetch_object($resql)) {
  154. $debit += $obj->debit;
  155. $credit += $obj->credit;
  156. $solde += ($obj->credit - $obj->debit);
  157. }
  158. $sql .= $db->plimit($limit + 1, $offset);
  159. dol_syslog("/accountancy/bookkeeping/thirdparty_lettering_customer.php", LOG_DEBUG);
  160. $resql = $db->query($sql);
  161. if (!$resql) {
  162. dol_print_error($db);
  163. exit();
  164. }
  165. $param = '';
  166. $param .= "&socid=".urlencode($socid);
  167. $num = $db->num_rows($resql);
  168. dol_syslog("/accountancy/bookkeeping/thirdparty_lettering_customer.php", LOG_DEBUG);
  169. if ($resql) {
  170. $i = 0;
  171. $param = "&socid=".$socid;
  172. print '<form name="add" action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="POST">';
  173. print '<input type="hidden" name="token" value="'.newToken().'">';
  174. print '<input type="hidden" name="socid" value="'.$object->id.'">';
  175. $letteringbutton = '<a class="divButAction"><span class="valignmiddle"><input class="butAction" type="submit" value="lettering" name="lettering" id="lettering"></span></a>';
  176. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, $letteringbutton, '', $limit);
  177. print '<div class="div-table-responsive-no-min">';
  178. print '<table class="liste centpercent">'."\n";
  179. /*
  180. print '<tr class="liste_titre">';
  181. //print '<td><input type="text" name="search_doc_type" value="' . $search_doc_type . '"></td>';
  182. // Date
  183. print '<td class="liste_titre center">';
  184. print '<div class="nowrap">';
  185. print $langs->trans('From') . ' ';
  186. print $form->selectDate($search_date_start, 'date_creation_start', 0, 0, 1);
  187. print '</div>';
  188. print '<div class="nowrap">';
  189. print $langs->trans('to') . ' ';
  190. print $form->selectDate($search_date_end, 'date_creation_end', 0, 0, 1);
  191. print '</div>';
  192. print '</td>';
  193. // Piece
  194. print '<td><input type="text" name="search_doc_ref" value="' . $search_doc_ref . '"></td>';
  195. print '<td colspan="6">&nbsp;</td>';
  196. print '<td class="right">';
  197. $searchpicto = $form->showFilterButtons();
  198. print $searchpicto;
  199. print '</td>';
  200. print '</tr>';
  201. */
  202. print '<tr class="liste_titre">';
  203. //print_liste_field_titre("Doctype", $_SERVER["PHP_SELF"], "bk.doc_type", "", $param, "", $sortfield, $sortorder);
  204. print_liste_field_titre("Docdate", $_SERVER["PHP_SELF"], "bk.doc_date", "", $param, "", $sortfield, $sortorder, 'center ');
  205. print_liste_field_titre("Piece", $_SERVER["PHP_SELF"], "bk.doc_ref", "", $param, "", $sortfield, $sortorder);
  206. print_liste_field_titre("LabelAccount", $_SERVER["PHP_SELF"], "bk.label_compte", "", $param, "", $sortfield, $sortorder);
  207. print_liste_field_titre("Debit", $_SERVER["PHP_SELF"], "bk.debit", "", $param, "", $sortfield, $sortorder);
  208. print_liste_field_titre("Credit", $_SERVER["PHP_SELF"], "bk.credit", "", $param, "", $sortfield, $sortorder);
  209. print_liste_field_titre("Balancing", $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder);
  210. print_liste_field_titre("Codejournal", $_SERVER["PHP_SELF"], "bk.code_journal", "", $param, "", $sortfield, $sortorder, 'center ');
  211. print_liste_field_titre("LetteringCode", $_SERVER["PHP_SELF"], "bk.lettering_code", "", $param, "", $sortfield, $sortorder, 'center ');
  212. print_liste_field_titre("", "", "", '', '', "", $sortfield, $sortorder, 'maxwidthsearch center ');
  213. print "</tr>\n";
  214. $solde = 0;
  215. $tmp = '';
  216. while ($obj = $db->fetch_object($resql)) {
  217. if ($tmp != $obj->lettering_code || empty($tmp)) {
  218. $tmp = $obj->lettering_code;
  219. }
  220. /*if ($tmp != $obj->lettering_code || empty($obj->lettering_code))*/ $solde += ($obj->credit - $obj->debit);
  221. print '<tr class="oddeven">';
  222. //print '<td>' . $obj->doc_type . '</td>' . "\n";
  223. print '<td class="center">'.dol_print_date($db->jdate($obj->doc_date), 'day').'</td>';
  224. print '<td>'.$obj->doc_ref.'</td>';
  225. print '<td>'.$obj->label_compte.'</td>';
  226. print '<td class="nowrap right">'.price($obj->debit).'</td>';
  227. print '<td class="nowrap right">'.price($obj->credit).'</td>';
  228. print '<td class="nowrap right">'.price(round($solde, 2)).'</td>';
  229. // Journal
  230. $accountingjournal = new AccountingJournal($db);
  231. $result = $accountingjournal->fetch('', $obj->code_journal);
  232. $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $obj->code_journal);
  233. print '<td class="center">'.$journaltoshow.'</td>';
  234. if (empty($obj->lettering_code) && empty($obj->date_validated)) {
  235. print '<td class="nowrap center"><input type="checkbox" class="flat checkforselect" name="toselect[]" id="toselect[]" value="'.$obj->rowid.'" /></td>';
  236. print '<td><a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?piece_num='.$obj->piece_num.'">';
  237. print img_edit();
  238. print '</a></td>'."\n";
  239. } else {
  240. print '<td class="center">'.$obj->lettering_code.'</td>';
  241. print '<td></td>';
  242. }
  243. print "</tr>\n";
  244. }
  245. print '<tr class="oddeven">';
  246. print '<td class="right" colspan="3">'.$langs->trans("Total").':</td>'."\n";
  247. print '<td class="right nowraponall amount"><strong>'.price($debit).'</strong></td>';
  248. print '<td class="right nowraponall amount"><strong>'.price($credit).'</strong></td>';
  249. print '<td colspan="4"></td>';
  250. print "</tr>\n";
  251. print '<tr class="oddeven">';
  252. print '<td class="right" colspan="3">'.$langs->trans("Balancing").':</td>'."\n";
  253. print '<td colspan="2">&nbsp;</td>';
  254. print '<td class="right nowraponall amount"><strong>'.price($credit - $debit).'</strong></td>';
  255. print '<td colspan="6"></td>';
  256. print "</tr>\n";
  257. print "</table>";
  258. print '<div class="tabsAction tabsActionNoBottom">'."\n";
  259. print $letteringbutton;
  260. print '</div>';
  261. print "</form>";
  262. $db->free($resql);
  263. } else {
  264. dol_print_error($db);
  265. }
  266. // End of page
  267. llxFooter();
  268. $db->close();