Example #1
0
 public void EditSettledPod(SettledPod SettledPod, int SettledType, string Updator)
 {
     DbParam[] dbParams = new DbParam[] {
         new DbParam("@ID", DbType.Int64, SettledPod.ID, ParameterDirection.Input),
         new DbParam("@ShipAmt", DbType.Decimal, SettledPod.ShipAmt ?? 0, ParameterDirection.Input),
         new DbParam("@BAFAmt", DbType.Decimal, SettledPod.BAFAmt, ParameterDirection.Input),
         new DbParam("@PointAmt", DbType.Decimal, SettledPod.PointAmt, ParameterDirection.Input),
         new DbParam("@OtherAmt", DbType.Decimal, SettledPod.OtherAmt, ParameterDirection.Input),
         new DbParam("@TotalAmt", DbType.Decimal, SettledPod.TotalAmt, ParameterDirection.Input),
         new DbParam("@Remark", DbType.String, SettledPod.Remark, ParameterDirection.Input),
         new DbParam("@SettledType", DbType.Int32, SettledType, ParameterDirection.Input),
         new DbParam("@Updator", DbType.String, Updator, ParameterDirection.Input)
     };
     base.ExecuteNoQuery("Proc_EditSettledPod", dbParams);
 }
Example #2
0
        public string EditSettledPod(long id, decimal?shipAmt, decimal?bafAmt, decimal?pointAmt, decimal?otherAmt, string remark, int?settledType)
        {
            SettledPod settledPod = new SettledPod()
            {
                ID       = id,
                ShipAmt  = shipAmt,
                BAFAmt   = bafAmt,
                PointAmt = pointAmt,
                OtherAmt = otherAmt,
                TotalAmt = (shipAmt ?? 0) + (bafAmt ?? 0) + (pointAmt ?? 0) + (otherAmt ?? 0),
                Remark   = remark
            };
            var response = new SettledService().EditSettledPod(new EditSettledPodRequest()
            {
                SettledPod = settledPod, SettledType = settledType ?? 0, Updator = base.UserInfo.Name
            });

            if (response.IsSuccess)
            {
                return("运单结算修改成功");
            }

            return("运单结算修改失败");
        }
        public void SettledPodForPay(IEnumerable <long> PodIDs, string creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, System.Text.StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service             = new PodService();
            var        groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
            {
                IDs = PodIDs, SettledType = 1
            });

            if (!groupedPodsResponse.IsSuccess)
            {
                throw groupedPodsResponse.Exception;
            }

            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }

            var quotedPrice = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);

            string             settledNumber = Guid.NewGuid().ToString();
            IList <SettledPod> settledPods   = new List <SettledPod>();
            long relatedCustomerID           = 0;

            #region akzo
            if (podsResponse.Result.First().CustomerID == 7)
            {
                relatedCustomerID = 7;
                #region  天同城
                foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
                {
                    double weight = gPod.Weight;
                    if (weight < 300)
                    {
                        weight = 300;
                    }
                    var         innerPodIDs = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                    QuotedPrice price       = new QuotedPrice();
                    QuotedPrice tempPrice;
                    tempPrice = quotedPrice.FirstOrDefault(q =>
                                                           q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                           q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal <= weight && q.EndVal > weight &&
                                                           q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));
                    if (tempPrice == null)
                    {
                        this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统对应报价,请先配置报价.");
                        continue;
                    }
                    else
                    {
                        price.Price = tempPrice.Price;
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }
                    decimal shipAmt = price.Price * (decimal)weight;

                    foreach (var id in innerPodIDs)
                    {
                        var originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                        if (originalPod.Weight == null)
                        {
                            this.GenErrorMessage_ByGroupedPod(gPod, Message, "请先设置货物的重量");
                            continue;
                        }
                        SettledPod settledPod = new SettledPod()
                        {
                            ProjectID           = originalPod.ProjectID,
                            CustomerOrderNumber = originalPod.CustomerOrderNumber,
                            SystemNumber        = originalPod.SystemNumber,
                            PodID                 = id,
                            SettledNumber         = settledNumber,
                            SettledType           = 1,
                            CustomerOrShipperID   = originalPod.ShipperID.Value,
                            CustomerOrShipperName = originalPod.ShipperName,
                            StartCityID           = originalPod.StartCityID.Value,
                            StartCityName         = originalPod.StartCityName,
                            EndCityID             = originalPod.EndCityID.Value,
                            EndCityName           = originalPod.EndCityName,
                            ShipperTypeID         = originalPod.ShipperTypeID.Value,
                            ShipperTypeName       = originalPod.ShipperTypeName,
                            PODTypeID             = originalPod.PODTypeID.Value,
                            PODTypeName           = originalPod.PODTypeName,
                            TtlOrTplID            = originalPod.TtlOrTplID.Value,
                            TtlOrTplName          = originalPod.TtlOrTplName,
                            ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                            BoxNumber             = originalPod.BoxNumber,
                            Weight                = originalPod.Weight,
                            Volume                = originalPod.Volume,
                            GoodsNumber           = originalPod.GoodsNumber,
                            ShipAmt               = shipAmt * (decimal)(originalPod.Weight / gPod.Weight),
                            BAFAmt                = 0,
                            PointAmt              = 0,
                            OtherAmt              = 0,
                            Amt1              = 0,
                            Amt2              = 0,
                            Amt3              = 0,
                            Amt4              = 0,
                            Amt5              = 0,
                            Str1              = string.Empty,
                            Str2              = string.Empty,
                            Str3              = string.Empty,
                            Str4              = price.Price.ToString(),
                            Str5              = string.Empty,
                            Remark            = string.Empty,
                            DateTime1         = null,
                            DateTime2         = null,
                            CreateTime        = DateTime.Now,
                            Creator           = creator,
                            InvoiceID         = 0,
                            RelatedCustomerID = originalPod.CustomerID,
                            IsAudit           = true
                        };
                        settledPods.Add(settledPod);
                    }

                    #region 判断同天同城同客户的运费是否小于80
                    var groupedCustomerPodsResponse = service.SettledPodSearch(new SettledPodRequest()
                    {
                        IDs = innerPodIDs, SettledType = 1, IsID = 1
                    });
                    if (!groupedCustomerPodsResponse.IsSuccess)
                    {
                        throw groupedCustomerPodsResponse.Exception;
                    }
                    foreach (var gcPod in groupedCustomerPodsResponse.Result.GroupedPods)
                    {
                        var                innerCustomerPodIDs    = gcPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                        decimal            sumshipAmt             = 0;
                        IList <SettledPod> settledCustomerPodPods = new List <SettledPod>();
                        foreach (var id in innerCustomerPodIDs)
                        {
                            var originalCustomerPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                            foreach (var settledPod in settledPods)
                            {
                                if (originalCustomerPod.CustomerOrderNumber == settledPod.CustomerOrderNumber)
                                {
                                    sumshipAmt += (decimal)settledPod.ShipAmt;
                                    settledCustomerPodPods.Add(settledPod);
                                }
                            }
                        }
                        if (sumshipAmt < 80)
                        {
                            foreach (var settledCustomerPodPod in settledCustomerPodPods)
                            {
                                settledCustomerPodPod.OtherAmt += (80 - sumshipAmt) * (decimal)(settledCustomerPodPod.Weight / gcPod.Weight);
                            }
                        }
                    }
                    #endregion
                }
                #endregion
            }
            #endregion
            #region Nike
            if (podsResponse.Result.First().CustomerID == 8)
            {
                //起运城市是太仓CLC、太仓CRW、上海的按同城结算(大仓和工厂直发[上海])
                var podsResponses = podsResponse.Result.Where(s => s.PODTypeName == "大仓出货" || s.PODTypeName == "工厂直发").GroupBy(x => new { x.ActualDeliveryDate, x.EndCityName, })
                                    .Select(g => new
                {
                    Peo   = g.Key,
                    count = g.Count(),
                    pods  = g.Select(k => { return(k); })
                });
                foreach (var pods in podsResponses)
                {
                    double boxnumner = 0;
                    double cube      = 0;
                    foreach (var pod in pods.pods)
                    {
                        if (string.IsNullOrEmpty(pod.BoxNumber.ToString()))
                        {
                            this.GenErrorMessage_ByPod(pod, Message, " 请设置该运单的箱数");
                            continue;
                        }
                        boxnumner += (double)pod.BoxNumber;
                    }
                    cube = boxnumner / 11;
                    Settlement(settledNumber, ProjectID, Message, cube, boxnumner, pods.pods, settledPods, quotedPrice);
                }
                //到货城市是太仓CLC、太仓CRW、上海的按同城结算(退货运单)
                var podsReturnResponses = podsResponse.Result.Where(s => s.PODTypeName == "退货运单").GroupBy(x => new { x.ActualDeliveryDate, x.StartCityName, })
                                          .Select(g => new
                {
                    Peo   = g.Key,
                    count = g.Count(),
                    pods  = g.Select(k => { return(k); })
                });
                foreach (var pods in podsReturnResponses)
                {
                    double boxnumner = 0;
                    double cube      = 0;
                    foreach (var pod in pods.pods)
                    {
                        if (string.IsNullOrEmpty(pod.BoxNumber.ToString()))
                        {
                            this.GenErrorMessage_ByPod(pod, Message, " 请设置该运单的箱数");
                            continue;
                        }
                        boxnumner += (double)pod.BoxNumber;
                    }
                    cube = boxnumner / 11;
                    Settlement(settledNumber, ProjectID, Message, cube, boxnumner, pods.pods, settledPods, quotedPrice);
                }
                //门店调拨(按正常的同天同城结算,但报价是按箱并不与承运商做关联结算,)
                var podsTransfersResponses = podsResponse.Result.Where(s => s.PODTypeName == "门店调拨").GroupBy(x => new { x.ActualDeliveryDate, x.StartCityName, x.EndCityName })
                                             .Select(g => new
                {
                    Peo   = g.Key,
                    count = g.Count(),
                    pods  = g.Select(k => { return(k); })
                });
                foreach (var pods in podsTransfersResponses)
                {
                    double boxnumner = 0;
                    foreach (var pod in pods.pods)
                    {
                        if (string.IsNullOrEmpty(pod.BoxNumber.ToString()))
                        {
                            this.GenErrorMessage_ByPod(pod, Message, " 请设置该运单的箱数");
                            continue;
                        }
                        boxnumner += (double)pod.BoxNumber;
                    }

                    Settlement(settledNumber, ProjectID, Message, 0, boxnumner, pods.pods, settledPods, quotedPrice);
                }

                //只有大仓出货按照11箱/方*10计算支出补贴
                var prs = podsResponse.Result.Where(p => p.PODTypeName == "大仓出货");
                prs.Each((i, e) =>
                {
                    settledPods.Each((m, n) =>
                    {
                        if (n.PodID == e.ID)
                        {
                            n.OtherAmt = (decimal)(n.BoxNumber / 11) * 10;
                        }
                    });
                });
            }
            #endregion
            #region AdidasPurchase
            if (podsResponse.Result.First().CustomerID == 13)
            {
                var newpodsResponse = from q in podsResponse.Result
                                      //where q.StartCityName != "天津" && q.StartCityName != "苏州"
                                      group q by new { q.ActualDeliveryDate, q.EndCityName, q.ShipperID }
                into r
                    select new
                {
                    ActualDeliveryDate = r.Key.ActualDeliveryDate.DateTimeToString(),
                    EndCityName        = r.Key.EndCityName,
                    ShipperID          = r.Key.ShipperID,
                    Volume             = r.Sum(a => a.Volume),
                    BoxNumber          = r.Sum(a => a.BoxNumber)
                };


                relatedCustomerID = 13;
                foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
                {
                    double cube        = gPod.Volume;
                    var    innerPodIDs = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                    //gPod.StartCityName = "广东";
                    foreach (var item in newpodsResponse)
                    {
                        if (item.ActualDeliveryDate.ToString() == gPod.ActualDeliveryDate && item.EndCityName == gPod.EndCityName)
                        {
                            cube = Convert.ToDouble(item.Volume);
                        }
                    }
                    QuotedPrice price;
                    price = quotedPrice.FirstOrDefault(q =>
                                                       q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                       q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                       q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));
                    if (price == null)
                    {
                        this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统对应报价,请先配置报价.");
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }
                    decimal shipAmt  = price.Price;
                    decimal delivery = 0;
                    foreach (var id in innerPodIDs)
                    {
                        //提货费 同天同城收一票
                        //if (cube < 40)
                        //{
                        //    var a = innerPodIDs.First();
                        //    if (innerPodIDs.First().ToString() == id.ToString())
                        //    {
                        //        switch (gPod.EndCityName)
                        //        {
                        //            case "广州":
                        //                delivery = 15;
                        //                break;
                        //            case "清远":
                        //                delivery = 25;
                        //                break;
                        //            case "云浮":
                        //                delivery = 25;
                        //                break;
                        //            case "东莞":
                        //                delivery = 25;
                        //                break;
                        //            case "中山":
                        //                delivery = 25;
                        //                break;
                        //            case "佛山":
                        //                delivery = 25;
                        //                break;
                        //            case "惠州":
                        //                delivery = 25;
                        //                break;
                        //            case "河源":
                        //                delivery = 25;
                        //                break;
                        //            default:
                        //                delivery = 0;
                        //                break;
                        //        }
                        //    }
                        //}
                        var originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                        //卸货费
                        //decimal unload = 0;
                        //if (gPod.EndCityName == "苏州")
                        //{
                        //    unload = (decimal)4.2;
                        //}
                        //else if (gPod.EndCityName == "广州")
                        //{
                        //    unload = cube< 150 ? (decimal)5.5 : (decimal)5;
                        //}
                        SettledPod settledPod = new SettledPod()
                        {
                            ProjectID           = originalPod.ProjectID,
                            CustomerOrderNumber = originalPod.CustomerOrderNumber,
                            SystemNumber        = originalPod.SystemNumber,
                            PodID                 = id,
                            SettledNumber         = settledNumber,
                            SettledType           = 1,
                            CustomerOrShipperID   = originalPod.ShipperID.Value,
                            CustomerOrShipperName = originalPod.ShipperName,
                            StartCityID           = originalPod.StartCityID.Value,
                            StartCityName         = originalPod.StartCityName,
                            EndCityID             = originalPod.EndCityID.Value,
                            EndCityName           = originalPod.EndCityName,
                            ShipperTypeID         = originalPod.ShipperTypeID.Value,
                            ShipperTypeName       = originalPod.ShipperTypeName,
                            PODTypeID             = originalPod.PODTypeID.Value,
                            PODTypeName           = originalPod.PODTypeName,
                            TtlOrTplID            = originalPod.TtlOrTplID.Value,
                            TtlOrTplName          = originalPod.TtlOrTplName,
                            ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                            BoxNumber             = originalPod.BoxNumber,
                            Weight                = originalPod.Weight,
                            Volume                = originalPod.Volume,
                            GoodsNumber           = originalPod.GoodsNumber,
                            ShipAmt               = shipAmt * (decimal)originalPod.Volume,
                            BAFAmt                = 0,
                            PointAmt              = 0,
                            OtherAmt              = 0,//unload * (decimal)originalPod.Volume + delivery * (decimal)originalPod.Volume,
                            Amt1              = 0,
                            Amt2              = 0,
                            Amt3              = 0,
                            Amt4              = 0,
                            Amt5              = 0,
                            Str1              = string.Empty,
                            Str2              = string.Empty,
                            Str3              = string.Empty,
                            Str4              = price.Price.ToString(),
                            Str5              = string.Empty,
                            Remark            = "其他费用=提货费+卸货费",
                            DateTime1         = null,
                            DateTime2         = null,
                            CreateTime        = DateTime.Now,
                            Creator           = creator,
                            InvoiceID         = 0,
                            RelatedCustomerID = originalPod.CustomerID,
                            IsAudit           = true
                        };

                        settledPods.Add(settledPod);
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }
                    //var temp = (from p in podsResponse.Result.Where(k => innerPodIDs.Contains(k.ID)) group p by p.ID into g select new { g.Key, Pods = g });
                    //if (temp != null)
                    //{
                    //    temp.Each((i, k) =>
                    //    {
                    //        var innPodIDs = k.Pods.Select(p => p.ID);

                    //        if (1 == 1)
                    //        {
                    //            settledPods.First(s => s.PodID == innPodIDs.First()).OtherAmt = 4.2*k.Pods.Select(a=>a.Volume);
                    //            settledPods.First(s => s.PodID == innPodIDs.First()).Remark += "成耀出货,同天同城同客户点费135";
                    //        }
                    //    });
                    //}
                }
            }
            #endregion

            if (Message.Length > 0)
            {
                return;
            }

            //OtherAmt  其他费用=保底费
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 1
                });
            }
        }
        public void SettledPodForPay(IEnumerable <long> PodIDs, string creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, System.Text.StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service             = new PodService();
            var        groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
            {
                IDs = PodIDs, SettledType = 1
            });

            if (!groupedPodsResponse.IsSuccess)
            {
                throw groupedPodsResponse.Exception;
            }
            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }
            var quotedPrice = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);

            string settledNumber   = Guid.NewGuid().ToString();
            var    newpodsResponse = from q in podsResponse.Result
                                     // where q.StartCityName != "天津" && q.StartCityName != "苏州"
                                     group q by new { q.ActualDeliveryDate, q.EndCityName, q.ShipperID }
            into r
                   select new
            {
                ActualDeliveryDate = r.Key.ActualDeliveryDate.DateTimeToString(),
                EndCityName        = r.Key.EndCityName,
                ShipperID          = r.Key.ShipperID,
                Volume             = r.Sum(a => a.Volume),
                BoxNumber          = r.Sum(a => a.BoxNumber)
            };
            IList <SettledPod> settledPods = new List <SettledPod>();
            long relatedCustomerID         = 0;

            #region AdidasPurchase
            if (podsResponse.Result.First().CustomerID == 13)
            {
                relatedCustomerID = 13;
                foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
                {
                    //double cube = gPod.BoxNumber / 12;
                    double cube        = gPod.Volume;
                    var    innerPodIDs = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                    //if (gPod.StartCityName != "衡阳")
                    //{
                    //    gPod.StartCityName = "广州";
                    //}
                    foreach (var item in newpodsResponse)
                    {
                        if (item.ActualDeliveryDate.ToString() == gPod.ActualDeliveryDate && item.EndCityName == gPod.EndCityName)
                        {
                            cube = Convert.ToDouble(item.Volume);
                        }
                    }
                    QuotedPrice price;
                    price = quotedPrice.FirstOrDefault(q =>
                                                       q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                       q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                       q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));
                    if (price == null)
                    {
                        this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统对应报价,请先配置报价.");
                    }
                    if (Message.Length > 0)
                    {
                        continue;
                    }
                    decimal shipAmt = price.Price;//* (decimal)cube
                    decimal unload;
                    foreach (var id in innerPodIDs)
                    {
                        //decimal delivery = 0;
                        //提货费
                        //if (cube < 20 && innerPodIDs.First().ToString() == id.ToString())
                        //{
                        //    delivery = 300;
                        //}
                        var originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                        //卸货费
                        //unload = 0;
                        //if (gPod.EndCityName == "苏州")
                        //{
                        //    unload = (decimal)4.2;
                        //}
                        //else if (gPod.EndCityName == "广州")
                        //{
                        //    unload = cube < 150 ? (decimal)5.5 : (decimal)5;
                        //}
                        SettledPod settledPod = new SettledPod()
                        {
                            ProjectID           = originalPod.ProjectID,
                            CustomerOrderNumber = originalPod.CustomerOrderNumber,
                            SystemNumber        = originalPod.SystemNumber,
                            PodID                 = id,
                            SettledNumber         = settledNumber,
                            SettledType           = 1,
                            CustomerOrShipperID   = originalPod.ShipperID.Value,
                            CustomerOrShipperName = originalPod.ShipperName,
                            StartCityID           = originalPod.StartCityID.Value,
                            StartCityName         = originalPod.StartCityName,
                            EndCityID             = originalPod.EndCityID.Value,
                            EndCityName           = originalPod.EndCityName,
                            ShipperTypeID         = originalPod.ShipperTypeID.Value,
                            ShipperTypeName       = originalPod.ShipperTypeName,
                            PODTypeID             = originalPod.PODTypeID.Value,
                            PODTypeName           = originalPod.PODTypeName,
                            TtlOrTplID            = originalPod.TtlOrTplID.Value,
                            TtlOrTplName          = originalPod.TtlOrTplName,
                            ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                            BoxNumber             = originalPod.BoxNumber,
                            Weight                = originalPod.Weight,
                            Volume                = originalPod.Volume,
                            GoodsNumber           = originalPod.GoodsNumber,
                            ShipAmt               = shipAmt * (decimal)originalPod.Volume,
                            BAFAmt                = 0,
                            PointAmt              = 0,
                            OtherAmt              = 0,// unload * (decimal)originalPod.Volume + delivery,
                            Amt1              = 0,
                            Amt2              = 0,
                            Amt3              = 0,
                            Amt4              = 0,
                            Amt5              = 0,
                            Str1              = string.Empty,
                            Str2              = string.Empty,
                            Str3              = string.Empty,
                            Str4              = price.Price.ToString(),
                            Str5              = string.Empty,
                            Remark            = "其他费用=提货费+卸货费",
                            DateTime1         = null,
                            DateTime2         = null,
                            CreateTime        = DateTime.Now,
                            Creator           = creator,
                            InvoiceID         = 0,
                            RelatedCustomerID = originalPod.CustomerID,
                            IsAudit           = true
                        };
                        settledPods.Add(settledPod);
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }
                }
            }
            #endregion

            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 1
                });
            }
        }
        public void SettledPodForPay(IEnumerable <long> PodIDs, string creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, System.Text.StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service             = new PodService();
            var        groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
            {
                IDs = PodIDs, SettledType = 1
            });

            if (!groupedPodsResponse.IsSuccess)
            {
                throw groupedPodsResponse.Exception;
            }

            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }

            var quotedPrice = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);

            string             settledNumber = Guid.NewGuid().ToString();
            IList <SettledPod> settledPods   = new List <SettledPod>();
            long relatedCustomerID           = 0;

            #region akzo
            if (podsResponse.Result.First().CustomerID == 7)
            {
                relatedCustomerID = 7;
                foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
                {
                    double weight = gPod.Weight;
                    if (weight < 300)
                    {
                        weight = 300;
                    }
                    var         innerPodIDs = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                    QuotedPrice price       = new QuotedPrice();
                    QuotedPrice tempPrice;
                    tempPrice = quotedPrice.FirstOrDefault(q =>
                                                           q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                           q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal <= weight && q.EndVal > weight &&
                                                           q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));
                    if (tempPrice == null)
                    {
                        this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统对应报价,请先配置报价.");
                        continue;
                    }
                    else
                    {
                        price.Price = tempPrice.Price;
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }
                    decimal shipAmt = price.Price * (decimal)weight;

                    foreach (var id in innerPodIDs)
                    {
                        var originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                        if (originalPod.Weight == null)
                        {
                            this.GenErrorMessage_ByGroupedPod(gPod, Message, "请先设置货物的重量");
                            continue;
                        }
                        SettledPod settledPod = new SettledPod()
                        {
                            ProjectID           = originalPod.ProjectID,
                            CustomerOrderNumber = originalPod.CustomerOrderNumber,
                            SystemNumber        = originalPod.SystemNumber,
                            PodID                 = id,
                            SettledNumber         = settledNumber,
                            SettledType           = 1,
                            CustomerOrShipperID   = originalPod.ShipperID.Value,
                            CustomerOrShipperName = originalPod.ShipperName,
                            StartCityID           = originalPod.StartCityID.Value,
                            StartCityName         = originalPod.StartCityName,
                            EndCityID             = originalPod.EndCityID.Value,
                            EndCityName           = originalPod.EndCityName,
                            ShipperTypeID         = originalPod.ShipperTypeID.Value,
                            ShipperTypeName       = originalPod.ShipperTypeName,
                            PODTypeID             = originalPod.PODTypeID.Value,
                            PODTypeName           = originalPod.PODTypeName,
                            TtlOrTplID            = originalPod.TtlOrTplID.Value,
                            TtlOrTplName          = originalPod.TtlOrTplName,
                            ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                            BoxNumber             = originalPod.BoxNumber,
                            Weight                = originalPod.Weight,
                            Volume                = originalPod.Volume,
                            GoodsNumber           = originalPod.GoodsNumber,
                            ShipAmt               = shipAmt * (decimal)(originalPod.Weight / gPod.Weight),
                            BAFAmt                = 0,
                            PointAmt              = 0,
                            OtherAmt              = 0,
                            Amt1              = 0,
                            Amt2              = 0,
                            Amt3              = 0,
                            Amt4              = 0,
                            Amt5              = 0,
                            Str1              = string.Empty,
                            Str2              = string.Empty,
                            Str3              = string.Empty,
                            Str4              = price.Price.ToString(),
                            Str5              = string.Empty,
                            Remark            = string.Empty,
                            DateTime1         = null,
                            DateTime2         = null,
                            CreateTime        = DateTime.Now,
                            Creator           = creator,
                            InvoiceID         = 0,
                            RelatedCustomerID = originalPod.CustomerID,
                            IsAudit           = true
                        };

                        settledPods.Add(settledPod);
                    }
                }
            }
            #endregion
            #region Nike
            if (podsResponse.Result.First().CustomerID == 8)
            {
                //起运城市是太仓CLC、太仓CRW、上海的按同城结算(大仓和工厂直发[上海])
                var podsResponses = podsResponse.Result.Where(s => s.PODTypeName == "大仓出货" || s.PODTypeName == "工厂直发").GroupBy(x => new { x.ActualDeliveryDate, x.EndCityName, })
                                    .Select(g => new
                {
                    Peo   = g.Key,
                    count = g.Count(),
                    pods  = g.Select(k => { return(k); })
                });
                foreach (var pods in podsResponses)
                {
                    double boxnumner = 0;
                    double cube      = 0;
                    foreach (var pod in pods.pods)
                    {
                        if (string.IsNullOrEmpty(pod.BoxNumber.ToString()))
                        {
                            this.GenErrorMessage_ByPod(pod, Message, " 请设置该运单的箱数");
                            continue;
                        }
                        boxnumner += (double)pod.BoxNumber;
                    }
                    cube = boxnumner / 12;
                    Settlement(settledNumber, ProjectID, Message, cube, boxnumner, pods.pods, settledPods, quotedPrice);
                }
                //到货城市是太仓CLC、太仓CRW、上海的按同城结算(退货运单)
                var podsReturnResponses = podsResponse.Result.Where(s => s.PODTypeName == "退货运单").GroupBy(x => new { x.ActualDeliveryDate, x.StartCityName, })
                                          .Select(g => new
                {
                    Peo   = g.Key,
                    count = g.Count(),
                    pods  = g.Select(k => { return(k); })
                });
                foreach (var pods in podsReturnResponses)
                {
                    double boxnumner = 0;
                    double cube      = 0;
                    foreach (var pod in pods.pods)
                    {
                        if (string.IsNullOrEmpty(pod.BoxNumber.ToString()))
                        {
                            this.GenErrorMessage_ByPod(pod, Message, " 请设置该运单的箱数");
                            continue;
                        }
                        boxnumner += (double)pod.BoxNumber;
                    }
                    cube = boxnumner / 12;
                    Settlement(settledNumber, ProjectID, Message, cube, boxnumner, pods.pods, settledPods, quotedPrice);
                }
                //门店调拨(按正常的同天同城结算,但报价是按箱并不与承运商做关联结算,)
                var podsTransfersResponses = podsResponse.Result.Where(s => s.PODTypeName == "门店调拨").GroupBy(x => new { x.ActualDeliveryDate, x.StartCityName, x.EndCityName })
                                             .Select(g => new
                {
                    Peo   = g.Key,
                    count = g.Count(),
                    pods  = g.Select(k => { return(k); })
                });
                foreach (var pods in podsTransfersResponses)
                {
                    double boxnumner = 0;
                    foreach (var pod in pods.pods)
                    {
                        if (string.IsNullOrEmpty(pod.BoxNumber.ToString()))
                        {
                            this.GenErrorMessage_ByPod(pod, Message, " 请设置该运单的箱数");
                            continue;
                        }
                        boxnumner += (double)pod.BoxNumber;
                    }

                    Settlement(settledNumber, ProjectID, Message, 0, boxnumner, pods.pods, settledPods, quotedPrice);
                }

                //只有大仓出货按照12箱/方*10计算支出补贴
                var prs = podsResponse.Result.Where(p => p.PODTypeName == "大仓出货");
                prs.Each((i, e) =>
                {
                    settledPods.Each((m, n) =>
                    {
                        if (n.PodID == e.ID)
                        {
                            n.OtherAmt = (decimal)(n.BoxNumber / 12) * 10;
                        }
                    });
                });
            }
            #endregion

            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 1
                });
            }
        }
Example #6
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="SettledType">结算类型 0 应收  1 应付</param>
        /// <param name="customerOrShipperID">结算对象ID</param>
        /// <param name="IsGroupedPods">运单是否需要同天同城合并</param>
        /// <param name="PodIDs"> 待结算运单ID集合</param>
        /// <param name="ProjectID">大项目ID</param>
        /// <param name="Creator">结算人</param>
        /// <param name="Message">错误提示</param>
        public BaseSettled(int SettledType, long customerOrShipperID, bool IsGroupedPods, IEnumerable <long> PodIDs, long ProjectID, string Creator, long RelatedCustomerID)
        {
            //赋值
            this.settledType         = SettledType;
            this.customerOrShipperID = customerOrShipperID;
            this.IsGroupedPods       = IsGroupedPods;
            this.podIDCollection     = PodIDs;
            this.projectID           = ProjectID;
            this.creator             = Creator;
            this.relatedCustomerID   = RelatedCustomerID;
            service = new PodService();

            //取得待结算运单列表
            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }
            this.podCollection = podsResponse.Result;

            #region 如果同天同城合并,取得合并运单列表
            if (this.IsGroupedPods)
            {
                Response <SettledPodResponse> groupedPodsResponse = new Response <SettledPodResponse>();

                if (this.relatedCustomerID == 35)
                {
                    //ID:35 艺康同天同点合并运单
                    groupedPodsResponse = service.SettledPodByAddress(new SettledPodRequest()
                    {
                        IDs = PodIDs, SettledType = settledType
                    });
                }
                else
                {
                    //同天同城合并运单
                    groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
                    {
                        IDs = PodIDs, SettledType = settledType
                    });
                }
                if (!groupedPodsResponse.IsSuccess)
                {
                    throw groupedPodsResponse.Exception;
                }
                this.SettledPodResponse = groupedPodsResponse.Result;
            }
            #endregion

            //生成结算序列号
            settledNumber = Guid.NewGuid().ToString();

            //取得报价
            quotedPriceCollection = ApplicationConfigHelper.GetProjectQuotedPrice(this.projectID, this.settledType, this.customerOrShipperID, this.relatedCustomerID).Where(q => q.ProjectID == this.projectID && q.Target == this.settledType && q.TargetID == this.customerOrShipperID && q.RelatedCustomerID == this.relatedCustomerID);

            //取得油价
            if (customerOrShipperID == 1 && RelatedCustomerID == 1)
            {
                BAF = ApplicationConfigHelper.GetBAFPrice(ProjectID);
            }

            //将运单中一些必要的字段在基类中赋值,以减少子类的代码
            this.podCollection.Each((i, pod) =>
            {
                SettledPod settledPod = new SettledPod()
                {
                    ProjectID           = this.projectID,
                    CustomerOrderNumber = pod.CustomerOrderNumber,
                    SystemNumber        = pod.SystemNumber,
                    PodID                 = pod.ID,
                    SettledNumber         = settledNumber,
                    SettledType           = this.settledType,
                    CustomerOrShipperID   = this.customerOrShipperID,
                    CustomerOrShipperName = this.settledType == 0 ? pod.CustomerName : pod.ShipperName,
                    StartCityID           = pod.StartCityID,
                    StartCityName         = pod.StartCityName,
                    EndCityID             = pod.EndCityID,
                    EndCityName           = pod.EndCityName,
                    ShipperTypeID         = pod.ShipperTypeID,
                    ShipperTypeName       = pod.ShipperTypeName,
                    PODTypeID             = pod.PODTypeID,
                    PODTypeName           = pod.PODTypeName,
                    TtlOrTplID            = pod.TtlOrTplID,
                    TtlOrTplName          = pod.TtlOrTplName,
                    ActualDeliveryDate    = pod.ActualDeliveryDate,
                    BoxNumber             = pod.BoxNumber,
                    Weight                = pod.Weight,
                    Volume                = pod.Volume,
                    GoodsNumber           = pod.GoodsNumber,
                    //费用信息需要在子方法中计算
                    ShipAmt  = 0,
                    BAFAmt   = 0,
                    PointAmt = 0,
                    OtherAmt = 0,
                    Amt1     = 0,
                    Amt2     = 0,
                    Amt3     = 0,
                    Amt4     = 0,
                    Amt5     = 0,
                    Str1     = string.Empty,
                    Str2     = string.Empty,
                    Str3     = string.Empty,
                    //str4代表报价,需要在子方法中找到
                    Str4              = string.Empty,
                    Str5              = string.Empty,
                    Remark            = string.Empty,
                    DateTime1         = null,
                    DateTime2         = null,
                    CreateTime        = DateTime.Now,
                    Creator           = this.creator,
                    InvoiceID         = 0,
                    RelatedCustomerID = pod.CustomerID,
                    IsAudit           = true
                };

                this.settledPodCollection.Add(settledPod);
            });
        }
Example #7
0
        public void SettledPodForPay(IEnumerable <long> PodIDs, string creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, System.Text.StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service             = new PodService();
            var        groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
            {
                IDs = PodIDs, SettledType = 1
            });

            if (!groupedPodsResponse.IsSuccess)
            {
                throw groupedPodsResponse.Exception;
            }

            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }

            var quotedPrice = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);

            string             settledNumber = Guid.NewGuid().ToString();
            IList <SettledPod> settledPods   = new List <SettledPod>();
            long relatedCustomerID           = 0;

            #region Adidas
            if (podsResponse.Result.First().CustomerID == 1)
            {
                relatedCustomerID = 1;
                foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
                {
                    double      cube        = gPod.BoxNumber / 12;
                    var         innerPodIDs = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                    QuotedPrice price       = new QuotedPrice();
                    QuotedPrice tempPrice;

                    tempPrice = quotedPrice.FirstOrDefault(q =>
                                                           q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                           q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                           q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));
                    if (tempPrice == null)
                    {
                        if (string.Equals(gPod.PODTypeName.Trim(), "退货运单", StringComparison.OrdinalIgnoreCase))
                        {
                            tempPrice = quotedPrice.FirstOrDefault(q =>
                                                                   q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.EndCityName.Trim() && q.EndCityName.Trim() == gPod.StartCityName.Trim() &&
                                                                   q.PodTypeName.Trim() == "出货运单" && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                                   q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));

                            if (tempPrice == null)
                            {
                                this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统报价,出货运单也无报价,请先配置报价.");
                                continue;
                            }

                            price.Price  = tempPrice.Price;
                            price.Price *= (decimal)0.9;
                        }
                        else
                        {
                            this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统对应报价,请先配置报价.");
                            continue;
                        }
                    }
                    else
                    {
                        price.Price = tempPrice.Price;
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }

                    decimal shipAmt = price.Price * (decimal)cube;

                    foreach (var id in innerPodIDs)
                    {
                        var        originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                        SettledPod settledPod  = new SettledPod()
                        {
                            ProjectID           = originalPod.ProjectID,
                            CustomerOrderNumber = originalPod.CustomerOrderNumber,
                            SystemNumber        = originalPod.SystemNumber,
                            PodID                 = id,
                            SettledNumber         = settledNumber,
                            SettledType           = 1,
                            CustomerOrShipperID   = originalPod.ShipperID.Value,
                            CustomerOrShipperName = originalPod.ShipperName,
                            StartCityID           = originalPod.StartCityID.Value,
                            StartCityName         = originalPod.StartCityName,
                            EndCityID             = originalPod.EndCityID.Value,
                            EndCityName           = originalPod.EndCityName,
                            ShipperTypeID         = originalPod.ShipperTypeID.Value,
                            ShipperTypeName       = originalPod.ShipperTypeName,
                            PODTypeID             = originalPod.PODTypeID.Value,
                            PODTypeName           = originalPod.PODTypeName,
                            TtlOrTplID            = originalPod.TtlOrTplID.Value,
                            TtlOrTplName          = originalPod.TtlOrTplName,
                            ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                            BoxNumber             = originalPod.BoxNumber,
                            Weight                = originalPod.Weight,
                            Volume                = originalPod.Volume,
                            GoodsNumber           = originalPod.GoodsNumber,
                            ShipAmt               = shipAmt * (decimal)(originalPod.BoxNumber / gPod.BoxNumber),
                            BAFAmt                = 0,
                            PointAmt              = 0,
                            OtherAmt              = 0,
                            Amt1              = 0,
                            Amt2              = 0,
                            Amt3              = 0,
                            Amt4              = 0,
                            Amt5              = 0,
                            Str1              = string.Empty,
                            Str2              = string.Empty,
                            Str3              = string.Empty,
                            Str4              = price.Price.ToString(),
                            Str5              = string.Empty,
                            Remark            = string.Empty,
                            DateTime1         = null,
                            DateTime2         = null,
                            CreateTime        = DateTime.Now,
                            Creator           = creator,
                            InvoiceID         = 0,
                            RelatedCustomerID = originalPod.CustomerID,
                            IsAudit           = true
                        };

                        settledPods.Add(settledPod);
                    }
                }
            }
            #endregion

            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 1
                });
            }
        }
Example #8
0
        /// <summary>
        /// 结算方法
        /// </summary>
        /// <param name="settledNumber"></param>
        /// <param name="ProjectID"></param>
        /// <param name="Message"></param>
        /// <param name="cube">合并后的立方</param>
        /// <param name="boxnumner">合并后的箱数</param>
        /// <param name="Temporary">合并后运单的集合</param>
        /// <param name="settledPods">结算结果集合</param>
        /// <param name="quotedPrices">报价</param>
        private void Settlement(string settledNumber, long ProjectID, StringBuilder Message, double cube, double boxnumner, IList <Pod> Temporary, IList <SettledPod> settledPods, IEnumerable <QuotedPrice> quotedPrices)
        {
            decimal     shipAmt = 0;
            string      n       = Temporary[0].EndCityName.Trim().Substring(0, 2) == "太仓" ? Temporary[0].EndCityName.Trim().Substring(0, 2) : Temporary[0].EndCityName.Trim();
            QuotedPrice price   = quotedPrices.FirstOrDefault(q =>
                                                              q.ProjectID == ProjectID && q.Target == 0 && q.TargetID == Temporary[0].CustomerID && q.StartCityName.Trim() == (Temporary[0].StartCityName.Trim().Substring(0, 2) == "太仓" ? Temporary[0].StartCityName.Trim().Substring(0, 2) : Temporary[0].StartCityName.Trim()) &&
                                                              q.EndCityName.Trim() == (Temporary[0].EndCityName.Trim().Substring(0, 2) == "太仓" ? Temporary[0].EndCityName.Trim().Substring(0, 2) : Temporary[0].EndCityName.Trim()) &&
                                                              q.PodTypeName.Trim() == Temporary[0].PODTypeName.Trim() && q.ShipperTypeName.Trim() == Temporary[0].ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == Temporary[0].TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                              q.EffectiveStartTime <= Temporary[0].ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= Temporary[0].ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));

            if (price == null)
            {
                this.GenErrorMessage(Temporary[0], Message, " 无系统对应报价,请先配置报价.");
            }
            if (Message.Length > 0)
            {
                return;
            }
            shipAmt = price.Price * (decimal)cube;
            foreach (var pod in Temporary)
            {
                SettledPod settledPod = new SettledPod()
                {
                    ProjectID           = pod.ProjectID,
                    CustomerOrderNumber = pod.CustomerOrderNumber,
                    SystemNumber        = pod.SystemNumber,
                    PodID                 = pod.ID,
                    SettledNumber         = settledNumber,
                    SettledType           = 0,
                    CustomerOrShipperID   = pod.CustomerID.Value,
                    CustomerOrShipperName = pod.CustomerName,
                    StartCityID           = pod.StartCityID.Value,
                    StartCityName         = pod.StartCityName,
                    EndCityID             = pod.EndCityID.Value,
                    EndCityName           = pod.EndCityName,
                    ShipperTypeID         = pod.ShipperTypeID.Value,
                    ShipperTypeName       = pod.ShipperTypeName,
                    PODTypeID             = pod.PODTypeID.Value,
                    PODTypeName           = pod.PODTypeName,
                    TtlOrTplID            = pod.TtlOrTplID.Value,
                    TtlOrTplName          = pod.TtlOrTplName,
                    ActualDeliveryDate    = pod.ActualDeliveryDate.Value,
                    BoxNumber             = pod.BoxNumber,
                    Weight                = pod.Weight,
                    Volume                = pod.Volume,
                    GoodsNumber           = pod.GoodsNumber,
                    ShipAmt               = shipAmt * (decimal)(pod.BoxNumber / boxnumner),
                    BAFAmt                = 0,
                    PointAmt              = 0,
                    OtherAmt              = 0,
                    Amt1              = 0,
                    Amt2              = 0,
                    Amt3              = 0,
                    Amt4              = 0,
                    Amt5              = 0,
                    Str1              = string.Empty,
                    Str2              = string.Empty,
                    Str3              = string.Empty,
                    Str4              = price.Price.ToString(),
                    Str5              = string.Empty,
                    Remark            = string.Empty,
                    DateTime1         = null,
                    DateTime2         = null,
                    CreateTime        = DateTime.Now,
                    Creator           = pod.Creator,
                    InvoiceID         = 0,
                    RelatedCustomerID = pod.CustomerID,
                    IsAudit           = true
                };
                settledPods.Add(settledPod);
            }
        }
        public void SettledPodForPay(IEnumerable <long> PodIDs, string creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, System.Text.StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service             = new PodService();
            var        groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
            {
                IDs = PodIDs, SettledType = 1
            });

            if (!groupedPodsResponse.IsSuccess)
            {
                throw groupedPodsResponse.Exception;
            }

            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }

            var quotedPrice = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);

            string settledNumber   = Guid.NewGuid().ToString();
            var    newpodsResponse = from q in podsResponse.Result
                                     where q.StartCityName != "天津" && q.StartCityName != "苏州"
                                     group q by new { q.ActualDeliveryDate, q.EndCityName, q.ShipperID }
            into r
                   select new
            {
                ActualDeliveryDate = r.Key.ActualDeliveryDate.DateTimeToString(),
                EndCityName        = r.Key.EndCityName,
                ShipperID          = r.Key.ShipperID,
                Volume             = r.Sum(a => a.Volume)
            };
            IList <SettledPod> settledPods = new List <SettledPod>();
            long relatedCustomerID         = 0;

            #region Adidas
            if (podsResponse.Result.First().CustomerID == 1)
            {
                relatedCustomerID = 1;
                foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
                {
                    double      cube        = gPod.BoxNumber / 12;
                    var         innerPodIDs = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                    QuotedPrice price;
                    price = quotedPrice.FirstOrDefault(q =>
                                                       q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                       q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                       q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));
                    if (price == null)
                    {
                        if (string.Equals(gPod.PODTypeName.Trim(), "退货运单", StringComparison.OrdinalIgnoreCase))
                        {
                            price = quotedPrice.FirstOrDefault(q =>
                                                               q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.EndCityName.Trim() && q.EndCityName.Trim() == gPod.StartCityName.Trim() &&
                                                               q.PodTypeName.Trim() == "出货运单" && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                               q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));

                            if (price == null)
                            {
                                this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统报价,出货运单也无报价,请先配置报价.");
                                continue;
                            }

                            price.Price  = price.Price;
                            price.Price *= (decimal)0.9;
                        }
                        else
                        {
                            this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统对应报价,请先配置报价.");
                            continue;
                        }
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }

                    decimal shipAmt = price.Price * (decimal)cube * (decimal)0.9;

                    foreach (var id in innerPodIDs)
                    {
                        var        originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                        SettledPod settledPod  = new SettledPod()
                        {
                            ProjectID           = originalPod.ProjectID,
                            CustomerOrderNumber = originalPod.CustomerOrderNumber,
                            SystemNumber        = originalPod.SystemNumber,
                            PodID                 = id,
                            SettledNumber         = settledNumber,
                            SettledType           = 1,
                            CustomerOrShipperID   = originalPod.ShipperID.Value,
                            CustomerOrShipperName = originalPod.ShipperName,
                            StartCityID           = originalPod.StartCityID.Value,
                            StartCityName         = originalPod.StartCityName,
                            EndCityID             = originalPod.EndCityID.Value,
                            EndCityName           = originalPod.EndCityName,
                            ShipperTypeID         = originalPod.ShipperTypeID.Value,
                            ShipperTypeName       = originalPod.ShipperTypeName,
                            PODTypeID             = originalPod.PODTypeID.Value,
                            PODTypeName           = originalPod.PODTypeName,
                            TtlOrTplID            = originalPod.TtlOrTplID.Value,
                            TtlOrTplName          = originalPod.TtlOrTplName,
                            ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                            BoxNumber             = originalPod.BoxNumber,
                            Weight                = originalPod.Weight,
                            Volume                = originalPod.Volume,
                            GoodsNumber           = originalPod.GoodsNumber,
                            ShipAmt               = shipAmt * (decimal)(originalPod.BoxNumber / gPod.BoxNumber),
                            BAFAmt                = 0,
                            PointAmt              = 0,
                            OtherAmt              = 0,
                            Amt1              = 0,
                            Amt2              = 0,
                            Amt3              = 0,
                            Amt4              = 0,
                            Amt5              = 0,
                            Str1              = string.Empty,
                            Str2              = string.Empty,
                            Str3              = string.Empty,
                            Str4              = price.Price.ToString(),
                            Str5              = string.Empty,
                            Remark            = string.Empty,
                            DateTime1         = null,
                            DateTime2         = null,
                            CreateTime        = DateTime.Now,
                            Creator           = creator,
                            InvoiceID         = 0,
                            RelatedCustomerID = originalPod.CustomerID,
                            IsAudit           = true
                        };

                        settledPods.Add(settledPod);
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }

                    if (string.Equals(gPod.PODTypeName.Trim(), "出货运单", StringComparison.OrdinalIgnoreCase))
                    {
                        var temp = (from p in podsResponse.Result.Where(k => innerPodIDs.Contains(k.ID) && k.PODTypeName.Trim() == "出货运单") group p by p.Str7 into g select new { g.Key, Pods = g });
                        if (temp != null)
                        {
                            temp.Each((i, k) =>
                            {
                                var innPodIDs = k.Pods.Select(p => p.ID);

                                if (1 == 1)
                                {
                                    settledPods.First(s => s.PodID == innPodIDs.First()).PointAmt = 135;
                                    settledPods.First(s => s.PodID == innPodIDs.First()).Remark  += "成耀出货,同天同城同客户点费135";
                                }
                            });
                        }
                    }
                    if (string.Equals(gPod.PODTypeName.Trim(), "调拨运单", StringComparison.OrdinalIgnoreCase))
                    {
                        var temp = (from p in podsResponse.Result.Where(k => innerPodIDs.Contains(k.ID) && k.PODTypeName.Trim() == "调拨运单") group p by p.ID into g select new { g.Key, Pods = g });
                        if (temp != null)
                        {
                            temp.Each((i, k) =>
                            {
                                var innPodIDs = k.Pods.Select(p => p.ID);
                                if (1 == 1)
                                {
                                    settledPods.First(s => s.PodID == innerPodIDs.First()).PointAmt = 70;
                                    settledPods.First(s => s.PodID == innerPodIDs.First()).Remark  += "成耀调拨,";
                                }
                            });
                        }
                    }
                    if (string.Equals(gPod.PODTypeName.Trim(), "退货运单", StringComparison.OrdinalIgnoreCase))
                    {
                        var temp = (from p in podsResponse.Result.Where(k => innerPodIDs.Contains(k.ID) && k.PODTypeName.Trim() == "退货运单") group p by p.Str7 into g select new { g.Key, Pods = g });
                        if (temp != null)
                        {
                            temp.Each((i, k) =>
                            {
                                var innPodIDs = k.Pods.Select(p => p.ID);

                                if (1 == 1)
                                {
                                    settledPods.First(s => s.PodID == innPodIDs.First()).PointAmt = 135 * (decimal)0.9;
                                    settledPods.First(s => s.PodID == innPodIDs.First()).Remark  += "成耀出货,同天同城同客户点费135";
                                }
                            });
                        }
                    }
                }
            }
            #endregion
            #region AdidasPurchase
            if (podsResponse.Result.First().CustomerID == 13)
            {
                relatedCustomerID = 13;
                foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
                {
                    double BoxNumber   = gPod.BoxNumber;
                    double cube        = gPod.Volume;
                    var    innerPodIDs = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                    gPod.StartCityName = "广州";

                    foreach (var item in newpodsResponse)
                    {
                        if (item.ActualDeliveryDate.ToString() == gPod.ActualDeliveryDate && item.EndCityName == gPod.EndCityName)
                        {
                            cube = Convert.ToDouble(item.Volume);
                        }
                    }

                    QuotedPrice price;
                    price = quotedPrice.FirstOrDefault(q =>
                                                       q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                       q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                       q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));
                    if (price == null)
                    {
                        if (string.Equals(gPod.PODTypeName.Trim(), "退货运单", StringComparison.OrdinalIgnoreCase))
                        {
                            price = quotedPrice.FirstOrDefault(q =>
                                                               q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.EndCityName.Trim() && q.EndCityName.Trim() == gPod.StartCityName.Trim() &&
                                                               q.PodTypeName.Trim() == "出货运单" && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                               q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));
                            if (price == null)
                            {
                                this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统报价,出货运单也无报价,请先配置报价.");
                                continue;
                            }
                            price.Price  = price.Price;
                            price.Price *= (decimal)0.9;
                        }
                        else
                        {
                            this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统对应报价,请先配置报价.");
                            continue;
                        }
                    }
                    if (Message.Length > 0)
                    {
                        continue;
                    }
                    decimal shipAmt = 0;
                    decimal unload;
                    foreach (var id in innerPodIDs)
                    {
                        decimal delivery = 0;
                        //提货费
                        if (cube < 40 && innerPodIDs.First().ToString() == id.ToString())
                        {
                            switch (gPod.EndCityName)
                            {
                            case "广州":
                                delivery = 15;
                                break;

                            case "清远":
                                delivery = 25;
                                break;

                            case "云浮":
                                delivery = 25;
                                break;

                            case "东莞":
                                delivery = 25;
                                break;

                            case "中山":
                                delivery = 25;
                                break;

                            case "佛山":
                                delivery = 25;
                                break;

                            case "惠州":
                                delivery = 25;
                                break;

                            case "河源":
                                delivery = 25;
                                break;

                            default:
                                delivery = 0;
                                break;
                            }
                        }
                        var originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                        if (cube > 10)
                        {
                            shipAmt = price.Price * (decimal)originalPod.Volume;
                        }
                        else
                        {
                            shipAmt = price.Price * (decimal)originalPod.BoxNumber;
                        }
                        //卸货费
                        unload = 0;
                        if (gPod.EndCityName == "苏州")
                        {
                            unload = (decimal)4.2;
                        }
                        else if (gPod.EndCityName == "广州")
                        {
                            unload = cube < 150 ? (decimal)5.5 : (decimal)5;
                        }
                        SettledPod settledPod = new SettledPod()
                        {
                            ProjectID           = originalPod.ProjectID,
                            CustomerOrderNumber = originalPod.CustomerOrderNumber,
                            SystemNumber        = originalPod.SystemNumber,
                            PodID                 = id,
                            SettledNumber         = settledNumber,
                            SettledType           = 1,
                            CustomerOrShipperID   = originalPod.ShipperID.Value,
                            CustomerOrShipperName = originalPod.ShipperName,
                            StartCityID           = originalPod.StartCityID.Value,
                            StartCityName         = originalPod.StartCityName,
                            EndCityID             = originalPod.EndCityID.Value,
                            EndCityName           = originalPod.EndCityName,
                            ShipperTypeID         = originalPod.ShipperTypeID.Value,
                            ShipperTypeName       = originalPod.ShipperTypeName,
                            PODTypeID             = originalPod.PODTypeID.Value,
                            PODTypeName           = originalPod.PODTypeName,
                            TtlOrTplID            = originalPod.TtlOrTplID.Value,
                            TtlOrTplName          = originalPod.TtlOrTplName,
                            ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                            BoxNumber             = originalPod.BoxNumber,
                            Weight                = originalPod.Weight,
                            Volume                = originalPod.Volume,
                            GoodsNumber           = originalPod.GoodsNumber,
                            ShipAmt               = shipAmt,
                            BAFAmt                = 0,
                            PointAmt              = 0,
                            OtherAmt              = unload * (decimal)originalPod.Volume + delivery * (decimal)originalPod.Volume,
                            Amt1              = 0,
                            Amt2              = 0,
                            Amt3              = 0,
                            Amt4              = 0,
                            Amt5              = 0,
                            Str1              = string.Empty,
                            Str2              = string.Empty,
                            Str3              = string.Empty,
                            Str4              = price.Price.ToString(),
                            Str5              = string.Empty,
                            Remark            = "其他费用=提货费+卸货费",
                            DateTime1         = null,
                            DateTime2         = null,
                            CreateTime        = DateTime.Now,
                            Creator           = creator,
                            InvoiceID         = 0,
                            RelatedCustomerID = originalPod.CustomerID,
                            IsAudit           = true
                        };

                        settledPods.Add(settledPod);
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }
                }
            }
            #endregion
            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 1
                });
            }
        }
Example #10
0
        public void SettledPodForPay(IEnumerable <long> PodIDs, string creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, System.Text.StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }
            PodService service      = new PodService();
            var        podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }
            var                quotedPrice   = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);
            string             settledNumber = Guid.NewGuid().ToString();
            IList <SettledPod> settledPods   = new List <SettledPod>();

            #region Nike
            if (podsResponse.Result.First().CustomerID == 8)
            {
                //起运城市是太仓CLC(大仓出货 空运)结算时不按同天同城合并
                var podsResponses = podsResponse.Result.Where(p => p.ShipperTypeName == "空运");
                foreach (var pod in podsResponses)
                {
                    if (string.IsNullOrEmpty(pod.BoxNumber.ToString()))
                    {
                        this.GenErrorMessage_ByPod(pod, Message, " 请设置该运单的箱数");
                        continue;
                    }
                    double  aircube = 0;
                    decimal price   = 0;
                    decimal shipAmt = 0;
                    aircube = (1000 / 6.0) * (double)pod.BoxNumber / 11.0;
                    if (aircube > 500)
                    {
                        price = (decimal)8.1;
                    }
                    else if (aircube > 100)
                    {
                        price = (decimal)9.7;
                    }
                    else
                    {
                        price = (decimal)11.9;
                    }
                    shipAmt = price * (decimal)aircube;
                    if (string.IsNullOrEmpty(pod.BoxNumber.ToString()))
                    {
                        this.GenErrorMessage_ByPod(pod, Message, " 请设置该运单的箱数");
                        continue;
                    }
                    SettledPod settledPod = new SettledPod()
                    {
                        ProjectID           = pod.ProjectID,
                        CustomerOrderNumber = pod.CustomerOrderNumber,
                        SystemNumber        = pod.SystemNumber,
                        PodID                 = pod.ID,
                        SettledNumber         = settledNumber,
                        SettledType           = 1,
                        CustomerOrShipperID   = pod.CustomerID.Value,
                        CustomerOrShipperName = pod.CustomerName,
                        StartCityID           = pod.StartCityID.Value,
                        StartCityName         = pod.StartCityName,
                        EndCityID             = pod.EndCityID.Value,
                        EndCityName           = pod.EndCityName,
                        ShipperTypeID         = pod.ShipperTypeID.Value,
                        ShipperTypeName       = pod.ShipperTypeName,
                        PODTypeID             = pod.PODTypeID.Value,
                        PODTypeName           = pod.PODTypeName,
                        TtlOrTplID            = pod.TtlOrTplID.Value,
                        TtlOrTplName          = pod.TtlOrTplName,
                        ActualDeliveryDate    = pod.ActualDeliveryDate.Value,
                        BoxNumber             = pod.BoxNumber,
                        Weight                = pod.Weight,
                        Volume                = pod.Volume,
                        GoodsNumber           = pod.GoodsNumber,
                        ShipAmt               = shipAmt,
                        BAFAmt                = 0,
                        PointAmt              = 0,
                        OtherAmt              = 0,
                        Amt1              = 0,
                        Amt2              = 0,
                        Amt3              = 0,
                        Amt4              = 0,
                        Amt5              = 0,
                        Str1              = string.Empty,
                        Str2              = string.Empty,
                        Str3              = string.Empty,
                        Str4              = price.ToString(),
                        Str5              = string.Empty,
                        Remark            = string.Empty,
                        DateTime1         = null,
                        DateTime2         = null,
                        CreateTime        = DateTime.Now,
                        Creator           = pod.Creator,
                        InvoiceID         = 0,
                        RelatedCustomerID = pod.CustomerID,
                        IsAudit           = true
                    };
                    settledPods.Add(settledPod);
                }
                //起运城市广州(工厂直发)
                var podsGZResponses = podsResponse.Result.Where(s => s.PODTypeName == "工厂直发" && s.StartCityName == "广州").GroupBy(x => new { x.ActualDeliveryDate, x.EndCityName, })
                                      .Select(g => new
                {
                    Peo   = g.Key,
                    count = g.Count(),
                    pods  = g.Select(k => { return(k); })
                });
                foreach (var pods in podsGZResponses)
                {
                    double boxnumner = 0;
                    double cube      = 0;
                    foreach (var pod in pods.pods)
                    {
                        if (string.IsNullOrEmpty(pod.BoxNumber.ToString()))
                        {
                            this.GenErrorMessage_ByPod(pod, Message, " 请设置该运单的箱数");
                            continue;
                        }
                        boxnumner += (double)pod.BoxNumber;
                    }
                    cube = boxnumner / 12;
                    Settlement(settledNumber, ProjectID, Message, cube, boxnumner, pods.pods, settledPods, quotedPrice);
                }
                //只有大仓出货按照11箱/方*10计算支出补贴
                var prs = podsResponse.Result.Where(p => p.PODTypeName == "大仓出货");
                prs.Each((i, e) =>
                {
                    settledPods.Each((m, n) =>
                    {
                        if (n.PodID == e.ID)
                        {
                            n.OtherAmt = (decimal)(n.BoxNumber / 12) * 10;
                        }
                    });
                });
            }
            #endregion
            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 1
                });
            }
        }
        public void SettledPodForPay(IEnumerable <long> PodIDs, string Creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service      = new PodService();
            var        podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }

            var                quotedPrice   = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);
            string             settledNumber = Guid.NewGuid().ToString();
            IList <SettledPod> settledPods   = new List <SettledPod>();

            foreach (var pod in podsResponse.Result)
            {
                //For Oriflame
                if (pod.CustomerID == 5)
                {
                    if (!pod.Weight.HasValue || pod.Weight.Value == 0)
                    {
                        Message.Append("运单:").Append(pod.CustomerOrderNumber).Append(",对应承运商为:").Append(pod.ShipperName).Append(",起运城市为:")
                        .Append(pod.StartCityName).Append(",目的城市为:").Append(pod.EndCityName).Append(",运输类型为:").Append(pod.ShipperTypeName)
                        .Append(",运单类型为:").Append(pod.PODTypeName).Append(",整车/零担为:").Append(pod.TtlOrTplName).Append(" 无重量,请先编辑运单重量。").Append("*");
                        continue;
                    }

                    IEnumerable <QuotedPrice> prices = quotedPrice.Where(q =>
                                                                         q.ProjectID == ProjectID && q.Target == 0 && q.TargetID == pod.CustomerID && q.StartCityName == pod.StartCityName && q.EndCityName == pod.EndCityName &&
                                                                         q.PodTypeName == pod.PODTypeName && q.ShipperTypeName == pod.ShipperTypeName && q.TplOrTtlName == pod.TtlOrTplName &&
                                                                         q.EffectiveStartTime <= pod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= pod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));

                    if (prices == null || !prices.Any())
                    {
                        Message.Append("运单:").Append(pod.CustomerOrderNumber).Append(",对应承运商为:").Append(pod.ShipperName).Append(",起运城市为:")
                        .Append(pod.StartCityName).Append(",目的城市为:").Append(pod.EndCityName).Append(",运输类型为:").Append(pod.ShipperTypeName)
                        .Append(",运单类型为:").Append(pod.PODTypeName).Append(",整车/零担为:").Append(pod.TtlOrTplName).Append(" 无对应报价,请先配置。").Append("*");
                        continue;
                    }

                    SettledPod settledPod = new SettledPod()
                    {
                        ProjectID           = pod.ProjectID,
                        CustomerOrderNumber = pod.CustomerOrderNumber,
                        SystemNumber        = pod.SystemNumber,
                        PodID                 = pod.ID,
                        SettledNumber         = settledNumber,
                        SettledType           = 1,
                        CustomerOrShipperID   = pod.ShipperID.Value,
                        CustomerOrShipperName = pod.ShipperName,
                        StartCityID           = pod.StartCityID.Value,
                        StartCityName         = pod.StartCityName,
                        EndCityID             = pod.EndCityID.Value,
                        EndCityName           = pod.EndCityName,
                        ShipperTypeID         = pod.ShipperTypeID.Value,
                        ShipperTypeName       = pod.ShipperTypeName,
                        PODTypeID             = pod.PODTypeID.Value,
                        PODTypeName           = pod.PODTypeName,
                        TtlOrTplID            = pod.TtlOrTplID.Value,
                        TtlOrTplName          = pod.TtlOrTplName,
                        ActualDeliveryDate    = pod.ActualDeliveryDate.Value,
                        BoxNumber             = pod.BoxNumber,
                        Weight                = pod.Weight,
                        Volume                = pod.Volume,
                        GoodsNumber           = pod.GoodsNumber,
                        BAFAmt                = 0,
                        PointAmt              = 0,
                        OtherAmt              = 0,
                        Amt1              = 0,
                        Amt2              = 0,
                        Amt3              = 0,
                        Amt4              = 0,
                        Amt5              = 0,
                        Str1              = string.Empty,
                        Str2              = string.Empty,
                        Str3              = string.Empty,
                        Str4              = string.Empty,
                        Str5              = string.Empty,
                        Remark            = string.Empty,
                        DateTime1         = null,
                        DateTime2         = null,
                        CreateTime        = DateTime.Now,
                        Creator           = Creator,
                        InvoiceID         = 0,
                        RelatedCustomerID = pod.CustomerID,
                        IsAudit           = true
                    };

                    prices = prices.OrderBy(p => p.StartVal);
                    decimal firstPrice  = prices.FirstOrDefault().Price;
                    decimal lastPrice   = prices.FirstOrDefault().Price;
                    double  firstweight = 1;

                    if (pod.Weight.Value <= firstweight)
                    {
                        settledPod.ShipAmt = firstPrice;
                    }
                    else
                    {
                        settledPod.ShipAmt = firstPrice + (decimal)(pod.Weight.Value - firstweight) * lastPrice;
                    }

                    settledPods.Add(settledPod);
                }
            }

            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 1
                });
            }
        }
        public void SettledPodForReceive(IEnumerable <long> PodIDs, string Creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service = new PodService();
            //forSettledPodsResponse 待结算运单列表
            var forSettledPodsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!forSettledPodsResponse.IsSuccess)
            {
                throw forSettledPodsResponse.Exception;
            }
            //同天同城合并,取得合并运单列表 groupedPodsResponse
            var groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
            {
                IDs = PodIDs, SettledType = 0
            });

            if (!groupedPodsResponse.IsSuccess)
            {
                throw groupedPodsResponse.Exception;
            }

            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }
            //取得报价
            var                quotedPrice   = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);
            var                BAF           = ApplicationConfigHelper.GetBAFPrice(ProjectID);
            string             settledNumber = Guid.NewGuid().ToString();
            IList <SettledPod> settledPods   = new List <SettledPod>();

            foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
            {
                decimal BAFPrice         = 0;
                double  cube             = 0;
                var     innerPodIDs      = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                var     tempOriginalPods = podsResponse.Result.Where(p => innerPodIDs.Contains(p.ID));
                tempOriginalPods.Each((i, p) =>
                {
                    int tempInt     = 0;
                    double tempCube = 0;
                    if (string.Equals(p.PODTypeName, "出货运单", StringComparison.OrdinalIgnoreCase))
                    {
                        if (p.CustomerOrderNumber.Substring(0, 2) == "SP" || int.TryParse(p.CustomerOrderNumber.Substring(0, 1), out tempInt))
                        {
                            tempCube = p.BoxNumber.Value / specialDivisor;//11.4
                        }
                        else
                        {
                            tempCube = p.BoxNumber.Value / commonDivisor;//11
                        }
                    }
                    else
                    {
                        tempCube = p.BoxNumber.Value / commonDivisor;
                    }
                    cube += tempCube;
                    podsResponse.Result.First(c => c.ID == p.ID).Str40 = tempCube.ToString();
                });
                QuotedPrice price = quotedPrice.FirstOrDefault(q =>
                                                               q.ProjectID == ProjectID && q.Target == 0 && q.TargetID == gPod.TargetID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                               q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                               q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));
                QueryBAFPrice BAFPrices = BAF.FirstOrDefault(q =>
                                                             q.ProjectID == ProjectID && q.BAFStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && q.BAFEndTime > gPod.ActualDeliveryDate.ObjectToDateTime());

                if (BAFPrices == null)
                {
                    BAFPrice = 0;
                }
                else
                {
                    BAFPrice = BAFPrices.BAFPrice;
                }
                if (price == null)
                {
                    var forSettledPodsTemp = forSettledPodsResponse.Result.Where(p => gPod.PodIDs.Split('|').Contains(p.ID.ToString()));
                    if (forSettledPodsTemp != null)
                    {
                        forSettledPodsTemp.Each((k, g) =>
                        {
                            Message.Append("运单:").Append(g.CustomerOrderNumber).Append(",对应客户为:").Append(g.CustomerName).Append(",起运城市为:")
                            .Append(g.StartCityName).Append(",目的城市为:").Append(g.EndCityName).Append(",运输类型为:").Append(g.ShipperTypeName)
                            .Append(",运单类型为:").Append(g.PODTypeName).Append(",整车/零担为:").Append(g.TtlOrTplName).Append(" 无系统对应报价,请先配置报价.").Append("*");
                        });
                    }
                    continue;
                }
                if (Message.Length > 0)
                {
                    continue;
                }
                decimal shipAmt = 0;
                shipAmt = price.Price * (decimal)cube;

                foreach (var id in innerPodIDs)
                {
                    var        originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                    SettledPod settledPod  = new SettledPod()
                    {
                        ProjectID           = originalPod.ProjectID,
                        CustomerOrderNumber = originalPod.CustomerOrderNumber,
                        SystemNumber        = originalPod.SystemNumber,
                        PodID                 = id,
                        SettledNumber         = settledNumber,
                        SettledType           = 0,
                        CustomerOrShipperID   = originalPod.CustomerID.Value,
                        CustomerOrShipperName = originalPod.CustomerName,
                        StartCityID           = originalPod.StartCityID.Value,
                        StartCityName         = originalPod.StartCityName,
                        EndCityID             = originalPod.EndCityID.Value,
                        EndCityName           = originalPod.EndCityName,
                        ShipperTypeID         = originalPod.ShipperTypeID.Value,
                        ShipperTypeName       = originalPod.ShipperTypeName,
                        PODTypeID             = originalPod.PODTypeID.Value,
                        PODTypeName           = originalPod.PODTypeName,
                        TtlOrTplID            = originalPod.TtlOrTplID.Value,
                        TtlOrTplName          = originalPod.TtlOrTplName,
                        ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                        BoxNumber             = originalPod.BoxNumber,
                        Weight                = originalPod.Weight,
                        Volume                = originalPod.Volume,
                        GoodsNumber           = originalPod.GoodsNumber,
                        ShipAmt               = shipAmt * (decimal)(originalPod.Str40.ObjectToDouble() / cube),
                        BAFAmt                = BAFPrice * shipAmt * (decimal)(originalPod.Str40.ObjectToDouble() / cube),
                        PointAmt              = 0,
                        OtherAmt              = 0,
                        Amt1              = 0,
                        Amt2              = 0,
                        Amt3              = 0,
                        Amt4              = 0,
                        Amt5              = 0,
                        Str1              = string.Empty,
                        Str2              = string.Empty,
                        Str3              = string.Empty,
                        Str4              = price.Price.ToString(),
                        Str5              = string.Empty,
                        Remark            = string.Empty,
                        DateTime1         = null,
                        DateTime2         = null,
                        CreateTime        = DateTime.Now,
                        Creator           = Creator,
                        InvoiceID         = 0,
                        RelatedCustomerID = originalPod.CustomerID,
                        IsAudit           = true
                    };

                    settledPods.Add(settledPod);
                }

                if (Message.Length > 0)
                {
                    continue;
                }

                if (string.Equals(gPod.PODTypeName.Trim(), "调拨运单", StringComparison.OrdinalIgnoreCase))
                {
                    var temp = (from p in podsResponse.Result.Where(k => innerPodIDs.Contains(k.ID)) group p by p.Str6 into g select new { g.Key, Pods = g });

                    if (temp != null)
                    {
                        temp.Each((i, k) =>
                        {
                            var innPodIDs = k.Pods.Select(p => p.ID);
                            if (k.Pods.First().CustomerOrderNumber.Substring(0, 2) == "BR" && (k.Pods.First().StartCityName.Trim() == "苏州" || k.Pods.First().EndCityName.Trim() == "苏州"))
                            {
                                //settledPods.Each((i1, k1) =>
                                //{
                                //    if (innPodIDs.Contains(k1.PodID))
                                //    {
                                settledPods.Each((i1, k1) => { if (innerPodIDs.Contains(k1.PodID))
                                                               {
                                                                   k1.PointAmt = 0;
                                                               }
                                                 });
                                settledPods.First(c => c.PodID == k.Pods.First().ID).PointAmt = point_from_suzhou;
                                settledPods.First(c => c.PodID == k.Pods.First().ID).Remark  += "Adidas调拨运单,BR开头的按照苏州至全国,全国至苏州,按照同天同城同客户合并后每票100计算点费";
                                //k1.PointAmt = point_from_suzhou;//(decimal)(k1.BoxNumber / commonDivisor) * point_from_suzhou
                                //k1.Remark = "Adidas调拨运单,发货城市苏州,按照方*100计算点费";
                                //  }
                                //});
                            }
                            else if (k.Pods.First().CustomerOrderNumber.Substring(0, 2) == "SP" && (k.Pods.First().StartCityName.Trim() == "上海" || k.Pods.First().EndCityName.Trim() == "上海"))
                            {
                                settledPods.Each((i1, k1) => { if (innerPodIDs.Contains(k1.PodID))
                                                               {
                                                                   k1.PointAmt = 0;
                                                               }
                                                 });
                                settledPods.First(c => c.PodID == k.Pods.First().ID).PointAmt = point_from_shanghai;
                                settledPods.First(c => c.PodID == k.Pods.First().ID).Remark  += "Adidas调拨运单,SP开头的按照上海至全国,全国至上海,按照同天同城同客户合并后每票100计算点费";
                            }
                            else if (k.Pods.First().CustomerOrderNumber.Substring(0, 3) == "TRS" || k.Pods.First().CustomerOrderNumber.Substring(0, 3) == "TRN")
                            {
                                settledPods.Each((i1, k1) =>
                                {
                                    if (innPodIDs.Contains(k1.PodID))
                                    {
                                        k1.PointAmt = (decimal)(k1.BoxNumber / commonDivisor) * point100;
                                        k1.Remark   = "Adidas调拨运单,TRS开头和TRN开头,按照方*100计算点费";
                                    }
                                });
                            }
                            else if (k.Pods.First().CustomerOrderNumber.Substring(0, 3) == "SPOW")
                            {
                                settledPods.Each((i1, k1) =>
                                {
                                    if (innPodIDs.Contains(k1.PodID))
                                    {
                                        k1.PointAmt = (decimal)(k1.BoxNumber / commonDivisor) * point80;
                                        k1.Remark   = "Adidas调拨运单,SPOW开头,按照方*100计算点费";
                                    }
                                });
                            }
                            //else if ((k.Pods.First().StartCityName.Trim() == "东莞" && k.Pods.First().EndCityName == "深圳")
                            //    || (k.Pods.First().StartCityName.Trim() == "深圳" && k.Pods.First().EndCityName == "东莞")
                            //    || (k.Pods.First().StartCityName.Trim() == "东莞" && k.Pods.First().EndCityName == "广州")
                            //    || (k.Pods.First().StartCityName.Trim() == "珠海" && k.Pods.First().EndCityName == "东莞")
                            //    )
                            //{
                            //    settledPods.Each((i1, k1) =>
                            //    {
                            //        if (innPodIDs.Contains(k1.PodID))
                            //        {
                            //            k1.PointAmt = (decimal)(k1.BoxNumber / commonDivisor) * 84;
                            //            k1.Remark = "Adidas调拨运单,发货城市" + k1.StartCityName + ",收货城市" + k1.EndCityName + ",按照方*84计算点费";
                            //        }
                            //    });
                            //}
                            else
                            {
                                settledPods.Each((i1, k1) =>
                                {
                                    if (innPodIDs.Contains(k1.PodID))
                                    {
                                        k1.PointAmt = (decimal)(k1.BoxNumber / commonDivisor) * point80;
                                        k1.Remark   = "Adidas调拨运单,如无特殊,按照方*80计算点费";
                                    }
                                });
                            }
                        });
                    }
                }

                //同城同天同一家客户经销商点费为100元、自营店(客户简称为中文)原则上无点费
                if (string.Equals(gPod.PODTypeName.Trim(), "退货运单", StringComparison.OrdinalIgnoreCase))
                {
                    var temp = (from p in podsResponse.Result.Where(k => innerPodIDs.Contains(k.ID) && k.Str10 == "经销商" || (k.Str10 == "自营店" && k.Str7 == "淘宝" && k.Str7 == "北区卫星舱")) group p by p.Str2 into g select new { g.Key, Pods = g });
                    if (temp != null)
                    {
                        temp.Each((i, k) =>
                        {
                            var innPodIDs = k.Pods.Select(p => p.ID);
                            settledPods.Each((i1, k1) => { if (innerPodIDs.Contains(k1.PodID))
                                                           {
                                                               k1.PointAmt = 0;
                                                           }
                                             });
                            settledPods.First(c => c.PodID == k.Pods.First().ID).PointAmt = point100;
                            settledPods.First(c => c.PodID == k.Pods.First().ID).Remark  += "Adidas退货,同天同城,点费100元。";
                        });
                    }
                }

                //出货 自营店(客户简称为中文)按方收取点费
                if (string.Equals(gPod.PODTypeName.Trim(), "出货运单", StringComparison.OrdinalIgnoreCase))
                {
                    var temp = podsResponse.Result.Where(p => innerPodIDs.Contains(p.ID) && p.Str10 == "自营店" && Regex.IsMatch(p.Str7.Substring(0, 1), @"^[\u4e00-\u9fa5]+$") && p.Str7 != "淘宝" && p.Str7 != "北区卫星舱" && (p.CustomerOrderNumber.Substring(0, 3) != "RBO" && p.CustomerOrderNumber.Substring(0, 2) != "OW" && p.CustomerOrderNumber.Substring(0, 2) != "ZD" && p.CustomerOrderNumber.Substring(0, 2) != "SC" && p.CustomerOrderNumber.Substring(0, 2) != "OB"));
                    if (temp != null)
                    {
                        temp.Each((i, k) =>
                        {
                            int tInt;
                            double cbm;
                            if (int.TryParse(k.CustomerOrderNumber.Substring(0, 1), out tInt))
                            {
                                cbm = k.BoxNumber.Value / specialDivisor;
                            }
                            else
                            {
                                cbm = k.BoxNumber.Value / commonDivisor;
                            }

                            settledPods.First(c => c.PodID == k.ID).PointAmt = point80 * (decimal)cbm;
                            settledPods.First(c => c.PodID == k.ID).Remark   = "Adidas出货,自营店按方*80 收取点费";
                        });
                    }
                }
            }

            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt - p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 0
                });
            }
        }
Example #13
0
        public void SettledPodForReceive(IEnumerable <long> PodIDs, string Creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service      = new PodService();
            var        podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }

            var quotedPrice = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);

            string settledNumber = Guid.NewGuid().ToString();

            IList <SettledPod> settledPods = new List <SettledPod>();

            foreach (var pod in podsResponse.Result)
            {
                if (string.IsNullOrEmpty(pod.Str9))
                {
                    this.GenErrorMessage(pod, Message, "毛重没有录入,请重新编辑运单");
                    continue;
                }

                double weight = 0;

                try
                {
                    weight = pod.Str9.ObjectToDouble();
                }
                catch
                {
                    this.GenErrorMessage(pod, Message, "毛重数据不是数字类型,请重新编辑运单");
                    continue;
                }

                int carType = 0;
                if (pod.TtlOrTplID == 27)
                {
                    if (string.IsNullOrEmpty(pod.Str29))
                    {
                        this.GenErrorMessage(pod, Message, "无整车吨位信息,请重新编辑运单");
                        continue;
                    }

                    try
                    {
                        carType = pod.Str29.ObjectToInt32();
                    }
                    catch
                    {
                        this.GenErrorMessage(pod, Message, "整车吨位信息有误(2|5|10|15|20),,请重新编辑运单");
                        continue;
                    }
                }

                SettledPod settledPod = new SettledPod()
                {
                    ProjectID           = pod.ProjectID,
                    CustomerOrderNumber = pod.CustomerOrderNumber,
                    SystemNumber        = pod.SystemNumber,
                    PodID                 = pod.ID,
                    SettledNumber         = settledNumber,
                    SettledType           = 0,
                    CustomerOrShipperID   = pod.CustomerID.Value,
                    CustomerOrShipperName = pod.CustomerName,
                    StartCityID           = pod.StartCityID.Value,
                    StartCityName         = pod.StartCityName,
                    EndCityID             = pod.EndCityID.Value,
                    EndCityName           = pod.EndCityName,
                    ShipperTypeID         = pod.ShipperTypeID.Value,
                    ShipperTypeName       = pod.ShipperTypeName,
                    PODTypeID             = pod.PODTypeID.Value,
                    PODTypeName           = pod.PODTypeName,
                    TtlOrTplID            = pod.TtlOrTplID.Value,
                    TtlOrTplName          = pod.TtlOrTplName,
                    ActualDeliveryDate    = pod.ActualDeliveryDate.Value,
                    BoxNumber             = pod.BoxNumber,
                    Weight                = weight,
                    Volume                = pod.Volume,
                    GoodsNumber           = pod.GoodsNumber,
                    BAFAmt                = 0,
                    PointAmt              = 0,
                    OtherAmt              = 0,
                    Amt1              = 0,
                    Amt2              = 0,
                    Amt3              = 0,
                    Amt4              = 0,
                    Amt5              = 0,
                    Str1              = string.Empty,
                    Str2              = string.Empty,
                    Str3              = string.Empty,
                    Str4              = string.Empty,
                    Str5              = string.Empty,
                    Remark            = string.Empty,
                    DateTime1         = null,
                    DateTime2         = null,
                    CreateTime        = DateTime.Now,
                    Creator           = Creator,
                    InvoiceID         = 0,
                    RelatedCustomerID = pod.CustomerID,
                    IsAudit           = true
                };

                IEnumerable <QuotedPrice> prices = quotedPrice.Where(q =>
                                                                     q.ProjectID == ProjectID && q.Target == 0 && q.TargetID == pod.CustomerID && q.StartCityName == pod.StartCityName && q.EndCityName == pod.EndCityName &&
                                                                     q.PodTypeName == pod.PODTypeName && q.ShipperTypeName == pod.ShipperTypeName && q.TplOrTtlName == pod.TtlOrTplName &&
                                                                     q.EffectiveStartTime <= pod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= pod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));

                if (prices == null || !prices.Any())
                {
                    this.GenErrorMessage(pod, Message, " 无对应报价,请先配置");
                    continue;
                }

                QuotedPrice price;
                QuotedPrice miniPrice = prices.FirstOrDefault(p => p.StartVal == 20 && p.EndVal == 50);

                if (miniPrice == null)
                {
                    this.GenErrorMessage(pod, Message, " 系统报价有问题!");
                    continue;
                }

                if (pod.TtlOrTplID == 26)//零担
                {
                    price = prices.FirstOrDefault(p => p.StartVal < weight && p.EndVal >= weight);

                    if (price == null)
                    {
                        this.GenErrorMessage(pod, Message, " 根据运单毛重,未找到对应报价");
                        continue;
                    }
                    var region = ApplicationConfigHelper.GetRegions().FirstOrDefault(r => r.ID == pod.EndCityID);
                    if ((pod.StartCityID == 10 && pod.EndCityID == 10) || (pod.StartCityID == 10 && region.SupperID == 10))
                    {
                        settledPod.ShipAmt = price.Price;
                    }
                    else
                    {
                        if (weight <= this._settledByItem)
                        {
                            settledPod.ShipAmt = price.Price;
                        }
                        else
                        {
                            settledPod.ShipAmt = price.Price * (decimal)weight;
                            if (settledPod.ShipAmt < miniPrice.Price)
                            {
                                settledPod.ShipAmt = miniPrice.Price;
                            }
                        }
                    }
                }
                else
                {
                    price = prices.First();
                    if (price == null || string.IsNullOrEmpty(price.Remark))
                    {
                        this.GenErrorMessage(pod, Message, "报价录入有误");
                        continue;
                    }

                    var     holeCarPrices = price.Remark.Split(';');
                    decimal holeCarPrice  = 0;
                    try
                    {
                        holeCarPrice = holeCarPrices.FirstOrDefault(p => p.Split(':')[0].ObjectToInt32() == carType).Split(':')[1].ObjectToDecimal();
                    }
                    catch
                    {
                        this.GenErrorMessage(pod, Message, "报价录入有误");
                        continue;
                    }

                    if (holeCarPrice == 0)
                    {
                        this.GenErrorMessage(pod, Message, "无对应报价,请录入报价");
                        continue;
                    }

                    settledPod.ShipAmt = holeCarPrice;
                }

                if (pod.Str22 == "1")
                {
                    if (string.Equals(pod.Str30.Trim(), "支票"))
                    {
                        settledPod.ShipAmt += this._receiveForCheck;
                    }
                    else
                    {
                        settledPod.ShipAmt += this._receiveForCache;
                    }
                }

                settledPods.Add(settledPod);
            }

            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 0
                });
            }
        }
Example #14
0
        public void SettledPodForPay(IEnumerable <long> PodIDs, string creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, System.Text.StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }
            PodService service = new PodService();

            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }


            string             settledNumber = Guid.NewGuid().ToString();
            IList <SettledPod> settledPods   = new List <SettledPod>();

            #region 海润光伏供应链
            if (podsResponse.Result.First().CustomerID == 28)
            {
                podsResponse.Result.Each((i, p) =>
                {
                    decimal shipAmt = 0;
                    if (!string.IsNullOrEmpty(p.Str7))
                    {
                        try
                        {
                            shipAmt = p.Str7.ObjectToDecimal();
                        }
                        catch
                        {
                            this.GenErrorMessage_ByPod(p, Message, "支出金额格式有误。");
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(p.Str6))
                        {
                            try
                            {
                                shipAmt = p.Str6.ObjectToDecimal() * (0.86).ObjectToDecimal();
                            }
                            catch
                            {
                                this.GenErrorMessage_ByPod(p, Message, "收入金额格式有误。");
                            }
                        }
                        else
                        {
                            this.GenErrorMessage_ByPod(p, Message, "收入金额支出金额都为空。");
                        }
                    }

                    SettledPod settledPod = new SettledPod()
                    {
                        ProjectID           = ProjectID,
                        CustomerOrderNumber = p.CustomerOrderNumber,
                        SystemNumber        = p.SystemNumber,
                        PodID                 = p.ID,
                        SettledNumber         = settledNumber,
                        SettledType           = 1,
                        CustomerOrShipperID   = p.ShipperID.Value,
                        CustomerOrShipperName = p.ShipperTypeName,
                        StartCityID           = p.StartCityID.Value,
                        StartCityName         = p.StartCityName,
                        EndCityID             = p.EndCityID.Value,
                        EndCityName           = p.EndCityName,
                        ShipperTypeID         = p.ShipperTypeID.Value,
                        ShipperTypeName       = p.ShipperTypeName,
                        PODTypeID             = p.PODTypeID.Value,
                        PODTypeName           = p.PODTypeName,
                        TtlOrTplID            = p.TtlOrTplID.Value,
                        TtlOrTplName          = p.TtlOrTplName,
                        ActualDeliveryDate    = p.ActualDeliveryDate.Value,
                        BoxNumber             = p.BoxNumber,
                        Weight                = p.Weight,
                        Volume                = p.Volume,
                        GoodsNumber           = p.GoodsNumber,
                        ShipAmt               = shipAmt,
                        BAFAmt                = 0,
                        PointAmt              = 0,
                        OtherAmt              = 0,
                        Amt1              = 0,
                        Amt2              = 0,
                        Amt3              = 0,
                        Amt4              = 0,
                        Amt5              = 0,
                        Str1              = string.Empty,
                        Str2              = string.Empty,
                        Str3              = string.Empty,
                        Str4              = string.Empty,
                        Str5              = string.Empty,
                        Remark            = string.Empty,
                        DateTime1         = null,
                        DateTime2         = null,
                        CreateTime        = DateTime.Now,
                        Creator           = creator,
                        InvoiceID         = 0,
                        RelatedCustomerID = p.CustomerID,
                        IsAudit           = true
                    };

                    settledPods.Add(settledPod);
                });
            }
            #endregion

            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 1
                });
            }
        }
Example #15
0
        public void SettledPodForPay(IEnumerable <long> PodIDs, string creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, System.Text.StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service             = new PodService();
            var        groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
            {
                IDs = PodIDs, SettledType = 1
            });

            if (!groupedPodsResponse.IsSuccess)
            {
                throw groupedPodsResponse.Exception;
            }

            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }

            var quotedPrice = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);

            string             settledNumber = Guid.NewGuid().ToString();
            IList <SettledPod> settledPods   = new List <SettledPod>();
            long relatedCustomerID           = 0;

            #region Adidas
            if (podsResponse.Result.First().CustomerID == 1)
            {
                relatedCustomerID = 1;

                var Data = from q in groupedPodsResponse.Result.GroupedPods
                           group q by new { q.ActualDeliveryDate, q.PODTypeName } into g
                let ids = g.Select(b => b.PodIDs.ToString()).ToArray()
                          select new
                {
                    g.Key,
                    ActualDeliveryDate = g.Max(a => a.ActualDeliveryDate),
                    ShipperTypeName    = g.Max(a => a.ShipperTypeName),
                    BoxNumber          = g.Sum(a => a.BoxNumber),
                    Volume             = g.Sum(a => a.Volume),
                    PodIDs             = string.Join("|", ids),
                };
                var DataFee = from q in podsResponse.Result
                              where Regex.IsMatch(q.Str7.Substring(0, 1), @"^[\u4e00-\u9fa5]+$")
                              group q by new { q.ActualDeliveryDate, q.PODTypeName, q.EndCityName, q.StartCityName, q.ShipperTypeName } into g
                    select new
                {
                    g.Key,
                    BoxNumber = g.Sum(a => a.BoxNumber)
                };
                //groupedPodsResponse.Result.GroupedPods.GroupBy(q => q.ActualDeliveryDate).Select(a=>a.Sum(q=>q.BoxNumber));
                foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
                {
                    double cube      = gPod.BoxNumber / 12;
                    double BoxNumber = 0;
                    foreach (var item in DataFee)
                    {
                        if (gPod.ActualDeliveryDate == item.Key.ActualDeliveryDate.ToString() && gPod.EndCityName == item.Key.EndCityName && gPod.StartCityName == item.Key.StartCityName && gPod.ShipperTypeName == item.Key.ShipperTypeName)
                        {
                            BoxNumber += (double)item.BoxNumber;
                        }
                    }

                    var         innerPodIDs = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                    QuotedPrice price;
                    price = quotedPrice.FirstOrDefault(q =>
                                                       q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                       q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                       q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));

                    if (price == null)
                    {
                        if (string.Equals(gPod.PODTypeName.Trim(), "退货运单", StringComparison.OrdinalIgnoreCase))
                        {
                            price = quotedPrice.FirstOrDefault(q =>
                                                               q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.EndCityName.Trim() && q.EndCityName.Trim() == gPod.StartCityName.Trim() &&
                                                               q.PodTypeName.Trim() == "出货运单" && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                               q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));

                            if (price == null)
                            {
                                //this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统报价,出货运单也无报价,请先配置报价.");
                                continue;
                            }

                            price.Price  = price.Price;
                            price.Price *= (decimal)0.9;
                        }
                        else
                        {
                            // this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统对应报价,请先配置报价.");
                            continue;
                        }
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }

                    decimal shipAmt = price.Price;

                    foreach (var id in innerPodIDs)
                    {
                        decimal delivery = 0;
                        //提货费
                        if (cube < 30)
                        {
                            var a = Data.First();
                            if (innerPodIDs.First().ToString() == id.ToString())
                            {
                                delivery = 300;
                            }
                        }

                        var originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                        //装卸费
                        if (gPod.PODTypeName == "退货运单")
                        {
                            delivery = (delivery + (decimal)(originalPod.BoxNumber / 12) * (decimal)4.2) * (decimal)0.9;
                        }
                        else
                        {
                            delivery += (decimal)(originalPod.BoxNumber / 12) * (decimal)4.2;
                        }

                        SettledPod settledPod = new SettledPod()
                        {
                            ProjectID           = originalPod.ProjectID,
                            CustomerOrderNumber = originalPod.CustomerOrderNumber,
                            SystemNumber        = originalPod.SystemNumber,
                            PodID                 = id,
                            SettledNumber         = settledNumber,
                            SettledType           = 1,
                            CustomerOrShipperID   = originalPod.ShipperID.Value,
                            CustomerOrShipperName = originalPod.ShipperName,
                            StartCityID           = originalPod.StartCityID.Value,
                            StartCityName         = originalPod.StartCityName,
                            EndCityID             = originalPod.EndCityID.Value,
                            EndCityName           = originalPod.EndCityName,
                            ShipperTypeID         = originalPod.ShipperTypeID.Value,
                            ShipperTypeName       = originalPod.ShipperTypeName,
                            PODTypeID             = originalPod.PODTypeID.Value,
                            PODTypeName           = originalPod.PODTypeName,
                            TtlOrTplID            = originalPod.TtlOrTplID.Value,
                            TtlOrTplName          = originalPod.TtlOrTplName,
                            ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                            BoxNumber             = originalPod.BoxNumber,
                            Weight                = originalPod.Weight,
                            Volume                = originalPod.Volume,
                            GoodsNumber           = originalPod.GoodsNumber,
                            ShipAmt               = shipAmt * (decimal)(originalPod.BoxNumber / 12),
                            BAFAmt                = 0,
                            PointAmt              = 0,

                            OtherAmt          = delivery,
                            Amt1              = 0,
                            Amt2              = 0,
                            Amt3              = 0,
                            Amt4              = 0,
                            Amt5              = 0,
                            Str1              = string.Empty,
                            Str2              = string.Empty,
                            Str3              = string.Empty,
                            Str4              = price.Price.ToString(),
                            Str5              = string.Empty,
                            Remark            = string.Empty,
                            DateTime1         = null,
                            DateTime2         = null,
                            CreateTime        = DateTime.Now,
                            Creator           = creator,
                            InvoiceID         = 0,
                            RelatedCustomerID = originalPod.CustomerID,
                            IsAudit           = true
                        };

                        settledPods.Add(settledPod);
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }

                    if (string.Equals(gPod.PODTypeName.Trim(), "出货运单", StringComparison.OrdinalIgnoreCase))
                    {
                        if ((BoxNumber / 12) <= 10)
                        {
                            var temp = (from p in podsResponse.Result.Where(k => innerPodIDs.Contains(k.ID) && Regex.IsMatch(k.Str7.Substring(0, 1), @"^[\u4e00-\u9fa5]+$")) group p by p.ID into g select new { g.Key, Pods = g });

                            if (temp != null)
                            {
                                temp.Each((i, k) =>
                                {
                                    var innPodIDs = k.Pods.Select(p => p.ID);

                                    if (1 == 1)
                                    {
                                        settledPods.First(s => s.PodID == innPodIDs.First()).PointAmt = 60;
                                        settledPods.First(s => s.PodID == innPodIDs.First()).Remark  += "陆久出货,同天低于10方收取60";
                                    }
                                });
                            }
                        }
                    }
                    //if (string.Equals(gPod.PODTypeName.Trim(), "调拨运单", StringComparison.OrdinalIgnoreCase))
                    //{
                    //    var temp = (from p in podsResponse.Result.Where(k => innerPodIDs.Contains(k.ID) && k.PODTypeName.Trim() == "调拨运单" && Char.IsLetter(k.Str7, 1)) group p by p.ID into g select new { g.Key, Pods = g });
                    //    if (temp != null)
                    //    {
                    //        temp.Each((i, k) =>
                    //        {
                    //            var innPodIDs = k.Pods.Select(p => p.ID);
                    //            if (1 == 1)
                    //            {
                    //                settledPods.First(s => s.PodID == innerPodIDs.First()).PointAmt = 60;
                    //                settledPods.First(s => s.PodID == innerPodIDs.First()).Remark += "陆久调拨,";
                    //            }
                    //        });
                    //    }
                    //}
                    if (string.Equals(gPod.PODTypeName.Trim(), "退货运单", StringComparison.OrdinalIgnoreCase))
                    {
                        if ((BoxNumber / 12) <= 10)
                        {
                            var temp = (from p in podsResponse.Result.Where(k => innerPodIDs.Contains(k.ID) && Regex.IsMatch(k.Str7.Substring(0, 1), @"^[\u4e00-\u9fa5]+$")) group p by p.ID into g select new { g.Key, Pods = g });

                            if (temp != null)
                            {
                                temp.Each((i, k) =>
                                {
                                    var innPodIDs = k.Pods.Select(p => p.ID);

                                    if (1 == 1)
                                    {
                                        settledPods.First(s => s.PodID == innPodIDs.First()).PointAmt = (decimal)(60 * 0.9);
                                        settledPods.First(s => s.PodID == innPodIDs.First()).Remark  += "陆久出货,同天低于10方收取60";
                                    }
                                });
                            }
                        }
                    }
                }
            }
            #endregion

            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });

                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 1
                });
            }
        }
