/**
* Expand the current (sub)product node.
*/
private int expandNode(int sequence,DetailProdOrderVO prodOrderVO,DefaultMutableTreeNode node,Hashtable usedComponents,Hashtable usedComponentsVO,HashMap compAltCodes,HashSet subProductsAlreadyAdded,PreparedStatement pstmt,PreparedStatement pstmt2,String serverLanguageId,String username,String imagePath) throws Throwable {
DefaultMutableTreeNode childNode = null;
MaterialVO vo = null;
BigDecimal qty = null;
Iterator it = null;
BigDecimal delta = null;
String itemCode = null;
MaterialVO prodVO = (MaterialVO)node.getUserObject();
for(int i=0;i<node.getChildCount();i++) {
childNode = (DefaultMutableTreeNode)node.getChildAt(i);
if (!childNode.isLeaf()) {
// the component is a sub-product...
sequence = expandNode(sequence,prodOrderVO,childNode,usedComponents,usedComponentsVO,compAltCodes,subProductsAlreadyAdded,pstmt,pstmt2,serverLanguageId,username,imagePath);
}
}
BigDecimal altQty = null;
for(int i=0;i<node.getChildCount();i++) {
childNode = (DefaultMutableTreeNode)node.getChildAt(i);
vo = (MaterialVO)childNode.getUserObject();
if (childNode.isLeaf()) {
// component found: check if there must be used an alternative component instead of the current one...
qty = (BigDecimal)usedComponents.get(vo.getItemCodeItm01ITM03());
if (qty!=null && qty.doubleValue()>0) {
if (vo.getQtyITM03().doubleValue()<=qty.doubleValue())
delta = vo.getQtyITM03();
else {
delta = qty;
}
vo.setQtyITM03(vo.getQtyITM03().subtract(delta));
usedComponents.put(vo.getItemCodeItm01ITM03(),qty.subtract(delta));
pstmt.setString(1,prodOrderVO.getCompanyCodeSys01DOC22());
pstmt.setBigDecimal(2,prodOrderVO.getDocYearDOC22());
pstmt.setBigDecimal(3,prodOrderVO.getDocNumberDOC22());
pstmt.setString(4,prodVO.getItemCodeItm01ITM03());
pstmt.setString(5,vo.getItemCodeItm01ITM03());
pstmt.setBigDecimal(6,delta);
pstmt.setInt(7,sequence);
pstmt.setString(8,username);
pstmt.setTimestamp(9,new java.sql.Timestamp(System.currentTimeMillis()));
pstmt.execute();
sequence++;
}
if (vo.getQtyITM03().doubleValue()>0) {
it = ((HashSet)compAltCodes.get(vo.getItemCodeItm01ITM03())).iterator();
while(vo.getQtyITM03().doubleValue()>0 && it.hasNext()) {
itemCode = it.next().toString();
qty = (BigDecimal)usedComponents.get(itemCode);
altQty = conv.convertQty(
((ProdOrderComponentVO)usedComponentsVO.get(itemCode)).getMinSellingQtyUmCodeReg02ITM01(),
vo.getMinSellingQtyUmCodeReg02ITM01(),
qty,
serverLanguageId,
username
);
if (qty!=null && qty.doubleValue()>0) {
if (vo.getQtyITM03().doubleValue()<=altQty.doubleValue()) {
delta = conv.convertQty(
vo.getMinSellingQtyUmCodeReg02ITM01(),
((ProdOrderComponentVO)usedComponentsVO.get(itemCode)).getMinSellingQtyUmCodeReg02ITM01(),
vo.getQtyITM03(),
serverLanguageId,
username
);
usedComponents.put(itemCode,qty.subtract(delta));
vo.setQtyITM03(new BigDecimal(0));
}
else {
delta = qty;
usedComponents.put(itemCode,new BigDecimal(0));
vo.setQtyITM03(vo.getQtyITM03().subtract(altQty));
}
pstmt.setString(1,prodOrderVO.getCompanyCodeSys01DOC22());
pstmt.setBigDecimal(2,prodOrderVO.getDocYearDOC22());
pstmt.setBigDecimal(3,prodOrderVO.getDocNumberDOC22());
pstmt.setString(4,prodVO.getItemCodeItm01ITM03());
pstmt.setString(5,itemCode);
pstmt.setBigDecimal(6,delta);
pstmt.setInt(7,sequence);
pstmt.setString(8,username);
pstmt.setTimestamp(9,new java.sql.Timestamp(System.currentTimeMillis()));
pstmt.execute();
sequence++;
}
}
}
}
else {
// the component is a sub-product...
pstmt.setString(1,prodOrderVO.getCompanyCodeSys01DOC22());
pstmt.setBigDecimal(2,prodOrderVO.getDocYearDOC22());
pstmt.setBigDecimal(3,prodOrderVO.getDocNumberDOC22());
pstmt.setString(4,prodVO.getItemCodeItm01ITM03());
pstmt.setString(5,vo.getItemCodeItm01ITM03());
pstmt.setBigDecimal(6,vo.getQtyITM03());
pstmt.setInt(7,sequence);
pstmt.setString(8,username);
pstmt.setTimestamp(9,new java.sql.Timestamp(System.currentTimeMillis()));
pstmt.execute();
sequence++;
}
}
ItemPK pk = new ItemPK(prodVO.getCompanyCodeSys01ITM03(),prodVO.getItemCodeItm01ITM03());
BigDecimal prg = item.getProgressiveHie02ITM01(pk, username);
// retrieve manufacture code...
Response res = new VOResponse(item.loadItem(
pk,
prg,
serverLanguageId,
username,
imagePath,
new ArrayList()
));
if (res.isError())
throw new Exception(res.getErrorMessage());
DetailItemVO itemVO = (DetailItemVO)((VOResponse)res).getVo();
// retrieve manufacture operations and insert them to DOC26...
ManufactureVO manVO = new ManufactureVO();
manVO.setCompanyCodeSys01PRO01(itemVO.getCompanyCodeSys01ITM01());
manVO.setManufactureCodePRO01(itemVO.getManufactureCodePro01ITM01());
GridParams gridParams = new GridParams();
gridParams.getOtherGridParams().put(ApplicationConsts.MANUFACTURE_VO,manVO);
res = ops.loadManufacturePhases(gridParams,serverLanguageId,username,new ArrayList());
if (res.isError())
throw new Exception(res.getErrorMessage());
java.util.List list = ((VOListResponse)res).getRows();
ManufacturePhaseVO phaseVO = null;
if (subProductsAlreadyAdded.contains(prodVO.getItemCodeItm01ITM03()))
return sequence;
subProductsAlreadyAdded.add(prodVO.getItemCodeItm01ITM03());
for(int i=0;i<list.size();i++) {
phaseVO = (ManufacturePhaseVO)list.get(i);
/*
"insert into DOC26_PRODUCTION_OPERATIONS(COMPANY_CODE_SYS01,DOC_YEAR,DOC_NUMBER,ITEM_CODE_ITM01,PHASE_NUMBER,"+
"OPERATION_CODE,OPERATION_DESCRIPTION,VALUE,DURATION,MANUFACTURE_TYPE,COMPLETION_PERC,QTY,TASK_CODE,TASK_DESCRIPTION,"+
"MACHINERY_CODE,MACHINERY_DESCRIPTION,SUBST_OPERATION_CODE,SUBST_OPERATION_DESCRIPTION,NOTE) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?"
*/
pstmt2.setString(1,prodOrderVO.getCompanyCodeSys01DOC22());
pstmt2.setBigDecimal(2,prodOrderVO.getDocYearDOC22());
pstmt2.setBigDecimal(3,prodOrderVO.getDocNumberDOC22());
pstmt2.setString(4,prodVO.getItemCodeItm01ITM03());
pstmt2.setBigDecimal(5,phaseVO.getPhaseNumberPRO02());
pstmt2.setString(6,phaseVO.getOperationCodePro04PRO02());
pstmt2.setString(7,phaseVO.getDescriptionSYS10());
pstmt2.setBigDecimal(8,phaseVO.getValuePRO02());
pstmt2.setBigDecimal(9,phaseVO.getDurationPRO02());