feat(工资): 添加已发字段 修改状态描述

master
yin5th 2023-01-14 14:24:14 +08:00
parent b8ebcd8b5e
commit 5c7d421225
3 changed files with 33 additions and 30 deletions

View File

@ -573,6 +573,8 @@ class Manager extends Base
$status = input('status/d', -1); $status = input('status/d', -1);
$date = input('date/s', ''); $date = input('date/s', '');
$status = $status ?: -1;
$accountId = $this->request->user['user_id'] ?? 0; $accountId = $this->request->user['user_id'] ?? 0;
$where = []; $where = [];
@ -605,16 +607,14 @@ class Manager extends Base
->where($where); ->where($where);
// 汇总信息 // 汇总信息
$info = $query->fieldRaw('sum(pml.amount) as amount, sum(pml.base_amount) as base_amount, $info = $query->fieldRaw('sum(pml.amount) as amount, sum(pml.base_amount) as base_amount,
sum(pml.overtime_amount) as overtime_amount')->find()->toArray(); sum(pml.overtime_amount) as overtime_amount,sum(pml.paid_amount) as paid_amount')->find()->toArray();
// 已发放工资
$doneAmount = $query->where('pml.status', 1)->fieldRaw('sum(pml.amount) as amount')->find()->toArray();
$res['info'] = [ $res['info'] = [
'amount' => $info['amount'] ?? 0, 'amount' => $info['amount'] ?? 0,
'base_amount' => $info['base_amount'] ?? 0, 'base_amount' => $info['base_amount'] ?? 0,
'overtime_amount' => $info['overtime_amount'] ?? 0, 'overtime_amount' => $info['overtime_amount'] ?? 0,
'done_amount' => $doneAmount['amount'] ?? 0, 'done_amount' => $info['paid_amount'] ?? 0,
'not_amount' => Math::sub($info['amount'] ?? 0, $doneAmount['amount'] ?? 0), 'not_amount' => Math::sub($info['amount'] ?? 0, $info['paid_amount'] ?? 0),
]; ];
if ($status >= 0) { if ($status >= 0) {
@ -629,9 +629,20 @@ class Manager extends Base
$res['total'] = $total; $res['total'] = $total;
if ($total > 0) { if ($total > 0) {
$res['list'] = $query->field('pml.id,pml.status,pml.amount,pml.base_amount,pml.overtime_amount,a.real_name as name')->page($page, $size)->order('pml.id', 'desc')->select(); $res['list'] = $query->field('pml.id,pml.status,pml.amount,pml.base_amount,pml.overtime_amount,pml.paid_amount,a.real_name as name')->page($page, $size)->order('pml.id', 'desc')->select();
$res['list']->each(function ($item) { $res['list']->each(function ($item) {
$item->status_text = $item->status == 1 ? '已发放' : '待发放'; $item->status = 0;
$item->status_text = '待发放';
if ($item['amount'] == $item['paid_amount'] && $item['amount'] > 0) {
$item->status_text = '完全发放';
$item->status = 1;
}
if ($item['amount'] > $item['paid_amount'] && $item['paid_amount'] > 0) {
$item->status_text = '部分发放';
$item->status = 2;
}
}); });
} }

View File

@ -175,8 +175,8 @@ class Worker extends Base
$arr = explode('-', $params['value']); $arr = explode('-', $params['value']);
$customer->save([ $customer->save([
'province' => $arr[0] ?? '', 'province' => $arr[0] ?? '',
'city' => $arr[1] ?? '', 'city' => $arr[1] ?? '',
'area' => $arr[2] ?? '', 'area' => $arr[2] ?? '',
]); ]);
} else { } else {
$customer->save([ $customer->save([
@ -564,7 +564,7 @@ class Worker extends Base
->leftJoin('account a', 'a.id = pml.account_id') ->leftJoin('account a', 'a.id = pml.account_id')
->where($where) ->where($where)
->group('pml.time') ->group('pml.time')
->fieldRaw('pml.time,pml.year,pml.month,sum(pml.amount) as amount,sum(pml.base_amount) as base_amount,sum(pml.overtime_amount) as overtime_amount'); ->fieldRaw('pml.time,pml.year,pml.month,sum(pml.amount) as amount,sum(pml.base_amount) as base_amount,sum(pml.overtime_amount) as overtime_amount,sum(pml.paid_amount) as paid_amount');
$total = $query->count(); $total = $query->count();
@ -576,30 +576,21 @@ class Worker extends Base
]; ];
if ($total > 0) { if ($total > 0) {
// 获取按月已发工资
$paidMonth = \app\model\PayMonthLog::alias('pml')
->leftJoin('account a', 'a.id = pml.account_id')
->where($where)
->where('pml.status', 1)
->group('pml.time')
->page($page, $size)
->order('time', 'desc')
->fieldRaw('sum(pml.amount) as amount,pml.time')
->select()->toArray();
$monthPay = [];
foreach ($paidMonth as $p) {
$monthPay[$p['time']] = $p['amount'];
}
$res['list'] = $query->page($page, $size)->order('time', 'desc')->select(); $res['list'] = $query->page($page, $size)->order('time', 'desc')->select();
$res['list']->each(function ($item) use ($monthPay) { $res['list']->each(function ($item) {
$item->date = $item['year'].'年'.$item['month'].'月'; $item->date = $item['year'].'年'.$item['month'].'月';
$item->done = $monthPay[$item->time] ?? 0; // $item->done = $monthPay[$item->time] ?? 0;
$item->status = 0; $item->status = 0;
$item->status_text = '待发放'; $item->status_text = '待发放';
if ($item->amount <= $item->done) {
if ($item['amount'] == $item['paid_amount'] && $item['amount'] > 0) {
$item->status_text = '完全发放';
$item->status = 1; $item->status = 1;
$item->status_text = '已发放'; }
if ($item['amount'] > $item['paid_amount'] && $item['paid_amount'] > 0) {
$item->status_text = '部分发放';
$item->status = 2;
} }
unset($item->year); unset($item->year);
unset($item->month); unset($item->month);

View File

@ -281,6 +281,7 @@ class Pay extends Base
->page($page, $size)->order('pml.time', 'desc')->order('pml.id', 'desc')->select(); ->page($page, $size)->order('pml.time', 'desc')->order('pml.id', 'desc')->select();
$res['list']->each(function ($item) { $res['list']->each(function ($item) {
$item->status_text = '待发放'; $item->status_text = '待发放';
if ($item['amount'] == $item['paid_amount'] && $item['amount'] > 0) { if ($item['amount'] == $item['paid_amount'] && $item['amount'] > 0) {
$item->status_text = '完全发放'; $item->status_text = '完全发放';
} }