update propales for margins
This commit is contained in:
parent
a37707f96f
commit
122fc5eaa7
@ -46,6 +46,8 @@ $langs->load('compta');
|
||||
$langs->load('bills');
|
||||
$langs->load('orders');
|
||||
$langs->load('products');
|
||||
if ($conf->marges->enabled)
|
||||
$langs->load('marges');
|
||||
|
||||
$id=GETPOST('id','int');
|
||||
$ref=GETPOST('ref','alpha');
|
||||
@ -788,6 +790,13 @@ else if ($action == "addline" && $user->rights->propale->creer)
|
||||
$localtax2_tx=get_localtax($tva_tx,2,$object->client);
|
||||
}
|
||||
|
||||
// ajout prix achat
|
||||
$fk_fournprice = $_POST['np_fournprice'];
|
||||
if ( ! empty($_POST['np_buying_price']) )
|
||||
$pa_ht = $_POST['np_buying_price'];
|
||||
else
|
||||
$pa_ht = null;
|
||||
|
||||
$info_bits=0;
|
||||
if ($tva_npr) $info_bits |= 0x01;
|
||||
|
||||
@ -814,7 +823,9 @@ else if ($action == "addline" && $user->rights->propale->creer)
|
||||
$type,
|
||||
-1,
|
||||
0,
|
||||
$_POST['fk_parent_line']
|
||||
$_POST['fk_parent_line'],
|
||||
$fk_fournprice,
|
||||
$pa_ht
|
||||
);
|
||||
|
||||
if ($result > 0)
|
||||
@ -841,6 +852,7 @@ else if ($action == "addline" && $user->rights->propale->creer)
|
||||
unset($_POST['dp_desc']);
|
||||
unset($_POST['np_tva_tx']);
|
||||
unset($_POST['np_desc']);
|
||||
unset($_POST['np_buying_price']);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -869,11 +881,18 @@ else if ($action == 'updateligne' && $user->rights->propale->creer && $_POST["sa
|
||||
$vat_rate=str_replace('*','',$vat_rate);
|
||||
$localtax1_rate=get_localtax($vat_rate,1,$object->client);
|
||||
$localtax2_rate=get_localtax($vat_rate,2,$object->client);
|
||||
$up_ht=GETPOST('pu')?GETPOST('pu'):GETPOST('subprice');
|
||||
$pu_ht=GETPOST('pu')?GETPOST('pu'):GETPOST('subprice');
|
||||
|
||||
// Define special_code for special lines
|
||||
$special_code=0;
|
||||
if (empty($_POST['qty'])) $special_code=3;
|
||||
// ajout prix d'achat
|
||||
$fk_fournprice = $_POST['fournprice'];
|
||||
if ( ! empty($_POST['buying_price']) )
|
||||
$pa_ht = $_POST['buying_price'];
|
||||
else
|
||||
$pa_ht = null;
|
||||
|
||||
// Define special_code for special lines
|
||||
$special_code=0;
|
||||
if (empty($_POST['qty'])) $special_code=3;
|
||||
|
||||
// On verifie que le prix minimum est respecte
|
||||
$productid = $_POST['productid'] ;
|
||||
@ -884,7 +903,7 @@ else if ($action == 'updateligne' && $user->rights->propale->creer && $_POST["sa
|
||||
$price_min = $product->price_min;
|
||||
if ($conf->global->PRODUIT_MULTIPRICES && $object->client->price_level) $price_min = $product->multiprices_min[$object->client->price_level];
|
||||
}
|
||||
if ($productid && $price_min && (price2num($up_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($price_min)))
|
||||
if ($productid && $price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($price_min)))
|
||||
{
|
||||
$mesg = '<div class="error">'.$langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->currency)).'</div>' ;
|
||||
}
|
||||
@ -892,7 +911,7 @@ else if ($action == 'updateligne' && $user->rights->propale->creer && $_POST["sa
|
||||
{
|
||||
$result = $object->updateline(
|
||||
$_POST['lineid'],
|
||||
$up_ht,
|
||||
$pu_ht,
|
||||
$_POST['qty'],
|
||||
$_POST['remise_percent'],
|
||||
$vat_rate,
|
||||
@ -902,7 +921,10 @@ else if ($action == 'updateligne' && $user->rights->propale->creer && $_POST["sa
|
||||
'HT',
|
||||
$info_bits,
|
||||
$special_code,
|
||||
$_POST['fk_parent_line']
|
||||
$_POST['fk_parent_line'],
|
||||
0,
|
||||
$fk_fournprice,
|
||||
$pa_ht
|
||||
);
|
||||
|
||||
// Define output language
|
||||
@ -917,8 +939,15 @@ else if ($action == 'updateligne' && $user->rights->propale->creer && $_POST["sa
|
||||
}
|
||||
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
|
||||
{
|
||||
$ret=$object->fetch($id); // Reload to get new records
|
||||
$ret=$object->fetch($id); // Reload to get new records
|
||||
propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
|
||||
|
||||
unset($_POST['qty']);
|
||||
unset($_POST['type']);
|
||||
unset($_POST['np_price']);
|
||||
unset($_POST['dp_desc']);
|
||||
unset($_POST['np_tva_tx']);
|
||||
unset($_POST['np_buying_price']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1527,10 +1556,18 @@ if (empty($reshook) && ! empty($extrafields->attribute_label))
|
||||
}
|
||||
}
|
||||
|
||||
// Amount HT
|
||||
// Amount HT
|
||||
print '<tr><td height="10">'.$langs->trans('AmountHT').'</td>';
|
||||
print '<td align="right" nowrap><b>'.price($object->total_ht).'</b></td>';
|
||||
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
|
||||
print '<td>'.$langs->trans("Currency".$conf->currency).'</td>';
|
||||
|
||||
// Margin Infos
|
||||
if ($conf->marges->enabled) {
|
||||
print '<td valign="top" width="50%" rowspan="4">';
|
||||
$object->displayMarginInfos();
|
||||
print '</td>';
|
||||
}
|
||||
print '</tr>';
|
||||
|
||||
// Amount VAT
|
||||
print '<tr><td height="10">'.$langs->trans('AmountVAT').'</td>';
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
* Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
|
||||
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2010-2011 Philippe Grand <philippe.grand@atoo-net.com>
|
||||
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.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
|
||||
@ -32,6 +33,7 @@ require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT ."/product/class/product.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT ."/contact/class/contact.class.php");
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT ."/marges/lib/marges.lib.php");
|
||||
|
||||
/**
|
||||
* \class Propal
|
||||
@ -306,7 +308,7 @@ class Propal extends CommonObject
|
||||
*
|
||||
* @see add_product
|
||||
*/
|
||||
function addline($propalid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0)
|
||||
function addline($propalid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht = 0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
@ -327,6 +329,7 @@ class Propal extends CommonObject
|
||||
$txtva=price2num($txtva);
|
||||
$txlocaltax1=price2num($txlocaltax1);
|
||||
$txlocaltax2=price2num($txlocaltax2);
|
||||
$pa_ht=price2num($pa_ht);
|
||||
if ($price_base_type=='HT')
|
||||
{
|
||||
$pu=$pu_ht;
|
||||
@ -395,6 +398,10 @@ class Propal extends CommonObject
|
||||
$this->line->special_code=$special_code;
|
||||
$this->line->fk_parent_line=$fk_parent_line;
|
||||
|
||||
// infos marge
|
||||
$this->line->fk_fournprice = $fk_fournprice;
|
||||
$this->line->pa_ht = $pa_ht;
|
||||
|
||||
// Mise en option de la ligne
|
||||
//if ($conf->global->PROPALE_USE_OPTION_LINE && !$qty) $ligne->special_code=3;
|
||||
if (empty($qty) && empty($special_code)) $this->line->special_code=3;
|
||||
@ -452,7 +459,7 @@ class Propal extends CommonObject
|
||||
* @param int $skip_update_total Skip update total
|
||||
* @return int 0 if OK, <0 if KO
|
||||
*/
|
||||
function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $desc='', $price_base_type='HT', $info_bits=0, $special_code=0, $fk_parent_line=0, $skip_update_total=0)
|
||||
function updateline($rowid, $pu, $qty, $remise_percent=0, $txtva, $txlocaltax1=0, $txlocaltax2=0, $desc='', $price_base_type='HT', $info_bits=0, $special_code=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht = 0)
|
||||
{
|
||||
global $conf,$user,$langs;
|
||||
|
||||
@ -466,6 +473,7 @@ class Propal extends CommonObject
|
||||
$txtva = price2num($txtva);
|
||||
$txlocaltax1=price2num($txlocaltax1);
|
||||
$txlocaltax2=price2num($txlocaltax2);
|
||||
$pa_ht=price2num($pa_ht);
|
||||
if (empty($qty) && empty($special_code)) $special_code=3; // Set option tag
|
||||
if (! empty($qty) && $special_code == 3) $special_code=0; // Remove option tag
|
||||
|
||||
@ -525,6 +533,10 @@ class Propal extends CommonObject
|
||||
$this->line->fk_parent_line = $fk_parent_line;
|
||||
$this->line->skip_update_total = $skip_update_total;
|
||||
|
||||
// infos marge
|
||||
$this->line->fk_fournprice = $fk_fournprice;
|
||||
$this->line->pa_ht = $pa_ht;
|
||||
|
||||
// TODO deprecated
|
||||
$this->line->price=$price;
|
||||
$this->line->remise=$remise;
|
||||
@ -738,7 +750,9 @@ class Propal extends CommonObject
|
||||
$this->lines[$i]->product_type,
|
||||
$this->lines[$i]->rang,
|
||||
$this->lines[$i]->special_code,
|
||||
$fk_parent_line
|
||||
$fk_parent_line,
|
||||
$this->lines[$i]->fk_fournprice,
|
||||
$this->lines[$i]->pa_ht
|
||||
);
|
||||
|
||||
if ($result < 0)
|
||||
@ -1057,7 +1071,7 @@ class Propal extends CommonObject
|
||||
* Lignes propales liees a un produit ou non
|
||||
*/
|
||||
$sql = "SELECT d.rowid, d.fk_propal, d.fk_parent_line, d.description, d.price, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,";
|
||||
$sql.= " d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.marge_tx, d.marque_tx, d.special_code, d.rang, d.product_type,";
|
||||
$sql.= " d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buying_price_ht as pa_ht, d.special_code, d.rang, d.product_type,";
|
||||
$sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label';
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid";
|
||||
@ -1096,8 +1110,9 @@ class Propal extends CommonObject
|
||||
$line->total_localtax1 = $objp->total_localtax1;
|
||||
$line->total_localtax2 = $objp->total_localtax2;
|
||||
$line->total_ttc = $objp->total_ttc;
|
||||
$line->marge_tx = $objp->marge_tx;
|
||||
$line->marque_tx = $objp->marque_tx;
|
||||
$line->fk_fournprice = $objp->fk_fournprice;
|
||||
$marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht, $objp->marge_tx, $objp->marque_tx);
|
||||
$line->pa_ht = $marginInfos[0];
|
||||
$line->special_code = $objp->special_code;
|
||||
$line->rang = $objp->rang;
|
||||
|
||||
@ -2358,7 +2373,7 @@ class Propal extends CommonObject
|
||||
{
|
||||
$sql = 'SELECT pt.rowid, pt.description, pt.fk_product, pt.fk_remise_except,';
|
||||
$sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,';
|
||||
$sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.marge_tx, pt.marque_tx, pt.pa_ht, pt.special_code,';
|
||||
$sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buying_price_ht as pa_ht, pt.special_code,';
|
||||
$sql.= ' pt.date_start, pt.date_end, pt.product_type, pt.rang,';
|
||||
$sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,';
|
||||
$sql.= ' p.description as product_desc';
|
||||
@ -2387,7 +2402,6 @@ class Propal extends CommonObject
|
||||
$this->lines[$i]->product_type = $obj->product_type;
|
||||
$this->lines[$i]->qty = $obj->qty;
|
||||
$this->lines[$i]->subprice = $obj->subprice;
|
||||
$this->lines[$i]->pa_ht = $obj->pa_ht;
|
||||
$this->lines[$i]->fk_remise_except = $obj->fk_remise_except;
|
||||
$this->lines[$i]->remise_percent = $obj->remise_percent;
|
||||
$this->lines[$i]->tva_tx = $obj->tva_tx;
|
||||
@ -2395,8 +2409,9 @@ class Propal extends CommonObject
|
||||
$this->lines[$i]->total_ht = $obj->total_ht;
|
||||
$this->lines[$i]->total_tva = $obj->total_tva;
|
||||
$this->lines[$i]->total_ttc = $obj->total_ttc;
|
||||
$this->lines[$i]->marge_tx = $obj->marge_tx;
|
||||
$this->lines[$i]->marque_tx = $obj->marque_tx;
|
||||
$this->lines[$i]->fk_fournprice = $obj->fk_fournprice;
|
||||
$marginInfos = getMarginInfos($obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, $this->lines[$i]->fk_fournprice, $obj->pa_ht, $obj->marge_tx, $obj->marque_tx);
|
||||
$this->lines[$i]->pa_ht = $marginInfos[0];
|
||||
$this->lines[$i]->special_code = $obj->special_code;
|
||||
$this->lines[$i]->rang = $obj->rang;
|
||||
$this->lines[$i]->date_start = $this->db->jdate($obj->date_start);
|
||||
@ -2445,8 +2460,9 @@ class PropaleLigne
|
||||
var $fk_remise_except;
|
||||
|
||||
var $rang = 0;
|
||||
var $marge_tx;
|
||||
var $marque_tx;
|
||||
|
||||
var $fk_fournprice;
|
||||
var $pa_ht;
|
||||
|
||||
var $special_code; // Liste d'options non cumulabels:
|
||||
// 1: frais de port
|
||||
@ -2497,7 +2513,7 @@ class PropaleLigne
|
||||
{
|
||||
$sql = 'SELECT pd.rowid, pd.fk_propal, pd.fk_parent_line, pd.fk_product, pd.description, pd.price, pd.qty, pd.tva_tx,';
|
||||
$sql.= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,';
|
||||
$sql.= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.marge_tx, pd.marque_tx, pd.special_code, pd.rang,';
|
||||
$sql.= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buying_price_ht as pa_ht, pd.special_code, pd.rang,';
|
||||
$sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pd';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pd.fk_product = p.rowid';
|
||||
@ -2525,8 +2541,9 @@ class PropaleLigne
|
||||
$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->fk_fournprice = $objp->fk_fournprice;
|
||||
$marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht, $objp->marge_tx, $objp->marque_tx);
|
||||
$this->pa_ht = $marginInfos[0];
|
||||
$this->special_code = $objp->special_code;
|
||||
$this->rang = $objp->rang;
|
||||
|
||||
@ -2571,6 +2588,14 @@ class PropaleLigne
|
||||
if (empty($this->special_code)) $this->special_code=0;
|
||||
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
|
||||
|
||||
if (empty($this->pa_ht)) $this->pa_ht=0;
|
||||
|
||||
// si prix d'achat non renseigné et utilisé pour calcul des marges alors prix achat = prix vente (idem pour remises)
|
||||
if ($this->pa_ht == 0) {
|
||||
if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1))
|
||||
$this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
if ($this->product_type < 0) return -1;
|
||||
|
||||
@ -2581,7 +2606,7 @@ class PropaleLigne
|
||||
$sql.= ' (fk_propal, fk_parent_line, description, fk_product, product_type, fk_remise_except, qty, tva_tx, localtax1_tx, localtax2_tx,';
|
||||
$sql.= ' subprice, remise_percent, ';
|
||||
$sql.= ' info_bits, ';
|
||||
$sql.= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, special_code, rang, marge_tx, marque_tx)';
|
||||
$sql.= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, special_code, rang, fk_product_fournisseur_price, buying_price_ht)';
|
||||
$sql.= " VALUES (".$this->fk_propal.",";
|
||||
$sql.= " ".($this->fk_parent_line>0?"'".$this->fk_parent_line."'":"null").",";
|
||||
$sql.= " '".$this->db->escape($this->desc)."',";
|
||||
@ -2602,10 +2627,10 @@ class PropaleLigne
|
||||
$sql.= " ".price2num($this->total_ttc).",";
|
||||
$sql.= ' '.$this->special_code.',';
|
||||
$sql.= ' '.$this->rang.',';
|
||||
if (isset($this->marge_tx)) $sql.= ' '.$this->marge_tx.',';
|
||||
else $sql.= ' null,';
|
||||
if (isset($this->marque_tx)) $sql.= ' '.$this->marque_tx;
|
||||
else $sql.= ' null';
|
||||
if (isset($this->fk_fournprice)) $sql.= ' '.$this->fk_fournprice.',';
|
||||
else $sql.= ' null,';
|
||||
if (isset($this->pa_ht)) $sql.= ' '.price2num($this->pa_ht).',';
|
||||
else $sql.= ' null';
|
||||
$sql.= ')';
|
||||
|
||||
dol_syslog("PropaleLigne::insert sql=$sql");
|
||||
@ -2701,6 +2726,14 @@ class PropaleLigne
|
||||
if (empty($this->special_code)) $this->special_code=0;
|
||||
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
|
||||
|
||||
if (empty($this->pa_ht)) $this->pa_ht=0;
|
||||
|
||||
// si prix d'achat non renseigné et utilisé pour calcul des marges alors prix achat = prix vente (idem pour remises)
|
||||
if ($this->pa_ht == 0) {
|
||||
if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1))
|
||||
$this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// Mise a jour ligne en base
|
||||
@ -2721,8 +2754,8 @@ class PropaleLigne
|
||||
$sql.= " , total_tva=".price2num($this->total_tva)."";
|
||||
$sql.= " , total_ttc=".price2num($this->total_ttc)."";
|
||||
}
|
||||
$sql.= " , marge_tx='".$this->marge_tx."'";
|
||||
$sql.= " , marque_tx='".$this->marque_tx."'";
|
||||
$sql.= " , fk_product_fournisseur_price='".$this->fk_fournprice."'";
|
||||
$sql.= " , buying_price_ht='".price2num($this->pa_ht)."'";
|
||||
$sql.= " , info_bits=".$this->info_bits;
|
||||
if (strlen($this->special_code)) $sql.= " , special_code=".$this->special_code;
|
||||
$sql.= " , fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user