private void BuyThis_GetThat(sales_promotion Promo, Invoice Invoice, sales_invoice SalesInvoice) { if (Promo.types == sales_promotion.Type.BuyThis_GetThat) { if (Invoice.Details.Where(x => x.Item.id_item == Promo.reference && x.Quantity >= Promo.quantity_step).Count() > 0) { foreach (Detail _Detail in Invoice.Details.Where(x => x.Item.id_item == Promo.reference)) { if (Promo.quantity_step > 0) { Promo _Promo = new Promo(); _Promo.Type = sales_promotion.Type.BuyThis_GetThat; _Promo.Shared = true; _Detail.Promos.Add(_Promo); List <sales_invoice_detail> sid = SalesInvoice.sales_invoice_detail.Where(x => x.id_item == Promo.reference_bonus && x.IsPromo).ToList(); //Prevent double clicking button and adding extra bonus to sale. find better way to implement. Short term code. foreach (sales_invoice_detail _Detail_ in sid) { SalesInvoice.sales_invoice_detail.Remove(_Detail_); } sales_invoice_detail sales_invoice_detail = new sales_invoice_detail(); //Needed to calculate the discounts and unit prices further on. sales_invoice_detail.State = System.Data.Entity.EntityState.Added; using (db db = new db()) { item item = db.items.Where(x => x.id_item == Promo.reference_bonus).FirstOrDefault(); if (item != null) { sales_invoice_detail.id_vat_group = item.id_vat_group; sales_invoice_detail.id_item = item.id_item; sales_invoice_detail.item_description = item.name; //sales_invoice_detail.item = item; } item_price item_price = item.item_price.Where(x => x.item_price_list.is_default == true).FirstOrDefault(); if (item_price != null) { sales_invoice_detail.unit_price = item_price.value; sales_invoice_detail.discount = item_price.value; } } sales_invoice_detail.IsPromo = true; sales_invoice_detail.quantity = Math.Floor(_Detail.Quantity / Promo.quantity_step); SalesInvoice.sales_invoice_detail.Add(sales_invoice_detail); } } } } }
private void Calculate(ref Invoice Invoice) { foreach (var Promo in SalesPromotionLIST) { //if (Promo.types == sales_promotion.Type.Discount_onGrandTotal) //{ // if (Promo.quantity_max >= Invoice.GrandTotal && Promo.quantity_min <= Invoice.GrandTotal) // { // Promo _Promo = new Promo(); // _Promo.Type = sales_promotion.Type.Discount_onGrandTotal; // _Promo.Shared = true; // _Promo.DiscountValue = Invoice.GrandTotal - (Promo.is_percentage == false ? Promo.result_value : (Invoice.GrandTotal * (Promo.result_value))); // Invoice.Promos.Add(_Promo); // } // else if (Math.Floor(Invoice.GrandTotal / Promo.quantity_step) >= 1) // { // int Step = (int)Math.Floor(Invoice.GrandTotal / Promo.quantity_step); // Promo _Promo = new Promo(); // _Promo.Type = sales_promotion.Type.Discount_onGrandTotal; // _Promo.Shared = true; // _Promo.DiscountValue = Invoice.GrandTotal - (Promo.is_percentage == false ? (Promo.result_value * Step) : (Invoice.GrandTotal * (Promo.result_value * Step))); // Invoice.Promos.Add(_Promo); // } //} //if (Promo.types == sales_promotion.Type.Discount_onBrand) //{ // if (Invoice.Details.Where(x => x.Item.item_brand.id_brand == Promo.reference).Count() > 0) // { // foreach (Detail _Detail in Invoice.Details.Where(x => x.Item.item_brand.id_brand == Promo.reference)) // { // Promo _Promo = new Promo(); // _Promo.Type = sales_promotion.Type.Discount_onBrand; // _Promo.Shared = true; // _Promo.DiscountValue = _Detail.PriceVAT - (Promo.is_percentage == false ? Promo.result_value : (_Detail.PriceVAT * (Promo.result_value))); // _Detail.Promos.Add(_Promo); // } // } //} if (Promo.types == sales_promotion.Type.BuyThis_GetThat) { if (Invoice.Details.Where(x => x.Item.id_item == Promo.reference && x.Quantity >= Promo.quantity_step).Count() > 0) { foreach (Detail _Detail in Invoice.Details.Where(x => x.Item.id_item == Promo.reference)) { Promo _Promo = new Promo(); _Promo.Type = sales_promotion.Type.BuyThis_GetThat; _Promo.Shared = true; using (db db = new db()) { _Promo.DiscountValue = db.item_price.Where(x => x.id_item == _Detail.Item.id_item).FirstOrDefault().value; } _Detail.Promos.Add(_Promo); } } } } }
private void BuyTag_GetThat(sales_promotion Promo, Invoice Invoice, sales_invoice SalesInvoice) { if (Promo.types == sales_promotion.Type.BuyTag_GetThat) { decimal TotalQuantity = 0; List <Detail> DetailList = new List <Detail>(); List <DetailTag> DetailTagList = new List <DetailTag>(); using (db db = new db()) { DetailList = Invoice.Details.Where(x => x.Item.item_tag_detail.Any(y => y.id_tag == Promo.reference)).ToList(); if (DetailList.Count() > 0) { DetailTag DetailTag = new DetailTag(); DetailTag.Tag = Promo.reference; DetailTag.Quantity = DetailList.Sum(x => x.Quantity); DetailTagList.Add(DetailTag); } TotalQuantity = DetailList.Sum(x => x.Quantity); } if (DetailTagList.Count() > 0 && TotalQuantity >= Promo.quantity_step) { foreach (DetailTag _DetailTag in DetailTagList) { Promo _Promo = new Promo(); _Promo.Type = sales_promotion.Type.BuyTag_GetThat; _Promo.Shared = true; List <sales_invoice_detail> sid = SalesInvoice.sales_invoice_detail.Where(x => x.item.item_tag_detail.Any(y => y.id_tag == Promo.reference) && x.IsPromo).ToList(); //Prevent double clicking button and adding extra bonus to sale. find better way to implement. Short term code. foreach (sales_invoice_detail _Detail_ in sid) { SalesInvoice.sales_invoice_detail.Remove(_Detail_); } PromotionProduct window = new PromotionProduct() { Title = "Modal Dialog", ShowInTaskbar = false, // don't show the dialog on the taskbar Topmost = true, // ensure we're Always On Top ResizeMode = ResizeMode.NoResize, // remove excess caption bar buttons TagID = Promo.reference, TotalQuantity = Math.Floor(_DetailTag.Quantity / Promo.quantity_step), }; window.ShowDialog(); List <DetailProduct> DetailProduct = window.ProductList; if (DetailProduct != null) { foreach (DetailProduct _DetailProduct in DetailProduct) { sales_invoice_detail sales_invoice_detail = new sales_invoice_detail(); //Needed to calculate the discounts and unit prices further on. sales_invoice_detail.State = System.Data.Entity.EntityState.Added; using (db db = new db()) { item item = db.items.Where(x => x.id_item == _DetailProduct.ProductId).FirstOrDefault(); if (item != null) { sales_invoice_detail.id_vat_group = item.id_vat_group; sales_invoice_detail.id_item = item.id_item; sales_invoice_detail.item_description = item.name; } item_price item_price = item.item_price.Where(x => x.item_price_list.is_default == true).FirstOrDefault(); if (item_price != null) { sales_invoice_detail.unit_price = item_price.value; sales_invoice_detail.discount = item_price.value; } } sales_invoice_detail.IsPromo = true; sales_invoice_detail.quantity = _DetailProduct.Quantity; SalesInvoice.sales_invoice_detail.Add(sales_invoice_detail); } } } } } }