|
|
@@ -113,6 +113,7 @@ class ReportingWork extends Api
|
|
|
* @ApiMethod (GET)
|
|
|
* @param string $part_code 部件编号
|
|
|
* @param string $workorder 工单编号
|
|
|
+ * @param string $sys_id 小组名称(可选,传了则返回本组完成数)
|
|
|
* @return array
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
@@ -130,6 +131,7 @@ class ReportingWork extends Api
|
|
|
if (empty($params['part_code'])) {
|
|
|
$this->error('部件编号不能为空');
|
|
|
}
|
|
|
+ $sysId = isset($params['sys_id']) ? trim((string)$params['sys_id']) : '';
|
|
|
$orderInfo = db('工单_基本资料')
|
|
|
->where('订单编号', $params['workorder'])
|
|
|
->whereNull('Mod_rq')
|
|
|
@@ -140,13 +142,15 @@ class ReportingWork extends Api
|
|
|
->where('work_order', $params['workorder'])
|
|
|
->where('part_code', $params['part_code'])
|
|
|
->whereNull('del_rq')
|
|
|
- // ->where('status', 0)
|
|
|
+ // 已拆分母工序 status=1 不展示,仅返回可报工工序 status=0
|
|
|
+ ->where('status', 0)
|
|
|
->field('process_code as 工艺编号,process_name as 工艺名称,standard_hour as 标准工时,standard_minutes as 标准分钟,
|
|
|
- standard_score as 标准工分,coefficient as 系数,remark as 备注,money as 金额')
|
|
|
+ standard_score as 标准工分,coefficient as 系数,remark as 备注,money as 金额,status')
|
|
|
->select();
|
|
|
usort($data, function ($a, $b) {
|
|
|
return strnatcmp((string)$a['工艺编号'], (string)$b['工艺编号']);
|
|
|
});
|
|
|
+ // 累计完成数:全部小组
|
|
|
$reportList = db('设备_工分计酬')
|
|
|
->where('work_order', $params['workorder'])
|
|
|
->where('part_code', $params['part_code'])
|
|
|
@@ -158,11 +162,30 @@ class ReportingWork extends Api
|
|
|
foreach ($reportList as $report) {
|
|
|
$completedMap[trim((string)$report['process_code'])] = floatval($report['completed_qty']);
|
|
|
}
|
|
|
+
|
|
|
+ // 本组完成数:按 sys_id(小组名称)过滤
|
|
|
+ $groupCompletedMap = [];
|
|
|
+ if ($sysId !== '') {
|
|
|
+ $groupReportList = db('设备_工分计酬')
|
|
|
+ ->where('work_order', $params['workorder'])
|
|
|
+ ->where('part_code', $params['part_code'])
|
|
|
+ ->where('sys_id', $sysId)
|
|
|
+ ->whereNull('del_rq')
|
|
|
+ ->field('process_code, SUM(number) as completed_qty')
|
|
|
+ ->group('process_code')
|
|
|
+ ->select();
|
|
|
+ foreach ($groupReportList as $report) {
|
|
|
+ $groupCompletedMap[trim((string)$report['process_code'])] = floatval($report['completed_qty']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
foreach ($data as $key => $row) {
|
|
|
$processCode = trim((string)$row['工艺编号']);
|
|
|
$completedQty = $completedMap[$processCode] ?? 0;
|
|
|
+ $groupCompletedQty = $groupCompletedMap[$processCode] ?? 0;
|
|
|
$data[$key]['制造数量'] = $manufactureQty;
|
|
|
$data[$key]['累计完成数'] = $completedQty;
|
|
|
+ $data[$key]['本组完成数'] = $groupCompletedQty;
|
|
|
$data[$key]['未完成数'] = floatval($manufactureQty) - $completedQty;
|
|
|
}
|
|
|
$this->success('成功', $data);
|
|
|
@@ -212,6 +235,7 @@ class ReportingWork extends Api
|
|
|
$insertData = [];
|
|
|
$logList = [];
|
|
|
$now = date('Y-m-d H:i:s');
|
|
|
+
|
|
|
foreach ($reportList as $idx => $item) {
|
|
|
$rowNo = $idx + 1;
|
|
|
if (empty($item['staff_no'])) {
|
|
|
@@ -233,77 +257,91 @@ class ReportingWork extends Api
|
|
|
if (empty($item['process_code'])) {
|
|
|
$this->error('第' . $rowNo . '条工艺编号不能为空');
|
|
|
}
|
|
|
- if (empty($item['process_name'])) {
|
|
|
- $this->error('第' . $rowNo . '条工艺名称不能为空');
|
|
|
- }
|
|
|
- // if (!isset($item['standard_hour']) || $item['standard_hour'] === '') {
|
|
|
- // $this->error('第' . $rowNo . '条标准工时不能为空');
|
|
|
- // }
|
|
|
- // if (!isset($item['money']) || $item['money'] === '') {
|
|
|
- // $this->error('第' . $rowNo . '条金额不能为空');
|
|
|
- // }
|
|
|
- // if (empty($item['standard_minutes'])) {
|
|
|
- // $this->error('第' . $rowNo . '条标准分钟不能为空');
|
|
|
- // }
|
|
|
- if (!isset($item['standard_score']) || $item['standard_score'] === '') {
|
|
|
- $this->error('第' . $rowNo . '条标准工分不能为空');
|
|
|
- }
|
|
|
if (!isset($item['number']) || $item['number'] === '') {
|
|
|
$this->error('第' . $rowNo . '条产量不能为空');
|
|
|
}
|
|
|
|
|
|
- $standardHour = floatval($item['standard_hour']);
|
|
|
- $standardScore = floatval($item['standard_score']);
|
|
|
- $money = floatval($item['money']);
|
|
|
- $coefficient = isset($item['coefficient']) && $item['coefficient'] !== '' ? floatval($item['coefficient']) : 'C';
|
|
|
- $number = floatval($item['number']);
|
|
|
- $standardMinutes = floatval($item['standard_minutes']);
|
|
|
- $productionHour = $standardHour * $number;
|
|
|
- $productionScore = $standardScore * $number;
|
|
|
- $salary = $this->calcReportSalary($number, $standardScore);
|
|
|
+ $workOrder = !empty($item['work_order']) ? trim((string)$item['work_order']) : trim((string)$item['workorder']);
|
|
|
+ $processCode = trim((string)$item['process_code']);
|
|
|
$partCode = null;
|
|
|
if (isset($item['part_code']) && $item['part_code'] !== '') {
|
|
|
$partCode = intval($item['part_code']);
|
|
|
}
|
|
|
+ $number = floatval($item['number']);
|
|
|
+ if ($number <= 0) {
|
|
|
+ $this->error('第' . $rowNo . '条产量必须大于0');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验工序在工艺资料中仍存在,并以工艺表为准写入名称/工分(避免前端缓存旧数据)
|
|
|
+ $processQuery = db('工单_基础工艺资料')
|
|
|
+ ->where('work_order', $workOrder)
|
|
|
+ ->where('process_code', $processCode)
|
|
|
+ ->whereNull('del_rq');
|
|
|
+ if ($partCode !== null) {
|
|
|
+ $processQuery->where('part_code', $partCode);
|
|
|
+ }
|
|
|
+ $processInfo = $processQuery
|
|
|
+ ->field('process_code,process_name,part_code,standard_hour,standard_minutes,standard_score,money,coefficient,big_process')
|
|
|
+ ->find();
|
|
|
+ if (empty($processInfo)) {
|
|
|
+ $this->error('第' . $rowNo . '条工序不存在或已删除(订单' . $workOrder . ' 工序号' . $processCode
|
|
|
+ . ($partCode !== null ? ' 部件' . $partCode : '') . '),请刷新工艺后重试');
|
|
|
+ }
|
|
|
+
|
|
|
+ $processName = trim((string)$processInfo['process_name']);
|
|
|
+ $standardHour = floatval($processInfo['standard_hour']);
|
|
|
+ $standardScore = floatval($processInfo['standard_score']);
|
|
|
+ $standardMinutes = floatval($processInfo['standard_minutes']);
|
|
|
+ $money = floatval($processInfo['money']);
|
|
|
+ $coefficient = isset($processInfo['coefficient']) && $processInfo['coefficient'] !== ''
|
|
|
+ ? $processInfo['coefficient']
|
|
|
+ : (isset($item['coefficient']) && $item['coefficient'] !== '' ? $item['coefficient'] : 'C');
|
|
|
+ if ($partCode === null && isset($processInfo['part_code']) && $processInfo['part_code'] !== '') {
|
|
|
+ $partCode = intval($processInfo['part_code']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $productionHour = round($standardHour * $number, 2);
|
|
|
+ $productionScore = round($standardScore * $number, 2);
|
|
|
+ $salary = $this->calcReportSalary($number, $standardScore);
|
|
|
+ $sysId = isset($item['sys_id']) ? trim((string)$item['sys_id']) : '';
|
|
|
|
|
|
$insertData[] = [
|
|
|
'staff_no' => $item['staff_no'],
|
|
|
'staff_name' => $item['staff_name'],
|
|
|
- 'work_order' => !empty($item['work_order']) ? $item['work_order'] : $item['workorder'],
|
|
|
+ 'work_order' => $workOrder,
|
|
|
'date' => !empty($item['date']) ? $item['date'] : date('Y-m-d'),
|
|
|
'majorprocess' => $item['majorprocess'],
|
|
|
'part_code' => $partCode,
|
|
|
- 'process_code' => $item['process_code'],
|
|
|
- 'process_name' => $item['process_name'],
|
|
|
+ 'process_code' => $processCode,
|
|
|
+ 'process_name' => $processName,
|
|
|
'standard_hour' => $standardHour,
|
|
|
'standard_score' => $standardScore,
|
|
|
'standard_minutes' => $standardMinutes,
|
|
|
'money' => $money,
|
|
|
'coefficient' => $coefficient,
|
|
|
'number' => $number,
|
|
|
- 'production_hour' => round($productionHour, 4),
|
|
|
- 'production_score' => round($productionScore, 4),
|
|
|
+ 'production_hour' => $productionHour,
|
|
|
+ 'production_score' => $productionScore,
|
|
|
'salary' => $salary,
|
|
|
- 'machine' => isset($item['machine']) ? $item['machine'] : '',
|
|
|
- 'sys_id' => isset($item['sys_id']) ? $item['sys_id'] : '',
|
|
|
+ 'machine' => isset($item['machine']) ? trim((string)$item['machine']) : '',
|
|
|
+ 'sys_id' => $sysId,
|
|
|
'sys_rq' => $now,
|
|
|
'mod_id' => isset($item['mod_id']) ? $item['mod_id'] : '',
|
|
|
'mod_rq' => null,
|
|
|
'del_rq' => null,
|
|
|
];
|
|
|
- $workOrder = !empty($item['work_order']) ? $item['work_order'] : $item['workorder'];
|
|
|
$logList[] = $this->buildReportingWorkLogRow([
|
|
|
'oper_type' => '新增报工',
|
|
|
- 'oper_user' => isset($item['sys_id']) ? $item['sys_id'] : '',
|
|
|
+ 'oper_user' => $sysId !== '' ? $sysId : (isset($item['mod_id']) ? $item['mod_id'] : ''),
|
|
|
'oper_time' => $now,
|
|
|
'work_order' => $workOrder,
|
|
|
'majorprocess' => $item['majorprocess'],
|
|
|
'part_code' => $partCode,
|
|
|
- 'process_code' => $item['process_code'],
|
|
|
- 'process_name' => $item['process_name'],
|
|
|
+ 'process_code' => $processCode,
|
|
|
+ 'process_name' => $processName,
|
|
|
'staff_no' => $item['staff_no'],
|
|
|
'staff_name' => $item['staff_name'],
|
|
|
- 'machine' => isset($item['machine']) ? $item['machine'] : '',
|
|
|
+ 'machine' => isset($item['machine']) ? trim((string)$item['machine']) : '',
|
|
|
'report_date' => !empty($item['date']) ? $item['date'] : date('Y-m-d'),
|
|
|
], '数量', '', (string)$number);
|
|
|
}
|
|
|
@@ -478,11 +516,14 @@ class ReportingWork extends Api
|
|
|
}
|
|
|
|
|
|
$number = floatval($params['number']);
|
|
|
+ if ($number <= 0) {
|
|
|
+ $this->error('产量必须大于0');
|
|
|
+ }
|
|
|
$standardHour = floatval($record['standard_hour']);
|
|
|
$standardScore = floatval($record['standard_score']);
|
|
|
|
|
|
- $productionHour = round($standardHour * $number, 4);
|
|
|
- $productionScore = round($standardScore * $number, 4);
|
|
|
+ $productionHour = round($standardHour * $number, 2);
|
|
|
+ $productionScore = round($standardScore * $number, 2);
|
|
|
$salary = $this->calcReportSalary($number, $standardScore);
|
|
|
$operTime = date('Y-m-d H:i:s');
|
|
|
$operUser = !empty($params['mod_id']) ? $params['mod_id'] : ($record['sys_id'] ?? '');
|
|
|
@@ -740,7 +781,7 @@ class ReportingWork extends Api
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 按新公式批量重算历史报工工资(数量 × 工分 × 0.067)
|
|
|
+ * 按新公式批量重算历史报工工资(数量 × 工分 × 0.067,保留2位)
|
|
|
* @ApiMethod (POST)
|
|
|
* @param string workorder 可选,限定工单编号
|
|
|
* @param string date_start 可选,报工日期起(Y-m-d)
|
|
|
@@ -774,8 +815,8 @@ class ReportingWork extends Api
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
$affected = $applyFilters(Db::table('设备_工分计酬')->whereNull('del_rq'))->update([
|
|
|
- 'production_score' => Db::raw('ROUND(`number` * `standard_score`, 4)'),
|
|
|
- 'salary' => Db::raw('ROUND(`number` * `standard_score` * 0.067, 4)'),
|
|
|
+ 'production_score' => Db::raw('ROUND(`number` * `standard_score`, 2)'),
|
|
|
+ 'salary' => Db::raw('ROUND(`number` * `standard_score` * 0.067, 2)'),
|
|
|
]);
|
|
|
if ($affected === false) {
|
|
|
throw new \Exception('批量更新失败');
|
|
|
@@ -891,13 +932,13 @@ SQL;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 报工工资:数量 × 工分 × 0.067
|
|
|
+ * 报工工资:数量 × 工分 × 0.067(保留2位,与库字段 decimal(10,2) 一致)
|
|
|
* @param mixed $number
|
|
|
* @param mixed $standardScore
|
|
|
* @return float
|
|
|
*/
|
|
|
private function calcReportSalary($number, $standardScore)
|
|
|
{
|
|
|
- return round(floatval($number) * floatval($standardScore) * 0.067, 4);
|
|
|
+ return round(floatval($number) * floatval($standardScore) * 0.067, 2);
|
|
|
}
|
|
|
}
|