protected override bool BeforeSave(bool newRecord)
        {
            //JID_1292: Cheque Date must be greater than Account Date
            MVA027PostDatedCheck pdc = new MVA027PostDatedCheck(GetCtx(), GetVA027_PostDatedCheck_ID(), Get_Trx());

            if (newRecord || Is_ValueChanged("VA027_CheckDate") || Is_ValueChanged("IsActive"))
            {
                if (!(pdc.GetVA027_Description() != null && pdc.GetVA027_Description().Contains("{->")))
                {
                    if (GetVA027_CheckDate().Value.Date <= pdc.GetDateAcct().Value.Date)
                    {
                        log.SaveError("", Msg.GetMsg(GetCtx(), "VA027_CheckDateCanbeGreaterSys"));
                        return(false);
                    }
                }
            }

            // validate when we giving check (Payable)
            MDocType docType = new MDocType(GetCtx(), pdc.GetC_DocType_ID(), Get_Trx());

            if (docType.GetDocBaseType() != "PDR")
            {
                // Validate Unique entry based on bank Account and Check No
                if ((!string.IsNullOrEmpty(GetVA027_CheckNo())) && (newRecord || Is_ValueChanged("VA027_CheckNo")))
                {
                    string sql = null;
                    // check on cheque detail tab
                    if (newRecord)
                    {
                        sql = @"SELECT COUNT(*) FROM VA027_ChequeDetails cd INNER JOIN VA027_PostDatedCheck pdc ON pdc.VA027_PostDatedCheck_ID = cd.VA027_PostDatedCheck_ID 
                            INNER JOIN  C_BankAccount ba ON ba.C_BankAccount_ID = pdc.C_BankAccount_ID 
                            INNER JOIN C_Bank b ON b.C_Bank_ID = ba.C_Bank_ID  
                            INNER JOIN C_DocType dt ON dt.C_DocType_ID = pdc.C_DocType_ID 
                            WHERE cd.IsActive = 'Y' AND pdc.IsActive = 'Y' AND pdc.DocStatus NOT IN ('RE', 'VO') AND dt.DocBaseType <> 'PDR' AND 
                            b.C_Bank_ID = (SELECT C_Bank_ID FROM c_bankaccount WHERE C_BankAccount_ID =" + pdc.GetC_BankAccount_ID() +
                              @" ) AND cd.VA027_CheckNo = '" + GetVA027_CheckNo() + @"'";
                    }
                    else
                    {
                        sql = @"SELECT COUNT(*) FROM VA027_ChequeDetails cd INNER JOIN VA027_PostDatedCheck pdc ON pdc.VA027_PostDatedCheck_ID = cd.VA027_PostDatedCheck_ID 
                            INNER JOIN  C_BankAccount ba ON ba.C_BankAccount_ID = pdc.C_BankAccount_ID 
                            INNER JOIN C_Bank b ON b.C_Bank_ID = ba.C_Bank_ID  
                            INNER JOIN C_DocType dt ON dt.C_DocType_ID = pdc.C_DocType_ID 
                            WHERE cd.IsActive = 'Y' AND pdc.IsActive = 'Y' AND pdc.DocStatus NOT IN ('RE', 'VO') AND dt.DocBaseType <> 'PDR' AND 
                            b.C_Bank_ID = (SELECT C_Bank_ID FROM c_bankaccount WHERE C_BankAccount_ID =" + pdc.GetC_BankAccount_ID() +
                              @" ) AND cd.VA027_CheckNo = '" + GetVA027_CheckNo() + @"' AND cd.VA027_ChequeDetails_ID <> " + GetVA027_ChequeDetails_ID();
                    }
                    int count = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx()));
                    if (count > 0)
                    {
                        log.SaveError("Error", Msg.GetMsg(GetCtx(), "VA027_Bank_ChequeNoNotSame"));
                        return(false);
                    }
                    else
                    {
                        // check independently on Post Dated check table
                        count = 0;
                        sql   = @"SELECT COUNT(*) FROM  VA027_PostDatedCheck pdc  
                            INNER JOIN  C_BankAccount ba ON ba.C_BankAccount_ID = pdc.C_BankAccount_ID 
                            INNER JOIN C_Bank b ON b.C_Bank_ID = ba.C_Bank_ID  
                            INNER JOIN C_DocType dt ON dt.C_DocType_ID = pdc.C_DocType_ID 
                            WHERE  pdc.IsActive = 'Y' AND pdc.VA027_MultiCheque = 'N' AND dt.DocBaseType <> 'PDR' AND 
                            b.C_Bank_ID = (SELECT C_Bank_ID FROM c_bankaccount WHERE C_BankAccount_ID =" + pdc.GetC_BankAccount_ID() +
                                @" ) AND pdc.VA027_CheckNo = '" + GetVA027_CheckNo() + @"' AND pdc.DocStatus NOT IN ('RE', 'VO')";
                        count = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx()));
                        if (count > 0)
                        {
                            log.SaveError("Error", Msg.GetMsg(GetCtx(), "VA027_Bank_ChequeNoNotSame"));
                            return(false);
                        }
                    }

                    // check Payment Table
                    count = 0;
                    sql   = @"SELECT COUNT(*) FROM  C_Payment pdc
                        INNER JOIN  C_BankAccount ba ON ba.C_BankAccount_ID = pdc.C_BankAccount_ID 
                        INNER JOIN C_Bank b ON b.C_Bank_ID = ba.C_Bank_ID  
                        INNER JOIN C_DocType dt ON dt.C_DocType_ID = pdc.C_DocType_ID
                        WHERE  pdc.IsActive = 'Y' AND
                        b.C_Bank_ID = (SELECT C_Bank_ID FROM c_bankaccount WHERE C_BankAccount_ID =" + pdc.GetC_BankAccount_ID() +
                            @" ) AND pdc.CheckNo = '" + GetVA027_CheckNo() + @"' AND DocStatus NOT IN ('RE', 'VO') AND dt.DocBaseType <> 'ARR'";
                    count = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx()));
                    if (count > 0)
                    {
                        log.SaveError("Error", Msg.GetMsg(GetCtx(), "VA027_Bank_ChequeNoNotSameOnPay"));
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemple #2
0
        public bool ReverseCorrectIt()
        {
            try
            {
                MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID());
                if (!MPeriod.IsOpen(GetCtx(), GetDateAcct(), dt.GetDocBaseType()))
                {
                    _processMsg = "@PeriodClosed@";
                    return(false);
                }

                // is Non Business Day?
                if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateAcct()))
                {
                    _processMsg = VAdvantage.Common.Common.NONBUSINESSDAY;
                    return(false);
                }
                //commented by arpit
                //if (!IsVA027_PaymentGenerated())
                //{
                //    _processMsg = "Payment Not Generated Yet";
                //    Get_Trx().Rollback();
                //    return false;
                //}
                //end here
                if (GetC_Payment_ID() > 0)
                {
                    MPayment pay = new MPayment(GetCtx(), GetC_Payment_ID(), Get_Trx());
                    if (pay.GetDocStatus() != "RE" && pay.GetDocStatus() != "VO")
                    {
                        _processMsg = Msg.GetMsg(GetCtx(), "VA027_PaymentNotVoid");
                        Get_Trx().Rollback();
                        return(false);
                    }
                }
                MVA027PostDatedCheck reversal = new MVA027PostDatedCheck(GetCtx(), 0, Get_Trx());
                CopyValues(this, reversal);
                reversal.SetClientOrg(this);
                reversal.SetVA027_PayAmt(Decimal.Negate(reversal.GetVA027_PayAmt()));
                reversal.SetDocumentNo(GetDocumentNo() + REVERSE_INDICATOR);
                if (!string.IsNullOrEmpty(GetVA027_CheckNo()))
                {
                    reversal.SetVA027_CheckNo(GetVA027_CheckNo() + REVERSE_INDICATOR);
                }
                reversal.SetDocStatus(DOCSTATUS_Drafted);
                reversal.SetDocAction(DOCACTION_Complete);
                reversal.SetProcessed(false);
                reversal.SetProcessing(false);
                reversal.SetPosted(false);
                reversal.SetVA027_Description(GetVA027_Description());
                reversal.AddDescription("{->" + GetDocumentNo() + ")");
                if (reversal.Save(Get_Trx()))
                {
                    DataSet ds = new DataSet();
                    ds = DB.ExecuteDataset("Select * from VA027_CHEQUEDETAILS Where VA027_PostDatedCheck_ID=" + GetVA027_PostDatedCheck_ID(), null, Get_Trx());
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        for (Int32 i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            MVA027ChequeDetails original = new MVA027ChequeDetails(GetCtx(), Util.GetValueOfInt(ds.Tables[0].Rows[i]["VA027_CHEQUEDETAILS_ID"]), Get_Trx());
                            MVA027ChequeDetails cd       = new MVA027ChequeDetails(GetCtx(), 0, Get_Trx());
                            if (original.GetC_Payment_ID() > 0)
                            {
                                MPayment payment = new MPayment(GetCtx(), original.GetC_Payment_ID(), Get_Trx());
                                if (payment.GetDocStatus() != "RE" && payment.GetDocStatus() != "VO")
                                {
                                    _processMsg = Msg.GetMsg(GetCtx(), "VA027_PaymentNotVoid");
                                    Get_Trx().Rollback();
                                    return(false);
                                }
                            }
                            cd.SetAD_Client_ID(original.GetAD_Client_ID());
                            cd.SetAD_Org_ID(original.GetAD_Org_ID());
                            cd.SetVA027_AccountName(original.GetVA027_AccountName());
                            cd.SetLineNo(original.GetLineNo());
                            cd.SetVA027_PostDatedCheck_ID(reversal.GetVA027_PostDatedCheck_ID());
                            cd.SetVA027_AccountNo(original.GetVA027_AccountNo());
                            cd.SetVA027_CheckDate(original.GetVA027_CheckDate());
                            cd.SetVA027_CheckNo(original.GetVA027_CheckNo() + REVERSE_INDICATOR);
                            cd.SetVA027_ChequeAmount(Decimal.Negate(original.GetVA027_ChequeAmount()));
                            cd.SetVA027_MICR(original.GetVA027_MICR());
                            cd.SetVA027_PaymentStatus("3");
                            cd.SetVA027_ValidMonth(original.GetVA027_ValidMonth());
                            cd.SetProcessed(true);
                            cd.Save(Get_Trx());
                        }
                    }
                }

                if (!reversal.ProcessIt(DocActionVariables.ACTION_COMPLETE))
                {
                    _processMsg = "Reversal ERROR: " + reversal.GetProcessMsg();
                    return(false);
                }
                reversal.CloseIt();
                _processMsg = reversal.GetDocumentNo();
                reversal.SetVA027_PaymentStatus("3");
                reversal.SetDocStatus(DOCSTATUS_Reversed);
                reversal.SetDocAction(DOCACTION_None);
                reversal.Save(Get_Trx());

                this.AddDescription("(" + GetDocumentNo() + "<-)");

                SetDocStatus(DOCSTATUS_Reversed);
                SetDocAction(DOCACTION_None);
                SetProcessed(true);
            }
            catch (Exception ex)
            {
                log.Severe(ex.ToString());
                log.Severe("Error in Reverse.");
            }

            return(true);
        }