PageRenderTime 104ms CodeModel.GetById 60ms app.highlight 15ms RepoModel.GetById 25ms app.codeStats 1ms

/htdocs/product/index.php

https://bitbucket.org/speedealing/speedealing
PHP | 261 lines | 185 code | 36 blank | 40 comment | 50 complexity | b6b43f15d8104b79e609d816d8716a37 MD5 | raw file
  1<?php
  2/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
  4 * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
  5 *
  6 * This program is free software; you can redistribute it and/or modify
  7 * it under the terms of the GNU General Public License as published by
  8 * the Free Software Foundation; either version 3 of the License, or
  9 * (at your option) any later version.
 10 *
 11 * This program is distributed in the hope that it will be useful,
 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 * GNU General Public License for more details.
 15 *
 16 * You should have received a copy of the GNU General Public License
 17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20/**
 21 *	\file       htdocs/product/index.php
 22 *  \ingroup    product
 23 *  \brief      Page accueil des produits et services
 24 */
 25
 26require '../main.inc.php';
 27require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
 28
 29$type=isset($_GET["type"])?$_GET["type"]:(isset($_POST["type"])?$_POST["type"]:'');
 30if ($type =='' && !$user->rights->produit->lire) $type='1';	// Force global page on service page only
 31if ($type =='' && !$user->rights->service->lire) $type='0';	// Force global page on prpduct page only
 32
 33// Security check
 34if ($type=='0') $result=restrictedArea($user,'produit');
 35else if ($type=='1') $result=restrictedArea($user,'service');
 36else $result=restrictedArea($user,'produit|service');
 37
 38$langs->load("products");
 39
 40$product_static = new Product($db);
 41
 42
 43/*
 44 * View
 45 */
 46
 47$transAreaType = $langs->trans("ProductsAndServicesArea");
 48$helpurl='';
 49if (! isset($_GET["type"]))
 50{
 51	$transAreaType = $langs->trans("ProductsAndServicesArea");
 52	$helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
 53}
 54if ((isset($_GET["type"]) && $_GET["type"] == 0) || empty($conf->service->enabled))
 55{
 56	$transAreaType = $langs->trans("ProductsArea");
 57	$helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
 58}
 59if ((isset($_GET["type"]) && $_GET["type"] == 1) || empty($conf->product->enabled))
 60{
 61	$transAreaType = $langs->trans("ServicesArea");
 62	$helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
 63}
 64
 65llxHeader("",$langs->trans("ProductsAndServices"),$helpurl);
 66
 67print_fiche_titre($transAreaType);
 68
 69print '<table border="0" width="100%" class="notopnoleftnoright">';
 70
 71print '<tr><td valign="top" width="30%" class="notopnoleft">';
 72
 73/*
 74 * Zone recherche produit/service
 75 */
 76$rowspan=2;
 77if (! empty($conf->barcode->enabled)) $rowspan++;
 78print '<form method="post" action="'.DOL_URL_ROOT.'/product/liste.php">';
 79print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 80print '<table class="noborder nohover" width="100%">';
 81print "<tr class=\"liste_titre\">";
 82print '<td colspan="3">'.$langs->trans("Search").'</td></tr>';
 83print "<tr ".$bc[false]."><td>";
 84print $langs->trans("Ref").':</td><td><input class="flat" type="text" size="14" name="sref"></td>';
 85print '<td rowspan="'.$rowspan.'"><input type="submit" class="button" value="'.$langs->trans("Search").'"></td></tr>';
 86if (! empty($conf->barcode->enabled))
 87{
 88	print "<tr ".$bc[false]."><td>";
 89	print $langs->trans("BarCode").':</td><td><input class="flat" type="text" size="14" name="sbarcode"></td>';
 90	//print '<td><input type="submit" class="button" value="'.$langs->trans("Search").'"></td>';
 91	print '</tr>';
 92}
 93print "<tr ".$bc[false]."><td>";
 94print $langs->trans("Other").':</td><td><input class="flat" type="text" size="14" name="sall"></td>';
 95//print '<td><input type="submit" class="button" value="'.$langs->trans("Search").'"></td>';
 96print '</tr>';
 97print "</table></form><br>";
 98
 99
