}       //	generateTable

        /// <summary>
        /// Generate Delta View
        /// </summary>
        /// <returns>true, if created</returns>
        private bool GenerateView()
        {
            //	View
            m_viewTable = MTable.Get(m_ctx, m_vTableName);
            if (m_viewTable == null)
            {
                m_viewTable = new MTable(m_ctx, 0, null);
            }

            PO.CopyValues(m_baseTable, m_viewTable);
            m_viewTable.SetTableName(m_vTableName);
            m_viewTable.SetName(m_baseTable.GetName() + " View");
            m_viewTable.SetIsView(true);
            if (!m_viewTable.Save())
            {
                throw new Exception("Cannot save " + m_vTableName);
            }

            MColumn[] vCols = SyncMColumns(false);

            //ColumnSync
            //	Create View
            StringBuilder sql = new StringBuilder("CREATE OR REPLACE VIEW ")
                                .Append(m_vTableName)
                                .Append(" AS SELECT ");

            for (int i = 0; i < vCols.Length; i++)
            {
                if (i > 0)
                {
                    sql.Append(",");
                }
                MColumn column     = vCols[i];
                String  columnName = column.GetColumnName();
                if (column.IsStandardColumn() ||
                    column.IsKey())
                {
                    sql.Append("b.").Append(columnName);
                }
                else
                {
                    sql.Append(",COALESCE(b.").Append(columnName)
                    .Append("d.").Append(columnName).Append(") AS ").Append(columnName);
                }
            }
            //	From
            String keyColumnName = m_baseTable.GetTableName() + "_ID";

            sql.Append(" FROM ").Append(m_baseTable.GetTableName())
            .Append(" b LEFT OUTER JOIN ").Append(m_dTableName)
            .Append(" d ON (b.").Append(keyColumnName)
            .Append("=d.").Append(keyColumnName).Append(")");
            //
            log.Info(sql.ToString());
            if (DataBase.DB.ExecuteQuery(sql.ToString(), null) < 0)
            {
                return(false);
            }
            return(true);
        }       //	generateView
        /**
         *  Copy Lines From other Project
         *	@param project project
         *	@return number of lines copied
         */
        public int CopyLinesFrom(MProject project)
        {
            if (IsProcessed() || project == null)
            {
                return(0);
            }
            int count = 0;

            MProjectLine[] fromLines = project.GetLines();
            for (int i = 0; i < fromLines.Length; i++)
            {
                MProjectLine line = new MProjectLine(GetCtx(), 0, project.Get_TrxName());
                PO.CopyValues(fromLines[i], line, GetAD_Client_ID(), GetAD_Org_ID());
                line.SetC_Project_ID(GetC_Project_ID());
                line.SetInvoicedAmt(Env.ZERO);
                line.SetInvoicedQty(Env.ZERO);
                line.SetC_OrderPO_ID(0);
                line.SetC_Order_ID(0);
                line.SetProcessed(false);
                if (line.Save())
                {
                    count++;
                }
            }
            if (fromLines.Length != count)
            {
                log.Log(Level.SEVERE, "Lines difference - Project=" + fromLines.Length + " <> Saved=" + count);
            }

            return(count);
        }
Beispiel #3
0
        /// <summary>
        /// Copy Lines From other Commission
        /// </summary>
        /// <param name="otherCom">commission</param>
        /// <returns>number of lines copied</returns>
        public int CopyLinesFrom(MCommission otherCom)
        {
            if (otherCom == null)
            {
                return(0);
            }
            MCommissionLine[] fromLines = otherCom.GetLines();
            int count = 0;

            for (int i = 0; i < fromLines.Length; i++)
            {
                MCommissionLine line = new MCommissionLine(GetCtx(), 0, Get_TrxName());
                PO.CopyValues(fromLines[i], line, GetAD_Client_ID(), GetAD_Org_ID());
                line.Set_ValueNoCheck("C_CommissionLine_ID", null);     //	new
                line.SetC_Commission_ID(GetC_Commission_ID());
                if (line.Save())
                {
                    count++;
                }
            }
            if (fromLines.Length != count)
            {
                log.Log(Level.SEVERE, "Line difference - From=" + fromLines.Length + " <> Saved=" + count);
            }
            return(count);
        }
        //Added by Arpit on 15th Dec,2016
        public static MJournal CopyFrom(Ctx ctx, int GL_Journal_ID, DateTime?dateDoc, Trx trxName)
        {
            MJournal from = new MJournal(ctx, GL_Journal_ID, trxName);

            if (from.GetGL_Journal_ID() == 0)
            {
                throw new ArgumentException("From Journal Batch not found GL_JournalBatch_ID=" + GL_Journal_ID);
            }
            //
            MJournal to = new MJournal(ctx, 0, trxName);

            PO.CopyValues(from, to, from.GetAD_Client_ID(), from.GetAD_Org_ID());
            to.Set_ValueNoCheck("DocumentNo", null);
            // to.Set_ValueNoCheck("C_Period_ID", null);
            to.SetDateAcct(dateDoc);
            to.SetDateDoc(dateDoc);
            to.SetDocStatus(DOCSTATUS_Drafted);
            to.SetDocAction(DOCACTION_Complete);
            to.SetIsApproved(false);
            to.SetProcessed(false);
            from.GetType();
            //
            if (!to.Save())
            {
                throw new Exception("Could not create GL Journal ");
            }

            if (to.CopyJLines(from, dateDoc) == 0)
            {
                throw new Exception("Could not create GL Journal Details");
            }

            return(to);
        }       //	copyFrom
Beispiel #5
0
 /// <summary>
 /// Update Elements in Container from Stage
 /// </summary>
 /// <param name="project">proejct</param>
 /// <param name="stage">stage</param>
 /// <param name="trxName">trx</param>
 protected void UpdateTTables(MWebProject project, MCStage stage,
                              Trx trxName)
 {
     int[] tableKeys = X_CM_CStageTTable.GetAllIDs("CM_CStageTTable",
                                                   "CM_CStage_ID=" + stage.Get_ID(), trxName);
     if (tableKeys != null && tableKeys.Length > 0)
     {
         for (int i = 0; i < tableKeys.Length; i++)
         {
             X_CM_CStageTTable thisStageTTable = new X_CM_CStageTTable(
                 project.GetCtx(), tableKeys[i], trxName);
             int[] thisContainerTTableKeys = X_CM_ContainerTTable.GetAllIDs(
                 "CM_ContainerTTable", "CM_Container_ID=" + stage.Get_ID()
                 + " AND CM_TemplateTable_ID="
                 + thisStageTTable.GetCM_TemplateTable_ID(), trxName);
             X_CM_ContainerTTable thisContainerTTable;
             if (thisContainerTTableKeys != null &&
                 thisContainerTTableKeys.Length > 0)
             {
                 thisContainerTTable = new X_CM_ContainerTTable(project
                                                                .GetCtx(), thisContainerTTableKeys[0], trxName);
             }
             else
             {
                 thisContainerTTable = new X_CM_ContainerTTable(project
                                                                .GetCtx(), 0, trxName);
             }
             thisContainerTTable.SetCM_Container_ID(stage.Get_ID());
             PO.CopyValues(new X_CM_CStageTTable(project.GetCtx(),
                                                 tableKeys[i], trxName), thisContainerTTable);
             thisContainerTTable.Save(trxName);
         }
     }
 }
