}       //	doIt

        /// <summary>
        /// Copy GL
        /// </summary>
        /// <param name="targetAS">target</param>
        private void CopyGL(MAcctSchema targetAS)
        {
            MAcctSchemaGL source = MAcctSchemaGL.Get(GetCtx(), _SourceAcctSchema_ID);
            MAcctSchemaGL target = new MAcctSchemaGL(GetCtx(), 0, Get_Trx());

            target.SetC_AcctSchema_ID(_TargetAcctSchema_ID);
            //ArrayList<KeyNamePair> list = source.getAcctInfo();
            List <KeyNamePair> list = source.GetAcctInfo();

            for (int i = 0; i < list.Count; i++)
            {
                //KeyNamePair pp = list.get(i);
                KeyNamePair pp = list[i];
                int         sourceC_ValidCombination_ID = pp.GetKey();
                String      columnName    = pp.GetName();
                MAccount    sourceAccount = MAccount.Get(GetCtx(), sourceC_ValidCombination_ID);
                MAccount    targetAccount = CreateAccount(targetAS, sourceAccount);
                target.SetValue(columnName, Utility.Util.GetValueOfInt(targetAccount.GetC_ValidCombination_ID()));
            }
            if (!target.Save())
            {
                throw new Exception("Could not Save GL");
            }
        }       //	copyGL
Esempio n. 2
0
        }       //	invalidateIt

        /// <summary>
        /// Prepare Document
        /// </summary>
        /// <returns>new status (In Progress or Invalid) </returns>
        public String PrepareIt()
        {
            log.Info(ToString());
            m_processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE);
            if (m_processMsg != null)
            {
                return(DocActionVariables.STATUS_INVALID);
            }
            MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID());

            //	Get Period
            MPeriod period = MPeriod.Get(GetCtx(), GetDateAcct());

            if (period == null)
            {
                log.Warning("No Period for " + GetDateAcct());
                m_processMsg = "@PeriodNotFound@";
                return(DocActionVariables.STATUS_INVALID);
            }
            //	Standard Period
            if (period.GetC_Period_ID() != GetC_Period_ID() &&
                period.IsStandardPeriod())
            {
                m_processMsg = "@PeriodNotValid@";
                return(DocActionVariables.STATUS_INVALID);
            }
            Boolean open = period.IsOpen(dt.GetDocBaseType());

            if (!open)
            {
                log.Warning(period.GetName()
                            + ": Not open for " + dt.GetDocBaseType() + " (" + GetDateAcct() + ")");
                m_processMsg = "@PeriodClosed@";
                return(DocActionVariables.STATUS_INVALID);
            }

            // JID_0521 - Restrict if debit and credit amount is not equal.-Mohit-12-jun-2019.
            if (GetTotalCr() != GetTotalDr())
            {
                m_processMsg = Msg.GetMsg(GetCtx(), "DBAndCRAmtNotEqual");
                return(DocActionVariables.STATUS_INVALID);
            }

            //	Lines
            MJournalLine[] lines = GetLines(true);
            if (lines.Length == 0)
            {
                m_processMsg = "@NoLines@";
                return(DocActionVariables.STATUS_INVALID);
            }

            //Manish 18/7/2016 .. Because if line dimention (Amount) column sum is not equals to debit or credit value complete process will not done.
            int     journalDRAndCR = 0;
            string  getlinevalues  = "SELECT NVL(ElementType,null) AS ElementType,AmtSourceDr,AmtAcctCr,AmtSourceCr,GL_JournalLine_ID FROM GL_JournalLine where GL_Journal_ID=" + Get_Value("GL_Journal_ID");
            DataSet dts            = DB.ExecuteDataset(getlinevalues, null, null);

            if (dts != null && dts.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
                {
                    journalDRAndCR = 0;

                    if (dts.Tables[0].Rows[i]["ElementType"].ToString() == "")
                    {
                        continue;
                    }

                    if (Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceDr"]) > 0)
                    {
                        journalDRAndCR = Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceDr"]);
                    }
                    else
                    {
                        if (Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceCr"]) > 0)
                        {
                            journalDRAndCR = Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceCr"]);
                        }
                    }

                    string getlineval = "SELECT SUM(amount) FROM gl_linedimension where GL_JournalLine_ID=" + Convert.ToInt32(dts.Tables[0].Rows[i]["GL_JournalLine_ID"]);
                    int    count      = Util.GetValueOfInt(DB.ExecuteScalar(getlineval));

                    if (journalDRAndCR != count)
                    {
                        m_processMsg = "@AmountNotMatch@";
                        return(DocActionVariables.STATUS_INVALID);
                    }
                }
            }



            //	Add up Amounts
            Decimal AmtSourceDr = Env.ZERO;
            Decimal AmtSourceCr = Env.ZERO;

            for (int i = 0; i < lines.Length; i++)
            {
                MJournalLine line = lines[i];
                if (!IsActive())
                {
                    continue;
                }
                //
                if (line.IsDocControlled())
                {
                    m_processMsg = "@DocControlledError@ - @Line@=" + line.GetLine()
                                   + " - " + line.GetAccountElementValue();
                    return(DocActionVariables.STATUS_INVALID);
                }
                //
                AmtSourceDr = Decimal.Add(AmtSourceDr, line.GetAmtAcctDr());
                AmtSourceCr = Decimal.Add(AmtSourceCr, line.GetAmtAcctCr());
            }
            SetTotalDr(AmtSourceDr);
            SetTotalCr(AmtSourceCr);

            //	Control Amount
            if (Env.ZERO.CompareTo(GetControlAmt()) != 0 &&
                GetControlAmt().CompareTo(GetTotalDr()) != 0)
            {
                m_processMsg = "@ControlAmtError@";
                return(DocActionVariables.STATUS_INVALID);
            }

            //	Unbalanced Jornal & Not Suspense
            if (AmtSourceDr.CompareTo(AmtSourceCr) != 0)
            {
                MAcctSchemaGL gl = MAcctSchemaGL.Get(GetCtx(), GetC_AcctSchema_ID());
                if (gl == null || !gl.IsUseSuspenseBalancing())
                {
                    m_processMsg = "@UnbalancedJornal@";
                    return(DocActionVariables.STATUS_INVALID);
                }
            }

            if (!DOCACTION_Complete.Equals(GetDocAction()))
            {
                SetDocAction(DOCACTION_Complete);
            }
            m_justPrepared = true;
            return(DocActionVariables.STATUS_INPROGRESS);
        }       //	prepareIt
        }       //	prepare

        /// <summary>
        /// Process
        /// </summary>
        /// <returns>Info</returns>
        protected override String DoIt()
        {
            log.Info("SourceAcctSchema_ID=" + _SourceAcctSchema_ID
                     + ", TargetAcctSchema_ID=" + _TargetAcctSchema_ID);

            if (_SourceAcctSchema_ID == 0 || _TargetAcctSchema_ID == 0)
            {
                throw new Exception("ID=0");
            }
            if (_SourceAcctSchema_ID == _TargetAcctSchema_ID)
            {
                throw new Exception("Account Schema must be different");
            }

            MAcctSchema source = MAcctSchema.Get(GetCtx(), _SourceAcctSchema_ID, null);

            if (source.Get_ID() == 0)
            {
                throw new Exception("@NotFound@ Source @C_AcctSchema_ID@=" + _SourceAcctSchema_ID);
            }
            MAcctSchema target = new MAcctSchema(GetCtx(), _TargetAcctSchema_ID, Get_Trx());

            if (target.Get_ID() == 0)
            {
                throw new Exception("@NotFound@ Target @C_AcctSchema_ID@=" + _TargetAcctSchema_ID);
            }
            //

            //	MAcctSchemaElement[] sourceElements = source.getAcctSchemaElements();
            MAcctSchemaElement[] targetElements = target.GetAcctSchemaElements();
            if (targetElements.Length == 0)
            {
                throw new Exception("@NotFound@ Target C_AcctSchema_Element");
            }
            //	Accounting Element must be the same
            MAcctSchemaElement sourceAcctElement = source.GetAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Account);

            if (sourceAcctElement == null)
            {
                throw new Exception("NotFound Source AC C_AcctSchema_Element");
            }
            MAcctSchemaElement targetAcctElement = target.GetAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Account);

            if (targetAcctElement == null)
            {
                throw new Exception("NotFound Target AC C_AcctSchema_Element");
            }
            if (sourceAcctElement.GetC_Element_ID() != targetAcctElement.GetC_Element_ID())
            {
                throw new Exception("@C_Element_ID@ different");
            }
            if (MAcctSchemaGL.Get(GetCtx(), _TargetAcctSchema_ID) == null)
            {
                CopyGL(target);
            }
            if (MAcctSchemaDefault.Get(GetCtx(), _TargetAcctSchema_ID) == null)
            {
                CopyDefault(target);
            }
            return("@OK@");
        }       //	doIt