예제 #1
0
        public void TestInstallmentPost_Valid()
        {
            #region ASSIGN

            TestRepository       tRepo       = new TestRepository();
            AccountsController   tController = null;
            Account              tAccount    = tRepo.GetAccountInformation(1, 3);
            AccountTransactionVM tVM         = new AccountTransactionVM()
            {
                Account = tAccount, Amount = 5000.0
            };

            tController = new AccountsController(tRepo)
            {
                ControllerContext = UtilityFunctions.GenerateMockControllerContext("UserB"),
            };

            #endregion

            #region ACT

            var tResult = tController.Installment(3, tVM);

            #endregion

            #region ASSERT

            Assert.IsTrue(tResult is RedirectToActionResult);
            Assert.AreEqual((tResult as RedirectToActionResult).ActionName, "Index");
            Assert.AreEqual((tResult as RedirectToActionResult).ControllerName, "Customers");

            #endregion
        }
예제 #2
0
        public static bool Insert_AccountCOdeSetup(AccountTransactionVM model)
        {
            string temp;

            try
            {
                SqlParameter[] param =
                {
                    new SqlParameter("@DealerCode", model.DealerCode),               //0
                    new SqlParameter("@SaleSecurity", model.SaleSecurity),           //1
                    new SqlParameter("@SaleBankGuarantee", model.SaleBankGuarantee), //2
                };
                dt = DataAccess.getDataTable("Sp_Insert_SaleAccountSetup", param, General.GetBMSConString());
                if (dt.Rows.Count > 0)
                {
                }

                IsSaved = true;
            }
            catch (Exception)
            {
                throw;
            }

            return(IsSaved);
        }
예제 #3
0
        public void TestInstallmentPost_OverdraftError()
        {
            #region ASSIGN

            TestRepository       tRepo       = new TestRepository();
            AccountsController   tController = null;
            Account              tAccount    = tRepo.GetAccountInformation(1, 3);
            AccountTransactionVM tVM         = new AccountTransactionVM()
            {
                Account = tAccount, Amount = 100000.0
            };

            tController = new AccountsController(tRepo)
            {
                ControllerContext = UtilityFunctions.GenerateMockControllerContext("UserB"),
            };

            #endregion

            #region ACT

            var tResult = tController.Installment(3, tVM);

            #endregion

            #region ASSERT

            Assert.IsTrue(tResult is ViewResult);
            Assert.AreEqual(((tResult as ViewResult).Model as AccountTransactionVM).Account.ID, 3);
            Assert.AreEqual(((tResult as ViewResult).Model as AccountTransactionVM).Account.AccountBalance, 50000.0);
            Assert.AreEqual(((tResult as ViewResult).Model as AccountTransactionVM).Amount, 0.0);
            Assert.IsNotNull((tResult as ViewResult).ViewData["ErrorMessage"]);

            #endregion
        }
예제 #4
0
        public void TestDepositPost_UnauthorizeAccountUser()
        {
            #region ASSIGN

            TestRepository       tRepo       = new TestRepository();
            AccountsController   tController = null;
            Account              tAccount    = tRepo.GetAccountInformation(0, 0);
            AccountTransactionVM tVM         = new AccountTransactionVM()
            {
                Account = tAccount, Amount = 0.0
            };

            tController = new AccountsController(tRepo)
            {
                ControllerContext = UtilityFunctions.GenerateMockControllerContext("User"),
            };

            #endregion

            #region ACT

            var tResult = tController.Deposit(0, tVM);

            #endregion

            #region ASSERT

            Assert.IsTrue(tResult is RedirectToActionResult);
            Assert.AreEqual((tResult as RedirectToActionResult).ActionName, "Index");

            #endregion
        }
예제 #5
0
        public IActionResult Withdraw(int id, [Bind("Account,Amount")] AccountTransactionVM accountPost)
        {
            if (id != accountPost.Account.ID)
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string   guid            = GetUserGuID();
                    Customer currentCustomer = _repo.GetCustomer(guid);
                    _repo.Withdraw(currentCustomer.ID, id, accountPost.Amount);
                }
                catch (UnauthorizedAccessException WTF)
                {
                    Console.WriteLine(WTF);
                    return(RedirectToAction(nameof(Index)));
                }
                catch (InvalidAccountException WTF)
                {
                    Console.WriteLine(WTF);
                    return(RedirectToAction(nameof(Index)));
                }
                catch (OverdraftProtectionException WTF)
                {
                    Console.WriteLine(WTF);
                    ViewData["ErrorMessage"] = "Overdraft Protection! Withdrawal amount exceeded current balance!";
                    accountPost.Amount       = 0;
                    return(View(accountPost));
                }
                catch (DbUpdateConcurrencyException WTF)
                {
                    Console.WriteLine(WTF);
                    return(RedirectToAction(nameof(Index)));
                    //if (!AccountExists(account.ID))
                    //{
                    //    return NotFound();
                    //}
                    //else
                    //{
                    //    throw;
                    //}
                }
                catch (Exception WTF)
                {
                    Console.WriteLine(WTF);
                    return(RedirectToAction(nameof(Index)));
                }

                return(RedirectToAction(nameof(Index), "Customers"));
            }
            return(View(accountPost));
        }
