Пример #1
0
        public int Save(Models.MCashAccount model)
        {
            Common.Logger l         = new Common.Logger();
            string        ClassName = "CAccounttransaction";

            try
            {
                DB.CashAccount bs = new DB.CashAccount();

                bs.CashAccountName = model.CashAccountName;
                bs.WareHouseId     = model.WareHouseId;
                bs.OpeningBalance  = model.OpeningBalance;
                bs.BeginDate       = model.BeginDate;
                bs.ClientId        = model.ClientId;
                bs.VendorId        = model.VendorId;
                bs.AccountType     = model.AccountType;
                //  l.Print(ClassName, Common.LogPointer.Info.ToString(), "Model Values id[" + model.id + "] AccountId[" + model.AccountId + "] Total[" + model.Total + "] CurrentTransaction[" + model.CurrentTransaction + "] TransactionType [ " + model.Transactiontype + " ] FiscalYearId [ " + model.FiscalYearId + " ] eDate [" + model.eDate + " ]");
                obj.CashAccounts.InsertOnSubmit(bs);
                obj.SubmitChanges();
                l.Print(ClassName, Common.LogPointer.Info.ToString(), "Record Inserted Successfully");
                return(1);
            }
            catch (Exception ex)
            {
                l.Print(ClassName, Common.LogPointer.Error.ToString(), ex.ToString());
                return(-1);
            }
        }
Пример #2
0
        public int Update(Models.MCashAccount model)
        {
            Common.Logger l         = new Common.Logger();
            string        ClassName = "CAccounttransaction";

            try
            {
                var query = from o in obj.CashAccounts
                            where o.id == model.id
                            select
                            o;
                foreach (var item in query)
                {
                    item.CashAccountName = model.CashAccountName;
                    item.WareHouseId     = model.WareHouseId;
                    item.OpeningBalance  = model.OpeningBalance;
                    item.BeginDate       = model.BeginDate;
                    item.ClientId        = model.ClientId;
                    item.VendorId        = model.VendorId;
                }


                //  l.Print(ClassName, Common.LogPointer.Info.ToString(), "Model Values id[" + model.id + "] AccountId[" + model.AccountId + "] Total[" + model.Total + "] CurrentTransaction[" + model.CurrentTransaction + "] TransactionType [ " + model.Transactiontype + " ] FiscalYearId [ " + model.FiscalYearId + " ] eDate [" + model.eDate + " ]");

                obj.SubmitChanges();
                l.Print(ClassName, Common.LogPointer.Info.ToString(), "Record Inserted Successfully");
                return(1);
            }
            catch (Exception ex)
            {
                l.Print(ClassName, Common.LogPointer.Error.ToString(), ex.ToString());
                return(-1);
            }
        }
Пример #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid && Page.IsPostBack)
            {
                Classes.CCashAccount ca = new Classes.CCashAccount();
                Models.MCashAccount  ma = new Models.MCashAccount();
                ma.AccountType     = "Personal";
                ma.BeginDate       = txtBeginDate.Text;
                ma.CashAccountName = txtCashAccountName.Text;
                ma.ClientId        = -1;
                ma.VendorId        = -1;
                ma.OpeningBalance  = txtOpeningBalance.Text;
                ma.WareHouseId     = Convert.ToInt32(Session["WareHouse"].ToString());
                ma.AccountType     = ma.AccountType = Common.Constants.CashAccountTypes.Personal.ToString();
                if (ca.Save(ma) > 0)
                {
                    Classes.CCashTransaction cct = new Classes.CCashTransaction();
                    Models.MCashTransactions mct = new Models.MCashTransactions();
                    mct.CashAccountId   = ca.GetLastAccountId();
                    mct.Credit          = txtOpeningBalance.Text;
                    mct.Debit           = "0";
                    mct.Description     = "Opened Account";
                    mct.eDate           = txtBeginDate.Text;
                    mct.FiscalYearId    = Convert.ToInt32(Session["FiscalYear"].ToString());
                    mct.OrderId         = -1;
                    mct.Total           = txtOpeningBalance.Text;
                    mct.TransactionId   = -1;
                    mct.TransactionType = "Credit";
                    mct.WareHouseId     = Convert.ToInt32(Session["WareHouse"].ToString());

                    mct.UserId = Session["UserId"].ToString();
                    if (cct.Save(mct) > 0)
                    {
                        ShowSuccessMessage();
                    }
                    else
                    {
                        ShowFailMessage();
                    }
                }
                else
                {
                    ShowFailMessage();
                }
            }
        }
