Ejemplo n.º 1
0
 public void AddIpDetail(IpDetail ipDetail)
 {
     if (IpDetails == null)
     {
         IpDetails = new List<IpDetail>();
     }
     IpDetails.Add(ipDetail);
 }
Ejemplo n.º 2
0
        private void MatchIpDetailInput(IpDetail ipDetail, IpDetailInput ipDetailInput, IList<IpLocationDetail> ipLocationDetailList, ref IpDetail gapIpDetail)
        {
            decimal remainQty = ipDetailInput.ReceiveQty * ipDetail.UnitQty;  //转为库存单位
            foreach (IpLocationDetail ipLocationDetail in ipLocationDetailList)
            {
                if (ipLocationDetail.IsClose)
                {
                    continue;
                }

                //iplocationdet只可能为正数
                if (ipLocationDetail.RemainReceiveQty >= remainQty)
                {
                    //收货明细匹配完
                    #region 添加收货记录和IpLocationDetail的映射关系
                    IpLocationDetail receivedIpLocationDetail = Mapper.Map<IpLocationDetail, IpLocationDetail>(ipLocationDetail);
                    receivedIpLocationDetail.ReceivedQty = remainQty;
                    ipDetailInput.AddReceivedIpLocationDetail(receivedIpLocationDetail);
                    #endregion

                    ipLocationDetail.ReceivedQty += remainQty;
                    remainQty = 0;
                    if (ipLocationDetail.Qty == ipLocationDetail.ReceivedQty)
                    {
                        ipLocationDetail.IsClose = true;
                    }
                }
                else
                {
                    //收货明细未匹配完
                    #region 添加收货记录和IpLocationDetail的映射关系
                    IpLocationDetail receivedIpLocationDetail = Mapper.Map<IpLocationDetail, IpLocationDetail>(ipLocationDetail);
                    receivedIpLocationDetail.ReceivedQty = ipLocationDetail.RemainReceiveQty;
                    ipDetailInput.AddReceivedIpLocationDetail(receivedIpLocationDetail);
                    #endregion

                    remainQty -= ipLocationDetail.RemainReceiveQty;
                    ipLocationDetail.ReceivedQty = ipLocationDetail.Qty;
                    ipLocationDetail.IsClose = true;
                }

                //更新
                if (ipLocationDetail.Id > 0)
                {
                    genericMgr.Update(ipLocationDetail);
                }

                if (remainQty == 0)
                {
                    //匹配完,跳出循环
                    break;
                }
            }

            //超收,还有未匹配完的数量
            if (remainQty > 0)
            {
                #region 记录差异
                if (gapIpDetail == null || !gapIpDetail.GapIpDetailId.HasValue)
                {
                    gapIpDetail = Mapper.Map<IpDetail, IpDetail>(ipDetail);
                    gapIpDetail.Type = com.Sconit.CodeMaster.IpDetailType.Gap;
                    gapIpDetail.GapReceiptNo = string.Empty;
                    gapIpDetail.ReceivedQty = 0;
                    gapIpDetail.IsClose = false;
                    gapIpDetail.GapIpDetailId = ipDetail.Id;
                }

                gapIpDetail.Qty += -(remainQty / ipDetail.UnitQty);          //多收,数量为负,转为订单单位

                IpLocationDetail gapIpLocationDetail = new IpLocationDetail();
                gapIpLocationDetail.IpNo = ipDetail.IpNo;
                gapIpLocationDetail.OrderType = ipDetail.OrderType;
                gapIpLocationDetail.OrderDetailId = ipDetail.OrderDetailId;
                gapIpLocationDetail.Item = ipDetail.Item;
                gapIpLocationDetail.HuId = null;  //收货未匹配产生的差异全部为数量(除了条码匹配条码)
                gapIpLocationDetail.LotNo = null;
                gapIpLocationDetail.IsCreatePlanBill = false;
                gapIpLocationDetail.PlanBill = null;
                gapIpLocationDetail.ActingBill = null;
                gapIpLocationDetail.IsFreeze = false;
                gapIpLocationDetail.IsATP = false;          //差异不能进行MRP运算
                gapIpLocationDetail.QualityType = ipDetail.QualityType;
                gapIpLocationDetail.OccupyType = com.Sconit.CodeMaster.OccupyType.None;
                gapIpLocationDetail.OccupyReferenceNo = null;
                gapIpLocationDetail.Qty = -remainQty;   //多收,产生负数的差异
                gapIpLocationDetail.ReceivedQty = 0;
                gapIpLocationDetail.IsClose = false;

                gapIpDetail.AddIpLocationDetail(gapIpLocationDetail);
                #endregion
            }
        }
Ejemplo n.º 3
0
        private IpDetail CycleMatchIpDetailInput(IpDetail ipDetail, IList<IpDetailInput> ipDetailInputList, IList<IpLocationDetail> ipLocationDetailList)
        {
            IpDetail gapIpDetail = null;
            #region 循环匹配收货记录和送货单库存明细
            foreach (IpDetailInput ipDetailInput in ipDetailInputList)
            {
                MatchIpDetailInput(ipDetail, ipDetailInput, ipLocationDetailList, ref gapIpDetail);
            }
            #endregion

            return gapIpDetail;
        }