100/*
101 * Nombre de produits et/ou services
102 */
103$prodser = array();
104$prodser[0][0]=$prodser[0][1]=$prodser[1][0]=$prodser[1][1]=0;
105
106$sql = "SELECT COUNT(p.rowid) as total, p.fk_product_type, p.tosell, p.tobuy";
107$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
108$sql.= ' WHERE p.entity IN ('.getEntity($product_static->element, 1).')';
109$sql.= " GROUP BY p.fk_product_type, p.tosell, p.tobuy";
110$result = $db->query($sql);
111while ($objp = $db->fetch_object($result))
112{
113	$status=1;
114	if (! $objp->tosell && ! $objp->tobuy) $status=0;
115	$prodser[$objp->fk_product_type][$status]=$objp->total;
116}
117
118print '<table class="noborder" width="100%">';
119print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Statistics").'</td></tr>';
120if (! empty($conf->product->enabled))
121{
122	$statProducts = "<tr $bc[0]>";
123	$statProducts.= '<td><a href="liste.php?type=0&amp;tosell=0&amp;tobuy=0">'.$langs->trans("ProductsNotOnSell").'</a></td><td align="right">'.round($prodser[0][0]).'</td>';
124	$statProducts.= "</tr>";
125	$statProducts.= "<tr $bc[1]>";
126	$statProducts.= '<td><a href="liste.php?type=0&amp;tosell=1">'.$langs->trans("ProductsOnSell").'</a></td><td align="right">'.round($prodser[0][1]).'</td>';
127	$statProducts.= "</tr>";
128}
129if (! empty($conf->service->enabled))
130{
131	$statServices = "<tr $bc[0]>";
132	$statServices.= '<td><a href="liste.php?type=1&amp;tosell=0&amp;tobuy=0">'.$langs->trans("ServicesNotOnSell").'</a></td><td align="right">'.round($prodser[1][0]).'</td>';
133	$statServices.= "</tr>";
134	$statServices.= "<tr $bc[1]>";
135	$statServices.= '<td><a href="liste.php?type=1&amp;tosell=1">'.$langs->trans("ServicesOnSell").'</a></td><td align="right">'.round($prodser[1][1]).'</td>';
136	$statServices.= "</tr>";
137}
138$total=0;
139if ($type == '0')
140{
141	print $statProducts;
142	$total=round($prodser[0][0])+round($prodser[0][1]);
143}
144else if ($type == '1')
145{
146	print $statServices;
147	$total=round($prodser[1][0])+round($prodser[1][1]);
148}
149else
150{
151	print $statProducts.$statServices;
152	$total=round($prodser[1][0])+round($prodser[1][1])+round($prodser[0][0])+round($prodser[0][1]);
153}
154print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">';
155print $total;
156print '</td></tr>';
157print '</table>';
158
159print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
160
161/*
162 * Last modified products
163 */
164$max=15;
165$sql = "SELECT p.rowid, p.label, p.price, p.ref, p.fk_product_type, p.tosell, p.tobuy,";
166$sql.= " p.tms as datem";
167$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
168$sql.= " WHERE p.entity IN (".getEntity($product_static->element, 1).")";
169if ($type != '') $sql.= " AND p.fk_product_type = ".$type;
170$sql.= $db->order("p.tms","DESC");
171$sql.= $db->plimit($max,0);
172
173//print $sql;
174$result = $db->query($sql);
175if ($result)
176{
177	$num = $db->num_rows($result);
178
179	$i = 0;
180
181	if ($num > 0)
182	{
183		$transRecordedType = $langs->trans("LastModifiedProductsAndServices",$max);
184		if (isset($_GET["type"]) && $_GET["type"] == 0) $transRecordedType = $langs->trans("LastRecordedProducts",$max);
185		if (isset($_GET["type"]) && $_GET["type"] == 1) $transRecordedType = $langs->trans("LastRecordedServices",$max);
186
187		print '<table class="noborder" width="100%">';
188
189		$colnb=5;
190		if (empty($conf->global->PRODUIT_MULTIPRICES)) $colnb++;
191
192		print '<tr class="liste_titre"><td colspan="'.$colnb.'">'.$transRecordedType.'</td></tr>';
193
194		$var=True;
195
196		while ($i < $num)
197		{
198			$objp = $db->fetch_object($result);
199
200			//Multilangs
201			if (! empty($conf->global->MAIN_MULTILANGS))
202			{
203				$sql = "SELECT label";
204				$sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
205				$sql.= " WHERE fk_product=".$objp->rowid;
206				$sql.= " AND lang='". $langs->getDefaultLang() ."'";
207
208				$resultd = $db->query($sql);
209				if ($resultd)
210				{
211					$objtp = $db->fetch_object($resultd);
212					if ($objtp && $objtp->label != '') $objp->label = $objtp->label;
213				}
214			}
215
216			$var=!$var;
217			print "<tr ".$bc[$var].">";
218			print '<td nowrap="nowrap">';
219			$product_static->id=$objp->rowid;
220			$product_static->ref=$objp->ref;
221			$product_static->type=$objp->fk_product_type;
222			print $product_static->getNomUrl(1,'',16);
223			print "</td>\n";
224			print '<td>'.dol_trunc($objp->label,32).'</td>';
225			print "<td>";
226			print dol_print_date($db->jdate($objp->datem),'day');
227			print "</td>";
228			// Sell price
229			if (empty($conf->global->PRODUIT_MULTIPRICES))
230			{
231				print '<td align="right">';
232    			if ($objp->price_base_type == 'TTC') print price($objp->price_ttc).' '.$langs->trans("TTC");
233    			else print price($objp->price).' '.$langs->trans("HT");
234    			print '</td>';
235			}
236			print '<td align="right" nowrap="nowrap">';
237			print $product_static->LibStatut($objp->tosell,5,0);
238			print "</td>";
239            print '<td align="right" nowrap="nowrap">';
240            print $product_static->LibStatut($objp->tobuy,5,1);
241            print "</td>";
242			print "</tr>\n";
243			$i++;
244		}
245
246		$db->free();
247
248		print "</table>";
249	}
250}
251else
252{
253	dol_print_error($db);
254}
255
256print '</td></tr></table>';
257
258llxFooter();
259
260$db->close();
261?>