Example #1
0
        public void ReportOrderOp(int orderOpId, decimal reportQty, decimal scrapQty, DateTime effectiveDate)
        {
            OrderOperation orderOperation = this.genericMgr.FindById<OrderOperation>(orderOpId);
            OrderMaster orderMaster = this.genericMgr.FindEntityWithNativeSql<OrderMaster>("select * from ORD_OrderMstr_4 WITH(NOLOCK) where OrderNo = ?", orderOperation.OrderNo).Single();
            OrderDetail orderDetail = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_4 WITH(NOLOCK) where OrderNo = ?", orderOperation.OrderNo).Single();
            IList<ProductLineMap> prodLineMapList = this.genericMgr.FindAll<ProductLineMap>("select s from ProductLineMap as s where s.ProductLine = ?", orderMaster.Flow);
            //            IList<OrderOperation> refOrderOperationList = null;
            //            if (orderOperation.NeedReport)
            //            {
            //                refOrderOperationList = this.genericMgr.FindEntityWithNativeSql<OrderOperation>(@"select * from ORD_OrderOp WITH(NOLOCK) where OrderNo= ?
            //                    and Op > ISNULL((select Op from ORD_OrderOp WITH(NOLOCK) where OrderNo = ? and Op < ? and NeedReport = ?), 0) and Op < ?"
            //                        , new object[] { orderMaster.OrderNo, orderMaster.OrderNo, orderOperation.Operation, true, orderOperation.Operation });
            //            }

            if (orderMaster.Status != CodeMaster.OrderStatus.InProcess)
            {
                throw new BusinessException("状态为{1}的生产单{0}不能报工",
                            orderMaster.OrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.OrderStatus, ((int)orderMaster.Status).ToString()));
            }

            if (!orderOperation.NeedReport)
            {
                throw new BusinessException("不是报工工序不能报工。");
            }

            #region 检查比报工工序小的工序是否报工
            //2013-10-23 三勇说对于试制订单来说不要去严格限制报工顺序
            int notSkipCheck = (from prodLine in prodLineMapList
                                where prodLine.SAPProductLine == "ZP01"
                                || prodLine.SAPProductLine == "ZP02"
                                || prodLine.SAPProductLine == "Z904"
                                select prodLine).Count();
            if (notSkipCheck == 0)
            {
                int count = this.genericMgr.FindAllWithNativeSql<int>(@"select count(*) as counter 
                                                        from ORD_OrderOp as op 
                                                        left join SAP_ProdOpReport as rp on op.Id = rp.OrderOpId and rp.IsCancel = ?
                                                        where op.OrderNo = ? and op.NeedReport = ? and op.Op < ? and rp.Id is null", new object[] { false, orderOperation.OrderNo, true, orderOperation.Operation }).SingleOrDefault();

                if (count > 0)
                {
                    throw new BusinessException("有小于报工工序的工序还未报工。");
                }
            }
            #endregion

            DateTime dateTimeNow = DateTime.Now;

            #region 报工
            if (reportQty > 0)
            {
                OrderOperationReport orderOperationReport = new OrderOperationReport();
                orderOperationReport.OrderNo = orderMaster.OrderNo;
                orderOperationReport.OrderDetailId = orderDetail.Id;
                orderOperationReport.OrderOperationId = orderOperation.Id;
                orderOperationReport.Operation = orderOperation.Operation;
                orderOperationReport.ReportQty = reportQty;
                orderOperationReport.ScrapQty = 0;
                orderOperationReport.BackflushQty = reportQty;
                orderOperationReport.WorkCenter = orderOperation.WorkCenter;
                orderOperationReport.Status = CodeMaster.OrderOpReportStatus.Close;
                orderOperationReport.EffectiveDate = effectiveDate;

                com.Sconit.Entity.SAP.ORD.ProdOpReport prodOpReport = new com.Sconit.Entity.SAP.ORD.ProdOpReport();
                prodOpReport.AUFNR = orderMaster.ExternalOrderNo;
                prodOpReport.WORKCENTER = orderOperation.WorkCenter;
                prodOpReport.GAMNG = reportQty;
                prodOpReport.Status = Entity.SAP.StatusEnum.Pending;
                prodOpReport.CreateDate = dateTimeNow;
                prodOpReport.LastModifyDate = dateTimeNow;
                prodOpReport.ErrorCount = 0;
                prodOpReport.SCRAP = 0;
                prodOpReport.IsCancel = false;
                prodOpReport.OrderNo = orderOperation.OrderNo;
                prodOpReport.OrderOpId = orderOperation.Id;
                prodOpReport.EffectiveDate = effectiveDate;
                prodOpReport.ProdLine = orderMaster.Flow;

                #region 成品收货
                if (orderOperation.IsReceiveFinishGoods)
                {
                    orderDetail.OrderDetailInputs = new List<OrderDetailInput>();
                    OrderDetailInput orderDetailInput = new OrderDetailInput();
                    orderDetailInput.ReceiveQty = reportQty;
                    orderDetail.OrderDetailInputs.Add(orderDetailInput);
                    IList<OrderDetail> orderDetailList = new List<OrderDetail>();
                    orderDetailList.Add(orderDetail);

                    ReceiptMaster receiptMaster = this.ReceiveOrder(orderDetailList);

                    orderOperationReport.ReceiptNo = receiptMaster.ReceiptNo;
                    prodOpReport.ReceiptNo = receiptMaster.ReceiptNo;
                }
                #endregion

                this.genericMgr.Create(orderOperationReport);

                prodOpReport.OrderOpReportId = orderOperationReport.Id;
                this.genericMgr.Create(prodOpReport);

                #region 反冲物料
                //if (orderOperation.NeedReport)
                //{
                //    orderOperation.CurrentReportQty = reportQty;
                //    this.productionLineMgr.BackflushProductOrder(orderOperation, orderOperationReport);

                //    if (refOrderOperationList != null && refOrderOperationList.Count > 0)
                //    {
                //        foreach (OrderOperation refOrderOperation in refOrderOperationList)
                //        {
                //            refOrderOperation.CurrentReportQty = reportQty;
                //            this.productionLineMgr.BackflushProductOrder(refOrderOperation, orderOperationReport);

                //            refOrderOperation.BackflushQty += reportQty;
                //            refOrderOperation.ReportQty += reportQty;
                //        }
                //    }
                //}
                #endregion

                //orderOperation.BackflushQty += reportQty;
                if (orderOperation.ReportQty >= orderDetail.OrderedQty)
                {
                    throw new BusinessException("已报工数量大于等于订单数量。");
                }

                orderOperation.ReportQty += reportQty;
            }
            else if (reportQty < 0)
            {
                throw new BusinessException("报工数量不能小于0。");
            }
            #endregion

            #region 废品
            if (scrapQty > 0)
            {
                OrderOperationReport orderOperationReport = new OrderOperationReport();
                orderOperationReport.OrderNo = orderMaster.OrderNo;
                orderOperationReport.OrderDetailId = orderDetail.Id;
                orderOperationReport.OrderOperationId = orderOperation.Id;
                orderOperationReport.Operation = orderOperation.Operation;
                orderOperationReport.ReportQty = 0;
                orderOperationReport.ScrapQty = scrapQty;
                orderOperationReport.BackflushQty = scrapQty;
                orderOperationReport.WorkCenter = orderOperation.WorkCenter;
                orderOperationReport.Status = CodeMaster.OrderOpReportStatus.Close;
                orderOperationReport.EffectiveDate = effectiveDate;

                com.Sconit.Entity.SAP.ORD.ProdOpReport prodOpReport = new com.Sconit.Entity.SAP.ORD.ProdOpReport();
                prodOpReport.AUFNR = orderMaster.ExternalOrderNo;
                prodOpReport.WORKCENTER = orderOperation.WorkCenter;
                prodOpReport.GAMNG = 0;
                prodOpReport.Status = Entity.SAP.StatusEnum.Pending;
                prodOpReport.CreateDate = dateTimeNow;
                prodOpReport.LastModifyDate = dateTimeNow;
                prodOpReport.ErrorCount = 0;
                prodOpReport.SCRAP = scrapQty;
                prodOpReport.IsCancel = false;
                prodOpReport.OrderNo = orderOperation.OrderNo;
                prodOpReport.OrderOpId = orderOperation.Id;
                prodOpReport.EffectiveDate = effectiveDate;
                prodOpReport.ProdLine = orderMaster.Flow;

                #region 成品收货
                if (orderOperation.IsReceiveFinishGoods)
                {
                    orderDetail.OrderDetailInputs = new List<OrderDetailInput>();
                    OrderDetailInput orderDetailInput = new OrderDetailInput();
                    orderDetailInput.ScrapQty = scrapQty;
                    orderDetail.OrderDetailInputs.Add(orderDetailInput);
                    IList<OrderDetail> orderDetailList = new List<OrderDetail>();
                    orderDetailList.Add(orderDetail);

                    ReceiptMaster receiptMaster = this.ReceiveOrder(orderDetailList);

                    orderOperationReport.ReceiptNo = receiptMaster.ReceiptNo;
                    prodOpReport.ReceiptNo = receiptMaster.ReceiptNo;
                }
                #endregion

                this.genericMgr.Create(orderOperationReport);

                prodOpReport.OrderOpReportId = orderOperationReport.Id;
                this.genericMgr.Create(prodOpReport);

                #region 反冲物料
                //if (orderOperation.NeedReport)
                //{
                //    orderOperation.CurrentReportQty = 0;
                //    orderOperation.CurrentScrapQty = scrapQty;
                //    this.productionLineMgr.BackflushProductOrder(orderOperation, orderOperationReport);

                //    if (refOrderOperationList != null && refOrderOperationList.Count > 0)
                //    {
                //        foreach (OrderOperation refOrderOperation in refOrderOperationList)
                //        {
                //            refOrderOperation.CurrentReportQty = 0;
                //            refOrderOperation.CurrentScrapQty = scrapQty;
                //            this.productionLineMgr.BackflushProductOrder(refOrderOperation, orderOperationReport);

                //            refOrderOperation.BackflushQty += scrapQty;
                //            refOrderOperation.ScrapQty += scrapQty;
                //        }
                //    }
                //}
                #endregion

                //orderOperation.BackflushQty += scrapQty;            
                orderOperation.ScrapQty += scrapQty;
            }
            else if (scrapQty < 0)
            {
                throw new BusinessException("废品数量不能小于0。");
            }
            #endregion

            this.genericMgr.Update(orderOperation);
            //if (refOrderOperationList != null && refOrderOperationList.Count > 0)
            //{
            //    foreach (OrderOperation refOrderOperation in refOrderOperationList)
            //    {
            //        this.genericMgr.Update(refOrderOperation);
            //    }
            //}
        }
        public void AntiBackflushProductOrder(OrderOperation orderOperation, OrderOperationReport orderOperationReport)
        {
            IList<OrderBomDetail> orderBomDetailList = this.genericMgr.FindEntityWithNativeSql<OrderBomDetail>(@"select * from ORD_OrderBomDet where OrderNo = ? and Op = ? and OrderQty <> 0", new object[] { orderOperation.OrderNo, orderOperation.Operation });
            if (orderBomDetailList != null && orderBomDetailList.Count > 0)
            {
                FlowMaster prodLine = this.genericMgr.FindEntityWithNativeSql<FlowMaster>(@"select * from SCM_FlowMstr where Code in (select Flow from ORD_OrderMstr_4 where OrderNo = ?)", orderOperation.OrderNo).Single();
                string fgItem = this.genericMgr.FindAllWithNativeSql<string>(@"select Item from ORD_OrderDet_4 where OrderNo = ?", orderOperation.OrderNo).Single();

                IList<BackflushInput> backflushInputList = (from bom in orderBomDetailList
                                                            where bom.OrderedQty != 0
                                                            select new BackflushInput
                                                            {
                                                                OrderNo = bom.OrderNo,
                                                                OrderDetailId = bom.OrderDetailId,
                                                                OrderDetailSequence = bom.OrderDetailSequence,
                                                                OrderBomDetail = bom,
                                                                OrderType = CodeMaster.OrderType.Production,
                                                                OrderSubType = CodeMaster.OrderSubType.Normal,
                                                                FGItem = fgItem,
                                                                Item = bom.Item,
                                                                ItemDescription = bom.ItemDescription,
                                                                ReferenceItemCode = bom.ReferenceItemCode,
                                                                Uom = bom.Uom,
                                                                BaseUom = bom.BaseUom,
                                                                UnitQty = bom.UnitQty,
                                                                Operation = bom.Operation,
                                                                OpReference = bom.OpReference,
                                                                Location = bom.Location,
                                                                ProductLine = prodLine.Code,
                                                                Qty = bom.BomUnitQty * (orderOperationReport.ReportQty + orderOperationReport.ScrapQty),
                                                                CurrentProductLine = prodLine,
                                                                EffectiveDate = orderOperationReport.EffectiveDate,
                                                                OrderOpReportId = orderOperationReport.Id,
                                                                OrderOpId = orderOperation.Id,
                                                                WorkCenter = orderOperation.WorkCenter,
                                                            }).ToList();

                IList<InventoryTransaction> inventoryTransactionList = this.locationDetailMgr.CancelBackflushProductMaterial(backflushInputList);
            }
        }