thirdparty_lettering_supplier.php 11 KB

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