prep.setInt(1, dId);
prep.setInt(2, warehouseId);
rs = db.query(prep);
rs.next();
int oId = rs.getInt(1) - 1;
BigDecimal tax = rs.getBigDecimal(2);
rs.close();
prep = prepare("SELECT C_DISCOUNT, C_LAST, C_CREDIT, W_TAX "
+ "FROM CUSTOMER, WAREHOUSE "
+ "WHERE C_ID=? AND W_ID=? AND C_W_ID=W_ID AND C_D_ID=?");
prep.setInt(1, cId);
prep.setInt(2, warehouseId);
prep.setInt(3, dId);
rs = db.query(prep);
rs.next();
BigDecimal discount = rs.getBigDecimal(1);
// c_last
rs.getString(2);
// c_credit
rs.getString(3);
BigDecimal wTax = rs.getBigDecimal(4);
rs.close();
BigDecimal total = new BigDecimal("0");
for (int number = 1; number <= olCnt; number++) {
int olId = itemId[number - 1];
int olSupplyId = supplyId[number - 1];
int olQuantity = quantity[number - 1];
prep = prepare("SELECT I_PRICE, I_NAME, I_DATA "
+ "FROM ITEM WHERE I_ID=?");
prep.setInt(1, olId);
rs = db.query(prep);
if (!rs.next()) {
if (rollback) {
// item not found - correct behavior
db.rollback();
return;
}
throw new SQLException("item not found: " + olId + " "
+ olSupplyId);
}
BigDecimal price = rs.getBigDecimal(1);
// i_name
rs.getString(2);
String data = rs.getString(3);
rs.close();
prep = prepare("SELECT S_QUANTITY, S_DATA, "
+ "S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04, S_DIST_05, "
+ "S_DIST_06, S_DIST_07, S_DIST_08, S_DIST_09, S_DIST_10 "
+ "FROM STOCK WHERE S_I_ID=? AND S_W_ID=?");
prep.setInt(1, olId);
prep.setInt(2, olSupplyId);
rs = db.query(prep);
if (!rs.next()) {
if (rollback) {
// item not found - correct behavior
db.rollback();
return;
}
throw new SQLException("item not found: " + olId + " "
+ olSupplyId);
}
int sQuantity = rs.getInt(1);
String sData = rs.getString(2);
String[] dist = new String[10];
for (int i = 0; i < 10; i++) {
dist[i] = rs.getString(3 + i);
}
rs.close();
String distInfo = dist[dId - 1];
stock[number - 1] = sQuantity;
if ((data.indexOf("original") != -1)
&& (sData.indexOf("original") != -1)) {
bg[number - 1] = 'B';
} else {
bg[number - 1] = 'G';
}
if (sQuantity > olQuantity) {
sQuantity = sQuantity - olQuantity;
} else {
sQuantity = sQuantity - olQuantity + 91;
}
prep = prepare("UPDATE STOCK SET S_QUANTITY=? "
+ "WHERE S_W_ID=? AND S_I_ID=?");
prep.setInt(1, sQuantity);
prep.setInt(2, olSupplyId);
prep.setInt(3, olId);
db.update(prep, "updateStock");
BigDecimal olAmount = new BigDecimal(olQuantity).multiply(
price).multiply(ONE.add(wTax).add(tax)).multiply(
ONE.subtract(discount));
olAmount = olAmount.setScale(2, BigDecimal.ROUND_HALF_UP);
amt[number - 1] = olAmount;
total = total.add(olAmount);
prep = prepare("INSERT INTO ORDER_LINE (OL_O_ID, OL_D_ID, OL_W_ID, OL_NUMBER, "
+ "OL_I_ID, OL_SUPPLY_W_ID, "
+ "OL_QUANTITY, OL_AMOUNT, OL_DIST_INFO) "