在laravel中按天月份年份进行报告 [英] making report in laravel By Day Month Year

查看:63
本文介绍了在laravel中按天月份年份进行报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码求和产品的数量和价格,但我首先需要每年月份的3个功能,我将在接下来的每个月的每一天,每年的最后一天获取总计的产品

My Code Sum Products and quantity and price but i need 3 functions for day year month in first i will get total of products in every day next in every month and last in every year

代码

$product_orders = \App\OrderProduct::select(DB::raw('sum(line_total) as total_line'),
DB::raw('sum(qty) as qty') , 'product_id','line_total','created_at')->
orderBy('created_at')->groupBy('product_id')->get();

数据库

id , prdouct_id ,order_id, qty ,unit_total , line_total , created_at , updated_at


推荐答案

##for grouping you can use it like these

public function day(){
$products= OrderProduct::select(
                DB::raw('DAY(created_at) as day'),DB::raw('sum(line_total) as total_line') , 'product_id','qty','line_total','created_at')->groupBy('day','product_id')->get();
}
public function month(){
$products= OrderProduct::select(
                DB::raw('MONTHNAME(created_at) as month'),
                DB::raw('sum(line_total) as total_line') , 'product_id','qty','line_total','created_at')->groupBy('month','product_id')->get();
}
public function year(){
$products= OrderProduct::select(
                DB::raw('YEAR(created_at) as year'),
               DB::raw('sum(line_total) as total_line') , 'product_id','qty','line_total','created_at')->groupBy('year','product_id')->get();
}

尝试一下,让我知道发生了什么

try this and let me know what happened

这篇关于在laravel中按天月份年份进行报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