Ejemplo n.º 4
0
        private ReceiptMaster ReceiveOrder(IList<OrderDetail> orderDetailList, bool isCheckKitTraceItem, ProductLineMap productLineMap, DateTime effectiveDate, string ipNo)
        {
            #region 判断是否全0收货
            if (orderDetailList == null || orderDetailList.Count == 0)
            {
                throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveDetailIsEmpty);
            }

            IList<OrderDetail> nonZeroOrderDetailList = orderDetailList.Where(o => o.ReceiveQtyInput != 0 || o.ScrapQtyInput != 0).ToList();

            if (nonZeroOrderDetailList.Count == 0)
            {
                throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveDetailIsEmpty);
            }
            #endregion

            #region 查询订单头对象
            IList<OrderMaster> orderMasterList = LoadOrderMasters(nonZeroOrderDetailList.Select(p => p.OrderNo).Distinct(), true);
            #endregion

            #region 获取收货订单类型
            IList<com.Sconit.CodeMaster.OrderType> orderTypeList = (from orderMaster in orderMasterList
                                                                    group orderMaster by orderMaster.Type into result
                                                                    select result.Key).ToList();

            if (orderTypeList.Count > 1)
            {
                throw new BusinessException(Resources.ORD.OrderMaster.Errors_CannotMixOrderTypeReceive);
            }

            com.Sconit.CodeMaster.OrderType orderType = orderTypeList.First();
            #endregion

            #region 计划协议不能按收货校验
            if (orderType == CodeMaster.OrderType.ScheduleLine)
            {
                throw new BusinessException("计划协议不能按订单收货。");
            }
            #endregion

            #region 排序单不能按订单收货校验
            if (orderMasterList.Where(o => o.OrderStrategy == CodeMaster.FlowStrategy.SEQ).Count() > 0)
            {
                throw new BusinessException("排序单不能按订单收货。");
            }
            #endregion

            #region 循环订单头检查
            foreach (OrderMaster orderMaster in orderMasterList)
            {
                //if (!Utility.SecurityHelper.HasPermission(orderMaster))
                //{
                //    throw new BusinessException("没有此订单{0}的操作权限。", orderMaster.OrderNo);
                //}

                orderMaster.OrderDetails = nonZeroOrderDetailList.Where(det => det.OrderNo == orderMaster.OrderNo).ToList();

                //如果非生产,把Submit状态改为InProcess
                if (orderMaster.Status == com.Sconit.CodeMaster.OrderStatus.Submit
                    && orderMaster.Type != com.Sconit.CodeMaster.OrderType.Production
                    && orderMaster.Type != com.Sconit.CodeMaster.OrderType.SubContract)
                {
                    UpdateOrderMasterStatus2InProcess(orderMaster);
                }

                //判断OrderHead状态
                if (orderMaster.Status != com.Sconit.CodeMaster.OrderStatus.InProcess)
                {
                    throw new BusinessException(Resources.ORD.OrderMaster.Errors_StatusErrorWhenReceive,
                            orderMaster.OrderNo, systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.OrderStatus, ((int)orderMaster.Status).ToString()));
                }

                #region 订单、生产线暂停检查
                if (orderMaster.IsPause)
                {
                    if (orderMaster.Type == CodeMaster.OrderType.Production)
                    {
                        throw new BusinessException("生产单{0}已经暂停,不能收货。", orderMaster.OrderNo);
                    }
                    else if (orderMaster.OrderStrategy == CodeMaster.FlowStrategy.KIT)
                    {
                        throw new BusinessException("KIT单{0}已经暂停,不能收货。", orderMaster.OrderNo);
                    }
                    else if (orderMaster.OrderStrategy == CodeMaster.FlowStrategy.SEQ)
                    {
                        throw new BusinessException("排序单{0}已经暂停,不能收货。", orderMaster.OrderNo);
                    }
                    else
                    {
                        throw new BusinessException("订单{0}已经暂停,不能收货。", orderMaster.OrderNo);
                    }
                }

                //if ((orderMaster.Type == CodeMaster.OrderType.Production
                //    || orderMaster.Type == CodeMaster.OrderType.SubContract
                //    //生产线暂停可以收货
                //    //|| orderMaster.OrderStrategy == CodeMaster.FlowStrategy.KIT
                //    //|| orderMaster.OrderStrategy == CodeMaster.FlowStrategy.SEQ
                //    )
                //    && !string.IsNullOrWhiteSpace(orderMaster.Flow))
                //{
                //    FlowMaster flowMaster = this.genericMgr.FindById<FlowMaster>(orderMaster.Flow);
                //    if (flowMaster.IsPause)
                //    {
                //        throw new BusinessException("生产线{0}已经暂停,不能收货。", orderMaster.Flow);
                //    }
                //}
                #endregion

                #region 整包装收货判断,快速的不要判断
                if (orderMaster.IsReceiveFulfillUC
                    && orderMaster.SubType == com.Sconit.CodeMaster.OrderSubType.Normal
                    && !(orderMaster.IsAutoRelease && orderMaster.IsAutoStart))
                {
                    foreach (OrderDetail orderDetail in orderMaster.OrderDetails)
                    {
                        //不合格品不作为收货数
                        //if (orderDetail.ReceiveQualifiedQtyInput % orderDetail.UnitCount != 0)
                        if (orderDetail.ReceiveQtyInput % orderDetail.UnitCount != 0)
                        {
                            //不是整包装
                            throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveQtyNotFulfillUnitCount, orderDetail.Item);
                        }
                    }
                }
                #endregion

                #region 是否过量发货判断,未发货即收货也要判断是否过量发货
                foreach (OrderDetail orderDetail in orderMaster.OrderDetails)
                {
                    if (!orderMaster.IsOpenOrder
                        && orderMaster.Type != com.Sconit.CodeMaster.OrderType.Production   //生产和委外不需要判断
                        && orderMaster.Type != com.Sconit.CodeMaster.OrderType.SubContract)
                    {
                        if (Math.Abs(orderDetail.ShippedQty) > Math.Abs(orderDetail.OrderedQty))
                        {
                            //订单的发货数已经大于等于订单数
                            throw new BusinessException(Resources.ORD.OrderMaster.Errors_ShipQtyExcceedOrderQty, orderDetail.OrderNo, orderDetail.Item);
                        }
                        else if (!orderMaster.IsShipExceed
                            && Math.Abs(orderDetail.ShippedQty + orderDetail.ReceiveQtyInput) > Math.Abs(orderDetail.OrderedQty))   //不允许过量收货
                        {
                            //订单的发货数 + 本次发货数大于订单数
                            throw new BusinessException(Resources.ORD.OrderMaster.Errors_ShipQtyExcceedOrderQty, orderDetail.OrderNo, orderDetail.Item);
                        }
                    }
                }
                #endregion

                #region 是否过量收货判断
                foreach (OrderDetail orderDetail in orderMaster.OrderDetails)
                {
                    if (!orderMaster.IsOpenOrder)
                    {
                        var orderDeviationQty = decimal.MaxValue;
                        if (!orderMaster.IsReceiveExceed)
                        {
                            orderDeviationQty = Math.Abs(orderDetail.OrderedQty);
                        }
                        else
                        {
                            if (orderMaster.CurrentFlowMaster.OrderDeviation > 0)
                            {
                                orderDeviationQty = Math.Abs(orderDetail.OrderedQty * (((decimal)orderMaster.CurrentFlowMaster.OrderDeviation / 100) + 1));
                            }
                        }
                        //订单的收货数已经大于等于订单数
                        if (Math.Abs(orderDetail.ReceivedQty) >= Math.Abs(orderDetail.OrderedQty))
                        {
                            throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveQtyExcceedOrderQty, orderDetail.OrderNo, orderDetail.Item);
                        }
                        else if (Math.Abs(orderDetail.ReceivedQty + orderDetail.RejectedQty + orderDetail.ScrapQty + orderDetail.ReceiveQtyInput + orderDetail.ScrapQtyInput) > orderDeviationQty)   //不允许过量收货
                        {
                            //订单的收货数 + 本次收货数大于订单数
                            throw new BusinessException(Resources.ORD.OrderMaster.Errors_ReceiveQtyExcceedOrderQty, orderDetail.OrderNo, orderDetail.Item);
                        }
                    }
                }
                #endregion

                #region KIT单收货判断
                if (orderMaster.OrderStrategy == CodeMaster.FlowStrategy.KIT)
                {
                    CheckKitOrderDetail(orderMaster, isCheckKitTraceItem, false);
                }
                #endregion
            }
            #endregion

            #region 校验发货先进先出
            CheckShipFiFo(orderMasterList);
            #endregion

            #region 循环更新订单明细
            foreach (OrderDetail orderDetail in nonZeroOrderDetailList)
            {
                //未发货直接收货需要累加已发货数量
                if (orderDetail.OrderType != com.Sconit.CodeMaster.OrderType.Production
                    && orderDetail.OrderType != com.Sconit.CodeMaster.OrderType.SubContract)
                {
                    orderDetail.ShippedQty += orderDetail.ReceiveQtyInput;
                }

                if (orderDetail.OrderType != com.Sconit.CodeMaster.OrderType.Production
                    && orderDetail.OrderType != com.Sconit.CodeMaster.OrderType.SubContract)
                {
                    //orderDetail.ReceivedQty += orderDetail.ReceiveQualifiedQtyInput;
                    orderDetail.ReceivedQty += orderDetail.ReceiveQtyInput;
                }
                else
                {
                    //生产收货更新合格数和不合格数量
                    //orderDetail.ReceivedQty += orderDetail.ReceiveQualifiedQtyInput;
                    orderDetail.ReceivedQty += orderDetail.ReceiveQtyInput;
                    orderDetail.ScrapQty += orderDetail.ScrapQtyInput;
                }
                genericMgr.Update(orderDetail);
            }
            #endregion

            #region 发货
            #region OrderDetailInput赋发货数量
            foreach (OrderDetail orderDetail in nonZeroOrderDetailList)
            {
                foreach (OrderDetailInput orderDetailInput in orderDetail.OrderDetailInputs)
                {
                    orderDetailInput.ShipQty = orderDetailInput.ReceiveQty;
                }
            }
            #endregion

            IpMaster ipMaster = null;
            var subType = orderMasterList.First().SubType;
            if ((orderType == com.Sconit.CodeMaster.OrderType.Production || orderType == com.Sconit.CodeMaster.OrderType.SubContract)
                && subType != CodeMaster.OrderSubType.Return)
            {
                //生产和委外的非退货单 
            }
            else
            {
                //物流单 生产和委外的退货单也要创建Ip
                ipMaster = this.ipMgr.TransferOrder2Ip(orderMasterList);
                #region 循环发货
                foreach (IpDetail ipDetail in ipMaster.IpDetails)
                {
                    ipDetail.CurrentPartyFrom = ipMaster.PartyFrom;  //为了记录库存事务
                    ipDetail.CurrentPartyFromName = ipMaster.PartyFromName;  //为了记录库存事务
                    ipDetail.CurrentPartyTo = ipMaster.PartyTo;      //为了记录库存事务
                    ipDetail.CurrentPartyToName = ipMaster.PartyToName;      //为了记录库存事务
                    //ipDetail.CurrentOccupyType = com.Sconit.CodeMaster.OccupyType.None; //todo-默认出库未占用库存,除非捡货或检验的出库

                    IList<InventoryTransaction> inventoryTransactionList = this.locationDetailMgr.InventoryOut(ipDetail, effectiveDate);

                    #region 建立发货库明细和IpDetailInput的关系
                    if (inventoryTransactionList != null && inventoryTransactionList.Count > 0)
                    {
                        ipDetail.IpLocationDetails = (from trans in inventoryTransactionList
                                                      group trans by new
                                                      {
                                                          HuId = trans.HuId,
                                                          LotNo = trans.LotNo,
                                                          IsCreatePlanBill = trans.IsCreatePlanBill,
                                                          IsConsignment = trans.IsConsignment,
                                                          PlanBill = trans.PlanBill,
                                                          ActingBill = trans.ActingBill,
                                                          QualityType = trans.QualityType,
                                                          IsFreeze = trans.IsFreeze,
                                                          IsATP = trans.IsATP,
                                                          OccupyType = trans.OccupyType,
                                                          OccupyReferenceNo = trans.OccupyReferenceNo
                                                      } into g
                                                      select new IpLocationDetail
                                                      {
                                                          HuId = g.Key.HuId,
                                                          LotNo = g.Key.LotNo,
                                                          IsCreatePlanBill = g.Key.IsCreatePlanBill,
                                                          IsConsignment = g.Key.IsConsignment,
                                                          PlanBill = g.Key.PlanBill,
                                                          ActingBill = g.Key.ActingBill,
                                                          QualityType = g.Key.QualityType,
                                                          IsFreeze = g.Key.IsFreeze,
                                                          IsATP = g.Key.IsATP,
                                                          OccupyType = g.Key.OccupyType,
                                                          OccupyReferenceNo = g.Key.OccupyReferenceNo,
                                                          Qty = g.Sum(t => -t.Qty),                      //发货的库存事务为负数,转为收货数应该取负数
                                                          //PlanBillQty = g.Sum(t=>-t.PlanBillQty),
                                                          //ActingBillQty = g.Sum(t=>-t.ActingBillQty)
                                                      }).ToList();
                    }
                    #endregion
                }
                #endregion

                #region 生成收货的IpInput
                foreach (OrderDetail orderDetail in nonZeroOrderDetailList)
                {
                    OrderMaster orderMaster = orderMasterList.Where(o => o.OrderNo == orderDetail.OrderNo).Single();
                    //订单收货一定是一条订单明细对应一条发货单明细
                    IpDetail ipDetail = ipMaster.IpDetails.Where(det => det.OrderDetailId == orderDetail.Id).Single();
                    ipDetail.IpDetailInputs = null;  //清空Ip的发货数据,准备添加收货数据

                    foreach (OrderDetailInput orderDetailInput in orderDetail.OrderDetailInputs)
                    {
                        IpDetailInput ipDetailInput = new IpDetailInput();
                        ipDetailInput.ReceiveQty = orderDetailInput.ShipQty;
                        if (orderMaster.IsReceiveScanHu || orderMaster.OrderStrategy == CodeMaster.FlowStrategy.KIT)
                        {
                            ipDetailInput.HuId = orderDetailInput.HuId;
                            ipDetailInput.LotNo = orderDetailInput.LotNo;
                        }

                        ipDetail.AddIpDetailInput(ipDetailInput);
                    }
                }

                if (orderMasterList.Where(o => o.OrderStrategy == CodeMaster.FlowStrategy.KIT).Count() > 0)
                {
                    #region Kit单生成收货Input
                    foreach (IpDetail ipDetail in ipMaster.IpDetails)
                    {
                        foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs)
                        {
                            if (!string.IsNullOrEmpty(ipDetailInput.HuId))
                            {
                                #region 按条码匹配
                                IpLocationDetail matchedIpLocationDetail = ipDetail.IpLocationDetails.Where(locDet => locDet.HuId == ipDetailInput.HuId).SingleOrDefault();
                                matchedIpLocationDetail.ReceivedQty = matchedIpLocationDetail.Qty;
                                if (matchedIpLocationDetail != null)
                                {
                                    ipDetailInput.AddReceivedIpLocationDetail(matchedIpLocationDetail);
                                }
                                #endregion
                            }
                            else
                            {
                                #region 按数量匹配
                                IpDetail gapIpDetail = new IpDetail();
                                MatchIpDetailInput(ipDetail, ipDetailInput, ipDetail.IpLocationDetails, ref gapIpDetail);
                                #endregion
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    #region 其它订单生成收货Input
                    if (ipMaster.IsShipScanHu && ipMaster.IsReceiveScanHu)
                    {
                        #region 按条码匹配
                        foreach (IpDetail ipDetail in ipMaster.IpDetails)
                        {
                            foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs)
                            {
                                IpLocationDetail matchedIpLocationDetail = ipDetail.IpLocationDetails.Where(locDet => locDet.HuId == ipDetailInput.HuId).SingleOrDefault();
                                matchedIpLocationDetail.ReceivedQty = matchedIpLocationDetail.Qty;
                                if (matchedIpLocationDetail != null)
                                {
                                    ipDetailInput.AddReceivedIpLocationDetail(matchedIpLocationDetail);
                                }
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        #region 按数量匹配
                        foreach (IpDetail ipDetail in ipMaster.IpDetails)
                        {
                            CycleMatchIpDetailInput(ipDetail, ipDetail.IpDetailInputs, ipDetail.IpLocationDetails);
                        }
                        #endregion
                    }
                    #endregion
                }
                #endregion
            }
            #endregion

            #region 收货 生产和委外退货的逻辑在CreateReceipt中实现
            ReceiptMaster receiptMaster = null;
            if (subType != CodeMaster.OrderSubType.Return &&
               (orderType == com.Sconit.CodeMaster.OrderType.Production || orderType == com.Sconit.CodeMaster.OrderType.SubContract))
            {
                #region 生产和委外正常收货 消耗原材料,收成品
                if (orderMasterList.Count > 1 && orderType == com.Sconit.CodeMaster.OrderType.Production)
                {
                    throw new TechnicalException("生产单不能合并收货。");
                }

                foreach (OrderMaster orderMaster in orderMasterList)
                {
                    orderMaster.IpNo = ipNo;
                    receiptMaster = this.receiptMgr.TransferOrder2Receipt(orderMaster);
                    this.receiptMgr.CreateReceipt(receiptMaster);

                    #region 回冲物料
                    if (productLineMap != null)
                    {
                        #region 整车
                        BackflushVan(productLineMap, nonZeroOrderDetailList, receiptMaster, orderMaster);
                        #endregion
                    }
                    else
                    {
                        #region 非整车
                        foreach (OrderDetail orderDetail in nonZeroOrderDetailList)
                        {
                            //OrderDetailInput orderDetailInput = orderDetail.OrderDetailInputs[0];
                            foreach (var orderDetailInput in orderDetail.OrderDetailInputs)
                            {
                                orderDetailInput.ReceiptDetails = receiptMaster.ReceiptDetails.Where(r => r.OrderDetailId == orderDetail.Id).ToList();
                            }
                        }
                        this.productionLineMgr.BackflushProductOrder(nonZeroOrderDetailList, orderMaster, DateTime.Now);
                        #endregion
                    }
                    #endregion
                }
                #endregion
            }
            else
            {
                #region 物流收货
                receiptMaster = this.receiptMgr.TransferIp2Receipt(ipMaster);
                if (orderMasterList.Where(o => o.OrderStrategy == CodeMaster.FlowStrategy.KIT).Count() > 0)
                {
                    //kit收货特殊处理
                    this.receiptMgr.CreateReceipt(receiptMaster, true, effectiveDate);
                }
                else
                {
                    this.receiptMgr.CreateReceipt(receiptMaster, false, effectiveDate);
                }
                #endregion
            }
            #endregion

            #region 尝试关闭订单
            foreach (OrderMaster orderMaster in orderMasterList)
            {
                if (orderMaster.Type == CodeMaster.OrderType.Production)
                {
                    #region 生产
                    if (productLineMap != null && productLineMap.ProductLine == orderMaster.Flow)
                    {
                        #region 总装生产单
                        CloseVanOrder(orderMaster, productLineMap);
                        #endregion
                    }
                    else if (productLineMap != null && (productLineMap.CabFlow == orderMaster.Flow || productLineMap.ChassisFlow == orderMaster.Flow))
                    {
                        #region  驾驶室和底盘
                        //驾驶室和底盘下线完工订单,总装下线后一起关闭
                        CompleteVanSubOrder(orderMaster);
                        #endregion
                    }
                    else
                    {
                        #region  非整车
                        TryCloseOrder(orderMaster);
                        #endregion
                    }
                    #endregion
                }
                else
                {
                    #region 物流
                    TryCloseOrder(orderMaster);
                    #endregion
                }
            }
            #endregion

            return receiptMaster;
        }
Ejemplo n.º 5
0
        public IDictionary<string, decimal> GetHuId(IpDetail ipDetail)
        {
            decimal uc = ipDetail.UnitCount;

            if (ipDetail.HuQty <= ipDetail.MaxUc)
            {
                uc = ipDetail.HuQty;
            }

            var HuIds = GetHuId(ipDetail.LotNo, ipDetail.Item, ipDetail.ManufactureParty, ipDetail.HuQty, uc);

            return HuIds;
        }
Ejemplo n.º 6
0
        public void CancelReceipt(ReceiptMaster receiptMaster, DateTime effectiveDate)
        {
            if (!Utility.SecurityHelper.HasPermission(receiptMaster))
            {
                //throw new BusinessException("没有此收货单{0}的操作权限。", receiptMaster.ReceiptNo);
            }

            #region 判断收货单状态,只有Close才能冲销
            if (receiptMaster.Status == CodeMaster.ReceiptStatus.Cancel)
            {
                throw new BusinessException("收货单{0}已经冲销。", receiptMaster.ReceiptNo,
                    systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.ReceiptStatus, ((int)receiptMaster.Status).ToString()));
            }
            #endregion

            #region 加载收货单明细及收货单库存明细
            //  TryLoadReceiptDetails(receiptMaster);
            IList<ReceiptLocationDetail> receiptLocationDetailList = TryLoadReceiptLocationDetails(receiptMaster);
            #endregion

            #region 加载订单头和明细
            //GAP收货取消不用调整订单数据
            IList<OrderMaster> orderMasterList = null;
            IList<OrderDetail> orderDetialList = null;
            //if (receiptMaster.Type == CodeMaster.IpDetailType.Normal)
            //{
            #region 获取订单头
            orderMasterList = LoadOrderMasters(receiptMaster.ReceiptDetails.Select(det => det.OrderNo).Distinct().ToArray());
            #endregion

            #region 获取订单明细
            orderDetialList = LoadOrderDetails(receiptMaster.ReceiptDetails.Where(det => det.OrderDetailId.HasValue).Select(det => det.OrderDetailId.Value).Distinct().ToArray());
            #endregion
            //}
            #endregion

            //小数保留位数
            int decimalLength = int.Parse(systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.DecimalLength));

            #region 回滚送货单
            if (!string.IsNullOrWhiteSpace(receiptMaster.IpNo))
            {
                IpMaster ipMaster = this.genericMgr.FindById<IpMaster>(receiptMaster.IpNo);

                #region 查找送货单明细
                string selectIpDetailStatement = string.Empty;
                IList<object> selectIpDetailPram = new List<object>();
                foreach (int ipDetailId in receiptMaster.ReceiptDetails.Select(recDet => recDet.IpDetailId).Distinct())
                {
                    if (selectIpDetailStatement == string.Empty)
                    {
                        selectIpDetailStatement = "from IpDetail where Id in (?";
                    }
                    else
                    {
                        selectIpDetailStatement += ",?";
                    }

                    selectIpDetailPram.Add(ipDetailId);
                }
                selectIpDetailStatement += ")";
                IList<IpDetail> ipDetailList = this.genericMgr.FindAll<IpDetail>(selectIpDetailStatement, selectIpDetailPram.ToArray());
                #endregion

                #region 查找送货单库存明细
                IList<IpLocationDetail> ipLocationDetailList = LoadIpLocationDetails(ipDetailList.Select(ipDet => ipDet.Id).ToArray());
                #endregion

                #region 查找差异送货单明细
                IList<IpDetail> gapIpDetailList = this.genericMgr.FindAll<IpDetail>("from IpDetail where GapReceiptNo = ?", receiptMaster.ReceiptNo);
                #endregion

                #region 差异全部关闭
                if (gapIpDetailList != null && gapIpDetailList.Count > 0)
                {
                    #region 查找差异送货单库存明细
                    IList<IpLocationDetail> gapIpLocationDetailList = LoadIpLocationDetails(gapIpDetailList.Select(ipDet => ipDet.Id).ToArray());
                    #endregion

                    foreach (IpDetail gapIpDetail in gapIpDetailList)
                    {
                        if (gapIpDetail.ReceivedQty != 0)
                        {
                            throw new BusinessException("收货单{0}的收货差异已经调整,不能冲销。", receiptMaster.ReceiptNo);
                        }

                        gapIpDetail.IsClose = true;
                        this.genericMgr.Update(gapIpDetail);
                    }

                    foreach (IpLocationDetail gapIpLocationDetail in gapIpLocationDetailList)
                    {
                        gapIpLocationDetail.IsClose = true;
                        this.genericMgr.Update(gapIpLocationDetail);
                    }
                }
                #endregion

                #region 打开未收货的发货明细
                //只有正常收货才能打开未收货的发货明细。
                int isGapRec = receiptMaster.ReceiptDetails.Where(recDet => recDet.IpDetailType == CodeMaster.IpDetailType.Gap).Count();
                if (isGapRec == 0)
                {
                    IList<IpDetail> unReceivedIpDetailList = this.genericMgr.FindAll<IpDetail>("from IpDetail where IpNo = ? and Type = ?",
                        new object[] { ipMaster.IpNo, CodeMaster.IpDetailType.Normal });

                    if (unReceivedIpDetailList != null && unReceivedIpDetailList.Count > 0)
                    {
                        #region 查找差异送货单库存明细
                        IList<IpLocationDetail> unReceivedIpLocationDetailList = LoadIpLocationDetails(unReceivedIpDetailList.Select(ipDet => ipDet.Id).ToArray());
                        #endregion

                        foreach (IpDetail unReceivedIpDetail in unReceivedIpDetailList)
                        {
                            if (unReceivedIpDetail.IsClose && receiptMaster.ReceiptDetails.Select(p => p.IpDetailId).Contains(unReceivedIpDetail.Id))
                            {
                                unReceivedIpDetail.IsClose = false;
                                this.genericMgr.Update(unReceivedIpDetail);
                            }
                        }

                        //foreach (IpLocationDetail unReceivedIpLocationDetail in unReceivedIpLocationDetailList)
                        //{
                        //    if (unReceivedIpLocationDetail.IsClose && receiptMaster.ReceiptDetails.Select(p => p.IpDetailId).Contains(unReceivedIpLocationDetail.IpDetailId))
                        //    {
                        //        unReceivedIpLocationDetail.IsClose = false;
                        //        this.genericMgr.Update(unReceivedIpLocationDetail);
                        //    }
                        //}
                    }
                }
                #endregion

                #region 收货库存明细和送货库存明细匹配
                foreach (ReceiptLocationDetail receiptLocationDetail in receiptLocationDetailList)
                {
                    ReceiptDetail receiptDetail = receiptMaster.ReceiptDetails.Where(recDet => recDet.Id == receiptLocationDetail.ReceiptDetailId).Single();

                    decimal remainBaseQty = receiptLocationDetail.Qty;  //基本单位
                    decimal remainQty = receiptLocationDetail.Qty / receiptDetail.UnitQty; //转为订单单位

                    if (!string.IsNullOrWhiteSpace(receiptLocationDetail.HuId)
                        && ipLocationDetailList.Where(ipLocDet => !string.IsNullOrWhiteSpace(ipLocDet.HuId)).Count() > 0)
                    {
                        #region 条码和条码匹配
                        IpLocationDetail ipLocationDetail = ipLocationDetailList.Where(ipLocDet => ipLocDet.HuId == receiptLocationDetail.HuId).SingleOrDefault();
                        IpDetail ipDetail = ipDetailList.Where(ipDet => ipDet.Id == receiptDetail.IpDetailId).Single();

                        if (ipDetail.Id != receiptDetail.IpDetailId)
                        {
                            throw new TechnicalException("收货单明细和发货单明细ID不匹配。");
                        }

                        if (ipDetail.Type != receiptDetail.IpDetailType)
                        {
                            throw new TechnicalException("收货单明细和发货单明细类型不匹配。");
                        }

                        #region 扣减发货单的收货数
                        if (ipLocationDetail != null)
                        {
                            ipLocationDetail.ReceivedQty -= remainBaseQty;
                            ipLocationDetail.IsClose = false;
                        }
                        ipDetail.ReceivedQty -= remainQty; //转为订单单位
                        ipDetail.IsClose = false;

                        remainBaseQty = 0;
                        remainQty = 0;
                        #endregion

                        if (ipLocationDetail != null)
                        {
                            this.genericMgr.Update(ipLocationDetail);
                        }
                        this.genericMgr.Update(ipDetail);
                        #endregion
                    }
                    else
                    {
                        #region 按数量匹配
                        IList<IpDetail> thisIpDetailList = ipDetailList.Where(ipDet => ipDet.ReceivedQty != 0  //过滤掉已经扣完的明细
                                                                    && ipDet.Id == receiptDetail.IpDetailId).ToList();

                        if (thisIpDetailList != null && thisIpDetailList.Count > 0)
                        {
                            IList<IpLocationDetail> thisIpLocationDetailList = null;
                            foreach (IpDetail thisIpDetail in thisIpDetailList)
                            {
                                if (thisIpDetail.ReceivedQty > 0)
                                {
                                    thisIpLocationDetailList = ipLocationDetailList.Where(
                                        ipLocDet => ipLocDet.ReceivedQty > 0 && ipLocDet.IpDetailId == thisIpDetail.Id).ToList();
                                }
                                else if (thisIpDetail.ReceivedQty < 0)
                                {
                                    thisIpLocationDetailList = ipLocationDetailList.Where(
                                        ipLocDet => ipLocDet.ReceivedQty < 0 && ipLocDet.IpDetailId == thisIpDetail.Id).ToList();
                                }

                                if (thisIpLocationDetailList != null && thisIpLocationDetailList.Count > 0)
                                {
                                    foreach (IpLocationDetail thisIpLocationDetail in thisIpLocationDetailList)
                                    {
                                        if (thisIpLocationDetail.ReceivedQty > remainBaseQty)
                                        {
                                            //如果剩余冲销数量为0则不打开送货单
                                            if (remainBaseQty != 0)
                                            {
                                                thisIpDetail.IsClose = false;
                                                thisIpLocationDetail.IsClose = false;
                                            }
                                            thisIpDetail.ReceivedQty -= remainQty;
                                            remainQty = 0;

                                            thisIpLocationDetail.ReceivedQty -= remainBaseQty;
                                            remainBaseQty = 0;


                                        }
                                        else
                                        {
                                            decimal thisBackflushQty = thisIpLocationDetail.ReceivedQty / thisIpDetail.UnitQty; //转为订单单位
                                            remainQty -= thisBackflushQty;
                                            thisIpDetail.ReceivedQty -= thisBackflushQty;

                                            remainBaseQty -= thisIpLocationDetail.ReceivedQty;
                                            thisIpLocationDetail.ReceivedQty = 0;

                                            thisIpDetail.IsClose = false;
                                            thisIpLocationDetail.IsClose = false;
                                        }

                                        this.genericMgr.Update(thisIpLocationDetail);
                                        this.genericMgr.Update(thisIpDetail);
                                    }
                                }
                                else
                                {
                                    //throw new TechnicalException("差异送货单明细和送货单库存明细不匹配。");
                                }
                            }
                        }
                        #endregion
                    }

                    if (remainBaseQty != 0)
                    {
                        throw new TechnicalException("收货单的收货数没有回冲完。");
                    }
                }
                #endregion

                #region 更新订单明细
                if (receiptMaster.OrderType != CodeMaster.OrderType.ScheduleLine)
                {
                    #region 非计划协议
                    foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails)
                    {
                        OrderDetail matchedOrderDetial = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId.Value).Single();

                        if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Normal)
                        {
                            matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty;
                            if (matchedOrderDetial.ReceivedQty < 0)
                            {
                                throw new TechnicalException("订单收货数小于0。");
                            }
                        }
                        else
                        {
                            //差异收货冲销
                            #region 调整发货方库存
                            if (receiptMaster.PartyFrom == ipMaster.PartyTo)   //发货方等于收货方
                            {
                                //更新订单的发货数
                                matchedOrderDetial.ShippedQty += receiptDetail.ReceivedQty;
                            }
                            #endregion

                            #region 调整收货方库存
                            else
                            {
                                //更新订单的收货数
                                matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty;
                            }
                            #endregion
                        }
                        genericMgr.Update(matchedOrderDetial);
                    }
                    #endregion
                }
                else
                {
                    foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails)
                    {
                        decimal receivedQty = receiptDetail.ReceivedQty;

                        if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Normal)
                        {
                            #region 调整收货方库存
                            IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and RecQty > 0 order by EndDate desc",
                                              new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm });

                            foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList)
                            {
                                if (receivedQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty))
                                {
                                    receivedQty -= scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty;
                                    scheduleOrderDetail.ReceivedQty -= receiptDetail.ReceivedQty;
                                }
                                else
                                {
                                    scheduleOrderDetail.ReceivedQty -= receivedQty;
                                    receivedQty = 0;
                                }

                                genericMgr.Update(scheduleOrderDetail);
                            }
                            #endregion
                        }
                        else
                        {
                            //差异收货冲销
                            #region 调整发货方库存
                            if (receiptMaster.PartyFrom == ipMaster.PartyTo)   //发货方等于收货方
                            {
                                IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and OrderQty > ShipQty order by EndDate",
                                              new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm });

                                foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList)
                                {
                                    if (receivedQty > (scheduleOrderDetail.OrderedQty - scheduleOrderDetail.ShippedQty))
                                    {
                                        receivedQty -= scheduleOrderDetail.OrderedQty - scheduleOrderDetail.ShippedQty;
                                        scheduleOrderDetail.ShippedQty = scheduleOrderDetail.OrderedQty;
                                    }
                                    else
                                    {
                                        scheduleOrderDetail.ShippedQty += receivedQty;
                                        receivedQty = 0;
                                    }

                                    genericMgr.Update(scheduleOrderDetail);
                                }
                            }
                            #endregion

                            #region 调整收货方库存
                            else
                            {
                                IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and RecQty > 0 order by EndDate desc",
                                              new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm });

                                foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList)
                                {
                                    if (receivedQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty))
                                    {
                                        receivedQty -= scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty;
                                        scheduleOrderDetail.ReceivedQty -= receiptDetail.ReceivedQty;
                                    }
                                    else
                                    {
                                        scheduleOrderDetail.ReceivedQty -= receivedQty;
                                        receivedQty = 0;
                                    }

                                    genericMgr.Update(scheduleOrderDetail);
                                }
                            }
                            #endregion
                        }
                    }
                }
                #endregion

                #region 回滚送货单状态
                //1. 普通状态的送货明细没有收过货
                //2. 差异状态的送货明细全部关闭
                if (ipDetailList.Where(ipDet => ipDet.Type == CodeMaster.IpDetailType.Normal && ipDet.ReceivedQty != 0).Count() == 0
                    && ipDetailList.Where(ipDet => ipDet.Type == CodeMaster.IpDetailType.Gap && !ipDet.IsClose).Count() == 0)
                {
                    ipMaster.Status = CodeMaster.IpStatus.Submit;
                    this.genericMgr.Update(ipMaster);

                    #region 回滚排序单状态
                    if (!string.IsNullOrWhiteSpace(ipMaster.SequenceNo))
                    {
                        SequenceMaster sequenceMaster = this.genericMgr.FindById<SequenceMaster>(ipMaster.SequenceNo);
                        sequenceMaster.Status = CodeMaster.SequenceStatus.Ship;
                        this.genericMgr.Update(sequenceMaster);
                    }
                    #endregion
                }
                else if (ipMaster.Status != CodeMaster.IpStatus.InProcess)
                {
                    ipMaster.Status = CodeMaster.IpStatus.InProcess;
                    this.genericMgr.Update(ipMaster);
                }
                #endregion

                #region 退回排序单状态
                if (!string.IsNullOrEmpty(ipMaster.SequenceNo))
                {
                    #region 更新排序单头
                    SequenceMaster sequenceMaster = this.genericMgr.FindById<SequenceMaster>(ipMaster.SequenceNo);

                    sequenceMaster.Status = CodeMaster.SequenceStatus.Ship;
                    sequenceMaster.CloseDate = null;
                    sequenceMaster.CloseUserId = 0;
                    sequenceMaster.CloseUserName = null;

                    this.genericMgr.Update(sequenceMaster);
                    #endregion

                    foreach (SequenceDetail sequenceDetail in TryLoadSequenceDetails(sequenceMaster))
                    {
                        //对于调整计划关闭的排序明细也有可能打开了,会有Bug
                        if (orderDetialList.Select(i => i.Id).Contains(sequenceDetail.OrderDetailId))
                        {
                            sequenceDetail.IsClose = false;
                            this.genericMgr.Update(sequenceDetail);
                        }
                    }
                }
                #endregion
            }
            else
            {
                #region 更新订单明细
                foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails)
                {
                    if (receiptDetail != null)
                    {
                        OrderDetail matchedOrderDetial = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId.Value).Single();
                        matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty;
                        matchedOrderDetial.ScrapQty -= receiptDetail.ScrapQty;
                        if (matchedOrderDetial.OrderType != CodeMaster.OrderType.Production
                           && matchedOrderDetial.OrderType != CodeMaster.OrderType.SubContract)
                        {
                            matchedOrderDetial.ShippedQty -= receiptDetail.ReceivedQty;
                            if (matchedOrderDetial.ShippedQty < 0)
                            {
                                throw new TechnicalException("订单发货数小于0。");
                            }
                        }

                        if (matchedOrderDetial.ReceivedQty < 0)
                        {
                            throw new TechnicalException("订单收货数小于0。");
                        }

                        this.genericMgr.Update(matchedOrderDetial);
                    }
                }
                #endregion
            }
            #endregion

            #region 更新订单
            foreach (OrderMaster orderMaster in orderMasterList)
            {
                if (orderMaster.Status != CodeMaster.OrderStatus.InProcess)
                {
                    orderMaster.Status = CodeMaster.OrderStatus.InProcess;
                    orderMaster.CloseDate = null;
                    orderMaster.CloseUserId = null;
                    orderMaster.CloseUserName = null;
                    this.genericMgr.Update(orderMaster);
                }
            }
            #endregion

            #region 更新收货单
            receiptMaster.Status = CodeMaster.ReceiptStatus.Cancel;
            this.genericMgr.Update(receiptMaster);
            #endregion

            #region 冲销收货记录
            List<IpDetail> cancelIpDetailList = new List<IpDetail>();
            foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails)
            {
                if (receiptDetail.ReceivedQty != 0)
                {
                    receiptDetail.CurrentPartyFrom = receiptMaster.PartyFrom;  //为了记录库存事务
                    receiptDetail.CurrentPartyFromName = receiptMaster.PartyFromName;
                    receiptDetail.CurrentPartyTo = receiptMaster.PartyTo;
                    receiptDetail.CurrentPartyToName = receiptMaster.PartyToName;
                    receiptDetail.CurrentExternalReceiptNo = receiptMaster.ExternalReceiptNo;
                    receiptDetail.CurrentIsReceiveScanHu = receiptMaster.IsReceiveScanHu || orderMasterList.Where(o => o.OrderStrategy == CodeMaster.FlowStrategy.KIT).Count() > 0;
                    receiptDetail.IsVoid = true;

                    foreach (ReceiptLocationDetail receiptLocationDetail in receiptDetail.ReceiptLocationDetails)
                    {
                        ReceiptDetailInput receiptDetailInput = new ReceiptDetailInput();
                        receiptDetailInput.HuId = receiptLocationDetail.HuId;
                        receiptDetailInput.ReceiveQty = -receiptLocationDetail.Qty / receiptDetail.UnitQty; //转为订单单位
                        receiptDetailInput.LotNo = receiptLocationDetail.LotNo;
                        receiptDetailInput.IsCreatePlanBill = receiptLocationDetail.IsCreatePlanBill;
                        receiptDetailInput.IsConsignment = receiptLocationDetail.IsConsignment;
                        receiptDetailInput.PlanBill = receiptLocationDetail.PlanBill;
                        receiptDetailInput.ActingBill = receiptLocationDetail.ActingBill;
                        receiptDetailInput.IsATP = receiptLocationDetail.IsATP;
                        receiptDetailInput.IsFreeze = receiptLocationDetail.IsFreeze;
                        receiptDetailInput.OccupyType = receiptLocationDetail.OccupyType;
                        receiptDetailInput.OccupyReferenceNo = receiptLocationDetail.OccupyReferenceNo;
                        receiptDetailInput.QualityType = receiptLocationDetail.QualityType;

                        receiptDetail.AddReceiptDetailInput(receiptDetailInput);
                    }

                    #region 更新库存、记库存事务
                    IList<InventoryTransaction> rctInventoryTransactionList = this.locationDetailMgr.InventoryIn(receiptDetail, effectiveDate);
                    #endregion

                    #region 订单直接收货创建发货明细对象
                    if (!string.IsNullOrWhiteSpace(receiptMaster.IpNo))
                    {
                        //nothing todo 
                    }
                    else if (receiptMaster.Type == CodeMaster.IpDetailType.Gap)
                    {
                        //nothing todo 
                    }
                    else if (receiptMaster.OrderType == CodeMaster.OrderType.Production)
                    {
                        //nothing todo 
                    }
                    else if (receiptMaster.OrderType == CodeMaster.OrderType.SubContract && receiptMaster.OrderSubType == CodeMaster.OrderSubType.Normal)
                    {
                        //nothing todo 
                    }
                    else
                    //if (string.IsNullOrWhiteSpace(receiptMaster.IpNo)
                    //    && receiptMaster.Type != CodeMaster.IpDetailType.Gap
                    //    && receiptMaster.OrderType != CodeMaster.OrderType.Production
                    //    && (receiptMaster.OrderType != CodeMaster.OrderType.SubContract))
                    {
                        IpDetail ipdetail = new IpDetail();
                        ipdetail.OrderNo = receiptDetail.OrderNo;
                        ipdetail.OrderType = receiptDetail.OrderType;
                        ipdetail.OrderSubType = receiptDetail.OrderSubType;
                        ipdetail.OrderDetailId = receiptDetail.OrderDetailId;
                        ipdetail.OrderDetailSequence = receiptDetail.OrderDetailSequence;
                        ipdetail.Item = receiptDetail.Item;
                        ipdetail.ItemDescription = receiptDetail.ItemDescription;
                        ipdetail.ReferenceItemCode = receiptDetail.ReferenceItemCode;
                        ipdetail.BaseUom = receiptDetail.BaseUom;
                        ipdetail.Uom = receiptDetail.Uom;
                        ipdetail.UnitCount = receiptDetail.UnitCount;
                        //ipdetail.UnitCountDescription = receiptDetail.UnitCountDescription;
                        //ipdetail.Container = receiptDetail.Container;
                        //ipdetail.ContainerDescription = receiptDetail.ContainerDescription;
                        ipdetail.QualityType = receiptDetail.QualityType;
                        //ipdetail.ManufactureParty = receiptDetail.ManufactureParty;
                        if ((ipdetail.OrderType == CodeMaster.OrderType.Procurement || ipdetail.OrderType == CodeMaster.OrderType.SubContract) && ipdetail.OrderSubType == CodeMaster.OrderSubType.Return)
                        {
                            //退货的订单需要入库y
                            ipdetail.Qty = receiptDetail.ReceivedQty;
                        }
                        else
                        {
                            ipdetail.Qty = -receiptDetail.ReceivedQty;
                        }
                        //ipdetail.ReceivedQty = 
                        ipdetail.UnitQty = receiptDetail.UnitQty;
                        ipdetail.LocationFrom = receiptDetail.LocationFrom;
                        ipdetail.LocationFromName = receiptDetail.LocationFromName;
                        ipdetail.LocationTo = receiptDetail.LocationTo;
                        ipdetail.LocationToName = receiptDetail.LocationToName;
                        ipdetail.IsInspect = false;
                        //ipdetail.BillTerm = receiptDetail.BillTerm;
                        ipdetail.IsVoid = true;

                        cancelIpDetailList.Add(ipdetail);

                        foreach (InventoryTransaction inventoryTransaction in rctInventoryTransactionList)
                        {
                            IpDetailInput ipDetailInput = new IpDetailInput();

                            ipDetailInput.HuId = inventoryTransaction.HuId;
                            if ((ipdetail.OrderType == CodeMaster.OrderType.Procurement || ipdetail.OrderType == CodeMaster.OrderType.SubContract) && ipdetail.OrderSubType == CodeMaster.OrderSubType.Return)
                            {
                                ipDetailInput.ShipQty = -inventoryTransaction.Qty / ipdetail.UnitQty;
                            }
                            else
                            {
                                ipDetailInput.ShipQty = inventoryTransaction.Qty / ipdetail.UnitQty;
                            }
                            ipDetailInput.LotNo = inventoryTransaction.LotNo;
                            ipDetailInput.IsCreatePlanBill = inventoryTransaction.IsCreatePlanBill;
                            if (inventoryTransaction.ActingBill.HasValue)
                            {
                                int planBill = this.genericMgr.FindAllWithNativeSql<Int32>("select PlanBill from BIL_ActBill where Id = ?", inventoryTransaction.ActingBill.Value).Single();
                                ipDetailInput.IsConsignment = true;
                                ipDetailInput.PlanBill = planBill;
                                ipDetailInput.ActingBill = null;
                            }
                            else
                            {
                                ipDetailInput.IsConsignment = inventoryTransaction.IsConsignment;
                                ipDetailInput.PlanBill = inventoryTransaction.PlanBill;
                                ipDetailInput.ActingBill = inventoryTransaction.ActingBill;
                            }
                            ipDetailInput.OccupyType = inventoryTransaction.OccupyType;
                            ipDetailInput.OccupyReferenceNo = inventoryTransaction.OccupyReferenceNo;

                            ipdetail.AddIpDetailInput(ipDetailInput);
                        }
                    }
                    #endregion
                }
            }
            #endregion

            #region 订单直接收货,冲销发货记录
            if (cancelIpDetailList != null && cancelIpDetailList.Count > 0)
            {
                foreach (IpDetail cancelIpDetail in cancelIpDetailList)
                {
                    cancelIpDetail.CurrentPartyFrom = receiptMaster.PartyFrom;  //为了记录库存事务
                    cancelIpDetail.CurrentPartyFromName = receiptMaster.PartyFromName;  //为了记录库存事务
                    cancelIpDetail.CurrentPartyTo = receiptMaster.PartyTo;      //为了记录库存事务
                    cancelIpDetail.CurrentPartyToName = receiptMaster.PartyToName;      //为了记录库存事务

                    this.locationDetailMgr.InventoryOut(cancelIpDetail);
                }
            }
            #endregion

            #region 生产单,委外冲销退回原材料
            if (receiptMaster.OrderType == CodeMaster.OrderType.Production ||
                receiptMaster.OrderType == CodeMaster.OrderType.SubContract)
            {
                var backflushInputList = ReceiptMaster2BackflushInputList(receiptMaster);
                locationDetailMgr.CancelBackflushProductMaterial(backflushInputList, effectiveDate);
                var orderBackflushDetailList = BackflushInputList2OrderBackflushDetailList(backflushInputList);
                DateTime dateTimeNow = DateTime.Now;
                User currentUser = SecurityContextHolder.Get();
                foreach (OrderBackflushDetail orderBackflushDetail in orderBackflushDetailList)
                {
                    orderBackflushDetail.EffectiveDate = effectiveDate;
                    orderBackflushDetail.CreateUserId = currentUser.Id;
                    orderBackflushDetail.CreateUserName = currentUser.FullName;
                    orderBackflushDetail.CreateDate = dateTimeNow;
                    orderBackflushDetail.IsVoid = true;
                    this.genericMgr.Create(orderBackflushDetail);
                }
            }
            #endregion
        }
