Exemplo n.º 1
0
 public async Task <int> SaveLedgerGeneralAsync(LedgerGeneral Ledgergeneral)
 {
     if (Ledgergeneral.LedgergeneralId < 1)
     {
         Context.Ledgergenerals.Add(Ledgergeneral);
     }
     else
     {
         Context.Entry(Ledgergeneral).State = EntityState.Modified;
     }
     return(await SaveAllAsync());
 }
Exemplo n.º 2
0
 public int SaveLedgerGeneral(LedgerGeneral Ledgergeneral)
 {
     if (Ledgergeneral.LedgergeneralId < 1)
     {
         Context.Ledgergenerals.Add(Ledgergeneral);
     }
     else
     {
         Context.Entry(Ledgergeneral).State = System.Data.Entity.EntityState.Modified;
     }
     return(SaveAll());
 }
Exemplo n.º 3
0
        private string GetBalance(LedgerGeneral a)
        {
            var     debitbalance  = Ledgergenerals.Where(b => b.LedgerAccountId == a.LedgerAccountId).Where(b => b.JournalEntryDate <= a.JournalEntryDate).Sum(b => b.Debit);
            var     creditbalance = Ledgergenerals.Where(b => b.LedgerAccountId == a.LedgerAccountId).Where(b => b.JournalEntryDate <= a.JournalEntryDate).Sum(b => b.Credit);
            decimal balance       = 0;
            string  suffix        = "";

            if (debitbalance > creditbalance)
            {
                balance = debitbalance - creditbalance;
                suffix  = "Dr";
            }
            if (debitbalance < creditbalance)
            {
                balance = creditbalance - debitbalance;
                suffix  = "Cr";
            }
            return(balance.ToString() + " " + suffix);
        }
Exemplo n.º 4
0
        public string ResolveOpp(int transactionId, int ledgerAccountId)
        {
            var v = context.LedgerTransactions.Where(a => a.LedgerTransactionId == transactionId);
            List <Ledgergeneral> ld         = new List <Ledgergeneral>();
            List <Ledgergeneral> ldd        = new List <Ledgergeneral>();
            Ledgergeneral        thisledger = new LedgerGeneral();
            List <OppAccount>    oppacounts = new List <ViewModels.OppAccount>();

            foreach (var item in v)
            {
                foreach (var i in item.LedgerGenerals)
                {
                    ldd.Add(i);
                    if (i.LedgerAccountId == ledgerAccountId)
                    {
                        thisledger = i;
                        continue;
                    }
                    ld.Add(i);
                }
            }
            StringBuilder sb        = new StringBuilder();
            Ledgergeneral maxdebit  = new LedgerGeneral();
            Ledgergeneral maxcredit = new LedgerGeneral();

            maxdebit  = ldd.Where(a => a.Debit == ldd.Max(b => b.Debit)).FirstOrDefault();
            maxcredit = ldd.Where(a => a.Credit == ldd.Max(b => b.Credit)).FirstOrDefault();
            bool debitbigger = false;

            if (maxdebit.Debit > maxcredit.Credit)
            {
                debitbigger = true;
            }
            else if (maxcredit.Credit > maxdebit.Debit)
            {
                debitbigger = false;
            }


            if (thisledger.Credit > 0)
            {
                if (thisledger == maxcredit)
                {
                    if (debitbigger == false)
                    {
                        foreach (var item in ld)
                        {
                            if (item.Credit > 0)
                            {
                                sb.AppendLine(item.Credit.ToString());
                            }
                            if (item.Debit > 0)
                            {
                                sb.AppendLine(item.Debit.ToString());
                            }
                        }
                    }
                    else
                    {
                        sb.AppendLine(thisledger.Credit.ToString());
                        return(sb.ToString());
                    }
                }
                else
                {
                    sb.AppendLine(thisledger.Credit.ToString());
                    return(sb.ToString());
                }
            }
            else if (thisledger.Debit > 0)
            {
                if (thisledger == maxdebit)
                {
                    if (debitbigger == true)
                    {
                        foreach (var item in ld)
                        {
                            if (item.Credit > 0)
                            {
                                sb.AppendLine(item.Credit.ToString());
                            }
                            if (item.Debit > 0)
                            {
                                sb.AppendLine(item.Debit.ToString());
                            }
                        }
                    }
                    else
                    {
                        sb.AppendLine(thisledger.Debit.ToString());
                        return(sb.ToString());
                    }
                }
                else
                {
                    sb.AppendLine(thisledger.Debit.ToString());
                    return(sb.ToString());
                }
            }

            return(sb.ToString());
        }
        private void SaveJournalEntry()
        {
            try
            {
                if (App.IsLicenseValid == false)
                {
                    MessageBox.Show("Your License Has Expired");
                    return;
                }



                if (((FinanceViewModel)DataContext).FakeUser == null)
                {
                    throw new Exception("Please Login");
                }
                ((App)Application.Current).CurrentUser = ((FinanceViewModel)DataContext).FakeUser;
                //if(FakeUser.UserRole.UserInRole!=UserRoles.Accountant && FakeUser.UserRole.UserInRole != UserRoles.Administrator)
                //{
                //    throw new Exception("You have no authority to enter journals");
                //}
                int TransactionId = 0;
                try
                {
                    var v = ((FinanceViewModel)DataContext).LedgerTransactions.DefaultIfEmpty().Max(a => a.LedgerTransactionId);
                    TransactionId = v + 1;
                }
                catch
                {
                    TransactionId = 1;
                }
                jdsd = new List <JournalData>();
                jdsc = new List <JournalData>();
                foreach (var item in xt1.Children)
                {
                    JournalData jd = new JournalData();
                    if (item is StackPanel)
                    {
                        StackPanel s = item as StackPanel;
                        foreach (var cnt in s.Children)
                        {
                            if (cnt is TextBox)
                            {
                                TextBox t1 = cnt as TextBox;
                                if (!string.IsNullOrEmpty(t1.Text))
                                {
                                    decimal d = 0;
                                    if (decimal.TryParse(t1.Text, out d))
                                    {
                                        jd.amount  = d;
                                        jd.EntryId = TransactionId;
                                    }
                                }
                            }
                            else if (cnt is ComboBox)
                            {
                                ComboBox c1 = cnt as ComboBox;
                                if (c1.SelectedIndex > -1)
                                {
                                    var la = c1.SelectedItem as LedgerAccount;
                                    // var logic =.Where(a => a.parentLedgerAccount.LedgerAccountId == la.LedgerAccountId).FirstOrDefault();
                                    foreach (var account in ((FinanceViewModel)DataContext).LedgerAccounts)
                                    {
                                        if (account.parentLedgerAccount != null)
                                        {
                                            if (la.LedgerAccountId == account.parentLedgerAccount.LedgerAccountId)
                                            {
                                                throw new Exception(la.AccountName + " Cannot be Selected");
                                            }
                                        }
                                    }
                                    jd.LedgerAccountId = la.LedgerAccountId;
                                }
                            }
                        }
                        if (jd.LedgerAccountId > 0 && jd.amount > 0)
                        {
                            jdsd.Add(jd);
                        }
                    }
                }
                foreach (var item in cdt1.Children)
                {
                    JournalData jd = new JournalData();
                    if (item is StackPanel)
                    {
                        StackPanel s = item as StackPanel;
                        foreach (var cnt in s.Children)
                        {
                            if (cnt is TextBox)
                            {
                                TextBox t1 = cnt as TextBox;
                                if (!string.IsNullOrEmpty(t1.Text))
                                {
                                    decimal d = 0;
                                    if (decimal.TryParse(t1.Text, out d))
                                    {
                                        jd.amount  = d;
                                        jd.EntryId = TransactionId;
                                    }
                                }
                            }
                            else if (cnt is ComboBox)
                            {
                                ComboBox c1 = cnt as ComboBox;
                                if (c1.SelectedIndex > -1)
                                {
                                    var la = c1.SelectedItem as LedgerAccount;
                                    // var logic =.Where(a => a.parentLedgerAccount.LedgerAccountId == la.LedgerAccountId).FirstOrDefault();
                                    foreach (var account in ((FinanceViewModel)DataContext).LedgerAccounts)
                                    {
                                        if (account.parentLedgerAccount != null)
                                        {
                                            if (la.LedgerAccountId == account.parentLedgerAccount.LedgerAccountId)
                                            {
                                                throw new Exception(la.AccountName + " Cannot be Selected");
                                            }
                                        }
                                    }
                                    jd.LedgerAccountId = (c1.SelectedItem as LedgerAccount).LedgerAccountId;
                                }
                            }
                        }
                        if (jd.LedgerAccountId > 0 && jd.amount > 0)
                        {
                            jdsc.Add(jd);
                        }
                    }
                }
                if (!IsJournalEntryValid())
                {
                    return;
                }
                if (jdsd.Count < 1 || jdsc.Count < 1)
                {
                    return;
                }
                else
                {
                    var totaldebits  = jdsd.Sum(a => a.amount);
                    var totalcredits = jdsc.Sum(a => a.amount);
                    if (totaldebits != totalcredits)
                    {
                        throw new Exception("Debit and Credit Do Not Balance \nOr You May have Some Error in Assigning Accounts");
                    }
                }
                //if (((App)Application.Current).V)
                //{
                //    MessageBox.Show("trial version");
                //    return;
                //}
                List <string>     debitaccounts = new List <string>();
                List <string>     creditamounts = new List <string>();
                LedgerTransaction lt            = new LedgerTransaction();
                //lt.LedgerTransactionId = TransactionId;
                lt.Date        = ((FinanceViewModel)DataContext).JournalDate;
                lt.Description = textBox1.Text;

                lt.UserId = ((FinanceViewModel)DataContext).FakeUser.UserId;
                ((FinanceViewModel)DataContext).Service.InsertLedgerTransaction(lt);
                foreach (var item in jdsd)
                {
                    LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                    ltd.Amount              = item.amount;
                    ltd.LedgerAccountId     = item.LedgerAccountId;
                    ltd.LedgerTransactionId = lt.LedgerTransactionId;
                    ((FinanceViewModel)DataContext).Service.InsertLedgerTransactionDetail(ltd);
                    LedgerGeneral lg = new LedgerGeneral();
                    lg.LedgerAccountId     = item.LedgerAccountId;
                    lg.LedgerTransactionId = lt.LedgerTransactionId;
                    lg.Debit            = item.amount;
                    lg.JournalEntryDate = lt.Date;
                    ((FinanceViewModel)DataContext).Service.InsertLedgerGeneral(lg);
                    debitaccounts.Add(lg.LedgerAccount.AccountName);
                }
                foreach (var item in jdsc)
                {
                    LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                    ltd.Amount              = item.amount;
                    ltd.LedgerAccountId     = item.LedgerAccountId;
                    ltd.LedgerTransactionId = lt.LedgerTransactionId;
                    ((FinanceViewModel)DataContext).Service.InsertLedgerTransactionDetail(ltd);
                    LedgerGeneral lg = new LedgerGeneral();
                    lg.LedgerAccountId     = item.LedgerAccountId;
                    lg.LedgerTransactionId = lt.LedgerTransactionId;
                    lg.Credit           = item.amount;
                    lg.JournalEntryDate = lt.Date;
                    ((FinanceViewModel)DataContext).Service.InsertLedgerGeneral(lg);
                    creditamounts.Add(lg.LedgerAccount.AccountName);
                }
                if (lt.Description.Length < 1)
                {
                    StringBuilder sb = new StringBuilder();
                    // sb.Append("Debit Account(s)");
                    foreach (var item in debitaccounts)
                    {
                        sb.AppendLine(item);
                    }
                    // sb.Append("Credit Account(s)");
                    foreach (var item in creditamounts)
                    {
                        sb.AppendLine(item);
                    }
                    lt.Description = sb.ToString();
                }


                ((FinanceViewModel)DataContext).Service.SaveAll();
                //  Messenger.Default.Send<UpdateView>(new Utility.UpdateView());
                ((FinanceViewModel)DataContext).Init2();
                // ((FinanceViewModel)DataContext).getJournalsBydate();
                ResetControls();
            }
            catch (Exception ex)
            {
                if (ex.Message == "Debit and Credit Do Not Balance")
                {
                    throw ex;
                }
                else
                {
                    ResetControls();
                    throw ex;
                }
            }
        }
