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

/htdocs/commande/liste.old.php

https://bitbucket.org/speedealing/speedealing
PHP | 396 lines | 304 code | 49 blank | 43 comment | 91 complexity | 37e6d2158918530cfc78a76be2e91ba6 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/commande/liste.php
  23. * \ingroup commande
  24. * \brief Page to list orders
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  30. $langs->load('orders');
  31. $langs->load('deliveries');
  32. $langs->load('companies');
  33. $orderyear=GETPOST("orderyear","int");
  34. $ordermonth=GETPOST("ordermonth","int");
  35. $deliveryyear=GETPOST("deliveryyear","int");
  36. $deliverymonth=GETPOST("deliverymonth","int");
  37. $sref=GETPOST('sref','alpha');
  38. $sref_client=GETPOST('sref_client','alpha');
  39. $snom=GETPOST('snom','alpha');
  40. $sall=GETPOST('sall');
  41. $socid=GETPOST('socid','int');
  42. $search_user=GETPOST('search_user','int');
  43. $search_sale=GETPOST('search_sale','int');
  44. // Security check
  45. $id = (GETPOST('orderid')?GETPOST('orderid'):GETPOST('id','int'));
  46. if ($user->societe_id) $socid=$user->societe_id;
  47. $result = restrictedArea($user, 'commande', $id,'');
  48. $sortfield = GETPOST("sortfield",'alpha');
  49. $sortorder = GETPOST("sortorder",'alpha');
  50. $page = GETPOST("page",'int');
  51. if ($page == -1) { $page = 0; }
  52. $offset = $conf->liste_limit * $page;
  53. $pageprev = $page - 1;
  54. $pagenext = $page + 1;
  55. if (! $sortfield) $sortfield='c.rowid';
  56. if (! $sortorder) $sortorder='DESC';
  57. $limit = $conf->liste_limit;
  58. $viewstatut=GETPOST('viewstatut');
  59. /*
  60. * Actions
  61. */
  62. // Do we click on purge search criteria ?
  63. if (GETPOST("button_removefilter_x"))
  64. {
  65. $search_categ='';
  66. $search_user='';
  67. $search_sale='';
  68. $search_ref='';
  69. $search_refcustomer='';
  70. $search_societe='';
  71. $search_montant_ht='';
  72. $orderyear='';
  73. $ordermonth='';
  74. $deliverymonth='';
  75. $deliveryyear='';
  76. }
  77. /*
  78. * View
  79. */
  80. $now=dol_now();
  81. $form = new Form($db);
  82. $formother = new FormOther($db);
  83. $formfile = new FormFile($db);
  84. $companystatic = new Societe($db);
  85. llxHeader('',$langs->trans("Orders"));
  86. $sql = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,';
  87. $sql.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as facturee';
  88. $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  89. $sql.= ', '.MAIN_DB_PREFIX.'commande as c';
  90. // We'll need this table joined to the select in order to filter by sale
  91. if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  92. if ($search_user > 0)
  93. {
  94. $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
  95. $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
  96. }
  97. $sql.= ' WHERE c.fk_soc = s.rowid';
  98. $sql.= ' AND c.entity = '.$conf->entity;
  99. if ($socid) $sql.= ' AND s.rowid = '.$socid;
  100. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  101. if ($sref)
  102. {
  103. $sql.= " AND c.ref LIKE '%".$db->escape($sref)."%'";
  104. }
  105. if ($sall)
  106. {
  107. $sql.= " AND (c.ref LIKE '%".$db->escape($sall)."%' OR c.note LIKE '%".$db->escape($sall)."%')";
  108. }
  109. if ($viewstatut <> '')
  110. {
  111. if ($viewstatut < 4 && $viewstatut > -3)
  112. {
  113. $sql.= ' AND c.fk_statut ='.$viewstatut; // brouillon, validee, en cours, annulee
  114. if ($viewstatut == 3)
  115. {
  116. $sql.= ' AND c.facture = 0'; // need to create invoice
  117. }
  118. }
  119. if ($viewstatut == 4)
  120. {
  121. $sql.= ' AND c.facture = 1'; // invoice created
  122. }
  123. if ($viewstatut == -2) // To process
  124. {
  125. //$sql.= ' AND c.fk_statut IN (1,2,3) AND c.facture = 0';
  126. $sql.= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))"; // If status is 2 and facture=1, it must be selected
  127. }
  128. if ($viewstatut == -3) // To bill
  129. {
  130. $sql.= ' AND c.fk_statut in (1,2,3)';
  131. $sql.= ' AND c.facture = 0'; // invoice not created
  132. }
  133. }
  134. if ($ordermonth > 0)
  135. {
  136. if ($orderyear > 0 && empty($day))
  137. $sql.= " AND c.date_valid BETWEEN '".$db->idate(dol_get_first_day($orderyear,$ordermonth,false))."' AND '".$db->idate(dol_get_last_day($orderyear,$ordermonth,false))."'";
  138. else if ($orderyear > 0 && ! empty($day))
  139. $sql.= " AND c.date_valid BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $ordermonth, $day, $orderyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $ordermonth, $day, $orderyear))."'";
  140. else
  141. $sql.= " AND date_format(c.date_valid, '%m') = '".$ordermonth."'";
  142. }
  143. else if ($orderyear > 0)
  144. {
  145. $sql.= " AND c.date_valid BETWEEN '".$db->idate(dol_get_first_day($orderyear,1,false))."' AND '".$db->idate(dol_get_last_day($orderyear,12,false))."'";
  146. }
  147. if ($deliverymonth > 0)
  148. {
  149. if ($deliveryyear > 0 && empty($day))
  150. $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($deliveryyear,$deliverymonth,false))."' AND '".$db->idate(dol_get_last_day($deliveryyear,$deliverymonth,false))."'";
  151. else if ($deliveryyear > 0 && ! empty($day))
  152. $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $deliverymonth, $day, $deliveryyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $deliverymonth, $day, $deliveryyear))."'";
  153. else
  154. $sql.= " AND date_format(c.date_livraison, '%m') = '".$deliverymonth."'";
  155. }
  156. else if ($deliveryyear > 0)
  157. {
  158. $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($deliveryyear,1,false))."' AND '".$db->idate(dol_get_last_day($deliveryyear,12,false))."'";
  159. }
  160. if (!empty($snom))
  161. {
  162. $sql.= ' AND s.nom LIKE \'%'.$db->escape($snom).'%\'';
  163. }
  164. if (!empty($sref_client))
  165. {
  166. $sql.= ' AND c.ref_client LIKE \'%'.$db->escape($sref_client).'%\'';
  167. }
  168. if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
  169. if ($search_user > 0)
  170. {
  171. $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".$search_user;
  172. }
  173. $sql.= ' ORDER BY '.$sortfield.' '.$sortorder;
  174. $sql.= $db->plimit($limit + 1,$offset);
  175. //print $sql;
  176. $resql = $db->query($sql);
  177. if ($resql)
  178. {
  179. if ($socid)
  180. {
  181. $soc = new Societe($db);
  182. $soc->fetch($socid);
  183. $title = $langs->trans('ListOfOrders') . ' - '.$soc->nom;
  184. }
  185. else
  186. {
  187. $title = $langs->trans('ListOfOrders');
  188. }
  189. if (strval($viewstatut) == '0')
  190. $title.=' - '.$langs->trans('StatusOrderDraftShort');
  191. if ($viewstatut == 1)
  192. $title.=' - '.$langs->trans('StatusOrderValidatedShort');
  193. if ($viewstatut == 2)
  194. $title.=' - '.$langs->trans('StatusOrderOnProcessShort');
  195. if ($viewstatut == 3)
  196. $title.=' - '.$langs->trans('StatusOrderToBillShort');
  197. if ($viewstatut == 4)
  198. $title.=' - '.$langs->trans('StatusOrderProcessedShort');
  199. if ($viewstatut == -1)
  200. $title.=' - '.$langs->trans('StatusOrderCanceledShort');
  201. if ($viewstatut == -2)
  202. $title.=' - '.$langs->trans('StatusOrderToProcessShort');
  203. if ($viewstatut == -3)
  204. $title.=' - '.$langs->trans('StatusOrderValidated').', '.$langs->trans("StatusOrderSent").', '.$langs->trans('StatusOrderToBill');
  205. $param='&socid='.$socid.'&viewstatut='.$viewstatut;
  206. if ($ordermonth) $param.='&ordermonth='.$ordermonth;
  207. if ($orderyear) $param.='&orderyear='.$orderyear;
  208. if ($deliverymonth) $param.='&deliverymonth='.$deliverymonth;
  209. if ($deliveryyear) $param.='&deliveryyear='.$deliveryyear;
  210. if ($sref) $param.='&sref='.$sref;
  211. if ($snom) $param.='&snom='.$snom;
  212. if ($sref_client) $param.='&sref_client='.$sref_client;
  213. if ($search_user > 0) $param.='&search_user='.$search_user;
  214. if ($search_sale > 0) $param.='&search_sale='.$search_sale;
  215. $num = $db->num_rows($resql);
  216. print_barre_liste($title, $page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num);
  217. $i = 0;
  218. // Lignes des champs de filtre
  219. print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
  220. print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
  221. print '<table class="noborder" width="100%">';
  222. $moreforfilter='';
  223. // If the user can view prospects other than his'
  224. if ($user->rights->societe->client->voir || $socid)
  225. {
  226. $langs->load("commercial");
  227. $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
  228. $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user);
  229. $moreforfilter.=' &nbsp; &nbsp; &nbsp; ';
  230. }
  231. // If the user can view prospects other than his'
  232. if ($user->rights->societe->client->voir || $socid)
  233. {
  234. $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
  235. $moreforfilter.=$form->select_dolusers($search_user,'search_user',1);
  236. }
  237. if (! empty($moreforfilter))
  238. {
  239. print '<tr class="liste_titre">';
  240. print '<td class="liste_titre" colspan="9">';
  241. print $moreforfilter;
  242. print '</td></tr>';
  243. }
  244. print '<tr class="liste_titre">';
  245. print_liste_field_titre($langs->trans('Ref'),$_SERVER["PHP_SELF"],'c.ref','',$param,'width="25%"',$sortfield,$sortorder);
  246. print_liste_field_titre($langs->trans('Company'),$_SERVER["PHP_SELF"],'s.nom','',$param,'',$sortfield,$sortorder);
  247. print_liste_field_titre($langs->trans('RefCustomerOrder'),$_SERVER["PHP_SELF"],'c.ref_client','',$param,'',$sortfield,$sortorder);
  248. print_liste_field_titre($langs->trans('OrderDate'),$_SERVER["PHP_SELF"],'c.date_commande','',$param, 'align="right"',$sortfield,$sortorder);
  249. print_liste_field_titre($langs->trans('DeliveryDate'),$_SERVER["PHP_SELF"],'c.date_livraison','',$param, 'align="right"',$sortfield,$sortorder);
  250. print_liste_field_titre($langs->trans('Status'),$_SERVER["PHP_SELF"],'c.fk_statut','',$param,'align="right"',$sortfield,$sortorder);
  251. print '</tr>';
  252. print '<tr class="liste_titre">';
  253. print '<td class="liste_titre">';
  254. print '<input class="flat" size="10" type="text" name="sref" value="'.$sref.'">';
  255. print '</td><td class="liste_titre" align="left">';
  256. print '<input class="flat" type="text" name="snom" value="'.$snom.'">';
  257. print '</td><td class="liste_titre" align="left">';
  258. print '<input class="flat" type="text" size="10" name="sref_client" value="'.$sref_client.'">';
  259. print '</td><td class="liste_titre">&nbsp;';
  260. print '</td><td class="liste_titre">&nbsp;';
  261. print '</td><td align="right" class="liste_titre">';
  262. print '<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")).'">';
  263. print '</td></tr>';
  264. $var=true;
  265. $total=0;
  266. $subtotal=0;
  267. $generic_commande = new Commande($db);
  268. while ($i < min($num,$limit))
  269. {
  270. $objp = $db->fetch_object($resql);
  271. $var=!$var;
  272. print '<tr '.$bc[$var].'>';
  273. print '<td nowrap="nowrap">';
  274. $generic_commande->id=$objp->rowid;
  275. $generic_commande->ref=$objp->ref;
  276. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  277. print '<td class="nobordernopadding" nowrap="nowrap">';
  278. print $generic_commande->getNomUrl(1,($viewstatut != 2?0:$objp->fk_statut));
  279. print '</td>';
  280. print '<td width="20" class="nobordernopadding" nowrap="nowrap">';
  281. if (($objp->fk_statut > 0) && ($objp->fk_statut < 3) && $db->jdate($objp->date_valid) < ($now - $conf->commande->client->warning_delay)) print img_picto($langs->trans("Late"),"warning");
  282. print '</td>';
  283. print '<td width="16" align="right" class="nobordernopadding">';
  284. $filename=dol_sanitizeFileName($objp->ref);
  285. $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($objp->ref);
  286. $urlsource=$_SERVER['PHP_SELF'].'?id='.$objp->rowid;
  287. print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
  288. print '</td></tr></table>';
  289. print '</td>';
  290. // Company
  291. $companystatic->id=$objp->socid;
  292. $companystatic->nom=$objp->nom;
  293. $companystatic->client=$objp->client;
  294. print '<td>';
  295. print $companystatic->getNomUrl(1,'customer');
  296. print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/orderstoinvoice.php?socid='.$companystatic->id.'">';
  297. // If module invoices enabled and user with invoice creation permissions
  298. if (! empty($conf->facture->enabled))
  299. {
  300. if ($user->rights->facture->creer)
  301. {
  302. if (($objp->fk_statut > 0 && $objp->fk_statut < 3) || ($objp->fk_statut == 3 && $objp->facturee == 0))
  303. {
  304. print img_picto($langs->trans("CreateInvoiceForThisCustomer").' : '.$companystatic->nom,'object_bill').'</a>';
  305. }
  306. }
  307. }
  308. print '</td>';
  309. print '<td>'.$objp->ref_client.'</td>';
  310. // Order date
  311. $y = dol_print_date($db->jdate($objp->date_commande),'%Y');
  312. $m = dol_print_date($db->jdate($objp->date_commande),'%m');
  313. $ml = dol_print_date($db->jdate($objp->date_commande),'%B');
  314. $d = dol_print_date($db->jdate($objp->date_commande),'%d');
  315. print '<td align="right">';
  316. print $d;
  317. print ' <a href="'.$_SERVER['PHP_SELF'].'?orderyear='.$y.'&amp;ordermonth='.$m.'">'.$ml.'</a>';
  318. print ' <a href="'.$_SERVER['PHP_SELF'].'?orderyear='.$y.'">'.$y.'</a>';
  319. print '</td>';
  320. // Delivery date
  321. $y = dol_print_date($db->jdate($objp->date_livraison),'%Y');
  322. $m = dol_print_date($db->jdate($objp->date_livraison),'%m');
  323. $ml = dol_print_date($db->jdate($objp->date_livraison),'%B');
  324. $d = dol_print_date($db->jdate($objp->date_livraison),'%d');
  325. print '<td align="right">';
  326. print $d;
  327. print ' <a href="'.$_SERVER['PHP_SELF'].'?deliveryyear='.$y.'&amp;deliverymonth='.$m.'">'.$ml.'</a>';
  328. print ' <a href="'.$_SERVER['PHP_SELF'].'?deliveryyear='.$y.'">'.$y.'</a>';
  329. print '</td>';
  330. // Statut
  331. print '<td align="right" nowrap="nowrap">'.$generic_commande->LibStatut($objp->fk_statut,$objp->facturee,5).'</td>';
  332. print '</tr>';
  333. $total+=$objp->total_ht;
  334. $subtotal+=$objp->total_ht;
  335. $i++;
  336. }
  337. print '</table>';
  338. print '</form>';
  339. $db->free($resql);
  340. }
  341. else
  342. {
  343. print dol_print_error($db);
  344. }
  345. llxFooter();
  346. $db->close();
  347. ?>