reglement.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. /**
  21. * \file htdocs/compta/tva/reglement.php
  22. * \ingroup tax
  23. * \brief List of VAT payments
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  31. $langs->load("compta");
  32. $langs->load("bills");
  33. // Security check
  34. $socid = isset($_GET["socid"])?$_GET["socid"]:'';
  35. if ($user->societe_id) $socid=$user->societe_id;
  36. $result = restrictedArea($user, 'tax', '', '', 'charges');
  37. $search_ref = GETPOST('search_ref','int');
  38. $search_label = GETPOST('search_label','alpha');
  39. $search_amount = GETPOST('search_amount','alpha');
  40. $search_account = GETPOST('search_account','int');
  41. $month = GETPOST("month","int");
  42. $year = GETPOST("year","int");
  43. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  44. $sortfield = GETPOST("sortfield",'alpha');
  45. $sortorder = GETPOST("sortorder",'alpha');
  46. $page = GETPOST("page",'int');
  47. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  48. $offset = $limit * $page;
  49. $pageprev = $page - 1;
  50. $pagenext = $page + 1;
  51. if (! $sortfield) $sortfield="t.datev";
  52. if (! $sortorder) $sortorder="DESC";
  53. $filtre=$_GET["filtre"];
  54. if (empty($_REQUEST['typeid']))
  55. {
  56. $newfiltre=str_replace('filtre=','',$filtre);
  57. $filterarray=explode('-',$newfiltre);
  58. foreach($filterarray as $val)
  59. {
  60. $part=explode(':',$val);
  61. if ($part[0] == 't.fk_typepayment') $typeid=$part[1];
  62. }
  63. }
  64. else
  65. {
  66. $typeid=$_REQUEST['typeid'];
  67. }
  68. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
  69. {
  70. $search_ref="";
  71. $search_label="";
  72. $search_amount="";
  73. $search_account='';
  74. $year="";
  75. $month="";
  76. $typeid="";
  77. }
  78. /*
  79. * View
  80. */
  81. llxHeader('', $langs->trans("VATPayments"));
  82. $form = new Form($db);
  83. $formother=new FormOther($db);
  84. $tva_static = new Tva($db);
  85. $bankstatic = new Account($db);
  86. $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,";
  87. $sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel";
  88. $sql.= " FROM ".MAIN_DB_PREFIX."tva as t";
  89. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON t.fk_typepayment = pst.id";
  90. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON t.fk_bank = b.rowid";
  91. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  92. $sql.= " WHERE t.entity = ".$conf->entity;
  93. if ($search_ref) $sql.=" AND t.rowid=".$search_ref;
  94. if ($search_label) $sql.=" AND t.label LIKE '%".$db->escape($search_label)."%'";
  95. if ($search_amount) $sql.=" AND t.amount='".$db->escape(price2num(trim($search_amount)))."'";
  96. if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account;
  97. if ($month > 0)
  98. {
  99. if ($year > 0)
  100. $sql.= " AND t.datev BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
  101. else
  102. $sql.= " AND date_format(t.datev, '%m') = '$month'";
  103. }
  104. else if ($year > 0)
  105. {
  106. $sql.= " AND t.datev BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  107. }
  108. if ($filtre) {
  109. $filtre=str_replace(":","=",$filtre);
  110. $sql .= " AND ".$filtre;
  111. }
  112. if ($typeid) {
  113. $sql .= " AND t.fk_typepayment=".$typeid;
  114. }
  115. $sql.= $db->order($sortfield,$sortorder);
  116. $totalnboflines=0;
  117. $result=$db->query($sql);
  118. if ($result)
  119. {
  120. $totalnboflines = $db->num_rows($result);
  121. }
  122. $sql.= $db->plimit($limit+1,$offset);
  123. $result = $db->query($sql);
  124. if ($result)
  125. {
  126. $num = $db->num_rows($result);
  127. $i = 0;
  128. $total = 0 ;
  129. $var=true;
  130. $param='';
  131. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  132. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  133. if ($typeid) $param.='&amp;typeid='.$typeid;
  134. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  135. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  136. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  137. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  138. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  139. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  140. print '<input type="hidden" name="page" value="'.$page.'">';
  141. print_barre_liste($langs->trans("VATPayments"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$totalnboflines, 'title_accountancy', 0, '', '', $limit);
  142. print '<div class="div-table-responsive">';
  143. print '<table class="noborder" width="100%">';
  144. print '<tr class="liste_titre_filter">';
  145. print '<td class="liste_titre"><input type="text" class="flat" size="4" name="search_ref" value="'.$search_ref.'"></td>';
  146. print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.$search_label.'"></td>';
  147. print '<td class="liste_titre"></td>';
  148. print '<td class="liste_titre" colspan="1" align="center">';
  149. print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
  150. $syear = $year;
  151. $formother->select_year($syear?$syear:-1,'year',1, 20, 5);
  152. print '</td>';
  153. // Type
  154. print '<td class="liste_titre" align="left">';
  155. $form->select_types_paiements($typeid,'typeid','',0,0,1,16);
  156. print '</td>';
  157. // Account
  158. if (! empty($conf->banque->enabled))
  159. {
  160. print '<td class="liste_titre">';
  161. $form->select_comptes($search_account,'search_account',0,'',1);
  162. print '</td>';
  163. }
  164. print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>';
  165. print '<td class="liste_titre" align="right">';
  166. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  167. print $searchpicto;
  168. print '</td>';
  169. print "</tr>\n";
  170. print '<tr class="liste_titre">';
  171. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"t.rowid","",$param,"",$sortfield,$sortorder);
  172. print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"t.label","",$param,'align="left"',$sortfield,$sortorder);
  173. print_liste_field_titre($langs->trans("DateValue"),$_SERVER["PHP_SELF"],"dv","",$param,'align="center"',$sortfield,$sortorder);
  174. print_liste_field_titre($langs->trans("DatePayment"),$_SERVER["PHP_SELF"],"dp","",$param,'align="center"',$sortfield,$sortorder);
  175. print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
  176. if (! empty($conf->banque->enabled)) print_liste_field_titre($langs->trans("Account"),$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder);
  177. print_liste_field_titre($langs->trans("PayedByThisPayment"),$_SERVER["PHP_SELF"],"t.amount","",$param,'align="right"',$sortfield,$sortorder);
  178. print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
  179. print "</tr>\n";
  180. while ($i < min($num,$limit))
  181. {
  182. $obj = $db->fetch_object($result);
  183. if ($obj->payment_code <> '')
  184. {
  185. $type = '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>';
  186. }
  187. else
  188. {
  189. $type = '<td>&nbsp;</td>';
  190. }
  191. print '<tr class="oddeven">';
  192. $tva_static->id=$obj->rowid;
  193. $tva_static->ref=$obj->rowid;
  194. print "<td>".$tva_static->getNomUrl(1)."</td>\n";
  195. print "<td>".dol_trunc($obj->label,40)."</td>\n";
  196. print '<td align="center">'.dol_print_date($db->jdate($obj->dv),'day')."</td>\n";
  197. print '<td align="center">'.dol_print_date($db->jdate($obj->dp),'day')."</td>\n";
  198. // Type
  199. print $type;
  200. // Account
  201. if (! empty($conf->banque->enabled))
  202. {
  203. print '<td>';
  204. if ($obj->fk_bank > 0)
  205. {
  206. $bankstatic->id=$obj->bid;
  207. $bankstatic->ref=$obj->bref;
  208. $bankstatic->number=$obj->bnumber;
  209. $bankstatic->account_number=$obj->account_number;
  210. $accountingjournal = new AccountingJournal($db);
  211. $accountingjournal->fetch($obj->fk_accountancy_journal);
  212. $bankstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1);
  213. $bankstatic->label=$obj->blabel;
  214. print $bankstatic->getNomUrl(1);
  215. }
  216. else print '&nbsp;';
  217. print '</td>';
  218. }
  219. // Amount
  220. $total = $total + $obj->amount;
  221. print "<td align=\"right\">".price($obj->amount)."</td>";
  222. print "<td>&nbsp;</td>";
  223. print "</tr>\n";
  224. $i++;
  225. }
  226. $colspan=5;
  227. if (! empty($conf->banque->enabled)) $colspan++;
  228. print '<tr class="liste_total"><td colspan="'.$colspan.'">'.$langs->trans("Total").'</td>';
  229. print "<td align=\"right\"><b>".price($total)."</b></td>";
  230. print "<td>&nbsp;</td></tr>";
  231. print "</table>";
  232. print '</div>';
  233. print '</form>';
  234. $db->free($result);
  235. }
  236. else
  237. {
  238. dol_print_error($db);
  239. }
  240. llxFooter();
  241. $db->close();