Commit 690278f5 by lizhilin

更新

parent 270d2697
<?php
namespace App\Admin\Actions;
use App\Command\Log;
use Dcat\Admin\Actions\Action;
use Dcat\Admin\Actions\Response;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
/**
* 导出 汇总表
* Class DownloadTemplate
*
* @package App\Admin\Actions
*/
class ReceivedInvoicedExcel extends Action
{
protected $request_param = [];
protected $request_filename = '';
protected $title = '';
/**
* 接收参数
*/
public function __construct($param = [], $filename = '', $title = '')
{
$this->request_param = $param;
$this->request_filename = $filename;
parent::__construct($title);
$this->title = $title;
}
//protected $title = '<button class="btn btn-primary"><i class="feather icon-download"></i> 下载模板</button>';
/**
* 按钮文本
*
* @return string|void
*/
public function title()
{
return '<button class="btn btn-primary"><i class="feather icon-download"></i> ' . $this->title . '</button>';
}
/**
* Handle the action request.
*
* @return Response
*/
public function handle(Request $request)
{
$param = $request->get('param');
$filename = $request->get('filename');
//调用导出接口
return $this->response()->download('/received-invoiced-Export?filename=' . $filename . '&param=' . json_encode($param) . '&_export_=1');
}
public function parameters()
{
return [
'mode' => '',
'param' => $this->request_param,
'filename' => $this->request_filename,
'title' => $this->title,
];
}
}
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
use App\Models\CovenantReceivePayment as ModelCovenantReceivePayment; use App\Models\CovenantReceivePayment as ModelCovenantReceivePayment;
use App\Admin\Repositories\LawyerReceivePaymentCollect; use App\Admin\Repositories\LawyerReceivePaymentCollect;
use App\Admin\Repositories\LawyerInvoicedPaymentCollect; use App\Admin\Repositories\LawyerInvoicedPaymentCollect;
use App\Admin\Actions\ReceivedInvoicedExcel;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
use App\Admin\Extensions\ReceivedInvoicedExport;
class ReceivePaymentController extends Controller class ReceivePaymentController extends Controller
{ {
...@@ -45,7 +49,16 @@ public function index(Content $content) ...@@ -45,7 +49,16 @@ public function index(Content $content)
}); });
//文字信息 //文字信息
$grid->tools(function (Grid\Tools $tools) use ($grid, $lawyerID) { $grid->tools(function (Grid\Tools $tools) use ($grid, $lawyerID, $year) {
//导出按钮
// 获取筛选条件
$param = [
'search' => ['lawyer_id' => $lawyerID, 'year' => $year, 'rtype' => 1]
];
// 导出
$filename = '已收款汇总表';
$tools->append(new ReceivedInvoicedExcel($param, $filename, '导出'));
//文字展示
$fullname = $number = ''; $fullname = $number = '';
if ($lawyerID) { if ($lawyerID) {
$obj = ModelsLawyer::find($lawyerID); $obj = ModelsLawyer::find($lawyerID);
...@@ -57,11 +70,11 @@ public function index(Content $content) ...@@ -57,11 +70,11 @@ public function index(Content $content)
$tools->append($card_info); $tools->append($card_info);
}); });
$grid->export()->disableExportAll(); // $grid->export()->disableExportAll();
$grid->export()->disableExportSelectedRow(); // $grid->export()->disableExportSelectedRow();
$grid->export()->rows(function ($rows) { // $grid->export()->rows(function ($rows) {
return $rows; // return $rows;
}); // });
}); });
...@@ -89,7 +102,16 @@ public function index(Content $content) ...@@ -89,7 +102,16 @@ public function index(Content $content)
}); });
//文字信息 //文字信息
$grid->tools(function (Grid\Tools $tools) use ($grid, $lawyerID) { $grid->tools(function (Grid\Tools $tools) use ($grid, $lawyerID, $year) {
//导出按钮
// 获取筛选条件
$param = [
'search' => ['lawyer_id' => $lawyerID, 'year' => $year, 'rtype' => 2]
];
// 导出
$filename = '已开票汇总表';
$tools->append(new ReceivedInvoicedExcel($param, $filename, '导出'));
//文字展示
$fullname = $number = ''; $fullname = $number = '';
if ($lawyerID) { if ($lawyerID) {
$obj = ModelsLawyer::find($lawyerID); $obj = ModelsLawyer::find($lawyerID);
...@@ -101,11 +123,12 @@ public function index(Content $content) ...@@ -101,11 +123,12 @@ public function index(Content $content)
$tools->append($card_info); $tools->append($card_info);
}); });
$grid->export()->disableExportAll(); // $grid->export()->disableExportAll();
$grid->export()->disableExportSelectedRow(); // $grid->export()->disableExportSelectedRow();
$grid->export()->rows(function ($rows) { // $grid->export()->rows(function ($rows) {
return $rows; // return $rows;
}); // });
}); });
...@@ -114,4 +137,20 @@ public function index(Content $content) ...@@ -114,4 +137,20 @@ public function index(Content $content)
return $content->body($tab); return $content->body($tab);
} }
/**
* 导出
*
* @param Request $request
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public function receivedInvoicedExport(Request $request)
{
$filename = $request->get('filename');
$param = json_decode($request->get('param'));
ob_end_clean();
return Excel::download(new ReceivedInvoicedExport($param), $filename . '.xlsx');
}
} }
<?php
namespace App\Admin\Extensions;
use App\Command\Log;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use App\Models\CovenantReceivePayment as ModelsCovenantReceivePayment;
class ReceivedInvoicedExport implements FromCollection, WithHeadings
{
private $row;
private $data;
private $headings;
/**
* TaskDataExcelExpoter constructor.
* @param array $param 筛选条件
* @param array $data 数据
* @param array $headings 表头
*/
public function __construct($param = [], $data = [], $headings = [])
{
$param = json_decode(json_encode($param), true);
$year = $param['search']['year'] ?? date("Y");
$nowyear = date("Y");
$monthNum = ($year && $year < $nowyear) ? 12 : date('m');
//表头设定
for ($i = 1; $i <= $monthNum; $i++) {
$tmp[$i] = $i . '月';
}
$header = $tmp;
$headings = [$header];
$data = $this->getList($param);
$this->headings = $headings;
$this->data = $data;
}
public function headings(): array
{
return $this->headings;
}
public function collection()
{
return collect($this->data);
}
// 获取列表数据
public function getList($param)
{
$param = json_decode(json_encode($param), true);
$lawyer_id = $param['search']['lawyer_id'] ?? 0;
$rtype = $param['search']['rtype'] ?? 1;
$year = $param['search']['year'] ?? date("Y");
$data = [];
$nowyear = date("Y");
$monthNum = ($year && $year < $nowyear) ? 12 : date('m');
for ($i = 1; $i <= $monthNum; $i++) {
if ($rtype == 1) { //已收款
$amount = ModelsCovenantReceivePayment::where(['rtype' => $rtype, 'lawyer_id' => $lawyer_id, 'year' => $year, 'month' => $i])->sum('received_amount');
} else { //已开票
$amount = ModelsCovenantReceivePayment::where(['rtype' => $rtype, 'lawyer_id' => $lawyer_id, 'year' => $year, 'month' => $i])->sum('invoiced_money');
}
$data[$i] = $amount;
}
return [$data];
return $data;
}
}
...@@ -21,10 +21,11 @@ public function get(Grid\Model $model) ...@@ -21,10 +21,11 @@ public function get(Grid\Model $model)
{ {
// 获取筛选条件 // 获取筛选条件
$year = $model->filter()->input('year'); $year = $model->filter()->input('year');
$lawyer_id = $model->filter()->input('no');
$param = [ $param = [
'search' => [ 'search' => [
'year' => $year 'year' => $year,
'lawyer_id' => $lawyer_id
] ]
]; ];
...@@ -37,12 +38,13 @@ public function getList(array $param) ...@@ -37,12 +38,13 @@ public function getList(array $param)
{ {
$year = $param['search']['year'] ?? ''; $year = $param['search']['year'] ?? '';
$lawyer_id = $param['search']['lawyer_id'] ?? 0;
$nowyear = date("Y"); $nowyear = date("Y");
$monthNum = ($year && $year < $nowyear) ? 12 : date('m'); $monthNum = ($year && $year < $nowyear) ? 12 : date('m');
$data = []; $data = [];
for ($i = 1; $i <= $monthNum; $i++) { for ($i = 1; $i <= $monthNum; $i++) {
$received_amount = ModelsCovenantReceivePayment::where(['rtype' => 2, 'year' => $year, 'month' => $i])->sum('invoiced_money'); $received_amount = ModelsCovenantReceivePayment::where(['rtype' => 2, 'lawyer_id' => $lawyer_id, 'year' => $year, 'month' => $i])->sum('invoiced_money');
$data[$i] = $received_amount; $data[$i] = $received_amount;
} }
......
...@@ -21,10 +21,11 @@ public function get(Grid\Model $model) ...@@ -21,10 +21,11 @@ public function get(Grid\Model $model)
{ {
// 获取筛选条件 // 获取筛选条件
$year = $model->filter()->input('year'); $year = $model->filter()->input('year');
$lawyer_id = $model->filter()->input('no');
$param = [ $param = [
'search' => [ 'search' => [
'year' => $year 'year' => $year,
'lawyer_id' => $lawyer_id
] ]
]; ];
...@@ -37,12 +38,13 @@ public function getList(array $param) ...@@ -37,12 +38,13 @@ public function getList(array $param)
{ {
$year = $param['search']['year'] ?? ''; $year = $param['search']['year'] ?? '';
$lawyer_id = $param['search']['lawyer_id'] ?? 0;
$nowyear = date("Y"); $nowyear = date("Y");
$monthNum = ($year && $year < $nowyear) ? 12 : date('m'); $monthNum = ($year && $year < $nowyear) ? 12 : date('m');
$data = []; $data = [];
for ($i = 1; $i <= $monthNum; $i++) { for ($i = 1; $i <= $monthNum; $i++) {
$received_amount = ModelsCovenantReceivePayment::where(['rtype' => 1, 'year' => $year, 'month' => $i])->sum('received_amount'); $received_amount = ModelsCovenantReceivePayment::where(['rtype' => 1, 'lawyer_id' => $lawyer_id, 'year' => $year, 'month' => $i])->sum('received_amount');
$data[$i] = $received_amount; $data[$i] = $received_amount;
} }
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
$router->resource('lawyer_income', 'LawyerIncomeController'); //律师创收表 $router->resource('lawyer_income', 'LawyerIncomeController'); //律师创收表
$router->resource('receive_payment', 'ReceivePaymentController'); //已收款/已开票汇总 $router->resource('receive_payment', 'ReceivePaymentController'); //已收款/已开票汇总
Route::get('received-invoiced-Export', 'ReceivePaymentController@receivedInvoicedExport'); //开票汇总导出
$router->resource('lawyer-covenant-income', 'LawyerCovenantIncomeController'); //创收收款表 $router->resource('lawyer-covenant-income', 'LawyerCovenantIncomeController'); //创收收款表
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment