|
|
@@ -1233,6 +1233,11 @@ class OrderSuperLoss extends Api
|
|
|
$workOrderData['jjcp_gdbh'],
|
|
|
$workOrderData['jjcp_yjno']
|
|
|
);
|
|
|
+ $gy_data = $this->expandSczlMultiTeamRows(
|
|
|
+ $gy_data,
|
|
|
+ $workOrderData['jjcp_gdbh'],
|
|
|
+ $workOrderData['jjcp_yjno']
|
|
|
+ );
|
|
|
$sumBz = [];
|
|
|
foreach ($gy_data as $kk => $vv){
|
|
|
//每道工序的产量(按班组分)
|
|
|
@@ -2379,6 +2384,139 @@ class OrderSuperLoss extends Api
|
|
|
->value('SUM(Gy0_计划损耗 * Gy0_ls * Gy0_ks)'));
|
|
|
}
|
|
|
|
|
|
+ /** 工序号查询兼容 9 / 09 / 9 */
|
|
|
+ private function resolveGxhWhereValues($gxh): array
|
|
|
+ {
|
|
|
+ $values = [(string)$gxh, $this->normalizeGxhKey($gxh), (string)(int)$gxh];
|
|
|
+ $n = (int)$gxh;
|
|
|
+ if ($n < 10) {
|
|
|
+ $values[] = sprintf('%02d', $n);
|
|
|
+ }
|
|
|
+
|
|
|
+ return array_values(array_unique(array_filter($values, static function ($v) {
|
|
|
+ return $v !== '';
|
|
|
+ })));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按 db_sczl 报工班组拆成多行(拆片等多员工,与历史入库一致)
|
|
|
+ */
|
|
|
+ private function buildGyRowsFromSczlTeams(string $gdbh, string $yjno, $gxh, array $templateRow): array
|
|
|
+ {
|
|
|
+ $gxValues = $this->resolveGxhWhereValues($gxh);
|
|
|
+ $sczlRows = db('db_sczl')
|
|
|
+ ->where('sczl_gdbh', $gdbh)
|
|
|
+ ->where('sczl_yjno', $yjno)
|
|
|
+ ->where('sczl_gxh', 'in', $gxValues)
|
|
|
+ ->order('sczl_rq asc')
|
|
|
+ ->select();
|
|
|
+ if (count($sczlRows) <= 1) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ $groups = [];
|
|
|
+ foreach ($sczlRows as $sr) {
|
|
|
+ $bh1 = trim((string)($sr['sczl_bh1'] ?? ''));
|
|
|
+ if ($bh1 === '000000') {
|
|
|
+ $bh1 = '';
|
|
|
+ }
|
|
|
+ $key = $bh1 !== '' ? ('bh:' . $bh1) : ('id:' . ($sr['UniqId'] ?? md5(json_encode($sr))));
|
|
|
+ if (!isset($groups[$key])) {
|
|
|
+ $groups[$key] = ['sczl' => $sr, 'cl' => 0.0, 'fp' => 0.0];
|
|
|
+ }
|
|
|
+ $groups[$key]['cl'] += floatval($sr['sczl_cl'] ?? 0);
|
|
|
+ $groups[$key]['fp'] += floatval($sr['sczl_fp'] ?? 0);
|
|
|
+ }
|
|
|
+ if (count($groups) <= 1) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ $rows = [];
|
|
|
+ foreach ($groups as $g) {
|
|
|
+ $sr = $g['sczl'];
|
|
|
+ $row = $templateRow;
|
|
|
+ $row['total_cl'] = $g['cl'];
|
|
|
+ $row['cl'] = $g['cl'];
|
|
|
+ $row['fp'] = $g['fp'];
|
|
|
+ $row['sczl_zcfp'] = 0;
|
|
|
+ $row['sczl_jtbh'] = $sr['sczl_jtbh'] ?? ($row['sczl_jtbh'] ?? '');
|
|
|
+ $row['sczl_bzdh'] = $sr['sczl_bzdh'] ?? '';
|
|
|
+ $row['sczl_bh'] = $sr['sczl_bh1'] ?? '';
|
|
|
+ for ($j = 1; $j <= 10; $j++) {
|
|
|
+ $bhKey = 'sczl_bh' . $j;
|
|
|
+ $rateKey = 'sczl_rate' . $j;
|
|
|
+ $val = isset($sr[$bhKey]) ? trim((string)$sr[$bhKey]) : '';
|
|
|
+ if ($val === '000000') {
|
|
|
+ $val = '';
|
|
|
+ }
|
|
|
+ $row[$bhKey] = $val;
|
|
|
+ $row[$rateKey] = (isset($sr[$rateKey]) && $sr[$rateKey] !== '') ? $sr[$rateKey] : 0;
|
|
|
+ }
|
|
|
+ $rows[] = $row;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $rows;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 仅 db_sczl 报工、无产量计酬时:若某工序只有一行且无计酬班组,按 sczl 多员工展开
|
|
|
+ */
|
|
|
+ private function expandSczlMultiTeamRows(array $gyData, string $gdbh, string $yjno): array
|
|
|
+ {
|
|
|
+ $byGx = [];
|
|
|
+ foreach ($gyData as $idx => $row) {
|
|
|
+ $gk = $this->normalizeGxhKey($row['Gy0_gxh'] ?? '');
|
|
|
+ if ($gk === '') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $byGx[$gk][] = $idx;
|
|
|
+ }
|
|
|
+
|
|
|
+ $replaceGx = [];
|
|
|
+ foreach ($byGx as $gk => $indexes) {
|
|
|
+ if (count($indexes) !== 1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $row = $gyData[$indexes[0]];
|
|
|
+ $gxValues = $this->resolveGxhWhereValues($row['Gy0_gxh']);
|
|
|
+ $payrollCnt = (int)db('设备_产量计酬')
|
|
|
+ ->where('sczl_gdbh', $gdbh)
|
|
|
+ ->where('sczl_yjno', $yjno)
|
|
|
+ ->where('sczl_gxh', 'in', $gxValues)
|
|
|
+ ->count();
|
|
|
+ if ($payrollCnt > 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $teams = $this->buildGyRowsFromSczlTeams($gdbh, $yjno, $row['Gy0_gxh'], $row);
|
|
|
+ if (count($teams) > 1) {
|
|
|
+ $replaceGx[$gk] = $teams;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($replaceGx)) {
|
|
|
+ return $gyData;
|
|
|
+ }
|
|
|
+
|
|
|
+ $out = [];
|
|
|
+ $doneGx = [];
|
|
|
+ foreach ($gyData as $row) {
|
|
|
+ $gk = $this->normalizeGxhKey($row['Gy0_gxh'] ?? '');
|
|
|
+ if (isset($replaceGx[$gk]) && !isset($doneGx[$gk])) {
|
|
|
+ foreach ($replaceGx[$gk] as $teamRow) {
|
|
|
+ $out[] = $teamRow;
|
|
|
+ }
|
|
|
+ $doneGx[$gk] = true;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (isset($doneGx[$gk])) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $out[] = $row;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $out;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 仅 db_sczl 报工、无产量计酬时,从最新一条报工补班组编号/分配比例(拆片等)
|
|
|
*/
|
|
|
@@ -2733,8 +2871,15 @@ class OrderSuperLoss extends Api
|
|
|
$item['sczl_bh' . $j] = '';
|
|
|
$item['sczl_rate' . $j] = 0;
|
|
|
}
|
|
|
- $this->fillSczlTeamMemberFields($item, $gdbh, $yjno);
|
|
|
- $gyData[] = $item;
|
|
|
+ $teams = $this->buildGyRowsFromSczlTeams($gdbh, $yjno, $item['Gy0_gxh'], $item);
|
|
|
+ if (!empty($teams)) {
|
|
|
+ foreach ($teams as $teamRow) {
|
|
|
+ $gyData[] = $teamRow;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $this->fillSczlTeamMemberFields($item, $gdbh, $yjno);
|
|
|
+ $gyData[] = $item;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return $gyData;
|