Nouveaux fichiers

This commit is contained in:
Rodolphe Quiedeville 2003-11-13 17:36:45 +00:00
parent f40d4cd948
commit 247a718553
5 changed files with 1715 additions and 0 deletions

View File

@ -0,0 +1,341 @@
<?PHP
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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");
$user->getrights('commande');
$user->getrights('expedition');
if (!$user->rights->commande->lire)
accessforbidden();
require("../project.class.php");
require("../propal.class.php");
require("../product/stock/entrepot.class.php");
/*
* Sécurité accés client
*/
if ($user->societe_id > 0)
{
$action = '';
$socidp = $user->societe_id;
}
/*
*
*/
if ($HTTP_POST_VARS["action"] == 'confirm_valid' && $HTTP_POST_VARS["confirm"] == yes && $user->rights->commande->valider)
{
$commande = new Commande($db);
$commande->fetch($_GET["id"]);
$result = $commande->cloture($user);
}
llxHeader('','Fiche commande','');
$html = new Form($db);
/* *************************************************************************** */
/* */
/* Mode vue et edition */
/* */
/* *************************************************************************** */
if ($id > 0)
{
$commande = New Commande($db);
if ( $commande->fetch($id) > 0)
{
$commande->livraison_array();
$soc = new Societe($db);
$soc->fetch($commande->soc_id);
$author = new User($db);
$author->id = $commande->user_author_id;
$author->fetch();
print_titre("Commande : ".$commande->ref);
/*
* Commande
*/
print '<form method="post" action="fiche.php">';
print '<input type="hidden" name="action" value="create">';
print '<input type="hidden" name="commande_id" value="'.$commande->id.'">';
print '<table class="border" cellspacing="0" cellpadding="2" width="100%">';
print '<tr><td width="20%">Client</td>';
print "<td colspan=\"2\">";
print '<b><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></b></td>';
print '<td width="50%">';
print $commande->statuts[$commande->statut];
print "</td></tr>";
print "<tr><td>Date</td>";
print "<td colspan=\"2\">".strftime("%A %d %B %Y",$commande->date)."</td>\n";
print '<td width="50%">Source : ' . $commande->sources[$commande->source] ;
if ($commande->source == 0)
{
/* Propale */
$propal = new Propal($db);
$propal->fetch($commande->propale_id);
print ' -> <a href="'.DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id.'">'.$propal->ref.'</a>';
}
print "</td></tr>";
print "<tr><td>Auteur</td><td colspan=\"2\">$author->fullname</td>";
print '<td>- ';
print "&nbsp;</td></tr>";
if ($commande->note)
{
print '<tr><td>Note</td></tr>';
print '<tr><td colspan="3">Note : '.nl2br($commande->note)."</td></tr>";
}
print '<tr><td colspan="4">';
/*
* Lignes de commandes
*
*/
echo '<table class="liste" width="100%" cellspacing="0" cellpadding="3">';
$sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice";
$sql .= " FROM llx_commandedet as l WHERE l.fk_commande = $id ORDER BY l.rowid";
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
$i = 0; $total = 0;
if ($num)
{
print '<tr class="liste_titre">';
print '<td width="54%">Description</td>';
print '<td align="center">Quan. Commandée</td>';
print '<td align="center">Quan. livrée</td>';
print '<td align="center">Reste à livrer</td>';
if (defined("MAIN_MODULE_STOCK"))
{
print '<td width="12%" align="center">Stock</td>';
}
print "</tr>\n";
}
$var=True;
$reste_a_livrer = array();
while ($i < $num)
{
$objp = $db->fetch_object( $i);
print "<TR $bc[$var]>";
if ($objp->fk_product > 0)
{
$product = new Product($db);
$product->fetch($objp->fk_product);
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->description)).'</a></td>';
}
else
{
print "<td>".stripslashes(nl2br($objp->description))."</TD>\n";
}
print '<td align="center">'.$objp->qty.'</td>';
print '<td align="center">';
$quantite_livree = $commande->livraisons[$objp->fk_product];
print $quantite_livree;
print '</td>';
$reste_a_livrer[$objp->fk_product] = $objp->qty - $quantite_livree;
$reste_a_livrer_x = $objp->qty - $quantite_livree;
$reste_a_livrer_total = $reste_a_livrer_total + $reste_a_livrer_x;
print '<td align="center">';
print $reste_a_livrer[$objp->fk_product];
print '</td>';
if (defined("MAIN_MODULE_STOCK"))
{
if ($product->stock_reel < $reste_a_livrer_x)
{
print '<td align="center" class="alerte">'.$product->stock_reel.'</td>';
}
else
{
print '<td align="center">'.$product->stock_reel.'</td>';
}
}
print "</tr>";
$i++;
$var=!$var;
}
$db->free();
print "</table>";
}
else
{
print $db->error();
}
/*
*
*
*/
if ($reste_a_livrer_total > 0)
{
$entrepot = new Entrepot($db);
print '<tr><td width="20%">Entrepôt</td>';
print '<td colspan="3">';
$html->select_array("entrepot_id",$entrepot->list_array());
print '</td></tr>';
print '<tr><td colspan="4" align="center"><input type="submit" value="Créer"></td></tr>';
}
print "</table>";
print "</form>\n";
/*
* Alerte de seuil
*
*/
if ($reste_a_livrer_total > 0 && defined("MAIN_MODULE_STOCK"))
{
print '<br><table class="liste" cellpadding="3" width="100%"><tr>';
foreach ($reste_a_livrer as $key => $value)
{
if ($value > 0)
{
$sql = "SELECT e.label as entrepot, ps.reel, p.label ";
$sql .= " FROM llx_entrepot as e, llx_product_stock as ps, llx_product as p";
$sql .= " WHERE e.rowid = ps.fk_entrepot AND ps.fk_product = p.rowid AND ps.fk_product = $key";
$sql .= " AND reel < $value";
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
$i = 0;
$var=True;
while ($i < $num)
{
$obja = $db->fetch_object( $i);
print "<tr $bc[$var]>";
print '<td width="54%">'.$obja->label.'</td><td>'.$obja->entrepot.'</td><td><b>Stock : '.$obja->reel.'</b></td>';
print "</tr>\n";
$i++;
}
$db->free();
}
}
}
print "</table>";
}
/*
*
*
*/
if ($user->societe_id == 0)
{
print '<p><table id="actions" width="100%"><tr>';
print '<td align="center" width="20%">-</td>';
print '<td align="center" width="20%">-</td>';
if ($user->rights->expedition->valider && $reste_a_livrer_total == 0)
{
print '<td align="center" width="20%"><a href="commande.php?id='.$_GET["id"].'&amp;action=cloture">Clôturer</a></td>';
}
else
{
print '<td align="center" width="20%">-</td>';
}
print '<td align="center" width="20%">-</td>';
print '<td align="center" width="20%">-</td>';
print "</tr></table>";
}
/*
* Déjà livré
*
*
*/
$sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande, ed.qty as qty_livre, e.ref, e.rowid as expedition_id";
$sql .= " FROM llx_commandedet as cd , llx_expeditiondet as ed, llx_expedition as e";
$sql .= " WHERE cd.fk_commande = $id AND cd.rowid = ed.fk_commande_ligne AND ed.fk_expedition = e.rowid";
$sql .= " ORDER BY cd.fk_product";
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
$i = 0; $total = 0;
if ($num)
{
print '<br><table class="liste" cellpadding="3" width="100%"><tr>';
print '<tr class="liste_titre">';
print '<td width="54%">Description</td>';
print '<td align="center">Quan. livrée</td>';
print '<td align="center">Expédition</td>';
print "</tr>\n";
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object( $i);
print "<TR $bc[$var]>";
if ($objp->fk_product > 0)
{
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->description)).'</a></td>';
}
else
{
print "<td>".stripslashes(nl2br($objp->description))."</TD>\n";
}
print '<td align="center">'.$objp->qty_livre.'</td>';
print '<td align="center"><a href="fiche.php?id='.$objp->expedition_id.'">'.$objp->ref.'</a></td>';
$i++;
}
print '</table>';
}
}
}
else
{
/* Commande non trouvée */
print "Commande inexistante ou accés refusé";
}
}
$db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
?>

