Ejemplo n.º 1
0
        /// <summary>
        /// Copy Tasks from other Phase
        /// </summary>
        /// <param name="fromPhase">from phase</param>
        /// <returns>number of tasks copied</returns>
        public int CopyTasksFrom(MProjectTypePhase fromPhase)
        {
            if (fromPhase == null)
            {
                return(0);
            }
            int count = 0;

            //	Copy Type Tasks
            MProjectTypeTask[] fromTasks = fromPhase.GetTasks();
            for (int i = 0; i < fromTasks.Length; i++)
            {
                MProjectTask toTask = new MProjectTask(this, fromTasks[i]);
                if (toTask.Save())
                {
                    count++;
                }
            }
            log.Fine("#" + count + " - " + fromPhase);
            if (fromTasks.Length != count)
            {
                log.Log(Level.SEVERE, "Count difference - TypePhase=" + fromTasks.Length + " <> Saved=" + count);
            }

            return(count);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Copy Tasks from other Phase
        /// </summary>
        /// <param name="fromPhase">from phase</param>
        /// <returns>number of tasks copied</returns>
        public int CopyTasksFrom(MProjectTypePhase fromPhase)
        {
            if (fromPhase == null)
            {
                return(0);
            }
            int count         = 0;
            int tasklinecount = 0;

            //	Copy Type Tasks
            MProjectTypeTask[] fromTasks = fromPhase.GetTasks();
            for (int i = 0; i < fromTasks.Length; i++)
            {
                MProjectTask toTask = new MProjectTask(this, fromTasks[i]);
                if (toTask.Save())
                {
                    // check if table exists then only it will copy the task lines
                    if (PO.Get_Table_ID("C_TaskLine") > 0)
                    {
                        tasklinecount = CopyMTaskLines(fromTasks[i].GetC_Task_ID(), toTask.GetC_ProjectTask_ID());
                    }
                    count++;
                }
            }
            log.Fine("#" + count + " - " + fromPhase + ", #" + tasklinecount);
            if (fromTasks.Length != count)
            {
                log.Log(Level.SEVERE, "Count difference - TypePhase=" + fromTasks.Length + " <> Saved=" + count);
            }

            return(count);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Copy Tasks from other Phase
        /// </summary>
        /// <param name="fromPhase">from phase</param>
        /// <returns>number of tasks copied</returns>
        public int CopyTasksFrom(MProjectPhase fromPhase)
        {
            if (fromPhase == null)
            {
                return(0);
            }
            int count = 0;

            //
            MProjectTask[] myTasks   = GetTasks();
            MProjectTask[] fromTasks = fromPhase.GetTasks();
            //	Copy Project Tasks
            for (int i = 0; i < fromTasks.Length; i++)
            {
                //	Check if Task already exists
                int  C_Task_ID = fromTasks[i].GetC_Task_ID();
                bool exists    = false;
                if (C_Task_ID == 0)
                {
                    exists = false;
                }
                else
                {
                    for (int ii = 0; ii < myTasks.Length; ii++)
                    {
                        if (myTasks[ii].GetC_Task_ID() == C_Task_ID)
                        {
                            exists = true;
                            break;
                        }
                    }
                }
                //	Phase exist
                if (exists)
                {
                    log.Info("Task already exists here, ignored - " + fromTasks[i]);
                }
                else
                {
                    MProjectTask toTask = new MProjectTask(GetCtx(), 0, Get_TrxName());
                    PO.CopyValues(fromTasks[i], toTask, GetAD_Client_ID(), GetAD_Org_ID());
                    toTask.SetC_ProjectPhase_ID(GetC_ProjectPhase_ID());
                    if (toTask.Save())
                    {
                        count++;
                    }
                }
            }
            if (fromTasks.Length != count)
            {
                log.Warning("Count difference - ProjectPhase=" + fromTasks.Length + " <> Saved=" + count);
            }

            return(count);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Generate Appointments if Owner is selected at Task Tab.
        /// </summary>
        private void GenerateAppointment()
        {
            if (C_ProjectTask_ID != 0)
            {
                sql = "select name from c_campaign where c_campaign_id = (select c_campaign_id from c_project where c_project_id = (select c_project_id "
                      + " from c_projectphase where c_projectphase_id = (select c_projectphase_id from c_projecttask where c_projecttask_id = " + C_ProjectTask_ID + ")))";
                string name = Util.GetValueOfString(DB.ExecuteScalar(sql, null, Get_Trx()));
                VAdvantage.Model.MProjectTask task = new VAdvantage.Model.MProjectTask(GetCtx(), C_ProjectTask_ID, Get_Trx());

                int AppointmentsInfo_ID = Util.GetValueOfInt(task.GetAppointmentsInfo_ID());
                sql = "select count(*) from AppointmentsInfo where AppointmentsInfo_ID = " + AppointmentsInfo_ID;
                int res = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx()));
                if (res == 0)
                {
                    string subject    = name + "_" + task.GetName();
                    string desc       = task.GetDescription();
                    int    AD_User_ID = task.GetSalesRep_ID();
                    //DateTime? sDate = task.
                    if (AD_User_ID != 0)
                    {
                        VAdvantage.Model.X_AppointmentsInfo appoint = new VAdvantage.Model.X_AppointmentsInfo(GetCtx(), 0, Get_Trx());
                        appoint.SetAD_Client_ID(GetCtx().GetAD_Client_ID());
                        appoint.SetAD_Org_ID(GetCtx().GetAD_Org_ID());
                        appoint.SetSubject(subject);
                        appoint.SetStartDate(task.GetStartDate());
                        appoint.SetEndDate(task.GetEndDate());
                        appoint.SetStatus(3);
                        appoint.SetDescription(task.GetDescription());
                        appoint.SetAppointmentCategory_ID(1000000);
                        appoint.SetIsRead(true);
                        appoint.SetAD_User_ID(AD_User_ID);
                        appoint.SetIsPrivate(false);
                        appoint.SetPriorityKey(5);
                        appoint.SetIsTask(true);
                        if (!appoint.Save(Get_Trx()))
                        {
                            log.SaveError("AppointmentNotSaved", "AppointmentNotSaved");
                            msg = Msg.GetMsg(GetCtx(), "AppointmentNotSaved");
                            //return msg;
                        }
                        task.SetAppointmentsInfo_ID(appoint.GetAppointmentsInfo_ID());
                        if (!task.Save(Get_Trx()))
                        {
                            log.SaveError("TaskNotSaved", "TaskNotSaved");
                        }
                        count = count++;
                        msg   = Msg.GetMsg(GetCtx(), "AppointmentSaved");
                    }
                    else
                    {
                        msg = Msg.GetMsg(GetCtx(), "OwnerNotSelected");
                        // return msg;
                    }
                }
                else
                {
                    string subject    = name + "_" + task.GetName();
                    string desc       = task.GetDescription();
                    int    AD_User_ID = task.GetSalesRep_ID();
                    //DateTime? sDate = task.
                    if (AD_User_ID != 0)
                    {
                        VAdvantage.Model.X_AppointmentsInfo appoint = new VAdvantage.Model.X_AppointmentsInfo(GetCtx(), Util.GetValueOfInt(task.GetAppointmentsInfo_ID()), Get_Trx());
                        appoint.SetAD_Client_ID(GetCtx().GetAD_Client_ID());
                        appoint.SetAD_Org_ID(GetCtx().GetAD_Org_ID());
                        appoint.SetSubject(subject);
                        appoint.SetStartDate(task.GetStartDate());
                        appoint.SetEndDate(task.GetEndDate());
                        appoint.SetStatus(3);
                        appoint.SetDescription(task.GetDescription());
                        appoint.SetAppointmentCategory_ID(1000000);
                        appoint.SetIsRead(true);
                        appoint.SetAD_User_ID(AD_User_ID);
                        appoint.SetIsPrivate(false);
                        appoint.SetIsTask(true);
                        if (!appoint.Save(Get_Trx()))
                        {
                            log.SaveError("AppointmentNotSaved", "AppointmentNotSaved");
                            msg = Msg.GetMsg(GetCtx(), "AppointmentNotSaved");
                            // return msg;
                        }
                        task.SetAppointmentsInfo_ID(appoint.GetAppointmentsInfo_ID());
                        if (!task.Save(Get_Trx()))
                        {
                            log.SaveError("TaskNotSaved", "TaskNotSaved");
                        }
                        count = count + 1;
                        msg   = Msg.GetMsg(GetCtx(), "AppointmentSaved");
                    }
                    else
                    {
                        msg = Msg.GetMsg(GetCtx(), "OwnerNotSelected");
                        // return msg;
                    }
                }
            }
        }
        /// <summary>
        /// Update Header
        /// </summary>
        private void UpdateHeader()
        {
            int id     = GetC_ProjectTask_ID();
            int projID = 0;

            if (id == 0)
            {
                projID = GetC_Project_ID();                    // Marketing Campaign Window
            }
            else
            {
                //Used transaction because total was not updating on header
                string Sql = "SELECT C_Project_ID FROM C_ProjectPhase WHERE C_ProjectPhase_ID in(select C_ProjectPhase_ID FROM" +
                             " C_ProjectTask WHERE C_ProjectTask_ID =" + id + ")";
                projID = Util.GetValueOfInt(DB.ExecuteScalar(Sql, null, Get_TrxName()));
            }
            //Used transaction because total was not updating on header
            string sql   = "SELECT IsOpportunity FROM C_Project WHERE C_Project_ID = " + projID;
            string isOpp = Util.GetValueOfString(DB.ExecuteScalar(sql, null, Get_TrxName()));
            //Amit
            string isCam = Util.GetValueOfString(DB.ExecuteScalar("SELECT IsCampaign FROM C_Project WHERE C_Project_ID = " + projID, null, Get_TrxName()));

            if (isOpp.Equals("N") && isCam.Equals("N") && id != 0)
            {
                // set sum of planned Amount from task line to task
                MProjectTask tsk = new MProjectTask(GetCtx(), id, Get_Trx());
                //Used transaction because total was not updating on header
                decimal plannedAmt = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(pl.PlannedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_ProjectTask_ID = " + id, null, Get_TrxName()));
                tsk.SetPlannedAmt(plannedAmt);
                tsk.Save();
            }
            //Amit
            else if (isOpp.Equals("N") && isCam.Equals("N") && id == 0 && GetC_ProjectPhase_ID() != 0)
            {
                //Used transaction because total was not updating on header
                MProjectPhase projectPhase = new MProjectPhase(GetCtx(), GetC_ProjectPhase_ID(), Get_TrxName());
                decimal       plnAmt       = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(pl.PlannedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_ProjectPhase_ID = " + GetC_ProjectPhase_ID() + " AND pl.C_Project_ID = " + projID, null, Get_TrxName()));
                projectPhase.SetPlannedAmt(plnAmt);
                projectPhase.Save();
            }
            else if (isOpp.Equals("Y"))                             // Opportunity Window
            {
                //Used transaction because total was not updating on header
                MProject prj    = new MProject(GetCtx(), projID, Get_TrxName());
                decimal  plnAmt = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(pl.PlannedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + projID, null, Get_TrxName()));
                prj.SetPlannedAmt(plnAmt);
                prj.Save();

                if (VAdvantage.Utility.Env.IsModuleInstalled("VA077_"))
                {
                    sql = @"UPDATE C_Project SET VA077_TotalMarginAmt=(SELECT ROUND(Sum(VA077_MarginAmt),2) FROM C_ProjectLine 
                            WHERE C_PROJECT_ID=" + projID + @" AND IsActive='Y'),
                            VA077_TotalPurchaseAmt=(SELECT ROUND(Sum(VA077_PurchaseAmt),2) FROM C_ProjectLine 
                            WHERE C_PROJECT_ID=" + projID + @" AND IsActive='Y'),
                            VA077_MarginPercent=(SELECT CASE WHEN Sum(PlannedAmt) > 0 Then 
                                                 ROUND(((Sum(PlannedAmt)- Sum(NVL(VA077_PurchaseAmt,0)))/Sum(PlannedAmt)*100),2) ELSE 0  END 
                                                 FROM C_ProjectLine WHERE C_PROJECT_ID=" + projID + @" AND IsActive='Y') 
                            WHERE C_Project_ID=" + projID;

                    int no = DB.ExecuteQuery(sql, null, Get_TrxName());
                    if (no != 1)
                    {
                        log.Log(Level.SEVERE, "updateHeader - #" + no);
                    }
                }
            }
            else if (id != 0)
            {
                MProjectTask tsk = new MProjectTask(GetCtx(), id, Get_TrxName());
                //Used transaction because total was not updating on header
                decimal plannedAmt = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(pl.PlannedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_ProjectTask_ID = " + id, null, Get_TrxName()));
                tsk.SetPlannedAmt(plannedAmt);
                tsk.Save();
            }
            else
            {
                sql = "UPDATE C_Project p SET " +
                      "PlannedAmt=(SELECT COALESCE(SUM(pl.PlannedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      ",PlannedQty=(SELECT COALESCE(SUM(pl.PlannedQty),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      ",PlannedMarginAmt=(SELECT COALESCE(SUM(pl.PlannedMarginAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      ",CommittedAmt=(SELECT COALESCE(SUM(pl.CommittedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      ",CommittedQty=(SELECT COALESCE(SUM(pl.CommittedQty),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      ",InvoicedAmt=(SELECT COALESCE(SUM(pl.InvoicedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      ", InvoicedQty =(SELECT COALESCE(SUM(pl.InvoicedQty),0) FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      " WHERE p.C_Project_ID=" + GetC_Project_ID();
                int no = DB.ExecuteQuery(sql, null, Get_TrxName());

                if (no != 1)
                {
                    log.Log(Level.SEVERE, "updateHeader - #" + no);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Update Header
        /// </summary>
        private void UpdateHeader()
        {
            int id     = GetC_ProjectTask_ID();
            int projID = 0;

            if (id == 0)
            {
                projID = GetC_Project_ID();                    // Marketing Campaign Window
            }
            else
            {
                string Sql = "SELECT C_Project_ID FROM C_ProjectPhase WHERE C_ProjectPhase_ID in(select C_ProjectPhase_ID FROM" +
                             " C_ProjectTask WHERE C_ProjectTask_ID =" + id + ")";
                projID = Util.GetValueOfInt(DB.ExecuteScalar(Sql, null, null));
            }
            string sql   = "SELECT IsOpportunity FROM C_Project WHERE C_Project_ID = " + projID;
            string isOpp = Util.GetValueOfString(DB.ExecuteScalar(sql, null, null));
            //Amit
            string isCam = Util.GetValueOfString(DB.ExecuteScalar("SELECT IsCampaign FROM C_Project WHERE C_Project_ID = " + projID));

            if (isOpp.Equals("N") && isCam.Equals("N") && id != 0)
            {
                // set sum of planned Amount from task line to task
                MProjectTask tsk        = new MProjectTask(GetCtx(), id, Get_Trx());
                decimal      plannedAmt = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(pl.PlannedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_ProjectTask_ID = " + id));
                tsk.SetPlannedAmt(plannedAmt);
                tsk.Save();
            }
            //Amit
            else if (isOpp.Equals("N") && isCam.Equals("N") && id == 0 && GetC_ProjectPhase_ID() != 0)
            {
                MProjectPhase projectPhase = new MProjectPhase(GetCtx(), GetC_ProjectPhase_ID(), null);
                decimal       plnAmt       = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(pl.PlannedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_ProjectPhase_ID = " + GetC_ProjectPhase_ID() + " AND pl.C_Project_ID = " + projID));
                projectPhase.SetPlannedAmt(plnAmt);
                projectPhase.Save();
            }
            else if (isOpp.Equals("Y"))                             // Opportunity Window
            {
                MProject prj    = new MProject(GetCtx(), projID, Get_TrxName());
                decimal  plnAmt = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(pl.PlannedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + projID));
                prj.SetPlannedAmt(plnAmt);
                prj.Save();
            }
            else if (id != 0)
            {
                MProjectTask tsk        = new MProjectTask(GetCtx(), id, Get_TrxName());
                decimal      plannedAmt = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(pl.PlannedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_ProjectTask_ID = " + id));
                tsk.SetPlannedAmt(plannedAmt);
                tsk.Save();
            }
            else
            {
                sql = "UPDATE C_Project p SET " +
                      "PlannedAmt=(SELECT COALESCE(SUM(pl.PlannedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      ",PlannedQty=(SELECT COALESCE(SUM(pl.PlannedQty),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      ",PlannedMarginAmt=(SELECT COALESCE(SUM(pl.PlannedMarginAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      ",CommittedAmt=(SELECT COALESCE(SUM(pl.CommittedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      ",CommittedQty=(SELECT COALESCE(SUM(pl.CommittedQty),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      ",InvoicedAmt=(SELECT COALESCE(SUM(pl.InvoicedAmt),0)  FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      ", InvoicedQty =(SELECT COALESCE(SUM(pl.InvoicedQty),0) FROM C_ProjectLine pl WHERE pl.IsActive = 'Y' AND pl.C_Project_ID = " + GetC_Project_ID() + ")" +
                      " WHERE p.C_Project_ID=" + GetC_Project_ID();
                int no = DB.ExecuteQuery(sql, null, Get_TrxName());

                if (no != 1)
                {
                    log.Log(Level.SEVERE, "updateHeader - #" + no);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// To copy task from other phase to new phase
        /// </summary>
        /// <param name="fromPhase">From Phase</param>
        /// <param name="toPhase">To Phase</param>
        /// <returns></returns>
        public int CopyTasksFrom(MProjectPhase fromPhase, MProjectPhase toPhase)
        {
            if (fromPhase == null)
            {
                return(0);
            }
            int           count = 0;
            ValueNamePair pp = null; StringBuilder msg = new StringBuilder();

            MProjectTask[] myTasks = GetTasks();
            MProjectTask[] fromTasks = fromPhase.GetTasks();
            int            C_Task_ID = 0; bool exists = false;

            //	Copy Project Tasks
            for (int i = 0; i < fromTasks.Length; i++)
            {
                //	Check if Task already exists
                C_Task_ID = fromTasks[i].GetC_ProjectTask_ID();
                exists    = false;
                if (C_Task_ID == 0)
                {
                    exists = false;
                }
                else
                {
                    for (int ii = 0; ii < myTasks.Length; ii++)
                    {
                        if (myTasks[ii].GetC_ProjectTask_ID() == C_Task_ID)
                        {
                            exists = true;
                            break;
                        }
                    }
                }
                //	Phase exist
                if (exists)
                {
                    log.Info("Task already exists here, ignored - " + fromTasks[i]);
                }
                else
                {
                    MProjectTask toTask = new MProjectTask(GetCtx(), 0, Get_TrxName());
                    PO.CopyValues(fromTasks[i], toTask, GetAD_Client_ID(), GetAD_Org_ID());
                    toTask.SetC_ProjectPhase_ID(toPhase.GetC_ProjectPhase_ID());
                    if (toTask.Save())
                    {
                        count++;
                        count += CopyMTaskLinesFromProjectTask(fromTasks[i], toTask, toPhase.GetC_Project_ID());
                    }
                    else
                    {
                        pp = VLogger.RetrieveError();
                        if (pp != null)
                        {
                            msg.Append(pp.GetName());
                            //if GetName is Empty then it will check GetValue
                            if (string.IsNullOrEmpty(msg.ToString()))
                            {
                                msg.Append(Msg.GetMsg("", pp.GetValue()));
                            }
                        }
                        if (string.IsNullOrEmpty(msg.ToString()))
                        {
                            msg.Append(Msg.GetMsg(GetCtx(), "VIS_LineNotSaved"));
                        }
                        else
                        {
                            msg.Append(Msg.GetMsg(GetCtx(), "VIS_LineNotSaved") + "," + msg.ToString());
                        }
                    }
                }
            }
            if (fromTasks.Length != count)
            {
                log.Warning("Count difference - ProjectPhase=" + fromTasks.Length + " <> Saved=" + count);
            }

            return(count);
        }