skip to Main Content

I get this error form helper.php. I need sale prices of product. but I get this error.And I dont understand when I get this error.

helper.php

public static function getSalesPriceUsingProductIDCode($id, $customerId)
{
    $data = PosCustomerProducts::valid()->where('complete_status',0)->where('customer_id', $customerId)->where('product_id', $id)
    ->select('product_id', 'sales_price')
    ->first()->sales_price;
    return $data;
}

orderSheetExport.php

if(isset($results[$product->id]))
{   
    if (Helper::getSalesPriceUsingProductIDCode($product->id,$results['customer_id'])==0)
    { 
        $excel_dynamic_data_values[$index][] =   $product->whole_sale_price * $results[$product->id];
        $productArray[$rsm_id][$product->id] += $results[$product->id] * $product->whole_sale_price;
        $singleProductArray[$rsm_id][$product->id] = $productArray[$rsm_id][$product->id];
        
    }else
    {    
        $excel_dynamic_data_values[$index][] = Helper::getSalesPriceUsingProductIDCode($product->id,$results['customer_id']) * $results[$product->id];       
        $productArray[$rsm_id][$product->id]       += $results[$product->id] *  Helper::getSalesPriceUsingProductIDCode( $product->id,$results['customer_id']);
        $singleProductArray[$rsm_id][$product->id] = $productArray[$rsm_id][$product->id];   
    }
}

2

Answers


  1. Chosen as BEST ANSWER

    I solve this problem. I also understand Why I was getting this error. When I use this helper function on a loop. It get some values that were not any sale price data. So it though this error. So, I write if else condition on it.

    Helper.php

    public static function getSalesPriceUsingProductIDCode($id, $customerId)
    {
        $data = PosCustomerProducts::valid()->where('complete_status',0)->where('customer_id', $customerId)->where('product_id', $id)
        ->select('product_id', 'sales_price')
        ->first();
            if ($data) {
                $data = $data->sales_price;
            } else {
                $data = 0;
            }
        return $data;
    }
    

  2. If you just need the sales_price use value function

    public static function getSalesPriceUsingProductIDCode($id, $customerId)
    {
        $data = PosCustomerProducts::valid()->where('complete_status',0)->where('customer_id', $customerId)->where('product_id', $id)
        ->select('product_id', 'sales_price')
        ->value('sales_price');
        return $data;
    }
    

    Kindly refer value() in Laravel Queries

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search