bean.setConn(conn);
// retrieve all out delivery note rows...
GridParams pars = new GridParams();
pars.getOtherGridParams().put(ApplicationConsts.DELIVERY_NOTE_PK,pk);
Response res = bean.loadOutDeliveryNoteRows(variant1Descriptions,variant2Descriptions,variant3Descriptions,variant4Descriptions,variant5Descriptions,pars,serverLanguageId,username);
if (res.isError())
throw new Exception(res.getErrorMessage());
String sql1 =
"select QTY,OUT_QTY from DOC02_SELLING_ITEMS where "+
"COMPANY_CODE_SYS01=? and DOC_TYPE=? and DOC_YEAR=? and DOC_NUMBER=? and ITEM_CODE_ITM01=? and "+
"VARIANT_TYPE_ITM06=? and VARIANT_CODE_ITM11=? and "+
"VARIANT_TYPE_ITM07=? and VARIANT_CODE_ITM12=? and "+
"VARIANT_TYPE_ITM08=? and VARIANT_CODE_ITM13=? and "+
"VARIANT_TYPE_ITM09=? and VARIANT_CODE_ITM14=? and "+
"VARIANT_TYPE_ITM10=? and VARIANT_CODE_ITM15=? ";
String sql2 =
"update DOC02_SELLING_ITEMS set OUT_QTY=?,LAST_UPDATE_USER=?,LAST_UPDATE_DATE=? where "+
"COMPANY_CODE_SYS01=? and DOC_TYPE=? and DOC_YEAR=? and DOC_NUMBER=? and ITEM_CODE_ITM01=? and OUT_QTY=? and "+
"VARIANT_TYPE_ITM06=? and VARIANT_CODE_ITM11=? and "+
"VARIANT_TYPE_ITM07=? and VARIANT_CODE_ITM12=? and "+
"VARIANT_TYPE_ITM08=? and VARIANT_CODE_ITM13=? and "+
"VARIANT_TYPE_ITM09=? and VARIANT_CODE_ITM14=? and "+
"VARIANT_TYPE_ITM10=? and VARIANT_CODE_ITM15=? ";
pstmt1 = conn.prepareStatement(sql1);
pstmt2 = conn.prepareStatement(sql2);
// for each item row, the related sale order row will be updated and available quantities in warehouse...
GridOutDeliveryNoteRowVO vo = null;
ResultSet rset1 = null;
BigDecimal qtyDOC02 = null;
BigDecimal outQtyDOC02 = null;
BigDecimal qtyToAdd = null;
Response innerResponse = null;
for(int i=0;i<((VOListResponse)res).getRows().size();i++) {
vo = (GridOutDeliveryNoteRowVO)((VOListResponse)res).getRows().get(i);
pstmt1.setString(1,vo.getCompanyCodeSys01DOC10());
pstmt1.setString(2,vo.getDocTypeDoc01DOC10());
pstmt1.setBigDecimal(3,vo.getDocYearDoc01DOC10());
pstmt1.setBigDecimal(4,vo.getDocNumberDoc01DOC10());
pstmt1.setString(5,vo.getItemCodeItm01DOC10());
pstmt1.setString(6,vo.getVariantTypeItm06DOC10());
pstmt1.setString(7,vo.getVariantCodeItm11DOC10());
pstmt1.setString(8,vo.getVariantTypeItm07DOC10());
pstmt1.setString(9,vo.getVariantCodeItm12DOC10());
pstmt1.setString(10,vo.getVariantTypeItm08DOC10());
pstmt1.setString(11,vo.getVariantCodeItm13DOC10());
pstmt1.setString(12,vo.getVariantTypeItm09DOC10());
pstmt1.setString(13,vo.getVariantCodeItm14DOC10());
pstmt1.setString(14,vo.getVariantTypeItm10DOC10());
pstmt1.setString(15,vo.getVariantCodeItm15DOC10());
rset1 = pstmt1.executeQuery();
if(rset1.next()) {
qtyDOC02 = rset1.getBigDecimal(1);
outQtyDOC02 = rset1.getBigDecimal(2);
rset1.close();
/*
// update out qty in the sale document row...
if (vo.getSupplierQtyDOC10().doubleValue()<qtyDOC02.subtract(outQtyDOC02).doubleValue())
qtyToAdd = vo.getSupplierQtyDOC10();
else
qtyToAdd = qtyDOC02.subtract(outQtyDOC02);
pstmt2.setBigDecimal(1,outQtyDOC02.add(qtyToAdd).setScale(vo.getSupplierQtyDecimalsREG02().intValue(),BigDecimal.ROUND_HALF_UP));
pstmt2.setString(2,vo.getCompanyCodeSys01DOC10());
pstmt2.setString(3,vo.getDocTypeDoc01DOC10());
pstmt2.setBigDecimal(4,vo.getDocYearDoc01DOC10());
pstmt2.setBigDecimal(5,vo.getDocNumberDoc01DOC10());
pstmt2.setString(6,vo.getItemCodeItm01DOC10());
pstmt2.setBigDecimal(7,outQtyDOC02);
*/
if (pstmt2.executeUpdate()==0)
throw new Exception("Updating not performed: the record was previously updated.");
}
else
rset1.close();
// update warehouse available qty..
WarehouseMovementVO movVO = new WarehouseMovementVO(
vo.getProgressiveHie01DOC10(),
vo.getQtyDOC10(),
vo.getCompanyCodeSys01DOC10(),
vo.getWarehouseCodeWar01DOC08(),
vo.getItemCodeItm01DOC10(),
ApplicationConsts.WAREHOUSE_MOTIVE_UNLOAD_BY_ORDER,
ApplicationConsts.ITEM_GOOD,
t1+" "+vo.getDocNumberDoc01DOC10()+"/"+vo.getDocYearDoc01DOC10(),
vo.getSerialNumbers(),
vo.getVariantCodeItm11DOC10(),
vo.getVariantCodeItm12DOC10(),
vo.getVariantCodeItm13DOC10(),
vo.getVariantCodeItm14DOC10(),
vo.getVariantCodeItm15DOC10(),
vo.getVariantTypeItm06DOC10(),
vo.getVariantTypeItm07DOC10(),
vo.getVariantTypeItm08DOC10(),
vo.getVariantTypeItm09DOC10(),
vo.getVariantTypeItm10DOC10()
);
innerResponse = movBean.addWarehouseMovement(movVO,t2,serverLanguageId,username);
if (innerResponse.isError())
throw new Exception(innerResponse.getErrorMessage());
}
return new VOResponse(Boolean.TRUE);
}