Ejemplo n.º 7
0
        public bool TryResumeClosedScheduleLineIpDetail(IpDetail ipDetail)
        {

            //检查ipmstr的订单类型和允许多次收货选项
            IpMaster ipmstr = genericMgr.FindById<IpMaster>(ipDetail.IpNo);

            if (ipmstr.OrderType != CodeMaster.OrderType.ScheduleLine)
            {
                throw new BusinessException("非计划协议类送货单不能按行恢复");
            }
            else if (ipmstr.IsAsnUniqueReceive)
            {
                throw new BusinessException("ASN设置为一次收货不能按行恢复");
            }
            else if (ipmstr.Status == CodeMaster.IpStatus.Close)
            {
                throw new BusinessException("送货单已关闭,不能恢复行");
            }
            else if (ipmstr.Status == CodeMaster.IpStatus.Cancel)
            {
                throw new BusinessException("送货单已取消,不能恢复行");
            }
            else if (ipDetail.ReceivedQty > 0)
            {
                throw new BusinessException("明细行有收货记录不能恢复");
            }
            else if (!ipDetail.IsClose)
            {
                throw new BusinessException("明细行并未关闭不需恢复");
            }
            else
            {
                ipDetail.IsClose = false;
                ipDetail.LastModifyDate = DateTime.Now;
                ipDetail.LastModifyUserId = SecurityContextHolder.Get().Id;
                ipDetail.LastModifyUserName = SecurityContextHolder.Get().Name;

                try
                {
                    genericMgr.Update(ipDetail);
                    return true;
                }
                catch (Exception e)
                {
                    return false;
                }

            }


        }
