private void SetActivityRateFromLanguageRate(LanguageRateGroup languageRateGroup) { if (languageRateGroup != null) { ActivityRates.LanguageRateId = languageRateGroup.Id; ActivityRates.LanguageRateName = languageRateGroup.Name; ActivityRates.LanguageRateCurrency = languageRateGroup.Currency; ActivityRates.LanguageRateTotal = Convert.ToDouble(numericUpDown_pem_rate_total.Value); ActivityRates.LanguageRates.Clear(); foreach (var languageRate in languageRateGroup.LanguageRates) { var newLanguageRate = new Sdl.Community.Structures.Projects.Activities.LanguageRate { ProjectActivityRateId = -1, ProjectActivityId = Activity.Id, SourceLanguage = languageRate.SourceLanguage, TargetLanguage = languageRate.TargetLanguage, RndType = languageRate.RndType, BaseRate = languageRate.BaseRate, RatePm = languageRate.RatePm, RateCm = languageRate.RateCm, RateRep = languageRate.RateRep, Rate100 = languageRate.Rate100, Rate95 = languageRate.Rate95, Rate85 = languageRate.Rate85, Rate75 = languageRate.Rate75, Rate50 = languageRate.Rate50, RateNew = languageRate.RateNew }; ActivityRates.LanguageRates.Add(newLanguageRate); } ActivityRates.ProjectActivityId = Activity.Id; } else { ActivityRates.LanguageRateId = -1; ActivityRates.LanguageRateName = string.Empty; ActivityRates.LanguageRateCurrency = ActivityRates.LanguageRateCurrency; ActivityRates.LanguageRateTotal = 0; ActivityRates.LanguageRates.Clear(); } }
public void UpdateActivityPropertiesViewer() { try { if (QualitivityViewPropertiesController.NavigationTreeView.SelectedNode != null) { var apv = new ActivityPropertiesView(); if (QualitivityViewPropertiesController.ObjectListView.SelectedObjects.Count > 0) { #region | ActivityPropertiesView | var tpa = (Activity)QualitivityViewPropertiesController.ObjectListView.SelectedObjects[0]; var tp = Helper.GetProjectFromId(tpa.ProjectId); if (tp.CompanyProfileId > -1) { #region | client | var cpi = Helper.GetClientFromId(tp.CompanyProfileId); var _pemRate = Tracked.Settings.LanguageRateGroups.FirstOrDefault(pemr => pemr.Id == cpi.ProfileRate.LanguageRateId); var client = new Client { ClientId = cpi.Id.ToString(), ClientName = cpi.Name }; var clientAddress = new Address { AddressStreet = cpi.Street, AddressZip = cpi.Zip, AddressCity = cpi.City, AddressState = cpi.State, AddressCountry = cpi.Country }; client.ClientAddress = clientAddress; var contactDetails = new ContactDetails { EMail = cpi.Email, WebPage = cpi.Web, Phone = cpi.Phone, FAX = cpi.Fax }; client.ContactDetails = contactDetails; client.ClientVat = cpi.VatCode; client.ClientTax = cpi.TaxCode; var defaultRates = new DefaultRates { HrRate = cpi.ProfileRate.HourlyRateRate, HrRateCurrency = cpi.ProfileRate.HourlyRateCurrency, PemRate = _pemRate != null ? _pemRate.Name : string.Empty }; client.DefaultRates = defaultRates; apv.ClientProfile = client; #endregion } #region | project | var project = new Sdl.Community.Structures.PropertyView.Project { ProjectId = tp.Id.ToString(), ProjectIdStudio = tp.StudioProjectId, ProjectName = tp.Name, ProjectDescription = tp.Description, ProjectStatus = tp.ProjectStatus, ProjectDateCreated = tp.Created, ProjectDateDue = tp.Due, ProjectDateComplated = tp.Completed, ProjectActivitesCount = tp.Activities.Count.ToString() }; apv.ProjectDetails = project; #endregion #region | activity | var activityDetails = new Sdl.Community.Structures.PropertyView.Activity { ActivityDocuments = tpa.Activities.Count, ActivityId = tpa.Id.ToString(), ActivityName = tpa.Name, ActivityDescription = tpa.Description }; var hourlyRate = new HourlyRate { HrCkd = tpa.HourlyRateChecked, hr_currency = tpa.DocumentActivityRates.HourlyRateCurrency, hr_quantity = Convert.ToDecimal(Math.Round(tpa.DocumentActivityRates.HourlyRateQuantity, 3)), hr_rate = Convert.ToDecimal(tpa.DocumentActivityRates.HourlyRateRate), hr_total = Convert.ToDecimal(tpa.DocumentActivityRates.HourlyRateTotal) }; activityDetails.HourlyRate = hourlyRate; var pemRate = new LanguageRateGroup { PemCkd = tpa.LanguageRateChecked, PemCurrency = tpa.DocumentActivityRates.LanguageRateId > -1 ? tpa.DocumentActivityRates.LanguageRateCurrency : string.Empty, PemName = tpa.DocumentActivityRates.LanguageRateId > -1 ? tpa.DocumentActivityRates.LanguageRateName : string.Empty, PemTotal = Convert.ToDecimal(tpa.DocumentActivityRates.LanguageRateId > -1 ? tpa.DocumentActivityRates.LanguageRateTotal : 0) }; activityDetails.PemRate = pemRate; activityDetails.ActivityDateStart = tpa.Started; activityDetails.ActivityDateEnd = tpa.Stopped; activityDetails.ActivityStatus = tpa.ActivityStatus.ToString(); activityDetails.ActivityBillable = tpa.Billable; activityDetails.ActivityTotal = Math.Round((tpa.HourlyRateChecked ? tpa.DocumentActivityRates.HourlyRateTotal : 0) + (tpa.LanguageRateChecked ? tpa.DocumentActivityRates.LanguageRateTotal : 0), 2) + tpa.DocumentActivityRates.HourlyRateCurrency; apv.ActivityDetails = activityDetails; #endregion propertyGrid1.SelectedObject = apv; #endregion } else { if (QualitivityViewPropertiesController.NavigationTreeView.SelectedNode.Tag != null && QualitivityViewPropertiesController.NavigationTreeView.SelectedNode.Tag.GetType() == typeof(Project)) { var tp = (Project)QualitivityViewPropertiesController.NavigationTreeView.SelectedNode.Tag; if (tp.CompanyProfileId > -1) { #region | client | var cpi = Helper.GetClientFromId(tp.CompanyProfileId); var pemRate = Tracked.Settings.LanguageRateGroups.FirstOrDefault(pemr => pemr.Id == cpi.ProfileRate.LanguageRateId); var client = new Client { ClientId = cpi.Id.ToString() }; var clientAddress = new Address { AddressStreet = cpi.Street, AddressZip = cpi.Zip, AddressCity = cpi.City, AddressState = cpi.State, AddressCountry = cpi.Country }; client.ClientAddress = clientAddress; var contactDetails = new ContactDetails { EMail = cpi.Email, WebPage = cpi.Web, Phone = cpi.Phone, FAX = cpi.Fax }; client.ContactDetails = contactDetails; client.ClientVat = cpi.VatCode; client.ClientTax = cpi.TaxCode; var defaultRates = new DefaultRates { HrRate = cpi.ProfileRate.HourlyRateRate, HrRateCurrency = cpi.ProfileRate.HourlyRateCurrency, PemRate = pemRate != null ? pemRate.Name : string.Empty }; client.DefaultRates = defaultRates; apv.ClientProfile = client; #endregion } #region | project | var project = new Sdl.Community.Structures.PropertyView.Project { ProjectId = tp.Id.ToString(), ProjectIdStudio = tp.StudioProjectId, ProjectName = tp.Name, ProjectDescription = tp.Description, ProjectStatus = tp.ProjectStatus, ProjectDateCreated = tp.Created, ProjectDateDue = tp.Due, ProjectDateComplated = tp.Completed, ProjectActivitesCount = tp.Activities.Count.ToString() }; apv.ProjectDetails = project; #endregion propertyGrid1.SelectedObject = apv; } else if (QualitivityViewPropertiesController.NavigationTreeView.SelectedNode.Tag != null && QualitivityViewPropertiesController.NavigationTreeView.SelectedNode.Tag.GetType() == typeof(CompanyProfile)) { #region | client | var cpi = (CompanyProfile)QualitivityViewPropertiesController.NavigationTreeView.SelectedNode.Tag; var pemRate = Tracked.Settings.LanguageRateGroups.FirstOrDefault(pemr => pemr.Id == cpi.ProfileRate.LanguageRateId); var client = new Client { ClientId = cpi.Id.ToString() }; var clientAddress = new Address { AddressStreet = cpi.Street, AddressZip = cpi.Zip, AddressCity = cpi.City, AddressState = cpi.State, AddressCountry = cpi.Country }; client.ClientAddress = clientAddress; var contactDetails = new ContactDetails { EMail = cpi.Email, WebPage = cpi.Web, Phone = cpi.Phone, FAX = cpi.Fax }; client.ContactDetails = contactDetails; client.ClientVat = cpi.VatCode; client.ClientTax = cpi.TaxCode; var defaultRates = new DefaultRates { HrRate = cpi.ProfileRate.HourlyRateRate, HrRateCurrency = cpi.ProfileRate.HourlyRateCurrency, PemRate = pemRate != null ? pemRate.Name : string.Empty }; client.DefaultRates = defaultRates; apv.ClientProfile = client; #endregion propertyGrid1.SelectedObject = apv; } else { propertyGrid1.SelectedObject = null; } } } else { propertyGrid1.SelectedObject = null; } } catch { // ignore } }
private void InitializeRatesTab() { var acc = new Accordion { CheckBoxMargin = new Padding(2), ContentMargin = new Padding(15, 5, 15, 5), ContentPadding = new Padding(1), Insets = new Padding(5), ControlBackColor = Color.White, ContentBackColor = Color.CadetBlue }; panel_activity_rates_parent.Controls.Add(acc); panel_language_rate.Dock = DockStyle.Fill; panel_hourly_rate.Dock = DockStyle.Fill; panel_custom_rate.Dock = DockStyle.Fill; acc.Add(panel_language_rate, "Language Rate", PluginResources.Select_a_language_rate, 0, true, contentBackColor: Color.Transparent); acc.Add(panel_hourly_rate, "Hourly Rate", PluginResources.Specify_an_hourly_rate, 1, true, contentBackColor: Color.Transparent); acc.Add(panel_custom_rate, "Custom Rate", PluginResources.Specify_a_custom_rate, 0, false, contentBackColor: Color.Transparent); checkBox_hourly_rate_CheckedChanged(null, null); checkBox_pem_rate_CheckedChanged(null, null); checkBox_custome_rate_CheckedChanged(null, null); checkBox_custom_rate.Checked = Activity.CustomRateChecked; textBox_custom_rate_description.Text = Activity.DocumentActivityRates.CustomRateDescription; numericUpDown_custom_rate_total.Value = Convert.ToDecimal(Activity.DocumentActivityRates.CustomRateTotal); textBox_hourly_rate_description.Text = Activity.DocumentActivityRates.HourlyRateDescription; textBox_language_rate_description.Text = Activity.DocumentActivityRates.LanguageRateDescription; if (objectListView_documents.Items.Count > 0) { checkBox_language_rate.Enabled = true; } else { checkBox_language_rate.Enabled = false; checkBox_language_rate.Checked = false; } ActivityRates = Activity.DocumentActivityRates.Clone() as ActivityRates; #region | PEM combobox | comboBox_pem_rates.BeginUpdate(); comboBox_pem_rates.Items.Clear(); var _cbi = new ComboboxItem(@"<empty>", null); comboBox_pem_rates.Items.Add(_cbi); if (IsEdit) { if (Activity.DocumentActivityRates.LanguageRateId > -1 && Activity.DocumentActivityRates.LanguageRateName.Trim() != string.Empty) { var cbi = new ComboboxItem(Activity.DocumentActivityRates.LanguageRateName + @" <saved version>", Activity.DocumentActivityRates.Clone() as ActivityRates); comboBox_pem_rates.Items.Add(cbi); } } foreach (var prg in Tracked.Settings.LanguageRateGroups) { var cbi = new ComboboxItem(prg.Name, prg.Clone() as LanguageRateGroup); comboBox_pem_rates.Items.Add(cbi); } comboBox_pem_rates.Sorted = true; comboBox_pem_rates.EndUpdate(); #endregion if (!IsEdit) { #region | hourly rate | linkLabel_get_default_hourly_rate_LinkClicked(null, null); linkLabel_get_total_hours_elapsed_from_documents_LinkClicked(null, null); calculate_hourly_rate(); if (numericUpDown_hourly_rate_total.Value > 0) { checkBox_hourly_rate.Checked = true; } #endregion #region | PEM Rate | var selectedIndex = 0; var foundPriceRateGroup = false; LanguageRateGroup prg = null; if (CompanyProfile != null && CompanyProfile.Id > -1) { foreach (ComboboxItem cbi in comboBox_pem_rates.Items) { if (cbi.Value != null && cbi.Value.GetType() == typeof(LanguageRateGroup)) { prg = (LanguageRateGroup)cbi.Value; if (prg.Id == CompanyProfile.ProfileRate.LanguageRateId) { foundPriceRateGroup = true; break; } selectedIndex++; } else { selectedIndex++; } } } comboBox_pem_rates.SelectedIndex = foundPriceRateGroup ? selectedIndex : 0; if (objectListView_documents.Items.Count > 0) { checkBox_language_rate.Checked = foundPriceRateGroup; SetActivityRateFromLanguageRate(prg); } #endregion checkBox_includeTagsInComparison.Checked = CompanyProfile == null || CompanyProfile.ComparerOptions.IncludeTagsInComparison; checkBox_group_changes.Checked = CompanyProfile == null || CompanyProfile.ComparerOptions.ConsolidateChanges; comboBox_comparisonType.SelectedIndex = CompanyProfile != null ? CompanyProfile.ComparerOptions.ComparisonType : 0; } else { #region | hourly rate | numericUpDown_hourly_rate_rate.Value = Convert.ToDecimal(Activity.DocumentActivityRates.HourlyRateRate); numericUpDown_hourly_rate_hours.Value = Convert.ToDecimal(Activity.DocumentActivityRates.HourlyRateQuantity); numericUpDown_hourly_rate_total.Value = Convert.ToDecimal(Activity.DocumentActivityRates.HourlyRateTotal); checkBox_hourly_rate.Checked = Activity.HourlyRateChecked; label_hourly_rate_curency.Text = Activity.DocumentActivityRates.HourlyRateCurrency; #endregion #region | PEM Rate | var selectedIndex = 0; var foundPriceRateGroup = false; if (Activity.DocumentActivityRates.LanguageRateId > -1 && Activity.DocumentActivityRates.LanguageRateName.Trim() != string.Empty) { foreach (ComboboxItem cbi in comboBox_pem_rates.Items) { if (cbi.Value != null && cbi.Value.GetType() == typeof(ActivityRates)) { var prg = cbi.Value as ActivityRates; if (prg != null && prg.LanguageRateId == Activity.DocumentActivityRates.LanguageRateId) { foundPriceRateGroup = true; break; } selectedIndex++; } else { selectedIndex++; } } } if (!foundPriceRateGroup) { foreach (ComboboxItem cbi in comboBox_pem_rates.Items) { if (cbi.Value != null && cbi.Value.GetType() == typeof(LanguageRateGroup)) { var prg = (LanguageRateGroup)cbi.Value; if (prg.Id == Activity.DocumentActivityRates.LanguageRateId) { foundPriceRateGroup = true; break; } selectedIndex++; } else { selectedIndex++; } } } comboBox_pem_rates.SelectedIndex = foundPriceRateGroup ? selectedIndex : 0; checkBox_language_rate.Checked = Activity.LanguageRateChecked; numericUpDown_pem_rate_total.Value = Convert.ToDecimal(Activity.DocumentActivityRates.LanguageRateTotal); if (foundPriceRateGroup) { label_rate_currency.Text = Activity.DocumentActivityRates.LanguageRateCurrency; label_hourly_rate_curency.Text = Activity.DocumentActivityRates.HourlyRateCurrency; } else { label_rate_currency.Text = Tracked.Settings.GetGeneralProperty("defaultCurrency").Value; } #endregion checkBox_includeTagsInComparison.Checked = Activity.ComparisonOptions.IncludeTagsInComparison; checkBox_group_changes.Checked = Activity.ComparisonOptions.ConsolidateChanges; comboBox_comparisonType.SelectedIndex = Activity.ComparisonOptions.ComparisonType; } Activity.DocumentActivityRates.CustomRateCurrency = Activity.DocumentActivityRates.HourlyRateCurrency; label_custom_rate_currency.Text = Activity.DocumentActivityRates.CustomRateCurrency; label_hourly_rate_curency_TextChanged(null, null); comboBox_billable_SelectedIndexChanged(null, null); if (comboBox_pem_rates.SelectedIndex == 0) { label_rate_currency.Text = label_hourly_rate_curency.Text; } }