thirdparty_lettering_supplier.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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_lettrage_supplier.php
  25. * \ingroup Advanced accountancy
  26. * \brief Tab to setup 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. {
  66. $search_year='';
  67. $search_doc_type='';
  68. $search_doc_ref='';
  69. }
  70. // Security check
  71. $socid = GETPOST("socid", 'int');
  72. // if ($user->societe_id) $socid=$user->societe_id;
  73. $lettering = new Lettering($db);
  74. $object = new Societe($db);
  75. $object->id = $socid;
  76. $result = $object->fetch($socid);
  77. if ($result<0)
  78. {
  79. setEventMessages($object->error, $object->errors, 'errors');
  80. }
  81. /*
  82. * Action
  83. */
  84. if ($action == 'lettering') {
  85. $result = $lettering->updateLettering($toselect);
  86. if ($result < 0) {
  87. setEventMessages('', $lettering->errors, 'errors');
  88. $error++;
  89. }
  90. }
  91. if ($action == 'autolettrage') {
  92. $result = $lettering->letteringThirdparty($socid);
  93. if ($result < 0) {
  94. setEventMessages('', $lettering->errors, 'errors');
  95. $error++;
  96. }
  97. }
  98. /*
  99. * View
  100. */
  101. $form = new Form($db);
  102. $formaccounting = new FormAccounting($db);
  103. $title=$object->name." - ".$langs->trans('TabLetteringSupplier');
  104. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  105. llxHeader('',$title,$help_url);
  106. $head = societe_prepare_head($object);
  107. dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
  108. dol_fiche_head($head, 'lettering_supplier', $langs->trans("ThirdParty"), 0, 'company');
  109. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  110. dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom', '', '', 0, '', '', 'arearefnobottom');
  111. dol_fiche_end();
  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_fournisseur . "' AND bk.numero_compte = '" . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . "' )";
  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. {
  131. dol_print_error($db);
  132. exit;
  133. }
  134. $nbtotalofrecords = $db->num_rows($resql);
  135. while ($obj = $db->fetch_object($resql)) {
  136. $debit += $obj->debit;
  137. $credit += $obj->credit;
  138. $solde += ($obj->credit - $obj->debit);
  139. }
  140. $sql.= $db->plimit($limit+1, $offset);
  141. dol_syslog ( "/accountancy/bookkeeping/thirdparty_lettrage_supplier.php", LOG_DEBUG );
  142. $resql = $db->query($sql);
  143. if (! $resql)
  144. {
  145. dol_print_error($db);
  146. exit;
  147. }
  148. $num = $db->num_rows($resql);
  149. dol_syslog ( "/accountancy/bookkeeping/thirdparty_lettrage_supplier.php", LOG_DEBUG );
  150. $resql = $db->query($sql);
  151. if ($resql) {
  152. $num = $db->num_rows($resql);
  153. $i = 0;
  154. print '<form name="add" action="'.$_SERVER["PHP_SELF"].'?socid=' . $object->id . '" method="POST">';
  155. print '<input type="hidden" name="socid" value="' . $object->id . '">';
  156. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
  157. print "<table class=\"noborder\" width=\"100%\">";
  158. print '<tr class="liste_titre">';
  159. print_liste_field_titre("Doctype", $_SERVER["PHP_SELF"], "bk.doc_type","",$param,"",$sortfield,$sortorder);
  160. print_liste_field_titre("Docdate", $_SERVER["PHP_SELF"], "bk.doc_date","",$param,"",$sortfield,$sortorder);
  161. print_liste_field_titre("Docref", $_SERVER["PHP_SELF"], "bk.doc_ref","",$param,"",$sortfield,$sortorder);
  162. print_liste_field_titre("LabelAccount", $_SERVER["PHP_SELF"], "bk.label_compte","",$param,"",$sortfield,$sortorder);
  163. print_liste_field_titre("Debit", $_SERVER["PHP_SELF"], "bk.debit","",$param,"",$sortfield,$sortorder);
  164. print_liste_field_titre("Credit", $_SERVER["PHP_SELF"], "bk.credit","",$param,"",$sortfield,$sortorder);
  165. print_liste_field_titre("Balancing", $_SERVER["PHP_SELF"], "","",$param,"",$sortfield,$sortorder);
  166. print_liste_field_titre("Codejournal", $_SERVER["PHP_SELF"], "bk.code_journal","",$param,"",$sortfield,$sortorder);
  167. print_liste_field_titre("LetteringCode", $_SERVER["PHP_SELF"], "bk.lettering_code", "", $param, "", $sortfield, $sortorder);
  168. print "</tr>\n";
  169. print '<tr class="liste_titre">';
  170. print '<td><input type="text" name="search_doc_type" value="' . $search_doc_type . '"></td>';
  171. print '<td><input type="text" name="search_year" value="' . $search_year . '"></td>';
  172. print '<td><input type="text" name="search_doc_refe" value="' . $search_doc_ref . '"></td>';
  173. print '<td colspan="6">&nbsp;</td>';
  174. print '<td class="right">';
  175. $searchpicto=$form->showFilterButtons();
  176. print $searchpicto;
  177. print '</td>';
  178. print '</tr>';
  179. $solde = 0;
  180. $tmp = '';
  181. while ($obj = $db->fetch_object($resql)) {
  182. if ($tmp != $obj->lettering_code || empty($tmp)) $tmp = $obj->lettering_code;
  183. /*if ($tmp != $obj->lettering_code || empty($obj->lettering_code))*/ $solde += ($obj->credit - $obj->debit);
  184. print '<tr class="oddeven">';
  185. if (empty($obj->lettering_code)) {
  186. print '<td><a href="' . dol_buildpath('/accountancy/bookkeeping/card.php', 1) . '?piece_num=' . $obj->piece_num . '">';
  187. print img_edit();
  188. print '</a>&nbsp;' . $obj->doc_type . '</td>' . "\n";
  189. } else {
  190. print '<td>' . $obj->doc_type . '</td>' . "\n";
  191. }
  192. print '<td>' . dol_print_date($db->jdate($obj->doc_date), 'day') . '</td>';
  193. print '<td>' . $obj->doc_ref . '</td>';
  194. print '<td>' . $obj->label_compte . '</td>';
  195. print '<td class="right">' . price($obj->debit) . '</td>';
  196. print '<td class="right">' . price($obj->credit) . '</td>';
  197. print '<td class="right">' . price(round($solde, 2)) . '</td>';
  198. print '<td align="center">' . $obj->code_journal . '</td>';
  199. if (empty($obj->lettering_code)) {
  200. print '<td class="nowrap" align="center"><input type="checkbox" class="flat checkforselect" name="toselect[]" id="toselect[]" value="' . $obj->rowid . '" /></td>';
  201. } else
  202. print '<td align="center">' . $obj->lettering_code . '</td>';
  203. print "</tr>\n";
  204. }
  205. print '<tr class="oddeven">';
  206. print '<td class="right" colspan="4">'.$langs->trans("Total").':</td>' . "\n";
  207. print '<td class="right"><strong>' . price($debit) . '</strong></td>';
  208. print '<td class="right"><strong>' . price($credit) . '</strong></td>';
  209. print '<td colspan="5"></td>';
  210. print "</tr>\n";
  211. print '<tr class="oddeven">';
  212. print '<td class="right" colspan="4">'.$langs->trans("Balancing").':</td>' . "\n";
  213. print '<td colspan="2">&nbsp;</td>';
  214. print '<td class="right"><strong>' . price($credit - $debit) . '</strong></td>';
  215. print '<td colspan="3"></td>';
  216. print "</tr>\n";
  217. print "</table>";
  218. print '<input class="butAction" type="submit" value="' . $langs->trans('AccountancyLettering') . '" name="lettering" id="lettering">';
  219. //print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid=' . $object->id . '&action=autolettrage">'.$langs->trans('AccountancyAutoLettering').'</a>';
  220. print "</form>";
  221. $db->free($resql);
  222. } else {
  223. dol_print_error($db);
  224. }
  225. // End of page
  226. llxFooter();
  227. $db->close();