Exemplo n.º 6
0
        //private string ResolveBalance(string StartDate, string EndDate, int transactionId, int ledgerAccountId)
        //{

        //    var v = Ledgergenerals
        //        .Where(a => a.JournalEntryDate >= DateTime.Parse("10/11/2017") && a.JournalEntryDate <= DateTime.Parse("10/12/2017"))
        //       .Where(a => a.LedgerAccountId == 1);

        //    List<Ledgergeneral> ldd = new List<Ledgergeneral>();

        //    List<OppAccount> oppacounts = new List<ViewModels.OppAccount>();
        //    foreach (var item in v)
        //    {
        //        ldd.Add(item);
        //    }
        //    decimal creditsum = ldd.Sum(a => a.Credit);
        //    decimal debitsum = ldd.Sum(a => a.Debit);
        //    string balance = "";
        //    if (creditsum > debitsum)
        //    {
        //        balance = "cBalance b/d" + (creditsum - debitsum).ToString();
        //    }
        //    if (debitsum > creditsum)
        //    {
        //        balance = "cBalance b/d" + (debitsum - creditsum).ToString();
        //    }
        //    return balance;
        //}

        public string ResolveOpp(int transactionId, int ledgerAccountId)
        {
            StringBuilder sb         = new StringBuilder();
            LedgerGeneral thisledger = new LedgerGeneral();
            var           v          = LedgerTransactions.Where(a => a.LedgerTransactionId == transactionId);


            List <LedgerGeneral> ld  = new List <LedgerGeneral>();
            List <LedgerGeneral> ldd = new List <LedgerGeneral>();

            //List<OppAccount> oppacounts = new List<ViewModels.OppAccount>();
            foreach (var item in v)
            {
                foreach (var i in item.LedgerGenerals)
                {
                    ldd.Add(i);
                    if (i.LedgerAccountId == ledgerAccountId)
                    {
                        thisledger = i;
                        continue;
                    }
                    ld.Add(i);
                }
            }
            if (ldd.Count() > 2)
            {
                LedgerGeneral maxdebit  = new LedgerGeneral();
                LedgerGeneral maxcredit = new LedgerGeneral();
                maxdebit  = ldd.Where(a => a.Debit == ldd.Max(b => b.Debit)).FirstOrDefault();
                maxcredit = ldd.Where(a => a.Credit == ldd.Max(b => b.Credit)).FirstOrDefault();
                bool debitbigger = false;
                if (maxdebit.Debit > maxcredit.Credit)
                {
                    debitbigger = true;
                }
                else if (maxcredit.Credit > maxdebit.Debit)
                {
                    debitbigger = false;
                }


                if (thisledger.Credit > 0)
                {
                    if (thisledger == maxcredit)
                    {
                        if (debitbigger == false)
                        {
                            foreach (var item in ld)
                            {
                                if (item.Credit > 0)
                                {
                                    var name = item.LedgerAccount.AccountName;
                                    if (name.Length > 8)
                                    {
                                        name = name.Substring(0, 8);
                                    }
                                    sb.Append(name + "                   ");
                                    sb.AppendLine(item.Credit.ToString());
                                }
                                if (item.Debit > 0)
                                {
                                    var name = item.LedgerAccount.AccountName;
                                    if (name.Length > 8)
                                    {
                                        name = name.Substring(0, 8);
                                    }
                                    sb.Append(name + "                   ");
                                    sb.AppendLine(item.Debit.ToString());
                                }
                            }
                        }
                        else
                        {
                            sb.Append(maxdebit.LedgerAccount.AccountName + "                   ");
                            sb.AppendLine(thisledger.Credit.ToString());
                            return(sb.ToString());
                        }
                    }
                    else
                    {
                        sb.Append(maxdebit.LedgerAccount.AccountName + "                   ");
                        sb.AppendLine(thisledger.Credit.ToString());
                        return(sb.ToString());
                    }
                }
                else if (thisledger.Debit > 0)
                {
                    if (thisledger == maxdebit)
                    {
                        if (debitbigger == true)
                        {
                            foreach (var item in ld)
                            {
                                if (item.Credit > 0)
                                {
                                    var name = item.LedgerAccount.AccountName;
                                    if (name.Length > 8)
                                    {
                                        name = name.Substring(0, 8);
                                    }
                                    sb.Append(name + "                   ");
                                    sb.AppendLine(item.Credit.ToString());
                                }
                                if (item.Debit > 0)
                                {
                                    var name = item.LedgerAccount.AccountName;
                                    if (name.Length > 8)
                                    {
                                        name = name.Substring(0, 8);
                                    }
                                    sb.Append(name + "                   ");
                                    sb.AppendLine(item.Debit.ToString());
                                }
                            }
                        }
                        else
                        {
                            sb.Append(maxcredit.LedgerAccount.AccountName + "                   ");
                            sb.AppendLine(thisledger.Debit.ToString());
                            return(sb.ToString());
                        }
                    }
                    else
                    {
                        sb.Append(maxcredit.LedgerAccount.AccountName + "                   ");
                        sb.AppendLine(thisledger.Debit.ToString());
                        return(sb.ToString());
                    }
                }
            }
            else
            {
                LedgerGeneral oppositeaccount = new LedgerGeneral();
                foreach (var item in ldd)
                {
                    if (item.LedgerAccountId != ledgerAccountId)
                    {
                        oppositeaccount = item;
                        break;
                    }
                }


                sb.Append(oppositeaccount.LedgerAccount.AccountName + "                   ");
                if (thisledger.Debit > 0)
                {
                    sb.AppendLine(thisledger.Debit.ToString());
                }
                if (thisledger.Credit > 0)
                {
                    sb.AppendLine(thisledger.Credit.ToString());
                }
            }


            return(sb.ToString().Trim());
        }
