Пример #1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Baskets EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBaskets(Basket basket)
 {
     base.AddObject("Baskets", basket);
 }
Пример #2
0
 /// <summary>
 /// Create a new Basket object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 public static Basket CreateBasket(global::System.Int32 id)
 {
     Basket basket = new Basket();
     basket.ID = id;
     return basket;
 }
Пример #3
0
        public Basket BasketCreate(BasketView i)
        {
            // здесь
            // Create spare_in_spare_outgo - для каждого прихода, из которых берется товар в отгрузку
            // Edit spare_in_spare_income
            // Create OfferingInBasketItem
            int SpareID = i.SpareID.Value;

            // Create Basket
            Basket b = new Basket();
            b.CreatedOn = DateTime.Now;
            b.Pbyr = i.Pbyr;
            b.Peur = i.Peur;
            b.Prur = i.Prur;
            b.Pusd = i.Pusd;
            b.Q = i.Q;
            b.SaleID = i.SaleID;
            b.SpareID = SpareID;
            objDataContext.AddToBaskets(b);
            objDataContext.SaveChanges();

            decimal unallocatedQ = b.Q.Value;

            // Edit spare_in_spare_income
            List<SpareInSpareIncomeView> incomes = objDataContext.SpareInSpareIncomeViews.Where(x => (x.SpareID == b.SpareID && x.QRest > 0)).OrderBy(x => x.SpareIncomeDate).ToList();
            List<SpareInSpareIncomeView> LinkedIncomes = new List<SpareInSpareIncomeView>();
            List<decimal> Qs = new List<decimal>();
            foreach (SpareInSpareIncomeView income in incomes)
            {
                spare_in_spare_income inc = objDataContext.spare_in_spare_income.FirstOrDefault(x => x.id == income.id);
                if (income.QRest >= unallocatedQ)
                {
                    decimal q = unallocatedQ;
                    inc.QRest -= q;
                    objDataContext.SaveChanges();
                    Qs.Add(q);
                    LinkedIncomes.Add(income);
                    break;
                }
                else
                {
                    decimal q = inc.QRest.Value;
                    unallocatedQ -= q;
                    inc.QRest = 0;
                    objDataContext.SaveChanges();
                    Qs.Add(q);
                    LinkedIncomes.Add(income);
                }
            }
            SpareInSpareIncomeView ActualIncome = LinkedIncomes.OrderByDescending(x => x.SpareIncomeDate).FirstOrDefault();
            spare_outgo outgo = SpareOutgoOpened();
            foreach (SpareInSpareIncomeView income in LinkedIncomes)
            {
                int ind = LinkedIncomes.IndexOf(income);

                // Create spare_in_spare_outgo - для каждого прихода, из которых берется товар в отгрузку
                // при этом подставляем цены и проценты из первого прихода

                spare_in_spare_outgo siso = new spare_in_spare_outgo();

                // [basic_price]    - цена в базовой валюте
                // получим из профиля код базовой валюты
                settings_profile profile = getProfileCurrent();
                string BasicCurrencyCode = profile.BasicCurrencyCode;
                siso.basic_price = ActualIncome.POutBasic;
                /*decimal basic_price = 0;
                switch (BasicCurrencyCode)
                {
                    case "RUR":
                        basic_price = b.Prur.Value;
                        break;

                    case "BYR":
                        basic_price = b.Pbyr.Value;
                        break;

                    case "EUR":
                        basic_price = b.Peur.Value;
                        break;

                    case "USD":
                        basic_price = b.Pusd.Value;
                        break;
                }
                outgo.basic_price = basic_price;                */
                siso.description = "";
                siso.discount = 0;
                siso.markup_percentage = ActualIncome.Markup;
                siso.num = ind;

                // [purchase_price]     - указать цену отпускную в валюте накладной отгрузки
                decimal price = 0;
                if (outgo.currency == null)
                    outgo.currencyReference.Load();
                switch (outgo.currency.code)
                {
                    case "RUR":
                        price = b.Prur.Value;
                        break;

                    case "BYR":
                        price = b.Pbyr.Value;
                        break;

                    case "EUR":
                        price = b.Peur.Value;
                        break;

                    case "USD":
                        price = b.Pusd.Value;
                        break;
                }
                siso.purchase_price = price;
                siso.quantity = Qs[ind];
                siso.spare = objDataContext.spares.FirstOrDefault(x => x.id == SpareID);
                siso.spare_in_spare_income = objDataContext.spare_in_spare_income.FirstOrDefault(x => x.id == income.id);
                siso.spare_outgo = outgo;
                siso.total_sum = siso.quantity * siso.purchase_price.Value;
                siso.vat_rate = getZeroVatRate();
                objDataContext.AddTospare_in_spare_outgo(siso);
                objDataContext.SaveChanges();

                // Create OfferingInBasketItem
                OfferingInBasketItem o = new OfferingInBasketItem();
                o.BasketItemID = b.ID;
                o.OfferingIncomeID = income.id;
                o.OfferingOutgoID = siso.id;
                o.Q = Qs[ind];
                objDataContext.AddToOfferingInBasketItems(o);
                objDataContext.SaveChanges();
            }
            objDataContext.SaveChanges();
            return b;
        }