예제 #1
0
        public string GenerateNumber(string code)
        {
            string numberSuffix = GetNextSequence(code);

            EntityPreference entityPreference = entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_ORDER_LENGTH);
            int orderLength = int.Parse(entityPreference.Value);

            numberSuffix = numberSuffix.PadLeft(orderLength - code.Length, '0');


            return(code + numberSuffix);
        }
예제 #2
0
        private string PrintHu(IList <Hu> huList, string userCode)
        {
            IList <object> list = new List <object>();

            list.Add(huList);
            list.Add(userCode);

            string huTemplate = entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_DEFAULT_HU_TEMPLATE).Value;

            string printUrl = reportMgr.WriteToFile(huTemplate, list);

            return(printUrl);
        }
예제 #3
0
        public string TranslateMessage(string content, User user, params string[] parameters)
        {
            try
            {
                content = ProcessMessage(content, parameters);

                if (user != null && user.UserLanguage != null && user.UserLanguage != string.Empty)
                {
                    content = this.ProcessLanguage(content, user.UserLanguage);
                }
                else
                {
                    EntityPreference defaultLanguage = entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_DEFAULT_LANGUAGE);
                    content = this.ProcessLanguage(content, defaultLanguage.Value);
                }
            }
            catch (Exception ex)
            {
                throw new TechnicalException("翻译时出现异常:" + ex.Message);
            }
            return(content);
        }
        public void CompleteTransportationOrder(TransportationOrder order, User user)
        {
            if (order.Status != BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS)
            {
                throw new BusinessErrorException("TransportationOrder.Error.StatusErrorWhenComplete", order.Status, order.OrderNo);
            }
            order.CompleteDate   = DateTime.Now;
            order.CompleteUser   = user;
            order.LastModifyDate = DateTime.Now;
            order.LastModifyUser = user;
            order.Status         = BusinessConstants.CODE_MASTER_STATUS_VALUE_COMPLETE;

            this.UpdateTransportationOrder(order);

            #region 完成时自动计价
            bool isAutoValuate = bool.Parse(entityPreferenceMgr.LoadEntityPreference(
                                                BusinessConstants.ENTITY_PREFERENCE_CODE_VALUATE_WHEN_COMPLETE).Value);
            if (isAutoValuate && !order.IsValuated)
            {
                ValuateTransportationOrder(order, user);
            }
            #endregion
        }
