小微园产仓库管理

小微园产仓库管理

功能范围
  • 调拨单打印物料标签 小微园仓库物料来源分别是:总厂调拨产成品入库,通过调拨单打印入库的物料标签保证小微园仓库入库的物料有条码。
  • 在库物料标签打印 对没有标签的在库物料进行打印标签,从而进行条码管理。
  • 生产领料 用PDA扫描工单和小微园仓库物料进行生产领料,并使工单与领料单完成绑定关系。
  • 产成品入库 用PDA扫描产品标签,并向ERP回写产品代码 + 产品数量 + 仓库代码 + 领料单 + 创单人
1.调拨单打印物料标签(业务流程图)
Created with Raphaël 2.2.0 A 总厂调拨单 B 小微园仓库打印物料标签 C 贴物料标签 F 结束框
1.1 业务表

vwICBill_41(ERP调拨单)查询
INV_BARCODE(条码表)新增
INV_BARCODELOG(条码历史表)新增
INV_STORAGEINFO(库存表)修改

1.2 核心代码
/// 
        /// 调拨入库打印
        /// 
        /// 
        public async Task <TransferStockPrintingDto> TransferStockPrinting(TransferStockPrintingInput input)
        {
            TransferStockPrintingDto dto = new TransferStockPrintingDto();
            if (input.Qty < input.PrintQty)
            {
                throw new UserFriendlyException("打印数量不能大于调拨数量");
            }
            //查找物料
            var material = await _materialRepository.FirstOrDefaultAsync(r=>r.MaterialCode.Equals(input.MaterialCode));
            if (material == null)
            {
                throw new UserFriendlyException(string.Format("物料[{0}],不存在",input.MaterialCode));
            }
            //查找仓库
            var wareHouse = await _wareHouseRepository.FirstOrDefaultAsync(r=>r.WhName.Equals(input.FDCStock));
            if (wareHouse == null)
            {
                throw new UserFriendlyException(string.Format("仓库[{0}],不存在", input.FDCStock));
            }
            //生成条码
            var barCode = _barcodeAppService.GenerateCommonSerialNumber(new CommonLotNumberInput { RuleCode = "MaterialsLabel" });
            if (barCode == null)
            {
                throw new UserFriendlyException(string.Format("条码规则[{0}],不存在", "MaterialsLabel"));
            }
            //查询已打数量
            var barCodeList = await _barcodeRepository.GetAllListAsync(r => r.MaterialCode.Equals(material.MaterialCode) && r.SourceCode.Equals(input.FBillNo)
             && r.SourceType == (int)CPSProductionPlanConsts.Bill_Transfer && r.LotNo.Equals(input.LotNumber));
            if (barCodeList != null)
            {
                if ((barCodeList.Sum(r => r.CurrentQty) + input.PrintQty) > input.Qty)
                {
                    throw new UserFriendlyException("打印数量不能大于调拨数量");
                }
            }

            #region 插入INV_BARCODE表(条码表)
            Barcode barCodeEntity = new Barcode();
            barCodeEntity.TenantId = AbpSession.TenantId;
            barCodeEntity.OrgId = AbpSession.OrgId;
            barCodeEntity.CreatorUserId = AbpSession.UserId;
            barCodeEntity.CreatorFullName = AbpSession.FullName;
            barCodeEntity.BarCode = barCode;
            barCodeEntity.LotNo = input.LotNumber;
            barCodeEntity.BarCodeStatus = BarcodeStatus.InStock.GetHashCode();
            barCodeEntity.BarType = BarcodeType.ContainerBarcode.GetHashCode();
            barCodeEntity.BoxType = 0;
            barCodeEntity.DateCode = DateTime.Now;
            barCodeEntity.SourceType = (int)CPSProductionPlanConsts.Bill_Transfer;
            barCodeEntity.SourceId = 0;
            barCodeEntity.SourceCode = input.FBillNo;
            barCodeEntity.PackQty = 0;
            barCodeEntity.CurrentQty = input.PrintQty;
            barCodeEntity.InitialQty = input.PrintQty;
            barCodeEntity.QCStatus = 1;
            barCodeEntity.MaterialId = material.Id;
            barCodeEntity.MaterialCode = material.MaterialCode;
            barCodeEntity.MaterialName = material.MaterialName;
            barCodeEntity.LocationCode = wareHouse.WhCode;
            barCodeEntity.WareHouseCode = wareHouse.WhCode;
            await _barcodeRepository.InsertAsync(barCodeEntity);
            #endregion

            #region 记录INV_BARCODELOG历史记录表
            BarcodeLog barLog = new BarcodeLog();
            barLog.TenantId = AbpSession.TenantId;
            barLog.OrgId = AbpSession.OrgId;
            barLog.InOutType = (int)EnumCommon.InAndOutType.In;
            barLog.SourceBillType = (int)EnumCommon.DocumentType.Transfer;
            barLog.TargetBillType = (int)EnumCommon.DocumentType.Transfer;
            barLog.BillCode = input.FBillNo;//ERP回写入库单
            barLog.BarCode = barCode;
            barLog.BarCodeRemark = "ERP回写调拨单";
            barLog.BarType = 1;
            barLog.SourceBarCode = barCode;
            barLog.LotNo = input.LotNumber;
            barLog.DateCode = DateTime.Now;
            barLog.MaterialId = material.Id;
            barLog.MaterialCode = material.MaterialCode;
            barLog.WareHouseId = wareHouse.Id;
            barLog.WareHouseCode = wareHouse.WhCode;
            barLog.LocationCode = wareHouse.WhCode;
            barLog.SourceType = (int)EnumCommon.DocumentType.Transfer;
            barLog.SourceCode = input.FBillNo;
            barLog.QTY = input.PrintQty;
            await _barcodeLogRepository.InsertAsync(barLog);
            #endregion

            #region 插入INV_STORAGEINFO表(存库表)
            decimal dInitialQty = 0; // 期初库存
            decimal dLastQty = 0;    // 期末库存
            var storages = await _storageInfoRepository.GetAll().Where(p => p.OrgId.Value.Equals(AbpSession.OrgId.Value)
                         && p.WareHouseCode == wareHouse.WhCode
                         && p.MaterialId == material.Id && p.MaterialCode.Equals(material.MaterialCode)
                        ).ToListAsync();
            if (storages.Count <= 0)
            {
                StorageInfo sto = new StorageInfo
                {
                    TenantId = AbpSession.TenantId,
                    OrgId = AbpSession.OrgId,
                    WareHouseId = 0,
                    WareHouseCode = wareHouse.WhCode,
                    MaterialId = material.Id,
                    MaterialCode = material.MaterialCode,
                    QTY = input.PrintQty,
                    LockQty = 0
                };
                await _storageInfoRepository.InsertAsync(sto);
            }
            else
            {
                StorageInfo sto = storages[0];
                dInitialQty = sto.QTY ?? 0;
                sto.QTY = (sto.QTY ?? 0) + input.PrintQty;
                dLastQty = sto.QTY ?? 0;
                await _storageInfoRepository.UpdateAsync(sto);
            }
            #endregion

            dto.CartonCode = barCode;
            dto.ItemCode = material.MaterialCode;
            dto.ItemName = material.MaterialName;
            dto.Unit = material.Unit;
            dto.CollectedQty = input.PrintQty;
            dto.Specifications = material.MaterialStandard;
            dto.PackTime = DateTime.Now;
            dto.BatchNumber = input.LotNumber;
            return dto;
        }
