Example #1
0
 public void RegisterSettlementPaidFactor()
 {
     using (var db = new ShoppingSchedulerContext())
     {
         var list = db.ShopCustomerSubsetSettlements.Where(p =>
                                                           !p.IsRegisteredInAccounting && p.Type == ShopCustomerSubsetSettlementType.PaidFactor).ToList();
         foreach (var shopCustomerSubsetSettlement in list)
         {
             try
             {
                 var temp = new Grdb
                 {
                     TypeNo      = 200,
                     StrDate     = shopCustomerSubsetSettlement.CreationTime.ToFa(),
                     DetailCode1 = shopCustomerSubsetSettlement.Shop.Accounting.DetailCode,
                     RequestId   = Guid.NewGuid(),
                     Items       = new List <GrdbItem>
                     {
                         new GrdbItem
                         {
                             GoodCode  = "85105",
                             Amount    = 1,
                             Fee       = shopCustomerSubsetSettlement.Amount,
                             ItemDesc1 = $"ثبت هزینه کارمزد اولین خرید مشتری جذب شده فروشگاه {shopCustomerSubsetSettlement.Shop.NationalCode}"
                         }
                     }
                 };
                 string              objStringify = JsonConvert.SerializeObject(temp);
                 HttpContent         content      = new StringContent(objStringify, Encoding.UTF8, "application/json");
                 HttpResponseMessage response     = _httpClient.PostAsync(GrdbServiceName, content).Result;
                 if (response.StatusCode == HttpStatusCode.Created)
                 {
                     var resultString = response.Content.ReadAsStringAsync().Result;
                     var result       = JsonConvert.DeserializeObject <Grdb>(resultString);
                     if (result.Id >= 0)
                     {
                         shopCustomerSubsetSettlement.RegisterInAccounting(result.Id.ToString());
                         db.SaveChanges();
                     }
                 }
                 else
                 {
                     _logger.Error($"######accounting RegisterShopCustomerSubsetSettlementAccountingService GRDB web service  -- {DateTime.Now}");
                     _logger.Error(temp);
                     _logger.Error(response);
                 }
             }
             catch (Exception e)
             {
                 _logger.Error($"######exception accounting RegisterShopCustomerSubsetSettlementAccountingService GRDB web service   -- {DateTime.Now}");
                 _logger.Error(e);
             }
         }
     }
 }
Example #2
0
 private bool CallGrdbService(Factor factor)
 {
     try
     {
         var factorRequest = new Grdb
         {
             // ReSharper disable once PossibleNullReferenceException
             Desc1       = factor.Id.ToString(),
             DetailCode1 = factor.Shop.Accounting.DetailCode,
             DetailCode2 = factor.Customer.Accounting.DetailCode,
             RequestId   = Guid.NewGuid(),
             DetailCode3 = DetailCode3,
             StrDate     = factor.CreationTime.ToFa(),
             TypeNo      = TypeNo,
             Items       = new List <GrdbItem>
             {
                 new GrdbItem
                 {
                     GoodCode  = GoodCode,
                     Amount    = 1,
                     Fee       = factor.DiscountPrice,
                     ItemDesc1 = $"فروش {factor.FactorRaws.Sum(p=>p.Quantity)} قلم کالا"
                 }
             },
             AddReds = new List <AddOrRed>
             {
                 new AddOrRed
                 {
                     Id       = Id,
                     AddorRed = AddorRed,
                     RowId    = RowId,
                     Per      = Per,
                     Price    = factor.DiscountPrice - factor.SystemDiscountPrice
                 }
             }
         };
         string              objStringify = JsonConvert.SerializeObject(factorRequest);
         HttpContent         content      = new StringContent(objStringify, Encoding.UTF8, "application/json");
         HttpResponseMessage response     = _httpClient.PostAsync(FactorServiceName, content).Result;
         if (response.StatusCode == HttpStatusCode.Created)
         {
             var resultString = response.Content.ReadAsStringAsync().Result;
             var result       = JsonConvert.DeserializeObject <Grdb>(resultString);
             if (result.Id >= 0)
             {
                 factor.RegisterInAccountingSystem(result.Id.ToString());
                 return(true);
             }
             return(false);
         }
         else
         {
             _logger.Error($"######accounting RegisterInAccountingSystem GRDB web service  -- {DateTime.Now}");
             _logger.Error(JsonConvert.SerializeObject(factorRequest));
             _logger.Error(response);
             return(false);
         }
     }
     catch (Exception e)
     {
         _logger.Error($"######exception accounting RegisterInAccountingSystem GRDB web service   -- {DateTime.Now}");
         _logger.Error(e);
         return(false);
     }
 }