Пример #1
0
            public List <Models.MViewModels.MViewPaymentHistory> GetPaymentHistory(int OrderId)
            {
                List <Models.MViewModels.MViewPaymentHistory> PaymentHistory = new List <Models.MViewModels.MViewPaymentHistory>();
                List <Models.MPayments>   Payments     = new List <Models.MPayments>();
                List <Models.PaymentLine> PaymentsLine = new List <Models.PaymentLine>()
                , tempPaymentsLine = new List <Models.PaymentLine>();

                Classes.CPayment       cp  = new CPayment();
                Classes.CPaymentLine   cpl = new CPaymentLine();
                Classes.CBankOfAccount cb  = new CBankOfAccount();
                Classes.CCashAccount   cca = new CCashAccount();
                Payments     = cp.GetAll();
                Payments     = Payments.Where(o => o.OrderId == OrderId).ToList();
                PaymentsLine = cpl.GetAll();
                for (int i = 0; i < Payments.Count; i++)
                {
                    tempPaymentsLine.Clear();
                    tempPaymentsLine = PaymentsLine.Where(o => o.PaymentId == Payments[i].id).ToList();
                    float CummulativePayment = 0;
                    for (int j = 0; j < tempPaymentsLine.Count; j++)
                    {
                        Models.MViewModels.MViewPaymentHistory ph = new Models.MViewModels.MViewPaymentHistory();
                        string AccountName = string.Empty;
                        if (tempPaymentsLine[j].ModeOfPayment == Common.Constants.ModeOfPayment.Cheque.ToString())
                        {
                            AccountName = cb.GetAccountNumberAccountTileById(tempPaymentsLine[j].BankId);
                        }
                        if (tempPaymentsLine[j].ModeOfPayment == Common.Constants.ModeOfPayment.Cash.ToString())
                        {
                            AccountName = cca.GetAccountNameById(tempPaymentsLine[j].BankId);
                        }
                        ph.AccountName        = AccountName;
                        ph.ChequeNumber       = tempPaymentsLine[j].Cheque;
                        ph.Date               = tempPaymentsLine[j].Date;
                        ph.ModeOfPayment      = tempPaymentsLine[j].ModeOfPayment;
                        ph.PaidAmount         = tempPaymentsLine[j].PaidAmount;
                        CummulativePayment   += Convert.ToSingle(tempPaymentsLine[j].PaidAmount);
                        ph.CummulativePayment = CummulativePayment.ToString();
                        PaymentHistory.Add(ph);
                    }
                }
                return(PaymentHistory);
            }
