Beispiel #1
0
        /**
         *  Set Amount or WriteOffAmt for Invoices
         *	@param windowNo window
         *	@param columnName source column
         */
        private void SetAmt(int windowNo, String columnName)
        {
            //  Needs to be Invoice
            if (!CASHTYPE_Invoice.Equals(GetCashType()))
            {
                return;
            }
            //  Check, if InvTotalAmt exists
            String total = GetCtx().GetContext(windowNo, "InvTotalAmt");

            if (total == null || total.Length == 0)
            {
                return;
            }
            Decimal InvTotalAmt = Convert.ToDecimal(total);

            Decimal PayAmt      = GetAmount();
            Decimal DiscountAmt = GetDiscountAmt();
            Decimal WriteOffAmt = GetWriteOffAmt();

            log.Fine(columnName + " - Invoice=" + InvTotalAmt
                     + " - Amount=" + PayAmt + ", Discount=" + DiscountAmt + ", WriteOff=" + WriteOffAmt);

            //  Amount - calculate write off
            if (columnName.Equals("Amount"))
            {
                WriteOffAmt = Decimal.Subtract(InvTotalAmt, Decimal.Subtract(PayAmt, DiscountAmt));
                SetWriteOffAmt(WriteOffAmt);
            }
            else    //  calculate PayAmt
            {
                PayAmt = Decimal.Subtract(InvTotalAmt, Decimal.Subtract(DiscountAmt, WriteOffAmt));
                SetAmount(PayAmt);
            }
        }
