From 690278f5551fb27238b241baaef5167775991a96 Mon Sep 17 00:00:00 2001 From: lizhilin <1007915129@qq.com> Date: Tue, 3 Dec 2024 17:00:46 +0800 Subject: [PATCH] 更新 --- app/Admin/Actions/ReceivedInvoicedExcel.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/Admin/Controllers/ReceivePaymentController.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++------------ app/Admin/Extensions/ReceivedInvoicedExport.php | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/Admin/Repositories/LawyerInvoicedPaymentCollect.php | 8 +++++--- app/Admin/Repositories/LawyerReceivePaymentCollect.php | 8 +++++--- app/Admin/routes.php | 1 + 6 files changed, 211 insertions(+), 18 deletions(-) create mode 100644 app/Admin/Actions/ReceivedInvoicedExcel.php create mode 100644 app/Admin/Extensions/ReceivedInvoicedExport.php diff --git a/app/Admin/Actions/ReceivedInvoicedExcel.php b/app/Admin/Actions/ReceivedInvoicedExcel.php new file mode 100644 index 0000000..738f51a --- /dev/null +++ b/app/Admin/Actions/ReceivedInvoicedExcel.php @@ -0,0 +1,70 @@ +<?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 . '¶m=' . json_encode($param) . '&_export_=1'); + } + + public function parameters() + { + return [ + 'mode' => '', + 'param' => $this->request_param, + 'filename' => $this->request_filename, + 'title' => $this->title, + ]; + } +} diff --git a/app/Admin/Controllers/ReceivePaymentController.php b/app/Admin/Controllers/ReceivePaymentController.php index f806f59..e69b588 100644 --- a/app/Admin/Controllers/ReceivePaymentController.php +++ b/app/Admin/Controllers/ReceivePaymentController.php @@ -16,6 +16,10 @@ use App\Models\CovenantReceivePayment as ModelCovenantReceivePayment; use App\Admin\Repositories\LawyerReceivePaymentCollect; 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 { @@ -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 = ''; if ($lawyerID) { $obj = ModelsLawyer::find($lawyerID); @@ -57,11 +70,11 @@ public function index(Content $content) $tools->append($card_info); }); - $grid->export()->disableExportAll(); - $grid->export()->disableExportSelectedRow(); - $grid->export()->rows(function ($rows) { - return $rows; - }); + // $grid->export()->disableExportAll(); + // $grid->export()->disableExportSelectedRow(); + // $grid->export()->rows(function ($rows) { + // return $rows; + // }); }); @@ -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 = ''; if ($lawyerID) { $obj = ModelsLawyer::find($lawyerID); @@ -101,11 +123,12 @@ public function index(Content $content) $tools->append($card_info); }); - $grid->export()->disableExportAll(); - $grid->export()->disableExportSelectedRow(); - $grid->export()->rows(function ($rows) { - return $rows; - }); + // $grid->export()->disableExportAll(); + // $grid->export()->disableExportSelectedRow(); + // $grid->export()->rows(function ($rows) { + // return $rows; + // }); + }); @@ -114,4 +137,20 @@ public function index(Content $content) 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'); + } } diff --git a/app/Admin/Extensions/ReceivedInvoicedExport.php b/app/Admin/Extensions/ReceivedInvoicedExport.php new file mode 100644 index 0000000..e8fe873 --- /dev/null +++ b/app/Admin/Extensions/ReceivedInvoicedExport.php @@ -0,0 +1,79 @@ +<?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; + } +} diff --git a/app/Admin/Repositories/LawyerInvoicedPaymentCollect.php b/app/Admin/Repositories/LawyerInvoicedPaymentCollect.php index 720700f..bfd207d 100644 --- a/app/Admin/Repositories/LawyerInvoicedPaymentCollect.php +++ b/app/Admin/Repositories/LawyerInvoicedPaymentCollect.php @@ -21,10 +21,11 @@ public function get(Grid\Model $model) { // 获取筛选条件 $year = $model->filter()->input('year'); - + $lawyer_id = $model->filter()->input('no'); $param = [ 'search' => [ - 'year' => $year + 'year' => $year, + 'lawyer_id' => $lawyer_id ] ]; @@ -37,12 +38,13 @@ public function getList(array $param) { $year = $param['search']['year'] ?? ''; + $lawyer_id = $param['search']['lawyer_id'] ?? 0; $nowyear = date("Y"); $monthNum = ($year && $year < $nowyear) ? 12 : date('m'); $data = []; 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; } diff --git a/app/Admin/Repositories/LawyerReceivePaymentCollect.php b/app/Admin/Repositories/LawyerReceivePaymentCollect.php index 7f5f98a..bea025a 100644 --- a/app/Admin/Repositories/LawyerReceivePaymentCollect.php +++ b/app/Admin/Repositories/LawyerReceivePaymentCollect.php @@ -21,10 +21,11 @@ public function get(Grid\Model $model) { // 获取筛选条件 $year = $model->filter()->input('year'); - + $lawyer_id = $model->filter()->input('no'); $param = [ 'search' => [ - 'year' => $year + 'year' => $year, + 'lawyer_id' => $lawyer_id ] ]; @@ -37,12 +38,13 @@ public function getList(array $param) { $year = $param['search']['year'] ?? ''; + $lawyer_id = $param['search']['lawyer_id'] ?? 0; $nowyear = date("Y"); $monthNum = ($year && $year < $nowyear) ? 12 : date('m'); $data = []; 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; } diff --git a/app/Admin/routes.php b/app/Admin/routes.php index a85ef75..0ed4da8 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -48,6 +48,7 @@ $router->resource('lawyer_income', 'LawyerIncomeController'); //律师创收表 $router->resource('receive_payment', 'ReceivePaymentController'); //已收款/已开票汇总 + Route::get('received-invoiced-Export', 'ReceivePaymentController@receivedInvoicedExport'); //开票汇总导出 $router->resource('lawyer-covenant-income', 'LawyerCovenantIncomeController'); //创收收款表 -- libgit2 0.26.0