예제 #6
0
        public JsonResult Insert_ReversalAccountTrans(AccountTransactionVM objects)
        {
            bool   result = false;
            string msg    = "Failed to save record..";

            result = ReversalMethods.Insert_AccountTransaction(objects, ref msg);

            if (result)
            {
                msg = "Successfully Added";
            }

            return(Json(new { Success = result, Message = msg }, JsonRequestBehavior.AllowGet));
        }
예제 #7
0
        public JsonResult Insert_AccountMapping(AccountTransactionVM objects)
        {
            bool result = false;

            string msg = "Failed to save record..";

            result = MasterMethods.Insert_AccountCOdeSetup(objects);

            if (result)
            {
                msg = "Successfully Added";
            }

            return(Json(new { Success = result, Message = msg }, JsonRequestBehavior.AllowGet));
        }
예제 #8
0
        public IActionResult Deposit(int id, [Bind("Account,Amount")] AccountTransactionVM accountPost)
        {
            if (id != accountPost.Account.ID)
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string   guid            = GetUserGuID();
                    Customer currentCustomer = _repo.GetCustomer(guid);
                    _repo.Deposit(currentCustomer.ID, id, accountPost.Amount);
                }
                catch (UnauthorizedAccessException WTF)
                {
                    Console.WriteLine(WTF);
                    return(RedirectToAction(nameof(Index)));
                }
                catch (InvalidAccountException WTF)
                {
                    Console.WriteLine(WTF);
                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateConcurrencyException WTF)
                {
                    Console.WriteLine(WTF);
                    //if (!AccountExists(account.ID))
                    //{
                    //    return NotFound();
                    //}
                    //else
                    //{
                    //    throw;
                    //}
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception WTF)
                {
                    Console.WriteLine(WTF);
                    return(RedirectToAction(nameof(Index)));
                }
                return(RedirectToAction(nameof(Index), "Customers"));
            }

            return(View(accountPost));
        }
        // GET: AccountTransaction/Details/5
        public async Task <IActionResult> Details(long?id)
        {
            AccountTransactionVM accountTransactionVM = new AccountTransactionVM();
            HttpClient           client = _helperAPI.InitializeClient();

            //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TempData.Peek("Token").ToString());
            HttpResponseMessage res = await client.GetAsync("api/AccountTransaction/" + id);

            if (res.StatusCode == HttpStatusCode.Unauthorized)
            {
                ViewBag.Message = "Unauthorized!";
            }

            //Checking the response is successful or not which is sent using HttpClient
            if (res.IsSuccessStatusCode)
            {
                //Storing the response details recieved from web api
                var result = res.Content.ReadAsStringAsync().Result;


                //Deserializing the response recieved from web api and storing into the Role list
                accountTransactionVM = JsonConvert.DeserializeObject <AccountTransactionVM>(result);
            }
            if (accountTransactionVM == null)
            {
                return(NotFound());
            }

            return(View(accountTransactionVM));
            //if (id == null)
            //{
            //    return NotFound();
            //}

            //var accountTransactionVM = await _context.AccountTransactionVM
            //    .Include(a => a.AccountCredit)
            //    .Include(a => a.AccountDebit)
            //    .Include(a => a.SaleContract)
            //    .FirstOrDefaultAsync(m => m.AccountTransactionId == id);
            //if (accountTransactionVM == null)
            //{
            //    return NotFound();
            //}

            //return View(accountTransactionVM);
        }
