/** * Before Save * @param newRecord new * @return true */ protected override Boolean BeforeSave(Boolean newRecord) { MPayment payment = new MPayment(GetCtx(), GetC_Payment_ID(), Get_TrxName()); if ((newRecord || Is_ValueChanged("C_Invoice_ID")) && (payment.GetC_Charge_ID() != 0 || payment.GetC_Invoice_ID() != 0 || payment.GetC_Order_ID() != 0)) { log.SaveError("PaymentIsAllocated", ""); return(false); } Decimal check = Decimal.Add(Decimal.Add(Decimal.Add(GetAmount(), GetDiscountAmt()), GetWriteOffAmt()), GetOverUnderAmt()); if (check.CompareTo(GetInvoiceAmt()) != 0) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@InvoiceAmt@(" + GetInvoiceAmt() + ") <> @Totals@(" + check + ")")); return(false); } // Org if (newRecord || Is_ValueChanged("C_Invoice_ID")) { GetInvoice(); if (_invoice != null) { SetAD_Org_ID(_invoice.GetAD_Org_ID()); } } return(true); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true, on Save</returns> protected override Boolean BeforeSave(Boolean newRecord) { MPayment payment = new MPayment(GetCtx(), GetC_Payment_ID(), Get_TrxName()); if ((newRecord || Is_ValueChanged("C_Invoice_ID")) && (payment.GetC_Charge_ID() != 0 || payment.GetC_Invoice_ID() != 0 || payment.GetC_Order_ID() != 0)) { log.SaveError("PaymentIsAllocated", ""); return(false); } // during saving a new record, system will check same invoice schedule reference exist on same payment or not if (newRecord && Get_ColumnIndex("C_InvoicePaySchedule_ID") >= 0 && GetC_InvoicePaySchedule_ID() > 0) { if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(*) FROM C_PaymentAllocate WHERE C_Payment_ID = " + GetC_Payment_ID() + @" AND IsActive = 'Y' AND C_InvoicePaySchedule_ID = " + GetC_InvoicePaySchedule_ID(), null, Get_Trx())) > 0) { //"Error" not required //log.SaveError("Error", Msg.GetMsg(GetCtx(), "VIS_NotSaveDuplicateRecord")); log.SaveError("", 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 (payment.IsHoldpaymentSchedule(GetC_InvoicePaySchedule_ID())) { log.SaveError("", Msg.GetMsg(GetCtx(), "VIS_PaymentisHold")); return(false); } } if (!Env.IsModuleInstalled("VA009_")) { Decimal check = Decimal.Add(Decimal.Add(Decimal.Add(GetAmount(), GetDiscountAmt()), GetWriteOffAmt()), GetOverUnderAmt()); if (check.CompareTo(GetInvoiceAmt()) != 0) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@InvoiceAmt@(" + GetInvoiceAmt() + ") <> @Totals@(" + check + ")")); return(false); } } // Org if (newRecord || Is_ValueChanged("C_Invoice_ID")) { GetInvoice(); if (_invoice != null) { SetAD_Org_ID(_invoice.GetAD_Org_ID()); } } return(true); }
/// <summary> /// Set Statement Line /// </summary> /// <param name="payment">Payment</param> /// <returns>Message</returns> public string SetPayments(MPayment payment) { SetC_Payment_ID(payment.GetC_Payment_ID()); //SetC_Currency_ID(payment.GetC_Currency_ID()); Decimal amt = payment.GetPayAmt(true); //Currency Conversion to BankStatementLine Currency if (GetC_Currency_ID() != payment.GetC_Currency_ID()) { int conversionType = Get_ColumnIndex("C_ConversionType_ID") > 0 ? Get_ValueAsInt("C_ConversionType_ID") : payment.GetC_ConversionType_ID(); amt = MConversionRate.Convert(GetCtx(), amt, payment.GetC_Currency_ID(), GetC_Currency_ID(), GetValutaDate(), conversionType, GetAD_Client_ID(), GetAD_Org_ID()); } if (amt != 0) { SetTrxAmt(amt); if (GetStmtAmt() == 0) { SetStmtAmt(amt); } else // Incase of Uncociled StatementLine have existing Amount { decimal _diffAmt = GetStmtAmt() - GetTrxAmt(); SetChargeAmt(_diffAmt - GetInterestAmt()); } SetDescription(payment.GetDescription()); } else { return(Msg.GetMsg(GetCtx(), "NoCurrencyConversion")); } //Set VA012_VoucherType if (Env.IsModuleInstalled("VA012_")) { bool _IsPaymentAllocate = false; int _InvCount; //When Payment have Multiple InvoicePaySchedules if (payment.Get_ColumnIndex("IsPaymentAllocate") > 0) { _IsPaymentAllocate = Util.GetValueOfBool(payment.Get_Value("IsPaymentAllocate")); } if (_IsPaymentAllocate) { _InvCount = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(C_PaymentAllocate_ID) FROM C_PaymentAllocate WHERE IsActive='Y' AND C_Payment_ID=" + payment.GetC_Payment_ID(), null, null)); } else { _InvCount = payment.GetC_Invoice_ID(); } if (_InvCount > 0 || payment.GetC_Order_ID() > 0) { SetVA012_VoucherType("M"); // 'M' indicates VA012_VoucherType as Payment } else if (payment.GetC_Charge_ID() > 0) { SetVA012_VoucherType("V"); // 'V' indicates VA012_VoucherType as Voucher } } return(""); }
/// <summary> /// GetPayment /// </summary> /// <param name="ctx"></param> /// <param name="fields"></param> /// <returns></returns> public Dictionary <string, string> GetPayment(Ctx ctx, string fields) { string[] paramValue = fields.Split(','); int C_Payment_ID; //Assign parameter value C_Payment_ID = Util.GetValueOfInt(paramValue[0].ToString()); MPayment payment = new MPayment(ctx, C_Payment_ID, null); Dictionary <string, string> result = new Dictionary <string, string>(); result["C_Charge_ID"] = payment.GetC_Charge_ID().ToString(); result["C_Invoice_ID"] = payment.GetC_Invoice_ID().ToString(); result["C_Order_ID"] = payment.GetC_Order_ID().ToString(); return(result); }
/** * Before Save * @param newRecord new * @return true */ protected override Boolean BeforeSave(Boolean newRecord) { string Sql = ""; int count = 0; if (GetC_Invoice_ID() > 0) { if (newRecord) { Sql = "SELECT COUNT(*) FROM c_paymentallocate WHERE IsActive='Y' AND C_Payment_ID=" + GetC_Payment_ID() + @" AND C_Invoice_ID=" + GetC_Invoice_ID() + " AND C_InvoicePaySchedule_ID=" + GetC_InvoicePaySchedule_ID() + " "; } else { Sql = "SELECT COUNT(*) FROM c_paymentallocate WHERE IsActive='Y' AND C_Payment_ID=" + GetC_Payment_ID() + @" AND C_Invoice_ID=" + GetC_Invoice_ID() + " AND C_InvoicePaySchedule_ID=" + GetC_InvoicePaySchedule_ID() + " AND c_paymentallocate_ID!=" + GetC_PaymentAllocate_ID() + ""; } count = Util.GetValueOfInt(DB.ExecuteScalar(Sql)); if (count > 0) { log.SaveError(Msg.GetMsg(GetCtx(), "INT13_SchedAlrdySel"), ""); return(false); } Sql = @"SELECT COUNT(*) FROM c_paymentallocate payall INNER JOIN C_Charge chg ON (payall.c_charge_ID =chg.C_Charge_ID) WHERE payall.INT13_AllocateType='C' AND payall.isactive ='Y' AND payall.C_Payment_ID =" + GetC_Payment_ID() + @" AND chg.isadvancecharge ='Y'"; count = Util.GetValueOfInt(DB.ExecuteScalar(Sql)); if (count > 0) { log.SaveError(Msg.GetMsg(GetCtx(), "INT13_NoInvAdvCharge"), ""); return(false); } } else if (GetC_Charge_ID() > 0) { MCharge charge = new MCharge(GetCtx(), GetC_Charge_ID(), null); if (charge.IsAdvanceCharge()) { if (newRecord) { Sql = @"SELECT COUNT(*) FROM c_paymentallocate payall INNER JOIN C_Charge chg ON (payall.c_charge_ID =chg.C_Charge_ID) WHERE payall.INT13_AllocateType='C' AND payall.isactive ='Y' AND payall.C_Payment_ID =" + GetC_Payment_ID() + @" AND chg.isadvancecharge ='N' "; } else { Sql = @"SELECT COUNT(*) FROM c_paymentallocate payall INNER JOIN C_Charge chg ON (payall.c_charge_ID =chg.C_Charge_ID) WHERE payall.INT13_AllocateType='C' AND payall.isactive ='Y' AND payall.C_Payment_ID =" + GetC_Payment_ID() + @" AND chg.isadvancecharge ='N' AND payall.c_paymentallocate_ID!= " + GetC_PaymentAllocate_ID(); } count = Util.GetValueOfInt(DB.ExecuteScalar(Sql)); if (count > 0) { log.SaveError(Msg.GetMsg(GetCtx(), "INT13_NoAdvChgOnCharge"), ""); return(false); } Sql = "SELECT COUNT(*) FROM C_PaymentAllocate WHERE IsActive='Y' AND INT13_AllocateType='I' AND C_Payment_ID=" + GetC_Payment_ID(); count = Util.GetValueOfInt(DB.ExecuteScalar(Sql)); if (count > 0) { log.SaveError(Msg.GetMsg(GetCtx(), "INT13_NoAdvChgOnInv"), ""); return(false); } } else { if (newRecord) { Sql = @"SELECT COUNT(*) FROM c_paymentallocate payall INNER JOIN C_Charge chg ON (payall.c_charge_ID =chg.C_Charge_ID) WHERE payall.INT13_AllocateType='C' AND payall.isactive ='Y' AND payall.C_Payment_ID =" + GetC_Payment_ID() + @" AND chg.isadvancecharge ='Y' "; } else { Sql = @"SELECT COUNT(*) FROM c_paymentallocate payall INNER JOIN C_Charge chg ON (payall.c_charge_ID =chg.C_Charge_ID) WHERE payall.INT13_AllocateType='C' AND payall.isactive ='Y' AND payall.C_Payment_ID =" + GetC_Payment_ID() + @" AND chg.isadvancecharge ='Y' AND payall.c_paymentallocate_ID != " + GetC_PaymentAllocate_ID(); } count = Util.GetValueOfInt(DB.ExecuteScalar(Sql)); if (count > 0) { log.SaveError(Msg.GetMsg(GetCtx(), "INT13_NoChgLnAdvChg"), ""); return(false); } } } MPayment payment = new MPayment(GetCtx(), GetC_Payment_ID(), Get_TrxName()); if ((newRecord || Is_ValueChanged("C_Invoice_ID")) && (payment.GetC_Charge_ID() != 0 || payment.GetC_Invoice_ID() != 0 || payment.GetC_Order_ID() != 0)) { log.SaveError("PaymentIsAllocated", ""); return(false); } if (GetC_Invoice_ID() > 0 && GetC_InvoicePaySchedule_ID() > 0) { string allocatesql = "Select Count(PA.C_Payment_ID) From C_PaymentAllocate PA Inner Join C_Payment Pay on Pay.C_Payment_ID=PA.C_Payment_ID Where PA.C_Invoice_ID=" + GetC_Invoice_ID() + " And " + "PA.C_InvoicePaySchedule_ID=" + GetC_InvoicePaySchedule_ID() + " And pay.Docstatus IN ('DR','IP')"; int countPaymentAllocate = Util.GetValueOfInt(DB.ExecuteScalar(allocatesql)); if (countPaymentAllocate > 0) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "INT15_PaymentAllocateExist")); return(false); } } // during saving a new record, system will check same invoice schedule reference exist on same payment or not if (newRecord && Get_ColumnIndex("C_InvoicePaySchedule_ID") >= 0 && GetC_InvoicePaySchedule_ID() > 0) { if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(*) FROM C_PaymentAllocate WHERE C_Payment_ID = " + GetC_Payment_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); } } if (!Env.IsModuleInstalled("VA009_")) { Decimal check = Decimal.Add(Decimal.Add(Decimal.Add(GetAmount(), GetDiscountAmt()), GetWriteOffAmt()), GetOverUnderAmt()); if (check.CompareTo(GetInvoiceAmt()) != 0) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@InvoiceAmt@(" + GetInvoiceAmt() + ") <> @Totals@(" + check + ")")); return(false); } } // Org if (newRecord || Is_ValueChanged("C_Invoice_ID")) { GetInvoice(); if (_invoice != null) { SetAD_Org_ID(_invoice.GetAD_Org_ID()); } } return(true); }
/** * Set Invoice - Callout * @param oldC_Invoice_ID old BP * @param newC_Invoice_ID new BP * @param windowNo window no */ //@UICallout public void SetC_Invoice_ID(String oldC_Invoice_ID, String newC_Invoice_ID, int windowNo) { if (newC_Invoice_ID == null || newC_Invoice_ID.Length == 0) { return; } int C_Invoice_ID = int.Parse(newC_Invoice_ID); SetC_Invoice_ID(C_Invoice_ID); if (C_Invoice_ID == 0) { return; } // Check Payment int C_Payment_ID = GetC_Payment_ID(); MPayment payment = new MPayment(GetCtx(), C_Payment_ID, null); if (payment.GetC_Charge_ID() != 0 || payment.GetC_Invoice_ID() != 0 || payment.GetC_Order_ID() != 0) { //p_changeVO.addError( Msg.GetMsg(GetCtx(),"PaymentIsAllocated")); return; } SetDiscountAmt(Env.ZERO); SetWriteOffAmt(Env.ZERO); SetOverUnderAmt(Env.ZERO); int C_InvoicePaySchedule_ID = 0; if (GetCtx().GetContextAsInt(Env.WINDOW_INFO, Env.TAB_INFO, "C_Invoice_ID") == C_Invoice_ID && GetCtx().GetContextAsInt(Env.WINDOW_INFO, Env.TAB_INFO, "C_InvoicePaySchedule_ID") != 0) { C_InvoicePaySchedule_ID = GetCtx().GetContextAsInt(Env.WINDOW_INFO, Env.TAB_INFO, "C_InvoicePaySchedule_ID"); } // Payment Date DateTime ts = CommonFunctions.CovertMilliToDate(GetCtx().GetContextAsTime(windowNo, "DateTrx")); if (ts == null) { ts = DateTime.Now; } // String sql = "SELECT C_BPartner_ID,C_Currency_ID," // 1..2 + " invoiceOpen(C_Invoice_ID, @paysch)," // 3 #1 + " invoiceDiscount(C_Invoice_ID,@tsdt,@paysch1), IsSOTrx " // 4..5 #2/3 + "FROM C_Invoice WHERE C_Invoice_ID=@invid"; // #4 int C_Currency_ID = 0; // Invoice Currency IDataReader idr = null; try { SqlParameter[] param = new SqlParameter[4]; param[0] = new SqlParameter("@paysch", C_InvoicePaySchedule_ID); param[1] = new SqlParameter("@tsdt", (DateTime?)ts); param[2] = new SqlParameter("@paysch1", C_InvoicePaySchedule_ID); param[3] = new SqlParameter("@invid", C_Invoice_ID); idr = DB.ExecuteReader(sql, null, null); if (idr.Read()) { // SetC_BPartner_ID(rs.GetInt(1)); C_Currency_ID = Util.GetValueOfInt(idr[1].ToString()); // Set Invoice Currency // SetC_Currency_ID(C_Currency_ID); // Decimal?invoiceOpen = null; if (!idr.IsDBNull(2)) { invoiceOpen = Util.GetValueOfDecimal(idr[2]); // Set Invoice Open Amount } if (invoiceOpen == null) { invoiceOpen = Env.ZERO; } Decimal?discountAmt = null; if (!idr.IsDBNull(3)) { discountAmt = Util.GetValueOfDecimal(idr[3]); // Set Discount Amt } if (discountAmt == null) { discountAmt = Env.ZERO; } // SetInvoiceAmt((Decimal)invoiceOpen); SetAmount(Decimal.Subtract((Decimal)invoiceOpen, (Decimal)discountAmt)); SetDiscountAmt(Convert.ToDecimal(discountAmt)); // reSet as dependent fields Get reSet GetCtx().SetContext(windowNo, "C_Invoice_ID", C_Invoice_ID); //IsSOTrx, Project } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, sql, e); } // Check Invoice/Payment Currency - may not be an issue(??) if (C_Currency_ID != 0) { int currency_ID = GetCtx().GetContextAsInt(windowNo, "C_Currency_ID"); if (currency_ID != C_Currency_ID) { String msg = Msg.ParseTranslation(GetCtx(), "@C_Currency_ID@: @C_Invoice_ID@ <> @C_Payment_ID@"); //p_changeVO.addError(msg); } } }