diff --git a/application/admin/controller/salary/Detail.php b/application/admin/controller/salary/Detail.php index 7a0ac7f..fcbdd29 100644 --- a/application/admin/controller/salary/Detail.php +++ b/application/admin/controller/salary/Detail.php @@ -43,7 +43,7 @@ class Detail extends Backend //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); - $items = Db::name('salary_item')->field('id,attr,name')->select(); + $items = Db::name('salary_item')->field('id,attr,type,name')->select(); $salaryItem = []; foreach ($items as $item) { @@ -106,6 +106,7 @@ class Detail extends Backend foreach ($adminIds as $adminId) { $attrValue = []; + $total = 0; foreach ($items as $item) { $res[$adminId]['admin_id'] = $adminId; @@ -114,9 +115,10 @@ class Detail extends Backend $itemKey = 'item_' . $item['id']; - if (isset($queryRes[$adminId][$item['id']])) { + if (!empty($queryRes[$adminId][$item['id']])) { $res[$adminId][$itemKey] = $this->clean_number($queryRes[$adminId][$item['id']]); $attrValue[$idAttr[$item['id']]] = $queryRes[$adminId][$item['id']]; + $total = $this->calc_total($total, $item['type'], $queryRes[$adminId][$item['id']]); continue; } @@ -124,12 +126,9 @@ class Detail extends Backend $res[$adminId][$itemKey] = 0; } - $jxTotal = ($attrValue['ZWJX'] - $attrValue['YYCB']) * $attrValue['TD']; - $res[$adminId]['jx_total'] = $this->clean_number($jxTotal); - $res[$adminId]['total'] = $this->clean_number(($attrValue['JBGZ'] + $attrValue['JBBZ'] + $attrValue['GWJT'] + $jxTotal + $attrValue['JXKHJL'] + $attrValue['QQ']) - - ($attrValue['SBJ'] + $attrValue['BX'] + $attrValue['KK'] + $attrValue['CDWDK'])); + $res[$adminId]['total'] = $this->clean_number($total + $jxTotal); } $res = array_values($res); @@ -145,6 +144,17 @@ class Detail extends Backend return $this->view->fetch(); } + public function calc_total($total, $type, $value){ + if ($type == 1) { + return $total + $value; + } + if ($type == 2) { + return $total - $value; + } + + return $total; + } + public function clean_number($num): string { return rtrim(rtrim(number_format($num, 10, '.', ''), '0'), '.'); } @@ -211,7 +221,7 @@ class Detail extends Backend ->where('salary_month', '=', $month) ->where('target_admin_id', $targetAdminId) ->select(); - $items = Db::name('salary_item')->field('id,name')->select(); + $items = Db::name('salary_item')->field('id,name,type')->select(); $queryData = array_column($queryData, NULL, 'item_id'); foreach ($items as $item) { @@ -219,8 +229,19 @@ class Detail extends Backend $row[$itemKey] = !empty($queryData[$item['id']]) ? $queryData[$item['id']]['item_value'] : 0; } + $typeMap = [ + 1 => '应发工资', + 2 => '应扣款项', + 3 => '其他' + ]; + $groupedItems = []; + foreach ($items as $item) { + $type = $item['type']; + $label = $typeMap[$type]; + $groupedItems[$label][] = $item; + } - $items = Db::name('salary_item')->field('id,name')->select(); + $this->view->assign('groupedItems', $groupedItems); $this->view->assign('items', $items); $this->view->assign('row', $row); return $this->view->fetch(); diff --git a/application/admin/view/salary/detail/custom_edit.html b/application/admin/view/salary/detail/custom_edit.html index ed6f0c8..9696b96 100644 --- a/application/admin/view/salary/detail/custom_edit.html +++ b/application/admin/view/salary/detail/custom_edit.html @@ -12,14 +12,22 @@ - {foreach $items as $item} -
- -
- -
+ {foreach $groupedItems as $groupName => $group} +
+
+ + {foreach $group as $index => $item} + {if $index % 2 == 0}
{/if} + +
+ +
+ {if $index % 2 == 1 || $index == count($group) - 1}
{/if} {/foreach} + {/foreach} + +