private void CombinePDFs() { // Load the Invoices to get the reference to the Invoice PDF List <Entities.Invoice> invoices = new List <Orchestrator.Entities.Invoice>(); Facade.IInvoice facInvoice = new Facade.Invoice(); foreach (int id in InvoiceIDs) { invoices.Add(facInvoice.GetForInvoiceId(id)); } PdfDocument combinedPDF = new PdfDocument(); PdfDocument pdf; // Combine the PDFS into a single document foreach (var invoice in invoices) { #if DEBUG using (FileStream fs = File.OpenRead(ConfigurationManager.AppSettings["GeneratedPDFRoot"] + invoice.PDFLocation)) { pdf = PdfReader.Open(fs, PdfDocumentOpenMode.Import); } #else using (FileStream fs = File.OpenRead(Server.MapPath(invoice.PDFLocation))) { pdf = PdfReader.Open(fs, PdfDocumentOpenMode.Import); } #endif foreach (PdfPage page in pdf.Pages) { combinedPDF.AddPage(page); } } // Stream this to the IFrame Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.Buffer = true; Response.ContentType = "application/pdf"; // this makes a new window appear: Response.AddHeader("content-disposition","attachment; filename=MyPDF.PDF"); Response.AddHeader("content-disposition", "inline; filename=Invoices.PDF"); MemoryStream binaryData = new MemoryStream(); combinedPDF.Save(binaryData); Response.BinaryWrite(binaryData.ToArray()); }
/// <summary> /// Load Invoice /// </summary> private void LoadInvoice() { //if (ViewState["invoice"]==null) //{ Facade.IInvoice facInvoice = new Facade.Invoice(); Facade.IInvoiceExtra facInvoiceExtra = new Facade.Invoice(); m_Invoice = facInvoice.GetForInvoiceId(m_InvoiceNo); if (m_Invoice.InvoiceType == eInvoiceType.SelfBill) { m_Invoice.Extras = facInvoiceExtra.GetExtraCollectionForInvoiceId(m_Invoice.InvoiceId); } ViewState["invoice"] = m_Invoice; //} //else // m_Invoice = (Entities.Invoice)ViewState["invoice"]; // Load the report with the relevant details if (m_Invoice != null) { lblInvoiceNo.Text = m_Invoice.InvoiceId.ToString(); lblInvoiceNo.ForeColor = Color.Black; lblInvoiceType.Text = m_Invoice.InvoiceType.ToString(); if (m_Invoice.InvoiceType == eInvoiceType.SelfBill) { lblClientInvoiceSelfBillAmount.Visible = true; lblClientSelfBillInvoiceNumber.Visible = true; txtClientSelfBillAmount.Visible = true; txtClientSelfBillAmount.Text = m_Invoice.ClientInvoiceAmount.ToString("C"); txtClientSelfBillInvoiceNumber.Visible = true; txtClientSelfBillInvoiceNumber.Text = m_Invoice.SelfBillInvoiceNumber; divClientSelfBillAmount.Visible = true; chkSelfBillRemainder.Visible = true; lblRemainder.Visible = true; } if (m_Invoice.OverrideReason != string.Empty) { pnlOverride.Visible = true; chkOverride.Checked = true; txtOverrideReason.Text = m_Invoice.OverrideReason.ToString(); txtOverrideGrossAmount.Text = m_Invoice.OverrideTotalAmountGross.ToString("C"); txtOverrideNetAmount.Text = m_Invoice.OverrideTotalAmountNet.ToString("C"); txtOverrideVAT.Text = m_Invoice.OverrideTotalAmountVAT.ToString("C"); } // Display the invoice date, but only allow the date to be altered if the invoice has not been posted. dteInvoiceDate.SelectedDate = m_Invoice.InvoiceDate; dteInvoiceDate.Enabled = !m_Invoice.Posted; lblDateCreated.Text = m_Invoice.CreatedDate.ToShortDateString(); lblDateCreated.ForeColor = Color.Black; txtInvoiceNotes.Text = m_Invoice.InvoiceDetails; chkIncludePODs.Checked = m_Invoice.IncludePODs; chkIncludeReferences.Checked = m_Invoice.IncludeReferences; if (m_Invoice.IncludeDemurrage) { chkIncludeDemurrage.Checked = true; rdoDemurrageType.SelectedIndex = Convert.ToInt32(m_Invoice.DemurrageType); rdoDemurrageType.Visible = true; } else { chkIncludeDemurrage.Visible = false; lblNoDemurrage.Visible = true; rdoDemurrageType.Visible = false; } if (m_Invoice.IncludeFuelSurcharge) { chkIncludeFuelSurcharge.Checked = true; txtFuelSurchargeRate.Text = m_Invoice.FuelSurchargeRate.ToString(); rdoFuelSurchargeType.SelectedIndex = Convert.ToInt32(m_Invoice.FuelSurchargeType); rdoFuelSurchargeType.Visible = true; divFuelSurcharge.Visible = true; } else { divFuelSurcharge.Visible = false; chkIncludeFuelSurcharge.Checked = false; rdoFuelSurchargeType.Visible = false; } chkJobDetails.Checked = m_Invoice.IncludeJobDetails; chkExtraDetails.Checked = m_Invoice.IncludeExtraDetails; rdoSortType.SelectedIndex = Convert.ToInt32(m_Invoice.InvoiceSortingType) - 1; ViewState[C_JOBIDCSV_VS] = m_Invoice.JobIdCSV; if (m_Invoice.InvoiceType == eInvoiceType.SelfBill && m_Invoice.Extras != null) { if (m_Invoice.Extras.Count != 0) { pnlExtras.Visible = true; dgExtras.DataSource = m_Invoice.Extras; dgExtras.DataBind(); m_extraIdCSV = ""; foreach (Entities.Extra extra in m_Invoice.Extras) { if (m_extraIdCSV.Length > 0) { m_extraIdCSV += ","; } m_extraIdCSV += extra.ExtraId; } ViewState["ExtraIdCSV"] = m_extraIdCSV; chkExtraDetails.Visible = true; } else { pnlExtras.Visible = false; } } if (m_isUpdate) { if (m_Invoice.ForCancellation) { btnAdd.Visible = false; btnSendToAccounts.Visible = false; chkPostToExchequer.Visible = false; chkDelete.Checked = true; } else { if (!chkPostToExchequer.Checked) { btnAdd.Visible = true; btnSendToAccounts.Visible = true; chkPostToExchequer.Visible = true; chkDelete.Checked = false; } } } else { chkPostToExchequer.Visible = true; } if (m_Invoice.Posted) { btnAdd.Visible = false; btnSendToAccounts.Visible = false; chkPostToExchequer.Checked = true; chkPostToExchequer.Visible = true; pnlInvoiceDeleted.Visible = false; chkDelete.Visible = false; pnlExtras.Enabled = false; pnlIncludes.Enabled = false; pnlOverride.Enabled = false; chkOverride.Enabled = false; pnlSelfRemainder.Enabled = false; txtInvoiceNotes.Enabled = false; rdoSortType.Enabled = false; txtClientSelfBillAmount.Enabled = false; chkSelfBillRemainder.Enabled = false; txtClientSelfBillInvoiceNumber.Enabled = false; btnSendToAccounts.Visible = false; btnViewInvoice.Visible = false; dteInvoiceDate.Enabled = false; } else { btnAdd.Visible = true; btnSendToAccounts.Visible = true; chkPostToExchequer.Checked = false; pnlInvoiceDeleted.Visible = true; chkDelete.Visible = true; } } Header1.Title = "Update Invoice"; Header1.subTitle = "Please make any changes neccessary."; btnAdd.Text = "Update"; }
/// <summary> /// Load Invoice /// </summary> private void LoadInvoice() { if (ViewState["invoice"] == null) { Facade.IInvoice facInvoice = new Facade.Invoice(); m_Invoice = facInvoice.GetForInvoiceId(m_InvoiceNo); ViewState["invoice"] = m_Invoice; } else { m_Invoice = (Entities.Invoice)ViewState["invoice"]; } // Load the report with the relevant details if (m_Invoice != null) { lblInvoiceNo.Text = m_Invoice.InvoiceId.ToString(); lblInvoiceNo.ForeColor = Color.Black; lblInvoiceType.Text = m_Invoice.InvoiceType.ToString(); lblDateCreated.Text = m_Invoice.CreatedDate.ToShortDateString(); lblDateCreated.ForeColor = Color.Black; rdiInvoiceDate.SelectedDate = m_Invoice.InvoiceDate; rtbTxtReason.Text = m_Invoice.InvoiceDetails; txtNETAmount.Text = m_Invoice.ClientInvoiceAmount.ToString("N2"); rdiInvoiceDate.Enabled = !m_Invoice.Posted; lblAccountCode.Text = m_Invoice.AccountCode; if (cboNominalCode.FindItemByValue(m_Invoice.NominalCode) != null) { cboNominalCode.FindItemByValue(m_Invoice.NominalCode).Selected = true; } cboNominalCode.Enabled = !m_Invoice.Posted; //cboVATType.SelectedValue = Convert.ToInt32(m_Invoice.VatRate).ToString(); // Load Client Facade.IInvoiceOneLiner facInv = new Facade.Invoice(); DataSet ds = facInv.GetClientForOneLinerInvoiceId(m_Invoice.InvoiceId); cboClient.SelectedValue = ds.Tables[0].Rows[0]["IdentityId"].ToString(); cboClient.Text = ds.Tables[0].Rows[0]["OrganisationName"].ToString(); cboClient.Enabled = false; Facade.IOrganisation facOrganisation = new Facade.Organisation(); Entities.Organisation client = facOrganisation.GetForIdentityId(int.Parse(cboClient.SelectedValue)); int LCID = Convert.ToInt32(ds.Tables[0].Rows[0]["LCID"]); CultureInfo culture = new CultureInfo(LCID); this.txtNETAmount.Culture = culture; if (client != null && (client.IndividualContacts != null && client.IndividualContacts.Count > 0)) { DataSet emailDataSet = this.GetContactDataSet(client.IndividualContacts, eContactType.Email); cboEmail.DataSource = emailDataSet; cboEmail.DataMember = "contactTable"; cboEmail.DataValueField = "ContactDetail"; cboEmail.DataTextField = "ContactDisplay"; cboEmail.DataBind(); if (this.cboEmail.Items.Count > 0) { this.txtEmail.Text = this.cboEmail.Items[0].Value; } } if (m_isUpdate) { if (m_Invoice.ForCancellation) { btnAdd.Visible = false; btnSendToAccounts.Visible = false; chkPostToExchequer.Visible = false; chkDelete.Checked = true; } else { btnAdd.Visible = true; btnSendToAccounts.Visible = true; chkPostToExchequer.Visible = true; chkDelete.Checked = false; } this.Title = "Update Invoice"; //Header1.subTitle = "Please make any changes neccessary."; btnAdd.Text = "Update"; } else { chkPostToExchequer.Visible = true; } chkPostToExchequer.Visible = true; LoadReport(); if (m_Invoice.Posted) { btnAdd.Visible = false; btnSendToAccounts.Visible = false; chkPostToExchequer.Checked = true; pnlInvoiceDeleted.Visible = false; chkDelete.Visible = false; chkPostToExchequer.Checked = true; chkPostToExchequer.Visible = true; txtNETAmount.Enabled = false; rtbTxtReason.Enabled = false; btnSendToAccounts.Visible = false; btnViewInvoice.Visible = false; rdiInvoiceDate.Enabled = false; txtNETAmount.Enabled = false; cboVATType.Enabled = false; } else { btnAdd.Visible = true; btnSendToAccounts.Visible = true; chkPostToExchequer.Checked = false; pnlInvoiceDeleted.Visible = true; chkDelete.Visible = true; } } else if (cboClient.SelectedValue != null) { Facade.IOrganisation facOrganisation = new Facade.Organisation(); Entities.Organisation client = facOrganisation.GetForIdentityId(int.Parse(cboClient.SelectedValue)); if (client != null && (client.IndividualContacts != null && client.IndividualContacts.Count > 0)) { DataSet emailDataSet = this.GetContactDataSet(client.IndividualContacts, eContactType.Email); cboEmail.DataSource = emailDataSet; cboEmail.DataMember = "contactTable"; cboEmail.DataValueField = "ContactDetail"; cboEmail.DataTextField = "ContactDisplay"; cboEmail.DataBind(); if (this.cboEmail.Items.Count > 0) { this.txtEmail.Text = this.cboEmail.Items[0].Value; } } } this.Title = "Update Invoice"; //Header1.subTitle = "Please make any changes neccessary."; btnAdd.Text = "Update"; }