AbdulBazith
1 month ago
176
36
Laravel

multiply the qty and rate from two tables with same product_id in laravel

Posted 1 month ago by AbdulBazith

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

Please sign in or create an account to participate in this conversation.