Example #1
0
        private RevisedBudgetOtherCosts CreateInstanceWithSameFlag(YearMonth currentYearMonth)
        {
            //Get an instance of an object
            RevisedBudgetOtherCosts newOC = new RevisedBudgetOtherCosts(this.CurrentConnectionManager);

            //Create primary key
            newOC.IdProject         = this._IdProject;
            newOC.IdPhase           = this._IdPhase;
            newOC.IdWP              = this._IdWP;
            newOC.IdCostCenter      = this._IdCostCenter;
            newOC.IdAssociate       = this._IdAssociate;
            newOC.IdAssociateViewer = this._IdAssociateViewer;
            newOC.YearMonth         = currentYearMonth.Value;

            //Set state flag
            if (this.State == EntityState.New)
            {
                newOC.SetNew();
            }
            if (this.State == EntityState.Modified)
            {
                newOC.SetModified();
            }
            if (this.State == EntityState.Deleted)
            {
                newOC.SetDeleted();
            }

            //Return the object
            return(newOC);
        }
        /// <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);
            }
        }
Example #3
0
        internal void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth)
        {
            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];
                currentOtherCost.Save();

                currentOtherCost            = CreateInstanceWithSameFlag(currentYearMonth);
                currentOtherCost.IdCostType = EOtherCostTypes.ProtoParts;
                currentOtherCost.CostVal    = ProtoPartsList[iteratorPosition];
                currentOtherCost.Save();

                currentOtherCost            = CreateInstanceWithSameFlag(currentYearMonth);
                currentOtherCost.IdCostType = EOtherCostTypes.ProtoTooling;
                currentOtherCost.CostVal    = ProtoToolingList[iteratorPosition];
                currentOtherCost.Save();

                currentOtherCost            = CreateInstanceWithSameFlag(currentYearMonth);
                currentOtherCost.IdCostType = EOtherCostTypes.Trials;
                currentOtherCost.CostVal    = TrialsList[iteratorPosition];
                currentOtherCost.Save();

                currentOtherCost            = CreateInstanceWithSameFlag(currentYearMonth);
                currentOtherCost.IdCostType = EOtherCostTypes.OtherExpenses;
                currentOtherCost.CostVal    = OtherExpensesList[iteratorPosition];
                currentOtherCost.Save();
            }
        }
 /// <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);
     }
 }
Example #5
0
        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();
            }
        }