/// <summary>
 /// Deprecated Method for adding a new object to the OfferingInBasketItems EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOfferingInBasketItems(OfferingInBasketItem offeringInBasketItem)
 {
     base.AddObject("OfferingInBasketItems", offeringInBasketItem);
 }
 /// <summary>
 /// Create a new OfferingInBasketItem object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="basketItemID">Initial value of the BasketItemID property.</param>
 /// <param name="offeringIncomeID">Initial value of the OfferingIncomeID property.</param>
 /// <param name="offeringOutgoID">Initial value of the OfferingOutgoID property.</param>
 /// <param name="q">Initial value of the Q property.</param>
 public static OfferingInBasketItem CreateOfferingInBasketItem(global::System.Int32 id, global::System.Int32 basketItemID, global::System.Int32 offeringIncomeID, global::System.Int32 offeringOutgoID, global::System.Decimal q)
 {
     OfferingInBasketItem offeringInBasketItem = new OfferingInBasketItem();
     offeringInBasketItem.ID = id;
     offeringInBasketItem.BasketItemID = basketItemID;
     offeringInBasketItem.OfferingIncomeID = offeringIncomeID;
     offeringInBasketItem.OfferingOutgoID = offeringOutgoID;
     offeringInBasketItem.Q = q;
     return offeringInBasketItem;
 }
Beispiel #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;
        }