PageRenderTime 116ms CodeModel.GetById 53ms app.highlight 8ms RepoModel.GetById 53ms app.codeStats 0ms

/htdocs/cashdesk/facturation.php

https://bitbucket.org/speedealing/speedealing
PHP | 165 lines | 114 code | 22 blank | 29 comment | 25 complexity | 0d86f23f709bb4b6edf800bd899fd596 MD5 | raw file
  1<?php
  2/* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
  3 * Copyright (C) 2008-2011 Laurent Destailleur   <eldy@uers.sourceforge.net>
  4 * Copyright (C) 2011 Juanjo Menent			  	 <jmenent@2byte.es>
  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/cashdesk/facturation.php
 22 *	\ingroup    cashdesk
 23 *	\brief      Include to show main page for cashdesk module
 24 */
 25
 26// Get list of articles (in warehouse '$conf_fkentrepot' if defined and stock module enabled)
 27if ( $_GET['filtre'] ) {
 28
 29	// Avec filtre
 30	$ret=array(); $i=0;
 31
 32	$sql = "SELECT p.rowid, p.ref, p.label, p.tva_tx, p.fk_product_type";
 33	if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
 34	$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
 35	if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = '".$conf_fkentrepot."'";
 36	$sql.= " WHERE p.entity IN (".getEntity('product', 1).")";
 37	$sql.= " AND p.tosell = 1";
 38	if(!$conf->global->CASHDESK_SERVICES) $sql.= " AND p.fk_product_type = 0";
 39	$sql.= " AND (p.ref LIKE '%".$_GET['filtre']."%' OR p.label LIKE '%".$_GET['filtre']."%' ";
 40	if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '%".$_GET['filtre']."%')";
 41	else $sql.= ")";
 42
 43	$sql.= " ORDER BY label";
 44
 45	dol_syslog("facturation.php sql=".$sql);
 46	$resql=$db->query($sql);
 47	if ($resql)
 48	{
 49		while ( $tab = $db->fetch_array($resql) )
 50		{
 51			foreach ( $tab as $cle => $valeur )
 52			{
 53				$ret[$i][$cle] = $valeur;
 54			}
 55			$i++;
 56		}
 57	}
 58	else
 59	{
 60		dol_print_error($db);
 61	}
 62	$tab_designations=$ret;
 63} else {
 64
 65	// Sans filtre
 66	$ret=array();
 67	$i=0;
 68
 69	$sql = "SELECT p.rowid, ref, label, tva_tx, p.fk_product_type";
 70	if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
 71	$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
 72	if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = '".$conf_fkentrepot."'";
 73	$sql.= " WHERE p.entity IN (".getEntity('product', 1).")";
 74	$sql.= " AND p.tosell = 1";
 75	if(!$conf->global->CASHDESK_SERVICES) $sql.= " AND p.fk_product_type = 0";
 76	$sql.= " ORDER BY p.label";
 77
 78	dol_syslog($sql);
 79	$resql=$db->query($sql);
 80	if ($resql)
 81	{
 82		while ( $tab = $db->fetch_array($resql) )
 83		{
 84			foreach ( $tab as $cle => $valeur )
 85			{
 86				$ret[$i][$cle] = $valeur;
 87			}
 88			$i++;
 89		}
 90	}
 91	else
 92	{
 93		dol_print_error($db);
 94	}
 95	$tab_designations=$ret;
 96}
 97
 98$nbr_enreg = count($tab_designations);
 99
100if ( $nbr_enreg > 1 )
101{
102	if ( $nbr_enreg > $conf_taille_listes )
103	{
104		$top_liste_produits = '----- '.$conf_taille_listes.' '.$langs->transnoentitiesnoconv("CashDeskProducts").' '.$langs->trans("CashDeskOn").' '.$nbr_enreg.' -----';
105	}
106	else
107	{
108		$top_liste_produits = '----- '.$nbr_enreg.' '.$langs->transnoentitiesnoconv("CashDeskProducts").' '.$langs->trans("CashDeskOn").' '.$nbr_enreg.' -----';
109	}
110
111}
112else if ( $nbr_enreg == 1 )
113{
114	$top_liste_produits = '----- 1 '.$langs->transnoentitiesnoconv("ProductFound"). ' -----';
115}
116else
117{
118	$top_liste_produits = '----- '.$langs->transnoentitiesnoconv("NoProductFound"). ' -----';
119}
120
121
122// Recuperation des taux de tva
123global $mysoc;
124
125$ret=array();
126$i=0;
127
128$sql = "SELECT t.rowid, t.taux";
129$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t";
130$sql.= ", ".MAIN_DB_PREFIX."c_pays as p";
131$sql.= " WHERE t.fk_pays = p.rowid";
132$sql.= " AND t.active = 1";
133$sql.= " AND p.code = '".$mysoc->country_code."'";
134//print $request;
135
136$res = $db->query($sql);
137if ($res)
138{
139	while ( $tab = $db->fetch_array($res) )
140	{
141		foreach ( $tab as $cle => $valeur )
142		{
143			$ret[$i][$cle] = $valeur;
144		}
145		$i++;
146	}
147}
148else
149{
150	dol_print_error($db);
151}
152$tab_tva = $ret;
153
154
155// Reinitialisation du mode de paiement, en cas de retour aux achats apres validation
156$obj_facturation->getSetPaymentMode('RESET');
157$obj_facturation->montantEncaisse('RESET');
158$obj_facturation->montantRendu('RESET');
159$obj_facturation->paiementLe('RESET');
160
161
162// Affichage des templates
163require ('tpl/facturation1.tpl.php');
164
165?>