@snapey Please Can you suggest me a idea plz
How to make total of products based on product category laravel
Guys iam working with a project Inventory Control like project.
I have a table product_category with columns
id(pk),
login_user_id,
product_category_name
ans this is my product table with columns
id(pk),
login_user_id,
product_name,
product_category_id,
and this is purchase_product table with columns
id(pk),
login_user_id,
date,
product_id,
qty,
total_amount
Now what my client expecting is i need to have the total amount based on the category of the product.
say for example.
if i have data in purchase_product table like
date Product qty total_amount
30-03 coconut oil 10 1000
30-03 ground nut oil 20 2000
30-03 Seasame oil 30 3000
30-03 Onion 10 200
30-03 tomato 20 200
in the above table first three belongs to oil type category. and second two belongs to vegetables category.
now how i need the total is
Oil - 6000
Vegetables -- 400
i need to get the total amount of the products based in its category.
here whats the problem is i didnt give product_category in the purchase_product table
but i have product_category table and product table with relationship.
How can i do this please Kindly help me for this.
i need to fetch based on date.
i have a date field in my blade file. i will choose the date and click the search button.
it moves to search_purchase_product method in controller there i need to search this date and the total amount with based on product category.
How to do this please Kindly help mee please.
I know the i need to use groupby
but whats my problem is in my purchase_product table i dont have product_category column
so what should i don please some one help.
and these are my models
ProductCategory
Product
PuchaseProduct
Kindly some one help please...
No, sorry, got to head to work in a minute
$purchases = PurchaseProduct::join('product', 'product.id', '=', 'purchase_product.product_id' )
->join('product_category', 'product_category.id', '=', 'product.product_category_id')
->select('purchase.product.id','product_name','qty','product_category.id' as 'category_id')
->get()
Sorry, got to dash
Start with this, add whatever columns you need from the three tables, add sql aggregate once you know you are getting all the joined data ok
Please or to participate in this conversation.