예제 #5
0
        public ActingBill CreateActingBill(PlannedBill plannedBill, LocationLotDetail locationLotDetail, User user)
        {
            PlannedBill oldPlannedBill = plannedBillMgr.LoadPlannedBill(plannedBill.Id);

            oldPlannedBill.CurrentActingQty = plannedBill.CurrentActingQty;

            //检验,已结算数+本次结算数不能大于总结算数量,可能有负数结算,所以要用绝对值比较
            if (!oldPlannedBill.ActingQty.HasValue)
            {
                oldPlannedBill.ActingQty = 0;
            }
            if (Math.Abs(oldPlannedBill.ActingQty.Value + oldPlannedBill.CurrentActingQty) > Math.Abs(oldPlannedBill.PlannedQty))
            {
                throw new BusinessErrorException("PlannedBill.Error.ActingQtyExceed");
            }

            DateTime dateTimeNow = DateTime.Now;

            ActingBill actingBill = this.RetriveActingBill(oldPlannedBill, dateTimeNow, user);

            #region 计算结算金额
            decimal currentBillAmount = 0;
            if (Math.Abs(oldPlannedBill.ActingQty.Value + oldPlannedBill.CurrentActingQty) < Math.Abs(oldPlannedBill.PlannedQty))
            {
                //总结算数小于计划数,用实际单价计算待开票金额

                #region 计算实际单价
                EntityPreference entityPreference = entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_AMOUNT_DECIMAL_LENGTH);
                int     decimalLength             = int.Parse(entityPreference.Value);
                decimal actualUnitPrice           = Math.Round((oldPlannedBill.PlannedAmount / oldPlannedBill.PlannedQty), decimalLength, MidpointRounding.AwayFromZero);
                #endregion

                currentBillAmount = actualUnitPrice * oldPlannedBill.CurrentActingQty;
            }
            else
            {
                //总结算数等于计划数,先用剩余金额作为待开票金额
                if (!oldPlannedBill.ActingAmount.HasValue)
                {
                    oldPlannedBill.ActingAmount = 0;
                }
                currentBillAmount = oldPlannedBill.PlannedAmount - oldPlannedBill.ActingAmount.Value;
            }
            actingBill.BillAmount += currentBillAmount;
            #endregion

            #region 更新Planed Bill的已结算数量和金额
            if (!oldPlannedBill.ActingQty.HasValue)
            {
                oldPlannedBill.ActingQty = 0;
            }
            oldPlannedBill.ActingQty += oldPlannedBill.CurrentActingQty;

            if (!oldPlannedBill.ActingAmount.HasValue)
            {
                oldPlannedBill.ActingAmount = 0;
            }
            oldPlannedBill.ActingAmount  += currentBillAmount;
            oldPlannedBill.LastModifyDate = dateTimeNow;
            oldPlannedBill.LastModifyUser = user;

            this.plannedBillMgr.UpdatePlannedBill(oldPlannedBill);
            #endregion

            if (actingBill.Id == 0)
            {
                actingBillMgr.CreateActingBill(actingBill);
            }
            else
            {
                actingBillMgr.UpdateActingBill(actingBill);
            }

            #region 记BillTransaction
            billTransactionMgr.RecordBillTransaction(plannedBill, actingBill, locationLotDetail, user);
            #endregion

            return(actingBill);
        }
