FahimAnzamDip / triangle-pos

Triangle POS is an open source Inventory Management with POS System. Developed with Laravel 10, Bootstrap 4 & Livewire 3. It's completely free to use.
620 stars 199 forks source link

Profit/loss summary #56

Open blkaleeb opened 10 months ago

blkaleeb commented 10 months ago

Hi, i think the profit data is imprecise.

foreach ($sales as $sale) { foreach ($sale->saleDetails as $saleDetail) { $product_costs += $saleDetail->product->product_cost; } }

this means if you get have the sales qty above 1, you will get the product cost equal to 1 product. for example: A = 130.000, we sell A with price 140.000. so the profit is 10.000 per item if we create sales with 5 qty, we get 570.000 profit instead of 50.000

RamaWasudewa commented 3 months ago

I agree with you. so I try to modify the public function calculateProfit() from: foreach ($sales as $sale) { foreach ($sale->saleDetails as $saleDetail) { $product_costs += $saleDetail->product->product_cost; } } to foreach ($sales as $sale) { foreach ($sale->saleDetails as $saleDetail) { //$product_costs += $saleDetail->product->product_cost; $product_costs += $saleDetail->product->product_cost * $saleDetail->quantity; } }

what do you think about that?

blkaleeb commented 2 months ago
foreach ($sales as $sale) {
            foreach ($sale->saleDetails as $saleDetail) {
                $product_costs += ($saleDetail->quantity * $saleDetail->product->product_cost);
            }
        }

i'm changing it like this, wdyt ? @RamaWasudewa