Пример #4
0
        public List <Models.MCashAccount> GetAllbyid(int id)
        {
            List <Models.MCashAccount> model = new List <Models.MCashAccount>();
            var query = from o in obj.CashAccounts where (o.id) == id select o;

            foreach (var item in query)
            {
                Models.MCashAccount m = new Models.MCashAccount();

                m.id = Convert.ToInt32(item.id);
                m.CashAccountName = item.CashAccountName;
                m.WareHouseId     = Convert.ToInt32(item.WareHouseId);
                m.OpeningBalance  = item.OpeningBalance;
                m.BeginDate       = item.BeginDate;

                model.Add(m);
            }

            return(model);
        }
Пример #5
0
        public List <Models.MCashAccount> GetAll()
        {
            List <Models.MCashAccount> model = new List <Models.MCashAccount>();
            var query = from o in obj.CashAccounts select o;

            foreach (var item in query)
            {
                Models.MCashAccount m = new Models.MCashAccount();

                m.id = Convert.ToInt32(item.id);
                m.CashAccountName = item.CashAccountName;
                m.WareHouseId     = Convert.ToInt32(item.WareHouseId);
                m.OpeningBalance  = item.OpeningBalance;
                m.BeginDate       = item.BeginDate;
                m.ClientId        = Convert.ToInt32(item.ClientId);
                m.VendorId        = Convert.ToInt32(item.VendorId);
                m.AccountType     = item.AccountType;

                model.Add(m);
            }

            return(model);
        }
Пример #6
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (Page.IsPostBack)
     {
         Classes.CCashAccount ca = new Classes.CCashAccount();
         Models.MCashAccount  ma = new Models.MCashAccount();
         ma.AccountType     = "Personal";
         ma.BeginDate       = txtBeginDate.Text;
         ma.CashAccountName = txtCashAccountName.Text;
         ma.ClientId        = -1;
         ma.VendorId        = -1;
         ma.OpeningBalance  = txtOpeningBalance.Text;
         ma.WareHouseId     = Convert.ToInt32(Session["WareHouse"].ToString());
         if (ca.Save(ma) > 0)
         {
             ShowSuccessMessage();
             BindData();
         }
         else
         {
             ShowFailMessage();
         }
     }
 }
Пример #7
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);
            }
        }
Пример #8
0
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     if (Session["WareHouse"] != null)
     {
         string WareHouseId = Session["WareHouse"].ToString();
         if (Convert.ToInt32(ddlClientType.SelectedValue) > 0)
         {
             string ClientTypeId   = ddlClientType.SelectedValue.ToString();
             string ClientName     = txtClientName.Text;
             string ClientPhone    = txtPhone.Text;
             string ClientEmail    = txtEmail.Text;
             string ClientAddress1 = txtAddress1.Text;
             string ClientAddress2 = txtAddress2.Text;
             string City           = txtCity.Text;
             string eDate          = DateTime.Now.ToString();
             bool   IsVendor       = false;
             if (cbIsVendor.Checked)
             {
                 IsVendor = true;
             }
             Models.MClients mc = new Models.MClients();
             mc.ClientTypeld = ClientTypeId;
             mc.Name         = ClientName;
             mc.phone        = ClientPhone;
             mc.Address1     = ClientAddress1;
             mc.Address2     = ClientAddress2;
             mc.EmailAddress = ClientEmail;
             mc.City         = City;
             mc.isVendor     = IsVendor;
             mc.edate        = eDate;
             mc.WareHouseId  = (WareHouseId);
             mc.GrantorName  = txtGrantorName.Text;
             mc.NIC          = txtNIC.Text;
             mc.GrantorNIC   = txtGrantorNIC.Text;
             Classes.CClients cc = new Classes.CClients();
             if (cc.Save(mc) > 0)
             {
                 Classes.CCashAccount ca = new Classes.CCashAccount();
                 Models.MCashAccount  ma = new Models.MCashAccount();
                 ma.CashAccountName = ClientName;
                 ma.BeginDate       = eDate;
                 ma.ClientId        = cc.GetLastClientId();
                 ma.OpeningBalance  = "0";
                 ma.AccountType     = Common.Constants.CashAccountTypes.Client.ToString();
                 ma.VendorId        = -1;
                 ma.WareHouseId     = Convert.ToInt32(Session["WareHouse"].ToString());
                 if (ca.Save(ma) > 0)
                 {
                     Classes.CCashTransaction cct = new Classes.CCashTransaction();
                     Models.MCashTransactions mct = new Models.MCashTransactions();
                     mct.CashAccountId   = ca.GetLastAccountId();
                     mct.Credit          = "0";
                     mct.Debit           = "0";
                     mct.Description     = "Opened Client Account[" + txtClientName.Text + "]";
                     mct.eDate           = DateTime.Now.ToShortDateString();
                     mct.FiscalYearId    = Convert.ToInt32(Session["FiscalYear"].ToString());
                     mct.OrderId         = -1;
                     mct.Total           = "0";
                     mct.TransactionId   = -1;
                     mct.TransactionType = "Credit";
                     mct.WareHouseId     = Convert.ToInt32(Session["WareHouse"].ToString());
                     mct.UserId          = Session["UserId"].ToString();
                     if (cct.Save(mct) > 0)
                     {
                         ShowSuccessMessage();
                         ClearTextBoxes(Page);
                     }
                     else
                     {
                         ShowFailMessage();
                     }
                 }
                 else
                 {
                     ShowErrorModal("Client Saved but Account was not opened");
                 }
             }
             else
             {
                 ShowFailMessage();
             }
         }
     }
     else
     {
         ShowErrorModal("Cannot Save, No Warehouse associated with current user");
     }
 }
