///	<summary>
        /// Populate CreditNote
        ///	</summary>
        private void populateCreditNote()
        {
            if (ViewState["CreditNote"] == null)
            {
                m_CreditNote = new Entities.CreditNote();
            }
            else
            {
                m_CreditNote = (Entities.CreditNote)ViewState["CreditNote"];
            }

            if (lblCreditNoteNo.Text != "To Be Issued ... (This Credit Note has not yet been saved, add Credit Note to allocate Credit Note No.)")
            {
                m_CreditNote.CreditNoteId = Convert.ToInt32(lblCreditNoteNo.Text);
            }

            //m_CreditNote.CreditNoteType = eCreditNoteType.OneLiner;
            m_CreditNote.ClientId = Convert.ToInt32(cboClient.SelectedValue);

            m_CreditNote.CreditNoteDetails = rtbTxtReason.Text;


            if (chkPostToExchequer.Checked)
            {
                m_CreditNote.Posted = true;
            }
            else
            {
                m_CreditNote.Posted = false;
            }

            int     vatNo   = 0;
            decimal vatRate = 0.00M;

            //Get VAT Rate for VAT Type
            Facade.IInvoice facInv  = new Facade.Invoice();
            eVATType        vatType = (eVATType)int.Parse(cboVATType.SelectedValue);

            facInv.GetVatRateForVatType(vatType, this.rdiCreditNoteDate.SelectedDate.Value, out vatNo, out vatRate);

            m_CreditNote.VatNo   = vatNo;
            m_CreditNote.VatRate = vatRate;

            Facade.IExchangeRates facER = new Facade.ExchangeRates();

            if (this.txtNETAmount.Culture.LCID != 2057)
            {
                m_CreditNote.LCID = this.txtNETAmount.Culture.LCID;

                m_CreditNote.ExchangeRateID =
                    facER.GetCurrentExchangeRateID(Facade.Culture.GetCurrencySymbol(m_CreditNote.LCID),
                                                   this.rdiCreditNoteDate.SelectedDate.Value);
            }
            else
            {
                m_CreditNote.ExchangeRateID = null;
                m_CreditNote.LCID           = 2057; //English
            }

            //Calculate VATamount and GrossAmount
            //#16479 Round all amounts to 2 decimal places
            m_CreditNote.ForeignNetAmount   = Math.Round(Decimal.Parse(txtNETAmount.Text, System.Globalization.NumberStyles.Currency), 2);
            m_CreditNote.ForeignVATAmount   = Math.Round((m_CreditNote.ForeignNetAmount * m_CreditNote.VatRate) / 100, 2);
            m_CreditNote.ForeignGrossAmount = Math.Round(m_CreditNote.ForeignNetAmount + m_CreditNote.ForeignVATAmount, 2);

            if (m_CreditNote.ExchangeRateID != null)
            {
                m_CreditNote.NetAmount = facER.GetConvertedRate((int)m_CreditNote.ExchangeRateID,
                                                                m_CreditNote.ForeignNetAmount);
                m_CreditNote.VATamount = facER.GetConvertedRate((int)m_CreditNote.ExchangeRateID,
                                                                m_CreditNote.ForeignVATAmount);
                m_CreditNote.GrossAmount = facER.GetConvertedRate((int)m_CreditNote.ExchangeRateID,
                                                                  m_CreditNote.ForeignGrossAmount);
            }
            else
            {
                m_CreditNote.NetAmount   = m_CreditNote.ForeignNetAmount;
                m_CreditNote.VATamount   = m_CreditNote.ForeignVATAmount;
                m_CreditNote.GrossAmount = m_CreditNote.ForeignGrossAmount;
            }

            m_CreditNote.AccountCode = lblAccountCode.Text;
            m_CreditNote.NominalCode = cboNominalCode.SelectedValue;

            m_CreditNote.CreditNoteDate = rdiCreditNoteDate.SelectedDate.Value;
        }
        /// <summary>
        /// Load Report Depending On CreditNote Type
        /// </summary>
        private void LoadReport()
        {
            // Configure the Session variables used to pass data to the report
            NameValueCollection reportParams = new NameValueCollection();

            //-------------------------------------------------------------------------------------
            //						Job/Collect-Drops/References/Demurrages Section
            //-------------------------------------------------------------------------------------
            //Facade.CreditNote facCreditNote = new Facade.CreditNote();

            if (m_isUpdate)
            {
                btnSendToAccounts.Visible = true;
                //A delete function may be rquired at some point
                //pnlCreditNoteDeleted.Visible = true;
            }

            // Client Name & Id
            reportParams.Add("Client", cboClient.Text);

            reportParams.Add("ClientId", cboClient.SelectedValue);

            // Details
            reportParams.Add("Reason", rtbTxtReason.Text);

            // CreditNote Id
            if (lblCreditNoteNo.Text != "To Be Issued ... (This Credit Note has not yet been saved, add Credit Note to allocate Credit Note No.)")
            {
                reportParams.Add("CreditNoteId", lblCreditNoteNo.Text);
            }
            else
            {
                reportParams.Add("CreditNoteId", "0");
            }

            reportParams.Add("NetAmount", decimal.Parse(txtNETAmount.Text, System.Globalization.NumberStyles.Currency).ToString());

            // Posted To Accounts
            if (chkPostToExchequer.Checked)
            {
                reportParams.Add("Accounts", "true");
            }

            int     vatNo   = 0;
            decimal vatRate = 0.00M;

            //Get VAT Rate for VAT Type
            Facade.IInvoice facInv  = new Facade.Invoice();
            eVATType        vatType = (eVATType)int.Parse(cboVATType.SelectedValue);

            facInv.GetVatRateForVatType(vatType, rdiCreditNoteDate.SelectedDate.Value, out vatNo, out vatRate);

            reportParams.Add("VATrate", vatRate.ToString());

            // CreditNote Date
            reportParams.Add("CreditNoteDate", rdiCreditNoteDate.SelectedDate.Value.ToShortDateString());

            //-------------------------------------------------------------------------------------
            //									Load Report Section
            //-------------------------------------------------------------------------------------
            Session[Orchestrator.Globals.Constants.ReportTypeSessionVariable] = eReportType.CreditNoteOneLiner;
//			Session[Orchestrator.Globals.Constants.ReportDataSessionVariable] = dsInv;
//			Session[Orchestrator.Globals.Constants.ReportDataMemberSessionVariable] = "Table";
            Session[Orchestrator.Globals.Constants.ReportParamsSessionVariable] = reportParams;

            bool enforceDataExistence;
            var  activeReport = Orchestrator.Reports.Utilities.GetActiveReport(eReportType.CreditNoteOneLiner, "", out enforceDataExistence);

            activeReport.Run(false);

            if (m_CreditNote == null)
            {
                populateCreditNote();
            }

            // Generate the location this report's pdf will be output to.
            StringBuilder sbFilename = new StringBuilder(ConfigurationManager.AppSettings["GeneratedPDFRoot"]);

            sbFilename.Append("\\CreditNotes\\");
            sbFilename.Append(m_CreditNote.CreditNoteDate.Year.ToString());
            sbFilename.Append("\\");
            sbFilename.Append(m_CreditNote.CreditNoteDate.Month.ToString());
            sbFilename.Append("\\");
            sbFilename.Append(m_CreditNote.CreditNoteDate.Day.ToString());
            sbFilename.Append("\\Credit_Note_");
            sbFilename.Append(m_CreditNote.CreditNoteId);

            sbFilename.Append(".pdf");
            string filename       = sbFilename.ToString();
            string oldPDFLocation = m_CreditNote.PDFLocation;

            PdfExport pdf = new PdfExport();

            Facade.CreditNote facCreditNote = new Facade.CreditNote();

            //If the invoice id is 0 then the invoice hasn't been created so don't save it
            if (m_CreditNote.CreditNoteId != 0)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(filename));

                //Export the report to PDF.
                pdf.Export(activeReport.Document, filename);

                string pdfRoot = ConfigurationManager.AppSettings["GeneratedPDFRoot"];
                filename = filename.Remove(0, (pdfRoot != null ? pdfRoot.Length : 0));

                m_CreditNote.PDFLocation = filename;

                string userName = ((Entities.CustomPrincipal)Page.User).UserName;

                facCreditNote.UpdatePDFLocation(m_CreditNote.CreditNoteId, filename, userName);

                pdfViewer.Src = Globals.Configuration.WebServer + filename;

                lblEmail.Visible           = true;
                btnEmailCreditNote.Visible = true;
                cboEmail.Visible           = true;
                rfvEmailAddress.Enabled    = true;
                revEmailAddress.Enabled    = true;
            }
            else
            {
                //Instead of saving the pdf just output the memory stream
                var ms = new System.IO.MemoryStream();
                pdf.Export(activeReport.Document, ms);

                pdfViewer.Src = "data:application/pdf;base64," + Convert.ToBase64String(ms.ToArray());

                lblEmail.Visible           = false;
                btnEmailCreditNote.Visible = false;
                cboEmail.Visible           = false;
                rfvEmailAddress.Enabled    = false;
                revEmailAddress.Enabled    = false;
            }

            pdfViewer.Visible = true;

            // Show the add CreditNote button.
            if (!chkPostToExchequer.Checked)
            {
                btnAdd.Visible = true;
            }

            // Deleted
            if (chkDelete.Checked)
            {
                Response.Redirect("../default.aspx");
            }
        }
