public bool CreateContract(int userId, Contract contract,Quota quota) { try { List<Quota> quotas = new List<Quota>(); quotas.Add(quota); contractService.CreateDocument(userId, contract, quotas, null, null, null); return true; } catch (Exception) { return false; } }
public static IPricingHandler GetPricingHandler(Quota quota, SenLan2Entities ctx) { switch (quota.PricingType) { case (int)PricingType.Fixed: return new FixPricingHandler(quota, ctx); case (int)PricingType.Manual: return new ManualPricingHandler(quota, ctx); case (int)PricingType.Average: return new AveragePricingHandler(quota,ctx); default: return null; } }
private void FixupQuota(Quota previousValue, bool skipKeys = false) { if (IsDeserializing) { return; } if (previousValue != null && previousValue.PaymentRequests.Contains(this)) { previousValue.PaymentRequests.Remove(this); } if (Quota != null) { if (!Quota.PaymentRequests.Contains(this)) { Quota.PaymentRequests.Add(this); } QuotaId = Quota.Id; } else if (!skipKeys) { QuotaId = null; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("Quota") && (ChangeTracker.OriginalValues["Quota"] == Quota)) { ChangeTracker.OriginalValues.Remove("Quota"); } else { ChangeTracker.RecordOriginalValue("Quota", previousValue); } if (Quota != null && !Quota.ChangeTracker.ChangeTrackingEnabled) { Quota.StartTracking(); } } }
/// <summary> /// 返回点价的平均价 /// </summary> /// <param name="quota"></param> /// <param name="userId"></param> /// <returns>返回人民币的平均价</returns> private decimal GetAveragePrice(Quota quota,int userId) { decimal averagePrice = 0; decimal qtyCount = 0; if (quota.Pricings != null) { List<Pricing> pricingList = quota.Pricings.Where(o => o.IsDeleted == false).ToList(); decimal amount; if (quota.Contract.TradeType == (int)TradeType.LongDomesticTrade || quota.Contract.TradeType == (int)TradeType.ShortDomesticTrade) { //内贸,直接取点价表里边的汇率 amount = quota.Pricings.Where(o => o.IsDeleted == false). Sum(o => (o.PricingQuantity ?? 0) * (o.FinalPrice ?? 0) * (o.ExchangeRate ?? 0)); } else { //外贸,通过点价基准和人民币计算汇率 if (_cnyCurrency == null) { using (var currencyService=SvcClientManager.GetSvcClient<CurrencyServiceClient>(SvcType.CurrencySvc)) { _cnyCurrency = currencyService.GetCurrencyByCode("CNY"); } } decimal currencyRate = 0; //如果没有点价的话,amount相乘为0 if (pricingList.Count > 0) { if (!_cnyRate.ContainsKey(pricingList[0].CurrencyId.Value)) { using (var rateService = SvcClientManager.GetSvcClient<RateServiceClient>(SvcType.RateSvc)) { currencyRate = rateService.GetExchangeRate(_cnyCurrency.Id,pricingList[0].CurrencyId.Value, userId) ?? 0; } _cnyRate.Add(pricingList[0].CurrencyId.Value, currencyRate); } else { currencyRate = _cnyRate[pricingList[0].CurrencyId.Value]; } } amount = pricingList.Sum(o => (o.PricingQuantity * o.FinalPrice * currencyRate) ?? 0); } qtyCount += pricingList.Sum(o => o.PricingQuantity ?? 0); averagePrice = amount / qtyCount; } return averagePrice; }
private void FixupQuota1(Quota previousValue) { if (IsDeserializing) { return; } if (previousValue != null && previousValue.PSQuotaRels1.Contains(this)) { previousValue.PSQuotaRels1.Remove(this); } if (Quota1 != null) { if (!Quota1.PSQuotaRels1.Contains(this)) { Quota1.PSQuotaRels1.Add(this); } SQuotaId = Quota1.Id; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("Quota1") && (ChangeTracker.OriginalValues["Quota1"] == Quota1)) { ChangeTracker.OriginalValues.Remove("Quota1"); } else { ChangeTracker.RecordOriginalValue("Quota1", previousValue); } if (Quota1 != null && !Quota1.ChangeTracker.ChangeTrackingEnabled) { Quota1.StartTracking(); } } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string method = context.Request["method"]; string openId = context.Request["openId"]; User user = userService.GetUserByOpenId(openId); if (user == null) { context.Response.Write("-1"); } else { if (method == "save") { DateTime today = DateTime.Today; Currency cny = contractService.GetCurrencyByCode("CNY"); int bpId = int.Parse(context.Request["BPId"]); int icId = int.Parse(context.Request["ICId"]); int contractType = int.Parse(context.Request["contractType"]); int commodityId = int.Parse(context.Request["com"]); int commodityTypeId = int.Parse(context.Request["comType"]); int brandId = int.Parse(context.Request["brand"]); decimal price = decimal.Parse(context.Request["price"]); decimal quantity = decimal.Parse(context.Request["quantity"]); string remark = context.Request["remark"].ToString(); Contract contract = new Contract(); contract.BPId = bpId; contract.InternalCustomerId = icId; contract.SignDate = today; contract.TradeType = (int)TradeType.ShortDomesticTrade; contract.ContractType = contractType; contract.Description = remark; contract.Sales = user.Id; Quota quota = new Quota(); if (brandId != 0) { quota.BrandId = brandId; } quota.CommodityId = commodityId; quota.CommodityTypeId = commodityTypeId; quota.PricingType = (int)PricingType.Fixed; quota.Quantity = quantity; quota.Price = price; quota.ImplementedDate = today; quota.PricingCurrencyId = cny.Id; quota.VATStatus = (int)QuotaVATStatus.NotAtAll; quota.FinanceStatus = false; quota.DeliveryStatus = false; quota.SettlementRate = 1; bool flag = contractService.CreateContract(user.Id, contract, quota); if (flag) { context.Response.Write("ok"); } else { context.Response.Write("error"); } } else if (method == "GetCom") { List<Commodity> list = contractService.GetAllCommodity(user.Id); List<keyValuePair> kv = list.Select(o => new keyValuePair { id = o.Id, name = o.Name }).OrderBy(o=>o.id).ToList(); string json = GetJson(kv); context.Response.Write(json); } else if (method == "GetComType") { int commodityId = int.Parse(context.Request["comId"]); List<CommodityType> list = contractService.GetAllCommodityTypeByCommodityId(commodityId); List<keyValuePair> kv = list.Select(o => new keyValuePair { id = o.Id, name = o.Name }).ToList(); string json = GetJson(kv); context.Response.Write(json); } else if (method == "GetBrand") { int commodityId = int.Parse(context.Request["comId"]); int commodityTypeId = int.Parse(context.Request["comTypeId"]); List<Brand> list = contractService.GetBrand(commodityTypeId, commodityId); List<keyValuePair> kv = list.Select(o => new keyValuePair { id = o.Id, name = o.Name }).ToList(); //if (kv.Count == 0) //{ kv.Insert(0, new keyValuePair { id = 0, name = "无" }); //} string json = GetJson(kv); context.Response.Write(json); } } }
/// <summary> /// 新增批次 /// </summary> /// <param name="quota"></param> public void AddQuota(Quota quota) { if (Quotas == null) Quotas = new List<Quota>(); int no = GetQuotaNo(); quota.Id = -no; Quotas.Add(quota); if (AddQuotas == null) { AddQuotas = new List<Quota>(); } AddQuotas.Add(quota); }
public AveragePricingHandler(Quota quota, SenLan2Entities ctx) :base(quota, ctx) { }
/// <summary> /// 获取批次的信息 /// </summary> /// <returns></returns> private Quota GetSaveQuota() { if (SelectPaymentMeanId.HasValue && SelectPaymentMeanId.Value == 0) { SelectPaymentMeanId = null; } var quota = new Quota { Quantity = Quantity, ApproveStatus = ApproveStatus, FinanceStatus = FinanceStatus == 1, DeliveryStatus = DeliveryStatus == 1, ImplementedDate = SignDate, CommodityId = CommodityId ?? 0, CommodityTypeId = CommodityTypeId ?? 0, BrandId = BrandId ?? 0, SpecificationId = SpecificationId ?? 0, PricingType = SelectPricingType, PricingStartDate = PricingStartDate, PricingEndDate = PricingEndDate, PricingSide = PricingSide ?? 0, Premium = Premium, Price = Price ?? 0, PricingCurrencyId = SelectPricingCurrencyId, WarehouseId = WarehouseId, DeliveryDate = DeliveryDate, ShipTerm = ShipTerm, ExQuotaNo = ExQuotaNo, VATInvoiceDate = VATInvoiceDate, PaymentMeanId = SelectPaymentMeanId, AutoQuotaNo = AutoContractNo//短单的对手批次号默认等于短单的对手合同号 }; if (SelectPricingBasis != 0) { quota.PricingBasis = SelectPricingBasis; } quota.SettlementRate = SelectPricingType == (int)PricingType.Fixed ? SettlementRate : null; //多品牌 quota.QuotaBrandRels.Clear(); foreach (QuotaBrandRel brandRel in AllQuotaBrandRelList) { var newBrandRel = new QuotaBrandRel { BrandId = brandRel.BrandId, Id = brandRel.Id, SpecificationId = (brandRel.SpecificationId == null || brandRel.SpecificationId.Value <= 0) ? null : brandRel.SpecificationId, IsDeleted = brandRel.IsDeleted, Quantity = brandRel.Quantity, Price = brandRel.Price, WarehouseId = brandRel.WarehouseId }; quota.QuotaBrandRels.Add(newBrandRel); } return quota; }
private void FixupQuota2(Quota previousValue, bool skipKeys = false) { if (IsDeserializing) { return; } if (previousValue != null && previousValue.Quota1.Contains(this)) { previousValue.Quota1.Remove(this); } if (Quota2 != null) { if (!Quota2.Quota1.Contains(this)) { Quota2.Quota1.Add(this); } RelQuotaId = Quota2.Id; } else if (!skipKeys) { RelQuotaId = null; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("Quota2") && (ChangeTracker.OriginalValues["Quota2"] == Quota2)) { ChangeTracker.OriginalValues.Remove("Quota2"); } else { ChangeTracker.RecordOriginalValue("Quota2", previousValue); } if (Quota2 != null && !Quota2.ChangeTracker.ChangeTrackingEnabled) { Quota2.StartTracking(); } } }
public BasePricingHandler(Quota quota, SenLan2Entities ctx) { Quota = quota; CTX = ctx; }
public ManualPricingHandler(Quota quota, SenLan2Entities ctx) : base(quota, ctx) { }