dolibarr  13.0.2
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-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 
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.'/accountancy/class/accountingjournal.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array("compta", "accountancy"));
39 
40 $action = GETPOST('action', 'aZ09');
41 $massaction = GETPOST('massaction', 'alpha');
42 $show_files = GETPOST('show_files', 'int');
43 $confirm = GETPOST('confirm', 'alpha');
44 $toselect = GETPOST('toselect', 'array');
45 $socid = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : GETPOST('id', 'int');
46 
47 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
48 $sortfield = GETPOST("sortfield", 'alpha');
49 $sortorder = GETPOST("sortorder", 'alpha');
50 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
51 if (empty($page) || $page == - 1) {
52  $page = 0;
53 } // If $page is not defined, or '' or -1
54 $offset = $limit * $page;
55 $pageprev = $page - 1;
56 $pagenext = $page + 1;
57 if ($sortorder == "")
58  $sortorder = "ASC";
59 if ($sortfield == "")
60  $sortfield = "bk.doc_date";
61 
62 /*
63 $search_date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
64 $search_date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'));
65 //$search_doc_type = GETPOST("search_doc_type", 'alpha');
66 $search_doc_ref = GETPOST("search_doc_ref", 'alpha');
67 */
68 
69 $lettering = GETPOST('lettering', 'alpha');
70 if (!empty($lettering)) {
71  $action = $lettering;
72 }
73 
74 /*
75 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
76 {
77  $search_date_start = '';
78  $search_date_end = '';
79  //$search_doc_type = '';
80  $search_doc_ref = '';
81 }
82 */
83 
84 // Security check
85 $socid = GETPOST("socid", 'int');
86 // if ($user->socid) $socid=$user->socid;
87 
88 $lettering = new Lettering($db);
89 $object = new Societe($db);
90 $object->id = $socid;
91 $result = $object->fetch($socid);
92 if ($result < 0)
93 {
94  setEventMessages($object->error, $object->errors, 'errors');
95 }
96 
97 
98 /*
99  * Action
100  */
101 
102 if ($action == 'lettering') {
103  $result = $lettering->updateLettering($toselect);
104 
105  if ($result < 0) {
106  setEventMessages('', $lettering->errors, 'errors');
107  $error++;
108  }
109 }
110 
111 /*
112 if ($action == 'autolettrage') {
113 
114  $result = $lettering->letteringThirdparty($socid);
115 
116  if ($result < 0) {
117  setEventMessages('', $lettering->errors, 'errors');
118  $error++;
119  }
120 }
121 */
122 
123 /*
124  * View
125  */
126 
127 $form = new Form($db);
128 $formaccounting = new FormAccounting($db);
129 
130 $title = $object->name." - ".$langs->trans('TabLetteringCustomer');
131 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
132 llxHeader('', $title, $help_url);
133 
134 $head = societe_prepare_head($object);
135 
136 dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
137 
138 print dol_get_fiche_head($head, 'lettering_customer', $langs->trans("ThirdParty"), 0, 'company');
139 
140 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
141 
142 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', '', '', 0, '', '', 'arearefnobottom');
143 
145 
146 $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, ";
147 $sql .= " bk.subledger_account, bk.numero_compte , bk.label_compte, bk.debit, ";
148 $sql .= " bk.credit, bk.montant, bk.sens, bk.code_journal, bk.piece_num, bk.lettering_code";
149 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as bk";
150 $sql .= " WHERE (bk.subledger_account = '".$db->escape($object->code_compta)."' AND bk.numero_compte = '".$db->escape($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER)."' )";
151 
152 /*
153 if (dol_strlen($search_date_start) || dol_strlen($search_date_end)) {
154  $sql .= " AND ( bk.doc_date BETWEEN '" . $db->idate($search_date_start) . "' AND '" . $db->idate($search_date_end) . "' )";
155 }
156 */
157 
158 $sql .= ' AND bk.entity IN ('.getEntity('accountingbookkeeping').')';
159 $sql .= $db->order($sortfield, $sortorder);
160 
161 $debit = 0;
162 $credit = 0;
163 $solde = 0;
164 // Count total nb of records and calc total sum
165 $nbtotalofrecords = '';
166 $resql = $db->query($sql);
167 if (!$resql) {
168  dol_print_error($db);
169  exit();
170 }
171 $nbtotalofrecords = $db->num_rows($resql);
172 
173 while ($obj = $db->fetch_object($resql)) {
174  $debit += $obj->debit;
175  $credit += $obj->credit;
176 
177  $solde += ($obj->credit - $obj->debit);
178 }
179 
180 $sql .= $db->plimit($limit + 1, $offset);
181 
182 dol_syslog("/accountancy/bookkeeping/thirdparty_lettering_customer.php", LOG_DEBUG);
183 $resql = $db->query($sql);
184 if (!$resql) {
185  dol_print_error($db);
186  exit();
187 }
188 
189 $param = '';
190 $param .= "&socid=".urlencode($socid);
191 
192 $num = $db->num_rows($resql);
193 
194 dol_syslog("/accountancy/bookkeeping/thirdparty_lettering_customer.php", LOG_DEBUG);
195 if ($resql) {
196  $i = 0;
197 
198  $param = "&socid=".$socid;
199  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="POST">';
200  print '<input type="hidden" name="token" value="'.newToken().'">';
201  print '<input type="hidden" name="socid" value="'.$object->id.'">';
202 
203  $letteringbutton = '<a class="divButAction"><span class="valignmiddle"><input class="butAction" type="submit" value="lettering" name="lettering" id="lettering"></span></a>';
204 
205  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, $letteringbutton, '', $limit);
206 
207  print '<div class="div-table-responsive-no-min">';
208  print '<table class="liste centpercent">'."\n";
209 
210  /*
211  print '<tr class="liste_titre">';
212  //print '<td><input type="text" name="search_doc_type" value="' . $search_doc_type . '"></td>';
213 
214  // Date
215  print '<td class="liste_titre center">';
216  print '<div class="nowrap">';
217  print $langs->trans('From') . ' ';
218  print $form->selectDate($search_date_start, 'date_creation_start', 0, 0, 1);
219  print '</div>';
220  print '<div class="nowrap">';
221  print $langs->trans('to') . ' ';
222  print $form->selectDate($search_date_end, 'date_creation_end', 0, 0, 1);
223  print '</div>';
224  print '</td>';
225 
226  // Piece
227  print '<td><input type="text" name="search_doc_ref" value="' . $search_doc_ref . '"></td>';
228 
229  print '<td colspan="6">&nbsp;</td>';
230  print '<td class="right">';
231  $searchpicto = $form->showFilterButtons();
232  print $searchpicto;
233  print '</td>';
234  print '</tr>';
235  */
236 
237  print '<tr class="liste_titre">';
238  //print_liste_field_titre("Doctype", $_SERVER["PHP_SELF"], "bk.doc_type", "", $param, "", $sortfield, $sortorder);
239  print_liste_field_titre("Docdate", $_SERVER["PHP_SELF"], "bk.doc_date", "", $param, "", $sortfield, $sortorder, 'center ');
240  print_liste_field_titre("Piece", $_SERVER["PHP_SELF"], "bk.doc_ref", "", $param, "", $sortfield, $sortorder);
241  print_liste_field_titre("LabelAccount", $_SERVER["PHP_SELF"], "bk.label_compte", "", $param, "", $sortfield, $sortorder);
242  print_liste_field_titre("Debit", $_SERVER["PHP_SELF"], "bk.debit", "", $param, "", $sortfield, $sortorder);
243  print_liste_field_titre("Credit", $_SERVER["PHP_SELF"], "bk.credit", "", $param, "", $sortfield, $sortorder);
244  print_liste_field_titre("Balancing", $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder);
245  print_liste_field_titre("Codejournal", $_SERVER["PHP_SELF"], "bk.code_journal", "", $param, "", $sortfield, $sortorder, 'center ');
246  print_liste_field_titre("LetteringCode", $_SERVER["PHP_SELF"], "bk.lettering_code", "", $param, "", $sortfield, $sortorder, 'center ');
247  print_liste_field_titre("", "", "", '', '', "", $sortfield, $sortorder, 'maxwidthsearch center ');
248  print "</tr>\n";
249 
250  $solde = 0;
251  $tmp = '';
252 
253  while ($obj = $db->fetch_object($resql)) {
254  if ($tmp != $obj->lettering_code || empty($tmp)) $tmp = $obj->lettering_code;
255  /*if ($tmp != $obj->lettering_code || empty($obj->lettering_code))*/ $solde += ($obj->credit - $obj->debit);
256 
257  print '<tr class="oddeven">';
258 
259  //print '<td>' . $obj->doc_type . '</td>' . "\n";
260  print '<td class="center">'.dol_print_date($db->jdate($obj->doc_date), 'day').'</td>';
261  print '<td>'.$obj->doc_ref.'</td>';
262  print '<td>'.$obj->label_compte.'</td>';
263  print '<td class="nowrap right">'.price($obj->debit).'</td>';
264  print '<td class="nowrap right">'.price($obj->credit).'</td>';
265  print '<td class="nowrap right">'.price(round($solde, 2)).'</td>';
266 
267  // Journal
268  $accountingjournal = new AccountingJournal($db);
269  $result = $accountingjournal->fetch('', $obj->code_journal);
270  $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $obj->code_journal);
271  print '<td class="center">'.$journaltoshow.'</td>';
272 
273  if (empty($obj->lettering_code)) {
274  print '<td class="nowrap center"><input type="checkbox" class="flat checkforselect" name="toselect[]" id="toselect[]" value="'.$obj->rowid.'" /></td>';
275  print '<td><a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?piece_num='.$obj->piece_num.'">';
276  print img_edit();
277  print '</a></td>'."\n";
278  } else {
279  print '<td class="center">'.$obj->lettering_code.'</td>';
280  print '<td></td>';
281  }
282 
283  print "</tr>\n";
284  }
285 
286  print '<tr class="oddeven">';
287  print '<td class="right" colspan="3">'.$langs->trans("Total").':</td>'."\n";
288  print '<td class="nowrap right"><strong>'.price($debit).'</strong></td>';
289  print '<td class="nowrap right"><strong>'.price($credit).'</strong></td>';
290  print '<td colspan="4"></td>';
291  print "</tr>\n";
292 
293  print '<tr class="oddeven">';
294  print '<td class="right" colspan="3">'.$langs->trans("Balancing").':</td>'."\n";
295  print '<td colspan="2">&nbsp;</td>';
296  print '<td class="nowrap right"><strong>'.price($credit - $debit).'</strong></td>';
297  print '<td colspan="6"></td>';
298  print "</tr>\n";
299 
300  print "</table>";
301 
302  print '<div class="tabsAction tabsActionNoBottom">'."\n";
303  print $letteringbutton;
304  print '</div>';
305 
306  print "</form>";
307  $db->free($resql);
308 } else {
309  dol_print_error($db);
310 }
311 
312 // End of page
313 llxFooter();
314 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
Class Lettering.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_htmloutput_mesg($mesgstring= '', $mesgarray=array(), $style= 'ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
print
Draft customers invoices.
Definition: index.php:89
Class to manage generation of HTML components for accounting management.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage accounting accounts.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59