void gvBatches_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                int preInvoiceBatchID = int.Parse(gvBatches.MasterTableView.DataKeyValues[e.Item.ItemIndex][_preInvoiceBatchID].ToString());

                switch (e.CommandName.ToLower())
                {
                case "continuegroup":
                    HiddenField  hidInvoiceType = (HiddenField)e.Item.FindControl("hidInvoiceType");
                    eInvoiceType invoiceType    = (eInvoiceType)int.Parse(hidInvoiceType.Value);
                    if (invoiceType == eInvoiceType.ClientInvoicing)
                    {
                        Response.Redirect(string.Format("../groupage/autorunconfirmation.aspx?bid={0}", preInvoiceBatchID));
                    }
                    else if (invoiceType == eInvoiceType.SubContractorSelfBill)
                    {
                        Response.Redirect(string.Format("../subcontractorsb/autorunconfirmation.aspx?bid={0}", preInvoiceBatchID));
                    }
                    break;

                case "removegroup":
                    Facade.IPreInvoice facPreInvoice = new Facade.PreInvoice();
                    facPreInvoice.DeleteBatch(preInvoiceBatchID);
                    gvBatches.Rebind();
                    break;
                }
            }
        }
        void dgInvoices_SelectCommand(object sender, ComponentArt.Web.UI.GridItemEventArgs e)
        {
            if (e.Item[0].ToString() != "")
            {
                eInvoiceType invoiceType = (eInvoiceType)Enum.Parse(typeof(eInvoiceType), e.Item[3].ToString().Replace(" ", ""));

                reportViewer.Visible = false;

                if (invoiceType == eInvoiceType.Normal || invoiceType == eInvoiceType.SelfBill)
                {
                    // Display the selected invoice id in the report.
                    int invoiceId = Convert.ToInt32(e.Item[0]);
                    DisplayInvoiceAuditReport(invoiceId);
                }
            }
        }
        private DataSet GetData()
        {
            #region Configure Parameters

            int clientId = 0;
            try
            {
                clientId = Convert.ToInt32(cboClient.SelectedValue);
            }
            catch { }

            int invoiceTypeId = 0;
            try
            {
                eInvoiceType invoiceType = (eInvoiceType)Enum.Parse(typeof(eInvoiceType), cboInvoiceType.SelectedValue.Replace(" ", ""));
                invoiceTypeId = (int)invoiceType;
            }
            catch { }

            DateTime startDate = dteInvoiceStartDate.SelectedDate.Value;
            startDate = startDate.Subtract(startDate.TimeOfDay);

            DateTime endDate = dteInvoiceEndDate.SelectedDate.Value;
            endDate = endDate.Subtract(endDate.TimeOfDay);
            endDate = endDate.Add(new TimeSpan(23, 59, 59));

            int dateType = int.Parse(rblDateType.SelectedValue);

            int?invoiceID = null;
            try
            {
                invoiceID = Convert.ToInt32(txtInvoiceId.Text);
            }
            catch { }

            bool showCancelled = chkShowCancelled.Checked;
            bool showPosted    = chkShowPosted.Checked;

            #endregion

            Facade.IInvoice facInvoice = new Facade.Invoice();
            return(facInvoice.GetInvoicesForAuditTrail(clientId, invoiceTypeId, dateType, startDate, endDate, showCancelled, showPosted, invoiceID));
        }
