Fix: Creation of invoice lines restored with old option PRODUCT_SHOW_WHEN_CREATE
This commit is contained in:
parent
35ba67c3fe
commit
e04b914353
@ -50,7 +50,7 @@ define (GEN_NUMBER_FACTURE, 5);
|
||||
|
||||
$sql = "SELECT min(rowid) FROM ".MAIN_DB_PREFIX."user";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
if ($resql)
|
||||
{
|
||||
$row = $db->fetch_row($resql);
|
||||
$user = new User($db, $row[0]);
|
||||
@ -59,14 +59,14 @@ if ($resql)
|
||||
$socids = array();
|
||||
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
if ($resql)
|
||||
{
|
||||
$num_socs = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num_socs)
|
||||
{
|
||||
$i++;
|
||||
|
||||
|
||||
$row = $db->fetch_row($resql);
|
||||
$socids[$i] = $row[0];
|
||||
}
|
||||
@ -75,14 +75,14 @@ if ($resql)
|
||||
$prodids = array();
|
||||
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE envente=1";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
if ($resql)
|
||||
{
|
||||
$num_prods = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num_prods)
|
||||
{
|
||||
$i++;
|
||||
|
||||
|
||||
$row = $db->fetch_row($resql);
|
||||
$prodids[$i] = $row[0];
|
||||
}
|
||||
@ -96,27 +96,31 @@ while ($i < GEN_NUMBER_FACTURE && $result >= 0)
|
||||
$socid = rand(1, $num_socs);
|
||||
|
||||
print "Invoice ".$i." for socid ".$socid;
|
||||
|
||||
|
||||
$facture = new Facture($db, $socids[$socid]);
|
||||
$facture->date = time();
|
||||
$facture->cond_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);
|
||||
if ($result >= 0)
|
||||
{
|
||||
$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
|
||||
{
|
||||
dol_print_error($db,$facture->error);
|
||||
@ -126,7 +130,7 @@ while ($i < GEN_NUMBER_FACTURE && $result >= 0)
|
||||
{
|
||||
dol_print_error($db,$facture->error);
|
||||
}
|
||||
|
||||
|
||||
print "\n";
|
||||
}
|
||||
|
||||
|
||||
@ -627,20 +627,22 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
|
||||
$facture->remise_absolue = $_POST['remise_absolue'];
|
||||
$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'])
|
||||
{
|
||||
$facid = $facture->create($user);
|
||||
|
||||
for ($i = 1; $i <= $NBLINES; $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']);
|
||||
$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
|
||||
{
|
||||
@ -652,7 +654,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
|
||||
|
||||
if ($facid > 0)
|
||||
{
|
||||
$prop = New Propal($db);
|
||||
$prop = new Propal($db);
|
||||
if ( $prop->fetch($_POST['propalid']) )
|
||||
{
|
||||
for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++)
|
||||
@ -1733,13 +1735,16 @@ if ($_GET['action'] == 'create')
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// Show deprecated optional form to add product line here
|
||||
if ($conf->global->PRODUCT_SHOW_WHEN_CREATE)
|
||||
{
|
||||
print '<tr><td colspan="3">';
|
||||
|
||||
// Zone de choix des produits prédéfinis à la création
|
||||
print '<table class="noborder">';
|
||||
print '<tr><td>'.$langs->trans('ProductsAndServices').'</td>';
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr>';
|
||||
print '<td>'.$langs->trans('ProductsAndServices').'</td>';
|
||||
print '<td>'.$langs->trans('Qty').'</td>';
|
||||
print '<td>'.$langs->trans('ReductionShort').'</td>';
|
||||
print '<td> </td>';
|
||||
@ -3002,7 +3007,8 @@ else
|
||||
print '<td>';
|
||||
|
||||
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
|
||||
if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS)
|
||||
|
||||
@ -245,6 +245,7 @@ class Facture extends CommonObject
|
||||
/*
|
||||
* Insert lines of invoices in database
|
||||
*/
|
||||
//dol_syslog("There is ".sizeof($this->lignes)." lines");
|
||||
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
|
||||
{
|
||||
$newinvoiceline=new FactureLigne($this->db);
|
||||
@ -1436,56 +1437,7 @@ class Facture extends CommonObject
|
||||
|
||||
|
||||
/**
|
||||
\brief Ajoute une ligne dans le tableau products
|
||||
\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
|
||||
* \brief Add an invoice line into database (linked to product/service or not)
|
||||
* \param facid Id de la facture
|
||||
* \param desc Description de la ligne
|
||||
* \param pu_ht Prix unitaire HT
|
||||
@ -2837,7 +2789,7 @@ class FactureLigne
|
||||
$this->fk_remise_except = $objp->fk_remise_except;
|
||||
$this->produit_id = $objp->fk_product; // Ne plus utiliser
|
||||
$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_end = $objp->date_end;
|
||||
$this->info_bits = $objp->info_bits;
|
||||
@ -2923,7 +2875,7 @@ class FactureLigne
|
||||
$sql.= " ".price2num($this->remise_percent).",";
|
||||
$sql.= " ".price2num($this->subprice).",";
|
||||
$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.",";
|
||||
else $sql.= 'null,';
|
||||
if ($this->date_start) { $sql.= "'".$this->db->idate($this->date_start)."',"; }
|
||||
|
||||
@ -369,16 +369,15 @@ class Form
|
||||
* \param htmlname Name of field in form
|
||||
* \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;
|
||||
$langs->load("trips");
|
||||
|
||||
// If product & services are enabled or both disabled.
|
||||
if (($conf->produit->enabled && $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.'">';
|
||||
if ($showempty)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user