private void UpdateExtras(ComponentArt.Web.UI.GridItem item, string command) { switch (command) { case "UPDATE": int extraId = Convert.ToInt32(item["ExtraId"].ToString()); Facade.IJobExtra facJobExtra = new Facade.Job(); Entities.Extra updatingExtra = facJobExtra.GetExtraForExtraId(extraId); updatingExtra.ExtraState = (eExtraState)Enum.Parse(typeof(eExtraState), item["ExtraState"].ToString()); Facade.IExchangeRates facER = new Facade.ExchangeRates(); if (updatingExtra.ExchangeRateID != null) { updatingExtra.ExtraAmount = facER.GetConvertedRate((int)updatingExtra.ExchangeRateID, Decimal.Parse(item["ForeignAmount"].ToString(), NumberStyles.Currency)); } else { updatingExtra.ExtraAmount = Decimal.Parse(item["ForeignAmount"].ToString(), NumberStyles.Currency); } updatingExtra.ForeignAmount = Decimal.Parse(item["ForeignAmount"].ToString(), NumberStyles.Currency); updatingExtra.ClientContact = item["ClientContact"].ToString(); facJobExtra.UpdateExtra(updatingExtra, ((Entities.CustomPrincipal)Page.User).UserName); break; } }
public static List <string> UpdateOrder(int orderID, DateTime collectFromDate, DateTime?collectFromTime, DateTime collectByDate, DateTime?collectByTime, int collectionTimeType, DateTime deliverFromDate, DateTime?deliverFromTime, DateTime deliverToDate, DateTime?deliverToTime, int deliveryTimeType, decimal rate, string deliveryNotes, string userID) { List <string> result = new List <string>(); result.Add(true.ToString()); Orchestrator.EF.DataContext data = EF.DataContext.Current; Orchestrator.EF.Order order = data.OrderSet.First(o => o.OrderId == orderID); //determine the date(s) to use order.CollectionDateTime = collectFromDate.Add(collectFromTime.HasValue ? new TimeSpan(collectFromTime.Value.Hour, collectFromTime.Value.Minute, 0) : new TimeSpan(23, 59, 0)); if (collectionTimeType == 1) { order.CollectionByDateTime = order.CollectionDateTime; } else { order.CollectionByDateTime = collectByDate.Add(collectByTime.HasValue ? new TimeSpan(collectByTime.Value.Hour, collectByTime.Value.Minute, 0) : new TimeSpan(23, 59, 0)); } order.DeliveryFromDateTime = deliverFromDate.Add(deliverFromTime.HasValue ? new TimeSpan(deliverFromTime.Value.Hour, deliverFromTime.Value.Minute, 0) : new TimeSpan(23, 59, 0)); if (deliveryTimeType == 1) { order.DeliveryDateTime = order.DeliveryFromDateTime.Value; } else { order.DeliveryDateTime = deliverToDate.Add(deliverToTime.HasValue ? new TimeSpan(deliverToTime.Value.Hour, deliverToTime.Value.Minute, 0) : new TimeSpan(23, 59, 0)); } order.LastUpdateDate = DateTime.Now; order.LastUpdateUserID = userID; order.DeliveryNotes = deliveryNotes; order.ForeignRate = rate; Facade.IExchangeRates facER = new Facade.ExchangeRates(); CultureInfo nativeCulture = new CultureInfo(Orchestrator.Globals.Configuration.NativeCulture); if (order.LCID != nativeCulture.LCID) { order.ExchangeRateID = facER.GetCurrentExchangeRateID(Facade.Culture.GetCurrencySymbol(order.LCID.Value), order.CollectionDateTime); order.Rate = facER.GetConvertedRate(order.ExchangeRateID.Value, order.ForeignRate.Value); } else { order.Rate = decimal.Round(order.ForeignRate.Value, 4, MidpointRounding.AwayFromZero); } data.SaveChanges(); result.Add(orderID.ToString()); return(result); }
private Entities.Extra PopulateExtra(Entities.Extra extra) { decimal rate = 0m; decimal fuelSurchargeRate = 0m; extra.ExtraType = (eExtraType)Enum.Parse(typeof(eExtraType), cboExtraType.SelectedValue.Replace(" ", "")); extra.ExtraState = (eExtraState)Enum.Parse(typeof(eExtraState), cboExtraState.SelectedValue.Replace(" ", "")); extra.ClientContact = txtClientContact.Text; if (rntAmount.Value.HasValue) { rate = (decimal)rntAmount.Value.Value; if (ApplyFuelSurcharge()) { fuelSurchargeRate = Math.Round(rate * (m_fuelSurchargePercentage / 100.0m), 4, MidpointRounding.AwayFromZero); } } extra.ForeignAmount = rate; extra.FuelSurchargeForeignAmount = fuelSurchargeRate; if (m_exchangeRateID != null && extra.ForeignAmount > 0) { Facade.IExchangeRates facER = new Facade.ExchangeRates(); extra.ExtraAmount = facER.GetConvertedRate((int)m_exchangeRateID, extra.ForeignAmount); extra.FuelSurchargeAmount = facER.GetConvertedRate((int)m_exchangeRateID, extra.FuelSurchargeForeignAmount); extra.ExchangeRateID = m_exchangeRateID; } else { extra.ExtraAmount = extra.ForeignAmount; extra.FuelSurchargeAmount = extra.FuelSurchargeForeignAmount; } extra.CustomDescription = txtComment.Text; return(extra); }
Entities.JobSubContractor GetJobSubContract(Entities.Instruction selected) { Facade.IExchangeRates facER = new Facade.ExchangeRates(); decimal rate = Decimal.Parse(rntSubContractRate.Text, System.Globalization.NumberStyles.Currency); Entities.JobSubContractor jobSubContract = new Entities.JobSubContractor(int.Parse(cboSubContractor.SelectedValue), rate, chkUseSubContractorTrailer.Checked); jobSubContract.LCID = rntSubContractRate.Culture.LCID; CultureInfo culture = new CultureInfo(Orchestrator.Globals.Configuration.NativeCulture); if (jobSubContract.LCID != culture.LCID) // Default { jobSubContract.ExchangeRateID = facER.GetCurrentExchangeRateID(Facade.Culture.GetCurrencySymbol(jobSubContract.LCID), selected.PlannedArrivalDateTime); jobSubContract.Rate = facER.GetConvertedRate((int)jobSubContract.ExchangeRateID, jobSubContract.ForeignRate); } else { jobSubContract.Rate = decimal.Round(jobSubContract.ForeignRate, 4, MidpointRounding.AwayFromZero); } return(jobSubContract); }
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 } }
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 } } } }
/// <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; }