Package org.jallinone.production.billsofmaterial.java

Examples of org.jallinone.production.billsofmaterial.java.MaterialVO


      // set explosion panel...
      explosionPanel.setLoadWhenVisibile(false);
      explosionPanel.setTreeController(new TreeController() {

        public void doubleClick(DefaultMutableTreeNode node) {
          MaterialVO vo = (MaterialVO)node.getUserObject();
          new ItemController(null,new ItemPK(vo.getCompanyCodeSys01ITM03(),vo.getItemCodeItm01ITM03()),false);
        }

        public void leftClick(DefaultMutableTreeNode node) {}

        public boolean rightClick(DefaultMutableTreeNode node) {
View Full Code Here


  /**
   * Expand the current node and fill in TMP01 table.
   */
  private int expandNode(int level,String lastPad,int progressive,DefaultMutableTreeNode parentNode,DecimalFormat format,DecimalFormat qtyFormat,BigDecimal reportId,PreparedStatement pstmt,DefaultMutableTreeNode node,String username) throws Exception {
    MaterialVO vo = (MaterialVO)node.getUserObject();
    String pad = "";

    if (level>0) {
      //      pad = "|";
      //      int spaces = level*2-1;
      //      for(int i=0;i<spaces;i++)
      //        pad += " ";
      //      if (level>1)
      //        pad += "|";

      pad = lastPad+"| ";

      pstmt.setBigDecimal(1,reportId);
      pstmt.setInt(2,progressive);
      pstmt.setString(3,vo.getCompanyCodeSys01ITM03());
      pstmt.setString(4,pad);
      pstmt.setString(5,null);
      pstmt.setString(6,null);
      pstmt.setBigDecimal(7,null);
      pstmt.setString(8,null);
      pstmt.setString(9,null);
      pstmt.setString(10,null);
      pstmt.setString(11,null);
      pstmt.setString(12,null);
      pstmt.setString(13,null);
      pstmt.setString(14,username);
      pstmt.setTimestamp(15,new java.sql.Timestamp(System.currentTimeMillis()));
      pstmt.execute();

      progressive++;
    }

    if (level>0) {
      //      if (level==1)
      //        pad = "+-";
      //      else {
      //        pad = "|";
      //        int spaces = level*2-1;
      //        for(int i=0;i<spaces;i++)
      //          pad += " ";
      //        pad += "+-";
      //      }
      pad = lastPad+"+-";
    }
    else
      pad = "";

    pstmt.setBigDecimal(1,reportId);
    pstmt.setInt(2,progressive);
    pstmt.setString(3,vo.getCompanyCodeSys01ITM03());
    pstmt.setString(4,pad);
    pstmt.setString(5,vo.getItemCodeItm01ITM03());
    pstmt.setString(6,vo.getDescriptionSYS10());
    pstmt.setInt(7,level);
    pstmt.setString(8,qtyFormat.format(vo.getQtyITM03()));
    pstmt.setString(9,vo.getMinSellingQtyUmCodeReg02ITM01());
    pstmt.setString(10,vo.getValuePUR04()==null?null:format.format(vo.getValuePUR04().doubleValue()));
    pstmt.setString(11,vo.getTotalPrices()==null?null:format.format(vo.getTotalPrices().doubleValue()));
    pstmt.setString(12,vo.getValuePRO02()==null?null:format.format(vo.getValuePRO02().doubleValue()));
    pstmt.setString(13,vo.getTotalCosts()==null?null:format.format(vo.getTotalCosts().doubleValue()));
    pstmt.execute();

    progressive++;


View Full Code Here

      // fill in comps hashtable with the collection of required components...
      ItemPK pk = null;
      ProdOrderProductVO prodVO = null;
      ArrayList components = null;
      MaterialVO compVO = null;
      Response res = null;
      ProdOrderComponentVO componentVO = null;
      Hashtable comps = new Hashtable(); // collection of <component item code,ProdOrderComponentVO object>
      for(int i=0;i<products.size();i++) {
        // retrieve bill of materials for each product...
        prodVO = (ProdOrderProductVO)products.get(i);
        pk = new ItemPK(prodVO.getCompanyCodeSys01DOC23(),prodVO.getItemCodeItm01DOC23());
        res = BillOfMaterialsUtil.getBillOfMaterials(conn,compCurr,pk,serverLanguageId,username,new ArrayList());
        if (res.isError()) {
          throw new Exception(res.getErrorMessage());
        }

        // extract components only (leaf nodes)...
        components = getComponents((DefaultMutableTreeNode) ((TreeModel)((VOResponse)res).getVo()).getRoot() );
        for(int j=0;j<components.size();j++) {
          compVO = (MaterialVO)components.get(j);
          componentVO = (ProdOrderComponentVO)comps.get(compVO.getItemCodeItm01ITM03());
          if (componentVO==null) {
            componentVO = new ProdOrderComponentVO();
            comps.put(compVO.getItemCodeItm01ITM03(),componentVO);
            componentVO.setAvailableQty(new BigDecimal(0));
            componentVO.setCompanyCodeSys01DOC24(compVO.getCompanyCodeSys01ITM03());
            componentVO.setDescriptionSYS10(compVO.getDescriptionSYS10());
            componentVO.setDocNumberDOC24(prodVO.getDocNumberDOC23());
            componentVO.setDocYearDOC24(prodVO.getDocYearDOC23());
            componentVO.setItemCodeItm01DOC24(compVO.getItemCodeItm01ITM03());
            componentVO.setMinSellingQtyUmCodeReg02ITM01(compVO.getMinSellingQtyUmCodeReg02ITM01());
            componentVO.setQtyDOC24(new BigDecimal(0));
          }
          componentVO.setQtyDOC24(componentVO.getQtyDOC24().add(compVO.getQtyITM03().multiply(prodVO.getQtyDOC23())));
        }
      }


      // check components availability in the specified warehouse...
View Full Code Here

      ArrayList values = new ArrayList();
      values.add(langId);
      values.add(pk.getCompanyCodeSys01ITM01());

      // retrieve the whole tree...
      MaterialVO compVO = new MaterialVO();
      compVO.setCompanyCodeSys01ITM03(pk.getCompanyCodeSys01ITM01());
      compVO.setDescriptionSYS10("");
      compVO.setItemCodeItm01ITM03(pk.getItemCodeITM01());
      compVO.setQtyITM03(new BigDecimal(1));
      DefaultMutableTreeNode node = new OpenSwingTreeNode(compVO);
      DefaultTreeModel model = new DefaultTreeModel(node);

      String sql2 = "'" + pk.getItemCodeITM01() + "'";
      ArrayList nodes = new ArrayList();
      ArrayList nodes2 = new ArrayList(); // current nodes...
      Hashtable auxnodes = new Hashtable();
      nodes.add(node);

      // read from ITM03 table...
      Response res = null;
      java.util.List rows = null;
      java.util.List auxlist = null;
      DefaultMutableTreeNode auxnode,auxnode2 = null;
      String currentItemCode = null;

      do {
        res = QueryUtil.getQuery(
            conn,
            new UserSessionParameters(username),
            sql1+sql2+sql3,
            values,
            attribute2dbField,
            MaterialVO.class,
            "Y",
            "N",
            null,
            new GridParams(),
            true
        );
        if (!res.isError()) {
          rows = ((VOListResponse)res).getRows();
          auxnodes.clear();
          nodes2 = new ArrayList();
          sql2 = "";

          // group items per item code parent...
          for(int i=0;i<rows.size();i++) {
            compVO = (MaterialVO)rows.get(i);
            sql2 += "'"+compVO.getItemCodeItm01ITM03()+"',";
            auxnode = new OpenSwingTreeNode(compVO);
            auxlist = (ArrayList)auxnodes.get(compVO.getParentItemCodeItm01ITM03());
            if (auxlist==null) {
              auxlist = new ArrayList();
              auxnodes.put(compVO.getParentItemCodeItm01ITM03(),auxlist);
            }
            auxlist.add(auxnode);
            nodes2.add(auxnode);
          }

          if (sql2.length()>0)
            sql2 = sql2.substring(0,sql2.length()-1);


          // add items to the corresponding parent...
          for(int i=0;i<nodes.size();i++) {
            auxnode = (DefaultMutableTreeNode)nodes.get(i);
            compVO = (MaterialVO)auxnode.getUserObject();
            auxlist = (ArrayList)auxnodes.get(compVO.getItemCodeItm01ITM03());
            if (auxlist!=null)
              for(int j=0;j<auxlist.size();j++) {
                auxnode.add( (DefaultMutableTreeNode) auxlist.get(j));
                ((MaterialVO)((DefaultMutableTreeNode)auxlist.get(j)).getUserObject()).setQtyITM03(
                    ((MaterialVO)((DefaultMutableTreeNode)auxlist.get(j)).getUserObject()).getQtyITM03().multiply(
View Full Code Here

   * @param node current analyzed node
   */
  private static Response expandNode(Connection conn,CurrencyVO currVO,PreparedStatement pstmt,PreparedStatement pstmt2,DefaultMutableTreeNode node) throws Exception {
    ResultSet rset = null;
    try {
      MaterialVO vo = (MaterialVO)node.getUserObject();
      if (node.getChildCount()==0) {
        // the current node is a leaf, so it cannot be constructed: it will be purchased...
        pstmt.setString(1,vo.getCompanyCodeSys01ITM03());
        pstmt.setString(2,vo.getItemCodeItm01ITM03());
        pstmt.setDate(3,new java.sql.Date(System.currentTimeMillis()));
        pstmt.setDate(4,new java.sql.Date(System.currentTimeMillis()+86400*1000-1));
        rset = pstmt.executeQuery();
        BigDecimal totPrice = new BigDecimal(0);
        BigDecimal totNum = new BigDecimal(0);
        BigDecimal price = null;
        BigDecimal num = null;
        String currencyCode = null;
        while(rset.next()) {
          price = rset.getBigDecimal(1);
          num = rset.getBigDecimal(2);
          currencyCode = rset.getString(3);
          price = CurrencyConversionUtils.convertCurrencyToCurrency(new java.sql.Date(System.currentTimeMillis()),price,currencyCode,currVO.getCurrencyCodeREG03(),conn);
          if (price!=null && num!=null) {
            totPrice = totPrice.add(price);
            totNum = totNum.add(num);
          }
        }
        rset.close();
        if (totPrice.doubleValue()>0) {
          vo.setValuePUR04(vo.getQtyITM03().multiply(totPrice).divide(num, BigDecimal.ROUND_HALF_UP).setScale(5, BigDecimal.ROUND_HALF_UP));
          vo.setTotalPrices(vo.getValuePUR04());
        }
      }
      else {
        // the current node is not a leaf, so it will be constructed: now it will be calculated production costs...
        pstmt2.setString(1,vo.getCompanyCodeSys01ITM03());
        pstmt2.setString(2,vo.getItemCodeItm01ITM03());
        rset = pstmt2.executeQuery();
        BigDecimal cost = null;
        if(rset.next()) {
          cost = rset.getBigDecimal(1);
        }
        rset.close();
        if (cost!=null && cost.doubleValue()>0) {
          vo.setValuePRO02(vo.getQtyITM03().multiply(cost).setScale(5, BigDecimal.ROUND_HALF_UP));
        }

        // navigate through children nodes...
        Response res = null;
        for(int i=0;i<node.getChildCount();i++) {
          res = expandNode(conn,currVO,pstmt,pstmt2,(DefaultMutableTreeNode)node.getChildAt(i));
          if (res.isError())
            return res;
        }
        if (res.isError())
          return res;

        // calculate total costs + total prices...
        MaterialVO childVO = null;
        BigDecimal totalPrices = new BigDecimal(0);
        BigDecimal totalCosts = vo.getValuePRO02();
        for(int i=0;i<node.getChildCount();i++) {
          childVO = (MaterialVO)((DefaultMutableTreeNode)node.getChildAt(i)).getUserObject();
          if (childVO.getTotalPrices()!=null && totalPrices!=null)
            //            totalPrices = totalPrices.add(childVO.getTotalPrices().multiply(childVO.getQtyITM03()));
            totalPrices = totalPrices.add(childVO.getTotalPrices());
          else
            totalPrices = null;
          if (childVO.getTotalCosts()!=null && totalCosts!=null)
            //            totalCosts = totalCosts.add(childVO.getTotalCosts().multiply(childVO.getQtyITM03()));
            totalCosts = totalCosts.add(childVO.getTotalCosts());
        }
        if (totalCosts!=null)
          vo.setTotalCosts(totalCosts.setScale(5,BigDecimal.ROUND_HALF_UP));
        if (totalPrices!=null && totalPrices!=null)
          vo.setTotalPrices(totalPrices.setScale(5,BigDecimal.ROUND_HALF_UP));
View Full Code Here

      ArrayList values = new ArrayList();
      values.add(langId);
      values.add(pk.getCompanyCodeSys01ITM01());

      // retrieve the whole tree...
      MaterialVO rootVO = new MaterialVO();
      rootVO.setCompanyCodeSys01ITM03(pk.getCompanyCodeSys01ITM01());
      rootVO.setDescriptionSYS10("");
      rootVO.setParentItemCodeItm01ITM03("");
      rootVO.setItemCodeItm01ITM03("");
      DefaultMutableTreeNode root = new OpenSwingTreeNode(rootVO);
      DefaultTreeModel model = new DefaultTreeModel(root);

      String sql2 = "'" + pk.getItemCodeITM01() + "'";

      // read from ITM03 table...
      Response res = null;
      java.util.List rows = null;
      DefaultMutableTreeNode auxnode,auxnode2;
      MaterialVO auxVO = null;
      Hashtable nodes = new Hashtable(); // collections of <item component code,related node>
      Hashtable auxnodes = new Hashtable(); // collections of <item component code,related node>
      Enumeration en = null;

      do {
        res = QueryUtil.getQuery(
            conn,
            new UserSessionParameters(username),
            sql1+sql2+sql3,
            values,
            attribute2dbField,
            MaterialVO.class,
            "Y",
            "N",
            null,
            new GridParams(),
            true
        );
        if (!res.isError()) {
          rows = ((VOListResponse)res).getRows();

          sql2 = "";

          for(int i=0;i<rows.size();i++) {
            auxVO = (MaterialVO)rows.get(i);
            sql2 += "'"+auxVO.getParentItemCodeItm01ITM03()+"',";
            auxnode = new OpenSwingTreeNode(auxVO);
            auxnode2 = (DefaultMutableTreeNode)nodes.get(auxVO.getItemCodeItm01ITM03());
            if (auxnode2!=null)
              auxnode.add(auxnode2);
            nodes.remove(auxVO.getItemCodeItm01ITM03());
            auxnodes.put(auxVO.getParentItemCodeItm01ITM03(),auxnode);
          }

          en = nodes.keys();
          while(en.hasMoreElements()) {
            root.add((DefaultMutableTreeNode)nodes.get(en.nextElement()));
View Full Code Here

   /**
    * 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());
View Full Code Here

TOP

Related Classes of org.jallinone.production.billsofmaterial.java.MaterialVO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.