Beispiel #4
0
        private void performSelfBillSearch()
        {
            Facade.IInvoice facInvoice = new Facade.Invoice();

            eInvoiceType searchInvoiceType = eInvoiceType.SelfBill;

            switch ((eInvoiceFilterType)Enum.Parse(typeof(eInvoiceFilterType), rdoFilterOptions.SelectedValue.Replace(" ", "")))
            {
            case eInvoiceFilterType.SelfBillInvoice:
                searchInvoiceType = eInvoiceType.SelfBill;
                break;

            case eInvoiceFilterType.Extra:
                searchInvoiceType = eInvoiceType.Extra;
                break;

            default:
                searchInvoiceType = eInvoiceType.Normal;
                break;
            }
            int posted = 0;

            switch ((eWithOrWithout)Enum.Parse(typeof(eWithOrWithout), rdoPosted.SelectedValue))
            {
            case eWithOrWithout.All:
                posted = 2;
                break;

            case eWithOrWithout.With:
                posted = 1;
                break;

            case eWithOrWithout.Without:
                posted = 0;
                break;
            }

            int clientId = cboClient.SelectedValue == "" ? 0 : Convert.ToInt32(cboClient.SelectedValue);

            string clientInvoiceNumber = string.Empty;

            if (txtClientInvoiceNumber.Text != string.Empty)
            {
                clientInvoiceNumber = txtClientInvoiceNumber.Text;
            }

            DateTime startDate = dteStartDate.SelectedDate.Value;

            startDate = startDate.Subtract(startDate.TimeOfDay);

            DateTime endDate = dteEndDate.SelectedDate.Value;

            endDate = endDate.Subtract(endDate.TimeOfDay);
            endDate = endDate.Add(new TimeSpan(23, 59, 59));

            // Job State
            eJobState jobState = new eJobState();

            if (cboJobState.SelectedValue != string.Empty)
            {
                jobState = (eJobState)Enum.Parse(typeof(eJobState), cboJobState.SelectedValue);
            }

            if (startDate != DateTime.MinValue && endDate != DateTime.MinValue)
            {
                dsInvoice = facInvoice.GetwithParamsAndDate(clientId, clientInvoiceNumber, jobState, posted, startDate, endDate, searchInvoiceType);
            }
            else
            {
                if (clientId == 0)
                {
                    dsInvoice = facInvoice.GetAll(posted, searchInvoiceType);
                }
                else
                {
                    dsInvoice = facInvoice.GetwithParams(clientId, clientInvoiceNumber, jobState, posted, searchInvoiceType);
                }
            }

            gvInvoices.Columns[7].Visible = true;
            gvInvoices.DataSource         = dsInvoice;

            ViewState[C_InvoiceDATA_VS] = dsInvoice;

            gvInvoices.DataBind();

            if (gvInvoices.Rows.Count == 0)
            {
                pnlNormalInvoice.Visible = false;
                lblNote.Text             = "There are no invoices for the given criteria.";
                lblNote.ForeColor        = Color.Red;
                lblNote.Visible          = true;
            }
            {
                pnlNormalInvoice.Visible = true;
                gvInvoices.Visible       = true;
            }
        }
        void gvPreInvoices_ItemCommand(object source, GridCommandEventArgs e)
        {
            string userName = ((Entities.CustomPrincipal)Page.User).UserName;

            switch (e.CommandName.ToLower())
            {
                #region Client Reference Editing

            case "cancelclientreference":
                e.Item.Edit = false;
                gvPreInvoices.Rebind();
                break;

            case "editclientreference":
                e.Item.Edit = true;
                gvPreInvoices.Rebind();
                break;

            case "editpurchaseorderreference":
                e.Item.Edit = true;
                gvPreInvoices.Rebind();
                break;

            case "updateclientreference":
                e.Item.Edit = false;
                string clientReference = string.Empty;

                LinkButton lnkChangeClientReference = e.Item.FindControl("lnkChangeClientReference") as LinkButton;
                TextBox    txtClientReference       = e.Item.FindControl("txtClientReference") as TextBox;

                if (lnkChangeClientReference != null && txtClientReference != null)
                {
                    string oldClientReference = lnkChangeClientReference.Text;
                    clientReference = txtClientReference.Text;

                    // Only apply the change if the client reference has been altered
                    if (oldClientReference != clientReference)
                    {
                        // Update the client reference
                        int preInvoiceID = int.Parse(((GridDataItem)e.Item).GetDataKeyValue("PreInvoiceID").ToString());
                        Facade.IPreInvoice facPreInvoice = new Facade.PreInvoice();
                        facPreInvoice.UpdateClientInvoiceReference(preInvoiceID, clientReference, userName);
                    }
                }
                gvPreInvoices.Rebind();
                break;

            case "updatepurchaseorderreference":
                e.Item.Edit = false;
                string purchaseOrderReference = string.Empty;

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

                if (lnkChangePurchaseOrderReference != null && txtPurchaseOrderReference != null)
                {
                    string oldPurchaseOrderReference = lnkChangePurchaseOrderReference.Text;
                    purchaseOrderReference = txtPurchaseOrderReference.Text;

                    // Only apply the change if the client reference has been altered
                    if (oldPurchaseOrderReference != purchaseOrderReference)
                    {
                        // Update the client reference
                        int preInvoiceID = int.Parse(((GridDataItem)e.Item).GetDataKeyValue("PreInvoiceID").ToString());
                        Facade.IPreInvoice facPreInvoice = new Facade.PreInvoice();
                        facPreInvoice.UpdatePurchaseOrderReference(preInvoiceID, purchaseOrderReference, userName);
                    }
                }
                gvPreInvoices.Rebind();
                break;

                #endregion

                #region Rate Editing

            //case "cancelrate":
            //    e.Item.Edit = false;
            //    e.Item.OwnerTableView.Rebind();
            //    gvPreInvoices.MasterTableView.Rebind();
            //    StayOpen = e.Item.OwnerTableView.ParentItem.ItemIndex;
            //    break;
            //case "editrate":
            //    e.Item.Edit = true;
            //    e.Item.OwnerTableView.Rebind();
            //    gvPreInvoices.MasterTableView.Rebind();
            //    StayOpen = e.Item.OwnerTableView.ParentItem.ItemIndex;
            //    break;
            case "update":     // update rate and pallet spaces.
                e.Item.Edit = false;
                decimal rate = 0;

                //LinkButton lnkChangeRate = e.Item.FindControl("lnkChangeRate") as LinkButton;
                HiddenField  hidOldRate = e.Item.FindControl("hidOldRate") as HiddenField;
                TextBox      txtRate    = e.Item.FindControl("txtRate") as TextBox;
                GridDataItem parentItem = e.Item.OwnerTableView.ParentItem;

                int         lcid = int.Parse(parentItem.GetDataKeyValue("LCID").ToString());
                CultureInfo preInvoiceCulture = new CultureInfo(lcid);

                if (Decimal.TryParse(txtRate.Text, System.Globalization.NumberStyles.Currency, preInvoiceCulture, out rate))
                {
                    decimal oldRate = 0;
                    oldRate = decimal.Parse(hidOldRate.Value);

                    // Only apply the rate change if the rate has altered.
                    if (oldRate != rate)
                    {
                        int itemID = int.Parse(txtRate.Attributes["ItemID"]);

                        // Update the rate (depends on item type - depends on invoice type)
                        int          preInvoiceID = int.Parse(parentItem.GetDataKeyValue("PreInvoiceID").ToString());
                        eInvoiceType invoiceType  = (eInvoiceType)int.Parse(parentItem.GetDataKeyValue("InvoiceTypeID").ToString());
                        CultureInfo  culture      = new CultureInfo(Orchestrator.Globals.Configuration.NativeCulture);

                        Facade.IPreInvoice    facPreInvoice = new Facade.PreInvoice();
                        Facade.IExchangeRates facER         = new Facade.ExchangeRates();

                        switch (invoiceType)
                        {
                        case eInvoiceType.ClientInvoicing:
                            Facade.IOrder  facOrder = new Facade.Order();
                            Entities.Order order    = facOrder.GetForOrderID(itemID);
                            order.ForeignRate = rate;

                            if (order.LCID != culture.LCID)
                            {
                                BusinessLogicLayer.IExchangeRates    blER = new BusinessLogicLayer.ExchangeRates();
                                BusinessLogicLayer.CurrencyConverter currencyConverter = blER.CreateCurrencyConverter(order.LCID, order.CollectionDateTime);
                                order.Rate = currencyConverter.ConvertToLocal(order.ForeignRate);
                            }
                            else
                            {
                                order.Rate = decimal.Round(order.ForeignRate, 4, MidpointRounding.AwayFromZero);
                            }

                            //if (order.OrderGroupID > 0)
                            //facPreInvoice.UpdateOrderGroupRate(preInvoiceID, order.OrderGroupID, order.ForeignRate, order.Rate, userName);
                            //else

                            facPreInvoice.UpdateOrderRate(preInvoiceID, itemID, order.ForeignRate, order.Rate, userName);

                            break;

                        case eInvoiceType.SubContractorSelfBill:
                        case eInvoiceType.SubContract:
                            // Needs to be Amended For Currency : TL 12/05/08;
                            Facade.IJobSubContractor  facJSC           = new Facade.Job();
                            Entities.JobSubContractor jobSubContractor = facJSC.GetSubContractorForJobSubContractId(itemID);
                            jobSubContractor.ForeignRate = rate;

                            if (jobSubContractor.LCID != culture.LCID)
                            {
                                jobSubContractor.Rate = facER.GetConvertedRate((int)jobSubContractor.ExchangeRateID, jobSubContractor.ForeignRate);
                            }
                            else
                            {
                                jobSubContractor.Rate = decimal.Round(jobSubContractor.ForeignRate, 4, MidpointRounding.AwayFromZero);
                            }

                            facPreInvoice.UpdateJobSubContractRate(preInvoiceID, itemID, jobSubContractor.ForeignRate, jobSubContractor.Rate, jobSubContractor.ExchangeRateID, userName);
                            break;

                        default:
                            throw new NotSupportedException("You can not alter item rates on invoices of type " + invoiceType.ToString());
                        }

                        this.lblSavedMessage.Text = string.Format("Your changes were saved at {0}", DateTime.Now.ToLongTimeString());
                    }
                }

                e.Item.OwnerTableView.Rebind();
                gvPreInvoices.MasterTableView.Rebind();
                StayOpen = parentItem.ItemIndex;
                break;

                #endregion
            }
        }
