Przeglądaj źródła

物料逻辑修改

lucw 7 miesięcy temu
rodzic
commit
84d1f18c56

+ 2 - 2
src/views/batchRecord/components/editModal.vue

@@ -523,6 +523,7 @@
           :bomCategoryId="workOrderInfo.bomCategoryId"
           :outputType="form.outputType"
           :categoryId="workOrderInfo.categoryId"
+          :executeStatus="form.executeStatus"
           @refresh="getListByWorkOrderId"
         ></material>
         <header-title
@@ -1406,7 +1407,6 @@
             this.form.produceTaskInstanceId = item.taskId;
           }
         }
-
       },
       // 选择工序
       produceTaskIdChange() {
@@ -1716,7 +1716,7 @@
           i.quantity = i.qualifiedQuantity;
 
           // 物料清单中如果存在则 selected 设置为 true
-          const any = this.addForm.outputDetails.find(
+          const any = this.form.outputDetails.find(
             (j) => j.categoryCode === i.categoryCode
           );
           if (any) {

+ 31 - 31
src/views/batchRecord/components/statistics.vue

@@ -662,7 +662,7 @@
                     item.title === '入库时间' ||
                     item.title === '生产日期'
                   ) {
-                    item.value = record.executorTime;
+                    item.value = record.storageTime;
                   }
                   item.unit = record.measuringUnit || this.unit;
                 });
@@ -740,36 +740,6 @@
               paramType: 7
             });
 
-            // 接收
-            if (!isNaN(pick.formedNum)) {
-              const item = data.find(
-                (i) => i.title === '接收量' || i.title === '接收数量'
-              );
-              if (item) {
-                item.value = pick.formedNum;
-              }
-            }
-
-            // 不合格品
-            if (!isNaN(pick.noQualifiedSum)) {
-              const item = data.find(
-                (i) => i.title == '不合格品量' || i.title == '不合格品数量'
-              );
-              if (item) {
-                item.value = pick.noQualifiedSum;
-              }
-            }
-
-            // 合格品量
-            if (!isNaN(pick.qualified)) {
-              const item = data.find(
-                (i) => i.title == '合格品数' || i.title == '合格品数量'
-              );
-              if (item) {
-                item.value = pick.qualified;
-              }
-            }
-
             return data;
           })
         };
@@ -802,6 +772,36 @@
               paramType: 7
             });
 
+            // 接收
+            if (!isNaN(task.formedNum)) {
+              const item = data.find(
+                (i) => i.title === '接收量' || i.title === '接收数量'
+              );
+              if (item) {
+                item.value = task.formedNum;
+              }
+            }
+
+            // 不合格品
+            if (!isNaN(task.noQualifiedSum)) {
+              const item = data.find(
+                (i) => i.title == '不合格品量' || i.title == '不合格品数量'
+              );
+              if (item) {
+                item.value = task.noQualifiedSum;
+              }
+            }
+
+            // 合格品量
+            if (!isNaN(task.qualified)) {
+              const item = data.find(
+                (i) => i.title == '合格品量' || i.title == '合格品数量'
+              );
+              if (item) {
+                item.value = task.qualified;
+              }
+            }
+
             return data;
           })
         };

+ 241 - 26
src/views/produce/components/prenatalExamination/material.vue

@@ -40,6 +40,7 @@
     >
       <template v-slot:reportQuantity="{ row }">
         <div>
+          {{ reportQuantitymax(row) }}
           <el-input-number
             size="small"
             v-model.number="row.reportQuantity"
@@ -209,7 +210,7 @@
             // 1-物料本身
           } else if (this.outputType == 2) {
             // 2-在制品
-            this.getCategoryAndLevelByCategoryId();
+            this.categoryInfoSetOutput();
           } else {
             // 3 BOM标准产出
             this.setMaterialQuotaInfo();
@@ -236,6 +237,13 @@
           this.$emit('update:pickDetails', this.localPickDetails);
           this.$emit('update:outputDetails', this.localOutputDetails);
         }
