添加单独水电续费

main
vine_liutk 2023-09-16 11:19:06 +08:00
parent b3fdde6cd4
commit 7a38edb865
12 changed files with 421 additions and 15 deletions

View File

@ -0,0 +1,110 @@
<?php
namespace App\Admin\Controllers;
use Slowlyo\OwlAdmin\Renderers\Page;
use Slowlyo\OwlAdmin\Renderers\Form;
use Slowlyo\OwlAdmin\Controllers\AdminController;
use App\Services\Admin\HydropowerFeeService;
use App\Models\Oldmen;
use Slowlyo\OwlAdmin\Renderers\TableColumn;
use App\Admin\Components;
/**
* 水电续费
*
* @property HydropowerFeeService $service
*/
class HydropowerFeeController extends AdminController
{
protected string $serviceName = HydropowerFeeService::class;
public function list(): Page
{
$crud = $this->baseCRUD()
->filterTogglable(false)
->headerToolbar([
$this->createButton(true, 'lg'),
...$this->baseHeaderToolBar()
])
->filter(
$this->baseFilter()->body([
amisMake()->TextControl('name', '姓名')->size('md'),
amisMake()->TextControl('card_no', '身份证')->size('md'),
amisMake()->TextControl('sn', '单据编号')->size('md'),
amis('button')->label(__('admin.reset'))->actionType('clear-and-submit'),
amis('submit')->label(__('admin.search'))->level('primary'),
])->actions([])
)
->columns([
amisMake()->TableColumn('sn', '单据编号')->sortable(),
amisMake()->TableColumn('oldman.name', '客人'),
amisMake()->TableColumn('start_at', '开始时间')->type('datetime')->sortable(true),
amisMake()->TableColumn('end_at', '结束时间')->type('datetime')->sortable(true),
amisMake()->TableColumn('money', '金额'),
amisMake()->TableColumn('created_at', '办理时间')->type('datetime')->sortable(true),
amisMake()->Operation()->label(__('admin.actions'))->buttons([
amisMake()->Button()->label('打印预览')->actionType('url')->blank(true)
->url(url('/print-water-fee').'?id=${id}')->level('link'),
$this->rowEditButton(true, 'lg'),
$this->rowDeleteButton()
]),
]);
return $this->baseList($crud);
}
public function form($isEdit = false): Form
{
return $this->baseForm()->body([
amisMake()->PickerControl('oldman_id', '姓名')
->valueField('id')
->labelField('name')
->joinValues(false)->extractValue(true)
->size('md')
->source([
'method' => 'get',
'url' => admin_url('oldmen?_action=getData&live_in='.Oldmen::STATUS_NORMAL),
'data' => [
'name'=>'${term}',
]
])
->pickerSchema(
[
'mode' => 'table',
'name' => 'monitor_list',
'headerToolbar' => amisMake()->form()
->wrapWithPanel(false)
->className('text-right')
->target('monitor_list')
->mode('inline')
->body([
amisMake()->TextControl('term', '姓名/身份证号')->addOn(
amis('submit')->label(__('admin.search'))->level('primary')
)
]),
'columns' => [
TableColumn::make()->name('name')->label('姓名'),
TableColumn::make()->name('card_no')->label('身份证号码'),
]
]
)->value(0)
->required(true),
amisMake()->GroupControl()->body([
amisMake()->DateControl('start_at', '开始时间')->format('YYYY-MM-DD 00:00:00')->required(true),
amisMake()->DateControl('end_at', '结束时间')->format('YYYY-MM-DD 23:59:59')->required(true),
]),
Components::make()->decimalControl('money', '金额')->required(true),
]);
}
public function detail(): Form
{
return $this->baseDetail()->body([
amisMake()->TextControl('id', 'ID')->static(),
amisMake()->TextControl('created_at', __('admin.created_at'))->static(),
amisMake()->TextControl('updated_at', __('admin.updated_at'))->static()
]);
}
}

View File

