public frmSaleReceived(Sale PSale, string TotalCost)
        {
            InitializeComponent();

            sale = PSale;

            lblTotalCost.Text = TotalCost;
            spnGiftVoucher.EditValue = 0;
            spnCash.EditValue = 0;
            lblChange.Text = TotalCost;
            lblTotalQuintity.Text = Quantity.ToString();
        }
        public Sale CreateSale(string VoucherNumber, string barcode)
        {
            Sale sale = new Sale();
            if (ZuluHelper.CheckStringIsEmptyOrNull(VoucherNumber))
            {
                ProductVariant productVariant = GetSaleProductVariant(barcode);

                if (productVariant == null)
                    return null;

            }
            else
            {
                //TODO Retrieve order and Add ProductVariant in that order
            }

            return null;
        }
        //Function Key F11
        private void PrintVoucher()
        {
            Sale sale = new Sale();
                int totalQuantity = 0;
                List<SaleProduct> saleProducts = new List<SaleProduct>();

                if(txtBarcode.Text.Length > 0)
                    AddSaleProducts(int.Parse(spnQty.Text.ToString()));

                sale.VoucherNumber = lblVoucherNo.Text;
                sale.SellerID = ZuluContext.Current.CurrentUser.UserID;
                sale.CounterNumber = int.Parse(ApplicationSetting.ClientID);
                sale.SaleTotal = int.Parse(lblTotalAmount.Text.Replace(",", ""));
                sale.GiftVoucherAmount = 0;

                foreach (var loopSaleProductSupport in ZuluContext.Current.SaleProductSupports)
                {
                    totalQuantity = totalQuantity + loopSaleProductSupport.Quantity;
                }

                sale.SaleTotalQuantity = totalQuantity;
                sale.SaleStatus = 2;

                SaleService.SaveSaleVoucher(sale);

                foreach (var loopSaleProductSupport in ZuluContext.Current.SaleProductSupports)
                {
                    SaleProduct saleProduct = new SaleProduct();
                    saleProduct.SaleID = sale.SaleID;
                    saleProduct.ProductBarcode = loopSaleProductSupport.ProductBarcode;
                    saleProduct.ProductName = loopSaleProductSupport.ProductName;
                    saleProduct.Quantity = loopSaleProductSupport.Quantity;
                    saleProduct.UnitPrice = loopSaleProductSupport.UnitPrice;
                    saleProduct.TotalCost = loopSaleProductSupport.TotalCost;

                    saleProducts.Add(saleProduct);
                }

                SaleService.SaveSaleDetails(sale.SaleID, saleProducts);

            frmSaleReceived ReceivedForm = new frmSaleReceived(sale, lblNetAmount.Text);

            NewVoucher();
            ReceivedForm.ShowDialog();
        }
 //Fucntion Key F9
 private void PendingVoucher()
 {
     Sale sale = new Sale();
     sale.SaleStatus = 1;
 }
 /// <summary>
 /// Create a new Sale object.
 /// </summary>
 /// <param name="saleID">Initial value of the SaleID property.</param>
 public static Sale CreateSale(global::System.Int32 saleID)
 {
     Sale sale = new Sale();
     sale.SaleID = saleID;
     return sale;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Sales EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSales(Sale sale)
 {
     base.AddObject("Sales", sale);
 }
        /// <summary>
        /// Save Sale Voucher
        /// </summary>
        /// <param name="sale">The object of Sale</param>
        public void SaveSaleVoucher(Sale sale)
        {
            Sale existingData = GetSalebySaleID(sale.SaleID);

            if (existingData == null)
            {
                sale.CreatedOn = DateTime.Now;
                _context.Sales.AddObject(sale);
            }
            else
            {
                existingData.VoucherNumber = sale.VoucherNumber;
                existingData.SellerID = sale.SellerID;
                existingData.CounterNumber = sale.CounterNumber;
                existingData.CreatedOn = sale.CreatedOn;
                existingData.SaleTotalQuantity = sale.SaleTotalQuantity;
                existingData.SaleStatus = sale.SaleStatus;
                existingData.SaleTotal = sale.SaleTotal;
                existingData.GiftVoucherAmount = sale.GiftVoucherAmount;

                if (!_context.IsAttached(existingData))
                    _context.Sales.Attach(existingData);
            }
            _context.SaveChanges();
        }
        /// <summary>
        /// Get the new voucher number
        /// </summary>
        /// <returns>The new voucher number.</returns>
        public string GetNewVoucherNumber()
        {
            string BaseVoucherNumber = ApplicationSetting.BaseVoucherNumber;
            var sale = new Sale();

            var sales = _context.Sales.OrderByDescending(c => c.CreatedOn).Take(10).ToList();

            if (sales != null && sales.Count > 0)
            {
                sale = sales.OrderBy(c => c.CreatedOn).LastOrDefault(c => c.VoucherNumber.Contains(BaseVoucherNumber));
            }

            int intReceiptNumber = 0;

            if (sale == null || sale.SaleID == 0)
                return BaseVoucherNumber + "0001";

            string receiptNumber = sale.VoucherNumber.Substring(sale.VoucherNumber.Count() - 4);
            int.TryParse(receiptNumber, out intReceiptNumber);

            intReceiptNumber = intReceiptNumber + 1;

            return BaseVoucherNumber + intReceiptNumber.ToString("0000");
        }
        private Sale Save(Sale sale, List<SaleProductVariant> saleProductVariants)
        {
            int saleID = 0;

            foreach (var saleProductVariant in saleProductVariants)
            {
                SaleProductVariant spVariant = new SaleProductVariant();
                //productunitid.CreatedOn = DateTime.Now;

                //TODO Reduce the stock from product variant

                //TODO Save product Variants

                _context.SaleProductVariants.AddObject(spVariant);
            }

            _context.SaveChanges();

            return null;
        }
        /// <summary>
        /// Save Sale Voucher
        /// </summary>
        /// <param name="sale">The object of Sale</param>
        public void SaveSaleVoucher(Sale sale)
        {
            Sale existingData = GetSalebySaleID(sale.SaleID);

            if (existingData == null)
            {
                sale.CreatedOn = DateTime.Now;
                sale.UpdatedOn = DateTime.Now;
                _context.Sales.AddObject(sale);
            }
            else
            {
                existingData.SaleID = sale.SaleID;
                existingData.VoucherNumber = sale.VoucherNumber;
                existingData.MemberID = sale.MemberID;
                existingData.SellerID = sale.SellerID;
                existingData.SaleSubTotalExcTax = sale.SaleSubTotalExcTax;
                existingData.SaleSubTotalIncTax = sale.SaleSubTotalIncTax;
                existingData.SaleTotalDiscount = sale.SaleTotalDiscount;
                existingData.TaxRate = sale.TaxRate;
                existingData.SaleTax = sale.SaleTax;
                existingData.SaleTotal = sale.SaleTotal;
                existingData.RefundedAmount = sale.RefundedAmount;
                existingData.CreatedOn = existingData.CreatedOn;
                existingData.SaleTotalQuantity = sale.SaleTotalQuantity;
                existingData.SaleStatus = sale.SaleStatus;
                existingData.UpdatedOn = DateTime.Now;

                if (!_context.IsAttached(existingData))
                    _context.Sales.Attach(existingData);
            }
            _context.SaveChanges();
        }