Ejemplo n.º 1
0
        private void UpdateCreditNote(Entities.CreditNote creditNote)
        {
            Facade.CreditNote facCreditNote = new Facade.CreditNote();
            string            userName      = ((Entities.CustomPrincipal)Page.User).UserName;

            facCreditNote.UpdateOneLiner(creditNote, userName);
        }
Ejemplo n.º 2
0
        private void PostToAccountsSystem()
        {
            Entities.CreditNote creditNote    = null;
            Facade.CreditNote   facCreditNote = new Facade.CreditNote();

            if (hidSelectedCreditNotes.Value.EndsWith(","))
            {
                hidSelectedCreditNotes.Value = hidSelectedCreditNotes.Value.Substring(0, hidSelectedCreditNotes.Value.Length - 1);
            }

            foreach (string creditNoteId in hidSelectedCreditNotes.Value.Split(','))
            {
                creditNote = PopulateCreditNote(Int32.Parse(creditNoteId));
                try
                {
                    UpdateCreditNote(creditNote);
                }
                catch (Exception e)
                {
                    string err = GetErrorString(e);
                    lblError.Text                = "There was a problem posting this Credit Note Id " + creditNoteId.ToString() + " this could be because it has already been posted to your account's system." + "<br/>" + err;
                    pnlError.Visible             = true;
                    hidSelectedCreditNotes.Value = "";
                    return;
                }
            }

            PopulateCreditNotes();
        }
