コード例 #1
0
        private InitialBudgetOtherCosts CreateInstanceWithSameFlag(YearMonth yearMonth)
        {
            //Get an instance of an object
            InitialBudgetOtherCosts newOC = new InitialBudgetOtherCosts(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         = yearMonth.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);
        }
コード例 #2
0
        /// <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)
        {
            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   = Rounding.Divide(this.ValuedHours, monthsNo);
                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();
                    }

                    //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);
                }
            }
            catch (Exception exc)
            {
                throw new IndException(exc);
            }
        }
コード例 #3
0
        /// <summary>
        /// Updates the budget (transactions enabled)
        /// </summary>
        /// <param name="startYearMonth"></param>
        /// <param name="endYearMonth"></param>
        /// <param name="otherCosts"></param>
        public void UpdateBudget(YearMonth startYearMonth, YearMonth endYearMonth, InitialBudgetOtherCosts otherCosts, bool insertMasterRecord)
        {
            BeginTransaction();

            try
            {
                if (insertMasterRecord)
                {
                    InsertMasterRecord();
                }

                SaveSplitted(startYearMonth, endYearMonth, otherCosts);

                CommitTransaction();
            }
            catch (Exception exc)
            {
                RollbackTransaction();
                throw new IndException(exc);
            }
        }
コード例 #4
0
        /// <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);
            }
        }
コード例 #5
0
        internal void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth)
        {
            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];
                    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();
                }
                else
                {
                    currentOtherCost            = CreateInstanceWithSameFlag(currentYearMonth);
                    currentOtherCost.IdCostType = EOtherCostTypes.TE;
                    currentOtherCost.CostVal    = (currentYearMonth.Value == endYearMonth.Value ? this._TE : 0);
                    currentOtherCost.Save();

                    currentOtherCost            = CreateInstanceWithSameFlag(currentYearMonth);
                    currentOtherCost.IdCostType = EOtherCostTypes.ProtoParts;
                    currentOtherCost.CostVal    = (currentYearMonth.Value == endYearMonth.Value ? this._ProtoParts : 0);
                    currentOtherCost.Save();

                    currentOtherCost            = CreateInstanceWithSameFlag(currentYearMonth);
                    currentOtherCost.IdCostType = EOtherCostTypes.ProtoTooling;
                    currentOtherCost.CostVal    = (currentYearMonth.Value == endYearMonth.Value ? this._ProtoTooling : 0);
                    currentOtherCost.Save();

                    currentOtherCost            = CreateInstanceWithSameFlag(currentYearMonth);
                    currentOtherCost.IdCostType = EOtherCostTypes.Trials;
                    currentOtherCost.CostVal    = (currentYearMonth.Value == endYearMonth.Value ? this._Trials : 0);
                    currentOtherCost.Save();

                    currentOtherCost            = CreateInstanceWithSameFlag(currentYearMonth);
                    currentOtherCost.IdCostType = EOtherCostTypes.OtherExpenses;
                    currentOtherCost.CostVal    = (currentYearMonth.Value == endYearMonth.Value ? this._OtherExpenses : 0);
                    currentOtherCost.Save();
                }
            }
        }
コード例 #6
0
        /// <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);
            }
        }
コード例 #7
0
        /// <summary>
        /// Saves the budget
        /// </summary>
        /// <param name="currentProject">The current project used</param>
        /// <param name="currentUser">The current logged user</param>
        /// <param name="FollowUpIdAssociate">The associate id if this is called from the follow up</param>
        /// <param name="otherCost">The other cost object associated with this budget</param>
        /// <param name="startYearMonth">The StartYearMonth</param>
        /// <param name="endYearMonth">the EndYearMonth</param>
        /// <param name="evidenceButtonVisible">Specify if the Submit button should be visible after this operation</param>
        public void InsertBudget(CurrentProject currentProject, CurrentUser currentUser, int FollowUpIdAssociate, InitialBudgetOtherCosts otherCost, YearMonth startYearMonth, YearMonth endYearMonth, out bool evidenceButtonVisible)
        {
            BeginTransaction();

            //Initialize the out paramter
            evidenceButtonVisible = false;

            try
            {
                //TODO: Call this method only if this is the case
                InsertMasterRecord();

                //Constructs a new FollowUpInitialBudget object
                FollowUpInitialBudget fIBudget = new FollowUpInitialBudget(this.CurrentConnectionManager);

                //Get the current budget state
                #region Get Current Budget State

                string budgetState = String.Empty;
                //Initialize the follow up buget object
                fIBudget.IdProject   = currentProject.Id;
                fIBudget.IdAssociate = ((FollowUpIdAssociate == ApplicationConstants.BUDGET_DIRECT_ACCESS ? ((currentUser.UserRole.Id == ApplicationConstants.ROLE_BUSINESS_ADMINISTATOR || currentUser.UserRole.Id == ApplicationConstants.ROLE_KEY_USER) && currentUser.IdImpersonatedAssociate > 0 ? currentUser.IdImpersonatedAssociate : currentUser.IdAssociate) : FollowUpIdAssociate));

                //Get the budget state
                DataSet dsButtons = fIBudget.GetInitialBudgetStateForEvidence("GetInitialBudgetStateForEvidence");
                //Find out the budget state from the dataset
                if (dsButtons != null)
                {
                    if (dsButtons.Tables[0].Rows.Count > 0)
                    {
                        budgetState = dsButtons.Tables[0].Rows[0]["StateCode"].ToString();
                    }
                    else
                    {
                        budgetState = ApplicationConstants.BUDGET_STATE_NONE;
                    }
                }
                else
                {
                    //Do not rollback here, exception will be caught later in this method
                    throw new IndException("This associate is not in CORETEAM");
                }
                #endregion Get Current Budget State
                //If the budget state is NONE than save it to OPEN
                if (budgetState == ApplicationConstants.BUDGET_STATE_NONE || budgetState == ApplicationConstants.BUDGET_STATE_UPLOADED)
                {
                    fIBudget.StateCode = ApplicationConstants.BUDGET_STATE_OPEN;
                    fIBudget.SetModified();
                    fIBudget.Save();

                    evidenceButtonVisible = true;
                }


                //Splits the budget into details and save them
                SaveSplitted(startYearMonth, endYearMonth, otherCost);

                CommitTransaction();
            }
            catch (Exception exc)
            {
                RollbackTransaction();
                throw new IndException(exc);
            }
        }