thirdparty_lettering_supplier.php 12 KB

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