Wrong amount for item in Quote and Order - magento

Hi i have a question regarding tax_amount, row_total, price_incl_tax and row_total_incl_tax.
My problem is that those values are caclulated as follow:
price = 30
price_excl_tax = 25.08
so for ex: price_incl_tax should be 30, but it is 25.08...
base_tax amount is good, it's calculated from price (30), but tax_amount is calculated from price_excl_tax
Did someone encoutered this issue ?

Ok, so it looks like it isn't problem with Magento itsefl, but with Thread Interference on PHP side.

Related

Calculate hours for training

I have some hesitations about 3 tables which are type_training , training & payment.
In the table type_training, I have a field named price with 4 amounts: for example:
1 hour 00 = 100 euros
1 hour 30 = 150 euros
2 hour 00 = 200 euros
2 hour 30 = 250 euros
In my page Training , I encode 2 recordings for the same student.
The student Dujardin has booked 3 hours for 300 euros.
In my form Payment, is it possible to retrieve the amount of 300 ?
So, in my Model Payment? I must to calculate the difference between the hour start and the hour end?
I don't know how to do ?
Then, after having retrieved the difference of hours in my example we have 3 hours.
How to I sum my 2 recordings in my field Total ? I have tried this?
$typetraining = Typetraining::find($request->fk_typetraining);
$data = $request->all();
$data['total'] = $typetraining->price + $request->????;
Payment::create($data);
In summary:
1) How to retrieve the difference between hour start & hour end,
2) How to calculate the amounts via the duration of my training?
For information, here is my architecture.
I thank you for your help and your explanations.
Edit: Watercamyan 19/09/2019
I adapat this?
createFromFormat('H:i', $request->get('hour_start'))
Per:
<div class="form-group{{ $errors->has('hour_start') ? 'has-error' : '' }}">
<label for="form-group-input-1">Hour start</label>
<input type="text" name="hour_start" id="hour_start" class="form-control" required="required" value="{{ old('hour_start')}}"/>
{!! $errors->first('hour_start', '<span class="help-block">:message</span>') !!}
</div>
Then, in my model Training I have like error message: Undefined variable: typeseances
$start = Carbon::parse($request->get('hour_start'));
$end= Carbon::parse($request->get('hour_end'));
$mins = $end->diffInMinutes($start, true);
$hoursTraining = $mins/60;
$total = $**typeTraining**->price * $hoursTraining;
I have like error message: Undefined variable: typeseances
I think, as JoeGalind said, you should seriously consider re-archetecting this to be simpler. Having to call a TypeTraining object that has nothing but a price, should indeed be moved up to the Training object. However, let me go through a way to solve it with your existing code.
First, as you said, you need to get the number of hours of the requested training. Unfortunately, you need part hours instead of whole hours to change the price. If you needed whole hours, this would be easy, you could use the Carbon method diffInHours(). But we can do it with diffInMinutes(), and then calculate out the partial hour.
First, we need to parse the hours coming in from the form into a Carbon object:
$start = Carbon::parse($request->get('hour_start'));
$end= Carbon::parse($request->get('hour_end'));
Note, I don't know how it is coming in from your form. You might need to parse it differently if the above doesn't work. Something like:
createFromFormat('H:i', $request->get('hour_start'))
or
createFromFormat('H:i:s', $request->get('hour_start'))
Now that you've got a carbon object, we need to calculate out the difference, including the part hours. Again, we'll use the minutes and calculate for part hours:
$mins = $end->diffInMinutes($start, true);
$hoursTraining = $mins/60;
This will yield your multiplier (the number of hours training), something like 2.0 or 2.5 or 2.25, etc. From here, if you have a base price for one hour (which is what I expect is in that TypeTraining model's price field), it is easy:
$total = $typeTraining->price * $hoursTraining;
The hard part, based on the way you have your code set up, is that you must pull the TypeTraining along with the Training, in order to know the price (again - just stick the price on the training to make life easier).
To get the price, something like this:
$training = Training::with('typeTraining')->where('fk_student', $request->get('fk_student)->first();
$price = $training->typeTraining->price;
Now you have the price to plug into the formula above.
This is surely not exact. And pulling the training with the FK on student is probably not what you want. If it is generic training, or there is some other identifier, use that to pull the training to get the price. But you can decide that later. I can only guess at some of this, as I don't know what's coming in, or what your query needs to be, or your relationships, but this should give you an idea. Most importantly, you were asking for how to calculate total, which is answered farther above.
I would recommend the following:
Add a "price" field to the training table. This way, if in the future, you increment that price, all your history stays with the current price.
After saving your "training", go ahead and calculate the hours between both dates using Carbon library, and select your current price from the TypeTraining table using this value.
Store the value on the Training table and then you can easily calculate the sum from anywhere.

Qlikview Ranking Expression

Quick question,does anybody know how to set an expression in Qlikview whereby the user could rank as follows:
"Company X first always, followed by all other companies ranked by highest value to lowest value"
Apologies this might seem like a very basic question as I am a novice in Qlikview.
Thank you for your help,
Liam
Set the sorting of the company field to be something like this:
if( company = 'Company6', 1000000, sum(value) )
Having the following data:
Companies:
Load * Inline [
company, value
Company1, 10
Company5, 60
Company2, 50
Company3, 30
Company4, 40
Company6, 20
];
And the result is below

Query with sum many columns from same table with laravel query

This seems very easy query but can't translate it into laravel query. I have table orders there are two columns total_usd and total_gbp. I want to sum each column to get total of usd and total of gbp on the page.
This query is working in phpmyadmin and I got correct result
SELECT sum(order_total_usd) as usd, sum(order_total_gbp) as gbp FROM `orders`
In laravel I've tried this
$sumOrders = Order::select('sum(order_total_gbp) as gbp, sum(order_total_usd) as usd');
when I dd($sumOrders) I've one really huge output which almost cause browser to freeze.
Where is my mistake here?
You can try something like this
$sumOrders = Order::select( \DB::raw("sum(order_total_gbp) as gbp"), \DB::raw("sum(order_total_usd) as usd"))->get();
You can use selectRaw
$sumOrders = Order::selectRaw('sum(order_total_gbp) as gbp, sum(order_total_usd) as usd');
Except for one missed word, your code is OK. Add "Raw" after "select" as shown:
$sumOrders =
Order::selectRaw(
'sum(order_total_gbp) as gbp,
sum(order_total_usd) as usd'
);
Just replace "Order::select(...)" with Order::selectRaw(...).
Have a great day!

Exchange rates for ENDOFMONTH

I have an Exchange Rate table that I'm trying to get the ending months calculation
It's using a minimum of 3 currencies lets use GBP USD EUR
I need to return when selecting that currency the End of month Currency
So something like k
EOMCcy=:IF(HASONEVALUE('Ccy'[Currency Symbol]),
CALCULATE([Exchange Rate],ENDOFMONTH('Exchange Rates'[Date]) ,BLANK()))
I know I need to validate the currency somewhere and I'm trying many thinks as I have a fromCcy and toCccy column e.g GBP USD
This would show in the [Exchange Rate] column =1.22
I was hoping someone can point me in the right direction or offer a better method with my code
Thank all
So I think I solved it
EOMCcy:=IF(HASONEVALUE('Ccy'[Currency Symbol]),
CALCULATE (
SUM ([ExchangeRate]),
FILTER (
ALL ( 'Exchange Rates'[Date]),
'Exchange Rates'[Date] = ENDOFMONTH('Exchange Rates'[Date])
)
),BLANK())

Magento rounds up the custom product price

I'm setting a custom price depending on each customer. Using a webservice I receive the specific price for each customer in the format: XX,DD
When I use the function setprice in order to set the new price for the product:
$product->setFinalPrice($price);
Magento rounds up the price and, for example, if the $price is 38,50, then it sets the product price to 38. I've tried changing the ',' for '.' with str_replace, but in this case, it seems it can't set up the price.
How can I tell Magento to use the decimals as well?
Thanks
First you should convert your price to decimal number:
$value="38,50";
$amount = Zend_Locale_Format::getNumber($value,array('locale'=>'nl_NL'));
// or you can use str_replace
In Magento products has two types of standard price:
$product->getPrice();
$product->getSpecialPrice();
finalPrice - it is not actually product value, it will be calculated by Magento based on price, special_price, tier price and so on. You should set price value and save the product:
$value = "38,50"; //this decimalformat is used in nl_Nl locale
$amount = Zend_Locale_Format::getNumber($value,array('locale'=>'nl_NL'));
$amount = Mage::app()->getStore()->roundPrice($amount); //round price based on Magento logic
$product->setPrice($amount); //price - is actual value of product
// some extra code here
$product->save();
I'll throw in that you can use:
echo number_format($_product->getPrice(), 2)
It will give you a couple of decimal places.
I am guessing you do not want the price to round up. If that is the case then your solution depends on the version of PHP you are using.
PHP 5.3 you can simply use the round function to round it down like so:
round($price, 2, PHP_ROUND_HALF_DOWN);
If you are using PHP 5.2 you do not have the luxary of the PHP_ROUND_HALF_DOWN so you have to put the following function in somewhere (a helper makes the most sense to me) and call it:
floor($line_item_price * 100) / 100;
What this does is first multiply the value with 100 and then floor the value. This gives you a rounded down value with the precision of 2. Then divide by 100 to get the correct value.
The number 100 comes from the power(10, desired precision)
I hope you are on PHP 5.3. I did not enjoy having to do the PHP 5.2 solution very much.
To round up a price in magento you need overwrite a directory/currency model method convert.
Mage_Directory_Model_Currency::convert()
here you will find like this
return $price*$rate
and need to set like this
return round($price*$rate);

Resources