+      },
+      produceTaskId: {
+        handler() {
+          this.getMaterialQuotaInfo();
+          this.getCategoryAndLevelByCategoryId();
+        },
+        immediate: true
       }
     },
     computed: {
@@ -319,6 +327,16 @@
                 if (!this.materialQuotaInfo) {
                   return '0' + (row.unit || '');
                 }
+                // 当前行为在制品 和 BOM标准产出
+                const preOutputItem = this.localOutputDetails.find(
+                  (item) => item.categoryCode === row.categoryCode
+                );
+
+                if (preOutputItem) {
+                  return (preOutputItem.reportQuantity || 0) + (row.unit || '');
+                }
+
+                // 当前行为原材料
                 const materialItem = this.materialQuotaInfo.materialQuota.find(
                   (item) => item.categoryCode === row.categoryCode
                 );
@@ -348,31 +366,98 @@
                 const outputItem = this.localOutputDetails.find(
                   (item) => item.categoryCode == row.categoryCode
                 );
-                if (!outputItem) {
-                  return row.sumReportQuantity + (row.unit || '');
+
+                // 查询其他工单sumOutputDetails中已产生的bom标准产出和在制品的累计消耗数量
+                let preCount = 0;
+                if (this.materialQuotaInfo) {
+                  const materialQuotaItem =
+                    this.materialQuotaInfo.materialQuota.find(
+                      (item) => item.categoryCode === row.categoryCode
+                    );
+
+                  if (!materialQuotaItem) {
+                    return;
+                  }
+
+                  // 计算比例
+                  const proportion =
+                    materialQuotaItem.count / this.materialQuotaInfo.baseCount;
+
+                  if (this.materialQuotaInfo.standardOutput) {
+                    // BOM标准产出
+                    const preItem = this.sumOutputDetails.find(
+                      (item) =>
+                        item.categoryCode ===
+                        this.materialQuotaInfo.standardOutput.categoryCode
+                    );
+                    if (preItem) {
+                      preCount += preItem.sumReportQuantity * proportion;
+                    }
+                  }
+
+                  if (this.categoryInfo) {
+                    // 在制品
+                    const preItem = this.sumOutputDetails.find(
+                      (item) =>
+                        item.categoryCode === this.categoryInfo.categoryCode
+                    );
+                    if (preItem) {
+                      preCount += preItem.sumReportQuantity * proportion;
+                    }
+                  }
                 }
+
                 let count = 0;
-                if (this.executeStatus === 2) {
-                  // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
-                  count =
-                    row.sumReportQuantity -
-                    (outputItem.reportQuantityCopy - outputItem.reportQuantity);
+                if (outputItem) {
+                  if (this.executeStatus === 2) {
+                    // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
+                    count =
+                      row.sumReportQuantity -
+                      (outputItem.reportQuantityCopy -
+                        outputItem.reportQuantity);
+                  } else {
+                    count = row.sumReportQuantity + outputItem.reportQuantity;
+                  }
                 } else {
-                  count = row.sumReportQuantity + outputItem.reportQuantity;
+                  count = row.sumReportQuantity;
                 }
 
-                return count + (row.unit || '');
+                return count + preCount + (row.unit || '');
               } else {
+                // 当前行为在制品 和 BOM标准产出
+                const output = this.localOutputDetails.find(
+                  (item) => item.categoryCode === row.categoryCode
+                );
+
+                if (output) {
+                  // 区分已执行状态
+                  if (this.executeStatus === 2) {
+                    // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
+                    return (
+                      output.sumReportQuantity -
+                      (output.reportQuantityCopy - output.reportQuantity) +
+                      (row.unit || '')
+                    );
+                  }
+                  return (
+                    (output.sumReportQuantity || 0) +
+                    output.reportQuantity +
+                    (row.unit || '')
+                  );
+                }
+
                 // 产出为在制品 或 BOM标准产出 累计消耗数量
                 if (!this.materialQuotaInfo) {
                   return row.sumReportQuantity + (row.unit || '');
                 }
+
                 const materialItem = this.materialQuotaInfo.materialQuota.find(
                   (item) => item.categoryCode === row.categoryCode
                 );
                 if (!materialItem) {
                   return row.sumReportQuantity + (row.unit || '');
                 }
+                // 计算在制 标准产出消耗原材料
                 const outputItem = this.localOutputDetails[0];
                 if (!outputItem) {
                   return row.sumReportQuantity + (row.unit || '');
@@ -381,6 +466,38 @@
                 const proportion =
                   materialItem.count / this.materialQuotaInfo.baseCount;
 
+                // 查询其他工单sumOutputDetails中已产生的bom标准产出和在制品的累计消耗数量
+                let preCount = 0;
+                // 如果当前物料不是BOM标准产出,则需要加上BOM标准产出的消耗数量
+                if (
+                  outputItem.categoryCode !=
+                  this.materialQuotaInfo.standardOutput.categoryCode
+                ) {
+                  // BOM标准产出
+                  const preItem = this.sumOutputDetails.find(
+                    (item) =>
+                      item.categoryCode ===
+                      this.materialQuotaInfo.standardOutput.categoryCode
+                  );
+                  if (preItem) {
+                    preCount += preItem.sumReportQuantity * proportion;
+                  }
+                }
+                // 在制品
+                if (this.categoryInfo) {
+                  if (
+                    this.categoryInfo.categoryCode != outputItem.categoryCode
+                  ) {
+                    const preItem = this.sumOutputDetails.find(
+                      (item) =>
+                        item.categoryCode === this.categoryInfo.categoryCode
+                    );
+                    if (preItem) {
+                      preCount += preItem.sumReportQuantity * proportion;
+                    }
+                  }
+                }
+
                 let cumulativeOutputQuantity = 0;
 
                 if (this.executeStatus === 2) {
@@ -398,7 +515,9 @@
                 // const sumReportQuantity = row.sumReportQuantity * proportion;
                 const sumReportQuantity = row.sumReportQuantity;
 
-                return needQuantity + sumReportQuantity + (row.unit || '');
+                return (
+                  needQuantity + preCount + sumReportQuantity + (row.unit || '')
+                );
               }
             }
           }
@@ -422,6 +541,8 @@
         localOutputDetails: [],
         // bom配置的 标准产出信息
         materialQuotaInfo: null,
+        // 在制品信息
+        categoryInfo: null,
         // 产出清单表头
         outputDetailsColumns: [
           {
@@ -519,11 +640,6 @@
         ]
       };
     },
-    mounted() {
-      if (this.bomCategoryId && this.produceTaskId) {
-        this.getMaterialQuotaInfo();
-      }
-    },
     methods: {
       // 选择物料
       openMaterialModal() {
@@ -582,6 +698,7 @@
 
         this.$emit('update:pickDetails', this.localPickDetails);
       },
+      // bom标准产出赋值
       setMaterialQuotaInfo() {
         console.log('this.materialQuotaInfo', this.materialQuotaInfo);
 
@@ -707,12 +824,17 @@
 
         this.$emit('update:outputDetails', this.localOutputDetails);
       },
-      // getCategoryAndLevelByCategoryId 获取产品
+      // getCategoryAndLevelByCategoryId 获取产品 在制品信息
       async getCategoryAndLevelByCategoryId() {
         const data = await getCategoryAndLevelByCategoryId(this.categoryId);
-        if (data) {
+        this.categoryInfo = data;
+        console.log('this.categoryInfo 在制品信息', this.categoryInfo);
+      },
+      // 在制品信息 设置产出物
+      categoryInfoSetOutput() {
+        if (this.categoryInfo) {
           const sumItem = this.sumOutputDetails.find(
-            (i) => i.categoryCode == data.categoryCode
+            (i) => i.categoryCode == this.categoryInfo.categoryCode
           );
 
           let sumQualifiedQuantity = 0;
@@ -727,7 +849,7 @@
 
           this.localOutputDetails = [
             {
-              ...data,
+              ...this.categoryInfo,
               id: null,
               reportQuantity: 0,
               reportQuantityCopy: 0,
@@ -750,7 +872,6 @@
         this.$emit('update:outputDetails', this.localOutputDetails);
 
         console.log('this.localOutputDetails', this.localOutputDetails);
-        console.log('this.materialQuotaInfo', this.materialQuotaInfo);
       },
       // 计算报工数量最大值
       reportQuantitymax(row) {
@@ -759,19 +880,75 @@
           const pickItem = this.localPickDetails.find(
             (item) => item.categoryCode === row.categoryCode
           );
-          // 物料本身 不能超过已报工数量减领料数量
+
+          // 查询其他工单sumOutputDetails中已产生的bom标准产出和在制品的累计消耗数量
+          let preCount = 0;
+          if (this.materialQuotaInfo) {
+            const materialQuotaItem = this.materialQuotaInfo.materialQuota.find(
+              (item) => item.categoryCode === row.categoryCode
+            );
+
+            if (materialQuotaItem) {
+              // 计算比例
+              const proportion =
+                materialQuotaItem.count / this.materialQuotaInfo.baseCount;
+
+              if (this.materialQuotaInfo.standardOutput) {
+                // BOM标准产出
+                const preItem = this.sumOutputDetails.find(
+                  (item) =>
+                    item.categoryCode ===
+                    this.materialQuotaInfo.standardOutput.categoryCode
+                );
+                if (preItem) {
+                  preCount += preItem.sumReportQuantity * proportion;
+                }
+              }
+
+              if (this.categoryInfo) {
+                // 在制品
+                const preItem = this.sumOutputDetails.find(
+                  (item) => item.categoryCode === this.categoryInfo.categoryCode
+                );
+                if (preItem) {
+                  preCount += preItem.sumReportQuantity * proportion;
+                }
+              }
+            }
+          }
+
+          // 未找到物料,则返回剩余数量
+          if (!pickItem) return pickItem.quantity - preCount;
 
           // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
           if (this.executeStatus === 2) {
             return (
               pickItem.quantity -
-              (pickItem.sumReportQuantity - row.reportQuantityCopy)
+              (pickItem.sumReportQuantity - row.reportQuantityCopy) -
+              preCount
             );
           } else {
-            return pickItem.quantity - pickItem.sumReportQuantity;
+            return pickItem.quantity - pickItem.sumReportQuantity - preCount;
           }
         }
         if (row.outputType == 2 || row.outputType == 3) {
+          // 当前行为在制品 和 BOM标准产出
+          const preOutputItem = this.preOutputDetails.find(
+            (item) => item.categoryCode === row.categoryCode
+          );
+
+          // 存在则当前row为在制品或BOM标准产出
+          if (preOutputItem) {
+            // 区分已执行状态
+            if (this.executeStatus === 2) {
+              return (
+                preOutputItem.quantity -
+                (row.sumReportQuantity - row.reportQuantityCopy)
+              );
+            }
+            return preOutputItem.quantity - row.sumReportQuantity;
+          }
+
           // 基于物料配额限制最大可报工数量(兼容已缓存/已保存一次的编辑场景,并区分已执行状态)
           if (!this.materialQuotaInfo) return Infinity;
           const quota = this.materialQuotaInfo.materialQuota || [];
@@ -794,6 +971,41 @@
             // 单位产出所需物料比例
             const proportion = item.count / baseCount;
 
+            // 查询其他工单 sumOutputDetails 中已产生的 BOM 标准产出和在制品的累计消耗数量
+            let preOutputConsumedProportion = 0;
+
+            // BOM标准产出
+            if (
+              this.materialQuotaInfo &&
+              this.materialQuotaInfo.standardOutput &&
+              row.categoryCode !==
+                this.materialQuotaInfo.standardOutput.categoryCode
+            ) {
+              const preStd = this.sumOutputDetails.find(
+                (s) =>
+                  s.categoryCode ===
+                  this.materialQuotaInfo.standardOutput.categoryCode
+              );
+              if (preStd) {
+                preOutputConsumedProportion +=
+                  preStd.sumReportQuantity * proportion;
+              }
+            }
+
+            // 在制品
+            if (
+              this.categoryInfo &&
+              row.categoryCode !== this.categoryInfo.categoryCode
+            ) {
+              const preWip = this.sumOutputDetails.find(
+                (s) => s.categoryCode === this.categoryInfo.categoryCode
+              );
+              if (preWip) {
+                preOutputConsumedProportion +=
+                  preWip.sumReportQuantity * proportion;
+              }
+            }
+
             // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
             let consumedQuantity = isExecuted
               ? row.sumReportQuantity - row.reportQuantityCopy
@@ -803,8 +1015,11 @@
             const consumedProportion = consumedQuantity * proportion;
 
             // 最大可报工数量
-            const maxQuantity =
-              (pickItem.quantity - consumedProportion) / proportion;
+            let maxQuantity =
+              (pickItem.quantity -
+                consumedProportion -
+                preOutputConsumedProportion) /
+              proportion;
 
             // 向下取整
             return Math.floor(maxQuantity);