Beispiel #6
0
        } // getAD_Tree_ID;

        /// <summary>
        /// Set/Copy Stage
        /// </summary>
        /// <param name="project">parent</param>
        /// <param name="stage">stage</param>
        /// <param name="path">path</param>
        protected void SetStage(MWebProject project, MCStage stage, String path)
        {
            _stage = stage;
            PO.CopyValues(stage, this);
            SetAD_Client_ID(project.GetAD_Client_ID());
            SetAD_Org_ID(project.GetAD_Org_ID());
            SetIsActive(stage.IsActive());
            SetCM_ContainerLink_ID(stage.GetCM_CStageLink_ID());
            //
            SetRelativeURL(path + stage.GetRelativeURL());
            //
            if (GetMeta_Author() == null || GetMeta_Author().Length == 0)
            {
                SetMeta_Author(project.GetMeta_Author());
            }
            if (GetMeta_Content() == null || GetMeta_Content().Length == 0)
            {
                SetMeta_Content(project.GetMeta_Content());
            }
            if (GetMeta_Copyright() == null || GetMeta_Copyright().Length == 0)
            {
                SetMeta_Copyright(project.GetMeta_Copyright());
            }
            if (GetMeta_Publisher() == null || GetMeta_Publisher().Length == 0)
            {
                SetMeta_Publisher(project.GetMeta_Publisher());
            }
            if (GetMeta_RobotsTag() == null || GetMeta_RobotsTag().Length == 0)
            {
                SetMeta_RobotsTag(project.GetMeta_RobotsTag());
            }
        } // setStage
        /**
         *  Copy Phases/Tasks from other Project
         *	@param fromProject project
         *	@return number of items copied
         */
        public int CopyPhasesFrom(MProject fromProject)
        {
            if (IsProcessed() || fromProject == null)
            {
                return(0);
            }
            int count     = 0;
            int taskCount = 0;

            //	Get Phases
            MProjectPhase[] myPhases   = GetPhases();
            MProjectPhase[] fromPhases = fromProject.GetPhases();
            //	Copy Phases
            for (int i = 0; i < fromPhases.Length; i++)
            {
                //	Check if Phase already exists
                int  C_Phase_ID = fromPhases[i].GetC_Phase_ID();
                bool exists     = false;
                if (C_Phase_ID == 0)
                {
                    exists = false;
                }
                else
                {
                    for (int ii = 0; ii < myPhases.Length; ii++)
                    {
                        if (myPhases[ii].GetC_Phase_ID() == C_Phase_ID)
                        {
                            exists = true;
                            break;
                        }
                    }
                }
                //	Phase exist
                if (exists)
                {
                    log.Info("Phase already exists here, ignored - " + fromPhases[i]);
                }
                else
                {
                    MProjectPhase toPhase = new MProjectPhase(GetCtx(), 0, Get_TrxName());
                    PO.CopyValues(fromPhases[i], toPhase, GetAD_Client_ID(), GetAD_Org_ID());
                    toPhase.SetC_Project_ID(GetC_Project_ID());
                    toPhase.SetC_Order_ID(0);
                    toPhase.SetIsComplete(false);
                    if (toPhase.Save())
                    {
                        count++;
                        taskCount += toPhase.CopyTasksFrom(fromPhases[i]);
                    }
                }
            }
            if (fromPhases.Length != count)
            {
                log.Warning("Count difference - Project=" + fromPhases.Length + " <> Saved=" + count);
            }

            return(count + taskCount);
        }
Beispiel #8
0
        }       //	getLines

        /// <summary>
        /// Copy Lines from other Journal
        /// </summary>
        /// <param name="fromJournal">Journal</param>
        /// <param name="dateAcct">date used - if null original</param>
        /// <param name="typeCR">type of copying (C)orrect=negate - (R)everse=flip dr/cr - otherwise just copy</param>
        /// <returns>number of lines copied</returns>
        public int CopyLinesFrom(MJournal fromJournal, DateTime?dateAcct, char typeCR)
        {
            if (IsProcessed() || fromJournal == null)
            {
                return(0);
            }
            int count     = 0;
            int lineCount = 0;

            MJournalLine[] fromLines = fromJournal.GetLines(false);
            for (int i = 0; i < fromLines.Length; i++)
            {
                MJournalLine toLine = new MJournalLine(GetCtx(), 0, fromJournal.Get_TrxName());
                PO.CopyValues(fromLines[i], toLine, GetAD_Client_ID(), GetAD_Org_ID());
                toLine.SetGL_Journal_ID(GetGL_Journal_ID());
                //
                if (dateAcct != null)
                {
                    toLine.SetDateAcct(dateAcct);
                }
                //	Amounts
                if (typeCR == 'C')                      //	correct
                {
                    // toLine.SetAmtSourceDr(fromLines[i].GetAmtSourceDr().negate());
                    toLine.SetAmtSourceDr(Decimal.Negate(fromLines[i].GetAmtSourceDr()));
                    toLine.SetAmtSourceCr(Decimal.Negate(fromLines[i].GetAmtSourceCr())); //.negate());
                }
                else if (typeCR == 'R')                                                   //	reverse
                {
                    toLine.SetAmtSourceDr(fromLines[i].GetAmtSourceCr());
                    toLine.SetAmtSourceCr(fromLines[i].GetAmtSourceDr());
                }
                toLine.SetIsGenerated(true);
                toLine.SetProcessed(false);

                // // Set Orignal Document Reference on Reversal Document
                if (Get_ColumnIndex("IsReversal") > 0 && IsReversal())
                {
                    if (toLine.Get_ColumnIndex("ReversalDoc_ID") > 0)
                    {
                        toLine.SetReversalDoc_ID(fromLines[i].GetGL_JournalLine_ID());
                    }
                }

                if (toLine.Save())
                {
                    count++;
                    lineCount += toLine.CopyLinesFrom(fromLines[i], toLine.GetGL_JournalLine_ID());
                }
            }
            if (fromLines.Length != count)
            {
                log.Log(Level.SEVERE, "Line difference - JournalLines=" + fromLines.Length + " <> Saved=" + count);
            }

            return(count);
        }       //	copyLinesFrom
        }       //	copyLinesFrom

        // Mainsh 18/7/2016...
        public int CopyLines(MJournal fromJournal, char typeCR)
        {
            DateTime?dateAcct = GetDateAcct();

            if (IsProcessed() || fromJournal == null)
            {
                return(0);
            }
            int count     = 0;
            int lineCount = 0;

            MJournalLine[] fromLines = fromJournal.GetLines(false);
            for (int i = 0; i < fromLines.Length; i++)
            {
                MJournalLine toLine = new MJournalLine(GetCtx(), 0, fromJournal.Get_TrxName());
                PO.CopyValues(fromLines[i], toLine, GetAD_Client_ID(), GetAD_Org_ID());
                toLine.SetGL_Journal_ID(GetGL_Journal_ID());
                //
                //if (dateAcct != null)
                //{
                //    toLine.SetDateAcct(dateAcct);
                //}
                //	Amounts
                //if (typeCR == 'C')			//	correct
                //{
                //    // toLine.SetAmtSourceDr(fromLines[i].GetAmtSourceDr().negate());
                //    toLine.SetAmtSourceDr(Decimal.Negate(fromLines[i].GetAmtSourceDr()));
                //    toLine.SetAmtSourceCr(Decimal.Negate(fromLines[i].GetAmtSourceCr()));//.negate());
                //}
                //else if (typeCR == 'R')		//	reverse
                //{
                toLine.SetAmtSourceDr(fromLines[i].GetAmtSourceDr());
                toLine.SetAmtSourceCr(fromLines[i].GetAmtSourceCr());
                // }

                toLine.SetDescription(fromLines[i].GetDescription());
                toLine.SetC_Currency_ID(fromLines[i].GetC_Currency_ID());
                toLine.SetIsGenerated(true);
                toLine.SetProcessed(false);
                toLine.SetQty(fromLines[i].GetQty());
                toLine.SetElementType(fromLines[i].GetElementType());


                if (toLine.Save(fromJournal.Get_TrxName()))
                {
                    count++;
                    lineCount += toLine.CopyLinesFrom(fromLines[i], toLine.GetGL_JournalLine_ID());
                }
            }
            if (fromLines.Length != count)
            {
                log.Log(Level.SEVERE, "Line difference - JournalLines=" + fromLines.Length + " <> Saved=" + count);
            }

            return(count);
        }       //	copyLinesFrom
        /// <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);
        }
        }   //	updateJournalTotal

        /// <summary>
        /// This functionis used to create Line Dimension Line
        /// </summary>
        /// <param name="fromJournal">object of old GL Journal Line from where we need to pick lines</param>
        /// <param name="newlineID">GL Journal Line ID - new record agsint which we copy lines</param>
        /// <param name="typeCR">Optional Parameter - When 'C' - its means Reverse record - amount to be negate in this case</param>
        /// <returns>count of line - which is created</returns>
        public int CopyLinesFrom(MJournalLine fromJournal, int newlineID, char typeCR = 'X')
        {
            if (IsProcessed() || fromJournal == null)
            {
                return(0);
            }
            int count     = 0;
            int lineCount = 0;

            MLineDimension[] fromLines = fromJournal.GetLines(false);
            for (int i = 0; i < fromLines.Length; i++)
            {
                MLineDimension toLine = new MLineDimension(GetCtx(), 0, fromJournal.Get_TrxName());
                PO.CopyValues(fromLines[i], toLine, GetAD_Client_ID(), GetAD_Org_ID());

                toLine.SetC_BPartner_ID(fromLines[i].GetC_BPartner_ID());
                toLine.SetC_Campaign_ID(fromLines[i].GetC_Campaign_ID());
                toLine.SetC_ElementValue_ID(fromLines[i].GetC_ElementValue_ID());
                toLine.SetC_Element_ID(fromLines[i].GetC_Element_ID());
                toLine.SetC_Location_ID(fromLines[i].GetC_Location_ID());
                toLine.SetC_Project_ID(fromLines[i].GetC_Project_ID());
                toLine.SetC_SalesRegion_ID(fromLines[i].GetC_SalesRegion_ID());
                toLine.SetM_Product_ID(fromLines[i].GetM_Product_ID());
                toLine.SetOrg_ID(fromLines[i].GetOrg_ID());
                toLine.SetSeqNo(fromLines[i].GetSeqNo());
                toLine.SetLineType(fromLines[i].GetLineType());
                toLine.SetGL_JournalLine_ID(newlineID);

                if (typeCR == 'C')
                {
                    toLine.SetAmount(Decimal.Negate(fromLines[i].GetAmount()));
                }
                else
                {
                    toLine.SetAmount(fromLines[i].GetAmount());
                }
                toLine.SetLine(fromLines[i].GetLine());

                if (toLine.Save(fromJournal.Get_TrxName()))
                {
                    count++;
                }
            }
            if (fromLines.Length != count)
            {
                log.Log(Level.SEVERE, "Line difference - LinesDimensionl=" + fromLines.Length + " <> Saved=" + count);
            }
            return(lineCount);
        }
        }       //	copyLinesFrom

        //end

        //added by To Create Journal Lines Arpit Rai 15th Dec,2016
        public int CopyJLines(MJournal fromJournal, DateTime?dateAcct)
        {
            if (IsProcessed() || fromJournal == null)
            {
                return(0);
            }
            int count     = 0;
            int lineCount = 0;

            MJournalLine[] fromLines = fromJournal.GetLines(false);
            for (int i = 0; i < fromLines.Length; i++)
            {
                MJournalLine toLine = new MJournalLine(GetCtx(), 0, fromJournal.Get_TrxName());
                PO.CopyValues(fromLines[i], toLine, GetAD_Client_ID(), GetAD_Org_ID());
                toLine.SetGL_Journal_ID(GetGL_Journal_ID());
                if (dateAcct != null)
                {
                    toLine.SetDateAcct(dateAcct);
                }
                else
                {
                    toLine.SetDateAcct(DateTime.Now);
                }
                toLine.SetAmtSourceDr(fromLines[i].GetAmtSourceDr());
                toLine.SetAmtSourceCr(fromLines[i].GetAmtSourceCr());
                toLine.SetDescription(fromLines[i].GetDescription());
                toLine.SetC_Currency_ID(fromLines[i].GetC_Currency_ID());
                toLine.SetIsGenerated(true);
                toLine.SetProcessed(false);
                toLine.SetQty(fromLines[i].GetQty());
                toLine.SetElementType(fromLines[i].GetElementType());
                if (toLine.Save(fromJournal.Get_TrxName()))
                {
                    count++;
                    lineCount += toLine.CopyLinesFrom(fromLines[i], toLine.GetGL_JournalLine_ID());
                }
            }
            if (fromLines.Length != count)
            {
                log.Log(Level.SEVERE, "Line difference - JournalLines=" + fromLines.Length + " <> Saved=" + count);
            }

            return(count);
        }
        }       //	getJournals

        /// <summary>
        /// Copy Journal/Lines from other Journal Batch
        /// </summary>
        /// <param name="jb">Journal Batch</param>
        /// <returns>number of journals + lines copied</returns>
        public int CopyDetailsFrom(MJournalBatch jb)
        {
            if (IsProcessed() || jb == null)
            {
                return(0);
            }
            int count     = 0;
            int lineCount = 0;

            MJournal[] fromJournals = jb.GetJournals(false);
            for (int i = 0; i < fromJournals.Length; i++)
            {
                MJournal toJournal = new MJournal(GetCtx(), 0, jb.Get_TrxName());
                PO.CopyValues(fromJournals[i], toJournal, GetAD_Client_ID(), GetAD_Org_ID());
                toJournal.SetGL_JournalBatch_ID(GetGL_JournalBatch_ID());
                toJournal.Set_ValueNoCheck("DocumentNo", null); //	create new

                //Manish 18/7/2016. C_Period_ID was Null.. But column is mandatory in database so value can't be null.
                toJournal.Set_ValueNoCheck("C_Period_ID", fromJournals[i].GetC_Period_ID());
                // end
                toJournal.SetDateDoc(GetDateDoc());             //	dates from this Batch
                toJournal.SetDateAcct(GetDateAcct());
                toJournal.SetDocStatus(MJournal.DOCSTATUS_Drafted);
                toJournal.SetDocAction(MJournal.DOCACTION_Complete);
                toJournal.SetTotalCr(Env.ZERO);
                toJournal.SetTotalDr(Env.ZERO);
                toJournal.SetIsApproved(false);
                toJournal.SetIsPrinted(false);
                toJournal.SetPosted(false);
                toJournal.SetProcessed(false);
                if (toJournal.Save())
                {
                    count++;
                    lineCount += toJournal.CopyLinesFrom(fromJournals[i], GetDateAcct(), 'x');
                }
            }
            if (fromJournals.Length != count)
            {
                log.Log(Level.SEVERE, "Line difference - Journals=" + fromJournals.Length + " <> Saved=" + count);
            }

            return(count + lineCount);
        }       //	copyLinesFrom
        /**
         *  Create new Project by copying
         *  @param ctx context
         *	@param C_Project_ID project
         *  @param dateDoc date of the document date
         *	@param trxName transaction
         *	@return Project
         */
        public static MProject CopyFrom(Ctx ctx, int C_Project_ID, DateTime?dateDoc, Trx trxName)
        {
            MProject from = new MProject(ctx, C_Project_ID, trxName);

            if (from.GetC_Project_ID() == 0)
            {
                throw new ArgumentException("From Project not found C_Project_ID=" + C_Project_ID);
            }
            //
            MProject to = new MProject(ctx, 0, trxName);

            PO.CopyValues(from, to, from.GetAD_Client_ID(), from.GetAD_Org_ID());
            to.Set_ValueNoCheck("C_Project_ID", I_ZERO);
            //	Set Value with Time
            String Value  = to.GetValue() + " ";
            String Time   = dateDoc.ToString();
            int    length = Value.Length + Time.Length;

            if (length <= 40)
            {
                Value += Time;
            }
            else
            {
                Value += Time.Substring(length - 40 - 1);
            }
            to.SetValue(Value);
            to.SetInvoicedAmt(Env.ZERO);
            to.SetProjectBalanceAmt(Env.ZERO);
            to.SetProcessed(false);
            //
            if (!to.Save())
            {
                throw new Exception("Could not create Project");
            }

            if (to.CopyDetailsFrom(from) == 0)
            {
                throw new Exception("Could not create Project Details");
            }

            return(to);
        }
