コード例 #1
0
        public IList<InventoryTransaction> InventoryIn(ReceiptDetail receiptDetail, DateTime effectiveDate)
        {
            List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();
            com.Sconit.CodeMaster.TransactionType? transType = GetTransactionType(receiptDetail);
            if (transType.HasValue)
            {
                #region 收货冲销,如果一个条码对应多条receiptDetailInput,需要先拆箱
                if (receiptDetail.IsVoid)
                {
                    var groupedHuIdList = from det in receiptDetail.ReceiptDetailInputs
                                          where !string.IsNullOrWhiteSpace(det.HuId)
                                          group det by det.HuId into gj
                                          select new
                                          {
                                              HuId = gj.Key,
                                              ReceiptDetailInputList = gj.ToList()
                                          };

                    if (groupedHuIdList != null && groupedHuIdList.Count() > 0)
                    {
                        //已知Bug,如果收货时不结算,两条不同的PlanBill生成条码会强制结算。但是在冲销时不会反结算。
                        #region 循环拆箱
                        foreach (var groupedHuId in groupedHuIdList.Where(g => g.ReceiptDetailInputList.Count() > 1))
                        {
                            InventoryUnPack inventoryUnPack = new InventoryUnPack();

                            inventoryUnPack.HuId = groupedHuId.HuId;
                            inventoryUnPack.CurrentHu = this.huMgr.GetHuStatus(groupedHuId.HuId);
                            IList<InventoryUnPack> inventoryUnPackList = new List<InventoryUnPack>();
                            inventoryUnPackList.Add(inventoryUnPack);
                            this.InventoryUnPack(inventoryUnPackList, effectiveDate);

                            foreach (ReceiptDetailInput receiptDetailInput in groupedHuId.ReceiptDetailInputList)
                            {
                                //把ReceiptDetailInput的HuId和LotNo至空,按数量出库。
                                receiptDetailInput.HuId = null;
                                receiptDetailInput.LotNo = null;
                                receiptDetailInput.IsConsignment = false;
                                receiptDetailInput.PlanBill = null;
                            }
                        }
                        #endregion

                        this.genericMgr.FlushSession();
                    }
                }
                #endregion

                foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                {
                    if (receiptDetailInput.ReceivedIpLocationDetailList != null && receiptDetailInput.ReceivedIpLocationDetailList.Count > 0)
                    {
                        List<InventoryTransaction> currentReceiptDetailInputInventoryTransactionList = new List<InventoryTransaction>();
                        #region 基于Ip收货,零件的寄售信息都在IpLocationDetail上面
                        foreach (IpLocationDetail receivedIpLocationDetail in receiptDetailInput.ReceivedIpLocationDetailList)
                        {
                            ReceiptDetailInput thisReceiptDetailInput = Mapper.Map<ReceiptDetailInput, ReceiptDetailInput>(receiptDetailInput);
                            thisReceiptDetailInput.ReceiveQty = (decimal)receivedIpLocationDetail.ReceivedQty / receiptDetail.UnitQty;
                            if (receiptDetail.CurrentIsReceiveScanHu && !string.IsNullOrWhiteSpace(receivedIpLocationDetail.HuId))
                            {
                                thisReceiptDetailInput.HuId = receivedIpLocationDetail.HuId;
                                thisReceiptDetailInput.LotNo = receivedIpLocationDetail.LotNo;
                            }

                            InventoryIO inventoryIO = new InventoryIO();

                            inventoryIO.Location = receiptDetail.LocationTo;
                            inventoryIO.Item = receiptDetail.Item;
                            if (receiptDetail.CurrentIsReceiveScanHu && receiptDetailInput.ReceivedIpLocationDetailList.Count == 1)
                            {
                                //如果收货扫描条码,并且只有一条发货库存明细,可以直接收为条码
                                //要用收货Input上指定的条码
                                inventoryIO.HuId = thisReceiptDetailInput.HuId;
                                inventoryIO.LotNo = thisReceiptDetailInput.LotNo;
                            }
                            inventoryIO.Qty = receivedIpLocationDetail.ReceivedQty;             //库存单位
                            inventoryIO.QualityType = receivedIpLocationDetail.QualityType;     //不合格品的ATP状态一定是false,合格品的状态一定是true,质检不采用ASN发货这里不可能出现
                            inventoryIO.IsATP = receivedIpLocationDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                            inventoryIO.IsFreeze = false;                       //可能指定移库冻结的零件?
                            inventoryIO.IsCreatePlanBill = receivedIpLocationDetail.IsCreatePlanBill;
                            inventoryIO.IsConsignment = receivedIpLocationDetail.IsConsignment;
                            inventoryIO.PlanBill = receivedIpLocationDetail.PlanBill;
                            inventoryIO.ActingBill = receivedIpLocationDetail.ActingBill;
                            inventoryIO.TransactionType = transType.Value;
                            //if (receivedIpLocationDetail.OccupyType == CodeMaster.OccupyType.Inspect)   //只有检验的收货要保留占用,其它收货不用保留
                            //{
                            inventoryIO.OccupyType = receivedIpLocationDetail.OccupyType;
                            inventoryIO.OccupyReferenceNo = receivedIpLocationDetail.OccupyReferenceNo;
                            //}
                            //inventoryIO.IsVoid = receiptDetail.IsVoid;
                            inventoryIO.EffectiveDate = effectiveDate;

                            #region 寄售处理
                            if (!receiptDetail.IsVoid &&
                                (((receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                                || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine)
                                && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                               || (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution
                                    && transType != CodeMaster.TransactionType.RCT_TR)  //差异调整至发货方,不用产生结算
                               || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract))
                            {
                                if (receivedIpLocationDetail.IsConsignment && receivedIpLocationDetail.PlanBill.HasValue)
                                {
                                    throw new TechnicalException("Can't create new planbill when receiptDetailInput aready has unsettled planbill.");
                                }
                                else
                                {
                                    #region 记录待结算
                                    PlanBill planBill = this.billMgr.CreatePlanBill(receiptDetail, thisReceiptDetailInput, effectiveDate);

                                    inventoryIO.IsConsignment = true;
                                    inventoryIO.IsCreatePlanBill = true;
                                    inventoryIO.PlanBill = planBill.Id;
                                    inventoryIO.CurrentPlanBill = planBill;

                                    thisReceiptDetailInput.IsConsignment = true;
                                    thisReceiptDetailInput.IsCreatePlanBill = true;
                                    thisReceiptDetailInput.PlanBill = planBill.Id;
                                    #endregion
                                }
                            }
                            #endregion

                            IList<InventoryTransaction> currentInventoryTransactionList = RecordInventory(inventoryIO);
                            #region 记录HuId,LotNo和WMS发货单行号
                            foreach (InventoryTransaction currentInventoryTransaction in currentInventoryTransactionList)
                            {
                                if (receiptDetail.CurrentIsReceiveScanHu && receiptDetailInput.ReceivedIpLocationDetailList.Count > 1
                                    && !string.IsNullOrWhiteSpace(receiptDetailInput.HuId))
                                {
                                    Hu hu = this.genericMgr.FindById<Hu>(receiptDetailInput.HuId);
                                    currentInventoryTransaction.HuId = hu.HuId;
                                    currentInventoryTransaction.LotNo = hu.LotNo;
                                }
                                currentInventoryTransaction.WMSRecSeq = receiptDetailInput.WMSRecSeq;
                            }
                            #endregion

                            RecordLocationTransaction(receiptDetail, thisReceiptDetailInput, effectiveDate, transType.Value, currentInventoryTransactionList);
                            inventoryTransactionList.AddRange(currentInventoryTransactionList);
                            currentReceiptDetailInputInventoryTransactionList.AddRange(currentInventoryTransactionList);
                        }

                        #region 收货扫描条码,需要装箱创建条码
                        if (receiptDetail.CurrentIsReceiveScanHu && receiptDetailInput.ReceivedIpLocationDetailList.Count > 1
                            && !string.IsNullOrWhiteSpace(receiptDetailInput.HuId))
                        {
                            #region 装箱
                            IList<InventoryPack> inventoryPackList = new List<InventoryPack>();
                            InventoryPack inventoryPack = new InventoryPack();
                            inventoryPack.Location = receiptDetail.LocationTo;
                            inventoryPack.HuId = receiptDetailInput.HuId;
                            inventoryPack.LocationLotDetailIdList = currentReceiptDetailInputInventoryTransactionList.Select(inv => inv.LocationLotDetailId).ToList();

                            inventoryPackList.Add(inventoryPack);
                            this.InventoryPack(inventoryPackList, effectiveDate);
                            #endregion
                        }
                        #endregion
                        #endregion
                    }
                    else
                    {
                        #region 基于ReceiptDetailInput收货
                        InventoryIO inventoryIO = new InventoryIO();

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

                        #region 寄售处理
                        if (!receiptDetail.IsVoid &&
                            (((receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                            || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine)
                            && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                           || (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution
                                && transType != CodeMaster.TransactionType.RCT_TR)  //差异调整至发货方,不用产生结算
                           || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract))
                        {
                            if (receiptDetailInput.IsConsignment && receiptDetailInput.PlanBill.HasValue)
                            {
                                throw new TechnicalException("Can't create new planbill when receiptDetailInput aready has unsettled planbill.");
                            }

                            #region 记录待结算
                            PlanBill planBill = this.billMgr.CreatePlanBill(receiptDetail, receiptDetailInput, effectiveDate);

                            inventoryIO.IsConsignment = true;
                            inventoryIO.IsCreatePlanBill = true;
                            inventoryIO.PlanBill = planBill.Id;
                            inventoryIO.CurrentPlanBill = planBill;

                            receiptDetailInput.IsConsignment = true;
                            receiptDetailInput.IsCreatePlanBill = true;
                            receiptDetailInput.PlanBill = planBill.Id;
                            #endregion

                            #region 判断是否立即结算
                            //if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract)   //委外加工立即结算
                            //{
                            //    isBillSettle = true;
                            //}
                            //else if (receiptDetail.ReceivedQty < 0)  // 判断寄售负库存是否立即结算
                            //{
                            //    isBillSettle = true;
                            //}
                            //else if (string.IsNullOrWhiteSpace(receiptDetail.LocationTo) == null
                            //    && receiptDetail.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.ReceivingSettlement) //判断目的库位为空的立即结算,如销售收货结算
                            //{
                            //    isBillSettle = true;
                            //}

                            //if (isBillSettle)
                            //{
                            //    //结算
                            //    planBill.CurrentActingQty = planBill.PlanQty;
                            //    BillTransaction billTransaction = this.billMgr.SettleBill(planBill, effectiveDate);
                            //    inventoryIO.IsConsignment = false;
                            //    receiptDetailInput.IsConsignment = false;
                            //}
                            #endregion
                        }
                        #endregion

                        IList<InventoryTransaction> currentInventoryTransactionList = RecordInventory(inventoryIO);
                        #region 记录WMS发货单行号
                        foreach (InventoryTransaction currentInventoryTransaction in currentInventoryTransactionList)
                        {
                            currentInventoryTransaction.WMSRecSeq = receiptDetailInput.WMSRecSeq;
                        }
                        #endregion
                        RecordLocationTransaction(receiptDetail, receiptDetailInput, effectiveDate, transType.Value, currentInventoryTransactionList);
                        inventoryTransactionList.AddRange(currentInventoryTransactionList);
                        #endregion
                    }
                }

                return inventoryTransactionList;
            }
            else if ((receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                    || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine
                    || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract)
                  && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
            {
                #region 采购退货收货
                if (!receiptDetail.IsVoid)
                {
                    foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                    {
                        foreach (IpLocationDetail receivedIpLocationDetail in receiptDetailInput.ReceivedIpLocationDetailList)
                        {
                            InventoryTransaction inventoryTransaction = new InventoryTransaction();
                            inventoryTransaction.Item = receiptDetail.Item;
                            inventoryTransaction.HuId = receiptDetailInput.HuId;
                            inventoryTransaction.LotNo = receiptDetailInput.LotNo;
                            inventoryTransaction.IsConsignment = receivedIpLocationDetail.IsConsignment;
                            //inventoryTransaction.IsCreatePlanBill = receiptDetailInput.IsCreatePlanBill;
                            inventoryTransaction.PlanBill = receivedIpLocationDetail.PlanBill;
                            if (receivedIpLocationDetail.IsConsignment && receivedIpLocationDetail.PlanBill.HasValue)
                            {
                                inventoryTransaction.PlanBillQty = receivedIpLocationDetail.ReceivedQty;  //转换为库存单位
                            }
                            //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                            //inventoryTransaction.ActingBillQty = ;
                            inventoryTransaction.Qty = receivedIpLocationDetail.ReceivedQty;  //转换为库存单位,入库位正数
                            inventoryTransaction.QualityType = receiptDetailInput.QualityType;
                            inventoryTransaction.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                            inventoryTransaction.IsFreeze = false;
                            inventoryTransaction.OccupyType = receiptDetailInput.OccupyType;
                            inventoryTransaction.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;

                            #region 退货收货
                            if (receivedIpLocationDetail.IsConsignment && receivedIpLocationDetail.PlanBill.HasValue)
                            {
                                //如果寄售库存,冲销PlanBill。
                                PlanBill planBill = this.genericMgr.FindById<PlanBill>(receivedIpLocationDetail.PlanBill.Value);
                                planBill.CurrentVoidQty = receivedIpLocationDetail.ReceivedQty / receiptDetail.UnitQty;  //订单单位
                                this.billMgr.VoidPlanBill(planBill);

                                //inventoryTransaction.IsConsignment = false;
                                //inventoryTransaction.PlanBill = null;
                            }
                            else
                            {
                                //非寄售库存产生负数PlanBill,立即结算。
                                ReceiptDetailInput thisReceiptDetailInput = Mapper.Map<ReceiptDetailInput, ReceiptDetailInput>(receiptDetailInput);
                                thisReceiptDetailInput.ReceiveQty = receivedIpLocationDetail.ReceivedQty / receiptDetail.UnitQty;   //订单单位

                                PlanBill planBill = this.billMgr.CreatePlanBill(receiptDetail, thisReceiptDetailInput, effectiveDate);
                                planBill.CurrentActingQty = planBill.PlanQty;
                                planBill.CurrentLocation = inventoryTransaction.Location;
                                SettleBillTransaction billTransaction = this.billMgr.SettleBill(planBill, effectiveDate);

                                inventoryTransaction.IsConsignment = false;
                                inventoryTransaction.IsCreatePlanBill = true;
                                inventoryTransaction.PlanBill = planBill.Id;
                                inventoryTransaction.PlanBillQty = 0;
                                inventoryTransaction.ActingBill = billTransaction.ActingBill;
                                inventoryTransaction.ActingBillQty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;
                            }
                            #endregion

                            inventoryTransactionList.Add(inventoryTransaction);
                        }
                    }
                }
                #endregion

                #region 采购退货收货冲销
                else
                {
                    #region 采购退货收货冲销
                    foreach (ReceiptLocationDetail receiptLocationDetail in receiptDetail.ReceiptLocationDetails)
                    {
                        InventoryTransaction inventoryTransaction = new InventoryTransaction();
                        inventoryTransaction.Item = receiptDetail.Item;
                        inventoryTransaction.HuId = receiptLocationDetail.HuId;
                        inventoryTransaction.LotNo = receiptLocationDetail.LotNo;
                        inventoryTransaction.IsConsignment = receiptLocationDetail.IsConsignment;
                        //inventoryTransaction.IsCreatePlanBill = receiptDetailInput.IsCreatePlanBill;
                        inventoryTransaction.PlanBill = receiptLocationDetail.PlanBill;
                        if (receiptLocationDetail.IsConsignment && receiptLocationDetail.PlanBill.HasValue)
                        {
                            inventoryTransaction.PlanBillQty = receiptLocationDetail.Qty;  //转换为库存单位
                        }
                        //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                        //inventoryTransaction.ActingBillQty = ;
                        inventoryTransaction.Qty = receiptLocationDetail.Qty;  //转换为库存单位,入库位正数
                        inventoryTransaction.QualityType = receiptLocationDetail.QualityType;
                        inventoryTransaction.IsATP = receiptLocationDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                        inventoryTransaction.IsFreeze = false;
                        inventoryTransaction.OccupyType = receiptLocationDetail.OccupyType;
                        inventoryTransaction.OccupyReferenceNo = receiptLocationDetail.OccupyReferenceNo;

                        if (receiptLocationDetail.IsConsignment && receiptLocationDetail.PlanBill.HasValue)
                        {
                            PlanBill planBill = this.genericMgr.FindById<PlanBill>(receiptLocationDetail.PlanBill);
                            planBill.CurrentVoidQty = -receiptLocationDetail.Qty / receiptDetail.UnitQty;  //退货收货冲销,要反冲销PlanQty。转为订单单位
                            this.billMgr.VoidPlanBill(planBill);
                        }

                        if (receiptLocationDetail.ActingBill.HasValue)
                        {
                            ActingBill actingBill = this.genericMgr.FindById<ActingBill>(receiptLocationDetail.ActingBill);
                            PlanBill planBill = this.genericMgr.FindById<PlanBill>(receiptLocationDetail.PlanBill);
                            actingBill.CurrentVoidQty = -receiptLocationDetail.Qty / receiptDetail.UnitQty;   //转为订单单位
                            this.billMgr.VoidSettleBill(actingBill, planBill, receiptLocationDetail.IsCreatePlanBill);
                        }

                        inventoryTransactionList.Add(inventoryTransaction);
                    }
                    #endregion
                }
                #endregion

                return inventoryTransactionList;
            }
            else if ((receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                        || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine
                        || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract)
                    && receiptDetail.IpDetailType == CodeMaster.IpDetailType.Gap
                    && receiptDetail.IpGapAdjustOption == CodeMaster.IpGapAdjustOption.GI)
            {
                #region 差异收货调整至供应商
                foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                {
                    InventoryTransaction inventoryTransaction = new InventoryTransaction();
                    inventoryTransaction.Item = receiptDetail.Item;
                    inventoryTransaction.HuId = receiptDetailInput.HuId;
                    inventoryTransaction.LotNo = receiptDetailInput.LotNo;
                    inventoryTransaction.IsConsignment = false;
                    inventoryTransaction.IsCreatePlanBill = false;
                    //inventoryTransaction.PlanBill = receiptDetailInput.PlanBill;
                    //inventoryTransaction.PlanBillQty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位
                    //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                    //inventoryTransaction.ActingBillQty = ;
                    inventoryTransaction.Qty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位,入库位正数
                    inventoryTransaction.QualityType = receiptDetailInput.QualityType;
                    inventoryTransaction.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryTransaction.IsFreeze = false;
                    //inventoryTransaction.OccupyType = receiptDetailInput.OccupyType;
                    //inventoryTransaction.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;

                    inventoryTransactionList.Add(inventoryTransaction);
                }
                #endregion
            }
            else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Production
                && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
            {
                #region 原材料回用
                foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                {
                    InventoryTransaction inventoryTransaction = new InventoryTransaction();
                    inventoryTransaction.Item = receiptDetail.Item;
                    inventoryTransaction.HuId = receiptDetailInput.HuId;
                    inventoryTransaction.LotNo = receiptDetailInput.LotNo;
                    inventoryTransaction.IsConsignment = false;
                    inventoryTransaction.IsCreatePlanBill = false;
                    //inventoryTransaction.PlanBill = receiptDetailInput.PlanBill;
                    //inventoryTransaction.PlanBillQty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位
                    //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                    //inventoryTransaction.ActingBillQty = ;
                    inventoryTransaction.Qty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位,入库位正数
                    inventoryTransaction.QualityType = receiptDetailInput.QualityType;
                    inventoryTransaction.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryTransaction.IsFreeze = false;
                    //inventoryTransaction.OccupyType = receiptDetailInput.OccupyType;
                    //inventoryTransaction.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;

                    inventoryTransactionList.Add(inventoryTransaction);
                }
                #endregion
            }
            else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution
                  && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
            {
                #region 销售收货
                foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                {
                    InventoryTransaction inventoryTransaction = new InventoryTransaction();
                    inventoryTransaction.Item = receiptDetail.Item;
                    inventoryTransaction.HuId = receiptDetailInput.HuId;
                    inventoryTransaction.LotNo = receiptDetailInput.LotNo;
                    //inventoryTransaction.IsConsignment = receiptDetailInput.IsConsignment;
                    //inventoryTransaction.IsCreatePlanBill = receiptDetailInput.IsCreatePlanBill;
                    //inventoryTransaction.PlanBill = receiptDetailInput.PlanBill;
                    //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                    inventoryTransaction.Qty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位,入库位正数
                    inventoryTransaction.QualityType = receiptDetailInput.QualityType;
                    inventoryTransaction.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryTransaction.IsFreeze = false;
                    inventoryTransaction.OccupyType = receiptDetailInput.OccupyType;
                    inventoryTransaction.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;

                    if (!receiptDetail.IsVoid)
                    {
                        #region 收货
                        PlanBill planBill = this.billMgr.CreatePlanBill(receiptDetail, receiptDetailInput, effectiveDate);
                        inventoryTransaction.IsConsignment = true;
                        inventoryTransaction.IsCreatePlanBill = true;
                        inventoryTransaction.PlanBill = planBill.Id;

                        if (receiptDetail.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.ReceivingSettlement)
                        {
                            planBill.CurrentActingQty = planBill.PlanQty;
                            planBill.CurrentLocation = planBill.LocationFrom;
                            SettleBillTransaction billTransaction = this.billMgr.SettleBill(planBill, effectiveDate);

                            inventoryTransaction.IsConsignment = false;
                            inventoryTransaction.PlanBillQty = 0;
                            inventoryTransaction.ActingBill = billTransaction.ActingBill;
                            inventoryTransaction.ActingBillQty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;
                        }
                        #endregion
                    }
                    else
                    {
                        #region 收货冲销
                        if (receiptDetailInput.ActingBill.HasValue)
                        {
                            ActingBill actingBill = this.genericMgr.FindById<ActingBill>(receiptDetailInput.ActingBill);
                            PlanBill planBill = this.genericMgr.FindById<PlanBill>(receiptDetailInput.PlanBill);
                            actingBill.CurrentVoidQty = -receiptDetailInput.ReceiveQty;
                            this.billMgr.VoidSettleBill(actingBill, planBill, receiptDetailInput.IsCreatePlanBill);
                        }
                        else if (receiptDetailInput.IsCreatePlanBill)
                        {
                            PlanBill planBill = this.genericMgr.FindById<PlanBill>(receiptDetailInput.PlanBill);
                            planBill.CurrentVoidQty = -receiptDetailInput.ReceiveQty;
                            this.billMgr.VoidPlanBill(planBill);
                        }
                        #endregion
                    }

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

            return inventoryTransactionList;
        }
コード例 #2
0
        private void RecordLocationTransaction(InventoryUnPack inventoryUnPack, DateTime effectiveDate, IList<InventoryTransaction> inventoryTransactionList, bool isIssue)
        {
            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 => isIssue ? -trans.Qty : trans.Qty),
                                                          Qty = result.Sum(trans => trans.Qty),
                                                          //PlanBillQty = result.Sum(trans => isIssue ? -trans.PlanBillQty : trans.PlanBillQty),
                                                          PlanBillQty = result.Sum(trans => trans.PlanBillQty),
                                                          //ActingBillQty = result.Sum(trans => isIssue ? -trans.ActingBillQty : trans.ActingBillQty),
                                                          ActingBillQty = result.Sum(trans => trans.ActingBillQty),
                                                          InventoryTransactionList = result.ToList()
                                                      };

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

                //locationTransaction.OrderNo = ;
                //locationTransaction.OrderType = ;
                //locationTransaction.OrderSubType = ;
                //locationTransaction.OrderDetailSequence = ;
                //locationTransaction.OrderDetailId = ;
                //locationTransaction.OrderBomDetId = 
                //locationTransaction.IpNo = 
                //locationTransaction.IpDetailId = 
                //locationTransaction.IpDetailSequence = 
                //locationTransaction.ReceiptNo = 
                //locationTransaction.ReceiptDetailId = 
                //locationTransaction.ReceiptDetailSequence = 
                //locationTransaction.SequenceNo = 
                //locationTransaction.TraceCode = ;
                locationTransaction.Item = inventoryUnPack.CurrentHu.Item;
                locationTransaction.Uom = inventoryUnPack.CurrentHu.Uom;
                locationTransaction.BaseUom = inventoryUnPack.CurrentHu.BaseUom;
                locationTransaction.Qty = groupedInventoryTransaction.Qty / inventoryUnPack.CurrentHu.UnitQty;
                locationTransaction.UnitQty = inventoryUnPack.CurrentHu.UnitQty;
                locationTransaction.IsConsignment = groupedInventoryTransaction.IsConsignment;
                if (groupedInventoryTransaction.IsConsignment && groupedInventoryTransaction.PlanBill.HasValue)
                {
                    locationTransaction.PlanBill = groupedInventoryTransaction.PlanBill.Value;
                }
                locationTransaction.PlanBillQty = groupedInventoryTransaction.PlanBillQty / inventoryUnPack.CurrentHu.UnitQty;
                if (groupedInventoryTransaction.ActingBill.HasValue)
                {
                    locationTransaction.ActingBill = groupedInventoryTransaction.ActingBill.Value;
                }
                locationTransaction.ActingBillQty = groupedInventoryTransaction.ActingBillQty / inventoryUnPack.CurrentHu.UnitQty;
                locationTransaction.QualityType = inventoryUnPack.CurrentHu.QualityType;
                locationTransaction.HuId = isIssue ? inventoryUnPack.CurrentHu.HuId : null;
                locationTransaction.LotNo = isIssue ? inventoryUnPack.CurrentHu.LotNo : null;
                locationTransaction.TransactionType = isIssue ? CodeMaster.TransactionType.ISS_REP : CodeMaster.TransactionType.RCT_REP;
                locationTransaction.IOType = isIssue ? CodeMaster.TransactionIOType.Out : CodeMaster.TransactionIOType.In;
                locationTransaction.PartyFrom = inventoryUnPack.CurrentHu.Region;
                locationTransaction.PartyTo = inventoryUnPack.CurrentHu.Region;
                locationTransaction.LocationFrom = inventoryUnPack.CurrentHu.Location;
                locationTransaction.LocationTo = inventoryUnPack.CurrentHu.Location;
                locationTransaction.LocationIOReason = string.Empty;
                locationTransaction.EffectiveDate = effectiveDate;
                locationTransaction.CreateUserId = SecurityContextHolder.Get().Id;
                locationTransaction.CreateDate = dateTimeNow;

                this.genericMgr.Create(locationTransaction);
                RecordLocationTransactionDetail(locationTransaction, groupedInventoryTransaction.InventoryTransactionList);
            }
        }