예제 #6
0
        private Repack CreateRepack(IList <RepackDetail> repackDetailList, string type, User user)
        {
            IList <RepackDetail> inRepackDetailList  = new List <RepackDetail>();
            IList <RepackDetail> outRepackDetailList = new List <RepackDetail>();
            bool hasHu = false;

            #region 判断RepackDetailList是否为空
            if (repackDetailList != null && repackDetailList.Count > 0)
            {
                foreach (RepackDetail repackDetail in repackDetailList)
                {
                    if (repackDetail.Qty != 0)
                    {
                        if (repackDetail.IOType == BusinessConstants.IO_TYPE_IN)
                        {
                            inRepackDetailList.Add(repackDetail);
                        }
                        else if (repackDetail.IOType == BusinessConstants.IO_TYPE_OUT)
                        {
                            outRepackDetailList.Add(repackDetail);
                            if (!hasHu && repackDetail.Hu != null)
                            {
                                hasHu = true;
                            }
                        }
                        else
                        {
                            throw new TechnicalException("Invalid IO Type:" + repackDetail.IOType);
                        }
                    }
                }

                #region 翻箱的如果没有输出,将输入代码合并,生成一张新条码
                if (outRepackDetailList.Count == 0 && type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_REPACK)
                {
                    Hu inHu  = inRepackDetailList[0].Hu;
                    Hu outHu = new Hu();
                    CloneHelper.CopyProperty(inHu, outHu);
                    outHu.OrderNo    = null;
                    outHu.ReceiptNo  = null;
                    outHu.Location   = null;
                    outHu.StorageBin = null;
                    outHu.Status     = BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE;

                    string repackShift = entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_REPACK_SHIFT).Value;

                    string prefix = inHu.HuId.Substring(0, inHu.HuId.Length - 4) + repackShift;
                    outHu.HuId       = numberControlMgr.GenerateNumber(prefix, 3);
                    outHu.Qty        = (from l in inRepackDetailList select l.Qty).Sum();
                    outHu.UnitCount  = outHu.Qty;
                    outHu.LotSize    = outHu.UnitCount;
                    outHu.PrintCount = 0;
                    huMgr.CreateHu(outHu);

                    RepackDetail outRepackDetail = new RepackDetail();
                    outRepackDetail.Hu       = outHu;
                    outRepackDetail.IOType   = BusinessConstants.IO_TYPE_OUT;
                    outRepackDetail.Qty      = outHu.Qty;
                    outRepackDetail.itemCode = outHu.Item.Code;
                    outRepackDetailList.Add(outRepackDetail);
                }
                #endregion

                if (inRepackDetailList.Count == 0 || outRepackDetailList.Count == 0)
                {
                    throw new BusinessErrorException("MasterData.Inventory.Repack.Error.RepackDetailEmpty");
                }
                if (hasHu && type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_DEVANNING && outRepackDetailList.Count < 2)
                {
                    throw new BusinessErrorException("MasterData.Inventory.Devanning.Error.DevanningDetailLessThanTwo");
                }
            }
            else
            {
                throw new BusinessErrorException("MasterData.Inventory.Repack.Error.RepackDetailEmpty");
            }
            #endregion

            #region 判断是否被拣货
            foreach (RepackDetail inRepackDetail in inRepackDetailList)
            {
                if (inRepackDetail.LocationLotDetail.Hu != null && this.locationMgr.IsHuOcuppyByPickList(inRepackDetail.LocationLotDetail.Hu.HuId))
                {
                    throw new BusinessErrorException("MasterData.Inventory.Repack.Error.HuOccupied", inRepackDetail.Hu.HuId);
                }
            }
            #endregion

            #region 判断翻箱后条码是否为新条码
            foreach (RepackDetail outRepackDetail in outRepackDetailList)
            {
                if (outRepackDetail.Hu != null && outRepackDetail.Hu.Status != BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE)
                {
                    throw new BusinessErrorException("MasterData.Inventory.Repack.Error.HuStatusNotCreate", outRepackDetail.Hu.HuId);
                }
            }
            #endregion

            #region 检查In和Out明细数量是否匹配
            IDictionary <string, decimal> inItemQtyDic = new Dictionary <string, decimal>();
            Location location = null;

            #region 收集In数量
            foreach (RepackDetail inRepackDetail in inRepackDetailList)
            {
                LocationLotDetail inLocationLotDetail = this.locationLotDetailMgr.LoadLocationLotDetail(inRepackDetail.LocationLotDetail.Id);

                if (location == null)
                {
                    location = inLocationLotDetail.Location;

                    if (!user.HasPermission(inLocationLotDetail.Location.Region.Code))
                    {
                        throw new BusinessErrorException("MasterData.Inventory.Repack.Error.NoPermission", location.Code);
                    }
                }
                else if (location.Code != inLocationLotDetail.Location.Code)
                {
                    throw new BusinessErrorException("MasterData.Inventory.Repack.Error.InRepackDetailLocationNotEqual");
                }

                if (inItemQtyDic.ContainsKey(inLocationLotDetail.Item.Code))
                {
                    inItemQtyDic[inLocationLotDetail.Item.Code] += inRepackDetail.Qty;
                }
                else
                {
                    inItemQtyDic.Add(inLocationLotDetail.Item.Code, inRepackDetail.Qty);
                }
            }
            #endregion

            #region 收集Out数量
            IDictionary <string, decimal> outItemQtyDic = new Dictionary <string, decimal>();

            foreach (RepackDetail outRepackDetail in outRepackDetailList)
            {
                if (type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_REPACK)
                {
                    if (outRepackDetail.Hu == null)
                    {
                        throw new BusinessErrorException("MasterData.Inventory.Repack.Error.HuIdIsEmpty");
                    }
                    else
                    {
                        if (outItemQtyDic.ContainsKey(outRepackDetail.Hu.Item.Code))
                        {
                            outItemQtyDic[outRepackDetail.Hu.Item.Code] += outRepackDetail.Qty;
                        }
                        else
                        {
                            outItemQtyDic.Add(outRepackDetail.Hu.Item.Code, outRepackDetail.Qty);
                        }
                    }
                }
                else if (type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_DEVANNING)
                {
                    string itemCode = outRepackDetail.Hu != null ? outRepackDetail.Hu.Item.Code : outRepackDetail.itemCode;

                    if (itemCode == null)
                    {
                        throw new TechnicalException("ItemCode not specified.");
                    }

                    if (outItemQtyDic.ContainsKey(itemCode))
                    {
                        outItemQtyDic[itemCode] += outRepackDetail.Qty;
                    }
                    else
                    {
                        outItemQtyDic.Add(itemCode, outRepackDetail.Qty);
                    }
                }
                else
                {
                    throw new TechnicalException("Repack type: " + type + " is not valided.");
                }
            }
            #endregion

            #region 比较
            if (inItemQtyDic.Count != outItemQtyDic.Count)
            {
                throw new BusinessErrorException("MasterData.Inventory.Repack.Error.InOutQtyNotMatch");
            }

            foreach (string itemCode in inItemQtyDic.Keys)
            {
                if (outItemQtyDic.ContainsKey(itemCode))
                {
                    decimal inQty  = inItemQtyDic[itemCode];
                    decimal outQty = outItemQtyDic[itemCode];

                    //是否自动创建剩余数量的记录
                    bool autoCreate = bool.Parse(entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_AUTO_CREATE_WHEN_DEAVING).Value);

                    #region 拆箱根据剩余数量得到剩余数量的条码
                    if (autoCreate && type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_DEVANNING && inQty > outQty)
                    {
                        RepackDetail remainRepackDetail = CloneHelper.DeepClone(inRepackDetailList[0]);
                        remainRepackDetail.Qty    = inQty - outQty;
                        remainRepackDetail.IOType = BusinessConstants.IO_TYPE_OUT;
                        outRepackDetailList.Add(remainRepackDetail);
                    }
                    #endregion

                    else if (inQty != outQty)
                    {
                        throw new BusinessErrorException("MasterData.Inventory.Repack.Error.InOutQtyNotMatch");
                    }
                }
                else
                {
                    throw new BusinessErrorException("MasterData.Inventory.Repack.Error.InOutItemNotMatch", itemCode);
                }
            }
            #endregion
            #endregion

            #region 创建翻箱单头
            Repack repack = new Repack();
            repack.RepackNo   = this.numberControlMgr.GenerateNumber(BusinessConstants.CODE_PREFIX_REPACK);
            repack.CreateDate = DateTime.Now;
            repack.CreateUser = user;
            repack.Type       = type;

            this.CreateRepack(repack);
            #endregion

            #region 创建翻箱单明细
            Int32?plannedBillId = null;   //拆箱传递PlannedBill
            foreach (RepackDetail inRepackDetail in inRepackDetailList)
            {
                //出库
                inRepackDetail.Repack = repack;
                this.locationMgr.InventoryRepackIn(inRepackDetail, user);

                this.repackDetailMgr.CreateRepackDetail(inRepackDetail);

                if (repack.Type == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_DEVANNING)
                {
                    plannedBillId = inRepackDetail.LocationLotDetail.IsConsignment ? inRepackDetail.LocationLotDetail.PlannedBill : null;
                }
            }

            foreach (RepackDetail outRepackDetail in outRepackDetailList)
            {
                //入库
                outRepackDetail.Repack = repack;
                InventoryTransaction inventoryTransaction = this.locationMgr.InventoryRepackOut(outRepackDetail, location, plannedBillId, user);
                outRepackDetail.LocationLotDetail = this.locationLotDetailMgr.LoadLocationLotDetail(inventoryTransaction.LocationLotDetailId);

                this.repackDetailMgr.CreateRepackDetail(outRepackDetail);
            }
            #endregion

            return(repack);
        }
        public TransportationActBill CreateTransportationActBill(TransportationOrder order, User user)
        {
            TransportationActBill actBill = new TransportationActBill();

            if (order.Expense != null)
            {
                actBill.BillAmount            = order.Expense.Amount;
                actBill.UnitPrice             = order.Expense.Amount;
                actBill.BillQty               = 1;
                actBill.Currency              = order.Expense.Currency;
                actBill.IsIncludeTax          = order.Expense.IsIncludeTax;
                actBill.Currency.Code         = order.Expense.Currency.Code;
                actBill.IsProvisionalEstimate = false;
            }
            else
            {
                string currency = null;
                foreach (TransportationOrderDetail orderDetail in order.OrderDetails)
                {
                    #region currency
                    if (orderDetail.InProcessLocation.Flow.Currency == null)
                    {
                        throw new BusinessErrorException("Transportation.Flow.CurrencyEmpty", orderDetail.InProcessLocation.Flow.Code);
                    }
                    if (currency == null)
                    {
                        currency = orderDetail.InProcessLocation.Flow.Currency.Code;
                    }
                    else if (currency != orderDetail.InProcessLocation.Flow.Currency.Code)
                    {
                        throw new BusinessErrorException("Transportation.OrderDetail.CurrencyNotEqual");
                    }
                    #endregion
                }

                IList <TransportPriceList> transportPriceList = transportPriceListMgr.GetTransportPriceList(order.Carrier.Code);
                if (transportPriceList == null || transportPriceList.Count == 0)
                {
                    throw new BusinessErrorException("Transportation.PriceList.Empty", order.Carrier.Code);
                }
                if (transportPriceList.Count > 1)
                {
                    throw new BusinessErrorException("Transportation.PriceList.MoreThanOne", order.Carrier.Code);
                }

                TransportPriceListDetail priceListDetail = null;
                if (order.PricingMethod != BusinessConstants.TRANSPORTATION_PRICING_METHOD_LADDERSTERE)
                {
                    priceListDetail = this.transportPriceListDetailMgr.GetLastestTransportPriceListDetail(transportPriceList[0]
                                                                                                          , order.CreateDate, currencyMgr.LoadCurrency(currency), order.PricingMethod, order.TransportationRoute.ShipFrom, order.TransportationRoute.ShipTo, BusinessConstants.TRANSPORTATION_PRICELIST_DETAIL_TYPE_TRANSPORTATION, order.VehicleType, order.TransportMethod);
                }

                #region 包车
                if (order.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_SHIPT)
                {
                    actBill.BillQty = 1;
                    if (priceListDetail != null && actBill.UnitPrice == 0)
                    {
                        actBill.UnitPrice  = priceListDetail.UnitPrice;
                        actBill.BillAmount = actBill.UnitPrice * actBill.BillQty;
                    }
                }
                #endregion

                #region 体积和阶梯
                else if (order.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_M3 || order.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_LADDERSTERE)
                {
                    decimal totalVolume = 0;
                    foreach (TransportationOrderDetail orderDetail in order.OrderDetails)
                    {
                        foreach (InProcessLocationDetail ipDet in orderDetail.InProcessLocation.InProcessLocationDetails)
                        {
                            if (!ipDet.OrderLocationTransaction.OrderDetail.PackageVolumn.HasValue || ipDet.OrderLocationTransaction.OrderDetail.PackageVolumn.Value == 0)
                            {
                                throw new BusinessErrorException("Transportation.PackageVolumn.Empty", ipDet.InProcessLocation.IpNo, ipDet.OrderLocationTransaction.Item.Code);
                            }
                            else
                            {
                                if (ipDet.OrderLocationTransaction.OrderDetail.HuLotSize == null || ipDet.OrderLocationTransaction.OrderDetail.HuLotSize.Value == 0)
                                {
                                    throw new BusinessErrorException("Transportation.HuLotSize.Empty", ipDet.InProcessLocation.IpNo, ipDet.OrderLocationTransaction.Item.Code);
                                }
                                int box = Convert.ToInt32(Math.Ceiling(ipDet.Qty / (decimal)(ipDet.OrderLocationTransaction.OrderDetail.HuLotSize.Value)));
                                totalVolume += ipDet.OrderLocationTransaction.OrderDetail.PackageVolumn.Value * box;
                            }
                        }
                    }

                    #region 托盘数
                    if (order.PallentCount != 0)
                    {
                        decimal pallentVolume = decimal.Parse(entityPreferenceMgr.LoadEntityPreference(
                                                                  BusinessConstants.ENTITY_PREFERENCE_CODE_PALLENTVOLUME).Value);
                        totalVolume += pallentVolume * order.PallentCount;
                    }
                    #endregion

                    if (order.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_M3)
                    {
                        #region 最小起运量
                        if (totalVolume < priceListDetail.MinVolume)
                        {
                            totalVolume = priceListDetail.MinVolume;
                        }
                        #endregion

                        actBill.BillQty = totalVolume;
                        if (priceListDetail != null && actBill.UnitPrice == 0)
                        {
                            actBill.UnitPrice = priceListDetail.UnitPrice;
                        }
                        actBill.BillAmount = actBill.UnitPrice * actBill.BillQty;
                    }
                    #region 阶梯
                    else if (order.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_LADDERSTERE)
                    {
                        priceListDetail = this.transportPriceListDetailMgr.GetLastestLadderStereTransportPriceListDetail(transportPriceList[0], null, order.CreateDate, currencyMgr.LoadCurrency(currency), null, order.PricingMethod, order.TransportationRoute.ShipFrom, order.TransportationRoute.ShipTo, BusinessConstants.TRANSPORTATION_PRICELIST_DETAIL_TYPE_TRANSPORTATION, null, order.VehicleType, totalVolume);
                        if (priceListDetail == null)
                        {
                            throw new BusinessErrorException("Transportation.PriceListDetail.Empty", order.PricingMethod);
                        }

                        #region 最小起运量
                        if (totalVolume < priceListDetail.MinVolume)
                        {
                            totalVolume = priceListDetail.MinVolume;
                        }
                        #endregion
                        actBill.UnitPrice = priceListDetail.UnitPrice;
                        actBill.BillQty   = totalVolume;
                        decimal minPrice = priceListDetail.MinPrice.HasValue ? priceListDetail.MinPrice.Value : 0;
                        actBill.BillAmount = minPrice + actBill.UnitPrice * actBill.BillQty;
                    }
                    #endregion
                }
                #endregion

                #region 重量
                else if (order.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_KG)
                {
                }
                #endregion



                else
                {
                    throw new BusinessErrorException("Transportation.PricingMethod.Empty");
                }

                actBill.UnitPrice = priceListDetail.UnitPrice;
                // actBill.BillAmount = actBill.UnitPrice * actBill.BillQty;
                actBill.Currency              = priceListDetail.Currency;
                actBill.IsIncludeTax          = priceListDetail.IsIncludeTax;
                actBill.Currency              = priceListDetail.Currency;
                actBill.IsProvisionalEstimate = priceListDetail.IsProvisionalEstimate;
                actBill.PricingMethod         = order.PricingMethod;
                actBill.PriceList             = priceListDetail.TransportPriceList;
                actBill.PriceListDetail       = priceListDetail;
                actBill.VehicleType           = priceListDetail.VehicleType;
                if (order.TransportationRoute != null)
                {
                    actBill.ShipFrom = order.TransportationRoute.ShipFrom;
                    actBill.ShipTo   = order.TransportationRoute.ShipTo;
                }
            }

            actBill.OrderNo         = order.OrderNo;
            actBill.BillAddress     = order.CarrierBillAddress;
            actBill.EffectiveDate   = DateTime.Parse(order.CreateDate.ToString("yyyy-MM-dd"));
            actBill.Status          = BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE;
            actBill.TransType       = BusinessConstants.TRANSPORTATION_PRICELIST_DETAIL_TYPE_TRANSPORTATION;
            actBill.CreateDate      = DateTime.Now;
            actBill.CreateUser      = user;
            actBill.LastModifyDate  = DateTime.Now;
            actBill.LastModifyUser  = user;
            actBill.TransportMethod = order.TransportMethod;
            this.CreateTransportationActBill(actBill);
            return(actBill);
        }
