diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 02108ecd4d8..99d47d704fc 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -73,9 +73,6 @@ $socid = restrictedArea($user, $module, $objectid, $dbtable);
// Nombre de ligne pour choix de produit/service predefinis
$NBLINES=4;
-$form=new Form($db);
-
-
/******************************************************************************/
/* Actions */
@@ -854,11 +851,11 @@ if ($_GET['propalid'] > 0)
print '';
if ($conf->projet->enabled) $rowspan++;
- if ($conf->expedition->enabled)
- {
- if ($conf->global->PROPALE_ADD_SHIPPING_DATE) $rowspan++;
- if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS) $rowspan++;
- }
+ if ($conf->expedition->enabled || $conf->livraison->enabled)
+ {
+ if ($conf->global->PROPALE_ADD_SHIPPING_DATE || !$conf->commande->enabled) $rowspan++;
+ if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS || !$conf->commande->enabled) $rowspan++;
+ }
// Notes
print '
';
print '| ';
@@ -1014,11 +1011,11 @@ if ($_GET['propalid'] > 0)
print ' | ';
if ($_GET['action'] == 'classer')
{
- $form->form_project($_SERVER['PHP_SELF'].'?propalid='.$propal->id, $propal->socid, $propal->projetidp, 'projetidp');
+ $html->form_project($_SERVER['PHP_SELF'].'?propalid='.$propal->id, $propal->socid, $propal->projetidp, 'projetidp');
}
else
{
- $form->form_project($_SERVER['PHP_SELF'].'?propalid='.$propal->id, $propal->socid, $propal->projetidp, 'none');
+ $html->form_project($_SERVER['PHP_SELF'].'?propalid='.$propal->id, $propal->socid, $propal->projetidp, 'none');
}
print ' | ';
}
diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php
index 49c363384c1..1b74e62f659 100644
--- a/htdocs/commande/commande.class.php
+++ b/htdocs/commande/commande.class.php
@@ -1207,7 +1207,7 @@ class Commande extends CommonObject
$sql = 'SELECT fk_product, sum(ed.qty)';
$sql.=' FROM '.MAIN_DB_PREFIX.'expeditiondet as ed, '.MAIN_DB_PREFIX.'expedition as e, '.MAIN_DB_PREFIX.'commande as c, '.MAIN_DB_PREFIX.'commandedet as cd';
- $sql.=' WHERE ed.fk_expedition = e.rowid AND ed.fk_commande_ligne = cd .rowid AND cd.fk_commande = c.rowid';
+ $sql.=' WHERE ed.fk_expedition = e.rowid AND ed.fk_origin_line = cd.rowid AND cd.fk_commande = c.rowid';
$sql.=' AND cd.fk_commande =' .$this->id;
if ($filtre_statut >= 0) $sql.=' AND e.fk_statut = '.$filtre_statut;
$sql .= ' GROUP BY fk_product ';
@@ -2401,28 +2401,28 @@ class CommandeLigne
if ($result)
{
$objp = $this->db->fetch_object($result);
- $this->rowid = $objp->rowid;
- $this->fk_propal = $objp->fk_propal;
- $this->desc = $objp->description;
- $this->qty = $objp->qty;
- $this->price = $objp->price;
- $this->subprice = $objp->subprice;
- $this->tva_tx = $objp->tva_tx;
- $this->remise = $objp->remise;
- $this->remise_percent = $objp->remise_percent;
+ $this->rowid = $objp->rowid;
+ $this->fk_commande = $objp->fk_commande;
+ $this->desc = $objp->description;
+ $this->qty = $objp->qty;
+ $this->price = $objp->price;
+ $this->subprice = $objp->subprice;
+ $this->tva_tx = $objp->tva_tx;
+ $this->remise = $objp->remise;
+ $this->remise_percent = $objp->remise_percent;
$this->fk_remise_except = $objp->fk_remise_except;
- $this->produit_id = $objp->fk_product;
- $this->info_bits = $objp->info_bits;
- $this->total_ht = $objp->total_ht;
- $this->total_tva = $objp->total_tva;
- $this->total_ttc = $objp->total_ttc;
- $this->marge_tx = $objp->marge_tx;
- $this->marque_tx = $objp->marque_tx;
- $this->rang = $objp->rang;
+ $this->produit_id = $objp->fk_product;
+ $this->info_bits = $objp->info_bits;
+ $this->total_ht = $objp->total_ht;
+ $this->total_tva = $objp->total_tva;
+ $this->total_ttc = $objp->total_ttc;
+ $this->marge_tx = $objp->marge_tx;
+ $this->marque_tx = $objp->marque_tx;
+ $this->rang = $objp->rang;
- $this->ref = $objp->product_ref;
- $this->product_libelle = $objp->product_libelle;
- $this->product_desc = $objp->product_desc;
+ $this->ref = $objp->product_ref;
+ $this->product_libelle = $objp->product_libelle;
+ $this->product_desc = $objp->product_desc;
$this->db->free($result);
}
diff --git a/htdocs/expedition/commande.php b/htdocs/expedition/commande.php
index 7e25c6134ea..7730a039ddb 100644
--- a/htdocs/expedition/commande.php
+++ b/htdocs/expedition/commande.php
@@ -1,7 +1,7 @@
* Copyright (C) 2005 Laurent Destailleur
- * Copyright (C) 2005-2006 Regis Houssin
+ * Copyright (C) 2005-2008 Regis Houssin
*
* 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
@@ -81,95 +81,94 @@ llxHeader('',$langs->trans("OrderCard"));
if ($_GET["id"] > 0)
{
- $commande = New Commande($db);
- if ( $commande->fetch($_GET["id"]) > 0)
- {
- $commande->loadExpeditions(1);
+ $commande = New Commande($db);
+ if ( $commande->fetch($_GET["id"]) > 0)
+ {
+ $commande->loadExpeditions(1);
- $soc = new Societe($db);
- $soc->fetch($commande->socid);
+ $soc = new Societe($db);
+ $soc->fetch($commande->socid);
- $author = new User($db);
- $author->id = $commande->user_author_id;
- $author->fetch();
+ $author = new User($db);
+ $author->id = $commande->user_author_id;
+ $author->fetch();
$head = commande_prepare_head($commande);
- dolibarr_fiche_head($head, 'shipping', $langs->trans("CustomerOrder"));
+ dolibarr_fiche_head($head, 'shipping', $langs->trans("CustomerOrder"));
- /*
- * Confirmation de la validation
- *
- */
- if ($_GET["action"] == 'cloture')
- {
- $html->form_confirm("commande.php?id=".$_GET["id"],"Clôturer la commande","Etes-vous sûr de vouloir clôturer cette commande ?","confirm_cloture");
- print " ";
- }
-
- // Onglet commande
- $nbrow=8;
- if ($conf->projet->enabled) $nbrow++;
-
- print '';
-
- // Ref
- print '| '.$langs->trans('Ref').' | ';
- print ''.$commande->ref.' | ';
- print ' ';
-
- // Ref commande client
- print '| ';
- print '';
- print ' | ';
- if ($user->rights->commande->creer && $_GET['action'] == 'RefCustomerOrder')
+ /*
+ * Confirmation de la validation
+ *
+ */
+ if ($_GET["action"] == 'cloture')
+ {
+ $html->form_confirm("commande.php?id=".$_GET["id"],"Clôturer la commande","Etes-vous sûr de vouloir clôturer cette commande ?","confirm_cloture");
+ print " ";
+ }
+
+ // Onglet commande
+ $nbrow=8;
+ if ($conf->projet->enabled) $nbrow++;
+
+ print '';
+
+ // Ref
+ print '| '.$langs->trans('Ref').' | ';
+ print ''.$commande->ref.' | ';
+ print ' ';
+
+ // Ref commande client
+ print '| ';
+ print '';
+ print ' | ';
+ if ($user->rights->commande->creer && $_GET['action'] == 'RefCustomerOrder')
{
- print '';
}
- else
+ else
{
print $commande->ref_client;
}
- print ' | ';
- print ' ';
-
-
- // Société
- print '| '.$langs->trans('Company').' | ';
- print ''.$soc->getNomUrl(1).' | ';
- print ' ';
-
- // Date
- print '| '.$langs->trans('Date').' | ';
- print ''.dolibarr_print_date($commande->date,'daytext').' | ';
- print ''.$langs->trans('Source').' : ' . $commande->sources[$commande->source] ;
- if ($commande->source == 0)
+ print ' | ';
+ print ' ';
+
+ // Société
+ print '| '.$langs->trans('Company').' | ';
+ print ''.$soc->getNomUrl(1).' | ';
+ print ' ';
+
+ // Date
+ print '| '.$langs->trans('Date').' | ';
+ print ''.dolibarr_print_date($commande->date,'daytext').' | ';
+ print ''.$langs->trans('Source').' : ' . $commande->sources[$commande->source] ;
+ if ($commande->source == 0)
{
// Si source = propal
$propal = new Propal($db);
$propal->fetch($commande->propale_id);
print ' -> '.$propal->ref.'';
}
- print ' | ';
- print ' ';
-
- // Date de livraison
- print '| ';
- print '';
- print ' | ';
- if ($_GET['action'] == 'editdate_livraison')
+ print ' | ';
+ print ' ';
+
+ // Date de livraison
+ print '| ';
+ print '';
+ print ' | ';
+ if ($_GET['action'] == 'editdate_livraison')
{
print '';
}
- else
+ else
{
print dolibarr_print_date($commande->date_livraison,'daytext');
}
- print ' | ';
- print ''.$langs->trans('NotePublic').' : ';
- print nl2br($commande->note_public);
- print ' | ';
- print ' ';
-
-
- // Adresse de livraison
- print '| ';
- print '';
- print ' | ';
-
- if ($_GET['action'] == 'editdelivery_adress')
+ print ' | ';
+ print ''.$langs->trans('NotePublic').' : ';
+ print nl2br($commande->note_public);
+ print ' | ';
+ print ' ';
+
+ // Adresse de livraison
+ print '| ';
+ print '';
+ print ' | ';
+
+ if ($_GET['action'] == 'editdelivery_adress')
{
$html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->adresse_livraison_id,$_GET['socid'],'adresse_livraison_id','commande',$commande->id);
}
- else
+ else
{
$html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->adresse_livraison_id,$_GET['socid'],'none','commande',$commande->id);
}
- print ' | ';
-
- // Conditions et modes de réglement
- print '';
- print '| ';
- print $langs->trans('PaymentConditionsShort');
- print ' | ';
+ print ' ';
+
+ // Conditions et modes de réglement
+ print '| ';
+ print '';
- print ' | ';
- if ($_GET['action'] == 'editconditions')
- {
- $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->cond_reglement_id,'cond_reglement_id');
- }
- else
- {
- $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->cond_reglement_id,'none');
- }
- print ' | ';
- print '| ';
- print '';
- print ' | ';
- if ($_GET['action'] == 'editmode')
- {
- $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'mode_reglement_id');
- }
- else
- {
- $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'none');
- }
- print ' | ';
+ if ($_GET['action'] != 'editconditions' && $commande->brouillon) print 'id.'">'.img_edit($langs->trans('SetConditions'),1).' | ';
+ print ' ';
+ print ' | ';
+ if ($_GET['action'] == 'editconditions')
+ {
+ $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->cond_reglement_id,'cond_reglement_id');
+ }
+ else
+ {
+ $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->cond_reglement_id,'none');
+ }
+ print ' | ';
+ print '| ';
+ print '';
+ print ' | ';
+ if ($_GET['action'] == 'editmode')
+ {
+ $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'mode_reglement_id');
+ }
+ else
+ {
+ $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'none');
+ }
+ print ' | ';
+
+ // Projet
+ if ($conf->projet->enabled)
+ {
+ $langs->load('projects');
+ print '| ';
+ print '';
+ print ' | ';
+ if ($_GET['action'] == 'classer')
+ {
+ $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->projet_id, 'projetid');
+ }
+ else
+ {
+ $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->projet_id, 'none');
+ }
+ print ' | ';
+ }
+
+ // Lignes de 3 colonnes
- // Projet
- if ($conf->projet->enabled)
- {
- $langs->load('projects');
- print '| ';
- print '';
- print ' | ';
- if ($_GET['action'] == 'classer')
- {
- $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->projet_id, 'projetid');
- }
- else
- {
- $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->projet_id, 'none');
- }
- print ' | ';
- }
+ // Total HT
+ print '| '.$langs->trans('AmountHT').' | ';
+ print ''.price($commande->total_ht).' | ';
+ print ''.$langs->trans('Currency'.$conf->monnaie).' | ';
- // Lignes de 3 colonnes
+ // Total TVA
+ print '| '.$langs->trans('AmountVAT').' | '.price($commande->total_tva).' | ';
+ print ''.$langs->trans('Currency'.$conf->monnaie).' | ';
+
+ // Total TTC
+ print '| '.$langs->trans('AmountTTC').' | '.price($commande->total_ttc).' | ';
+ print ''.$langs->trans('Currency'.$conf->monnaie).' | ';
- // Total HT
- print '| '.$langs->trans('AmountHT').' | ';
- print ''.price($commande->total_ht).' | ';
- print ''.$langs->trans('Currency'.$conf->monnaie).' | ';
-
- // Total TVA
- print '| '.$langs->trans('AmountVAT').' | '.price($commande->total_tva).' | ';
- print ''.$langs->trans('Currency'.$conf->monnaie).' | ';
+ // Statut
+ print '| '.$langs->trans('Status').' | ';
+ print ''.$commande->getLibStatut(4).' | ';
+ print ' ';
- // Total TTC
- print '| '.$langs->trans('AmountTTC').' | '.price($commande->total_ttc).' | ';
- print ''.$langs->trans('Currency'.$conf->monnaie).' | ';
-
- // Statut
- print '| '.$langs->trans('Status').' | ';
- print ''.$commande->getLibStatut(4).' | ';
- print ' ';
-
- print ' ';
+ print ' | ';
- /**
- * Lignes de commandes avec quantité livrées et reste à livrer
- * Les quantités livrées sont stockées dans $commande->expeditions[fk_product]
- */
- echo '';
+ /**
+ * Lignes de commandes avec quantité livrées et reste à livrer
+ * Les quantités livrées sont stockées dans $commande->expeditions[fk_product]
+ */
+ print '';
- $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.subprice";
- $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as l ";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product = p.rowid";
- $sql.= " WHERE l.fk_commande = ".$commande->id;
- $sql.= " AND p.fk_product_type <> 1";
- $sql.= " ORDER BY l.rowid";
+ $sql = "SELECT cd.fk_product, cd.description, cd.price, cd.qty, cd.rowid, cd.tva_tx, cd.subprice";
+ $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd ";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
+ $sql.= " WHERE cd.fk_commande = ".$commande->id;
+ $sql.= " AND p.fk_product_type <> 1";
+ $sql.= " ORDER BY cd.rowid";
- $resql = $db->query($sql);
- if ($resql)
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ $i = 0;
+
+ print '';
+ print '| '.$langs->trans("Description").' | ';
+ print ''.$langs->trans("QtyOrdered").' | ';
+ print ''.$langs->trans("QtyShipped").' | ';
+ print ''.$langs->trans("KeepToShip").' | ';
+ if ($conf->stock->enabled)
+ {
+ print ''.$langs->trans("Stock").' | ';
+ }
+ else
+ {
+ print ' | ';
+ }
+ print " \n";
+
+ $var=true;
+ $reste_a_livrer = array();
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($resql);
+
+ $var=!$var;
+ print "";
+ if ($objp->fk_product > 0)
{
- $num = $db->num_rows($resql);
- $i = 0;
-
- print ' ';
- print '| '.$langs->trans("Description").' | ';
- print ''.$langs->trans("QtyOrdered").' | ';
- print ''.$langs->trans("QtyShipped").' | ';
- print ''.$langs->trans("KeepToShip").' | ';
- if ($conf->stock->enabled)
- {
- print ''.$langs->trans("Stock").' | ';
- }
- else
- {
- print ' | ';
- }
- print " \n";
-
- $var=true;
- $reste_a_livrer = array();
- while ($i < $num)
- {
- $objp = $db->fetch_object($resql);
-
- $var=!$var;
- print "";
- if ($objp->fk_product > 0)
- {
- $product = new Product($db);
- $product->fetch($objp->fk_product);
- print '| ';
- print '';
- print img_object($langs->trans("Product"),"product").' '.$product->ref.'';
- print $product->libelle?' - '.$product->libelle:'';
- print ' | ';
- }
- else
- {
- print "".nl2br($objp->description)." | \n";
- }
-
- print ''.$objp->qty.' | ';
-
- print '';
- $quantite_livree = $commande->expeditions[$objp->fk_product];
- print $quantite_livree;
- print ' | ';
-
- $reste_a_livrer[$objp->fk_product] = $objp->qty - $quantite_livree;
- $reste_a_livrer_total = $reste_a_livrer_total + $reste_a_livrer[$objp->fk_product];
- print '';
- print $reste_a_livrer[$objp->fk_product];
- print ' | ';
-
- if ($conf->stock->enabled)
- {
- print '';
- print $product->stock_reel;
- if ($product->stock_reel < $reste_a_livrer[$objp->fk_product])
- {
- print ' '.img_warning($langs->trans("StockTooLow"));
- }
- print ' | ';
- }
- else
- {
- print ' | ';
- }
- print " ";
-
- $i++;
- $var=!$var;
- }
- $db->free($resql);
-
- if (! $num)
- {
- print ''.$langs->trans("NoArticleOfTypeProduct").' ';
- }
-
- print " | ";
+ $product = new Product($db);
+ $product->fetch($objp->fk_product);
+ print '';
+ print '';
+ print img_object($langs->trans("Product"),"product").' '.$product->ref.'';
+ print $product->libelle?' - '.$product->libelle:'';
+ print ' | ';
}
else
{
- dolibarr_print_error($db);
+ print "".nl2br($objp->description)." | \n";
}
-
- print '';
-
- /*
- * Boutons Actions
- */
- if ($user->societe_id == 0)
- {
- print '';
+ print ' '.$objp->qty.' | ';
- // Bouton expedier sans gestion des stocks
- if (! $conf->stock->enabled && $reste_a_livrer_total > 0 && ! $commande->brouillon && $user->rights->expedition->creer)
- {
- print ' '.$langs->trans("NewSending").'';
- }
+ print ' ';
+ $quantite_livree = $commande->expeditions[$objp->fk_product];
+ print $quantite_livree;
+ print ' | ';
- print " ";
+ $reste_a_livrer[$objp->fk_product] = $objp->qty - $quantite_livree;
+ $reste_a_livrer_total = $reste_a_livrer_total + $reste_a_livrer[$objp->fk_product];
+ print '';
+ print $reste_a_livrer[$objp->fk_product];
+ print ' | ';
- }
-
- print '| ';
-
- /*
- * Documents générés
- *
- */
- $comref = sanitize_string($commande->ref);
- $file = $conf->commande->dir_output . '/' . $comref . '/' . $comref . '.pdf';
- $relativepath = $comref.'/'.$comref.'.pdf';
- $filedir = $conf->commande->dir_output . '/' . $comref;
- $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id;
- $genallowed=0;
- $delallowed=0;
-
- $somethingshown=$html->show_documents('commande',$comref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf);
-
-
- print ' | ';
-
-
- // Bouton expedier avec gestion des stocks
- if ($conf->stock->enabled && $reste_a_livrer_total > 0 && $commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer)
+ if ($conf->stock->enabled)
{
- print_titre($langs->trans("NewSending"));
-
- print '\n";
-
- $somethingshown=1;
+ print ' | ';
+ print $product->stock_reel;
+ if ($product->stock_reel < $reste_a_livrer[$objp->fk_product])
+ {
+ print ' '.img_warning($langs->trans("StockTooLow"));
+ }
+ print ' | ';
}
+ else
+ {
+ print ' | ';
+ }
+ print " ";
+
+ $i++;
+ $var=!$var;
+ }
+ $db->free($resql);
+
+ if (! $num)
+ {
+ print ''.$langs->trans("NoArticleOfTypeProduct").' ';
+ }
+
+ print " | ";
+ }
+ else
+ {
+ dolibarr_print_error($db);
+ }
+
+ print '';
+
+
+ /*
+ * Boutons Actions
+ */
+ if ($user->societe_id == 0)
+ {
+ print '';
+
+ // Bouton expedier sans gestion des stocks
+ if (! $conf->stock->enabled && $reste_a_livrer_total > 0 && ! $commande->brouillon && $user->rights->expedition->creer)
+ {
+ print ' '.$langs->trans("NewSending").'';
+ }
+ print " ";
+ }
+
+ print '| ';
+
+ /*
+ * Documents générés
+ *
+ */
+ $comref = sanitize_string($commande->ref);
+ $file = $conf->commande->dir_output . '/' . $comref . '/' . $comref . '.pdf';
+ $relativepath = $comref.'/'.$comref.'.pdf';
+ $filedir = $conf->commande->dir_output . '/' . $comref;
+ $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id;
+ $genallowed=0;
+ $delallowed=0;
+
+ $somethingshown=$html->show_documents('commande',$comref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf);
+
+ print ' | ';
+
+ // Bouton expedier avec gestion des stocks
+ if ($conf->stock->enabled && $reste_a_livrer_total > 0 && $commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer)
+ {
+ print_titre($langs->trans("NewSending"));
+
+ print ' | ";
+ print "\n";
+
+ $somethingshown=1;
+ }
+
+ print " ";
/*
@@ -498,7 +491,7 @@ if ($_GET["id"] > 0)
$sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e";
if ($conf->livraison->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid";
$sql .= " WHERE cd.fk_commande = ".$commande->id;
- $sql .= " AND cd.rowid = ed.fk_commande_ligne";
+ $sql .= " AND cd.rowid = ed.fk_origin_line";
$sql .= " AND ed.fk_expedition = e.rowid";
$sql .= " ORDER BY cd.fk_product";
diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php
index b5de9d43c50..bd7f685a811 100644
--- a/htdocs/expedition/expedition.class.php
+++ b/htdocs/expedition/expedition.class.php
@@ -1,7 +1,8 @@
- * Copyright (C) 2006 Laurent Destailleur
- * Copyright (C) 2007 Franky Van Liedekerke
+/* Copyright (C) 2003 Rodolphe Quiedeville
+ * Copyright (C) 2006 Laurent Destailleur
+ * Copyright (C) 2007 Franky Van Liedekerke
+ * Copyright (C) 2005-2008 Régis Houssin
*
* 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
@@ -29,7 +30,8 @@
*/
require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php");
-require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
+if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
+if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
/**
@@ -40,9 +42,12 @@ class Expedition extends CommonObject
{
var $db;
var $id;
+ var $socid;
var $brouillon;
var $entrepot_id;
var $modelpdf;
+ var $origin;
+ var $origin_id;
/**
@@ -50,8 +55,8 @@ class Expedition extends CommonObject
*
*/
function Expedition($DB)
- {
- global $langs;
+ {
+ global $langs;
$this->db = $DB;
$this->lignes = array();
@@ -61,7 +66,7 @@ class Expedition extends CommonObject
$this->statuts[1] = $langs->trans("Validated");
$this->products = array();
- }
+ }
/**
* \brief Créé expédition en base
@@ -69,115 +74,125 @@ class Expedition extends CommonObject
* \return int <0 si erreur, id expédition 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 l'expedition */
+ $this->brouillon = 1;
+
+ $this->user = $user;
+
+ $this->db->begin();
+
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."expedition (date_creation, fk_user_author, date_expedition";
+ $sql.= ", fk_soc";
+ $sql.= ")";
+ $sql.= " VALUES (now(), $user->id, ".$this->db->idate($this->date_expedition);
+ $sql.= ", ".$this->socid;
+ $sql.= ")";
+
+ $resql=$this->db->query($sql);
+ if ($resql)
{
- require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php";
- $error = 0;
- /* On positionne en mode brouillon la commande */
- $this->brouillon = 1;
+ $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."expedition");
- $this->user = $user;
-
- $this->db->begin();
-
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."expedition (date_creation, fk_user_author, date_expedition, fk_commande";
- if ($this->entrepot_id) $sql.= ", fk_entrepot";
- $sql.= ")";
- $sql.= " VALUES (now(), $user->id, ".$this->db->idate($this->date_expedition).",$this->commande_id";
- if ($this->entrepot_id) $sql.= ", $this->entrepot_id";
- $sql.= ")";
-
- $resql=$this->db->query($sql);
- if ($resql)
+ $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
+ if ($this->db->query($sql))
+ {
+ // Insertion des lignes
+ for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{
- $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."expedition");
-
- $sql = "UPDATE ".MAIN_DB_PREFIX."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_lines();
-
- // Insertion des lignes
- for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
- {
- if (! $this->create_line(0, $this->lignes[$i]->commande_ligne_id, $this->lignes[$i]->qty))
- {
- $error++;
- }
- }
-
- /*
- *
- */
- $sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = 2 WHERE rowid=".$this->commande_id;
- if (! $this->db->query($sql))
- {
- $error++;
- }
+ if (! $this->create_line($this->lignes[$i]->entrepot_id, $this->lignes[$i]->origin_line_id, $this->lignes[$i]->qty))
+ {
+ $error++;
+ }
+ }
- if ($error==0)
- {
- $this->db->commit();
- return $this->id;
- }
- else
- {
- $error++;
- $this->error=$this->db->error()." - sql=$sql";
- $this->db->rollback();
- return -3;
- }
- }
- else
- {
- $error++;
- $this->error=$this->db->error()." - sql=$sql";
- $this->db->rollback();
- return -2;
- }
+ if ($this->id && $this->origin_id)
+ {
+ if ($conf->commande->enabled)
+ {
+ $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_exp (fk_expedition, fk_commande) VALUES ('.$this->id.','.$this->origin_id.')';
+ if (!$this->db->query($sql))
+ {
+ $error++;
+ }
+
+ $sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = 2 WHERE rowid=".$this->origin_id;
+ if (! $this->db->query($sql))
+ {
+ $error++;
+ }
+ }
+ else
+ {
+ $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'pr_exp (fk_expedition, fk_propal) VALUES ('.$this->id.','.$this->origin_id.')';
+ if (!$this->db->query($sql))
+ {
+ $error++;
+ }
+
+ //Todo: definir un statut
+ $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = 9 WHERE rowid=".$this->origin_id;
+ if (! $this->db->query($sql))
+ {
+ $error++;
+ }
+ }
+ }
+
+ if ($error==0)
+ {
+ $this->db->commit();
+ return $this->id;
}
else
{
- $error++;
- $this->error=$this->db->error()." - sql=$sql";
- $this->db->rollback();
- return -1;
+ $error++;
+ $this->error=$this->db->error()." - sql=$sql";
+ $this->db->rollback();
+ return -3;
}
+ }
+ else
+ {
+ $error++;
+ $this->error=$this->db->error()." - sql=$sql";
+ $this->db->rollback();
+ return -2;
+ }
}
+ else
+ {
+ $error++;
+ $this->error=$this->db->error()." - sql=$sql";
+ $this->db->rollback();
+ return -1;
+ }
+ }
/**
*
*
*/
- function create_line($transaction, $commande_ligne_id, $qty)
+ function create_line($entrepot_id, $origin_line_id, $qty)
{
- $error = 0;
+ $error = 0;
- $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]->fk_product;
- }
- $j++;
- }
-
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet (fk_expedition, fk_commande_ligne, qty)";
- $sql .= " VALUES ($this->id,".$commande_ligne_id.",".$qty.")";
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet (fk_expedition, fk_entrepot, fk_origin_line, qty)";
+ $sql .= " VALUES (".$this->id.", ".$entrepot_id.", ".$origin_line_id.", ".$qty.")";
if (! $this->db->query($sql) )
- {
- $error++;
- }
+ {
+ $error++;
+ }
if ($error == 0 )
- {
- return 1;
- }
+ {
+ return 1;
+ }
}
/**
@@ -188,16 +203,16 @@ class Expedition extends CommonObject
{
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, e.model_pdf,";
- $sql.= " c.fk_adresse_livraison";
+ $sql = "SELECT e.rowid, e.fk_soc as socid, e.date_creation, e.ref, e.fk_user_author, e.fk_statut";
+ $sql.= ", ".$this->db->pdate("e.date_expedition")." as date_expedition, e.model_pdf, e.fk_adresse_livraison";
+ if ($conf->commande->enabled) $sql.=", ce.fk_commande as origin_id";
if ($conf->livraison->enabled) $sql.=", l.rowid as livraison_id";
- $sql.= " FROM ".MAIN_DB_PREFIX."commande as c,";
- $sql.= " ".MAIN_DB_PREFIX."expedition as e";
+ $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."co_exp as ce ON e.rowid = ce.fk_expedition";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON ce.fk_commande = c.rowid";
if ($conf->livraison->enabled) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON e.rowid = l.fk_expedition";
$sql.= " WHERE e.rowid = ".$id;
- $sql.= " AND e.fk_commande = c.rowid";
-
+
$result = $this->db->query($sql) ;
if ($result)
@@ -208,17 +223,17 @@ class Expedition extends CommonObject
$this->id = $obj->rowid;
$this->ref = $obj->ref;
+ $this->socid = $obj->socid;
$this->statut = $obj->fk_statut;
- $this->commande_id = $obj->fk_commande;
- if ($conf->livraison->enabled)
- {
- $this->livraison_id = $obj->livraison_id;
- }
+ $this->origin_id = $obj->origin_id;
+ $this->livraison_id = $obj->livraison_id;
$this->user_author_id = $obj->fk_user_author;
$this->date = $obj->date_expedition;
- $this->entrepot_id = $obj->fk_entrepot;
$this->adresse_livraison_id = $obj->fk_adresse_livraison;
$this->modelpdf = $obj->model_pdf;
+
+ if ($conf->commande->enabled) $this->origin = "commande";
+
$this->db->free($result);
if ($this->statut == 0) $this->brouillon = 1;
@@ -416,95 +431,94 @@ class Expedition extends CommonObject
* Ajoute une ligne
*
*/
- function addline( $id, $qty )
- {
- $num = sizeof($this->lignes);
- $ligne = new ExpeditionLigne($this->db);
+ function addline( $entrepot_id, $id, $qty )
+ {
+ $num = sizeof($this->lignes);
+ $ligne = new ExpeditionLigne($this->db);
- $ligne->commande_ligne_id = $id;
- $ligne->qty = $qty;
+ $ligne->entrepot_id = $entrepot_id;
+ $ligne->origin_line_id = $id;
+ $ligne->qty = $qty;
- $this->lignes[$num] = $ligne;
- }
+ $this->lignes[$num] = $ligne;
+ }
/**
*
*
*/
function delete_line($idligne)
- {
- if ($this->statut == 0)
- {
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet WHERE rowid = $idligne";
-
- if ($this->db->query($sql) )
+ {
+ if ($this->statut == 0)
+ {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet WHERE rowid = $idligne";
+
+ if ($this->db->query($sql) )
{
- $this->update_price();
-
+ $this->update_price();
return 1;
}
- else
+ else
{
return 0;
}
+ }
}
- }
+
/**
* Supprime la fiche
*
*/
function delete()
{
- $this->db->begin();
+ $this->db->begin();
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition = $this->id ;";
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition = ".$this->id;
if ( $this->db->query($sql) )
- {
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition WHERE rowid = $this->id;";
- if ( $this->db->query($sql) )
- {
- $this->db->commit();
-
- // On efface le répertoire de pdf provisoire
- $expref = sanitize_string($this->ref);
- if ($conf->expedition->dir_output)
- {
- $dir = $conf->expedition->dir_output . "/" . $expref ;
- $file = $conf->expedition->dir_output . "/" . $expref . "/" . $expref . ".pdf";
- if (file_exists($file))
- {
- if (!dol_delete_file($file))
- {
- $this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
- return 0;
- }
- }
- if (file_exists($dir))
- {
- if (!dol_delete_dir($dir))
- {
- $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
- return 0;
- }
- }
- }
-
- return 1;
- }
- else
- {
- $this->db->rollback();
- return -2;
- }
- }
+ {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition WHERE rowid = ".$this->id;
+ if ( $this->db->query($sql) )
+ {
+ $this->db->commit();
+
+ // On efface le répertoire de pdf provisoire
+ $expref = sanitize_string($this->ref);
+ if ($conf->expedition->dir_output)
+ {
+ $dir = $conf->expedition->dir_output . "/" . $expref ;
+ $file = $conf->expedition->dir_output . "/" . $expref . "/" . $expref . ".pdf";
+ if (file_exists($file))
+ {
+ if (!dol_delete_file($file))
+ {
+ $this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
+ return 0;
+ }
+ }
+ if (file_exists($dir))
+ {
+ if (!dol_delete_dir($dir))
+ {
+ $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
+ return 0;
+ }
+ }
+ }
+ return 1;
+ }
+ else
+ {
+ $this->db->rollback();
+ return -2;
+ }
+ }
else
- {
- $this->db->rollback();
- return -1;
- }
+ {
+ $this->db->rollback();
+ return -1;
+ }
}
-
/**
* Classe la commande
*
@@ -553,27 +567,29 @@ class Expedition extends CommonObject
/*
- * Lit la commande associée
+ * Lit le document associé
*
*/
- function fetch_commande()
+ function fetch_object($object)
{
- $this->commande = & new Commande($this->db);
- $this->commande->fetch($this->commande_id);
+ $class = ucfirst($object);
+ $this->$object = & new $class($this->db);
+ $this->$object->fetch($this->origin_id);
}
function fetch_lines()
{
- $sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.qty as qty_commande";
- $sql.= ", ed.qty as qty_expedie, ed.fk_commande_ligne";
+ //Todo: récupérer les champs du document associé a part
+
+ $sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.qty as qty_asked";
+ $sql.= ", ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot";
$sql.= ", p.ref, p.label, p.weight, p.weight_units, p.volume, p.volume_units";
$sql.= " FROM (".MAIN_DB_PREFIX."commandedet as cd";
$sql.= ", ".MAIN_DB_PREFIX."expeditiondet as ed)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON (p.rowid = cd.fk_product)";
$sql.= " WHERE ed.fk_expedition = ".$this->id;
- $sql.= " AND ed.fk_commande_ligne = cd.rowid";
-
+ $sql.= " AND ed.fk_origin_line = cd.rowid";
$resql = $this->db->query($sql);
if ($resql)
@@ -585,13 +601,14 @@ class Expedition extends CommonObject
$ligne = new ExpeditionLigne($this->db);
$obj = $this->db->fetch_object($resql);
- $ligne->order_line_id = $obj->fk_commande_ligne;
+ $ligne->origin_line_id = $obj->fk_origin_line;
+ $ligne->entrepot_id = $obj->fk_entrepot;
$ligne->fk_product = $obj->fk_product;
$ligne->ref = $obj->ref;
$ligne->libelle = $obj->label;
$ligne->description = $obj->description;
- $ligne->qty_commande = $obj->qty_commande;
- $ligne->qty_expedie = $obj->qty_expedie;
+ $ligne->qty_asked = $obj->qty_asked;
+ $ligne->qty_shipped = $obj->qty_shipped;
$ligne->weight = $obj->weight;
$ligne->weight_units = $obj->weight_units;
$ligne->volume = $obj->volume;
@@ -734,8 +751,8 @@ class ExpeditionLigne
var $qty_expedition;
var $fk_product;
- // From llx_commandedet
- var $qty_commande;
+ // From llx_commandedet or llx_propaldet
+ var $qty_asking;
var $libelle; // Label produit
var $product_desc; // Description produit
var $ref;
diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php
index d52a8f4376f..c4c3550c444 100644
--- a/htdocs/expedition/fiche.php
+++ b/htdocs/expedition/fiche.php
@@ -2,7 +2,7 @@
/* Copyright (C) 2003-2005 Rodolphe Quiedeville
* Copyright (C) 2005-2006 Laurent Destailleur
* Copyright (C) 2005 Simon TOSSER
- * Copyright (C) 2005-2007 Régis Houssin
+ * Copyright (C) 2005-2008 Régis Houssin
*
* 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
@@ -34,6 +34,7 @@ require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT ."/expedition/mods/pdf/ModelePdfExpedition.class.php");
if ($conf->produit->enabled) require_once(DOL_DOCUMENT_ROOT."/product.class.php");
if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
+if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
if ($conf->stock->enabled) require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php");
$langs->load("companies");
@@ -55,6 +56,8 @@ if ($user->societe_id > 0)
$socid = $user->societe_id;
}
+$origin = $_GET["origin"]?$_GET["origin"]:$_POST["origin"];
+$origin_id = $_GET["origin_id"]?$_GET["origin_id"]:$_POST["origin_id"];
/*
* Actions
@@ -62,47 +65,51 @@ if ($user->societe_id > 0)
if ($_POST["action"] == 'add')
{
- // \todo Mettre id entrepot sur ligne detail expedition et non sur fiche expedition
+ $db->begin();
- $db->begin();
+ // Creation de l'objet expedition
+ $expedition = new Expedition($db);
- // Creation de l'objet expedition
- $expedition = new Expedition($db);
+ $expedition->date_expedition = time();
+ $expedition->note = $_POST["note"];
+ $expedition->origin = $origin;
+ $expedition->origin_id = $origin_id;
- $expedition->date_expedition = time();
- $expedition->note = $_POST["note"];
- $expedition->commande_id = $_POST["commande_id"];
- $expedition->entrepot_id = $_POST["entrepot_id"];
-
- // On boucle sur chaque ligne de commande pour compléter objet expedition
- // avec qté à livrer
- $commande = new Commande($db);
- $commande->fetch($expedition->commande_id);
- $commande->fetch_lines();
- for ($i = 0 ; $i < sizeof($commande->lignes) ; $i++)
+ // On boucle sur chaque ligne du document d'origine pour compléter objet expedition
+ // avec qté à livrer
+ $class = ucfirst($expedition->origin);
+ $object = new $class($db);
+ $object->fetch($expedition->origin_id);
+ //$object->fetch_lines();
+
+ $expedition->socid = $object->socid;
+
+ for ($i = 0 ; $i < sizeof($object->lignes) ; $i++)
+ {
+ $ent = "entl".$i;
+ $idl = "idl".$i;
+ $qty = "qtyl".$i;
+ $entrepot_id = $_POST[$ent]?$_POST[$ent]:$_POST["entrepot_id"];
+ if ($_POST[$qty] > 0)
{
- $qty = "qtyl".$i;
- $idl = "idl".$i;
- if ($_POST[$qty] > 0)
- {
- $expedition->addline($_POST[$idl],$_POST[$qty]);
- }
- }
-
- $ret=$expedition->create($user);
- if ($ret > 0)
- {
- $db->commit();
- Header("Location: fiche.php?id=".$expedition->id);
- exit;
- }
- else
- {
- $db->rollback();
- $mesg=''.$expedition->error.' ';
- $_GET["commande_id"]=$_POST["commande_id"];
- $_GET["action"]='create';
+ $expedition->addline($entrepot_id,$_POST[$idl],$_POST[$qty]);
}
+ }
+
+ $ret=$expedition->create($user);
+ if ($ret > 0)
+ {
+ $db->commit();
+ Header("Location: fiche.php?id=".$expedition->id);
+ exit;
+ }
+ else
+ {
+ $db->rollback();
+ $mesg=''.$expedition->error.' ';
+ $_GET["commande_id"]=$_POST["commande_id"];
+ $_GET["action"]='create';
+ }
}
/*
@@ -186,26 +193,29 @@ if ($_GET["action"] == 'create')
print $mesg.' ';
}
- $commande = new Commande($db);
- $commande->loadExpeditions();
+ $class = ucfirst($origin);
- if ( $commande->fetch($_GET["commande_id"]))
+ $object = new $class($db);
+ $object->loadExpeditions();
+
+ if ( $object->fetch($origin_id))
{
$soc = new Societe($db);
- $soc->fetch($commande->socid);
+ $soc->fetch($object->socid);
$author = new User($db);
- $author->id = $commande->user_author_id;
+ $author->id = $object->user_author_id;
$author->fetch();
$entrepot = new Entrepot($db);
/*
- * Commande
+ * Document source
*/
print '
|