Beispiel #2
0
        /**
         *  Before Save
         *	@param newRecord
         *	@return true/false
         */
        protected override bool BeforeSave(bool newRecord)
        {
            // Added by Amit 1-8-2015 VAMRP
            //if (Env.HasModulePrefix("VAMRP_", out mInfo))
            //{
            //    //for kc
            //    //charge
            //    if (GetCashType() == "C")
            //    {
            //        SetC_Invoice_ID(0);
            //        SetDiscountAmt(0);
            //        SetWriteOffAmt(0);
            //        SetC_BankAccount_ID(0);
            //    }
            //    //invoice
            //    if (GetCashType() == "I")
            //    {
            //        SetC_BPartner_ID(0);
            //        SetC_Charge_ID(0);
            //        SetC_BankAccount_ID(0);
            //    }
            //    //bank a/c transfer
            //    if (GetCashType() == "T")
            //    {
            //        SetC_Invoice_ID(0);
            //        SetDiscountAmt(0);
            //        SetWriteOffAmt(0);
            //        SetC_BPartner_ID(0);
            //        SetC_Charge_ID(0);
            //    }
            //    //genral expense
            //    if (GetCashType() == "E")
            //    {
            //        SetC_Invoice_ID(0);
            //        SetDiscountAmt(0);
            //        SetWriteOffAmt(0);
            //        SetC_BPartner_ID(0);
            //        SetC_Charge_ID(0);
            //        SetC_BankAccount_ID(0);
            //    }
            //    //genral receipt
            //    if (GetCashType() == "R")
            //    {
            //        SetC_Invoice_ID(0);
            //        SetDiscountAmt(0);
            //        SetWriteOffAmt(0);
            //        SetC_BPartner_ID(0);
            //        SetC_Charge_ID(0);
            //        SetC_BankAccount_ID(0);
            //    }
            //    //differennce
            //    if (GetCashType() == "D")
            //    {
            //        SetC_Invoice_ID(0);
            //        SetDiscountAmt(0);
            //        SetWriteOffAmt(0);
            //        SetC_BPartner_ID(0);
            //        SetC_Charge_ID(0);
            //        SetC_BankAccount_ID(0);
            //    }
            //}
            // End

            //	Cannot change generated Invoices
            if (Is_ValueChanged("C_Invoice_ID"))
            {
                Object generated = Get_ValueOld("IsGenerated");
                if (generated != null && ((Boolean)generated))
                {
                    log.Warning("Cannot change line with generated Invoice");
                    return(false);
                }
            }

            // during saving a new record, system will check same invoice schedule reference exist on same cash line or not
            if (newRecord && GetCashType() == CASHTYPE_Invoice && GetC_InvoicePaySchedule_ID() > 0)
            {
                if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(*) FROM C_CashLine WHERE C_Cash_ID = " + GetC_Cash_ID() +
                                                        @" AND IsActive = 'Y' AND C_InvoicePaySchedule_ID = " + GetC_InvoicePaySchedule_ID(), null, Get_Trx())) > 0)
                {
                    log.SaveError("Error", Msg.GetMsg(GetCtx(), "VIS_NotSaveDuplicateRecord"));
                    return(false);
                }
            }

            //	Verify CashType
            if (CASHTYPE_Invoice.Equals(GetCashType()) && GetC_Invoice_ID() == 0)
            {
                SetCashType(CASHTYPE_GeneralExpense);
            }
            if (CASHTYPE_BankAccountTransfer.Equals(GetCashType()) && GetC_BankAccount_ID() == 0)
            {
                SetCashType(CASHTYPE_GeneralExpense);
            }
            if (CASHTYPE_Charge.Equals(GetCashType()) && GetC_Charge_ID() == 0)
            {
                SetCashType(CASHTYPE_GeneralExpense);
            }

            bool verify = newRecord ||
                          Is_ValueChanged("CashType") ||
                          Is_ValueChanged("C_Invoice_ID") ||
                          Is_ValueChanged("C_BankAccount_ID");

            if (verify)
            {
                //	Verify Currency
                if (CASHTYPE_BankAccountTransfer.Equals(GetCashType()))
                {
                    SetC_Currency_ID(GetBankAccount().GetC_Currency_ID());
                }
                else if (CASHTYPE_Invoice.Equals(GetCashType()))
                {
                    // Added by Amit 1-8-2015 VAMRP
                    if (Env.HasModulePrefix("VAMRP_", out mInfo))
                    {
                        // SetC_Currency_ID(GetInvoice().GetC_Currency_ID());
                    }
                    else
                    {
                        // Commented To Get the Invoice Open Amount Right in case of Diff Currencies
                        // SetC_Currency_ID(GetInvoice().GetC_Currency_ID());
                    }
                    //end
                }
                else    //	Cash
                {
                    SetC_Currency_ID(GetCashBook().GetC_Currency_ID());
                }

                //	Set Organization
                if (CASHTYPE_BankAccountTransfer.Equals(GetCashType()))
                {
                    SetAD_Org_ID(GetBankAccount().GetAD_Org_ID());
                }
                //	Cash Book
                else if (CASHTYPE_Invoice.Equals(GetCashType()))
                {
                    SetAD_Org_ID(GetCashBook().GetAD_Org_ID());
                }
                //	otherwise (charge) - leave it
                //	Enforce Org
                if (GetAD_Org_ID() == 0)
                {
                    SetAD_Org_ID(GetParent().GetAD_Org_ID());
                }
            }

            /**	General fix of Currency
             * UPDATE C_CashLine cl SET C_Currency_ID = (SELECT C_Currency_ID FROM C_Invoice i WHERE i.C_Invoice_ID=cl.C_Invoice_ID) WHERE C_Currency_ID IS NULL AND C_Invoice_ID IS NOT NULL;
             * UPDATE C_CashLine cl SET C_Currency_ID = (SELECT C_Currency_ID FROM C_BankAccount b WHERE b.C_BankAccount_ID=cl.C_BankAccount_ID) WHERE C_Currency_ID IS NULL AND C_BankAccount_ID IS NOT NULL;
             * UPDATE C_CashLine cl SET C_Currency_ID = (SELECT b.C_Currency_ID FROM C_Cash c, C_CashBook b WHERE c.C_Cash_ID=cl.C_Cash_ID AND c.C_CashBook_ID=b.C_CashBook_ID) WHERE C_Currency_ID IS NULL;
             **/

            //	Get Line No
            if (GetLine() == 0)
            {
                String sql = "SELECT COALESCE(MAX(Line),0)+10 FROM C_CashLine WHERE C_Cash_ID=@param1";
                int    ii  = DB.GetSQLValue(Get_TrxName(), sql, GetC_Cash_ID());
                SetLine(ii);
            }

            // Added by Amit 1-8-2015 VAMRP
            //if (Env.HasModulePrefix("VAMRP_", out mInfo))
            //{
            //    if (GetVSS_RECEIPTNO() == null || GetVSS_RECEIPTNO() == "")
            //    {
            //        MOrg mo = new MOrg(GetCtx(), GetAD_Org_ID(), Get_TrxName());
            //        String org_name = mo.GetName();
            //        //modified by ashish.bisht on 04-feb-10
            //        String paymenttype = GetVSS_PAYMENTTYPE();
            //        String test_name = "DocNo_" + org_name + "_" + paymenttype;

            //        int[] s = MSequence.GetAllIDs("AD_Sequence", "Name= '" + test_name + "'", Get_TrxName());

            //        if (s != null && s.Length != 0)
            //        {
            //            MSequence sqq = new MSequence(GetCtx(), s[0], Get_TrxName());
            //            String ss = sqq.GetName();

            //            if (ss.Equals(test_name))
            //            {
            //                int inc = sqq.GetIncrementNo();
            //                String pre = sqq.GetPrefix();
            //                String suff = sqq.GetSuffix();

            //                int curr = sqq.GetCurrentNext();
            //                curr = curr + inc;
            //                sqq.SetCurrentNext(curr);
            //                sqq.Save();
            //                String StrCurr = "" + curr;

            //                if (pre == null && suff == null)
            //                {
            //                    SetVSS_RECEIPTNO(StrCurr);
            //                }
            //                if (pre != null && suff == null)
            //                {
            //                    SetVSS_RECEIPTNO(pre + StrCurr);
            //                }
            //                if (pre == null && suff != null)
            //                {
            //                    SetVSS_RECEIPTNO(StrCurr + suff);
            //                }

            //                if (pre != null && suff != null)
            //                {
            //                    SetVSS_RECEIPTNO(pre + StrCurr + suff);
            //                }
            //            }
            //        }
            //    }
            //}
            //End
            return(true);
        }