View File

@ -0,0 +1,400 @@
<?PHP
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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$
*
*/
class Expedition
{
var $db ;
var $id ;
var $brouillon;
var $entrepot_id;
/**
* Initialisation
*
*/
Function Expedition($DB)
{
$this->db = $DB;
$this->lignes = array();
$this->sources[0] = "Proposition commerciale";
$this->sources[1] = "Internet";
$this->sources[2] = "Courrier";
$this->sources[3] = "Téléphone";
$this->sources[4] = "Fax";
$this->statuts[-1] = "Annulée";
$this->statuts[0] = "Brouillon";
$this->statuts[1] = "Validée";
$this->products = array();
}
/**
* Créé
*
*
*/
Function create($user)
{
require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php";
$error = 0;
/* On positionne en mode brouillon la commande */
$this->brouillon = 1;
$this->user = $user;
$this->db->begin();
$sql = "INSERT INTO llx_expedition (date_creation, fk_user_author, date_expedition, fk_commande, fk_entrepot) ";
$sql .= " VALUES (now(), $user->id, ".$this->db->idate($this->date_expedition).",$this->commande_id, $this->entrepot_id)";
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
/*
*
*
*/
$sql = "UPDATE llx_expedition SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
if ($this->db->query($sql))
{
$this->commande = new Commande($this->db);
$this->commande->id = $this->commande_id;
$this->commande->fetch_lignes();
/*
* Insertion des produits dans la base
*/
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{
//TODO
if (! $this->create_line(0, $this->lignes[$i]->commande_ligne_id, $this->lignes[$i]->qty))
{
$error++;
}
}
/*
*
*
*/
$sql = "UPDATE llx_commande SET fk_statut = 2 WHERE rowid=".$this->commande_id;
if (! $this->db->query($sql))
{
$error++;
}
if ($error ==0)
{
$this->db->commit();
}
else
{
$this->db->rollback();
}
return $this->id;
}
else
{
$error++;
return -1;
}
}
else
{
$error++;
print $this->db->error() . '<b><br>'.$sql;
return 0;
}
}
/**
*
*
*/
Function create_line($transaction, $commande_ligne_id, $qty)
{
$error = 0;
$mouvS = new MouvementStock($this->db);
$idprod = 0;
$j = 0;
while (($j < sizeof($this->commande->lignes)) && idprod == 0)
{
if ($this->commande->lignes[$j]->id == $commande_ligne_id)
{
$idprod = $this->commande->lignes[$j]->product_id;
}
$j++;
}
if (! $mouvS->livraison($this->user, $idprod, $this->entrepot_id, $qty, 0) )
{
$error++;
}
$sql = "INSERT INTO llx_expeditiondet (fk_expedition, fk_commande_ligne, qty)";
$sql .= " VALUES ($this->id,".$commande_ligne_id.",".$qty.")";
if (! $this->db->query($sql) )
{
$error++;
}
if ($error == 0 )
{
return 1;
}
}
/**
*
* Lit une commande
*
*/
Function fetch ($id)
{
$sql = "SELECT e.rowid, e.date_creation, e.ref, e.fk_user_author, e.fk_statut, e.fk_commande";
$sql .= ", ".$this->db->pdate("e.date_expedition")." as date_expedition ";
$sql .= " FROM llx_expedition as e";
$sql .= " WHERE e.rowid = $id";
$result = $this->db->query($sql) ;
if ( $result )
{
$obj = $this->db->fetch_object();
$this->id = $obj->rowid;
$this->ref = $obj->ref;
$this->statut = $obj->fk_statut;
$this->commande_id = $obj->fk_commande;
$this->user_author_id = $obj->fk_user_author;
$this->date = $obj->date_expedition;
$this->db->free();
if ($this->statut == 0)
$this->brouillon = 1;
return 1;
}
else
{
print $this->db->error();
return -1;
}
}
/**
* Valide l'expedition
*
*
*/
Function valid($user)
{
$result = 0;
if ($user->rights->expedition->valider)
{
$sql = "UPDATE llx_expedition SET ref='EXP".$this->id."', fk_statut = 1, date_valid=now(), fk_user_valid=$user->id";
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
if ($this->db->query($sql) )
{
$result = 1;
}
else
{
$result = -1;
print $this->db->error() . ' in ' . $sql;
}
}
return $result ;
}
/**
* Annule la commande
*
*
*/
Function cancel($user)
{
if ($user->rights->commande->valider)
{
$sql = "UPDATE llx_commande SET fk_statut = -1";
$sql .= " WHERE rowid = $this->id AND fk_statut = 1 ;";
if ($this->db->query($sql) )
{
return 1;
}
else
{
print $this->db->error() . ' in ' . $sql;
}
}
}
/**
* Ajoute un produit
*
*/
Function insert_product_generic($p_desc, $p_price, $p_qty, $p_tva_tx=19.6, $p_product_id=0, $remise_percent=0)
{
if ($this->statut == 0)
{
if (strlen(trim($p_qty)) == 0)
{
$p_qty = 1;
}
$p_price = ereg_replace(",",".",$p_price);
$price = $p_price;
$subprice = $p_price;
if ($remise_percent > 0)
{
$remise = round(($p_price * $remise_percent / 100), 2);
$price = $p_price - $remise;
}
$sql = "INSERT INTO llx_commandedet (fk_commande, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
$sql .= " (".$this->id.", $p_product_id,". $p_qty.",". $price.",".$p_tva_tx.",'".$p_desc."',$remise_percent, $subprice) ; ";
if ($this->db->query($sql) )
{
if ($this->update_price() > 0)
{
return 1;
}
else
{
return -1;
}
}
else
{
print $this->db->error();
print "<br>".$sql;
return -2;
}
}
}
/**
* Ajoute une ligne
*
*/
Function addline( $id, $qty )
{
$num = sizeof($this->lignes);
$ligne = new ExpeditionLigne();
$ligne->commande_ligne_id = $id;
$ligne->qty = $qty;
$this->lignes[$num] = $ligne;
}
/**
*
*
*/
Function delete_line($idligne)
{
if ($this->statut == 0)
{
$sql = "DELETE FROM llx_commandedet WHERE rowid = $idligne";
if ($this->db->query($sql) )
{
$this->update_price();
return 1;
}
else
{
return 0;
}
}
}
/**
* Supprime la fiche
*
*/
Function delete()
{
$this->db->begin();
$sql = "DELETE FROM llx_expeditiondet WHERE fk_expedition = $this->id ;";
if ( $this->db->query($sql) )
{
$sql = "DELETE FROM llx_expedition WHERE rowid = $this->id;";
if ( $this->db->query($sql) )
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -2;
}
}
else
{
$this->db->rollback();
return -1;
}
}
/**
* Class la commande
*
*
*/
Function classin($cat_id)
{
$sql = "UPDATE llx_commande SET fk_projet = $cat_id";
$sql .= " WHERE rowid = $this->id;";
if ($this->db->query($sql) )
{
return 1;
}
else
{
print $this->db->error() . ' in ' . $sql;
}
}
}
class ExpeditionLigne
{
}
?>