Example #16
0
        public void SettledPodForPay(IEnumerable <long> PodIDs, string creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, System.Text.StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service             = new PodService();
            var        groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
            {
                IDs = PodIDs, SettledType = 1
            });

            if (!groupedPodsResponse.IsSuccess)
            {
                throw groupedPodsResponse.Exception;
            }

            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }

            var quotedPrice = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);

            string             settledNumber = Guid.NewGuid().ToString();
            IList <SettledPod> settledPods   = new List <SettledPod>();
            long relatedCustomerID           = 0;

            #region Adidas
            if (podsResponse.Result.First().CustomerID == 1)
            {
                relatedCustomerID = 1;
                foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
                {
                    double      cube        = gPod.BoxNumber / 12;
                    var         innerPodIDs = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                    QuotedPrice price       = new QuotedPrice();
                    QuotedPrice tempPrice;
                    tempPrice = quotedPrice.FirstOrDefault(q =>
                                                           q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                           q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                           q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));
                    if (tempPrice == null)
                    {
                        if (string.Equals(gPod.PODTypeName.Trim(), "退货运单", StringComparison.OrdinalIgnoreCase))
                        {
                            tempPrice = quotedPrice.FirstOrDefault(q =>
                                                                   q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.EndCityName.Trim() && q.EndCityName.Trim() == gPod.StartCityName.Trim() &&
                                                                   q.PodTypeName.Trim() == "出货运单" && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                                   q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));

                            if (tempPrice == null)
                            {
                                this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统报价,出货运单也无报价,请先配置报价.");
                                continue;
                            }

                            price.Price  = tempPrice.Price;
                            price.Price *= (decimal)0.9;
                        }
                        else
                        {
                            this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统对应报价,请先配置报价.");
                            continue;
                        }
                    }
                    else
                    {
                        price.Price = tempPrice.Price;
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }

                    decimal shipAmt = price.Price * (decimal)cube;

                    foreach (var id in innerPodIDs)
                    {
                        var        originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                        SettledPod settledPod  = new SettledPod()
                        {
                            ProjectID           = originalPod.ProjectID,
                            CustomerOrderNumber = originalPod.CustomerOrderNumber,
                            SystemNumber        = originalPod.SystemNumber,
                            PodID                 = id,
                            SettledNumber         = settledNumber,
                            SettledType           = 1,
                            CustomerOrShipperID   = originalPod.ShipperID.Value,
                            CustomerOrShipperName = originalPod.ShipperName,
                            StartCityID           = originalPod.StartCityID.Value,
                            StartCityName         = originalPod.StartCityName,
                            EndCityID             = originalPod.EndCityID.Value,
                            EndCityName           = originalPod.EndCityName,
                            ShipperTypeID         = originalPod.ShipperTypeID.Value,
                            ShipperTypeName       = originalPod.ShipperTypeName,
                            PODTypeID             = originalPod.PODTypeID.Value,
                            PODTypeName           = originalPod.PODTypeName,
                            TtlOrTplID            = originalPod.TtlOrTplID.Value,
                            TtlOrTplName          = originalPod.TtlOrTplName,
                            ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                            BoxNumber             = originalPod.BoxNumber,
                            Weight                = originalPod.Weight,
                            Volume                = originalPod.Volume,
                            GoodsNumber           = originalPod.GoodsNumber,
                            ShipAmt               = shipAmt * (decimal)(originalPod.BoxNumber / gPod.BoxNumber),
                            BAFAmt                = 0,
                            PointAmt              = 0,
                            OtherAmt              = 0,
                            Amt1              = 0,
                            Amt2              = 0,
                            Amt3              = 0,
                            Amt4              = 0,
                            Amt5              = 0,
                            Str1              = string.Empty,
                            Str2              = string.Empty,
                            Str3              = string.Empty,
                            Str4              = price.Price.ToString(),
                            Str5              = string.Empty,
                            Remark            = string.Empty,
                            DateTime1         = null,
                            DateTime2         = null,
                            CreateTime        = DateTime.Now,
                            Creator           = creator,
                            InvoiceID         = 0,
                            RelatedCustomerID = originalPod.CustomerID,
                            IsAudit           = true
                        };

                        settledPods.Add(settledPod);
                    }
                }
            }
            #endregion
            #region Akzo
            if (podsResponse.Result.First().CustomerID == 7)
            {
                relatedCustomerID = 7;
                //var groupedModels = podsResponse.Result.GroupBy(s => new { s.ActualDeliveryDate,s.Str17}).Select(g => new { models = g.Key, Pods = g.Select(k => { return k; }) });
                var         groupedModels    = podsResponse.Result.GroupBy(s => new { s.ActualDeliveryDate, s.Str17 }).Select(g => new { models = g.Key, count = g.Count() });
                IList <Pod> settelModelspods = new List <Pod>();
                foreach (var groupedModel in groupedModels)
                {
                    DateTime time       = (DateTime)groupedModel.models.ActualDeliveryDate;
                    string   CarModels  = groupedModel.models.Str17;
                    int      placeCount = 0;
                    decimal  shipAmt    = 0;
                    double   Models     = 0;
                    double   weight     = 0;
                    string   price      = "";
                    foreach (var item in podsResponse.Result)
                    {
                        if (item.ActualDeliveryDate == time && item.Str17 == CarModels)
                        {
                            var originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == item.ID);
                            settelModelspods.Add(originalPod);
                        }
                    }
                    foreach (var settelModelspod in settelModelspods)
                    {
                        weight += (double)settelModelspod.Weight;
                    }
                    if (settelModelspods[0].Str17 == "小面包车" || settelModelspods[0].Str17 == "金杯车")
                    {
                        placeCount = settelModelspods.GroupBy(s => new { s.Str3 }).Select(g => new { str3 = g.Key }).Count();
                        shipAmt    = 260 + (placeCount - 1) * 30;
                        price      = "按车结算";
                    }
                    else
                    {
                        Models = string.IsNullOrEmpty(settelModelspods[0].Str17) ? 0 : Convert.ToDouble(settelModelspods[0].Str17);
                        if (Models == 0)
                        {
                            this.GenErrorMessage_ByPod(podsResponse.Result.FirstOrDefault(p => p.ID == settelModelspods[0].ID), Message, "请设置车型");
                            continue;
                        }
                        if (Models <= 5.5)
                        {
                            placeCount = settelModelspods.GroupBy(s => new { s.Str3 }).Select(g => new { str3 = g.Key, count = g.Count() }).Count();
                            shipAmt    = 260 + (placeCount - 1) * 50;
                            price      = "按车结算";
                        }
                        if (Models >= 6.2)
                        {
                            if (weight < 10000)
                            {
                                weight = 10000;
                            }
                            shipAmt = (decimal)weight / 1000 * 70;
                            price   = (0.07).ToString();
                        }
                    }

                    foreach (var settelModelspod in settelModelspods)
                    {
                        SettledPod settledPod = new SettledPod()
                        {
                            ProjectID           = settelModelspod.ProjectID,
                            CustomerOrderNumber = settelModelspod.CustomerOrderNumber,
                            SystemNumber        = settelModelspod.SystemNumber,
                            PodID                 = settelModelspod.ID,
                            SettledNumber         = settledNumber,
                            SettledType           = 1,
                            CustomerOrShipperID   = settelModelspod.ShipperID.Value,
                            CustomerOrShipperName = settelModelspod.ShipperName,
                            StartCityID           = settelModelspod.StartCityID.Value,
                            StartCityName         = settelModelspod.StartCityName,
                            EndCityID             = settelModelspod.EndCityID.Value,
                            EndCityName           = settelModelspod.EndCityName,
                            ShipperTypeID         = settelModelspod.ShipperTypeID.Value,
                            ShipperTypeName       = settelModelspod.ShipperTypeName,
                            PODTypeID             = settelModelspod.PODTypeID.Value,
                            PODTypeName           = settelModelspod.PODTypeName,
                            TtlOrTplID            = settelModelspod.TtlOrTplID.Value,
                            TtlOrTplName          = settelModelspod.TtlOrTplName,
                            ActualDeliveryDate    = settelModelspod.ActualDeliveryDate.Value,
                            BoxNumber             = settelModelspod.BoxNumber,
                            Weight                = settelModelspod.Weight,
                            Volume                = settelModelspod.Volume,
                            GoodsNumber           = settelModelspod.GoodsNumber,
                            ShipAmt               = shipAmt * (decimal)(settelModelspod.Weight / weight),
                            BAFAmt                = 0,
                            PointAmt              = 0,
                            OtherAmt              = 0,
                            Amt1              = 0,
                            Amt2              = 0,
                            Amt3              = 0,
                            Amt4              = 0,
                            Amt5              = 0,
                            Str1              = string.Empty,
                            Str2              = string.Empty,
                            Str3              = string.Empty,
                            Str4              = price,
                            Str5              = string.Empty,
                            Remark            = time.ToString() + "|" + CarModels,
                            DateTime1         = null,
                            DateTime2         = null,
                            CreateTime        = DateTime.Now,
                            Creator           = creator,
                            InvoiceID         = 0,
                            RelatedCustomerID = settelModelspod.CustomerID,
                            IsAudit           = true
                        };
                        settledPods.Add(settledPod);
                    }
                    settelModelspods.Clear();
                }
            }
            #endregion
            #region Nike
            if (podsResponse.Result.First().CustomerID == 8)
            {
                //门店调拨(按正常的同天同城结算,但报价是按箱并不与承运商做关联结算,)
                var podsTransfersResponses = podsResponse.Result.Where(s => s.PODTypeName == "门店调拨").GroupBy(x => new { x.ActualDeliveryDate, x.StartCityName, x.EndCityName })
                                             .Select(g => new
                {
                    Peo   = g.Key,
                    count = g.Count(),
                    pods  = g.Select(k => { return(k); })
                });
                foreach (var pods in podsTransfersResponses)
                {
                    double boxnumner = 0;
                    foreach (var pod in pods.pods)
                    {
                        if (string.IsNullOrEmpty(pod.BoxNumber.ToString()))
                        {
                            this.GenErrorMessage_ByPod(pod, Message, " 请设置该运单的箱数");
                            continue;
                        }
                        boxnumner += (double)pod.BoxNumber;
                    }
                    Settlement(settledNumber, ProjectID, Message, 0, boxnumner, pods.pods, settledPods, quotedPrice);
                }
            }
            #endregion

            #region AdidasPurchase
            if (podsResponse.Result.First().CustomerID == 13)
            {
                var newpodsResponse = from q in podsResponse.Result
                                      //where q.StartCityName != "天津" && q.StartCityName != "苏州"
                                      group q by new { q.ActualDeliveryDate, q.EndCityName, q.ShipperID }
                into r
                    select new
                {
                    ActualDeliveryDate = r.Key.ActualDeliveryDate.DateTimeToString(),
                    EndCityName        = r.Key.EndCityName,
                    ShipperID          = r.Key.ShipperID,
                    Volume             = r.Sum(a => a.Volume),
                    BoxNumber          = r.Sum(a => a.BoxNumber)
                };
                relatedCustomerID = 13;
                foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
                {
                    double cube        = gPod.Volume;
                    var    innerPodIDs = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                    //gPod.StartCityName = "广东";
                    foreach (var item in newpodsResponse)
                    {
                        if (item.ActualDeliveryDate.ToString() == gPod.ActualDeliveryDate && item.EndCityName == gPod.EndCityName)
                        {
                            cube = Convert.ToDouble(item.Volume);
                        }
                    }
                    QuotedPrice price;
                    price = quotedPrice.FirstOrDefault(q =>
                                                       q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                       q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                       q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));
                    if (price == null)
                    {
                        this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统对应报价,请先配置报价.");
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }
                    decimal shipAmt  = price.Price;
                    decimal delivery = 0;
                    foreach (var id in innerPodIDs)
                    {
                        //提货费 同天同城收一票
                        //if (cube < 40)
                        //{
                        //    var a = innerPodIDs.First();
                        //    if (innerPodIDs.First().ToString() == id.ToString())
                        //    {
                        //        switch (gPod.EndCityName)
                        //        {
                        //            case "广州":
                        //                delivery = 15;
                        //                break;
                        //            case "清远":
                        //                delivery = 25;
                        //                break;
                        //            case "云浮":
                        //                delivery = 25;
                        //                break;
                        //            case "东莞":
                        //                delivery = 25;
                        //                break;
                        //            case "中山":
                        //                delivery = 25;
                        //                break;
                        //            case "佛山":
                        //                delivery = 25;
                        //                break;
                        //            case "惠州":
                        //                delivery = 25;
                        //                break;
                        //            case "河源":
                        //                delivery = 25;
                        //                break;
                        //            default:
                        //                delivery = 0;
                        //                break;
                        //        }
                        //    }
                        //}
                        var originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                        //卸货费
                        //decimal unload = 0;
                        //if (gPod.EndCityName == "苏州")
                        //{
                        //    unload = (decimal)4.2;
                        //}
                        //else if (gPod.EndCityName == "广州")
                        //{
                        //    unload = cube< 150 ? (decimal)5.5 : (decimal)5;
                        //}
                        SettledPod settledPod = new SettledPod()
                        {
                            ProjectID           = originalPod.ProjectID,
                            CustomerOrderNumber = originalPod.CustomerOrderNumber,
                            SystemNumber        = originalPod.SystemNumber,
                            PodID                 = id,
                            SettledNumber         = settledNumber,
                            SettledType           = 1,
                            CustomerOrShipperID   = originalPod.ShipperID.Value,
                            CustomerOrShipperName = originalPod.ShipperName,
                            StartCityID           = originalPod.StartCityID.Value,
                            StartCityName         = originalPod.StartCityName,
                            EndCityID             = originalPod.EndCityID.Value,
                            EndCityName           = originalPod.EndCityName,
                            ShipperTypeID         = originalPod.ShipperTypeID.Value,
                            ShipperTypeName       = originalPod.ShipperTypeName,
                            PODTypeID             = originalPod.PODTypeID.Value,
                            PODTypeName           = originalPod.PODTypeName,
                            TtlOrTplID            = originalPod.TtlOrTplID.Value,
                            TtlOrTplName          = originalPod.TtlOrTplName,
                            ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                            BoxNumber             = originalPod.BoxNumber,
                            Weight                = originalPod.Weight,
                            Volume                = originalPod.Volume,
                            GoodsNumber           = originalPod.GoodsNumber,
                            ShipAmt               = shipAmt * (decimal)originalPod.Volume,
                            BAFAmt                = 0,
                            PointAmt              = 0,
                            OtherAmt              = 0,//unload * (decimal)originalPod.Volume + delivery * (decimal)originalPod.Volume,
                            Amt1              = 0,
                            Amt2              = 0,
                            Amt3              = 0,
                            Amt4              = 0,
                            Amt5              = 0,
                            Str1              = string.Empty,
                            Str2              = string.Empty,
                            Str3              = string.Empty,
                            Str4              = price.Price.ToString(),
                            Str5              = string.Empty,
                            Remark            = "其他费用=提货费+卸货费",
                            DateTime1         = null,
                            DateTime2         = null,
                            CreateTime        = DateTime.Now,
                            Creator           = creator,
                            InvoiceID         = 0,
                            RelatedCustomerID = originalPod.CustomerID,
                            IsAudit           = true
                        };

                        settledPods.Add(settledPod);
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }
                    //var temp = (from p in podsResponse.Result.Where(k => innerPodIDs.Contains(k.ID)) group p by p.ID into g select new { g.Key, Pods = g });
                    //if (temp != null)
                    //{
                    //    temp.Each((i, k) =>
                    //    {
                    //        var innPodIDs = k.Pods.Select(p => p.ID);

                    //        if (1 == 1)
                    //        {
                    //            settledPods.First(s => s.PodID == innPodIDs.First()).OtherAmt = 4.2*k.Pods.Select(a=>a.Volume);
                    //            settledPods.First(s => s.PodID == innPodIDs.First()).Remark += "成耀出货,同天同城同客户点费135";
                    //        }
                    //    });
                    //}
                }
            }
            #endregion
            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 1
                });
            }
        }
