dolibarr/htdocs/cashdesk/facturation.php

187 lines
5.3 KiB
PHP
Raw Normal View History

2008-09-30 01:18:52 +02:00
<?php
2008-11-18 23:44:53 +01:00
/* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
2011-10-01 13:23:10 +02:00
* Copyright (C) 2008-2011 Laurent Destailleur <eldy@uers.sourceforge.net>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Marcos García <marcosgdf@gmail.com>
2013-12-16 22:56:59 +01:00
* Copyright (C) 2013 Adolfo Segura <adolfo.segura@gmail.com>
*
2008-09-30 01:18:52 +02:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2008-09-30 01:18:52 +02:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2011-08-01 00:21:57 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2008-09-30 01:18:52 +02:00
*/
/**
* \file htdocs/cashdesk/facturation.php
* \ingroup cashdesk
* \brief Include to show main page for cashdesk module
*/
// Get list of articles (in warehouse '$conf_fkentrepot' if defined and stock module enabled)
if ( GETPOST('filtre') ) {
2008-09-30 01:18:52 +02:00
2008-10-26 16:17:52 +01:00
// Avec filtre
2008-11-18 23:44:53 +01:00
$ret=array(); $i=0;
2009-10-20 17:23:32 +02:00
$sql = "SELECT p.rowid, p.ref, p.label, p.tva_tx, p.fk_product_type";
2012-09-15 11:21:22 +02:00
if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
2009-11-11 17:25:44 +01:00
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
2012-09-15 11:21:22 +02:00
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."'";
$sql.= " WHERE p.entity IN (".getEntity('product', 1).")";
$sql.= " AND p.tosell = 1";
if(!$conf->global->CASHDESK_SERVICES) $sql.= " AND p.fk_product_type = 0";
$sql.= " AND (p.ref LIKE '%".$db->escape(GETPOST('filtre'))."%' OR p.label LIKE '%".$db->escape(GETPOST('filtre'))."%'";
if (! empty($conf->barcode->enabled)) {
$filtre = GETPOST('filtre');
//If the barcode looks like an EAN13 format and the last digit is included in it,
//then whe look for the 12-digit too
//As the twelve-digit string will also hit the 13-digit code, we only look for this one
if (strlen($filtre) == 13) {
$crit_12digit = substr($filtre, 0, 12);
$sql .= " OR p.barcode LIKE '%".$db->escape($crit_12digit)."%')";
} else {
$sql.= " OR p.barcode LIKE '%".$db->escape($filtre)."%')";
}
}
else $sql.= ")";
2009-11-11 17:25:44 +01:00
$sql.= " ORDER BY label";
dol_syslog("facturation.php sql=".$sql);
$resql=$db->query($sql);
2009-10-20 17:23:32 +02:00
if ($resql)
2008-11-18 23:44:53 +01:00
{
$nbr_enreg = $db->num_rows($resql);
while ($i < $conf_taille_listes && $tab = $db->fetch_array($resql) )
2008-11-18 23:44:53 +01:00
{
2009-10-20 17:23:32 +02:00
foreach ( $tab as $cle => $valeur )
{
$ret[$i][$cle] = $valeur;
}
$i++;
2008-11-18 23:44:53 +01:00
}
2013-06-07 19:12:38 +02:00
$db->free($resql);
2009-10-20 17:23:32 +02:00
}
else
{
dol_print_error($db);
2008-11-18 23:44:53 +01:00
}
$tab_designations=$ret;
2008-10-26 16:17:52 +01:00
} else {
2008-09-30 01:18:52 +02:00
2008-10-26 16:17:52 +01:00
// Sans filtre
2009-11-11 17:35:58 +01:00
$ret=array();
$i=0;
$sql = "SELECT p.rowid, ref, label, tva_tx, p.fk_product_type";
2012-09-15 11:21:22 +02:00
if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
2009-11-11 17:25:44 +01:00
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
2012-09-15 11:21:22 +02:00
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."'";
$sql.= " WHERE p.entity IN (".getEntity('product', 1).")";
$sql.= " AND p.tosell = 1";
if(!$conf->global->CASHDESK_SERVICES) $sql.= " AND p.fk_product_type = 0";
2009-11-11 17:41:34 +01:00
$sql.= " ORDER BY p.label";
2009-11-11 17:25:44 +01:00
dol_syslog($sql);
$resql=$db->query($sql);
2009-11-11 17:35:58 +01:00
if ($resql)
2008-11-18 23:44:53 +01:00
{
$nbr_enreg = $db->num_rows($resql);
while ($i < $conf_taille_listes && $tab = $db->fetch_array($resql))
2008-11-18 23:44:53 +01:00
{
2009-11-11 17:35:58 +01:00
foreach ( $tab as $cle => $valeur )
{
$ret[$i][$cle] = $valeur;
}
$i++;
2008-11-18 23:44:53 +01:00
}
2013-06-07 19:12:38 +02:00
$db->free($resql);
2009-11-11 17:35:58 +01:00
}
else
{
dol_print_error($db);
2008-11-18 23:44:53 +01:00
}
$tab_designations=$ret;
2008-10-26 16:17:52 +01:00
}
2008-09-30 01:18:52 +02:00
//$nbr_enreg = count($tab_designations);
2008-09-30 01:18:52 +02:00
2011-10-13 20:32:03 +02:00
if ( $nbr_enreg > 1 )
{
if ( $nbr_enreg > $conf_taille_listes )
{
$top_liste_produits = '----- '.$conf_taille_listes.' '.$langs->transnoentitiesnoconv("CashDeskProducts").' '.$langs->trans("CashDeskOn").' '.$nbr_enreg.' -----';
2011-10-13 20:32:03 +02:00
}
else
{
$top_liste_produits = '----- '.$nbr_enreg.' '.$langs->transnoentitiesnoconv("CashDeskProducts").' '.$langs->trans("CashDeskOn").' '.$nbr_enreg.' -----';
2008-10-26 16:17:52 +01:00
}
2008-09-30 01:18:52 +02:00
2011-10-13 20:32:03 +02:00
}
else if ( $nbr_enreg == 1 )
{
$top_liste_produits = '----- 1 '.$langs->transnoentitiesnoconv("ProductFound"). ' -----';
2011-10-13 20:32:03 +02:00
}
else
{
$top_liste_produits = '----- '.$langs->transnoentitiesnoconv("NoProductFound"). ' -----';
2008-10-26 16:17:52 +01:00
}
2008-09-30 01:18:52 +02:00
2008-11-18 23:44:53 +01:00
// Recuperation des taux de tva
2008-10-26 16:17:52 +01:00
global $mysoc;
2009-11-11 17:25:44 +01:00
2009-11-11 17:35:58 +01:00
$ret=array();
$i=0;
2009-11-11 17:25:44 +01:00
$sql = "SELECT t.rowid, t.taux";
2009-11-11 17:41:34 +01:00
$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t";
$sql.= ", ".MAIN_DB_PREFIX."c_pays as p";
2009-11-11 17:25:44 +01:00
$sql.= " WHERE t.fk_pays = p.rowid";
$sql.= " AND t.active = 1";
$sql.= " AND p.code = '".$mysoc->country_code."'";
2008-10-26 16:17:52 +01:00
//print $request;
2008-11-18 23:44:53 +01:00
2013-06-24 19:34:02 +02:00
$resql = $db->query($sql);
if ($resql)
2008-11-18 23:44:53 +01:00
{
2013-06-24 19:34:02 +02:00
while ( $tab = $db->fetch_array($resql) )
2008-11-18 23:44:53 +01:00
{
2009-11-11 17:35:58 +01:00
foreach ( $tab as $cle => $valeur )
{
$ret[$i][$cle] = $valeur;
}
$i++;
2008-11-18 23:44:53 +01:00
}
2013-06-07 19:12:38 +02:00
$db->free($resql);
2009-11-11 17:35:58 +01:00
}
else
{
dol_print_error($db);
2008-11-18 23:44:53 +01:00
}
$tab_tva = $ret;
2008-09-30 01:18:52 +02:00
2008-11-18 23:44:53 +01:00
// Reinitialisation du mode de paiement, en cas de retour aux achats apres validation
2012-01-06 15:26:32 +01:00
$obj_facturation->getSetPaymentMode('RESET');
2012-03-18 19:23:01 +01:00
$obj_facturation->montantEncaisse('RESET');
$obj_facturation->montantRendu('RESET');
$obj_facturation->paiementLe('RESET');
2008-09-30 01:18:52 +02:00
2008-10-26 16:17:52 +01:00
// Affichage des templates
2010-03-30 15:26:20 +02:00
require ('tpl/facturation1.tpl.php');
2008-09-30 01:18:52 +02:00
?>