PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/facture/list.old.php

https://bitbucket.org/speedealing/speedealing
PHP | 422 lines | 322 code | 51 blank | 49 comment | 64 complexity | 3e03a1a6f7467ed2b1307436ecafff29 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  4. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  7. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  8. * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/compta/facture/list.php
  26. * \ingroup facture
  27. * \brief Page to create/see an invoice
  28. */
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  33. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  39. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  40. if (! empty($conf->projet->enabled))
  41. {
  42. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  44. }
  45. $langs->load('bills');
  46. $langs->load('companies');
  47. $langs->load('products');
  48. $langs->load('main');
  49. $sall=trim(GETPOST('sall'));
  50. $projectid=(GETPOST('projectid')?GETPOST('projectid','int'):0);
  51. $id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int')); // For backward compatibility
  52. $ref=GETPOST('ref','alpha');
  53. $socid=GETPOST('socid','int');
  54. $action=GETPOST('action','alpha');
  55. $confirm=GETPOST('confirm','alpha');
  56. $lineid=GETPOST('lineid','int');
  57. $userid=GETPOST('userid','int');
  58. $search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha');
  59. $search_societe=GETPOST('search_societe','alpha');
  60. $search_montant_ht=GETPOST('search_montant_ht','alpha');
  61. $search_montant_ttc=GETPOST('search_montant_ttc','alpha');
  62. $sortfield = GETPOST("sortfield",'alpha');
  63. $sortorder = GETPOST("sortorder",'alpha');
  64. $page = GETPOST("page",'int');
  65. if ($page == -1) {
  66. $page = 0;
  67. }
  68. $offset = $conf->liste_limit * $page;
  69. if (! $sortorder) $sortorder='DESC';
  70. if (! $sortfield) $sortfield='f.datef';
  71. $limit = $conf->liste_limit;
  72. $pageprev = $page - 1;
  73. $pagenext = $page + 1;
  74. $search_user = GETPOST('search_user','int');
  75. $search_sale = GETPOST('search_sale','int');
  76. $day = GETPOST('day','int');
  77. $month = GETPOST('month','int');
  78. $year = GETPOST('year','int');
  79. $filtre = GETPOST('filtre');
  80. // Security check
  81. $fieldid = (! empty($ref)?'facnumber':'rowid');
  82. if (! empty($user->societe_id)) $socid=$user->societe_id;
  83. $result = restrictedArea($user, 'facture', $id,'','','fk_soc',$fieldid);
  84. // FIXME $usehm not used ?
  85. $usehm=(! empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:false);
  86. $object=new Facture($db);
  87. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  88. $hookmanager->initHooks(array('invoicecard'));
  89. $now=dol_now();
  90. /*
  91. * Actions
  92. */
  93. $parameters=array('socid'=>$socid);
  94. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  95. // Do we click on purge search criteria ?
  96. if (GETPOST("button_removefilter_x"))
  97. {
  98. $search_categ='';
  99. $search_user='';
  100. $search_sale='';
  101. $search_ref='';
  102. $search_refcustomer='';
  103. $search_societe='';
  104. $search_montant_ht='';
  105. $year='';
  106. $month='';
  107. }
  108. /*
  109. * View
  110. */
  111. llxHeader('',$langs->trans('Bill'),'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes');
  112. $form = new Form($db);
  113. $formother = new FormOther($db);
  114. $formfile = new FormFile($db);
  115. $bankaccountstatic=new Account($db);
  116. $facturestatic=new Facture($db);
  117. if (! $sall) $sql = 'SELECT';
  118. else $sql = 'SELECT DISTINCT';
  119. $sql.= ' f.rowid as facid, f.facnumber, f.type, f.increment, f.total as total_ht, f.tva as total_tva, f.total_ttc,';
  120. $sql.= ' f.datef as df, f.date_lim_reglement as datelimite,';
  121. $sql.= ' f.paye as paye, f.fk_statut, f.note,';
  122. $sql.= ' s.nom, s.rowid as socid';
  123. if (! $sall) $sql.= ', SUM(pf.amount) as am'; // To be able to sort on status
  124. $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  125. $sql.= ', '.MAIN_DB_PREFIX.'facture as f';
  126. if (! $sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
  127. else $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON fd.fk_facture = f.rowid';
  128. // We'll need this table joined to the select in order to filter by sale
  129. if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  130. if ($search_user > 0)
  131. {
  132. $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
  133. $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
  134. }
  135. $sql.= ' WHERE f.fk_soc = s.rowid';
  136. $sql.= " AND f.entity = ".$conf->entity;
  137. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  138. if ($socid) $sql.= ' AND s.rowid = '.$socid;
  139. if ($userid)
  140. {
  141. if ($userid == -1) $sql.=' AND f.fk_user_author IS NULL';
  142. else $sql.=' AND f.fk_user_author = '.$userid;
  143. }
  144. if ($filtre)
  145. {
  146. $aFilter = explode(',', $filtre);
  147. foreach ($aFilter as $filter)
  148. {
  149. $filt = explode(':', $filter);
  150. $sql .= ' AND ' . trim($filt[0]) . ' = ' . trim($filt[1]);
  151. }
  152. }
  153. if ($search_ref)
  154. {
  155. $sql.= ' AND f.facnumber LIKE \'%'.$db->escape(trim($search_ref)).'%\'';
  156. }
  157. if ($search_societe)
  158. {
  159. $sql.= ' AND s.nom LIKE \'%'.$db->escape(trim($search_societe)).'%\'';
  160. }
  161. if ($search_montant_ht)
  162. {
  163. $sql.= ' AND f.total = \''.$db->escape(trim($search_montant_ht)).'\'';
  164. }
  165. if ($search_montant_ttc)
  166. {
  167. $sql.= ' AND f.total_ttc = \''.$db->escape(trim($search_montant_ttc)).'\'';
  168. }
  169. if ($month > 0)
  170. {
  171. if ($year > 0 && empty($day))
  172. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
  173. else if ($year > 0 && ! empty($day))
  174. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
  175. else
  176. $sql.= " AND date_format(f.datef, '%m') = '".$month."'";
  177. }
  178. else if ($year > 0)
  179. {
  180. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  181. }
  182. if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
  183. if ($search_user > 0)
  184. {
  185. $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='facture' AND tc.source='internal' AND ec.element_id = f.rowid AND ec.fk_socpeople = ".$search_user;
  186. }
  187. if (! $sall)
  188. {
  189. $sql.= ' GROUP BY f.rowid, f.facnumber, f.type, f.increment, f.total, f.total_ttc,';
  190. $sql.= ' f.datef, f.date_lim_reglement,';
  191. $sql.= ' f.paye, f.fk_statut, f.note,';
  192. $sql.= ' s.nom, s.rowid';
  193. }
  194. else
  195. {
  196. $sql.= ' AND (s.nom LIKE \'%'.$db->escape($sall).'%\' OR f.facnumber LIKE \'%'.$db->escape($sall).'%\' OR f.note LIKE \'%'.$db->escape($sall).'%\' OR fd.description LIKE \'%'.$db->escape($sall).'%\')';
  197. }
  198. $sql.= ' ORDER BY ';
  199. $listfield=explode(',',$sortfield);
  200. foreach ($listfield as $key => $value) $sql.= $listfield[$key].' '.$sortorder.',';
  201. $sql.= ' f.rowid DESC ';
  202. $sql.= $db->plimit($limit+1,$offset);
  203. //print $sql;
  204. print '<div class="row">';
  205. print start_box($langs->trans('BillsCustomers'),"twelve","16-Money-2.png",false);
  206. $resql = $db->query($sql);
  207. if ($resql)
  208. {
  209. $num = $db->num_rows($resql);
  210. if ($socid)
  211. {
  212. $soc = new Societe($db);
  213. $soc->fetch($socid);
  214. }
  215. $param='&socid='.$socid;
  216. if ($month) $param.='&month='.$month;
  217. if ($year) $param.='&year=' .$year;
  218. if ($search_ref) $param.='&search_ref=' .$search_ref;
  219. if ($search_societe) $param.='&search_societe=' .$search_societe;
  220. if ($search_sale > 0) $param.='&search_sale=' .$search_sale;
  221. if ($search_user > 0) $param.='&search_user=' .$search_user;
  222. if ($search_montant_ht) $param.='&search_montant_ht='.$search_montant_ht;
  223. if ($search_montant_ttc) $param.='&search_montant_ttc='.$search_montant_ttc;
  224. //print_barre_liste($langs->trans('BillsCustomers').' '.($socid?' '.$soc->nom:''),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num);
  225. $i = 0;
  226. print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  227. print '<table class="liste" width="100%">';
  228. // If the user can view prospects other than his'
  229. $moreforfilter='';
  230. if ($user->rights->societe->client->voir || $socid)
  231. {
  232. $langs->load("commercial");
  233. $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
  234. $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user);
  235. $moreforfilter.=' &nbsp; &nbsp; &nbsp; ';
  236. }
  237. // If the user can view prospects other than his'
  238. if ($user->rights->societe->client->voir || $socid)
  239. {
  240. $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
  241. $moreforfilter.=$form->select_dolusers($search_user,'search_user',1);
  242. }
  243. if ($moreforfilter)
  244. {
  245. print '<tr class="liste_titre">';
  246. print '<td class="liste_titre" colspan="9">';
  247. print $moreforfilter;
  248. print '</td></tr>';
  249. }
  250. print '<tr class="liste_titre">';
  251. print_liste_field_titre($langs->trans('Ref'),$_SERVER['PHP_SELF'],'f.facnumber','',$param,'',$sortfield,$sortorder);
  252. print_liste_field_titre($langs->trans('Date'),$_SERVER['PHP_SELF'],'f.datef','',$param,'align="center"',$sortfield,$sortorder);
  253. print_liste_field_titre($langs->trans("DateDue"),$_SERVER['PHP_SELF'],"f.date_lim_reglement",'',$param,'align="center"',$sortfield,$sortorder);
  254. print_liste_field_titre($langs->trans('Company'),$_SERVER['PHP_SELF'],'s.nom','',$param,'',$sortfield,$sortorder);
  255. print_liste_field_titre($langs->trans('AmountHT'),$_SERVER['PHP_SELF'],'f.total','',$param,'align="right"',$sortfield,$sortorder);
  256. print_liste_field_titre($langs->trans('AmountVAT'),$_SERVER['PHP_SELF'],'f.tva','',$param,'align="right"',$sortfield,$sortorder);
  257. print_liste_field_titre($langs->trans('AmountTTC'),$_SERVER['PHP_SELF'],'f.total_ttc','',$param,'align="right"',$sortfield,$sortorder);
  258. print_liste_field_titre($langs->trans('Received'),$_SERVER['PHP_SELF'],'am','',$param,'align="right"',$sortfield,$sortorder);
  259. print_liste_field_titre($langs->trans('Status'),$_SERVER['PHP_SELF'],'fk_statut,paye,am','',$param,'align="right"',$sortfield,$sortorder);
  260. //print '<td class="liste_titre">&nbsp;</td>';
  261. print '</tr>';
  262. // Filters lines
  263. print '<tr class="liste_titre">';
  264. print '<td class="liste_titre" align="left">';
  265. print '<input class="flat" size="10" type="text" name="search_ref" value="'.$search_ref.'">';
  266. print '</td>';
  267. print '<td class="liste_titre" align="center">';
  268. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
  269. print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
  270. $formother->select_year($year?$year:-1,'year',1, 20, 5);
  271. print '</td>';
  272. print '<td class="liste_titre" align="left">&nbsp;</td>';
  273. print '<td class="liste_titre" align="left"><input class="flat" type="text" name="search_societe" value="'.$search_societe.'"></td>';
  274. print '<td class="liste_titre" align="right"><input class="flat" type="text" size="10" name="search_montant_ht" value="'.$search_montant_ht.'"></td>';
  275. print '<td class="liste_titre" align="right">&nbsp;</td>';
  276. print '<td class="liste_titre" align="right"><input class="flat" type="text" size="10" name="search_montant_ttc" value="'.$search_montant_ttc.'"></td>';
  277. print '<td class="liste_titre" align="right">&nbsp;</td>';
  278. print '<td class="liste_titre" align="right"><input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  279. print "</td></tr>\n";
  280. if ($num > 0)
  281. {
  282. $var=True;
  283. $total_ht=0;
  284. $total_tva=0;
  285. $total_ttc=0;
  286. $totalrecu=0;
  287. while ($i < min($num,$limit))
  288. {
  289. $objp = $db->fetch_object($resql);
  290. $var=!$var;
  291. $datelimit=$db->jdate($objp->datelimite);
  292. print '<tr '.$bc[$var].'>';
  293. print '<td nowrap="nowrap">';
  294. $facturestatic->id=$objp->facid;
  295. $facturestatic->ref=$objp->facnumber;
  296. $facturestatic->type=$objp->type;
  297. $notetoshow=dol_string_nohtmltag(($user->societe_id>0?$objp->note_public:$objp->note),1);
  298. $paiement = $facturestatic->getSommePaiement();
  299. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  300. print '<td class="nobordernopadding" nowrap="nowrap">';
  301. print $facturestatic->getNomUrl(1,'',200,0,$notetoshow);
  302. print $objp->increment;
  303. print '</td>';
  304. print '<td width="16" align="right" class="nobordernopadding">';
  305. $filename=dol_sanitizeFileName($objp->facnumber);
  306. $filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($objp->facnumber);
  307. $urlsource=$_SERVER['PHP_SELF'].'?id='.$objp->facid;
  308. print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
  309. print '</td>';
  310. print '</tr>';
  311. print '</table>';
  312. print "</td>\n";
  313. // Date
  314. print '<td align="center" nowrap>';
  315. print dol_print_date($db->jdate($objp->df),'day');
  316. print '</td>';
  317. // Date limit
  318. print '<td align="center" nowrap="1">'.dol_print_date($datelimit,'day');
  319. if ($datelimit < ($now - $conf->facture->client->warning_delay) && ! $objp->paye && $objp->fk_statut == 1 && ! $paiement)
  320. {
  321. print img_warning($langs->trans('Late'));
  322. }
  323. print '</td>';
  324. print '<td>';
  325. $thirdparty=new Societe($db);
  326. $thirdparty->id=$objp->socid;
  327. $thirdparty->nom=$objp->nom;
  328. print $thirdparty->getNomUrl(1,'customer');
  329. print '</td>';
  330. print '<td align="right">'.price($objp->total_ht).' '.$langs->getCurrencySymbol($conf->currency).'</td>';
  331. print '<td align="right">'.price($objp->total_tva).' '.$langs->getCurrencySymbol($conf->currency).'</td>';
  332. print '<td align="right">'.price($objp->total_ttc).' '.$langs->getCurrencySymbol($conf->currency).'</td>';
  333. print '<td align="right">'.(! empty($paiement)?price($paiement).' '.$langs->getCurrencySymbol($conf->currency):'&nbsp;').'</td>';
  334. // Affiche statut de la facture
  335. print '<td align="right" nowrap="nowrap">';
  336. print $facturestatic->LibStatut($objp->paye,$objp->fk_statut,5,$paiement,$objp->type);
  337. print "</td>";
  338. //print "<td>&nbsp;</td>";
  339. print "</tr>\n";
  340. $total_ht+=$objp->total_ht;
  341. $total_tva+=$objp->total_tva;
  342. $total_ttc+=$objp->total_ttc;
  343. $totalrecu+=$paiement;
  344. $i++;
  345. }
  346. if (($offset + $num) <= $limit)
  347. {
  348. // Print total
  349. print '<tr class="liste_total">';
  350. print '<td class="liste_total" colspan="4" align="left">'.$langs->trans('Total').'</td>';
  351. print '<td class="liste_total" align="right">'.price($total_ht).' '.$langs->getCurrencySymbol($conf->currency).'</td>';
  352. print '<td class="liste_total" align="right">'.price($total_tva).' '.$langs->getCurrencySymbol($conf->currency).'</td>';
  353. print '<td class="liste_total" align="right">'.price($total_ttc).' '.$langs->getCurrencySymbol($conf->currency).'</td>';
  354. print '<td class="liste_total" align="right">'.price($totalrecu).' '.$langs->getCurrencySymbol($conf->currency).'</td>';
  355. print '<td class="liste_total" align="center">&nbsp;</td>';
  356. print '</tr>';
  357. }
  358. }
  359. print "</table>\n";
  360. print "</form>\n";
  361. $db->free($resql);
  362. }
  363. else
  364. {
  365. dol_print_error($db);
  366. }
  367. print end_box();
  368. print '</div>';
  369. llxFooter();
  370. $db->close();
  371. ?>