dolibarr  13.0.2
thirdparty_lettering_supplier.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-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 
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.'/accountancy/class/accountingjournal.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 $socid = GETPOST('socid', 'int') ? ((int) GETPOST('socid', 'int')) : ((int) GETPOST('id', 'int'));
45 
46 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
47 $sortfield = GETPOST("sortfield", 'alpha');
48 $sortorder = GETPOST("sortorder", 'alpha');
49 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
50 if (empty($page) || $page == - 1) {
51  $page = 0;
52 } // If $page is not defined, or '' or -1
53 $offset = $limit * $page;
54 $pageprev = $page - 1;
55 $pagenext = $page + 1;
56 if ($sortorder == "")
57  $sortorder = "ASC";
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 
68 $lettering = GETPOST('lettering', 'alpha');
69 if (!empty($lettering)) {
70  $action = $lettering;
71 }
72 
73 /*
74 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
75 {
76  $search_date_start = '';
77  $search_date_end = '';
78  //$search_doc_type='';
79  $search_doc_ref='';
80 }
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 if ($action == 'lettering') {
102  $result = $lettering->updateLettering($toselect);
103 
104  if ($result < 0) {
105  setEventMessages('', $lettering->errors, 'errors');
106  $error++;
107  }
108 }
109 
110 /*
111 if ($action == 'autolettrage') {
112 
113  $result = $lettering->letteringThirdparty($socid);
114 
115  if ($result < 0) {
116  setEventMessages('', $lettering->errors, 'errors');
117  $error++;
118  }
119 }
120 */
121 
122 /*
123  * View
124  */
125 
126 $form = new Form($db);
127 $formaccounting = new FormAccounting($db);
128 
129 $title = $object->name." - ".$langs->trans('TabLetteringSupplier');
130 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
131 llxHeader('', $title, $help_url);
132 
133 $head = societe_prepare_head($object);
134 
135 dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
136 
137 print dol_get_fiche_head($head, 'lettering_supplier', $langs->trans("ThirdParty"), 0, 'company');
138 
139 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
140 
141 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', '', '', 0, '', '', 'arearefnobottom');
142 
144 
145 $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, ";
146 $sql .= " bk.subledger_account, bk.numero_compte , bk.label_compte, bk.debit, ";
147 $sql .= " bk.credit, bk.montant, bk.sens, bk.code_journal, bk.piece_num, bk.lettering_code, bk.date_validated ";
148 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as bk";
149 $sql .= " WHERE (bk.subledger_account = '".$db->escape($object->code_compta_fournisseur)."' AND bk.numero_compte = '".$db->escape($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER)."' )";
150 if (dol_strlen($search_date_start) || dol_strlen($search_date_end)) {
151  $sql .= " AND (bk.doc_date BETWEEN '".$db->idate($search_date_start)."' AND '".$db->idate($search_date_end)."' )";
152 }
153 $sql .= ' AND bk.entity IN ('.getEntity('accountingbookkeeping').')';
154 $sql .= $db->order($sortfield, $sortorder);
155 
156 $debit = 0;
157 $credit = 0;
158 $solde = 0;
159 // Count total nb of records and calc total sum
160 $nbtotalofrecords = '';
161 $resql = $db->query($sql);
162 if (!$resql)
163 {
164  dol_print_error($db);
165  exit;
166 }
167 $nbtotalofrecords = $db->num_rows($resql);
168 
169 while ($obj = $db->fetch_object($resql)) {
170  $debit += $obj->debit;
171  $credit += $obj->credit;
172 
173  $solde += ($obj->credit - $obj->debit);
174 }
175 
176 $sql .= $db->plimit($limit + 1, $offset);
177 
178 dol_syslog("/accountancy/bookkeeping/thirdparty_lettering_supplier.php", LOG_DEBUG);
179 $resql = $db->query($sql);
180 if (!$resql) {
181  dol_print_error($db);
182  exit;
183 }
184 
185 $param = '';
186 $param .= "&socid=".urlencode($socid);
187 
188 $num = $db->num_rows($resql);
189 
190 dol_syslog("/accountancy/bookkeeping/thirdparty_lettering_supplier.php", LOG_DEBUG);
191 $resql = $db->query($sql);
192 if ($resql) {
193  $num = $db->num_rows($resql);
194  $i = 0;
195 
196  $param = "&socid=".$socid;
197  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="POST">';
198  print '<input type="hidden" name="token" value="'.newToken().'">';
199  print '<input type="hidden" name="socid" value="'.$object->id.'">';
200 
201  $letteringbutton = '<a class="divButAction"><span class="valignmiddle"><input class="butAction" type="submit" value="lettering" name="lettering" id="lettering"></span></a>';
202 
203  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, $letteringbutton, '', $limit);
204 
205  print '<div class="div-table-responsive-no-min">';
206  print '<table class="liste centpercent">'."\n";
207 
208  /*
209  print '<tr class="liste_titre">';
210  //print '<td><input type="text" name="search_doc_type" value="' . $search_doc_type . '"></td>';
211 
212  // Date
213  print '<td class="liste_titre center">';
214  print '<div class="nowrap">';
215  print $langs->trans('From') . ' ';
216  print $form->selectDate($search_date_start, 'date_creation_start', 0, 0, 1);
217  print '</div>';
218  print '<div class="nowrap">';
219  print $langs->trans('to') . ' ';
220  print $form->selectDate($search_date_end, 'date_creation_end', 0, 0, 1);
221  print '</div>';
222  print '</td>';
223 
224  // Piece
225  print '<td><input type="text" name="search_doc_ref" value="' . $search_doc_ref . '"></td>';
226 
227  print '<td colspan="6">&nbsp;</td>';
228  print '<td class="right">';
229  $searchpicto = $form->showFilterButtons();
230  print $searchpicto;
231  print '</td>';
232  print '</tr>';
233  */
234 
235  print '<tr class="liste_titre">';
236  //print_liste_field_titre("Doctype", $_SERVER["PHP_SELF"], "bk.doc_type", "", $param, "", $sortfield, $sortorder);
237  print_liste_field_titre("Docdate", $_SERVER["PHP_SELF"], "bk.doc_date", "", $param, "", $sortfield, $sortorder, 'center ');
238  print_liste_field_titre("Piece", $_SERVER["PHP_SELF"], "bk.doc_ref", "", $param, "", $sortfield, $sortorder);
239  print_liste_field_titre("LabelAccount", $_SERVER["PHP_SELF"], "bk.label_compte", "", $param, "", $sortfield, $sortorder);
240  print_liste_field_titre("Debit", $_SERVER["PHP_SELF"], "bk.debit", "", $param, "", $sortfield, $sortorder);
241  print_liste_field_titre("Credit", $_SERVER["PHP_SELF"], "bk.credit", "", $param, "", $sortfield, $sortorder);
242  print_liste_field_titre("Balancing", $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder);
243  print_liste_field_titre("Codejournal", $_SERVER["PHP_SELF"], "bk.code_journal", "", $param, "", $sortfield, $sortorder, 'center ');
244  print_liste_field_titre("LetteringCode", $_SERVER["PHP_SELF"], "bk.lettering_code", "", $param, "", $sortfield, $sortorder, 'center ');
245  print_liste_field_titre("", "", "", '', '', "", $sortfield, $sortorder, 'maxwidthsearch center ');
246  print "</tr>\n";
247 
248  $solde = 0;
249  $tmp = '';
250  while ($obj = $db->fetch_object($resql)) {
251  if ($tmp != $obj->lettering_code || empty($tmp)) $tmp = $obj->lettering_code;
252  /*if ($tmp != $obj->lettering_code || empty($obj->lettering_code))*/ $solde += ($obj->credit - $obj->debit);
253 
254  print '<tr class="oddeven">';
255 
256  //print '<td>' . $obj->doc_type . '</td>' . "\n";
257  print '<td class="center">'.dol_print_date($db->jdate($obj->doc_date), 'day').'</td>';
258  print '<td>'.$obj->doc_ref.'</td>';
259  print '<td>'.$obj->label_compte.'</td>';
260  print '<td class="nowrap right">'.price($obj->debit).'</td>';
261  print '<td class="nowrap right">'.price($obj->credit).'</td>';
262  print '<td class="nowrap right">'.price(round($solde, 2)).'</td>';
263 
264  // Journal
265  $accountingjournal = new AccountingJournal($db);
266  $result = $accountingjournal->fetch('', $obj->code_journal);
267  $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $obj->code_journal);
268  print '<td class="center">'.$journaltoshow.'</td>';
269 
270  if (empty($obj->lettering_code) && empty($obj->date_validated)) {
271  print '<td class="nowrap center"><input type="checkbox" class="flat checkforselect" name="toselect[]" id="toselect[]" value="'.$obj->rowid.'" /></td>';
272  print '<td><a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?piece_num='.$obj->piece_num.'">';
273  print img_edit();
274  print '</a></td>'."\n";
275  } else {
276  print '<td class="center">'.$obj->lettering_code.'</td>';
277  print '<td></td>';
278  }
279 
280  print "</tr>\n";
281  }
282 
283  print '<tr class="oddeven">';
284  print '<td class="right" colspan="3">'.$langs->trans("Total").':</td>'."\n";
285  print '<td class="nowrap right"><strong>'.price($debit).'</strong></td>';
286  print '<td class="nowrap right"><strong>'.price($credit).'</strong></td>';
287  print '<td colspan="6"></td>';
288  print "</tr>\n";
289 
290  print '<tr class="oddeven">';
291  print '<td class="right" colspan="3">'.$langs->trans("Balancing").':</td>'."\n";
292  print '<td colspan="2">&nbsp;</td>';
293  print '<td class="nowrap right"><strong>'.price($credit - $debit).'</strong></td>';
294  print '<td colspan="4"></td>';
295  print "</tr>\n";
296 
297  print "</table>";
298 
299  print '<div class="tabsAction tabsActionNoBottom">'."\n";
300  print $letteringbutton;
301  print '</div>';
302 
303  print "</form>";
304  $db->free($resql);
305 } else {
306  dol_print_error($db);
307 }
308 
309 // End of page
310 llxFooter();
311 $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_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
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