Skip to content

Commit

Permalink
Allow to enter price in currency
Browse files Browse the repository at this point in the history
  • Loading branch information
atm-maxime committed Dec 10, 2016
1 parent b1d5f26 commit 6474591
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
9 changes: 6 additions & 3 deletions htdocs/compta/facture.php
Expand Up @@ -1314,6 +1314,7 @@
$predef='';
$product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
$price_ht = GETPOST('price_ht');
$price_ht_devise = GETPOST('multicurrency_price_ht');
if (GETPOST('prod_entry_mode') == 'free')
{
$idprod=0;
Expand Down Expand Up @@ -1348,7 +1349,7 @@
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors');
$error ++;
}
if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && (! ($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not ''
if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && (! ($price_ht >= 0) || $price_ht == '') && empty($price_ht_devise)) // Unit price can be 0 but not ''
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
$error ++;
Expand Down Expand Up @@ -1505,6 +1506,7 @@
$desc = $product_desc;
$type = GETPOST('type');
$fk_unit= GETPOST('units', 'alpha');
$pu_ht_devise = price2num($price_ht_devise, 'MU');
}

// Margin
Expand All @@ -1524,7 +1526,7 @@
setEventMessages($mesg, null, 'errors');
} else {
// Insert line
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $date_start, $date_end, 0, $info_bits, '', $price_base_type, $pu_ttc, $type, - 1, $special_code, '', 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $_POST['progress'], '', $fk_unit);
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $date_start, $date_end, 0, $info_bits, '', $price_base_type, $pu_ttc, $type, - 1, $special_code, '', 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $_POST['progress'], '', $fk_unit, $pu_ht_devise);

if ($result > 0)
{
Expand Down Expand Up @@ -1604,6 +1606,7 @@
$pu_ht = GETPOST('price_ht');
$vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
$qty = GETPOST('qty');
$pu_ht_devise = GETPOST('multicurrency_subprice');

// Define info_bits
$info_bits = 0;
Expand Down Expand Up @@ -1688,7 +1691,7 @@
$result = $object->updateline(GETPOST('lineid'), $description, $pu_ht, $qty, GETPOST('remise_percent'),
$date_start, $date_end, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $type,
GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options, GETPOST('progress'),
$_POST['units']);
$_POST['units'],$pu_ht_devise);

if ($result >= 0) {
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
Expand Down
16 changes: 10 additions & 6 deletions htdocs/compta/facture/class/facture.class.php
Expand Up @@ -2411,9 +2411,10 @@ function set_draft($user,$idwarehouse=-1)
* @param int $situation_percent Situation advance percentage
* @param int $fk_prev_id Previous situation line id reference
* @param string $fk_unit Code of the unit to use. Null to use the default one
* @param double $pu_ht_devise Unit price in currency
* @return int <0 if KO, Id of line if OK
*/
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $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=self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_options=0, $situation_percent=100, $fk_prev_id='', $fk_unit = null)
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $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=self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_options=0, $situation_percent=100, $fk_prev_id='', $fk_unit = null, $pu_ht_devise = 0)
{
// Deprecation warning
if ($label) {
Expand Down Expand Up @@ -2493,7 +2494,7 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $f
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.

$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, $situation_percent, $this->multicurrency_tx);
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, $situation_percent, $this->multicurrency_tx, $pu_ht_devise);

$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
Expand All @@ -2506,6 +2507,7 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $f
$multicurrency_total_ht = $tabprice[16];
$multicurrency_total_tva = $tabprice[17];
$multicurrency_total_ttc = $tabprice[18];
$pu_ht_devise = $tabprice[19];

// Rank to use
$rangtouse = $rang;
Expand Down Expand Up @@ -2565,7 +2567,7 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $f
// Multicurrency
$this->line->fk_multicurrency = $this->fk_multicurrency;
$this->line->multicurrency_code = $this->multicurrency_code;
$this->line->multicurrency_subprice = price2num($this->line->subprice * $this->multicurrency_tx);
$this->line->multicurrency_subprice = $pu_ht_devise;
$this->line->multicurrency_total_ht = $multicurrency_total_ht;
$this->line->multicurrency_total_tva = $multicurrency_total_tva;
$this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
Expand Down Expand Up @@ -2628,9 +2630,10 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $f
* @param array $array_options extrafields array
* @param int $situation_percent Situation advance percentage
* @param string $fk_unit Code of the unit to use. Null to use the default one
* @param double $pu_ht_devise Unit price in currency
* @return int < 0 if KO, > 0 if OK
*/
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type= self::TYPE_STANDARD, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $situation_percent=0, $fk_unit = null)
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type= self::TYPE_STANDARD, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $situation_percent=0, $fk_unit = null, $pu_ht_devise = 0)
{
global $conf,$user;
// Deprecation warning
Expand Down Expand Up @@ -2688,7 +2691,7 @@ function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $dat
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}

$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, $situation_percent, $this->multicurrency_tx);
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, $situation_percent, $this->multicurrency_tx, $pu_ht_devise);

$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
Expand All @@ -2703,6 +2706,7 @@ function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $dat
$multicurrency_total_ht = $tabprice[16];
$multicurrency_total_tva = $tabprice[17];
$multicurrency_total_ttc = $tabprice[18];
$pu_ht_devise = $tabprice[19];

// Old properties: $price, $remise (deprecated)
$price = $pu;
Expand Down Expand Up @@ -2778,7 +2782,7 @@ function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $dat
$this->line->pa_ht = $pa_ht;

// Multicurrency
$this->line->multicurrency_subprice = price2num($this->line->subprice * $this->multicurrency_tx);
$this->line->multicurrency_subprice = $pu_ht_devise;
$this->line->multicurrency_total_ht = $multicurrency_total_ht;
$this->line->multicurrency_total_tva = $multicurrency_total_tva;
$this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
Expand Down
11 changes: 10 additions & 1 deletion htdocs/core/lib/price.lib.php
Expand Up @@ -71,7 +71,7 @@
* 17=multicurrency_total_tva
* 18=multicurrency_total_ttc
*/
function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller = '', $localtaxes_array='', $progress=100, $multicurrency_tx=1)
function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller = '', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_ht_devise=0)
{
global $conf,$mysoc,$db;

Expand Down Expand Up @@ -140,6 +140,14 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt
}
else dol_print_error($db);
}

// pu calculation from pu_devise if pu empty
if(empty($pu) && !empty($pu_ht_devise)) {
$pu = $pu_ht_devise / $multicurrency_tx;
} else {
$pu_ht_devise = $pu * $multicurrency_tx;
}

// initialize total (may be HT or TTC depending on price_base_type)
$tot_sans_remise = $pu * $qty * $progress / 100;
$tot_avec_remise_ligne = $tot_sans_remise * (1 - ($remise_percent_ligne / 100));
Expand Down Expand Up @@ -332,6 +340,7 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt
$result[16] = price2num($result[0] * $multicurrency_tx, 'MT');
$result[17] = price2num($result[1] * $multicurrency_tx, 'MT');
$result[18] = price2num($result[2] * $multicurrency_tx, 'MT');
$result[19] = price2num($pu_ht_devise, 'MU');

// initialize result array
//for ($i=0; $i <= 18; $i++) $result[$i] = (float) $result[$i];
Expand Down

0 comments on commit 6474591

Please sign in to comment.