if (Debug.verboseOn()) Debug.logVerbose("Returned Records: " + retRecords.size(), module);
if (Debug.verboseOn()) Debug.logVerbose("Sent Items: " + records.size(), module);
while (i.hasNext()) {
Record rec = (Record) i.next();
ModelRecord model = rec.getModelRecord();
// make the adjustment lists
if (itemAdjustments.size() < records.size()) {
List currentItem = new ArrayList();
if (rec.getDouble("TAX_AMT_COUNTRY").doubleValue() > 0) {
if (Debug.verboseOn()) Debug.logVerbose("Country Tax Amount: " + rec.getDouble("TAX_AMT_COUNTRY"), module);
Double rate = new Double(rec.getDouble("TAX_RATE_COUNTRY").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_COUNTRY").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_COUNTRY") != null ? rec.getString("JUR_COUNTRY").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
currentItem.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_COUNTRY"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
if (rec.getDouble("TAX_AMT_STATE").doubleValue() > 0) {
Double rate = new Double(rec.getDouble("TAX_RATE_STATE").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_STATE").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_STATE") != null ? rec.getString("JUR_STATE").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
currentItem.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_STATE"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
if (rec.getDouble("TAX_AMT_COUNTY").doubleValue() > 0) {
Double rate = new Double(rec.getDouble("TAX_RATE_COUNTY").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_COUNTY").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_COUNTY_CODE") != null ? rec.getString("JUR_COUNTY_CODE").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
currentItem.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_COUNTY"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
if (rec.getDouble("TAX_AMT_CITY").doubleValue() > 0) {
Double rate = new Double(rec.getDouble("TAX_RATE_CITY").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_CITY").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_CITY") != null ? rec.getString("JUR_CITY").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
currentItem.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_CITY"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
if (rec.getDouble("TAX_AMT_SEC_STATE").doubleValue() > 0) {
Double rate = new Double(rec.getDouble("TAX_RATE_SEC_STATE").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_SEC_STATE").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_SEC_STATE") != null ? rec.getString("JUR_SEC_STATE").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
currentItem.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_SEC_STATE"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
if (rec.getDouble("TAX_AMT_SEC_COUNTY").doubleValue() > 0) {
Double rate = new Double(rec.getDouble("TAX_RATE_SEC_COUNTY").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_SEC_COUNTY").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_SEC_COUNTY_CODE") != null ? rec.getString("JUR_SEC_COUNTY_CODE").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
currentItem.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_SEC_COUNTY"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
if (rec.getDouble("TAX_AMT_SEC_CITY").doubleValue() > 0) {
Double rate = new Double(rec.getDouble("TAX_RATE_SEC_CITY").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_SEC_CITY").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_SEC_CITY") != null ? rec.getString("JUR_SEC_CITY").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
currentItem.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_SEC_CITY"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
// add a list of adjustments to the adjustment list
itemAdjustments.add(currentItem);
} else if (orderAdjustments.size() == 0) {
if (rec.getDouble("TAX_AMT_COUNTRY").doubleValue() > 0) {
Double rate = new Double(rec.getDouble("TAX_RATE_COUNTRY").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_COUNTRY").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_COUNTRY") != null ? rec.getString("JUR_COUNTRY").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
orderAdjustments.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_COUNTRY"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
if (rec.getDouble("TAX_AMT_STATE").doubleValue() > 0) {
Double rate = new Double(rec.getDouble("TAX_RATE_STATE").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_STATE").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_STATE") != null ? rec.getString("JUR_STATE").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
orderAdjustments.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_STATE"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
if (rec.getDouble("TAX_AMT_COUNTY").doubleValue() > 0) {
Double rate = new Double(rec.getDouble("TAX_RATE_COUNTY").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_COUNTY").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_COUNTY_CODE") != null ? rec.getString("JUR_COUNTY_CODE").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
orderAdjustments.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_COUNTY"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
if (rec.getDouble("TAX_AMT_CITY").doubleValue() > 0) {
Double rate = new Double(rec.getDouble("TAX_RATE_CITY").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_CITY").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_CITY") != null ? rec.getString("JUR_CITY").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
orderAdjustments.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_CITY"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
if (rec.getDouble("TAX_AMT_SEC_STATE").doubleValue() > 0) {
Double rate = new Double(rec.getDouble("TAX_RATE_SEC_STATE").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_SEC_STATE").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_SEC_STATE") != null ? rec.getString("JUR_SEC_STATE").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
orderAdjustments.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_SEC_STATE"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
if (rec.getDouble("TAX_AMT_SEC_COUNTY").doubleValue() > 0) {
Double rate = new Double(rec.getDouble("TAX_RATE_SEC_COUNTY").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_SEC_COUNTY").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_SEC_COUNTY_CODE") != null ? rec.getString("JUR_SEC_COUNTY_CODE").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
orderAdjustments.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_SEC_COUNTY"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
if (rec.getDouble("TAX_AMT_SEC_CITY").doubleValue() > 0) {
Double rate = new Double(rec.getDouble("TAX_RATE_SEC_CITY").doubleValue() * 100);
String type = rec.getString("TAX_TYPE_SEC_CITY").equals("S") ? "SALES TAX" : "USE TAX";
String jur = rec.get("JUR_SEC_CITY") != null ? rec.getString("JUR_SEC_CITY").trim() : "";
String comments = jur + "|" + type + "|" + rate.toString();
orderAdjustments.add(delegator.makeValue("OrderAdjustment",
UtilMisc.toMap("amount", rec.getDouble("TAX_AMT_SEC_CITY"),
"orderAdjustmentTypeId", "SALES_TAX", "comments", comments)));
}
} else {
throw new TaxwareException("Invalid number of return adjustments.");
}
for (int a = 0; a < model.fields.size(); a++) {
ModelField mf = (ModelField) model.fields.get(a);
String name = mf.name;
String value = rec.getString(name);
if (Debug.verboseOn()) Debug.logVerbose("Field: " + name + " => " + value, module);
}
}
return retRecords.size();