1.3 MES操作界面

小微园产仓库管理_第1张图片

小微园产仓库管理_第2张图片

2.生产领料 (业务流程图)
Created with Raphaël 2.2.0 A CPS下发工单 PDA扫描生产工单, 根据工单BOM显示 需要领的物料 PDA扫描物料完成领料, 此时工单与领料单关联 F 结束
2.1 业务表

PRD_MO_D(工单表)查询
PRD_MO_BOM(工单BOM) 查询
INV_BARCODELOG(条码历史记录表)新增
INV_BARCODE(条码表)修改
INV_STORAGEINFO(库存表)修改

2.2核心代码
        #region 扫描物料标签(不需要拆分)
        public async Task<ProductPickOutPutDto> SubmitBarcodeLotPickOut(BarcodeStockLotPickOutInputDto input)
        {
            ProductPickOutPutDto dto = new ProductPickOutPutDto();
            string moCode = input.MOCode;//领料工单
            string wareHouseCode = input.WareHouseCode;//仓库code
            string materialCode = input.MaterialCode;//需领物料
            decimal collectQty = input.CollectQty;//需领数量
            string barCode = input.BarCode;//已扫物料条码

            //第一步:判断是否需要拆批
            if (collectQty <= 0)
            {
                throw new UserFriendlyException("领料数量必须大于0");
            }
            var _barCodeLog = await _barcodeLogRepository.GetAllListAsync(r=>r.SourceBarCode.Equals(moCode) && r.WareHouseCode == wareHouseCode && r.MaterialCode.Equals(materialCode) 
            && r.SourceBillType == (int)EnumCommon.DocumentType.ProductPick && r.InOutType == (int)EnumCommon.InAndOutType.Out);
            decimal collectedQty = _barCodeLog.Sum(r=>r.QTY.Value);//已扫物料数量
            if (collectedQty >= collectQty)
            {
                throw new UserFriendlyException("该物料已经领完");
            }
            var _barcCode = await _barcodeRepository.FirstOrDefaultAsync(r=>r.BarCode.Equals(barCode) && r.WareHouseCode == wareHouseCode && r.MaterialCode.Equals(materialCode));
            if (_barcCode == null)
            {
                throw new UserFriendlyException(string.Format("该物料条码[{0}]不存在",barCode));
            }
            decimal barcCodeQty = _barcCode.CurrentQty.Value;//条码物料数量

            //需要拆批
            if (barcCodeQty >  (collectQty - collectedQty))
            {
                dto.CountedQty = collectedQty;//显示已经扫码数量
                dto.ExceedQty = collectQty - collectedQty;//需要拆分数量
                dto.CurrentQty = barcCodeQty;//当前物料数量
                dto.LotCode = _barcCode.LotNo;//物料批次号
                return dto;
            }
            //不需要拆批,记录到BarcodeLog中
            BarcodeLog barLog = new BarcodeLog();
            barLog.TenantId = AbpSession.TenantId;
            barLog.OrgId = AbpSession.OrgId;
            barLog.InOutType = (int)EnumCommon.InAndOutType.Out;
            barLog.SourceBillType = (int)EnumCommon.DocumentType.ProductPick;
            barLog.TargetBillType = (int)EnumCommon.DocumentType.ProductPick;
            barLog.BillCode = moCode;//领料工单
            barLog.BarCode = barCode;
            barLog.BarCodeRemark = "生产工单领料";
            barLog.BarType = 1;
            barLog.SourceBarCode = barCode;
            barLog.LotNo = _barcCode.LotNo;
            barLog.DateCode = DateTime.Now;
            barLog.MaterialId = 0;
            barLog.MaterialCode = materialCode;
            barLog.WareHouseId = 0;
            barLog.WareHouseCode = _barcCode.WareHouseCode;
            barLog.LocationCode = _barcCode.WareHouseCode;
            barLog.SourceType = (int)EnumCommon.DocumentType.ProductPick;
            barLog.SourceCode = moCode;
            barLog.QTY = barcCodeQty;
            await _barcodeLogRepository.InsertAsync(barLog);
            dto.CountedQty = barcCodeQty + collectedQty;//显示已经扫码数量
            dto.ExceedQty = 0;
            dto.CurrentQty = barcCodeQty;//当前物料数量
            dto.LotCode = _barcCode.LotNo;//物料批次号
            return dto;
        }
        #endregion