Beispiel #3
0
        /**
         *  Before Save
         *	@param newRecord
         *	@return true/false
         */
        protected override bool BeforeSave(bool newRecord)
        {
            // Added by Amit 1-8-2015 VAMRP
            //if (Env.HasModulePrefix("VAMRP_", out mInfo))
            //{
            //    //for kc
            //    //charge
            //    if (GetCashType() == "C")
            //    {
            //        SetC_Invoice_ID(0);
            //        SetDiscountAmt(0);
            //        SetWriteOffAmt(0);
            //        SetC_BankAccount_ID(0);
            //    }
            //    //invoice
            //    if (GetCashType() == "I")
            //    {
            //        SetC_BPartner_ID(0);
            //        SetC_Charge_ID(0);
            //        SetC_BankAccount_ID(0);
            //    }
            //    //bank a/c transfer
            //    if (GetCashType() == "T")
            //    {
            //        SetC_Invoice_ID(0);
            //        SetDiscountAmt(0);
            //        SetWriteOffAmt(0);
            //        SetC_BPartner_ID(0);
            //        SetC_Charge_ID(0);
            //    }
            //    //genral expense
            //    if (GetCashType() == "E")
            //    {
            //        SetC_Invoice_ID(0);
            //        SetDiscountAmt(0);
            //        SetWriteOffAmt(0);
            //        SetC_BPartner_ID(0);
            //        SetC_Charge_ID(0);
            //        SetC_BankAccount_ID(0);
            //    }
            //    //genral receipt
            //    if (GetCashType() == "R")
            //    {
            //        SetC_Invoice_ID(0);
            //        SetDiscountAmt(0);
            //        SetWriteOffAmt(0);
            //        SetC_BPartner_ID(0);
            //        SetC_Charge_ID(0);
            //        SetC_BankAccount_ID(0);
            //    }
            //    //differennce
            //    if (GetCashType() == "D")
            //    {
            //        SetC_Invoice_ID(0);
            //        SetDiscountAmt(0);
            //        SetWriteOffAmt(0);
            //        SetC_BPartner_ID(0);
            //        SetC_Charge_ID(0);
            //        SetC_BankAccount_ID(0);
            //    }
            //}
            // End

            //	Cannot change generated Invoices
            if (Is_ValueChanged("C_Invoice_ID"))
            {
                Object generated = Get_ValueOld("IsGenerated");
                if (generated != null && ((Boolean)generated))
                {
                    log.Warning("Cannot change line with generated Invoice");
                    return(false);
                }
            }

            // during saving a new record, system will check same invoice schedule reference exist on same cash line or not
            if (newRecord && GetCashType() == CASHTYPE_Invoice && GetC_InvoicePaySchedule_ID() > 0)
            {
                if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(*) FROM C_CashLine WHERE C_Cash_ID = " + GetC_Cash_ID() +
                                                        @" AND IsActive = 'Y' AND C_InvoicePaySchedule_ID = " + GetC_InvoicePaySchedule_ID(), null, Get_Trx())) > 0)
                {
                    log.SaveError("Error", Msg.GetMsg(GetCtx(), "VIS_NotSaveDuplicateRecord"));
                    return(false);
                }
            }

            // check schedule is hold or not, if hold then no to save record
            if (Get_ColumnIndex("C_InvoicePaySchedule_ID") >= 0 && GetC_InvoicePaySchedule_ID() > 0)
            {
                if (IsHoldpaymentSchedule(GetC_InvoicePaySchedule_ID()))
                {
                    log.SaveError("", Msg.GetMsg(GetCtx(), "VIS_PaymentisHold"));
                    return(false);
                }
            }

            //	Verify CashType
            if (CASHTYPE_Invoice.Equals(GetCashType()) && GetC_Invoice_ID() == 0)
            {
                SetCashType(CASHTYPE_GeneralExpense);
            }
            if (CASHTYPE_BankAccountTransfer.Equals(GetCashType()) && GetC_BankAccount_ID() == 0)
            {
                SetCashType(CASHTYPE_GeneralExpense);
            }
            if (CASHTYPE_Charge.Equals(GetCashType()) && GetC_Charge_ID() == 0)
            {
                SetCashType(CASHTYPE_GeneralExpense);
            }

            // JID_1244: On Save of record need to check cash journal account date with check date. If check date is greater than account data need to give error as on payment window.
            if (CASHTYPE_BankAccountTransfer.Equals(GetCashType()))
            {
                if (GetCheckDate() != null)
                {
                    if (GetCheckDate().Value.Date > GetParent().GetDateAcct().Value.Date)
                    {
                        log.SaveError("Error", Msg.GetMsg(GetCtx(), "VIS_CheckDateCantbeGreaterSys"));
                        return(false);
                    }
                }
            }

            bool verify = newRecord ||
                          Is_ValueChanged("CashType") ||
                          Is_ValueChanged("C_Invoice_ID") ||
                          Is_ValueChanged("C_BankAccount_ID");

            if (verify)
            {
                //	Verify Currency
                if (CASHTYPE_BankAccountTransfer.Equals(GetCashType()))
                {
                    SetC_Currency_ID(GetBankAccount().GetC_Currency_ID());
                }
                else if (CASHTYPE_Invoice.Equals(GetCashType()))
                {
                    // Added by Amit 1-8-2015 VAMRP
                    if (Env.HasModulePrefix("VAMRP_", out mInfo))
                    {
                        // SetC_Currency_ID(GetInvoice().GetC_Currency_ID());
                    }
                    else
                    {
                        // Commented To Get the Invoice Open Amount Right in case of Diff Currencies
                        // SetC_Currency_ID(GetInvoice().GetC_Currency_ID());
                    }
                    //end
                }
                // Added by Bharat on 16/12/2016 handle the case of Multicurrency in Cash Book Transfer
                else if (CASHTYPE_CashBookTransfer.Equals(GetCashType()))
                {
                }
                else if (CASHTYPE_CashRecievedFrom.Equals(GetCashType()))
                {
                }
                else    //	Cash
                {
                    SetC_Currency_ID(GetCashBook().GetC_Currency_ID());
                }

                //	Set Organization
                if (CASHTYPE_BankAccountTransfer.Equals(GetCashType()))
                {
                    SetAD_Org_ID(GetBankAccount().GetAD_Org_ID());
                }
                //	Cash Book
                else if (CASHTYPE_Invoice.Equals(GetCashType()))
                {
                    SetAD_Org_ID(GetCashBook().GetAD_Org_ID());
                }
                //	otherwise (charge) - leave it
                //	Enforce Org
                if (GetAD_Org_ID() == 0)
                {
                    SetAD_Org_ID(GetParent().GetAD_Org_ID());
                }
            }

            /**	General fix of Currency
             * UPDATE C_CashLine cl SET C_Currency_ID = (SELECT C_Currency_ID FROM C_Invoice i WHERE i.C_Invoice_ID=cl.C_Invoice_ID) WHERE C_Currency_ID IS NULL AND C_Invoice_ID IS NOT NULL;
             * UPDATE C_CashLine cl SET C_Currency_ID = (SELECT C_Currency_ID FROM C_BankAccount b WHERE b.C_BankAccount_ID=cl.C_BankAccount_ID) WHERE C_Currency_ID IS NULL AND C_BankAccount_ID IS NOT NULL;
             * UPDATE C_CashLine cl SET C_Currency_ID = (SELECT b.C_Currency_ID FROM C_Cash c, C_CashBook b WHERE c.C_Cash_ID=cl.C_Cash_ID AND c.C_CashBook_ID=b.C_CashBook_ID) WHERE C_Currency_ID IS NULL;
             **/

            //	Get Line No
            if (GetLine() == 0)
            {
                String sql = "SELECT COALESCE(MAX(Line),0)+10 FROM C_CashLine WHERE C_Cash_ID=@param1";
                int    ii  = DB.GetSQLValue(Get_TrxName(), sql, GetC_Cash_ID());
                SetLine(ii);
            }

            // JID_1326: Voucher number would be pick from document number from header Hyphen line number
            if (String.IsNullOrEmpty(GetVSS_RECEIPTNO()))
            {
                SetVSS_RECEIPTNO(Util.GetValueOfString(GetParent().Get_Value("DocumentNo")) + "-" + GetLine());
            }

            // Added by Amit 1-8-2015 VAMRP
            //if (Env.HasModulePrefix("VAMRP_", out mInfo))
            //{
            //    if (GetVSS_RECEIPTNO() == null || GetVSS_RECEIPTNO() == "")
            //    {
            //        MOrg mo = new MOrg(GetCtx(), GetAD_Org_ID(), Get_TrxName());
            //        String org_name = mo.GetName();
            //        //modified by ashish.bisht on 04-feb-10
            //        String paymenttype = GetVSS_PAYMENTTYPE();
            //        String test_name = "DocNo_" + org_name + "_" + paymenttype;

            //        int[] s = MSequence.GetAllIDs("AD_Sequence", "Name= '" + test_name + "'", Get_TrxName());

            //        if (s != null && s.Length != 0)
            //        {
            //            MSequence sqq = new MSequence(GetCtx(), s[0], Get_TrxName());
            //            String ss = sqq.GetName();

            //            if (ss.Equals(test_name))
            //            {
            //                int inc = sqq.GetIncrementNo();
            //                String pre = sqq.GetPrefix();
            //                String suff = sqq.GetSuffix();

            //                int curr = sqq.GetCurrentNext();
            //                curr = curr + inc;
            //                sqq.SetCurrentNext(curr);
            //                sqq.Save();
            //                String StrCurr = "" + curr;

            //                if (pre == null && suff == null)
            //                {
            //                    SetVSS_RECEIPTNO(StrCurr);
            //                }
            //                if (pre != null && suff == null)
            //                {
            //                    SetVSS_RECEIPTNO(pre + StrCurr);
            //                }
            //                if (pre == null && suff != null)
            //                {
            //                    SetVSS_RECEIPTNO(StrCurr + suff);
            //                }

            //                if (pre != null && suff != null)
            //                {
            //                    SetVSS_RECEIPTNO(pre + StrCurr + suff);
            //                }
            //            }
            //        }
            //    }
            //}
            //End

            // Reset Amount Dimension if Amount is different
            if (Util.GetValueOfInt(Get_Value("AmtDimAmount")) > 0)
            {
                string  qry       = "SELECT Amount FROM C_DimAmt WHERE C_DimAmt_ID=" + Util.GetValueOfInt(Get_Value("AmtDimAmount"));
                decimal amtdimAmt = Util.GetValueOfDecimal(DB.ExecuteScalar(qry, null, Get_TrxName()));

                if (amtdimAmt != GetAmount())
                {
                    resetAmtDim = true;
                    Set_Value("AmtDimAmount", null);
                }
            }

            return(true);
        }