634
htdocs/expedition/fiche.php Normal file
View File

@ -0,0 +1,634 @@
<?PHP
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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");
$user->getrights('commande');
$user->getrights('expedition');
if (!$user->rights->expedition->lire)
accessforbidden();
require("../project.class.php");
require("../propal.class.php");
require("../product/stock/entrepot.class.php");
/*
* Sécurité accés client
*/
if ($user->societe_id > 0)
{
$action = '';
$socidp = $user->societe_id;
}
/*
*
*/
if ($HTTP_POST_VARS["action"] == 'classin')
{
$commande = new Commande($db);
$commande->fetch($_GET["id"]);
$commande->classin($HTTP_POST_VARS["projetid"]);
}
/*
*
*/
if ($HTTP_POST_VARS["action"] == 'add')
{
$expedition = new Expedition($db);
$expedition->date_expedition = time();
$expedition->note = $HTTP_POST_VARS["note"];
$expedition->commande_id = $HTTP_POST_VARS["commande_id"];
$expedition->entrepot_id = $HTTP_POST_VARS["entrepot_id"];
$commande = new Commande($db);
$commande->fetch($expedition->commande_id);
$commande->fetch_lignes();
for ($i = 0 ; $i < sizeof($commande->lignes) ; $i++)
{
$qty = "qtyl".$i;
$idl = "idl".$i;
if ($HTTP_POST_VARS[$qty] > 0)
{
$expedition->addline($HTTP_POST_VARS[$idl],$HTTP_POST_VARS[$qty]);
}
}
$expedition->create($user);
$id = $expedition->id;
$action = '';
}
/*
*
*/
if ($HTTP_POST_VARS["action"] == 'confirm_valid' && $HTTP_POST_VARS["confirm"] == yes && $user->rights->expedition->valider)
{
$expedition = new Expedition($db);
$expedition->fetch($_GET["id"]);
$result = $expedition->valid($user);
}
if ($HTTP_POST_VARS["action"] == 'confirm_delete' && $HTTP_POST_VARS["confirm"] == yes)
{
if ($user->rights->expedition->supprimer )
{
$expedition = new Expedition($db);
$expedition->id = $_GET["id"];
$expedition->delete();
Header("Location: liste.php");
}
}
/*
*
*/
llxHeader('','Fiche expedition','ch-expedition.html',$form_search);
$html = new Form($db);
/*********************************************************************
*
* Mode creation
*
*
*
************************************************************************/
if ($HTTP_POST_VARS["action"] == 'create')
{
print_titre("Créer une expédition");
$commande = new Commande($db);
$commande->livraison_array();
if ( $commande->fetch($HTTP_POST_VARS["commande_id"]))
{
$soc = new Societe($db);
$soc->fetch($commande->soc_id);
$author = new User($db);
$author->id = $commande->user_author_id;
$author->fetch();
$entrepot = new Entrepot($db);
/*
* Commande
*/
print '<form action="fiche.php" method="post">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="commande_id" value="'.$commande->id.'">';
print '<input type="hidden" name="entrepot_id" value="'.$HTTP_POST_VARS["entrepot_id"].'">';
print '<table class="border" cellspacing="0" cellpadding="2" width="100%">';
print '<tr><td width="20%">Client</td>';
print '<td width="40%"><b><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></b></td>';
print '<td width="40%" colspan="2">';
print $commande->statuts[$commande->statut];
print "</td></tr>";
print "<tr><td>Date</td>";
print "<td>".strftime("%A %d %B %Y",$commande->date)."</td>\n";
print '<td colspan="2" width="50%">Commande : ' . $commande->ref ;
print "</td></tr>\n";
print '<tr><td>Entrepôt</td>';
print '<td>';
$ents = $entrepot->list_array();
print $ents[$HTTP_POST_VARS["entrepot_id"]];
print '</td>';
print "<td>Auteur</td><td>$author->fullname</td>\n";
if ($commande->note)
{
print '<tr><td colspan="3">Note : '.nl2br($commande->note)."</td></tr>";
}
print "</table>";
/*
* Lignes de commandes
*
*/
echo '<br><table border="0" width="100%" cellspacing="0" cellpadding="3">';
$lignes = $commande->fetch_lignes();
$num = sizeof($commande->lignes);
$i = 0; $total = 0;
if ($num)
{
print '<tr class="liste_titre">';
print '<td width="54%">Description</td>';
print '<td align="center">Quan. commandée</td>';
print '<td align="center">Quan. livrée</td>';
print '<td align="center">Quan. à livrer</td>';
if (defined("MAIN_MODULE_STOCK"))
{
print '<td width="12%" align="center">Stock</td>';
}
print "</tr>\n";
}
$var=True;
while ($i < $num)
{
$ligne = $commande->lignes[$i];
print "<tr $bc[$var]>\n";
if ($ligne->product_id > 0)
{
$product = new Product($db);
$product->fetch($ligne->product_id);
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$ligne->product_id.'">'.nl2br($ligne->description).'</a></td>';
}
else
{
print "<td>".nl2br($ligne->description)."</TD>\n";
}
print '<td align="center">'.$ligne->qty.'</td>';
/*
*
*/
print '<td align="center">';
$quantite_livree = $commande->livraisons[$ligne->product_id];
print $quantite_livree;;
print '</td>';
/*
*
*/
print '<td align="center">';
print '<input name="idl'.$i.'" type="hidden" value="'.$ligne->id.'">';
$quantite_commandee = $ligne->qty;
$quantite_a_livrer = $quantite_commandee - $quantite_livree;
if (defined("MAIN_MODULE_STOCK"))
{
$stock = $product->stock_entrepot[$HTTP_POST_VARS["entrepot_id"]];
print '<input name="qtyl'.$i.'" type="text" size="6" value="'.min($quantite_a_livrer, $stock).'">';
print '</td>';
if ($stock < $quantite_a_livrer)
{
print '<td align="center" class="alerte">'.$stock.'</td>';
}
else
{
print '<td align="center">'.$stock.'</td>';
}
}
else
{
print '<input name="qtyl'.$i.'" type="text" size="6" value="'.$quantite_a_livrer.'">';
print '</td>';
}
print "</tr>\n";
$i++;
$var=!$var;
}
/*
*
*/
print '<tr><td align="center" colspan="3"><input type="submit" value="Créer"></td></tr>';
print "</table>";
print '</form>';
}
else
{
print $db->error() . "<br>$sql";;
}
}
else
/* *************************************************************************** */
/* */
/* Mode vue et edition */
/* */
/* *************************************************************************** */
{
if ($id > 0)
{
$expedition = New Expedition($db);
if ( $expedition->fetch($id) > 0)
{
$author = new User($db);
$author->id = $expedition->user_author_id;
$author->fetch();
$commande = New Commande($db);
$commande->fetch($expedition->commande_id);
$soc = new Societe($db);
$soc->fetch($commande->soc_id);
print_titre("Expedition : ".$expedition->ref);
/*
* Confirmation de la suppression
*
*/
if ($action == 'delete')
{
$html->form_confirm("$PHP_SELF?id=$id","Supprimer l'expedition","Etes-vous sûr de vouloir supprimer cette expedition ?","confirm_delete");
}
/*
* Confirmation de la validation
*
*/
if ($_GET["action"] == 'valid')
{
$html->form_confirm("$PHP_SELF?id=$id","Valider l'expédition","Etes-vous sûr de vouloir valider cette expédition ?","confirm_valid");
}
/*
* Confirmation de l'annulation
*
*/
if ($_GET["action"] == 'annuler')
{
$html->form_confirm("$PHP_SELF?id=$id","Annuler la commande","Etes-vous sûr de vouloir annuler cette commande ?","confirm_cancel");
}
/*
* Commande
*/
if ($commande->brouillon == 1 && $user->rights->commande->creer)
{
print '<form action="fiche.php?id='.$id.'" method="post">';
print '<input type="hidden" name="action" value="setremise">';
}
print '<table class="border" cellspacing="0" cellpadding="2" width="100%">';
print '<tr><td width="20%">Client</td>';
print '<td width="40%" colspan="2">';
print '<b><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></b></td>';
print '<td width="50%">';
print $commande->statuts[$commande->statut];
print "</td></tr>";
print "<tr><td>Commande</td>";
print '<td colspan="2"><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$commande->id.'">'.$commande->ref."</a></td>\n";
print "<tr><td>Date</td>";
print "<td colspan=\"2\">".strftime("%A %d %B %Y",$commande->date)."</td>\n";
print '<td width="50%">';
print "</td></tr>";
print "<tr><td>Auteur</td><td colspan=\"2\">$author->fullname</td>";
print "</table>";
/*
* Lignes
*
*/
echo '<br><table border="0" width="100%" cellspacing="0" cellpadding="3">';
$sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande, ed.qty as qty_livre";
$sql .= " FROM llx_commandedet as cd , llx_expeditiondet as ed";
$sql .= " WHERE ed.fk_expedition = $id AND cd.rowid = ed.fk_commande_ligne ";
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
$i = 0; $total = 0;
if ($num)
{
print '<tr class="liste_titre">';
print '<td width="54%">Description</td>';
print '<td align="center">Quan. commandée</td>';
print '<td align="center">Quan. livrée</td>';
print "</tr>\n";
}
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object( $i);
print "<TR $bc[$var]>";
if ($objp->fk_product > 0)
{
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->description)).'</a></td>';
}
else
{
print "<td>".stripslashes(nl2br($objp->description))."</TD>\n";
}
print '<td align="center">'.$objp->qty_commande.'</td>';
print '<td align="center">'.$objp->qty_livre.'</td>';
print "</tr>";
$i++;
$var=!$var;
}
$db->free();
}
else
{
print "$sql";
print $db->error();
}
print "</table>";
/*
* Fin Ajout ligne
*
*/
if ($user->societe_id == 0)
{
print '<p><table id="actions" width="100%"><tr>';
if ($expedition->brouillon && $user->rights->expedition->supprimer)
{
print "<td align=\"center\" width=\"20%\"><a href=\"$PHP_SELF?id=$id&amp;action=delete\">Supprimer</a></td>";
}
else
{
print "<td align=\"center\" width=\"20%\">-</td>";
}
print "<td align=\"center\" width=\"20%\">-</td>";
print '<td align="center" width="20%">-</td>';
print '<td align="center" width="20%">-</td>';
if ($expedition->statut == 0)
{
if ($user->rights->expedition->valider)
{
print "<td align=\"center\" width=\"20%\"><a href=\"$PHP_SELF?id=$id&amp;action=valid\">Valider</a></td>";
}
else
{
print '<td align="center" width="20%">-</td>';
}
}
elseif ($commande->statut == 1)
{
if ($user->rights->commande->valider)
{
print "<td align=\"center\" width=\"20%\"><a href=\"fiche.php?id=$id&amp;action=annuler\">Annuler la commande</a></td>";
}
else
{
print '<td align="center" width="20%">-</td>';
}
}
else
{
print '<td align="center" width="20%">-</td>';
}
print "</tr></table>";
}
print "<p>\n";
/*
* Déjà livré
*
*
*/
$sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande, ed.qty as qty_livre, e.ref";
$sql .= " FROM llx_commandedet as cd , llx_expeditiondet as ed, llx_expedition as e";
$sql .= " WHERE cd.fk_commande = $expedition->commande_id AND e.rowid <> $expedition->id AND cd.rowid = ed.fk_commande_ligne AND ed.fk_expedition = e.rowid";
$sql .= " ORDER BY cd.fk_product";
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
$i = 0; $total = 0;
if ($num)
{
print '<br><table class="liste" cellpadding="3" width="100%"><tr>';
print '<tr class="liste_titre">';
print '<td width="54%">Description</td>';
print '<td align="center">Quan. livrée</td>';
print '<td align="center">Expédition</td>';
print "</tr>\n";
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object( $i);
print "<TR $bc[$var]>";
if ($objp->fk_product > 0)
{
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->description)).'</a></td>';
}
else
{
print "<td>".stripslashes(nl2br($objp->description))."</TD>\n";
}
print '<td align="center">'.$objp->qty_livre.'</td>';
print '<td align="center">'.$objp->ref.'</td>';
$i++;
}
print '</table>';
}
}
/*
* Documents générés
*
*/
$file = FAC_OUTPUTDIR . "/" . $commande->ref . "/" . $commande->ref . ".pdf";
if (file_exists($file))
{
print "<table width=\"100%\" cellspacing=2><tr><td width=\"50%\" valign=\"top\">";
print_titre("Documents");
print '<table width="100%" cellspacing="0" class="border" cellpadding="3">';
print "<tr $bc[0]><td>Commande PDF</td>";
print '<td><a href="'.FAC_OUTPUT_URL."/".$commande->ref."/".$commande->ref.'.pdf">'.$commande->ref.'.pdf</a></td>';
print '<td align="right">'.filesize($file). ' bytes</td>';
print '<td align="right">'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'</td>';
print '</tr>';
print "</table>\n";
print '</td><td valign="top" width="50%">';
print_titre("Actions");
/*
* Liste des actions
*
*/
$sql = "SELECT ".$db->pdate("a.datea")." as da, a.note";
$sql .= " FROM llx_actioncomm as a WHERE a.fk_soc = $commande->socidp AND a.fk_action in (9,10) AND a.fk_commande = $id";
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
if ($num)
{
$i = 0; $total = 0;
print '<table border="1" cellspacing="0" cellpadding="4" width="100%">';
print "<tr $bc[$var]><td>Date</td><td>Action</td></tr>\n";
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object( $i);
$var=!$var;
print "<tr $bc[$var]>";
print "<td>".strftime("%d %B %Y",$objp->da)."</TD>\n";
print '<td>'.stripslashes($objp->note).'</TD>';
print "</tr>";
$i++;
}
print "</table>";
}
}
else
{
print $db->error();
}
/*
*
*
*/
print "</td></tr></table>";
}
/*
*
*
*/
if ($action == 'classer')
{
print "<p><form method=\"post\" action=\"$PHP_SELF?id=$id\">\n";
print '<input type="hidden" name="action" value="classin">';
print '<table cellspacing="0" class="border" cellpadding="3">';
print '<tr><td>Projet</td><td>';
$proj = new Project($db);
$html->select_array("projetid",$proj->liste_array($commande->soc_id));
print "</td></tr>";
print '<tr><td colspan="2" align="center"><input type="submit" value="Envoyer"></td></tr></table></form></p>';
}
/*
*
*
*/
if ($action == 'presend')
{
$replytoname = $user->fullname;
$from_name = $replytoname;
$replytomail = $user->email;
$from_mail = $replytomail;
print "<form method=\"post\" action=\"$PHP_SELF?id=$id&amp;action=send\">\n";
print '<input type="hidden" name="replytoname" value="'.$replytoname.'">';
print '<input type="hidden" name="replytomail" value="'.$replytomail.'">';
print "<p><b>Envoyer la commande par mail</b>";
print "<table cellspacing=0 border=1 cellpadding=3>";
print '<tr><td>Destinataire</td><td colspan="5">';
$form = new Form($db);
$form->select_array("destinataire",$soc->contact_email_array());
print "</td><td><input size=\"30\" name=\"sendto\" value=\"$commande->email\"></td></tr>";
print "<tr><td>Expéditeur</td><td colspan=\"5\">$from_name</td><td>$from_mail</td></tr>";
print "<tr><td>Reply-to</td><td colspan=\"5\">$replytoname</td>";
print "<td>$replytomail</td></tr></table>";
print "<input type=\"submit\" value=\"Envoyer\"></form>";
}
}
else
{
/* Commande non trouvée */
print "Commande inexistante ou accés refusé";
}
}
}
$db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
?>

