Fix: Creation of invoice lines restored with old option PRODUCT_SHOW_WHEN_CREATE

This commit is contained in:
Laurent Destailleur 2009-04-21 19:24:12 +00:00
parent 35ba67c3fe
commit e04b914353
4 changed files with 43 additions and 82 deletions

View File

@ -102,21 +102,25 @@ while ($i < GEN_NUMBER_FACTURE && $result >= 0)
$facture->cond_reglement_id = 3; $facture->cond_reglement_id = 3;
$facture->mode_reglement_id = 3; $facture->mode_reglement_id = 3;
$nbp = rand(2, 5);
$xnbp = 0;
while ($xnbp < $nbp)
{
// \TODO Utiliser addline plutot que add_product
$prodid = rand(1, $num_prods);
$facture->add_product($prodids[$prodid], rand(1,5), 0);
$xnbp++;
}
$result=$facture->create($user); $result=$facture->create($user);
if ($result >= 0) if ($result >= 0)
{ {
$result=$facture->set_valid($user,$socid); $result=$facture->set_valid($user,$socid);
if ($result) print " OK"; if ($result)
{
$nbp = rand(2, 5);
$xnbp = 0;
while ($xnbp < $nbp)
{
$prodid = rand(1, $num_prods);
$product=new Product($db);
$product->fetch($prodids[$prodid]);
$result=$facture->addline($facid,$product->description,$product->price, rand(1,5), $product->tva_tx, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
$xnbp++;
}
print " OK";
}
else else
{ {
dol_print_error($db,$facture->error); dol_print_error($db,$facture->error);

View File

@ -627,20 +627,22 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
$facture->remise_absolue = $_POST['remise_absolue']; $facture->remise_absolue = $_POST['remise_absolue'];
$facture->remise_percent = $_POST['remise_percent']; $facture->remise_percent = $_POST['remise_percent'];
// If invoices lines already known // If some invoice's lines already known
if (! $_POST['propalid'] && ! $_POST['commandeid'] && ! $_POST['contratid']) if (! $_POST['propalid'] && ! $_POST['commandeid'] && ! $_POST['contratid'])
{ {
$facid = $facture->create($user);
for ($i = 1; $i <= $NBLINES; $i++) for ($i = 1; $i <= $NBLINES; $i++)
{ {
if ($_POST['idprod'.$i]) if ($_POST['idprod'.$i])
{ {
$product=new Product($db);
$product->fetch($_POST['idprod'.$i]);
$startday=dol_mktime(12, 0 , 0, $_POST['date_start'.$i.'month'], $_POST['date_start'.$i.'day'], $_POST['date_start'.$i.'year']); $startday=dol_mktime(12, 0 , 0, $_POST['date_start'.$i.'month'], $_POST['date_start'.$i.'day'], $_POST['date_start'.$i.'year']);
$endday=dol_mktime(12, 0 , 0, $_POST['date_end'.$i.'month'], $_POST['date_end'.$i.'day'], $_POST['date_end'.$i.'year']); $endday=dol_mktime(12, 0 , 0, $_POST['date_end'.$i.'month'], $_POST['date_end'.$i.'day'], $_POST['date_end'.$i.'year']);
$facture->add_product($_POST['idprod'.$i], $_POST['qty'.$i], $_POST['remise_percent'.$i], $startday, $endday); $result=$facture->addline($facid,$product->description,$product->price, $_POST['qty'.$i], $product->tva_tx, $_POST['idprod'.$i], $_POST['remise_percent'.$i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
} }
} }
$facid = $facture->create($user);
} }
else else
{ {
@ -652,7 +654,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
if ($facid > 0) if ($facid > 0)
{ {
$prop = New Propal($db); $prop = new Propal($db);
if ( $prop->fetch($_POST['propalid']) ) if ( $prop->fetch($_POST['propalid']) )
{ {
for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++)
@ -1733,13 +1735,16 @@ if ($_GET['action'] == 'create')
} }
else else
{ {
// Show deprecated optional form to add product line here
if ($conf->global->PRODUCT_SHOW_WHEN_CREATE) if ($conf->global->PRODUCT_SHOW_WHEN_CREATE)
{ {
print '<tr><td colspan="3">'; print '<tr><td colspan="3">';
// Zone de choix des produits prédéfinis à la création // Zone de choix des produits prédéfinis à la création
print '<table class="noborder">'; print '<table class="noborder" width="100%">';
print '<tr><td>'.$langs->trans('ProductsAndServices').'</td>'; print '<tr>';
print '<td>'.$langs->trans('ProductsAndServices').'</td>';
print '<td>'.$langs->trans('Qty').'</td>'; print '<td>'.$langs->trans('Qty').'</td>';
print '<td>'.$langs->trans('ReductionShort').'</td>'; print '<td>'.$langs->trans('ReductionShort').'</td>';
print '<td> &nbsp; &nbsp; </td>'; print '<td> &nbsp; &nbsp; </td>';
@ -3002,7 +3007,8 @@ else
print '<td>'; print '<td>';
print $html->select_type_of_lines(-1,'type',1); print $html->select_type_of_lines(-1,'type',1);
if ($conf->produit->enabled && $conf->service->enabled) print '<br>'; if (($conf->produit->enabled && $conf->service->enabled)
|| (empty($conf->produit->enabled) && empty($conf->service->enabled))) print '<br>';
// Editor wysiwyg // Editor wysiwyg
if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS)

View File

@ -245,6 +245,7 @@ class Facture extends CommonObject
/* /*
* Insert lines of invoices in database * Insert lines of invoices in database
*/ */
//dol_syslog("There is ".sizeof($this->lignes)." lines");
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{ {
$newinvoiceline=new FactureLigne($this->db); $newinvoiceline=new FactureLigne($this->db);
@ -1436,56 +1437,7 @@ class Facture extends CommonObject
/** /**
\brief Ajoute une ligne dans le tableau products * \brief Add an invoice line into database (linked to product/service or not)
\param idproduct Id du produit a ajouter
\param qty Quantit
\param remise_percent Remise relative effectuée sur le produit
\param date_start
\param date_end
\return void
\remarks $this->client doit etre charg
\TODO Remplacer les appels a cette fonction par generation objet Ligne
inséré dans tableau $this->products
*/
function add_product($idproduct, $qty, $remise_percent, $date_start='', $date_end='')
{
global $conf, $mysoc;
// Nettoyage parametres
if (! $qty) $qty = 1;
dol_syslog("Facture::add_product $idproduct, $qty, $remise_percent, $date_start, $date_end", LOG_DEBUG);
if ($idproduct > 0)
{
$prod=new Product($this->db);
$prod->fetch($idproduct);
$tva_tx = get_default_tva($mysoc,$this->client,$prod->tva_tx);
// multiprix
if($conf->global->PRODUIT_MULTIPRICES)
$price = $prod->multiprices[$this->client->price_level];
else
$price = $prod->price;
$line=new FactureLigne($this->db);
$line->rowid = $idproduct;
$line->fk_product = $idproduct;
$line->desc = $prod->description;
$line->qty = $qty;
$line->subprice = $price;
$line->remise_percent = $remise_percent;
$line->tva_tx = $tva_tx;
$line->product_type = $prod->type;
if ($date_start) { $line->date_start = $date_start; }
if ($date_end) { $line->date_end = $date_end; }
$this->products[]=$line;
}
}
/**
* \brief Ajoute une ligne de facture (associé à un produit/service prédéfini ou non
* \param facid Id de la facture * \param facid Id de la facture
* \param desc Description de la ligne * \param desc Description de la ligne
* \param pu_ht Prix unitaire HT * \param pu_ht Prix unitaire HT
@ -2837,7 +2789,7 @@ class FactureLigne
$this->fk_remise_except = $objp->fk_remise_except; $this->fk_remise_except = $objp->fk_remise_except;
$this->produit_id = $objp->fk_product; // Ne plus utiliser $this->produit_id = $objp->fk_product; // Ne plus utiliser
$this->fk_product = $objp->fk_product; $this->fk_product = $objp->fk_product;
$this->produc_type = $objp->product_type; $this->product_type = $objp->product_type;
$this->date_start = $objp->date_start; $this->date_start = $objp->date_start;
$this->date_end = $objp->date_end; $this->date_end = $objp->date_end;
$this->info_bits = $objp->info_bits; $this->info_bits = $objp->info_bits;
@ -2923,7 +2875,7 @@ class FactureLigne
$sql.= " ".price2num($this->remise_percent).","; $sql.= " ".price2num($this->remise_percent).",";
$sql.= " ".price2num($this->subprice).","; $sql.= " ".price2num($this->subprice).",";
$sql.= " ".price2num($this->price).","; $sql.= " ".price2num($this->price).",";
$sql.= " ".price2num($this->remise).","; $sql.= " ".($this->remise?price2num($this->remise):'0').","; // Deprecated
if ($this->fk_remise_except) $sql.= $this->fk_remise_except.","; if ($this->fk_remise_except) $sql.= $this->fk_remise_except.",";
else $sql.= 'null,'; else $sql.= 'null,';
if ($this->date_start) { $sql.= "'".$this->db->idate($this->date_start)."',"; } if ($this->date_start) { $sql.= "'".$this->db->idate($this->date_start)."',"; }

View File

@ -369,16 +369,15 @@ class Form
* \param htmlname Name of field in form * \param htmlname Name of field in form
* \param showempty Add an empty field * \param showempty Add an empty field
*/ */
function select_type_of_lines($selected='',$htmlname='type',$showempty=0) function select_type_of_lines($selected='',$htmlname='type',$showempty=0,$hidetext=0)
{ {
global $db,$langs,$user,$conf; global $db,$langs,$user,$conf;
$langs->load("trips");
// If product & services are enabled or both disabled. // If product & services are enabled or both disabled.
if (($conf->produit->enabled && $conf->service->enabled) if (($conf->produit->enabled && $conf->service->enabled)
|| (empty($conf->produit->enabled) && empty($conf->service->enabled))) || (empty($conf->produit->enabled) && empty($conf->service->enabled)))
{ {
print $langs->trans("Type").': '; if (empty($hidetext)) print $langs->trans("Type").': ';
print '<select class="flat" name="'.$htmlname.'">'; print '<select class="flat" name="'.$htmlname.'">';
if ($showempty) if ($showempty)
{ {