Add type in invoice lines
This commit is contained in:
parent
cdc6493ba5
commit
d930a0dd32
@ -835,7 +835,20 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
|
||||
*/
|
||||
if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && $user->rights->facture->creer)
|
||||
{
|
||||
if ($_POST['qty'] && (($_POST['pu']!='' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod']))
|
||||
$result=0;
|
||||
|
||||
if (empty($_POST['idprod']) && $_POST["type"] < 0)
|
||||
{
|
||||
$fac->error = $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")) ;
|
||||
$result = -1 ;
|
||||
}
|
||||
if (empty($_POST['idprod']) && empty($_POST["pu"]))
|
||||
{
|
||||
$fac->error = $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")) ;
|
||||
$result = -1 ;
|
||||
}
|
||||
|
||||
if ($result >= 0 && $_POST['qty'] && (($_POST['pu']!='' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod']))
|
||||
{
|
||||
$fac = new Facture($db);
|
||||
$ret=$fac->fetch($_POST['facid']);
|
||||
@ -895,6 +908,7 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') &&
|
||||
$desc = $prod->description;
|
||||
$desc.= $prod->description && $_POST['np_desc'] ? "\n" : "";
|
||||
$desc.= $_POST['np_desc'];
|
||||
$type = $prod->type;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -902,36 +916,40 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') &&
|
||||
$tva_tx=eregi_replace('\*','',$_POST['tva_tx']);
|
||||
$tva_npr=eregi('\*',$_POST['tva_tx'])?1:0;
|
||||
$desc=$_POST['dp_desc'];
|
||||
$type=$_POST["type"];
|
||||
}
|
||||
|
||||
$info_bits=0;
|
||||
if ($tva_npr) $info_bits |= 0x01;
|
||||
|
||||
|
||||
if($prod->price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($prod->price_min)))
|
||||
if ($result >= 0)
|
||||
{
|
||||
$fac->error = $langs->trans("CantBeLessThanMinPrice",price2num($prod->price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)) ;
|
||||
$result = -1 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Insert line
|
||||
$result = $fac->addline(
|
||||
$_POST['facid'],
|
||||
$desc,
|
||||
$pu_ht,
|
||||
$_POST['qty'],
|
||||
$tva_tx,
|
||||
$_POST['idprod'],
|
||||
$_POST['remise_percent'],
|
||||
$date_start,
|
||||
$date_end,
|
||||
0,
|
||||
$info_bits,
|
||||
'',
|
||||
$price_base_type,
|
||||
$pu_ttc
|
||||
);
|
||||
if($prod->price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($prod->price_min)))
|
||||
{
|
||||
$fac->error = $langs->trans("CantBeLessThanMinPrice",price2num($prod->price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)) ;
|
||||
$result = -1 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Insert line
|
||||
$result = $fac->addline(
|
||||
$_POST['facid'],
|
||||
$desc,
|
||||
$pu_ht,
|
||||
$_POST['qty'],
|
||||
$tva_tx,
|
||||
$_POST['idprod'],
|
||||
$_POST['remise_percent'],
|
||||
$date_start,
|
||||
$date_end,
|
||||
0,
|
||||
$info_bits,
|
||||
'',
|
||||
$price_base_type,
|
||||
$pu_ttc,
|
||||
$type
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -971,18 +989,38 @@ if ($_POST['action'] == 'updateligne' && $user->rights->facture->creer && $_POST
|
||||
$vat_rate=$_POST['tva_tx'];
|
||||
$vat_rate=eregi_replace('\*','',$vat_rate);
|
||||
|
||||
// On vérifie que le prix minimum est respecté
|
||||
if($_POST['productid']!='')
|
||||
// Check parameters
|
||||
if (empty($_POST['productid']) && $_POST["type"] < 0)
|
||||
{
|
||||
$productid = $_POST['productid'] ;
|
||||
$pruduct = new Product($db) ;
|
||||
$pruduct->fetch($productid) ;
|
||||
$fac->error = $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")) ;
|
||||
$result = -1 ;
|
||||
}
|
||||
// Check minimum price
|
||||
if(! empty($_POST['productid']))
|
||||
{
|
||||
$productid = $_POST['productid'];
|
||||
$pruduct = new Product($db);
|
||||
$pruduct->fetch($productid);
|
||||
$type=$pruduct->type;
|
||||
}
|
||||
if($pruduct->price_min && ($_POST['productid']!='') && (price2num($_POST['price'])*(1-price2num($_POST['remise_percent'])/100) < price2num($pruduct->price_min)))
|
||||
{
|
||||
$mesg = '<div class="error">'.$langs->trans("CantBeLessThanMinPrice",price2num($pruduct->price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).'</div>' ;
|
||||
$mesg = '<div class="error">'.$langs->trans("CantBeLessThanMinPrice",price2num($pruduct->price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).'</div>';
|
||||
$result=-1;
|
||||
}
|
||||
|
||||
// Define params
|
||||
if (! empty($_POST['productid']))
|
||||
{
|
||||
$type=$pruduct->type;
|
||||
}
|
||||
else
|
||||
{
|
||||
$type=$_POST["type"];
|
||||
}
|
||||
|
||||
// Update line
|
||||
if ($result >= 0)
|
||||
{
|
||||
$result = $fac->updateline($_POST['rowid'],
|
||||
$_POST['desc'],
|
||||
@ -993,7 +1031,8 @@ if ($_POST['action'] == 'updateligne' && $user->rights->facture->creer && $_POST
|
||||
$date_end,
|
||||
$vat_rate,
|
||||
'HT',
|
||||
$info_bits
|
||||
$info_bits,
|
||||
$type
|
||||
);
|
||||
|
||||
$outputlangs = $langs;
|
||||
@ -2862,8 +2901,7 @@ else
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO Select type (service or product)
|
||||
print $html->select_type_of_lines($objp->fk_product_type,'type',1);
|
||||
print $html->select_type_of_lines($objp->product_type,'type',1);
|
||||
}
|
||||
|
||||
// Description - Editor wysiwyg
|
||||
@ -2958,7 +2996,8 @@ else
|
||||
$var=true;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td>';
|
||||
// TODO Select type (product or service)
|
||||
|
||||
print $html->select_type_of_lines(-1,'type',1);
|
||||
|
||||
// Editeur wysiwyg
|
||||
if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS)
|
||||
|
||||
@ -1480,6 +1480,7 @@ class Facture extends CommonObject
|
||||
$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; }
|
||||
|
||||
@ -1503,17 +1504,21 @@ class Facture extends CommonObject
|
||||
* \param fk_remise_except Id remise
|
||||
* \param price_base_type HT or TTC
|
||||
* \param pu_ttc Prix unitaire TTC
|
||||
* \return int >0 si ok, <0 si ko
|
||||
* \param type Type of line (0=product, 1=service)
|
||||
* \return int >0 if OK, <0 if KO
|
||||
* \remarks Les parametres sont deja censé etre juste et avec valeurs finales a l'appel
|
||||
* de cette methode. Aussi, pour le taux tva, il doit deja avoir ete défini
|
||||
* par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit)
|
||||
* et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
|
||||
*/
|
||||
function addline($facid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0)
|
||||
function addline($facid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=0)
|
||||
{
|
||||
dol_syslog("Facture::Addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc", LOG_DEBUG);
|
||||
dol_syslog("Facture::Addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type", LOG_DEBUG);
|
||||
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
|
||||
|
||||
// Check parameters
|
||||
if ($type < 0) return -1;
|
||||
|
||||
if ($this->brouillon)
|
||||
{
|
||||
$this->db->begin();
|
||||
@ -1583,6 +1588,7 @@ class Facture extends CommonObject
|
||||
$ligne->total_ht=$total_ht;
|
||||
$ligne->total_tva=$total_tva;
|
||||
$ligne->total_ttc=$total_ttc;
|
||||
$ligne->product_type=$type;
|
||||
|
||||
// \TODO Ne plus utiliser
|
||||
$ligne->price=$price;
|
||||
@ -1617,36 +1623,40 @@ class Facture extends CommonObject
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Mets à jour une ligne de facture
|
||||
* \param rowid Id de la ligne de facture
|
||||
* \param desc Description de la ligne
|
||||
* \param pu Prix unitaire (HT ou TTC selon price_base_type)
|
||||
* \param qty Quantité
|
||||
* \param remise_percent Pourcentage de remise de la ligne
|
||||
* \param date_start Date de debut de validité du service
|
||||
* \param date_end Date de fin de validité du service
|
||||
* \param tva_tx Taux TVA
|
||||
* \param price_base_type HT ou TTC
|
||||
* \param info_bits Miscellanous informations
|
||||
* \return int < 0 si erreur, > 0 si ok
|
||||
* \brief Update line
|
||||
* \param rowid Id of line to update
|
||||
* \param desc Description of line
|
||||
* \param pu Prix unitaire (HT ou TTC selon price_base_type)
|
||||
* \param qty Quantity
|
||||
* \param remise_percent Pourcentage de remise de la ligne
|
||||
* \param date_start Date de debut de validité du service
|
||||
* \param date_end Date de fin de validité du service
|
||||
* \param tva_tx VAT Rate
|
||||
* \param price_base_type HT or TTC
|
||||
* \param info_bits Miscellanous informations
|
||||
* \param type Type of line (0=product, 1=service)
|
||||
* \return int < 0 si erreur, > 0 si ok
|
||||
*/
|
||||
function updateline($rowid, $desc, $pu, $qty, $remise_percent=0, $date_start, $date_end, $txtva, $price_base_type='HT', $info_bits=0)
|
||||
function updateline($rowid, $desc, $pu, $qty, $remise_percent=0, $date_start, $date_end, $txtva, $price_base_type='HT', $info_bits=0, $type=0)
|
||||
{
|
||||
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
|
||||
|
||||
dol_syslog("Facture::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $price_base_type, $info_bits", LOG_DEBUG);
|
||||
dol_syslog("Facture::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $price_base_type, $info_bits, $type", LOG_DEBUG);
|
||||
|
||||
if ($this->brouillon)
|
||||
{
|
||||
$this->db->begin();
|
||||
|
||||
// Nettoyage paramètres
|
||||
// Clean parameters
|
||||
$remise_percent=price2num($remise_percent);
|
||||
$qty=price2num($qty);
|
||||
if (! $qty) $qty=1;
|
||||
$pu = price2num($pu);
|
||||
$txtva=price2num($txtva);
|
||||
|
||||
// Check parameters
|
||||
if ($type < 0) return -1;
|
||||
|
||||
// Calcul du total TTC et de la TVA pour la ligne a partir de
|
||||
// qty, pu, remise_percent et txtva
|
||||
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
|
||||
@ -1685,6 +1695,7 @@ class Facture extends CommonObject
|
||||
$ligne->total_tva=$total_tva;
|
||||
$ligne->total_ttc=$total_ttc;
|
||||
$ligne->info_bits=$info_bits;
|
||||
$ligne->product_type=$type;
|
||||
|
||||
// A ne plus utiliser
|
||||
$ligne->price=$price;
|
||||
@ -2741,9 +2752,9 @@ class Facture extends CommonObject
|
||||
|
||||
|
||||
/**
|
||||
\class FactureLigne
|
||||
\brief Classe permettant la gestion des lignes de factures
|
||||
\remarks Gere des lignes de la table llx_facturedet
|
||||
* \class FactureLigne
|
||||
* \brief Classe permettant la gestion des lignes de factures
|
||||
* \remarks Gere des lignes de la table llx_facturedet
|
||||
*/
|
||||
class FactureLigne
|
||||
{
|
||||
@ -2756,16 +2767,16 @@ class FactureLigne
|
||||
var $fk_facture;
|
||||
//! Description ligne
|
||||
var $desc;
|
||||
var $fk_product; // Id produit prédéfini
|
||||
var $fk_product; // Id of predefined product
|
||||
var $product_type = 0; // Type 0 = product, 1 = Service
|
||||
|
||||
var $qty; // Quantité (exemple 2)
|
||||
var $tva_tx; // Taux tva produit/service (exemple 19.6)
|
||||
var $subprice; // P.U. HT (exemple 100)
|
||||
var $remise_percent; // % de la remise ligne (exemple 20%)
|
||||
var $qty; // Quantity (example 2)
|
||||
var $tva_tx; // Taux tva produit/service (example 19.6)
|
||||
var $subprice; // P.U. HT (example 100)
|
||||
var $remise_percent; // % de la remise ligne (example 20%)
|
||||
var $rang = 0;
|
||||
|
||||
var $info_bits = 0; // Liste d'options cumulables:
|
||||
var $info_bits = 0; // Liste d'options cumulables:
|
||||
// Bit 0: 0 si TVA normal - 1 si TVA NPR
|
||||
// Bit 1: 0 si ligne normal - 1 si bit discount
|
||||
|
||||
@ -2859,9 +2870,9 @@ class FactureLigne
|
||||
|
||||
|
||||
/**
|
||||
* \brief Insère l'objet ligne de facture en base
|
||||
* \param notrigger 1 ne declenche pas les triggers, 0 sinon
|
||||
* \return int <0 si ko, >0 si ok
|
||||
* \brief Insert line in database
|
||||
* \param notrigger 1 no triggers
|
||||
* \return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function insert($notrigger=0)
|
||||
{
|
||||
@ -2874,6 +2885,8 @@ class FactureLigne
|
||||
if (! $this->subprice) $this->subprice=0;
|
||||
if (! $this->price) $this->price=0;
|
||||
|
||||
// Check parameters
|
||||
if ($this->product_type < 0) return -1;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
@ -2951,7 +2964,7 @@ class FactureLigne
|
||||
if ($discount->fk_facture)
|
||||
{
|
||||
$this->error=$langs->trans("ErrorDiscountAlreadyUsed",$discount->id);
|
||||
dol_syslog("FactureLigne::insert Error ".$this->error);
|
||||
dol_syslog("FactureLigne::insert Error ".$this->error, LOG_ERROR);
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
@ -2961,7 +2974,7 @@ class FactureLigne
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error=$discount->error;
|
||||
dol_syslog("FactureLigne::insert Error ".$this->error);
|
||||
dol_syslog("FactureLigne::insert Error ".$this->error, LOG_ERROR);
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
@ -2970,7 +2983,7 @@ class FactureLigne
|
||||
else
|
||||
{
|
||||
$this->error=$langs->trans("ErrorADiscountThatHasBeenRemovedIsIncluded");
|
||||
dol_syslog("FactureLigne::insert Error ".$this->error);
|
||||
dol_syslog("FactureLigne::insert Error ".$this->error, LOG_ERROR);
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
@ -2978,7 +2991,7 @@ class FactureLigne
|
||||
else
|
||||
{
|
||||
$this->error=$discount->error;
|
||||
dol_syslog("FactureLigne::insert Error ".$this->error);
|
||||
dol_syslog("FactureLigne::insert Error ".$this->error, LOG_ERROR);
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
@ -3001,7 +3014,7 @@ class FactureLigne
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("FactureLigne::insert Error ".$this->error);
|
||||
dol_syslog("FactureLigne::insert Error ".$this->error, LOG_ERROR);
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
@ -3009,14 +3022,17 @@ class FactureLigne
|
||||
|
||||
|
||||
/**
|
||||
* \brief Mise a jour de l'objet ligne de facture en base
|
||||
* \return int <0 si ko, >0 si ok
|
||||
* \brief Update line in database
|
||||
* \return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function update()
|
||||
{
|
||||
// Clean parameters
|
||||
$this->desc=trim($this->desc);
|
||||
|
||||
// Check parameters
|
||||
if ($this->product_type < 0) return -1;
|
||||
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
@ -3035,6 +3051,7 @@ class FactureLigne
|
||||
else { $sql.=',date_start=null'; }
|
||||
if ($this->date_end) { $sql.= ",date_end='".$this->db->idate($this->date_end)."'"; }
|
||||
else { $sql.=',date_end=null'; }
|
||||
$sql.= ",product_type=".$this->product_type;
|
||||
$sql.= ",rang='".$this->rang."'";
|
||||
$sql.= ",info_bits='".$this->info_bits."'";
|
||||
$sql.= ",total_ht=".price2num($this->total_ht)."";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user