#region 提交生产领料单
        public async Task SubmitMakeOrAuditBill(SubmitInputDto input)
        {
            string moCode = input.MOCode;//工单
            string moErpId = string.Empty;//源单ID
            var mo = await _moDRepository.FirstOrDefaultAsync(r => r.MOCode.Equals(moCode));
            if (mo == null)
            {
                throw new UserFriendlyException("生产工单不存在");
            }
            if (!string.IsNullOrWhiteSpace(mo.PMOCode))
            {
                moErpId = mo.ErpId;
            }
            else
            {
                var moSource = await _moDRepository.FirstOrDefaultAsync(r => r.MOCode.Equals(mo.PMOCode));
                if (string.IsNullOrEmpty(moSource.ErpId))
                {
                    throw new UserFriendlyException(string.Format("原工单[{0}],没有ERPID",moSource.MOCode));
                }
                moErpId = moSource.ErpId;
            }
            var depart = await _DepartmentRepository.FirstOrDefaultAsync(r=>r.Id==mo.DeptId);
            if (depart == null)
            {
                throw new UserFriendlyException(string.Format("该部门id[{0}]不存在",mo.DeptId));
            }
            var _barCodeLog = await _barcodeLogRepository.GetAllListAsync(r => r.SourceBarCode.Equals(moCode)
             && r.SourceBillType == (int)EnumCommon.DocumentType.ProductPick && r.InOutType == (int)EnumCommon.InAndOutType.Out);
            if (_barCodeLog == null)
            {
                throw new UserFriendlyException("该工单还未领料请勿提交");
            }
            //获取工单领料明细
            var moBom = await GetPrdPickApplyDetail(new GetDetailRegionInputDto { BillId = mo.Id });
            //已扫物料明细
            var barData = from a in _barCodeLog
                       group a by new { a.MaterialCode,a.WareHouseCode } into b
                       select new BarcodeLog
                       {
                           QTY = b.Sum(c => c.QTY.Value),
                           MaterialCode = b.Key.MaterialCode,
                           WareHouseCode = b.Key.WareHouseCode
                       };
            if (moBom.Count() != barData.Count())
            {
                throw new UserFriendlyException("请全部领料再提交");
            }
            //验证是否全部领料
            foreach (var itemBom in moBom)
            {
                var itemDate = barData.FirstOrDefault(t=>t.MaterialCode.Equals(itemBom.MaterialCode));
                if (itemDate == null)
                {
                    throw new UserFriendlyException(string.Format("物料[{0}],还未领料", itemBom.MaterialCode));
                }
                if (itemBom.Qty > itemDate.QTY)
                {
                    throw new UserFriendlyException(string.Format("该物料[{0}]需领{1}已领{2},请继续领完", itemBom.MaterialCode,itemBom.Qty,itemDate.QTY));
                }
            }

            //ERP完成生产领料
            #region  创建领料单
            ProductionPickingInput productionPickingInput = new ProductionPickingInput();
            ProductionPickingDataPage1 productionPickingDataPage1 = new ProductionPickingDataPage1();
            productionPickingDataPage1.FDeptID.FName = depart.Code;//领料部门
            productionPickingDataPage1.FSelTranType = ((int)EnumCommon.DocumentType.ProductPick).ToString();//选单类型
            productionPickingDataPage1.FBillerID.FName = AbpSession.FullName;//制单人   
            productionPickingDataPage1.FFManagerID.FName = AbpSession.FullName;//发料人
            productionPickingInput.Data.Page1.Add(productionPickingDataPage1);
            foreach (BarcodeLog item in barData)
            {
                int index = 1;
                ProductionPickingDataPage2 productionPickingDataPage2 = new ProductionPickingDataPage2();
                productionPickingDataPage2.FItemID.FName = item.MaterialCode;//物料代码
                productionPickingDataPage2.FQty = item.QTY.Value.ToString();//领料数量 
                productionPickingDataPage2.FDCSPID.FNumber = item.WareHouseCode;//领料仓位
                productionPickingDataPage2.FSCStockID1.FNumber = item.WareHouseCode;//领料仓库  
                productionPickingDataPage2.FSourceTranType = ((int)EnumCommon.DocumentType.Mo).ToString();//原单类型(生产任务单)
                productionPickingDataPage2.FSourceInterId = moErpId;//源单内码   
                productionPickingDataPage2.FICMOInterID = moErpId;//生产任务单内码 
                productionPickingDataPage2.FEntryID2 = index.ToString();//行号
                productionPickingInput.Data.Page2.Add(productionPickingDataPage2);
                index++;
            }
            //创建领料单
            K3Result resultProductionPicking = await _productStorageAppService.CommonPopstK3(productionPickingInput, "/PickList/Save");
            if (resultProductionPicking.StatusCode != 200)
            {
                throw new UserFriendlyException(resultProductionPicking.Message);
            }
            #region 启用审核
            //审核信息
            ProductStorageExamineDTO productStorageExamineDTO = new ProductStorageExamineDTO()
            {
                Data = new ProductStorageExamine() { FBillNo = resultProductionPicking.Data.BillNo, FChecker = AbpSession.FullName, FCheckDirection = "1", FDealComment = "PDA审核" }
            };
            //审核生产汇报/请检单
            K3Result resultProductionPicking2 = await _productStorageAppService.CommonPopstK3(productStorageExamineDTO, "/PickList/CheckBill");
            if (resultProductionPicking2.StatusCode != 200)
            {
                throw new UserFriendlyException(resultProductionPicking2.Message);
            }
            #endregion

            #region 完成审核
            //审核信息
            productStorageExamineDTO = new ProductStorageExamineDTO()
            {
                Data = new ProductStorageExamine() { FBillNo = resultProductionPicking.Data.BillNo, FChecker = AbpSession.FullName, FCheckDirection = "2", FDealComment = "PDA审核" }
            };
            //审核生产汇报/请检单
            K3Result resultProductionPicking3 = await _productStorageAppService.CommonPopstK3(productStorageExamineDTO, "/PickList/CheckBill");
            if (resultProductionPicking3.StatusCode != 200)
            {
                throw new UserFriendlyException(resultProductionPicking3.Message);
            }
            #endregion
            #endregion

            #region 更新MES库存信息
            //----------更新条码信息表-------------
            foreach (var barLog in _barCodeLog)
            {
                var barcode = await _barcodeRepository.FirstOrDefaultAsync(r=>r.BarCode.Equals(barLog.BarCode));
                barcode.CurrentQty -= barLog.QTY;
                await _barcodeRepository.UpdateAsync(barcode);
            }
            //----------更新库存表-----------------
            foreach (var itemBar in barData)
            {
                var storages = await _storageInfoRepository.GetAll().Where(p => p.OrgId.Value.Equals(AbpSession.OrgId.Value)
                                 && p.WareHouseCode == itemBar.WareHouseCode
                                 && p.MaterialCode.Equals(itemBar.MaterialCode)
                                ).FirstOrDefaultAsync();
                storages.QTY -= itemBar.QTY;
            }
            //----------生产工单关联领料单号----------------
            mo.PickMo = resultProductionPicking.Data.BillNo;
            await _moDRepository.UpdateAsync(mo);
            #endregion
        }

        #endregion