Exemplo n.º 7
0
        private void SaveInLedger(SaleOrder SaleOrder, string Mode, LedgerAccount SelectedCustomer, LedgerAccount SelectedBankAccount, string ChequeNumber)
        {
            LedgerTransaction lt = new LedgerTransaction();

            lt.Date        = DateTime.Now;
            lt.UserId      = 1;
            lt.Description = "sales  ";
            Context.LedgerTransactions.Add(lt);
            var result = Context.SaveChanges();

            if (result > 0)
            {
                if (SaleOrder.Due <= 0)
                {
                    if (Mode == "IsCash")
                    {
                        LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                        ltd.Amount = SaleOrder.AmountAfterDiscount;
                        ltd.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd.LedgerAccountId     = 1;
                        Context.LedgerTransactionDetails.Add(ltd);
                        Context.SaveChanges();

                        LedgerTransactionDetail ltd1 = new LedgerTransactionDetail();
                        ltd1.Amount = SaleOrder.AmountAfterDiscount;
                        ltd1.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd1.LedgerAccountId     = 2;
                        Context.LedgerTransactionDetails.Add(ltd1);
                        Context.SaveChanges();

                        LedgerGeneral lg = new LedgerGeneral();
                        lg.LedgerAccountId     = 1;
                        lg.LedgerTransactionId = lt.LedgerTransactionId;
                        lg.Debit            = SaleOrder.AmountAfterDiscount;
                        lg.Credit           = 0;
                        lg.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg);
                        Context.SaveChanges();

                        LedgerGeneral lg1 = new LedgerGeneral();
                        lg1.LedgerAccountId     = 2;
                        lg1.LedgerTransactionId = lt.LedgerTransactionId;
                        lg1.Credit           = SaleOrder.AmountAfterDiscount;
                        lg1.Debit            = 0;
                        lg1.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg1);
                        Context.SaveChanges();
                    }
                    else if (Mode == "IsCredit")
                    {
                        LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                        ltd.Amount = SaleOrder.AmountAfterDiscount;
                        ltd.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd.LedgerAccountId     = 2;
                        Context.LedgerTransactionDetails.Add(ltd);
                        Context.SaveChanges();

                        LedgerTransactionDetail ltd1 = new LedgerTransactionDetail();
                        ltd1.Amount = SaleOrder.AmountAfterDiscount;
                        ltd1.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd1.LedgerAccountId     = SelectedCustomer.LedgerAccountId;
                        Context.LedgerTransactionDetails.Add(ltd1);
                        Context.SaveChanges();

                        LedgerGeneral lg = new LedgerGeneral();
                        lg.LedgerAccountId     = 2;
                        lg.LedgerTransactionId = lt.LedgerTransactionId;
                        lg.Debit            = 0;
                        lg.Credit           = SaleOrder.AmountAfterDiscount;
                        lg.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg);
                        Context.SaveChanges();

                        LedgerGeneral lg1 = new LedgerGeneral();
                        lg1.LedgerAccountId     = SelectedCustomer.LedgerAccountId;
                        lg1.LedgerTransactionId = lt.LedgerTransactionId;
                        lg1.Credit           = 0;
                        lg1.Debit            = SaleOrder.AmountAfterDiscount;
                        lg1.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg1);
                        Context.SaveChanges();
                    }
                    else if (Mode == "IsBank")
                    {
                        LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                        ltd.Amount = SaleOrder.AmountAfterDiscount;
                        ltd.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd.LedgerAccountId     = 2;
                        Context.LedgerTransactionDetails.Add(ltd);
                        Context.SaveChanges();

                        LedgerTransactionDetail ltd1 = new LedgerTransactionDetail();
                        ltd1.Amount = SaleOrder.AmountPaid;
                        ltd1.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd1.LedgerAccountId     = SelectedBankAccount.LedgerAccountId;
                        Context.LedgerTransactionDetails.Add(ltd1);
                        Context.SaveChanges();

                        LedgerGeneral lg = new LedgerGeneral();
                        lg.LedgerAccountId     = 2;
                        lg.LedgerTransactionId = lt.LedgerTransactionId;
                        lg.Debit            = 0;
                        lg.Credit           = SaleOrder.AmountAfterDiscount;
                        lg.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg);
                        Context.SaveChanges();

                        LedgerGeneral lg1 = new LedgerGeneral();
                        lg1.LedgerAccountId     = SelectedBankAccount.LedgerAccountId;
                        lg1.LedgerTransactionId = lt.LedgerTransactionId;
                        lg1.Credit           = 0;
                        lg1.Debit            = SaleOrder.AmountAfterDiscount;
                        lg1.ChequeNumber     = ChequeNumber;
                        lg1.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg1);
                        Context.SaveChanges();
                    }
                }
                else
                {
                    if (Mode == "IsCash")
                    {
                        LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                        ltd.Amount = SaleOrder.AmountPaid;
                        ltd.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd.LedgerAccountId     = 1;
                        Context.LedgerTransactionDetails.Add(ltd);
                        Context.SaveChanges();

                        LedgerTransactionDetail ltd1 = new LedgerTransactionDetail();
                        ltd1.Amount = SaleOrder.AmountAfterDiscount;
                        ltd1.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd1.LedgerAccountId     = 2;
                        Context.LedgerTransactionDetails.Add(ltd1);
                        Context.SaveChanges();

                        LedgerTransactionDetail ltd2 = new LedgerTransactionDetail();
                        ltd2.Amount = SaleOrder.Due;
                        ltd2.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd2.LedgerAccountId     = SelectedCustomer.LedgerAccountId;
                        Context.LedgerTransactionDetails.Add(ltd2);
                        Context.SaveChanges();

                        LedgerGeneral lg = new LedgerGeneral();
                        lg.LedgerAccountId     = 1;
                        lg.LedgerTransactionId = lt.LedgerTransactionId;
                        lg.Credit           = 0;
                        lg.Debit            = SaleOrder.AmountPaid;
                        lg.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg);
                        Context.SaveChanges();

                        LedgerGeneral lg1 = new LedgerGeneral();
                        lg1.LedgerAccountId     = 2;
                        lg1.LedgerTransactionId = lt.LedgerTransactionId;
                        lg1.Debit            = 0;
                        lg1.Credit           = SaleOrder.AmountAfterDiscount;
                        lg1.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg1);
                        Context.SaveChanges();

                        LedgerGeneral lg2 = new LedgerGeneral();
                        lg2.LedgerAccountId     = SelectedCustomer.LedgerAccountId;
                        lg2.LedgerTransactionId = lt.LedgerTransactionId;
                        lg2.Credit           = 0;
                        lg2.Debit            = SaleOrder.Due;
                        lg2.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg2);
                        Context.SaveChanges();
                    }
                    else if (Mode == "IsCredit")
                    {
                        LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                        ltd.Amount = SaleOrder.AmountAfterDiscount;
                        ltd.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd.LedgerAccountId     = 2;
                        Context.LedgerTransactionDetails.Add(ltd);
                        Context.SaveChanges();

                        if (SaleOrder.AmountPaid > 0)
                        {
                            LedgerTransactionDetail ltd1 = new LedgerTransactionDetail();
                            ltd1.Amount = SaleOrder.AmountPaid;
                            ltd1.LedgerTransactionId = lt.LedgerTransactionId;
                            ltd1.LedgerAccountId     = 1;
                            Context.LedgerTransactionDetails.Add(ltd1);
                            Context.SaveChanges();
                        }

                        LedgerTransactionDetail ltd2 = new LedgerTransactionDetail();
                        ltd2.Amount = SaleOrder.Due;
                        ltd2.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd2.LedgerAccountId     = SelectedCustomer.LedgerAccountId;
                        Context.LedgerTransactionDetails.Add(ltd2);
                        Context.SaveChanges();

                        LedgerGeneral lg = new LedgerGeneral();
                        lg.LedgerAccountId     = 2;
                        lg.LedgerTransactionId = lt.LedgerTransactionId;
                        lg.Debit            = 0;
                        lg.Credit           = SaleOrder.AmountAfterDiscount;
                        lg.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg);
                        Context.SaveChanges();

                        if (SaleOrder.AmountPaid > 0)
                        {
                            LedgerGeneral lg1 = new LedgerGeneral();
                            lg1.LedgerAccountId     = 1;
                            lg1.LedgerTransactionId = lt.LedgerTransactionId;
                            lg1.Credit           = 0;
                            lg1.Debit            = SaleOrder.AmountPaid;
                            lg1.JournalEntryDate = lt.Date;
                            Context.Ledgergenerals.Add(lg1);
                            Context.SaveChanges();
                        }

                        LedgerGeneral lg2 = new LedgerGeneral();
                        lg2.LedgerAccountId     = SelectedCustomer.LedgerAccountId;
                        lg2.LedgerTransactionId = lt.LedgerTransactionId;
                        lg2.Credit           = 0;
                        lg2.Debit            = SaleOrder.Due;
                        lg2.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg2);
                        Context.SaveChanges();
                    }
                    else if (Mode == "IsBank")
                    {
                        LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                        ltd.Amount = SaleOrder.AmountAfterDiscount;
                        ltd.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd.LedgerAccountId     = 2;
                        Context.LedgerTransactionDetails.Add(ltd);
                        Context.SaveChanges();


                        LedgerTransactionDetail ltd1 = new LedgerTransactionDetail();
                        ltd1.Amount = SaleOrder.AmountPaid;
                        ltd1.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd1.LedgerAccountId     = SelectedBankAccount.LedgerAccountId;
                        Context.LedgerTransactionDetails.Add(ltd1);
                        Context.SaveChanges();

                        LedgerTransactionDetail ltd2 = new LedgerTransactionDetail();
                        ltd2.Amount = SaleOrder.Due;
                        ltd2.LedgerTransactionId = lt.LedgerTransactionId;
                        ltd2.LedgerAccountId     = SelectedCustomer.LedgerAccountId;
                        Context.LedgerTransactionDetails.Add(ltd2);
                        Context.SaveChanges();



                        LedgerGeneral lg = new LedgerGeneral();
                        lg.LedgerAccountId     = 2;
                        lg.LedgerTransactionId = lt.LedgerTransactionId;
                        lg.Credit           = SaleOrder.AmountAfterDiscount;
                        lg.Debit            = 0;
                        lg.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg);
                        Context.SaveChanges();

                        LedgerGeneral lg1 = new LedgerGeneral();
                        lg1.LedgerAccountId     = SelectedBankAccount.LedgerAccountId;
                        lg1.LedgerTransactionId = lt.LedgerTransactionId;
                        lg1.Credit           = 0;
                        lg1.Debit            = SaleOrder.AmountPaid;
                        lg1.ChequeNumber     = ChequeNumber;
                        lg1.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg1);
                        Context.SaveChanges();

                        LedgerGeneral lg2 = new LedgerGeneral();
                        lg2.LedgerAccountId     = SelectedCustomer.LedgerAccountId;
                        lg2.LedgerTransactionId = lt.LedgerTransactionId;
                        lg2.Debit            = SaleOrder.Due;
                        lg2.Credit           = 0;
                        lg2.JournalEntryDate = lt.Date;
                        Context.Ledgergenerals.Add(lg2);
                        Context.SaveChanges();
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void ResolvePaymentMode(Invoice voice, LedgerTransaction lt, LedgerAccount account)
        {
            if (SelectedPurchaseVm.Due <= 0)
            {
                if (IsCash)
                {
                    LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                    ltd.Amount = voice.Total;
                    ltd.LedgerTransactionId = lt.LedgerTransactionId;
                    ltd.LedgerAccountId     = 1;

                    AccountService.SaveLedgerTransactionDetail(ltd);
                    LedgerTransactionDetail ltd1 = new LedgerTransactionDetail();
                    ltd1.Amount = voice.Total;
                    ltd1.LedgerTransactionId = lt.LedgerTransactionId;
                    ltd1.LedgerAccountId     = 3;
                    AccountService.SaveLedgerTransactionDetail(ltd1);

                    LedgerGeneral lg = new LedgerGeneral();
                    lg.LedgerAccountId     = 1;
                    lg.LedgerTransactionId = lt.LedgerTransactionId;
                    lg.Credit           = voice.Total;
                    lg.Debit            = 0;
                    lg.JournalEntryDate = lt.Date;
                    AccountService.SaveLedgerGeneral(lg);

                    LedgerGeneral lg1 = new LedgerGeneral();
                    lg1.LedgerAccountId     = 3;
                    lg1.LedgerTransactionId = lt.LedgerTransactionId;
                    lg1.Debit            = voice.Total;
                    lg1.Credit           = 0;
                    lg1.JournalEntryDate = lt.Date;
                    AccountService.SaveLedgerGeneral(lg1);
                }
                else if (IsCredit)
                {
                    LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                    ltd.Amount = voice.Total;
                    ltd.LedgerTransactionId = lt.LedgerTransactionId;
                    ltd.LedgerAccountId     = 3;
                    AccountService.SaveLedgerTransactionDetail(ltd);

                    LedgerTransactionDetail ltd1 = new LedgerTransactionDetail();
                    ltd1.Amount = voice.Total;
                    ltd1.LedgerTransactionId = lt.LedgerTransactionId;
                    ltd1.LedgerAccountId     = account.LedgerAccountId;
                    AccountService.SaveLedgerTransactionDetail(ltd1);

                    LedgerGeneral lg = new LedgerGeneral();
                    lg.LedgerAccountId     = 3;
                    lg.LedgerTransactionId = lt.LedgerTransactionId;
                    lg.Debit            = voice.Total;
                    lg.Credit           = 0;
                    lg.JournalEntryDate = lt.Date;
                    AccountService.SaveLedgerGeneral(lg);

                    LedgerGeneral lg1 = new LedgerGeneral();
                    lg1.LedgerAccountId     = account.LedgerAccountId;
                    lg1.LedgerTransactionId = lt.LedgerTransactionId;
                    lg1.Credit           = voice.Total;
                    lg1.Debit            = 0;
                    lg1.JournalEntryDate = lt.Date;
                    AccountService.SaveLedgerGeneral(lg1);
                }
                else if (IsBank)
                {
                    LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                    ltd.Amount = voice.Total;
                    ltd.LedgerTransactionId = lt.LedgerTransactionId;
                    ltd.LedgerAccountId     = 3;
                    AccountService.SaveLedgerTransactionDetail(ltd);

                    LedgerTransactionDetail ltd1 = new LedgerTransactionDetail();
                    ltd1.Amount = voice.Total;
                    ltd1.LedgerTransactionId = lt.LedgerTransactionId;
                    ltd1.LedgerAccountId     = SelectedBankAccount.LedgerAccountId;
                    AccountService.SaveLedgerTransactionDetail(ltd1);

                    LedgerGeneral lg = new LedgerGeneral();
                    lg.LedgerAccountId     = 3;
                    lg.LedgerTransactionId = lt.LedgerTransactionId;
                    lg.Debit            = voice.Total;
                    lg.Credit           = 0;
                    lg.JournalEntryDate = lt.Date;
                    AccountService.SaveLedgerGeneral(lg);

                    LedgerGeneral lg1 = new LedgerGeneral();
                    lg1.LedgerAccountId     = SelectedBankAccount.LedgerAccountId;
                    lg1.LedgerTransactionId = lt.LedgerTransactionId;
                    lg1.Credit           = voice.Total;
                    lg1.Debit            = 0;
                    lg1.JournalEntryDate = lt.Date;
                    AccountService.SaveLedgerGeneral(lg1);
                }
            }
            else
            {
                if (IsCash)
                {
                    LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                    ltd.Amount = voice.AmountPaid;
                    ltd.LedgerTransactionId = lt.LedgerTransactionId;
                    ltd.LedgerAccountId     = 1;
                    AccountService.SaveLedgerTransactionDetail(ltd);

                    LedgerTransactionDetail ltd1 = new LedgerTransactionDetail();
                    ltd1.Amount = voice.Total;
                    ltd1.LedgerTransactionId = lt.LedgerTransactionId;
                    ltd1.LedgerAccountId     = 3;
                    AccountService.SaveLedgerTransactionDetail(ltd1);

                    LedgerTransactionDetail ltd2 = new LedgerTransactionDetail();
                    ltd2.Amount = voice.Due;
                    ltd2.LedgerTransactionId = lt.LedgerTransactionId;
                    ltd2.LedgerAccountId     = account.LedgerAccountId;
                    AccountService.SaveLedgerTransactionDetail(ltd2);

                    LedgerGeneral lg = new LedgerGeneral();
                    lg.LedgerAccountId     = 1;
                    lg.LedgerTransactionId = lt.LedgerTransactionId;
                    lg.Credit           = voice.AmountPaid;
                    lg.Debit            = 0;
                    lg.JournalEntryDate = lt.Date;
                    AccountService.SaveLedgerGeneral(lg);

                    LedgerGeneral lg1 = new LedgerGeneral();
                    lg1.LedgerAccountId     = 3;
                    lg1.LedgerTransactionId = lt.LedgerTransactionId;
                    lg1.Debit            = voice.Total;
                    lg1.Credit           = 0;
                    lg1.JournalEntryDate = lt.Date;
                    AccountService.SaveLedgerGeneral(lg1);

                    LedgerGeneral lg2 = new LedgerGeneral();
                    lg2.LedgerAccountId     = account.LedgerAccountId;
                    lg2.LedgerTransactionId = lt.LedgerTransactionId;
                    lg2.Debit            = 0;
                    lg2.Credit           = voice.Due;
                    lg2.JournalEntryDate = lt.Date;
                    AccountService.SaveLedgerGeneral(lg2);
                }
                //else if (IsCredit)
                //{
                //    LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                //    ltd.Amount = voice.Total;
                //    ltd.LedgerTransactionId = lt.LedgerTransactionId;
                //    ltd.LedgerAccountId = 3;
                //    AccountService.SaveLedgerTransactionDetail(ltd);

                //    LedgerTransactionDetail ltd1 = new LedgerTransactionDetail();
                //    ltd1.Amount = voice.Total;
                //    ltd1.LedgerTransactionId = lt.LedgerTransactionId;
                //    ltd1.LedgerAccountId = account.LedgerAccountId;
                //    AccountService.SaveLedgerTransactionDetail(ltd1);

                //    LedgerGeneral lg = new LedgerGeneral();
                //    lg.LedgerAccountId = 3;
                //    lg.LedgerTransactionId = lt.LedgerTransactionId;
                //    lg.Debit = voice.Total;
                //    lg.Credit = 0;
                //    lg.JournalEntryDate = lt.Date;
                //    AccountService.SaveLedgerGeneral(lg);

                //    LedgerGeneral lg1 = new LedgerGeneral();
                //    lg1.LedgerAccountId = account.LedgerAccountId;
                //    lg1.LedgerTransactionId = lt.LedgerTransactionId;
                //    lg1.Credit = voice.Total;
                //    lg1.Debit = 0;
                //    lg1.JournalEntryDate = lt.Date;
                //    AccountService.SaveLedgerGeneral(lg1);
                //}
                else if (IsBank)
                {
                    LedgerTransactionDetail ltd = new LedgerTransactionDetail();
                    ltd.Amount = voice.Total;
                    ltd.LedgerTransactionId = lt.LedgerTransactionId;
                    ltd.LedgerAccountId     = 3;
                    AccountService.SaveLedgerTransactionDetail(ltd);

                    LedgerTransactionDetail ltd1 = new LedgerTransactionDetail();
                    ltd1.Amount = voice.AmountPaid;
                    ltd1.LedgerTransactionId = lt.LedgerTransactionId;
                    ltd1.LedgerAccountId     = SelectedBankAccount.LedgerAccountId;
                    AccountService.SaveLedgerTransactionDetail(ltd1);

                    LedgerTransactionDetail ltd2 = new LedgerTransactionDetail();
                    ltd2.Amount = voice.Due;
                    ltd2.LedgerTransactionId = lt.LedgerTransactionId;
                    ltd2.LedgerAccountId     = account.LedgerAccountId;
                    AccountService.SaveLedgerTransactionDetail(ltd2);



                    LedgerGeneral lg = new LedgerGeneral();
                    lg.LedgerAccountId     = 3;
                    lg.LedgerTransactionId = lt.LedgerTransactionId;
                    lg.Debit            = voice.Total;
                    lg.Credit           = 0;
                    lg.JournalEntryDate = lt.Date;
                    AccountService.SaveLedgerGeneral(lg);

                    LedgerGeneral lg1 = new LedgerGeneral();
                    lg1.LedgerAccountId     = SelectedBankAccount.LedgerAccountId;
                    lg1.LedgerTransactionId = lt.LedgerTransactionId;
                    lg1.Credit           = voice.AmountPaid;
                    lg1.Debit            = 0;
                    lg1.JournalEntryDate = lt.Date;
                    AccountService.SaveLedgerGeneral(lg1);

                    LedgerGeneral lg2 = new LedgerGeneral();
                    lg2.LedgerAccountId     = account.LedgerAccountId;
                    lg2.LedgerTransactionId = lt.LedgerTransactionId;
                    lg2.Credit           = voice.Due;
                    lg2.Debit            = 0;
                    lg2.JournalEntryDate = lt.Date;
                    AccountService.SaveLedgerGeneral(lg2);
                }
            }
        }