Ejemplo n.º 3
0
        private Entities.CreditNote PopulateCreditNote(int creditNoteId)
        {
            Entities.CreditNote creditNote = null;

            Facade.CreditNote facCreditNote = new Orchestrator.Facade.CreditNote();
            creditNote = facCreditNote.GetForCreditNoteId(creditNoteId);

            creditNote.Posted = true;

            return(creditNote);
        }
        protected void btnEmailCreditNote_Click(object sender, EventArgs e)
        {
            if (ViewState["CreditNote"] != null)
            {
                m_CreditNote = (Entities.CreditNote)ViewState["CreditNote"];

                using (MailMessage mailMessage = new System.Net.Mail.MailMessage())
                {
                    mailMessage.From = new MailAddress(Orchestrator.Globals.Configuration.MailFromAddress, Orchestrator.Globals.Configuration.MailFromName);

                    string emailAddress = this.cboEmail.Text;

                    if (this.cboEmail.SelectedValue != String.Empty)
                    {
                        emailAddress = this.cboEmail.SelectedValue;
                    }

                    mailMessage.To.Add(new MailAddress(emailAddress));

                    mailMessage.Attachments.Add(new Attachment(Server.MapPath(m_CreditNote.PDFLocation)));
                    mailMessage.Subject    = Orchestrator.Globals.Configuration.InstallationCompanyName + " Credit Note Number " + m_CreditNote.CreditNoteId.ToString();
                    mailMessage.IsBodyHtml = false;

                    // We need to get/determine what text should be attached to the email for the invoice.
                    string body = string.Format("Please find attached Credit Note “{0}” from {1}. If you require POD’s please access the self service website here {2}. Please contact Customer Services on {3}  for additional help,\n\n Regards", m_CreditNote.CreditNoteId.ToString(), Orchestrator.Globals.Configuration.InstallationCompanyName, Orchestrator.Globals.Configuration.OrchestratorURL, Orchestrator.Globals.Configuration.InstallationCustomerServicesNumber);
                    mailMessage.Body = body;

                    SmtpClient smtp = new System.Net.Mail.SmtpClient();
                    smtp.Host        = Globals.Configuration.MailServer;
                    smtp.Credentials = new NetworkCredential(Globals.Configuration.MailUsername, Globals.Configuration.MailPassword);

                    smtp.Send(mailMessage);
                    lblEmailSent.Visible = true;
                }
            }
        }
        ///	<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 CreditNote
        ///	</summary>
        private void LoadCreditNote()
        {
            if (ViewState["CreditNote"] == null)
            {
                Facade.CreditNote facCreditNote = new Facade.CreditNote();
                m_CreditNote = facCreditNote.GetForCreditNoteId(m_CreditNoteNo);

                ViewState["CreditNote"] = m_CreditNote;
            }
            else
            {
                m_CreditNote = (Entities.CreditNote)ViewState["CreditNote"];
            }

            // Load the report with the relevant details
            if (m_CreditNote != null)
            {
                lblCreditNoteNo.Text      = m_CreditNote.CreditNoteId.ToString();
                lblCreditNoteNo.ForeColor = Color.Black;

                //lblCreditNoteType.Text = m_CreditNote.CreditNoteType.ToString();

                lblDateCreated.Text      = m_CreditNote.CreateDate.ToShortDateString();
                lblDateCreated.ForeColor = Color.Black;

                lblAccountCode.Text = m_CreditNote.AccountCode;

                rdiCreditNoteDate.SelectedDate = m_CreditNote.CreditNoteDate;
                rdiCreditNoteDate.Enabled      = !m_CreditNote.Posted;

                rtbTxtReason.Text = m_CreditNote.CreditNoteDetails;
                txtNETAmount.Text = m_CreditNote.ForeignNetAmount.ToString("N2");

                if (cboNominalCode.FindItemByValue(m_CreditNote.NominalCode) != null)
                {
                    cboNominalCode.FindItemByValue(m_CreditNote.NominalCode).Selected = true;
                }

                cboNominalCode.Enabled = !m_CreditNote.Posted;

                //cboVATType.SelectedValue = Convert.ToInt32(m_CreditNote.VatNo).ToString();

                // Load Client
                //TODO Is this necessary?
                Facade.IOrganisation  facOrganisation = new Facade.Organisation();
                Entities.Organisation client          = facOrganisation.GetForIdentityId(m_CreditNote.ClientId);

                cboClient.SelectedValue = m_CreditNote.ClientId.ToString();
                cboClient.Text          = client.OrganisationName;
                cboClient.Enabled       = false;

                if (m_isUpdate)
                {
                    // TODO: the culture will have to come from the invoice when it is available.
                    CultureInfo culture = new CultureInfo(m_CreditNote.LCID);
                    this.txtNETAmount.Culture = culture;

                    btnAdd.Visible             = true;
                    btnSendToAccounts.Visible  = true;
                    chkPostToExchequer.Visible = true;
                    chkDelete.Checked          = false;

                    this.Title  = "Update Credit Note";
                    btnAdd.Text = "Update";
                }
                else
                {
                    // take the culture from the client if we are adding
                    CultureInfo culture = new CultureInfo(client.LCID);
                    this.txtNETAmount.Culture = culture;

                    chkPostToExchequer.Visible = true;
                }

                chkPostToExchequer.Visible = true;

                LoadReport();

                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_CreditNote.Posted)
                {
                    btnAdd.Visible               = false;
                    btnSendToAccounts.Visible    = false;
                    chkPostToExchequer.Checked   = true;
                    pnlCreditNoteDeleted.Visible = false;
                    chkDelete.Visible            = false;
                    chkPostToExchequer.Checked   = true;
                    chkPostToExchequer.Visible   = true;
                    txtNETAmount.Enabled         = false;
                    rtbTxtReason.Enabled         = false;
                    btnSendToAccounts.Visible    = false;
                    btnViewCreditNote.Visible    = false;
                    rdiCreditNoteDate.Enabled    = false;
                    rtbTxtReason.Enabled         = false;
                    txtNETAmount.Enabled         = false;
                    cboVATType.Enabled           = false;
                }
                else
                {
                    btnAdd.Visible             = true;
                    btnSendToAccounts.Visible  = true;
                    chkPostToExchequer.Checked = false;
                    //A delete function may be rquired at some point
                    //pnlCreditNoteDeleted.Visible = true;
                    //chkDelete.Visible = true;
                }
            }

            this.Title = "Update Credit Note";
            //Header1.subTitle = "Please make any changes neccessary.";
            btnAdd.Text = "Update";
        }