private void LoadVatTypes()
        {
            Orchestrator.Facade.Invoice facInvoice = new Orchestrator.Facade.Invoice();
            dsTaxRates = facInvoice.GetTaxRates(this.rdiInvoiceDate.SelectedDate.Value);

            cboVATType.DataTextField  = "Description";
            cboVATType.DataValueField = "VatTypeId";
            cboVATType.DataSource     = dsTaxRates;
            cboVATType.DataBind();

            //select the Standard VAT Type
            int standard;

            if (m_invoiceExtra == null)
            {
                standard = (int)eVATType.Standard;
            }
            else
            {
                standard = facInvoice.GetVatTypeForVatNo(m_invoiceExtra.VatNo);
            }

            foreach (ListItem li in cboVATType.Items)
            {
                if (li.Value == standard.ToString())
                {
                    li.Selected = true;
                    break;
                }
            }
        }
        private void LoadBatchInvoices()
        {
            Facade.IInvoiceBatches facInv = new Orchestrator.Facade.Invoice();

            DataSet dsInvoice = facInv.GetAllBatches();

            // Put in dummy checkbox column
            dsInvoice.Tables[0].Columns.Add("Include", typeof(Boolean));

            //dgInvoiceBatch.DataSource = dsInvoice;
            gvInvoiceBatch.DataSource = dsInvoice;

            //dgInvoiceBatch.DataBind();
            gvInvoiceBatch.DataBind();

            if (dsInvoice.Tables[0].Rows.Count > 0)
            {
                //dgInvoiceBatch.Visible = true;
                gvInvoiceBatch.Visible           = true;
                pnlInvoiceBatch.Visible          = true;
                lblNote.Visible                  = false;
                btnAddUpdateMutliInvoice.Visible = true;
            }
            else
            {
                lblNote.Text      = "No prepared batches";
                lblNote.ForeColor = Color.Blue;
                lblNote.Visible   = true;
                //dgInvoiceBatch.Visible = false;
                pnlInvoiceBatch.Visible          = true;
                btnAddUpdateMutliInvoice.Visible = false;
            }
        }
        private Entities.Invoice PopulateInvoice(int invoiceId)
        {
            Entities.Invoice m_Invoice = null;

            Facade.IInvoice facInvoice = new Orchestrator.Facade.Invoice();
            m_Invoice = facInvoice.GetForInvoiceId(invoiceId);

            return(m_Invoice);
        }
        private void LoadVatTypes()
        {
            Orchestrator.Facade.Invoice facInvoice = new Orchestrator.Facade.Invoice();
            DataSet dsTaxRates = facInvoice.GetTaxRates(this.rdiCreditNoteDate.SelectedDate.Value);

            cboVATType.DataTextField  = "Description";
            cboVATType.DataValueField = "VATTypeId";
            cboVATType.DataSource     = dsTaxRates;
            cboVATType.DataBind();

            //select the Standard VAT Type
            string standard = ((int)eVATType.Standard).ToString();

            foreach (ListItem li in cboVATType.Items)
            {
                if (li.Value == standard)
                {
                    li.Selected = true;
                    break;
                }
            }
        }
        private void LoadBatchInvoices()
        {
            Facade.IInvoiceBatches facInv = new Orchestrator.Facade.Invoice();

            DataSet dsInvoice = facInv.GetAllBatches();

            dgInvoiceBatch.DataSource = dsInvoice;

            dgInvoiceBatch.DataBind();

            if (dsInvoice.Tables[0].Rows.Count > 0)
            {
                dgInvoiceBatch.Visible  = true;
                pnlInvoiceBatch.Visible = true;
            }
            else
            {
                lblNote.Text            = "No invoice batches to invoice";
                lblNote.ForeColor       = Color.Red;
                lblNote.Visible         = true;
                dgInvoiceBatch.Visible  = false;
                pnlInvoiceBatch.Visible = true;
            }
        }
        void gvPreInvoices_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            string tableName = e.Item.OwnerTableView.Name;

            if (tableName == PreInvoiceTableName)
            {
                if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.EditItem)
                {
                    DataRowView drv = (DataRowView)e.Item.DataItem;

                    HtmlInputRadioButton rdoDoNothing             = e.Item.FindControl("rdoDoNothing") as HtmlInputRadioButton;
                    HtmlInputRadioButton rdoReject                = e.Item.FindControl("rdoReject") as HtmlInputRadioButton;
                    HtmlInputRadioButton rdoRegenerate            = e.Item.FindControl("rdoRegenerate") as HtmlInputRadioButton;
                    HtmlInputRadioButton rdoApprove               = e.Item.FindControl("rdoApprove") as HtmlInputRadioButton;
                    HtmlInputRadioButton rdoApproveAndPost        = e.Item.FindControl("rdoApproveAndPost") as HtmlInputRadioButton;
                    DropDownList         cboTaxRate               = e.Item.FindControl("cboTaxRate") as DropDownList;
                    LinkButton           lnkChangeClientReference = (LinkButton)e.Item.FindControl("lnkChangeClientReference");
                    TextBox    txtClientReference       = (TextBox)e.Item.FindControl("txtClientReference");
                    LinkButton lnkSaveClientReference   = (LinkButton)e.Item.FindControl("lnkSaveClientReference");
                    LinkButton lnkCancelClientReference = (LinkButton)e.Item.FindControl("lnkCancelClientReference");

                    LinkButton lnkChangePurchaseOrderReference = (LinkButton)e.Item.FindControl("lnkChangePurchaseOrderReference");
                    TextBox    txtPurchaseOrderReference       = (TextBox)e.Item.FindControl("txtPurchaseOrderReference");
                    LinkButton lnkSavePurchaseOrderReference   = (LinkButton)e.Item.FindControl("lnkSavePurchaseOrderReference");
                    LinkButton lnkCancelPurchaseOrderReference = (LinkButton)e.Item.FindControl("lnkCancelPurchaseOrderReference");

                    Label lblNetAmount           = e.Item.FindControl("lblNetAmount") as Label;
                    Label lblExtraAmount         = e.Item.FindControl("lblExtraAmount") as Label;
                    Label lblFuelSurchargeAmount = e.Item.FindControl("lblFuelSurchargeAmount") as Label;
                    Label lblTaxAmount           = e.Item.FindControl("lblTaxAmount") as Label;
                    Label lblTotalAmount         = e.Item.FindControl("lblTotalAmount") as Label;

                    HtmlInputCheckBox chkUseHeadedPaper = e.Item.FindControl("chkUseHeadedPaper") as HtmlInputCheckBox;

                    rdoDoNothing.Name      += "_" + e.Item.ItemIndex.ToString();
                    rdoReject.Name         += "_" + e.Item.ItemIndex.ToString();
                    rdoRegenerate.Name     += "_" + e.Item.ItemIndex.ToString();
                    rdoApprove.Name        += "_" + e.Item.ItemIndex.ToString();
                    rdoApproveAndPost.Name += "_" + e.Item.ItemIndex.ToString();

                    if (this.dsTaxRates == null)
                    {
                        Orchestrator.Facade.Invoice facInvoice = new Orchestrator.Facade.Invoice();
                        DataSet taxRates = facInvoice.GetTaxRates((DateTime)drv["InvoiceDate"]);
                        this.dsTaxRates = taxRates;
                    }

                    cboTaxRate.DataTextField  = "Description";
                    cboTaxRate.DataValueField = "VatNo";
                    cboTaxRate.DataSource     = this.dsTaxRates;
                    cboTaxRate.DataBind();
                    cboTaxRate.ClearSelection();
                    int taxRateID = 0;
                    int.TryParse(drv["TaxRateID"].ToString(), out taxRateID);
                    if (cboTaxRate.Items.FindByValue(taxRateID.ToString()) == null)
                    {
                        ListItem newItem = new ListItem("New Standard", taxRateID.ToString());
                        cboTaxRate.Items.Add(newItem);
                    }

                    cboTaxRate.Items.FindByValue(taxRateID.ToString()).Selected = true;

                    if (drv["ClientInvoiceReference"] != DBNull.Value)
                    {
                        txtClientReference.Text = lnkChangeClientReference.Text = (string)drv["ClientInvoiceReference"];
                    }
                    else
                    {
                        txtClientReference.Text       = string.Empty;
                        lnkChangeClientReference.Text = "none provided";
                    }

                    if (drv["PurchaseOrderReference"] != DBNull.Value)
                    {
                        txtPurchaseOrderReference.Text = lnkChangePurchaseOrderReference.Text = (string)drv["PurchaseOrderReference"];
                    }
                    else
                    {
                        txtPurchaseOrderReference.Text       = string.Empty;
                        lnkChangePurchaseOrderReference.Text = "none provided";
                    }

                    txtPurchaseOrderReference.Visible       = lnkSavePurchaseOrderReference.Visible = lnkCancelPurchaseOrderReference.Visible = e.Item.Edit;
                    lnkChangePurchaseOrderReference.Visible = !e.Item.Edit;

                    txtClientReference.Visible       = lnkSaveClientReference.Visible = lnkCancelClientReference.Visible = e.Item.Edit;
                    lnkChangeClientReference.Visible = !e.Item.Edit;

                    if ((bool)drv["RequiresRegeneration"])
                    {
                        rdoApprove.Visible        = false;
                        rdoApproveAndPost.Visible = false;
                        rdoRegenerate.Checked     = true;
                    }
                    //else
                    //    rdoApprove.Checked = true;

                    int         lcID    = (int)drv["LCID"];
                    CultureInfo culture = new CultureInfo(lcID);

                    lblNetAmount.Text           = ((decimal)drv["ForeignNetAmount"]).ToString("C", culture);
                    lblExtraAmount.Text         = ((decimal)drv["ForeignExtraAmount"]).ToString("C", culture);
                    lblFuelSurchargeAmount.Text = ((decimal)drv["ForeignFuelSurchargeAmount"]).ToString("C", culture);
                    lblTaxAmount.Text           = ((decimal)drv["ForeignTaxAmount"]).ToString("C", culture);
                    lblTotalAmount.Text         = ((decimal)drv["ForeignTotalAmount"]).ToString("C", culture);

                    chkUseHeadedPaper.Checked = Orchestrator.Globals.Configuration.UseHeadedPaper;
                }
                else if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Header)
                {
                    RadioButton rdoDoNothing      = e.Item.FindControl("rdoDoNothing") as RadioButton;
                    RadioButton rdoReject         = e.Item.FindControl("rdoReject") as RadioButton;
                    RadioButton rdoRegenerate     = e.Item.FindControl("rdoRegenerate") as RadioButton;
                    RadioButton rdoApprove        = e.Item.FindControl("rdoApprove") as RadioButton;
                    RadioButton rdoApproveAndPost = e.Item.FindControl("rdoApproveAndPost") as RadioButton;

                    rdoDoNothing.GroupName      += "_Header";
                    rdoReject.GroupName         += "_Header";
                    rdoRegenerate.GroupName     += "_Header";
                    rdoApprove.GroupName        += "_Header";
                    rdoApproveAndPost.GroupName += "_Header";

                    AddReaction(rdoDoNothing, "spnDoNothing");
                    AddReaction(rdoReject, "spnReject");
                    AddReaction(rdoRegenerate, "spnRegenerate");
                    AddReaction(rdoApprove, "spnApprove");
                    AddReaction(rdoApproveAndPost, "spnApproveAndPost");

                    //rdoApprove.Checked = true;
                }
            }
            else if (tableName == PreInvoiceItemTableName)
            {
                if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.EditItem)
                {
                    HiddenField hidOldRate      = e.Item.FindControl("hidOldRate") as HiddenField;
                    TextBox     txtRate         = e.Item.FindControl("txtRate") as TextBox;
                    Label       lblPalletSpaces = e.Item.FindControl("lblPalletSpaces") as Label;
                    //LinkButton lnkChangeRate = e.Item.FindControl("lnkChangeRate") as LinkButton;
                    //LinkButton lnkCancelRate = e.Item.FindControl("lnkCancelRate") as LinkButton;
                    //LinkButton lnkSaveRate = e.Item.FindControl("lnkSaveRate") as LinkButton;

                    DataRowView drv    = e.Item.DataItem as DataRowView;
                    int         itemID = (int)drv["ItemID"];
                    txtRate.Attributes.Add("ItemID", ((int)drv["ItemID"]).ToString());

                    int         lcID    = (int)drv["LCID"];
                    CultureInfo culture = new CultureInfo(lcID);
                    txtRate.Text         = ((decimal)drv["ForeignRate"]).ToString("C", culture);
                    lblPalletSpaces.Text = ((decimal)drv["PalletSpaces"]).ToString("F2");
                    hidOldRate.Value     = ((decimal)drv["ForeignRate"]).ToString("F2");
                    //txtRate.Visible = e.Item.Edit;
                    //lnkChangeRate.Visible = !e.Item.Edit;

                    // If the item is part of a group only allow the rate to be changed on the first item.
                    //int groupID = (int)drv["GroupID"];
                    //if (!e.Item.Edit && groupID > 0)
                    //{
                    //    // Is there any item with the same group id but a lower item id?
                    //    bool groupAlreadyRendered =
                    //        drv.Row.Table.Select(string.Format("GroupID = {0} AND ItemID < {1}", groupID, itemID)).
                    //            Length > 0;
                    //    //lnkChangeRate.Visible = !groupAlreadyRendered;
                    //}
                }
            }
        }
