1
0
Fork 0
medical-record-server/app/Admin/Controllers/TotalRecordController.php

86 lines
4.2 KiB
PHP

<?php
namespace App\Admin\Controllers;
use Slowlyo\OwlAdmin\Controllers\AdminController;
use App\Models\{Patient, PatientRecord};
use Illuminate\Support\Facades\DB;
use App\Admin\Services\TotalRecordService;
/**
* 财务统计
*/
class TotalRecordController extends AdminController
{
protected string $serviceName = TotalRecordService::class;
protected $patientOptions;
// public function index()
// {
// $list = PatientRecord::with(['patient'])->filter(request()->all())->groupBy('patient_id')->select([
// 'patient_id',
// DB::raw('count(1) as count'),
// DB::raw('sum(`origin_price`) as `origin_price`'),
// DB::raw('sum(`sell_price`) as `sell_price`'),
// ])->get();
// if ($this->actionOfGetData()) {
// return $this->response()->success(['items' => $list]);
// }
// return $this->response()->success($this->basePage()->data(['items' => $list])->className('cxd-Crud')->body([
// $this->baseFilter()->actions()->mode('inline')->body([
// amisMake()->SelectControl()->options($this->getPatientOptions())->searchable()->name('patient_id')->label(__('patient_record.patient_id'))->size('md')->clearable(),
// amisMake()->DateRangeControl()->name('treat_range')->label(__('total-record.treat_at'))->clearable()->size('md'),
// amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
// ]),
// amisMake()->Table()->affixHeader(false)->source('${items}')->columns([
// amisMake()->Column()->name('patient.name')->label(__('total-record.name')),
// amisMake()->Column()->name('count')->label(__('total-record.count')),
// amisMake()->Column()->name('origin_price')->label(__('total-record.origin_price')),
// amisMake()->Column()->name('sell_price')->label(__('total-record.sell_price')),
// ]),
// ]));
// }
public function list()
{
$crud = $this->baseCRUD()
->filterTogglable(false)
->columnsTogglable(false)
->headerToolbar([
// amis('reload')->align('right'),
])
->filter($this->baseFilter()->actions()->body([
amisMake()->SelectControl()->options($this->getPatientOptions())->searchable()->name('patient_id')->label(__('patient-record.patient_id'))->size('md')->clearable(),
amisMake()->DateRangeControl()->name('treat_range')->label(__('total-record.treat_at'))->clearable()->size('md'),
// amisMake()->Button()->label(__('admin.reset'))->actionType('clear-and-submit'),
amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
]))
->columns([
amisMake()->Column()->name('patient.name')->label(__('total-record.name')),
amisMake()->Date()->name('min_treat_at')->label(__('total-record.min_treat_at'))->sortable(true),
amisMake()->Date()->name('max_treat_at')->label(__('total-record.max_treat_at'))->sortable(true),
amisMake()->Column()->name('count')->label(__('total-record.count'))->sortable(true),
amisMake()->Column()->name('origin_price')->label(__('total-record.origin_price'))->sortable(true),
amisMake()->Column()->name('sell_price')->label(__('total-record.sell_price'))->sortable(true),
])->affixRowClassName('text-info-dk')->affixRow([
['type' => 'text', 'text' => '总计', 'colSpan' => 3],
['type' => 'text', 'text' => '记录数: ${total}'],
['type' => 'text', 'text' => __('total-record.origin_price') . ': ${origin_price}'],
['type' => 'text', 'text' => __('total-record.sell_price') . ': ${sell_price}'],
]);
return $this->baseList($crud);
}
public function getPatientOptions()
{
if (!$this->patientOptions) {
$this->patientOptions = Patient::select(['id as value', 'name as label'])->sort()->get();
}
return $this->patientOptions;
}
}