public ActionResult Payment(int id) { var ctx = new SmsContext(); InvoicesModel model = new InvoicesModel(); var invoiceInfor = ctx.SP_GET_HOA_DON_INFO(id).FirstOrDefault(); List <V_HOA_DON> detailList = ctx.V_HOA_DON.Where(dh => dh.MA_HOA_DON == id).ToList(); model.Infor = invoiceInfor; model.detailList = detailList; SmsMasterModel master = new SmsMasterModel(); var companyName = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "COMPANY_NAME").FirstOrDefault(); var address = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "ADDRESS").FirstOrDefault(); var phoneNumber = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "PHONE_NUMBER").FirstOrDefault(); var faxNumber = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "FAX_NUMBER").FirstOrDefault(); var advertisementHeader = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "ADVERTISEMENT_HEADER").FirstOrDefault(); var advertisementFooter = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "ADVERTISEMENT_FOOTER").FirstOrDefault(); master.CompanyName = companyName == null ? "" : companyName.VALUE; master.Address = address == null ? "" : address.VALUE; master.AdvertisementHeader = advertisementHeader == null ? "" : advertisementHeader.VALUE; master.AdvertisementFooter = advertisementFooter == null ? "" : advertisementFooter.VALUE; master.PhoneNumber = phoneNumber == null ? "" : phoneNumber.VALUE; master.FaxNumber = faxNumber == null ? "" : faxNumber.VALUE; model.SmsMaster = master; ctx.Dispose(); return(View(model)); }
public ActionResult ShowDetail(InvoicesModel model) { var ctx = new SmsContext(); var invoiceInfor = ctx.HOA_DON.Single(uh => uh.MA_HOA_DON == model.Infor.MA_HOA_DON && uh.ACTIVE == "A"); if (invoiceInfor == null || invoiceInfor.STATUS != 2) { ViewBag.Message = "Không thể cấp quyền sửa hóa đơn cho hóa đơn này."; } else { if (invoiceInfor.MA_KHACH_HANG != null && !string.IsNullOrEmpty(invoiceInfor.MA_KHACH_HANG.ToString())) { var customer = ctx.KHACH_HANG.Single(uh => uh.MA_KHACH_HANG == invoiceInfor.MA_KHACH_HANG && uh.ACTIVE == "A"); if (customer != null) { customer.DOANH_SO = Convert.ToDecimal(customer.DOANH_SO) - Convert.ToDecimal(invoiceInfor.SO_TIEN_KHACH_TRA) - Convert.ToDecimal(invoiceInfor.SO_TIEN_NO_GOI_DAU); customer.NO_GOI_DAU = Convert.ToDecimal(customer.NO_GOI_DAU) - Convert.ToDecimal(invoiceInfor.SO_TIEN_NO_GOI_DAU); if (customer.NO_GOI_DAU <= 0) { customer.NGAY_PHAT_SINH_NO = null; } customer.UPDATE_AT = DateTime.Now; customer.UPDATE_BY = (int)Session["UserId"]; } var debitHist = ctx.KHACH_HANG_DEBIT_HIST.OrderByDescending(uh => uh.ID).FirstOrDefault(uh => uh.MA_HOA_DON == model.Infor.MA_HOA_DON && uh.ACTIVE == "A"); if (debitHist != null) { debitHist.ACTIVE = "I"; debitHist.UPDATE_AT = DateTime.Now; debitHist.UPDATE_BY = (int)Session["UserId"]; } } invoiceInfor.STATUS = 1; invoiceInfor.SO_TIEN_KHACH_TRA = 0; invoiceInfor.SO_TIEN_NO_GOI_DAU = 0; invoiceInfor.MA_NHAN_VIEN_THU_TIEN = null; invoiceInfor.EDIT_APPROVER = (int)Session["UserId"]; invoiceInfor.UPDATE_AT = DateTime.Now; invoiceInfor.UPDATE_BY = (int)Session["UserId"]; ctx.SaveChanges(); } List <V_HOA_DON> detailList = ctx.V_HOA_DON.Where(dh => dh.MA_HOA_DON == model.Infor.MA_HOA_DON).ToList(); var infor = ctx.SP_GET_HOA_DON_INFO(model.Infor.MA_HOA_DON).FirstOrDefault(); model.Infor = infor; model.detailList = detailList; ctx.Dispose(); return(RedirectToAction("Index")); }
public ActionResult ShowDetail(int id, int?flg, int?status) { var ctx = new SmsContext(); InvoicesModel model = new InvoicesModel(); var invoiceInfor = ctx.SP_GET_HOA_DON_INFO(id).FirstOrDefault(); if (invoiceInfor != null && invoiceInfor.MA_KHACH_HANG != null) { var customer = ctx.KHACH_HANG.Find(invoiceInfor.MA_KHACH_HANG); if (customer != null) { var kind = customer.KIND; model.customerDebit = customer.NO_GOI_DAU; invoiceInfor.SO_TIEN_NO_GOI_DAU = Convert.ToDouble(customer.NO_GOI_DAU); string key = ""; if (kind == 1) { key = "MAX_DEBIT_KIND_1"; } else if (kind == 2) { key = "MAX_DEBIT_KIND_2"; } else { key = "MAX_DEBIT_KIND_3"; } var maxdebit = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == key).FirstOrDefault(); if (maxdebit != null && maxdebit.VALUE != null) { decimal debit = decimal.Parse(maxdebit.VALUE.Replace(",", "")); model.maxDebit = debit; } } } List <V_HOA_DON> detailList = ctx.V_HOA_DON.Where(dh => dh.MA_HOA_DON == id).ToList(); model.Infor = invoiceInfor; model.detailList = detailList; ViewBag.Flg = flg; if (status == 0) { ViewBag.Message = "Không đủ số lượng để xuất kho. Vui lòng kiểm tra lại hóa đơn."; ViewBag.Status = 0; } else if (status == -1) { ViewBag.Message = "Hóa đơn đã được thu tiền. Không thể thu tiền hóa đơn này"; ViewBag.Status = -1; } ctx.Dispose(); return(View(model)); }
public ActionResult Export(int id, int?makho) { var ctx = new SmsContext(); var infor = ctx.SP_GET_HOA_DON_INFO(id).FirstOrDefault(); if (makho == null) { makho = 0; } var detailList = ctx.SP_GET_HD_DETAIL_FOR_EXPORT(Convert.ToInt32(makho), Convert.ToInt32(id)).ToList <SP_GET_HD_DETAIL_FOR_EXPORT_Result>(); ExportModel model = new ExportModel(); model.DetailList = detailList; model.Infor = infor; model.storeId = Convert.ToInt32(makho); ctx.Dispose(); return(View(model)); }
public ActionResult Show(int id, string message, string messageInfor) { var ctx = new SmsContext(); var invoiceInfor = ctx.SP_GET_HOA_DON_INFO(id).FirstOrDefault(); InvoicesModel model = new InvoicesModel(); if (invoiceInfor != null && invoiceInfor.MA_KHACH_HANG != null) { var customerInformation = ctx.KHACH_HANG.Find(invoiceInfor.MA_KHACH_HANG); if (customerInformation != null) { model.CustomerInformation = customerInformation; } } List <SP_GET_HOA_DON_DETAIL_FOR_RETURN_Result> detailList = ctx.SP_GET_HOA_DON_DETAIL_FOR_RETURN(id).ToList <SP_GET_HOA_DON_DETAIL_FOR_RETURN_Result>(); model.Infor = invoiceInfor; model.detailReturnList = detailList; ViewBag.Message = message; ViewBag.MessageInfor = messageInfor; ctx.Dispose(); return(View(model)); }
public ActionResult Payment(InvoicesModel model) { var ctx = new SmsContext(); var invoice = ctx.HOA_DON.Find(model.Infor.MA_HOA_DON); if (invoice != null && invoice.STATUS >= 2) { return(RedirectToAction("Collection", new { @messagae = "Hóa đơn đã được thu tiền." })); } if (invoice != null && invoice.ACTIVE == "A") { if (model.Infor.SO_TIEN_KHACH_TRA == null) { model.Infor.SO_TIEN_KHACH_TRA = 0; } if (model.Infor.SO_TIEN_KHACH_TRA <= (model.Infor.TONG_TIEN - model.Infor.CHIEC_KHAU)) { model.Infor.SO_TIEN_NO_GOI_DAU = (model.Infor.TONG_TIEN - model.Infor.CHIEC_KHAU) - model.Infor.SO_TIEN_KHACH_TRA; } else { model.Infor.SO_TIEN_KHACH_TRA = (model.Infor.TONG_TIEN - model.Infor.CHIEC_KHAU); model.Infor.SO_TIEN_NO_GOI_DAU = 0; } invoice.SO_TIEN_KHACH_TRA = model.Infor.SO_TIEN_KHACH_TRA; invoice.SO_TIEN_NO_GOI_DAU = model.Infor.SO_TIEN_NO_GOI_DAU; invoice.STATUS = 2; invoice.UPDATE_AT = DateTime.Now; invoice.UPDATE_BY = (int)Session["UserId"]; invoice.MA_NHAN_VIEN_THU_TIEN = (int)Session["UserId"]; if (Convert.ToInt32(model.Infor.MA_KHACH_HANG) > 0) { var customer = ctx.KHACH_HANG.Find(Convert.ToInt32(model.Infor.MA_KHACH_HANG)); if (customer != null && customer.ACTIVE == "A") { customer.DOANH_SO = customer.DOANH_SO + Convert.ToDecimal(model.Infor.TONG_TIEN) - Convert.ToDecimal(model.Infor.CHIEC_KHAU); if (model.Infor.SO_TIEN_NO_GOI_DAU > 0) { if (customer.NGAY_PHAT_SINH_NO == null) { customer.NGAY_PHAT_SINH_NO = DateTime.Now; } var DebitHist = ctx.KHACH_HANG_DEBIT_HIST.Create(); DebitHist.NO_TRUOC = Convert.ToDouble(customer.NO_GOI_DAU); DebitHist.NO_SAU = Convert.ToDouble(customer.NO_GOI_DAU) + model.Infor.SO_TIEN_NO_GOI_DAU; DebitHist.NGAY_PHAT_SINH = DateTime.Now; DebitHist.PHAT_SINH = -1 * Convert.ToDouble(model.Infor.SO_TIEN_NO_GOI_DAU); DebitHist.MA_HOA_DON = model.Infor.MA_HOA_DON; DebitHist.MA_KHACH_HANG = customer.MA_KHACH_HANG; DebitHist.MA_NHAN_VIEN_TH = (int)Session["UserId"]; DebitHist.ACTIVE = "A"; DebitHist.UPDATE_AT = DateTime.Now; DebitHist.UPDATE_BY = (int)Session["UserId"]; DebitHist.CREATE_AT = DateTime.Now; DebitHist.CREATE_BY = (int)Session["UserId"]; ctx.KHACH_HANG_DEBIT_HIST.Add(DebitHist); } //customer.NO_GOI_DAU = customer.NO_GOI_DAU + Convert.ToDecimal(model.Infor.SO_TIEN_NO_GOI_DAU); customer.NO_GOI_DAU = Convert.ToDecimal(model.Infor.SO_TIEN_NO_GOI_DAU); customer.UPDATE_AT = DateTime.Now; customer.UPDATE_BY = (int)Session["UserId"]; } else { ViewBag.Message = "Không tìm thấy khách hàng tương ứng."; return(View("../Home/Error")); } } ctx.SaveChanges(); } else { ctx.Dispose(); ViewBag.Message = "Không tìm thấy hóa đơn tương ứng."; return(View("../Home/Error")); } var invoiceInfor = ctx.SP_GET_HOA_DON_INFO(model.Infor.MA_HOA_DON).FirstOrDefault(); List <V_HOA_DON> detailList = ctx.V_HOA_DON.Where(dh => dh.MA_HOA_DON == model.Infor.MA_HOA_DON).ToList(); model.Infor = invoiceInfor; model.detailList = detailList; SmsMasterModel master = new SmsMasterModel(); var companyName = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "COMPANY_NAME").FirstOrDefault(); var address = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "ADDRESS").FirstOrDefault(); var phoneNumber = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "PHONE_NUMBER").FirstOrDefault(); var faxNumber = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "FAX_NUMBER").FirstOrDefault(); var advertisementHeader = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "ADVERTISEMENT_HEADER").FirstOrDefault(); var advertisementFooter = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "ADVERTISEMENT_FOOTER").FirstOrDefault(); master.CompanyName = companyName == null ? "" : companyName.VALUE; master.Address = address == null ? "" : address.VALUE; master.AdvertisementHeader = advertisementHeader == null ? "" : advertisementHeader.VALUE; master.AdvertisementFooter = advertisementFooter == null ? "" : advertisementFooter.VALUE; master.PhoneNumber = phoneNumber == null ? "" : phoneNumber.VALUE; master.FaxNumber = faxNumber == null ? "" : faxNumber.VALUE; model.SmsMaster = master; ctx.Dispose(); return(View(model)); }
public ActionResult PaymentAndExport(InvoicesModel model) { var ctx = new SmsContext(); var InvoiceId = new SqlParameter { ParameterName = "MA_HOA_DON", Value = Convert.ToInt32(model.Infor.MA_HOA_DON) }; var UserId = new SqlParameter { ParameterName = "MA_NHAN_VIEN_THUC_HIEN", Value = Convert.ToInt32(Session["UserId"]) }; if (model.Infor.SO_TIEN_KHACH_TRA >= (model.Infor.TONG_TIEN - model.Infor.CHIEC_KHAU)) { model.Infor.SO_TIEN_KHACH_TRA = model.Infor.TONG_TIEN - model.Infor.CHIEC_KHAU; } var TotalPay = new SqlParameter { ParameterName = "SO_TIEN_KHACH_TRA", Value = Convert.ToDouble(model.Infor.SO_TIEN_KHACH_TRA) }; var returnValue = new SqlParameter { ParameterName = "RETURN_VALUE", Value = Convert.ToInt32(0), Direction = ParameterDirection.Output }; ctx.Database.CommandTimeout = 300; var tonkho = ctx.Database.ExecuteSqlCommand("exec SP_THU_TIEN_XUAT_KHO @MA_HOA_DON, @MA_NHAN_VIEN_THUC_HIEN, @SO_TIEN_KHACH_TRA , @RETURN_VALUE OUT", InvoiceId, UserId, TotalPay, returnValue ); int returnVal = Convert.ToInt32(returnValue.Value); int flg = Convert.ToInt32(Request.Form["flg"]); if (returnVal == 0) { ViewBag.Message = "Không đủ số lượng để xuất kho. Vui lòng kiểm tra lại hóa đơn."; ViewBag.Status = 0; ctx.Dispose(); return(RedirectToAction("ShowDetail", new { @id = model.Infor.MA_HOA_DON, @flg = flg, @status = 0 })); } else if (returnVal == -1) { ViewBag.Message = "Hóa đơn đã được thu tiền. Không thể thu tiền hóa đơn này"; ViewBag.Status = -1; ctx.Dispose(); return(RedirectToAction("ShowDetail", new { @id = model.Infor.MA_HOA_DON, @flg = flg, @status = -1 })); } var invoiceInfor = ctx.SP_GET_HOA_DON_INFO(model.Infor.MA_HOA_DON).FirstOrDefault(); List <V_HOA_DON> detailList = ctx.V_HOA_DON.Where(dh => dh.MA_HOA_DON == model.Infor.MA_HOA_DON).ToList(); model.Infor = invoiceInfor; model.detailList = detailList; SmsMasterModel master = new SmsMasterModel(); var companyName = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "COMPANY_NAME").FirstOrDefault(); var address = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "ADDRESS").FirstOrDefault(); var phoneNumber = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "PHONE_NUMBER").FirstOrDefault(); var faxNumber = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "FAX_NUMBER").FirstOrDefault(); var advertisementHeader = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "ADVERTISEMENT_HEADER").FirstOrDefault(); var advertisementFooter = ctx.SMS_MASTER.Where(u => u.ACTIVE == "A" && u.NAME == "ADVERTISEMENT_FOOTER").FirstOrDefault(); master.CompanyName = companyName == null ? "" : companyName.VALUE; master.Address = address == null ? "" : address.VALUE; master.AdvertisementHeader = advertisementHeader == null ? "" : advertisementHeader.VALUE; master.AdvertisementFooter = advertisementFooter == null ? "" : advertisementFooter.VALUE; master.PhoneNumber = phoneNumber == null ? "" : phoneNumber.VALUE; master.FaxNumber = faxNumber == null ? "" : faxNumber.VALUE; model.SmsMaster = master; ctx.Dispose(); return(View(model)); }
public ActionResult Export(ExportModel model) { var ctx = new SmsContext(); var storeId = new SqlParameter { ParameterName = "MA_KHO", Value = Convert.ToInt32(model.storeId) }; var InvoiceId = new SqlParameter { ParameterName = "MA_HOA_DON", Value = Convert.ToInt32(model.Infor.MA_HOA_DON) }; var UserId = new SqlParameter { ParameterName = "MA_NHAN_VIEN_THUC_HIEN", Value = Convert.ToInt32(Session["UserId"]) }; var customerName = new SqlParameter { ParameterName = "TEN_KHACH_HANG", Value = model.Infor.TEN_KHACH_HANG }; var returnValue = new SqlParameter { ParameterName = "RETURN_VALUE", Value = Convert.ToInt32(0), Direction = ParameterDirection.Output }; ctx.Database.CommandTimeout = 300; var export = ctx.Database.ExecuteSqlCommand("exec SP_SALE_EXPORT @MA_KHO, @MA_HOA_DON, @MA_NHAN_VIEN_THUC_HIEN, @TEN_KHACH_HANG , @RETURN_VALUE OUT", storeId, InvoiceId, UserId, customerName, returnValue ); int returnVal = Convert.ToInt32(returnValue.Value); if (returnVal == -1) { ctx.Dispose(); return(RedirectToAction("Index", new { @message = "Không thể xuất kho hóa đơn này. Lý do: có thể hóa đơn đã được xuất kho, hay đã bị hủy." })); } else if (returnVal == 0) { ViewBag.Message = "Không đủ số lượng để xuất kho"; } else { ctx.Dispose(); return(RedirectToAction("Index", new { @messageInfor = "Xuất kho thành công" })); } var infor = ctx.SP_GET_HOA_DON_INFO(model.Infor.MA_HOA_DON).FirstOrDefault(); var detailList = ctx.SP_GET_HD_DETAIL_FOR_EXPORT(Convert.ToInt32(model.storeId), Convert.ToInt32(model.Infor.MA_HOA_DON)).ToList <SP_GET_HD_DETAIL_FOR_EXPORT_Result>(); model.DetailList = detailList; model.Infor = infor; ctx.Dispose(); return(View(model)); }