Beispiel #7
0
        void gvPreInvoices_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            string tableName = e.Item.OwnerTableView.Name;

            if (tableName == PreInvoiceTableName)
            {
                #region Pre Invoice Table
                if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.EditItem)
                {
                    DataRowView drv = (DataRowView)e.Item.DataItem;

                    RadDateInput rdiInvoiceDate = e.Item.FindControl("rdiInvoiceDate") as RadDateInput;

                    CheckBox chkPreInvoice = e.Item.FindControl("chkPreInvoice") as CheckBox;
                    if (chkPreInvoice != null)
                    {
                        chkPreInvoice.Attributes.Add("PreInvoiceId", drv["PreInvoiceId"].ToString());
                    }

                    RadTextBox rtClientReference        = e.Item.FindControl("rtClientReference") as RadTextBox;
                    RadTextBox rtPurchaseOrderReference = e.Item.FindControl("rtPurchaseOrderReference") as RadTextBox;

                    HtmlInputRadioButton rdoDoNothing      = e.Item.FindControl("rdoDoNothing") as HtmlInputRadioButton;
                    HtmlInputRadioButton rdoReject         = e.Item.FindControl("rdoReject") as HtmlInputRadioButton;
                    HtmlInputRadioButton rdoApprove        = e.Item.FindControl("rdoApprove") as HtmlInputRadioButton;
                    HtmlInputRadioButton rdoApproveAndPost = e.Item.FindControl("rdoApproveAndPost") as HtmlInputRadioButton;
                    HtmlInputCheckBox    chkUseHeadedPaper = e.Item.FindControl("chkUseHeadedPaper") as HtmlInputCheckBox;

                    HiddenField hidIsDirty = e.Item.FindControl("hidIsDirty") as HiddenField;

                    DropDownList cboTaxRate = e.Item.FindControl("cboTaxRate") as DropDownList;

                    Label lblPendingChanges      = e.Item.FindControl("lblPendingChanges") as Label;
                    Label lblNetAmount           = e.Item.FindControl("lblNetAmount") as Label;
                    Label lblExtraAmount         = e.Item.FindControl("lblExtraAmount") as Label;
                    Label lblFuelSurchargeAmount = e.Item.FindControl("lblFuelSurchargeAmount") as Label;
                    Label lblTaxAmount           = e.Item.FindControl("lblTaxAmount") as Label;
                    Label lblTotalAmount         = e.Item.FindControl("lblTotalAmount") as Label;

                    rdoDoNothing.Name      += "_" + e.Item.ItemIndex.ToString();
                    rdoReject.Name         += "_" + e.Item.ItemIndex.ToString();
                    rdoApprove.Name        += "_" + e.Item.ItemIndex.ToString();
                    rdoApproveAndPost.Name += "_" + e.Item.ItemIndex.ToString();

                    rdiInvoiceDate.SelectedDate = (DateTime)drv["InvoiceDate"];

                    hidIsDirty.Value = ((bool)drv["RequiresRegeneration"]).ToString();

                    if (this.dsTaxRates == null)
                    {
                        Orchestrator.Facade.Invoice facInvoice = new Orchestrator.Facade.Invoice();
                        DataSet taxRates = facInvoice.GetTaxRates((DateTime)drv["InvoiceDate"]);
                        this.dsTaxRates = taxRates;
                    }

                    cboTaxRate.DataTextField  = "Description";
                    cboTaxRate.DataValueField = "VatNo";
                    cboTaxRate.DataSource     = this.dsTaxRates;
                    cboTaxRate.DataBind();
                    cboTaxRate.ClearSelection();

                    int taxRateID = 0;
                    int.TryParse(drv["TaxRateID"].ToString(), out taxRateID);
                    if (cboTaxRate.Items.FindByValue(taxRateID.ToString()) == null)
                    {
                        ListItem newItem = new ListItem("New Standard", taxRateID.ToString());
                        cboTaxRate.Items.Add(newItem);
                    }

                    cboTaxRate.Items.FindByValue(taxRateID.ToString()).Selected = true;

                    if (drv["ClientInvoiceReference"] != DBNull.Value)
                    {
                        rtClientReference.Text = (string)drv["ClientInvoiceReference"];
                    }
                    else
                    {
                        rtClientReference.Text = string.Empty;
                    }

                    if (drv["PurchaseOrderReference"] != DBNull.Value)
                    {
                        rtPurchaseOrderReference.Text = (string)drv["PurchaseOrderReference"];
                    }
                    else
                    {
                        rtPurchaseOrderReference.Text = string.Empty;
                    }

                    int invoiceGenerationParametersID = int.Parse(drv["InvoiceGenerationParametersID"].ToString());
                    if ((bool)drv["RequiresRegeneration"])
                    {
                        lblPendingChanges.Text = "Pending Changes...";
                        lblPendingChanges.Style.Remove("display");

                        rdoDoNothing.Style.Add("display", "none");
                        rdoReject.Style.Add("display", "none");
                        rdoApprove.Style.Add("display", "none");
                        rdoApproveAndPost.Style.Add("display", "none");
                    }
                    else if (this.PreInvoiceIdsSentToWorkFlow.Exists(p => p == invoiceGenerationParametersID))
                    {
                        lblPendingChanges.Text = "Processing...";
                        lblPendingChanges.Style.Remove("display");

                        rdoDoNothing.Style.Add("display", "none");
                        rdoReject.Style.Add("display", "none");
                        rdoApprove.Style.Add("display", "none");
                        rdoApproveAndPost.Style.Add("display", "none");
                        this.PreInvoiceIdsSentToWorkFlow.Remove(invoiceGenerationParametersID);
                    }
                    else
                    {
                        lblPendingChanges.Text = string.Empty;
                        lblPendingChanges.Style.Add("display", "none");

                        rdoDoNothing.Style.Remove("display");
                        rdoReject.Style.Remove("display");
                        rdoApprove.Style.Remove("display");
                        rdoApproveAndPost.Style.Remove("display");
                    }

                    int         lcID    = (int)drv["LCID"];
                    CultureInfo culture = new CultureInfo(lcID);

                    lblNetAmount.Text           = ((decimal)drv["ForeignNetAmount"]).ToString("C", culture);
                    lblExtraAmount.Text         = ((decimal)drv["ForeignExtraAmount"]).ToString("C", culture);
                    lblFuelSurchargeAmount.Text = ((decimal)drv["ForeignFuelSurchargeAmount"]).ToString("C", culture);
                    lblTaxAmount.Text           = ((decimal)drv["ForeignTaxAmount"]).ToString("C", culture);
                    lblTotalAmount.Text         = ((decimal)drv["ForeignTotalAmount"]).ToString("C", culture);

                    chkUseHeadedPaper.Checked = Orchestrator.Globals.Configuration.UseHeadedPaper;
                }
                else if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Header)
                {
                    RadioButton rdoDoNothing = e.Item.FindControl("rdoDoNothing") as RadioButton;
                    //RadioButton rdoReject = e.Item.FindControl("rdoReject") as RadioButton;
                    RadioButton rdoApprove        = e.Item.FindControl("rdoApprove") as RadioButton;
                    RadioButton rdoApproveAndPost = e.Item.FindControl("rdoApproveAndPost") as RadioButton;

                    rdoDoNothing.GroupName += "_Header";
                    //rdoReject.GroupName += "_Header";
                    rdoApprove.GroupName        += "_Header";
                    rdoApproveAndPost.GroupName += "_Header";

                    AddReaction(rdoDoNothing, "spnDoNothing");
                    //AddReaction(rdoReject, "spnReject");
                    AddReaction(rdoApprove, "spnApprove");
                    AddReaction(rdoApproveAndPost, "spnApproveAndPost");
                }
                #endregion
            }
            else if (tableName == PreInvoiceItemTableName)
            {
                #region Detail Table
                if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.EditItem)
                {
                    HiddenField hidOldRate          = e.Item.FindControl("hidOldRate") as HiddenField;
                    TextBox     txtRate             = e.Item.FindControl("txtRate") as TextBox;
                    Label       lblPalletSpaces     = e.Item.FindControl("lblPalletSpaces") as Label;
                    HtmlAnchor  lnkOrderId          = e.Item.FindControl("lnkOrderId") as HtmlAnchor;
                    Label       lblJobSubcontractId = e.Item.FindControl("lblJobSubcontractId") as Label;

                    DataRowView drv = e.Item.DataItem as DataRowView;

                    int itemID = (int)drv["ItemID"];
                    txtRate.Attributes.Add("ItemID", itemID.ToString());

                    if (Convert.ToBoolean(drv["IsOrder"]) == true)
                    {
                        lblJobSubcontractId.Visible = false;
                        lnkOrderId.Visible          = true;
                        lnkOrderId.InnerHtml        = itemID.ToString();
                        lnkOrderId.HRef             = "javascript:viewOrder(" + itemID.ToString() + ");";
                    }
                    else
                    {
                        lblJobSubcontractId.Visible = true;
                        lnkOrderId.Visible          = false;
                        lblJobSubcontractId.Text    = itemID.ToString();
                    }

                    int         lcID              = (int)drv["LCID"];
                    CultureInfo culture           = new CultureInfo(lcID);
                    int         rateDecimalPlaces = (int)drv["RateDecimalPlaces"];
                    if (rateDecimalPlaces != 2)
                    {
                        culture.NumberFormat.CurrencyDecimalDigits = rateDecimalPlaces;
                    }

                    txtRate.Text = ((decimal)drv["ForeignRate"]).ToString("C", culture);

                    lblPalletSpaces.Text = ((decimal)drv["PalletSpaces"]).ToString("F2");
                    hidOldRate.Value     = txtRate.Text;
                }
                #endregion
            }
        }