Beispiel #4
0
        /**
         *  Before Save
         *	@param newRecord
         *	@return true/false
         */
        protected override bool BeforeSave(bool newRecord)
        {
            //	Cannot change generated Invoices
            if (Is_ValueChanged("C_Invoice_ID"))
            {
                Object generated = Get_ValueOld("IsGenerated");
                if (generated != null && ((Boolean)generated))
                {
                    log.Warning("Cannot change line with generated Invoice");
                    return(false);
                }
            }

            //	Verify CashType
            if (CASHTYPE_Invoice.Equals(GetCashType()) && GetC_Invoice_ID() == 0)
            {
                SetCashType(CASHTYPE_GeneralExpense);
            }
            if (CASHTYPE_BankAccountTransfer.Equals(GetCashType()) && GetC_BankAccount_ID() == 0)
            {
                SetCashType(CASHTYPE_GeneralExpense);
            }
            if (CASHTYPE_Charge.Equals(GetCashType()) && GetC_Charge_ID() == 0)
            {
                SetCashType(CASHTYPE_GeneralExpense);
            }

            bool verify = newRecord ||
                          Is_ValueChanged("CashType") ||
                          Is_ValueChanged("C_Invoice_ID") ||
                          Is_ValueChanged("C_BankAccount_ID");

            if (verify)
            {
                //	Verify Currency
                if (CASHTYPE_BankAccountTransfer.Equals(GetCashType()))
                {
                    SetC_Currency_ID(GetBankAccount().GetC_Currency_ID());
                }
                else if (CASHTYPE_Invoice.Equals(GetCashType()))
                {
                    // Commented To Get the Invoice Open Amount Right in case of Diff Currencies
                    // SetC_Currency_ID(GetInvoice().GetC_Currency_ID());
                }
                else    //	Cash
                {
                    SetC_Currency_ID(GetCashBook().GetC_Currency_ID());
                }

                //	Set Organization
                if (CASHTYPE_BankAccountTransfer.Equals(GetCashType()))
                {
                    SetAD_Org_ID(GetBankAccount().GetAD_Org_ID());
                }
                //	Cash Book
                else if (CASHTYPE_Invoice.Equals(GetCashType()))
                {
                    SetAD_Org_ID(GetCashBook().GetAD_Org_ID());
                }
                //	otherwise (charge) - leave it
                //	Enforce Org
                if (GetAD_Org_ID() == 0)
                {
                    SetAD_Org_ID(GetParent().GetAD_Org_ID());
                }
            }

            /**	General fix of Currency
             * UPDATE C_CashLine cl SET C_Currency_ID = (SELECT C_Currency_ID FROM C_Invoice i WHERE i.C_Invoice_ID=cl.C_Invoice_ID) WHERE C_Currency_ID IS NULL AND C_Invoice_ID IS NOT NULL;
             * UPDATE C_CashLine cl SET C_Currency_ID = (SELECT C_Currency_ID FROM C_BankAccount b WHERE b.C_BankAccount_ID=cl.C_BankAccount_ID) WHERE C_Currency_ID IS NULL AND C_BankAccount_ID IS NOT NULL;
             * UPDATE C_CashLine cl SET C_Currency_ID = (SELECT b.C_Currency_ID FROM C_Cash c, C_CashBook b WHERE c.C_Cash_ID=cl.C_Cash_ID AND c.C_CashBook_ID=b.C_CashBook_ID) WHERE C_Currency_ID IS NULL;
             **/

            //	Get Line No
            if (GetLine() == 0)
            {
                String sql = "SELECT COALESCE(MAX(Line),0)+10 FROM C_CashLine WHERE C_Cash_ID=@param1";
                int    ii  = DB.GetSQLValue(Get_TrxName(), sql, GetC_Cash_ID());
                SetLine(ii);
            }

            return(true);
        }