public ActionResult Invoice(InvoiceViewModel invoiceModel, HttpPostedFileBase file, FormCollection fc) { BCBSClient client = new BCBSClient(); //ModelState.Where(m => m.Key == "CustomerCode").FirstOrDefault().Value.Errors.Clear(); //if (ModelState.IsValid) //{ long Id = 0; string fname = string.Empty; if (file != null && file.ContentLength > 0) { // extract only the fielname var fileName = Path.GetFileName(file.FileName); string ext = Path.GetExtension(file.FileName); Guid g = Guid.NewGuid(); fname = g.ToString() + ext; // store the file inside ~/UploadDocuments/uploads folder var path = Path.Combine(Server.MapPath("~/UploadDocuments/uploads"), fname); file.SaveAs(path); invoiceModel.SupportingDocuments = fname; } //string csv = string.Empty; Id = client.InsertCustomerInvoice(invoiceModel.InvoiceNumber, invoiceModel.CustomerId, invoiceModel.InvoiceDate, invoiceModel.PrepareBy, invoiceModel.PrepareByExt, invoiceModel.AuthorizedBy, invoiceModel.AuthorizedByExt, invoiceModel.Division, invoiceModel.IsDeffered, invoiceModel.DefferedAccount, invoiceModel.FromDate, invoiceModel.ToDate, invoiceModel.SpecialInstuction, invoiceModel.SupportingDocuments, invoiceModel.TotalAmount); if (Id > 0) { //csv += "Invoice Number," + invoiceModel.InvoiceNumber + "\n"; //csv += "Invoice Date," + invoiceModel.InvoiceDate.ToString("MM/dd/yyyy") + "\n"; //csv += "Prepared by," + invoiceModel.PrepareBy + ", Authorized By," + invoiceModel.AuthorizedBy + "\n"; //csv += "Devision," + invoiceModel.Division + "\n\n"; //csv += "Customer Name," + invoiceModel.Customer.Name + "\n"; //csv += "Address\n"; //csv += invoiceModel.Customer.CustomerAddress + " " + invoiceModel.Customer.City + " " + invoiceModel.Customer.State + " " + invoiceModel.Customer.PostalCode + "\n"; //csv += "Contact Name," + invoiceModel.Customer.FirstName + " " + invoiceModel.Customer.LastName + "\n"; //csv += "Phone," + invoiceModel.Customer.Phone + "\n\n"; SBFEmailViewModel sbfemail = new SBFEmailViewModel(); //mailer.SBF(); string fcActivities = fc["Activities"].ToString(); List<string> activities = new List<string>(); if (!string.IsNullOrEmpty(fcActivities)) { bool isbilled = client.SetActivityBilled(fcActivities); if (isbilled) { var activityIds = fcActivities.Split(','); foreach (var x in activityIds) { if (!string.IsNullOrEmpty(x)) { long activityId = Convert.ToInt64(x); long sbfActivityId = client.InsertSBFActivity(Id, activityId); if (sbfActivityId > 0) { activities.Add(activityId.ToString()); continue; } else { break; } } } } } if (activities != null && activities.Count > 0) { string ids = string.Join(",", activities.ToArray()); string result = client.GetActivitiesByActivityIds(ids); List<ActivityListModel> activity = JsonConvert.DeserializeObject<List<ActivityListModel>>(result); if (sbfemail.ActivityList == null) { //csv += "Contract -Activity\n\n"; //csv += "Project Name,Service Type,From Date,End Date,Charges,Value,Amount\n"; sbfemail.ActivityList = new List<ActivityListModel>(); } if (activity != null) { foreach (ActivityListModel x in activity) { string charge = string.Empty; if (x.Charges == true) { charge = "Expense"; } else { charge = "Revenue"; } string estimate = string.Empty; if (x.Estimate == true) { estimate = "Real"; } else { estimate = "Estimate"; } //csv += x.ProjectName + "," + x.Service + "," + x.FromDate.ToString("MM/dd/yyyy") + "," + x.EndDate.ToString("MM/dd/yyyy") + "," + charge + "," + estimate + "," + x.Amount + "\n"; } //csv += ",,,,,Total," + invoiceModel.TotalAmount + "\n\n"; //if (invoiceModel.IsDeffered == true) //{ //csv += "Deffered Account," + invoiceModel.DefferedAccount + "\n"; //} //csv += "From Date," + invoiceModel.FromDate.ToString("MM/dd/yyyy") + ",,End Date," + invoiceModel.ToDate.ToString("MM/dd/yyyy") + "\n"; sbfemail.ActivityList = activity; } } IUserMailer mailer = new UserMailer(); sbfemail.Invoice = invoiceModel; string CustomerData = client.GetcustomerById(invoiceModel.CustomerId); if (!string.IsNullOrEmpty(CustomerData)) { sbfemail.Customer = JsonConvert.DeserializeObject<CustomerModel>(CustomerData); } string ContractData = client.GetcontractById(invoiceModel.ContractId); ContractModel contract = new ContractModel(); if (!string.IsNullOrEmpty(ContractData)) { contract = JsonConvert.DeserializeObject<ContractModel>(ContractData); sbfemail.Contract = contract; } string fileName = "SBF_" + sbfemail.Invoice.InvoiceNumber + "_" + DateTime.Now.ToString("MM_dd_yyyy_HH_mm_ss"); string excelFileName = CreatExcel(sbfemail, fileName); mailer.SBF(sbfemail, file, "SBF Invoice - BCBS Acc Sys").Send(); if (!string.IsNullOrEmpty(excelFileName)) { string path = Path.Combine(Server.MapPath("~/UploadDocuments/uploads/xlsx"), excelFileName); return File(path, "text/csv", excelFileName); } else { TempData["Message"] = "Customer Invoice generated successfully..!"; //string fileName = "SBF_" + invoiceModel.InvoiceNumber + "_" + DateTime.Now.ToString("MM-dd-yyyy"); // return RedirectToAction("Index", "Customer"); } } else { string fullPath = Request.MapPath("~/UploadDocuments/uploads/" + fname); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } TempData["Error"] = "Customer Invoice generation failed..!"; return View(invoiceModel); } ModelState.Clear(); //} //else //{ // string customerlist = client.GetcustomerList(); // if (!string.IsNullOrEmpty(customerlist)) // { // ViewBag.Customers = JsonConvert.DeserializeObject<List<CustomerModel>>(customerlist).Select(x => new { x.Id, x.Name }); // } // else // { // ViewBag.Customers = ""; // } // return View(invoiceModel); //} }
public ActionResult GenerateInvoice(string Id) { InvoiceViewModel invoiceModel = new InvoiceViewModel(); invoiceModel.Customer = new CustomerModel(); invoiceModel.FromDate = DateTime.Now; invoiceModel.ToDate = DateTime.Now; invoiceModel.InvoiceDate = DateTime.Now; if (!string.IsNullOrEmpty(Id)) { BCBSClient client = new BCBSClient(); string CustomerData = client.GetcustomerById(Convert.ToInt64(Id)); if (!string.IsNullOrEmpty(CustomerData)) { CustomerModel Customer = new CustomerModel(); Customer = JsonConvert.DeserializeObject<CustomerModel>(CustomerData); if (Customer != null) { invoiceModel.Customer = Customer; } } } return PartialView(invoiceModel); }
public string CreateAcknowledgementExcel(AcknowledgementModel avm, string fileName, string removedProjects, string removedServices) { string path = Path.Combine(Server.MapPath("~/UploadDocuments/Acknowledgements")); DirectoryInfo d = new DirectoryInfo(@path); if (d.Exists) { FileInfo newFile = new FileInfo(d.FullName + @"\" + fileName + ".xlsx"); if (newFile.Exists) { newFile.Delete(); // ensures we create a new workbook newFile = new FileInfo(d.FullName + @"\" + fileName + ".xlsx"); } using (ExcelPackage package = new ExcelPackage(newFile)) { // add a new worksheet to the empty workbook string titleHeader = string.Empty; titleHeader = "BILLING ACKNOWLEDGEMENT FORM"; ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(titleHeader); string imagepath = Path.Combine(Server.MapPath("~/Images/"), "bcbs-excel.png"); Image logo = Image.FromFile(imagepath); int a = 1; //worksheet.Row(a * 5).Height = 39.00D; var picture = worksheet.Drawings.AddPicture(a.ToString(), logo); picture.From.Column = 6; picture.From.Row = a; picture.SetSize(130, 100); //Add the headers worksheet.Column(1).Width = 5; worksheet.Column(2).Width = 10; worksheet.Column(3).Width = 10; worksheet.Column(4).Width = 10; worksheet.Column(5).Width = 10; worksheet.Column(6).Width = 10; CustomerModel customer = new CustomerModel(); BCBSClient client = new BCBSClient(); customer = JsonConvert.DeserializeObject<CustomerModel>(client.GetcustomerById(avm.CustomerId)); worksheet.Cells["B1"].Value = titleHeader; worksheet.Cells["B3"].Value = "PLAN/ORGANIZATION:"; worksheet.Cells["c3"].Value = customer.Name; worksheet.Cells["C3"].Style.Border.BorderAround(ExcelBorderStyle.Medium, Color.Black); //worksheet.Cells["F4"].Value = "(will be provided by Finance)"; worksheet.Cells["B5"].Value = "ATTENTION:"; worksheet.Cells["C5"].Value = customer.FirstName + " " + customer.LastName; worksheet.Cells["C5"].Style.Border.BorderAround(ExcelBorderStyle.Medium, Color.Black); worksheet.Cells["B7"].Value = "ADDRESS:"; worksheet.Cells["C7"].Value = customer.CustomerAddress; //worksheet.Cells["C7"].Style.Border.BorderAround(ExcelBorderStyle.Medium, Color.Black); worksheet.Cells["C8"].Value = customer.City; //worksheet.Cells["C8"].Style.Border.BorderAround(ExcelBorderStyle.Medium, Color.Black); worksheet.Cells["C9"].Value = customer.State + " " + customer.Country + " " + customer.PostalCode; //worksheet.Cells["C9"].Style.Border.BorderAround(ExcelBorderStyle.Medium, Color.Black); int last = 11; int tableinit = 11; int tableend = 0; for (int i = 0; i < avm.Projects.Count(); i++) { List<string> removedProjectList = new List<string>(); if (!string.IsNullOrEmpty(removedProjects)) { removedProjectList = removedProjects.Split(',').ToList(); } if (removedProjectList.Count > 0) { var r = removedProjectList.Where(x => x.Equals(avm.Projects[i].Project.Id + "@" + i)); if (r != null) { if (r.Count() > 0) { continue; } } } last++; worksheet.Cells["B" + last].Value = avm.Projects[i].Project.Name; tableinit = last; int totalinit = 0; int totalend = 0; for (int j = 0; j < avm.Projects[i].Services.Count; j++) { last++; if (j == 0) { worksheet.Cells["C" + last].Value = "Service Name"; worksheet.Cells["D" + last].Value = "Volume"; worksheet.Cells["E" + last].Value = "Rate"; worksheet.Cells["F" + last].Value = "Total"; last++; totalinit = last; } List<string> removedServiceList = new List<string>(); if (!string.IsNullOrEmpty(removedServices)) { removedServiceList = removedServices.Split(',').ToList(); } var r = removedServiceList.Where(x => x.Equals(i + "_" + j)); if (r != null) { if (r.Count() > 0) { last--; continue; } } worksheet.Cells["C" + last].Value = avm.Projects[i].Services[j].Name; worksheet.Cells["D" + last].Value = avm.Projects[i].Services[j].NewVolume; if (avm.Projects[i].Services[j].FeesType == "Transaction") { worksheet.Cells["E" + last].Value = avm.Projects[i].Services[j].Total.ToString("C") + " / " + avm.Projects[i].Services[j].NewVolume + " " + avm.Projects[i].Services[j].FeesType;//avm.Projects[i].Services[j].Volume; } else { worksheet.Cells["E" + last].Value = avm.Projects[i].Services[j].Total.ToString("C") + "/ " + avm.Projects[i].Services[j].FeesType; } worksheet.Cells["F" + last].Value = avm.Projects[i].Services[j].Total; worksheet.Cells["F" + last].Style.Numberformat.Format = "$#,###0.00"; } totalend = last; tableend = last; last++; worksheet.Cells["F" + last].Formula = "=SUM(F" + totalinit + ":F" + totalend + ")"; worksheet.Cells["F" + last].Calculate(); worksheet.Cells["F" + last].Style.Numberformat.Format = "$#,###0.00"; last++; using (var range = worksheet.Cells[tableinit, 2, tableend, 6]) { range.Style.Border.BorderAround(ExcelBorderStyle.Medium, Color.Black); } } package.Save(); } return newFile.Name; } else { return null; } }
public ActionResult Edit(long id) { CustomerModel Customer = new CustomerModel(); if (id > 0) { BCBSClient client = new BCBSClient(); string CustomerData = client.GetcustomerById(id); if (!string.IsNullOrEmpty(CustomerData)) { Customer = JsonConvert.DeserializeObject<CustomerModel>(CustomerData); } else { TempData["Error"] = "Requested customer not available!!"; return RedirectToAction("Index", "Customer"); } } return View(Customer); }
public ActionResult SBFEmailView(SBFEmailViewModel sbf) { BCBSClient client = new BCBSClient(); sbf.ActivityList = new List<ActivityListModel>(); string result = client.GetActivitiesByContractIds("23,24"); List<ActivityListModel> activity = JsonConvert.DeserializeObject<List<ActivityListModel>>(result); sbf.ActivityList = activity; string CustomerData = client.GetcustomerById(4); if (!string.IsNullOrEmpty(CustomerData)) { sbf.Customer = JsonConvert.DeserializeObject<CustomerModel>(CustomerData); } InvoiceViewModel ivm = new InvoiceViewModel(); ivm.AuthorizedBy = "Paatrick Egan"; ivm.AuthorizedByExt = "5497"; ivm.ContractId = 12; ivm.CustomerId = 4; ivm.FromDate = DateTime.Now; ivm.ToDate = DateTime.Now.AddDays(2); ivm.TotalAmount = 350.00; sbf.Invoice = ivm; string ContractData = client.GetcontractById(24); ContractModel contract = new ContractModel(); if (!string.IsNullOrEmpty(ContractData)) { contract = JsonConvert.DeserializeObject<ContractModel>(ContractData); sbf.Contract = contract; } return View(sbf); }