thirdparty_lettering_customer.php 11 KB

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