Пример #2
0
        public int RevertSingleTransaction(int TransactionId, int Units, int ProductId)
        {
            try
            {
                var TransactionType = (from o in obj.Transaction1s
                                       where o.id == TransactionId
                                       select o.TransactionType).FirstOrDefault();
                var PaymentId = (from o in obj.Payments
                                 where o.TransactionId == TransactionId
                                 select o.id).FirstOrDefault();
                var DataPaymentLine = from o in obj.PaymentLines
                                      where o.PaymentId == Convert.ToInt32(PaymentId)
                                      select o;
                var AccountType = (from o in obj.Payments
                                   join paymentLine in obj.PaymentLines
                                   on o.id equals paymentLine.PaymentId
                                   select paymentLine.ModeOfPayment);
                string AccountId = string.Empty;


                Classes.CPayment         cp        = new CPayment();
                Models.MPayments         mp        = new Models.MPayments();
                Classes.CInventory       ci        = new CInventory();
                List <Models.MInventory> Inventory = new List <Models.MInventory>();
                Classes.CProducts        cpr       = new CProducts();

                Inventory = ci.GetAll();
                string CostPrice = (from o in obj.Transaction1s
                                    where o.ProductID == ProductId &&
                                    o.id == TransactionId
                                    select o.CostPrice).FirstOrDefault();
                string SalePrice = (from o in obj.Transaction1s
                                    where o.ProductID == ProductId &&
                                    o.id == TransactionId
                                    select o.SalePrice).FirstOrDefault();
                switch (TransactionType)
                {
                case "Addition":
                {
                    //Reverting Inventory
                    float oldUnits = (from o in Inventory
                                      where o.ProductId == (ProductId).ToString()
                                      select Convert.ToSingle(o.Quantity)).FirstOrDefault();
                    float newUnits = oldUnits - Convert.ToSingle(Units);

                    var query = from o in obj.Inventories
                                where o.ProductId == Convert.ToInt32(ProductId)
                                select o;
                    foreach (var item in query)
                    {
                        item.Quantity = newUnits.ToString();
                    }
                    obj.SubmitChanges();


                    obj.SubmitChanges();
                    //checking for cash of bank account
                    if (Convert.ToString(AccountType) == Common.Constants.ModeOfPayment.Cash.ToString())
                    {
                        string Amount = (Convert.ToSingle(CostPrice) * Convert.ToSingle(Units)).ToString();
                        Classes.CBankOfAccount      cba = new CBankOfAccount();
                        Classes.CAccountTransaction cat = new CAccountTransaction();
                        //Reverting Account
                        float OldTotal = cba.ReturnTotalOfAccountById(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal + Convert.ToSingle(Amount);
                        cba.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);

                        //Add Revert Account Transaction
                        Models.MAccountTransaction mat = new Models.MAccountTransaction();
                        mat.AccountId    = AccountId.ToString();
                        mat.Credit       = "0";
                        mat.Debit        = Amount.ToString();
                        mat.Description  = "Reverted Sale Transaction Product Id[" + ProductId + "] Units [" + Units + "]";
                        mat.eDate        = DateTime.Now;
                        mat.FiscalYearId = (from o in obj.AccountTransactions
                                            where o.CurrentTransaction == TransactionId.ToString()
                                            select o.FiscalYearId.ToString()).FirstOrDefault();
                        mat.Total           = cba.ReturnTotalOfAccountById(Convert.ToInt32(AccountId)).ToString();
                        mat.Transactiontype = "Credit";

                        cat.Save(mat);
                    }
                    else if (Convert.ToString(AccountType) == Common.Constants.ModeOfPayment.Cheque.ToString())
                    {
                        Classes.CCashAccount     cca = new CCashAccount();
                        Classes.CCashTransaction cct = new CCashTransaction();
                        Models.MCashTransactions mct = new Models.MCashTransactions();
                        Models.MCashAccount      mca = new Models.MCashAccount();
                        string Amount = (Convert.ToSingle(CostPrice) * Convert.ToSingle(Units)).ToString();
                        //Reverting Account
                        float OldTotal = cca.ReturnTotalOfCashAccount(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal + Convert.ToSingle(Amount);
                        //setting new total
                        cca.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);

                        mct.CashAccountId = Convert.ToInt32(AccountId);
                        mct.Credit        = Amount;
                        mct.Debit         = "0";
                        mct.Description   = "Reverted Sale Transaction Product Id[" + ProductId + "] Units [" + Units + "]";
                        mct.eDate         = DateTime.Now.ToShortDateString();
                        mct.FiscalYearId  = Convert.ToInt32((from o in obj.CashTransactions
                                                             where o.TransactionId == TransactionId
                                                             select o.FiscalYearId).FirstOrDefault());
                        mct.OrderId         = -1;
                        mct.TransactionId   = -1;
                        mct.TransactionType = Common.Constants.TransactionStatus.Reverse.ToString();
                        mct.UserId          = Convert.ToString((from o in obj.CashTransactions
                                                                where o.TransactionId == TransactionId
                                                                select o.UserId).FirstOrDefault());
                        mct.WareHouseId = Convert.ToInt32((from o in obj.CashTransactions
                                                           where o.TransactionId == TransactionId
                                                           select o.WareHouseId).FirstOrDefault());
                        cct.Save(mct);
                    }

                    break;
                }

                case "Deduction":
                {
                    //Reverting Inventory
                    float oldUnits = (from o in Inventory
                                      where o.ProductId == (ProductId).ToString()
                                      select Convert.ToSingle(o.Quantity)).FirstOrDefault();
                    float newUnits = oldUnits + Convert.ToSingle(Units);

                    var query = from o in obj.Inventories
                                where o.ProductId == Convert.ToInt32(ProductId)
                                select o;
                    foreach (var item in query)
                    {
                        item.Quantity = newUnits.ToString();
                    }
                    obj.SubmitChanges();


                    //checking for cash of bank account
                    if (Convert.ToString(AccountType) == Common.Constants.ModeOfPayment.Cash.ToString())
                    {
                        string Amount = (Convert.ToSingle(CostPrice) * Convert.ToSingle(Units)).ToString();
                        Classes.CBankOfAccount      cba = new CBankOfAccount();
                        Classes.CAccountTransaction cat = new CAccountTransaction();
                        //Reverting Account
                        float OldTotal = cba.ReturnTotalOfAccountById(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal - Convert.ToSingle(Amount);
                        cba.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);

                        //Add Revert Account Transaction
                        Models.MAccountTransaction mat = new Models.MAccountTransaction();
                        mat.AccountId    = AccountId.ToString();
                        mat.Credit       = "0";
                        mat.Debit        = Amount.ToString();
                        mat.Description  = "Reverted Sale Transaction Product Id[" + ProductId + "] Units [" + Units + "]";
                        mat.eDate        = DateTime.Now;
                        mat.FiscalYearId = (from o in obj.AccountTransactions
                                            where o.CurrentTransaction == TransactionId.ToString()
                                            select o.FiscalYearId.ToString()).FirstOrDefault();
                        mat.Total           = cba.ReturnTotalOfAccountById(Convert.ToInt32(AccountId)).ToString();
                        mat.Transactiontype = "Credit";

                        cat.Save(mat);
                    }
                    else if (Convert.ToString(AccountType) == Common.Constants.ModeOfPayment.Cheque.ToString())
                    {
                        Classes.CCashAccount     cca = new CCashAccount();
                        Classes.CCashTransaction cct = new CCashTransaction();
                        Models.MCashTransactions mct = new Models.MCashTransactions();
                        Models.MCashAccount      mca = new Models.MCashAccount();
                        string Amount = (Convert.ToSingle(CostPrice) * Convert.ToSingle(Units)).ToString();
                        //Reverting Account
                        float OldTotal = cca.ReturnTotalOfCashAccount(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal - Convert.ToSingle(Amount);
                        //setting new total
                        cca.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);


                        //cash account transation
                        mct.CashAccountId = Convert.ToInt32(AccountId);
                        mct.Credit        = "0";
                        mct.Debit         = Amount;
                        mct.Description   = "Reverted Sale Transaction Product Id[" + ProductId + "] Units [" + Units + "]";
                        mct.eDate         = DateTime.Now.ToShortDateString();
                        mct.FiscalYearId  = Convert.ToInt32((from o in obj.CashTransactions
                                                             where o.TransactionId == TransactionId
                                                             select o.FiscalYearId).FirstOrDefault());
                        mct.OrderId         = -1;
                        mct.TransactionId   = -1;
                        mct.TransactionType = Common.Constants.TransactionStatus.Reverse.ToString();
                        mct.UserId          = Convert.ToString((from o in obj.CashTransactions
                                                                where o.TransactionId == TransactionId
                                                                select o.UserId).FirstOrDefault());
                        mct.WareHouseId = Convert.ToInt32((from o in obj.CashTransactions
                                                           where o.TransactionId == TransactionId
                                                           select o.WareHouseId).FirstOrDefault());
                        cct.Save(mct);
                    }
                    break;
                }

                default:
                    break;
                }

                //deletin Transaction
                var transactions = from o in obj.Transaction1s
                                   where o.id == TransactionId
                                   select o;
                foreach (var item in transactions)
                {
                    obj.Transaction1s.DeleteOnSubmit(item);
                }
                //deleting Payment lines
                foreach (var item in DataPaymentLine)
                {
                    obj.PaymentLines.DeleteOnSubmit(item);
                }
                obj.SubmitChanges();
                //deleting payments
                mp.id = Convert.ToInt32(PaymentId);
                cp.Delete(mp);
                return(1);
            }
            catch
            {
                return(-1);
            }
        }