Exemplo n.º 9
0
 public int InsertLedgerGeneral(LedgerGeneral Ledgergeneral)
 {
     Context.Ledgergenerals.Add(Ledgergeneral);
     return(SaveAll());
 }
Exemplo n.º 10
0
 public int DeleteLedgerGeneral(LedgerGeneral Ledgergeneral)
 {
     Context.Ledgergenerals.Remove(Ledgergeneral);
     return(SaveAll());
 }
Exemplo n.º 11
0
 public async Task <int> DeleteLedgerGeneralAsync(LedgerGeneral Ledgergeneral)
 {
     Context.Ledgergenerals.Remove(Ledgergeneral);
     return(await SaveAllAsync());
 }
Exemplo n.º 12
0
        private void CreateNewAccount(ERPContext context)
        {
            LedgerAccount newAccount;
                
            if (_newEntryGroup.Equals("Bank"))
            {
                newAccount = new LedgerAccount
                {
                    Name = _newEntryName,
                    Class = "Asset",
                    Notes = "Current Asset",
                    LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>()
                };
            }

            else if (_newEntryGroup.Equals("Operating Expense"))
            {
                newAccount = new LedgerAccount
                {
                    Name = _newEntryName,
                    Class = "Expense",
                    Notes = "Operating Expense",
                    LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>()
                };
            }

            else if (_newEntryGroup.Equals("Accounts Receivable"))
            {
                newAccount = new LedgerAccount
                {
                    Name = _newEntryName,
                    Class = "Asset",
                    Notes = "Accounts Receivable",
                    LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>()
                };
            }

            else if (_newEntryGroup.Equals("Accounts Payable"))
            {
                newAccount = new LedgerAccount
                {
                    Name = _newEntryName,
                    Class = "Liability",
                    Notes = "Accounts Payable",
                    LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>()
                };
            }

            else
            {
                newAccount = new LedgerAccount
                {
                    Name = _newEntryName,
                    Class = "Expense",
                    Notes = "Operating Expense",
                    LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>()
                };
            }

            var newAccountGeneralLedger = new LedgerGeneral
            {
                LedgerAccount = newAccount,
                PeriodYear = context.Ledger_General.First().PeriodYear,
                Period = context.Ledger_General.First().Period
            };

            var newAccountBalances = new LedgerAccountBalance
            {
                LedgerAccount = newAccount,
                PeriodYear = context.Ledger_General.First().PeriodYear
            };

            newAccount.LedgerGeneral = newAccountGeneralLedger;
            newAccount.LedgerAccountBalances.Add(newAccountBalances);
            context.Ledger_Accounts.Add(newAccount);
        }