Exemplo n.º 3
0
        ///	<summary>
        /// Populate Invoice
        ///	</summary>
        private void populateInvoice()
        {
            if (ViewState["invoice"] == null)
            {
                m_Invoice = new Entities.Invoice();
            }
            else
            {
                m_Invoice = (Entities.Invoice)ViewState["invoice"];
            }

            if (lblInvoiceNo.Text != "To Be Issued ... (This invoice has not yet been saved, add invoice to allocate Invoice No.)")
            {
                m_Invoice.InvoiceId = Convert.ToInt32(lblInvoiceNo.Text);
            }

            m_Invoice.InvoiceType = eInvoiceType.OneLiner;

            m_Invoice.InvoiceDetails = rtbTxtReason.Text;

            m_Invoice.InvoiceDate = rdiInvoiceDate.SelectedDate.Value;

            Facade.IExchangeRates facER = new Facade.ExchangeRates();

            int exchangeRateId = -1;

            // the txtNetAmount textbox has had its culture set by the client.
            if (this.txtNETAmount.Culture.LCID != 2057)
            {
                exchangeRateId = facER.GetCurrentExchangeRateID(Facade.Culture.GetCurrencySymbol(this.txtNETAmount.Culture.LCID), this.rdiInvoiceDate.SelectedDate.Value);
            }

            m_Invoice.ClientInvoiceAmount = Decimal.Parse(txtNETAmount.Text, System.Globalization.NumberStyles.Currency);

            if (chkPostToExchequer.Checked)
            {
                m_Invoice.Posted = true;
            }
            else
            {
                m_Invoice.Posted = false;
            }

            int     vatNo   = 0;
            decimal vatRate = 0.00M;

            //Get VAT Rate and Vat Type
            Facade.IInvoice facInv  = new Facade.Invoice();
            eVATType        vatType = (eVATType)int.Parse(cboVATType.SelectedValue);

            facInv.GetVatRateForVatType(vatType, m_Invoice.InvoiceDate, out vatNo, out vatRate);

            m_Invoice.VatRate = vatRate;
            m_Invoice.VatNo   = vatNo;

            m_Invoice.AccountCode = lblAccountCode.Text;
            m_Invoice.NominalCode = cboNominalCode.SelectedValue;

            // Deleted checked not required until the Invoice's are allowed to be deleted
            if (chkDelete.Checked)
            {
                m_Invoice.ForCancellation = true;
            }
            else
            {
                m_Invoice.ForCancellation = false;
            }
        }