Ejemplo n.º 8
0
        private void RecordLocationTransaction(IpDetail ipDetail, IpDetailInput ipDetailInput, DateTime effectiveDate,
           com.Sconit.CodeMaster.TransactionType transType, IList<InventoryTransaction> inventoryTransactionList)
        {
            DateTime dateTimeNow = DateTime.Now;

            //根据PlanBill和ActingBill分组,为了不同供应商的库存事务分开
            var groupedInventoryTransactionList = from trans in inventoryTransactionList
                                                  group trans by new
                                                  {
                                                      IsConsignment = trans.IsConsignment,
                                                      PlanBill = trans.PlanBill,
                                                      ActingBill = trans.ActingBill
                                                  }
                                                      into result
                                                      select new
                                                      {
                                                          IsConsignment = result.Key.IsConsignment,
                                                          PlanBill = result.Key.PlanBill,
                                                          ActingBill = result.Key.ActingBill,
                                                          Qty = result.Sum(trans => trans.Qty),
                                                          PlanBillQty = result.Sum(trans => trans.PlanBillQty),
                                                          ActingBillQty = result.Sum(trans => trans.ActingBillQty),
                                                          InventoryTransactionList = result.ToList()
                                                      };

            foreach (var groupedInventoryTransaction in groupedInventoryTransactionList)
            {
                LocationTransaction locationTransaction = new LocationTransaction();

                locationTransaction.OrderNo = ipDetail.OrderNo;
                locationTransaction.OrderType = ipDetail.OrderType;
                locationTransaction.OrderSubType = ipDetail.OrderSubType;
                locationTransaction.OrderDetailSequence = ipDetail.OrderDetailSequence;
                locationTransaction.OrderDetailId = ipDetail.OrderDetailId.Value;
                //locationTransaction.OrderBomDetId = 
                locationTransaction.IpNo = ipDetail.IpNo;
                locationTransaction.IpDetailId = ipDetail.Id;
                locationTransaction.IpDetailSequence = ipDetail.Sequence;
                locationTransaction.ReceiptNo = string.Empty;
                //locationTransaction.RecDetSeq = 
                locationTransaction.SequenceNo = ipDetailInput.SequenceNo;
                //locationTransaction.TraceCode =
                locationTransaction.Item = ipDetail.Item;
                locationTransaction.Uom = ipDetail.Uom;
                locationTransaction.BaseUom = ipDetail.BaseUom;
                locationTransaction.Qty = groupedInventoryTransaction.Qty / ipDetail.UnitQty;
                locationTransaction.UnitQty = ipDetail.UnitQty;
                locationTransaction.IsConsignment = groupedInventoryTransaction.IsConsignment;
                if (groupedInventoryTransaction.IsConsignment && groupedInventoryTransaction.PlanBill.HasValue)
                {
                    locationTransaction.PlanBill = groupedInventoryTransaction.PlanBill.Value;
                }
                locationTransaction.PlanBillQty = groupedInventoryTransaction.PlanBillQty / ipDetail.UnitQty;
                if (groupedInventoryTransaction.ActingBill.HasValue)
                {
                    locationTransaction.ActingBill = groupedInventoryTransaction.ActingBill.Value;
                }
                locationTransaction.ActingBillQty = groupedInventoryTransaction.ActingBillQty / ipDetail.UnitQty;
                locationTransaction.QualityType = ipDetail.QualityType;
                locationTransaction.HuId = ipDetailInput.HuId;
                locationTransaction.LotNo = ipDetailInput.LotNo;
                locationTransaction.TransactionType = transType;
                locationTransaction.IOType = CodeMaster.TransactionIOType.Out;
                locationTransaction.PartyFrom = ipDetail.CurrentPartyFrom;
                locationTransaction.PartyTo = ipDetail.CurrentPartyTo;
                locationTransaction.LocationFrom = ipDetail.LocationFrom;
                locationTransaction.LocationTo = ipDetail.LocationTo;
                locationTransaction.LocationIOReason = string.Empty;
                locationTransaction.EffectiveDate = effectiveDate;
                locationTransaction.CreateUserId = SecurityContextHolder.Get().Id;
                locationTransaction.CreateDate = dateTimeNow;

                this.genericMgr.Create(locationTransaction);

                RecordLocationTransactionDetail(locationTransaction, groupedInventoryTransaction.InventoryTransactionList);
            }
        }
        public ActionResult _DetailUnitPriceUpdate(IpDetail updateIpDetail, string Item, string IpNo)
        {

            IpDetail ipDetail = genericMgr.FindById<IpDetail>(updateIpDetail.Id);
            try
            {
                ipDetail.UnitPrice = updateIpDetail.UnitPrice;
                ipDetail.IsProvisionalEstimate = updateIpDetail.IsProvisionalEstimate;
                genericMgr.Update(ipDetail);


                IList<object> param = new List<object>();
                string hql = " from IpDetail i where 1=1";
                if (!string.IsNullOrEmpty(IpNo))
                {
                    hql += " and i.IpNo=?";
                    param.Add(IpNo);
                }
                if (!string.IsNullOrEmpty(Item))
                {
                    hql += " and i.Item=?";
                    param.Add(Item);
                }

                IList<IpDetail> IpDetailList = genericMgr.FindAll<IpDetail>(hql, param.ToArray());
                return PartialView(new GridModel(IpDetailList));
            }
            catch (BusinessException ex)
            {
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 500;
                Response.Write(ex.GetMessages()[0].GetMessageString());
                return Json(null);
            }
        }
