dolibarr  7.0.0-beta
reglement.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2011-2017 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
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/tva/class/tva.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
33 
34 $langs->load("compta");
35 $langs->load("bills");
36 
37 // Security check
38 $socid = isset($_GET["socid"])?$_GET["socid"]:'';
39 if ($user->societe_id) $socid=$user->societe_id;
40 $result = restrictedArea($user, 'tax', '', '', 'charges');
41 
42 $search_ref = GETPOST('search_ref','int');
43 $search_label = GETPOST('search_label','alpha');
44 $search_amount = GETPOST('search_amount','alpha');
45 $search_account = GETPOST('search_account','int');
46 $month = GETPOST("month","int");
47 $year = GETPOST("year","int");
48 
49 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
50 $sortfield = GETPOST("sortfield",'alpha');
51 $sortorder = GETPOST("sortorder",'alpha');
52 $page = GETPOST("page",'int');
53 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
54 $offset = $limit * $page;
55 $pageprev = $page - 1;
56 $pagenext = $page + 1;
57 if (! $sortfield) $sortfield="t.datev";
58 if (! $sortorder) $sortorder="DESC";
59 
60 $filtre=$_GET["filtre"];
61 
62 if (empty($_REQUEST['typeid']))
63 {
64  $newfiltre=str_replace('filtre=','',$filtre);
65  $filterarray=explode('-',$newfiltre);
66  foreach($filterarray as $val)
67  {
68  $part=explode(':',$val);
69  if ($part[0] == 't.fk_typepayment') $typeid=$part[1];
70  }
71 }
72 else
73 {
74  $typeid=$_REQUEST['typeid'];
75 }
76 
77 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers
78 {
79  $search_ref="";
80  $search_label="";
81  $search_amount="";
82  $search_account='';
83  $year="";
84  $month="";
85  $typeid="";
86 }
87 
88 
89 /*
90  * View
91  */
92 
93 llxHeader('', $langs->trans("VATPayments"));
94 
95 $form = new Form($db);
96 $formother=new FormOther($db);
97 $tva_static = new Tva($db);
98 $bankstatic = new Account($db);
99 
100 $sql = "SELECT t.rowid, t.amount, t.label, t.datev as dv, t.datep as dp, t.fk_typepayment as type, t.num_payment, t.fk_bank, pst.code as payment_code,";
101 $sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel";
102 $sql.= " FROM ".MAIN_DB_PREFIX."tva as t";
103 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON t.fk_typepayment = pst.id AND pst.entity IN (".getEntity('c_paiement').")";
104 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON t.fk_bank = b.rowid";
105 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
106 $sql.= " WHERE t.entity IN (".getEntity('tax').")";
107 if ($search_ref) $sql.= natural_search("t.rowid", $search_ref);
108 if ($search_label) $sql.= natural_search("t.label", $search_label);
109 if ($search_amount) $sql.= natural_search("t.amount", price2num(trim($search_amount)), 1);
110 if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account;
111 if ($month > 0)
112 {
113  if ($year > 0)
114  $sql.= " AND t.datev BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
115  else
116  $sql.= " AND date_format(t.datev, '%m') = '$month'";
117 }
118 else if ($year > 0)
119 {
120  $sql.= " AND t.datev BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
121 }
122 if ($filtre) {
123  $filtre=str_replace(":","=",$filtre);
124  $sql .= " AND ".$filtre;
125 }
126 if ($typeid) {
127  $sql .= " AND t.fk_typepayment=".$typeid;
128 }
129 $sql.= $db->order($sortfield,$sortorder);
130 $totalnboflines=0;
131 $result=$db->query($sql);
132 if ($result)
133 {
134  $totalnboflines = $db->num_rows($result);
135 }
136 $sql.= $db->plimit($limit+1,$offset);
137 
138 $result = $db->query($sql);
139 if ($result)
140 {
141  $num = $db->num_rows($result);
142  $i = 0;
143  $total = 0 ;
144  $var=true;
145 
146  $param='';
147  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
148  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
149  if ($typeid) $param.='&amp;typeid='.$typeid;
150 
151 
152  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
153  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
154  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
155  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
156  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
157  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
158  print '<input type="hidden" name="page" value="'.$page.'">';
159 
160  print_barre_liste($langs->trans("VATPayments"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$totalnboflines, 'title_accountancy', 0, '', '', $limit);
161 
162  print '<div class="div-table-responsive">';
163  print '<table class="noborder" width="100%">';
164 
165  print '<tr class="liste_titre_filter">';
166  print '<td class="liste_titre"><input type="text" class="flat" size="4" name="search_ref" value="'.$search_ref.'"></td>';
167  print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.$search_label.'"></td>';
168  print '<td class="liste_titre"></td>';
169  print '<td class="liste_titre" colspan="1" align="center">';
170  print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
171  $syear = $year;
172  $formother->select_year($syear?$syear:-1,'year',1, 20, 5);
173  print '</td>';
174  // Type
175  print '<td class="liste_titre" align="left">';
176  $form->select_types_paiements($typeid,'typeid','',0,0,1,16);
177  print '</td>';
178  // Account
179  if (! empty($conf->banque->enabled))
180  {
181  print '<td class="liste_titre">';
182  $form->select_comptes($search_account,'search_account',0,'',1);
183  print '</td>';
184  }
185  print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
186  print '<td class="liste_titre" align="right">';
187  $searchpicto=$form->showFilterAndCheckAddButtons(0);
188  print $searchpicto;
189  print '</td>';
190  print "</tr>\n";
191 
192  print '<tr class="liste_titre">';
193  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"t.rowid","",$param,"",$sortfield,$sortorder);
194  print_liste_field_titre("Label",$_SERVER["PHP_SELF"],"t.label","",$param,'align="left"',$sortfield,$sortorder);
195  print_liste_field_titre("DateValue",$_SERVER["PHP_SELF"],"dv","",$param,'align="center"',$sortfield,$sortorder);
196  print_liste_field_titre("DatePayment",$_SERVER["PHP_SELF"],"dp","",$param,'align="center"',$sortfield,$sortorder);
197  print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
198  if (! empty($conf->banque->enabled)) print_liste_field_titre("Account",$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder);
199  print_liste_field_titre("PayedByThisPayment",$_SERVER["PHP_SELF"],"t.amount","",$param,'align="right"',$sortfield,$sortorder);
200  print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
201  print "</tr>\n";
202 
203  while ($i < min($num,$limit))
204  {
205  $obj = $db->fetch_object($result);
206 
207  if ($obj->payment_code <> '')
208  {
209  $type = '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>';
210  }
211  else
212  {
213  $type = '<td>&nbsp;</td>';
214  }
215 
216  print '<tr class="oddeven">';
217 
218  $tva_static->id=$obj->rowid;
219  $tva_static->ref=$obj->rowid;
220  print "<td>".$tva_static->getNomUrl(1)."</td>\n";
221  print "<td>".dol_trunc($obj->label,40)."</td>\n";
222  print '<td align="center">'.dol_print_date($db->jdate($obj->dv),'day')."</td>\n";
223  print '<td align="center">'.dol_print_date($db->jdate($obj->dp),'day')."</td>\n";
224  // Type
225  print $type;
226  // Account
227  if (! empty($conf->banque->enabled))
228  {
229  print '<td>';
230  if ($obj->fk_bank > 0)
231  {
232  $bankstatic->id=$obj->bid;
233  $bankstatic->ref=$obj->bref;
234  $bankstatic->number=$obj->bnumber;
235  $bankstatic->account_number=$obj->account_number;
236 
237  $accountingjournal = new AccountingJournal($db);
238  $accountingjournal->fetch($obj->fk_accountancy_journal);
239  $bankstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1);
240 
241  $bankstatic->label=$obj->blabel;
242  print $bankstatic->getNomUrl(1);
243  }
244  else print '&nbsp;';
245  print '</td>';
246  }
247  // Amount
248  $total = $total + $obj->amount;
249  print "<td align=\"right\">".price($obj->amount)."</td>";
250  print "<td>&nbsp;</td>";
251  print "</tr>\n";
252 
253  $i++;
254  }
255 
256  $colspan=5;
257  if (! empty($conf->banque->enabled)) $colspan++;
258  print '<tr class="liste_total"><td colspan="'.$colspan.'">'.$langs->trans("Total").'</td>';
259  print "<td align=\"right\"><b>".price($total)."</b></td>";
260  print "<td>&nbsp;</td></tr>";
261 
262  print "</table>";
263  print '</div>';
264 
265  print '</form>';
266 
267  $db->free($result);
268 }
269 else
270 {
271  dol_print_error($db);
272 }
273 
274 
275 llxFooter();
276 
277 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:445
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
Class to manage bank accounts.
Put here description of your class.
Definition: tva.class.php:33
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.
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:46
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
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_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:459
print
Draft customers invoices.
Definition: index.php:91
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
Class to manage accounting accounts.
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.