Dbut modification expedition livraison

Phase1: modification des expeditions
- elles pourront dsormais etre li  une propale (pas encore effectif)
- l'id entrepot est stock dans la ligne produit
This commit is contained in:
Regis Houssin 2008-01-17 10:27:59 +00:00
parent 857e8c0726
commit c19f0c753f
20 changed files with 1167 additions and 902 deletions

View File

@ -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 '</td>';
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 '<td valign="top" colspan="2" width="50%" rowspan="'.$rowspan.'">'.$langs->trans('NotePublic').' :<br>'. nl2br($propal->note_public).'</td>';
@ -901,7 +898,7 @@ if ($_GET['propalid'] > 0)
// gerer par les commandes et non les propales
if ($conf->expedition->enabled || $conf->livraison->enabled)
{
if ($conf->global->PROPALE_ADD_SHIPPING_DATE)
if ($conf->global->PROPALE_ADD_SHIPPING_DATE || !$conf->commande->enabled)
{
$langs->load('deliveries');
print '<tr><td>';
@ -928,7 +925,7 @@ if ($_GET['propalid'] > 0)
}
// adresse de livraison
if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS)
if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS || !$conf->commande->enabled)
{
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
@ -1014,11 +1011,11 @@ if ($_GET['propalid'] > 0)
print '</td><td colspan="3">';
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 '</td></tr>';
}

View File

