dolibarr  9.0.0
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2016 Frédéric France <frederic.france@free.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array('compta', 'banks', 'bills'));
33 
34 // Security check
35 $socid = isset($_GET["socid"])?$_GET["socid"]:'';
36 if ($user->societe_id) $socid=$user->societe_id;
37 $result = restrictedArea($user, 'tax', '', '', 'charges');
38 
39 $search_ref = GETPOST('search_ref','int');
40 $search_label = GETPOST('search_label','alpha');
41 $search_amount = GETPOST('search_amount','alpha');
42 $search_status = GETPOST('search_status','int');
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) { $page = 0; } // If $page is not defined, or '' or -1
49 $offset = $limit * $page;
50 $pageprev = $page - 1;
51 $pagenext = $page + 1;
52 if (! $sortfield) $sortfield="cs.date_ech";
53 if (! $sortorder) $sortorder="DESC";
54 
55 $year=GETPOST("year",'int');
56 $filtre=GETPOST("filtre",'int');
57 
58 if (! GETPOSTISSET('search_typeid'))
59 {
60  $newfiltre=str_replace('filtre=','',$filtre);
61  $filterarray=explode('-',$newfiltre);
62  foreach($filterarray as $val)
63  {
64  $part=explode(':',$val);
65  if ($part[0] == 'cs.fk_type') $search_typeid=$part[1];
66  }
67 }
68 else
69 {
70  $search_typeid=GETPOST('search_typeid','int');
71 }
72 
73 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers
74 {
75  $search_ref="";
76  $search_label="";
77  $search_amount="";
78  $search_status='';
79  $search_typeid="";
80  $year="";
81  $month="";
82 }
83 
84 
85 /*
86  * View
87  */
88 
89 $form = new Form($db);
90 $formsocialcontrib = new FormSocialContrib($db);
91 $chargesociale_static=new ChargeSociales($db);
92 
93 llxHeader('', $langs->trans("SocialContributions"));
94 
95 $sql = "SELECT cs.rowid as id, cs.fk_type as type, ";
96 $sql.= " cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode,";
97 $sql.= " c.libelle as type_lib,";
98 $sql.= " SUM(pc.amount) as alreadypayed";
99 $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
100 $sql.= " ".MAIN_DB_PREFIX."chargesociales as cs";
101 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid";
102 $sql.= " WHERE cs.fk_type = c.id";
103 $sql.= " AND cs.entity = ".$conf->entity;
104 // Search criteria
105 if ($search_ref) $sql.=" AND cs.rowid=".$db->escape($search_ref);
106 if ($search_label) $sql.=natural_search("cs.libelle", $search_label);
107 if ($search_amount) $sql.=natural_search("cs.amount", price2num(trim($search_amount)), 1);
108 if ($search_status != '' && $search_status >= 0) $sql.=" AND cs.paye = ".$db->escape($search_status);
109 if ($year > 0)
110 {
111  $sql .= " AND (";
112  // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
113  // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
114  $sql .= " (cs.periode IS NOT NULL AND date_format(cs.periode, '%Y') = '".$year."') ";
115  $sql .= "OR (cs.periode IS NULL AND date_format(cs.date_ech, '%Y') = '".$year."')";
116  $sql .= ")";
117 }
118 if ($filtre) {
119  $filtre=str_replace(":","=",$filtre);
120  $sql .= " AND ".$filtre;
121 }
122 if ($search_typeid) {
123  $sql .= " AND cs.fk_type=".$db->escape($search_typeid);
124 }
125 $sql.= " GROUP BY cs.rowid, cs.fk_type, cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode, c.libelle";
126 $sql.= $db->order($sortfield,$sortorder);
127 
128 $totalnboflines=0;
129 $result=$db->query($sql);
130 if ($result)
131 {
132  $totalnboflines = $db->num_rows($result);
133 }
134 $sql.= $db->plimit($limit+1,$offset);
135 
136 $resql=$db->query($sql);
137 if ($resql)
138 {
139  $num = $db->num_rows($resql);
140  $i = 0;
141 
142  $param='';
143  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
144  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
145  if ($search_ref) $param.='&search_ref='.urlencode($search_ref);
146  if ($search_label) $param.='&search_label='.urlencode($search_label);
147  if ($search_amount) $param.='&search_amount='.urlencode($search_amount);
148  if ($search_typeid) $param.='&search_typeid='.urlencode($search_typeid);
149  if ($search_status != '' && $search_status != '-1') $param.='&search_status='.urlencode($search_status);
150  if ($year) $param.='&year='.urlencode($year);
151 
152  $newcardbutton='';
153  if($user->rights->tax->charges->creer)
154  {
155  $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?action=create">'.$langs->trans('MenuNewSocialContribution');
156  $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
157  $newcardbutton.= '</a>';
158  }
159 
160  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
161  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
162  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
163  print '<input type="hidden" name="action" value="list">';
164  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
165  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
166  print '<input type="hidden" name="page" value="'.$page.'">';
167  print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
168 
169  if ($year)
170  {
171  $center=($year?"<a href='index.php?year=".($year-1)."'>".img_previous()."</a> ".$langs->trans("Year")." $year <a href='index.php?year=".($year+1)."'>".img_next()."</a>":"");
172  print_barre_liste($langs->trans("SocialContributions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $totalnboflines, 'title_accountancy.png', 0, $newcardbutton, '', $limit);
173  }
174  else
175  {
176  print_barre_liste($langs->trans("SocialContributions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, $newcardbutton, '', $limit);
177  }
178 
179  if (empty($mysoc->country_id) && empty($mysoc->country_code))
180  {
181  print '<div class="error">';
182  $langs->load("errors");
183  $countrynotdefined=$langs->trans("ErrorSetACountryFirst");
184  print $countrynotdefined;
185  print '</div>';
186  }
187  else
188  {
189  print '<div class="div-table-responsive">';
190  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
191 
192  print '<tr class="liste_titre_filter">';
193  // Ref
194  print '<td class="liste_titre" align="left">';
195  print '<input class="flat" type="text" size="3" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
196  print '</td>';
197  // Label
198  print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_label" value="'.dol_escape_htmltag($search_label).'"></td>';
199  // Type
200  print '<td class="liste_titre" align="left">';
201  $formsocialcontrib->select_type_socialcontrib($search_typeid,'search_typeid',1,0,0,'maxwidth100onsmartphone');
202  print '</td>';
203  // Period end date
204  print '<td class="liste_titre">&nbsp;</td>';
205  // Amount
206  print '<td class="liste_titre" align="right">';
207  print '<input class="flat" type="text" size="6" name="search_amount" value="'.dol_escape_htmltag($search_amount).'">';
208  print '</td>';
209  print '<td class="liste_titre">&nbsp;</td>';
210  // Status
211  print '<td class="liste_titre maxwidthonsmartphone" align="right">';
212  $liststatus=array('0'=>$langs->trans("Unpaid"), '1'=>$langs->trans("Paid"));
213  print $form->selectarray('search_status', $liststatus, $search_status, 1);
214  print '</td>';
215 
216  print '<td class="liste_titre" align="right">';
217  $searchpicto=$form->showFilterAndCheckAddButtons(0);
218  print $searchpicto;
219  print '</td>';
220  print "</tr>\n";
221 
222  print '<tr class="liste_titre">';
223  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"id","",$param,"",$sortfield,$sortorder);
224  print_liste_field_titre("Label",$_SERVER["PHP_SELF"],"cs.libelle","",$param,'align="left"',$sortfield,$sortorder);
225  print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
226  print_liste_field_titre("PeriodEndDate",$_SERVER["PHP_SELF"],"periode","",$param,'align="center"',$sortfield,$sortorder);
227  print_liste_field_titre("Amount",$_SERVER["PHP_SELF"],"cs.amount","",$param,'align="right"',$sortfield,$sortorder);
228  print_liste_field_titre("DateDue",$_SERVER["PHP_SELF"],"cs.date_ech","",$param,'align="center"',$sortfield,$sortorder);
229  print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"cs.paye","",$param,'align="right"',$sortfield,$sortorder);
230  print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
231  print "</tr>\n";
232 
233  $i=0;
234  $totalarray=array();
235  while ($i < min($num,$limit))
236  {
237  $obj = $db->fetch_object($resql);
238 
239  $chargesociale_static->id=$obj->id;
240  $chargesociale_static->ref=$obj->id;
241  $chargesociale_static->lib=$obj->libelle;
242  $chargesociale_static->type_libelle=$obj->type_lib;
243 
244  print '<tr class="oddeven">';
245 
246  // Ref
247  print '<td width="60">';
248  print $chargesociale_static->getNomUrl(1,'20');
249  print '</td>';
250 
251  // Label
252  print '<td>'.dol_trunc($obj->libelle,42).'</td>';
253 
254  // Type
255  print '<td>'.$obj->type_lib.'</td>';
256 
257  // Date end period
258  print '<td align="center">';
259  if ($obj->periode)
260  {
261  print '<a href="index.php?year='.strftime("%Y",$db->jdate($obj->periode)).'">'.dol_print_date($db->jdate($obj->periode),'day').'</a>';
262  }
263  else
264  {
265  print '&nbsp;';
266  }
267  print '</td>';
268 
269  // Amount
270  print '<td align="right" width="100">'.price($obj->amount).'</td>';
271  if (! $i) $totalarray['nbfield']++;
272  if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
273  $totalarray['totalttc'] += $obj->amount;
274 
275  // Due date
276  print '<td width="110" align="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
277 
278  print '<td align="right" class="nowrap">'.$chargesociale_static->LibStatut($obj->paye,5,$obj->alreadypayed).'</td>';
279 
280  print '<td></td>';
281 
282  print '</tr>';
283  $i++;
284  }
285 
286  // Show total line
287  if (isset($totalarray['totalttcfield']))
288  {
289  print '<tr class="liste_total">';
290  if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
291  else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
292  print '<td></td>';
293  print '<td></td>';
294  print '<td></td>';
295  print '<td align="right">'.price($totalarray['totalttc']).'</td>';
296  print '<td></td>';
297  print '<td></td>';
298  print '<td></td>';
299  print '</tr>';
300  }
301 
302  print '</table>';
303  print '</div>';
304  }
305  print '</form>';
306 }
307 else
308 {
309  dol_print_error($db);
310 }
311 
312 // End of page
313 llxFooter();
314 $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.
print
Draft customers invoices.
Definition: index.php:91
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_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
img_next($titlealt='default', $moreatt='')
Show next logo.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting a parameter.
Class to manage generation of HTML components for social contributions management.
llxHeader()
Empty header.
Definition: wrapper.php:44
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
Classe permettant la gestion des paiements des charges La tva collectee n&#39;est calculee que sur les fa...
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...