PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/propal/list.old.php

https://bitbucket.org/speedealing/speedealing
PHP | 404 lines | 300 code | 55 blank | 49 comment | 60 complexity | c7c7cf26566a8f1613f6c5d96640e23b MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  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-2011 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2010-2011 Philippe Grand <philippe.grand@atoo-net.com>
  10. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  11. * Copyright (C) 2012 David Moothen <dmoothen@websitti.fr>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. */
  26. /**
  27. * \file htdocs/comm/propal.php
  28. * \ingroup propale
  29. * \brief Page of commercial proposals card and list
  30. */
  31. require '../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/propal/class/propal.class.php';
  37. if (! empty($conf->projet->enabled))
  38. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  39. $langs->load('companies');
  40. $langs->load('propal');
  41. $langs->load('compta');
  42. $langs->load('bills');
  43. $langs->load('orders');
  44. $langs->load('products');
  45. $socid=GETPOST('socid','int');
  46. $search_user=GETPOST('search_user','int');
  47. $search_sale=GETPOST('search_sale','int');
  48. $search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha');
  49. $search_refcustomer=GETPOST('search_refcustomer','alpha');
  50. $search_societe=GETPOST('search_societe','alpha');
  51. $search_montant_ht=GETPOST('search_montant_ht','alpha');
  52. $sall=GETPOST("sall");
  53. $mesg=(GETPOST("msg") ? GETPOST("msg") : GETPOST("mesg"));
  54. $year=GETPOST("year");
  55. $month=GETPOST("month");
  56. // Nombre de ligne pour choix de produit/service predefinis
  57. $NBLINES=4;
  58. // Security check
  59. $module='propal';
  60. $dbtable='';
  61. $objectid='';
  62. if (! empty($user->societe_id)) $socid=$user->societe_id;
  63. if (! empty($socid))
  64. {
  65. $objectid=$socid;
  66. $module='societe';
  67. $dbtable='&societe';
  68. }
  69. $result = restrictedArea($user, $module, $objectid, $dbtable);
  70. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  71. $hookmanager->initHooks(array('propalcard'));
  72. /*
  73. * Actions
  74. */
  75. // Do we click on purge search criteria ?
  76. if (GETPOST("button_removefilter_x"))
  77. {
  78. $search_categ='';
  79. $search_user='';
  80. $search_sale='';
  81. $search_ref='';
  82. $search_refcustomer='';
  83. $search_societe='';
  84. $search_montant_ht='';
  85. $year='';
  86. $month='';
  87. }
  88. /*
  89. * View
  90. */
  91. llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
  92. $form = new Form($db);
  93. $formother = new FormOther($db);
  94. $formfile = new FormFile($db);
  95. $formpropal = new FormPropal($db);
  96. $companystatic=new Societe($db);
  97. $now=dol_now();
  98. $sortfield = GETPOST("sortfield",'alpha');
  99. $sortorder = GETPOST("sortorder",'alpha');
  100. $page = GETPOST("page",'int');
  101. if ($page == -1) { $page = 0; }
  102. $offset = $conf->liste_limit * $page;
  103. $pageprev = $page - 1;
  104. $pagenext = $page + 1;
  105. $viewstatut=$db->escape(GETPOST('viewstatut'));
  106. $object_statut = $db->escape(GETPOST('propal_statut'));
  107. if($object_statut != '')
  108. $viewstatut=$object_statut;
  109. if (! $sortfield) $sortfield='p.datep';
  110. if (! $sortorder) $sortorder='DESC';
  111. $limit = $conf->liste_limit;
  112. $sql = 'SELECT s.nom, s.rowid, s.client, ';
  113. $sql.= 'p.rowid as propalid, p.total_ht, p.ref, p.ref_client, p.fk_statut, p.fk_user_author, p.datep as dp, p.fin_validite as dfv,';
  114. if (! $user->rights->societe->client->voir && ! $socid) $sql .= " sc.fk_soc, sc.fk_user,";
  115. $sql.= ' u.login';
  116. $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p';
  117. if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet as pd ON p.rowid=pd.fk_propal';
  118. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON p.fk_user_author = u.rowid';
  119. // We'll need this table joined to the select in order to filter by sale
  120. if ($search_sale || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  121. if ($search_user > 0)
  122. {
  123. $sql.=", ".MAIN_DB_PREFIX."element_contact as c";
  124. $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
  125. }
  126. $sql.= ' WHERE p.fk_soc = s.rowid';
  127. $sql.= ' AND p.entity = '.$conf->entity;
  128. if (! $user->rights->societe->client->voir && ! $socid) //restriction
  129. {
  130. $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  131. }
  132. if ($search_ref)
  133. {
  134. $sql.= " AND p.ref LIKE '%".$db->escape(trim($search_ref))."%'";
  135. }
  136. if ($search_refcustomer)
  137. {
  138. $sql.= " AND p.ref_client LIKE '%".$db->escape(trim($search_refcustomer))."%'";
  139. }
  140. if ($search_societe)
  141. {
  142. $sql.= " AND s.nom LIKE '%".$db->escape(trim($search_societe))."%'";
  143. }
  144. if ($search_montant_ht)
  145. {
  146. $sql.= " AND p.total_ht='".$db->escape(trim($search_montant_ht))."'";
  147. }
  148. if ($sall) $sql.= " AND (s.nom LIKE '%".$db->escape($sall)."%' OR p.note LIKE '%".$db->escape($sall)."%' OR pd.description LIKE '%".$db->escape($sall)."%')";
  149. if ($socid) $sql.= ' AND s.rowid = '.$socid;
  150. if ($viewstatut <> '')
  151. {
  152. $sql.= ' AND p.fk_statut IN ('.$viewstatut.')';
  153. }
  154. if ($month > 0)
  155. {
  156. if ($year > 0 && empty($day))
  157. $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
  158. else if ($year > 0 && ! empty($day))
  159. $sql.= " AND p.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
  160. else
  161. $sql.= " AND date_format(p.datep, '%m') = '".$month."'";
  162. }
  163. else if ($year > 0)
  164. {
  165. $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  166. }
  167. if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
  168. if ($search_user > 0)
  169. {
  170. $sql.= " AND c.fk_c_type_contact = tc.rowid AND tc.element='propal' AND tc.source='internal' AND c.element_id = p.rowid AND c.fk_socpeople = ".$search_user;
  171. }
  172. $sql.= ' ORDER BY '.$sortfield.' '.$sortorder.', p.ref DESC';
  173. $sql.= $db->plimit($limit + 1,$offset);
  174. $result=$db->query($sql);
  175. if ($result)
  176. {
  177. $objectstatic=new Propal($db);
  178. $userstatic=new User($db);
  179. $num = $db->num_rows($result);
  180. if ($socid)
  181. {
  182. $soc = new Societe($db);
  183. $soc->fetch($socid);
  184. }
  185. $param='&socid='.$socid.'&viewstatut='.$viewstatut;
  186. if ($month) $param.='&month='.$month;
  187. if ($year) $param.='&year='.$year;
  188. if ($search_ref) $param.='&search_ref=' .$search_ref;
  189. if ($search_refcustomer) $param.='&search_ref=' .$search_refcustomer;
  190. if ($search_societe) $param.='&search_societe=' .$search_societe;
  191. if ($search_user > 0) $param.='&search_user='.$search_user;
  192. if ($search_sale > 0) $param.='&search_sale='.$search_sale;
  193. if ($search_montant_ht) $param.='&search_montant_ht='.$search_montant_ht;
  194. print_barre_liste($langs->trans('ListOfProposals').' '.($socid?'- '.$soc->nom:''), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num);
  195. // Lignes des champs de filtre
  196. print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
  197. $i = 0;
  198. print '<table class="liste" width="100%">';
  199. $moreforfilter='';
  200. // If the user can view prospects other than his'
  201. if ($user->rights->societe->client->voir || $socid)
  202. {
  203. $langs->load("commercial");
  204. $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
  205. $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user);
  206. $moreforfilter.=' &nbsp; &nbsp; &nbsp; ';
  207. }
  208. // If the user can view prospects other than his'
  209. if ($user->rights->societe->client->voir || $socid)
  210. {
  211. $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
  212. // $moreforfilter.=$form->select_dolusers($search_user,'search_user',1);
  213. }
  214. if (! empty($moreforfilter))
  215. {
  216. print '<tr class="liste_titre">';
  217. print '<td class="liste_titre" colspan="9">';
  218. print $moreforfilter;
  219. print '</td></tr>';
  220. }
  221. print '<tr class="liste_titre">';
  222. print_liste_field_titre($langs->trans('Ref'),$_SERVER["PHP_SELF"],'p.ref','',$param,'',$sortfield,$sortorder);
  223. print_liste_field_titre($langs->trans('Company'),$_SERVER["PHP_SELF"],'s.nom','',$param,'',$sortfield,$sortorder);
  224. print_liste_field_titre($langs->trans('RefCustomer'),$_SERVER["PHP_SELF"],'p.ref_client','',$param,'',$sortfield,$sortorder);
  225. print_liste_field_titre($langs->trans('Date'),$_SERVER["PHP_SELF"],'p.datep','',$param, 'align="center"',$sortfield,$sortorder);
  226. print_liste_field_titre($langs->trans('DateEndPropalShort'),$_SERVER["PHP_SELF"],'dfv','',$param, 'align="center"',$sortfield,$sortorder);
  227. print_liste_field_titre($langs->trans('AmountHT'),$_SERVER["PHP_SELF"],'p.total_ht','',$param, 'align="right"',$sortfield,$sortorder);
  228. print_liste_field_titre($langs->trans('Author'),$_SERVER["PHP_SELF"],'u.login','',$param,'align="right"',$sortfield,$sortorder);
  229. print_liste_field_titre($langs->trans('Status'),$_SERVER["PHP_SELF"],'p.fk_statut','',$param,'align="right"',$sortfield,$sortorder);
  230. print_liste_field_titre('');
  231. print "</tr>\n";
  232. print '<tr class="liste_titre">';
  233. print '<td class="liste_titre">';
  234. print '<input class="flat" size="10" type="text" name="search_ref" value="'.$search_ref.'">';
  235. print '</td>';
  236. print '<td class="liste_titre" align="left">';
  237. print '<input class="flat" type="text" size="16" name="search_societe" value="'.$search_societe.'">';
  238. print '</td>';
  239. print '<td class="liste_titre">';
  240. print '<input class="flat" size="10" type="text" name="search_refcustomer" value="'.$search_refcustomer.'">';
  241. print '</td>';
  242. print '<td class="liste_titre" colspan="1" align="center">';
  243. print $langs->trans('Month').': <input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
  244. print '&nbsp;'.$langs->trans('Year').': ';
  245. $syear = $year;
  246. $formother->select_year($syear,'year',1, 20, 5);
  247. print '</td>';
  248. print '<td class="liste_titre" colspan="1">&nbsp;</td>';
  249. print '<td class="liste_titre" align="right">';
  250. print '<input class="flat" type="text" size="10" name="search_montant_ht" value="'.$search_montant_ht.'">';
  251. print '</td>';
  252. print '<td class="liste_titre">&nbsp;</td>';
  253. print '<td class="liste_titre" align="right">';
  254. $formpropal->select_propal_statut($viewstatut,1);
  255. print '</td>';
  256. print '<td class="liste_titre" align="right"><input class="liste_titre" type="image" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  257. print '</td>';
  258. print "</tr>\n";
  259. $var=true;
  260. $total=0;
  261. $subtotal=0;
  262. while ($i < min($num,$limit))
  263. {
  264. $objp = $db->fetch_object($result);
  265. $now = dol_now();
  266. $var=!$var;
  267. print '<tr '.$bc[$var].'>';
  268. print '<td nowrap="nowrap">';
  269. $objectstatic->id=$objp->propalid;
  270. $objectstatic->ref=$objp->ref;
  271. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  272. print '<td class="nobordernopadding" nowrap="nowrap">';
  273. print $objectstatic->getNomUrl(1);
  274. print '</td>';
  275. print '<td width="20" class="nobordernopadding" nowrap="nowrap">';
  276. if ($objp->fk_statut == 1 && $db->jdate($objp->dfv) < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
  277. print '</td>';
  278. print '<td width="16" align="right" class="nobordernopadding">';
  279. $filename=dol_sanitizeFileName($objp->ref);
  280. $filedir=$conf->propal->dir_output . '/' . dol_sanitizeFileName($objp->ref);
  281. $urlsource=$_SERVER['PHP_SELF'].'?id='.$objp->propalid;
  282. print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
  283. print '</td></tr></table>';
  284. if ($objp->client == 1)
  285. {
  286. $url = DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->rowid;
  287. }
  288. else
  289. {
  290. $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$objp->rowid;
  291. }
  292. // Company
  293. $companystatic->id=$objp->rowid;
  294. $companystatic->nom=$objp->nom;
  295. $companystatic->client=$objp->client;
  296. print '<td>';
  297. print $companystatic->getNomUrl(1,'customer');
  298. print '</td>';
  299. // Customer ref
  300. print '<td nowrap="nowrap">';
  301. print $objp->ref_client;
  302. print '</td>';
  303. // Date propale
  304. print '<td align="center">';
  305. $y = dol_print_date($db->jdate($objp->dp),'%Y');
  306. $m = dol_print_date($db->jdate($objp->dp),'%m');
  307. $mt= dol_print_date($db->jdate($objp->dp),'%b');
  308. $d = dol_print_date($db->jdate($objp->dp),'%d');
  309. print $d."\n";
  310. print ' <a href="'.$_SERVER["PHP_SELF"].'?year='.$y.'&amp;month='.$m.'">';
  311. print $mt."</a>\n";
  312. print ' <a href="'.$_SERVER["PHP_SELF"].'?year='.$y.'">';
  313. print $y."</a></td>\n";
  314. // Date fin validite
  315. if ($objp->dfv)
  316. {
  317. print '<td align="center">'.dol_print_date($db->jdate($objp->dfv),'day');
  318. print '</td>';
  319. }
  320. else
  321. {
  322. print '<td>&nbsp;</td>';
  323. }
  324. print '<td align="right">'.price($objp->total_ht)."</td>\n";
  325. $userstatic->id=$objp->fk_user_author;
  326. $userstatic->login=$objp->login;
  327. print '<td align="center">';
  328. if ($userstatic->id) print $userstatic->getLoginUrl(1);
  329. else print '&nbsp;';
  330. print "</td>\n";
  331. print '<td align="right">'.$objectstatic->LibStatut($objp->fk_statut,5)."</td>\n";
  332. print '<td>&nbsp;</td>';
  333. print "</tr>\n";
  334. $total += $objp->total_ht;
  335. $subtotal += $objp->total_ht;
  336. $i++;
  337. }
  338. print '</table>';
  339. print '</form>';
  340. $db->free($result);
  341. }
  342. else
  343. {
  344. dol_print_error($db);
  345. }
  346. // End of page
  347. llxFooter();
  348. $db->close();
  349. ?>