Пример #9
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Session["WareHouse"] != null)
            {
                string WareHouseId = Session["WareHouse"].ToString();

                if (Page.IsValid)
                {
                    string         VendorName    = txtVendorName.Text;
                    string         VendorAddress = txtVendorAddress.Text;
                    string         VendorPhone   = txtVendorPhoneNo.Text;
                    Models.MVendor mv            = new Models.MVendor();
                    mv.name        = VendorName;
                    mv.Addreess    = VendorAddress;
                    mv.phone       = VendorPhone;
                    mv.WareHouseId = WareHouseId;
                    Classes.CVendor ccv = new Classes.CVendor();
                    if (ccv.Save(mv) > 0)
                    {
                        //ShowFailMessage();
                        Classes.CCashAccount ca = new Classes.CCashAccount();
                        Models.MCashAccount  ma = new Models.MCashAccount();
                        ma.CashAccountName = VendorName;
                        ma.BeginDate       = DateTime.Now.ToShortDateString();
                        ma.ClientId        = -1;
                        ma.OpeningBalance  = "0";
                        ma.AccountType     = ma.AccountType = Common.Constants.CashAccountTypes.Vendor.ToString();
                        ma.VendorId        = ccv.GetLastVendorId();;
                        ma.WareHouseId     = Convert.ToInt32(Session["WareHouse"].ToString());
                        if (ca.Save(ma) > 0)
                        {
                            Classes.CCashTransaction cct = new Classes.CCashTransaction();
                            Models.MCashTransactions mct = new Models.MCashTransactions();
                            mct.CashAccountId   = ca.GetLastAccountId();
                            mct.Credit          = "0";
                            mct.Debit           = "0";
                            mct.Description     = "Opened Client Account[" + txtVendorName.Text + "]";
                            mct.eDate           = DateTime.Now.ToShortDateString();
                            mct.FiscalYearId    = Convert.ToInt32(Session["FiscalYear"].ToString());
                            mct.OrderId         = -1;
                            mct.Total           = "0";
                            mct.TransactionId   = -1;
                            mct.TransactionType = "Credit";
                            mct.WareHouseId     = Convert.ToInt32(Session["WareHouse"].ToString());
                            mct.UserId          = Session["UserId"].ToString();
                            if (cct.Save(mct) > 0)
                            {
                                ShowSuccessMessage();
                                ClearTextBoxes(Page);
                            }
                            else
                            {
                                ShowFailMessage();
                            }
                        }
                        else
                        {
                            ShowErrorModal("Vendor Saved but Account was not opened");
                        }
                    }
                    else
                    {
                        ShowFailMessage();
                    }
                }
            }
            else
            {
                ShowErrorModal("Cannot Save, No Warehouse associated with current user");
            }
        }
        private int ProcessPayments(string PaymentId, string OrderId, string totalCost, string CurrentAmountPaid,
                                    string AccountId, float AmountRemaining, string RemainingAmount, string DatePaid, string Type, string Cheque)
        {
            if (Page.IsValid)
            {
                Classes.CBankOfAccount      cba = new Classes.CBankOfAccount();
                Classes.CAccountTransaction cat = new Classes.CAccountTransaction();
                Classes.CCashAccount        cha = new Classes.CCashAccount();
                Classes.CCashTransaction    cht = new Classes.CCashTransaction();
                Classes.CPayment            cp  = new Classes.CPayment();
                Classes.CPaymentLine        cpl = new Classes.CPaymentLine();
                Classes.CSaleTransations    cs  = new Classes.CSaleTransations();
                Models.MAccountTransaction  mat = new Models.MAccountTransaction();
                Models.MPayments            mp  = new Models.MPayments();
                Models.PaymentLine          mpl = new Models.PaymentLine();
                Models.MCashTransactions    mht = new Models.MCashTransactions();
                Models.MCashAccount         mha = new Models.MCashAccount();

                #region Payments
                mp.Paid = (Convert.ToSingle(totalCost) - AmountRemaining).ToString();
                if (cp.UpdateAmountPaid(Convert.ToInt32(PaymentId), mp.Paid) < 0)
                {
                    return(-1);
                }
                #endregion

                #region PaymentLine
                mpl.PaymentId        = Convert.ToInt32(PaymentId);
                mpl.BankId           = Convert.ToInt32(AccountId);
                mpl.Date             = DatePaid;
                mpl.PaidAmount       = CurrentAmountPaid;
                mpl.RemainingAmount  = RemainingAmount;
                mpl.CumulativeAmount = (Convert.ToSingle(cpl.LastPaidAmount(mpl.PaymentId))
                                        + Convert.ToSingle(CurrentAmountPaid)).ToString();
                int OptionValue = Convert.ToInt32(ddlOption.SelectedValue);
                mpl.Cheque = Cheque;
                switch (OptionValue)
                {
                case -1:
                {
                    return(-1);
                }

                case 1:
                {
                    #region Account Transactions
                    mpl.ModeOfPayment = Common.Constants.ModeOfPayment.Cheque.ToString();
                    float AccountTotal = cba.ReturnTotalOfAccountById(Convert.ToInt32(AccountId));
                    mat.AccountId = AccountId;
                    if (Type.Contains("Vendor"))
                    {
                        mat.Description = "Payment Of Order Id[" + OrderId + "] Paid, Amount ["
                                          + CurrentAmountPaid + "]";
                        mat.Debit              = CurrentAmountPaid;
                        mat.Credit             = "0";
                        mat.Total              = (AccountTotal - Convert.ToSingle(CurrentAmountPaid)).ToString();
                        mat.CurrentTransaction = cs.GetIdByOrderId(Convert.ToInt32(OrderId)).ToString();
                        mat.Transactiontype    = "Debit";

                        mat.FiscalYearId = Session["FiscalYear"].ToString();
                        mat.eDate        = Convert.ToDateTime(DatePaid);
                    }
                    else if (Type.Contains("Client"))
                    {
                        mat.Description = "Payment Of Order Id[" + OrderId + "] Recieved, Amount ["
                                          + CurrentAmountPaid + "]";
                        mat.Debit              = "0";
                        mat.Credit             = CurrentAmountPaid;
                        mat.CurrentTransaction = cs.GetIdByOrderId(Convert.ToInt32(OrderId)).ToString();
                        mat.Total              = (AccountTotal + Convert.ToSingle(CurrentAmountPaid)).ToString();
                        mat.Transactiontype    = "Credit";
                        mat.FiscalYearId       = Session["FiscalYear"].ToString();
                        mat.eDate              = Convert.ToDateTime(DatePaid);
                    }
                    else
                    {
                        return(-3);
                    }

                    if (cat.Save(mat) < 0)
                    {
                        return(-4);
                    }
                    if (cba.SetNewAccountTotal(Convert.ToInt32(AccountId), Convert.ToSingle(mat.Total)) < 0)
                    {
                        return(-5);
                    }
                    #endregion
                    break;
                }

                case 2:
                {
                    #region Cash Transaction
                    mpl.ModeOfPayment = Common.Constants.ModeOfPayment.Cash.ToString();
                    mpl.Cheque        = "-";
                    float AccountTotal = cha.ReturnTotalOfCashAccount(Convert.ToInt32(AccountId));
                    mht.CashAccountId = Convert.ToInt32(AccountId);
                    if (Type.Contains("Vendor"))
                    {
                        mht.Credit      = "0";
                        mht.Debit       = CurrentAmountPaid;
                        mht.Description = "Payment Of Order Id[" + OrderId + "] Paid, Amount ["
                                          + CurrentAmountPaid + "]";
                        mht.eDate           = (DatePaid);
                        mht.FiscalYearId    = Convert.ToInt32(Session["FiscalYear"].ToString());
                        mht.OrderId         = Convert.ToInt32(OrderId);
                        mht.Total           = totalCost;
                        mht.TransactionId   = -1;
                        mht.TransactionType = "Debit";
                        mht.UserId          = Session["User"].ToString();
                        mht.WareHouseId     = Convert.ToInt32(Session["WareHouse"].ToString());
                    }
                    else if (Type.Contains("Client"))
                    {
                        mht.Credit      = CurrentAmountPaid;
                        mht.Debit       = "0";
                        mht.Description = "Payment Of Order Id[" + OrderId + "] Recieved, Amount ["
                                          + CurrentAmountPaid + "]";
                        mht.eDate           = (DatePaid);
                        mht.FiscalYearId    = Convert.ToInt32(Session["FiscalYear"].ToString());
                        mht.OrderId         = Convert.ToInt32(OrderId);
                        mht.Total           = totalCost;
                        mht.TransactionId   = -1;
                        mht.TransactionType = "Debit";
                        mht.UserId          = Session["User"].ToString();
                        mht.WareHouseId     = Convert.ToInt32(Session["WareHouse"].ToString());
                    }
                    else
                    {
                        return(-3);
                    }

                    if (cht.Save(mht) < 0)
                    {
                        return(-4);
                    }
                    if (cha.SetNewAccountTotal(Convert.ToInt32(AccountId), Convert.ToSingle(mat.Total)) < 0)
                    {
                        return(-5);
                    }
                    #endregion
                    break;
                }

                default:
                    return(-1);
                }
                if (cpl.Save(mpl) < 0)
                {
                    return(-2);
                }
                #endregion



                #region Accounts
                if (Convert.ToSingle(mp.Paid) > 0)
                {
                    if (Type == "Vendor")
                    {
                        Classes.CJournal cj = new Classes.CJournal();
                        Models.MJournal  mj = new Models.MJournal();
                        mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.MerchandiseInventory).ToString();
                        mj.amount = mp.Paid;
                        mj.des    = "Payment Recieved of Order id [" + OrderId + "]";
                        mj.e_date = (DatePaid);
                        mj.type   = Common.Constants.Accounts.Type.Debit.ToString();
                        cj.Save(mj);

                        mj        = new Models.MJournal();
                        mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.AccountsPayable).ToString();
                        mj.amount = mp.Paid;
                        mj.des    = "Payment Recieved of Order id [" + OrderId + "]";
                        mj.e_date = (DatePaid);
                        mj.type   = Common.Constants.Accounts.Type.Credit.ToString();
                        cj.Save(mj);
                    }
                    else if (Type == "Client")
                    {
                        Classes.CJournal cj = new Classes.CJournal();
                        Models.MJournal  mj = new Models.MJournal();
                        mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.CostOfGoodsSold).ToString();
                        mj.amount = mp.Paid;
                        mj.des    = "Payment Recieved of Order id [" + OrderId + "]";
                        mj.e_date = (DatePaid);
                        mj.type   = Common.Constants.Accounts.Type.Debit.ToString();
                        cj.Save(mj);

                        mj        = new Models.MJournal();
                        mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.MerchandiseInventory).ToString();
                        mj.amount = mp.Paid;
                        mj.des    = "Payment Recieved of Order id [" + OrderId + "]";
                        mj.e_date = (DatePaid);
                        mj.type   = Common.Constants.Accounts.Type.Credit.ToString();
                        cj.Save(mj);

                        cj        = new Classes.CJournal();
                        mj        = new Models.MJournal();
                        mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.AccountsRecievalbes).ToString();
                        mj.amount = mp.Paid;
                        mj.des    = "Payment Recieved of Order id [" + OrderId + "]";
                        mj.e_date = (DatePaid);
                        mj.type   = Common.Constants.Accounts.Type.Debit.ToString();
                        cj.Save(mj);

                        mj        = new Models.MJournal();
                        mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.Sales).ToString();
                        mj.amount = mp.Paid;
                        mj.des    = "Payment Recieved of Order id [" + OrderId + "]";
                        mj.e_date = (DatePaid);
                        mj.type   = Common.Constants.Accounts.Type.Credit.ToString();
                        cj.Save(mj);
                    }
                }
                #endregion
            }
            lblSalesAmountRemaining.Text = AmountRemaining.ToString();
            lblSalesAmountPaid.Text      = (Convert.ToSingle(totalCost) - AmountRemaining).ToString();
            return(1);
        }