@ -20,7 +20,7 @@ class LiveContinueController extends AdminController
$crud = $this->baseCRUD()
->filterTogglable(false)
->headerToolbar([
amis('button')->label('续住')->icon('fa fa-plus')->actionType('link')->level('primary')->link('live-in-continue'),
amis('button')->label('续住')->icon('fa fa-plus')->actionType('link')->level('primary')->link('live-continue-do'),
])
->filter(
$this->baseFilter()->body([

View File

@ -0,0 +1,37 @@
<?php
namespace App\Filters\Admin;
use EloquentFilter\ModelFilter;
class HydropowerFeeFilter extends ModelFilter
{
/**
* oldman
*/
public function oldman($oldmanId){
return $this->where('oldman_id', $oldmanId);
}
public function sn($sn){
return $this->where('sn', $sn);
}
/**
* 名称
*/
public function name($name){
return $this->whereHas('oldman', function($q) use ($name) {
return $q->where('name', 'like', '%'.$name.'%');
});
}
/**
* 身份证
*/
public function cardNo($cardNo){
return $this->whereHas('oldman', function($q) use ($cardNo) {
return $q->where('card_no', 'like', '%'.$cardNo.'%');
});
}
}

View File

@ -2,7 +2,7 @@
namespace App\Http\Controllers;
use App\Models\ConstFlow;
use App\Models\{ConstFlow, HydropowerFee};
use Illuminate\Http\Request;
use App\Services\Admin\ConstFlowService;
@ -65,6 +65,50 @@ class PrintController extends Controller
return view('print-const', compact('name', 'time', 'idsn', 'list', 'total', 'bigTotal', 'timeZone', 'adminName'));
}
public function showWaterFee(Request $request){
$name = '';
$time = now()->format('Y-m-d H:i:s');
$sn = '';
//默认list最少N行最多N行
$list = [];
$total = 0;
$bigTotal = '';
$adminName = '';
$timeZone = '';
$flow = HydropowerFee::find($request->input('id', 0));
if($flow){
$flow->load(['oldman', 'adminuser']);
$name = $flow->oldman->name;
$time = $flow->created_at->format('Y-m-d H:i:s');
$sn = $flow->sn;
$i = 1;
$list[] = [
'fee_name' => '水电缴费',
'fee_value' => $flow->money,
];
for($i; $i<4; $i++){
$list[] = [
'fee_name' => '',
'fee_value' => 0,
];
}
if(count($list) > 0){
$total = collect($list)->sum('fee_value');
if($total > 0){
$bigTotal = $this->num2chinese($total);
}else{
$bigTotal = '负'.$this->num2chinese(abs($total));
}
}
$adminName = $flow->adminuser->name;
$timeZone = substr($flow->start_at, 0, 10).'至'.substr($flow->end_at, 0, 10);
}
return view('print-water-fee', compact('name', 'time', 'list', 'total', 'bigTotal', 'timeZone', 'adminName', 'sn'));
}
private function num2chinese($num) {
$cnNums = array(
@ -75,7 +119,7 @@ class PrintController extends Controller
$cnDecUnits = array("", "");
$cnInteger = "";
$intStr = (string)$num;
$intStr = (string)floor($num);
$len = strlen($intStr);
if ($len > 15 || $num < 0) {
return false; // 超出处理范围
@ -87,6 +131,7 @@ class PrintController extends Controller
$zeroCount = 0;
$outChinese = "";
//处理整数部分
for ($i = 0; $i < $len; $i++) {
$idx = $len - $i - 1;
$thisNum = (int)$intStr[$idx];
@ -98,18 +143,21 @@ class PrintController extends Controller
$outChinese = "" . $outChinese; // 处理零
}
$zeroCount = 0;
$outChinese = $cnNums[$thisNum] . $cnIntUnits[$i % 4] . $outChinese;
if ($i % 4 == 0) {
$outChinese = $cnIntRadice[$i / 4] . $outChinese;
if ($i > 0 && $i % 4 == 0) {
$outChinese = $cnNums[$thisNum] .$cnIntRadice[$i / 4] . $outChinese;
}else{
$outChinese = $cnNums[$thisNum] . $cnIntUnits[$i % 4] . $outChinese;
}
}
if ($zeroCount > 0) {
$outChinese = "" . $outChinese; // 处理最后的零
$outChinese = '零'.$outChinese; // 处理最后的零
}else{
$outChinese = rtrim($outChinese,'零'); // 处理最后的零
}
$outChinese .= "";
// 处理小数部分
if (strpos($num, '.') !== false) {
$decPart = substr($num, strpos($num, '.') + 1);

View File

@ -51,8 +51,8 @@ class ConstFlow extends Model
{
parent::boot();
// 监听 flow 创建事件创建sn
static::creating(function ($oldmen) {
$oldmen->sn = self::createSn();
static::creating(function ($constFlow) {
$constFlow->sn = self::createSn();
});
}

View File

@ -0,0 +1,45 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use EloquentFilter\Filterable;
use Carbon\Carbon;
use Slowlyo\OwlAdmin\OwlAdmin;
use Slowlyo\OwlAdmin\Models\AdminUser;
class HydropowerFee extends Model
{
use Filterable;
protected $fillable = [
'oldman_id', 'money', 'extends', 'start_at', 'end_at', 'sn', 'adminuser_id',
];
public function oldman(){
return $this->belongsTo(Oldmen::class, 'oldman_id');
}
public function adminuser(){
return $this->belongsTo(AdminUser::class, 'adminuser_id');
}
protected static function boot()
{
parent::boot();
// 监听 flow 创建事件创建sn
static::creating(function ($hydropowerFee) {
if(empty($hydropowerFee->sn)){
$hydropowerFee->sn = self::createSn();
}
if(empty($hydropowerFee->adminuser_id)){
$hydropowerFee->adminuser_id = OwlAdmin::user()->id;
}
});
}
private static function createSn()
{
return Carbon::now()->isoFormat('YYMMDDHHmmss').rand(1000, 9999);
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Services\Admin;
use App\Models\HydropowerFee;
use App\Filters\Admin\HydropowerFeeFilter;
/**
* 水电续费
*
* @method HydropowerFee getModel()
* @method HydropowerFee|\Illuminate\Database\Query\Builder query()
*/
class HydropowerFeeService extends BaseService
{
protected string $modelName = HydropowerFee::class;
protected string $modelFilterName = HydropowerFeeFilter::class;
protected array $withRelationships = ['oldman'];
}

View File

@ -3,7 +3,7 @@
namespace App\Services\Admin;
use App\Models\Oldmen;
use App\Models\ConstFlow;
use App\Models\{ConstFlow, HydropowerFee};
use DB;
use Throwable;
use Carbon\Carbon;
@ -76,6 +76,17 @@ class LiveContinueService extends OldmenService
'avliable_at' => $endAt,
'nurse_lv' => $newLv,
]);
//同步水电费
if(isset($feeArr['live_fee']['water_fee']) && $feeArr['live_fee']['water_fee'] > 0){
HydropowerFee::create([
'oldman_id' => $flow->oldman_id,
'start_at' => $flow->start_at,
'end_at' => $flow->end_at,
'sn' => str_pad($flow->id, 6, '0',STR_PAD_LEFT),
'adminuser_id'=> $flow->adminuser_id,
'money' => $feeArr['live_fee']['water_fee']
]);
}
DB::commit();
}catch(Throwable $th){
DB::rollBack();

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('hydropower_fees', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('oldman_id');
$table->string('sn')->comment('流水编号');
$table->timestamp('start_at')->nullable()->comment('开始时间');
$table->timestamp('end_at')->nullable()->comment('结束时间');
$table->decimal('money', 10, 2)->default(0.00)->nullable()->comment('金额');
$table->unsignedBigInteger('adminuser_id')->comment('操作人');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('hydropower_fees');
}
};

View File

@ -0,0 +1,100 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8"/>
<title>打印</title>
<style>
@media print {
@page {
margin: 0;
}
body {
margin: 0.8cm;
}
}
body {
font-family: "宋体", sans-serif;
}
.container {
/* width: 800px; */
text-align: center;
}
.tag {
overflow: hidden; /* 清除浮动 */
}
span{
display: block;
float: left;
width: 33.333%;
text-align: left;
}
span.left {
text-align: left;
}
span.right {
float: right;
text-align: left;
}
table.print-table {
width: 100%;
border-collapse:collapse;
border: 1px solid black;
margin: 0 auto;
table-layout: fixed;
}
td, th{
line-height: 30px;
border: 1px solid black;
}
</style>
</head>
<body>
<button type="button" class="print-hide" onclick="this.style.display='none';window.print();this.style.display='inline';">打印</button>
<div class="container" id="print-content">
<p style="font-size:25px;margin-top: 10px">重庆市巴南区狮子山老年公寓收据</p>
<p class="tag" style="font-size:20px;">
<span class="left">客户姓名 {{$name}}</span>
<span class="middle">日期 {{$time}}</span>
<span class="right">单据编号 {{$sn}}</span>
</p>
<table class="print-table">
<tr>
<th style="width: 5%;">序号</th>
<th style="width: 25%;">费用类别</th>
<th style="width: 30%;">起止日期</th>
<th style="width: 15%;">金额(元)</th>
<th style="width: 25%;">备注</th>
</tr>
@foreach($list as $item)
<tr>
<td>{{$loop->iteration}}</td>
<td>@if(empty($item['fee_name']))-@else{{$item['fee_name']}}@endif</td>
<td>@if(empty($item['fee_name']))-@else<input type="text" style="border:none" value="{{$timeZone}}">@endif</td>
<td>{{$item['fee_value']}}</td>
<td>
<input type="text" style="border:none">
</td>
</tr>
@endforeach
<tr>
<td colspan="3" style=" text-align: left;">合计大写:{{$bigTotal}}</td>
<td >{{$total}}</td>
<td ></td>
</tr>
</table>
<p class="tag" style="font-size:20px;">
<span class="left">单位盖章 </span>
<span class="middle"> </span>
<span class="right">收款人 {{$adminName}}</span>
</p>
<p class="tag" style="font-size:20px;">
<span class="left">白联:存根</span>
<span class="middle">红联:客户</span>
<span class="right">黄联:记账</span>
</p>
</div>
</body>
<script>
</script>
</html>

View File

@ -10,7 +10,7 @@ Route::group([
'prefix' => config('admin.route.prefix'),
'middleware' => config('admin.route.middleware'),
], function (Router $router) {
// 用明细
$router->resource('const_flows', \App\Admin\Controllers\ConstFlowController::class);
// 水电续
$router->resource('hydropower_fees', \App\Admin\Controllers\HydropowerFeeController::class);
});

View File

@ -16,4 +16,5 @@ use Illuminate\Support\Facades\Route;
Route::redirect('/', '/admin', 302);
Route::get('/print-const-flow', [PrintController::class, 'showConst']);
Route::get('/print-const-flow', [PrintController::class, 'showConst']);
Route::get('/print-water-fee', [PrintController::class, 'showWaterFee']);