private void addPayment_Click(object sender, RoutedEventArgs e)
        {
            double paymentAmount = 0;

            if (payment.Text != "0" && paymentDueDouble != 0 && double.TryParse(payment.Text, out paymentAmount))
            {
                totalPaymentDouble  += paymentAmount;
                totalPayment.Content = totalPaymentDouble;

                paymentDueDouble   = grandTotalDouble - totalPaymentDouble;
                paymentDue.Content = paymentDueDouble;
                paymentDatagrid.Items.Add(new { Mode = paymentMode.Text, Amount = paymentAmount, Date = paymentDate });

                Journal_Detail jd = new Journal_Detail();
                jd.Amount = (decimal)paymentAmount;

                if (paymentMode.SelectedIndex == 0)
                {
                    jd.Sub_Account_ID = 1;
                }
                else if (paymentMode.SelectedIndex == 1)
                {
                    jd.Sub_Account_ID = 3;
                }
                //else if (paymentMode.SelectedIndex == 2)
                //    mode = "D";
                //else if (paymentMode.SelectedIndex == 3)
                //    mode = "C";

                //jd.SNO = paymentSerial++; ///this will be serialized in DB insertion
                jd.Narration = "";
                listJournal_Detail.Add(jd);

                payment.Text = "";
                paymentDatagrid.SelectedIndex = paymentDatagrid.Items.Count - 1;
                //paymentDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
                paymentMode.Focus();
            }
            else
            {
                MessageBox.Show("error in payment section");
            }

            //Type t = paymentDatagrid.Items.GetItemAt(0).GetType();
            //PropertyInfo p = t.GetProperty("Mode");
            //object v = p.GetValue(paymentDatagrid.Items.GetItemAt(0), null);
            //Console.WriteLine(v.ToString());
        }
        public static bool PostPurchaseJournal(Journal j, List <Product_Supplier> listProduct_Supplier, List <Journal_Detail> listJournal_Details, int amount, double paymentDue)
        {
            int serial = 1;

            try
            {
                if (listJournal_Details.Count > 0)
                {
                    foreach (var item in listJournal_Details)
                    {
                        item.SNO     = serial++;
                        item.Journal = j;
                    }
                }
                else
                {
                    Journal_Detail jd = new Journal_Detail();
                    jd.SNO            = 1;
                    jd.Sub_Account_ID = 1; ///cash account
                    jd.Amount         = amount;
                    jd.Narration      = "";
                    jd.Journal        = j;
                }

                foreach (var ps in listProduct_Supplier)
                {
                    ps.Journal = j;
                }

                //var ps = db.Product_Suppliers.OrderByDescending(ep => ep.ID).FirstOrDefault();
                //ps.Journal = j; ///adding journal id in product supplier

                db.Journals.InsertOnSubmit(j);
                //db.SubmitChanges();

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public static Journal PostSalesJournal(Sale sale, Journal j, List <Journal_Detail> listJournal_Details, int amount, double paymentDue)///DateTime datetime, int sub_accountID1, int sub_accountID2, int jurnalType, int status, int prepBy, int authBy, int amount
        {
            try
            {
                int serial = 1;

                if (listJournal_Details.Count > 0)
                {
                    foreach (var item in listJournal_Details)
                    {
                        item.SNO     = serial++;
                        item.Journal = j;
                    }
                }
                else
                {
                    Journal_Detail jd = new Journal_Detail();
                    jd.SNO            = 1;
                    jd.Sub_Account_ID = 1; ///cash account
                    jd.Amount         = amount;
                    jd.Narration      = "";
                    jd.Journal        = j;
                }

                sale.Journal = j; /// assigning journal id in sales invoice

                //var sale = db.Sales.OrderByDescending(ep => ep.Invoice_ID).FirstOrDefault();
                //sale.Journal = j;

                db.Journals.InsertOnSubmit(j);
                //db.SubmitChanges();

                return(j);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }