Commit 45a59f10 by lizhilin

导出

parent 6cfd86fe
<?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;
/**
* 导出 律师提成汇总表
*
* @package App\Admin\Actions
*/
class LawyerCommissionCollectExcel 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('/lawyer-commission-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,
];
}
}
<?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;
/**
* 导出 律师成本汇总表
*
* @package App\Admin\Actions
*/
class LawyerCostCollectExcel 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('/lawyer-cost-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,
];
}
}
...@@ -66,6 +66,16 @@ protected function grid() ...@@ -66,6 +66,16 @@ protected function grid()
$filter->between('sign_at', '签约日期')->date()->width(4); $filter->between('sign_at', '签约日期')->date()->width(4);
}); });
$grid->export()->rows(function ($rows) {
foreach ($rows as $index => &$row) {
$row['ctype'] = Covenant::CTYPE[$row['ctype']];
$row['payment_method'] = ($row['payment_method'] == 1) ? '开票付款' : '付款开票';
$row['is_closed'] = ($row['is_closed'] == 1) ? '已结案' : '未结案';
$row['is_return'] = ($row['is_return'] == 1) ? '已退还' : '未退还';
}
return $rows;
});
$grid->actions(function (Grid\Displayers\Actions $actions) { $grid->actions(function (Grid\Displayers\Actions $actions) {
//编辑 //编辑
if (!Admin::user()->can('hetong-edit')) { if (!Admin::user()->can('hetong-edit')) {
......
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
use Dcat\Admin\Grid; use Dcat\Admin\Grid;
use Dcat\Admin\Show; use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController; use Dcat\Admin\Http\Controllers\AdminController;
use App\Admin\Actions\LawyerCommissionCollectExcel;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
use App\Admin\Extensions\lawyerCommissionExportExten;
class LawyerCommissionCollectController extends AdminController class LawyerCommissionCollectController extends AdminController
{ {
...@@ -23,7 +27,7 @@ protected function grid() ...@@ -23,7 +27,7 @@ protected function grid()
return Grid::make(new LawyerCommission(), function (Grid $grid) { return Grid::make(new LawyerCommission(), function (Grid $grid) {
$number = $grid->model()->filter()->input('no') ?? ''; //律师编号 $number = $grid->model()->filter()->input('no') ?? ''; //律师编号
$nowyear = date("Y"); $nowyear = date("Y");
$year = $grid->model()->filter()->input('year') ?? ''; $year = $grid->model()->filter()->input('year') ?? date('Y');
$monthNum = ($year && $year < $nowyear) ? 12 : date('m'); $monthNum = ($year && $year < $nowyear) ? 12 : date('m');
...@@ -49,16 +53,39 @@ protected function grid() ...@@ -49,16 +53,39 @@ protected function grid()
$grid->disablePagination(); $grid->disablePagination();
//文字信息 //文字信息
$grid->tools(function (Grid\Tools $tools) use ($grid, $number) { $grid->tools(function (Grid\Tools $tools) use ($grid, $number, $year) {
$fullname = ''; $fullname = '';
if ($number) { if ($number) {
$obj = ModelsLawyer::where('number', $number)->first(); $obj = ModelsLawyer::where('number', $number)->first();
$fullname = $obj->name; $fullname = $obj->name;
} }
$card_info = "&nbsp;&nbsp;律师编号:{$number}&nbsp;&nbsp;&nbsp;律师姓名:{$fullname}"; // 导出按钮 获取筛选条件
$param = [
'search' => ['number' => $number, 'year' => $year]
];
// 导出
$filename = $year . '年' . $fullname . '律师提成汇总表';
$tools->append(new LawyerCommissionCollectExcel($param, $filename, '导出'));
$card_info = "&nbsp;&nbsp;律师编号:{$number}&nbsp;&nbsp;&nbsp;律师姓名:{$fullname}";
$tools->append($card_info); $tools->append($card_info);
}); });
}); });
} }
/**
* 导出
*
* @param Request $request
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public function lawyerCommissionExport(Request $request)
{
$filename = $request->get('filename');
$param = json_decode($request->get('param'));
ob_end_clean();
return Excel::download(new lawyerCommissionExportExten($param), $filename . '.xlsx');
}
} }
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
use Dcat\Admin\Grid; use Dcat\Admin\Grid;
use Dcat\Admin\Show; use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController; use Dcat\Admin\Http\Controllers\AdminController;
use App\Admin\Actions\LawyerCostCollectExcel;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
use App\Admin\Extensions\lawyerCostExportExten;
class LawyerCostCollectController extends AdminController class LawyerCostCollectController extends AdminController
{ {
...@@ -22,7 +26,7 @@ protected function grid() ...@@ -22,7 +26,7 @@ protected function grid()
return Grid::make(new LawyerCost(), function (Grid $grid) { return Grid::make(new LawyerCost(), function (Grid $grid) {
$number = $grid->model()->filter()->input('no') ?? ''; //律师编号 $number = $grid->model()->filter()->input('no') ?? ''; //律师编号
$nowyear = date("Y"); $nowyear = date("Y");
$year = $grid->model()->filter()->input('year') ?? ''; $year = $grid->model()->filter()->input('year') ?? date('Y');
$monthNum = ($year && $year < $nowyear) ? 12 : date('m'); $monthNum = ($year && $year < $nowyear) ? 12 : date('m');
$grid->column('title', '项目名称')->width('10%'); $grid->column('title', '项目名称')->width('10%');
...@@ -45,12 +49,20 @@ protected function grid() ...@@ -45,12 +49,20 @@ protected function grid()
$grid->disablePagination(); $grid->disablePagination();
//文字信息 //文字信息
$grid->tools(function (Grid\Tools $tools) use ($grid, $number) { $grid->tools(function (Grid\Tools $tools) use ($grid, $number, $year) {
$fullname = ''; $fullname = '';
if ($number) { if ($number) {
$obj = ModelsLawyer::where('number', $number)->first(); $obj = ModelsLawyer::where('number', $number)->first();
$fullname = $obj->name; $fullname = $obj->name;
} }
// 导出按钮 获取筛选条件
$param = [
'search' => ['number' => $number, 'year' => $year]
];
// 导出
$filename = $year . '年' . $fullname . '律师成本汇总表';
$tools->append(new LawyerCostCollectExcel($param, $filename, '导出'));
$card_info = "&nbsp;&nbsp;律师编号:{$number}&nbsp;&nbsp;&nbsp;律师姓名:{$fullname}"; $card_info = "&nbsp;&nbsp;律师编号:{$number}&nbsp;&nbsp;&nbsp;律师姓名:{$fullname}";
$tools->append($card_info); $tools->append($card_info);
...@@ -131,4 +143,20 @@ protected function form() ...@@ -131,4 +143,20 @@ protected function form()
$form->display('updated_at'); $form->display('updated_at');
}); });
} }
/**
* 导出
*
* @param Request $request
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public function lawyerCostExport(Request $request)
{
$filename = $request->get('filename');
$param = json_decode($request->get('param'));
ob_end_clean();
return Excel::download(new lawyerCostExportExten($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;
use App\Models\LawyerCost as ModelLawyerCost;
use App\Models\Lawyer as ModelLawyer;
class lawyerCostExportExten 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');
//表头设定
$tmp = [];
$tmp['title'] = '项目名称';
for ($i = 1; $i <= $monthNum; $i++) {
$tmp[$i] = $i . '月';
}
$tmp['total'] = '合计';
$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);
$lnum = $param['search']['number'] ?? ''; //律师编号
$year = $param['search']['year'] ?? date("Y");
$data = [];
$nowyear = date("Y");
$monthNum = ($year && $year < $nowyear) ? 12 : date('m');
$fieldTotal = 0;
$list = ModelLawyerCost::COSTiTEM;
foreach ($list as $key => $val) {
$tmp = [];
$tmp['title'] = $val['name']; //项目名称
for ($i = 1; $i <= $monthNum; $i++) {
$tmp[$i] = 0;
}
//总计
$tmp['total'] = 0;
for ($i = 1; $i <= $monthNum; $i++) {
$tmp[$i] = '0.00';
$condition = ['year' => $year, 'month' => $i, 'number' => $lnum];
//基本工资
if ($val['field'] == 'basic_salary') {
$basic_salary = ModelLawyerCost::where($condition)->sum('basic_salary');
$tmp[$i] = $basic_salary;
$fieldTotal += $basic_salary;
}
//专项附加
if ($val['field'] == 'special_additional') {
$special_additional = ModelLawyerCost::where($condition)->sum('special_additional');
$tmp[$i] = $special_additional;
$fieldTotal += $special_additional;
}
//社保
if ($val['field'] == 'social') {
$social_person_fee = ModelLawyerCost::where($condition)->sum('social_person_fee');
$social_company_fee = ModelLawyerCost::where($condition)->sum('social_company_fee');
$tmp[$i] = sprintf("%.2f", ($social_person_fee + $social_company_fee));
}
//社保个人部分
if ($val['field'] == 'social_person_fee') {
$social_person_fee = ModelLawyerCost::where($condition)->sum('social_person_fee');
$tmp[$i] = $social_person_fee;
}
//社保企业部分
if ($val['field'] == 'social_company_fee') {
$social_company_fee = ModelLawyerCost::where($condition)->sum('social_company_fee');
$tmp[$i] = $social_company_fee;
}
//公积金
if ($val['field'] == 'accumulation_fund') {
$person_fee = ModelLawyerCost::where($condition)->sum('accumulation_fund_person_fee');
$company_fee = ModelLawyerCost::where($condition)->sum('accumulation_fund_company_fee');
$tmp[$i] = sprintf("%.2f", ($person_fee + $company_fee));
}
//公积金个人部分
if ($val['field'] == 'accumulation_fund_person_fee') {
$person_fee = ModelLawyerCost::where($condition)->sum('accumulation_fund_person_fee');
$tmp[$i] = sprintf("%.2f", $person_fee);
}
//公积金企业部分
if ($val['field'] == 'accumulation_fund_company_fee') {
$company_fee = ModelLawyerCost::where($condition)->sum('accumulation_fund_company_fee');
$tmp[$i] = sprintf("%.2f", $company_fee);
}
//律所年检费
if ($val['field'] == 'annual_inspection_fee') {
$annual_inspection_fee = ModelLawyerCost::where($condition)->sum('annual_inspection_fee');
$tmp[$i] = $annual_inspection_fee;
}
//律所年金
if ($val['field'] == 'annuity') {
$annuity = ModelLawyerCost::where($condition)->sum('annuity');
$tmp[$i] = $annuity;
}
//贴票成本
if ($val['field'] == 'posting_tickets_fee') {
$lawyerObj = ModelLawyer::where('number', $lnum)->first();
$tickets_money = ModelLawyerCost::getPostingTicketsMoney($lawyerObj->id, $year, $lawyerObj->commission_rate, $lawyerObj->ticket_ratio, $i);
$tmp[$i] = $tickets_money;
}
//助理律师成本
if ($val['field'] == 'assistant_fee') {
$assistant_fee = ModelLawyerCost::where($condition)->sum('assistant_fee');
$tmp[$i] = $assistant_fee;
}
//办公室租赁成本
if ($val['field'] == 'office_rental_fee') {
$office_rental_fee = ModelLawyerCost::where($condition)->sum('office_rental_fee');
$tmp[$i] = $office_rental_fee;
}
//无票成本
if ($val['field'] == 'noticket_cost') {
$noticket_cost = ModelLawyerCost::where($condition)->sum('noticket_cost');
$tmp[$i] = $noticket_cost;
}
//个人所得税
if ($val['field'] == 'personal_income_tax') {
$personal_income_tax = ModelLawyerCost::where($condition)->sum('personal_income_tax');
$tmp[$i] = $personal_income_tax;
}
//总计
$tmp['total'] += $tmp[$i];
}
$data[$key] = $tmp;
}
//总计
//初始化
$heji = ['title' => '合计'];
for ($i = 0; $i <= $monthNum; $i++) {
array_push($heji, 0);
}
$heji['total'] = 0;
unset($heji[0]);
foreach ($data as $key => $item) {
if (isset($item[1])) {
$heji[1] += $item[1];
}
if (isset($item[2])) {
$heji[2] += $item[2];
}
if (isset($item[3])) {
$heji[3] += $item[3];
}
if (isset($item[4])) {
$heji[4] += $item[4];
}
if (isset($item[5])) {
$heji[5] += $item[5];
}
if (isset($item[6])) {
$heji[6] += $item[6];
}
if (isset($item[7])) {
$heji[7] += $item[7];
}
if (isset($item[8])) {
$heji[8] += $item[8];
}
if (isset($item[9])) {
$heji[9] += $item[9];
}
if (isset($item[10])) {
$heji[10] += $item[10];
}
if (isset($item[11])) {
$heji[11] += $item[11];
}
if (isset($item[12])) {
$heji[12] += $item[12];
}
if (isset($item['total'])) {
$heji['total'] += $item['total'];
}
}
array_push($data, $heji);
//转成字符串导出
foreach ($data as $kk => &$vv) {
if (isset($vv[1])) {
$vv[1] = (string)$vv[1];
}
if (isset($vv[2])) {
$vv[2] = (string)$vv[2];
}
if (isset($vv[3])) {
$vv[3] = (string)$vv[3];
}
if (isset($vv[4])) {
$vv[4] = (string)$vv[4];
}
if (isset($vv[5])) {
$vv[5] = (string)$vv[5];
}
if (isset($vv[6])) {
$vv[6] = (string)$vv[6];
}
if (isset($vv[7])) {
$vv[7] = (string)$vv[7];
}
if (isset($vv[8])) {
$vv[8] = (string)$vv[8];
}
if (isset($vv[9])) {
$vv[9] = (string)$vv[9];
}
if (isset($vv[10])) {
$vv[10] = (string)$vv[10];
}
if (isset($vv[11])) {
$vv[11] = (string)$vv[11];
}
if (isset($vv[12])) {
$vv[12] = (string)$vv[12];
}
if (isset($vv['total'])) {
$vv['total'] = (string)$vv['total'];
}
}
return $data;
}
}
...@@ -5,10 +5,8 @@ ...@@ -5,10 +5,8 @@
use App\Models\Lawyer as ModelLawyer; use App\Models\Lawyer as ModelLawyer;
use App\Models\LawyerCost as ModelLawyerCost; use App\Models\LawyerCost as ModelLawyerCost;
use App\Models\CovenantReceivePayment as ModelCovenantReceivePayment; use App\Models\CovenantReceivePayment as ModelCovenantReceivePayment;
//use Dcat\Admin\Repositories\EloquentRepository;
use Dcat\Admin\Repositories\Repository; use Dcat\Admin\Repositories\Repository;
use Dcat\Admin\Grid; use Dcat\Admin\Grid;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
class LawyerCommission extends Repository class LawyerCommission extends Repository
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
$router->resource('lycost-list', 'LawyerCostListController'); //律师成本明细 $router->resource('lycost-list', 'LawyerCostListController'); //律师成本明细
$router->resource('lycost-collect', 'LawyerCostCollectController'); //律师成本汇总 $router->resource('lycost-collect', 'LawyerCostCollectController'); //律师成本汇总
Route::get('lawyer-cost-Export', 'LawyerCostCollectController@lawyerCostExport'); //律师成本汇总导出
$router->resource('lawyer_income', 'LawyerIncomeController'); //律师创收表 $router->resource('lawyer_income', 'LawyerIncomeController'); //律师创收表
...@@ -59,6 +60,7 @@ ...@@ -59,6 +60,7 @@
$router->resource('lawyer_commission', 'LawyerCommissionController'); //律师提成表 $router->resource('lawyer_commission', 'LawyerCommissionController'); //律师提成表
$router->resource('lawyer-commission-collect', 'LawyerCommissionCollectController'); //律师提成 查看汇总 $router->resource('lawyer-commission-collect', 'LawyerCommissionCollectController'); //律师提成 查看汇总
Route::get('lawyer-commission-Export', 'LawyerCommissionCollectController@lawyerCommissionExport'); //律师提成汇总导出
$router->resource('lawyer_collect', 'LawyerCollectController'); //律师汇总表 $router->resource('lawyer_collect', 'LawyerCollectController'); //律师汇总表
......
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