@snapey please do u have any idea
multiply the qty and rate from two tables with same product_id in laravel
guys i have two tables
table opening_stock with columns
id
open_date
product_id
open_qty
db structure below
id open_date product_id open_qty
1 21-07-2019 1 100
2 21-07-2019 2 250
table product_rate with columns
id
r_date
product_id
rate_per_kg
db structure below
id r_date product_id rate_per_kg
1 21-07-2019 1 10
2 22-07-2019 1 11
3 21-07-2019 2 35
what i expect is i will give a date through form $request->from_date and $request->to_date both date move to controller and check first in OpenStock model. in open_stocks table there will be only one date so it should fetch record from that table and then it should move to ProductRate model and fetch record with given rate (within given date there may be two or more records in that the latest date within the given date) records are fetched and then the open_qty and rate_per_kg should be multiplied with same product_id and it should be displayed in blade file
the output i expect as given below
and what i expect the output as in blade file
s.no productName open_stock rate/kg total
1 tomato 100 11 1100
2 potato 250 35 8750
Total 9850
my products table with columns
id
product_name
//
id product_name
1 tomato
2 potato
my relationship in the OpenStock model
public function product()
{
return $this->belongsTo('App\Product', 'product_id');
}
myrealtionship in ProductRate Model
public function product()
{
return $this->belongsTo('App\Product', 'product_id');
}
Kindly some one help please
You can use the result collection as a lookup table.
eg, in blade
<td>{{ $product->id }}</td>
<td>{{ $product->name }} </td>
<td>{{ $product->openingstock->open_qty }}</td>
<td>{{ $prices->firstWhere('product_id',$product->id)->rate_per_kg }}</td>
<td>{{ $prices->firstWhere('product_id',$product->id)->rate_per_kg * $product->openingstock->open_qty }} </td>
Please or to participate in this conversation.