Example #17
0
        public void SettledPodForReceive(IEnumerable <long> PodIDs, string Creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service = new PodService();
            //var forSettledPodsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest() { PodIDs = PodIDs });

            //if (!forSettledPodsResponse.IsSuccess)
            //{
            //    throw forSettledPodsResponse.Exception;
            //}

            var groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
            {
                IDs = PodIDs, SettledType = 0
            });

            if (!groupedPodsResponse.IsSuccess)
            {
                throw groupedPodsResponse.Exception;
            }

            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }

            var                quotedPrices  = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);
            string             settledNumber = Guid.NewGuid().ToString();
            IList <SettledPod> settledPods   = new List <SettledPod>();

            #region 空运结算
            //空运运单
            IList <Pod> airFreights = new List <Pod>();
            foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
            {
                double  airFreightPrice     = 0;
                decimal airFreighShipAmt    = 0;
                double  airFreightBoxNumber = 0;
                var     innerPodIDs         = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                var     tempOriginalPods    = podsResponse.Result.Where(p => innerPodIDs.Contains(p.ID));
                foreach (var tempOriginalPod in tempOriginalPods)
                {
                    if (string.Equals(tempOriginalPod.ShipperTypeName, "空运", StringComparison.OrdinalIgnoreCase))
                    {
                        airFreights.Add(tempOriginalPod);
                    }
                }
                if (airFreights.Count > 0)
                {
                    foreach (var airFreight in airFreights)
                    {
                        airFreightBoxNumber = (1000 / 6.0) * (double)(airFreight.BoxNumber / 11);
                        if (airFreightBoxNumber > 500)
                        {
                            airFreightPrice = 11.44;
                        }
                        if (airFreightBoxNumber > 100)
                        {
                            airFreightPrice = 13.52;
                        }
                        else
                        {
                            airFreightPrice = 16.64;
                        }
                        if (airFreight.BoxNumber == null)
                        {
                            this.GenErrorMessage(airFreight, Message, "请先设置货物的箱数");
                            continue;
                        }
                        airFreighShipAmt = (decimal)airFreightBoxNumber * (decimal)airFreightPrice;
                        SettledPod settledPod = new SettledPod()
                        {
                            ProjectID           = airFreight.ProjectID,
                            CustomerOrderNumber = airFreight.CustomerOrderNumber,
                            SystemNumber        = airFreight.SystemNumber,
                            PodID                 = airFreight.ID,
                            SettledNumber         = settledNumber,
                            SettledType           = 0,
                            CustomerOrShipperID   = airFreight.CustomerID.Value,
                            CustomerOrShipperName = airFreight.CustomerName,
                            StartCityID           = airFreight.StartCityID.Value,
                            StartCityName         = airFreight.StartCityName,
                            EndCityID             = airFreight.EndCityID.Value,
                            EndCityName           = airFreight.EndCityName,
                            ShipperTypeID         = airFreight.ShipperTypeID.Value,
                            ShipperTypeName       = airFreight.ShipperTypeName,
                            PODTypeID             = airFreight.PODTypeID.Value,
                            PODTypeName           = airFreight.PODTypeName,
                            TtlOrTplID            = airFreight.TtlOrTplID.Value,
                            TtlOrTplName          = airFreight.TtlOrTplName,
                            ActualDeliveryDate    = airFreight.ActualDeliveryDate.Value,
                            BoxNumber             = airFreight.BoxNumber,
                            Weight                = airFreight.Weight,
                            Volume                = airFreight.Volume,
                            GoodsNumber           = airFreight.GoodsNumber,
                            ShipAmt               = airFreighShipAmt,
                            BAFAmt                = 0,
                            PointAmt              = 0,
                            OtherAmt              = 0,
                            Amt1              = 0,
                            Amt2              = 0,
                            Amt3              = 0,
                            Amt4              = 0,
                            Amt5              = 0,
                            Str1              = string.Empty,
                            Str2              = string.Empty,
                            Str3              = string.Empty,
                            Str4              = airFreightPrice.ToString(),
                            Str5              = string.Empty,
                            Remark            = string.Empty,
                            DateTime1         = null,
                            DateTime2         = null,
                            CreateTime        = DateTime.Now,
                            Creator           = Creator,
                            InvoiceID         = 0,
                            RelatedCustomerID = airFreight.CustomerID,
                            IsAudit           = true
                        };

                        settledPods.Add(settledPod);
                    }
                }
                airFreights.Clear();
            }
            #endregion
            #region 公路运算
            //起运城市是太仓CLC、太仓CRW、上海的按同城结算(大仓和工厂直发)
            var podsResponses = podsResponse.Result.Where(s => s.PODTypeName != "退货运单" && s.PODTypeName != "门店调拨" && s.ShipperTypeName != "空运").GroupBy(x => new { x.ActualDeliveryDate, x.EndCityName, })
                                .Select(g => new
            {
                Peo   = g.Key,
                count = g.Count(),
                pods  = g.Select(k => { return(k); })
            });
            //存放发货地点为太仓CLC、太仓CRW、上海的运单(大仓发货、工厂直发)
            IList <Pod> Temporary = new List <Pod>();
            //存放发货地点为广州的运单(工厂直发)
            IList <Pod> guangzhouTemporary = new List <Pod>();
            foreach (var podsRp in podsResponses)
            {
                double boxnumner           = 0;
                double guangzhouzboxnumner = 0;
                double cube           = 0;
                double guangzhouzcube = 0;
                foreach (var pod in podsRp.pods)
                {
                    if (pod.BoxNumber == null)
                    {
                        this.GenErrorMessage(pod, Message, "请先设置货物的箱数");
                        continue;
                    }
                    if (string.Equals(pod.StartCityName.Trim(), "广州", StringComparison.OrdinalIgnoreCase))
                    {
                        guangzhouzboxnumner += (double)pod.BoxNumber;
                        guangzhouTemporary.Add(pod);
                    }
                    else
                    {
                        boxnumner += (double)pod.BoxNumber;
                        Temporary.Add(pod);
                    }
                }
                cube           = boxnumner / 11;
                guangzhouzcube = guangzhouzboxnumner / 11;
                if (Temporary.Count > 0)
                {
                    Settlement(settledNumber, ProjectID, Message, cube, boxnumner, Temporary, settledPods, quotedPrices);
                    Temporary.Clear();
                }
                if (guangzhouTemporary.Count > 0)
                {
                    Settlement(settledNumber, ProjectID, Message, guangzhouzcube, guangzhouzboxnumner, guangzhouTemporary, settledPods, quotedPrices);
                    guangzhouTemporary.Clear();
                }
            }
            //退货运单,目的城市是太仓CLC、太仓CRW、上海的按同城结算
            var ReturnspodsResponses = podsResponse.Result.Where(s => s.PODTypeName == "退货运单" && s.ShipperTypeName != "空运").GroupBy(x => new { x.ActualDeliveryDate, x.StartCityName, })
                                       .Select(g => new
            {
                Peo   = g.Key,
                count = g.Count(),
                pods  = g.Select(k => { return(k); })
            });
            //存放目的地为太仓CLC、太仓CRW、上海的运单(退货运单)
            IList <Pod> ReturnsTemporary = new List <Pod>();
            //存放目的地为广州的运单(退货运单)
            IList <Pod> ReturnsguangzhouTemporary = new List <Pod>();
            foreach (var podsRp in ReturnspodsResponses)
            {
                double Returnsboxnumber           = 0;
                double Returnsguangzhouzboxnumner = 0;
                double Returnscube           = 0;
                double Returnsguangzhouzcube = 0;
                foreach (var pod in podsRp.pods)
                {
                    if (pod.BoxNumber == null)
                    {
                        this.GenErrorMessage(pod, Message, "请先设置货物的箱数");
                        continue;
                    }
                    if (string.Equals(pod.StartCityName.Trim(), "广州", StringComparison.OrdinalIgnoreCase))
                    {
                        Returnsguangzhouzboxnumner += (double)pod.BoxNumber;
                        ReturnsguangzhouTemporary.Add(pod);
                    }
                    else
                    {
                        Returnsboxnumber += (double)pod.BoxNumber;
                        ReturnsTemporary.Add(pod);
                    }
                }
                Returnscube           = Returnsboxnumber / 11;
                Returnsguangzhouzcube = Returnsboxnumber / 11;
                if (ReturnsTemporary.Count > 0)
                {
                    Settlement(settledNumber, ProjectID, Message, Returnscube, Returnsboxnumber, ReturnsTemporary, settledPods, quotedPrices);
                    ReturnsTemporary.Clear();
                }
                if (ReturnsguangzhouTemporary.Count > 0)
                {
                    Settlement(settledNumber, ProjectID, Message, Returnsguangzhouzcube, Returnsguangzhouzboxnumner, ReturnsguangzhouTemporary, settledPods, quotedPrices);
                    ReturnsguangzhouTemporary.Clear();
                }
            }
            #endregion
            //除“华启物流”外都有提货补贴
            var prs = podsResponse.Result.Where(p => p.ShipperName != "华启物流");
            prs.Each((i, e) =>
            {
                settledPods.Each((m, n) => {
                    if (n.PodID == e.ID)
                    {
                        n.OtherAmt = (decimal)n.BoxNumber * (decimal)1.56;
                    }
                });
            });

            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 0
                });
            }
        }
        public void SettledPodForReceive(IEnumerable <long> PodIDs, string Creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service      = new PodService();
            var        podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }

            var                quotedPrice   = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);
            string             settledNumber = Guid.NewGuid().ToString();
            IList <SettledPod> settledPods   = new List <SettledPod>();

            foreach (var pod in podsResponse.Result)
            {
                if (!pod.Weight.HasValue || pod.Weight.Value == 0)
                {
                    this.GenErrorMessage(pod, Message, " 无重量,请先编辑运单重量.");
                    continue;
                }

                if (string.IsNullOrEmpty(pod.Str2))
                {
                    this.GenErrorMessage(pod, Message, " 无OPP编号,请先编辑运单OPP编号.");
                    continue;
                }

                SettledPod settledPod = new SettledPod()
                {
                    ProjectID           = pod.ProjectID,
                    CustomerOrderNumber = pod.CustomerOrderNumber,
                    SystemNumber        = pod.SystemNumber,
                    PodID                 = pod.ID,
                    SettledNumber         = settledNumber,
                    SettledType           = 0,
                    CustomerOrShipperID   = pod.CustomerID.Value,
                    CustomerOrShipperName = pod.CustomerName,
                    StartCityID           = pod.StartCityID.Value,
                    StartCityName         = pod.StartCityName,
                    EndCityID             = pod.EndCityID.Value,
                    EndCityName           = pod.EndCityName,
                    ShipperTypeID         = pod.ShipperTypeID.Value,
                    ShipperTypeName       = pod.ShipperTypeName,
                    PODTypeID             = pod.PODTypeID.Value,
                    PODTypeName           = pod.PODTypeName,
                    TtlOrTplID            = pod.TtlOrTplID.Value,
                    TtlOrTplName          = pod.TtlOrTplName,
                    ActualDeliveryDate    = pod.ActualDeliveryDate.Value,
                    BoxNumber             = pod.BoxNumber,
                    Weight                = pod.Weight,
                    Volume                = pod.Volume,
                    GoodsNumber           = pod.GoodsNumber,
                    BAFAmt                = 0,
                    PointAmt              = 0,
                    OtherAmt              = 0,
                    Amt1              = 0,
                    Amt2              = 0,
                    Amt3              = 0,
                    Amt4              = 0,
                    Amt5              = 0,
                    Str1              = string.Empty,
                    Str2              = string.Empty,
                    Str3              = string.Empty,
                    Str4              = string.Empty,
                    Str5              = string.Empty,
                    Remark            = string.Empty,
                    DateTime1         = null,
                    DateTime2         = null,
                    CreateTime        = DateTime.Now,
                    Creator           = Creator,
                    InvoiceID         = 0,
                    RelatedCustomerID = pod.CustomerID,
                    IsAudit           = true
                };

                IEnumerable <QuotedPrice> prices = quotedPrice.Where(q =>
                                                                     q.ProjectID == ProjectID && q.Target == 0 && q.TargetID == pod.CustomerID && q.StartCityName == pod.StartCityName && q.EndCityName == pod.EndCityName &&
                                                                     q.PodTypeName == pod.PODTypeName && q.ShipperTypeName == pod.ShipperTypeName && q.TplOrTtlName == pod.TtlOrTplName &&
                                                                     q.EffectiveStartTime <= pod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= pod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));

                if (prices == null || !prices.Any())
                {
                    this.GenErrorMessage(pod, Message, " 无对应报价,请先配置.");
                    continue;
                }

                var price = prices.FirstOrDefault();
                if (price == null)
                {
                    throw new Exception("系统出错");
                }

                string priceStr = price.Remark;

                if (string.IsNullOrEmpty(priceStr))
                {
                    this.GenErrorMessage(pod, Message, " 报价字符串为空,不符规定,请重新编辑.");
                    continue;
                }

                IEnumerable <string> priceTotal = priceStr.Split(';');
                if (priceTotal == null || !priceTotal.Any())
                {
                    this.GenErrorMessage(pod, Message, " 报价字符串有问题,不符规定,请重新编辑.");
                    continue;
                }

                int i = 0;
                int j = 0;
                foreach (string str in priceTotal)
                {
                    i++;
                    var temp = str.Split(':');
                    if (temp == null || !temp.Any())
                    {
                        this.GenErrorMessage(pod, Message, " 报价字符串(" + str + ")有问题,不符规定,请重新编辑.");
                        continue;
                    }

                    string oppId = temp[0];
                    if (!string.Equals(oppId, pod.Str2, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    var priceArray = temp[1].Split(',');
                    if (priceArray == null || priceArray.Length != 4)
                    {
                        this.GenErrorMessage(pod, Message, " 报价字符串(" + str + ")有问题,不符规定,请重新编辑.");
                        continue;
                    }

                    decimal firstPrice  = 0;
                    decimal lastPrice   = 0;
                    double  firstWeight = 0;
                    int     type        = 0;

                    try
                    {
                        firstPrice  = priceArray[0].ObjectToDecimal();
                        lastPrice   = priceArray[1].ObjectToDecimal();
                        firstWeight = double.Parse(priceArray[2]);
                        type        = priceArray[3].ObjectToInt32();
                    }
                    catch
                    {
                        this.GenErrorMessage(pod, Message, " 报价字符串(" + str + ")有问题,不符规定,请重新编辑.");
                        continue;
                    }

                    if (firstPrice == 0 || lastPrice == 0 || firstWeight == 0)
                    {
                        this.GenErrorMessage(pod, Message, " 报价字符串(" + str + ")有问题,不符规定,请重新编辑.");
                        continue;
                    }

                    if (pod.Weight.Value <= firstWeight)
                    {
                        settledPod.ShipAmt = firstPrice;
                    }
                    else
                    {
                        var tempWeight    = pod.Weight.Value - firstWeight;
                        var tempWeightInt = Convert.ToInt32(tempWeight);
                        if (type == 0 && tempWeight > tempWeightInt)
                        {
                            tempWeight = tempWeightInt + 1;
                        }

                        settledPod.ShipAmt = firstPrice + (decimal)tempWeight * lastPrice;
                    }

                    settledPods.Add(settledPod);
                    j = 1;
                }

                if (i == priceTotal.Count() && j == 0)
                {
                    this.GenErrorMessage(pod, Message, " 报价字符串不存在与运单匹配的OPP编号,请重新编辑.");
                    continue;
                }
            }

            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 0
                });
            }
        }
        public void SettledPodForReceive(IEnumerable <long> PodIDs, string Creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service = new PodService();
            var        forSettledPodsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!forSettledPodsResponse.IsSuccess)
            {
                throw forSettledPodsResponse.Exception;
            }

            var groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
            {
                IDs = PodIDs, SettledType = 0
            });

            if (!groupedPodsResponse.IsSuccess)
            {
                throw groupedPodsResponse.Exception;
            }

            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }
            var    quotedPrice   = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);
            var    BAF           = ApplicationConfigHelper.GetBAFPrice(ProjectID);
            string settledNumber = Guid.NewGuid().ToString();

            var SXshipper = from q in podsResponse.Result
                            where q.ShipperName == "山晓物流" || q.ShipperName == "陆久物流"
                            group q by new { q.ActualDeliveryDate, q.ShipperID, q.StartCityName, q.EndCityName }//q.ShipperID
            into r
                select new
            {
                ActualDeliveryDate = r.Key.ActualDeliveryDate.DateTimeToString(),
                StartCityName      = r.Key.StartCityName,
                EndCityName        = r.Key.EndCityName,
                ShipperID          = r.Key.ShipperID,
                Volume             = r.Sum(a => a.Volume)
            };
            var newpodsResponse = from q in podsResponse.Result
                                  where q.ShipperName != "山晓物流" && q.ShipperName != "陆久物流"
                                  group q by new { q.ActualDeliveryDate, q.EndCityName }//q.ShipperID
            into r
                select new
            {
                ActualDeliveryDate = r.Key.ActualDeliveryDate.DateTimeToString(),
                StartCityName      = "广州",
                EndCityName        = r.Key.EndCityName,
                // ShipperID = r.Key.ShipperID,
                Volume = r.Sum(a => a.Volume)
            };
            IList <SettledPod> settledPods = new List <SettledPod>();

            foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
            {
                //燃油附加费
                decimal BAFPrice = 0;
                //立方数
                double cube = gPod.Volume;
                //if( gPod.EndCityName=="苏州"){
                //    switch (gPod.StartCityName)
                //    {
                //        case "大连":
                //            break;
                //        case "青岛":
                //            break;
                //        case "丹东":
                //            break;
                //        case "番禺":
                //            break;
                //        case "清远":
                //            break;
                //        case "云浮":
                //            break;
                //        default:
                //           gPod.StartCityName = "广州";
                //           break;
                //    }
                //}else
                //  if(gPod.EndCityName == "天津") {
                //switch (gPod.StartCityName)
                //{
                //   case "大连":
                //       break;
                //   case "青岛":
                //       break;
                //   case "丹东":
                //       break;
                //   case "番禺":
                //       break;
                //   default:
                //     gPod.StartCityName = "广州";
                //     break;
                //}
                //}
                if (gPod.StartCityName == "大连" || gPod.StartCityName == "丹东")
                {
                    foreach (var item in SXshipper)
                    {
                        if (item.ActualDeliveryDate.ToString() == gPod.ActualDeliveryDate && gPod.StartCityName == item.StartCityName && item.EndCityName == gPod.EndCityName)
                        {
                            cube = Convert.ToDouble(item.Volume);
                        }
                    }
                }
                else
                {
                    foreach (var item in newpodsResponse)
                    {
                        if (item.ActualDeliveryDate.ToString() == gPod.ActualDeliveryDate && item.EndCityName == gPod.EndCityName)
                        {
                            cube = Convert.ToDouble(item.Volume);
                        }
                    }
                }
                var innerPodIDs = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                //得到长途运输费的报价

                QuotedPrice price = quotedPrice.FirstOrDefault(q =>//
                                                               q.ProjectID == ProjectID && q.Target == 0 && q.TargetID == 13 && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                               q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                               q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));

                QueryBAFPrice BAFPrices = BAF.FirstOrDefault(q =>
                                                             q.ProjectID == ProjectID && q.BAFStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && q.BAFEndTime > gPod.ActualDeliveryDate.ObjectToDateTime());


                if (BAFPrices != null)
                {
                    BAFPrice = BAFPrices.BAFPrice;
                }
                if (price == null)
                {
                    var forSettledPodsTemp = forSettledPodsResponse.Result.Where(p => gPod.PodIDs.Split('|').Contains(p.ID.ToString()));
                    if (forSettledPodsTemp != null)
                    {
                        forSettledPodsTemp.Each((k, g) =>
                        {
                            Message.Append("运单:").Append(g.CustomerOrderNumber).Append(",对应客户为:").Append(g.CustomerName).Append(",起运城市为:")
                            .Append(g.StartCityName).Append(",目的城市为:").Append(g.EndCityName).Append(",运输类型为:").Append(g.ShipperTypeName)
                            .Append(",运单类型为:").Append(g.PODTypeName).Append(",整车/零担为:").Append(g.TtlOrTplName).Append(" 无系统对应报价,请先配置报价.").Append("*");
                        });
                    }
                    continue;
                }
                if (Message.Length > 0)
                {
                    continue;
                }
                decimal shipAmt = 0;

                foreach (var id in innerPodIDs)
                {
                    //提货费
                    // decimal del = 0;
                    var originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                    //是否是长途运输
                    //   if (originalPod.Str5 == "Y")
                    //  {
                    //   QuotedPrice delivery = quotedPrice.FirstOrDefault(q =>
                    //  q.ProjectID == ProjectID && q.Target == 0 && q.TargetID == gPod.TargetID && q.StartCityName.Trim() == originalPod.Str3 && q.EndCityName.Trim() == originalPod.Str3
                    //  && q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube
                    //  && q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));
                    //  if (delivery != null)
                    // {
                    // del = delivery.Price;
                    // }
                    // }
                    shipAmt = price.Price >= 100 ? price.Price * (decimal)originalPod.Volume : price.Price * (decimal)originalPod.BoxNumber;

                    SettledPod settledPod = new SettledPod()
                    {
                        ProjectID           = originalPod.ProjectID,
                        CustomerOrderNumber = originalPod.CustomerOrderNumber,
                        SystemNumber        = originalPod.SystemNumber,
                        PodID                 = id,
                        SettledNumber         = settledNumber,
                        SettledType           = 0,
                        CustomerOrShipperID   = originalPod.CustomerID.Value,
                        CustomerOrShipperName = originalPod.CustomerName,
                        StartCityID           = originalPod.StartCityID.Value,
                        StartCityName         = originalPod.StartCityName,
                        EndCityID             = originalPod.EndCityID.Value,
                        EndCityName           = originalPod.EndCityName,
                        ShipperTypeID         = originalPod.ShipperTypeID.Value,
                        ShipperTypeName       = originalPod.ShipperTypeName,
                        PODTypeID             = originalPod.PODTypeID.Value,
                        PODTypeName           = originalPod.PODTypeName,
                        TtlOrTplID            = originalPod.TtlOrTplID.Value,
                        TtlOrTplName          = originalPod.TtlOrTplName,
                        ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                        BoxNumber             = originalPod.BoxNumber,
                        Weight                = originalPod.Weight,
                        Volume                = originalPod.Volume,
                        GoodsNumber           = originalPod.GoodsNumber,
                        ShipAmt               = shipAmt,
                        //燃油附加费=长途运费*费率(浮动率)
                        BAFAmt   = shipAmt * BAFPrice,// BAFPrice * shipAmt * (decimal)(originalPod.Str40.ObjectToDouble() / cube),
                        PointAmt = 0,
                        //其他费=卸货费(箱数*0.45)+提货费(是工厂直发才有提货费)
                        OtherAmt          = 0,//(decimal)originalPod.BoxNumber * (decimal)0.45 + del * (decimal)originalPod.Volume,
                        Amt1              = 0,
                        Amt2              = 0,
                        Amt3              = 0,
                        Amt4              = 0,
                        Amt5              = 0,
                        Str1              = string.Empty,
                        Str2              = string.Empty,
                        Str3              = string.Empty,
                        Str4              = price.Price.ToString(),
                        Str5              = string.Empty,
                        Remark            = string.Empty,
                        DateTime1         = null,
                        DateTime2         = null,
                        CreateTime        = DateTime.Now,
                        Creator           = Creator,
                        InvoiceID         = 0,
                        RelatedCustomerID = originalPod.CustomerID,
                        IsAudit           = true
                    };
                    settledPods.Add(settledPod);
                }
                if (Message.Length > 0)
                {
                    continue;
                }
            }
            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt - p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 0
                });
            }
        }
Example #20
0
        public void SettledPodForReceive(IEnumerable <long> PodIDs, string Creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service = new PodService();
            var        forSettledPodsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!forSettledPodsResponse.IsSuccess)
            {
                throw forSettledPodsResponse.Exception;
            }

            var groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
            {
                IDs = PodIDs, SettledType = 0
            });

            if (!groupedPodsResponse.IsSuccess)
            {
                throw groupedPodsResponse.Exception;
            }

            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }

            IList <SettledPod> settledPods   = new List <SettledPod>();
            string             settledNumber = Guid.NewGuid().ToString();

            podsResponse.Result.Each((i, p) => {
                decimal shipAmt = 0;
                if (!string.IsNullOrEmpty(p.Str6))
                {
                    try
                    {
                        shipAmt = p.Str6.ObjectToDecimal();
                    }
                    catch
                    {
                        Message.Append("运单:").Append(p.CustomerOrderNumber).Append(",对应客户为:").Append(p.CustomerName).Append(",起运城市为:")
                        .Append(p.StartCityName).Append(",目的城市为:").Append(p.EndCityName).Append(",运输类型为:").Append(p.ShipperTypeName)
                        .Append(",运单类型为:").Append(p.PODTypeName).Append(",整车/零担为:").Append(p.TtlOrTplName).Append(" 应收金额不正确.").Append("*");
                    }
                }
                else
                {
                    Message.Append("运单:").Append(p.CustomerOrderNumber).Append(",对应客户为:").Append(p.CustomerName).Append(",起运城市为:")
                    .Append(p.StartCityName).Append(",目的城市为:").Append(p.EndCityName).Append(",运输类型为:").Append(p.ShipperTypeName)
                    .Append(",运单类型为:").Append(p.PODTypeName).Append(",整车/零担为:").Append(p.TtlOrTplName).Append(" 应收金额为空.").Append("*");
                }

                SettledPod settledPod = new SettledPod()
                {
                    ProjectID           = ProjectID,
                    CustomerOrderNumber = p.CustomerOrderNumber,
                    SystemNumber        = p.SystemNumber,
                    PodID                 = p.ID,
                    SettledNumber         = settledNumber,
                    SettledType           = 0,
                    CustomerOrShipperID   = p.CustomerID.Value,
                    CustomerOrShipperName = p.CustomerName,
                    StartCityID           = p.StartCityID.Value,
                    StartCityName         = p.StartCityName,
                    EndCityID             = p.EndCityID.Value,
                    EndCityName           = p.EndCityName,
                    ShipperTypeID         = p.ShipperTypeID.Value,
                    ShipperTypeName       = p.ShipperTypeName,
                    PODTypeID             = p.PODTypeID.Value,
                    PODTypeName           = p.PODTypeName,
                    TtlOrTplID            = p.TtlOrTplID.Value,
                    TtlOrTplName          = p.TtlOrTplName,
                    ActualDeliveryDate    = p.ActualDeliveryDate.Value,
                    BoxNumber             = p.BoxNumber,
                    Weight                = p.Weight,
                    Volume                = p.Volume,
                    GoodsNumber           = p.GoodsNumber,
                    ShipAmt               = shipAmt,
                    BAFAmt                = 0,
                    PointAmt              = 0,
                    OtherAmt              = 0,
                    Amt1              = 0,
                    Amt2              = 0,
                    Amt3              = 0,
                    Amt4              = 0,
                    Amt5              = 0,
                    Str1              = string.Empty,
                    Str2              = string.Empty,
                    Str3              = string.Empty,
                    Str4              = string.Empty,
                    Str5              = string.Empty,
                    Remark            = string.Empty,
                    DateTime1         = null,
                    DateTime2         = null,
                    CreateTime        = DateTime.Now,
                    Creator           = Creator,
                    InvoiceID         = 0,
                    RelatedCustomerID = p.CustomerID,
                    IsAudit           = true
                };

                settledPods.Add(settledPod);
            });

            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 0
                });
            }
        }
