liyinglin 2 years ago
parent 4f28be262d
commit 4ae241231c

@ -29,6 +29,8 @@ use App\Scopes\AdminProjectScope;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Spatie\Permission\Models\Role;
class StatisticsController extends CommonController
@ -448,6 +450,7 @@ class StatisticsController extends CommonController
*/
public function bed()
{
$is_export = \request('is_export',0);
$projects = $this->_checkProjects();
if (!$projects->count()) {
return $this->error($this->noProjects);
@ -483,6 +486,33 @@ class StatisticsController extends CommonController
$item->rate = round($item->order_total / $bedsIdTemp->count(), 4) * 100;
}
}
// 导出
if($is_export){
$area = $area->toArray();
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', '病区');
$sheet->setCellValue('B1', '床位数量');
$sheet->setCellValue('C1', '床位占比');
$sheet->setCellValue('D1', '订单数量');
$sheet->setCellValue('E1', '护工配比');
$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]['beds_count']);
$sheet->setCellValue('C' . $i, $area[$i - 2]['bed_rate']);
$sheet->setCellValue('D' . $i, $area[$i - 2]['order_total']);
$sheet->setCellValue('E' . $i, $area[$i - 2]['rate']);
}
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"));
}

@ -23,6 +23,7 @@
<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">
@ -52,4 +53,13 @@
</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

Loading…
Cancel
Save