예제 #10
0
        //GET: Accounts/Edit/5
        public IActionResult Installment(int?id)
        {
            // Check if valid id was presented.
            if (id == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            AccountTransactionVM account = null;

            try
            {
                string   guid            = GetUserGuID();
                Customer currentCustomer = _repo.GetCustomer(guid);
                Account  currentAccount  = _repo.GetAccountInformation(currentCustomer.ID, id.Value);

                if (currentAccount != null)
                {
                    // Check if valid loan account.
                    if (_repo.IsAccountLoanPayable(currentAccount))
                    {
                        account = new AccountTransactionVM()
                        {
                            Account = currentAccount,
                            Amount  = 0.0,
                        };
                    }
                    else
                    {
                        return(RedirectToAction(nameof(Index)));
                    }
                }
            }
            catch (Exception WTF)
            {
                Console.WriteLine(WTF);
                return(RedirectToAction(nameof(Index)));
            }

            if (account == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["AccountType"] = _repo.GetAccountTypeName(account.Account.AccountTypeID);
            return(View(account));
        }
        // GET: AccountTransaction/Delete/5
        public async Task <IActionResult> Delete(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AccountTransactionVM accountTransactionVM = new AccountTransactionVM();
            HttpClient           client = _helperAPI.InitializeClient();

            //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TempData.Peek("Token").ToString());
            HttpResponseMessage res = await client.GetAsync("api/AccountTransaction/" + id);

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                accountTransactionVM = JsonConvert.DeserializeObject <AccountTransactionVM>(result);
            }
            if (accountTransactionVM == null)
            {
                return(NotFound());
            }
            //if (id == null)
            //{
            //    return NotFound();
            //}

            //var accountTransactionVM = await _context.AccountTransactionVM
            //    .Include(a => a.AccountCredit)
            //    .Include(a => a.AccountDebit)
            //    .Include(a => a.SaleContract)
            //    .FirstOrDefaultAsync(m => m.AccountTransactionId == id);
            //if (accountTransactionVM == null)
            //{
            //    return NotFound();
            //}

            return(View(accountTransactionVM));
        }
        public async Task <IActionResult> Edit(long id, [Bind("AccountTransactionId,Type,AccountDebitId,AccountCreditId,VoucherNo,VoucherDate,Narration,AmountDebit,AmountCredit,SaleContractId,SaleContractNumber,DateAdded,IsActive")] AccountTransactionVM accountTransactionVM)//,DateUpdated,AccountDebitCode,AccountCreditCode,
        {
            if (id != accountTransactionVM.AccountTransactionId)
            {
                return(NotFound());
            }
            HttpClient client = _helperAPI.InitializeClient();

            if (ModelState.IsValid)
            {
                try
                {
                    accountTransactionVM.DateUpdated = DateTime.Now;

                    //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TempData.Peek("Token").ToString());
                    var content             = new StringContent(JsonConvert.SerializeObject(accountTransactionVM), Encoding.UTF8, "application/json");
                    HttpResponseMessage res = client.PutAsync("api/AccountTransaction/" + id, content).Result;
                    if (res.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index"));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    //if (!RoleVMExists(roleVM.Id))
                    //{
                    //    return NotFound();
                    //}
                    //else
                    //{
                    throw;
                    //}
                }
                return(RedirectToAction(nameof(Index)));
            }

            List <TblAccountVM> tblAccountVM = new List <TblAccountVM>();
            var contentType = new MediaTypeWithQualityHeaderValue("application/json");

            client.DefaultRequestHeaders.Accept.Add(contentType);
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TempData.Peek("Token").ToString());
            //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token"));

            HttpResponseMessage tblAccountVMRes = await client.GetAsync("api/Account");

            if (tblAccountVMRes.StatusCode == HttpStatusCode.Unauthorized)
            {
                ViewBag.Message = "Unauthorized!";
            }

            //Checking the response is successful or not which is sent using HttpClient
            if (tblAccountVMRes.IsSuccessStatusCode)
            {
                //Storing the response details recieved from web api
                var result = tblAccountVMRes.Content.ReadAsStringAsync().Result;


                //Deserializing the response recieved from web api and storing into the role list
                tblAccountVM = JsonConvert.DeserializeObject <List <TblAccountVM> >(result);
            }
            ViewData["AccountCreditId"] = new SelectList(tblAccountVM, "AccountId", "AccountTitle", accountTransactionVM.AccountCreditId);
            ViewData["AccountDebitId"]  = new SelectList(tblAccountVM, "AccountId", "AccountTitle", accountTransactionVM.AccountCreditId);



            List <SaleContractVM> saleContractVM = new List <SaleContractVM>();
            HttpResponseMessage   resp           = await client.GetAsync("api/SaleContracts");

            if (resp.StatusCode == HttpStatusCode.Unauthorized)
            {
                ViewBag.Message = "Unauthorized!";
            }

            //Checking the response is successful or not which is sent using HttpClient
            if (resp.IsSuccessStatusCode)
            {
                //Storing the response details recieved from web api
                var result = resp.Content.ReadAsStringAsync().Result;


                //Deserializing the response recieved from web api and storing into the role list
                saleContractVM = JsonConvert.DeserializeObject <List <SaleContractVM> >(result);
            }
            ViewData["SaleContractId"] = new SelectList(saleContractVM, "SaleContractId", "SaleContractNumber", accountTransactionVM.SaleContractId);


            List <TransactionTypeVM> transactionTypeVM = new List <TransactionTypeVM>();
            HttpResponseMessage      respo             = await client.GetAsync("api/TransactionType");

            if (respo.StatusCode == HttpStatusCode.Unauthorized)
            {
                ViewBag.Message = "Unauthorized!";
            }

            //Checking the response is successful or not which is sent using HttpClient
            if (respo.IsSuccessStatusCode)
            {
                //Storing the response details recieved from web api
                var result = respo.Content.ReadAsStringAsync().Result;


                //Deserializing the response recieved from web api and storing into the role list
                transactionTypeVM = JsonConvert.DeserializeObject <List <TransactionTypeVM> >(result);
            }
            ViewData["Type"] = new SelectList(transactionTypeVM, "TransactionTypeId", "Description", accountTransactionVM.Type);
            //if (id != accountTransactionVM.AccountTransactionId)
            //{
            //    return NotFound();
            //}

            //if (ModelState.IsValid)
            //{
            //    try
            //    {
            //        _context.Update(accountTransactionVM);
            //        await _context.SaveChangesAsync();
            //    }
            //    catch (DbUpdateConcurrencyException)
            //    {
            //        if (!AccountTransactionVMExists(accountTransactionVM.AccountTransactionId))
            //        {
            //            return NotFound();
            //        }
            //        else
            //        {
            //            throw;
            //        }
            //    }
            //    return RedirectToAction(nameof(Index));
            //}
            //ViewData["AccountCreditId"] = new SelectList(_context.TblAccountVM, "AccountId", "AccountId", accountTransactionVM.AccountCreditId);
            //ViewData["AccountDebitId"] = new SelectList(_context.TblAccountVM, "AccountId", "AccountId", accountTransactionVM.AccountDebitId);
            //ViewData["SaleContractId"] = new SelectList(_context.SaleContractVM, "SaleContractId", "SaleContractId", accountTransactionVM.SaleContractId);
            return(View(accountTransactionVM));
        }
        // GET: AccountTransaction/Edit/5
        public async Task <IActionResult> Edit(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AccountTransactionVM accountTransactionVM = new AccountTransactionVM();
            HttpClient           client = _helperAPI.InitializeClient();

            //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TempData.Peek("Token").ToString());
            HttpResponseMessage res = await client.GetAsync("api/AccountTransaction/" + id);

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                accountTransactionVM = JsonConvert.DeserializeObject <AccountTransactionVM>(result);
            }

            if (accountTransactionVM == null)
            {
                return(NotFound());
            }
            List <TblAccountVM> tblAccountVM = new List <TblAccountVM>();
            var contentType = new MediaTypeWithQualityHeaderValue("application/json");

            client.DefaultRequestHeaders.Accept.Add(contentType);
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TempData.Peek("Token").ToString());
            //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token"));

            HttpResponseMessage tblAccountVMRes = await client.GetAsync("api/Account");

            if (tblAccountVMRes.StatusCode == HttpStatusCode.Unauthorized)
            {
                ViewBag.Message = "Unauthorized!";
            }

            //Checking the response is successful or not which is sent using HttpClient
            if (tblAccountVMRes.IsSuccessStatusCode)
            {
                //Storing the response details recieved from web api
                var result = tblAccountVMRes.Content.ReadAsStringAsync().Result;


                //Deserializing the response recieved from web api and storing into the role list
                tblAccountVM = JsonConvert.DeserializeObject <List <TblAccountVM> >(result);
            }
            ViewData["AccountCreditId"] = new SelectList(tblAccountVM, "AccountId", "AccountTitle", accountTransactionVM.AccountCreditId);
            ViewData["AccountDebitId"]  = new SelectList(tblAccountVM, "AccountId", "AccountTitle", accountTransactionVM.AccountCreditId);



            List <SaleContractVM> saleContractVM = new List <SaleContractVM>();
            HttpResponseMessage   resp           = await client.GetAsync("api/SaleContracts");

            if (resp.StatusCode == HttpStatusCode.Unauthorized)
            {
                ViewBag.Message = "Unauthorized!";
            }

            //Checking the response is successful or not which is sent using HttpClient
            if (resp.IsSuccessStatusCode)
            {
                //Storing the response details recieved from web api
                var result = resp.Content.ReadAsStringAsync().Result;


                //Deserializing the response recieved from web api and storing into the role list
                saleContractVM = JsonConvert.DeserializeObject <List <SaleContractVM> >(result);
            }
            ViewData["SaleContractId"] = new SelectList(saleContractVM, "SaleContractId", "SaleContractNumber", accountTransactionVM.SaleContractId);


            List <TransactionTypeVM> transactionTypeVM = new List <TransactionTypeVM>();
            HttpResponseMessage      respo             = await client.GetAsync("api/TransactionType");

            if (respo.StatusCode == HttpStatusCode.Unauthorized)
            {
                ViewBag.Message = "Unauthorized!";
            }

            //Checking the response is successful or not which is sent using HttpClient
            if (respo.IsSuccessStatusCode)
            {
                //Storing the response details recieved from web api
                var result = respo.Content.ReadAsStringAsync().Result;


                //Deserializing the response recieved from web api and storing into the role list
                transactionTypeVM = JsonConvert.DeserializeObject <List <TransactionTypeVM> >(result);
            }
            ViewData["Type"] = new SelectList(transactionTypeVM, "TransactionTypeId", "Description", accountTransactionVM.Type);

            return(View(accountTransactionVM));

            //if (id == null)
            //{
            //    return NotFound();
            //}

            //var accountTransactionVM = await _context.AccountTransactionVM.FindAsync(id);
            //if (accountTransactionVM == null)
            //{
            //    return NotFound();
            //}
            //ViewData["AccountCreditId"] = new SelectList(_context.TblAccountVM, "AccountId", "AccountId", accountTransactionVM.AccountCreditId);
            //ViewData["AccountDebitId"] = new SelectList(_context.TblAccountVM, "AccountId", "AccountId", accountTransactionVM.AccountDebitId);
            //ViewData["SaleContractId"] = new SelectList(_context.SaleContractVM, "SaleContractId", "SaleContractId", accountTransactionVM.SaleContractId);
            return(View(accountTransactionVM));
        }
        public static string Insert_CrdSIMasterData(VehicleSaleMasterVM model, AccountTransactionVM AccountModel)
        {
            string      leadid = "";
            SysFunction sys    = new SysFunction();

            if (model.TransCode == "" || model.TransCode == "0" || model.TransCode == null)
            {
                string getNextTransCode = "declare @lastval varchar(14),@id int " +
                                          "set @id = (select count(*) from VehicleSaleMaster) " +
                                          "set @id=@id+1 " +
                                          "if len(@id) = 1 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate()) ) %100  as varchar(10)) +'00000' " +
                                          "if len(@id) = 2 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'0000' " +
                                          "if len(@id) = 3 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'000' " +
                                          "if len(@id) >= 4 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'00' " +
                                          "if len(@id) >= 5 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'0' " +
                                          "declare @i varchar(14) " +
                                          "set @i = CAST(@id as varchar(14)) " +
                                          "set @lastval = @lastval+@i " +
                                          "select @lastval as TransCode";

                dt = DataAccess.getDataTableByQuery(getNextTransCode, nullSqlParam, General.GetBMSConString());

                strAutoCode = dt.Rows[0]["TransCode"].ToString();
            }
            else
            {
                strAutoCode = model.TransCode;;
            }



            try
            {
                //var Serializer = new JavaScriptSerializer();
                string transType  = "CrdSI";
                string delflag    = "N";
                string dealerCode = "MCM01";

                DateTime UniDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                DateTime UniTime = Convert.ToDateTime(DateTime.Now.ToShortTimeString());
                string   txt     = model.TransDate;


                //DateTime leadDate = DateTime.ParseExact(model.TransDate,"MM/dd/yyyy", CultureInfo.InvariantCulture);
                SqlParameter[] sqlParam =
                {
                    new SqlParameter("@DealerCode", dealerCode),                   //0
                    new SqlParameter("@TransCode", strAutoCode),                   //2
                    new SqlParameter("@TransDate", sys.SaveDate(txt)),             //3
                    new SqlParameter("@TransType", transType),                     //4
                    new SqlParameter("@SaleType", model.SaleType),                 //5
                    new SqlParameter("@CreditTerms", model.CreditTerms),           //6
                    new SqlParameter("@EmpCode", model.EmpCode),                   //7
                    new SqlParameter("@CusCode", model.CusCode),                   //8
                    new SqlParameter("@CustomerType", model.CustomerType),         //9
                    new SqlParameter("@CNICNTN", model.CNICNTN),                   //10
                    new SqlParameter("@ContactNo", model.ContactNo),               //11
                    new SqlParameter("@PriceLevel", model.PriceLevel),             //12
                    new SqlParameter("@BillTo", model.BillTo),                     //13
                    new SqlParameter("@ShipTo", model.ShipTo),                     //14
                    new SqlParameter("@SameAs", model.SameAs),                     //15
                    new SqlParameter("@TotalQty", model.TotalQty),                 //16
                    new SqlParameter("@ServceQty", model.TotalQty),                //17
                    new SqlParameter("@TotalAmount", model.TotalAmount),           //18
                    new SqlParameter("@PaymentReceiptCode", (object)DBNull.Value), //19
                    new SqlParameter("@PaidAmoun", (object)DBNull.Value),          //20
                    new SqlParameter("@DelFlag", delflag),                         //21
                    new SqlParameter("@RefType", model.RefType),                   //22
                    new SqlParameter("@RefDocumentNo", model.RefDocumentNo),       //23
                    new SqlParameter("@PostFlag", (object)DBNull.Value),           //24
                    new SqlParameter("@VoucherNo", (object)DBNull.Value),          //25
                    new SqlParameter("@VoucherDate", (object)DBNull.Value),        //26
                    new SqlParameter("@UpdUser", AuthBase.UserId),                 //27
                    new SqlParameter("@UpdDate", UniDate),                         //28
                    new SqlParameter("@UpdTime", UniTime),                         //29
                    new SqlParameter("@UpdTerm", General.CurrentIP),               //30
                };
                dt = DataAccess.getDataTable("SP_Insert_VehicleSaleMaster", sqlParam, General.GetBMSConString());
                if (dt.Rows.Count > 0)
                {
                }
                leadid  = strAutoCode;
                IsSaved = true;
            }
            catch (Exception ex)
            {
                //throw;
            }



            //-------------------------Account Transaction----------------------------------

            string ActAutoCode;

            if (AccountModel.TransactionCode == "" || AccountModel.TransactionCode == "0" || AccountModel.TransactionCode == null)
            {
                string getNextTransCode = "declare @lastval varchar(14),@id int " +
                                          "set @id = (select count(*) from AccountTransaction) " +
                                          "set @id=@id+1 " +
                                          "if len(@id) = 1 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate()) ) %100  as varchar(10)) +'00000' " +
                                          "if len(@id) = 2 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'0000' " +
                                          "if len(@id) = 3 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'000' " +
                                          "if len(@id) >= 4 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'00' " +
                                          "if len(@id) >= 5 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'0' " +
                                          "declare @i varchar(14) " +
                                          "set @i = CAST(@id as varchar(14)) " +
                                          "set @lastval = @lastval+@i " +
                                          "select @lastval as TransactionCode";

                dt = DataAccess.getDataTableByQuery(getNextTransCode, nullSqlParam, General.GetBMSConString());

                ActAutoCode = dt.Rows[0]["TransactionCode"].ToString();
            }
            else
            {
                ActAutoCode = AccountModel.TransactionCode;;
            }



            try
            {
                //var Serializer = new JavaScriptSerializer();

                string delflag    = "N";
                string dealerCode = "MCM01";
                string TrType     = "CrdSI";
                int    Credit     = 0;
                string Narration  = " Credit Sale Invoice ";
                //DateTime CreateDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                DateTime CreateTime = Convert.ToDateTime(DateTime.Now.ToShortTimeString());
                DateTime CreateDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                //DateTime leadDate = DateTime.ParseExact(AccountModel.TransactionDate,"MM/dd/yyyy", CultureInfo.InvariantCulture);
                SqlParameter[] sqlParam =
                {
                    new SqlParameter("@DealerCode", dealerCode),         //0
                    //new SqlParameter("@ID",),//2
                    new SqlParameter("@TransactionCode", ActAutoCode),   //3
                    new SqlParameter("@TransactionDate", CreateDate),    //4
                    new SqlParameter("@CusCode", model.CusCode),         //5
                    new SqlParameter("@AccountCode", model.CusCode),     //6
                    new SqlParameter("@InvType", TrType),                //7
                    new SqlParameter("@TrType", TrType),                 //8
                    new SqlParameter("@Narration", Narration),           //9
                    new SqlParameter("@Reference", model.RefDocumentNo), //10
                    new SqlParameter("@Debit", model.TotalAmount),       //11
                    new SqlParameter("@Credit", Credit),                 //12
                    new SqlParameter("@Balance", model.TotalAmount),     //13
                    new SqlParameter("@Remarks", Narration),             //14
                    new SqlParameter("@CreateDate", CreateDate),         //15
                    new SqlParameter("@CreateTime", CreateTime),         //16
                    new SqlParameter("@CreateUser", AuthBase.EmpCode),   //17
                    new SqlParameter("@CreateTerm", AuthBase.UserId),    //18
                    new SqlParameter("@UpdDate", (object)DBNull.Value),  //19
                    new SqlParameter("@UpdTime", (object)DBNull.Value),  //20
                    new SqlParameter("@UpdUser", (object)DBNull.Value),  //21
                    new SqlParameter("@UpdTerm", (object)DBNull.Value),  //22
                };
                dt = DataAccess.getDataTable("SP_Insert_AccountTransaction", sqlParam, General.GetBMSConString());
                if (dt.Rows.Count > 0)
                {
                }
                leadid  = strAutoCode;
                IsSaved = true;
            }
            catch (Exception ex)
            {
                //throw;
            }

            return(leadid);
        }
