feature: 工资管理

This commit is contained in:
zhuyu 2025-05-29 15:30:21 +08:00
parent 60960debe7
commit 448e878813
2 changed files with 43 additions and 14 deletions

View File

@ -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();

View File

@ -12,14 +12,22 @@
<input id="c-salary_month" readonly="readonly" class="form-control datetimepicker" data-date-format="YYYY-MM" data-use-current="true" name="row[salary_month]" type="text" value="{$row.salary_month|htmlentities}">
</div>
</div>
{foreach $items as $item}
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{$item['name']}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-item_value" class="form-control" step="0.01" name="row[item_{$item['id']}]" type="number" value="{$row['item_' . $item.id]|htmlentities}">
{foreach $groupedItems as $groupName => $group}
<div class="form-group" style="border-top: 1px solid #ddd; padding-top: 10px; margin-top: 20px;">
<label class="control-label col-xs-12 col-sm-2 text-left" style="font-weight: bold;">{$groupName}</label>
</div>
{foreach $group as $index => $item}
{if $index % 2 == 0}<div class="form-group">{/if}
<label class="control-label col-xs-12 col-sm-2">{$item.name}:</label>
<div class="col-xs-12 col-sm-5">
<input class="form-control" step="0.01" name="row[item_{$item.id}]" type="number" value="{$row['item_' . $item.id]|htmlentities}">
</div>
{if $index % 2 == 1 || $index == count($group) - 1}</div>{/if}
{/foreach}
{/foreach}
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>