2.3 PDA操作界面

小微园产仓库管理_第3张图片

3. 产成品入库(业务流程图)
Created with Raphaël 2.2.0 A 开始 PDA扫描产品批次标签, 选择仓库完成产成品入库 F 结束
3.1 业务表

QC_PROCESS_CHECK_LOG(质检记录表)
INV_BARCODE(条码表)修改
INV_PRDINSTOCK_H(入库主表)新增
INV_PRDINSTOCK_D(入库明细表)新增
INV_STORAGEINFO(库存表)修改/新增

3.2 核心代码
        //半成品入库
        public async Task<InStrockSuccessDto> SetProductIntoJob(SetProductIntoJobInputList input)
        {
            if (AbpSession.UserName.IsEmptyOrNull())
            {
                throw new UserFriendlyException("未登陆");
            }
            try
            {
                string MoCode = string.Empty;//原始工单
                string MoId = string.Empty;//原工单ID
                string MaterialCode = string.Empty;//物料
                InStrockSuccessDto result = new InStrockSuccessDto() { Msg = "入库成功", issuccess = true };
                List<Barcode> listBarcode = new List<Barcode>();
                foreach (var item1 in input.listJobInput)
                {
                    int barInt = item1.BarcodeStr.ToInt32();
                    var nBarcode = await _barcodeRepository.FirstOrDefaultAsync(x => x.Id.Equals(barInt) && x.BarCodeStatus.Equals(0));

                    if (nBarcode != null)
                    {
                        var nMoD = await _moDRepository.FirstOrDefaultAsync(x => x.MOCode.Equals(nBarcode.SourceCode));
                        if (nMoD != null)
                        {
                            if (!nMoD.PMOCode.IsEmptyOrNull())
                            {
                                nBarcode.SourceCode = nMoD.PMOCode;
                            }
                            MoId = nMoD.ErpId;//工单ID赋值
                        }
                        else
                        {
                            throw new UserFriendlyException("无法查找到当前批次号【" + nBarcode.SourceCode + "】的来源工单");
                        }
                        listBarcode.Add(nBarcode);
                    }
                }
                if (listBarcode == null)
                {
                    throw new UserFriendlyException("listBarcode  p4592");
                }
                MoCode = listBarcode[0].SourceCode;//原始工单赋值
                if (listBarcode.Count() == 0)
                {
                    throw new UserFriendlyException("检查当前批次号是否已经入过库。");
                }
                if (listBarcode.Any(o => o.SourceCode != listBarcode[0].SourceCode))
                {
                    throw new UserFriendlyException("扫描列表中存在不同的工单,请检查");
                }
                ProductInStrockHeaderDto headerDto = new ProductInStrockHeaderDto();
                headerDto.DetailsDto = new List<ProductInStrockDetailDto>();
                headerDto.SourceCode = listBarcode[0].SourceCode;
                headerDto.WareHouseCode = input.WarehouseCode;
                headerDto.FFManagerNumber = AbpSession.UserName;
                headerDto.FSManagerNumber = AbpSession.UserName;
                #region 获取基础信息

                //获取部门Code
                var mODetail = await _moDRepository.FirstOrDefaultAsync(x => x.MOCode.Equals(MoCode));
                if (mODetail != null)
                {
                    var department = await _DepartmentRepository.FirstOrDefaultAsync(src => src.ERPID.Value.Equals(mODetail.DeptId.Value));
                    if (department != null)
                    {
                        headerDto.DeptCode = department.Code;
                    }
                }
                //获取库位Code
                var wareHouse = await _wareHouseRepository.FirstOrDefaultAsync(x => x.WhBarCode.Equals(headerDto.WareHouseCode));
                if (wareHouse != null)
                {
                    var region = await _regionRepository.FirstOrDefaultAsync(x => x.WhId == wareHouse.ERPID.Value);
                    if (region != null)
                    {
                        headerDto.LocationCode = region.RegionCode;
                    }
                }
                //根据生产任务单获取领料单
                var prdPick = await _prdPickDetail.FirstOrDefaultAsync(x => x.SourceCode.Equals(MoCode));
                if (prdPick != null)
                {
                    headerDto.PickingCode = prdPick.PickCode;
                }
                foreach (var v in listBarcode)
                {
                    Material material = await _materialRepository.FirstOrDefaultAsync(src => src.MaterialCode == v.MaterialCode);
                    ProductInStrockDetailDto DetailDto = new ProductInStrockDetailDto();
                    DetailDto.WareHouseCode = input.WarehouseCode;
                    DetailDto.MaterialCode = v.MaterialCode;
                    DetailDto.Qty = v.CurrentQty.ToInt32();
                    DetailDto.BarCode = v.BarCode;
                    if (material != null)
                    {
                        DetailDto.MaterialUnit = material.Unit;
                    }
                    headerDto.DetailsDto.Add(DetailDto);
                }
                MaterialCode = listBarcode[0].MaterialCode;

                #endregion
                var useK3 = await _valueSetCodeRepository.FirstOrDefaultAsync(r => r.TypeCode.Equals("k3User") && r.Code.Equals(AbpSession.UserName));
                if (useK3 == null)
                {
                    throw new UserFriendlyException("请在CPS维护K3账号");
                }
                #region  创建ERP单据

                #region  创建请检单任务汇报单
                ProductionReportInput productionReportInput = new ProductionReportInput();
                ProductionReportPage1 productionReportPage1 = new ProductionReportPage1();
                productionReportPage1.FWorkShop.FNumber = headerDto.DeptCode;//生产车间
                productionReportPage1.FSelTranType = ((int)EnumCommon.DocumentType.Mo).ToString();//选单类型
                productionReportPage1.FBillerID.FName = AbpSession.FullName;//制单人
                productionReportPage1.FDate = DateTime.Now.ToString();//创单日期
                productionReportInput.Data.Page1.Add(productionReportPage1);
                foreach (ProductInStrockDetailDto itemD in headerDto.DetailsDto)
                {
                    ProductionReportPage2 productionReportPage2 = new ProductionReportPage2();
                    productionReportPage2.FPlanStartDate = DateTime.Now.ToString();//计划开工日期
                    productionReportPage2.FPlanEndDate = DateTime.Now.ToString();//计划完成日期
                    productionReportPage2.FItemID.FNumber = itemD.MaterialCode;//产品代码
                    productionReportPage2.FUnitID.FName = itemD.MaterialUnit;//产品单位
                    productionReportPage2.FWorkShopID.FNumber = headerDto.DeptCode;//生产车间
                    productionReportPage2.FEntrySelfJ1168 = "全检";//检验方式
                    productionReportPage2.FAuxQtyPlan = itemD.Qty.ToString();//计划生产数量
                    productionReportPage2.FAuxQtyFinish = itemD.Qty.ToString();//实作数量
                    productionReportPage2.FAuxQtyPass = itemD.Qty.ToString();//合格数量
                    productionReportPage2.FNotPassAuxQty = "0";//不合格数量
                    productionReportPage2.FSourceBillNo = headerDto.SourceCode;//原单编号
                    productionReportPage2.FSourceInterId = MoId;//原单ID
                    productionReportPage2.FSourceTranType = ((int)EnumCommon.DocumentType.Mo).ToString();//原单类型(生产任务单)
                    productionReportPage2.FPPBomEntryID = "0";
                    productionReportInput.Data.Page2.Add(productionReportPage2);
                   
                }
                //创建生产汇报/请检单
                K3Result resultproductionReport = await _productStorageAppService.CommonPopstK3(productionReportInput, "/ICMORpt/Save");
                if (resultproductionReport.StatusCode != 200)
                {
                    throw new UserFriendlyException(resultproductionReport.Message);
                }
                #endregion
                #region  审核请检单任务汇报单
                #region 启用审核
                //审核信息
                ProductStorageExamineDTO productStorageExamineDTO = new ProductStorageExamineDTO()
                {
                    Data = new ProductStorageExamine() { FBillNo = resultproductionReport.Data.BillNo, FChecker = AbpSession.FullName, FCheckDirection = "1", FDealComment = "PDA审核" }
                };
                //审核生产汇报/请检单
                K3Result productionReport2 = await _productStorageAppService.CommonPopstK3(productStorageExamineDTO, "/ICMORpt/CheckBill");
                if (productionReport2.StatusCode != 200)
                {
                    throw new UserFriendlyException(productionReport2.Message);
                }
                #endregion
                #region 完成审核
                //审核信息
                productStorageExamineDTO = new ProductStorageExamineDTO()
                {
                    Data = new ProductStorageExamine() { FBillNo = resultproductionReport.Data.BillNo, FChecker = AbpSession.FullName, FCheckDirection = "2", FDealComment = "PDA审核" }
                };
                //审核生产汇报/请检单
                K3Result productionReport3 = await _productStorageAppService.CommonPopstK3(productStorageExamineDTO, "/ICMORpt/CheckBill");
                if (productionReport3.StatusCode != 200)
                {
                    throw new UserFriendlyException(productionReport3.Message);
                }
                #endregion
                #endregion
                #region 入库单
                ProductStorageInput instrockInput = new ProductStorageInput();
                ProductStorageDataPage1 inStrockH = new ProductStorageDataPage1();
                inStrockH.FHeadSelfA0232 = mODetail.PickMo;//领料单号  暂时屏蔽 上线再启用
                inStrockH.FDeptID.FNumber = headerDto.DeptCode;//部门code
                inStrockH.FROB = "1";//红蓝单标志
                inStrockH.FStatus = "Y";//审核标志
                inStrockH.FDCStockID.FNumber = headerDto.WareHouseCode;//仓库code
                inStrockH.FFManagerID.FNumber = headerDto.FFManagerNumber;//验收人
                inStrockH.FSManagerID.FNumber = headerDto.FSManagerNumber;//保管人
                inStrockH.FBillerID.FName = AbpSession.FullName;//制单人
                instrockInput.Data.Page1.Add(inStrockH);
                foreach (ProductInStrockDetailDto itemD in headerDto.DetailsDto)
                {
                    int index = 1;
                    ProductStorageDataPage2 inStrockD = new ProductStorageDataPage2();
                    inStrockD.FItemID.FNumber = itemD.MaterialCode;
                    inStrockD.FUnitID.FName = itemD.MaterialUnit;
                    inStrockD.FAuxQtyMust = itemD.Qty.ToString();
                    inStrockD.Fauxqty = itemD.Qty.ToString();
                    inStrockD.FDCStockID1.FNumber = itemD.WareHouseCode;
                    inStrockD.FDCSPID.FNumber = headerDto.LocationCode;//仓位
                    inStrockD.FBatchNo = itemD.BarCode;
                    inStrockD.FICMOBillNo = headerDto.SourceCode;
                    inStrockD.FSourceBillNo = resultproductionReport.Data.BillNo;//请检单单号
                    inStrockD.FSourceInterId = resultproductionReport.Data.BillInterID;//请检单ID
                    inStrockD.FEntryID2 = index.ToString();//请检单明细行号
                    inStrockD.FSourceEntryID = index.ToString();
                    inStrockD.FSourceTranType = ((int)EnumCommon.DocumentType.InspectionRequest).ToString();//单据类型(质检单)
                    instrockInput.Data.Page2.Add(inStrockD);
                    index++;
                }
                //创建入库单
                K3Result resultStorage = await _productStorageAppService.CommonPopstK3(instrockInput, "/ProductReceipt/Save");
                if (resultStorage.StatusCode != 200)
                {
                    throw new UserFriendlyException(resultStorage.Message);
                }
                result.useK3 = useK3.Value;
                result.billNo = resultStorage.Data.BillNo;

                #region  审核入库单 入库单逻辑为多级审核,所以直接操作K3数据库完成一级审核
                //                using (var uow = UnitOfWorkManager.Begin(TransactionScopeOption.Suppress))
                //                {
                //                    using (DapperDbContext Context = new DapperDbContext("K3DB"))
                //                    {
                //                        string strSQL = string.Format(
                //@"declare @ret int 
                //exec JQ_CheckICStockBill_ZSH  {0}, '{1}', {2}, @ret output
                //select @ret", Convert.ToInt32(result.useK3), DateTime.Now, Convert.ToInt32(resultStorage.Data.BillInterID));
                //                        int i = Convert.ToInt32(Context.Execute(strSQL));
                //                        if (i != 1)
                //                        {
                //                            throw new UserFriendlyException("入库单审核失败");
                //                        }
                //                    }
                //                    uow.Complete();
                //                }
                #endregion
                #region 审核信息  只有当单据为审批流时审批接口才能使用
                #region 启动审核
                ProductStorageExamineDTO productStorageExamineDTO2 = new ProductStorageExamineDTO()
                {
                    Data = new ProductStorageExamine() { FBillNo = resultStorage.Data.BillNo, FChecker = AbpSession.FullName, FCheckDirection = "1", FDealComment = "PDA审核" }
                };
                K3Result resultStorage2 = await _productStorageAppService.CommonPopstK3(productStorageExamineDTO2, "/ProductReceipt/CheckBill");
                if (resultStorage2.StatusCode != 200)
                {
                    throw new UserFriendlyException(resultStorage2.Message);
                }
                #endregion
                #region 完成审核
                //审核信息
                productStorageExamineDTO2 = new ProductStorageExamineDTO()
                {
                    Data = new ProductStorageExamine() { FBillNo = resultStorage.Data.BillNo, FChecker = AbpSession.FullName, FCheckDirection = "2", FDealComment = "PDA审核" }
                };
                //审核生产汇报/请检单
                K3Result resultStorage3 = await _productStorageAppService.CommonPopstK3(productStorageExamineDTO2, "/ProductReceipt/CheckBill");
                if (resultStorage3.StatusCode != 200)
                {
                    throw new UserFriendlyException(resultStorage3.Message);
                }
                #endregion
                #endregion

                #endregion

                #endregion

                #region 更新MES状态
               
                #region 更新Barcode表
                //批次提交成功后修改状态值为1
                foreach (var item in listBarcode)
                {
                    item.BarCodeStatus = 1;
                    item.LocationCode = headerDto.LocationCode;
                    item.ReceiptCode = resultStorage.Data.BillNo;
                    item.WareHouseCode = headerDto.WareHouseCode;
                    item.LocationCode = headerDto.LocationCode;
                    await _barcodeRepository.UpdateAsync(item);

                    #region 记录INV_BARCODELOG历史记录表
                    BarcodeLog barLog = new BarcodeLog();
                    barLog.TenantId = AbpSession.TenantId;
                    barLog.OrgId = AbpSession.OrgId;
                    barLog.InOutType = (int)EnumCommon.InAndOutType.In;
                    barLog.SourceBillType = (int)EnumCommon.DocumentType.InspectionRequest;
                    barLog.TargetBillType = (int)EnumCommon.DocumentType.WarehouseReceipt;
                    barLog.BillCode = resultStorage.Data.BillNo;//ERP回写入库单
                    barLog.BarCode = item.BarCode;
                    barLog.BarCodeRemark = "ERP回写入库单";
                    barLog.BarType = 1;
                    barLog.SourceBarCode = item.BarCode;
                    barLog.LotNo = item.BarCode;
                    barLog.DateCode = DateTime.Now;
                    barLog.MaterialId = item.MaterialId;
                    barLog.MaterialCode = item.MaterialCode;
                    barLog.WareHouseId = 0;
                    barLog.WareHouseCode = headerDto.WareHouseCode;
                    barLog.LocationCode = headerDto.LocationCode;
                    barLog.SourceType = (int)EnumCommon.DocumentType.InspectionRequest;
                    barLog.SourceCode = resultproductionReport.Data.BillNo;
                    barLog.QTY = item.CurrentQty;
                    await _barcodeLogRepository.InsertAsync(barLog);
                    #endregion
                }
                #endregion
                #region 创建入库单
                #region 单据主档
                PrdInStockHeader prdInStockHeader = new PrdInStockHeader();
                prdInStockHeader.TenantId = AbpSession.TenantId;
                prdInStockHeader.OrgId = AbpSession.OrgId;
                prdInStockHeader.InStockCode = resultStorage.Data.BillNo;
                prdInStockHeader.InStockDate = DateTime.Now;
                prdInStockHeader.InStockStatus = 2;
                prdInStockHeader.ROB = 0;
                prdInStockHeader.BizType = 1;
                prdInStockHeader.CheckUserName = AbpSession.UserName;
                prdInStockHeader.CheckDate = DateTime.Now;
                prdInStockHeader.Custodian = AbpSession.UserName;
                prdInStockHeader.IsActive = true;
                var prdInStockHeadeId = await _prdInStockHeaderRepository.InsertAndGetIdAsync(prdInStockHeader);
                #endregion
                #region 单据明细
                foreach (var item in listBarcode)
                {
                    int index = 1;
                    PrdInStockDetail prdInStockDetail = new PrdInStockDetail();
                    prdInStockDetail.TenantId = AbpSession.TenantId;
                    prdInStockDetail.OrgId = AbpSession.OrgId;
                    prdInStockDetail.InStockId = prdInStockHeadeId;
                    prdInStockDetail.InStockCode = resultStorage.Data.BillNo;
                    prdInStockDetail.InStockLine = index;
                    prdInStockDetail.MaterialId = item.MaterialId.Value;
                    prdInStockDetail.MaterialCode = item.MaterialCode;
                    prdInStockDetail.Qty = item.CurrentQty.Value;
                    prdInStockDetail.ProductType = 1;
                    prdInStockDetail.InStockType = 1;
                    prdInStockDetail.WareHouseCode = headerDto.WareHouseCode;
                    prdInStockDetail.LocationCode = headerDto.LocationCode;
                    prdInStockDetail.BarCode = item.BarCode;
                    prdInStockDetail.MOCode = item.SourceCode;
                    prdInStockDetail.MOLine = index;
                    prdInStockDetail.SourceCode = resultproductionReport.Data.BillNo;

                    await _prdInStockDetailRepository.InsertAsync(prdInStockDetail);
                    index++;
                }
                #endregion
                #endregion
                #region 更新库存表

                foreach (var item in listBarcode)
                {
                    decimal dInitialQty = 0; // 期初库存
                    decimal dLastQty = 0;    // 期末库存
                    var storages = await _storageInfoRepository.GetAll().Where(p => p.OrgId.Value.Equals(AbpSession.OrgId.Value)
                                 && p.WareHouseCode == headerDto.WareHouseCode
                                 && p.MaterialId == item.MaterialId.Value && p.MaterialCode.Equals(item.MaterialCode)
                                ).ToListAsync();
                    if (storages.Count <= 0)
                    {
                        StorageInfo sto = new StorageInfo
                        {
                            TenantId = AbpSession.TenantId,
                            OrgId = AbpSession.OrgId,
                            WareHouseId = 0,
                            WareHouseCode = headerDto.WareHouseCode,
                            MaterialId = item.MaterialId.Value,
                            MaterialCode = item.MaterialCode,
                            QTY = item.CurrentQty,
                            LockQty = 0
                        };
                        await _storageInfoRepository.InsertAsync(sto);
                    }
                    else
                    {
                        StorageInfo sto = storages[0];
                        dInitialQty = sto.QTY ?? 0;
                        sto.QTY = (sto.QTY ?? 0) + item.CurrentQty;
                        dLastQty = sto.QTY ?? 0;
                        await _storageInfoRepository.UpdateAsync(sto);
                    }
                }
                #endregion

                #endregion
                Logger.Error("结束");
                return result;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
3.3 PDA操作界面
  • 接口

/============================== 入库请求 ========/
委外单列表:api/services/wpda/po/QueryWWPOList
采购单查询:api/services/wpda/po/QueryPODataByInput
采购单列表:api/services/wpda/po/QueryPOList
采购单表头 表体数据:api/services/wpda/po/GetPODataByCode
采购单请点记录:api/services/wpda/po/POGetReceiveRecord
获取采购单物料清点的表体:api/services/wpda/po/GetPODetailsByCode
采购单物品清点修改:api/services/wpda/po/POUpdateReceiveRecord
采购单物品清点删除:api/services/wpda/po/PODeleteReceiveRecord
采购单物品清点保存:api/services/wpda/po/POSaveReceive
送货单查询:api/services/wpda/po/QueryASNDataByBarcode
送货单请点记录:api/services/wpda/po/ASNGetReceiveRecord
获取送货单物料清点的表体:api/services/wpda/po/GetASNDetailsByCode
送货单物品清点修改:api/services/wpda/po/ASNUpdateReceiveRecord
送货单物品清点删除:api/services/wpda/po/ASNDeleteReceiveRecord
送货单物品清点保存:api/services/wpda/po/ASNSaveReceive
提交制单和审核:api/services/wpda/common/SubmitMakeOrAuditBill
扫描提交清点数据:api/services/wpda/po/POCheckByCode
wedty
/======== 品质检验 ========/
获取质量检验的列表:api/services/wpda/IQC/IQCGetDefaultReceiptForIQC
查询来料质检列表:api/services/wpda/IQC/IQCQueryReceiptForIQC
获取AQL的列表:api/services/wpda/IQC/IQCGetAQLList
设置AQL的参数:api/services/wpda/IQC/IQCSetAQLValue
免检:api/services/wpda/IQC/IQCSubmitExemption
获取普通质检:api/services/wpda/IQC/IQCGetNormalData
提交普通质检:api/services/wpda/IQC/IQCSetNormalData
获得质检条码信息:api/services/wpda/IQC/IQCGetBarcodeData
质检拒收:api/services/wpda/IQC/IQCSetBarcodeReject
质检确认:api/services/wpda/IQC/IQCSubmitFinish
获取高级质检1 的数据:api/services/wpda/IQC/IQCGetAdvanceData
获取高级质检2 的数据:api/services/wpda/IQC/IQCGetAdvanceData
提交高级质检1 的数据:api/services/wpda/IQC/IQCSetAdvance1Data
提交高级质检2 的数据:api/services/wpda/IQC/IQCSetAdvance2Data
获取高级质检2 质检项目:api/services/wpda/IQC/GetIQCAdvance2CheckItem
修改高检二质检项目:api/services/wpda/IQC/IQCUpdateAdvance2Item
扫码质检:api/services/wpda/iQC/IQCQueryReceiptForIQC
获取标签待质检信息:/api/services/wpda/iQC/GetCheckData
提交标签质检信息:/api/services/wpda/iQC/SubmitCheckData
/======== MRP评审 ====/
查询MRP评审信息列表:api/services/wpda/IQC/IQCGetMRPReviewData
提交评审结果:api/services/wpda/IQC/IQCSetMRPReviewData
/======== 条码修改 /
查询未入库的条码信息:api/services/wpda/BarcodeEdit/BarEditGetUnInstockBarcodeData
修改未入库的条码信息:api/services/wpda/BarcodeEdit/BarEditSetBarcodeQty
/======== 来料入库 /
扫码查询收货单信息:api/services/wpda/PurInstock/QueryReceiptDataByInput
库位验证:api/services/wpda/common/VerifyBinCode
物料扫码:api/services/wpda/common/SubmitBarcodeInstock
生成入库单:api/services/wpda/common/SubmitMakeOrAuditBill
扫码锁定标签:/api/services/wpda/purInstock/LockBarcodeAsync
加载单据详情(已锁定的条码标签):/api/services/wpda/purInstock/LoadLockBarcodeList
修改库位:/api/services/wpda/purInstock/AlterBarcodeLocation
提交入库信息:/api/services/wpda/purInstock/SubmitInstockInfo
/======== 采购退料(制单) /
扫码加载采购退料信息:api/services/wpda/PurReturn/QueryAuditPOBillForPurReturn
扫码退料:api/services/wpda/PurReturn/SubmitBarcodePurReturn
确认提交:api/services/wpda/common/SubmitMakeOrAuditBill
/======== 生产领料(申请制单) /
根据单号、日期、部门搜索:api/services/wpda/PrdPick/GetPickApplyList
申请单详情:api/services/wpda/PrdPick/GetPrdPickApplyData
加载单据明细具体数据:api/services/wpda/common/GetMaterialLotData
清点扫描:api/services/wpda/common/SubmitBarcodeLotPickOut
生成领料单:api/services/wpda/common/SubmitMakeOrAuditBill
/======== 调拨========/
根据单号、日期搜索:api/services/wpda/Transfer/QueryTransferListForOutStock
调拨单详情:api/services/wpda/Transfer/GetTransferByInputForOutStock
具体记录明细详情:api/services/wpda/common/GetMaterialLotData
扫描物料条码:api/services/wpda/common/SubmitTransfer
拆包:api/services/wpda/common/SubmitTransferByPick
提交:api/services/wpda/common/SubmitMakeOrAuditBill
/================ 产成品入库 ========/
搜索产成品-生单的单号:api/services/wpda/PrdInstock/QueryWOInstockList
扫物料码并上架:api/services/wpda/common/SubmitBarcodeInstock
生成入库单:api/services/wpda/common/SubmitMakeOrAuditBill
/======== 其他入库 ========/
汇总已扫总数:api/services/wpda/OtherInstock/GetMakeOtherStockTotal
已扫码列表:api/services/wpda/OtherInstock/GetMakeOtherStockDetail
扫物料码并上架:api/services/wpda/common/SubmitBarcodeInstock
生成其他入库单:api/services/wpda/common/SubmitMakeOrAuditBill
/======== 其他入库 ========/
汇总已扫总数:api/services/wpda/OtherInstock/GetMakeOtherStockTotal
已扫码列表:api/services/wpda/OtherInstock/GetMakeOtherStockDetail
扫码出库:api/services/wpda/common/SubmitBarcodeOutAudit
生成其他出库单:api/services/wpda/common/SubmitMakeOrAuditBill
/======== 生产退料(BOM内) ========/
汇总已扫总数:api/services/wpda/OtherInstock/GetMakeOtherStockTotal
扫码:api/services/wpda/common/SubmitProductReturnByBarcode
详情:api/services/wpda/common/GetProductReturnDetail
提交:api/services/wpda/common/SubmitMakeOrAuditBill
/======== 销售出库(发货通知单) ========/
搜索发货通知单列表:api/services/wpda/SalesOutStock/QueryDNOutList
发货通知单详情:api/services/wpda/SalesOutStock/GetDNDataForPick
明细记录详情:api/services/wpda/SalesOutStock/GetDNDataForPick
生成出库单:api/services/wpda/common/SubmitMakeOrAuditBill
/======== 库存锁定 ========/
搜索单据:api/services/wpda/StockCheck/QueryCheckStockList
加载单据详情:api/services/wpda/StockCheck/GetCheckStockByCode
/======== 盘点 ========/
搜索单据:api/services/wpda/StockCheck/QueryCheckStockList
加载单据详情:api/services/wpda/StockCheck/GetCheckStockByCode
搜索物料:api/services/wpda/StockCheck/GetMaterialData
获取记录:api/services/wpda/StockCheck/GetCheckStockPageRecord
获取单据明细:api/services/wpda/StockCheck/GetCheckStockPageDetail
确定盘点数量:api/services/wpda/StockCheck/SubmitCheckData
/======== 生产退料(BOM外) ========/
搜索:api/services/wpda/common/SearchProductRuturnApplyBill
扫描条码:api/services/wpda/common/SubmitProductReturnApplyByBarcode
单据详情:/api/services/wpda/common/SearchSubmitDetailForProductReturnApply
/======== 库存报废 ========/
汇总已扫总数:api/services/wpda/OtherInstock/GetMakeOtherStockTotal
扫条码:api/services/wpda/common/GetLableData
报废:api/services/wpda/common/ScrapInventory
报废列表:api/services/wpda/common/ScrapDetail
撤销报废:api/services/wpda/common/RepealScrap
/======== 销售退货 ==============================/
搜索:api/services/wpda/SalesReturn/QuerySalesReturnList
加载单据信息:api/services/wpda/SalesReturn/GetSalesReturnData
提交条码入库:api/services/wpda/common/SubmitBarcodeInstock
提交审核:api/services/wpda/common/SubmitMakeOrAuditBill

Created with Raphaël 2.2.0 A 开始框 B 处理框 C 判断框(是或否?) E 输入输出框 F 结束框 D 子流程 yes no
Created with Raphaël 2.2.0 A:开始框 B:处理框 C: 判断框(是或否?) E 输入输出框 F:结束框 D:子流程 yes no

你可能感兴趣的:(项目)