You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2009/03/27 18:00:00 UTC
svn commit: r759247 [1/2] - in
/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting: ./
agreement/ finaccount/ invoice/ payment/ period/ tax/
thirdparty/authorizedotnet/ thirdparty/clearcommerce/ thirdparty/paypal/
thirdparty/valuelink/ thirdp...
Author: doogie
Date: Fri Mar 27 16:59:58 2009
New Revision: 759247
URL: http://svn.apache.org/viewvc?rev=759247&view=rev
Log:
Fix lines that *only* have whitespace.
Modified:
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/agreement/AgreementServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountProductServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/period/PeriodServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMPaymentServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCPaymentServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCServicesTest.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/paypal/PayPalEvents.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/valuelink/ValueLinkApi.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/valuelink/ValueLinkServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/verisign/PayflowPro.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/worldpay/SelectRespServlet.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/worldpay/WorldPayEvents.java
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java?rev=759247&r1=759246&r2=759247&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java Fri Mar 27 16:59:58 2009
@@ -40,7 +40,7 @@
import org.ofbiz.webapp.event.EventHandlerException;
public class GlEvents {
-
+
public static final String module = GlEvents.class.getName();
public static String createReconcileAccount(HttpServletRequest request,HttpServletResponse response) {
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
@@ -87,7 +87,7 @@
Debug.logError(e, module);
return "error";
}
-
+
}
Map fieldMap = UtilMisc.toMap("glReconciliationName", "Reconciliation at date " + UtilDateTime.nowTimestamp(), "glAccountId", glAccountId, "organizationPartyId", organizationPartyId, "reconciledDate", UtilDateTime.nowTimestamp(), "reconciledBalance", reconciledBalance, "userLogin", userLogin);
Map glReconResult = null;
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/agreement/AgreementServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/agreement/AgreementServices.java?rev=759247&r1=759246&r2=759247&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/agreement/AgreementServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/agreement/AgreementServices.java Fri Mar 27 16:59:58 2009
@@ -43,7 +43,7 @@
*/
public class AgreementServices {
-
+
public static final String module = AgreementServices.class.getName();
// set some BigDecimal properties
private static BigDecimal ZERO = BigDecimal.ZERO;
@@ -57,7 +57,7 @@
if (decimals != -1) ZERO = ZERO.setScale(decimals, rounding);
}
public static final String resource = "AccountingUiLabels";
-
+
/**
* Determines commission receiving parties and amounts for the provided product, price, and quantity
* @param ctx The DispatchContext that this service is operating in.
@@ -80,7 +80,7 @@
Locale locale = (Locale) context.get("locale");
String errMsg = null;
List commissions = FastList.newInstance();
-
+
try {
BigDecimal amount = ((BigDecimal)context.get("amount"));
BigDecimal quantity = (BigDecimal)context.get("quantity");
@@ -91,7 +91,7 @@
quantity = quantity.abs();
String productId = (String) context.get("productId");
String invoiceItemTypeId = (String) context.get("invoiceItemTypeId");
-
+
// Collect agreementItems applicable to this orderItem/returnItem
// TODO: partyIds should be part of this query!
List agreementItems = delegator.findByAndCache("AgreementItemAndProductAppl", UtilMisc.toMap(
@@ -112,7 +112,7 @@
}
// this is not very efficient if there were many
agreementItems = EntityUtil.filterByDate(agreementItems);
-
+
Iterator it = agreementItems.iterator();
while (it.hasNext()) {
GenericValue agreementItem = (GenericValue) it.next();
@@ -124,7 +124,7 @@
BigDecimal commission = ZERO;
BigDecimal min = new BigDecimal("-1e12"); // Limit to 1 trillion commission
BigDecimal max = new BigDecimal("1e12");
-
+
// number of days due for commission, which will be the lowest termDays of all the AgreementTerms
long days = -1;
Iterator itt = terms.iterator();
@@ -164,7 +164,7 @@
commission = max;
commission = negative ? commission.negate() : commission;
commission = commission.setScale(decimals, rounding);
-
+
Map partyCommissionResult = UtilMisc.toMap(
"partyIdFrom", agreementItem.getString("partyIdFrom"),
"partyIdTo", agreementItem.getString("partyIdTo"),
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java?rev=759247&r1=759246&r2=759247&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java Fri Mar 27 16:59:58 2009
@@ -84,11 +84,11 @@
// obtain the order information
OrderReadHelper orh = new OrderReadHelper(delegator, orderId);
-
+
// NOTE DEJ20070808: this means that we want store related settings for where the item is being purchased,
//NOT where the account was setup; should this be changed to use settings from the store where the account was setup?
String productStoreId = orh.getProductStoreId();
-
+
// TODO, NOTE DEJ20070808: why is this setup this way anyway? for the allowAuthToNegative wouldn't that be better setup
//on the FinAccount and not on the ProductStoreFinActSetting? maybe an override on the FinAccount would be good...
@@ -125,7 +125,7 @@
// fin the store requires a pin number; validate the PIN with the code
Map findProductStoreFinActSettingMap = UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", finAccountTypeId);
GenericValue finAccountSettings = delegator.findByPrimaryKeyCache("ProductStoreFinActSetting", findProductStoreFinActSettingMap);
-
+
if (finAccountSettings == null) {
Debug.logWarning("In finAccountPreAuth could not find ProductStoreFinActSetting record, values searched by: " + findProductStoreFinActSettingMap, module);
}
@@ -206,8 +206,8 @@
Debug.logWarning("In finAccountPreAuth for finAccountId [" + finAccountId + "] availableBalance [" + availableBalanceOriginal + "] was different after rounding [" + availableBalance + "]; it should never have made it into the database this way, so check whatever put it there.", module);
}
}
-
-
+
+
Map result = ServiceUtil.returnSuccess();
String authMessage = null;
Boolean processResult;
@@ -221,7 +221,7 @@
if (("Y".equals(allowAuthToNegative) && availableBalance.compareTo(minBalance) > -1)
|| (availableBalance.compareTo(amount) > -1)) {
Timestamp thruDate;
-
+
if (finAccountSettings != null && finAccountSettings.getLong("authValidDays") != null) {
thruDate = UtilDateTime.getDayEnd(UtilDateTime.nowTimestamp(), finAccountSettings.getLong("authValidDays"));
} else {
@@ -237,7 +237,7 @@
refNum = (String) tmpResult.get("finAccountAuthId");
processResult = Boolean.TRUE;
}
-
+
// refresh the account
finAccount.refresh();
} else {
@@ -280,7 +280,7 @@
if (authTransaction == null) {
return ServiceUtil.returnError(err + " Could not find authorization transaction.");
}
-
+
Map input = UtilMisc.toMap("userLogin", userLogin, "finAccountAuthId", authTransaction.get("referenceNum"));
Map serviceResults = dispatcher.runSync("expireFinAccountAuth", input);
@@ -365,7 +365,7 @@
partyId = billToParty.getString("partyId");
}
}
-
+
// BIG NOTE: make sure the expireFinAccountAuth and finAccountWithdraw services are done in the SAME TRANSACTION
//(ie no require-new-transaction in either of them AND no running async)
@@ -622,7 +622,7 @@
return ServiceUtil.returnError("Financial account has expired as of " + finAccount.getTimestamp("thruDate"));
}
Debug.log("Deposit into financial account #" + finAccountId + " [" + amount + "]", module);
-
+
// get the previous balance
BigDecimal previousBalance = finAccount.getBigDecimal("actualBalance");
if (previousBalance == null) {
@@ -855,7 +855,7 @@
return ServiceUtil.returnError(e.getMessage());
}
}
-
+
return ServiceUtil.returnSuccess();
}
@@ -892,10 +892,10 @@
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
-
+
return null;
}
-
+
private static String createFinAcctPaymentTransaction(GenericDelegator delegator, LocalDispatcher dispatcher, GenericValue userLogin, BigDecimal amount,
String productStoreId, String partyId, String orderId, String orderItemSeqId, String currencyUom, String txType, String finAccountId, String reasonEnumId) throws GeneralException {
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountProductServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountProductServices.java?rev=759247&r1=759246&r2=759247&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountProductServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountProductServices.java Fri Mar 27 16:59:58 2009
@@ -162,7 +162,7 @@
}
}
}
-
+
// create the context for FSE
Map expContext = FastMap.newInstance();
expContext.put("orderHeader", orderHeader);
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java?rev=759247&r1=759246&r2=759247&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java Fri Mar 27 16:59:58 2009
@@ -41,7 +41,7 @@
import javolution.util.FastMap;
public class FinAccountServices {
-
+
public static final String module = FinAccountServices.class.getName();
public static Map createAccountAndCredit(DispatchContext dctx, Map context) {
@@ -150,7 +150,7 @@
transactionMap.put("reasonEnumId", context.get("reasonEnumId"));
transactionMap.put("comments", context.get("comments"));
transactionMap.put("userLogin", userLogin);
-
+
Map creditTransResult = dispatcher.runSync("createFinAccountTrans", transactionMap);
if (ServiceUtil.isError(creditTransResult) || ServiceUtil.isFailure(creditTransResult)) {
return creditTransResult;
@@ -172,14 +172,14 @@
GenericValue userLogin = (GenericValue) context.get("userLogin");
String productStoreId = (String) context.get("productStoreId");
String finAccountTypeId = (String) context.get("finAccountTypeId");
-
+
try {
// get the product store id and use it to generate a unique fin account code
GenericValue productStoreFinAccountSetting = delegator.findByPrimaryKeyCache("ProductStoreFinActSetting", UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", finAccountTypeId));
if (productStoreFinAccountSetting == null) {
return ServiceUtil.returnError("No settings found for store [" + productStoreId + "] for fin account type [" + finAccountTypeId + "]");
}
-
+
Long accountCodeLength = productStoreFinAccountSetting.getLong("accountCodeLength");
Long accountValidDays = productStoreFinAccountSetting.getLong("accountValidDays");
Long pinCodeLength = productStoreFinAccountSetting.getLong("pinCodeLength");
@@ -210,7 +210,7 @@
inContext.put("organizationPartyId", payToPartyId);
Map createResult = dispatcher.runSync("createFinAccount", inContext);
-
+
if (ServiceUtil.isError(createResult)) {
return createResult;
} else {
@@ -368,7 +368,7 @@
GenericValue productStore = delegator.getRelatedOne("ProductStore", orderHeader);
GenericValue orderItem = delegator.findByPrimaryKey("OrderItem", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId));
if (!"ITEM_CANCELLED".equals(orderItem.getString("statusId"))) {
-
+
// make sure the item hasn't already been returned
List returnItems = orderItem.getRelated("ReturnItem");
if (returnItems == null || returnItems.size() == 0) {
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java?rev=759247&r1=759246&r2=759247&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java Fri Mar 27 16:59:58 2009
@@ -199,7 +199,7 @@
// Set the precision depending on the type of invoice
int invoiceTypeDecimals = UtilNumber.getBigDecimalScale("invoice." + invoiceType + ".decimals");
if (invoiceTypeDecimals == -1) invoiceTypeDecimals = decimals;
-
+
// Make an order read helper from the order
OrderReadHelper orh = new OrderReadHelper(orderHeader);
@@ -239,7 +239,7 @@
if (orderTermNetDays != null) {
dueDate = UtilDateTime.getDayEnd(invoiceDate, orderTermNetDays);
}
-
+
// create the invoice record
Map createInvoiceContext = FastMap.newInstance();
createInvoiceContext.put("partyId", billToCustomerPartyId);
@@ -258,7 +258,7 @@
if (ServiceUtil.isError(createInvoiceResult)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource,"AccountingErrorCreatingInvoiceFromOrder",locale), null, null, createInvoiceResult);
}
-
+
// call service, not direct entity op: delegator.create(invoice);
String invoiceId = (String) createInvoiceResult.get("invoiceId");
@@ -428,7 +428,7 @@
}
BigDecimal billingAmount = orderItem.getBigDecimal("unitPrice").setScale(invoiceTypeDecimals, rounding);
-
+
Map createInvoiceItemContext = FastMap.newInstance();
createInvoiceItemContext.put("invoiceId", invoiceId);
createInvoiceItemContext.put("invoiceItemSeqId", invoiceItemSeqId);
@@ -512,7 +512,7 @@
Iterator itemAdjIter = itemAdjustments.iterator();
while (itemAdjIter.hasNext()) {
GenericValue adj = (GenericValue) itemAdjIter.next();
-
+
// Check against OrderAdjustmentBilling to see how much of this adjustment has already been invoiced
BigDecimal adjAlreadyInvoicedAmount = null;
try {
@@ -523,7 +523,7 @@
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
-
+
// If the absolute invoiced amount >= the abs of the adjustment amount, the full amount has already been invoiced,
// so skip this adjustment
if (adj.get("amount") == null) { // JLR 17/4/7 : fix a bug coming from POS in case of use of a discount (on item(s) or sale, item(s) here) and a cash amount higher than total (hence issuing change)
@@ -532,7 +532,7 @@
if (adjAlreadyInvoicedAmount.abs().compareTo(adj.getBigDecimal("amount").setScale(invoiceTypeDecimals, rounding).abs()) > 0) {
continue;
}
-
+
BigDecimal amount = ZERO;
if (adj.get("amount") != null) {
// pro-rate the amount
@@ -576,7 +576,7 @@
// some adjustments fill out the comments field instead
String description = (UtilValidate.isEmpty(adj.getString("description")) ? adj.getString("comments") : adj.getString("description"));
createInvoiceItemAdjContext.put("description", description);
-
+
// invoice items for sales tax are not taxable themselves
// TODO: This is not an ideal solution. Instead, we need to use OrderAdjustment.includeInTax when it is implemented
if (!(adj.getString("orderAdjustmentTypeId").equals("SALES_TAX"))) {
@@ -618,19 +618,19 @@
// this adjustment amount
BigDecimal thisAdjAmount = amount;
-
+
// adjustments only apply to totals when they are not tax or shipping adjustments
if (!"SALES_TAX".equals(adj.getString("orderAdjustmentTypeId")) &&
!"SHIPPING_ADJUSTMENT".equals(adj.getString("orderAdjustmentTypeId"))) {
// increment the invoice subtotal
invoiceSubTotal = invoiceSubTotal.add(thisAdjAmount).setScale(100, rounding);
-
+
// add to the ship amount only if it applies to this item
if (shippingApplies) {
invoiceShipProRateAmount = invoiceShipProRateAmount.add(thisAdjAmount).setScale(invoiceTypeDecimals, rounding);
}
}
-
+
// increment the counter
invoiceItemSeqNum++;
invoiceItemSeqId = UtilFormatOut.formatPaddedNumber(invoiceItemSeqNum, INVOICE_ITEM_SEQUENCE_ID_DIGITS);
@@ -693,13 +693,13 @@
while (shipAdjIter.hasNext()) {
GenericValue adj = (GenericValue) shipAdjIter.next();
BigDecimal adjAlreadyInvoicedAmount = (BigDecimal) shipAdjustments.get(adj);
-
+
if ("N".equalsIgnoreCase(prorateShipping)) {
// Set the divisor and multiplier to 1 to avoid prorating
BigDecimal divisor = BigDecimal.ONE;
BigDecimal multiplier = BigDecimal.ONE;
-
+
// The base amount in this case is the adjustment amount minus the total already invoiced for that adjustment, since
// it won't be prorated
BigDecimal baseAmount = adj.getBigDecimal("amount").setScale(invoiceTypeDecimals, rounding).subtract(adjAlreadyInvoicedAmount);
@@ -710,7 +710,7 @@
// Pro-rate the shipping amount based on shippable information
BigDecimal divisor = shippableAmount;
BigDecimal multiplier = invoiceShipProRateAmount;
-
+
// The base amount in this case is the adjustment amount, since we want to prorate based on the full amount
BigDecimal baseAmount = adj.getBigDecimal("amount").setScale(invoiceTypeDecimals, rounding);
BigDecimal adjAmount = calcHeaderAdj(delegator, adj, invoiceType, invoiceId, invoiceItemSeqId,
@@ -732,13 +732,13 @@
GenericValue adj = (GenericValue) taxAdjIter.next();
BigDecimal adjAlreadyInvoicedAmount = (BigDecimal) taxAdjustments.get(adj);
BigDecimal adjAmount = null;
-
+
if ("N".equalsIgnoreCase(prorateTaxes)) {
// Set the divisor and multiplier to 1 to avoid prorating
BigDecimal divisor = BigDecimal.ONE;
BigDecimal multiplier = BigDecimal.ONE;
-
+
// The base amount in this case is the adjustment amount minus the total already invoiced for that adjustment, since
// it won't be prorated
// Note this should use invoice decimals & rounding instead of taxDecimals and taxRounding for tax adjustments, because it will be added to the invoice
@@ -750,7 +750,7 @@
// Pro-rate the tax amount based on shippable information
BigDecimal divisor = orderSubTotal;
BigDecimal multiplier = invoiceSubTotal;
-
+
// The base amount in this case is the adjustment amount, since we want to prorate based on the full amount
// Note this should use invoice decimals & rounding instead of taxDecimals and taxRounding for tax adjustments, because it will be added to the invoice
BigDecimal baseAmount = adj.getBigDecimal("amount").setScale(invoiceTypeDecimals, rounding);
@@ -828,7 +828,7 @@
return ServiceUtil.returnError(errMsg);
}
}
-
+
// Service for creating commission invoices
public static Map createCommissionInvoices(DispatchContext dctx, Map context) {
GenericDelegator delegator = dctx.getDelegator();
@@ -836,7 +836,7 @@
GenericValue userLogin = (GenericValue) context.get("userLogin");
Locale locale = (Locale) context.get("locale");
List invoicesCreated = FastList.newInstance();
-
+
String invoiceIdIn = (String) context.get("invoiceId");
String invoiceItemSeqIdIn = (String) context.get("invoiceItemSeqId");
BigDecimal amountTotal = InvoiceWorker.getInvoiceTotal(delegator, invoiceIdIn);
@@ -845,14 +845,14 @@
Debug.logWarning("Invoice [" + invoiceIdIn + "] has an amount total of [" + amountTotal + "], so no commission invoice will be created", module);
return ServiceUtil.returnSuccess(UtilProperties.getMessage(resource,"AccountingInvoiceCommissionZeroInvoiceAmount",locale));
}
-
+
try {
// Change this when amountApplied is BigDecimal, 18 digit scale to keep all the precision
BigDecimal appliedFraction = ((BigDecimal)context.get("amountApplied")).divide(amountTotal, 12, rounding);
Map inMap = UtilMisc.toMap("invoiceId", invoiceIdIn);
GenericValue invoice = delegator.findByPrimaryKey("Invoice", inMap);
String invoiceTypeId = invoice.getString("invoiceTypeId");
-
+
// Determine sales or return
boolean isReturn = false;
if ("SALES_INVOICE".equals(invoiceTypeId)) {
@@ -863,12 +863,12 @@
Debug.logWarning("This type of invoice has no commission; returning success", module);
return ServiceUtil.returnSuccess(UtilProperties.getMessage(resource,"AccountingInvoiceCommissionInvalid",locale));
}
-
+
if (invoiceItemSeqIdIn != null) {
inMap.put("invoiceItemSeqId", invoiceItemSeqIdIn);
}
List invoiceItems = delegator.findByAnd("InvoiceItem", inMap);
-
+
// Map of commission Lists (of Maps) for each party
Map commissionParties = FastMap.newInstance();
// Determine commissions for various parties
@@ -881,7 +881,7 @@
amount = invoiceItem.getBigDecimal("amount");
amount = isReturn ? amount.negate() : amount;
String productId = invoiceItem.getString("productId");
-
+
// Determine commission parties for this invoiceItem
if (productId != null && productId.length() > 0) {
Map outMap = dispatcher.runSync("getCommissionForProduct", UtilMisc.<String, Object>toMap(
@@ -893,7 +893,7 @@
if (ServiceUtil.isError(outMap)) {
return outMap;
}
-
+
// build a Map of partyIds (both to and from) in a commission and the amounts
// Note that getCommissionForProduct returns a List of Maps with a lot values. See services.xml definition for reference.
List itemComms = (List) outMap.get("commissions");
@@ -911,10 +911,10 @@
}
}
}
-
+
String invoiceType = "COMMISSION_INVOICE";
Timestamp now = UtilDateTime.nowTimestamp();
-
+
// Create invoice for each commission receiving party
Iterator it = commissionParties.entrySet().iterator();
while (it.hasNext()) {
@@ -925,12 +925,12 @@
if (UtilValidate.isEmpty(commList)) {
continue;
}
-
+
// From and To are reversed between commission and invoice
String partyIdBillTo = (String) ((Map)commList.get(0)).get("partyIdFrom");
String partyIdBillFrom = (String) ((Map)commList.get(0)).get("partyIdTo");
Long days = (Long) ((Map)commList.get(0)).get("days");
-
+
// create the invoice record
// To and From are in commission's sense, opposite for invoice
Map createInvoiceContext = FastMap.newInstance();
@@ -946,14 +946,14 @@
createInvoiceContext.put("statusId", "INVOICE_IN_PROCESS");
createInvoiceContext.put("currencyUomId", invoice.getString("currencyUomId"));
createInvoiceContext.put("userLogin", userLogin);
-
+
// store the invoice first
Map createInvoiceResult = dispatcher.runSync("createInvoice", createInvoiceContext);
if (ServiceUtil.isError(createInvoiceResult)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource,"AccountingInvoiceCommissionError",locale), null, null, createInvoiceResult);
}
String invoiceId = (String) createInvoiceResult.get("invoiceId");
-
+
// create the bill-from (or pay-to) contact mech as the primary PAYMENT_LOCATION of the party from the store
List contactMechs = delegator.findByAnd("PartyContactMechPurpose", UtilMisc.toMap("partyId", partyIdBillTo, "contactMechPurposeTypeId", "BILLING_LOCATION"));
if (contactMechs.size() > 0) {
@@ -973,7 +973,7 @@
"contactMechPurposeTypeId", "PAYMENT_LOCATION"));
toStore.add(payToCm);
}
-
+
// create the item records
Iterator itt = commList.iterator();
while (itt.hasNext()) {
@@ -1007,7 +1007,7 @@
return ServiceUtil.returnError(errMsg);
}
}
-
+
public static Map readyInvoices(DispatchContext dctx, Map context) {
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericValue userLogin = (GenericValue) context.get("userLogin");
@@ -1031,14 +1031,14 @@
}
return ServiceUtil.returnSuccess();
}
-
+
public static Map createInvoicesFromShipment(DispatchContext dctx, Map context) {
//GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
String shipmentId = (String) context.get("shipmentId");
Locale locale = (Locale) context.get("locale");
List invoicesCreated = new ArrayList();
-
+
Map serviceContext = UtilMisc.toMap("shipmentIds", UtilMisc.toList(shipmentId), "userLogin", context.get("userLogin"));
try {
Map result = dispatcher.runSync("createInvoicesFromShipments", serviceContext);
@@ -1051,7 +1051,7 @@
response.put("invoicesCreated", invoicesCreated);
return response;
}
-
+
public static Map createSalesInvoicesFromDropShipment(DispatchContext dctx, Map context) {
LocalDispatcher dispatcher = dctx.getDispatcher();
String shipmentId = (String) context.get("shipmentId");
@@ -1067,10 +1067,10 @@
Debug.logError(e, errorMessage, module);
return ServiceUtil.returnError(errorMessage);
}
-
+
return serviceResult;
}
-
+
public static Map createInvoicesFromShipments(DispatchContext dctx, Map context) {
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
@@ -1082,7 +1082,7 @@
boolean salesShipmentFound = false;
boolean purchaseShipmentFound = false;
boolean dropShipmentFound = false;
-
+
List invoicesCreated = new ArrayList();
//DEJ20060520: not used? planned to be used? List shipmentIdList = new LinkedList();
@@ -1129,16 +1129,16 @@
} else if (dropShipmentFound) {
List shipments = delegator.findList("Shipment", shipmentIdsCond, null, null, null, false);
-
+
// Get the list of purchase order IDs related to the shipments
List purchaseOrderIds = EntityUtil.getFieldListFromEntityList(shipments, "primaryOrderId", true);
-
+
if (createSalesInvoicesForDropShipments) {
-
+
// If a sales invoice is being created for a drop shipment, we have to reference the original sales order items
// Get the list of the linked orderIds (original sales orders)
orderItemAssocs = delegator.findList("OrderItemAssoc", EntityCondition.makeCondition("toOrderId", EntityOperator.IN, purchaseOrderIds), null, null, null, false);
-
+
// Get only the order items which are indirectly related to the purchase order - this limits the list to the drop ship group(s)
items = EntityUtil.getRelated("FromOrderItem", orderItemAssocs);
} else {
@@ -1242,7 +1242,7 @@
orderedQty = orderItem.getBigDecimal("quantity");
if (dropShipmentFound && createSalesInvoicesForDropShipments.booleanValue()) {
-
+
// Override the issueQty with the quantity from the purchase order item
GenericValue orderItemAssoc = EntityUtil.getFirst(EntityUtil.filterByAnd(orderItemAssocs, UtilMisc.toMap("orderId", issue.getString("orderId"), "orderItemSeqId", issue.getString("orderItemSeqId"))));
GenericValue purchaseOrderItem = orderItemAssoc.getRelatedOne("ToOrderItem");
@@ -1300,15 +1300,15 @@
// If shipping charges are not prorated, the shipments need to be examined for additional shipping charges
if ("N".equalsIgnoreCase(productStore.getString("prorateShipping"))) {
-
+
// Get the set of filtered shipments
List invoiceableShipments = null;
try {
if (dropShipmentFound) {
-
+
List invoiceablePrimaryOrderIds = null;
if (createSalesInvoicesForDropShipments) {
-
+
// If a sales invoice is being created for the drop shipment, we need to reference back to the original purchase order IDs
// Get the IDs for orders which have billable items
@@ -1318,9 +1318,9 @@
// invoiced in a previous sales invoice
List reverseOrderItemAssocs = EntityUtil.filterByCondition(orderItemAssocs, EntityCondition.makeCondition("orderId", EntityOperator.IN, invoiceableLinkedOrderIds));
invoiceablePrimaryOrderIds = EntityUtil.getFieldListFromEntityList(reverseOrderItemAssocs, "toOrderId", true);
-
+
} else {
-
+
// If a purchase order is being created for a drop shipment, the purchase order IDs can be used directly
invoiceablePrimaryOrderIds = EntityUtil.getFieldListFromEntityList(toBillItems, "orderId", true);
@@ -1344,7 +1344,7 @@
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
-
+
// Total the additional shipping charges for the shipments
Map additionalShippingCharges = FastMap.newInstance();
BigDecimal totalAdditionalShippingCharges = ZERO;
@@ -1358,7 +1358,7 @@
totalAdditionalShippingCharges = totalAdditionalShippingCharges.add(shipmentAdditionalShippingCharges);
}
}
-
+
// If the additional shipping charges are greater than zero, process them
if (totalAdditionalShippingCharges.signum() == 1) {
@@ -1400,7 +1400,7 @@
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
-
+
List emptyList = new ArrayList();
Map calcTaxContext = new HashMap();
calcTaxContext.put("productStoreId", orh.getProductStoreId());
@@ -1463,7 +1463,7 @@
if (cardOrderPaymentPref != null) {
paymentMethodId = cardOrderPaymentPref.getString("paymentMethodId");
}
-
+
if (paymentMethodId != null ) {
// Release all outstanding (not settled or cancelled) authorizations, while keeping a running
@@ -1497,7 +1497,7 @@
}
}
}
-
+
// Create a new OrderPaymentPreference for the order to handle the new (totalled) charge. Don't
// set the maxAmount so that it doesn't interfere with other authorizations
Map serviceContext = UtilMisc.toMap("orderId", orderId, "paymentMethodId", paymentMethodId, "paymentMethodTypeId", "CREDIT_CARD", "userLogin", context.get("userLogin"));
@@ -1530,7 +1530,7 @@
String errMsg = UtilProperties.getMessage(resource, "AccountingUnableToAuthAdditionalShipCharges", UtilMisc.toMap("shipmentId", shipmentId, "paymentMethodId", paymentMethodId, "orderPaymentPreferenceId", orderPaymentPreferenceId), locale);
Debug.logError(errMsg, module);
}
-
+
}
}
}
@@ -1584,7 +1584,7 @@
String errorMsg = UtilProperties.getMessage(resource, "AccountingErrorCreatingInvoiceForShipment",UtilMisc.toMap("shipmentId",shipmentId), locale);
boolean salesReturnFound = false;
boolean purchaseReturnFound = false;
-
+
List invoicesCreated = new ArrayList();
try {
@@ -1615,7 +1615,7 @@
// group the shipments by returnId (because we want a seperate itemized invoice for each return)
Map itemsShippedGroupedByReturn = FastMap.newInstance();
-
+
for (Iterator iter = shippedItems.iterator(); iter.hasNext(); ) {
GenericValue item = (GenericValue) iter.next();
String returnId = null;
@@ -1725,7 +1725,7 @@
// loop through shipment receipts to create invoice items and return item billings for each item and adjustment
int invoiceItemSeqNum = 1;
String invoiceItemSeqId = UtilFormatOut.formatPaddedNumber(invoiceItemSeqNum, INVOICE_ITEM_SEQUENCE_ID_DIGITS);
-
+
for (Iterator iter = billItems.iterator(); iter.hasNext(); ) {
GenericValue item = (GenericValue) iter.next();
boolean shipmentReceiptFound = false;
@@ -1763,7 +1763,7 @@
} else if (itemIssuanceFound) {
quantity = item.getBigDecimal("quantity");
}
-
+
// create the invoice item for this shipment receipt
input = UtilMisc.toMap("invoiceId", invoiceId, "invoiceItemTypeId", invoiceItemTypeId, "quantity", quantity);
input.put("invoiceItemSeqId", "" + invoiceItemSeqId); // turn the int into a string with ("" + int) hack
@@ -1924,7 +1924,7 @@
invoiceItemSeqNum += 1;
invoiceItemSeqId = UtilFormatOut.formatPaddedNumber(invoiceItemSeqNum, INVOICE_ITEM_SEQUENCE_ID_DIGITS);
}
-
+
// Set the invoice to READY
serviceResults = dispatcher.runSync("setInvoiceStatus", UtilMisc.<String, Object>toMap("invoiceId", invoiceId, "statusId", "INVOICE_READY", "userLogin", userLogin));
if (ServiceUtil.isError(serviceResults)) {
@@ -1962,12 +1962,12 @@
Debug.logError(e, "Problem getting Invoice for Invoice ID" + invoiceId, module);
return ServiceUtil.returnError("Problem getting Invoice for Invoice ID" + invoiceId);
}
-
+
// Ignore invoices that aren't ready yet
if (! invoice.getString("statusId").equals("INVOICE_READY")) {
return ServiceUtil.returnSuccess();
}
-
+
// Get the payment applications that can be used to pay the invoice
List paymentAppl = null;
try {
@@ -2254,7 +2254,7 @@
}
String defaultInvoiceProcessing = UtilProperties.getPropertyValue("AccountingConfig","invoiceProcessing");
-
+
boolean debug = true; // show processing messages in the log..or not....
// a 'y' in invoiceProssesing wil reverse the default processing
@@ -2287,7 +2287,7 @@
if (changeProcessing == null) {
changeProcessing = "N"; // not provided, so no change
}
-
+
boolean invoiceProcessing = true;
if (defaultInvoiceProcessing.equals("YY")) {
invoiceProcessing = true;
@@ -2349,7 +2349,7 @@
if (payment.getString("statusId").equals("PMNT_CONFIRMED")) {
errorMessageList.add(UtilProperties.getMessage(resource, "AccountingPaymentConfirmed", UtilMisc.toMap("paymentId",paymentId), locale));
}
-
+
currencyUomId = payment.getString("currencyUomId");
// if the amount to apply is 0 give it amount the payment still need
@@ -2401,7 +2401,7 @@
}
}
}
-
+
// check if at least one send is the same as one receiver on the other payment
if (!payment.getString("partyIdFrom").equals(toPayment.getString("partyIdTo")) &&
!payment.getString("partyIdTo").equals(toPayment.getString("partyIdFrom"))) {
@@ -2419,7 +2419,7 @@
} catch (GenericEntityException e) {
ServiceUtil.returnError(e.getMessage());
}
-
+
if (invoice == null) {
errorMessageList.add(UtilProperties.getMessage(resource, "AccountingInvoiceNotFound",UtilMisc.toMap("invoiceId",invoiceId),locale));
} else {
@@ -2428,7 +2428,7 @@
}
}
}
-
+
// billing account
GenericValue billingAccount = null;
BigDecimal billingAccountApplyAvailable = ZERO;
@@ -2465,22 +2465,22 @@
} catch (GenericEntityException e) {
ServiceUtil.returnError(e.getMessage());
}
-
+
if (invoice == null) {
errorMessageList.add(UtilProperties.getMessage(resource, "AccountingInvoiceNotFound",UtilMisc.toMap("invoiceId",invoiceId),locale));
} else { // check the invoice and when supplied the invoice item...
-
+
if (invoice.getString("statusId").equals("INVOICE_CANCELLED")) {
errorMessageList.add(UtilProperties.getMessage(resource,"AccountingInvoiceCancelledCannotApplyTo",UtilMisc.toMap("invoiceId",invoiceId),locale));
}
-
+
// check the currency
if (currencyUomId != null && invoice.get("currencyUomId") != null &&
!currencyUomId.equals(invoice.getString("currencyUomId"))) {
Debug.logInfo(UtilProperties.getMessage(resource, "AccountingInvoicePaymentCurrencyProblem",
UtilMisc.toMap("invoiceCurrency", invoice.getString("currencyUomId"), "paymentCurrency", payment.getString("currencyUomId")),locale), module);
Debug.logInfo("will try to apply payment on the actualCurrency amount on payment", module);
-
+
if (payment.get("actualCurrencyAmount") == null || payment.get("actualCurrencyUomId") == null) {
errorMessageList.add("Actual amounts are required in the currency of the invoice to make this work....");
} else {
@@ -2494,16 +2494,16 @@
amountAppliedMax = paymentApplyAvailable;
}
}
-
+
// check if the invoice already covered by payments
BigDecimal invoiceTotal = InvoiceWorker.getInvoiceTotal(invoice);
invoiceApplyAvailable = InvoiceWorker.getInvoiceNotApplied(invoice);
-
+
// adjust the amountAppliedMax value if required....
if (invoiceApplyAvailable.compareTo(amountAppliedMax) < 0) {
amountAppliedMax = invoiceApplyAvailable;
}
-
+
if (invoiceTotal.signum() == 0) {
errorMessageList.add(UtilProperties.getMessage(resource,"AccountingInvoiceTotalZero",UtilMisc.toMap("invoiceId",invoiceId),locale));
} else if (paymentApplicationId == null) {
@@ -2520,16 +2520,16 @@
"amountApplied",amountApplied,"isoCode",invoice.getString("currencyUomId")),locale));
}
}
-
+
// check if at least one sender is the same as one receiver on the invoice
if (!payment.getString("partyIdFrom").equals(invoice.getString("partyId")) &&
!payment.getString("partyIdTo").equals(invoice.getString("partyIdFrom"))) {
errorMessageList.add(UtilProperties.getMessage(resource, "AccountingFromPartySameToParty", locale));
}
-
+
if (debug) Debug.logInfo("Invoice info retrieved and checked ...", module);
}
-
+
// if provided check the invoice item.
if (invoiceItemSeqId != null) {
// when itemSeqNr not provided delay checking on invoiceItemSeqId
@@ -2538,14 +2538,14 @@
} catch (GenericEntityException e) {
ServiceUtil.returnError(e.getMessage());
}
-
+
if (invoiceItem == null) {
errorMessageList.add(UtilProperties.getMessage(resource,"AccountingInvoiceItemNotFound",UtilMisc.toMap("invoiceId",invoiceId,"invoiceItemSeqId",invoiceItemSeqId),locale));
} else {
if (invoice.get("currencyUomId") != null && currencyUomId != null && !invoice.getString("currencyUomId").equals(currencyUomId)) {
errorMessageList.add(UtilProperties.getMessage(resource,"AccountingInvoicePaymentCurrencyProblem",UtilMisc.toMap("paymentCurrencyId", currencyUomId,"itemCurrency",invoice.getString("currencyUomId")) ,locale));
}
-
+
// get the invoice item applied value
BigDecimal quantity = null;
if (invoiceItem.get("quantity") == null) {
@@ -2760,7 +2760,7 @@
toMessage = UtilProperties.getMessage(resource, "AccountingApplicationToPayment",UtilMisc.toMap("paymentId",toPaymentId),locale);
}
}
-
+
if (amountApplied.signum() == 0) {
errorMessageList.add(UtilProperties.getMessage(resource, "AccountingNoAmount",locale));
} else {
@@ -2923,7 +2923,7 @@
}
}
}
-
+
// if no paymentApplicationId supplied create a new record with the data
// supplied...
if (paymentApplicationId == null && amountApplied != null) {
@@ -2949,7 +2949,7 @@
Locale locale = (Locale) context.get("locale");
GenericValue orderAdjustment = (GenericValue) context.get("orderAdjustment");
Map result = ServiceUtil.returnSuccess();
-
+
BigDecimal invoicedTotal = ZERO;
List invoicedAdjustments = null;
try {
@@ -2984,7 +2984,7 @@
if (decimals == -1 || rounding == -1) {
return ServiceUtil.returnError("Arithmetic properties for Invoice services not configured properly. Cannot proceed.");
}
-
+
// check if a record already exists with this data
List checkAppls = null;
try {
@@ -3098,5 +3098,5 @@
return ServiceUtil.returnError(ee.getMessage());
}
}
-
+
}
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java?rev=759247&r1=759246&r2=759247&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java Fri Mar 27 16:59:58 2009
@@ -45,7 +45,7 @@
* InvoiceWorker - Worker methods of invoices
*/
public class InvoiceWorker {
-
+
public static String module = InvoiceWorker.class.getName();
private static BigDecimal ZERO = BigDecimal.ZERO;
private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
@@ -66,18 +66,18 @@
if (delegator == null) {
throw new IllegalArgumentException("Null delegator is not allowed in this method");
}
-
+
GenericValue invoice = null;
try {
invoice = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId));
} catch (GenericEntityException e) {
Debug.logError(e, "Problem getting Invoice", module);
}
-
+
if (invoice == null) {
throw new IllegalArgumentException("The invoiceId passed does not match an existing invoice");
}
-
+
return getInvoiceTotal(invoice, actualCurrency);
}
@@ -138,11 +138,11 @@
return invoiceTaxTotal.setScale(decimals, rounding);
}
-
+
public static BigDecimal getInvoiceNoTaxTotal(GenericValue invoice) {
return getInvoiceTotal(invoice, Boolean.TRUE).subtract(getInvoiceTaxTotal(invoice));
}
-
+
/**
* Method to return the total amount of an invoice
* @param invoice GenericValue object of the Invoice
@@ -151,7 +151,7 @@
public static BigDecimal getInvoiceTotal(GenericValue invoice) {
return getInvoiceTotal(invoice, Boolean.TRUE);
}
-
+
public static BigDecimal getInvoiceTotal(GenericValue invoice, Boolean actualCurrency) {
BigDecimal invoiceTotal = ZERO;
BigDecimal invoiceTaxTotal = ZERO;
@@ -208,7 +208,7 @@
} catch (GenericEntityException e) {
Debug.logError(e, "Trouble getting InvoiceRole list", module);
}
-
+
if (billToRoles != null) {
GenericValue role = EntityUtil.getFirst(billToRoles);
GenericValue party = null;
@@ -232,7 +232,7 @@
}
return null;
}
-
+
/**
* Method to obtain the send from party for an invoice
* @param invoice GenericValue object of the Invoice
@@ -252,7 +252,7 @@
} catch (GenericEntityException e) {
Debug.logError(e, "Trouble getting InvoiceRole list", module);
}
-
+
if (sendFromRoles != null) {
GenericValue role = EntityUtil.getFirst(sendFromRoles);
GenericValue party = null;
@@ -266,7 +266,7 @@
}
return null;
}
-
+
/**
* Method to obtain the billing address for an invoice
* @param invoice GenericValue object of the Invoice
@@ -275,7 +275,7 @@
public static GenericValue getBillToAddress(GenericValue invoice) {
return getInvoiceAddressByType(invoice, "BILLING_LOCATION");
}
-
+
/**
* Method to obtain the sending address for an invoice
* @param invoice GenericValue object of the Invoice
@@ -284,7 +284,7 @@
public static GenericValue getSendFromAddress(GenericValue invoice) {
return getInvoiceAddressByType(invoice, "PAYMENT_LOCATION");
}
-
+
public static GenericValue getInvoiceAddressByType(GenericValue invoice, String contactMechPurposeTypeId) {
GenericDelegator delegator = invoice.getDelegator();
List locations = null;
@@ -318,7 +318,7 @@
}
}
}
-
+
// now return the first PostalAddress from the locations
GenericValue postalAddress = null;
GenericValue contactMech = null;
@@ -328,7 +328,7 @@
} catch (GenericEntityException e) {
Debug.logError(e, "Trouble getting Contact for contactMechId: " + contactMech.getString("contactMechId"), module);
}
-
+
if (contactMech.getString("contactMechTypeId").equals("POSTAL_ADDRESS")) {
try {
postalAddress = contactMech.getRelatedOne("PostalAddress");
@@ -340,10 +340,10 @@
}
return contactMech;
}
-
+
private static GenericValue getAddressFromParty(GenericValue party, String purposeTypeId) {
if (party == null) return null;
-
+
GenericValue contactMech = null;
GenericValue postalAddress = null;
try {
@@ -358,7 +358,7 @@
} catch (GenericEntityException e) {
Debug.logError(e, "Trouble getting current ContactMech for Party/Purpose", module);
}
-
+
if (contactMech != null) {
if (contactMech.getString("contactMechTypeId").equals("POSTAL_ADDRESS")) {
try {
@@ -368,12 +368,12 @@
}
}
}
-
+
if (postalAddress != null)
return postalAddress;
return null;
}
-
+
/**
* Method to return the total amount of an invoice which is not yet applied to a payment
* @param invoice GenericValue object of the Invoice
@@ -402,7 +402,7 @@
return InvoiceWorker.getInvoiceTotal(invoice, Boolean.TRUE).subtract(getInvoiceApplied(invoice, asOfDateTime));
}
-
+
/**
* Method to return the total amount of an invoice which is applied to a payment
* @param invoice GenericValue object of the Invoice
@@ -411,7 +411,7 @@
public static BigDecimal getInvoiceApplied(GenericDelegator delegator, String invoiceId) {
return getInvoiceApplied(delegator, invoiceId, UtilDateTime.nowTimestamp(), Boolean.TRUE);
}
-
+
/**
* Returns amount applied to invoice before an asOfDateTime, based on Payment.effectiveDate <= asOfDateTime
*
@@ -424,10 +424,10 @@
if (delegator == null) {
throw new IllegalArgumentException("Null delegator is not allowed in this method");
}
-
+
BigDecimal invoiceApplied = ZERO;
List paymentApplications = null;
-
+
// lookup payment applications which took place before the asOfDateTime for this invoice
EntityConditionList dateCondition = EntityCondition.makeCondition(UtilMisc.toList(
EntityCondition.makeCondition("effectiveDate", EntityOperator.EQUALS, null),
@@ -462,7 +462,7 @@
public static BigDecimal getInvoiceApplied(GenericValue invoice) {
return getInvoiceApplied(invoice, UtilDateTime.nowTimestamp());
}
-
+
/**
* @param delegator
* @param invoiceId
@@ -484,21 +484,21 @@
if (delegator == null) {
throw new IllegalArgumentException("Null delegator is not allowed in this method");
}
-
+
GenericValue invoiceItem = null;
try {
invoiceItem = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId,"invoiceItemSeqId", invoiceItemSeqId));
} catch (GenericEntityException e) {
Debug.logError(e, "Problem getting InvoiceItem", module);
}
-
+
if (invoiceItem == null) {
throw new IllegalArgumentException("The invoiceId/itemSeqId passed does not match an existing invoiceItem");
}
-
+
return getInvoiceItemApplied(invoiceItem);
}
-
+
/**
* Method to return the total amount of an invoiceItem which is applied to a payment
* @param invoice GenericValue object of the Invoice
@@ -545,7 +545,7 @@
if (invoice.getString("currencyUomId").equals(otherCurrencyUomId)) {
return BigDecimal.ONE; // organization party has the same currency so conversion not required.
}
-
+
try {
// check if the invoice is posted and get the conversion from there
List acctgTransEntries = invoice.getRelated("AcctgTrans");
@@ -590,19 +590,19 @@
if (delegator == null) {
throw new IllegalArgumentException("Null delegator is not allowed in this method");
}
-
+
GenericValue invoice = null;
try {
invoice = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId));
} catch (GenericEntityException e) {
Debug.logError(e, "Problem getting Invoice", module);
}
-
+
if (invoice == null) {
throw new IllegalArgumentException("The invoiceId passed does not match an existing invoice");
}
-
+
return getInvoiceCurrencyConversionRate(invoice);
}
-
+
}
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java?rev=759247&r1=759246&r2=759247&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java Fri Mar 27 16:59:58 2009
@@ -53,7 +53,7 @@
* Worker methods for BillingAccounts
*/
public class BillingAccountWorker {
-
+
public static final String module = BillingAccountWorker.class.getName();
private static BigDecimal ZERO = BigDecimal.ZERO;
private static int decimals = -1;
@@ -95,10 +95,10 @@
if (currencyUomId.equals(billingAccountVO.getString("accountCurrencyUomId"))) {
BigDecimal accountBalance = BillingAccountWorker.getBillingAccountBalance(billingAccountVO);
-
+
Map billingAccount = new HashMap(billingAccountVO);
BigDecimal accountLimit = getAccountLimit(billingAccountVO);
-
+
billingAccount.put("accountBalance", accountBalance);
BigDecimal accountAvailable = accountLimit.subtract(accountBalance);
totalAvailable = totalAvailable.add(accountAvailable);
@@ -109,7 +109,7 @@
}
return billingAccountList;
}
-
+
/**
* Returns the accountLimit of the BillingAccount or BigDecimal ZERO if it is null
* @param billingAccount
@@ -123,7 +123,7 @@
return ZERO;
}
}
-
+
/**
* Calculates the "available" balance of a billing account, which is the
* net balance minus amount of pending (not cancelled, rejected, or received) order payments.
@@ -139,7 +139,7 @@
}
public static BigDecimal getBillingAccountBalance(GenericValue billingAccount) throws GenericEntityException {
-
+
GenericDelegator delegator = billingAccount.getDelegator();
String billingAccountId = billingAccount.getString("billingAccountId");
@@ -176,10 +176,10 @@
/*
GenericDelegator delegator = billingAccount.getDelegator();
String billingAccountId = billingAccount.getString("billingAccountId");
-
+
// first get the net balance of invoices - payments
BigDecimal balance = getBillingAccountNetBalance(delegator, billingAccountId);
-
+
// now the amounts of all the pending orders (not cancelled, rejected or completed)
List orderHeaders = getBillingAccountOpenOrders(delegator, billingAccountId);
@@ -204,7 +204,7 @@
return balance;
*/
}
-
+
/**
* Returns list of orders which are currently open against a billing account
*/
@@ -217,7 +217,7 @@
EntityJoinOperator.AND);
return delegator.findList("OrderHeader", ecl, null, null, null, false);
}
-
+
/**
* Returns the amount which could be charged to a billing account, which is defined as the accountLimit minus account balance and minus the balance of outstanding orders
* When trying to figure out how much of a billing account can be used to pay for an outstanding order, use this method
@@ -235,7 +235,7 @@
return ZERO;
}
}
-
+
public static BigDecimal getBillingAccountAvailableBalance(GenericDelegator delegator, String billingAccountId) throws GenericEntityException {
GenericValue billingAccount = delegator.findByPrimaryKey("BillingAccount", UtilMisc.toMap("billingAccountId", billingAccountId));
return getBillingAccountAvailableBalance(billingAccount);
@@ -251,7 +251,7 @@
*/
public static BigDecimal getBillingAccountNetBalance(GenericDelegator delegator, String billingAccountId) throws GenericEntityException {
BigDecimal balance = ZERO;
-
+
// search through all PaymentApplications and add the amount that was applied to invoice and subtract the amount applied from payments
List paymentAppls = delegator.findByAnd("PaymentApplication", UtilMisc.toMap("billingAccountId", billingAccountId));
for (Iterator pAi = paymentAppls.iterator(); pAi.hasNext(); ) {
@@ -267,11 +267,11 @@
balance = balance.subtract(amountApplied);
}
}
-
+
balance = balance.setScale(decimals, rounding);
return balance;
}
-
+
/**
* Returns the amount of the billing account which could be captured, which is BillingAccount.accountLimit - net balance
* @param billingAccount
@@ -281,27 +281,27 @@
public static BigDecimal availableToCapture(GenericValue billingAccount) throws GenericEntityException {
BigDecimal netBalance = getBillingAccountNetBalance(billingAccount.getDelegator(), billingAccount.getString("billingAccountId"));
BigDecimal accountLimit = billingAccount.getBigDecimal("accountLimit");
-
+
return accountLimit.subtract(netBalance).setScale(decimals, rounding);
}
-
+
public static Map calcBillingAccountBalance(DispatchContext dctx, Map context) {
GenericDelegator delegator = dctx.getDelegator();
String billingAccountId = (String) context.get("billingAccountId");
Map result = ServiceUtil.returnSuccess();
-
+
try {
GenericValue billingAccount = delegator.findByPrimaryKey("BillingAccount", UtilMisc.toMap("billingAccountId", billingAccountId));
if (billingAccount == null) {
return ServiceUtil.returnError("Unable to locate billing account #" + billingAccountId);
}
-
+
result.put("billingAccount", billingAccount);
result.put("accountBalance", getBillingAccountBalance(delegator, billingAccountId));
result.put("netAccountBalance", getBillingAccountNetBalance(delegator, billingAccountId));
result.put("availableBalance", getBillingAccountAvailableBalance(billingAccount));
result.put("availableToCapture", availableToCapture(billingAccount));
-
+
return result;
} catch (GenericEntityException e) {
Debug.logError(e, module);
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java?rev=759247&r1=759246&r2=759247&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java Fri Mar 27 16:59:58 2009
@@ -55,7 +55,7 @@
public static final int PIN_NUMBER_LENGTH = 6;
public static BigDecimal ZERO = BigDecimal.ZERO;
-
+
// Base Gift Certificate Services
public static Map createGiftCertificate(DispatchContext dctx, Map context) {
LocalDispatcher dispatcher = dctx.getDispatcher();
@@ -84,7 +84,7 @@
GenericValue giftCertSettings = delegator.findByPrimaryKeyCache("ProductStoreFinActSetting", UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId));
Map acctResult = null;
-
+
if ("Y".equals(giftCertSettings.getString("requirePinCode"))) {
// TODO: move this code to createFinAccountForStore as well
int cardNumberLength = CARD_NUMBER_LENGTH;
@@ -100,7 +100,7 @@
// in this case, the card number is the finAccountId
finAccountId = cardNumber;
-
+
// create the FinAccount
Map acctCtx = UtilMisc.toMap("finAccountId", finAccountId);
acctCtx.put("finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId);
@@ -117,12 +117,12 @@
cardNumber = (String) acctResult.get("finAccountCode");
}
}
-
+
if (ServiceUtil.isError(acctResult)) {
String error = ServiceUtil.getErrorMessage(acctResult);
return ServiceUtil.returnError(error);
}
-
+
// create the initial (deposit) transaction
// do something tricky here: run as the "system" user
// that can actually create a financial account transaction
@@ -195,7 +195,7 @@
if (finAccountId == null) {
return ServiceUtil.returnError("Cannot get fin account for adding to balance");
}
-
+
if (finAccount == null) {
try {
finAccount = delegator.findByPrimaryKey("FinAccount", UtilMisc.toMap("finAccountId", finAccountId));
@@ -276,7 +276,7 @@
} catch (GenericEntityException e) {
return ServiceUtil.returnError("Cannot get financial account settings " + e.getMessage());
}
-
+
// check the actual balance (excluding authorized amounts) and create the transaction if it is sufficient
BigDecimal previousBalance = finAccount.get("actualBalance") == null ? BigDecimal.ZERO : finAccount.getBigDecimal("actualBalance");
@@ -327,7 +327,7 @@
} catch (GenericEntityException e) {
return ServiceUtil.returnError("Cannot get financial account settings " + e.getMessage());
}
-
+
// TODO: get the real currency from context
//String currencyUom = UtilProperties.getPropertyValue("general.properties", "currency.uom.id.default", "USD");
// get the balance
@@ -361,7 +361,7 @@
if (authTransaction == null) {
return ServiceUtil.returnError("No authorization transaction found for the OrderPaymentPreference; cannot capture");
}
-
+
// get the gift certificate and its authorization from the authorization
String finAccountAuthId = authTransaction.getString("referenceNum");
try {
@@ -376,10 +376,10 @@
if ((giftCard.getTimestamp("thruDate") != null) && (giftCard.getTimestamp("thruDate").before(UtilDateTime.nowTimestamp()))) {
return ServiceUtil.returnError("Gift certificate has expired as of " + giftCard.getTimestamp("thruDate"));
}
-
+
// obtain the order information
OrderReadHelper orh = new OrderReadHelper(delegator, orderPaymentPreference.getString("orderId"));
-
+
Map redeemCtx = new HashMap();
redeemCtx.put("userLogin", userLogin);
redeemCtx.put("productStoreId", orh.getProductStoreId());
@@ -397,13 +397,13 @@
if (ServiceUtil.isError(redeemResult)) {
return redeemResult;
}
-
+
// now release the authorization should this use the gift card release service?
Map releaseResult = dispatcher.runSync("expireFinAccountAuth", UtilMisc.<String, Object>toMap("userLogin", userLogin, "finAccountAuthId", finAccountAuthId));
if (ServiceUtil.isError(releaseResult)) {
return releaseResult;
}
-
+
Map result = ServiceUtil.returnSuccess();
if (redeemResult != null) {
Boolean processResult = (Boolean) redeemResult.get("processResult");
@@ -422,7 +422,7 @@
}
}
-
+
public static Map giftCertificateAuthorize(DispatchContext dctx, Map context) {
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericDelegator delegator = dctx.getDelegator();
@@ -463,16 +463,16 @@
} else {
return ServiceUtil.returnError("No product store financial account settings available");
}
-
+
if (finAccountId == null) {
return ServiceUtil.returnError("Gift certificate pin number is invalid");
}
-
+
// check for expiration date
if ((finAccount.getTimestamp("thruDate") != null) && (finAccount.getTimestamp("thruDate").before(UtilDateTime.nowTimestamp()))) {
return ServiceUtil.returnError("Gift certificate has expired as of " + finAccount.getTimestamp("thruDate"));
}
-
+
// check the amount to authorize against the available balance of fin account, which includes active authorizations as well as transactions
BigDecimal availableBalance = finAccount.getBigDecimal("availableBalance");
Boolean processResult = null;
@@ -501,7 +501,7 @@
refNum = "N/A"; // a refNum is always required from authorization
processResult = Boolean.FALSE;
}
-
+
result.put("processAmount", amount);
result.put("authResult", processResult);
result.put("processAmount", amount);
@@ -509,7 +509,7 @@
result.put("authCode", "A");
result.put("captureCode", "C");
result.put("authRefNum", refNum);
-
+
return result;
} catch (GenericEntityException ex) {
Debug.logError(ex, "Cannot authorize gift certificate", module);
@@ -519,7 +519,7 @@
return ServiceUtil.returnError("Cannot authorize gift certificate due to " + ex.getMessage());
}
}
-
+
public static Map giftCertificateRefund(DispatchContext dctx, Map context) {
GenericValue userLogin = (GenericValue) context.get("userLogin");
GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");
@@ -699,7 +699,7 @@
Debug.logError(e, "Unable to get Product Store FinAccount settings for " + FinAccountHelper.giftCertFinAccountTypeId, module);
ServiceUtil.returnError("Unable to get Product Store FinAccount settings for " + FinAccountHelper.giftCertFinAccountTypeId + ": " + e.getMessage());
}
-
+
// survey information
String surveyId = giftCertSettings.getString("purchaseSurveyId");
@@ -824,7 +824,7 @@
uiLabelMap.addBottomResourceBundle("CommonUiLabels");
answerMap.put("uiLabelMap", uiLabelMap);
answerMap.put("locale", locale);
-
+
// set the bcc address(s)
String bcc = productStoreEmail.getString("bccAddress");
if (copyMe) {
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java?rev=759247&r1=759246&r2=759247&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java Fri Mar 27 16:59:58 2009
@@ -89,7 +89,7 @@
// set zero to the proper scale
if (decimals != -1) ZERO = ZERO.setScale(decimals);
}
-
+
/**
* Authorizes a single order preference with an option to specify an amount. The result map has the Booleans
* "errors" and "finished" which notify the user if there were any errors and if the authorizatoin was finished.
@@ -155,7 +155,7 @@
} else {
transAmount = orderPaymentPreference.getBigDecimal("maxAmount");
}
-
+
// round this before moving on just in case a funny number made it this far
transAmount = transAmount.setScale(decimals, rounding);
@@ -194,7 +194,7 @@
// TODO: what do we do with this? we need to fail the auth but still allow the order through so it can be fixed later
// NOTE: this is called through a different path for auto re-orders, so it should be good to go... will leave this comment here just in case...
}
-
+
// if we have a failure at this point and no NSF retry is needed, then try other credit cards on file, if the user has any
if (!needsNsfRetry) {
// is this an auto-order?
@@ -211,7 +211,7 @@
} else {
// TODO optional: any other ways to find the bill to party? perhaps look at info from OrderPaymentPreference, ie search back from other PaymentMethod...
}
-
+
if (UtilValidate.isNotEmpty(billToPartyId)) {
otherPaymentMethodAndCreditCardList = delegator.findByAnd("PaymentMethodAndCreditCard",
UtilMisc.toMap("partyId", billToPartyId, "paymentMethodTypeId", "CREDIT_CARD"));
@@ -222,18 +222,18 @@
Iterator otherPaymentMethodAndCreditCardIter = otherPaymentMethodAndCreditCardList.iterator();
while (otherPaymentMethodAndCreditCardIter.hasNext()) {
GenericValue otherPaymentMethodAndCreditCard = (GenericValue) otherPaymentMethodAndCreditCardIter.next();
-
+
// change OrderPaymentPreference in memory only and call auth service
orderPaymentPreference.set("paymentMethodId", otherPaymentMethodAndCreditCard.getString("paymentMethodId"));
Map authRetryResult = authPayment(dispatcher, userLogin, orh, orderPaymentPreference, totalRemaining, reAuth, transAmount);
try {
boolean processRetryResult = processResult(dctx, authPaymentResult, userLogin, orderPaymentPreference);
-
+
if (processRetryResult) {
// wow, we got here that means the other card was successful...
// on success save the OrderPaymentPreference, and then return finished (which will break from loop)
orderPaymentPreference.store();
-
+
Map results = ServiceUtil.returnSuccess();
results.put("messages", authRetryResult.get("customerRespMsgs"));
results.put("processAmount", thisAmount);
@@ -250,7 +250,7 @@
results.put("errors", Boolean.TRUE);
return results;
}
-
+
// if no sucess, fall through to return not finished
}
}
@@ -472,7 +472,7 @@
if (paymentPreference.get("securityCode") != null) {
processContext.put("cardSecurityCode", paymentPreference.get("securityCode"));
}
-
+
// get the billing information
getBillingInformation(orh, paymentPreference, processContext);
@@ -501,9 +501,9 @@
Map processorResult = null;
try {
// invoke the payment processor; allow 5 minute transaction timeout and require a new tx; we'll capture the error and pass back nicely
-
+
GenericValue creditCard = (GenericValue) processContext.get("creditCard");
-
+
// only try other exp dates if orderHeader.autoOrderShoppingListId is not empty, productStore.autoOrderCcTryExp=Y and this payment is a creditCard
boolean tryOtherExpDates = "Y".equals(productStore.getString("autoOrderCcTryExp")) && creditCard != null && UtilValidate.isNotEmpty(orderHeader.getString("autoOrderShoppingListId"));
@@ -511,7 +511,7 @@
if (!tryOtherExpDates || UtilValidate.isDateAfterToday(creditCard.getString("expireDate"))) {
processorResult = dispatcher.runSync(serviceName, processContext, TX_TIME, true);
}
-
+
// try other expire dates if the expireDate is not after today, or if we called the auth service and resultBadExpire = true
if (tryOtherExpDates && (!UtilValidate.isDateAfterToday(creditCard.getString("expireDate")) || (processorResult != null && Boolean.TRUE.equals((Boolean) processorResult.get("resultBadExpire"))))) {
// try adding 2, 3, 4 years later with the same month
@@ -519,7 +519,7 @@
int dateSlash1 = expireDate.indexOf("/");
String month = expireDate.substring(0, dateSlash1);
String year = expireDate.substring(dateSlash1 + 1);
-
+
// start adding 2 years, if comes back with resultBadExpire try again up to twice incrementing one year
year = StringUtil.addToNumberString(year, 2);
// note that this is set in memory only for now, not saved to the database unless successful
@@ -534,14 +534,14 @@
creditCard.set("expireDate", month + "/" + year);
processorResult = dispatcher.runSync(serviceName, processContext, TX_TIME, true);
}
-
+
if (!ServiceUtil.isError(processorResult) && Boolean.TRUE.equals((Boolean) processorResult.get("resultBadExpire"))) {
// okay, try one more year... and this is the last try
year = StringUtil.addToNumberString(year, 1);
creditCard.set("expireDate", month + "/" + year);
processorResult = dispatcher.runSync(serviceName, processContext, TX_TIME, true);
}
-
+
// at this point if we have a successful result, let's save the new creditCard expireDate
if (!ServiceUtil.isError(processorResult) && Boolean.TRUE.equals((Boolean) processorResult.get("authResult"))) {
// TODO: this is bad; we should be expiring the old card and creating a new one instead of editing it
@@ -1106,7 +1106,7 @@
return ServiceUtil.returnError(ex.getMessage());
}
if (captureResult != null) {
-
+
BigDecimal amountCaptured = (BigDecimal) captureResult.get("captureAmount");
Debug.logInfo("Amount captured for order [" + orderId + "] from unapplied payments associated to billing account [" + billingAccountId + "] is: " + amountCaptured, module);
@@ -1323,7 +1323,7 @@
BigDecimal captureAmount = (BigDecimal) context.get("captureAmount");
String orderId = (String) context.get("orderId");
Map results = ServiceUtil.returnSuccess();
-
+
try {
// Note that the partyIdFrom of the Payment should be the partyIdTo of the invoice, since you're receiving a payment from the party you billed
GenericValue invoice = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId));
@@ -1337,7 +1337,7 @@
if (ServiceUtil.isError(tmpResult)) {
return tmpResult;
}
-
+
String paymentId = (String) tmpResult.get("paymentId");
tmpResult = dispatcher.runSync("createPaymentApplication", UtilMisc.<String, Object>toMap("paymentId", paymentId, "invoiceId", invoiceId, "billingAccountId", billingAccountId,
"amountApplied", captureAmount, "userLogin", userLogin));
@@ -1348,7 +1348,7 @@
return ServiceUtil.returnError("No payment created for invoice [" + invoiceId + "] and billing account [" + billingAccountId + "]");
}
results.put("paymentId", paymentId);
-
+
if (orderId != null && captureAmount.compareTo(BigDecimal.ZERO) > 0) {
// Create a paymentGatewayResponse, if necessary
GenericValue order = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
@@ -1359,7 +1359,7 @@
List orderPaymentPreferences = delegator.findByAnd("OrderPaymentPreference", UtilMisc.toMap("orderId", orderId, "paymentMethodTypeId", "EXT_BILLACT"));
if (orderPaymentPreferences.size() > 0) {
GenericValue orderPaymentPreference = EntityUtil.getFirst(orderPaymentPreferences);
-
+
// Check the productStore setting to see if we need to do this explicitly
GenericValue productStore = order.getRelatedOne("ProductStore");
if (productStore.getString("manualAuthIsCapture") == null || (! productStore.getString("manualAuthIsCapture").equalsIgnoreCase("Y"))) {
@@ -1383,7 +1383,7 @@
// Update the orderPaymentPreference
orderPaymentPreference.set("statusId", "PAYMENT_SETTLED");
orderPaymentPreference.store();
-
+
results.put("paymentGatewayResponseId", responseId);
}
}
@@ -1407,7 +1407,7 @@
captureAmount = captureAmount.setScale(decimals, rounding);
String orderId = (String) context.get("orderId");
BigDecimal capturedAmount = BigDecimal.ZERO;
-
+
try {
// Select all the unapplied payment applications associated to the billing account
List conditionList = UtilMisc.toList(EntityCondition.makeCondition("billingAccountId", EntityOperator.EQUALS, billingAccountId),
@@ -1460,7 +1460,7 @@
results.put("captureAmount", capturedAmount);
return results;
}
-
+
private static Map capturePayment(DispatchContext dctx, GenericValue userLogin, OrderReadHelper orh, GenericValue paymentPref, BigDecimal amount) {
return capturePayment(dctx, userLogin, orh, paymentPref, amount, null);
}
@@ -1545,8 +1545,8 @@
} catch (GenericServiceException ex) {
return ServiceUtil.returnError("Cannot get model service for " + serviceName);
}
-
-
+
+
if (authTrans != null) {
captureContext.put("authTrans", authTrans);
}
@@ -1717,7 +1717,7 @@
response.set("paymentMethodId", orderPaymentPreference.get("paymentMethodId"));
response.set("transCodeEnumId", "PGT_AUTHORIZE");
response.set("currencyUomId", currencyUomId);
-
+
// set the avs/fraud result
response.set("gatewayAvsResult", context.get("avsCode"));
response.set("gatewayCvResult", context.get("cvCode"));
@@ -1732,7 +1732,7 @@
response.set("gatewayFlag", context.get("authFlag"));
response.set("gatewayMessage", context.get("authMessage"));
response.set("transactionDate", UtilDateTime.nowTimestamp());
-
+
if (Boolean.TRUE.equals((Boolean) context.get("resultDeclined"))) response.set("resultDeclined", "Y");
if (Boolean.TRUE.equals((Boolean) context.get("resultNsf"))) response.set("resultNsf", "Y");
if (Boolean.TRUE.equals((Boolean) context.get("resultBadExpire"))) response.set("resultBadExpire", "Y");
@@ -1740,7 +1740,7 @@
// save the response
savePgr(dctx, response);
-
+
// create the internal messages
List messages = (List) context.get("internalRespMsgs");
if (UtilValidate.isNotEmpty(messages)) {
@@ -1755,11 +1755,11 @@
savePgr(dctx, respMsg);
}
}
-
+
if (response.getBigDecimal("amount").compareTo((BigDecimal)context.get("processAmount")) != 0) {
Debug.logWarning("The authorized amount does not match the max amount : Response - " + response + " : result - " + context, module);
}
-
+
// set the status of the OrderPaymentPreference
if (context != null && authResult.booleanValue()) {
orderPaymentPreference.set("statusId", "PAYMENT_AUTHORIZED");
@@ -1768,11 +1768,11 @@
} else {
orderPaymentPreference.set("statusId", "PAYMENT_ERROR");
}
-
+
// remove sensitive credit card data regardless of outcome
orderPaymentPreference.set("securityCode", null);
orderPaymentPreference.set("track2", null);
-
+
boolean needsNsfRetry = needsNsfRetry(orderPaymentPreference, context, delegator);
if (needsNsfRetry) {
orderPaymentPreference.set("needsNsfRetry", "Y");
@@ -1792,7 +1792,7 @@
creditCard.set("consecutiveFailedAuths", new Long(consecutiveFailedAuths.longValue() + 1));
}
creditCard.set("lastFailedAuthDate", nowTimestamp);
-
+
if (Boolean.TRUE.equals((Boolean) context.get("resultNsf"))) {
Long consecutiveFailedNsf = creditCard.getLong("consecutiveFailedNsf");
if (consecutiveFailedNsf == null) {
@@ -1805,7 +1805,7 @@
creditCard.store();
}
}
-
+
// auth was successful, to clear out any failed auth or nsf info
if (authResult.booleanValue()) {
if ((creditCard != null) && (creditCard.get("lastFailedAuthDate") != null)) {
@@ -1824,7 +1824,7 @@
return ServiceUtil.returnSuccess();
}
-
+
private static boolean needsNsfRetry(GenericValue orderPaymentPreference, Map processContext, GenericDelegator delegator) throws GenericEntityException {
boolean needsNsfRetry = false;
if (Boolean.TRUE.equals((Boolean) processContext.get("resultNsf"))) {
@@ -2468,12 +2468,12 @@
return ServiceUtil.returnSuccess();
}
-
+
public static Map retryFailedAuthNsfs(DispatchContext dctx, Map context) {
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericValue userLogin = (GenericValue) context.get("userLogin");
-
+
// get the date/time for one week before now since we'll only retry once a week for NSFs
Calendar calcCal = Calendar.getInstance();
calcCal.setTimeInMillis(System.currentTimeMillis());
@@ -2517,7 +2517,7 @@
return ServiceUtil.returnSuccess();
}
-
+
public static GenericValue getCaptureTransaction(GenericValue orderPaymentPreference) {
GenericValue capTrans = null;
try {
@@ -2940,7 +2940,7 @@
}
}
}
-
+
return ServiceUtil.returnSuccess();
}
@@ -3139,7 +3139,7 @@
String expireDate = creditCard.getString("expireDate");
String lastNumberStr = expireDate.substring(expireDate.length() - 1);
int lastNumber = Integer.parseInt(lastNumberStr);
-
+
if ((float) lastNumber / 2.0 == 0.0) {
return alwaysBadExpireProcessor(dctx, context);
} else {