/// <summary> /// Apply the cost center currency to the current object properties /// </summary> /// <param name="associateCurrency">the associate currency</param> protected override void ApplyCostCenterCurrency(int associateCurrency, CurrencyConverter converter) { CostCenter currentCostCenter = new CostCenter(this.CurrentConnectionManager); currentCostCenter.Id = IdCostCenter; int idCurrency = currentCostCenter.GetCostCenterCurrency().Id; _New = converter.GetConversionValue(_New, associateCurrency, new YearMonth(YearMonth), idCurrency); }
/// <summary> /// Apply the cost center currency to the current object properties /// </summary> /// <param name="associateCurrency">the associate currency</param> protected override void ApplyCostCenterCurrency(int associateCurrency, CurrencyConverter converter) { CostCenter currentCostCenter = new CostCenter(this.CurrentConnectionManager); currentCostCenter.Id = IdCostCenter; int idCurrency = currentCostCenter.GetCostCenterCurrency().Id; if (_ValuedHours != ApplicationConstants.DECIMAL_NULL_VALUE) { _ValuedHours = converter.GetConversionValue(_ValuedHours, associateCurrency, new YearMonth(YearMonth), idCurrency); } _Sales = converter.GetConversionValue(_Sales, associateCurrency, new YearMonth(YearMonth), idCurrency); }
private void ApplyCostCenterCurrency(int idCostCenter, int associateCurrency, CurrencyConverter converter) { CostCenter currentCostCenter = new CostCenter(this.CurrentConnectionManager); currentCostCenter.Id = idCostCenter; int idCurrency = currentCostCenter.GetCostCenterCurrency().Id; _CostVal = converter.GetConversionValue(_CostVal, associateCurrency, new YearMonth(YearMonth), idCurrency); }
internal void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth, bool isAssociateCurrency, int idCostCenter, int associateCurrency, CurrencyConverter converter) { bool splitOtherCostsUniform = (ApplicationConstants.SPLIT_OTHER_COSTS_ALGORYTHM == ApplicationConstants.SPLIT_OTHER_COSTS_ALGORYTHM_UNIFORM); int monthsNo = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1; decimal[] TEList = Rounding.Divide(this._TE, monthsNo); decimal[] ProtoPartsList = Rounding.Divide(this._ProtoParts, monthsNo); decimal[] ProtoToolingList = Rounding.Divide(this._ProtoTooling, monthsNo); decimal[] TrialsList = Rounding.Divide(this._Trials, monthsNo); decimal[] OtherExpensesList = Rounding.Divide(this._OtherExpenses, monthsNo); for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1)) { InitialBudgetOtherCosts currentOtherCost = new InitialBudgetOtherCosts(this.CurrentConnectionManager); if (splitOtherCostsUniform) { int iteratorPosition = currentYearMonth.GetMonthsDiffrence(startYearMonth); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.TE; currentOtherCost.CostVal = TEList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoParts; currentOtherCost.CostVal = ProtoPartsList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoTooling; currentOtherCost.CostVal = ProtoToolingList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.Trials; currentOtherCost.CostVal = TrialsList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.OtherExpenses; currentOtherCost.CostVal = OtherExpensesList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); } else { currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.TE; currentOtherCost.CostVal = (currentYearMonth.Value == endYearMonth.Value ? this._TE : 0); //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoParts; currentOtherCost.CostVal = (currentYearMonth.Value == endYearMonth.Value ? this._ProtoParts : 0); //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoTooling; currentOtherCost.CostVal = (currentYearMonth.Value == endYearMonth.Value ? this._ProtoTooling : 0); //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.Trials; currentOtherCost.CostVal = (currentYearMonth.Value == endYearMonth.Value ? this._Trials : 0); //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.OtherExpenses; currentOtherCost.CostVal = (currentYearMonth.Value == endYearMonth.Value ? this._OtherExpenses : 0); //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); } } }
internal void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth, bool isAssociateCurrency, int idCostCenter, int associateCurrency, CurrencyConverter converter) { int monthsNo = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1; decimal[] TEList = Rounding.Divide(this._NewCosts.TE, monthsNo); decimal[] ProtoPartsList = Rounding.Divide(this._NewCosts.ProtoParts, monthsNo); decimal[] ProtoToolingList = Rounding.Divide(this._NewCosts.ProtoTooling, monthsNo); decimal[] TrialsList = Rounding.Divide(this._NewCosts.Trials, monthsNo); decimal[] OtherExpensesList = Rounding.Divide(this._NewCosts.OtherExpenses, monthsNo); for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1)) { int iteratorPosition = currentYearMonth.GetMonthsDiffrence(startYearMonth); RevisedBudgetOtherCosts currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.TE; currentOtherCost.CostVal = TEList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoParts; currentOtherCost.CostVal = ProtoPartsList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoTooling; currentOtherCost.CostVal = ProtoToolingList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.Trials; currentOtherCost.CostVal = TrialsList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.OtherExpenses; currentOtherCost.CostVal = OtherExpensesList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); } }
/// <summary> /// Saves the budgets from budgetList to the database, applying an exchange rate conversion /// </summary> /// <param name="budgetList">list of ReforecastBudget objects to be saved to the database</param> /// <param name="displayedDataType">the type of data to be saved (one of the values in the Constants region)</param> /// <param name="amountScaleOption">the amount scale in which the data is represented</param> /// <param name="associateCurrency">the currency of the associate saving the budget</param> /// <param name="converter">converter object used to exchange values from one currency to another</param> public void SaveAll(List <ReforecastBudget> budgetList, int displayedDataType, AmountScaleOption amountScaleOption, int associateCurrency, CurrencyConverter converter) { //Begin the transaction BeginTransaction(); try { foreach (ReforecastBudget budget in budgetList) { budget.UpdateMasterRecord(); budget.ApplyAmountScaleOption(amountScaleOption); if (displayedDataType > DATA_VALUE_HOURS) { budget.ApplyCostCenterCurrency(associateCurrency, converter); } budget.UpdateDetail(displayedDataType); } //Commit the transaction CommitTransaction(); } catch (Exception ex) { //If, for any reason, an exception was thrown, rollback the transaction RollbackTransaction(); throw new IndException(ex); } }
private void ApplyCurrencyForCostCenterTable(DataSet sourceDS, int associateCurrency, CurrencyConverter converter, int dsIndex) { DataTable sourceTable = sourceDS.Tables[2]; //Cycle through each row of the cost center table foreach (DataRow row in sourceTable.Rows) { //Get the cost center currency for the current row int costCenterCurrency = (int)row["IdCurrency"]; //If both currencies are the same, do nothing if (costCenterCurrency == associateCurrency) { continue; } BudgetColumnsCalculationsList columns = this.GetCalculatedColumns(dsIndex); foreach (KeyValuePair <string, EBudgetCalculationMethod> entry in columns) { //Get the current calculated column name string columnName = entry.Key; if (sourceTable.Columns[columnName].DataType == typeof(decimal)) { //Gets the current value of the column decimal val = (decimal)row[columnName]; //Get the parrent datarow DataRow wpRow = GetParentWPRow(sourceTable.DataSet, row); //Get the start year month and end year month for the currenct cost center YearMonth startYearMonth = new YearMonth((int)wpRow["StartYearMonth"]); YearMonth endYearMonth = new YearMonth((int)wpRow["EndYearMonth"]); //Calculate the existing value for each month in the date interval int numberOfMonths = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1; decimal[] yearMonthValues = Rounding.Divide(val, numberOfMonths); decimal newValue = 0; //Calculates the new value for each month and sum it for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1)) { int valueIterator = currentYearMonth.GetMonthsDiffrence(startYearMonth); newValue += converter.GetConversionValue(yearMonthValues[valueIterator], costCenterCurrency, currentYearMonth, associateCurrency); } //Updates the value row[columnName] = Rounding.Round(newValue); } } } }
/// <summary> /// Transforms the datasource by updating the decimal values with the exchange rate of the associate currency /// </summary> /// <param name="sourceDS">The source data set</param> /// <param name="currentUser">The current logged user</param> protected override void ApplyAssociateCurrency(DataSet sourceDS, CurrentUser currentUser, CurrencyConverter converter, int dsIndex) { ApplyCurrencyForCostCenterTable(sourceDS, currentUser.IdCurrency, converter, dsIndex); UpdateParentTableValues(sourceDS.Tables[1], sourceDS.Tables[2], new string[] { "IdPhase", "IdWP" }, dsIndex); UpdateParentTableValues(sourceDS.Tables[0], sourceDS.Tables[1], new string[] { "IdPhase" }, dsIndex); }
/// <summary> /// Updates the budget (transactions enabled) /// </summary> /// <param name="startYearMonth"></param> /// <param name="endYearMonth"></param> /// <param name="otherCosts"></param> /// <param name="isAssociateCurrency"></param> /// <param name="associateCurrency"></param> /// <param name="converter"></param> /// <param name="scaleOption"></param> public void UpdateBudget(YearMonth startYearMonth, YearMonth endYearMonth, InitialBudgetOtherCosts otherCosts, bool isAssociateCurrency, int associateCurrency, CurrencyConverter converter, AmountScaleOption scaleOption, bool insertMasterRecord) { BeginTransaction(); try { if (insertMasterRecord) { InsertMasterRecord(); } SaveSplitted(startYearMonth, endYearMonth, otherCosts, isAssociateCurrency, associateCurrency, converter, scaleOption); CommitTransaction(); } catch (Exception exc) { RollbackTransaction(); throw new IndException(exc); } }
/// <summary> /// Save the Initial Budget object by splitting it into several object accordin to /// startYearMonth and endYearMonth values. /// </summary> /// <param name="startYearMonth">The startYearMonth value</param> /// <param name="endYearMonth">The endYearMonth value</param> private void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth, InitialBudgetOtherCosts otherCosts, bool isAssociateCurrency, int associateCurrency, CurrencyConverter converter, AmountScaleOption scaleOption) { try { //Get the months difference int monthsNo = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1; int[] totalHours = Rounding.Divide(this.TotalHours, monthsNo); decimal[] sales = Rounding.Divide(this.Sales, monthsNo); decimal[] valHours = new decimal[monthsNo]; if (this.ValuedHours != ApplicationConstants.DECIMAL_NULL_VALUE) { valHours = Rounding.Divide(this.ValuedHours, monthsNo); } else { for (int i = 0; i < monthsNo; i++) { valHours[i] = ApplicationConstants.DECIMAL_NULL_VALUE; } } int[] detailsIds = new int[monthsNo]; //Iterate through each month and construct the InitialBudget object for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1)) { //construct a new initial budget object InitialBudget newBudget = new InitialBudget(this.CurrentConnectionManager); newBudget.IdProject = this.IdProject; newBudget.IdPhase = this.IdPhase; newBudget.IdWP = this.IdWP; newBudget.IdCostCenter = this.IdCostCenter; newBudget.IdAssociate = this.IdAssociate; newBudget.YearMonth = currentYearMonth.Value; newBudget.TotalHours = totalHours[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; newBudget.ValuedHours = valHours[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; newBudget.Sales = sales[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; if (this.State == EntityState.New) { newBudget.SetNew(); } if (this.State == EntityState.Modified) { newBudget.SetModified(); } if (this.State == EntityState.Deleted) { newBudget.SetDeleted(); } //Apply the cost center currency if this is the case if (isAssociateCurrency) { newBudget.ApplyCostCenterCurrency(associateCurrency, converter); } //Apply the amount scale newBudget.ApplyAmountScaleOption(scaleOption); //Saves the new budget if (this.State == EntityState.New) { IdDetail = newBudget.Save(); } else { newBudget.Save(); } } //Insert Other cost object if (otherCosts != null) { otherCosts.SaveSplitted(startYearMonth, endYearMonth, isAssociateCurrency, this.IdCostCenter, associateCurrency, converter); } } catch (Exception exc) { throw new IndException(exc); } }
/// <summary> /// Apply the associate currency to the current object properties /// </summary> /// <param name="associateCurrency">the associate currency</param> protected virtual void ApplyCostCenterCurrency(int associateCurrency, CurrencyConverter converter) { }
public virtual void ApplyDataSourceTransformations(DataSet sourceDS, bool isAssociateCurrency, CurrentUser currentUser, CurrencyConverter converter, int dsIndex) { if (!isAssociateCurrency) { RemoveNonCalculableValues(sourceDS.Tables[0], dsIndex); RemoveNonCalculableValues(sourceDS.Tables[1], dsIndex); } }
/// <summary> /// Transforms the datasource by updating the decimal values with the exchange rate of the associate currency /// </summary> /// <param name="sourceDS">The source dataset</param> /// <param name="currentUser">The current logged user</param> /// <param name="dsIndex">the index of the dataset for which the calculations are made (in revised budget there are 3 tabs -> 3 datasets)</param> protected virtual void ApplyAssociateCurrency(DataSet sourceDS, CurrentUser currentUser, CurrencyConverter converter, int dsIndex) { }
/// <summary> /// Save the Revised Budget object by splitting it into several object according to /// startYearMonth and endYearMonth values. /// </summary> /// <param name="startYearMonth">The startYearMonth value</param> /// <param name="endYearMonth">The endYearMonth value</param> /// <param name="otherCosts">other costs object that will be saved if it is not null</param> /// <param name="isAssociateCurrency">specifies if a conversion must be made from the associate currency to the cost center currency before saving</param> /// <param name="associateCurrency">the id of the associate currency</param> /// <param name="converter">the currency converter object to be used for the currency conversion</param> /// <param name="scaleOption">the amount scale from the budget interface (if it is not unit, a multiplication must be made before saving)</param> private void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth, RevisedBudgetOtherCosts otherCosts, bool isAssociateCurrency, int associateCurrency, CurrencyConverter converter, AmountScaleOption scaleOption) { //TODO: Implement transactions //Get the months difference int monthsNo = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1; int[] newHours = Rounding.Divide(this.NewHours, monthsNo); decimal[] newSales = Rounding.Divide(this.NewSales, monthsNo); //Iterate through each month and construct the InitialBudget object for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1)) { //construct a new revised budget object RevisedBudget newBudget = new RevisedBudget(this.CurrentConnectionManager); newBudget.IdProject = this.IdProject; newBudget.IdPhase = this.IdPhase; newBudget.IdWP = this.IdWP; newBudget.IdCostCenter = this.IdCostCenter; newBudget.IdAssociate = this.IdAssociate; newBudget.YearMonth = currentYearMonth.Value; newBudget.NewHours = newHours[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; newBudget.NewSales = newSales[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; newBudget.SaveHours = this.SaveHours; if (this.State == EntityState.New) { newBudget.SetNew(); } if (this.State == EntityState.Modified) { newBudget.SetModified(); } if (this.State == EntityState.Deleted) { newBudget.SetDeleted(); } //Apply the cost center currency if this is the case if (isAssociateCurrency) { newBudget.ApplyCostCenterCurrency(associateCurrency, converter); } //Apply the amount scale newBudget.ApplyAmountScaleOption(scaleOption); //Saves the new budget int idNewBudget = newBudget.Save(); } //Insert Other cost object if (otherCosts != null) { otherCosts.SaveSplitted(startYearMonth, endYearMonth, isAssociateCurrency, this.IdCostCenter, associateCurrency, converter); } }
/// <summary> /// Saves the revised budget to the database /// </summary> /// <param name="startYearMonth">start yearmonth of the work package associated to this budget entry (cost center)</param> /// <param name="endYearMonth">end yearmonth of the work package associated to this budget entry (cost center)</param> /// <param name="otherCosts">other costs object which is saved to the database</param> /// <param name="isAssociateCurrency">specifies whether the data is in the currency of the associate /// (if this is the case, the values must be converted to the cost center currency before saving)</param> /// <param name="associateCurrency">the currency of the associate</param> /// <param name="converter">the converter object used to convert values between currencies</param> /// <param name="scaleOption">the scale option in which the values are represented (if it is different than unit, it will be /// converted before saving)</param> /// <param name="insertMasterRecord">specifies whether a master record will be inserted in the BUDGET_REVISED table</param> public void SaveBudget(YearMonth startYearMonth, YearMonth endYearMonth, RevisedBudgetOtherCosts otherCosts, bool isAssociateCurrency, int associateCurrency, CurrencyConverter converter, AmountScaleOption scaleOption, bool insertMasterRecord) { //Begin the transaction BeginTransaction(); try { //Insert the master record only if it is necessary if (insertMasterRecord) { InsertMasterRecord(); } //Save the budget SaveSplitted(startYearMonth, endYearMonth, otherCosts, isAssociateCurrency, associateCurrency, converter, scaleOption); //Commit the transaction CommitTransaction(); } catch (Exception exc) { //If, for any reason, an exception was thrown, rollback the transaction RollbackTransaction(); throw new IndException(exc); } }