Example #21
0
        public void SettledPodForPay(IEnumerable <long> PodIDs, string Creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }

            PodService service      = new PodService();
            var        podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }

            var                quotedPrice   = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);
            string             settledNumber = Guid.NewGuid().ToString();
            IList <SettledPod> settledPods   = new List <SettledPod>();

            foreach (var pod in podsResponse.Result)
            {
                //For Hilti
                if (pod.CustomerID == 2)
                {
                    if (string.IsNullOrEmpty(pod.Str24))
                    {
                        this.GenErrorMessage(pod, Message, " 无净重,请先编辑运单毛重");
                        continue;
                    }

                    double weight = 0;
                    try
                    {
                        weight = pod.Str24.ObjectToDouble();
                    }
                    catch
                    {
                        this.GenErrorMessage(pod, Message, "净重数据不是数字类型,请重新编辑运单");
                        continue;
                    }

                    IEnumerable <QuotedPrice> prices = quotedPrice.Where(q =>
                                                                         q.ProjectID == ProjectID && q.Target == 0 && q.TargetID == pod.CustomerID && q.StartCityName == pod.StartCityName && q.EndCityName == pod.EndCityName &&
                                                                         q.PodTypeName == pod.PODTypeName && q.ShipperTypeName == pod.ShipperTypeName && q.TplOrTtlName == pod.TtlOrTplName &&
                                                                         q.EffectiveStartTime <= pod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= pod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));

                    if (prices == null || !prices.Any())
                    {
                        this.GenErrorMessage(pod, Message, " 无对应报价,请先配置");
                        continue;
                    }

                    SettledPod settledPod = new SettledPod()
                    {
                        ProjectID           = pod.ProjectID,
                        CustomerOrderNumber = pod.CustomerOrderNumber,
                        SystemNumber        = pod.SystemNumber,
                        PodID                 = pod.ID,
                        SettledNumber         = settledNumber,
                        SettledType           = 1,
                        CustomerOrShipperID   = pod.ShipperID.Value,
                        CustomerOrShipperName = pod.ShipperName,
                        StartCityID           = pod.StartCityID.Value,
                        StartCityName         = pod.StartCityName,
                        EndCityID             = pod.EndCityID.Value,
                        EndCityName           = pod.EndCityName,
                        ShipperTypeID         = pod.ShipperTypeID.Value,
                        ShipperTypeName       = pod.ShipperTypeName,
                        PODTypeID             = pod.PODTypeID.Value,
                        PODTypeName           = pod.PODTypeName,
                        TtlOrTplID            = pod.TtlOrTplID.Value,
                        TtlOrTplName          = pod.TtlOrTplName,
                        ActualDeliveryDate    = pod.ActualDeliveryDate.Value,
                        BoxNumber             = pod.BoxNumber,
                        Weight                = weight,
                        Volume                = pod.Volume,
                        GoodsNumber           = pod.GoodsNumber,
                        BAFAmt                = 0,
                        PointAmt              = 0,
                        OtherAmt              = 0,
                        Amt1              = 0,
                        Amt2              = 0,
                        Amt3              = 0,
                        Amt4              = 0,
                        Amt5              = 0,
                        Str1              = string.Empty,
                        Str2              = string.Empty,
                        Str3              = string.Empty,
                        Str4              = string.Empty,
                        Str5              = string.Empty,
                        Remark            = string.Empty,
                        DateTime1         = null,
                        DateTime2         = null,
                        CreateTime        = DateTime.Now,
                        Creator           = Creator,
                        InvoiceID         = 0,
                        RelatedCustomerID = pod.CustomerID,
                        IsAudit           = true
                    };

                    QuotedPrice price;
                    QuotedPrice minPrice = prices.FirstOrDefault(p => p.StartVal == 0 && p.EndVal == 50);

                    if (minPrice == null)
                    {
                        this.GenErrorMessage(pod, Message, " 系统报价有问题!");
                        continue;
                    }

                    price = prices.FirstOrDefault(p => p.StartVal < weight && p.EndVal >= weight);

                    if (price == null)
                    {
                        this.GenErrorMessage(pod, Message, " 根据运单净重,未找到对应报价");
                        continue;
                    }

                    if (weight <= this._settledByItem)
                    {
                        settledPod.ShipAmt = minPrice.Price;
                    }
                    else
                    {
                        settledPod.ShipAmt = price.Price * (decimal)weight;
                        if (settledPod.ShipAmt < minPrice.Price)
                        {
                            settledPod.ShipAmt = minPrice.Price;
                        }
                    }

                    if (pod.Str22 == "1")
                    {
                        if (string.Equals(pod.Str30.Trim(), "现金"))
                        {
                            if (string.IsNullOrEmpty(pod.Str14))
                            {
                                this.GenErrorMessage(pod, Message, " 代收款方式为现金,但未提供代收款金额,无法结算代收现金手续费,请编辑运单代收款金额");
                                continue;
                            }

                            decimal tempAmt = 0;
                            try
                            {
                                tempAmt = pod.Str14.ObjectToDecimal();
                            }
                            catch
                            {
                                this.GenErrorMessage(pod, Message, " 代收款方式为现金,但代收款金额输入有误,无法结算代收现金手续费,请编辑运单代收款金额");
                                continue;
                            }

                            decimal tempAmt1 = tempAmt * this._rate;
                            if (tempAmt1 < this._minFee)
                            {
                                tempAmt1 = this._minFee;
                            }

                            settledPod.ShipAmt += tempAmt1;
                        }
                    }

                    if (pod.Str31 == "1")
                    {
                        settledPod.ShipAmt += this._caoGanAmt;
                    }

                    settledPods.Add(settledPod);
                }
            }

            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 1
                });
            }
        }
        public void SettledPodForPay(IEnumerable <long> PodIDs, string creator, long ProjectID, int Target, long CustomerOrShipperID, long RelatedCustomerID, StringBuilder Message)
        {
            if (Message.Length > 0)
            {
                return;
            }
            PodService         service     = new PodService();
            IList <SettledPod> settledPods = new List <SettledPod>();
            //podsResponse 待结算运单列表
            var podsResponse = service.QueryPodByPodIDs(new QueryPodByIDsRequest()
            {
                PodIDs = PodIDs
            });

            if (!podsResponse.IsSuccess)
            {
                throw podsResponse.Exception;
            }
            //取得报价
            var quotedPrice = ApplicationConfigHelper.GetProjectQuotedPrice(ProjectID, Target, CustomerOrShipperID, RelatedCustomerID);
            //生成结算序列号
            string settledNumber = Guid.NewGuid().ToString();

            long relatedCustomerID = 0;

            #region Adidas

            if (podsResponse.Result.First().CustomerID == 1)
            {
                relatedCustomerID = 1;
                var groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
                {
                    IDs = PodIDs, SettledType = 1
                });
                if (!groupedPodsResponse.IsSuccess)
                {
                    throw groupedPodsResponse.Exception;
                }
                foreach (var gPod in groupedPodsResponse.Result.GroupedPods)
                {
                    double      cube        = gPod.BoxNumber / 11;
                    var         innerPodIDs = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                    QuotedPrice price       = quotedPrice.FirstOrDefault(q =>
                                                                         q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                                         q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal < cube && q.EndVal >= cube &&
                                                                         q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));
                    if (price == null)
                    {
                        this.GenErrorMessage_ByGroupedPod(gPod, Message, "无系统对应报价, 请先配置报价.");
                        continue;
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }

                    decimal shipAmt = price.Price * (decimal)cube;

                    foreach (var id in innerPodIDs)
                    {
                        var        originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                        SettledPod settledPod  = new SettledPod()
                        {
                            ProjectID           = originalPod.ProjectID,
                            CustomerOrderNumber = originalPod.CustomerOrderNumber,
                            SystemNumber        = originalPod.SystemNumber,
                            PodID                 = id,
                            SettledNumber         = settledNumber,
                            SettledType           = 1,
                            CustomerOrShipperID   = originalPod.ShipperID.Value,
                            CustomerOrShipperName = originalPod.ShipperName,
                            StartCityID           = originalPod.StartCityID.Value,
                            StartCityName         = originalPod.StartCityName,
                            EndCityID             = originalPod.EndCityID.Value,
                            EndCityName           = originalPod.EndCityName,
                            ShipperTypeID         = originalPod.ShipperTypeID.Value,
                            ShipperTypeName       = originalPod.ShipperTypeName,
                            PODTypeID             = originalPod.PODTypeID.Value,
                            PODTypeName           = originalPod.PODTypeName,
                            TtlOrTplID            = originalPod.TtlOrTplID.Value,
                            TtlOrTplName          = originalPod.TtlOrTplName,
                            ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                            BoxNumber             = originalPod.BoxNumber,
                            Weight                = originalPod.Weight,
                            Volume                = originalPod.Volume,
                            GoodsNumber           = originalPod.GoodsNumber,
                            ShipAmt               = shipAmt * (decimal)(originalPod.BoxNumber / gPod.BoxNumber),
                            BAFAmt                = 0,
                            PointAmt              = 0,
                            OtherAmt              = 0,
                            Amt1              = 0,
                            Amt2              = 0,
                            Amt3              = 0,
                            Amt4              = 0,
                            Amt5              = 0,
                            Str1              = string.Empty,
                            Str2              = string.Empty,
                            Str3              = string.Empty,
                            Str4              = price.Price.ToString(),
                            Str5              = string.Empty,
                            Remark            = string.Empty,
                            DateTime1         = null,
                            DateTime2         = null,
                            CreateTime        = DateTime.Now,
                            Creator           = creator,
                            InvoiceID         = 0,
                            RelatedCustomerID = originalPod.CustomerID,
                            IsAudit           = true
                        };

                        settledPods.Add(settledPod);
                    }

                    if (Message.Length > 0)
                    {
                        continue;
                    }

                    //同天同城,出货运单,第一个客户不算点费,之后30元一个
                    if (string.Equals(gPod.PODTypeName.Trim(), "出货运单", StringComparison.OrdinalIgnoreCase))
                    {
                        var temp = (from p in podsResponse.Result.Where(k => innerPodIDs.Contains(k.ID)) group p by p.Str7 into g select new { g.Key, Pods = g });
                        if (temp != null)
                        {
                            temp.Each((i, k) =>
                            {
                                if (i > 0)
                                {
                                    var innPodIDs = k.Pods.Select(p => p.ID);
                                    settledPods.First(s => s.PodID == innPodIDs.First()).PointAmt = 30;
                                    settledPods.First(s => s.PodID == innPodIDs.First()).Remark   = "佳勤出货,同天同城同客户30元点费";
                                }
                            });
                        }
                    }

                    //同天同城,退货运单,客户类型为经销商,无论去几个地方30元,自营店无
                    if (string.Equals(gPod.PODTypeName.Trim(), "退货运单", StringComparison.OrdinalIgnoreCase))
                    {
                        var temp = (from p in podsResponse.Result.Where(k => innerPodIDs.Contains(k.ID)) group p by p.Str10 into g select new { g.Key, Pods = g });
                        if (temp != null)
                        {
                            foreach (var k in temp)
                            {
                                if (k.Key == "经销商")
                                {
                                    var innPodIDs = k.Pods.Select(p => p.ID);
                                    settledPods.First(s => innPodIDs.Contains(s.PodID)).PointAmt = 30;
                                    settledPods.First(s => innPodIDs.Contains(s.PodID)).Remark   = "佳勤退货,同天同城经销商30元点费";
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            #endregion Adidas
            #region akzo
            if (podsResponse.Result.First().CustomerID == 7)
            {
                relatedCustomerID = 7;
                #region   目的地是四川但不是成都的   为转仓运单
                var            regins    = ApplicationConfigHelper.GetRegions().Where(r => r.SupperID == 29 && r.Name != "成都");
                IList <string> cityNames = new List <string>();
                regins.Each((i, r) =>
                {
                    cityNames.Add(r.Name);
                    ApplicationConfigHelper.GetRegions().Where(g => g.SupperID == r.ID || g.SupperID == 256).Each((j, k) => cityNames.Add(k.Name));
                });
                IList <Pod> Normal = new List <Pod>();
                //存放转仓运单的
                IList <Pod> Special = new List <Pod>();
                podsResponse.Result.Each((i, p) =>
                {
                    if (cityNames.Contains(p.EndCityName))
                    {
                        Special.Add(p);
                    }
                    else
                    {
                        Normal.Add(p);
                    }
                });
                IEnumerable <long> podIDC  = Normal.Select(p => p.ID);
                var         groupedSprcial = Special.GroupBy(s => s.ActualDeliveryDate).Select(g => new { Date = g.Key.Value, Pods = g.Select(k => { return(k); }) });
                IList <Pod> DatePods       = new List <Pod>();
                double      SpecialWeight  = 0;
                decimal     SpecialPrice   = 0;
                decimal     SpecialShipAmt = 0;
                foreach (var item in groupedSprcial)
                {
                    DateTime dt = item.Date;
                    foreach (var pod in Special)
                    {
                        if (pod.ActualDeliveryDate == dt)
                        {
                            SpecialWeight += (double)pod.Weight;
                            DatePods.Add(pod);
                        }
                    }
                    if (SpecialWeight >= 30000)
                    {
                        SpecialPrice = (decimal)668 / 1000;
                    }
                    else if (SpecialWeight >= 20000)
                    {
                        SpecialPrice = (decimal)670 / 1000;
                    }
                    else if (SpecialWeight >= 10000)
                    {
                        SpecialPrice = (decimal)675 / 1000;
                    }
                    else if (SpecialWeight >= 3000)
                    {
                        SpecialPrice = (decimal)685 / 1000;
                    }
                    else
                    {
                        SpecialPrice = (decimal)690 / 1000;
                    }
                    SpecialShipAmt = (decimal)SpecialWeight * SpecialPrice;
                    if (SpecialWeight > 0)
                    {
                        foreach (var special in DatePods)
                        {
                            if (special.Weight == null)
                            {
                                this.GenErrorMessage_ByPod(special, Message, "请先设置货物的重量");
                                continue;
                            }
                            SettledPod settledPod = new SettledPod()
                            {
                                ProjectID           = special.ProjectID,
                                CustomerOrderNumber = special.CustomerOrderNumber,
                                SystemNumber        = special.SystemNumber,
                                PodID                 = special.ID,
                                SettledNumber         = special.CustomerOrderNumber,
                                SettledType           = 1,
                                CustomerOrShipperID   = special.ShipperID.Value,
                                CustomerOrShipperName = special.ShipperName,
                                StartCityID           = special.StartCityID.Value,
                                StartCityName         = special.StartCityName,
                                EndCityID             = special.EndCityID.Value,
                                EndCityName           = special.EndCityName,
                                ShipperTypeID         = special.ShipperTypeID.Value,
                                ShipperTypeName       = special.ShipperTypeName,
                                PODTypeID             = special.PODTypeID.Value,
                                PODTypeName           = special.PODTypeName,
                                TtlOrTplID            = special.TtlOrTplID.Value,
                                TtlOrTplName          = special.TtlOrTplName,
                                ActualDeliveryDate    = special.ActualDeliveryDate.Value,
                                BoxNumber             = special.BoxNumber,
                                Weight                = special.Weight,
                                Volume                = special.Volume,
                                GoodsNumber           = special.GoodsNumber,
                                ShipAmt               = SpecialShipAmt * (decimal)(special.Weight / SpecialWeight),
                                BAFAmt                = 0,
                                PointAmt              = 0,
                                OtherAmt              = 0,
                                Amt1              = 0,
                                Amt2              = 0,
                                Amt3              = 0,
                                Amt4              = 0,
                                Amt5              = 0,
                                Str1              = string.Empty,
                                Str2              = string.Empty,
                                Str3              = string.Empty,
                                Str4              = SpecialPrice.ToString(),
                                Str5              = string.Empty,
                                Remark            = string.Empty,
                                DateTime1         = null,
                                DateTime2         = null,
                                CreateTime        = DateTime.Now,
                                Creator           = creator,
                                InvoiceID         = 0,
                                RelatedCustomerID = special.CustomerID,
                                IsAudit           = true
                            };

                            settledPods.Add(settledPod);
                        }
                    }
                    SpecialWeight  = 0;
                    SpecialPrice   = 0;
                    SpecialShipAmt = 0;
                    DatePods.Clear();
                }
                var groupedPodsResponse = service.SettledPodSearch(new SettledPodRequest()
                {
                    IDs = podIDC, SettledType = 1, IsID = 1
                });
                if (!groupedPodsResponse.IsSuccess)
                {
                    throw groupedPodsResponse.Exception;
                }
                #endregion

                #region  目的地是成都 、重庆、西藏下面的市   就要按照同天同城同客户获取报价

                var podsResponses = from q in podsResponse.Result
                                    group q by new { q.Str2, q.StartCityName, q.ActualDeliveryDate, q.EndCityName }

                into g
                let ids = g.Select(b => b.ID.ToString()).ToArray()
                          select new
                {
                    ActualDeliveryDate = g.Max(a => a.ActualDeliveryDate),
                    ShipperTypeName    = g.Max(a => a.ShipperTypeName),
                    BoxNumber          = g.Sum(a => a.BoxNumber),
                    Volume             = g.Sum(a => a.Volume),
                    Weight             = g.Sum(a => a.Weight),
                    TargetID           = g.Max(a => a.ShipperID),
                    ShipperName        = g.Max(a => a.ShipperName),
                    ShipperTypeID      = g.Max(a => a.ShipperTypeID),
                    PODTypeID          = g.Max(a => a.PODTypeID),
                    PODTypeName        = g.Max(a => a.PODTypeName),
                    TtlOrTplID         = g.Max(a => a.TtlOrTplID),
                    TtlOrTplName       = g.Max(a => a.TtlOrTplName),
                    StartCityID        = g.Max(a => a.StartCityID),
                    StartCityName      = g.Max(a => a.StartCityName),
                    GoodsNumber        = g.Max(a => a.GoodsNumber),
                    EndCityName        = g.Max(a => a.EndCityName),
                    PodIDs             = string.Join("|", ids),
                    //sd=g.Max(a=>a.),
                };
                foreach (var gPod in podsResponses)
                {
                    List <string> endcityname = new List <string> {
                        "成都", "重庆", "长寿", "达州", "涪陵", "广安", "华蓥", "江津", "万源",
                        "万州", "永川", "昌都", "噶尔", "拉萨", "林芝", "那曲", " 乃东", "日喀则"
                    };

                    if (endcityname.Contains(gPod.EndCityName))
                    {
                        double weight  = (double)gPod.Weight;
                        double weights = 0;
                        if (weight < 50)
                        {
                            weights = 50;
                        }
                        else
                        {
                            weights = weight;
                        }

                        var         innerPodIDs = gPod.PodIDs.Split('|').Select(i => i.ObjectToInt64());
                        QuotedPrice price       = new QuotedPrice();
                        QuotedPrice tempPrice;
                        //tempPrice = quotedPrice.FirstOrDefault(q =>
                        //q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim()
                        //&& q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal <= weight && q.EndVal > weight
                        //&& q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));

                        tempPrice = quotedPrice.FirstOrDefault(q =>
                                                               q.ProjectID == ProjectID && q.Target == 1 && q.TargetID == gPod.TargetID && q.RelatedCustomerID == relatedCustomerID && q.StartCityName.Trim() == gPod.StartCityName.Trim() && q.EndCityName.Trim() == gPod.EndCityName.Trim() &&
                                                               q.PodTypeName.Trim() == gPod.PODTypeName.Trim() && q.ShipperTypeName.Trim() == gPod.ShipperTypeName.Trim() && q.TplOrTtlName.Trim() == gPod.TtlOrTplName.Trim() && q.StartVal <= weights && q.EndVal > weight &&
                                                               q.EffectiveStartTime <= gPod.ActualDeliveryDate.ObjectToDateTime() && (q.EffectiveEndTime >= gPod.ActualDeliveryDate.ObjectToDateTime() || q.EffectiveEndTime == null));



                        GroupedPods gPods = new GroupedPods();
                        gPods.PodIDs          = gPod.PodIDs;
                        gPods.TargetName      = gPod.ShipperName;
                        gPods.StartCityName   = gPod.StartCityName;
                        gPods.EndCityName     = gPod.EndCityName;
                        gPods.ShipperTypeName = gPod.ShipperTypeName;
                        gPods.PODTypeName     = gPod.PODTypeName;
                        gPods.TtlOrTplName    = gPod.TtlOrTplName;
                        if (tempPrice == null)
                        {
                            this.GenErrorMessage_ByGroupedPod(gPods, Message, "无系统对应报价,请先配置报价.");
                            continue;
                        }
                        else
                        {
                            price.Price = tempPrice.Price;
                        }

                        if (Message.Length > 0)
                        {
                            continue;
                        }
                        decimal shipAmt = price.Price;

                        foreach (var id in innerPodIDs)
                        {
                            var originalPod = podsResponse.Result.FirstOrDefault(p => p.ID == id);
                            if (originalPod.Weight == null)
                            {
                                this.GenErrorMessage_ByGroupedPod(gPods, Message, "请先设置货物的重量");
                                continue;
                            }
                            SettledPod settledPod = new SettledPod()
                            {
                                ProjectID           = originalPod.ProjectID,
                                CustomerOrderNumber = originalPod.CustomerOrderNumber,
                                SystemNumber        = originalPod.SystemNumber,
                                PodID                 = id,
                                SettledNumber         = settledNumber,
                                SettledType           = 1,
                                CustomerOrShipperID   = originalPod.ShipperID.Value,
                                CustomerOrShipperName = originalPod.ShipperName,
                                StartCityID           = originalPod.StartCityID.Value,
                                StartCityName         = originalPod.StartCityName,
                                EndCityID             = originalPod.EndCityID.Value,
                                EndCityName           = originalPod.EndCityName,
                                ShipperTypeID         = originalPod.ShipperTypeID.Value,
                                ShipperTypeName       = originalPod.ShipperTypeName,
                                PODTypeID             = originalPod.PODTypeID.Value,
                                PODTypeName           = originalPod.PODTypeName,
                                TtlOrTplID            = originalPod.TtlOrTplID.Value,
                                TtlOrTplName          = originalPod.TtlOrTplName,
                                ActualDeliveryDate    = originalPod.ActualDeliveryDate.Value,
                                BoxNumber             = originalPod.BoxNumber,
                                Weight                = originalPod.Weight,
                                Volume                = originalPod.Volume,
                                GoodsNumber           = originalPod.GoodsNumber,
                                ShipAmt               = weight < 50 ? shipAmt * (decimal)(originalPod.Weight / weight) * 50 : shipAmt * (decimal)originalPod.Weight,
                                BAFAmt                = 0,
                                PointAmt              = 0,
                                OtherAmt              = 0,
                                Amt1              = 0,
                                Amt2              = 0,
                                Amt3              = 0,
                                Amt4              = 0,
                                Amt5              = 0,
                                Str1              = string.Empty,
                                Str2              = string.Empty,
                                Str3              = string.Empty,
                                Str4              = price.Price.ToString(),
                                Str5              = string.Empty,
                                Remark            = string.Empty,
                                DateTime1         = null,
                                DateTime2         = null,
                                CreateTime        = DateTime.Now,
                                Creator           = creator,
                                InvoiceID         = 0,
                                RelatedCustomerID = originalPod.CustomerID,
                                IsAudit           = true
                            };

                            settledPods.Add(settledPod);
                        }
                    }
                }


                #endregion
            }
            #endregion
            if (Message.Length > 0)
            {
                return;
            }
            else
            {
                settledPods.Each((i, p) => { p.TotalAmt = p.ShipAmt + p.PointAmt + p.BAFAmt + p.OtherAmt + p.Amt1 + p.Amt2 + p.Amt3 + p.Amt4 + p.Amt5; });
                new SettledService().SettlePods(new SettlePodsRequest()
                {
                    SettledPods = settledPods, SettledType = 1
                });
            }
        }