Ejemplo n.º 10
0
        //[Transaction(TransactionMode.Requires)]
        //public IList<InventoryTransaction> CancelInventoryOut(IpDetail ipDetail)
        //{
        //    return CancelInventoryOut(ipDetail, DateTime.Now);
        //}

        //[Transaction(TransactionMode.Requires)]
        //public IList<InventoryTransaction> CancelInventoryOut(IpDetail ipDetail, DateTime effectiveDate)
        //{
        //    List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();
        //    com.Sconit.CodeMaster.TransactionType? transType = GetTransactionType(ipDetail);
        //    if (transType.HasValue)
        //    {
        //        foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs)
        //        {
        //            InventoryIO inventoryIO = new InventoryIO();

        //            inventoryIO.Location = ipDetail.LocationFrom;
        //            inventoryIO.Item = ipDetail.Item;
        //            inventoryIO.HuId = ipDetailInput.HuId;
        //            inventoryIO.Qty = ipDetailInput.ShipQty * ipDetail.UnitQty;  //转换为库存单位,冲销数为正数
        //            inventoryIO.LotNo = ipDetailInput.LotNo;
        //            inventoryIO.QualityType = ipDetail.QualityType;     //不合格品的ATP状态一定是false,合格品的状态一定是true,质检不采用ASN发货这里不可能出现
        //            inventoryIO.IsATP = ipDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
        //            inventoryIO.IsFreeze = false;                       //可能指定移库冻结的零件?
        //            inventoryIO.IsCreatePlanBill = ipDetailInput.IsCreatePlanBill;
        //            inventoryIO.IsConsignment = ipDetailInput.IsConsignment;
        //            inventoryIO.PlanBill = ipDetailInput.PlanBill;
        //            inventoryIO.ActingBill = ipDetailInput.ActingBill;
        //            inventoryIO.TransactionType = transType.Value;
        //            inventoryIO.OccupyType = ipDetail.CurrentOccupyType;
        //            inventoryIO.OccupyReferenceNo = ipDetail.CurrentOccupyReferenceNo;
        //            inventoryIO.IsVoid = ipDetail.IsVoid;
        //            inventoryIO.EffectiveDate = effectiveDate;

        //            inventoryTransactionList.AddRange(RecordInventory(inventoryIO));
        //            RecordLocationTransaction(ipDetail, ipDetailInput, effectiveDate, transType.Value, inventoryTransactionList);
        //        }
        //    }
        //    else if (((ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement    //采购发货
        //       || ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.CustomerGoods)     //客供品发货
        //       && ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
        //       || (ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution      //销售退货发货
        //       && ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return))
        //    {
        //        //在途物料冲销不影响库存
        //    }
        //    else
        //    {
        //        throw new TechnicalException("未知情况,需要跟踪。");
        //    }

        //    return inventoryTransactionList;
        //}

        private com.Sconit.CodeMaster.TransactionType? GetTransactionType(IpDetail ipDetail)
        {
            if (ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                || ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.CustomerGoods)
            {
                if (ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    return null;
                }
                else if (ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
                {
                    if (!ipDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_PO;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_PO_VOID;
                    }
                }
            }
            else if (ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine)
            {
                if (ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    return null;
                }
                else if (ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
                {
                    if (!ipDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_SL;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_SL_VOID;
                    }
                }
            }
            else if (ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution)
            {
                if (ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    if (!ipDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_SO;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_SO_VOID;
                    }
                }
                else if (ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
                {
                    return null;
                }
            }
            else if (ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Transfer)
            {
                if (ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    if (!ipDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_TR;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_TR_VOID;
                    }
                }
                else if (ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
                {
                    if (!ipDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_TR_RTN;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_TR_RTN_VOID;
                    }
                }
            }
            else if (ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContractTransfer)
            {
                if (ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    if (!ipDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_STR;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_STR_VOID;
                    }
                }
                else if (ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
                {
                    if (!ipDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_STR_RTN;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_STR_RTN_VOID;
                    }
                }
            }
            else if (ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Production)
            {
                if (ipDetail.OrderSubType == CodeMaster.OrderSubType.Return)
                {
                    if (!ipDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_WO_RTN;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_WO_RTN_VOID;
                    }
                }
                else
                {
                    return null;
                }
            }
            else if (ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract)
            {
                if (ipDetail.OrderSubType == CodeMaster.OrderSubType.Return)
                {
                    if (!ipDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_SWO_RTN;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.ISS_SWO_RTN_VOID;
                    }
                }
                else
                {
                    return null;
                }
            }
            else
            {
                throw new TechnicalException("Wrong order type of ipDetail:[" + ipDetail.OrderType + "]");
            }

            return null;
        }
Ejemplo n.º 11
0
        public IList<InventoryTransaction> InventoryOut(IpDetail ipDetail, DateTime effectiveDate)
        {
            List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();
            com.Sconit.CodeMaster.TransactionType? transType = GetTransactionType(ipDetail);
            if (transType.HasValue)
            {
                foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs)
                {
                    InventoryIO inventoryIO = new InventoryIO();

                    inventoryIO.Location = ipDetail.LocationFrom;
                    inventoryIO.Item = ipDetail.Item;
                    inventoryIO.HuId = ipDetailInput.HuId;
                    inventoryIO.Qty = -ipDetailInput.ShipQty * ipDetail.UnitQty;  //转换为库存单位,发货为负数
                    inventoryIO.LotNo = ipDetailInput.LotNo;
                    inventoryIO.QualityType = ipDetail.QualityType;     //不合格品的ATP状态一定是false,合格品的状态一定是true,质检不采用ASN发货这里不可能出现
                    inventoryIO.IsATP = ipDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryIO.IsFreeze = false;                       //可能指定移库冻结的零件?
                    inventoryIO.IsCreatePlanBill = ipDetailInput.IsCreatePlanBill;
                    inventoryIO.IsConsignment = ipDetailInput.IsConsignment;
                    inventoryIO.PlanBill = ipDetailInput.PlanBill;
                    inventoryIO.ActingBill = ipDetailInput.ActingBill;
                    inventoryIO.TransactionType = transType.Value;
                    //if (ipDetail.CurrentOccupyType == com.Sconit.CodeMaster.OccupyType.Pick)
                    //{
                    //    //发货不能发捡货单占用的零件
                    //    throw new TechnicalException("Can't ship material occupied by picklist.");
                    //}
                    //else if (ipDetail.CurrentOccupyType == com.Sconit.CodeMaster.OccupyType.Inspect
                    //    && (transType.Value != com.Sconit.CodeMaster.TransactionType.ISS_TR
                    //    || transType.Value != com.Sconit.CodeMaster.TransactionType.ISS_TR_VOID))
                    //{
                    //    //检验、不合格品占用的零件只能做移库及移库冲销
                    //    throw new TechnicalException("Can't ship material occupied by inspect order.");
                    //}
                    inventoryIO.OccupyType = ipDetailInput.OccupyType;
                    inventoryIO.OccupyReferenceNo = ipDetailInput.OccupyReferenceNo;
                    inventoryIO.IsVoid = ipDetail.IsVoid;
                    inventoryIO.EffectiveDate = effectiveDate;
                    inventoryIO.ManufactureParty = ipDetailInput.ManufactureParty;

                    IList<InventoryTransaction> currentInventoryTransactionList = RecordInventory(inventoryIO);
                    #region 记录WMS发货单行号
                    foreach (InventoryTransaction currentInventoryTransaction in currentInventoryTransactionList)
                    {
                        currentInventoryTransaction.WMSIpSeq = ipDetailInput.WMSIpSeq;
                    }
                    #endregion
                    RecordLocationTransaction(ipDetail, ipDetailInput, effectiveDate, transType.Value, currentInventoryTransactionList);
                    inventoryTransactionList.AddRange(currentInventoryTransactionList);
                }
            }
            //else if (ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
            //    && ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
            //{
            //    #region 采购发货为供应商生成在途寄售物料
            //    foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs)
            //    {
            //        inventoryTransactionList = new List<InventoryTransaction>();

            //        InventoryTransaction inventoryTransaction = new InventoryTransaction();
            //        inventoryTransaction.Item = ipDetail.Item;
            //        inventoryTransaction.HuId = ipDetailInput.HuId;
            //        inventoryTransaction.LotNo = ipDetailInput.LotNo;
            //        inventoryTransaction.IsConsignment = true;
            //        inventoryTransaction.IsCreatePlanBill = true;
            //        PlanBill planBill = this.billMgr.CreatePlanBill(ipDetail, ipDetailInput, effectiveDate);
            //        inventoryTransaction.PlanBill = planBill.Id;
            //        inventoryTransaction.Qty = ipDetailInput.ShipQty;
            //        inventoryTransaction.QualityType = ipDetail.QualityType;
            //        inventoryTransaction.IsATP = ipDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
            //        inventoryTransaction.IsFreeze = false;
            //        inventoryTransaction.OccupyType = com.Sconit.CodeMaster.OccupyType.None;
            //        inventoryTransactionList.Add(inventoryTransaction);
            //    }
            //    #endregion
            //}
            else if (((ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement    //采购发货
                        || ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine        //计划协议
                        || ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.CustomerGoods)      //客供品发货
                        && ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                || (ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution
                && ipDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)//销售退货发货
                        || ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract   //委外
                        || ipDetail.OrderType == com.Sconit.CodeMaster.OrderType.Production     //生产
                )
            {
                #region 生成在途非寄售物料
                inventoryTransactionList = new List<InventoryTransaction>();
                foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs)
                {
                    InventoryTransaction inventoryTransaction = new InventoryTransaction();

                    inventoryTransaction.Item = ipDetail.Item;
                    inventoryTransaction.HuId = ipDetailInput.HuId;
                    inventoryTransaction.LotNo = ipDetailInput.LotNo;
                    inventoryTransaction.IsConsignment = false;
                    inventoryTransaction.IsCreatePlanBill = false;
                    inventoryTransaction.Qty = -ipDetailInput.ShipQty * ipDetail.UnitQty;  //转换为库存单位,出库位负数
                    inventoryTransaction.QualityType = ipDetail.QualityType;
                    inventoryTransaction.IsATP = ipDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryTransaction.IsFreeze = false;
                    inventoryTransaction.OccupyType = com.Sconit.CodeMaster.OccupyType.None;

                    inventoryTransactionList.Add(inventoryTransaction);
                }
                #endregion
            }
            else
            {
                throw new TechnicalException("未知情况,需要跟踪。");
            }

            return inventoryTransactionList;
        }
Ejemplo n.º 12
0
 public IList<InventoryTransaction> InventoryOut(IpDetail ipDetail)
 {
     return InventoryOut(ipDetail, DateTime.Now);
 }
Ejemplo n.º 13
0
        public IDictionary<string, decimal> GetHuId(IpDetail ipDetail)
        {
            var HuIds = GetHuId(ipDetail.LotNo, ipDetail.Item, ipDetail.ManufactureParty,
                ipDetail.HuQty, ipDetail.UnitCount);

            return HuIds;
        }
Ejemplo n.º 14
0
        public void CancelReceipt(ReceiptMaster receiptMaster, DateTime effectiveDate)
        {
            #region 判断收货单状态,只有Close才能冲销
            if (receiptMaster.Status == CodeMaster.ReceiptStatus.Cancel)
            {
                throw new BusinessException("收货单{0}已经冲销。", receiptMaster.ReceiptNo,
                    systemMgr.GetCodeDetailDescription(com.Sconit.CodeMaster.CodeMaster.ReceiptStatus, ((int)receiptMaster.Status).ToString()));
            }
            #endregion

            #region 加载收货单明细及收货单库存明细
            //  TryLoadReceiptDetails(receiptMaster);
            IList<ReceiptLocationDetail> receiptLocationDetailList = TryLoadReceiptLocationDetails(receiptMaster);
            #endregion

            #region 加载订单头和明细
            //GAP收货取消不用调整订单数据
            IList<OrderMaster> orderMasterList = null;
            IList<OrderDetail> orderDetialList = null;
            //if (receiptMaster.Type == CodeMaster.IpDetailType.Normal)
            //{
            #region 获取订单头
            orderMasterList = LoadOrderMasters(receiptMaster.ReceiptDetails.Select(det => det.OrderNo).Distinct().ToArray());
            #endregion

            #region 获取订单明细
            orderDetialList = LoadOrderDetails(receiptMaster.ReceiptDetails.Where(det => det.OrderDetailId.HasValue).Select(det => det.OrderDetailId.Value).Distinct().ToArray());
            #endregion
            //}
            #endregion

            //小数保留位数
            int decimalLength = int.Parse(systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.DecimalLength));

            #region 回滚送货单
            if (!string.IsNullOrWhiteSpace(receiptMaster.IpNo))
            {
                IpMaster ipMaster = this.genericMgr.FindById<IpMaster>(receiptMaster.IpNo);

                #region 查找送货单明细
                string selectIpDetailStatement = string.Empty;
                IList<object> selectIpDetailPram = new List<object>();
                foreach (int ipDetailId in receiptMaster.ReceiptDetails.Select(recDet => recDet.IpDetailId).Distinct())
                {
                    if (selectIpDetailStatement == string.Empty)
                    {
                        selectIpDetailStatement = "from IpDetail where Id in (?";
                    }
                    else
                    {
                        selectIpDetailStatement += ",?";
                    }

                    selectIpDetailPram.Add(ipDetailId);
                }
                selectIpDetailStatement += ")";
                IList<IpDetail> ipDetailList = this.genericMgr.FindAll<IpDetail>(selectIpDetailStatement, selectIpDetailPram.ToArray());
                #endregion

                #region 查找送货单库存明细
                IList<IpLocationDetail> ipLocationDetailList = LoadIpLocationDetails(ipDetailList.Select(ipDet => ipDet.Id).ToArray());
                #endregion

                #region 查找差异送货单明细
                IList<IpDetail> gapIpDetailList = this.genericMgr.FindAll<IpDetail>("from IpDetail where GapReceiptNo = ?", receiptMaster.ReceiptNo);
                #endregion

                #region 差异全部关闭
                if (gapIpDetailList != null && gapIpDetailList.Count > 0)
                {
                    #region 查找差异送货单库存明细
                    IList<IpLocationDetail> gapIpLocationDetailList = LoadIpLocationDetails(gapIpDetailList.Select(ipDet => ipDet.Id).ToArray());
                    #endregion

                    foreach (IpDetail gapIpDetail in gapIpDetailList)
                    {
                        if (gapIpDetail.ReceivedQty != 0)
                        {
                            throw new BusinessException("收货单{0}的收货差异已经调整,不能冲销。", receiptMaster.ReceiptNo);
                        }

                        gapIpDetail.IsClose = true;
                        this.genericMgr.Update(gapIpDetail);
                    }

                    foreach (IpLocationDetail gapIpLocationDetail in gapIpLocationDetailList)
                    {
                        gapIpLocationDetail.IsClose = true;
                        this.genericMgr.Update(gapIpLocationDetail);
                    }
                }
                #endregion

                #region 打开未收货的发货明细
                //只有ASN一次性收货才打开未收货的发货明细
                if (ipMaster.IsAsnUniqueReceive)
                {
                    //只有正常收货才能打开未收货的发货明细。
                    int isGapRec = receiptMaster.ReceiptDetails.Where(recDet => recDet.IpDetailType == CodeMaster.IpDetailType.Gap).Count();
                    if (isGapRec == 0)
                    {
                        IList<IpDetail> unReceivedIpDetailList = this.genericMgr.FindAll<IpDetail>("from IpDetail where IpNo = ? and Type = ?",
                            new object[] { ipMaster.IpNo, CodeMaster.IpDetailType.Normal });

                        if (unReceivedIpDetailList != null && unReceivedIpDetailList.Count > 0)
                        {
                            #region 查找差异送货单库存明细
                            IList<IpLocationDetail> unReceivedIpLocationDetailList = LoadIpLocationDetails(unReceivedIpDetailList.Select(ipDet => ipDet.Id).ToArray());
                            #endregion

                            foreach (IpDetail unReceivedIpDetail in unReceivedIpDetailList)
                            {
                                if (unReceivedIpDetail.IsClose)
                                {
                                    unReceivedIpDetail.IsClose = false;
                                    this.genericMgr.Update(unReceivedIpDetail);
                                }
                            }

                            foreach (IpLocationDetail unReceivedIpLocationDetail in unReceivedIpLocationDetailList)
                            {
                                if (unReceivedIpLocationDetail.IsClose)
                                {
                                    unReceivedIpLocationDetail.IsClose = false;
                                    this.genericMgr.Update(unReceivedIpLocationDetail);
                                }
                            }
                        }
                    }
                }
                #endregion

                #region 收货库存明细和送货库存明细匹配
                foreach (ReceiptLocationDetail receiptLocationDetail in receiptLocationDetailList)
                {
                    ReceiptDetail receiptDetail = receiptMaster.ReceiptDetails.Where(recDet => recDet.Id == receiptLocationDetail.ReceiptDetailId).Single();

                    decimal remainBaseQty = receiptLocationDetail.Qty;  //基本单位
                    decimal remainQty = receiptLocationDetail.Qty / receiptDetail.UnitQty; //转为订单单位

                    if (!string.IsNullOrWhiteSpace(receiptLocationDetail.HuId)
                        && ipLocationDetailList.Where(ipLocDet => !string.IsNullOrWhiteSpace(ipLocDet.HuId)).Count() > 0)
                    {
                        #region 条码和条码匹配
                        IpLocationDetail ipLocationDetail = ipLocationDetailList.Where(ipLocDet => ipLocDet.HuId == receiptLocationDetail.HuId).SingleOrDefault();
                        IpDetail ipDetail = ipDetailList.Where(ipDet => ipDet.Id == receiptDetail.IpDetailId).Single();

                        if (ipDetail.Id != receiptDetail.IpDetailId)
                        {
                            throw new TechnicalException("收货单明细和发货单明细ID不匹配。");
                        }

                        if (ipDetail.Type != receiptDetail.IpDetailType)
                        {
                            throw new TechnicalException("收货单明细和发货单明细类型不匹配。");
                        }

                        #region 扣减发货单的收货数
                        if (ipLocationDetail != null)
                        {
                            ipLocationDetail.ReceivedQty -= remainBaseQty;
                            ipLocationDetail.IsClose = false;
                        }
                        ipDetail.ReceivedQty -= remainQty; //转为订单单位
                        ipDetail.IsClose = false;

                        remainBaseQty = 0;
                        remainQty = 0;
                        #endregion

                        if (ipLocationDetail != null)
                        {
                            this.genericMgr.Update(ipLocationDetail);
                        }
                        this.genericMgr.Update(ipDetail);
                        #endregion
                    }
                    else
                    {
                        #region 按数量匹配
                        IList<IpDetail> thisIpDetailList = ipDetailList.Where(ipDet => ipDet.ReceivedQty != 0  //过滤掉已经扣完的明细
                                                                    && ipDet.Id == receiptDetail.IpDetailId).ToList();

                        if (thisIpDetailList != null && thisIpDetailList.Count > 0)
                        {
                            IList<IpLocationDetail> thisIpLocationDetailList = null;
                            foreach (IpDetail thisIpDetail in thisIpDetailList)
                            {
                                if (thisIpDetail.ReceivedQty > 0)
                                {
                                    thisIpLocationDetailList = ipLocationDetailList.Where(
                                        ipLocDet => ipLocDet.ReceivedQty > 0 && ipLocDet.IpDetailId == thisIpDetail.Id).ToList();
                                }
                                else if (thisIpDetail.ReceivedQty < 0)
                                {
                                    thisIpLocationDetailList = ipLocationDetailList.Where(
                                        ipLocDet => ipLocDet.ReceivedQty < 0 && ipLocDet.IpDetailId == thisIpDetail.Id).ToList();
                                }

                                if (thisIpLocationDetailList != null && thisIpLocationDetailList.Count > 0)
                                {
                                    foreach (IpLocationDetail thisIpLocationDetail in thisIpLocationDetailList)
                                    {
                                        if (thisIpLocationDetail.ReceivedQty > remainBaseQty)
                                        {
                                            thisIpDetail.ReceivedQty -= remainQty;
                                            remainQty = 0;

                                            thisIpLocationDetail.ReceivedQty -= remainBaseQty;
                                            remainBaseQty = 0;

                                            thisIpDetail.IsClose = false;
                                            thisIpLocationDetail.IsClose = false;
                                        }
                                        else
                                        {
                                            decimal thisBackflushQty = thisIpLocationDetail.ReceivedQty / thisIpDetail.UnitQty; //转为订单单位
                                            remainQty -= thisBackflushQty;
                                            thisIpDetail.ReceivedQty -= thisBackflushQty;

                                            remainBaseQty -= thisIpLocationDetail.ReceivedQty;
                                            thisIpLocationDetail.ReceivedQty = 0;

                                            thisIpDetail.IsClose = false;
                                            thisIpLocationDetail.IsClose = false;
                                        }

                                        this.genericMgr.Update(thisIpLocationDetail);
                                        this.genericMgr.Update(thisIpDetail);
                                    }
                                }
                                else
                                {
                                    //throw new TechnicalException("差异送货单明细和送货单库存明细不匹配。");
                                }
                            }
                        }
                        #endregion
                    }

                    if (remainBaseQty != 0)
                    {
                        throw new TechnicalException("收货单的收货数没有回冲完。");
                    }
                }
                #endregion

                #region 更新订单明细
                if (receiptMaster.OrderType != CodeMaster.OrderType.ScheduleLine)
                {
                    #region 非计划协议
                    foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails)
                    {
                        OrderDetail matchedOrderDetial = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId.Value).Single();

                        if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Normal)
                        {
                            matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty;
                            if (matchedOrderDetial.ReceivedQty < 0)
                            {
                                throw new TechnicalException("订单收货数小于0。");
                            }
                        }
                        else
                        {
                            //差异收货冲销
                            #region 调整发货方库存
                            if (receiptMaster.PartyFrom == ipMaster.PartyTo)   //发货方等于收货方
                            {
                                //更新订单的发货数
                                matchedOrderDetial.ShippedQty += receiptDetail.ReceivedQty;
                            }
                            #endregion

                            #region 调整收货方库存
                            else
                            {
                                //更新订单的收货数
                                matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty;
                            }
                            #endregion
                        }
                        genericMgr.Update(matchedOrderDetial);
                    }
                    #endregion
                }
                else
                {
                    foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails)
                    {
                        decimal receivedQty = receiptDetail.ReceivedQty;

                        if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Normal)
                        {
                            #region 调整收货方库存
                            IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq = ? and ScheduleType = ? and RecQty > 0 order by EndDate desc",
                                              new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence, CodeMaster.ScheduleType.Firm });

                            foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList)
                            {
                                if (receivedQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty))
                                {
                                    receivedQty -= scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty;
                                    scheduleOrderDetail.ReceivedQty -= receiptDetail.ReceivedQty;
                                }
                                else
                                {
                                    scheduleOrderDetail.ReceivedQty -= receivedQty;
                                    receivedQty = 0;
                                }

                                genericMgr.Update(scheduleOrderDetail);
                            }
                            #endregion
                        }
                        else
                        {
                            //差异收货冲销
                            #region 调整发货方库存
                            if (receiptMaster.PartyFrom == ipMaster.PartyTo)   //发货方等于收货方
                            {
                                IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq = ? and ScheduleType = ? and OrderQty > ShipQty order by EndDate",
                                              new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence, CodeMaster.ScheduleType.Firm });

                                foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList)
                                {
                                    if (receivedQty > (scheduleOrderDetail.OrderedQty - scheduleOrderDetail.ShippedQty))
                                    {
                                        receivedQty -= scheduleOrderDetail.OrderedQty - scheduleOrderDetail.ShippedQty;
                                        scheduleOrderDetail.ShippedQty = scheduleOrderDetail.OrderedQty;
                                    }
                                    else
                                    {
                                        scheduleOrderDetail.ShippedQty += receivedQty;
                                        receivedQty = 0;
                                    }

                                    genericMgr.Update(scheduleOrderDetail);
                                }
                            }
                            #endregion

                            #region 调整收货方库存
                            else
                            {
                                IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq = ? and ScheduleType = ? and RecQty > 0 order by EndDate desc",
                                              new object[] { receiptDetail.ExternalOrderNo, receiptDetail.ExternalSequence, CodeMaster.ScheduleType.Firm });

                                foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList)
                                {
                                    if (receivedQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty))
                                    {
                                        receivedQty -= scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty;
                                        scheduleOrderDetail.ReceivedQty -= receiptDetail.ReceivedQty;
                                    }
                                    else
                                    {
                                        scheduleOrderDetail.ReceivedQty -= receivedQty;
                                        receivedQty = 0;
                                    }

                                    genericMgr.Update(scheduleOrderDetail);
                                }
                            }
                            #endregion
                        }
                    }
                }
                #endregion

                #region 回滚送货单状态
                //1. 普通状态的送货明细没有收过货
                //2. 差异状态的送货明细全部关闭
                if (ipDetailList.Where(ipDet => ipDet.Type == CodeMaster.IpDetailType.Normal && ipDet.ReceivedQty != 0).Count() == 0
                    && ipDetailList.Where(ipDet => ipDet.Type == CodeMaster.IpDetailType.Gap && !ipDet.IsClose).Count() == 0)
                {
                    ipMaster.Status = CodeMaster.IpStatus.Submit;
                    this.genericMgr.Update(ipMaster);
                }
                else if (ipMaster.Status != CodeMaster.IpStatus.InProcess)
                {
                    ipMaster.Status = CodeMaster.IpStatus.InProcess;
                    this.genericMgr.Update(ipMaster);
                }
                #endregion
            }
            else
            {
                #region 更新订单明细
                foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails)
                {
                    if (receiptDetail != null)
                    {
                        OrderDetail matchedOrderDetial = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId.Value).Single();
                        matchedOrderDetial.ReceivedQty -= receiptDetail.ReceivedQty;
                        matchedOrderDetial.ScrapQty -= receiptDetail.ScrapQty;
                        if (matchedOrderDetial.OrderType != CodeMaster.OrderType.Production
                            && matchedOrderDetial.OrderType != CodeMaster.OrderType.SubContract)
                        {
                            matchedOrderDetial.ShippedQty -= receiptDetail.ReceivedQty;
                            if (matchedOrderDetial.ShippedQty < 0)
                            {
                                throw new TechnicalException("订单发货数小于0。");
                            }
                        }

                        if (matchedOrderDetial.ReceivedQty < 0)
                        {
                            throw new TechnicalException("订单收货数小于0。");
                        }

                        this.genericMgr.Update(matchedOrderDetial);
                    }
                }
                #endregion
            }
            #endregion

            #region 更新订单
            foreach (OrderMaster orderMaster in orderMasterList)
            {
                if (orderMaster.Status != CodeMaster.OrderStatus.InProcess)
                {
                    orderMaster.Status = CodeMaster.OrderStatus.InProcess;
                    orderMaster.CloseDate = null;
                    orderMaster.CloseUserId = null;
                    orderMaster.CompleteUserName = null;
                    this.genericMgr.Update(orderMaster);
                }
            }
            #endregion

            #region 更新收货单
            receiptMaster.Status = CodeMaster.ReceiptStatus.Cancel;
            this.genericMgr.Update(receiptMaster);
            #endregion

            #region 冲销收货记录
            List<IpDetail> cancelIpDetailList = new List<IpDetail>();
            foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails)
            {
                if (receiptDetail.ReceivedQty != 0)
                {
                    receiptDetail.CurrentPartyFrom = receiptMaster.PartyFrom;  //为了记录库存事务
                    receiptDetail.CurrentPartyFromName = receiptMaster.PartyFromName;
                    receiptDetail.CurrentPartyTo = receiptMaster.PartyTo;
                    receiptDetail.CurrentPartyToName = receiptMaster.PartyToName;
                    receiptDetail.CurrentExternalReceiptNo = receiptMaster.ExternalReceiptNo;
                    receiptDetail.CurrentIsReceiveScanHu = receiptMaster.IsReceiveScanHu;
                    receiptDetail.IsVoid = true;

                    foreach (ReceiptLocationDetail receiptLocationDetail in receiptDetail.ReceiptLocationDetails)
                    {
                        ReceiptDetailInput receiptDetailInput = new ReceiptDetailInput();
                        receiptDetailInput.HuId = receiptLocationDetail.HuId;
                        receiptDetailInput.ReceiveQty = -receiptLocationDetail.Qty / receiptDetail.UnitQty; //转为订单单位
                        receiptDetailInput.LotNo = receiptLocationDetail.LotNo;
                        receiptDetailInput.IsCreatePlanBill = receiptLocationDetail.IsCreatePlanBill;
                        receiptDetailInput.IsConsignment = receiptLocationDetail.IsConsignment;
                        receiptDetailInput.PlanBill = receiptLocationDetail.PlanBill;
                        receiptDetailInput.ActingBill = receiptLocationDetail.ActingBill;
                        receiptDetailInput.IsATP = receiptLocationDetail.IsATP;
                        receiptDetailInput.IsFreeze = receiptLocationDetail.IsFreeze;
                        receiptDetailInput.OccupyType = receiptLocationDetail.OccupyType;
                        receiptDetailInput.OccupyReferenceNo = receiptLocationDetail.OccupyReferenceNo;
                        receiptDetailInput.QualityType = receiptLocationDetail.QualityType;

                        receiptDetail.AddReceiptDetailInput(receiptDetailInput);
                    }

                    #region 更新库存、记库存事务
                    IList<InventoryTransaction> rctInventoryTransactionList = this.locationDetailMgr.InventoryIn(receiptDetail, effectiveDate);
                    #endregion

                    #region 订单直接收货创建发货明细对象
                    if (string.IsNullOrWhiteSpace(receiptMaster.IpNo)
                        && receiptMaster.Type != CodeMaster.IpDetailType.Gap
                        && receiptMaster.OrderType != CodeMaster.OrderType.Production
                        && receiptMaster.OrderType != CodeMaster.OrderType.SubContract)
                    {
                        IpDetail ipdetail = new IpDetail();
                        ipdetail.OrderNo = receiptDetail.OrderNo;
                        ipdetail.OrderType = receiptDetail.OrderType;
                        ipdetail.OrderSubType = receiptDetail.OrderSubType;
                        ipdetail.OrderDetailId = receiptDetail.OrderDetailId;
                        ipdetail.OrderDetailSequence = receiptDetail.OrderDetailSequence;
                        ipdetail.Item = receiptDetail.Item;
                        ipdetail.ItemDescription = receiptDetail.ItemDescription;
                        ipdetail.ReferenceItemCode = receiptDetail.ReferenceItemCode;
                        ipdetail.BaseUom = receiptDetail.BaseUom;
                        ipdetail.Uom = receiptDetail.Uom;
                        ipdetail.UnitCount = receiptDetail.UnitCount;
                        //ipdetail.UnitCountDescription = receiptDetail.UnitCountDescription;
                        //ipdetail.Container = receiptDetail.Container;
                        //ipdetail.ContainerDescription = receiptDetail.ContainerDescription;
                        ipdetail.QualityType = receiptDetail.QualityType;
                        //ipdetail.ManufactureParty = receiptDetail.ManufactureParty;
                        ipdetail.Qty = receiptDetail.ReceivedQty;
                        //ipdetail.ReceivedQty = 
                        ipdetail.UnitQty = receiptDetail.UnitQty;
                        ipdetail.LocationFrom = receiptDetail.LocationFrom;
                        ipdetail.LocationFromName = receiptDetail.LocationFromName;
                        ipdetail.LocationTo = receiptDetail.LocationTo;
                        ipdetail.LocationToName = receiptDetail.LocationToName;
                        ipdetail.IsInspect = false;
                        //ipdetail.BillTerm = receiptDetail.BillTerm;
                        ipdetail.IsVoid = true;

                        cancelIpDetailList.Add(ipdetail);

                        foreach (InventoryTransaction inventoryTransaction in rctInventoryTransactionList)
                        {
                            IpDetailInput ipDetailInput = new IpDetailInput();

                            ipDetailInput.HuId = inventoryTransaction.HuId;
                            ipDetailInput.ShipQty = inventoryTransaction.Qty / ipdetail.UnitQty;
                            ipDetailInput.LotNo = inventoryTransaction.LotNo;
                            ipDetailInput.IsCreatePlanBill = inventoryTransaction.IsCreatePlanBill;
                            if (inventoryTransaction.ActingBill.HasValue)
                            {
                                int planBill = this.genericMgr.FindAllWithNativeSql<Int32>("select PlanBill from BIL_ActBill where Id = ?", inventoryTransaction.ActingBill.Value).Single();
                                ipDetailInput.IsConsignment = true;
                                ipDetailInput.PlanBill = planBill;
                                ipDetailInput.ActingBill = null;
                            }
                            else
                            {
                                ipDetailInput.IsConsignment = inventoryTransaction.IsConsignment;
                                ipDetailInput.PlanBill = inventoryTransaction.PlanBill;
                                ipDetailInput.ActingBill = inventoryTransaction.ActingBill;
                            }
                            ipDetailInput.OccupyType = inventoryTransaction.OccupyType;
                            ipDetailInput.OccupyReferenceNo = inventoryTransaction.OccupyReferenceNo;

                            ipdetail.AddIpDetailInput(ipDetailInput);
                        }
                    }
                    #endregion
                }

                #region 来源区域是LOC、SQC 的冲销后更新 读取安吉文件中间表的冲销数
                if ((receiptMaster.PartyFrom == systemMgr.GetEntityPreferenceValue(Entity.SYS.EntityPreference.CodeEnum.WMSAnjiRegion) || receiptMaster.PartyFrom == "SQC")
                    && receiptMaster.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal && !string.IsNullOrWhiteSpace(receiptDetail.ExternalOrderNo))
                {
                    var wmsDatfileById = this.genericMgr.FindAll<WMSDatFile>(" select w from WMSDatFile as w where w.WMSId=? ", receiptDetail.ExternalOrderNo, NHibernate.NHibernateUtil.String);
                    if (wmsDatfileById != null && wmsDatfileById.Count > 0)
                    {
                        wmsDatfileById.First().CancelQty += receiptDetail.ReceivedQty;
                        this.genericMgr.Update(wmsDatfileById.First());
                    }
                    //this.genericMgr.UpdateWithNativeQuery(" update FIS_WMSDatFile set CancelQty=CancelQty+? where WMSId=? ",new object[]{ receiptDetail.ReceivedQty, receiptDetail.ExternalOrderNo},new IType[]{NHibernate.NHibernateUtil.Decimal,NHibernate.NHibernateUtil.String});
                    #region 冲销的写入中间表传给安吉
                    this.genericMgr.Create(new CancelReceiptMasterDAT { WMSNo = receiptDetail.ExternalOrderNo, WMSSeq = receiptDetail.OrderDetailId, ReceivedQty = receiptDetail.ReceivedQty, CreateDate = System.DateTime.Now });
                    #endregion
                }
                #endregion
            }
            #endregion

            #region 订单直接收货,冲销发货记录
            if (cancelIpDetailList != null && cancelIpDetailList.Count > 0)
            {
                foreach (IpDetail cancelIpDetail in cancelIpDetailList)
                {
                    cancelIpDetail.CurrentPartyFrom = receiptMaster.PartyFrom;  //为了记录库存事务
                    cancelIpDetail.CurrentPartyFromName = receiptMaster.PartyFromName;  //为了记录库存事务
                    cancelIpDetail.CurrentPartyTo = receiptMaster.PartyTo;      //为了记录库存事务
                    cancelIpDetail.CurrentPartyToName = receiptMaster.PartyToName;      //为了记录库存事务

                    this.locationDetailMgr.InventoryOut(cancelIpDetail);
                }
            }
            #endregion

            #region 生产单冲销退回原材料
            //if (receiptMaster.OrderType == CodeMaster.OrderType.Production
            //    || receiptMaster.OrderType == CodeMaster.OrderType.SubContract)
            //{
            //    DateTime dateTimeNow = DateTime.Now;
            //    User currentUser = SecurityContextHolder.Get();
            //    IList<OrderBackflushDetail> orderBackflushDetailList = new List<OrderBackflushDetail>();
            //    FlowMaster productLine = this.genericMgr.FindById<FlowMaster>(receiptMaster.Flow);
            //    foreach (ReceiptDetail receiptDetail in receiptMaster.ReceiptDetails)
            //    {
            //        OrderMaster orderMaster = orderMasterList.Where(mstr => mstr.OrderNo == receiptDetail.OrderNo).Single();
            //        OrderDetail orderDetail = orderDetialList.Where(det => det.Id == receiptDetail.OrderDetailId).Single();
            //        IList<OrderBomDetail> orderBomDetailList = this.genericMgr.FindAll<OrderBomDetail>("from OrderBomDetail where OrderDetailId = ?", receiptDetail.OrderDetailId);

            //        IList<BackflushInput> backflushInputList = (from bom in orderBomDetailList
            //                                                    where bom.OrderedQty != 0
            //                                                    select new BackflushInput
            //                                                    {
            //                                                        OrderNo = orderMaster.OrderNo,
            //                                                        OrderType = orderMaster.Type,
            //                                                        OrderSubType = orderMaster.SubType,
            //                                                        OrderDetailSequence = orderDetail.Sequence,
            //                                                        OrderDetailId = orderDetail.Id,
            //                                                        OrderBomDetail = bom,
            //                                                        ReceiptNo = receiptMaster.ReceiptNo,
            //                                                        ReceiptDetailId = receiptDetail.Id,
            //                                                        ReceiptDetailSequence = receiptDetail.Sequence,
            //                                                        TraceCode = orderMaster.TraceCode,
            //                                                        Item = bom.Item,
            //                                                        ItemDescription = bom.ItemDescription,
            //                                                        ReferenceItemCode = bom.ReferenceItemCode,
            //                                                        Uom = bom.Uom,
            //                                                        BaseUom = bom.BaseUom,
            //                                                        Qty = bom.BomUnitQty * (receiptDetail.ReceivedQty + receiptDetail.ScrapQty),
            //                                                        UnitQty = bom.UnitQty,
            //                                                        Location = string.IsNullOrWhiteSpace(bom.Location) ? (string.IsNullOrWhiteSpace(orderDetail.LocationFrom) ? orderMaster.LocationFrom : orderDetail.LocationFrom) : bom.Location,
            //                                                        CurrentProductLine = productLine,
            //                                                        ProductLine = productLine.Code,
            //                                                        FGItem = orderDetail.Item,
            //                                                        FGQualityType = CodeMaster.QualityType.Qualified,
            //                                                        Operation = bom.Operation,
            //                                                        OpReference = bom.OpReference,

            //                                                    }).ToList();

            //        IList<InventoryTransaction> inventoryTransactionList = this.locationDetailMgr.CancelBackflushProductMaterial(backflushInputList, effectiveDate);

            //        foreach (BackflushInput backflushInput in backflushInputList)
            //        {
            //            ((List<OrderBackflushDetail>)orderBackflushDetailList).AddRange(from trans in backflushInput.InventoryTransactionList
            //                                                                            group trans by trans.PlanBill into g
            //                                                                            select new OrderBackflushDetail
            //                                                                            {
            //                                                                                OrderNo = backflushInput.OrderNo,
            //                                                                                OrderDetailId = backflushInput.OrderDetailId,
            //                                                                                OrderDetailSequence = backflushInput.OrderDetailSequence,
            //                                                                                OrderBomDetailId = backflushInput.OrderBomDetail.Id,
            //                                                                                OrderBomDetailSequence = backflushInput.OrderBomDetail.Sequence,
            //                                                                                ReceiptNo = backflushInput.ReceiptNo,
            //                                                                                ReceiptDetailId = backflushInput.ReceiptDetailId,
            //                                                                                ReceiptDetailSequence = backflushInput.ReceiptDetailSequence,
            //                                                                                Bom = backflushInput.OrderBomDetail.Bom,
            //                                                                                FGItem = backflushInput.FGItem,
            //                                                                                Item = backflushInput.Item,
            //                                                                                ItemDescription = backflushInput.ItemDescription,
            //                                                                                ReferenceItemCode = backflushInput.ReferenceItemCode,
            //                                                                                Uom = backflushInput.Uom,
            //                                                                                BaseUom = backflushInput.BaseUom,
            //                                                                                UnitQty = backflushInput.UnitQty,
            //                                                                                ManufactureParty = backflushInput.OrderBomDetail.ManufactureParty,
            //                                                                                TraceCode = backflushInput.TraceCode,
            //                                                                                //HuId = result.Key.HuId,
            //                                                                                //LotNo = result.Key.LotNo,
            //                                                                                Operation = backflushInput.Operation,
            //                                                                                OpReference = backflushInput.OpReference,
            //                                                                                BackflushedQty = backflushInput.FGQualityType == CodeMaster.QualityType.Qualified ? g.Sum(trans => trans.Qty) / backflushInput.UnitQty : 0,   //根据收货成品的质量状态记录至不同的回冲数量中
            //                                                                                BackflushedRejectQty = backflushInput.FGQualityType == CodeMaster.QualityType.Reject ? g.Sum(trans => trans.Qty) / backflushInput.UnitQty : 0,
            //                                                                                //BackflushedScrapQty = input.BackflushedQty,
            //                                                                                LocationFrom = backflushInput.OrderBomDetail.Location,
            //                                                                                ProductLine = backflushInput.ProductLine,
            //                                                                                ProductLineFacility = backflushInput.ProductLineFacility,
            //                                                                                PlanBill = g.Key,
            //                                                                                EffectiveDate = effectiveDate,
            //                                                                                CreateUserId = currentUser.Id,
            //                                                                                CreateUserName = currentUser.FullName,
            //                                                                                CreateDate = dateTimeNow,
            //                                                                                IsVoid = true,
            //                                                                                ReserveNo = backflushInput.OrderBomDetail.ReserveNo,
            //                                                                                ReserveLine = backflushInput.OrderBomDetail.ReserveLine,
            //                                                                                AUFNR = backflushInput.OrderBomDetail.AUFNR,
            //                                                                                ICHARG = backflushInput.OrderBomDetail.ICHARG,
            //                                                                                BWART = (int.Parse(backflushInput.OrderBomDetail.BWART) + 1).ToString(),
            //                                                                            });
            //        }
            //    }

            //    foreach (OrderBackflushDetail orderBackflushDetail in orderBackflushDetailList)
            //    {
            //        this.genericMgr.Create(orderBackflushDetail);
            //    }
            //}
            #endregion
        }