Beispiel #15
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);
        }
Beispiel #16
0
        /// <summary>
        /// Is used to do a reverse entry of "Production Record" into the system
        /// </summary>
        /// <returns>message successfuly created or not</returns>
        protected override string DoIt()
        {
            if (M_Production_ID > 0)
            {
                //Copy Production Header
                X_M_Production production = new X_M_Production(GetCtx(), M_Production_ID, Get_Trx());

                //check production is Reversed or not, if Reversed then not to do anything
                if (production.IsReversed())
                {
                    return(Msg.GetMsg(GetCtx(), "AlreadyReversed"));
                }

                //Get data from Production Plan
                dsProductionPlan = DB.ExecuteDataset(@"SELECT AD_CLIENT_ID , AD_ORG_ID , DESCRIPTION , LINE , M_LOCATOR_ID , 
                                       M_PRODUCT_ID , M_PRODUCTIONPLAN_ID ,  M_PRODUCTION_ID  ,  PROCESSED  , PRODUCTIONQTY  M_WAREHOUSE_ID FROM M_ProductionPlan 
                                       WHERE IsActive = 'Y' AND M_PRODUCTION_ID = " + M_Production_ID, null, Get_Trx());

                //get data from production Line
                dsProductionLine = DB.ExecuteDataset(@"SELECT AD_CLIENT_ID , AD_ORG_ID , DESCRIPTION , LINE , M_ATTRIBUTESETINSTANCE_ID , M_LOCATOR_ID , 
                                       M_PRODUCT_ID ,  M_PRODUCTIONLINE_ID, M_PRODUCTIONPLAN_ID , M_PRODUCTION_ID  , PROCESSED  , MOVEMENTQTY , 
                                       C_UOM_ID , PLANNEDQTY , M_WAREHOUSE_ID FROM M_ProductionLine 
                                       WHERE IsActive = 'Y' AND M_PRODUCTION_ID = " + M_Production_ID, null, Get_Trx());

                // Create New record of Production Header with Reverse Entry
                X_M_Production productionTo = new X_M_Production(production.GetCtx(), 0, production.Get_Trx());
                try
                {
                    productionTo.Set_TrxName(production.Get_Trx());
                    PO.CopyValues(production, productionTo, production.GetAD_Client_ID(), production.GetAD_Org_ID());
                    productionTo.SetName("{->" + productionTo.GetName() + ")");
                    if (production.Get_ColumnIndex("DocumentNo") > 0)
                    {
                        productionTo.Set_Value("DocumentNo", ("{->" + productionTo.Get_Value("DocumentNo") + ")"));
                    }
                    productionTo.SetMovementDate(production.GetMovementDate()); //SI_0662 : not to create reverse record in current date, it should be created with the same date.
                    productionTo.SetProcessed(false);
                    if (!productionTo.Save(production.Get_Trx()))
                    {
                        production.Get_Trx().Rollback();
                        ValueNamePair pp = VLogger.RetrieveError();
                        _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                        throw new Exception("Could not create Production reverse entry");
                    }
                    else
                    {
                        #region create new record of Production Plan
                        if (dsProductionPlan != null && dsProductionPlan.Tables.Count > 0 && dsProductionPlan.Tables[0].Rows.Count > 0)
                        {
                            for (int i = 0; i < dsProductionPlan.Tables[0].Rows.Count; i++)
                            {
                                //Original Line
                                fromProdPlan = new X_M_ProductionPlan(GetCtx(), Util.GetValueOfInt(dsProductionPlan.Tables[0].Rows[i]["M_PRODUCTIONPLAN_ID"]), Get_Trx());

                                // Create New record of Production Plan with Reverse Entry
                                toProdPlan = new X_M_ProductionPlan(production.GetCtx(), 0, production.Get_Trx());
                                try
                                {
                                    toProdPlan.Set_TrxName(production.Get_Trx());
                                    PO.CopyValues(fromProdPlan, toProdPlan, fromProdPlan.GetAD_Client_ID(), fromProdPlan.GetAD_Org_ID());
                                    toProdPlan.SetProductionQty(Decimal.Negate(toProdPlan.GetProductionQty()));
                                    toProdPlan.SetM_Production_ID(productionTo.GetM_Production_ID());
                                    toProdPlan.SetProcessed(false);
                                    if (!toProdPlan.Save(production.Get_Trx()))
                                    {
                                        production.Get_Trx().Rollback();
                                        ValueNamePair pp = VLogger.RetrieveError();
                                        _log.Log(Level.SEVERE, "Could Not create Production Plan reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                                        throw new Exception("Could not create Production Plan reverse entry");
                                    }
                                    else
                                    {
                                        #region check record exist on production line
                                        if (dsProductionLine != null && dsProductionLine.Tables.Count > 0 && dsProductionLine.Tables[0].Rows.Count > 0)
                                        {
                                            //check record exist on production line against production plan
                                            drProductionLine = dsProductionLine.Tables[0].Select("M_ProductionPlan_ID  = " + fromProdPlan.GetM_ProductionPlan_ID());
                                            if (drProductionLine.Length > 0)
                                            {
                                                for (int j = 0; j < drProductionLine.Length; j++)
                                                {
                                                    //Original Line
                                                    fromProdline = new X_M_ProductionLine(GetCtx(), Util.GetValueOfInt(drProductionLine[j]["M_PRODUCTIONLINE_ID"]), Get_Trx());

                                                    // Create New record of Production line with Reverse Entry
                                                    toProdline = new X_M_ProductionLine(production.GetCtx(), 0, production.Get_Trx());
                                                    try
                                                    {
                                                        toProdline.Set_TrxName(production.Get_Trx());
                                                        PO.CopyValues(fromProdline, toProdline, fromProdPlan.GetAD_Client_ID(), fromProdPlan.GetAD_Org_ID());
                                                        toProdline.SetMovementQty(Decimal.Negate(toProdline.GetMovementQty()));
                                                        toProdline.SetPlannedQty(Decimal.Negate(toProdline.GetPlannedQty()));
                                                        toProdline.SetM_Production_ID(productionTo.GetM_Production_ID());
                                                        toProdline.SetM_ProductionPlan_ID(toProdPlan.GetM_ProductionPlan_ID());
                                                        toProdline.SetReversalDoc_ID(fromProdline.GetM_ProductionLine_ID()); //maintain refernce of Orignal record on reversed record
                                                        toProdline.SetProcessed(false);
                                                        if (!CheckQtyAvailablity(GetCtx(), toProdline.GetM_Warehouse_ID(), toProdline.GetM_Locator_ID(), toProdline.GetM_Product_ID(), toProdline.GetM_AttributeSetInstance_ID(), toProdline.GetMovementQty(), Get_Trx()))
                                                        {
                                                            production.Get_Trx().Rollback();
                                                            ValueNamePair pp = VLogger.RetrieveError();
                                                            if (!string.IsNullOrEmpty(pp.GetName()))
                                                            {
                                                                throw new Exception("Could not create Production line reverse entry, " + pp.GetName());
                                                            }
                                                            else
                                                            {
                                                                throw new Exception("Could not create Production line reverse entry");
                                                            }
                                                        }
                                                        if (!toProdline.Save(production.Get_Trx()))
                                                        {
                                                            production.Get_Trx().Rollback();
                                                            ValueNamePair pp = VLogger.RetrieveError();
                                                            _log.Log(Level.SEVERE, "Could Not create Production Line reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                                                            throw new Exception("Could not create Production line reverse entry");
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        _log.Info("Error Occured during Production Reverse " + ex.ToString());
                                                        if (dsProductionLine != null)
                                                        {
                                                            dsProductionLine.Dispose();
                                                        }
                                                        if (dsProductionPlan != null)
                                                        {
                                                            dsProductionPlan.Dispose();
                                                        }
                                                        return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result));
                                                    }
                                                }
                                            }
                                        }
                                        #endregion
                                    }
                                }
                                catch (Exception ex)
                                {
                                    _log.Info("Error Occured during Production Reverse " + ex.ToString());
                                    if (dsProductionLine != null)
                                    {
                                        dsProductionLine.Dispose();
                                    }
                                    if (dsProductionPlan != null)
                                    {
                                        dsProductionPlan.Dispose();
                                    }
                                    return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result));
                                }
                            }
                        }
                        #endregion

                        result = productionTo.GetName();
                    }

                    //set Reversed as True
                    productionTo.SetIsReversed(true);
                    if (!productionTo.Save(production.Get_Trx()))
                    {
                        production.Get_Trx().Rollback();
                        ValueNamePair pp = VLogger.RetrieveError();
                        _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                        throw new Exception("Could not create Production reverse entry");
                    }

                    //Set reversed as true, Reverse Refernce on Orignal Document
                    production.SetIsReversed(true);
                    production.SetM_Ref_Production(productionTo.GetM_Production_ID());
                    if (!production.Save(production.Get_Trx()))
                    {
                        production.Get_Trx().Rollback();
                        ValueNamePair pp = VLogger.RetrieveError();
                        _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                        throw new Exception("Could not create Production reverse entry");
                    }
                }
                catch (Exception ex)
                {
                    _log.Info("Error Occured during Production Reverse " + ex.ToString());
                    if (dsProductionLine != null)
                    {
                        dsProductionLine.Dispose();
                    }
                    if (dsProductionPlan != null)
                    {
                        dsProductionPlan.Dispose();
                    }
                    return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result));
                }
            }
            return(Msg.GetMsg(GetCtx(), "DocumentReversedSuccessfully" + result));
        }
        /// <summary>
        /// Is used to do a reverse entry of "Production Record" into the system
        /// </summary>
        /// <returns>message successfuly created or not</returns>
        protected override string DoIt()
        {
            if (M_Production_ID > 0)
            {
                //Copy Production Header
                ViennaAdvantage.Model.X_M_Production production = new ViennaAdvantage.Model.X_M_Production(GetCtx(), M_Production_ID, Get_Trx());

                string cnt    = "Select count(*) from m_production pro where pro.movementdate >" + GlobalVariable.TO_DATE(production.GetMovementDate(), true) + " and pro.processed='Y' ";
                int    trncnt = Util.GetValueOfInt(DB.ExecuteScalar(cnt));
                if (trncnt > 0)
                {
                    production.SetGOM01_IsRecordAvail(true);
                    production.Save(Get_TrxName());
                    return(Msg.GetMsg(GetCtx(), "Please Check some transaction already availble in future"));
                }
                else
                {
                    production.SetGOM01_IsRecordAvail(false);
                    production.Save(Get_TrxName());
                }

                //check production is Reversed or not, if Reversed then not to do anything
                if (production.IsReversed())
                {
                    return(Msg.GetMsg(GetCtx(), "AlreadyReversed"));
                }

                //Get data from Production Plan
                dsProductionPlan = DB.ExecuteDataset(@"SELECT AD_CLIENT_ID , AD_ORG_ID , DESCRIPTION , LINE , M_LOCATOR_ID , 
                                       M_PRODUCT_ID , M_PRODUCTIONPLAN_ID ,  M_PRODUCTION_ID  ,  PROCESSED  , PRODUCTIONQTY  M_WAREHOUSE_ID FROM M_ProductionPlan 
                                       WHERE IsActive = 'Y' AND M_PRODUCTION_ID = " + M_Production_ID, null, Get_Trx());

                //get data from production Line
                dsProductionLine = DB.ExecuteDataset(@"SELECT AD_CLIENT_ID , AD_ORG_ID , DESCRIPTION , LINE , M_ATTRIBUTESETINSTANCE_ID , M_LOCATOR_ID , 
                                       M_PRODUCT_ID ,  M_PRODUCTIONLINE_ID, M_PRODUCTIONPLAN_ID , M_PRODUCTION_ID  , PROCESSED  , MOVEMENTQTY , 
                                       C_UOM_ID , PLANNEDQTY , M_WAREHOUSE_ID FROM M_ProductionLine 
                                       WHERE IsActive = 'Y' AND M_PRODUCTION_ID = " + M_Production_ID, null, Get_Trx());


                // Create New record of Production Header with Reverse Entry
                X_M_Production productionTo = new X_M_Production(production.GetCtx(), 0, production.Get_Trx());
                try
                {
                    productionTo.Set_TrxName(production.Get_Trx());
                    PO.CopyValues(production, productionTo, production.GetAD_Client_ID(), production.GetAD_Org_ID());
                    productionTo.SetName("{->" + productionTo.GetName() + ")");
                    if (production.Get_ColumnIndex("DocumentNo") > 0)
                    {
                        productionTo.Set_Value("DocumentNo", ("{->" + productionTo.Get_Value("DocumentNo") + ")"));
                    }
                    productionTo.SetMovementDate(production.GetMovementDate()); //SI_0662 : not to create reverse record in current date, it should be created with the same date.
                    productionTo.SetProcessed(false);
                    if (!productionTo.Save(production.Get_Trx()))
                    {
                        production.Get_Trx().Rollback();
                        ValueNamePair pp = VLogger.RetrieveError();
                        _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                        throw new Exception("Could not create Production reverse entry");
                    }
                    else
                    {
                        #region create new record of Production Plan
                        if (dsProductionPlan != null && dsProductionPlan.Tables.Count > 0 && dsProductionPlan.Tables[0].Rows.Count > 0)
                        {
                            for (int i = 0; i < dsProductionPlan.Tables[0].Rows.Count; i++)
                            {
                                //Original Line
                                fromProdPlan = new X_M_ProductionPlan(GetCtx(), Util.GetValueOfInt(dsProductionPlan.Tables[0].Rows[i]["M_PRODUCTIONPLAN_ID"]), Get_Trx());

                                // Create New record of Production Plan with Reverse Entry
                                toProdPlan = new X_M_ProductionPlan(production.GetCtx(), 0, production.Get_Trx());
                                try
                                {
                                    toProdPlan.Set_TrxName(production.Get_Trx());
                                    PO.CopyValues(fromProdPlan, toProdPlan, fromProdPlan.GetAD_Client_ID(), fromProdPlan.GetAD_Org_ID());
                                    toProdPlan.SetProductionQty(Decimal.Negate(toProdPlan.GetProductionQty()));
                                    toProdPlan.SetM_Production_ID(productionTo.GetM_Production_ID());
                                    toProdPlan.SetProcessed(false);
                                    if (!toProdPlan.Save(production.Get_Trx()))
                                    {
                                        production.Get_Trx().Rollback();
                                        ValueNamePair pp = VLogger.RetrieveError();
                                        _log.Log(Level.SEVERE, "Could Not create Production Plan reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                                        throw new Exception("Could not create Production Plan reverse entry");
                                    }
                                    else
                                    {
                                        #region check record exist on production line
                                        if (dsProductionLine != null && dsProductionLine.Tables.Count > 0 && dsProductionLine.Tables[0].Rows.Count > 0)
                                        {
                                            //check record exist on production line against production plan
                                            drProductionLine = dsProductionLine.Tables[0].Select("M_ProductionPlan_ID  = " + fromProdPlan.GetM_ProductionPlan_ID());
                                            if (drProductionLine.Length > 0)
                                            {
                                                for (int j = 0; j < drProductionLine.Length; j++)
                                                {
                                                    //Original Line
                                                    fromProdline = new X_M_ProductionLine(GetCtx(), Util.GetValueOfInt(drProductionLine[j]["M_PRODUCTIONLINE_ID"]), Get_Trx());

                                                    // Create New record of Production line with Reverse Entry
                                                    toProdline = new X_M_ProductionLine(production.GetCtx(), 0, production.Get_Trx());
                                                    try
                                                    {
                                                        toProdline.Set_TrxName(production.Get_Trx());
                                                        PO.CopyValues(fromProdline, toProdline, fromProdPlan.GetAD_Client_ID(), fromProdPlan.GetAD_Org_ID());
                                                        toProdline.SetMovementQty(Decimal.Negate(toProdline.GetMovementQty()));
                                                        toProdline.SetPlannedQty(Decimal.Negate(toProdline.GetPlannedQty()));
                                                        toProdline.SetM_Production_ID(productionTo.GetM_Production_ID());
                                                        toProdline.SetM_ProductionPlan_ID(toProdPlan.GetM_ProductionPlan_ID());
                                                        toProdline.SetReversalDoc_ID(fromProdline.GetM_ProductionLine_ID()); //maintain refernce of Orignal record on reversed record
                                                        toProdline.SetProcessed(false);
                                                        // if (!CheckQtyAvailablity(GetCtx(), toProdline.GetM_Warehouse_ID(), toProdline.GetM_Locator_ID(), toProdline.GetM_ProductContainer_ID(), toProdline.GetM_Product_ID(), toProdline.GetM_AttributeSetInstance_ID(), toProdline.GetMovementQty(), Get_Trx()))
                                                        if (!CheckQtyAvailablity(GetCtx(), toProdline.GetM_Warehouse_ID(), toProdline.GetM_Locator_ID(), 0, toProdline.GetM_Product_ID(), toProdline.GetM_AttributeSetInstance_ID(), toProdline.GetMovementQty(), Get_Trx()))
                                                        {
                                                            production.Get_Trx().Rollback();
                                                            ValueNamePair pp = VLogger.RetrieveError();
                                                            if (!string.IsNullOrEmpty(pp.GetName()))
                                                            {
                                                                throw new Exception("Could not create Production line reverse entry, " + pp.GetName());
                                                            }
                                                            else
                                                            {
                                                                throw new Exception("Could not create Production line reverse entry");
                                                            }
                                                        }
                                                        if (!toProdline.Save(production.Get_Trx()))
                                                        {
                                                            production.Get_Trx().Rollback();
                                                            ValueNamePair pp = VLogger.RetrieveError();
                                                            _log.Log(Level.SEVERE, "Could Not create Production Line reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                                                            throw new Exception("Could not create Production line reverse entry");
                                                        }
                                                        else
                                                        {
                                                            // Create New record of Production line Policy (Material Policy) with Reverse Entry
                                                            sql.Clear();
                                                            sql.Append(@"INSERT INTO M_ProductionLineMA 
                                                                  (  AD_CLIENT_ID, AD_ORG_ID , CREATED , CREATEDBY , ISACTIVE , UPDATED , UPDATEDBY ,
                                                                    M_PRODUCTIONLINE_ID , M_ATTRIBUTESETINSTANCE_ID , MMPOLICYDATE , M_PRODUCTCONTAINER_ID, MOVEMENTQTY )
                                                                  (SELECT AD_CLIENT_ID, AD_ORG_ID , sysdate , CREATEDBY , ISACTIVE , sysdate , UPDATEDBY ,
                                                                      " + toProdline.GetM_ProductionLine_ID() + @" , M_ATTRIBUTESETINSTANCE_ID , MMPOLICYDATE , M_PRODUCTCONTAINER_ID,  -1 * MOVEMENTQTY
                                                                    FROM M_ProductionLineMA  WHERE M_ProductionLine_ID = " + fromProdline.GetM_ProductionLine_ID() + @" ) ");
                                                            int no = DB.ExecuteQuery(sql.ToString(), null, Get_Trx());
                                                            _log.Info("No of records saved on Meterial Policy against Production line ID : " + toProdline.GetM_ProductionLine_ID() + " are : " + no);
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        _log.Info("Error Occured during Production Reverse " + ex.ToString());
                                                        if (dsProductionLine != null)
                                                        {
                                                            dsProductionLine.Dispose();
                                                        }
                                                        if (dsProductionPlan != null)
                                                        {
                                                            dsProductionPlan.Dispose();
                                                        }
                                                        return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result));
                                                    }
                                                }
                                            }
                                        }
                                        #endregion
                                    }
                                }
                                catch (Exception ex)
                                {
                                    _log.Info("Error Occured during Production Reverse " + ex.ToString());
                                    if (dsProductionLine != null)
                                    {
                                        dsProductionLine.Dispose();
                                    }
                                    if (dsProductionPlan != null)
                                    {
                                        dsProductionPlan.Dispose();
                                    }
                                    return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result));
                                }
                            }
                        }
                        #endregion

                        result = productionTo.GetName();
                    }

                    //set Reversed as True
                    productionTo.SetIsReversed(true);
                    if (!productionTo.Save(production.Get_Trx()))
                    {
                        production.Get_Trx().Rollback();
                        ValueNamePair pp = VLogger.RetrieveError();
                        _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                        throw new Exception("Could not create Production reverse entry");
                    }

                    //Set reversed as true, Reverse Refernce on Orignal Document
                    production.SetIsReversed(true);
                    production.SetM_Ref_Production(productionTo.GetM_Production_ID());
                    if (!production.Save(production.Get_Trx()))
                    {
                        production.Get_Trx().Rollback();
                        ValueNamePair pp = VLogger.RetrieveError();
                        _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                        throw new Exception("Could not create Production reverse entry");
                    }
                }
                catch (Exception ex)
                {
                    _log.Info("Error Occured during Production Reverse " + ex.ToString());
                    if (dsProductionLine != null)
                    {
                        dsProductionLine.Dispose();
                    }
                    if (dsProductionPlan != null)
                    {
                        dsProductionPlan.Dispose();
                    }
                    return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result));
                }
            }
            return(Msg.GetMsg(GetCtx(), "DocumentReversedSuccessfully" + result));
        }
        /// <summary>
        /// To copy details from one project to another
        /// </summary>
        /// <param name="fromProject">From Project</param>
        /// <param name="toProject">To Project</param>
        /// <returns>No Of Lines copied</returns>
        public int CopyDetailsFrom(MProject fromProject, MProject toProject)
        {
            if (IsProcessed() || fromProject == null || toProject == null)
            {
                return(0);
            }
            int count = 0; ValueNamePair pp = null; StringBuilder msg = new StringBuilder();

            #region create lines for project
            if (toProject.GetProjectLineLevel().Equals(PROJECTLINELEVEL_Project))
            {
                MProjectLine[] fromLines = fromProject.GetLines();
                MProjectLine   line      = null;
                for (int i = 0; i < fromLines.Length; i++)
                {
                    line = new MProjectLine(GetCtx(), 0, fromProject.Get_TrxName());
                    PO.CopyValues(fromLines[i], line, GetAD_Client_ID(), GetAD_Org_ID());
                    line.SetC_Project_ID(toProject.GetC_Project_ID());
                    line.SetInvoicedAmt(Env.ZERO);
                    line.SetInvoicedQty(Env.ZERO);
                    line.SetC_OrderPO_ID(0);
                    line.SetC_Order_ID(0);
                    line.SetProcessed(false);
                    if (line.Save())
                    {
                        count++;
                    }
                    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());
                        }
                    }
                }
            }
            #endregion

            if (toProject.GetProjectLineLevel().Equals(PROJECTLINELEVEL_Phase) || toProject.GetProjectLineLevel().Equals(PROJECTLINELEVEL_Task) ||
                toProject.GetProjectLineLevel().Equals(PROJECTLINELEVEL_TaskLine))
            {
                #region if project line level is Project then create lines for phase only
                MProjectPhase[]     myPhases = GetPhases();
                MProjectPhase[]     fromPhases = fromProject.GetPhases();
                int                 C_Phase_ID = 0; bool exists = false;
                MProjectPhase       toPhase   = null;
                MProjectLine[]      fromLines = null;
                List <MProjectLine> list      = null;
                //	Copy Phases
                for (int i = 0; i < fromPhases.Length; i++)
                {
                    //	Check if Phase already exists
                    C_Phase_ID = fromPhases[i].GetC_Phase_ID();
                    exists     = false;
                    if (C_Phase_ID == 0)
                    {
                        exists = false;
                    }
                    else
                    {
                        for (int ii = 0; ii < myPhases.Length; ii++)
                        {
                            if (myPhases[ii].GetC_Phase_ID() == C_Phase_ID)
                            {
                                exists = true;
                                break;
                            }
                        }
                    }
                    //	Phase exist
                    if (exists)
                    {
                        log.Info("Phase already exists here, ignored - " + fromPhases[i]);
                    }
                    else
                    {
                        toPhase = new MProjectPhase(GetCtx(), 0, Get_TrxName());
                        PO.CopyValues(fromPhases[i], toPhase, GetAD_Client_ID(), GetAD_Org_ID());
                        toPhase.SetC_Project_ID(toProject.GetC_Project_ID());
                        toPhase.SetC_Order_ID(0);
                        toPhase.SetIsComplete(false);
                        if (toPhase.Save())
                        {
                            count++;
                            if (toProject.GetProjectLineLevel().Equals(PROJECTLINELEVEL_Task) || toProject.GetProjectLineLevel().Equals(PROJECTLINELEVEL_TaskLine))
                            {
                                toPhase.CopyTasksFrom(fromPhases[i], toPhase);
                            }
                            else
                            {
                                DataSet projDs = DB.ExecuteDataset(" SELECT C_ProjectLine_ID FROM C_ProjectLine WHERE " +
                                                                   " C_ProjectPhase_ID=" + fromPhases[i].GetC_ProjectPhase_ID() + " AND " +
                                                                   " C_Project_ID = " + fromPhases[i].GetC_Project_ID() + " ORDER BY Line ");

                                if (projDs != null && projDs.Tables[0].Rows.Count > 0)
                                {
                                    list = new List <MProjectLine>();
                                    for (int k = 0; k < projDs.Tables[0].Rows.Count; k++)
                                    {
                                        list.Add(new MProjectLine(GetCtx(), Util.GetValueOfInt(projDs.Tables[0].Rows[k]["C_ProjectLine_ID"]), Get_TrxName()));
                                    }
                                    fromLines = new MProjectLine[list.Count];
                                    fromLines = list.ToArray();
                                }

                                if (fromLines != null && fromLines.Length > 0)
                                {
                                    MProjectLine line = null;
                                    for (int j = 0; j < fromLines.Length; j++)
                                    {
                                        line = new MProjectLine(GetCtx(), 0, fromProject.Get_TrxName());
                                        PO.CopyValues(fromLines[j], line, GetAD_Client_ID(), GetAD_Org_ID());
                                        line.SetC_Project_ID(toProject.GetC_Project_ID());
                                        line.SetC_ProjectPhase_ID(toPhase.GetC_ProjectPhase_ID());
                                        line.SetInvoicedAmt(Env.ZERO);
                                        line.SetInvoicedQty(Env.ZERO);
                                        line.SetC_OrderPO_ID(0);
                                        line.SetC_Order_ID(0);
                                        line.SetProcessed(false);
                                        if (line.Save())
                                        {
                                            count++;
                                        }
                                        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());
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        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());
                            }
                        }
                    }
                }
                #endregion
            }



            //    count = CopyLinesFrom(fromProject)
            //+ CopyPhasesFrom(fromProject);
            return(count);
        }