Exemplo n.º 13
0
        private void CreateNewAccount(ERPContext context)
        {
            LedgerAccount newAccount;

            if (_newEntryGroup.Equals("Bank"))
            {
                newAccount = new LedgerAccount
                {
                    Name  = _newEntryName,
                    Class = "Asset",
                    Notes = "Current Asset",
                    LedgerAccountBalances = new ObservableCollection <LedgerAccountBalance>()
                };
            }

            else if (_newEntryGroup.Equals("Operating Expense"))
            {
                newAccount = new LedgerAccount
                {
                    Name  = _newEntryName,
                    Class = "Expense",
                    Notes = "Operating Expense",
                    LedgerAccountBalances = new ObservableCollection <LedgerAccountBalance>()
                };
            }

            else if (_newEntryGroup.Equals("Accounts Receivable"))
            {
                newAccount = new LedgerAccount
                {
                    Name  = _newEntryName,
                    Class = "Asset",
                    Notes = "Accounts Receivable",
                    LedgerAccountBalances = new ObservableCollection <LedgerAccountBalance>()
                };
            }

            else if (_newEntryGroup.Equals("Accounts Payable"))
            {
                newAccount = new LedgerAccount
                {
                    Name  = _newEntryName,
                    Class = "Liability",
                    Notes = "Accounts Payable",
                    LedgerAccountBalances = new ObservableCollection <LedgerAccountBalance>()
                };
            }

            else
            {
                newAccount = new LedgerAccount
                {
                    Name  = _newEntryName,
                    Class = "Expense",
                    Notes = "Operating Expense",
                    LedgerAccountBalances = new ObservableCollection <LedgerAccountBalance>()
                };
            }

            var newAccountGeneralLedger = new LedgerGeneral
            {
                LedgerAccount = newAccount,
                PeriodYear    = context.Ledger_General.First().PeriodYear,
                Period        = context.Ledger_General.First().Period
            };

            var newAccountBalances = new LedgerAccountBalance
            {
                LedgerAccount = newAccount,
                PeriodYear    = context.Ledger_General.First().PeriodYear
            };

            newAccount.LedgerGeneral = newAccountGeneralLedger;
            newAccount.LedgerAccountBalances.Add(newAccountBalances);
            context.Ledger_Accounts.Add(newAccount);
        }