//without invoice date and number private async Task <CLayer.Invoice> MakeNewInvoice(long offlineBookingId) { CLayer.Invoice data = new CLayer.Invoice(); data.OfflineBookingId = offlineBookingId; // data.InvoiceDate = DateTime.Today; CLayer.OfflineBooking ob = BLayer.OfflineBooking.GetAllDetailsById(offlineBookingId); string num = BLayer.Settings.GetValue(CLayer.Settings.INVOICE_DUE_DAYS); int i = 0; int.TryParse(num, out i); //karthikms added code and comment //CLayer.InvoiceNumberData inv = BLayer.NumberGenerator.GetInvoiceNumber(); data.DueDate = ob.CheckOut.AddDays(i); data.Status = (int)CLayer.ObjectStatus.InvoiceStatus.Saved; data.InvoiceType = (int)CLayer.ObjectStatus.InvoiceType.Invoice; //karthikms added code and comment //data.InvoiceNumber = inv.InvoiceNumber.ToString(); data.InvoiceId = BLayer.Invoice.Save(data); data = BLayer.Invoice.GetInvoiceByOfflineBooking(offlineBookingId); data = await MessageFromHtml(offlineBookingId); return(data); }
public ActionResult MailContent(long obId) { CLayer.Invoice data = BLayer.Invoice.GetInvoiceByOfflineBooking(obId); if (data == null) { data = new CLayer.Invoice(); data.OfflineBookingId = obId; /// data.InvoiceDate = DateTime.Today; data.DueDate = DateTime.Today.AddDays(10); data.InvoiceType = (int)CLayer.ObjectStatus.InvoiceType.Invoice; BLayer.Invoice.Save(data); //data = BLayer.Invoice.GetInvoiceByOfflineBooking(offId); //data = await MessageFromHtml(offId); } Areas.Admin.Models.Invoice inv = new Areas.Admin.Models.Invoice(); inv.InvoiceId = data.InvoiceId; inv.OfflineBookingId = data.OfflineBookingId; inv.IsMailed = (data.MailedDate <= DateTime.Today); inv.HtmlSection1 = data.HtmlSection1; inv.HtmlSection2 = data.HtmlSection2; inv.HtmlSection3 = data.HtmlSection3; CLayer.OfflineBooking dd = BLayer.OfflineBooking.GetAllCustomerDetails(obId); if (dd != null) { inv.CustomerName = dd.CustomerName; } return(View("Mail", inv)); }
public ActionResult CustomerInvoicePDF(long obId) { Areas.Admin.Models.Invoice inv = new Areas.Admin.Models.Invoice(); try { CLayer.Invoice data = BLayer.Invoice.GetInvoiceByOfflineBooking(obId); if (data == null) { data = new CLayer.Invoice(); data.OfflineBookingId = obId; // data.InvoiceDate = DateTime.Today; data.DueDate = DateTime.Today.AddDays(10); data.InvoiceType = (int)CLayer.ObjectStatus.InvoiceType.Invoice; BLayer.Invoice.Save(data); } inv.InvoiceId = data.InvoiceId; inv.OfflineBookingId = data.OfflineBookingId; inv.IsMailed = (data.MailedDate <= DateTime.Today); inv.HtmlSection1 = data.HtmlSection1; inv.HtmlSection2 = data.HtmlSection2; inv.HtmlSection3 = data.HtmlSection3; } catch (Exception ex) { Common.LogHandler.HandleError(ex); } return(new ViewAsPdf("CustomerInvoicePDF", inv)); }
private async Task <CLayer.Invoice> MessageFromHtml(long offid) { string url = ConfigurationManager.AppSettings.Get("InvoiceLink") + offid.ToString(); System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); string mainHtml = await client.GetStringAsync(url); string html1, html2, html3, html4; int i, len; html1 = mainHtml; html1 = html1.Substring(html1.IndexOf("<!--#FIRSTROW_START-->")); len = html1.Length; i = html1.LastIndexOf("<!--#FIRSTROW_END-->"); html1 = html1.Substring(0, len - (len - i)); html2 = mainHtml; html2 = html2.Substring(html2.IndexOf("<!--#SECONDROW_START-->")); len = html2.Length; i = html2.LastIndexOf("<!--#SECONDROW_END-->"); html2 = html2.Substring(0, len - (len - i)); html3 = mainHtml; html3 = html3.Substring(html3.IndexOf("<!--#THIRDROW_START-->")); len = html3.Length; i = html3.LastIndexOf("<!--#THIRDROW_END-->"); html3 = html3.Substring(0, len - (len - i)); CLayer.Invoice data = BLayer.Invoice.GetInvoiceByOfflineBooking(offid); if (data == null) { return(null); } data.HtmlSection1 = html1; data.HtmlSection2 = html2; data.HtmlSection3 = html3; int OfflineBookingType = BLayer.OfflineBooking.GetBookingType(offid); if (OfflineBookingType == (int)CLayer.ObjectStatus.OfflineBookingType.Direct) { html4 = mainHtml; html4 = html4.Substring(html4.IndexOf("<!--#FOURTHROW_START-->")); len = html4.Length; i = html4.LastIndexOf("<!--#FOURTHROW_END-->"); html4 = html4.Substring(0, len - (len - i)); data.HtmlSection4 = html4; } else { data.HtmlSection4 = ""; } BLayer.Invoice.Save(data); return(data); }
public ActionResult MailContent(long obId) { CLayer.Invoice data = BLayer.Invoice.GetInvoiceByOfflineBooking(obId); if (data == null) { data = new CLayer.Invoice(); data.OfflineBookingId = obId; data.InvoiceDate = DateTime.Today; data.DueDate = DateTime.Today.AddDays(10); data.InvoiceType = (int)CLayer.ObjectStatus.InvoiceType.Invoice; BLayer.Invoice.Save(data); //data = BLayer.Invoice.GetInvoiceByOfflineBooking(offId); //data = await MessageFromHtml(offId); } Models.Invoice inv = new Models.Invoice(); inv.InvoiceId = data.InvoiceId; inv.InvoiceNumber = data.InvoiceNumber; inv.OfflineBookingId = data.OfflineBookingId; inv.IsMailed = (data.MailedDate <= DateTime.Today); inv.HtmlSection1 = data.HtmlSection1; inv.HtmlSection2 = data.HtmlSection2; inv.HtmlSection3 = data.HtmlSection3; return(View("Mail", inv)); }
public CLayer.Invoice GetInvoice(long invoiceId) { string sql = "Select * from Invoices Where InvoiceId=" + invoiceId.ToString(); DataTable dt = Connection.GetSQLTable(sql); CLayer.Invoice data = null; if (dt.Rows.Count == 0) { return(data); } data = new CLayer.Invoice(); DataRow dr = dt.Rows[0]; data.InvoiceId = Connection.ToLong(dr["InvoiceId"]); data.InvoiceNumber = Connection.ToString(dr["InvoiceNumber"]); data.Discounts = Connection.ToDouble(dr["Discounts"]); data.DueDate = Connection.ToDate(dr["DueDate"]); data.HtmlSection1 = Connection.ToString(dr["HtmlSection1"]); data.HtmlSection2 = Connection.ToString(dr["HtmlSection2"]); data.HtmlSection3 = Connection.ToString(dr["HtmlSection3"]); data.InvoiceDate = Connection.ToDate(dr["InvoiceDate"]); data.InvoiceType = Connection.ToInteger(dr["InvoiceType"]); data.MailedDate = Connection.ToDate(dr["MailedDate"]); data.OfflineBookingId = Connection.ToLong(dr["OfflineBookingId"]); data.Others = Connection.ToDouble(dr["Others"]); data.Reimbursements = Connection.ToDouble(dr["Reimbursements"]); data.Status = Connection.ToInteger(dr["Status"]); data.ToAddress = Connection.ToString(dr["ToAddress"]); return(data); }
public long GDSSave(CLayer.Invoice data) { List <DataPlug.Parameter> param = new List <DataPlug.Parameter>(); param.Add(Connection.GetParameter("pInvoiceId", DataPlug.DataType._BigInt, data.InvoiceId)); param.Add(Connection.GetParameter("pBookingId", DataPlug.DataType._BigInt, data.BookingId)); param.Add(Connection.GetParameter("pToAddress", DataPlug.DataType._Varchar, data.ToAddress)); param.Add(Connection.GetParameter("pInvoiceDate", DataPlug.DataType._Date, data.InvoiceDate)); param.Add(Connection.GetParameter("pDueDate", DataPlug.DataType._Date, data.DueDate)); param.Add(Connection.GetParameter("pMailDate", DataPlug.DataType._Date, data.MailedDate)); param.Add(Connection.GetParameter("pReimbursements", DataPlug.DataType._Decimal, data.Reimbursements)); param.Add(Connection.GetParameter("pDiscounts", DataPlug.DataType._Decimal, data.Discounts)); param.Add(Connection.GetParameter("pOthers", DataPlug.DataType._Decimal, data.Others)); param.Add(Connection.GetParameter("pInvoiceType", DataPlug.DataType._Int, data.InvoiceType)); param.Add(Connection.GetParameter("pInvoiceNumber", DataPlug.DataType._Varchar, data.InvoiceNumber)); param.Add(Connection.GetParameter("pStatus", DataPlug.DataType._Int, data.Status)); param.Add(Connection.GetParameter("pHtmlSection1", DataPlug.DataType._Text, data.HtmlSection1)); param.Add(Connection.GetParameter("pHtmlSection2", DataPlug.DataType._Text, data.HtmlSection2)); param.Add(Connection.GetParameter("pHtmlSection3", DataPlug.DataType._Text, data.HtmlSection3)); param.Add(Connection.GetParameter("pHtmlSection4", DataPlug.DataType._Text, data.HtmlSection4)); object obj = Connection.ExecuteQueryScalar("GDSInvoice_Save", param); return(Connection.ToLong(obj)); }
public long UpdateGDSInvoiceByBookingID(CLayer.Invoice data) { List <DataPlug.Parameter> param = new List <DataPlug.Parameter>(); param.Add(Connection.GetParameter("pInvoiceId", DataPlug.DataType._BigInt, data.InvoiceId)); param.Add(Connection.GetParameter("pBookingId", DataPlug.DataType._BigInt, data.BookingId)); param.Add(Connection.GetParameter("pInvoiceDate", DataPlug.DataType._Date, data.InvoiceDate)); param.Add(Connection.GetParameter("pInvoiceNumber", DataPlug.DataType._Varchar, data.InvoiceNumber)); object obj = Connection.ExecuteQueryScalar("GDSInvoice_Updateinvoicenumber", param); return(Connection.ToLong(obj)); }
public async Task <ActionResult> ReportPdf(long obId) { CLayer.Invoice data = BLayer.Invoice.GetProformaByOfflineBooking(obId); if (data == null) { data = new CLayer.Invoice(); data.OfflineBookingId = obId; data.InvoiceDate = DateTime.Today; data.DueDate = DateTime.Today.AddDays(10); data.InvoiceType = (int)CLayer.ObjectStatus.InvoiceType.Proforma; BLayer.Invoice.Save(data); //data = BLayer.Invoice.GetProformaByOfflineBooking(offId); //data = await MessageFromHtml(offId); } Models.Invoice inv = new Models.Invoice(); inv.InvoiceId = data.InvoiceId; inv.OfflineBookingId = data.OfflineBookingId; inv.IsMailed = (data.MailedDate <= DateTime.Today); string url = ConfigurationManager.AppSettings.Get("ProformaLink") + obId.ToString(); System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); string mainHtml = await client.GetStringAsync(url); string html2; int i, len; // html2 = mainHtml; // html2 = html2.Substring(html2.IndexOf("<!--#SECONDROW_START-->")); // len = html2.Length; //i = html2.LastIndexOf("<!--#SECONDROW_END-->"); //html2 = html2.Substring(0, len - (len - i)); if (data.HtmlSection2 != null && data.HtmlSection2 != "") { inv.HtmlSection2 = data.HtmlSection2; } else { // inv.HtmlSection2 = html2; } inv.HtmlSection1 = data.HtmlSection1; inv.HtmlSection3 = data.HtmlSection3; return(View("Preview", inv)); }
private async Task <CLayer.Invoice> MakeNewInvoice(long BookingId, long InvID = 0) { CLayer.Invoice data = new CLayer.Invoice(); data.BookingId = BookingId; InventoryAPIType = BLayer.Property.GetInventoryAPITypeId(BLayer.Bookings.GetPropertyId(BookingId)); // data.InvoiceDate = DateTime.Today; List <CLayer.BookingItem> ob = new List <CLayer.BookingItem>(); if (InventoryAPIType == (int)CLayer.ObjectStatus.InventoryAPIType.Amadeus) { ob = BLayer.BookingItem.GetAllDetails(BookingId, true); } else { ob = BLayer.BookingItem.GetAllDetails(BookingId); } string num = BLayer.Settings.GetValue(CLayer.Settings.INVOICE_DUE_DAYS); int i = 0; int.TryParse(num, out i); data.DueDate = ob[0].CheckOut.AddDays(i); data.Status = (int)CLayer.ObjectStatus.InvoiceStatus.Saved; data.InvoiceType = (int)CLayer.ObjectStatus.InvoiceType.Invoice; if (InventoryAPIType == (int)CLayer.ObjectStatus.InventoryAPIType.Amadeus) { data.InvoiceNumber = Convert.ToString(TempData["InvoiceNumber"]); data.InvoiceDate = Convert.ToDateTime(TempData["InvoiceDate"]); data.InvoiceId = InvID; data.InvoiceId = BLayer.Invoice.GDSSave(data); } else { data.InvoiceId = BLayer.Invoice.Save(data); } if (InventoryAPIType == (int)CLayer.ObjectStatus.InventoryAPIType.Amadeus) { data = BLayer.Invoice.GetGDSInvoiceByBookingID(BookingId); } else { data = BLayer.Invoice.GetInvoiceByOfflineBooking(BookingId); } data = await MessageFromHtml(BookingId); return(data); }
public async Task <bool> DeleteOfflineSavedData(long OfflineBookingId) { try { if (User.IsInRole("Administrator")) { BLayer.OfflineBooking.DeleteOfflineBooking(OfflineBookingId); return(true); } else { if (BLayer.OfflineBooking.CheckOfflineBookingDeleteorNot(OfflineBookingId)) { CLayer.Invoice data = BLayer.Invoice.GetInvoiceByOfflineBooking(OfflineBookingId); if (data != null) { if (data.Status != (int)CLayer.ObjectStatus.InvoiceStatus.Submitted) { BLayer.OfflineBooking.DeleteOfflineBooking(OfflineBookingId); return(true); } else { await BookingDeleteRequestAlertMail(OfflineBookingId); return(false); } } else { BLayer.OfflineBooking.DeleteOfflineBooking(OfflineBookingId); return(true); } } else { await BookingDeleteRequestAlertMail(OfflineBookingId); return(false); } } } catch (Exception ex) { Common.LogHandler.HandleError(ex); } return(true); }
public async Task <ActionResult> Edit(long obid) { CLayer.Invoice data = BLayer.Invoice.GetProformaByOfflineBooking(obid); if (data != null) { if (data.HtmlSection1 == "" || data.HtmlSection2 == "") { data = await MessageFromHtml(obid); } } else { data = new CLayer.Invoice(); data.OfflineBookingId = obid; data.InvoiceDate = DateTime.Today; data.DueDate = DateTime.Today.AddDays(10); data.InvoiceType = (int)CLayer.ObjectStatus.InvoiceType.Proforma; BLayer.Invoice.Save(data); // data = BLayer.Invoice.(obid); data = await MessageFromHtml(obid); } Models.Invoice inv = new Models.Invoice(); inv.InvoiceId = data.InvoiceId; DateTime dt = DateTime.Today; if (data.InvoiceDate != DateTime.MinValue) { inv.InvoiceDate = data.InvoiceDate.ToString("dd/MM/yyyy"); } string u = User.Identity.GetUserId(); long id = 0; long.TryParse(u, out id); if (BLayer.User.GetRole(id) != CLayer.Role.Roles.Administrator) { inv.ShowText = 2; } inv.OfflineBookingId = data.OfflineBookingId; inv.IsMailed = (data.MailedDate <= DateTime.Today); inv.HtmlSection1 = data.HtmlSection1; inv.HtmlSection2 = data.HtmlSection2; inv.HtmlSection3 = data.HtmlSection3; inv.InvoiceNumber = data.InvoiceNumber; return(View("Edit", inv)); }
private async Task <CLayer.Invoice> MessageFromHtml(long offid) { string url = ConfigurationManager.AppSettings.Get("ProformaLink") + offid.ToString(); System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); string mainHtml = await client.GetStringAsync(url); string html1, html2, html3; int i, len; html1 = mainHtml; html1 = html1.Substring(html1.IndexOf("<!--#FIRSTROW_START-->")); len = html1.Length; i = html1.LastIndexOf("<!--#FIRSTROW_END-->"); html1 = html1.Substring(0, len - (len - i)); html2 = mainHtml; html2 = html2.Substring(html2.IndexOf("<!--#SECONDROW_START-->")); len = html2.Length; i = html2.LastIndexOf("<!--#SECONDROW_END-->"); html2 = html2.Substring(0, len - (len - i)); html3 = mainHtml; html3 = html3.Substring(html3.IndexOf("<!--#THIRDROW_START-->")); len = html3.Length; i = html3.LastIndexOf("<!--#THIRDROW_END-->"); html3 = html3.Substring(0, len - (len - i)); CLayer.Invoice data = BLayer.Invoice.GetProformaByOfflineBooking(offid); if (data == null) { return(null); } data.HtmlSection1 = html1; data.HtmlSection2 = html2; data.HtmlSection3 = html3; BLayer.Invoice.Save(data); return(data); }
public ActionResult InvoiceDigitalSignPDF(long obId) { string url = ConfigurationManager.AppSettings.Get("InvoicePDFPreview") + obId.ToString(); String pfxPath = ConfigurationManager.AppSettings.Get("PFXFileForInvoice"); string pfxpassword = ConfigurationManager.AppSettings.Get("PFXFileForInvoiceKey"); // PdfDocument pdf = new PdfDocument(); CLayer.Invoice data = BLayer.Invoice.GetInvoiceByOfflineBooking(obId); string filename = ""; if (data.InvoiceNumber == "") { filename = "Invoice_" + data.InvoiceId.ToString() + ".pdf"; } else { filename = "Invoice_" + data.InvoiceNumber + ".pdf"; } string filepath = Server.MapPath(INVOICE_FOLDER) + filename; //var thread = new Thread(() => pdf.LoadFromHTML(url, false, false, false)); //thread.SetApartmentState(ApartmentState.STA); //thread.Start(); //thread.Join(); WebClient wc = new WebClient(); wc.DownloadFile(url, filepath); // pdf.SaveToFile(filepath); //pdf.PageSettings.Margins.Top = 2.2F; //pdf.PageSettings.Margins.Left = 2.2F; //pdf.PageSettings.Margins.Right = 2.2F; // pdf.Close(); //pdf = new PdfDocument(); PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile(filepath); PdfCertificate digi = new PdfCertificate(pfxPath, pfxpassword); PdfSignature signature = new PdfSignature(pdf, pdf.Pages[0], digi, "Staybazar.com"); signature.ContactInfo = "Staybazar.com"; signature.Certificated = true; signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges; pdf.SaveToFile(filepath); pdf.Close(); byte[] filedata = System.IO.File.ReadAllBytes(filepath); string contentType = MimeMapping.GetMimeMapping(filepath); var cd = new System.Net.Mime.ContentDisposition { FileName = filename, Inline = true, }; Response.AppendHeader("Content-Disposition", cd.ToString()); return(File(filedata, contentType)); }
public async Task <ActionResult> InvoicePDF(long obId) { CLayer.Invoice data = BLayer.Invoice.GetInvoiceByOfflineBooking(obId); if (data == null) { data = await MakeNewInvoice(obId); //data = new CLayer.Invoice(); //data.OfflineBookingId = obId; //data.InvoiceDate = DateTime.Today; //data.DueDate = DateTime.Today.AddDays(10); //data.InvoiceType = (int)CLayer.ObjectStatus.InvoiceType.Invoice; //BLayer.Invoice.Save(data); //data = BLayer.Invoice.GetInvoiceByOfflineBooking(offId); //data = await MessageFromHtml(offId); } Models.Invoice inv = new Models.Invoice(); inv.InvoiceId = data.InvoiceId; inv.OfflineBookingId = data.OfflineBookingId; inv.IsMailed = (data.MailedDate <= DateTime.Today); string url = ConfigurationManager.AppSettings.Get("InvoiceLink") + obId.ToString(); System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); string mainHtml = await client.GetStringAsync(url); string html1, html2, html3, html4; int i, len; html1 = mainHtml; html1 = html1.Substring(html1.IndexOf("<!--#FIRSTROW_START-->")); len = html1.Length; i = html1.LastIndexOf("<!--#FIRSTROW_END-->"); html1 = html1.Substring(0, len - (len - i)); html2 = mainHtml; html2 = html2.Substring(html2.IndexOf("<!--#SECONDROW_START-->")); len = html2.Length; i = html2.LastIndexOf("<!--#SECONDROW_END-->"); html2 = html2.Substring(0, len - (len - i)); html3 = mainHtml; html3 = html3.Substring(html3.IndexOf("<!--#THIRDROW_START-->")); len = html3.Length; i = html3.LastIndexOf("<!--#THIRDROW_END-->"); html3 = html3.Substring(0, len - (len - i)); html4 = mainHtml; int idx = html4.IndexOf("<!--#FOURTHROW_START-->"); if (idx > -1) { html4 = html4.Substring(idx); len = html4.Length; i = html4.LastIndexOf("<!--#FOURTHROW_END-->"); html4 = html4.Substring(0, len - (len - i)); } else { html4 = ""; } if (data.HtmlSection2 != null && data.HtmlSection2 != "") { inv.HtmlSection1 = data.HtmlSection1; inv.HtmlSection2 = data.HtmlSection2; inv.HtmlSection3 = data.HtmlSection3; } else { inv.HtmlSection3 = html3; inv.HtmlSection2 = html2; inv.HtmlSection1 = html1; } int OfflineBookingType = BLayer.OfflineBooking.GetBookingType(obId); if (OfflineBookingType == (int)CLayer.ObjectStatus.OfflineBookingType.Direct) { if (data.HtmlSection4 != null && data.HtmlSection4 != "") { inv.HtmlSection4 = data.HtmlSection4; } else { inv.HtmlSection4 = html4; } } else { inv.HtmlSection4 = ""; } //inv.HtmlSection1 = data.HtmlSection1; //inv.HtmlSection2 = data.HtmlSection2; //inv.HtmlSection3 = data.HtmlSection3; return(new ViewAsPdf("PDF", inv)); }
public static long GDSSave(CLayer.Invoice data) { DataLayer.Invoice inv = new DataLayer.Invoice(); return(inv.GDSSave(data)); }
public async Task <ActionResult> Edit(long obid) { CLayer.Invoice data = BLayer.Invoice.GetInvoiceByOfflineBooking(obid); if (data != null) { int bookType = BLayer.OfflineBooking.GetBookingType(obid); if (bookType == (int)CLayer.ObjectStatus.OfflineBookingType.Direct) { if (data.HtmlSection1 == "" || data.HtmlSection2 == "" || data.HtmlSection4 == "") { data = await MessageFromHtml(obid); } } else { if (data.HtmlSection1 == "" || data.HtmlSection2 == "") { data = await MessageFromHtml(obid); } } } else { data = await MakeNewInvoice(obid); } Models.Invoice inv = new Models.Invoice(); inv.InvoiceId = data.InvoiceId; DateTime dt = DateTime.Today; if (data.InvoiceDate != DateTime.MinValue) { inv.InvoiceDate = data.InvoiceDate.ToString("dd/MM/yyyy"); } string u = User.Identity.GetUserId(); long id = 0; long.TryParse(u, out id); if (BLayer.User.GetRole(id) != CLayer.Role.Roles.Administrator) { inv.ShowText = 2; } inv.OfflineBookingId = data.OfflineBookingId; inv.IsMailed = (data.MailedDate <= DateTime.Today); inv.HtmlSection1 = data.HtmlSection1; inv.HtmlSection2 = data.HtmlSection2; inv.HtmlSection3 = data.HtmlSection3; if (obid > 0) { int OfflineBookingType = BLayer.OfflineBooking.GetBookingType(obid); if (OfflineBookingType == (int)CLayer.ObjectStatus.OfflineBookingType.Direct) { inv.HtmlSection4 = data.HtmlSection4; } else { inv.HtmlSection4 = ""; } } // inv.HtmlMid = data.HtmlSection2; inv.Status = data.Status; return(View(inv)); }
public static long UpdateGDSInvoiceByBookingID(CLayer.Invoice data) { DataLayer.Invoice inv = new DataLayer.Invoice(); return(inv.UpdateGDSInvoiceByBookingID(data)); }
public async Task <bool> SendMailInvoice(long OfflineBookingId) { string Filename = ""; // send mail to customer -- after save string msg = await GetMailBody(OfflineBookingId); Common.Mailer ml = new Common.Mailer(); System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); CLayer.OfflineBooking booking = BLayer.OfflineBooking.GetAllDetailsById(OfflineBookingId); CLayer.OfflineBooking customer = new CLayer.OfflineBooking(); int bookingType = BLayer.OfflineBooking.GetBookingType(OfflineBookingId); if (bookingType == (int)CLayer.ObjectStatus.OfflineBookingType.TAC) { //Mail To Supplier if (OfflineBookingId > 0) { CLayer.OfflineBooking OfflinePropertydata = BLayer.OfflineBooking.GetAllpropertyDetails(OfflineBookingId); if (OfflinePropertydata != null) { if (OfflinePropertydata.SupplierEmail != null && OfflinePropertydata.SupplierEmail != "") { mail.To.Add(OfflinePropertydata.SupplierEmail); } } } string BccEmailsforSup = BLayer.Settings.GetValue(CLayer.Settings.CC_SUPPLIERCOMMUNICATION); if (BccEmailsforSup.Trim() != "") { string[] emails = BccEmailsforSup.Split(','); for (int i = 0; i < emails.Length; ++i) { mail.CC.Add(emails[i]); } } } else { //Mail To Customer if (OfflineBookingId > 0) { customer = BLayer.OfflineBooking.GetAllCustomerDetails(OfflineBookingId); } if (customer != null) { if (customer.CustomerEmail != "") { mail.To.Add(customer.CustomerEmail); } } #region for corporate //for corporate admins //long userid = BLayer.User.GetUserId(customer.CustomerEmail); //if (userid > 0) //{ // CLayer.Role.Roles rle = BLayer.User.GetRole(userid); // if (rle == CLayer.Role.Roles.CorporateUser) // { // long cid = BLayer.B2B.GetCorporateIdOfUser(userid); // } //} //message = await Common.Mailer.MessageFromHtml(System.Configuration.ConfigurationManager.AppSettings.Get("CorpIntimation") + bookingId.ToString() + "&key=" + BLayer.Settings.GetValue(CLayer.Settings.PUBLIC_PAGE_LOCK)); //long cid = BLayer.B2B.GetCorporateIdOfUser(byUser.UserId); //if (cid > 0) //{ // string em = BLayer.User.GetEmail(cid); // if (em != null && em != "") // { // msg.CC.Add(em); // } //} //mail.To.Add(BLayer.Settings.GetValue(CLayer.Settings.SUPPORT_EMAIL)); #endregion string BccEmailsforcus = BLayer.Settings.GetValue(CLayer.Settings.CC_CUSTOMERCOMMUNICATION); if (BccEmailsforcus.Trim() != "") { string[] emails = BccEmailsforcus.Split(','); for (int i = 0; i < emails.Length; ++i) { mail.CC.Add(emails[i]); } } } CLayer.Invoice data = BLayer.Invoice.GetInvoiceByOfflineBooking(OfflineBookingId); if (data != null) { mail.Subject = "Invoice against Booking ID: " + booking.ConfirmationNumber + ", Invoice No. " + data.InvoiceNumber; } mail.Body = msg; mail.IsBodyHtml = true; //add atachment try { Areas.Admin.Models.Invoice inv = new Areas.Admin.Models.Invoice(); if (data != null) { inv.InvoiceId = data.InvoiceId; inv.OfflineBookingId = data.OfflineBookingId; inv.IsMailed = (data.MailedDate <= DateTime.Today); inv.HtmlSection1 = data.HtmlSection1; inv.HtmlSection2 = data.HtmlSection2; inv.HtmlSection3 = data.HtmlSection3; ViewAsPdf v = new ViewAsPdf("~/Areas/Admin/Views/ManageOfflineBooking/Mail.cshtml", inv) { PageMargins = new Rotativa.Options.Margins(1, 1, 1, 1), PageOrientation = Rotativa.Options.Orientation.Portrait, PageSize = Rotativa.Options.Size.Letter }; string newdirectory = "Files\\Temp\\" + inv.InvoiceId; if (!Directory.Exists(Server.MapPath("~") + "\\" + newdirectory)) { Directory.CreateDirectory(Server.MapPath("~") + "\\" + newdirectory); } Filename = Server.MapPath("~") + "\\" + newdirectory + "\\" + "Invoice_" + data.InvoiceNumber + ".pdf"; var byteArray = v.BuildPdf(ControllerContext); var fileStream = new FileStream(Filename, FileMode.Create, FileAccess.Write); fileStream.Write(byteArray, 0, byteArray.Length); fileStream.Close(); fileStream.Dispose(); // System.Net.Mail.Attachment attachment; Attachment attacht = new Attachment(Filename, MediaTypeNames.Application.Octet); mail.Attachments.Add(attacht); } } catch (Exception ex) { Common.LogHandler.HandleError(ex); } string AccountMail = BLayer.Settings.GetValue(CLayer.Settings.ACCOUNT_EMAILS); if (AccountMail != "") { string[] Accemails = AccountMail.Split(','); for (int i = 0; i < Accemails.Length; ++i) { mail.CC.Add(Accemails[i]); } } //send to ops mail string SalesPersonOPSMails = ""; if (OfflineBookingId > 0) { CLayer.OfflineBooking OffdataStaff = BLayer.OfflineBooking.GetAllDetailsById(OfflineBookingId); if (OffdataStaff != null) { if (OffdataStaff.SalesPersonId > 0) { CLayer.User usrstaff = BLayer.User.Get(OffdataStaff.SalesPersonId); if (usrstaff != null) { if (usrstaff.OPSEmail != null && usrstaff.OPSEmail != "") { SalesPersonOPSMails = usrstaff.OPSEmail; } } } } } if (SalesPersonOPSMails != "") { string CcOPSEmails = SalesPersonOPSMails.Trim(); if (CcOPSEmails != "") { string[] emails = CcOPSEmails.Split(','); for (int i = 0; i < emails.Length; ++i) { mail.CC.Add(emails[i]); } } } try { await ml.SendMailAsyncForBooking(mail, Common.Mailer.MailType.Reservation); } catch (Exception ex) { Common.LogHandler.HandleError(ex); } return(true); }
public async Task <ActionResult> SaveDetails(Models.Invoice data) { CLayer.Invoice sdata = null; if (data.OfflineBookingId > 0) { sdata = BLayer.Invoice.GetInvoiceByOfflineBooking(data.OfflineBookingId); } if (sdata == null) { sdata = await MakeNewInvoice(data.OfflineBookingId); } sdata.OfflineBookingId = data.OfflineBookingId; if (data.InvoiceId > 0) { sdata.InvoiceId = data.InvoiceId; } //DateTime dt = DateTime.Today; //DateTime.TryParse(data.InvoiceDate, out dt); //sdata.InvoiceDate = dt; sdata.HtmlSection1 = data.HtmlSection1; sdata.HtmlSection2 = data.HtmlSection2; sdata.HtmlSection3 = data.HtmlSection3; if (data.OfflineBookingId > 0) { int OfflineBookingType = BLayer.OfflineBooking.GetBookingType(data.OfflineBookingId); if (OfflineBookingType == (int)CLayer.ObjectStatus.OfflineBookingType.Direct) { sdata.HtmlSection4 = data.HtmlSection4; } else { sdata.HtmlSection4 = ""; } } //Common.Utils. // sdata.InvoiceDate = DateTime.Today; sdata.InvoiceType = (int)CLayer.ObjectStatus.InvoiceType.Invoice; if (data.OPType == 1) // Save button clicked { BLayer.Invoice.Save(sdata); // BLayer.Invoice.Save(sdata); } else if (data.OPType == 2) // Send mail button { int bookingType = BLayer.OfflineBooking.GetBookingType(data.OfflineBookingId); if (bookingType == (int)CLayer.ObjectStatus.OfflineBookingType.Regular) { data.OPType = 1; sdata.MailedDate = DateTime.Today; BLayer.Invoice.Save(sdata); if (sdata != null) { if (sdata.InvoiceId > 0) { BLayer.Invoice.SetMailedDate(sdata.InvoiceId, DateTime.Today); if (data.OfflineBookingId > 0) { // Send mail await SendMailInvoice(data.OfflineBookingId); } } } } } else if (data.OPType == 3) // { sdata = await MessageFromHtml(data.OfflineBookingId); BLayer.Invoice.Save(sdata); } else if (data.OPType == 4) //Approve Invoce details { //bool allowed = false; //if (BLayer.OfflineBooking.GetBookingType(sdata.OfflineBookingId) != (int)CLayer.ObjectStatus.OfflineBookingType.TAC) //{ // allowed = true; //} // if (allowed) // { int taxtype = BLayer.OfflineBooking.GetTaxType(sdata.OfflineBookingId); //Invoice Number if Exists CLayer.Invoice invdt = new CLayer.Invoice(); if (data.InvoiceId > 0) { invdt = BLayer.Invoice.GetInvoice(data.InvoiceId); if (invdt != null) { if (invdt.InvoiceNumber != null && invdt.InvoiceNumber != "") { sdata.InvoiceNumber = invdt.InvoiceNumber; } } } if (sdata.InvoiceNumber == null || sdata.InvoiceNumber == "") { CLayer.InvoiceNumberData inValue; if (taxtype == (int)CLayer.ObjectStatus.OfflineBookingTaxType.GST) { inValue = BLayer.NumberGenerator.GetGSTInvoiceNumber(sdata.OfflineBookingId); } else { inValue = BLayer.NumberGenerator.GetInvoiceNumber(); } if (inValue != null) { sdata.InvoiceNumber = inValue.InvoiceNumber; sdata.InvoiceDate = inValue.InvoiceDate; } } sdata.HtmlSection1 = sdata.HtmlSection1.Replace(INVOICE_NUMBER_LOC, sdata.InvoiceNumber.ToString()); sdata.HtmlSection1 = sdata.HtmlSection1.Replace(INVOICE_DATE_LOC, sdata.InvoiceDate.ToString("dd/MM/yyyy")); if (sdata.HtmlSection4 != "") { sdata.HtmlSection4 = sdata.HtmlSection4.Replace(INVOICE_NUMBER_LOC, sdata.InvoiceNumber.ToString()); sdata.HtmlSection4 = sdata.HtmlSection4.Replace(INVOICE_DATE_LOC, sdata.InvoiceDate.ToString("dd/MM/yyyy")); } sdata.Status = (int)CLayer.ObjectStatus.InvoiceStatus.Submitted; BLayer.Invoice.Save(sdata); if (data.OfflineBookingId > 0) { CLayer.OfflineBooking cus = BLayer.OfflineBooking.GetAllCustomerDetails(data.OfflineBookingId); //if (!BLayer.OfflineBooking.CanSendInvoiceMail(cus.CustomerName, cus.CustomerEmail)) //{ // // Send mail // await SendMailInvoice(data.OfflineBookingId); //} } // }// only if allowed } else if (data.OPType == 5) //reset Invoice details { sdata.HtmlSection1 = ""; sdata.HtmlSection2 = ""; sdata.HtmlSection4 = ""; BLayer.Invoice.Save(sdata); } return(RedirectToAction("Edit", new { obid = sdata.OfflineBookingId })); }
private async Task <CLayer.Invoice> MessageFromHtml(long offid) { // string url = ConfigurationManager.AppSettings.Get("GDSInvoiceLink") + offid.ToString(); string url = ConfigurationManager.AppSettings.Get("GDSInvoiceLink") + offid.ToString() + "&loggedInUser="******""; System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); string mainHtml = await client.GetStringAsync(url); string html1, html2, html3, html4; int i, len; html1 = mainHtml; html1 = html1.Substring(html1.IndexOf("<!--#FIRSTROW_START-->")); len = html1.Length; i = html1.LastIndexOf("<!--#FIRSTROW_END-->"); html1 = html1.Substring(0, len - (len - i)); html2 = mainHtml; html2 = html2.Substring(html2.IndexOf("<!--#SECONDROW_START-->")); len = html2.Length; i = html2.LastIndexOf("<!--#SECONDROW_END-->"); html2 = html2.Substring(0, len - (len - i)); html3 = mainHtml; html3 = html3.Substring(html3.IndexOf("<!--#THIRDROW_START-->")); len = html3.Length; i = html3.LastIndexOf("<!--#THIRDROW_END-->"); html3 = html3.Substring(0, len - (len - i)); InventoryAPIType = BLayer.Property.GetInventoryAPITypeId(BLayer.Bookings.GetPropertyId(offid)); CLayer.Invoice data = null; if (InventoryAPIType == (int)CLayer.ObjectStatus.InventoryAPIType.Amadeus) { data = BLayer.Invoice.GetGDSInvoiceByBookingID(offid); } else { data = BLayer.Invoice.GetInvoiceByOfflineBooking(offid); } if (data == null) { return(null); } data.HtmlSection1 = html1; data.HtmlSection2 = html2; data.HtmlSection3 = html3; int BookingType = BLayer.Bookings.GetBookingType(offid); BookingType = BookingType > 1 ? (int)CLayer.ObjectStatus.PropertyInventoryType.Offline : (int)CLayer.ObjectStatus.PropertyInventoryType.Online; if (BookingType == (int)CLayer.ObjectStatus.PropertyInventoryType.Online) { html4 = mainHtml; html4 = html4.Substring(html4.IndexOf("<!--#FOURTHROW_START-->")); len = html4.Length; i = html4.LastIndexOf("<!--#FOURTHROW_END-->"); html4 = html4.Substring(0, len - (len - i)); data.HtmlSection4 = html4; } else { data.HtmlSection4 = ""; } BLayer.Invoice.Save(data); return(data); }
public async Task <ActionResult> showInvoicePreviewonly(long obId) { CLayer.Invoice data = new CLayer.Invoice(); InventoryAPIType = BLayer.Property.GetInventoryAPITypeId(BLayer.Bookings.GetPropertyId(obId)); if (InventoryAPIType == (int)CLayer.ObjectStatus.InventoryAPIType.Amadeus) { data = BLayer.Invoice.GetGDSInvoiceByBookingID(obId); } else { data = BLayer.Invoice.GetInvoiceByOfflineBooking(obId); } //if (data != null) //{ // if (data.InvoiceNumber == null || data.InvoiceNumber == "") // { // string invNumber = BLayer.NumberGenerator.GetInvoiceNumber(); // CLayer.Invoice InvoiceNumber = new CLayer.Invoice(); // data.InvoiceNumber = invNumber; // BLayer.Invoice.Save(data); // } //} if (data == null) { //string invNumber = BLayer.NumberGenerator.GetInvoiceNumber(); //data = new CLayer.Invoice(); //data.OfflineBookingId = obId; //data.InvoiceNumber = invNumber; //data.InvoiceDate = DateTime.Today; //data.DueDate = DateTime.Today.AddDays(10); //data.InvoiceType = (int)CLayer.ObjectStatus.InvoiceType.Invoice; //BLayer.Invoice.Save(data); data = await MakeNewInvoice(obId); } string url = ConfigurationManager.AppSettings.Get("GDSInvoiceLink") + obId.ToString(); System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); string mainHtml = await client.GetStringAsync(url); string html1, html2, html3, html4; int i, len; html1 = mainHtml; html1 = html1.Substring(html1.IndexOf("<!--#FIRSTROW_START-->")); len = html1.Length; i = html1.LastIndexOf("<!--#FIRSTROW_END-->"); html1 = html1.Substring(0, len - (len - i)); html2 = mainHtml; html2 = html2.Substring(html2.IndexOf("<!--#SECONDROW_START-->")); len = html2.Length; i = html2.LastIndexOf("<!--#SECONDROW_END-->"); html2 = html2.Substring(0, len - (len - i)); html3 = mainHtml; html3 = html3.Substring(html3.IndexOf("<!--#THIRDROW_START-->")); len = html3.Length; i = html3.LastIndexOf("<!--#THIRDROW_END-->"); html3 = html3.Substring(0, len - (len - i)); html4 = mainHtml; int idx = html4.IndexOf("<!--#FOURTHROW_START-->"); if (idx > -1) { html4 = html4.Substring(idx); len = html4.Length; i = html4.LastIndexOf("<!--#FOURTHROW_END-->"); html4 = html4.Substring(0, len - (len - i)); } else { html4 = ""; } StayBazar.Areas.Admin.Models.Invoice inv = new StayBazar.Areas.Admin.Models.Invoice(); inv.InvoiceId = data.InvoiceId; inv.BookingId = data.BookingId; inv.IsMailed = (data.MailedDate <= DateTime.Today); if (data.HtmlSection2 != null && data.HtmlSection2 != "") { inv.HtmlSection1 = data.HtmlSection1; inv.HtmlSection2 = data.HtmlSection2; inv.HtmlSection3 = data.HtmlSection3; } else { inv.HtmlSection3 = html3; inv.HtmlSection2 = html2; inv.HtmlSection1 = html1; } int BookingType = BLayer.Bookings.GetBookingType(obId); BookingType = BookingType > 1 ? (int)CLayer.ObjectStatus.PropertyInventoryType.Offline : (int)CLayer.ObjectStatus.PropertyInventoryType.Online; if (BookingType == (int)CLayer.ObjectStatus.PropertyInventoryType.Online) { if (data.HtmlSection4 != null && data.HtmlSection4 != "") { inv.HtmlSection4 = data.HtmlSection4; } else { inv.HtmlSection4 = html4; } } else { inv.HtmlSection4 = ""; } ViewBag.DisableEdit = "True"; return(View("Preview", inv)); }
public async Task <ActionResult> InvoicePDF(long obId) { CLayer.Invoice data = new CLayer.Invoice(); InventoryAPIType = BLayer.Property.GetInventoryAPITypeId(BLayer.Bookings.GetPropertyId(obId)); if (InventoryAPIType == (int)CLayer.ObjectStatus.InventoryAPIType.Amadeus) { data = BLayer.Invoice.GetGDSInvoiceByBookingID(obId); } else { data = BLayer.Invoice.GetInvoiceByOfflineBooking(obId); } if (data == null) { data = await MakeNewInvoice(obId); //data = new CLayer.Invoice(); //data.OfflineBookingId = obId; //data.InvoiceDate = DateTime.Today; //data.DueDate = DateTime.Today.AddDays(10); //data.InvoiceType = (int)CLayer.ObjectStatus.InvoiceType.Invoice; //BLayer.Invoice.Save(data); //data = BLayer.Invoice.GetInvoiceByOfflineBooking(offId); //data = await MessageFromHtml(offId); } StayBazar.Areas.Admin.Models.Invoice inv = new StayBazar.Areas.Admin.Models.Invoice(); inv.InvoiceId = data.InvoiceId; inv.BookingId = data.BookingId; inv.IsMailed = (data.MailedDate <= DateTime.Today); string url = ConfigurationManager.AppSettings.Get("GDSInvoiceLink") + obId.ToString() + "&loggedInUser="******""; System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); string mainHtml = await client.GetStringAsync(url); string html1, html2, html3, html4; int i, len; html1 = mainHtml; html1 = html1.Substring(html1.IndexOf("<!--#FIRSTROW_START-->")); len = html1.Length; i = html1.LastIndexOf("<!--#FIRSTROW_END-->"); html1 = html1.Substring(0, len - (len - i)); html2 = mainHtml; html2 = html2.Substring(html2.IndexOf("<!--#SECONDROW_START-->")); len = html2.Length; i = html2.LastIndexOf("<!--#SECONDROW_END-->"); html2 = html2.Substring(0, len - (len - i)); html3 = mainHtml; html3 = html3.Substring(html3.IndexOf("<!--#THIRDROW_START-->")); len = html3.Length; i = html3.LastIndexOf("<!--#THIRDROW_END-->"); html3 = html3.Substring(0, len - (len - i)); html4 = mainHtml; int idx = html4.IndexOf("<!--#FOURTHROW_START-->"); if (idx > -1) { html4 = html4.Substring(idx); len = html4.Length; i = html4.LastIndexOf("<!--#FOURTHROW_END-->"); html4 = html4.Substring(0, len - (len - i)); } else { html4 = ""; } if (data.HtmlSection2 != null && data.HtmlSection2 != "") { inv.HtmlSection1 = data.HtmlSection1; inv.HtmlSection2 = data.HtmlSection2; inv.HtmlSection3 = data.HtmlSection3; } else { inv.HtmlSection3 = html3; inv.HtmlSection2 = html2; inv.HtmlSection1 = html1; } int BookingType = BLayer.Bookings.GetBookingType(obId); BookingType = BookingType > 1 ? (int)CLayer.ObjectStatus.PropertyInventoryType.Offline : (int)CLayer.ObjectStatus.PropertyInventoryType.Online; if (BookingType == (int)CLayer.ObjectStatus.PropertyInventoryType.Online) { if (data.HtmlSection4 != null && data.HtmlSection4 != "") { inv.HtmlSection4 = data.HtmlSection4; } else { inv.HtmlSection4 = html4; } } else { inv.HtmlSection4 = ""; } //inv.HtmlSection1 = data.HtmlSection1; //inv.HtmlSection2 = data.HtmlSection2; //inv.HtmlSection3 = data.HtmlSection3; return(new ViewAsPdf("PDF", inv)); }
public async Task <ActionResult> Preview(long obId) { CLayer.Invoice data = BLayer.Invoice.GetProformaByOfflineBooking(obId); if (data != null) { if (data.InvoiceNumber == null || data.InvoiceNumber == "") { string invNumber = BLayer.NumberGenerator.GetProformaNumber(); CLayer.Invoice InvoiceNumber = new CLayer.Invoice(); data.InvoiceNumber = invNumber; BLayer.Invoice.Save(data); } } if (data == null) { string invNumber = BLayer.NumberGenerator.GetProformaNumber(); data = new CLayer.Invoice(); data.OfflineBookingId = obId; data.InvoiceNumber = invNumber; data.InvoiceDate = DateTime.Today; data.DueDate = DateTime.Today.AddDays(10); data.InvoiceType = (int)CLayer.ObjectStatus.InvoiceType.Proforma; BLayer.Invoice.Save(data); //data = BLayer.Invoice.GetProformaByOfflineBooking(offId); //data = await MessageFromHtml(offId); } Models.Invoice inv = new Models.Invoice(); inv.InvoiceId = data.InvoiceId; inv.OfflineBookingId = data.OfflineBookingId; inv.IsMailed = (data.MailedDate <= DateTime.Today); string url = ConfigurationManager.AppSettings.Get("ProformaLink") + obId.ToString(); System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); string mainHtml = await client.GetStringAsync(url); string html1, html2, html3; int i, len; html1 = mainHtml; html1 = html1.Substring(html1.IndexOf("<!--#FIRSTROW_START-->")); len = html1.Length; i = html1.LastIndexOf("<!--#FIRSTROW_END-->"); html1 = html1.Substring(0, len - (len - i)); html2 = mainHtml; html2 = html2.Substring(html2.IndexOf("<!--#SECONDROW_START-->")); len = html2.Length; i = html2.LastIndexOf("<!--#SECONDROW_END-->"); html2 = html2.Substring(0, len - (len - i)); html3 = mainHtml; html3 = html3.Substring(html3.IndexOf("<!--#THIRDROW_START-->")); len = html3.Length; i = html3.LastIndexOf("<!--#THIRDROW_END-->"); html3 = html3.Substring(0, len - (len - i)); if (data.HtmlSection2 != null && data.HtmlSection2 != "") { inv.HtmlSection1 = data.HtmlSection1; inv.HtmlSection2 = data.HtmlSection2; inv.HtmlSection3 = data.HtmlSection3; } else { inv.HtmlSection3 = html3; inv.HtmlSection2 = html2; inv.HtmlSection1 = html1; } return(View("Preview", inv)); }
//[Common.RoleRequired(AllowAllRoles = true)] public async Task <ActionResult> Preview(long obId) { try { #region Preview if (!User.Identity.IsAuthenticated) { if (Session[CLayer.ObjectStatus.GUEST_ID_SESSION] == null) { return(RedirectToAction("Index", "Continue")); } } CLayer.Invoice data = new CLayer.Invoice(); InventoryAPIType = BLayer.Property.GetInventoryAPITypeId(BLayer.Bookings.GetPropertyId(obId)); long PropertyID = BLayer.Bookings.GetPropertyId(obId); if (InventoryAPIType == (int)CLayer.ObjectStatus.InventoryAPIType.Amadeus) { data = BLayer.Invoice.GetGDSInvoiceByBookingID(obId); } else { data = BLayer.Invoice.GetInvoiceByOfflineBooking(obId); } if (data != null) { if (data.InvoiceNumber == null || data.InvoiceNumber == "") { CLayer.InvoiceNumberData inValue; inValue = BLayer.NumberGenerator.GetGDSGSTInvoiceNumber(data.BookingId, PropertyID); if (inValue != null) { data.InvoiceNumber = inValue.InvoiceNumber; data.InvoiceDate = inValue.InvoiceDate; InvoiceNumber = inValue.InvoiceNumber; InvoiceDate = inValue.InvoiceDate; TempData["InvoiceNumber"] = InvoiceNumber; TempData["InvoiceDate"] = InvoiceDate; CLayer.Invoice dataGDSInvoice = new CLayer.Invoice(); dataGDSInvoice.InvoiceId = data.InvoiceId; dataGDSInvoice.BookingId = data.BookingId; dataGDSInvoice.InvoiceNumber = inValue.InvoiceNumber; dataGDSInvoice.InvoiceDate = inValue.InvoiceDate; long Result = BLayer.Invoice.UpdateGDSInvoiceByBookingID(data); } } } if (data == null) { data = await MakeNewInvoice(obId); } if (data.InvoiceNumber == null || data.InvoiceNumber == "") { CLayer.InvoiceNumberData inValue; inValue = BLayer.NumberGenerator.GetGDSGSTInvoiceNumber(data.BookingId, PropertyID); if (inValue != null) { CLayer.Invoice dataGDSInvoice = new CLayer.Invoice(); dataGDSInvoice.InvoiceId = data.InvoiceId; dataGDSInvoice.BookingId = data.BookingId; dataGDSInvoice.InvoiceNumber = inValue.InvoiceNumber; dataGDSInvoice.InvoiceDate = inValue.InvoiceDate; long Result = BLayer.Invoice.UpdateGDSInvoiceByBookingID(data); } } string url = ConfigurationManager.AppSettings.Get("GDSInvoiceLink") + obId.ToString() + "&loggedInUser="******""; System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); string mainHtml = await client.GetStringAsync(url); string html1, html2, html3, html4; int i, len; html1 = mainHtml; html1 = html1.Substring(html1.IndexOf("<!--#FIRSTROW_START-->")); len = html1.Length; i = html1.LastIndexOf("<!--#FIRSTROW_END-->"); html1 = html1.Substring(0, len - (len - i)); html2 = mainHtml; html2 = html2.Substring(html2.IndexOf("<!--#SECONDROW_START-->")); len = html2.Length; i = html2.LastIndexOf("<!--#SECONDROW_END-->"); html2 = html2.Substring(0, len - (len - i)); html3 = mainHtml; html3 = html3.Substring(html3.IndexOf("<!--#THIRDROW_START-->")); len = html3.Length; i = html3.LastIndexOf("<!--#THIRDROW_END-->"); html3 = html3.Substring(0, len - (len - i)); html4 = mainHtml; int idxloc = html4.IndexOf("<!--#FOURTHROW_START-->"); if (idxloc > -1) { html4 = html4.Substring(idxloc); len = html4.Length; i = html4.LastIndexOf("<!--#FOURTHROW_END-->"); html4 = html4.Substring(0, len - (len - i)); } else { html4 = ""; } StayBazar.Areas.Admin.Models.Invoice inv = new StayBazar.Areas.Admin.Models.Invoice(); inv.InvoiceId = data.InvoiceId; inv.BookingId = data.BookingId; inv.IsMailed = (data.MailedDate <= DateTime.Today); if (data.HtmlSection2 != null && data.HtmlSection2 != "") { inv.HtmlSection1 = data.HtmlSection1; inv.HtmlSection2 = data.HtmlSection2; inv.HtmlSection3 = data.HtmlSection3; } else { inv.HtmlSection3 = html3; inv.HtmlSection2 = html2; inv.HtmlSection1 = html1; } int BookingType = BLayer.Bookings.GetBookingType(obId); BookingType = BookingType > 1 ? (int)CLayer.ObjectStatus.PropertyInventoryType.Offline : (int)CLayer.ObjectStatus.PropertyInventoryType.Online; if (BookingType == (int)CLayer.ObjectStatus.PropertyInventoryType.Online) { if (data.HtmlSection4 != null && data.HtmlSection4 != "") { inv.HtmlSection4 = data.HtmlSection4; } else { inv.HtmlSection4 = html4; } } else { inv.HtmlSection4 = ""; } ViewBag.DisableEdit = ""; inv.LoggedInUser = User.Identity.GetUserId(); return(View("Preview", inv)); #endregion } catch (Exception ex) { return(null); } }
public async Task <ActionResult> SaveDetails(Models.Invoice data) { CLayer.Invoice sdata = null; if (data.OfflineBookingId > 0) { sdata = BLayer.Invoice.GetProformaByOfflineBooking(data.OfflineBookingId); } if (sdata == null) { sdata = new CLayer.Invoice(); } sdata.OfflineBookingId = data.OfflineBookingId; sdata.InvoiceId = data.InvoiceId; DateTime dt = DateTime.Today; DateTime.TryParse(data.InvoiceDate, out dt); sdata.InvoiceDate = dt; sdata.HtmlSection1 = data.HtmlSection1; sdata.HtmlSection2 = data.HtmlSection2; sdata.HtmlSection3 = data.HtmlSection3; //Common.Utils. // sdata.InvoiceDate = DateTime.Today; sdata.DueDate = DateTime.Today.AddDays(10); string prNumber = BLayer.NumberGenerator.GetProformaNumber(); sdata.InvoiceNumber = prNumber; sdata.InvoiceType = (int)CLayer.ObjectStatus.InvoiceType.Proforma; if (data.OPType == 1)//save btn { BLayer.Invoice.Save(sdata); // BLayer.Invoice.Save(sdata); } else if (data.OPType == 2)//mail btn { data.OPType = 1; BLayer.Invoice.Save(sdata); if (sdata != null) { if (sdata.InvoiceId > 0) { BLayer.Invoice.SetMailedDate(sdata.InvoiceId, DateTime.Today); } } // send mail to customer -- after save string msg = await GetMailBody(sdata.OfflineBookingId); //send mail here using msg as body Common.Mailer ml = new Common.Mailer(); System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); CLayer.OfflineBooking customer = new CLayer.OfflineBooking(); if (data.OfflineBookingId > 0) { customer = BLayer.OfflineBooking.GetAllCustomerDetails(data.OfflineBookingId); } if (customer != null) { if (customer.CustomerEmail != "") { mail.To.Add(customer.CustomerEmail); } } //mail.To.Add(BLayer.Settings.GetValue(CLayer.Settings.SUPPORT_EMAIL)); string BccEmailsforcus = BLayer.Settings.GetValue(CLayer.Settings.CC_CUSTOMERCOMMUNICATION); if (BccEmailsforcus != "") { string[] emails = BccEmailsforcus.Split(','); for (int i = 0; i < emails.Length; ++i) { mail.Bcc.Add(emails[i]); } } mail.Subject = "Invoice"; mail.Body = msg; mail.IsBodyHtml = true; try { await ml.SendMailAsyncForBooking(mail, Common.Mailer.MailType.Reservation); } catch (Exception ex) { Common.LogHandler.HandleError(ex); } } else if (data.OPType == 3) //reset { sdata.HtmlSection1 = ""; sdata.HtmlSection2 = ""; BLayer.Invoice.Save(sdata); } return(await Edit(data.OfflineBookingId)); }