Beispiel #6
0
        private void SaveBatchChanges()
        {
            string userName = ((Entities.CustomPrincipal)Page.User).UserName;

            // React to the user's options.
            foreach (GridDataItem row in gvPreInvoices.Items)
            {
                string tableName    = row.OwnerTableView.Name;
                int    preInvoiceId = -1;
                int.TryParse(row.GetDataKeyValue("PreInvoiceID").ToString(), out preInvoiceId);

                if (tableName == PreInvoiceTableName && (row.ItemType == GridItemType.Item || row.ItemType == GridItemType.AlternatingItem))
                {
                    HiddenField hidIsDirty = row.FindControl("hidIsDirty") as HiddenField;
                    bool        isDirty    = false;

                    if (bool.TryParse(hidIsDirty.Value, out isDirty) && isDirty)
                    {
                        #region Update PreInvoice
                        DateTime?invoiceDate = null;
                        string   clientReference = string.Empty, purchaseOrderReference = string.Empty;
                        int      taxRateID = -1;

                        RadDateInput rdiInvoiceDate = row.FindControl("rdiInvoiceDate") as RadDateInput;

                        RadTextBox rtClientReference        = row.FindControl("rtClientReference") as RadTextBox;
                        RadTextBox rtPurchaseOrderReference = row.FindControl("rtPurchaseOrderReference") as RadTextBox;

                        DropDownList cboTaxRate = row.FindControl("cboTaxRate") as DropDownList;

                        if (rdiInvoiceDate.SelectedDate.HasValue)
                        {
                            invoiceDate = rdiInvoiceDate.SelectedDate.Value;
                        }

                        clientReference        = rtClientReference.Text;
                        purchaseOrderReference = rtPurchaseOrderReference.Text;

                        int.TryParse(cboTaxRate.SelectedValue, out taxRateID);

                        Facade.IPreInvoice facPreInvoice = new Facade.PreInvoice();
                        facPreInvoice.UpdatePreinvoiceDetails(preInvoiceId, invoiceDate, clientReference, purchaseOrderReference, taxRateID, userName);
                        #endregion
                    }
                }
                else if (tableName == PreInvoiceItemTableName && (row.ItemType == GridItemType.Item || row.ItemType == GridItemType.AlternatingItem))
                {
                    HiddenField hidInvoiceItemIsDirty = row.FindControl("hidInvoiceItemIsDirty") as HiddenField;
                    bool        isDirty = false;

                    HiddenField hidInvoiceItemPendingDelete = row.FindControl("hidInvoiceItemPendingDelete") as HiddenField;
                    bool        isPendingDelete             = false;

                    if (bool.TryParse(hidInvoiceItemPendingDelete.Value, out isPendingDelete) && isPendingDelete)
                    {
                        Facade.IPreInvoice facPreInvoice = new Facade.PreInvoice();

                        TextBox      txtRate    = row.FindControl("txtRate") as TextBox;
                        GridDataItem parentItem = row.OwnerTableView.ParentItem;

                        int itemID = int.Parse(txtRate.Attributes["ItemID"]);

                        // Update the rate (depends on item type - depends on invoice type)
                        int preInvoiceID = int.Parse(parentItem.GetDataKeyValue("PreInvoiceID").ToString());

                        facPreInvoice.RemovePreInvoiceOrder(preInvoiceID, itemID);
                    }

                    else if (bool.TryParse(hidInvoiceItemIsDirty.Value, out isDirty) && isDirty)
                    {
                        #region Pre Invoice Item

                        decimal      rate       = 0;
                        HiddenField  hidOldRate = row.FindControl("hidOldRate") as HiddenField;
                        TextBox      txtRate    = row.FindControl("txtRate") as TextBox;
                        GridDataItem parentItem = row.OwnerTableView.ParentItem;

                        int         lcid = int.Parse(parentItem.GetDataKeyValue("LCID").ToString());
                        CultureInfo preInvoiceCulture = new CultureInfo(lcid);

                        if (Decimal.TryParse(txtRate.Text, System.Globalization.NumberStyles.Currency, preInvoiceCulture, out rate))
                        {
                            //decimal oldRate = 0;
                            //oldRate = decimal.Parse(hidOldRate.Value);

                            // Only apply the rate change if the rate has altered.
                            //if (oldRate != rate)
                            if (hidOldRate.Value != txtRate.Text)
                            {
                                int itemID = int.Parse(txtRate.Attributes["ItemID"]);

                                // Update the rate (depends on item type - depends on invoice type)
                                int          preInvoiceID = int.Parse(parentItem.GetDataKeyValue("PreInvoiceID").ToString());
                                eInvoiceType invoiceType  = (eInvoiceType)int.Parse(parentItem.GetDataKeyValue("InvoiceTypeID").ToString());
                                CultureInfo  culture      = new CultureInfo(Orchestrator.Globals.Configuration.NativeCulture);

                                Facade.IPreInvoice    facPreInvoice = new Facade.PreInvoice();
                                Facade.IExchangeRates facER         = new Facade.ExchangeRates();

                                switch (invoiceType)
                                {
                                case eInvoiceType.ClientInvoicing:
                                    #region Client Invoice

                                    Facade.IOrder  facOrder = new Facade.Order();
                                    Entities.Order order    = facOrder.GetForOrderID(itemID);
                                    order.ForeignRate = rate;

                                    if (order.LCID != culture.LCID)
                                    {
                                        BusinessLogicLayer.IExchangeRates    blER = new BusinessLogicLayer.ExchangeRates();
                                        BusinessLogicLayer.CurrencyConverter currencyConverter = blER.CreateCurrencyConverter(order.LCID, order.CollectionDateTime);
                                        order.Rate = currencyConverter.ConvertToLocal(order.ForeignRate);
                                    }
                                    else
                                    {
                                        order.Rate = decimal.Round(order.ForeignRate, 4, MidpointRounding.AwayFromZero);
                                    }

                                    facPreInvoice.UpdateOrderRate(preInvoiceID, itemID, order.ForeignRate, order.Rate, userName);

                                    #endregion
                                    break;

                                case eInvoiceType.SubContractorSelfBill:
                                case eInvoiceType.SubContract:
                                    #region Subby Invoicing
                                    // Needs to be Amended For Currency : TL 12/05/08;
                                    Facade.IJobSubContractor  facJSC           = new Facade.Job();
                                    Entities.JobSubContractor jobSubContractor = facJSC.GetSubContractorForJobSubContractId(itemID);
                                    jobSubContractor.ForeignRate = rate;

                                    if (jobSubContractor.LCID != culture.LCID)
                                    {
                                        jobSubContractor.Rate = facER.GetConvertedRate((int)jobSubContractor.ExchangeRateID, jobSubContractor.ForeignRate);
                                    }
                                    else
                                    {
                                        jobSubContractor.Rate = decimal.Round(jobSubContractor.ForeignRate, 4, MidpointRounding.AwayFromZero);
                                    }

                                    facPreInvoice.UpdateJobSubContractRate(preInvoiceID, itemID, jobSubContractor.ForeignRate, jobSubContractor.Rate, jobSubContractor.ExchangeRateID, userName);
                                    #endregion
                                    break;

                                default:
                                    throw new NotSupportedException("You can not alter item rates on invoices of type " + invoiceType.ToString());
                                }
                            }
                        }

                        #endregion
                    }
                }
            }
        }