예제 #1
0
        public bool CreateQuoteDetail(ExcelProxyQuotedetail quotedetail, EntityReference product)
        {
            using (var orgContext = new OrganizationServiceContext(service))
            {
                var newquoteDetail = new QuoteDetail()
                {
                    ProductId             = product,
                    new_SKU               = quotedetail.SKU,
                    new_manufacturingname = findVendor(quotedetail.Vendor),
                    IsPriceOverridden     = true,
                    Quantity              = Convert.ToInt32(quotedetail.quantity),
                    PricePerUnit          = new Money(Convert.ToDecimal(quotedetail.priceperunit)),
                    new_usdprice          = Convert.ToDecimal(quotedetail.new_usdprice),
                    new_totalpurchaseusd  = Convert.ToDouble(quotedetail.new_totalpurchaseusd),
                    new_koef              = Convert.ToDecimal(quotedetail.new_koef),
                    QuoteId               = mainEntityId,
                    new_sellingusd        = Convert.ToDouble(quotedetail.new_sellingusd),
                    new_generalsellingusd = Convert.ToDouble(quotedetail.new_generalsellingusd),
                    new_exchangerate      = Convert.ToDouble(quotedetail.exchangeRates),
                    UoMId = (from i in orgContext.CreateQuery <UoM>()
                             where i.Name == "Базовая единица"
                             select new EntityReference
                    {
                        Id = i.Id,
                        LogicalName = i.LogicalName,
                        Name = i.Name
                    }).FirstOrDefault()
                };

                try
                {
                    service.Create(newquoteDetail);
                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException(ex.Message);
                }
            }
            return(true);
        }
예제 #2
0
        public bool CreateQuoteDetail(ExcelProxyQuotedetail quotedetail, EntityReference product)
        {
            using (var orgContext = new OrganizationServiceContext(service))
            {
                var newquoteDetail = new QuoteDetail()
                {
                    ProductId               = product,
                    IsPriceOverridden       = true,
                    Quantity                = Convert.ToInt32(quotedetail.Count),
                    PricePerUnit            = new Money(Convert.ToDecimal(quotedetail.priceForOneHRN)),
                    new_priceprocurementUAH = new Money(Convert.ToDecimal(quotedetail.buyPriceHRN)),
                    new_totalpurchaseUAH    = new Money(Convert.ToDecimal(quotedetail.buyPriceAllHRN)),
                    new_pricepurchaseusd    = Convert.ToDouble(quotedetail.buyPriceAllUSD),
                    QuoteId              = mainEntityId,
                    new_kursspeka        = Convert.ToDouble(quotedetail.exchangeRates),
                    new_viborkurs        = new OptionSetValue(100000003),
                    new_totalpurchaseusd = Convert.ToDouble(quotedetail.totalUSD),
                    UoMId = (from i in orgContext.CreateQuery <UoM>()
                             where i.Name == "Базовая единица"
                             //where i.Id == new Guid("28FD5C9C-22F7-419C-BBBC-720523DD3666")
                             select new EntityReference
                    {
                        Id = i.Id,
                        LogicalName = i.LogicalName,
                        Name = i.Name
                    }).FirstOrDefault()
                };

                try
                {
                    service.Create(newquoteDetail);
                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException(ex.Message);
                }
            }
            return(true);
        }
