public ActionResult Edit(int key) { var model = new Edit(); if (key > 0) { model.MasterKey = key;//use in detail grid var temp = _Service.GetMD(key); model.Master = new TR01AViewModel(temp.Master); var dataCollection = new List <TR01BViewModel>(); foreach (var item in temp.DetaiList) { dataCollection.Add(new TR01BViewModel(item)); } model.DetailList = dataCollection; var entity = new PURSysEntities(); var BA01BList = entity.BA01B.Where(x => x.BA01A_ID == model.Master.BA01A_ID).ToList(); var BA01B = BA01BList.FirstOrDefault(x => x.BA01B_ID == model.Master.BA01B_ID); if (BA01B != null) { model.Master.TEL_NO = BA01B.TEL_NO; model.Master.TEL_EX = BA01B.TEL_EX; } ViewBag.Data = BA01BList; } else { model.MasterKey = 0; model.Master = new TR01AViewModel(); model.Master.DtPUR_DT = DateTime.UtcNow.AddHours(07); model.DetailList = new List <TR01BViewModel>(); } return(View("Edit", model)); }
public ActionResult CreateReport(int key) { TR01Service _Service = new TR01Service(); var temp = _Service.GetMD(key); var model = new ERP_V2.ViewModels.TR01.Edit(); model.Master = new ERP_V2.ViewModels.TR01.TR01AViewModel(temp.Master); var entity = new PURSysEntities(); var BA01B = entity.BA01B.FirstOrDefault(x => x.BA01B_ID == model.Master.BA01B_ID); if (BA01B == null) { BA01B = new BA01B(); } var BA01A = entity.BA01A.FirstOrDefault(x => x.BA01A_ID == model.Master.BA01A_ID); var dataCollection = new List <ERP_V2.ViewModels.TR01.TR01BViewModel>(); foreach (var item in temp.DetaiList) { dataCollection.Add(new ERP_V2.ViewModels.TR01.TR01BViewModel(item)); } model.DetailList = dataCollection; var companyName = model.Master.CPN_NM; decimal taxRate = 1; if (model.Master.TAX_RT.HasValue) { taxRate = decimal.Parse(model.Master.TAX_RT.Value.ToString()); } var reportModel = new Reports.TR01.TR01ReportModel() { Company = model.Master.CPN_NM, Provider = BA01A.INC_NM, Contact = BA01B.CNT_NM, TelNo = BA01B.TEL_NO, Address = BA01A.ADD_DR, OrderNO = model.Master.PUR_NO, Date = model.Master.DtPUR_DT.Value.ToString("yyyy/MM/dd"), FAX = BA01A.FAX_NO, TaxRate = taxRate }; reportModel.Unit = entity.BA03A.FirstOrDefault(x => x.BA03A_ID == model.Master.BA03A_ID).CUR_NM; reportModel.DetaiList = new List <Reports.TR01.Detail>(); int i = 1; decimal total = 0; foreach (var item in dataCollection) { var BA02A = entity.BA02A.FirstOrDefault(x => x.BA02A_ID == item.BA02A_ID); var detailItem = new Reports.TR01.Detail() { ItemNO = item.ITM_NM, Spec = BA02A.ITM_SP, Date = model.Master.DtEXP_DT.Value.ToString("yyyy/MM/dd"), Qty = item.PUR_QT, Unit = BA02A.UNT_NM, Price = item.PUR_PR.Value, TotalPrice = item.PUR_QT * item.PUR_PR.Value, RelativeNO = item.REL_NO, SeqNO = i, REM = item.REM_MM }; total += detailItem.TotalPrice; reportModel.DetaiList.Add(detailItem); i++; } var result = new List <ERP_V2.Reports.TR01.TR01ReportModel>(); reportModel.Price = total;//未稅 reportModel.TotalSummaryPrice = total * taxRate; if (UserInfo.LanguageType == Utility.Language.Type.VN) { } reportModel.TotalSummaryPrice = Math.Round(reportModel.TotalSummaryPrice, 0); var str = reportModel.TotalSummaryPrice.ToString("G29"); if (str == "0") { reportModel.MoneyInChinese = ""; } else { reportModel.MoneyInChinese = " " + ConvertVN(str); //EastAsiaNumericFormatter.FormatWithCulture("L", total, null, new CultureInfo("zh-TW")); } // var tempNum = EastAsiaNumericFormatter.FormatWithCulture("L", 50500, null, new CultureInfo("zh-TW")); result.Add(reportModel); System.Web.HttpContext.Current.Session["tempData"] = result; return(View()); }