Beispiel #19
0
        }       //	generateView

        /// <summary>
        /// Synchronize target table with base table in dictionary
        /// </summary>
        /// <param name="derived">is derived</param>
        /// <returns></returns>
        private MColumn[] SyncMColumns(bool derived)
        {
            MTable target = derived ? m_derivedTable : m_viewTable;
            MTable source = derived ? m_baseTable : m_derivedTable;

            MColumn[] sCols = source.GetColumns(false);
            MColumn[] tCols = target.GetColumns(false);
            //	Base Columns
            foreach (MColumn sCol in sCols)
            {
                MColumn tCol = null;
                foreach (MColumn column in tCols)
                {
                    if (sCol.GetColumnName().Equals(column.GetColumnName()))
                    {
                        tCol = column;
                        break;
                    }
                }
                if (tCol == null)
                {
                    tCol = new MColumn(target);
                }
                PO.CopyValues(sCol, tCol);
                tCol.SetAD_Table_ID(target.GetAD_Table_ID());   //	reset parent
                tCol.SetIsCallout(false);
                tCol.SetCallout(null);
                tCol.SetIsMandatory(false);
                tCol.SetIsMandatoryUI(false);
                tCol.SetIsTranslated(false);
                //	tCol.SetIsUpdateable(true);
                if (tCol.IsKey())
                {
                    tCol.SetIsKey(false);
                    tCol.SetAD_Reference_ID(DisplayType.TableDir);
                }
                if (tCol.Save())
                {
                    throw new Exception("Cannot save column " + sCol.GetColumnName());
                }
            }
            //
            tCols = target.GetColumns(true);
            List <String> addlColumns = new List <String>();

            if (derived && !m_history)  //	delta only
            {
                //	KeyColumn
                String  keyColumnName = target.GetTableName() + "_ID";
                MColumn key           = target.GetColumn(keyColumnName);
                if (key == null)
                {
                    key = new MColumn(target);
                    M_Element ele = M_Element.Get(m_ctx, keyColumnName, target.Get_TrxName());
                    if (ele == null)
                    {
                        ele = new M_Element(m_ctx, keyColumnName, target.GetEntityType(), null);
                        ele.Save();
                    }
                    key.SetAD_Element_ID(ele.GetAD_Element_ID());
                    key.SetAD_Reference_ID(DisplayType.ID);
                    key.Save();
                }
                addlColumns.Add(keyColumnName);
                //	Addl References
                if (m_userDef)
                {
                    String colName = "AD_Role_ID";
                    addlColumns.Add(colName);
                    if (target.GetColumn(colName) == null)
                    {
                        MColumn col = new MColumn(target);
                        col.SetColumnName(colName);
                        col.SetAD_Reference_ID(DisplayType.TableDir);
                        CreateColumn(col, target, false);
                        col.SetIsUpdateable(false);
                        col.SetIsMandatory(false);
                    }
                    colName = "AD_User_ID";
                    addlColumns.Add(colName);
                    if (target.GetColumn(colName) == null)
                    {
                        MColumn col = new MColumn(target);
                        col.SetColumnName(colName);
                        col.SetAD_Reference_ID(DisplayType.TableDir);
                        col.SetIsUpdateable(false);
                        col.SetIsMandatory(false);
                        CreateColumn(col, target, false);
                    }
                }
                else    //	System
                {
                    String colName = "IsSystemDefault";
                    addlColumns.Add(colName);
                    if (target.GetColumn(colName) == null)
                    {
                        MColumn col = new MColumn(target);
                        col.SetColumnName(colName);
                        col.SetAD_Reference_ID(DisplayType.YesNo);
                        col.SetDefaultValue("N");
                        col.SetIsUpdateable(false);
                        col.SetIsMandatory(true);
                        CreateColumn(col, target, false);
                    }
                }
            }


            //	Delete
            foreach (MColumn tCol in tCols)
            {
                MColumn sCol = null;
                foreach (MColumn column in sCols)
                {
                    if (tCol.GetColumnName().Equals(column.GetColumnName()))
                    {
                        sCol = column;
                        break;
                    }
                }
                if (sCol == null)
                {
                    if (!addlColumns.Contains(tCol.GetColumnName()))
                    {
                        if (!tCol.Delete(true))
                        {
                            throw new Exception("Cannot delete column "
                                                + tCol.GetColumnName());
                        }
                    }
                }
            }
            return(tCols);
        }       //	SyncMColumns
