|
|
@@ -937,6 +937,7 @@ class OrderSuperLoss extends Api
|
|
|
})
|
|
|
->where('c.jjcp_smb', 'like', '末%')
|
|
|
->select();
|
|
|
+ halt($list);
|
|
|
$data = [];
|
|
|
|
|
|
foreach ($list as $item) {
|
|
|
@@ -993,6 +994,171 @@ class OrderSuperLoss extends Api
|
|
|
$this->success('成功', $result);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 员工月度超节损工序明细
|
|
|
+ * @ApiMethod (GET)
|
|
|
+ * @param string $month 月份,202611 或 2026-11
|
|
|
+ * @param string $code 员工编号
|
|
|
+ */
|
|
|
+ public function EmployeeMonthDetail()
|
|
|
+ {
|
|
|
+ if (!$this->request->isGet() && !$this->request->isPost()) {
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+ $params = $this->request->param();
|
|
|
+ $monthRaw = isset($params['month']) ? trim((string)$params['month']) : '';
|
|
|
+ if ($monthRaw === '' && isset($params['date'])) {
|
|
|
+ $monthRaw = trim((string)$params['date']);
|
|
|
+ }
|
|
|
+ $code = isset($params['code']) ? trim((string)$params['code']) : '';
|
|
|
+ if ($code === '' && isset($params['员工编号'])) {
|
|
|
+ $code = trim((string)$params['员工编号']);
|
|
|
+ }
|
|
|
+ $month = str_replace(['-', '/', '.'], '', $monthRaw);
|
|
|
+ if ($code === '' || !preg_match('/^\d{6}$/', $month)) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $holders = [];
|
|
|
+ $binds = [];
|
|
|
+ for ($i = 1; $i <= 8; $i++) {
|
|
|
+ $holders[] = "RTRIM(a.`sczl_bh{$i}`) = :emp{$i}";
|
|
|
+ $binds['emp' . $i] = $code;
|
|
|
+ }
|
|
|
+ $rows = \db('工单_质量考核汇总')
|
|
|
+ ->alias('a')
|
|
|
+ ->join('工单_印件资料 b', 'a.Gy0_gdbh = b.Yj_Gdbh AND a.`印件及工序` = b.yj_Yjno', 'LEFT')
|
|
|
+ ->where('a.sys_ny', $month)
|
|
|
+ ->whereRaw('(' . implode(' OR ', $holders) . ')', $binds)
|
|
|
+ ->field('a.Gy0_gdbh,a.`印件及工序`,a.`工序`,a.`工序名称`,a.CjsJe,a.sczl_bzdh,a.`产品代号`,a.`产品名称`,b.`质量考核`,
|
|
|
+ a.sczl_bh1,a.sczl_bh2,a.sczl_bh3,a.sczl_bh4,a.sczl_bh5,a.sczl_bh6,a.sczl_bh7,a.sczl_bh8,
|
|
|
+ a.sczl_rate1,a.sczl_rate2,a.sczl_rate3,a.sczl_rate4,a.sczl_rate5,a.sczl_rate6,a.sczl_rate7,a.sczl_rate8,
|
|
|
+ a.Xm1,a.Xm2,a.Xm3,a.Xm4,a.Xm5,a.Xm6,a.Xm7,a.Xm8')
|
|
|
+ ->order('a.Gy0_gdbh asc,a.印件及工序 asc,a.工序 asc')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $employeeName = '';
|
|
|
+ $processAmount = [];
|
|
|
+ if (!empty($rows)) {
|
|
|
+ $orders = [];
|
|
|
+ foreach ($rows as $row) {
|
|
|
+ $orders[$row['Gy0_gdbh']] = $row['Gy0_gdbh'];
|
|
|
+ if ($employeeName === '') {
|
|
|
+ for ($i = 1; $i <= 8; $i++) {
|
|
|
+ if (trim((string)$row['sczl_bh' . $i]) === $code && trim((string)$row['Xm' . $i]) !== '') {
|
|
|
+ $employeeName = trim((string)$row['Xm' . $i]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $sumRows = \db('工单_质量考核汇总')
|
|
|
+ ->where('sys_ny', $month)
|
|
|
+ ->where('Gy0_gdbh', 'in', array_values($orders))
|
|
|
+ ->field('Gy0_gdbh,`印件及工序`,`工序`,SUM(CjsJe) AS process_je')
|
|
|
+ ->group('Gy0_gdbh,`印件及工序`,`工序`')
|
|
|
+ ->select();
|
|
|
+ foreach ($sumRows as $sumRow) {
|
|
|
+ $key = $sumRow['Gy0_gdbh'] . '|' . trim((string)$sumRow['印件及工序']) . '|' . trim((string)$sumRow['工序']);
|
|
|
+ $processAmount[$key] = round((float)$sumRow['process_je'], 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($employeeName === '') {
|
|
|
+ $employeeName = (string)\db('人事_基本资料')->where('员工编号', $code)->value('rtrim(员工姓名)');
|
|
|
+ }
|
|
|
+
|
|
|
+ $groups = [
|
|
|
+ '参与考核' => [],
|
|
|
+ '不参与考核' => [],
|
|
|
+ ];
|
|
|
+ foreach ($rows as $row) {
|
|
|
+ $rate = 0.0;
|
|
|
+ for ($i = 1; $i <= 8; $i++) {
|
|
|
+ if (trim((string)$row['sczl_bh' . $i]) !== $code) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $slotRate = (float)$row['sczl_rate' . $i];
|
|
|
+ if ($slotRate == 0.0) {
|
|
|
+ $slotRate = 1.0;
|
|
|
+ }
|
|
|
+ $rate += $slotRate;
|
|
|
+ }
|
|
|
+ $teamAmount = round((float)$row['CjsJe'], 2);
|
|
|
+ $personalAmount = round($teamAmount * $rate, 2);
|
|
|
+ $processKey = $row['Gy0_gdbh'] . '|' . trim((string)$row['印件及工序']) . '|' . trim((string)$row['工序']);
|
|
|
+ $orderKey = $row['Gy0_gdbh'] . '|' . trim((string)$row['印件及工序']);
|
|
|
+ $category = ((string)$row['质量考核'] === '1') ? '不参与考核' : '参与考核';
|
|
|
+ if (!isset($groups[$category][$orderKey])) {
|
|
|
+ $groups[$category][$orderKey] = [
|
|
|
+ '工单编号' => trim((string)$row['Gy0_gdbh']),
|
|
|
+ '印件号' => trim((string)$row['印件及工序']),
|
|
|
+ '产品代号' => trim((string)$row['产品代号']),
|
|
|
+ '产品名称' => trim((string)$row['产品名称']),
|
|
|
+ '工序明细' => [],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $percent = rtrim(rtrim(number_format($rate * 100, 2, '.', ''), '0'), '.');
|
|
|
+ $groups[$category][$orderKey]['工序明细'][] = [
|
|
|
+ '工序号' => trim((string)$row['工序']),
|
|
|
+ '工序名称' => trim((string)$row['工序名称']),
|
|
|
+ '班组' => trim((string)$row['sczl_bzdh']),
|
|
|
+ '工序节损金额' => isset($processAmount[$processKey]) ? $processAmount[$processKey] : 0,
|
|
|
+ '班组节损金额' => $teamAmount,
|
|
|
+ '个人承担比例' => $percent . '%',
|
|
|
+ '个人节损金额' => $personalAmount,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $assessed = $this->summarizeEmployeeSuperLossOrders($groups['参与考核']);
|
|
|
+ $excluded = $this->summarizeEmployeeSuperLossOrders($groups['不参与考核']);
|
|
|
+ $this->success('成功', [
|
|
|
+ '月份' => $month,
|
|
|
+ '员工编号' => $code,
|
|
|
+ '员工姓名' => trim($employeeName),
|
|
|
+ '参与考核' => $assessed,
|
|
|
+ '不参与考核' => $excluded,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 员工月度明细按工单归类,并在分类结尾汇总
|
|
|
+ * @param array $orders
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ private function summarizeEmployeeSuperLossOrders(array $orders)
|
|
|
+ {
|
|
|
+ $list = array_values($orders);
|
|
|
+ $orderCount = count($list);
|
|
|
+ $processCount = 0;
|
|
|
+ $teamAmount = 0.0;
|
|
|
+ $personalAmount = 0.0;
|
|
|
+ $processKeys = [];
|
|
|
+ $processAmount = 0.0;
|
|
|
+ foreach ($list as $order) {
|
|
|
+ foreach ($order['工序明细'] as $line) {
|
|
|
+ $processCount++;
|
|
|
+ $teamAmount += (float)$line['班组节损金额'];
|
|
|
+ $personalAmount += (float)$line['个人节损金额'];
|
|
|
+ $key = $order['工单编号'] . '|' . $order['印件号'] . '|' . $line['工序号'];
|
|
|
+ if (!isset($processKeys[$key])) {
|
|
|
+ $processKeys[$key] = true;
|
|
|
+ $processAmount += (float)$line['工序节损金额'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ '工单' => $list,
|
|
|
+ '汇总' => [
|
|
|
+ '工单数' => $orderCount,
|
|
|
+ '工序数' => $processCount,
|
|
|
+ '工序节损金额' => round($processAmount, 2),
|
|
|
+ '班组节损金额' => round($teamAmount, 2),
|
|
|
+ '个人节损金额' => round($personalAmount, 2),
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 单条工单超节损计算
|