181
htdocs/expedition/index.php Normal file
View File

@ -0,0 +1,181 @@
<?PHP
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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");
llxHeader('','Expéditions','',$form_search);
print_titre("Expeditions");
print '<table border="0" width="100%" cellspacing="0" cellpadding="4">';
print '<tr><td valign="top" width="30%">';
/*
*
*/
/*
* Expeditions à valider
*/
$sql = "SELECT e.rowid, e.ref, s.nom, s.idp, c.ref as commande_ref, c.rowid as commande_id FROM llx_expedition as e, llx_societe as s, llx_commande as c";
$sql .= " WHERE e.fk_commande = c.rowid AND c.fk_soc = s.idp AND e.fk_statut = 0";
if ($socidp)
{
$sql .= " AND c.fk_soc = $socidp";
}
print '<table border="0" cellspacing="0" cellpadding="3" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="3">'.translate("Expeditions à valider").'</td></tr>';
if ( $db->query($sql) )
{
$num = $db->num_rows();
if ($num)
{
$i = 0;
while ($i < $num)
{
$var=!$var;
$obj = $db->fetch_object($i);
print "<tr $bc[$var]><td width=\"20%\"><a href=\"fiche.php?id=$obj->rowid\">$obj->ref</a></td>";
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td>';
print '<td><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$obj->commande_id.'">'.$obj->commande_ref.'</a></td></tr>';
$i++;
}
}
}
print "</table><br>";
/*
*
*/
print '</td><td valign="top" width="70%">';
/*
* Commandes à traiter
*/
$sql = "SELECT c.rowid, c.ref, s.nom, s.idp FROM llx_commande as c, llx_societe as s";
$sql .= " WHERE c.fk_soc = s.idp AND c.fk_statut = 1";
if ($socidp)
{
$sql .= " AND c.fk_soc = $socidp";
}
if ( $db->query($sql) )
{
$num = $db->num_rows();
if ($num)
{
$i = 0;
print '<table border="0" cellspacing="0" cellpadding="3" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="2">'.translate("Commandes à traiter").'</td></tr>';
while ($i < $num)
{
$var=!$var;
$obj = $db->fetch_object($i);
print "<tr $bc[$var]><td width=\"20%\"><a href=\"commande.php?id=$obj->rowid\">$obj->ref</a></td>";
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td></tr>';
$i++;
}
print "</table><br>";
}
}
/*
* Commandes à traiter
*/
$sql = "SELECT c.rowid, c.ref, s.nom, s.idp FROM llx_commande as c, llx_societe as s";
$sql .= " WHERE c.fk_soc = s.idp AND c.fk_statut = 2";
if ($socidp)
{
$sql .= " AND c.fk_soc = $socidp";
}
if ( $db->query($sql) )
{
$num = $db->num_rows();
if ($num)
{
$i = 0;
print '<table border="0" cellspacing="0" cellpadding="3" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="2">'.translate("Commandes en traitement").'</td></tr>';
while ($i < $num)
{
$var=!$var;
$obj = $db->fetch_object($i);
print "<tr $bc[$var]><td width=\"20%\"><a href=\"commande.php?id=$obj->rowid\">$obj->ref</a></td>";
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td></tr>';
$i++;
}
print "</table><br>";
}
}
/*
* Expeditions à valider
*/
$sql = "SELECT e.rowid, e.ref, s.nom, s.idp, c.ref as commande_ref, c.rowid as commande_id FROM llx_expedition as e, llx_societe as s, llx_commande as c";
$sql .= " WHERE e.fk_commande = c.rowid AND c.fk_soc = s.idp AND e.fk_statut = 1";
if ($socidp)
{
$sql .= " AND c.fk_soc = $socidp";
}
$sql .= " ORDER BY c.rowid DESC";
$sql .= $db->plimit(5, 0);
if ( $db->query($sql) )
{
$num = $db->num_rows();
if ($num)
{
$i = 0;
print '<table border="0" cellspacing="0" cellpadding="3" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="3">'.translate("5 dernières expéditions").'</td></tr>';
while ($i < $num)
{
$var=!$var;
$obj = $db->fetch_object($i);
print "<tr $bc[$var]><td width=\"20%\"><a href=\"fiche.php?id=$obj->rowid\">$obj->ref</a></td>";
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td>';
print '<td><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$obj->commande_id.'">'.$obj->commande_ref.'</a></td></tr>';
$i++;
}
print "</table><br>";
}
}
print '</td></tr></table>';
$db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
?>