Beispiel #20
0
        /// <summary>
        /// To copy the task lines from project template Standard Task lines tab
        /// </summary>
        /// <param name="Task_ID">ID of tasks</param>
        /// <param name="C_ProjectTask_ID">Project task ID</param>
        /// <returns>No of lines created</returns>
        public int CopyMTaskLinesFromProjectTask(MProjectTask fromTask, MProjectTask toTask, int To_Project_ID)
        {
            ValueNamePair pp            = null;
            int           tasklinecount = 0;
            StringBuilder msg           = new StringBuilder();

            try
            {
                MProjectLine[]      fromLines = null;
                List <MProjectLine> list      = new List <MProjectLine>();

                DataSet projDs = DB.ExecuteDataset(" SELECT C_ProjectLine_ID FROM C_ProjectLine WHERE " +
                                                   " C_ProjectPhase_ID =" + fromTask.GetC_ProjectPhase_ID() + " AND C_ProjectTask_ID =" + fromTask.GetC_ProjectTask_ID() +
                                                   " AND IsActive='Y' ORDER BY Line ");

                if (projDs != null && projDs.Tables[0].Rows.Count > 0)
                {
                    for (int k = 0; k < projDs.Tables[0].Rows.Count; k++)
                    {
                        list.Add(new MProjectLine(GetCtx(), Util.GetValueOfInt(projDs.Tables[0].Rows[k]["C_ProjectLine_ID"]), Get_TrxName()));
                    }
                    fromLines = new MProjectLine[list.Count];
                    fromLines = list.ToArray();
                }

                if (fromLines != null && fromLines.Length > 0)
                {
                    for (int j = 0; j < fromLines.Length; j++)
                    {
                        MProjectLine line = new MProjectLine(GetCtx(), 0, Get_TrxName());
                        PO.CopyValues(fromLines[j], line, GetAD_Client_ID(), GetAD_Org_ID());
                        line.SetC_Project_ID(To_Project_ID);
                        line.SetC_ProjectTask_ID(toTask.GetC_ProjectTask_ID());
                        line.SetC_ProjectPhase_ID(toTask.GetC_ProjectPhase_ID());
                        line.SetInvoicedAmt(Env.ZERO);
                        line.SetInvoicedQty(Env.ZERO);
                        line.SetC_OrderPO_ID(0);
                        line.SetC_Order_ID(0);
                        line.SetProcessed(false);
                        if (line.Save())
                        {
                            tasklinecount++;
                        }
                        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());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Log(Level.SEVERE, "", ex);
            }
            //
            return(tasklinecount);
        }
Beispiel #21
0
        }       //	generate

        /// <summary>
        /// Generate Delta and History Table
        /// </summary>
        /// <returns></returns>
        private bool GenerateTable()
        {
            //	Table
            m_derivedTable = MTable.Get(m_ctx, m_dTableName);
            if (m_derivedTable == null)
            {
                m_derivedTable = new MTable(m_ctx, 0, null);
            }

            PO.CopyValues(m_baseTable, m_derivedTable);
            m_derivedTable.SetTableName(m_dTableName);
            m_derivedTable.SetName(m_derivedTable.GetName() + " SubTable");
            m_derivedTable.SetSubTableType(m_derivedTableType);
            m_derivedTable.SetBase_Table_ID(m_baseTable.GetAD_Table_ID());
            if (!m_derivedTable.Save())
            {
                throw new Exception("Cannot save " + m_dTableName);
            }

            MColumn[] dCols = SyncMColumns(true);

            //	Sync Columns in Database
            List <MColumn> list = new List <MColumn>(dCols.Length);

            foreach (MColumn element in dCols)
            {
                list.Add(element);
            }
            Trx trx = Trx.Get("getDatabaseMetaData");
            //

            String catalog   = "";
            String schema    = DataBase.DB.GetSchema();
            String tableName = m_dTableName;

            tableName = tableName.ToUpper();
            int noColumns = 0;
            //
            DataSet rs = null;

            using (DatabaseMetaData md = new DatabaseMetaData())
            {
                rs = md.GetColumns(catalog, schema, tableName);
            }
            for (int rscount = 0; rscount <= rs.Tables[0].Rows.Count - 1; rscount++)
            {
                noColumns++;
                String columnName = rs.Tables[0].Rows[rscount]["COLUMN_NAME"].ToString();
                bool   found      = false;
                for (int i = 0; i < list.Count; i++)
                {
                    MColumn dCol = list[i];
                    if (columnName.Equals(dCol.GetColumnName(), StringComparison.OrdinalIgnoreCase))
                    {
                        String sql = dCol.GetSQLModify(m_derivedTable, false);
                        DataBase.DB.ExecuteUpdateMultiple(sql, false, null);
                        found = true;
                        list.Remove(list[i]);
                        break;
                    }
                }
                if (!found)
                {
                    String sql = "ALTER TABLE " + m_dTableName + " DROP COLUMN " + columnName;
                    DataBase.DB.ExecuteQuery(sql, null);
                }
            }
            //rs.close();
            trx.Close();

            //	No Columns
            if (noColumns == 0)
            {
                String sql = m_derivedTable.GetSQLCreate();
                return(DataBase.DB.ExecuteUpdateMultiple(sql, false, null) >= 0);
            }
            //	New Columns
            for (int i = 0; i < list.Count(); i++)
            {
                MColumn dCol = list[i];
                if (dCol.IsVirtualColumn())
                {
                    continue;
                }
                String sql = dCol.GetSQLAdd(m_derivedTable);
                DataBase.DB.ExecuteUpdateMultiple(sql, false, null);
            }
            return(true);
        }       //	generateTable
Beispiel #22
0
 /**
  *  Import Constructor
  *	@param impP import
  */
 public MProduct(X_I_Product impP)
     : this(impP.GetCtx(), 0, impP.Get_TrxName())
 {
     PO.CopyValues(impP, this, impP.GetAD_Client_ID(), impP.GetAD_Org_ID());
 }