Пример #3
0
            public List <Models.MViewModels.MViewCashAccountBalanceSheet> GetAll(string AccountType)
            {
                List <Models.MViewModels.MViewCashAccountBalanceSheet> Get = new List <Models.MViewModels.MViewCashAccountBalanceSheet>();

                Models.MViewModels.MViewCashAccountBalanceSheet mvt = new Models.MViewModels.MViewCashAccountBalanceSheet();
                List <Models.MCashTransactions> CashTransactions    = new List <Models.MCashTransactions>();
                List <Models.MCashAccount>      CashAccounts        = new List <Models.MCashAccount>();

                Classes.CCashTransaction cct = new CCashTransaction();
                Classes.CCashAccount     cca = new CCashAccount();
                Classes.CUsers           cu  = new CUsers();
                CashAccounts     = cca.GetAll();
                CashTransactions = cct.GetAll();
                Get.Clear();
                switch (AccountType)
                {
                case "Personal":
                {
                    var joined = from ct in CashTransactions
                                 join ca in CashAccounts
                                 on ct.CashAccountId equals ca.id
                                 where ca.AccountType == Common.Constants.CashAccountTypes.Personal.ToString()
                                 select ct;

                    foreach (var item in joined)
                    {
                        mvt = new Models.MViewModels.MViewCashAccountBalanceSheet();
                        string AccountName = cca.GetAccountNameById(item.CashAccountId);
                        string UserName    = cu.GetUserNameById(Convert.ToInt32(item.UserId));
                        mvt.AccountId     = AccountName;
                        mvt.Balance       = item.Total;
                        mvt.Credit        = item.Credit;
                        mvt.Debit         = item.Debit;
                        mvt.Description   = item.Description;
                        mvt.TransactionBy = UserName;
                        mvt.Date          = item.eDate;
                        Get.Add(mvt);
                    }
                    break;
                }

                case "Vendor":
                {
                    var joined = from ct in CashTransactions
                                 join ca in CashAccounts
                                 on ct.CashAccountId equals ca.id
                                 where ca.AccountType == Common.Constants.CashAccountTypes.Vendor.ToString()
                                 select ct;

                    foreach (var item in joined)
                    {
                        mvt = new Models.MViewModels.MViewCashAccountBalanceSheet();
                        string AccountName = cca.GetAccountNameById(item.CashAccountId);
                        string UserName    = cu.GetUserNameById(Convert.ToInt32(item.UserId));
                        mvt.AccountId     = AccountName;
                        mvt.Balance       = item.Total;
                        mvt.Credit        = item.Credit;
                        mvt.Debit         = item.Debit;
                        mvt.Description   = item.Description;
                        mvt.TransactionBy = UserName;
                        mvt.Date          = item.eDate;
                        Get.Add(mvt);
                    }
                    break;
                }

                case "Client":
                {
                    var joined = from ct in CashTransactions

                                 join ca in CashAccounts
                                 on ct.CashAccountId equals ca.id
                                 where ca.AccountType == Common.Constants.CashAccountTypes.Client.ToString()
                                 select ct;

                    foreach (var item in joined)
                    {
                        mvt = new Models.MViewModels.MViewCashAccountBalanceSheet();
                        string AccountName = cca.GetAccountNameById(item.CashAccountId);
                        string UserName    = cu.GetUserNameById(Convert.ToInt32(item.UserId));
                        mvt.AccountId     = AccountName;
                        mvt.Balance       = item.Total;
                        mvt.Credit        = item.Credit;
                        mvt.Debit         = item.Debit;
                        mvt.Description   = item.Description;
                        mvt.TransactionBy = UserName;
                        mvt.Date          = item.eDate;
                        Get.Add(mvt);
                    }
                    break;
                }

                default:
                    break;
                }


                return(Get);
            }