Dbut ajout bon de livraison
This commit is contained in:
parent
dbf750c381
commit
03a1fa6188
@ -1033,11 +1033,11 @@ class Commande
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Renvoie un tableau avec les livraison par ligne
|
||||
* \brief Renvoie un tableau avec les expéditions par ligne
|
||||
* \param filtre_statut Filtre sur statut
|
||||
* \return int 0 si OK, <0 si KO
|
||||
*/
|
||||
function livraison_array($filtre_statut=-1)
|
||||
function expedition_array($filtre_statut=-1)
|
||||
{
|
||||
$this->livraisons = array();
|
||||
$sql = 'SELECT fk_product, sum(ed.qty)';
|
||||
@ -1048,6 +1048,54 @@ class Commande
|
||||
$sql .= ' GROUP BY fk_product ';
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $this->db->num_rows();
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$row = $this->db->fetch_row( $i);
|
||||
$this->expeditions[$row[0]] = $row[1];
|
||||
$i++;
|
||||
}
|
||||
$this->db->free();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie un tableau avec les expeditions par ligne
|
||||
*
|
||||
*/
|
||||
function nb_expedition()
|
||||
{
|
||||
$sql = 'SELECT count(*) FROM '.MAIN_DB_PREFIX.'expedition as e';
|
||||
$sql .=" WHERE e.fk_commande = $this->id";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$row = $this->db->fetch_row(0);
|
||||
return $row[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Renvoie un tableau avec les livraisons par ligne
|
||||
* \param filtre_statut Filtre sur statut
|
||||
* \return int 0 si OK, <0 si KO
|
||||
*/
|
||||
function livraison_array($filtre_statut=-1)
|
||||
{
|
||||
$this->livraisons = array();
|
||||
$sql = 'SELECT cd.fk_product, sum(ed.qty)';
|
||||
$sql.=' FROM '.MAIN_DB_PREFIX.'livraisondet as ld, '.MAIN_DB_PREFIX.'livraison as l, '.MAIN_DB_PREFIX.'commande as c, '.MAIN_DB_PREFIX.'commandedet as cd';
|
||||
$sql.=' WHERE ld.fk_livraison = l.rowid AND ld.fk_commande_ligne = cd .rowid AND cd.fk_commande = c.rowid';
|
||||
$sql.=' AND cd.fk_commande =' .$this->id;
|
||||
if ($filtre_statut >= 0) $sql.=' AND l.fk_statut = '.$filtre_statut;
|
||||
$sql .= ' GROUP BY cd.fk_product ';
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $this->db->num_rows();
|
||||
$i = 0;
|
||||
@ -1063,22 +1111,6 @@ class Commande
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie un tableau avec les livraison par ligne
|
||||
*
|
||||
*/
|
||||
function nb_expedition()
|
||||
{
|
||||
$sql = 'SELECT count(*) FROM '.MAIN_DB_PREFIX.'expedition as e';
|
||||
$sql .=" WHERE e.fk_commande = $this->id";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$row = $this->db->fetch_row(0);
|
||||
return $row[0];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* \brief Supprime une ligne de la commande
|
||||
* \param idligne Id de la ligne à supprimer
|
||||
|
||||
@ -103,7 +103,7 @@ if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->
|
||||
$expedition = new Expedition($db);
|
||||
$expedition->fetch($_GET["id"]);
|
||||
$result = $expedition->valid($user);
|
||||
$expedition->PdfWrite();
|
||||
//$expedition->PdfWrite();
|
||||
}
|
||||
|
||||
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes')
|
||||
@ -156,7 +156,7 @@ if ($_GET["action"] == 'create')
|
||||
}
|
||||
|
||||
$commande = new Commande($db);
|
||||
$commande->livraison_array();
|
||||
$commande->expedition_array();
|
||||
|
||||
if ( $commande->fetch($_GET["commande_id"]))
|
||||
{
|
||||
@ -209,8 +209,8 @@ if ($_GET["action"] == 'create')
|
||||
|
||||
$lignes = $commande->fetch_lignes(1);
|
||||
|
||||
/* Lecture des livraisons déjà effectuées */
|
||||
$commande->livraison_array();
|
||||
/* Lecture des expeditions déjà effectuées */
|
||||
$commande->expedition_array();
|
||||
|
||||
$num = sizeof($commande->lignes);
|
||||
$i = 0;
|
||||
@ -341,6 +341,13 @@ else
|
||||
$head[$h][1] = $langs->trans("SendingCard");
|
||||
$hselected = $h;
|
||||
$h++;
|
||||
|
||||
if ($conf->livraison->enable)
|
||||
{
|
||||
$head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$livraison->id;
|
||||
$head[$h][1] = $langs->trans("DeliveryCard");
|
||||
$h++;
|
||||
}
|
||||
|
||||
dolibarr_fiche_head($head, $hselected, $langs->trans("Sending"));
|
||||
|
||||
|
||||
713
htdocs/livraison/fiche.php
Normal file
713
htdocs/livraison/fiche.php
Normal file
@ -0,0 +1,713 @@
|
||||
<?php
|
||||
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
|
||||
*
|
||||
* 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$
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
\file htdocs/livraison/fiche.php
|
||||
\ingroup livraison
|
||||
\brief Fiche descriptive d'un bon de livraison
|
||||
\version $Revision$
|
||||
*/
|
||||
|
||||
require("./pre.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
|
||||
|
||||
|
||||
$langs->load("bills");
|
||||
|
||||
$user->getrights('expedition');
|
||||
if (!$user->rights->expedition->livraison->lire)
|
||||
accessforbidden();
|
||||
|
||||
|
||||
// Sécurité accés client
|
||||
if ($user->societe_id > 0)
|
||||
{
|
||||
$action = '';
|
||||
$socidp = $user->societe_id;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($_POST["action"] == 'add')
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
// Creation de l'objet livraison
|
||||
$livraison = new Livraison($db);
|
||||
|
||||
$livraison->date_livraison = time();
|
||||
$livraison->note = $_POST["note"];
|
||||
$livraison->commande_id = $_POST["commande_id"];
|
||||
|
||||
// On boucle sur chaque ligne de commande pour compléter objet livraison
|
||||
// avec qté à livrer
|
||||
$commande = new Commande($db);
|
||||
$commande->fetch($livraison->commande_id);
|
||||
$commande->fetch_lignes();
|
||||
for ($i = 0 ; $i < sizeof($commande->lignes) ; $i++)
|
||||
{
|
||||
$qty = "qtyl".$i;
|
||||
$idl = "idl".$i;
|
||||
if ($_POST[$qty] > 0)
|
||||
{
|
||||
$livraison->addline($_POST[$idl],$_POST[$qty]);
|
||||
}
|
||||
}
|
||||
|
||||
$ret=$livraison->create($user);
|
||||
if ($ret > 0)
|
||||
{
|
||||
$db->commit();
|
||||
Header("Location: fiche.php?id=".$livraison->id);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
$mesg='<div class="error">'.$livraison->error.'</div>';
|
||||
$_GET["commande_id"]=$_POST["commande_id"];
|
||||
$_GET["action"]='create';
|
||||
}
|
||||
}
|
||||
|
||||
if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->expedition->livraison->valider)
|
||||
{
|
||||
$livraison = new Livraison($db);
|
||||
$livraison->fetch($_GET["id"]);
|
||||
$result = $livraison->valid($user);
|
||||
$livraison->PdfWrite();
|
||||
}
|
||||
|
||||
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes')
|
||||
{
|
||||
if ($user->rights->expedition->livraison->supprimer )
|
||||
{
|
||||
$livraison = new Livraison($db);
|
||||
$livraison->id = $_GET["id"];
|
||||
$livraison->delete();
|
||||
Header("Location: liste.php");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Générer ou regénérer le PDF
|
||||
*/
|
||||
if ($_REQUEST['action'] == 'builddoc') // En get ou en post
|
||||
{
|
||||
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
|
||||
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
|
||||
$result=livraison_pdf_create($db, $_REQUEST['id'],$_REQUEST['model'],$outputlangs);
|
||||
if ($result <= 0)
|
||||
{
|
||||
dolibarr_print_error($db,$result);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
$html = new Form($db);
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Mode creation
|
||||
*
|
||||
*********************************************************************/
|
||||
if ($_GET["action"] == 'create')
|
||||
{
|
||||
llxHeader('','Fiche expedition','ch-expedition.html',$form_search);
|
||||
|
||||
print_titre($langs->trans("CreateADeliveryOrder"));
|
||||
|
||||
if ($mesg)
|
||||
{
|
||||
print $mesg.'<br>';
|
||||
}
|
||||
|
||||
$commande = new Commande($db);
|
||||
$commande->livraison_array();
|
||||
|
||||
if ( $commande->fetch($_GET["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="'.$_GET["entrepot_id"].'">';
|
||||
print '<table class="border" width="100%">';
|
||||
print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
|
||||
print '<td width="30%"><b><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></b></td>';
|
||||
|
||||
print '<td width="50%" colspan="2">';
|
||||
|
||||
print "</td></tr>";
|
||||
|
||||
print "<tr><td>".$langs->trans("Date")."</td>";
|
||||
print "<td>".strftime("%A %d %B %Y",$commande->date)."</td>\n";
|
||||
|
||||
print '<td>'.$langs->trans("Order").'</td><td><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$commande->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref.'</a>';
|
||||
print "</td></tr>\n";
|
||||
|
||||
print '<tr>';
|
||||
/*
|
||||
print '<td>'.$langs->trans("Warehouse").'</td>';
|
||||
print '<td>';
|
||||
$ents = $entrepot->list_array();
|
||||
print '<a href="'.DOL_URL_ROOT.'/product/stock/fiche.php?id='.$_GET["entrepot_id"].'">'.img_object($langs->trans("ShowWarehouse"),'stock').' '.$ents[$_GET["entrepot_id"]].'</a>';
|
||||
print '</td>';
|
||||
*/
|
||||
print "<td>".$langs->trans("Author")."</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 class="noborder" width="100%">';
|
||||
|
||||
$lignes = $commande->fetch_lignes(1);
|
||||
|
||||
/* Lecture des livraisons déjà effectuées */
|
||||
$commande->livraison_array();
|
||||
|
||||
$num = sizeof($commande->lignes);
|
||||
$i = 0;
|
||||
|
||||
if ($num)
|
||||
{
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td width="54%">'.$langs->trans("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 ($conf->stock->enabled)
|
||||
{
|
||||
print '<td width="12%" align="center">'.$langs->trans("Stock").'</td>';
|
||||
}
|
||||
print "</tr>\n";
|
||||
}
|
||||
$var=true;
|
||||
while ($i < $num)
|
||||
{
|
||||
$ligne = $commande->lignes[$i];
|
||||
$var=!$var;
|
||||
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.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
|
||||
if ($ligne->description) print nl2br($ligne->description);
|
||||
print '</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>';
|
||||
|
||||
$quantite_commandee = $ligne->qty;
|
||||
$quantite_a_livrer = $quantite_commandee - $quantite_livree;
|
||||
|
||||
if ($conf->stock->enabled)
|
||||
{
|
||||
$stock = $product->stock_entrepot[$_GET["entrepot_id"]];
|
||||
$stock+=0; // Convertit en numérique
|
||||
|
||||
// Quantité à livrer
|
||||
print '<td align="center">';
|
||||
print '<input name="idl'.$i.'" type="hidden" value="'.$ligne->id.'">';
|
||||
print '<input name="qtyl'.$i.'" type="text" size="6" value="'.min($quantite_a_livrer, $stock).'">';
|
||||
print '</td>';
|
||||
|
||||
// Stock
|
||||
if ($stock < $quantite_a_livrer)
|
||||
{
|
||||
print '<td align="center" class="alerte">'.$stock.'</td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td align="center">'.$stock.'</td>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Quantité à livrer
|
||||
print '<td align="center">';
|
||||
print '<input name="idl'.$i.'" type="hidden" value="'.$ligne->id.'">';
|
||||
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="4"><br><input type="submit" class="button" value="'.$langs->trans("Create").'"></td></tr>';
|
||||
print "</table>";
|
||||
print '</form>';
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
}
|
||||
else
|
||||
/* *************************************************************************** */
|
||||
/* */
|
||||
/* Mode vue et edition */
|
||||
/* */
|
||||
/* *************************************************************************** */
|
||||
{
|
||||
if ($_GET["id"] > 0)
|
||||
{
|
||||
$livraison = New Livraison($db);
|
||||
$result = $livraison->fetch($_GET["id"]);
|
||||
|
||||
if ( $livraison->id > 0)
|
||||
{
|
||||
$author = new User($db);
|
||||
$author->id = $livraison->user_author_id;
|
||||
$author->fetch();
|
||||
|
||||
llxHeader('','Fiche expedition','ch-expedition.html',$form_search,$author);
|
||||
|
||||
$commande = New Commande($db);
|
||||
$commande->fetch($livraison->commande_id);
|
||||
|
||||
$soc = new Societe($db);
|
||||
$soc->fetch($commande->soc_id);
|
||||
|
||||
$h=0;
|
||||
if ($conf->expedition->enable)
|
||||
{
|
||||
$head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$expedition->id;
|
||||
$head[$h][1] = $langs->trans("SendingCard");
|
||||
$h++;
|
||||
}
|
||||
|
||||
$head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$livraison->id;
|
||||
$head[$h][1] = $langs->trans("DeliveryCard");
|
||||
$hselected = $h;
|
||||
$h++;
|
||||
|
||||
dolibarr_fiche_head($head, $hselected, $langs->trans("Sending"));
|
||||
|
||||
/*
|
||||
* Confirmation de la suppression
|
||||
*
|
||||
*/
|
||||
if ($_GET["action"] == 'delete')
|
||||
{
|
||||
$html->form_confirm("fiche.php?id=$livraison->id","Supprimer le bon de livraison","Etes-vous sûr de vouloir supprimer ce bon de livraison ?","confirm_delete");
|
||||
print '<br>';
|
||||
}
|
||||
|
||||
/*
|
||||
* Confirmation de la validation
|
||||
*
|
||||
*/
|
||||
if ($_GET["action"] == 'valid')
|
||||
{
|
||||
$html->form_confirm("fiche.php?id=$livraison->id","Valider le bon de livraison","Etes-vous sûr de vouloir valider ce bon de livraison ?","confirm_valid");
|
||||
print '<br>';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Commande
|
||||
*/
|
||||
if ($commande->brouillon == 1 && $user->rights->commande->creer)
|
||||
{
|
||||
print '<form action="fiche.php?id='.$livraison->id.'" method="post">';
|
||||
}
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// Ref
|
||||
print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
|
||||
print '<td colspan="3">'.$livraison->ref.'</td></tr>';
|
||||
|
||||
// Client
|
||||
print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
|
||||
print '<td width="30%">';
|
||||
print '<b><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></b></td>';
|
||||
|
||||
// Auteur
|
||||
print '<td width="20%">'.$langs->trans("Author").'</td><td width="30%">'.$author->fullname.'</td>';
|
||||
|
||||
print "</tr>";
|
||||
|
||||
// Commande liée
|
||||
print '<tr><td>'.$langs->trans("Order").'</td>';
|
||||
print '<td><a href="'.DOL_URL_ROOT.'/expedition/commande.php?id='.$commande->id.'">'.$commande->ref."</a></td>\n";
|
||||
print '<td> </td><td> </td></tr>';
|
||||
|
||||
// Date
|
||||
print '<tr><td>'.$langs->trans("Date").'</td>';
|
||||
print "<td>".strftime("%A %d %B %Y",$livraison->date)."</td>\n";
|
||||
/*
|
||||
// Entrepot
|
||||
$entrepot = new Entrepot($db);
|
||||
$entrepot->fetch($expedition->entrepot_id);
|
||||
print '<td width="20%">'.$langs->trans("Warehouse").'</td><td><a href="'.DOL_URL_ROOT.'/product/stock/fiche.php?id='.$entrepot->id.'">'.$entrepot->libelle.'</a></td>';
|
||||
*/
|
||||
print '</tr>';
|
||||
|
||||
print "</table>\n";
|
||||
|
||||
/*
|
||||
* Lignes produits
|
||||
*/
|
||||
echo '<br><table class="noborder" width="100%">';
|
||||
|
||||
$sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande";
|
||||
$sql .= " , ld.qty as qty_livre";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd , ".MAIN_DB_PREFIX."livraisondet as ld";
|
||||
$sql .= " WHERE ld.fk_livraison = $livraison->id AND cd.rowid = ld.fk_commande_ligne ";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
$num_prod = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Products").'</td>';
|
||||
print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
|
||||
print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
$var=true;
|
||||
while ($i < $num_prod)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
|
||||
$var=!$var;
|
||||
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.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
|
||||
if ($objp->description) print nl2br($objp->description);
|
||||
print '</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($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
|
||||
print "</table>\n";
|
||||
|
||||
print "\n</div>\n";
|
||||
|
||||
|
||||
/*
|
||||
* Boutons actions
|
||||
*/
|
||||
|
||||
if ($user->societe_id == 0)
|
||||
{
|
||||
print '<div class="tabsAction">';
|
||||
|
||||
if ($livraison->statut == 0 && $user->rights->expedition->livraison->valider && $num_prod > 0)
|
||||
{
|
||||
print '<a class="butAction" href="fiche.php?id='.$livraison->id.'&action=valid">'.$langs->trans("Validate").'</a>';
|
||||
}
|
||||
|
||||
print '<a class="butAction" href="fiche.php?id='.$livraison->id.'&action=builddoc">'.$langs->trans('BuildPDF').'</a>';
|
||||
|
||||
if ($livraison->brouillon && $user->rights->expedition->livraison->supprimer)
|
||||
{
|
||||
print '<a class="butActionDelete" href="fiche.php?id='.$livraison->id.'&action=delete">'.$langs->trans("Delete").'</a>';
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
}
|
||||
print "\n";
|
||||
|
||||
print "<table width=\"100%\" cellspacing=2><tr><td width=\"50%\" valign=\"top\">";
|
||||
|
||||
/*
|
||||
* Documents générés
|
||||
*/
|
||||
|
||||
//mis en commentaire pour test du patch
|
||||
//$filename=sanitize_string($expedition->id);
|
||||
//$filedir=$conf->expedition->dir_output . "/" .get_exdir($expedition->id);
|
||||
|
||||
$filename=sanitize_string($livraison->ref);
|
||||
$filedir=$conf->livraison->dir_output . "/" .$livraison->ref;
|
||||
|
||||
$urlsource=$_SERVER["PHP_SELF"]."?id=".$livraison->id;
|
||||
|
||||
//$genallowed=$user->rights->expedition->creer;
|
||||
//$delallowed=$user->rights->expedition->supprimer;
|
||||
$genallowed=1;
|
||||
$delallowed=0;
|
||||
|
||||
$result=$html->show_documents('livraison',$filename,$filedir,$urlsource,$genallowed,$delallowed,$livraison->modelpdf);
|
||||
|
||||
/*
|
||||
* Déjà livre
|
||||
*/
|
||||
$sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande";
|
||||
$sql .= " , ld.qty as qty_livre, l.ref, ld.fk_livraison as livraison_id";
|
||||
$sql .= ",".$db->pdate("l.date_livraison")." as date_livraison";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
|
||||
$sql .= " , ".MAIN_DB_PREFIX."livraisondet as ld, ".MAIN_DB_PREFIX."livraison as l";
|
||||
$sql .= " WHERE cd.fk_commande = ".$livraison->commande_id;
|
||||
$sql .= " AND l.rowid <> ".$livraison->id;
|
||||
$sql .= " AND cd.rowid = ld.fk_commande_ligne";
|
||||
$sql .= " AND ld.fk_livraison = l.rowid";
|
||||
$sql .= " AND l.fk_statut > 0";
|
||||
$sql .= " ORDER BY cd.fk_product";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
|
||||
if ($num)
|
||||
{
|
||||
print '<br>';
|
||||
|
||||
print_titre($langs->trans("OtherSendingsForSameOrder"));
|
||||
print '<table class="liste" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td align="left">'.$langs->trans("Sending").'</td>';
|
||||
print '<td>'.$langs->trans("Description").'</td>';
|
||||
print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
|
||||
print '<td align="center">'.$langs->trans("Date").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
$var=True;
|
||||
while ($i < $num)
|
||||
{
|
||||
$var=!$var;
|
||||
$objp = $db->fetch_object($resql);
|
||||
print "<tr $bc[$var]>";
|
||||
print '<td align="left"><a href="'.DOL_URL_ROOT.'/livraison/fiche.php?id='.$objp->livraison_id.'">'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.'<a></td>';
|
||||
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.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
|
||||
if ($objp->description) print nl2br($objp->description);
|
||||
print '</td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<td>".stripslashes(nl2br($objp->description))."</td>\n";
|
||||
}
|
||||
print '<td align="center">'.$objp->qty_livre.'</td>';
|
||||
print '<td align="center">'.dolibarr_print_date($objp->date_livraison).'</td>';
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else {
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
|
||||
/*
|
||||
* Commandes associées
|
||||
*
|
||||
*/
|
||||
$file = $conf->commande->dir_output . "/" . $commande->ref . "/" . $commande->ref . ".pdf";
|
||||
$relativepath = $commande->ref . "/" . $commande->ref . ".pdf";
|
||||
|
||||
$var=true;
|
||||
|
||||
if (file_exists($file))
|
||||
{
|
||||
print '<br>';
|
||||
print_titre("Orders");
|
||||
print '<table width="100%" class="border">';
|
||||
|
||||
print "<tr $bc[$true]><td>".$langs->trans("Order")." PDF</td>";
|
||||
print '<td><a href="'.DOL_URL_ROOT.'/document.php?modulepart=commande&file='.urlencode($relativepath).'">'.$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 ".MAIN_DB_PREFIX."actioncomm as a";
|
||||
$sql .= " WHERE a.fk_soc = ".$commande->soc_id." AND a.fk_action in (9,10)";
|
||||
$sql .= " AND a.fk_commande = ".$livraison->id;
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num)
|
||||
{
|
||||
$i = 0;
|
||||
print '<table class="border" width="100%">';
|
||||
print "<tr $bc[$var]><td>".$langs->trans("Date")."</td><td>".$langs->trans("Action")."</td></tr>\n";
|
||||
|
||||
$var=True;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
$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>";
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
|
||||
if ($action == 'presend')
|
||||
{
|
||||
$replytoname = $user->fullname;
|
||||
$from_name = $replytoname;
|
||||
|
||||
$replytomail = $user->email;
|
||||
$from_mail = $replytomail;
|
||||
|
||||
print "<form method=\"post\" action=\"fiche.php?id=$livraison->id&action=send\">\n";
|
||||
print '<input type="hidden" name="replytoname" value="'.$replytoname.'">';
|
||||
print '<input type="hidden" name="replytomail" value="'.$replytomail.'">';
|
||||
|
||||
print "<p><b>Envoyer le bon de livraison 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>";
|
||||
}
|
||||
|
||||
print '</td></tr></table>';
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Expedition non trouvée */
|
||||
llxHeader('','Fiche expedition','ch-expedition.html',$form_search);
|
||||
print "Expedition inexistante ou accés refusé";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Expedition non trouvée */
|
||||
llxHeader('','Fiche expedition','ch-expedition.html',$form_search);
|
||||
print "Expedition inexistante ou accés refusé";
|
||||
}
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
llxFooter('$Date$ - $Revision$');
|
||||
?>
|
||||
@ -58,13 +58,15 @@ class Livraison
|
||||
|
||||
/**
|
||||
* \brief Créé bon de livraison en base
|
||||
* \param user Objet du user qui cré
|
||||
* \param user Objet du user qui crée
|
||||
* \return int <0 si erreur, id livraison créée si ok
|
||||
*/
|
||||
function create($user)
|
||||
{
|
||||
global $conf;
|
||||
require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php";
|
||||
$error = 0;
|
||||
|
||||
/* On positionne en mode brouillon le bon de livraison */
|
||||
$this->brouillon = 1;
|
||||
|
||||
@ -72,25 +74,36 @@ class Livraison
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."livraison (date_creation, fk_user_author, fk_expedition, fk_commande";
|
||||
if ($this->entrepot_id) $sql.= ", fk_entrepot";
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."livraison (fk_soc, fk_soc_contact, date_creation, fk_user_author, fk_commande";
|
||||
if ($this->commande_id) $sql.= ", fk_commande";
|
||||
if ($this->expedition_id) $sql.= ", fk_expedition";
|
||||
$sql.= ")";
|
||||
$sql.= " VALUES (now(), $user->id, ".$this->db->idate($this->date_expedition).",$this->commande_id";
|
||||
if ($this->entrepot_id) $sql.= ", $this->entrepot_id";
|
||||
$sql.= " VALUES ($this->soc_id, $this->contactid, now(), $user->id, $this->commande_id";
|
||||
if ($this->commande_id) $sql.= ", $this->commande_id";
|
||||
if ($this->expedition_id) $sql.= ", $this->expedition_id";
|
||||
$sql.= ")";
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."expedition");
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."livraison");
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."livraison 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();
|
||||
if ($conf->expedition->enable)
|
||||
{
|
||||
$this->expedition = new Expedition($this->db);
|
||||
$this->expedition->id = $this->expedition_id;
|
||||
$this->expedition->fetch_lignes();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->commande = new Commande($this->db);
|
||||
$this->commande->id = $this->commande_id;
|
||||
$this->commande->fetch_lignes();
|
||||
}
|
||||
|
||||
/*
|
||||
* Insertion des produits dans la base
|
||||
@ -162,7 +175,7 @@ class Livraison
|
||||
$j++;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet (fk_expedition, fk_commande_ligne, qty)";
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."livraisondet (fk_livraison, fk_commande_ligne, qty)";
|
||||
$sql .= " VALUES ($this->id,".$commande_ligne_id.",".$qty.")";
|
||||
|
||||
if (! $this->db->query($sql) )
|
||||
@ -177,17 +190,18 @@ class Livraison
|
||||
}
|
||||
/**
|
||||
*
|
||||
* Lit une commande
|
||||
* Lit un bon de livraison
|
||||
*
|
||||
*/
|
||||
function fetch ($id)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$sql = "SELECT e.rowid, e.date_creation, e.ref, e.fk_user_author, e.fk_statut, e.fk_commande, e.fk_entrepot";
|
||||
$sql .= ", ".$this->db->pdate("e.date_expedition")." as date_expedition ";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
|
||||
$sql .= " WHERE e.rowid = $id";
|
||||
$sql = "SELECT l.rowid, l.fk_soc, l.fk_soc_contact, l.date_creation, l.ref, l.fk_user_author,";
|
||||
$sql .=" l.fk_statut, l.fk_commande, l.fk_expedition, l.fk_user_valid, l.note, l.note_public";
|
||||
$sql .= ", ".$this->db->pdate("l.date_livraison")." as date_livraison, fk_adresse_livraison, model_pdf";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."livraison as l";
|
||||
$sql .= " WHERE l.rowid = $id";
|
||||
|
||||
$result = $this->db->query($sql) ;
|
||||
|
||||
@ -195,18 +209,25 @@ class Livraison
|
||||
{
|
||||
$obj = $this->db->fetch_object($result);
|
||||
|
||||
$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->entrepot_id = $obj->fk_entrepot;
|
||||
$this->id = $obj->rowid;
|
||||
$this->socid = $obj->fk_soc;
|
||||
$this->contact_id = $obj->fk_soc_contact;
|
||||
$this->ref = $obj->ref;
|
||||
$this->statut = $obj->fk_statut;
|
||||
$this->commande_id = $obj->fk_commande;
|
||||
$this->expedition_id = $obj->fk_expedition;
|
||||
$this->user_author_id = $obj->fk_user_author;
|
||||
$this->user_valid_id = $obj->fk_user_valid;
|
||||
$this->date = $obj->date_livraison;
|
||||
$this->adresse_livraison_id = $obj->fk_entrepot;
|
||||
$this->note = $obj->note;
|
||||
$this->note_public = $obj->note_public;
|
||||
$this->modelpdf = $obj->model_pdf;
|
||||
$this->db->free();
|
||||
|
||||
if ($this->statut == 0) $this->brouillon = 1;
|
||||
|
||||
$file = $conf->expedition->dir_output . "/" .get_exdir($expedition->id) . "/" . $this->id.".pdf";
|
||||
$file = $conf->livraison->dir_output . "/" .get_exdir($livraison->id) . "/" . $this->id.".pdf";
|
||||
$this->pdf_filename = $file;
|
||||
|
||||
return 1;
|
||||
@ -235,24 +256,49 @@ class Livraison
|
||||
|
||||
$error = 0;
|
||||
|
||||
if ($user->rights->expedition->valider)
|
||||
if ($user->rights->expedition->livraison->valider)
|
||||
{
|
||||
$this->ref = "EXP".$this->id;
|
||||
|
||||
if (defined('LIVRAISON_ADDON'))
|
||||
{
|
||||
if (is_readable(DOL_DOCUMENT_ROOT .'/livraison/mods/'.LIVRAISON_ADDON.'.php'))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT .'/livraison/mods/'.LIVRAISON_ADDON.'.php';
|
||||
|
||||
// Definition du nom de module de numerotation de commande
|
||||
$modName=COMMANDE_ADDON;
|
||||
|
||||
// Recuperation de la nouvelle reference
|
||||
$objMod = new $modName($this->db);
|
||||
$soc = new Societe($this->db);
|
||||
$soc->fetch($this->soc_id);
|
||||
|
||||
// on vérifie si le bon de livraison est en numérotation provisoire
|
||||
$comref = substr($this->ref, 1, 4);
|
||||
if ($comref == PROV)
|
||||
{
|
||||
$num = $objMod->commande_get_num($soc);
|
||||
}
|
||||
else
|
||||
{
|
||||
$num = $this->ref;
|
||||
}
|
||||
|
||||
// \todo Tester si non dejà au statut validé. Si oui, on arrete afin d'éviter
|
||||
// de décrémenter 2 fois le stock.
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET ref='".$this->ref."', fk_statut = 1, date_valid=now(), fk_user_valid=$user->id";
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."livraison SET ref='$num', 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) )
|
||||
{
|
||||
/*
|
||||
|
||||
// Si module stock géré et que expedition faite depuis un entrepot
|
||||
if ($conf->stock->enabled && $this->entrepot_id)
|
||||
{
|
||||
/*
|
||||
* Enregistrement d'un mouvement de stock pour chaque produit de l'expedition
|
||||
*/
|
||||
|
||||
//Enregistrement d'un mouvement de stock pour chaque produit de l'expedition
|
||||
|
||||
|
||||
dolibarr_syslog("expedition.class.php::valid enregistrement des mouvements");
|
||||
|
||||
@ -292,6 +338,8 @@ class Livraison
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -405,10 +453,10 @@ class Livraison
|
||||
{
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition = $this->id ;";
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."livraisondet WHERE fk_livraison = $this->id ;";
|
||||
if ( $this->db->query($sql) )
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition WHERE rowid = $this->id;";
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison WHERE rowid = $this->id;";
|
||||
if ( $this->db->query($sql) )
|
||||
{
|
||||
$this->db->commit();
|
||||
@ -426,25 +474,7 @@ class Livraison
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Classe la commande
|
||||
*
|
||||
*
|
||||
*/
|
||||
function classin($cat_id)
|
||||
{
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Genere le pdf
|
||||
|
||||
Loading…
Reference in New Issue
Block a user