dolibarr  7.0.0-beta
thirdparty_lettrage.php
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 Alexandre Spangaro <alexandre.spangaro@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
28 require '../../main.inc.php';
29 
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 $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 
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 = "DESC";
54 if ($sortfield == "")
55  $sortfield = "bk.doc_date";
56 
57 $search_year = GETPOST("search_year", 'int');
58 $search_doc_type = GETPOST("search_doc_type", 'alpha');
59 $search_doc_ref = GETPOST("search_doc_ref", 'alpha');
60 
61 $lettering = GETPOST('lettering');
62 if (! empty($lettering)) {
63  $action = $lettering;
64 }
65 $toselect = GETPOST('toselect', 'array');
66 
67 // Did we click on purge search criteria ?
68 // All tests are required to be compatible with all browsers
69 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
70  $search_year = '';
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 
79 $object = new Societe($db);
80 $object->id = $socid;
81 $result = $object->fetch($socid);
82 if ($result < 0) {
83  setEventMessage($object->error, 'errors');
84 }
85 
86 $form = new Form($db);
87 $BookKeeping = new lettering($db);
88 $formaccounting = new FormAccounting($db);
89 
90 /*
91  * Action
92  */
93 
94 if ($action == 'lettering') {
95 
96  $result = $BookKeeping->updateLettrage($toselect);
97 
98  if ($result < 0) {
99  setEventMessages('', $BookKeeping->errors, 'errors');
100  $error ++;
101  }
102 }
103 
104 if ($action == 'autolettrage') {
105 
106  $result = $BookKeeping->lettrageTiers($socid);
107 
108  if ($result < 0) {
109  setEventMessages('', $BookKeeping->errors, 'errors');
110  $error ++;
111  }
112 }
113 
114 llxHeader('', 'Compta - Grand Livre');
115 
116 /*
117  * Affichage onglets
118  */
119 $head = societe_prepare_head($object);
120 
121 dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
122 
123 dol_fiche_head($head, 'accounting', $langs->trans("ThirdParty"), 0, 'company');
124 
125 print '<table width="100%" class="border">';
126 print '<tr><td width="30%">' . $langs->trans("ThirdPartyName") . '</td><td width="70%" colspan="3">';
127 $object->next_prev_filter = "te.fournisseur = 1";
128 print $form->showrefnav($object, 'socid', '', ($user->societe_id ? 0 : 1), 'rowid', 'nom', '', '');
129 print '</td></tr>';
130 
131 if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
132 {
133  print '<tr><td>' . $langs->trans('Prefix') . '</td><td colspan="3">' . $object->prefix_comm . '</td></tr>';
134 }
135 
136 print '<tr>';
137 print '<td class="nowrap">' . $langs->trans("CustomerCode") . '</td><td colspan="3">';
138 print $object->code_client;
139 if ($object->check_codeclient() != 0)
140  print ' <font class="error">(' . $langs->trans("WrongCustomerCode") . ')</font>';
141 print '</td>';
142 print '</tr>';
143 
144 $langs->load('compta');
145 print '<tr>';
146 print '<td>';
147 print $form->editfieldkey("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta, $object, $user->rights->societe->creer);
148 print '</td><td colspan="3">';
149 print $form->editfieldval("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta, $object, $user->rights->societe->creer);
150 print '</td>';
151 print '</tr>';
152 
153 // Address
154 print '<tr><td valign="top">' . $langs->trans("Address") . '</td><td colspan="3">';
155 dol_print_address($object->address, 'gmap', 'thirdparty', $object->id);
156 print '</td></tr>';
157 
158 // Zip / Town
159 print '<tr><td class="nowrap">' . $langs->trans("Zip") . ' / ' . $langs->trans("Town") . '</td><td colspan="3">' . $object->zip . (($object->zip && $object->town) ? ' / ' : '') . $object->town . '</td>';
160 print '</tr>';
161 
162 // Country
163 print '<tr><td>' . $langs->trans("Country") . '</td><td colspan="3">';
164 // $img=picto_from_langcode($object->country_code);
165 $img = '';
166 if ($object->isInEEC())
167  print $form->textwithpicto(($img ? $img . ' ' : '') . $object->country, $langs->trans("CountryIsInEEC"), 1, 0);
168 else
169  print ($img ? $img . ' ' : '') . $object->country;
170 print '</td></tr>';
171 
172 print '</table>';
173 
174 $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, ";
175 $sql .= " bk.thirdparty_code, bk.numero_compte , bk.label_compte, bk.debit, ";
176 $sql .= " bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering_code ";
177 $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk";
178 $sql .= " WHERE (bk.thirdparty_code = '" . $object->code_compta . "' AND bk.numero_compte = '" . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . "' )";
179 
180 if (dol_strlen($search_year)) {
181  $date_start = dol_mktime(0, 0, 0, 1, 1, $search_year);
182  $date_end = dol_mktime(23, 59, 59, 12, 31, $search_year);
183  $sql .= " AND ( bk.doc_date BETWEEN '" . $db->idate($date_start) . "' AND '" . $db->idate($date_end) . "' )";
184 }
185 
186 $sql .= $db->order($sortfield, $sortorder);
187 
188 $debit = 0;
189 $credit = 0;
190 $solde = 0;
191 // Count total nb of records and calc total sum
192 $nbtotalofrecords = '';
193 $resql = $db->query($sql);
194 if (! $resql) {
195  dol_print_error($db);
196  exit();
197 }
198 $nbtotalofrecords = $db->num_rows($resql);
199 
200 while ( $obj = $db->fetch_object($resql) ) {
201  $debit += $obj->debit;
202  $credit += $obj->credit;
203 
204  $solde += ($obj->credit - $obj->debit);
205 }
206 
207 $sql .= $db->plimit($limit + 1, $offset);
208 
209 dol_syslog("/accountancy/bookkeeping/thirdparty_lettrage.php", LOG_DEBUG);
210 $resql = $db->query($sql);
211 if (! $resql) {
212  dol_print_error($db);
213  exit();
214 }
215 
216 $num = $db->num_rows($resql);
217 
218 dol_syslog("/accountancy/bookkeeping/thirdparty_lettrage.php", LOG_DEBUG);
219 if ($resql) {
220  $i = 0;
221 
222  print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '" method="POST">';
223  print '<input type="hidden" name="socid" value="' . $object->id . '">';
224 
225  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
226 
227  print "<table class=\"noborder\" width=\"100%\">";
228  print '<tr class="liste_titre">';
229  print_liste_field_titre("Doctype", $_SERVER["PHP_SELF"], "bk.doc_type", "", $param, "", $sortfield, $sortorder);
230  print_liste_field_titre("Docdate", $_SERVER["PHP_SELF"], "bk.doc_date", "", $param, "", $sortfield, $sortorder);
231  print_liste_field_titre("Docref", $_SERVER["PHP_SELF"], "bk.doc_ref", "", $param, "", $sortfield, $sortorder);
232  print_liste_field_titre("Labelcompte", $_SERVER["PHP_SELF"], "bk.label_compte", "", $param, "", $sortfield, $sortorder);
233  print_liste_field_titre("Debit", $_SERVER["PHP_SELF"], "bk.debit", "", $param, "", $sortfield, $sortorder);
234  print_liste_field_titre("Credit", $_SERVER["PHP_SELF"], "bk.credit", "", $param, "", $sortfield, $sortorder);
235  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "bk.montant", "", $param, "", $sortfield, $sortorder);
236  print_liste_field_titre("Sens", $_SERVER["PHP_SELF"], "bk.sens", "", $param, "", $sortfield, $sortorder);
237  print_liste_field_titre("Codejournal", $_SERVER["PHP_SELF"], "bk.code_journal", "", $param, "", $sortfield, $sortorder);
238  print_liste_field_titre("Solde", $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder);
239  print '<td></td>';
240  print "</tr>\n";
241 
242  print '<tr class="liste_titre">';
243  print '<td><input type="text" name="search_doc_type" value="' . $search_doc_type . '"></td>';
244  print '<td><input type="text" name="search_year" value="' . $search_year . '"></td>';
245  print '<td><input type="text" name="search_doc_refe" value="' . $search_doc_ref . '"></td>';
246  print '<td colspan="7">&nbsp;</td>';
247  print '<td align="right">';
248  $searchpicto = $form->showFilterButtons();
249  print $searchpicto;
250  print '</td>';
251  print '</tr>';
252 
253  $var = false;
254  $solde = 0;
255  $tmp = '';
256  while ( $obj = $db->fetch_object($resql) ) {
257 
258  if ($tmp != $obj->lettering_code || empty($tmp))
259  $tmp = $obj->lettering_code;
260 
261  if ($tmp != $obj->lettering_code || empty($obj->lettering_code))
262  $var = ! $var;
263 
264  $solde += ($obj->credit - $obj->debit);
265 
266  print "<tr $bc[$var]>";
267 
268  if (empty($obj->lettering_code)) {
269  print '<td><a href="' . dol_buildpath('/accountancy/bookkeeping/card.php', 1) . '?piece_num=' . $obj->piece_num . '">';
270  print img_edit();
271  print '</a>&nbsp;' . $obj->doc_type . '</td>' . "\n";
272  } else
273  print '<td>' . $obj->doc_type . '</td>' . "\n";
274 
275  print '<td>' . dol_print_date($db->jdate($obj->doc_date), 'day') . '</td>';
276  print '<td>' . $obj->doc_ref . '</td>';
277  print '<td>' . $obj->label_compte . '</td>';
278  print '<td>' . price($obj->debit) . '</td>';
279  print '<td>' . price($obj->credit) . '</td>';
280  print '<td>' . price($obj->montant) . '</td>';
281  print '<td>' . $obj->sens . '</td>';
282  print '<td>' . $obj->code_journal . '</td>';
283  print '<td>' . round($solde, 2) . '</td>';
284 
285  if (empty($obj->lettering_code)) {
286  print '<td class="nowrap" align="center"><input type="checkbox" class="flat checkforselect" name="toselect[]" id="toselect[]" value="' . $obj->rowid . '" /></td>';
287  } else
288  print '<td>' . $obj->lettering_code . '</td>';
289 
290  print "</tr>\n";
291  }
292 
293  print '<tr class="oddeven">';
294 
295  print '<td colspan="4">Mouvement totaux</td>' . "\n";
296  print '<td><strong>' . price($debit) . '</strong></td>';
297  print '<td><strong>' . price($credit) . '</strong></td>';
298  print '<td colspan="5"></td>';
299  print "</tr>\n";
300 
301  print "<tr $bc[$var]>";
302  print '<td colspan="9">Solde Comptable</td>' . "\n";
303  print '<td><strong>' . price($credit - $debit) . '</strong></td>';
304  print '<td colspan="5"></td>';
305  print "</tr>\n";
306 
307  print "</table>";
308 
309  print '<input class="butAction" type="submit" value="lettering" name="lettering" id="lettering">';
310  print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '&action=autolettrage">' . $langs->trans('AccountancyAutoLettering') . '</a>';
311  print "</form>";
312  $db->free($resql);
313 } else {
314  dol_print_error($db);
315 }
316 
317 // End of page
318 llxFooter();
319 $db->close();
320 
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_htmloutput_mesg($mesgstring='', $mesgarray='', $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_address($address, $htmlid, $mode, $id, $noprint=0, $charfornl='')
Format address string.
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...)
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
Class lettering.
llxHeader()
Empty header.
Definition: wrapper.php:46
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:40
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).
print
Draft customers invoices.
Definition: index.php:91
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
Class to manage generation of HTML components for accounting management.
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:1013
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.