dolibarr  7.0.0-beta
thirdparty_lettrage_supplier.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 
29 // Dolibarr environment
30 require '../../main.inc.php';
31 
32 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
33 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
34 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php';
35 require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
36 require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
37 
38 $action = GETPOST('action', 'aZ09');
39 $massaction = GETPOST('massaction', 'alpha');
40 $show_files = GETPOST('show_files', 'int');
41 $confirm = GETPOST('confirm', 'alpha');
42 $toselect = GETPOST('toselect', 'array');
43 
44 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
45 $sortfield = GETPOST("sortfield", 'alpha');
46 $sortorder = GETPOST("sortorder", 'alpha');
47 $page = GETPOST("page", 'int');
48 if (empty($page) || $page == - 1) {
49  $page = 0;
50 } // If $page is not defined, or '' or -1
51 $offset = $limit * $page;
52 $pageprev = $page - 1;
53 $pagenext = $page + 1;
54 if ($sortorder == "")
55  $sortorder = "DESC";
56 if ($sortfield == "")
57  $sortfield = "bk.doc_date";
58 
59 $search_year = GETPOST("search_year",'int');
60 $search_doc_type = GETPOST("search_doc_type",'alpha');
61 $search_doc_ref = GETPOST("search_doc_ref",'alpha');
62 
63 $lettering = GETPOST('lettering');
64 if (!empty($lettering)) {
65  $action=$lettering;
66 }
67 $toselect = GETPOST('toselect','array');
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 {
73  $search_year='';
74  $search_doc_type='';
75  $search_doc_ref='';
76 }
77 
78 
79 // Security check
80 $socid = GETPOST("socid", 'int');
81 // if ($user->societe_id) $socid=$user->societe_id;
82 
83 $object = new Societe($db);
84 $object->id = $socid;
85 $result = $object->fetch($socid);
86 if ($result<0) {
87  setEventMessage($object->error,'errors');
88 }
89 
90 $form = new Form($db);
91 $BookKeeping = new lettering($db);
92 $formaccounting = new FormAccounting($db);
93 
94 /*
95  * Action
96  */
97 if ($action == 'lettering') {
98 
99  $result = $BookKeeping->updateLettrage($toselect);
100 
101  // var_dump($result);
102  if ($result < 0) {
103  setEventMessages('', $BookKeeping->errors, 'errors');
104  $error ++;
105  }
106 }
107 
108 if ($action == 'autolettrage') {
109 
110  $result = $BookKeeping->lettrageTiers($socid);
111 
112  if ($result < 0) {
113  setEventMessages('', $BookKeeping->errors, 'errors');
114  $error ++;
115  }
116 }
117 
118 $title = 'AccountancyLettrage';
119 
120 llxHeader('', $title);
121 
122 
123 $param='';
124 if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
125 if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
126 if (!empty($search_year)) $param.='&search_year='.$search_year;
127 if (!empty($socid)) $param.='&socid='.$socid;
128 if (!empty($search_doc_type)) $param.='&search_doc_type='.$search_doc_type;
129 if (!empty($search_doc_ref)) $param.='&search_doc_ref='.$search_doc_ref;
130 
131 
132 /*
133  * Affichage onglets
134  */
135 $head = societe_prepare_head($object);
136 
137 dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
138 
139 dol_fiche_head($head, 'accounting_supplier', $langs->trans("ThirdParty"), 0, 'company');
140 
141 print '<table width="100%" class="border">';
142 print '<tr><td width="30%">' . $langs->trans("ThirdPartyName") . '</td><td width="70%" colspan="3">';
143 $object->next_prev_filter = "te.fournisseur = 1";
144 print $form->showrefnav($object, 'socid', '', ($user->societe_id ? 0 : 1), 'rowid', 'nom', '', '');
145 print '</td></tr>';
146 
147 if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
148 {
149  print '<tr><td>' . $langs->trans('Prefix') . '</td><td colspan="3">' . $object->prefix_comm . '</td></tr>';
150 }
151 
152 print '<tr>';
153 print '<td class="nowrap">' . $langs->trans("SupplierCode") . '</td><td colspan="3">';
154 print $object->code_fournisseur;
155 if ($object->check_codefournisseur() != 0)
156  print ' <font class="error">(' . $langs->trans("WrongSupplierCode") . ')</font>';
157 print '</td>';
158 print '</tr>';
159 
160 $langs->load('compta');
161 print '<tr>';
162 print '<td>';
163 print $form->editfieldkey("SupplierAccountancyCode", 'supplieraccountancycode', $object->code_compta_fournisseur, $object, $user->rights->societe->creer);
164 print '</td><td colspan="3">';
165 print $form->editfieldval("SupplierAccountancyCode", 'supplieraccountancycode', $object->code_compta_fournisseur, $object, $user->rights->societe->creer);
166 print '</td>';
167 print '</tr>';
168 
169 // Address
170 print '<tr><td valign="top">' . $langs->trans("Address") . '</td><td colspan="3">';
171 dol_print_address($object->address, 'gmap', 'thirdparty', $object->id);
172 print '</td></tr>';
173 
174 // Zip / Town
175 print '<tr><td class="nowrap">' . $langs->trans("Zip") . ' / ' . $langs->trans("Town") . '</td><td colspan="3">' . $object->zip . (($object->zip && $object->town) ? ' / ' : '') . $object->town . '</td>';
176 print '</tr>';
177 
178 // Country
179 print '<tr><td>' . $langs->trans("Country") . '</td><td colspan="3">';
180 // $img=picto_from_langcode($object->country_code);
181 $img = '';
182 if ($object->isInEEC())
183  print $form->textwithpicto(($img ? $img . ' ' : '') . $object->country, $langs->trans("CountryIsInEEC"), 1, 0);
184 else
185  print ($img ? $img . ' ' : '') . $object->country;
186 print '</td></tr>';
187 
188 print '</table>';
189 
190 $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, ";
191 $sql .= " bk.thirdparty_code, bk.numero_compte , bk.label_compte, bk.debit, ";
192 $sql .= " bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering_code ";
193 $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk";
194 $sql .= " WHERE (bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' AND bk.numero_compte = '" . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . "' )";
195 
196 if (dol_strlen($search_year)) {
197  $date_start = dol_mktime(0, 0, 0, 1, 1, $search_year);
198  $date_end = dol_mktime(23, 59, 59, 12, 31, $search_year);
199  $sql .= " AND ( bk.doc_date BETWEEN '".$db->idate($date_start)."' AND '".$db->idate($date_end)."' )";
200 }
201 
202 $sql.= $db->order($sortfield,$sortorder);
203 
204 $debit = 0;
205 $credit = 0;
206 $solde = 0;
207 // Count total nb of records and calc total sum
208 $nbtotalofrecords = '';
209 $resql = $db->query($sql);
210 if (! $resql)
211 {
212  dol_print_error($db);
213  exit;
214 }
215 $nbtotalofrecords = $db->num_rows($resql);
216 
217 while ($obj = $db->fetch_object($resql)) {
218  $debit += $obj->debit;
219  $credit += $obj->credit;
220 
221  $solde += ($obj->credit - $obj->debit);
222 }
223 
224 $sql.= $db->plimit($limit+1, $offset);
225 
226 dol_syslog ( "/accountancy/bookkeeping/thirdparty_lettrage_supplier.php", LOG_DEBUG );
227 $resql = $db->query($sql);
228 if (! $resql)
229 {
230  dol_print_error($db);
231  exit;
232 }
233 
234 $num = $db->num_rows($resql);
235 
236 dol_syslog ( "/accountancy/bookkeeping/thirdparty_lettrage_supplier.php", LOG_DEBUG );
237 $resql = $db->query($sql);
238 if ($resql) {
239  $num = $db->num_rows($resql);
240  $i = 0;
241 
242  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'?socid=' . $object->id . '" method="POST">';
243  print '<input type="hidden" name="socid" value="' . $object->id . '">';
244 
245  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
246 
247  print "<table class=\"noborder\" width=\"100%\">";
248  print '<tr class="liste_titre">';
249  print_liste_field_titre("Doctype", $_SERVER["PHP_SELF"], "bk.doc_type","",$param,"",$sortfield,$sortorder);
250  print_liste_field_titre("Docdate", $_SERVER["PHP_SELF"], "bk.doc_date","",$param,"",$sortfield,$sortorder);
251  print_liste_field_titre("Docref", $_SERVER["PHP_SELF"], "bk.doc_ref","",$param,"",$sortfield,$sortorder);
252  print_liste_field_titre("Labelcompte", $_SERVER["PHP_SELF"], "bk.label_compte","",$param,"",$sortfield,$sortorder);
253  print_liste_field_titre("Debit", $_SERVER["PHP_SELF"], "bk.debit","",$param,"",$sortfield,$sortorder);
254  print_liste_field_titre("Credit", $_SERVER["PHP_SELF"], "bk.credit","",$param,"",$sortfield,$sortorder);
255  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "bk.montant","",$param,"",$sortfield,$sortorder);
256  print_liste_field_titre("Sens", $_SERVER["PHP_SELF"], "bk.sens","",$param,"",$sortfield,$sortorder);
257  print_liste_field_titre("Codejournal", $_SERVER["PHP_SELF"], "bk.code_journal","",$param,"",$sortfield,$sortorder);
258  print_liste_field_titre("Solde", $_SERVER["PHP_SELF"], "","",$param,"",$sortfield,$sortorder);
259  print '<td></td>';
260  print "</tr>\n";
261 
262  print '<tr class="liste_titre">';
263  print '<td><input type="text" name="search_doc_type" value="' . $search_doc_type . '"></td>';
264  print '<td><input type="text" name="search_year" value="' . $search_year . '"></td>';
265  print '<td><input type="text" name="search_doc_refe" value="' . $search_doc_ref . '"></td>';
266  print '<td colspan="7">&nbsp;</td>';
267  print '<td align="right">';
268  $searchpicto=$form->showFilterButtons();
269  print $searchpicto;
270  print '</td>';
271  print '</tr>';
272 
273  $var = false;
274  $solde = 0;
275  $tmp = '';
276  while ($obj = $db->fetch_object($resql)) {
277 
278  if ($tmp != $obj->lettering_code || empty($tmp))
279  $tmp = $obj->lettering_code;
280 
281  if ($tmp != $obj->lettering_code || empty($obj->lettering_code))
282  $var = ! $var;
283 
284  $solde += ($obj->credit - $obj->debit);
285 
286  print "<tr $bc[$var]>";
287 
288  if (empty($obj->lettering_code)) {
289  print '<td><a href="' . dol_buildpath('/accountancy/bookkeeping/card.php', 1) . '?piece_num=' . $obj->piece_num . '">';
290  print img_edit();
291  print '</a>&nbsp;' . $obj->doc_type . '</td>' . "\n";
292  } else
293  print '<td>' . $obj->doc_type . '</td>' . "\n";
294 
295  print '<td>' . dol_print_date($db->jdate($obj->doc_date), 'day') . '</td>';
296  print '<td>' . $obj->doc_ref . '</td>';
297  print '<td>' . $obj->label_compte . '</td>';
298  print '<td>' . price($obj->debit) . '</td>';
299  print '<td>' . price($obj->credit) . '</td>';
300  print '<td>' . price($obj->montant) . '</td>';
301  print '<td>' . $obj->sens . '</td>';
302  print '<td>' . $obj->code_journal . '</td>';
303  print '<td>' . round($solde, 2) . '</td>';
304 
305  if (empty($obj->lettering_code)) {
306  print '<td class="nowrap" align="center"><input type="checkbox" class="flat checkforselect" name="toselect[]" id="toselect[]" value="' . $obj->rowid . '" /></td>';
307  } else
308  print '<td>' . $obj->lettering_code . '</td>';
309 
310  print "</tr>\n";
311  }
312 
313  print '<tr class="oddeven">';
314 
315  print '<td colspan="4">Mouvement totaux</td>' . "\n";
316  print '<td><strong>' . price($debit) . '</strong></td>';
317  print '<td><strong>' . price($credit) . '</strong></td>';
318  print '<td colspan="5"></td>';
319  print "</tr>\n";
320 
321  print "<tr $bc[$var]>";
322  print '<td colspan="9">Solde Comptable</td>' . "\n";
323  print '<td><strong>' . price($credit - $debit) . '</strong></td>';
324  print '<td colspan="5"></td>';
325  print "</tr>\n";
326 
327  print "</table>";
328 
329  print '<input class="butAction" type="submit" value="lettering" name="lettering" id="lettering">';
330  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid=' . $object->id . '&action=autolettrage">'.$langs->trans('AccountancyAutoLettering').'</a>';
331  print "</form>";
332  $db->free($resql);
333 } else {
334  dol_print_error($db);
335 }
336 
337 // End of page
338 llxFooter();
339 $db->close();
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.