@ -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);
}

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2008 Regis Houssin <regis@dolibarr.fr>
*
* 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 "<br />";
}
// Onglet commande
$nbrow=8;
if ($conf->projet->enabled) $nbrow++;
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="18%">'.$langs->trans('Ref').'</td>';
print '<td colspan="3">'.$commande->ref.'</td>';
print '</tr>';
// Ref commande client
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
print $langs->trans('RefCustomer').'</td><td align="left">';
print '</td>';
if ($_GET['action'] != 'RefCustomerOrder' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=RefCustomerOrder&amp;id='.$commande->id.'">'.img_edit($langs->trans('Modify')).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
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 "<br />";
}
// Onglet commande
$nbrow=8;
if ($conf->projet->enabled) $nbrow++;
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="18%">'.$langs->trans('Ref').'</td>';
print '<td colspan="3">'.$commande->ref.'</td>';
print '</tr>';
// Ref commande client
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
print $langs->trans('RefCustomer').'</td><td align="left">';
print '</td>';
if ($_GET['action'] != 'RefCustomerOrder' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=RefCustomerOrder&amp;id='.$commande->id.'">'.img_edit($langs->trans('Modify')).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
if ($user->rights->commande->creer && $_GET['action'] == 'RefCustomerOrder')
{
print '<form action="fiche.php?id='.$id.'" method="post">';
print '<form action="fiche.php?id='.$id.'" method="post">';
print '<input type="hidden" name="action" value="set_ref_client">';
print '<input type="text" class="flat" size="20" name="ref_client" value="'.$commande->ref_client.'">';
print ' <input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
}
else
else
{
print $commande->ref_client;
}
print '</td>';
print '</tr>';
// Société
print '<tr><td>'.$langs->trans('Company').'</td>';
print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
print '</tr>';
// Date
print '<tr><td>'.$langs->trans('Date').'</td>';
print '<td colspan="2">'.dolibarr_print_date($commande->date,'daytext').'</td>';
print '<td width="50%">'.$langs->trans('Source').' : ' . $commande->sources[$commande->source] ;
if ($commande->source == 0)
print '</td>';
print '</tr>';
// Société
print '<tr><td>'.$langs->trans('Company').'</td>';
print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
print '</tr>';
// Date
print '<tr><td>'.$langs->trans('Date').'</td>';
print '<td colspan="2">'.dolibarr_print_date($commande->date,'daytext').'</td>';
print '<td width="50%">'.$langs->trans('Source').' : ' . $commande->sources[$commande->source] ;
if ($commande->source == 0)
{
// Si source = propal
$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>';
print '</tr>';
// Date de livraison
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('DeliveryDate');
print '</td>';
if ($_GET['action'] != 'editdate_livraison' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editdate_livraison')
print '</td>';
print '</tr>';
// Date de livraison
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('DeliveryDate');
print '</td>';
if ($_GET['action'] != 'editdate_livraison' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editdate_livraison')
{
print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'" method="post">';
print '<input type="hidden" name="action" value="setdate_livraison">';
@ -177,314 +176,308 @@ if ($_GET["id"] > 0)
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
}
else
else
{
print dolibarr_print_date($commande->date_livraison,'daytext');
}
print '</td>';
print '<td rowspan="'.$nbrow.'" valign="top">'.$langs->trans('NotePublic').' :<br>';
print nl2br($commande->note_public);
print '</td>';
print '</tr>';
// Adresse de livraison
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('DeliveryAddress');
print '</td>';
if ($_GET['action'] != 'editdelivery_adress' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdelivery_adress&amp;socid='.$commande->socid.'&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetDeliveryAddress'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editdelivery_adress')
print '</td>';
print '<td rowspan="'.$nbrow.'" valign="top">'.$langs->trans('NotePublic').' :<br>';
print nl2br($commande->note_public);
print '</td>';
print '</tr>';
// Adresse de livraison
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('DeliveryAddress');
print '</td>';
if ($_GET['action'] != 'editdelivery_adress' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdelivery_adress&amp;socid='.$commande->socid.'&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetDeliveryAddress'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
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 '</td></tr>';
// Conditions et modes de réglement
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('PaymentConditionsShort');
print '</td>';
print '</td></tr>';
// Conditions et modes de réglement
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('PaymentConditionsShort');
print '</td>';
if ($_GET['action'] != 'editconditions' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
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 '</td></tr>';
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('PaymentMode');
print '</td>';
if ($_GET['action'] != 'editmode' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
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 '</td></tr>';
if ($_GET['action'] != 'editconditions' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
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 '</td></tr>';
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('PaymentMode');
print '</td>';
if ($_GET['action'] != 'editmode' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
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 '</td></tr>';
// Projet
if ($conf->projet->enabled)
{
$langs->load('projects');
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Project');
print '</td>';
if ($_GET['action'] != 'classer' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=classer&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetProject')).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
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 '</td></tr>';
}
// Lignes de 3 colonnes
// Projet
if ($conf->projet->enabled)
{
$langs->load('projects');
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Project');
print '</td>';
if ($_GET['action'] != 'classer' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=classer&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetProject')).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
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 '</td></tr>';
}
// Total HT
print '<tr><td>'.$langs->trans('AmountHT').'</td>';
print '<td align="right"><b>'.price($commande->total_ht).'</b></td>';
print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
// Lignes de 3 colonnes
// Total TVA
print '<tr><td>'.$langs->trans('AmountVAT').'</td><td align="right">'.price($commande->total_tva).'</td>';
print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
// Total TTC
print '<tr><td>'.$langs->trans('AmountTTC').'</td><td align="right">'.price($commande->total_ttc).'</td>';
print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
// Total HT
print '<tr><td>'.$langs->trans('AmountHT').'</td>';
print '<td align="right"><b>'.price($commande->total_ht).'</b></td>';
print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
// Total TVA
print '<tr><td>'.$langs->trans('AmountVAT').'</td><td align="right">'.price($commande->total_tva).'</td>';
print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
// Statut
print '<tr><td>'.$langs->trans('Status').'</td>';
print '<td colspan="2">'.$commande->getLibStatut(4).'</td>';
print '</tr>';
// Total TTC
print '<tr><td>'.$langs->trans('AmountTTC').'</td><td align="right">'.price($commande->total_ttc).'</td>';
print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
// Statut
print '<tr><td>'.$langs->trans('Status').'</td>';
print '<td colspan="2">'.$commande->getLibStatut(4).'</td>';
print '</tr>';
print '</table><br>';
print '</table><br>';
/**
* Lignes de commandes avec quantité livrées et reste à livrer
* Les quantités livrées sont stockées dans $commande->expeditions[fk_product]
*/
echo '<table class="liste" width="100%">';
/**
* Lignes de commandes avec quantité livrées et reste à livrer
* Les quantités livrées sont stockées dans $commande->expeditions[fk_product]
*/
print '<table class="liste" width="100%">';
$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 '<tr class="liste_titre">';
print '<td>'.$langs->trans("Description").'</td>';
print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
print '<td align="center">'.$langs->trans("KeepToShip").'</td>';
if ($conf->stock->enabled)
{
print '<td align="center">'.$langs->trans("Stock").'</td>';
}
else
{
print '<td>&nbsp;</td>';
}
print "</tr>\n";
$var=true;
$reste_a_livrer = array();
while ($i < $num)
{
$objp = $db->fetch_object($resql);
$var=!$var;
print "<tr $bc[$var]>";
if ($objp->fk_product > 0)
{
$num = $db->num_rows($resql);
$i = 0;
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Description").'</td>';
print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
print '<td align="center">'.$langs->trans("KeepToShip").'</td>';
if ($conf->stock->enabled)
{
print '<td align="center">'.$langs->trans("Stock").'</td>';
}
else
{
print '<td>&nbsp;</td>';
}
print "</tr>\n";
$var=true;
$reste_a_livrer = array();
while ($i < $num)
{
$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.'">';
print img_object($langs->trans("Product"),"product").' '.$product->ref.'</a>';
print $product->libelle?' - '.$product->libelle:'';
print '</td>';
}
else
{
print "<td>".nl2br($objp->description)."</td>\n";
}
print '<td align="center">'.$objp->qty.'</td>';
print '<td align="center">';
$quantite_livree = $commande->expeditions[$objp->fk_product];
print $quantite_livree;
print '</td>';
$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 '<td align="center">';
print $reste_a_livrer[$objp->fk_product];
print '</td>';
if ($conf->stock->enabled)
{
print '<td align="center">';
print $product->stock_reel;
if ($product->stock_reel < $reste_a_livrer[$objp->fk_product])
{
print ' '.img_warning($langs->trans("StockTooLow"));
}
print '</td>';
}
else
{
print '<td>&nbsp;</td>';
}
print "</tr>";
$i++;
$var=!$var;
}
$db->free($resql);
if (! $num)
{
print '<tr '.$bc[false].'><td colspan="5">'.$langs->trans("NoArticleOfTypeProduct").'<br>';
}
print "</table>";
$product = new Product($db);
$product->fetch($objp->fk_product);
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">';
print img_object($langs->trans("Product"),"product").' '.$product->ref.'</a>';
print $product->libelle?' - '.$product->libelle:'';
print '</td>';
}
else
{
dolibarr_print_error($db);
print "<td>".nl2br($objp->description)."</td>\n";
}
print '</div>';
/*
* Boutons Actions
*/
if ($user->societe_id == 0)
{
print '<div class="tabsAction">';
print '<td align="center">'.$objp->qty.'</td>';
// Bouton expedier sans gestion des stocks
if (! $conf->stock->enabled && $reste_a_livrer_total > 0 && ! $commande->brouillon && $user->rights->expedition->creer)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/expedition/fiche.php?action=create&amp;commande_id='.$_GET["id"].'">'.$langs->trans("NewSending").'</a>';
}
print '<td align="center">';
$quantite_livree = $commande->expeditions[$objp->fk_product];
print $quantite_livree;
print '</td>';
print "</div>";
$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 '<td align="center">';
print $reste_a_livrer[$objp->fk_product];
print '</td>';
}
print '<table width="100%"><tr><td width="50%" valign="top">';
/*
* 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 '</td><td valign="top" width="50%">';
// 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 '<form method="GET" action="'.DOL_URL_ROOT.'/expedition/fiche.php">';
print '<input type="hidden" name="action" value="create">';
print '<input type="hidden" name="id" value="'.$commande->id.'">';
print '<input type="hidden" name="commande_id" value="'.$commande->id.'">';
print '<table class="border" width="100%">';
$entrepot = new Entrepot($db);
$langs->load("stocks");
print '<tr>';
print '<td>'.$langs->trans("Warehouse").'</td>';
print '<td>';
if (sizeof($user->entrepots) === 1)
{
$uentrepot = array();
$uentrepot[$user->entrepots[0]['id']] = $user->entrepots[0]['label'];
$html->select_array("entrepot_id",$uentrepot);
}
else
{
$html->select_array("entrepot_id",$entrepot->list_array());
}
if (sizeof($entrepot->list_array()) <= 0)
{
print ' &nbsp; Aucun entrepôt définit, <a href="'.DOL_URL_ROOT.'/product/stock/fiche.php?action=create">definissez en un</a>';
}
print '</td></tr>';
/*
print '<tr><td width="20%">Mode d\'expédition</td>';
print '<td>';
$html->select_array("entrepot_id",$entrepot->list_array());
print '</td></tr>';
*/
print '<tr><td align="center" colspan="2">';
print '<input type="submit" class="button" named="save" value="'.$langs->trans("NewSending").'">';
print '</td></tr>';
print "</table>";
print "</form>\n";
$somethingshown=1;
print '<td align="center">';
print $product->stock_reel;
if ($product->stock_reel < $reste_a_livrer[$objp->fk_product])
{
print ' '.img_warning($langs->trans("StockTooLow"));
}
print '</td>';
}
else
{
print '<td>&nbsp;</td>';
}
print "</tr>";
$i++;
$var=!$var;
}
$db->free($resql);
if (! $num)
{
print '<tr '.$bc[false].'><td colspan="5">'.$langs->trans("NoArticleOfTypeProduct").'<br>';
}
print "</table>";
}
else
{
dolibarr_print_error($db);
}
print '</div>';
/*
* Boutons Actions
*/
if ($user->societe_id == 0)
{
print '<div class="tabsAction">';
// Bouton expedier sans gestion des stocks
if (! $conf->stock->enabled && $reste_a_livrer_total > 0 && ! $commande->brouillon && $user->rights->expedition->creer)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/expedition/fiche.php?action=create&amp;object_id='.$_GET["id"].'">'.$langs->trans("NewSending").'</a>';
}
print "</div>";
}
print '<table width="100%"><tr><td width="50%" valign="top">';
/*
* 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 '</td><td valign="top" width="50%">';
// 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 '<form method="GET" action="'.DOL_URL_ROOT.'/expedition/fiche.php">';
print '<input type="hidden" name="action" value="create">';
print '<input type="hidden" name="id" value="'.$commande->id.'">';
print '<input type="hidden" name="origin" value="commande">';
print '<input type="hidden" name="origin_id" value="'.$commande->id.'">';
print '<table class="border" width="100%">';
print "</td></tr></table>";
$entrepot = new Entrepot($db);
$langs->load("stocks");
print '<tr>';
print '<td>'.$langs->trans("Warehouse").'</td>';
print '<td>';
if (sizeof($user->entrepots) === 1)
{
$uentrepot = array();
$uentrepot[$user->entrepots[0]['id']] = $user->entrepots[0]['label'];
$html->select_array("entrepot_id",$uentrepot);
}
else
{
$html->select_array("entrepot_id",$entrepot->list_array());
}
if (sizeof($entrepot->list_array()) <= 0)
{
print ' &nbsp; Aucun entrepôt définit, <a href="'.DOL_URL_ROOT.'/product/stock/fiche.php?action=create">definissez en un</a>';
}
print '</td></tr>';
/*
print '<tr><td width="20%">Mode d\'expédition</td>';
print '<td>';
$html->select_array("entrepot_id",$entrepot->list_array());
print '</td></tr>';
*/
print '<tr><td align="center" colspan="2">';
print '<input type="submit" class="button" named="save" value="'.$langs->trans("NewSending").'">';
print '</td></tr>';
print "</table>";
print "</form>\n";
$somethingshown=1;
}
print "</td></tr></table>";
/*
@ -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";

View File

@ -1,7 +1,8 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
* Copyright (C) 2005-2008 Régis Houssin <regis@dolibarr.fr>
*
* 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;

View File

@ -2,7 +2,7 @@
/* 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>
* Copyright (C) 2005-2007 Régis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2008 Régis Houssin <regis@dolibarr.fr>
*
* 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='<div class="error">'.$expedition->error.'</div>';
$_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='<div class="error">'.$expedition->error.'</div>';
$_GET["commande_id"]=$_POST["commande_id"];
$_GET["action"]='create';
}
}
/*
@ -186,26 +193,29 @@ if ($_GET["action"] == 'create')
print $mesg.'<br>';
}
$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 '<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="origin" value="'.$origin.'">';
print '<input type="hidden" name="origin_id" value="'.$object->id.'">';
if ($_GET["entrepot_id"])
{
print '<input type="hidden" name="entrepot_id" value="'.$_GET["entrepot_id"].'">';
@ -213,41 +223,34 @@ if ($_GET["action"] == 'create')
print '<table class="border" width="100%">';
// Ref commande
print '<tr><td>'.$langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$commande->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref.'</a></td>';
print "</tr>\n";
// Ref commande client
// Ref
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
print $langs->trans('RefCustomerOrderShort').'</td><td align="left">';
print '</td>';
if ($_GET['action'] != 'RefCustomerOrder' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=RefCustomerOrder&amp;id='.$commande->id.'">'.img_edit($langs->trans('Modify')).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
if ($user->rights->commande->creer && $_GET['action'] == 'RefCustomerOrder')
if ($conf->commande->enabled)
{
print '<form action="fiche.php?id='.$id.'" method="post">';
print '<input type="hidden" name="action" value="set_ref_client">';
print '<input type="text" class="flat" size="20" name="ref_client" value="'.$commande->ref_client.'">';
print ' <input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
print $langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$object->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$object->ref;
}
else
{
print $commande->ref_client;
print $langs->trans("RefProposal").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/comm/fiche.php?propalid='.$object->id.'">'.img_object($langs->trans("ShowProposal"),'propal').' '.$object->ref;
}
print '</a></td>';
print "</tr>\n";
// Ref client
print '<tr><td>';
print $langs->trans('RefCustomer').'</td><td colspan="3">';
print $object->ref_client;
print '</td>';
print '</tr>';
// Sociét
// Tiers
print '<tr><td>'.$langs->trans('Company').'</td>';
print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
print '</tr>';
// Date
print "<tr><td>".$langs->trans("Date")."</td>";
print '<td colspan="3">'.dolibarr_print_date($commande->date,"dayhour")."</td></tr>\n";
print '<td colspan="3">'.dolibarr_print_date($object->date,"day")."</td></tr>\n";
// Entrepot (si forcé)
if ($conf->stock->enabled && $_GET["entrepot_id"])
@ -259,9 +262,9 @@ if ($_GET["action"] == 'create')
print '</td></tr>';
}
if ($commande->note && ! $user->societe_id)
if ($object->note && ! $user->societe_id)
{
print '<tr><td colspan="3">'.$langs->trans("NotePrivate").': '.nl2br($commande->note)."</td></tr>";
print '<tr><td colspan="3">'.$langs->trans("NotePrivate").': '.nl2br($object->note)."</td></tr>";
}
print "</table>";
@ -270,15 +273,15 @@ if ($_GET["action"] == 'create')
* Lignes de commandes
*
*/
echo '<br><table class="noborder" width="100%">';
print '<br><table class="noborder" width="100%">';
$lignes = $commande->fetch_lines(1);
$numcommandes = sizeof($commande->lignes);
//$lignes = $object->fetch_lines(1);
$numAsked = sizeof($object->lignes);
/* Lecture des expeditions déjà effectuées */
$commande->loadExpeditions();
$object->loadExpeditions();
if ($numcommandes)
if ($numAsked)
{
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Description").'</td>';
@ -300,10 +303,10 @@ if ($_GET["action"] == 'create')
}
$var=true;
$indicecommande = 0;
while ($indicecommande < $numcommandes)
$indiceAsked = 0;
while ($indiceAsked < $numAsked)
{
$ligne = $commande->lignes[$indicecommande];
$ligne = $object->lignes[$indiceAsked];
$var=!$var;
print "<tr $bc[$var]>\n";
if ($ligne->fk_product > 0)
@ -324,12 +327,12 @@ if ($_GET["action"] == 'create')
print '<td align="center">'.$ligne->qty.'</td>';
print '<td align="center">';
$quantite_livree = $commande->expeditions[$ligne->fk_product];
print $quantite_livree;;
$quantityDelivered = $object->expeditions[$ligne->fk_product];
print $quantityDelivered;
print '</td>';
$quantite_commandee = $ligne->qty;
$quantite_a_livrer = $quantite_commandee - $quantite_livree;
$quantityAsked = $ligne->qty;
$quantityToBeDelivered = $quantityAsked - $quantityDelivered;
if ($conf->stock->enabled)
{
@ -338,20 +341,20 @@ if ($_GET["action"] == 'create')
{
$stock = $product->stock_entrepot[$_GET["entrepot_id"]];
$stock+=0; // Convertit en numérique
$defaultqty=min($quantite_a_livrer, $stock);
$defaultqty=min($quantityToBeDelivered, $stock);
}
// Quantité à livrer
print '<td align="center">';
print '<input name="idl'.$indicecommande.'" type="hidden" value="'.$ligne->id.'">';
print '<input name="qtyl'.$indicecommande.'" type="text" size="4" value="'.$defaultqty.'">';
print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$ligne->id.'">';
print '<input name="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$defaultqty.'">';
print '</td>';
// Stock
if ($_GET["entrepot_id"])
{
print '<td align="right">'.$stock;
if ($stock < $quantite_a_livrer)
if ($stock < $quantityToBeDelivered)
{
print ' '.img_warning($langs->trans("StockTooLow"));
}
@ -387,7 +390,7 @@ if ($_GET["action"] == 'create')
}
print '<td align="left">';
$html->select_array('warehouse'.$i,$array,'',1,0,0);
$html->select_array('entl'.$i,$array,'',1,0,0);
print '</td>';
}
}
@ -395,14 +398,14 @@ if ($_GET["action"] == 'create')
{
// Quantité à livrer
print '<td align="center">';
print '<input name="idl'.$indicecommande.'" type="hidden" value="'.$ligne->id.'">';
print '<input name="qtyl'.$indicecommande.'" type="text" size="6" value="'.$quantite_a_livrer.'">';
print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$ligne->id.'">';
print '<input name="qtyl'.$indiceAsked.'" type="text" size="6" value="'.$quantityToBeDelivered.'">';
print '</td>';
}
print "</tr>\n";
$indicecommande++;
$indiceAsked++;
$var=!$var;
}
@ -426,36 +429,35 @@ else
/* */
/* *************************************************************************** */
{
if ($_GET["id"] > 0)
if ($_GET["id"] > 0)
{
$expedition = New Expedition($db);
$result = $expedition->fetch($_GET["id"]);
$lignes = $expedition->lignes;
$num_prod = sizeof($lignes);
if ($expedition->id > 0)
{
$expedition = New Expedition($db);
$result = $expedition->fetch($_GET["id"]);
$lignes = $expedition->lignes;
$num_prod = sizeof($lignes);
$object = New Commande($db);
$object->fetch($expedition->origin_id);
if ($expedition->id > 0)
{
$soc = new Societe($db);
$soc->fetch($expedition->socid);
$commande = New Commande($db);
$commande->fetch($expedition->commande_id);
$h=0;
$head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$expedition->id;
$head[$h][1] = $langs->trans("SendingCard");
$hselected = $h;
$h++;
$soc = new Societe($db);
$soc->fetch($commande->socid);
if ($conf->livraison->enabled && $expedition->livraison_id)
{
$head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$expedition->livraison_id;
$head[$h][1] = $langs->trans("DeliveryCard");
$h++;
}
$h=0;
$head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$expedition->id;
$head[$h][1] = $langs->trans("SendingCard");
$hselected = $h;
$h++;
if ($conf->livraison->enabled && $expedition->livraison_id)
{
$head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$expedition->livraison_id;
$head[$h][1] = $langs->trans("DeliveryCard");
$h++;
}
dolibarr_fiche_head($head, $hselected, $langs->trans("Sending"));
dolibarr_fiche_head($head, $hselected, $langs->trans("Sending"));
/*
* Confirmation de la suppression
@ -492,9 +494,9 @@ else
$totalVolume = '';
for ($i = 0 ; $i < $num_prod ; $i++)
{
$totalWeight += $lignes[$i]->weight*$lignes[$i]->qty_expedie;
$totalWeight += $lignes[$i]->weight*$lignes[$i]->qty_shipped;
$weightUnit = $lignes[$i]->weight_units;
$totalVolume += $lignes[$i]->volume*$lignes[$i]->qty_expedie;
$totalVolume += $lignes[$i]->volume*$lignes[$i]->qty_shipped;
$volumeUnit = $lignes[$i]->volume_units;
}
@ -509,19 +511,29 @@ else
print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
print "</tr>";
// Commande liée
print '<tr><td>'.$langs->trans("RefOrder").'</td>';
print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/expedition/commande.php?id='.$commande->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref."</a></td>\n";
// Document liée
print '<tr><td>';
if ($conf->commande->enabled)
{
print $langs->trans("RefOrder").'</td>';
print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/expedition/commande.php?id='.$object->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$object->ref;
}
else
{
print $langs->trans("RefProposal").'</td>';
print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/expedition/propal.php?propalid='.$object->id.'">'.img_object($langs->trans("ShowProposal"),'propal').' '.$object->ref;
}
print "</a></td>\n";
print '</tr>';
// Commande liée
print '<tr><td>'.$langs->trans("RefCustomerOrderShort").'</td>';
print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/expedition/commande.php?id='.$commande->id.'">'.$commande->ref_client."</a></td>\n";
// Ref client
print '<tr><td>'.$langs->trans("RefCustomer").'</td>';
print '<td colspan="3">'.$object->ref_client."</a></td>\n";
print '</tr>';
// Date
print '<tr><td>'.$langs->trans("Date").'</td>';
print '<td colspan="3">'.dolibarr_print_date($expedition->date,"dayhour")."</td>\n";
print '<td colspan="3">'.dolibarr_print_date($expedition->date,"day")."</td>\n";
print '</tr>';
// Poids Total
@ -570,7 +582,6 @@ else
for ($i = 0 ; $i < $num_prod ; $i++)
{
$var=!$var;
print "<tr $bc[$var]>";
if ($lignes[$i]->fk_product > 0)
{
@ -585,22 +596,22 @@ else
}
// Qte commandé
print '<td align="center">'.$lignes[$i]->qty_commande.'</td>';
print '<td align="center">'.$lignes[$i]->qty_asked.'</td>';
// Qte a expedier ou expedier
print '<td align="center">'.$lignes[$i]->qty_expedie.'</td>';
print '<td align="center">'.$lignes[$i]->qty_shipped.'</td>';
// Poids
print '<td align="center">'.$lignes[$i]->weight*$lignes[$i]->qty_expedie.' '.measuring_units_string($lignes[$i]->weight_units,"weight").'</td>';
print '<td align="center">'.$lignes[$i]->weight*$lignes[$i]->qty_shipped.' '.measuring_units_string($lignes[$i]->weight_units,"weight").'</td>';
// Volume
print '<td align="center">'.$lignes[$i]->volume*$lignes[$i]->qty_expedie.' '.measuring_units_string($lignes[$i]->volume_units,"volume").'</td>';
print '<td align="center">'.$lignes[$i]->volume*$lignes[$i]->qty_shipped.' '.measuring_units_string($lignes[$i]->volume_units,"volume").'</td>';
// Entrepot source
if ($conf->stock->enabled)
{
$entrepot = new Entrepot($db);
$entrepot->fetch($expedition->entrepot_id);
$entrepot->fetch($lignes[$i]->entrepot_id);
print '<td align="left">'.$entrepot->getNomUrl(1).'</td>';
}
@ -664,20 +675,20 @@ else
$somethingshown=$html->show_documents('expedition',$expeditionref,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf);
if ($genallowed && ! $somethingshown) $somethingshown=1;
/*
* Autres expeditions
*/
$sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande";
$sql .= " , ed.qty as qty_livre, e.ref, ed.fk_expedition as expedition_id";
$sql .= ",".$db->pdate("e.date_expedition")." as date_expedition";
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
$sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e";
$sql .= " WHERE cd.fk_commande = ".$expedition->commande_id;
$sql .= " AND e.rowid <> ".$expedition->id;
$sql .= " AND cd.rowid = ed.fk_commande_ligne";
$sql .= " AND ed.fk_expedition = e.rowid";
$sql .= " ORDER BY cd.fk_product";
$sql = "SELECT obj.fk_product, obj.description, obj.rowid, obj.qty as qty_asking";
$sql.= ", ed.qty as qty_shipped, ed.fk_expedition as expedition_id";
$sql.= ", e.ref, ".$db->pdate("e.date_expedition")." as date_expedition";
$sql.= " FROM ".MAIN_DB_PREFIX.$expedition->origin."det as obj";
$sql.= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e";
$sql.= " WHERE obj.fk_".$expedition->origin." = ".$expedition->origin_id;
$sql.= " AND e.rowid <> ".$expedition->id;
$sql.= " AND obj.rowid = ed.fk_origin_line";
$sql.= " AND ed.fk_expedition = e.rowid";
$sql.= " ORDER BY obj.fk_product";
$resql = $db->query($sql);
if ($resql)
@ -719,7 +730,7 @@ else
{
print "<td>".nl2br(dolibarr_trunc($objp->description,24))."</td>\n";
}
print '<td align="center">'.$objp->qty_livre.'</td>';
print '<td align="center">'.$objp->qty_shipped.'</td>';
print '<td align="center" nowrap="nowrap">'.dolibarr_print_date($objp->date_expedition).'</td>';
print '</tr>';
$i++;

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2008 Regis Houssin <regis@dolibarr.fr>
*
* 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
@ -50,19 +50,26 @@ print "</form></table><br />\n";
/*
* Expeditions à valider
*/
$sql = "SELECT e.rowid, e.ref, s.nom, s.rowid as socid, c.ref as commande_ref, c.rowid as commande_id";
if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX."expedition as e, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE e.fk_commande = c.rowid AND c.fk_soc = s.rowid AND e.fk_statut = 0";
$clause = " WHERE ";
$sql = "SELECT e.rowid, e.ref";
$sql.= ", s.nom, s.rowid as socid";
$sql.= ", c.ref as commande_ref, c.rowid as commande_id";
$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";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
if (!$user->rights->commercial->client->voir && !$socid)
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
$sql.= $clause." sc.fk_user = " .$user->id;
$clause = " AND ";
}
$sql.= $clause." e.fk_statut = 0";
if ($socid)
{
$sql .= " AND c.fk_soc = ".$socid;
}
if (!$user->rights->commercial->client->voir && !$socid) //restriction
{
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
}
$resql=$db->query($sql);
if ($resql)
{
@ -173,39 +180,48 @@ if ( $resql )
/*
* Expeditions à valider
*/
$sql = "SELECT e.rowid, e.ref, s.nom, s.rowid as socid, c.ref as commande_ref, c.rowid as commande_id";
if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."expedition as e, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE e.fk_commande = c.rowid AND c.fk_soc = s.rowid AND e.fk_statut = 1";
$clause = " WHERE ";
$sql = "SELECT e.rowid, e.ref";
$sql.= ", s.nom, s.rowid as socid";
$sql.= ", c.ref as commande_ref, c.rowid as commande_id";
$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";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
if (!$user->rights->commercial->client->voir && !$socid)
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
$sql.= $clause." sc.fk_user = " .$user->id;
$clause = " AND ";
}
$sql.= $clause." e.fk_statut = 1";
if ($socid) $sql .= " AND c.fk_soc = ".$socid;
if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
$sql .= " ORDER BY e.date_expedition DESC";
$sql .= $db->plimit(5, 0);
$sql.= " ORDER BY e.date_expedition DESC";
$sql.= $db->plimit(5, 0);
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
if ($num)
{
$i = 0;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="3">'.$langs->trans("LastSendings",$num).'</td></tr>';
$var = True;
while ($i < $num)
{
$i = 0;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="3">'.$langs->trans("LastSendings",$max).'</td></tr>';
$var = True;
while ($i < $num)
{
$var=!$var;
$obj = $db->fetch_object($resql);
print "<tr $bc[$var]><td width=\"20%\"><a href=\"fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowSending"),"sending").' ';
print $obj->ref.'</a></td>';
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
print '<td><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$obj->commande_id.'">'.img_object($langs->trans("ShowOrder"),"order").' '.$obj->commande_ref.'</a></td></tr>';
$i++;
}
print "</table><br>";
$var=!$var;
$obj = $db->fetch_object($resql);
print "<tr $bc[$var]><td width=\"20%\"><a href=\"fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowSending"),"sending").' ';
print $obj->ref.'</a></td>';
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
print '<td><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$obj->commande_id.'">'.img_object($langs->trans("ShowOrder"),"order").' '.$obj->commande_ref.'</a></td></tr>';
$i++;
}
print "</table><br>";
}
$db->free($resql);
}

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2008 Regis Houssin <regis@dolibarr.fr>
*
* 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
@ -31,6 +31,8 @@ require("./pre.inc.php");
if (!$user->rights->expedition->lire) accessforbidden();
$langs->load('companies');
// Sécurité accés client
if ($user->societe_id > 0)
{
@ -55,42 +57,51 @@ $offset = $limit * $_GET["page"] ;
/******************************************************************************/
llxHeader('',$langs->trans('ListOfSendings'),'ch-expedition.html');
llxHeader('',$langs->trans('ListOfSendings'));
$sql = "SELECT e.rowid, e.ref,".$db->pdate("e.date_expedition")." as date_expedition, e.fk_statut, s.nom as socname, s.rowid as socid, c.ref as comref, c.rowid as comid";
if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."commande as c";
if ($socid) $sql.=", ".MAIN_DB_PREFIX."commande as c";
if ($user->rights->commercial->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON c.rowid = e.fk_commande";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = c.fk_soc";
$sql_add = " WHERE ";
$clause = " WHERE ";
$sql = "SELECT e.rowid, e.ref,".$db->pdate("e.date_expedition")." as date_expedition, e.fk_statut";
$sql.= ", s.nom as socname, s.rowid as socid";
$sql.= ", ori.ref as oriref, ori.rowid as oriid";
$sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
if ($conf->commande->enabled)
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."co_exp as ce ON e.rowid = ce.fk_expedition";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as ori ON ce.fk_commande = ori.rowid";
}
else
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."pr_exp as pe ON e.rowid = pe.fk_expedition";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."propal as ori ON pe.fk_commande = ori.rowid";
}
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
if (!$user->rights->commercial->client->voir && !$socid)
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
$sql.= $clause." sc.fk_user = " .$user->id;
$clause = " AND ";
}
if ($socid)
{
$sql.= $sql_add . " e.fk_commande = c.rowid AND c.fk_soc = ".$socid;
$sql_add = " AND ";
$sql.= $clause." e.fk_soc = ".$socid;
$clause = " AND ";
}
if ($_POST["sf_ref"])
{
$sql.= $sql_add . " e.ref like '%".addslashes($_POST["sf_ref"])."%'";
$sql_add = " AND ";
}
if (!$user->rights->commercial->client->voir && !$socid) //restriction
{
$sql .= $sql_add . " e.fk_commande = c.rowid AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
$sql.= $clause." e.ref like '%".addslashes($_POST["sf_ref"])."%'";
$clause = " AND ";
}
$expedition = new Expedition($db);
$sql .= " ORDER BY $sortfield $sortorder";
$sql .= $db->plimit($limit + 1,$offset);
$sql.= " ORDER BY $sortfield $sortorder";
$sql.= $db->plimit($limit + 1,$offset);
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$expedition = new Expedition($db);
print_barre_liste($langs->trans('ListOfSendings'), $_GET["page"], "liste.php","&amp;socid=$socid",$sortfield,$sortorder,'',$num);
$i = 0;
@ -99,50 +110,64 @@ if ($resql)
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("Ref"),"liste.php","e.ref","","&amp;socid=$socid",'width="15%"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Company"),"liste.php","s.nom", "", "&amp;socid=$socid",'width="25%" align="left"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Order"),"liste.php","c.ref", "", "&amp;socid=$socid",'width="25%" align="left"',$sortfield,$sortorder);
if ($conf->commande->enabled)
{
print_liste_field_titre($langs->trans("Order"),"liste.php","ori.ref", "", "&amp;socid=$socid",'width="25%" align="left"',$sortfield,$sortorder);
}
else
{
print_liste_field_titre($langs->trans("Proposal"),"liste.php","ori.ref", "", "&amp;socid=$socid",'width="25%" align="left"',$sortfield,$sortorder);
}
print_liste_field_titre($langs->trans("Date"),"liste.php","e.date_expedition","","&amp;socid=$socid", 'width="25%" align="right" colspan="2"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Status"),"liste.php","e.fk_statut","","&amp;socid=$socid",'width="10%" align="center"',$sortfield,$sortorder);
print "</tr>\n";
$var=True;
while ($i < min($num,$limit))
{
$objp = $db->fetch_object($resql);
$var=!$var;
print "<tr $bc[$var]>";
print "<td><a href=\"fiche.php?id=".$objp->rowid."\">".img_object($langs->trans("ShowSending"),"sending").'</a>&nbsp;';
print "<a href=\"fiche.php?id=".$objp->rowid."\">".$objp->ref."</a></td>\n";
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->socid.'">'.$objp->socname.'</a></td>';
if ($conf->commande->enabled)
{
$objp = $db->fetch_object($resql);
$var=!$var;
print "<tr $bc[$var]>";
print "<td><a href=\"fiche.php?id=".$objp->rowid."\">".img_object($langs->trans("ShowSending"),"sending").'</a>&nbsp;';
print "<a href=\"fiche.php?id=".$objp->rowid."\">".$objp->ref."</a></td>\n";
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->socid.'">'.$objp->socname.'</a></td>';
print '<td><a href="'.DOL_URL_ROOT.'/expedition/commande.php?id='.$objp->comid.'">'.$objp->comref.'</a></td>';
$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">'.$expedition->statuts[$objp->fk_statut].'</td>';
print "</tr>\n";
$i++;
print '<td><a href="'.DOL_URL_ROOT.'/expedition/commande.php?id='.$objp->oriid.'">'.$objp->oriref.'</a></td>';
}
else
{
print '<td><a href="'.DOL_URL_ROOT.'/expedition/propal.php?propalid='.$objp->oriid.'">'.$objp->oriref.'</a></td>';
}
$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">'.$expedition->statuts[$objp->fk_statut].'</td>';
print "</tr>\n";
$i++;
}
print "</table>";
$db->free($resql);

View File

@ -21,7 +21,7 @@
/**
\defgroup expedition Module expedition
\brief Module pour g<EFBFBD>rer les expeditions de produits
\brief Module pour gerer les expeditions de produits
*/
/**
@ -42,7 +42,7 @@ class modExpedition extends DolibarrModules
/**
* \brief Constructeur. Definit les noms, constantes et boites
* \param DB handler d'acc<EFBFBD>s base
* \param DB handler d'acces base
*/
function modExpedition($DB)
{
@ -51,7 +51,7 @@ class modExpedition extends DolibarrModules
$this->family = "crm";
$this->name = "Expedition";
$this->description = "Gestion des exp<EFBFBD>ditions";
$this->description = "Gestion des expeditions";
$this->revision = explode(' ','$Revision$');
$this->version = $this->revision[1];
$this->const_name = 'MAIN_MODULE_EXPEDITION';
@ -64,8 +64,8 @@ class modExpedition extends DolibarrModules
// Config pages
$this->config_page_url = array("confexped.php");
// D<EFBFBD>pendances
$this->depends = array();
// Dependances
$this->depends = array("modPropale");
$this->requiredby = array();
// Constantes
@ -73,13 +73,13 @@ class modExpedition extends DolibarrModules
$this->const[0][0] = "LIVRAISON_ADDON_PDF";
$this->const[0][1] = "chaine";
$this->const[0][2] = "typhon";
$this->const[0][3] = 'Nom du gestionnaire de g<EFBFBD>n<EFBFBD>ration des commandes en PDF';
$this->const[0][3] = 'Nom du gestionnaire de generation des commandes en PDF';
$this->const[0][4] = 0;
$this->const[1][0] = "LIVRAISON_ADDON";
$this->const[1][1] = "chaine";
$this->const[1][2] = "mod_livraison_jade";
$this->const[1][3] = 'Nom du gestionnaire de num<EFBFBD>rotation des bons de livraison';
$this->const[1][3] = 'Nom du gestionnaire de numerotation des bons de livraison';
$this->const[1][4] = 0;
// Boxes
@ -99,7 +99,7 @@ class modExpedition extends DolibarrModules
$r++;
$this->rights[$r][0] = 102;
$this->rights[$r][1] = 'Cr<EFBFBD>er modifier les expeditions';
$this->rights[$r][1] = 'Creer modifier les expeditions';
$this->rights[$r][2] = 'w';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'creer';
@ -128,7 +128,7 @@ class modExpedition extends DolibarrModules
$r++;
$this->rights[$r][0] = 1102;
$this->rights[$r][1] = 'Cr<EFBFBD>er modifier les bons de livraison';
$this->rights[$r][1] = 'Creer modifier les bons de livraison';
$this->rights[$r][2] = 'w';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'livraison';
@ -154,8 +154,8 @@ class modExpedition extends DolibarrModules
/**
* \brief Fonction appel<EFBFBD>e lors de l'activation du module. Ins<EFBFBD>re en base les constantes, boites, permissions du module.
* D<EFBFBD>finit <EFBFBD>galement les r<EFBFBD>pertoires de donn<EFBFBD>es <EFBFBD> cr<EFBFBD>er pour ce module.
* \brief Fonction appelee lors de l'activation du module. Insere en base les constantes, boites, permissions du module.
* Definit egalement les repertoires de donnees a creer pour ce module.
*/
function init()
{
@ -171,7 +171,7 @@ class modExpedition extends DolibarrModules
}
/**
* \brief Fonction appel<EFBFBD>e lors de la d<EFBFBD>sactivation d'un module.
* \brief Fonction appelee lors de la desactivation d'un module.
* Supprime de la base les constantes, boites et permissions du module.
*/
function remove()

View File

@ -22,7 +22,7 @@
*/
/** \defgroup propale Module propale
\brief Module pour g<EFBFBD>rer la tenue de propositions commerciales
\brief Module pour gerer la tenue de propositions commerciales
*/
/**
@ -43,7 +43,7 @@ class modPropale extends DolibarrModules
/**
* \brief Constructeur. Definit les noms, constantes et boites
* \param DB handler d'acc<EFBFBD>s base
* \param DB handler d'acces base
*/
function modPropale($DB)
{
@ -64,7 +64,7 @@ class modPropale extends DolibarrModules
// Dir
$this->dirs = array();
// D<EFBFBD>pendances
// Dependances
$this->depends = array("modSociete","modCommercial");
$this->config_page_url = array("propale.php");
@ -74,13 +74,13 @@ class modPropale extends DolibarrModules
$this->const[0][0] = "PROPALE_ADDON_PDF";
$this->const[0][1] = "chaine";
$this->const[0][2] = "azur";
$this->const[0][3] = 'Nom du gestionnaire de g<EFBFBD>n<EFBFBD>ration des propales en PDF';
$this->const[0][3] = 'Nom du gestionnaire de generation des propales en PDF';
$this->const[0][4] = 0;
$this->const[1][0] = "PROPALE_ADDON";
$this->const[1][1] = "chaine";
$this->const[1][2] = "mod_propale_marbre";
$this->const[1][3] = 'Nom du gestionnaire de num<EFBFBD>rotation des propales';
$this->const[1][3] = 'Nom du gestionnaire de numerotation des propales';
$this->const[1][4] = 0;
// Boxes
@ -93,54 +93,54 @@ class modPropale extends DolibarrModules
$this->rights[1][0] = 21; // id de la permission
$this->rights[1][1] = 'Lire les propositions commerciales'; // libelle de la permission
$this->rights[1][2] = 'r'; // type de la permission (d<EFBFBD>pr<EFBFBD>ci<EFBFBD> <20> ce jour)
$this->rights[1][3] = 1; // La permission est-elle une permission par d<EFBFBD>faut
$this->rights[1][2] = 'r'; // type de la permission (deprecie a ce jour)
$this->rights[1][3] = 1; // La permission est-elle une permission par defaut
$this->rights[1][4] = 'lire';
$this->rights[2][0] = 22; // id de la permission
$this->rights[2][1] = 'Cr<EFBFBD>er/modifier les propositions commerciales'; // libelle de la permission
$this->rights[2][2] = 'w'; // type de la permission (d<EFBFBD>pr<EFBFBD>ci<EFBFBD> <20> ce jour)
$this->rights[2][3] = 0; // La permission est-elle une permission par d<EFBFBD>faut
$this->rights[2][1] = 'Creer/modifier les propositions commerciales'; // libelle de la permission
$this->rights[2][2] = 'w'; // type de la permission (deprecie a ce jour)
$this->rights[2][3] = 0; // La permission est-elle une permission par defaut
$this->rights[2][4] = 'creer';
$this->rights[3][0] = 24; // id de la permission
$this->rights[3][1] = 'Valider les propositions commerciales'; // libelle de la permission
$this->rights[3][2] = 'd'; // type de la permission (d<EFBFBD>pr<EFBFBD>ci<EFBFBD> <20> ce jour)
$this->rights[3][3] = 0; // La permission est-elle une permission par d<EFBFBD>faut
$this->rights[3][2] = 'd'; // type de la permission (deprecie a ce jour)
$this->rights[3][3] = 0; // La permission est-elle une permission par defaut
$this->rights[3][4] = 'valider';
$this->rights[4][0] = 25; // id de la permission
$this->rights[4][1] = 'Envoyer les propositions commerciales aux clients'; // libelle de la permission
$this->rights[4][2] = 'd'; // type de la permission (d<EFBFBD>pr<EFBFBD>ci<EFBFBD> <20> ce jour)
$this->rights[4][3] = 0; // La permission est-elle une permission par d<EFBFBD>faut
$this->rights[4][2] = 'd'; // type de la permission (deprecie a ce jour)
$this->rights[4][3] = 0; // La permission est-elle une permission par defaut
$this->rights[4][4] = 'envoyer';
$this->rights[5][0] = 26; // id de la permission
$this->rights[5][1] = 'Cl<EFBFBD>turer les propositions commerciales'; // libelle de la permission
$this->rights[5][2] = 'd'; // type de la permission (d<EFBFBD>pr<EFBFBD>ci<EFBFBD> <20> ce jour)
$this->rights[5][3] = 0; // La permission est-elle une permission par d<EFBFBD>faut
$this->rights[5][1] = 'Cloturer les propositions commerciales'; // libelle de la permission
$this->rights[5][2] = 'd'; // type de la permission (deprecie a ce jour)
$this->rights[5][3] = 0; // La permission est-elle une permission par defaut
$this->rights[5][4] = 'cloturer';
$this->rights[6][0] = 27; // id de la permission
$this->rights[6][1] = 'Supprimer les propositions commerciales'; // libelle de la permission
$this->rights[6][2] = 'd'; // type de la permission (d<EFBFBD>pr<EFBFBD>ci<EFBFBD> <20> ce jour)
$this->rights[6][3] = 0; // La permission est-elle une permission par d<EFBFBD>faut
$this->rights[6][2] = 'd'; // type de la permission (deprecie a ce jour)
$this->rights[6][3] = 0; // La permission est-elle une permission par defaut
$this->rights[6][4] = 'supprimer';
}
/**
* \brief Fonction appel<EFBFBD>e lors de l'activation du module. Ins<EFBFBD>re en base les constantes, boites, permissions du module.
* D<EFBFBD>finit <EFBFBD>galement les r<EFBFBD>pertoires de donn<EFBFBD>es <EFBFBD> cr<EFBFBD>er pour ce module.
* \brief Fonction appelee lors de l'activation du module. Insere en base les constantes, boites, permissions du module.
* Definit egalement les repertoires de donnees a creer pour ce module.
*/
function init()
{
global $conf;
// Permissions et valeurs par d<EFBFBD>faut
// Permissions et valeurs par defaut
$this->remove();
// R<EFBFBD>pertoires
// Repertoires
$this->dirs[0] = $conf->propal->dir_output;
$this->dirs[1] = $conf->propal->dir_temp;
@ -154,7 +154,7 @@ class modPropale extends DolibarrModules
}
/**
* \brief Fonction appel<EFBFBD>e lors de la d<EFBFBD>sactivation d'un module.
* \brief Fonction appelee lors de la desactivation d'un module.
* Supprime de la base les constantes, boites et permissions du module.
*/
function remove()

View File

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2008 Regis Houssin <regis@dolibarr.fr>
*
* 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
@ -133,27 +134,27 @@ if (isset($_POST['action']) && $_POST['action'] == 'upgrade')
***************************************************************************************/
if (! $error)
{
$db->begin();
// Chaque action de migration doit renvoyer une ligne sur 4 colonnes avec
// dans la 1ere colonne, la description de l'action a faire
// dans la 4eme colonne, le texte 'OK' si fait ou 'AlreadyDone' si rien n'est fait ou 'Error'
// Chaque action de migration doit renvoyer une ligne sur 4 colonnes avec
// dans la 1ere colonne, la description de l'action a faire
// dans la 4eme colonne, le texte 'OK' si fait ou 'AlreadyDone' si rien n'est fait ou 'Error'
// Script pour V2 -> V2.1
migrate_paiements($db,$langs,$conf);
migrate_paiements($db,$langs,$conf);
migrate_contracts_det($db,$langs,$conf);
migrate_contracts_det($db,$langs,$conf);
migrate_contracts_date1($db,$langs,$conf);
migrate_contracts_date1($db,$langs,$conf);
migrate_contracts_date2($db,$langs,$conf);
migrate_contracts_date2($db,$langs,$conf);
migrate_contracts_date3($db,$langs,$conf);
migrate_contracts_date3($db,$langs,$conf);
migrate_contracts_open($db,$langs,$conf);
migrate_contracts_open($db,$langs,$conf);
migrate_modeles($db,$langs,$conf);
migrate_modeles($db,$langs,$conf);
migrate_price_propal($db,$langs,$conf);
@ -163,7 +164,7 @@ if (isset($_POST['action']) && $_POST['action'] == 'upgrade')
migrate_price_contrat($db,$langs,$conf);
migrate_paiementfourn_facturefourn($db,$langs,$conf);
migrate_paiementfourn_facturefourn($db,$langs,$conf);
// Script pour V2.1 -> V2.2
migrate_paiements_orphelins_1($db,$langs,$conf);
@ -173,11 +174,14 @@ if (isset($_POST['action']) && $_POST['action'] == 'upgrade')
migrate_links_transfert($db,$langs,$conf);
migrate_delete_old_files($db,$langs,$conf);
// Script pour V2.2 -> V2.4
migrate_commande_expedition($db,$langs,$conf);
// On commit dans tous les cas.
// La procedure etant concue pour pouvoir passer plusieurs fois quelquesoit la situation.
$db->commit();
$db->close();
// On commit dans tous les cas.
// La procedure etant concue pour pouvoir passer plusieurs fois quelquesoit la situation.
$db->commit();
$db->close();
}
@ -1454,6 +1458,75 @@ function migrate_module_menus($db,$langs,$conf)
}
}
/*
* Correspondance des expeditions et des commandes clients dans la table llx_co_exp
*/
function migrate_commande_expedition($db,$langs,$conf)
{
if ($conf->expedition->enabled)
{
print '<tr><td colspan="4">';
print '<br>';
print '<b>'.$langs->trans('MigrationShipmentOrderMatching')."</b><br>\n";
$result = $db->DDLDescTable(MAIN_DB_PREFIX."expedition","fk_commande");
$obj = $db->fetch_object($result);
if ($obj)
{
$sql = "SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX."expedition as e";
$resql = $db->query($sql);
if ($resql)
{
$i = 0;
$error = 0;
$num = $db->num_rows($resql);
if ($num)
{
$db->begin();
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."co_exp (fk_expedition,fk_commande)";
$sql.= " VALUES (".$obj->rowid.",".$obj->fk_commande.")";
$resql2=$db->query($sql);
if (!$resql2)
{
$error++;
dolibarr_print_error($db);
}
print ". ";
$i++;
}
if ($error == 0)
{
$db->commit();
$sql = "ALTER TABLE ".MAIN_DB_PREFIX."expedition DROP COLUMN fk_commande";
$db->query($sql);
}
else
{
$db->rollback();
}
}
}
else
{
dolibarr_print_error($db);
}
}
else
{
print $langs->trans('AlreadyDone')."<br>\n";
}
print '</td></tr>';
}
}
/* A faire egalement: Modif statut paye et fk_facture des factures payés completement
On recherche facture incorrecte:

View File

@ -43,11 +43,11 @@ function propal_prepare_head($propal)
$head[$h][2] = 'comm';
$h++;
if (!$conf->commande->enabled && (($conf->expedition->enabled && $user->rights->expedition->lire)
|| ($conf->livraison->enabled && $user->rights->expedition->livraison->lire)))
if ((!$conf->commande->enabled && (($conf->expedition->enabled && $user->rights->expedition->lire)
|| ($conf->livraison->enabled && $user->rights->expedition->livraison->lire))))
{
$langs->load("sendings");
$head[$h][0] = DOL_URL_ROOT.'/expedition/propal.php?id='.$propal->id;
$head[$h][0] = DOL_URL_ROOT.'/expedition/propal.php?propalid='.$propal->id;
if ($conf->expedition->enabled) $text=$langs->trans("Sendings");
if ($conf->livraison->enabled) $text.='/'.$langs->trans("Receivings");
$head[$h][1] = $text;

View File

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2008 Regis Houssin <regis@dolibarr.fr>
*
* 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
@ -264,25 +265,27 @@ class Entrepot
*/
function list_array()
{
$liste = array();
$liste = array();
$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."entrepot WHERE statut = 1";
$sql = "SELECT rowid, label";
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot";
$sql.= " WHERE statut = 1";
$result = $this->db->query($sql) ;
$i = 0;
$num = $this->db->num_rows();
if ( $result )
{
while ($i < $num)
$result = $this->db->query($sql) ;
$i = 0;
$num = $this->db->num_rows();
if ( $result )
{
while ($i < $num)
{
$row = $this->db->fetch_row($i);
$liste[$row[0]] = $row[1];
$i++;
}
$this->db->free();
}
return $liste;
$this->db->free();
}
return $liste;
}
/**
@ -295,31 +298,30 @@ class Entrepot
$sql = "SELECT sum(ps.reel)";
$sql .= " FROM llx_product_stock as ps";
if ($conf->categorie->enabled && !$user->rights->categorie->voir)
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cp.fk_categorie = c.rowid";
}
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cp.fk_categorie = c.rowid";
}
$sql .= " WHERE ps.fk_entrepot = ".$this->id;
if ($conf->categorie->enabled && !$user->rights->categorie->voir)
{
$sql.= ' AND IFNULL(c.visible,1)=1';
}
{
$sql.= ' AND IFNULL(c.visible,1)=1';
}
$result = $this->db->query($sql) ;
if ( $result )
{
$row = $this->db->fetch_row(0);
return $row[0];
$this->db->free();
}
{
$row = $this->db->fetch_row(0);
return $row[0];
$this->db->free();
}
else
{
return 0;
}
{
return 0;
}
}
/**
* \brief Retourne le libellé du statut d'un entrepot (ouvert, ferme)

View File

@ -41,3 +41,48 @@ alter table llx_menu add column tms timestamp;
update llx_menu set url='/comm/prospect/prospects.php?leftmenu=prospects' where rowid=702 and url='/contact/index.php?leftmenu=prospects&type=p';
ALTER TABLE llx_menu ADD UNIQUE INDEX idx_menu_uk_menu (menu_handler, fk_menu, url);
-- Drop unused table
drop table if exists llx_so_gr;
-- Modification expedition
create table llx_co_exp
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_commande integer NOT NULL,
fk_expedition integer NOT NULL,
key(fk_commande),
key(fk_expedition)
)type=innodb;
-- V4 ALTER TABLE llx_expedition DROP INDEX fk_expedition_methode;
-- V4 ALTER TABLE llx_expedition DROP INDEX fk_commande;
-- V4 ALTER TABLE llx_expedition DROP INDEX ref;
-- V4 ALTER TABLE llx_expeditiondet DROP INDEX fk_expedition;
-- V4 ALTER TABLE llx_expeditiondet DROP INDEX fk_commande_ligne;
alter table llx_expedition add column fk_soc integer NOT NULL after ref;
alter table llx_expedition add column fk_adresse_livraison integer after date_expedition;
-- V4.1 UPDATE llx_expedition as e SET e.fk_soc = (SELECT c.fk_soc FROM llx_commande AS c WHERE e.fk_commande = c.rowid);
-- V4.1 UPDATE llx_expedition as e SET e.fk_adresse_livraison = (SELECT c.fk_adresse_livraison FROM llx_commande AS c WHERE e.fk_commande = c.rowid);
ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_soc (fk_soc);
ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_user_author (fk_user_author);
ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_user_valid (fk_user_valid);
ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_expedition_methode (fk_expedition_methode);
-- V4 ALTER TABLE llx_expedition ADD CONSTRAINT fk_expedition_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
-- V4 ALTER TABLE llx_expedition ADD CONSTRAINT fk_expedition_fk_user_author FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid);
-- V4 ALTER TABLE llx_expedition ADD CONSTRAINT fk_expedition_fk_user_valid FOREIGN KEY (fk_user_valid) REFERENCES llx_user (rowid);
-- V4 ALTER TABLE llx_expedition ADD CONSTRAINT fk_expedition_fk_expedition_methode FOREIGN KEY (fk_expedition_methode) REFERENCES llx_expedition_methode (rowid);
ALTER TABLE llx_expedition ADD UNIQUE INDEX idx_expedition_uk_ref (ref);
ALTER TABLE llx_expeditiondet CHANGE fk_commande_ligne fk_origin_line integer;
ALTER TABLE llx_expeditiondet ADD COLUMN fk_entrepot integer after fk_origin_line;
ALTER TABLE llx_expeditiondet ADD COLUMN rang integer DEFAULT 0 after qty;
-- V4.1 UPDATE llx_expeditiondet as ed SET ed.fk_entrepot = (SELECT e.fk_entrepot FROM llx_expedition AS e WHERE ed.fk_expedition = e.rowid);
ALTER TABLE llx_expedition DROP COLUMN fk_entrepot;
ALTER TABLE llx_expeditiondet ADD INDEX idx_expeditiondet_fk_expedition (fk_expedition);
ALTER TABLE llx_expeditiondet ADD INDEX idx_expeditiondet_fk_entrepot (fk_entrepot);
-- V4 ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_expedition FOREIGN KEY (fk_expedition) REFERENCES llx_expedition (rowid);
-- V4 ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_entrepot FOREIGN KEY (fk_entrepot) REFERENCES llx_entrepot (rowid);

View File

@ -0,0 +1,30 @@
-- ===================================================================
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
--
-- 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$
-- ===================================================================
create table llx_co_exp
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_commande integer NOT NULL,
fk_expedition integer NOT NULL,
key(fk_commande),
key(fk_expedition)
)type=innodb;

View File

@ -0,0 +1,33 @@
-- ===================================================================
-- Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
--
-- 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$
-- ===================================================================
ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_soc (fk_soc);
ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_user_author (fk_user_author);
ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_user_valid (fk_user_valid);
ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_expedition_methode (fk_expedition_methode);
ALTER TABLE llx_expedition ADD CONSTRAINT fk_expedition_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
ALTER TABLE llx_expedition ADD CONSTRAINT fk_expedition_fk_user_author FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid);
ALTER TABLE llx_expedition ADD CONSTRAINT fk_expedition_fk_user_valid FOREIGN KEY (fk_user_valid) REFERENCES llx_user (rowid);
ALTER TABLE llx_expedition ADD CONSTRAINT fk_expedition_fk_expedition_methode FOREIGN KEY (fk_expedition_methode) REFERENCES llx_expedition_methode (rowid);
ALTER TABLE llx_expedition ADD UNIQUE INDEX idx_expedition_uk_ref (ref);

View File

@ -1,5 +1,6 @@
-- ===================================================================
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
--
-- 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
@ -23,19 +24,15 @@ create table llx_expedition
rowid integer AUTO_INCREMENT PRIMARY KEY,
tms timestamp,
ref varchar(30) NOT NULL,
fk_commande integer,
date_creation datetime, -- date de creation
date_valid datetime, -- date de validation
date_expedition date, -- date de l'expedition
fk_soc integer NOT NULL,
date_creation datetime, -- date de creation
fk_user_author integer, -- createur
date_valid datetime, -- date de validation
fk_user_valid integer, -- valideur
fk_entrepot integer,
date_expedition date, -- date de l'expedition
fk_adresse_livraison integer, -- adresse de livraison
fk_expedition_methode integer,
fk_statut smallint DEFAULT 0,
note text,
model_pdf varchar(50),
UNIQUE INDEX (ref),
key(fk_expedition_methode),
key(fk_commande)
model_pdf varchar(50)
)type=innodb;

View File

@ -0,0 +1,24 @@
-- ===================================================================
-- Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
--
-- 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$
-- ===================================================================
ALTER TABLE llx_expeditiondet ADD INDEX idx_expeditiondet_fk_expedition (fk_expedition);
ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_expedition FOREIGN KEY (fk_expedition) REFERENCES llx_expedition (rowid);

View File

@ -1,5 +1,6 @@
-- ===================================================================
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
--
-- 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
@ -22,9 +23,8 @@ create table llx_expeditiondet
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_expedition integer NOT NULL,
fk_commande_ligne integer NOT NULL,
qty real, -- quantité
key(fk_expedition),
key(fk_commande_ligne)
fk_origin_line integer, -- Correspondance de la ligne avec le document d'origine (propal, commande)
fk_entrepot integer, -- Entrepot de depart du produit
qty real, -- Quantity
rang integer DEFAULT 0
)type=innodb;

View File

@ -1,5 +1,6 @@
-- ===================================================================
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
--
-- 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
@ -25,18 +26,18 @@ create table llx_livraison
fk_commande integer DEFAULT 0, -- commande auquel est rattache le bon de livraison
fk_expedition integer, -- expedition auquel est rattache le bon de livraison
ref varchar(30) NOT NULL, -- delivery number
date_creation datetime, -- date de creation
date_valid datetime, -- date de validation
date_creation datetime, -- date de creation
fk_user_author integer, -- createur du bon de livraison
date_valid datetime, -- date de validation
fk_user_valid integer, -- valideur du bon de livraison
date_livraison date default NULL, -- date de livraison
fk_adresse_livraison integer, -- adresse de livraison
fk_statut smallint default 0,
total_ht real default 0,
total_ttc real default 0,
note text,
note_public text,
model_pdf varchar(50),
date_livraison date default NULL,
fk_adresse_livraison integer, -- adresse de livraison
UNIQUE INDEX (ref),
key(fk_commande)

View File

@ -1,5 +1,6 @@
-- ===================================================================
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
--
-- 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