예제 #15
0
        public static bool Insert_CSIMasterData(VehicleSaleMasterVM model, AccountTransactionVM AccountModel, ReceiptMasterVM ReceiptModel, string ProdDesc, string EngineNo, string ChassisNo, string DealerCode, ref string msg)
        {
            string leadid     = "";
            string json       = "";
            var    Serializer = new JavaScriptSerializer();
            List <VehicleSaleMasterVM> lst = new List <VehicleSaleMasterVM>();

            //SysFunction sys = new SysFunction();


            if (model.TransCode == "" || model.TransCode == "0" || model.TransCode == null)
            {
                strAutoCode = sys.AutoGen("VehicleSaleMaster", "TransCode", DateTime.Parse(DateTime.Now.ToShortDateString()).ToString("dd/MM/yyyy"), DealerCode);



                //  dt = DataAccess.getDataTableByQuery(getNextTransCode, nullSqlParam, General.GetSBOConString());

                //   strAutoCode = dt.Rows[0]["TransCode"].ToString();
            }
            else
            {
                strAutoCode = model.TransCode;;
            }



            try
            {
                //var Serializer = new JavaScriptSerializer();
                string transType = "CSI";
                string delflag   = "N";
                //string dealerCode = "MCM01";

                DateTime UniDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                DateTime UniTime = Convert.ToDateTime(DateTime.Now.ToShortTimeString());
                //   string txt = sys.SaveDate(model.TransDate);


                //DateTime leadDate = DateTime.ParseExact(model.TransDate,"MM/dd/yyyy", CultureInfo.InvariantCulture);
                SqlParameter[] sqlParam =
                {
                    new SqlParameter("@DealerCode", DealerCode),                   //0
                    new SqlParameter("@TransCode", strAutoCode),                   //2
                    new SqlParameter("@TransDate", sys.SaveDate(model.TransDate)), //3
                    new SqlParameter("@TransType", transType),                     //4
                    new SqlParameter("@SaleType", model.SaleType),                 //5
                    new SqlParameter("@CreditTerms", model.CreditTerms),           //6
                    new SqlParameter("@EmpCode", model.EmpCode),                   //7
                    new SqlParameter("@CusCode", model.CusCode),                   //8
                    new SqlParameter("@CustomerType", model.CustomerType),         //9
                    new SqlParameter("@CNICNTN", model.CNICNTN),                   //10
                    new SqlParameter("@ContactNo", model.ContactNo),               //11
                    new SqlParameter("@PriceLevel", model.PriceLevel),             //12
                    new SqlParameter("@BillTo", model.BillTo),                     //13
                    new SqlParameter("@ShipTo", model.ShipTo),                     //14
                    new SqlParameter("@SameAs", model.SameAs),                     //15
                    new SqlParameter("@TotalQty", model.TotalQty),                 //16
                    new SqlParameter("@ServceQty", model.TotalQty),                //17
                    new SqlParameter("@TotalAmount", model.TotalAmount),           //18
                    new SqlParameter("@PaymentReceiptCode", (object)DBNull.Value), //19
                    new SqlParameter("@PaidAmoun", (object)DBNull.Value),          //20
                    new SqlParameter("@DelFlag", delflag),                         //21
                    new SqlParameter("@RefType", model.RefType),                   //22
                    new SqlParameter("@RefDocumentNo", model.RefDocumentNo),       //23
                    new SqlParameter("@PostFlag", (object)DBNull.Value),           //24
                    new SqlParameter("@VoucherNo", (object)DBNull.Value),          //25
                    new SqlParameter("@VoucherDate", (object)DBNull.Value),        //26
                    new SqlParameter("@UpdUser", AuthBase.UserId),                 //27
                    new SqlParameter("@UpdDate", UniDate),                         //28
                    new SqlParameter("@UpdTime", UniTime),                         //29
                    new SqlParameter("@UpdTerm", General.CurrentIP),               //30
                    new SqlParameter("@CusInvCode", model.CusInvCode),             //30
                };

                //    dt = DataAccess.getDataTable("SP_Insert_VehicleSaleMaster", sqlParam, General.GetSBOConString());
                //    if (dt.Rows.Count > 0)
                //    {
                //        IsSaved = true;
                //        // lst = EnumerableExtension.ToList<VehicleSaleMasterVM>(dt);
                //    }
                //    json = Serializer.Serialize(lst);
                //}
                //catch (Exception ex)
                //{
                //    ObjTrans.RollBackTransaction(ref Trans);

                //    msg = ex.Message;
                //}


                if (ObjTrans.BeginTransaction(ref Trans) == true)
                {
                    sys.ExecuteSP_NonQuery("SP_Insert_VehicleSaleMaster", sqlParam, Trans);


                    IsSaved = true;
                }
            }

            catch (Exception ex)
            {
                ObjTrans.RollBackTransaction(ref Trans);
                //throw;
                msg = ex.Message;
            }



            //-------------------------Account Transaction----------------------------------



            string ActAutoCode;

            if (AccountModel.TransactionCode == "" || AccountModel.TransactionCode == "0" || AccountModel.TransactionCode == null)
            {
                string getNextTransCode = "declare @lastval varchar(14),@id int " +
                                          "set @id = (select count(*) from AccountTrasnaction) " +
                                          "set @id=@id+1 " +
                                          "if len(@id) = 1 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate()) ) %100  as varchar(10)) +'00000' " +
                                          "if len(@id) = 2 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'0000' " +
                                          "if len(@id) = 3 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'000' " +
                                          "if len(@id) >= 4 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'00' " +
                                          "if len(@id) >= 5 " +
                                          "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'0' " +
                                          "declare @i varchar(14) " +
                                          "set @i = CAST(@id as varchar(14)) " +
                                          "set @lastval = @lastval+@i " +
                                          "select @lastval as TransactionCode";

                dt = DataAccess.getDataTableByQuery(getNextTransCode, nullSqlParam, General.GetSBOConString());

                ActAutoCode = dt.Rows[0]["TransactionCode"].ToString();
            }
            else
            {
                ActAutoCode = AccountModel.TransactionCode;;
            }



            try
            {
                //var Serializer = new JavaScriptSerializer();

                string delflag    = "N";
                string dealerCode = "MCM01";
                string TrType     = "CSI";
                int    Credit     = 0;
                string Narration  = " Cash Sale Invoice ";
                //DateTime CreateDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                DateTime CreateTime = Convert.ToDateTime(DateTime.Now.ToShortTimeString());
                DateTime CreateDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                //DateTime leadDate = DateTime.ParseExact(AccountModel.TransactionDate,"MM/dd/yyyy", CultureInfo.InvariantCulture);
                SqlParameter[] sqlParam =
                {
                    new SqlParameter("@DealerCode", DealerCode),         //0
                    //new SqlParameter("@ID",),//2
                    new SqlParameter("@TransactionCode", ActAutoCode),   //3
                    new SqlParameter("@TransactionDate", CreateDate),    //4
                    new SqlParameter("@CusCode", model.CusCode),         //5
                    new SqlParameter("@AccountCode", model.CusCode),     //6
                    new SqlParameter("@InvType", TrType),                //7
                    new SqlParameter("@TrType", TrType),                 //8
                    new SqlParameter("@Narration", Narration),           //9
                    new SqlParameter("@Reference", model.RefDocumentNo), //10
                    new SqlParameter("@Debit", model.TotalAmount),       //11
                    new SqlParameter("@Credit", Credit),                 //12
                    new SqlParameter("@Balance", model.TotalAmount),     //13
                    new SqlParameter("@Remarks", Narration),             //14
                    new SqlParameter("@CreateDate", CreateDate),         //15
                    new SqlParameter("@CreateTime", CreateTime),         //16
                    new SqlParameter("@CreateUser", AuthBase.EmpCode),   //17
                    new SqlParameter("@CreateTerm", AuthBase.UserId),    //18
                    new SqlParameter("@UpdDate", (object)DBNull.Value),  //19
                    new SqlParameter("@UpdTime", (object)DBNull.Value),  //20
                    new SqlParameter("@UpdUser", (object)DBNull.Value),  //21
                    new SqlParameter("@UpdTerm", (object)DBNull.Value),  //22
                    new SqlParameter("@ReceiptNo", (DBNull.Value))
                };
                if (sys.ExecuteSP_NonQuery("SP_Insert_AccountTransaction", sqlParam, Trans) == true)
                {
                    IsSaved = true;
                }
                //if (ObjTrans.BeginTransaction(ref Trans) == true)
                //{
                //    sys.ExecuteSP_NonQuery("SP_Insert_AccountTransaction", sqlParam, Trans);



                //    IsSaved = true;
                //}
            }

            catch (Exception ex)
            {
                ObjTrans.RollBackTransaction(ref Trans);
                msg = ex.Message;
            }



            return(IsSaved);
        }