예제 #3
0
        public void Processes(Annotation annotation, IOrganizationService service)
        {
            using (var orgContext = new OrganizationServiceContext(service))
            {
                var quoteMain = (from y in orgContext.CreateQuery <Quote>()
                                 where y.Id == annotation.ObjectId.Id
                                 select y).FirstOrDefault();

                var exel = new ExcelReader().ExcelOpenSpreadsheets(annotation.DocumentBody.ToString(),
                                                                   annotation.FileName.ToString());

                if (exel == null)
                {
                    return;
                }

                var data = new CreateNewProduct();
                List <ExcelProxyQuote> quote = new List <ExcelProxyQuote>();
                data.service      = service;
                data.mainEntityId = annotation.ObjectId;

                int line = 0;
                for (var i = 0; i < exel.Tables[0].Rows.Count; i++)
                {
                    if (exel.Tables[0].Rows[i][0].ToString() == "SKU")
                    {
                        line = i;
                        break;
                    }
                }

                for (int i = line + 1; i < exel.Tables[0].Rows.Count; i++)
                {
                    var product     = new ExcelProxyProduct();
                    var quotedetail = new ExcelProxyQuotedetail();

                    if (exel.Tables[0].Rows[i][1].ToString() != string.Empty && exel.Tables[0].Rows[i][0].ToString() != "Итого:")
                    {
                        product.SKU     = exel.Tables[0].Rows[i][0].ToString();
                        product.Vendor  = exel.Tables[0].Rows[i][1].ToString();
                        product.Product = exel.Tables[0].Rows[i][2].ToString();

                        quotedetail.Product               = exel.Tables[0].Rows[i][2].ToString();
                        quotedetail.Vendor                = exel.Tables[0].Rows[i][1].ToString();
                        quotedetail.SKU                   = exel.Tables[0].Rows[i][0].ToString();
                        quotedetail.quantity              = exel.Tables[0].Rows[i][3].ToString();
                        quotedetail.priceperunit          = exel.Tables[0].Rows[i][4].ToString();
                        quotedetail.baseamount            = exel.Tables[0].Rows[i][5].ToString();
                        quotedetail.new_usdprice          = exel.Tables[0].Rows[i][6].ToString();
                        quotedetail.new_totalpurchaseusd  = exel.Tables[0].Rows[i][7].ToString();
                        quotedetail.new_koef              = exel.Tables[0].Rows[i][8].ToString();
                        quotedetail.new_sellingusd        = exel.Tables[0].Rows[i][9].ToString();
                        quotedetail.new_generalsellingusd = exel.Tables[0].Rows[i][10].ToString();
                        quotedetail.exchangeRates         = exel.Tables[0].Rows[i][11].ToString();

                        quote.Add(new ExcelProxyQuote
                        {
                            new_usd      = exel.Tables[0].Rows[i][7].ToString(),
                            new_summausd = exel.Tables[0].Rows[i][10].ToString()
                        });

                        EntityReference idProduct = data.ProductFromSpec(product, quoteMain.PriceLevelId);

                        if (idProduct == null)
                        {
                            throw new InvalidPluginExecutionException("Product not found");
                        }
                        if (data.CreateQuoteDetail(quotedetail, idProduct) == false)
                        {
                            throw new InvalidPluginExecutionException("QuoteDetail don`t create");
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                double usd = (from i in quote
                              select Convert.ToDouble(i.new_usd)).Sum();
                double summusd = (from i in quote
                                  select Convert.ToDouble(i.new_summausd)).Sum();

                var updateQuote = new Quote()
                {
                    Id           = annotation.ObjectId.Id,
                    new_usd      = usd,
                    new_summausd = summusd
                };

                service.Update(updateQuote);
            }
        }
예제 #4
0
        internal void Processes(Annotation annotation, IOrganizationService service)
        {
            var exel = new ExcelReader().ExcelOpenSpreadsheets(annotation.DocumentBody.ToString(),
                                                               annotation.FileName.ToString());

            if (exel == null)
            {
                return;
            }

            if (exel.Tables[0].Rows[1][0].ToString() != "SKU")
            {
                return;
            }

            var data = new CreateNewProduct();
            List <ExcelProxyQuote> quote = new List <ExcelProxyQuote>();

            data.service      = service;
            data.mainEntityId = annotation.ObjectId;

            for (int i = 2; i < exel.Tables[0].Rows.Count; i++)
            {
                var product     = new ExcelProxyProduct();
                var quotedetail = new ExcelProxyQuotedetail();

                if (exel.Tables[0].Rows[i][0].ToString() != string.Empty && exel.Tables[0].Rows[i][0].ToString() != "Итого:")
                {
                    product.SKU                = exel.Tables[0].Rows[i][0].ToString();
                    product.Vendor             = exel.Tables[0].Rows[i][1].ToString();
                    product.recomendetPriceUSD = exel.Tables[0].Rows[i][10].ToString();
                    product.Product            = exel.Tables[0].Rows[i][2].ToString();

                    quotedetail.Product        = exel.Tables[0].Rows[i][2].ToString();
                    quotedetail.Count          = exel.Tables[0].Rows[i][3].ToString();
                    quotedetail.priceForOneHRN = exel.Tables[0].Rows[i][4].ToString();
                    quotedetail.priceAllHRN    = exel.Tables[0].Rows[i][5].ToString();
                    quotedetail.buyPriceHRN    = exel.Tables[0].Rows[i][6].ToString();
                    quotedetail.buyPriceAllHRN = exel.Tables[0].Rows[i][7].ToString();
                    quotedetail.buyPriceAllUSD = exel.Tables[0].Rows[i][11].ToString();
                    quotedetail.exchangeRates  = exel.Tables[0].Rows[i][13].ToString();
                    quotedetail.totalUSD       = exel.Tables[0].Rows[i][12].ToString();

                    quote.Add(new ExcelProxyQuote
                    {
                        Marza        = exel.Tables[0].Rows[i][8].ToString(),
                        MarzaPersent = exel.Tables[0].Rows[i][9].ToString(),
                        //discount = exel.Tables[0].Rows[i][13].ToString(),
                        //discountForPartners = exel.Tables[0].Rows[i][14].ToString(),
                        exchangeRates = exel.Tables[0].Rows[i][13].ToString()
                    });

                    EntityReference idProduct = data.ProductFromSpec(product);

                    if (idProduct == null)
                    {
                        throw new InvalidPluginExecutionException("Product not found");
                    }
                    if (data.CreateQuoteDetail(quotedetail, idProduct) == false)
                    {
                        throw new InvalidPluginExecutionException("QuoteDetail don`t create");
                    }
                }
                else
                {
                    break;
                }
            }

            decimal sum = (from i in quote
                           select Convert.ToDecimal(i.Marza)).Sum();
            decimal percent = (from i in quote
                               select Convert.ToDecimal(i.MarzaPersent)).Average();
            decimal discount = (from i in quote
                                select Convert.ToDecimal(i.discount)).Average();
            double rates = (from i in quote
                            select Convert.ToDouble(i.exchangeRates)).Average();

            using (var orgContext = new OrganizationServiceContext(service))
            {
                var quoteMain = (from y in orgContext.CreateQuery <Quote>()
                                 where y.Id == annotation.ObjectId.Id
                                 select y).FirstOrDefault();

                var updateQuote = new Quote()
                {
                    Id                   = annotation.ObjectId.Id,
                    new_marginUSD        = new Money((quoteMain.new_marginUSD == null ? decimal.Zero : quoteMain.new_marginUSD.Value) + sum),
                    new_morginpercentage = percent == 0 ? 0 : (quoteMain.new_morginpercentage ?? 0 + percent) * 100,
                    new_exchangerate     = quoteMain.new_exchangerate ?? 0 + rates/*,
                                                                                   * DiscountPercentage = quoteMain.DiscountPercentage ?? 0 + discount*/
                };

                service.Update(updateQuote);
            }
        }