📄 viewpayment.bsh
字号:
/* * Copyright (C) 2006 Open Source Strategies, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */import com.opensourcestrategies.financials.accounts.AccountsHelper;import org.ofbiz.base.util.*;import org.ofbiz.entity.*;import org.ofbiz.entity.condition.*;import org.ofbiz.accounting.invoice.*;import org.ofbiz.accounting.payment.*;import org.ofbiz.accounting.util.*;import org.ofbiz.party.party.*;import java.util.*;import java.math.*;import java.text.NumberFormat;delegator = request.getAttribute("delegator");boolean isDisbursement = false;paymentId = parameters.get("paymentId");if (paymentId == null) { paymentId = request.getParameter("paymentId");}if (paymentId == null) { request.setAttribute("_ERROR_MESSAGE_", "ERROR: paymentId is in valid, Please check paymentId and retry"); return "error";}paymentValue = delegator.findByPrimaryKey("Payment",UtilMisc.toMap("paymentId",paymentId));if (paymentValue == null) { request.setAttribute("_ERROR_MESSAGE_", "ERROR: Cannot find Payment from paymentId [" + paymentId + "]. Please check paymentId and retry"); return "error";}context.put("paymentId",paymentId);context.put("paymentValue",paymentValue);// Sets up payment and related data for the FTLisDisbursement = UtilAccounting.isDisbursement(paymentValue);context.put("isDisbursement", isDisbursement);if (isDisbursement) { paymentMethodId = paymentValue.get("paymentMethodId"); if (paymentMethodId != null) { paymentMethod = paymentValue.getRelatedOneCache("PaymentMethod"); context.put("paymentMethod",paymentMethod); } partyNameTo = PartyHelper.getPartyName(delegator, paymentValue.get("partyIdTo"), false); context.put("partyNameTo",partyNameTo);} else { partyNameFrom = PartyHelper.getPartyName(delegator, paymentValue.get("partyIdFrom"), false); context.put("partyNameFrom",partyNameFrom);}paymentType = paymentValue.getRelatedOneCache("PaymentType");context.put("paymentType",paymentType);paymentMethodTypeId = paymentValue.get("paymentMethodTypeId");if (paymentMethodTypeId == null) { Debug.logError("paymentMethodTypeId is Null" + paymentValue,"viewPayment.bsh" );} else { paymentMethodType = paymentValue.getRelatedOneCache("PaymentMethodType"); context.put("paymentMethodType",paymentMethodType);}// figure out how much has already been applied and how much is still openint decimals = UtilNumber.getBigDecimalScale("invoice.decimals");int rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");BigDecimal paymentApplied = PaymentWorker.getPaymentAppliedBd(paymentValue);BigDecimal paymentToApply = paymentValue.getBigDecimal("amount").subtract(paymentApplied).setScale(decimals,rounding);// determine if the payment can still be applied to outstanding invoices, which is the case if the payment is PMNT_NOT_PAID (ie, input)boolean hasAmountToApply=false;boolean isTaxPayment = UtilAccounting.isTaxPayment(paymentValue);//Get the payments already appliedpaymentApplications = paymentValue.getRelated("PaymentApplication");if (paymentApplications !=null && paymentApplications.size() > 0){ paymentApplicationsList = new ArrayList(); Iterator p = paymentApplications.iterator(); while (p.hasNext()) { paymentApplication = p.next(); paymentApplicationMap = new HashMap(); paymentApplicationMap.put("paymentId", paymentApplication.getString("paymentId")); paymentApplicationMap.put("paymentApplicationId", paymentApplication.getString("paymentApplicationId")); paymentApplicationMap.put("amountApplied", paymentApplication.getString("amountApplied")); paymentApplicationMap.put("taxAuthGeoId", paymentApplication.getString("taxAuthGeoId")); paymentApplicationMap.put("invoiceId", paymentApplication.getString("invoiceId")); invoiceId = paymentApplication.getString("invoiceId"); if (invoiceId != null && !invoiceId.equals("")) { invoice = delegator.findByPrimaryKey("Invoice",UtilMisc.toMap("invoiceId",invoiceId)); if (invoice != null) { BigDecimal invoiceAmount = InvoiceWorker.getInvoiceTotalBd(invoice).setScale(decimals,rounding); BigDecimal invoiceApplied = InvoiceWorker.getInvoiceAppliedBd(invoice).setScale(decimals,rounding); paymentApplicationMap.put("description",invoice.getString("description")); paymentApplicationMap.put("invoiceDate", invoice.get("invoiceDate")); if (!invoiceAmount.equals(invoiceApplied)) { // put in the map BigDecimal invoiceToApply = invoiceAmount.subtract(invoiceApplied); paymentApplicationMap.put("outstandingAmount", invoiceToApply); } } } paymentApplicationsList.add(paymentApplicationMap); } context.put("paymentApplicationsList",paymentApplicationsList); context.put("paymentApplications",paymentApplications);}//get list of taxAuths.taxAuthGeoIds =null;if (isTaxPayment && ("PMNT_NOT_PAID".equals(paymentValue.getString("statusId")))) { // if the payment is some sort of a tax payment, then find the Geos for which this tax payment can be applied // based on the pay-to party. Data is used to populate taxAuthGeoId for PaymentApplications taxAuthGeoIds = delegator.findByAnd("TaxAuthorityAndDetail",UtilMisc.toMap("taxAuthPartyId",paymentValue.get("partyIdTo"))); context.put("taxAuthGeoIds", taxAuthGeoIds); context.put("amountToApply", paymentToApply);}if ((paymentToApply.doubleValue() > 0) && ("PMNT_NOT_PAID".equals(paymentValue.getString("statusId")))) { hasAmountToApply = true; // Based on Payment.parentTypeId see if we need to read unpaid invoices or get list of taxAuths. if (!isTaxPayment) { // get a list of all the invoices which are not canceled, written off, or paid, and which are applicable to this payment based on parties conditions = UtilMisc.toList(new EntityExpr("partyId", EntityOperator.EQUALS,paymentValue.get("partyIdFrom")), new EntityExpr("partyIdFrom", EntityOperator.EQUALS, paymentValue.get("partyIdTo")), new EntityExpr("statusId", EntityOperator.NOT_IN,UtilMisc.toList("CANCELLED","WRITEOFF","PAID"))); entityConditionList = new EntityConditionList(conditions, EntityOperator.AND); List invoices = delegator.findByCondition("Invoice", entityConditionList, null, null); // now create a list of Maps which hold invoice information, the amountApplied, and the amount to be applied (ie, still open) if (invoices != null && invoices.size() > 0) { ArrayList invoicesList = new ArrayList(); // to pass back to the screeen list of unapplied invoices Iterator p = invoices.iterator(); while (p.hasNext()) { invoice = p.next(); BigDecimal invoiceAmount = InvoiceWorker.getInvoiceTotalBd(invoice).setScale(decimals,rounding); BigDecimal invoiceApplied = InvoiceWorker.getInvoiceAppliedBd(invoice).setScale(decimals,rounding); if (!invoiceAmount.equals(invoiceApplied)) { // put in the map BigDecimal invoiceToApply = invoiceAmount.subtract(invoiceApplied); Map invoiceMap = new HashMap(); invoiceMap.put("invoiceId", invoice.getString("invoiceId")); invoiceMap.put("currencyUomId", invoice.getString("currencyUomId")); invoiceMap.put("amount", invoiceAmount); invoiceMap.put("description",invoice.getString("description")); invoiceMap.put("invoiceDate", invoice.get("invoiceDate")); invoiceMap.put("amountApplied", invoiceApplied); invoiceMap.put("outstandingAmount", invoiceToApply); if (paymentToApply.compareTo(invoiceToApply) < 0 ) { invoiceMap.put("amountToApply",paymentToApply); } else { invoiceMap.put("amountToApply",invoiceToApply); } invoicesList.add(invoiceMap); } } context.put("invoices",invoicesList); } } else { if (taxAuthGeoIds !=null && taxAuthGeoIds.size() > 0) { ArrayList taxAuthPaymentApplicationList = new ArrayList(); Iterator p = taxAuthGeoIds.iterator(); while (p.hasNext()) { taxAuth = p.next(); Map taxAuthPaymentApplicationMap = new HashMap(); taxAuthPaymentApplicationMap.put("paymentId",paymentId); taxAuthPaymentApplicationMap.put("geoId",taxAuth.get("geoId")); taxAuthPaymentApplicationMap.put("amountToApply",paymentToApply); taxAuthPaymentApplicationList.add(taxAuthPaymentApplicationMap); } context.put("taxAuthPaymentApplicationList",taxAuthPaymentApplicationList); } }}// need to customize view based on type of payment.context.put("isTaxPayment", isTaxPayment);context.put("hasAmountToApply",hasAmountToApply);if (isDisbursement) { parameters.put("headerItem","payables"); context.put("addPaymentTypeId","DISBURSEMENT");} else { parameters.put("headerItem","receivables"); context.put("addPaymentTypeId","RECEIPT");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -