dolibarr  9.0.0
thirdparty_lettering_customer.php
Go to the documentation of this file.
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@zendsi.com>
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 
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
31 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
32 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.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 
36 // Load translation files required by the page
37 $langs->loadLangs(array("compta","accountancy"));
38 
39 $action = GETPOST('action', 'aZ09');
40 $massaction = GETPOST('massaction', 'alpha');
41 $show_files = GETPOST('show_files', 'int');
42 $confirm = GETPOST('confirm', 'alpha');
43 $toselect = GETPOST('toselect', 'array');
44 
45 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
46 $sortfield = GETPOST("sortfield", 'alpha');
47 $sortorder = GETPOST("sortorder", 'alpha');
48 $page = 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 = "DESC";
57 if ($sortfield == "")
58  $sortfield = "bk.doc_date";
59 
60 $search_year = GETPOST("search_year", 'int');
61 $search_doc_type = GETPOST("search_doc_type", 'alpha');
62 $search_doc_ref = GETPOST("search_doc_ref", 'alpha');
63 
64 $lettering = GETPOST('lettering', 'alpha');
65 if (! empty($lettering)) {
66  $action = $lettering;
67 }
68 
69 // Did we click on purge search criteria ?
70 // All tests are required to be compatible with all browsers
71 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
72  $search_year = '';
73  $search_doc_type = '';
74  $search_doc_ref = '';
75 }
76 
77 // Security check
78 $socid = GETPOST("socid", 'int');
79 // if ($user->societe_id) $socid=$user->societe_id;
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 {
87  setEventMessages($object->error, $object->errors, 'errors');
88 }
89 
90 
91 /*
92  * Action
93  */
94 
95 if ($action == 'lettering') {
96 
97  $result = $lettering->updateLettering($toselect);
98 
99  if ($result < 0) {
100  setEventMessages('', $lettering->errors, 'errors');
101  $error++;
102  }
103 }
104 
105 if ($action == 'autolettrage') {
106 
107  $result = $lettering->letteringThirdparty($socid);
108 
109  if ($result < 0) {
110  setEventMessages('', $lettering->errors, 'errors');
111  $error++;
112  }
113 }
114 
115 
116  /*
117  * View
118  */
119 
120 $form = new Form($db);
121 $formaccounting = new FormAccounting($db);
122 
123 $title=$object->name." - ".$langs->trans('TabLetteringCustomer');
124 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
125 llxHeader('',$title,$help_url);
126 
127 $head = societe_prepare_head($object);
128 
129 dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
130 
131 dol_fiche_head($head, 'lettering_customer', $langs->trans("ThirdParty"), 0, 'company');
132 
133 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
134 
135 dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom', '', '', 0, '', '', 'arearefnobottom');
136 
137 dol_fiche_end();
138 
139 print '<br>';
140 
141 $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, ";
142 $sql .= " bk.subledger_account, bk.numero_compte , bk.label_compte, bk.debit, ";
143 $sql .= " bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering_code ";
144 $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk";
145 $sql .= " WHERE (bk.subledger_account = '" . $object->code_compta . "' AND bk.numero_compte = '" . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . "' )";
146 
147 if (dol_strlen($search_year)) {
148  $date_start = dol_mktime(0, 0, 0, 1, 1, $search_year);
149  $date_end = dol_mktime(23, 59, 59, 12, 31, $search_year);
150  $sql .= " AND ( bk.doc_date BETWEEN '" . $db->idate($date_start) . "' AND '" . $db->idate($date_end) . "' )";
151 }
152 
153 $sql .= $db->order($sortfield, $sortorder);
154 
155 $debit = 0;
156 $credit = 0;
157 $solde = 0;
158 // Count total nb of records and calc total sum
159 $nbtotalofrecords = '';
160 $resql = $db->query($sql);
161 if (! $resql) {
162  dol_print_error($db);
163  exit();
164 }
165 $nbtotalofrecords = $db->num_rows($resql);
166 
167 while ( $obj = $db->fetch_object($resql) ) {
168  $debit += $obj->debit;
169  $credit += $obj->credit;
170 
171  $solde += ($obj->credit - $obj->debit);
172 }
173 
174 $sql .= $db->plimit($limit + 1, $offset);
175 
176 dol_syslog("/accountancy/bookkeeping/thirdparty_lettering_customer.php", LOG_DEBUG);
177 $resql = $db->query($sql);
178 if (! $resql) {
179  dol_print_error($db);
180  exit();
181 }
182 
183 $num = $db->num_rows($resql);
184 
185 dol_syslog("/accountancy/bookkeeping/thirdparty_lettering_customer.php", LOG_DEBUG);
186 if ($resql) {
187  $i = 0;
188 
189  print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '" method="POST">';
190  print '<input type="hidden" name="socid" value="' . $object->id . '">';
191 
192  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
193 
194  print "<table class=\"noborder\" width=\"100%\">";
195  print '<tr class="liste_titre">';
196  print_liste_field_titre("Doctype", $_SERVER["PHP_SELF"], "bk.doc_type", "", $param, "", $sortfield, $sortorder);
197  print_liste_field_titre("Docdate", $_SERVER["PHP_SELF"], "bk.doc_date", "", $param, "", $sortfield, $sortorder);
198  print_liste_field_titre("Docref", $_SERVER["PHP_SELF"], "bk.doc_ref", "", $param, "", $sortfield, $sortorder);
199  print_liste_field_titre("LabelAccount", $_SERVER["PHP_SELF"], "bk.label_compte", "", $param, "", $sortfield, $sortorder);
200  print_liste_field_titre("Debit", $_SERVER["PHP_SELF"], "bk.debit", "", $param, "", $sortfield, $sortorder);
201  print_liste_field_titre("Credit", $_SERVER["PHP_SELF"], "bk.credit", "", $param, "", $sortfield, $sortorder);
202  print_liste_field_titre("Balancing", $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder);
203  print_liste_field_titre("Codejournal", $_SERVER["PHP_SELF"], "bk.code_journal", "", $param, "", $sortfield, $sortorder);
204  print_liste_field_titre("LetteringCode", $_SERVER["PHP_SELF"], "bk.lettering_code", "", $param, "", $sortfield, $sortorder);
205  print "</tr>\n";
206 
207  print '<tr class="liste_titre">';
208  print '<td><input type="text" name="search_doc_type" value="' . $search_doc_type . '"></td>';
209  print '<td><input type="text" name="search_year" value="' . $search_year . '"></td>';
210  print '<td><input type="text" name="search_doc_refe" value="' . $search_doc_ref . '"></td>';
211  print '<td colspan="5">&nbsp;</td>';
212  print '<td align="right">';
213  $searchpicto = $form->showFilterButtons();
214  print $searchpicto;
215  print '</td>';
216  print '</tr>';
217 
218  $solde = 0;
219  $tmp = '';
220  while ( $obj = $db->fetch_object($resql) ) {
221 
222  if ($tmp != $obj->lettering_code || empty($tmp)) $tmp = $obj->lettering_code;
223  /*if ($tmp != $obj->lettering_code || empty($obj->lettering_code))*/ $solde += ($obj->credit - $obj->debit);
224 
225  print '<tr class="oddeven">';
226 
227  if (empty($obj->lettering_code)) {
228  print '<td><a href="' . dol_buildpath('/accountancy/bookkeeping/card.php', 1) . '?piece_num=' . $obj->piece_num . '">';
229  print img_edit();
230  print '</a>&nbsp;' . $obj->doc_type . '</td>' . "\n";
231  } else {
232  print '<td>' . $obj->doc_type . '</td>' . "\n";
233  }
234 
235  print '<td>' . dol_print_date($db->jdate($obj->doc_date), 'day') . '</td>';
236  print '<td>' . $obj->doc_ref . '</td>';
237  print '<td>' . $obj->label_compte . '</td>';
238  print '<td align="right">' . price($obj->debit) . '</td>';
239  print '<td align="right">' . price($obj->credit) . '</td>';
240  print '<td align="right">' . price(round($solde, 2)) . '</td>';
241  print '<td align="center">' . $obj->code_journal . '</td>';
242 
243  if (empty($obj->lettering_code)) {
244  print '<td class="nowrap" align="center"><input type="checkbox" class="flat checkforselect" name="toselect[]" id="toselect[]" value="' . $obj->rowid . '" /></td>';
245  } else
246  print '<td align="center">' . $obj->lettering_code . '</td>';
247 
248  print "</tr>\n";
249  }
250 
251  print '<tr class="oddeven">';
252  print '<td align="right" colspan="4">'.$langs->trans("Total").':</td>' . "\n";
253  print '<td align="right"><strong>' . price($debit) . '</strong></td>';
254  print '<td align="right"><strong>' . price($credit) . '</strong></td>';
255  print '<td colspan="5"></td>';
256  print "</tr>\n";
257 
258  print '<tr class="oddeven">';
259  print '<td align="right" colspan="4">'.$langs->trans("Balancing").':</td>' . "\n";
260  print '<td colspan="2">&nbsp;</td>';
261  print '<td align="right"><strong>' . price($credit - $debit) . '</strong></td>';
262  print '<td colspan="3"></td>';
263  print "</tr>\n";
264 
265  print "</table>";
266 
267  print '<input class="butAction" type="submit" value="lettering" name="lettering" id="lettering">';
268  //print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '&action=autolettering">' . $langs->trans('AccountancyAutoLettering') . '</a>';
269  print "</form>";
270  $db->free($resql);
271 } else {
272  dol_print_error($db);
273 }
274 
275 // End of page
276 llxFooter();
277 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class Lettering.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage generation of HTML components for accounting management.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).