예제 #16
0
        public static bool Insert_AccountTransaction(AccountTransactionVM AccountModel, ref string msg)
        {
            string strReceiptNo;

            try
            {
                DataTable dt = sysfun.GetData("SP_GET_BlnAmt_AccountTransaction '" + AccountModel.DealerCode + "','" + AccountModel.Reference + "'", "BMS0517ConnectionString");

                DataTable dt2 = sysfun.GetData("Select ShortForm from VehExpHead where VehExpCode = '" + AccountModel.TrType + "' and DealerCode in ('" + AccountModel.DealerCode + "','COMON')", "BMS0517ConnectionString");

                DataTable dt3 = sysfun.GetData("Select AccountCode from Customer where CusCode = '" + AccountModel.CusCode + "' and DealerCode = '" + AccountModel.DealerCode + "'", "BMS0517ConnectionString");

                if (AccountModel.Reference != null)
                {
                    string getNextTransCode = "declare @lastval varchar(14),@id int " +
                                              "set @id = (select count(*) from AccountTransaction) " +
                                              "set @id=@id+1 " +
                                              "if len(@id) = 1 " +
                                              "set @lastval='" + "'+cast((YEAR(getDate()) ) %100  as varchar(10)) +'00000' " +
                                              "if len(@id) = 2 " +
                                              "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'0000' " +
                                              "if len(@id) = 3 " +
                                              "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'000' " +
                                              "if len(@id) >= 4 " +
                                              "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'00' " +
                                              "if len(@id) >= 5 " +
                                              "set @lastval='" + "'+cast((YEAR(getDate())  ) %100  as varchar(10)) +'0' " +
                                              "declare @i varchar(14) " +
                                              "set @i = CAST(@id as varchar(14)) " +
                                              "set @lastval = @lastval+@i " +
                                              "select @lastval as TransactionCode";

                    DataTable dt4 = DataAccess.getDataTableByQuery(getNextTransCode, nullSqlParam, General.GetBMSConString());

                    strReceiptNo = dt4.Rows[0]["TransactionCode"].ToString();

                    //strReceiptNo = sysfun.AutoGen("AccountTransaction", "TransactionCode", DateTime.Parse(DateTime.Now.ToShortDateString()).ToString("dd/MM/yyyy"), item.DealerCode);

                    SqlParameter[] sqlParam =
                    {
                        new SqlParameter("@DealerCode",      AccountModel.DealerCode),                                                        //0
                        new SqlParameter("@TransactionCode", strReceiptNo),                                                                   //3
                        new SqlParameter("@TransactionDate", sysfun.SaveDate(AccountModel.TransactionDate)),                                  //4
                        new SqlParameter("@CusCode",         AccountModel.CusCode),                                                           //5
                        new SqlParameter("@AccountCode",     dt3.Rows[0]["AccountCode"].ToString()),                                          //6
                        new SqlParameter("@InvType",         AccountModel.InvType),                                                           //7
                        new SqlParameter("@TrType",          AccountModel.TrType),                                                            //8
                        new SqlParameter("@Narration",       AccountModel.Narration),                                                         //9
                        new SqlParameter("@Reference",       AccountModel.Reference),                                                         //10
                        new SqlParameter("@Debit",           AccountModel.Debit),                                                             //11
                        new SqlParameter("@Credit",          AccountModel.Credit),                                                            //12
                        new SqlParameter("@Balance",         dt.Rows[0]["Balance"].ToString() == "" ? "0" :dt.Rows[0]["Balance"].ToString()), //13
                        new SqlParameter("@Remarks",         (object)DBNull.Value),                                                           //14
                        new SqlParameter("@CreateDate",      DateTime.Now),
                        new SqlParameter("@CreateTime",      DateTime.Now),
                        new SqlParameter("@CreateUser",      AuthBase.EmpCode),             //17
                        new SqlParameter("@CreateTerm",      AuthBase.UserId),              //18
                        new SqlParameter("@UpdDate",         (object)DBNull.Value),         //19
                        new SqlParameter("@UpdTime",         (object)DBNull.Value),         //20
                        new SqlParameter("@UpdUser",         (object)DBNull.Value),         //21
                        new SqlParameter("@UpdTerm",         (object)DBNull.Value),         //22
                        new SqlParameter("@ReceiptNo",       strAutoCode),                  //22
                    };

                    if (sysfun.ExecuteSP_NonQuery("SP_Insert_AccountTransaction", sqlParam, Trans) == true)
                    {
                        IsSaved = true;
                    }
                    else
                    {
                        ObjTrans.RollBackTransaction(ref Trans);
                        return(false);
                    }
                }

                ObjTrans.CommittTransaction(ref Trans);
            }
            catch (Exception ex)
            {
                ObjTrans.RollBackTransaction(ref Trans);
                msg = ex.Message;
                return(false);
            }

            return(IsSaved);
        }