master
cody 2 years ago
parent d0fe26edc5
commit ae0a279cf9

@ -527,4 +527,68 @@ class StatisticsController extends CommonController
return view($this->bladePath . ".bed", compact("area", "orderTotal", "totalBed", "project", "project_id", "month", "projects"));
}
/**
* 收入统计
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function income()
{
$is_export = \request('is_export', 0);
$projects = $this->_checkProjects();
if (!$projects->count()) {
return $this->error($this->noProjects);
}
$project_id = request()->project_id ?? $projects->first()->id;
$project = Project::find($project_id);
$month = request()->month ?? date("Y-m");
$months = $this->_getMonths();
// 当月天数
$days = date('t', strtotime($month));
$area = Area::withCount('beds')->where('project_id', $project_id)->get();
$beds = Bed::whereIn('area_id', $area->pluck('id'))->where('project_id', $project_id)->get();
$totalBed = $beds->count();
// 订单总数
$orderTotal = Orders::where('project_id', $project_id)
->where('created_at', 'like', '%' . $month . '%')
->whereIn('bed_id', $beds->pluck('id'))
->sum('total');
foreach ($area as $item) {
$item->order_total = $orderTotal;
$item->shouxufei = $orderTotal * 0.006;
$item->zengshishui = $orderTotal * 0.06;
$item->shijishouru = $orderTotal - $item->shouxufei - $item->zengshishui;
$item->guanlifei = $item->shijishouru * 0.06;
}
// 导出
if ($is_export) {
$area = $area->toArray();
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', '病区');
$sheet->setCellValue('B1', '护理费用(元)');
$sheet->setCellValue('C1', '手续费0.6%');
$sheet->setCellValue('D1', '增值税6%');
$sheet->setCellValue('E1', '实际收入(元)');
$sheet->setCellValue('F1', '院方管理费6%');
$count = count($area); //计算有多少条数据
for ($i = 2; $i <= $count + 1; $i++) {
$sheet->setCellValue('A' . $i, $area[$i - 2]['name']);
$sheet->setCellValue('B' . $i, $area[$i - 2]['order_total']);
$sheet->setCellValue('C' . $i, $area[$i - 2]['shouxufei']);
$sheet->setCellValue('D' . $i, $area[$i - 2]['zengshishui']);
$sheet->setCellValue('E' . $i, $area[$i - 2]['shijishouru']);
$sheet->setCellValue('F' . $i, $area[$i - 2]['guanlifei']);
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $project->name . '_' . date('YmdHis') . '.xlsx"');
header('Cache-Control: max-age=0');
$writer = new Xlsx($spreadsheet);
$writer->save('php://output');
exit;
}
return view($this->bladePath . ".bed", compact("area", "orderTotal", "totalBed", "project", "project_id", "month", "projects"));
}
}

@ -0,0 +1,68 @@
@extends("admin.layouts.layout")
@push("header")
@endpush
@section("content")
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body" style="overflow: auto">
<div class="mb-3">
<form class="form-inline">
<select class="form-control mr-1" name="project_id"
onchange="$(this).closest('form').submit()">
@foreach($projects as $pp)
<option
value="{{$pp->id}}" @if($pp->id == $project_id) {{ "selected" }}@endif>{{$pp->name}}</option>
@endforeach
</select>
<select class="form-control" name="month" onchange="$(this).closest('form').submit()">
@foreach($months as $mm)
<option value="{{$mm}}" @if($mm == $month) {{ "selected" }}@endif>{{$mm}}</option>
@endforeach
</select>
<button class="btn btn-primary ml-1" type="button" onclick="doExport(this)">导出</button>
</form>
</div>
<table class="table table-bordered mb-0 table-datatable">
<thead>
<tr>
<th class="p-1" style="white-space: nowrap">病区</th>
<th class="p-1" style="white-space: nowrap">护理费用(元)</th>
<th class="p-1" style="white-space: nowrap">手续费0.6%</th>
<th class="p-1" style="white-space: nowrap">增值税6%</th>
<th class="p-1" style="white-space: nowrap">实际收入(元)</th>
<th class="p-1" style="white-space: nowrap">院方管理费6%</th>
</tr>
</thead>
<tbody>
@foreach ($area as $row)
<tr>
<td>{{ $row->name }}</td>
<td>{{ $row->order_total }}</td>
<td>{{ $row->shouxufei }}</td>
<td>{{ $row->zengshishui }}</td>
<td>{{ $row->shijishouru }}</td>
<td>{{ $row->guanlifei }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
function doExport(ele) {
var url = "{{ url("admin/statistics/bed") }}";
url += "?is_export=1";
var params = $(ele).closest("form").serialize();
url += "&" + params;
window.open(url);
}
</script>
@endsection

@ -96,6 +96,8 @@ Route::group(["namespace" => "Admin", "prefix" => "admin"], function () {
Route::get("orders/artboard", 'OrdersController@artboard');
Route::get("statistics/bed", 'StatisticsController@bed');
Route::get("statistics/income", 'StatisticsController@income');
Route::get("statistics/huli", 'StatisticsController@huli');
Route::get("statistics/overview", 'StatisticsController@overview');
Route::get("statistics/salary", 'StatisticsController@salary');

Loading…
Cancel
Save