* * 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 2 of the License, or * (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 * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ * $Source$ * */ require("./pre.inc.php"); require("../propal.class.php"); require("../facture.class.php"); $user->getrights('produit'); $user->getrights('propale'); $user->getrights('facture'); $mesg = ''; if (!$user->rights->produit->lire) { accessforbidden(); } if ($_POST["action"] == 'add' && $user->rights->produit->creer) { $product = new Product($db); $product->ref = $_POST["ref"]; $product->libelle = $_POST["libelle"]; $product->price = $_POST["price"]; $product->tva_tx = $_POST["tva_tx"]; $product->type = $_POST["type"]; $product->envente = $_POST["statut"]; $product->description = $_POST["desc"]; $product->duration_value = $_POST["duration_value"]; $product->duration_unit = $_POST["duration_unit"]; $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"]; $id = $product->create($user); Header("Location: fiche.php?id=$id"); } if ($_POST["action"] == 'update' && $_POST["cancel"] <> 'Annuler' && ( $user->rights->produit->modifier || $user->rights->produit->creer)) { $product = new Product($db); if ($product->fetch($_POST["id"])) { $product->ref = $_POST["ref"]; $product->libelle = $_POST["libelle"]; $product->price = $_POST["price"]; $product->tva_tx = $_POST["tva_tx"]; $product->description = $_POST["desc"]; $product->envente = $_POST["statut"]; $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"]; $product->duration_value = $_POST["duration_value"]; $product->duration_unit = $_POST["duration_unit"]; if ($product->check()) { if ($product->update($product->id, $user)) { $_GET["action"] = ''; $mesg = 'Fiche mise à jour'; } else { $_GET["action"] = 're-edit'; $mesg = 'Fiche non mise à jour !' . "
" . $product->mesg_error; } } else { $_GET["action"] = 're-edit'; $mesg = 'Fiche non mise à jour !' . "
" . $product->mesg_error; } } Header("Location: fiche.php?id=".$product->id); } if ($_POST["action"] == 'addinpropal') { $propal = New Propal($db); $propal->fetch($_POST["propalid"]); $result = $propal->insert_product($_GET["id"], $_POST["qty"], $_POST["remise_percent"]); if ( $result < 0) { $mesg = "erreur $result"; } Header("Location: ../comm/propal.php?propalid=".$propal->id); } if ($_POST["action"] == 'addinfacture' && ( $user->rights->facture->modifier || $user->rights->facture->creer)) { $product = new Product($db); $result = $product->fetch($_GET["id"]); $facture = New Facture($db); $facture->fetch($_POST["factureid"]); $facture->addline($_POST["factureid"], addslashes($product->libelle), $product->price, $_POST["qty"], $product->tva_tx, $product->id); $action = ''; $mesg = 'Produit ajouté à la facture '; $mesg .= ''.$facture->ref.''; } if ($_POST["action"] == 'add_fourn' && $_POST["cancel"] <> 'Annuler') { $product = new Product($db); if( $product->fetch($_GET["id"]) ) { if ($product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]) > 0) { $action = ''; $mesg = 'Founisseur ajouté'; } else { $action = ''; } } } if ($_GET["action"] == 'remove_fourn') { $product = new Product($db); if( $product->fetch($_GET["id"]) ) { if ($product->remove_fournisseur($user, $_GET["id_fourn"]) > 0) { $_GET["action"] = ''; $mesg = 'Founisseur supprimé'; } else { $_GET["action"] = ''; } } } if ($_POST["action"] == 'update_price' && $_POST["cancel"] <> 'Annuler' && ( $user->rights->produit->modifier || $user->rights->produit->creer)) { $product = new Product($db); $result = $product->fetch($_GET["id"]); $product->price = ereg_replace(" ","",$_POST["price"]); if ( $product->update_price($product->id, $user) > 0 ) { $_GET["action"] = ''; $mesg = 'Fiche mise à jour'; } else { $_GET["action"] = 'edit_price'; $mesg = 'Fiche non mise à jour !' . "
" . $product->mesg_error; } } if ($_POST["cancel"] == 'Annuler') { $action = ''; Header("Location: fiche.php?id=".$_POST["id"]); } llxHeader("","","Fiche produit"); /* * Création du produit * * * * */ if ($_GET["action"] == 'create') { $nbligne=0; print "
\n"; print "\n"; print ''."\n"; print '
Nouveau '.$types[$_GET["type"]].'

'."\n"; print ''; print ''; print ''; print "".''; print "".''; print "".''; print ''; if ($_GET["type"] == 0 && defined("MAIN_MODULE_STOCK")) { print "".''; } else { print ''; } print '"; if ($_GET["type"] == 1) { print "".''; } print "".''; print '
Référence
Libellé
Prix de vente
Taux TVA'; $html = new Form($db); print $html->select_tva("tva_tx"); print '
Statut'; print '
Seuil stock'; print ''; print '
Description'; print '
Durée  '; print 'jour '; print 'semaine '; print 'mois '; print 'année'; print '
 
'; print '
'; } else { if ($_GET["id"]) { if ($_GET["action"] <> 're-edit') { $product = new Product($db); $result = $product->fetch($_GET["id"]); } if ( $result ) { if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') { /* * Fiche en visu */ // Zone recherche print ''; print ''; print '
'; print ''; print 'Réf :  '; print '
'; print 'Libellé :  '; print '
'; print '
'; $head[0][0] = DOL_URL_ROOT."/product/fiche.php?id=".$product->id; $head[0][1] = 'Fiche'; $head[1][0] = DOL_URL_ROOT."/product/price.php?id=".$product->id; $head[1][1] = 'Prix'; $h = 2; if($product->type == 0) { $head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id; $head[$h][1] = 'Stock'; $h++; } $head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id; $head[$h][1] = 'Statistiques'; dolibarr_fiche_head($head, 0, 'Fiche '.$types[$product->type].' : '.$product->ref); print($mesg); print ''; print ""; print ''; print ''; print ''; print ''; if ($product->type == 0) { $nblignefour=4; } else { $nblignefour=3; } print ''; print ''; if ($product->type == 0 && defined("MAIN_MODULE_STOCK")) { print ''; if ($product->no_stock) { print "'; } print ""; if ($product->type == 1) { print "".''; } print "
Référence'.$product->ref.''; if ($product->envente) { print "En vente"; } else { print "Cet article n'est pas en vente"; } print '
Libellé'.$product->libelle.'
Prix de vente'.price($product->price).''; print 'Fournisseurs [Ajouter]'; $sql = "SELECT s.nom, s.idp"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur as pf"; $sql .=" WHERE pf.fk_soc = s.idp AND pf.fk_product = ".$product->id; $sql .= " ORDER BY lower(s.nom)"; if ( $db->query($sql) ) { $num = $db->num_rows(); $i = 0; print ''; $var=True; while ($i < $num) { $objp = $db->fetch_object($i); $var=!$var; print ""; print ''; print ''; $i++; } print '
'.$objp->nom.''; print ''; print '
'; $db->free(); } print '
Taux TVA'.$product->tva_tx.' %
StockPas de définition de stock pour ce produit"; } else { if ($product->stock_reel <= $product->seuil_stock_alerte) { print ''.$product->stock_reel.' Seuil : '.$product->seuil_stock_alerte; } else { print "".$product->stock_reel; } } print '
Description".nl2br($product->description)."
Durée'.$product->duration_value.' '; if ($product->duration_value > 1) { $plu = "s"; } switch ($product->duration_unit) { case "d": print "jour$plu "; break; case "w": print "semaine$plu "; break; case "m": print 'mois '; break; case "y": print "an$plu "; break; } print '
"; } print "
\n"; if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer) { print '
Nouveau prix
'; print '
'; print ''; print ''; print ''; print ''; print ''; print '
Prix de vente
 '; print '
'; print '
'; } /* * Ajouter un fournisseur * */ if ($_GET["action"] == 'ajout_fourn' && $user->rights->produit->creer) { print_titre ("Ajouter un fournisseur"); print '
'; print ''; print ''; print ''; print ''; print ''; print '
FournisseursRéférence
 '; print '
'; print '
'; } } /* * Fiche en mode edition */ if (($_GET["action"] == 'edit' || $_GET["action"] == 're-edit') && $user->rights->produit->creer) { print_fiche_titre('Edition de la fiche '.$types[$product->type].' : '.$product->ref, $mesg); print "
\n"; print ''; print ''; print ''; print "".''; print ''; print "".''; print "".''; if ($product->type == 0 && defined("MAIN_MODULE_STOCK")) { print "".''; } else { print ''; } print "".'"; if ($product->type == 1) { print "".''; } print "".''; print '
Référence
Libellé
Taux TVA'; $html = new Form($db); print $html->select_tva("tva_tx", $product->tva_tx); print '
Statut'; print '
Seuil stock'; print ''; print '
Description'; print '
Durée'; switch ($product->duration_unit) { case "d": print 'jour '; print 'semaine '; print 'mois '; print 'année'; break; case "w": print 'jour '; print 'semaine '; print 'mois '; print 'année'; break; case "m": print 'jour '; print 'semaine '; print 'mois '; print 'année'; break; case "y": print 'jour '; print 'semaine '; print 'mois '; print 'année'; break; default: print 'jour '; print 'semaine '; print 'mois '; print 'année'; break; } print '
 '; print '
'; print '
'; } } else { print "Error"; } } /* ************************************************************************** */ /* */ /* Barre d'action */ /* */ /* ************************************************************************** */ print "
\n"; if ($_GET["action"] == '') { if ($user->rights->produit->modifier || $user->rights->produit->creer) { print 'Changer le prix'; } } if ($_GET["action"] == '') { if ($user->rights->produit->modifier || $user->rights->produit->creer) { print 'Editer'; } } if ($product->type == 0 && defined("MAIN_MODULE_STOCK")) { print 'Correction stock'; } print "
"; if ($_GET["id"] && $_GET["action"] == '' && $product->envente) { $htmls = new Form($db); $propal = New Propal($db); print ''; if($user->rights->propale->creer) { print "".''; print ''; print ''; print "".''; if($user->rights->propale->creer) { print ''; } print ''; } if($user->rights->facture->creer) { print "".''; print "".'
'; print_titre("Ajouter à ma proposition") . ''; print_titre("Ajouter aux autres propositions") . '
'; $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.ref,".$db->pdate("p.datep")." as dp"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p"; $sql .=" WHERE p.fk_soc = s.idp AND p.fk_statut = 0 AND p.fk_user_author = ".$user->id; $sql .= " ORDER BY p.datec DESC, tms DESC"; if ( $db->query($sql) ) { $num = $db->num_rows(); $i = 0; print ''; $var=True; while ($i < $num) { $objp = $db->fetch_object($i); $var=!$var; print ""; print "\n"; print "\n"; print "\n"; print ''; print ''; print '"; print ''; $i++; } print "
propalid\">$objp->refidp\">$objp->nom". strftime("%d %B %Y",$objp->dp)."
'; print ' Rem.'; print ' %'; print " ".$product->stock_proposition; print ''; print ''; print "
"; $db->free(); } print '
'; $otherprop = $propal->liste_array(1, '<>'.$user->id); if (sizeof($otherprop)) { print '
'; print ''; print ''; print "".''; print '
Autres Propositions'; $htmls->select_array("propalid", $otherprop); print ''; print ' Rem.'; print ' %'; print ''; print ''; print '
'; } print '
'; print_titre("Ajouter à ma facture"); print ''; print_titre("Ajouter aux autres factures"); print '
'; $sql = "SELECT s.nom, s.idp, f.rowid as factureid, f.facnumber,".$db->pdate("f.datef")." as df"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f"; $sql .=" WHERE f.fk_soc = s.idp AND f.fk_statut = 0 AND f.fk_user_author = ".$user->id; $sql .= " ORDER BY f.datec DESC, f.rowid DESC"; if ( $db->query($sql) ) { $num = $db->num_rows(); $i = 0; print ''; $var=True; while ($i < $num) { $objp = $db->fetch_object( $i); $var=!$var; print ""; print "\n"; print "\n"; print "\n"; print ''; print ''; print ''; print '"; print ''; $i++; } print "
factureid\">$objp->facnumberidp\">$objp->nom". strftime("%d %B %Y",$objp->df)."
'; print ' Rem.'; print ' %'; print ''; print ''; print "
"; $db->free(); } else { print $db->error() . "
" . $sql; } print '
'; print '
'; } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>