예제 #8
0
        public IList <OrderDetail> ConvertResolverToOrderDetails(Resolver resolver, Flow flow)
        {
            OrderHead           orderHead    = orderMgr.TransferFlow2Order(flow);
            IList <OrderDetail> orderDetails = new List <OrderDetail>();

            if (resolver.Transformers == null)
            {
                throw new BusinessErrorException("OrderDetail.Error.OrderDetailEmpty");
            }
            foreach (Transformer transformer in resolver.Transformers)
            {
                if (transformer.TransformerDetails != null)
                {
                    foreach (TransformerDetail transformerDetail in transformer.TransformerDetails)
                    {
                        if (transformerDetail.CurrentQty == 0) //数量为零的过滤掉
                        {
                            continue;
                        }

                        OrderDetail newOrderDetail = new OrderDetail();
                        //newOrderDetail.IsScanHu = true;
                        int seqInterval = int.Parse(entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_SEQ_INTERVAL).Value);
                        if (orderDetails == null || orderDetails.Count == 0)
                        {
                            newOrderDetail.Sequence = seqInterval;
                        }
                        else
                        {
                            newOrderDetail.Sequence = orderDetails.Last <OrderDetail>().Sequence + seqInterval;
                        }
                        newOrderDetail.Item = itemMgr.LoadItem(transformerDetail.ItemCode);
                        newOrderDetail.Uom  = uomMgr.LoadUom(transformerDetail.UomCode);
                        newOrderDetail.HuId = transformerDetail.HuId;
                        if ((resolver.ModuleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_SHIPRETURN) ||
                            resolver.ModuleType == BusinessConstants.TRANSFORMER_MODULE_TYPE_RECEIVERETURN)
                        {
                            newOrderDetail.OrderedQty = -transformerDetail.CurrentQty;
                            newOrderDetail.HuQty      = -transformerDetail.Qty;
                        }
                        else
                        {
                            newOrderDetail.OrderedQty = transformerDetail.CurrentQty;
                            newOrderDetail.HuQty      = transformerDetail.Qty;
                        }
                        if (!(resolver.OrderType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT ||
                              resolver.OrderType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_CUSTOMERGOODS))
                        {
                            newOrderDetail.LocationFrom = locationMgr.LoadLocation(transformer.LocationFromCode);
                        }
                        if (!(resolver.OrderType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_DISTRIBUTION))
                        {
                            newOrderDetail.LocationTo = locationMgr.LoadLocation(transformer.LocationToCode);
                        }
                        newOrderDetail.ReferenceItemCode = transformer.ReferenceItemCode;
                        newOrderDetail.UnitCount         = transformerDetail.UnitCount;
                        //newOrderDetail.PackageType = transformerDetail.PackageType;
                        newOrderDetail.OrderHead      = orderHead;
                        newOrderDetail.IsScanHu       = true;
                        newOrderDetail.PutAwayBinCode = resolver.BinCode;
                        orderDetails.Add(newOrderDetail);
                    }
                }
            }
            return(orderDetails);
        }
예제 #9
0
        public IList <MaterialFlushBack> AssignMaterialFlushBack(MaterialFlushBack sourceMaterialFlushBack, IList <OrderLocationTransaction> inOrderLocationTransactionList)
        {
            Hu hu = null;

            if (sourceMaterialFlushBack.HuId != null && sourceMaterialFlushBack.HuId.Trim() != string.Empty)
            {
                hu = this.huMgr.CheckAndLoadHu(sourceMaterialFlushBack.HuId);
            }

            IList <MaterialFlushBack> materialFlushBackList = new List <MaterialFlushBack>();
            decimal theoryTotalQty = 0;  //理论消耗量

            if (inOrderLocationTransactionList != null && inOrderLocationTransactionList.Count > 0)
            {
                foreach (OrderLocationTransaction inOrderLocationTransaction in inOrderLocationTransactionList)
                {
                    IList <OrderLocationTransaction> orderLocationTransactionList = this.orderLocationTransactionMgr.GetOrderLocationTransaction(inOrderLocationTransaction.OrderDetail.Id, BusinessConstants.IO_TYPE_OUT);
                    if (orderLocationTransactionList != null && orderLocationTransactionList.Count > 0)
                    {
                        foreach (OrderLocationTransaction orderLocationTransaction in orderLocationTransactionList)
                        {
                            if (orderLocationTransaction.Item.Code == sourceMaterialFlushBack.RawMaterial.Code)
                            {
                                if (sourceMaterialFlushBack.Operation == 0 ||
                                    orderLocationTransaction.Operation == sourceMaterialFlushBack.Operation)
                                {
                                    if ((hu == null) ||                                                                                                                //按数量分配
                                        (hu != null && (hu.Version == null || hu.Version.Trim() == string.Empty)) || //按条码分配
                                        (hu != null && hu.Version != null && hu.Version.Trim() != string.Empty && hu.Version == orderLocationTransaction.ItemVersion)) //按条码和工程状态分配
                                    {
                                        MaterialFlushBack materialFlushBack = new MaterialFlushBack();
                                        materialFlushBack.OrderDetail = inOrderLocationTransaction.OrderDetail;
                                        materialFlushBack.OrderLocationTransaction = orderLocationTransaction;
                                        materialFlushBack.Operation   = orderLocationTransaction.Operation;
                                        materialFlushBack.RawMaterial = orderLocationTransaction.Item;
                                        materialFlushBack.Uom         = orderLocationTransaction.OrderDetail.Uom;
                                        materialFlushBack.HuId        = sourceMaterialFlushBack.HuId;
                                        if (inOrderLocationTransaction.OrderDetail.OrderHead.Type != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
                                        {
                                            materialFlushBack.Qty = inOrderLocationTransaction.CurrentReceiveQty * orderLocationTransaction.UnitQty;
                                        }
                                        else
                                        {
                                            //生产,废品和次品都消耗原材料
                                            materialFlushBack.Qty =
                                                (inOrderLocationTransaction.CurrentReceiveQty + inOrderLocationTransaction.CurrentRejectQty + inOrderLocationTransaction.CurrentScrapQty)
                                                * orderLocationTransaction.UnitQty;
                                        }
                                        theoryTotalQty += materialFlushBack.Qty;

                                        materialFlushBackList.Add(materialFlushBack);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            int FlushBackListCount = materialFlushBackList.Count;

            if (FlushBackListCount == 0)
            {
                throw new BusinessErrorException("Order.Error.ReceiveOrder.AssignMaterial", sourceMaterialFlushBack.RawMaterial.Code);
            }

            EntityPreference entityPreference = entityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_AMOUNT_DECIMAL_LENGTH);
            int decimalLength = int.Parse(entityPreference.Value);

            decimal remainFlushBack = sourceMaterialFlushBack.Qty;

            for (int i = 0; i < FlushBackListCount; i++)
            {
                //分配的消耗量等于实际的总消耗量 / 理论总消耗量 * 单个物料的消耗量,最后一条用减法处理
                if (i < FlushBackListCount - 1)
                {
                    materialFlushBackList[i].Qty = Math.Round(sourceMaterialFlushBack.Qty / theoryTotalQty * materialFlushBackList[i].Qty, decimalLength, MidpointRounding.AwayFromZero);;
                    remainFlushBack = remainFlushBack - materialFlushBackList[i].Qty;
                }
                else
                {
                    materialFlushBackList[i].Qty = remainFlushBack;
                }
            }
            //foreach(MaterialFlushBack materialFlushBack in materialFlushBackList)
            //{



            //    materialFlushBack.Qty = sourceMaterialFlushBack.Qty / theoryTotalQty * materialFlushBack.Qty;
            //}

            return(materialFlushBackList);
        }