dolibarr  7.0.0-beta
index.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@capnetworks.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 $langs->load("compta");
32 $langs->load("banks");
33 $langs->load("bills");
34 
35 // Security check
36 $socid = isset($_GET["socid"])?$_GET["socid"]:'';
37 if ($user->societe_id) $socid=$user->societe_id;
38 $result = restrictedArea($user, 'tax', '', '', 'charges');
39 
40 $search_ref = GETPOST('search_ref','int');
41 $search_label = GETPOST('search_label','alpha');
42 $search_amount = GETPOST('search_amount','alpha');
43 $search_status = GETPOST('search_status','int');
44 
45 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
46 $sortfield = GETPOST("sortfield",'alpha');
47 $sortorder = GETPOST("sortorder",'alpha');
48 $page = GETPOST("page",'int');
49 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
50 $offset = $limit * $page;
51 $pageprev = $page - 1;
52 $pagenext = $page + 1;
53 if (! $sortfield) $sortfield="cs.date_ech";
54 if (! $sortorder) $sortorder="DESC";
55 
56 $year=GETPOST("year",'int');
57 $filtre=GETPOST("filtre",'int');
58 
59 if (empty($_REQUEST['typeid']))
60 {
61  $newfiltre=str_replace('filtre=','',$filtre);
62  $filterarray=explode('-',$newfiltre);
63  foreach($filterarray as $val)
64  {
65  $part=explode(':',$val);
66  if ($part[0] == 'cs.fk_type') $typeid=$part[1];
67  }
68 }
69 else
70 {
71  $typeid=$_REQUEST['typeid'];
72 }
73 
74 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
75 {
76  $search_ref="";
77  $search_label="";
78  $search_amount="";
79  $search_status='';
80  $typeid="";
81  $year="";
82  $month="";
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 ($typeid) {
123  $sql .= " AND cs.fk_type=".$db->escape($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  $var=true;
142 
143  $param='';
144  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
145  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
146  if ($year) $param.='&amp;year='.$year;
147  if ($typeid) $param.='&amp;typeid='.$typeid;
148 
149  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
150  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
151  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
152  print '<input type="hidden" name="action" value="list">';
153  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
154  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
155  print '<input type="hidden" name="page" value="'.$page.'">';
156  print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
157 
158  if ($year)
159  {
160  $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>":"");
161  print_barre_liste($langs->trans("SocialContributions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
162  }
163  else
164  {
165  print_barre_liste($langs->trans("SocialContributions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
166  }
167 
168  if (empty($mysoc->country_id) && empty($mysoc->country_code))
169  {
170  print '<div class="error">';
171  $langs->load("errors");
172  $countrynotdefined=$langs->trans("ErrorSetACountryFirst");
173  print $countrynotdefined;
174  print '</div>';
175  }
176  else
177  {
178  print '<div class="div-table-responsive">';
179  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
180 
181  print '<tr class="liste_titre_filter">';
182  // Ref
183  print '<td class="liste_titre" align="left">';
184  print '<input class="flat" type="text" size="3" name="search_ref" value="'.$search_ref.'">';
185  print '</td>';
186  // Label
187  print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_label" value="'.$search_label.'"></td>';
188  // Type
189  print '<td class="liste_titre" align="left">';
190  $formsocialcontrib->select_type_socialcontrib($typeid,'typeid',1,0,0,'maxwidth100onsmartphone');
191  print '</td>';
192  // Period end date
193  print '<td class="liste_titre">&nbsp;</td>';
194  // Amount
195  print '<td class="liste_titre" align="right">';
196  print '<input class="flat" type="text" size="6" name="search_amount" value="'.$search_amount.'">';
197  print '</td>';
198  print '<td class="liste_titre">&nbsp;</td>';
199  // Status
200  print '<td class="liste_titre maxwidthonsmartphone" align="right">';
201  $liststatus=array('0'=>$langs->trans("Unpaid"), '1'=>$langs->trans("Paid"));
202  print $form->selectarray('search_status', $liststatus, $search_status, 1);
203  print '</td>';
204 
205  print '<td class="liste_titre" align="right">';
206  $searchpicto=$form->showFilterAndCheckAddButtons(0);
207  print $searchpicto;
208  print '</td>';
209  print "</tr>\n";
210 
211  print '<tr class="liste_titre">';
212  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"id","",$param,"",$sortfield,$sortorder);
213  print_liste_field_titre("Label",$_SERVER["PHP_SELF"],"cs.libelle","",$param,'align="left"',$sortfield,$sortorder);
214  print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
215  print_liste_field_titre("PeriodEndDate",$_SERVER["PHP_SELF"],"periode","",$param,'align="center"',$sortfield,$sortorder);
216  print_liste_field_titre("Amount",$_SERVER["PHP_SELF"],"cs.amount","",$param,'align="right"',$sortfield,$sortorder);
217  print_liste_field_titre("DateDue",$_SERVER["PHP_SELF"],"cs.date_ech","",$param,'align="center"',$sortfield,$sortorder);
218  print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"cs.paye","",$param,'align="right"',$sortfield,$sortorder);
219  print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
220  print "</tr>\n";
221 
222  $i=0;
223  $totalarray=array();
224  while ($i < min($num,$limit))
225  {
226  $obj = $db->fetch_object($resql);
227 
228  print '<tr class="oddeven">';
229 
230  // Ref
231  print '<td width="60">';
232  $chargesociale_static->id=$obj->id;
233  $chargesociale_static->lib=$obj->id;
234  $chargesociale_static->ref=$obj->id;
235  print $chargesociale_static->getNomUrl(1,'20');
236  print '</td>';
237 
238  // Label
239  print '<td>'.dol_trunc($obj->libelle,42).'</td>';
240 
241  // Type
242  print '<td>'.$obj->type_lib.'</td>';
243 
244  // Date end period
245  print '<td align="center">';
246  if ($obj->periode)
247  {
248  print '<a href="index.php?year='.strftime("%Y",$db->jdate($obj->periode)).'">'.dol_print_date($db->jdate($obj->periode),'day').'</a>';
249  }
250  else
251  {
252  print '&nbsp;';
253  }
254  print '</td>';
255 
256  // Amount
257  print '<td align="right" width="100">'.price($obj->amount).'</td>';
258  if (! $i) $totalarray['nbfield']++;
259  if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
260  $totalarray['totalttc'] += $obj->amount;
261 
262  // Due date
263  print '<td width="110" align="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
264 
265  print '<td align="right" class="nowrap">'.$chargesociale_static->LibStatut($obj->paye,5,$obj->alreadypayed).'</td>';
266 
267  print '<td></td>';
268 
269  print '</tr>';
270  $i++;
271  }
272 
273  // Show total line
274  if (isset($totalarray['totalttcfield']))
275  {
276  print '<tr class="liste_total">';
277  if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
278  else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
279  print '<td></td>';
280  print '<td></td>';
281  print '<td></td>';
282  print '<td align="right">'.price($totalarray['totalttc']).'</td>';
283  print '<td></td>';
284  print '<td></td>';
285  print '<td></td>';
286  print '</tr>';
287  }
288 
289  print '</table>';
290  print '</div>';
291  }
292  print '</form>';
293 }
294 else
295 {
296  dol_print_error($db);
297 }
298 
299 llxFooter();
300 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
img_previous($titlealt= 'default', $moreatt='')
Show previous logo.
img_next($titlealt= 'default', $moreatt='')
Show next logo.
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
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
llxHeader()
Header empty.
Definition: index.php:37
Class to manage generation of HTML components for social contributions management.
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).
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:1013
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.