159
htdocs/expedition/liste.php Normal file
View File

@ -0,0 +1,159 @@
<?PHP
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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$
*
*/
/**
* Gestion d'une proposition commerciale
* @package propale
*/
require("./pre.inc.php");
$user->getrights('expedition');
if (!$user->rights->expedition->lire)
accessforbidden();
/*
* Sécurité accés client
*/
if ($user->societe_id > 0)
{
$action = '';
$socidp = $user->societe_id;
}
llxHeader();
/******************************************************************************/
/* Fin des Actions */
/******************************************************************************/
/****************************************************************************
* *
* *
* *
* *
****************************************************************************/
if ($sortfield == "")
{
$sortfield="e.rowid";
}
if ($sortorder == "")
{
$sortorder="DESC";
}
if ($page == -1) { $page = 0 ; }
$limit = $conf->liste_limit;
$offset = $limit * $page ;
$pageprev = $page - 1;
$pagenext = $page + 1;
$sql = "SELECT e.rowid, e.ref,".$db->pdate("e.date_expedition")." as date_expedition" ;
$sql .= " FROM llx_expedition as e ";
$sql_add = " WHERE ";
if ($socidp)
{
$sql .= $sql_add . " s.idp = $socidp";
$sql_add = " AND ";
}
if (strlen($HTTP_POST_VARS["sf_ref"]) > 0)
{
$sql .= $sql_add . " e.ref like '%".$HTTP_POST_VARS["sf_ref"] . "%'";
}
$sql .= " ORDER BY $sortfield $sortorder";
$sql .= $db->plimit($limit + 1,$offset);
if ( $db->query($sql) )
{
$num = $db->num_rows();
print_barre_liste("Expeditions", $page, $PHP_SELF,"&amp;socidp=$socidp",$sortfield,$sortorder,'',$num);
$i = 0;
print '<TABLE border="0" width="100%" cellspacing="0" cellpadding="4">';
print '<TR class="liste_titre">';
print_liste_field_titre_new ("Réf",$PHP_SELF,"p.ref","","&amp;socidp=$socidp",'width="15%"',$sortfield);
print_liste_field_titre_new ("Société",$PHP_SELF,"s.nom","","&amp;socidp=$socidp",'width="30%"',$sortfield);
print_liste_field_titre_new ("Date",$PHP_SELF,"c.date_expedition","","&amp;socidp=$socidp", 'width="25%" align="right" colspan="2"',$sortfield);
print_liste_field_titre_new ("Statut",$PHP_SELF,"p.fk_statut","","&amp;socidp=$socidp",'width="10%" align="center"',$sortfield);
print "</tr>\n";
$var=True;
while ($i < min($num,$limit))
{
$objp = $db->fetch_object( $i);
$var=!$var;
print "<TR $bc[$var]>";
print "<TD><a href=\"fiche.php?id=$objp->rowid\">$objp->ref</a></TD>\n";
print "<TD><a href=\"../comm/fiche.php?socid=$objp->idp\">$objp->nom</a></TD>\n";
$now = time();
$lim = 3600 * 24 * 15 ;
if ( ($now - $objp->date_expedition) > $lim && $objp->statutid == 1 )
{
print "<td><b> &gt; 15 jours</b></td>";
}
else
{
print "<td>&nbsp;</td>";
}
print "<TD align=\"right\">";
$y = strftime("%Y",$objp->date_expedition);
$m = strftime("%m",$objp->date_expedition);
print strftime("%d",$objp->date_expedition)."\n";
print " <a href=\"propal.php?year=$y&amp;month=$m\">";
print strftime("%B",$objp->date_expedition)."</a>\n";
print " <a href=\"propal.php?year=$y\">";
print strftime("%Y",$objp->date_expedition)."</a></TD>\n";
print "<td align=\"center\">$objp->statut</TD>\n";
print "</TR>\n";
$i++;
}
print "</table>";
$db->free();
}
else
{
print $db->error();
}
$db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
?>