Package org.jallinone.sales.documents.java

Examples of org.jallinone.sales.documents.java.DetailSaleDocVO


      ResultSet rset1 = null;
      BigDecimal qtyDOC02 = null;
      BigDecimal outQtyDOC02 = null;
      BigDecimal qtyToAdd = null;
      Response innerResponse = null;
      DetailSaleDocVO saleDocVO = null;
      for(int i=0;i<((VOListResponse)res).getRows().size();i++) {
        vo = (GridOutDeliveryNoteRowVO)((VOListResponse)res).getRows().get(i);

        // update delivery request...
        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.getQtyDOC10().doubleValue()<qtyDOC02.subtract(outQtyDOC02).doubleValue())
            qtyToAdd = vo.getQtyDOC10();
          else
            qtyToAdd = qtyDOC02.subtract(outQtyDOC02);
          pstmt2.setBigDecimal(1,outQtyDOC02.add(qtyToAdd).setScale(vo.getDecimalsREG02().intValue(),BigDecimal.ROUND_HALF_UP));
          pstmt2.setString(2,username);
          pstmt2.setTimestamp(3,new java.sql.Timestamp(System.currentTimeMillis()));
          pstmt2.setString(4,vo.getCompanyCodeSys01DOC10());
          pstmt2.setString(5,vo.getDocTypeDoc01DOC10());
          pstmt2.setBigDecimal(6,vo.getDocYearDoc01DOC10());
          pstmt2.setBigDecimal(7,vo.getDocNumberDoc01DOC10());
          pstmt2.setString(8,vo.getItemCodeItm01DOC10());
          pstmt2.setBigDecimal(9,outQtyDOC02);

          pstmt2.setString(10,vo.getVariantTypeItm06DOC10());
          pstmt2.setString(11,vo.getVariantCodeItm11DOC10());
          pstmt2.setString(12,vo.getVariantTypeItm07DOC10());
          pstmt2.setString(13,vo.getVariantCodeItm12DOC10());
          pstmt2.setString(14,vo.getVariantTypeItm08DOC10());
          pstmt2.setString(15,vo.getVariantCodeItm13DOC10());
          pstmt2.setString(16,vo.getVariantTypeItm09DOC10());
          pstmt2.setString(17,vo.getVariantCodeItm14DOC10());
          pstmt2.setString(18,vo.getVariantTypeItm10DOC10());
          pstmt2.setString(19,vo.getVariantCodeItm15DOC10());

          if (pstmt2.executeUpdate()==0)
            throw new Exception("Updating not performed: the record was previously updated.");
        }
        else
          rset1.close();

        // close delivery note requests document...
        pstmt3.setString(1,ApplicationConsts.CLOSED);
        pstmt3.setString(2,username);
        pstmt3.setTimestamp(3,new java.sql.Timestamp(System.currentTimeMillis()));
        pstmt3.setString(4,vo.getCompanyCodeSys01DOC10());
        pstmt3.setString(5,vo.getDocTypeDoc01DOC10());
        pstmt3.setBigDecimal(6,vo.getDocYearDoc01DOC10());
        pstmt3.setBigDecimal(7,vo.getDocNumberDoc01DOC10());
        pstmt3.setString(8,vo.getCompanyCodeSys01DOC10());
        pstmt3.setString(9,vo.getDocTypeDoc01DOC10());
        pstmt3.setBigDecimal(10,vo.getDocYearDoc01DOC10());
        pstmt3.setBigDecimal(11,vo.getDocNumberDoc01DOC10());
        int processedRows = pstmt3.executeUpdate();


        // update sale document...
        if (vo.getDocTypeDoc01DOC10().equals(ApplicationConsts.DELIVERY_REQUEST_DOC_TYPE)) {
           SaleDocPK saleDocPK = new SaleDocPK(vo.getCompanyCodeSys01DOC10(),vo.getDocTypeDoc01DOC10(),vo.getDocYearDoc01DOC10(),vo.getDocNumberDoc01DOC10());

           saleDocVO = loadSaleDocBean.loadSaleDoc(
          saleDocPK,
          serverLanguageId,
          username,
          new ArrayList()
          );

          pstmt1.setString(1,saleDocVO.getCompanyCodeSys01DOC01());
          pstmt1.setString(2,saleDocVO.getDocTypeDoc01DOC01());
          pstmt1.setBigDecimal(3,saleDocVO.getDocYearDoc01DOC01());
          pstmt1.setBigDecimal(4,saleDocVO.getDocNumberDoc01DOC01());
          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.getQtyDOC10().doubleValue()<qtyDOC02.subtract(outQtyDOC02).doubleValue())
              qtyToAdd = vo.getQtyDOC10();
            else
              qtyToAdd = qtyDOC02.subtract(outQtyDOC02);
            pstmt2.setBigDecimal(1,outQtyDOC02.add(qtyToAdd).setScale(vo.getDecimalsREG02().intValue(),BigDecimal.ROUND_HALF_UP));
            pstmt2.setString(2,username);
            pstmt2.setTimestamp(3,new java.sql.Timestamp(System.currentTimeMillis()));
            pstmt2.setString(4,saleDocVO.getCompanyCodeSys01DOC01());
            pstmt2.setString(5,saleDocVO.getDocTypeDoc01DOC01());
            pstmt2.setBigDecimal(6,saleDocVO.getDocYearDoc01DOC01());
            pstmt2.setBigDecimal(7,saleDocVO.getDocNumberDoc01DOC01());
            pstmt2.setString(8,vo.getItemCodeItm01DOC10());
            pstmt2.setBigDecimal(9,outQtyDOC02);

            pstmt2.setString(10,vo.getVariantTypeItm06DOC10());
            pstmt2.setString(11,vo.getVariantCodeItm11DOC10());
View Full Code Here


        public void codeValidated(boolean validated) {}

        public void codeChanged(ValueObject parentVO,Collection parentChangedAttributes) {}

        public void beforeLookupAction(ValueObject parentVO) {
          DetailSaleDocVO vo = (DetailSaleDocVO)form.getVOModel().getValueObject();
          wareDataLocator.getLookupFrameParams().put(ApplicationConsts.COMPANY_CODE_SYS01,vo.getCompanyCodeSys01DOC01());
          wareDataLocator.getLookupValidationParameters().put(ApplicationConsts.COMPANY_CODE_SYS01,vo.getCompanyCodeSys01DOC01());
        }

        public void forceValidate() {}

      });



      // destination lookup...
      destDataLocator.setGridMethodName("loadDestinations");
      destDataLocator.setValidationMethodName("validateDestinationCode");

      controlDestCode.setLookupController(destController);
      destController.setForm(form);
      destController.setLookupDataLocator(destDataLocator);
      destController.setFrameTitle("destinations");
      destController.setLookupValueObjectClassName("org.jallinone.sales.destinations.java.DestinationVO");
      destController.addLookup2ParentLink("destinationCodeREG18", "destinationCodeReg18DOC01");
      destController.addLookup2ParentLink("descriptionREG18","descriptionDOC01");
      destController.addLookup2ParentLink("addressREG18", "addressDOC01");
      destController.addLookup2ParentLink("cityREG18","cityDOC01");
      destController.addLookup2ParentLink("zipREG18","zipDOC01");
      destController.addLookup2ParentLink("provinceREG18","provinceDOC01");
      destController.addLookup2ParentLink("countryREG18","countryDOC01");
      destController.setAllColumnVisible(false);
      destController.setVisibleColumn("destinationCodeREG18", true);
      destController.setVisibleColumn("descriptionREG18", true);
      destController.setVisibleColumn("addressREG18", true);
      destController.setVisibleColumn("cityREG18", true);
      destController.setVisibleColumn("zipREG18", true);
      destController.setVisibleColumn("provinceREG18", true);
      destController.setVisibleColumn("countryREG18", true);

      destController.setHeaderColumnName("addressREG18", "address");
      destController.setHeaderColumnName("cityREG18", "city");
      destController.setHeaderColumnName("zipREG18", "zip");
      destController.setHeaderColumnName("provinceREG18", "province");
      destController.setHeaderColumnName("countryREG18", "country");

      destController.setPreferredWidthColumn("descriptionREG18",200);
      destController.setFramePreferedSize(new Dimension(750,500));
      destController.addLookupListener(new LookupListener() {

        public void codeValidated(boolean validated) {}

        public void codeChanged(ValueObject parentVO,Collection parentChangedAttributes) {
          DetailSaleDocVO vo = (DetailSaleDocVO)form.getVOModel().getValueObject();
          if (vo.getWarehouseCodeWar01DOC01()==null || vo.getWarehouseCodeWar01DOC01().equals("")) {
            vo.setDescriptionWar01DOC01(null);
            vo.setAddressDOC01(null);
            vo.setCityDOC01(null);
            vo.setProvinceDOC01(null);
            vo.setZipDOC01(null);
            vo.setCountryDOC01(null);
          }
        }

        public void beforeLookupAction(ValueObject parentVO) {
          DetailSaleDocVO vo = (DetailSaleDocVO)form.getVOModel().getValueObject();
          destDataLocator.getLookupFrameParams().put(ApplicationConsts.SUBJECT_PK,new SubjectPK(vo.getCompanyCodeSys01DOC01(),vo.getProgressiveReg04DOC01()));
          destDataLocator.getLookupValidationParameters().put(ApplicationConsts.SUBJECT_PK,new SubjectPK(vo.getCompanyCodeSys01DOC01(),vo.getProgressiveReg04DOC01()));
        }

        public void forceValidate() {}

      });
View Full Code Here

      long time = System.currentTimeMillis();
      BigDecimal totalTaxableIncome = new BigDecimal(0);

      // retrieve document header value object...
      DetailSaleDocVO vo = docBean.loadSaleDoc(pk,serverLanguageId,username,new ArrayList());

      // check if there exists a vat code defined at customer level...
      BigDecimal customerVatValue = null;
      String customerVatCode = null;
      String customerVatDescription = null;
      if (vo.getCustomerVatCodeReg01DOC01()!=null && !vo.getCustomerVatCodeReg01DOC01().equals("")) {
        // retrieve vat value and deductible percentage...
        Response res = vatBean.validateVatCode(
            new LookupValidationParams(vo.getCustomerVatCodeReg01DOC01(),new HashMap()),
            serverLanguageId,
            username,
            new ArrayList()
        );
        if (!res.isError()) {
          VatVO vatVO = (VatVO)((VOListResponse)res).getRows().get(0);
          customerVatValue = new BigDecimal(vatVO.getValueREG01().doubleValue()*(1d-vatVO.getDeductibleREG01().doubleValue()/100d));
          customerVatCode = vatVO.getVatCodeREG01();
          customerVatDescription = vatVO.getDescriptionSYS10();
        }
      }

      // retrieve all item rows...
      GridParams pars = new GridParams();
      pars.getOtherGridParams().put(ApplicationConsts.SALE_DOC_PK,pk);
      Response rowsResponse = rowsBean.loadSaleDocRows(variant1Descriptions,variant2Descriptions,variant3Descriptions,variant4Descriptions,variant5Descriptions,pars,serverLanguageId,username);
      if (rowsResponse.isError())
        throw new Exception(rowsResponse.getErrorMessage());
      java.util.List itemRows = ((VOListResponse)rowsResponse).getRows();

      // for each item, calculate item discounts...
      GridSaleDocRowVO itemVO = null;
      Response rowResponse = null;
      DetailSaleDocRowVO detailItemVO = null;
      Response itemTotDiscResponse = null;
      ArrayList detailItemRows = new ArrayList();
      double vatPerc;
      for(int i=0;i<itemRows.size();i++) {
        itemVO = (GridSaleDocRowVO)itemRows.get(i);
        // retrieve item detail...
        rowResponse = bean.loadSaleDocRow(
          variant1Descriptions,variant2Descriptions,variant3Descriptions,variant4Descriptions,variant5Descriptions,
          new SaleDocRowPK(
            pk.getCompanyCodeSys01DOC01(),
            pk.getDocTypeDOC01(),
            pk.getDocYearDOC01(),
            pk.getDocNumberDOC01(),
            itemVO.getItemCodeItm01DOC02(),
            itemVO.getVariantTypeItm06DOC02(),
            itemVO.getVariantCodeItm11DOC02(),
            itemVO.getVariantTypeItm07DOC02(),
            itemVO.getVariantCodeItm12DOC02(),
            itemVO.getVariantTypeItm08DOC02(),
            itemVO.getVariantCodeItm13DOC02(),
            itemVO.getVariantTypeItm09DOC02(),
            itemVO.getVariantCodeItm14DOC02(),
            itemVO.getVariantTypeItm10DOC02(),
            itemVO.getVariantCodeItm15DOC02()
          ),
          serverLanguageId,
          username

        );
        if (rowResponse.isError())
          throw new Exception(rowsResponse.getErrorMessage());
        detailItemVO = (DetailSaleDocRowVO)((VOResponse)rowResponse).getVo();
        detailItemRows.add(detailItemVO);

        // calculate item discount...
        detailItemVO.setTaxableIncomeDOC02(detailItemVO.getQtyDOC02().multiply(detailItemVO.getValueSal02DOC02()).setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP));
        itemTotDiscResponse = itemDiscountBean.getSaleItemTotalDiscount(detailItemVO,serverLanguageId,username);
        if (itemTotDiscResponse.isError())
          throw new Exception(itemTotDiscResponse.getErrorMessage());

        // apply total discount to item detail...
        detailItemVO.setTotalDiscountDOC02( detailItemVO.getTotalDiscountDOC02().setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP) );

        // apply total discount to taxable income...
        detailItemVO.setTaxableIncomeDOC02(detailItemVO.getTaxableIncomeDOC02().subtract(detailItemVO.getTotalDiscountDOC02()).setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP));

        // calculate row vat...
        vatPerc = detailItemVO.getValueReg01DOC02().doubleValue()*(1d-detailItemVO.getDeductibleReg01DOC02().doubleValue()/100d)/100;
        detailItemVO.setVatValueDOC02(detailItemVO.getTaxableIncomeDOC02().multiply(new BigDecimal(vatPerc)).setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP));

        // calculate row total...
        detailItemVO.setValueDOC02(detailItemVO.getTaxableIncomeDOC02().add(detailItemVO.getVatValueDOC02()));

        // apply taxable income to total taxable income...
        totalTaxableIncome = totalTaxableIncome.add(detailItemVO.getTaxableIncomeDOC02());
      }

      // retrieve all activities rows...
      rowsResponse = rowsBean.loadSaleDocActivities(pars,serverLanguageId,username);
      if (rowsResponse.isError())
        throw new Exception(rowsResponse.getErrorMessage());
      java.util.List actsRows = ((VOListResponse)rowsResponse).getRows();
      SaleDocActivityVO actVO = null;
      for(int i=0;i<actsRows.size();i++) {
        actVO = (SaleDocActivityVO)actsRows.get(i);
        actVO.setTaxableIncomeDOC13(
          actVO.getValueDOC13().setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
        );

        // apply taxable income to total taxable income...
        totalTaxableIncome = totalTaxableIncome.add(actVO.getTaxableIncomeDOC13());
      }

      // retrieve all charges rows...
      rowsResponse = rowsBean.loadSaleDocCharges(pars,serverLanguageId,username);
      if (rowsResponse.isError())
        throw new Exception(rowsResponse.getErrorMessage());
      java.util.List chargesRows = ((VOListResponse)rowsResponse).getRows();
      SaleDocChargeVO chargeVO = null;
      for(int i=0;i<chargesRows.size();i++) {
        chargeVO = (SaleDocChargeVO)chargesRows.get(i);
        if (chargeVO.getValueDOC03()!=null) {
          chargeVO.setTaxableIncomeDOC03(
            chargeVO.getValueDOC03().setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
          );

          // apply taxable income to total taxable income...
          totalTaxableIncome = totalTaxableIncome.add(chargeVO.getTaxableIncomeDOC03());
        }
      }

      // fill in coeff...
      Hashtable coeff = new Hashtable(); // collection of <item/act/valuecharge,taxableincome/totaltaxableincome>
      for(int i=0;i<detailItemRows.size();i++) {
        detailItemVO = (DetailSaleDocRowVO)detailItemRows.get(i);
        coeff.put(detailItemVO,detailItemVO.getTaxableIncomeDOC02().divide(totalTaxableIncome,BigDecimal.ROUND_HALF_UP));
      }

      for(int i=0;i<actsRows.size();i++) {
        actVO = (SaleDocActivityVO)actsRows.get(i);
        coeff.put(actVO,actVO.getTaxableIncomeDOC13().divide(totalTaxableIncome,BigDecimal.ROUND_HALF_UP));
      }

      for(int i=0;i<chargesRows.size();i++) {
        chargeVO = (SaleDocChargeVO)chargesRows.get(i);
        if (chargeVO.getValueDOC03()!=null) {
          coeff.put(chargeVO,chargeVO.getTaxableIncomeDOC03().divide(totalTaxableIncome,BigDecimal.ROUND_HALF_UP));
        }
      }

      // apply % charges to all taxable incomes...
      SaleDocChargeVO percVO = null;
      for(int k=0;k<chargesRows.size();k++) {
        percVO = (SaleDocChargeVO)chargesRows.get(k);
        if (percVO.getPercDOC03()!=null) {
          for(int i=0;i<detailItemRows.size();i++) {
            detailItemVO = (DetailSaleDocRowVO)detailItemRows.get(i);
            detailItemVO.setTaxableIncomeDOC02(
              detailItemVO.getTaxableIncomeDOC02().add(detailItemVO.getTaxableIncomeDOC02().multiply(percVO.getPercDOC03().divide(new BigDecimal(100),BigDecimal.ROUND_HALF_UP))).
              setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
            );
          }

          for(int i=0;i<actsRows.size();i++) {
            actVO = (SaleDocActivityVO)actsRows.get(i);
            actVO.setTaxableIncomeDOC13(
              actVO.getTaxableIncomeDOC13().add(actVO.getTaxableIncomeDOC13().multiply(percVO.getPercDOC03().divide(new BigDecimal(100),BigDecimal.ROUND_HALF_UP))).
              setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
            );
          }

          for(int i=0;i<chargesRows.size();i++) {
            chargeVO = (SaleDocChargeVO)chargesRows.get(i);
            if (chargeVO.getValueDOC03()!=null) {
              chargeVO.setTaxableIncomeDOC03(
                chargeVO.getTaxableIncomeDOC03().add(chargeVO.getTaxableIncomeDOC03().multiply(percVO.getPercDOC03().divide(new BigDecimal(100),BigDecimal.ROUND_HALF_UP))).
                setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
              );
            }
          }

        }
      }

      // +MC 7/1/2011 (as in SaleDocTotalsBean.getSaleDocTotals)
      // apply discount (eventually) defined at row level...
      if (vo.getDiscountValueDOC01()!=null) {

        for(int i=0;i<detailItemRows.size();i++) {
          detailItemVO = (DetailSaleDocRowVO)detailItemRows.get(i);
          detailItemVO.setTaxableIncomeDOC02(
            detailItemVO.getTaxableIncomeDOC02().subtract(vo.getDiscountValueDOC01().multiply((BigDecimal)coeff.get(detailItemVO))).
            setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
          );
        }

        for(int i=0;i<actsRows.size();i++) {
          actVO = (SaleDocActivityVO)actsRows.get(i);
          actVO.setTaxableIncomeDOC13(
            actVO.getTaxableIncomeDOC13().subtract(vo.getDiscountValueDOC01().multiply((BigDecimal)coeff.get(actVO))).
            setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
          );
        }

        for(int i=0;i<chargesRows.size();i++) {
          chargeVO = (SaleDocChargeVO)chargesRows.get(i);
          if (chargeVO.getValueDOC03()!=null) {
            chargeVO.setTaxableIncomeDOC03(
              chargeVO.getTaxableIncomeDOC03().subtract(vo.getDiscountValueDOC01().multiply((BigDecimal)coeff.get(chargeVO))).
              setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
            );
          }
        }

      }
      else if (vo.getDiscountPercDOC01()!=null) {
        for(int i=0;i<detailItemRows.size();i++) {
          detailItemVO = (DetailSaleDocRowVO)detailItemRows.get(i);
          detailItemVO.setTaxableIncomeDOC02(
            detailItemVO.getTaxableIncomeDOC02().subtract(detailItemVO.getTaxableIncomeDOC02().multiply(vo.getDiscountPercDOC01().divide(new BigDecimal(100),BigDecimal.ROUND_HALF_UP))).
            setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
          );
        }

        for(int i=0;i<actsRows.size();i++) {
          actVO = (SaleDocActivityVO)actsRows.get(i);
          actVO.setTaxableIncomeDOC13(
            actVO.getTaxableIncomeDOC13().subtract(actVO.getTaxableIncomeDOC13().multiply(vo.getDiscountPercDOC01().divide(new BigDecimal(100),BigDecimal.ROUND_HALF_UP))).
            setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
          );
        }

        for(int i=0;i<chargesRows.size();i++) {
          chargeVO = (SaleDocChargeVO)chargesRows.get(i);
          if (chargeVO.getValueDOC03()!=null) {
            chargeVO.setTaxableIncomeDOC03(
              chargeVO.getTaxableIncomeDOC03().subtract(chargeVO.getTaxableIncomeDOC03().multiply(vo.getDiscountPercDOC01().divide(new BigDecimal(100),BigDecimal.ROUND_HALF_UP))).
              setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
            );
          }
        }

      }

      // retrieve header discounts..
      rowsResponse = rowsBean.loadSaleDocDiscounts(pars,serverLanguageId,username);
      if (rowsResponse.isError())
        throw new Exception(rowsResponse.getErrorMessage());
      java.util.List discounts = ((VOListResponse)rowsResponse).getRows();

      // apply header discounts to all taxable incomes...
      SaleDocDiscountVO discVO = null;
      for(int k=0;k<discounts.size();k++) {
        discVO = (SaleDocDiscountVO)discounts.get(k);
        if (discVO.getPercDOC05()!=null) {
          // the current discount is % discount...
          for(int i=0;i<detailItemRows.size();i++) {
            detailItemVO = (DetailSaleDocRowVO)detailItemRows.get(i);
            detailItemVO.setTaxableIncomeDOC02(
              detailItemVO.getTaxableIncomeDOC02().subtract(detailItemVO.getTaxableIncomeDOC02().multiply(discVO.getPercDOC05().divide(new BigDecimal(100),BigDecimal.ROUND_HALF_UP))).
              setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
            );
          }

          for(int i=0;i<actsRows.size();i++) {
            actVO = (SaleDocActivityVO)actsRows.get(i);
            actVO.setTaxableIncomeDOC13(
              actVO.getTaxableIncomeDOC13().subtract(actVO.getTaxableIncomeDOC13().multiply(discVO.getPercDOC05().divide(new BigDecimal(100),BigDecimal.ROUND_HALF_UP))).
              setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
            );
          }

          for(int i=0;i<chargesRows.size();i++) {
            chargeVO = (SaleDocChargeVO)chargesRows.get(i);
            if (chargeVO.getValueDOC03()!=null) {
              chargeVO.setTaxableIncomeDOC03(
                chargeVO.getTaxableIncomeDOC03().subtract(chargeVO.getTaxableIncomeDOC03().multiply(discVO.getPercDOC05().divide(new BigDecimal(100),BigDecimal.ROUND_HALF_UP))).
                setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
              );
            }
          }

        }
        else if (discVO.getValueDOC05()!=null) {
          // the current discount is a value discount...
          for(int i=0;i<detailItemRows.size();i++) {
            detailItemVO = (DetailSaleDocRowVO)detailItemRows.get(i);
            detailItemVO.setTaxableIncomeDOC02(
              detailItemVO.getTaxableIncomeDOC02().subtract(discVO.getValueDOC05().multiply((BigDecimal)coeff.get(detailItemVO))).
              setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
            );
          }

          for(int i=0;i<actsRows.size();i++) {
            actVO = (SaleDocActivityVO)actsRows.get(i);
            actVO.setTaxableIncomeDOC13(
              actVO.getTaxableIncomeDOC13().subtract(discVO.getValueDOC05().multiply((BigDecimal)coeff.get(actVO))).
              setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
            );
          }

          for(int i=0;i<chargesRows.size();i++) {
            chargeVO = (SaleDocChargeVO)chargesRows.get(i);
            if (chargeVO.getValueDOC03()!=null) {
              chargeVO.setTaxableIncomeDOC03(
                chargeVO.getTaxableIncomeDOC03().subtract(discVO.getValueDOC05().multiply((BigDecimal)coeff.get(chargeVO))).
                setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
              );
            }
          }

        }

      }

      // update vat values, item rows and calculate totals...
      Hashtable itemsTaxableIncomeRows = new Hashtable(); // collection of pairs <vatcode,TaxableIncomeVO>
      totalTaxableIncome = new BigDecimal(0);
      BigDecimal totalVat = new BigDecimal(0);
      String vatCode = null;
      String vatDescr = null;
      TaxableIncomeVO tVO = null;
      pstmt = conn.prepareStatement(
        "update DOC02_SELLING_ITEMS set TAXABLE_INCOME=?,VAT_VALUE=?,VALUE=?,TOTAL_DISCOUNT=?,LAST_UPDATE_USER=?,LAST_UPDATE_DATE=?  "+
        "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=? "
      );
      for(int i=0;i<detailItemRows.size();i++) {
        detailItemVO = (DetailSaleDocRowVO)detailItemRows.get(i);

        if (customerVatValue==null) {
          vatCode = detailItemVO.getVatCodeItm01DOC02();
          vatDescr = detailItemVO.getVatDescriptionDOC02();
          vatPerc = detailItemVO.getValueReg01DOC02().doubleValue()*(1d-detailItemVO.getDeductibleReg01DOC02().doubleValue()/100d)/100;
        }
        else {
          vatCode = customerVatCode;
          vatDescr = customerVatDescription;
          vatPerc = customerVatValue.doubleValue()/100d;
        }

        detailItemVO.setVatValueDOC02(detailItemVO.getTaxableIncomeDOC02().multiply(new BigDecimal(vatPerc)).setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP));
        detailItemVO.setValueDOC02(detailItemVO.getTaxableIncomeDOC02().add(detailItemVO.getVatValueDOC02()));

        totalTaxableIncome = totalTaxableIncome.add(detailItemVO.getTaxableIncomeDOC02());
        totalVat = totalVat.add(detailItemVO.getVatValueDOC02());

        tVO = (TaxableIncomeVO)itemsTaxableIncomeRows.get(vatCode);
        if (tVO==null) {
          tVO = new TaxableIncomeVO();
          tVO.setRowType(tVO.ITEM_ROW_TYPE);
          tVO.setVatCode(vatCode);
          tVO.setVatDescription(vatDescr);
          tVO.setVatValue(new BigDecimal(0));
          tVO.setTaxableIncome(new BigDecimal(0));
          itemsTaxableIncomeRows.put(vatCode,tVO);
        }
        tVO.setTaxableIncome(tVO.getTaxableIncome().add(detailItemVO.getTaxableIncomeDOC02()).setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP));
        tVO.setVatValue(tVO.getVatValue().add(detailItemVO.getVatValueDOC02()).setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP));

        pstmt.setBigDecimal(1,detailItemVO.getTaxableIncomeDOC02());
        pstmt.setBigDecimal(2,detailItemVO.getVatValueDOC02());
        pstmt.setBigDecimal(3,detailItemVO.getValueDOC02());
        pstmt.setBigDecimal(4,detailItemVO.getTotalDiscountDOC02());
        pstmt.setString(5,username);
        pstmt.setTimestamp(6,new java.sql.Timestamp(System.currentTimeMillis()));
        pstmt.setString(7,detailItemVO.getCompanyCodeSys01DOC02());
        pstmt.setString(8,detailItemVO.getDocTypeDOC02());
        pstmt.setBigDecimal(9,detailItemVO.getDocYearDOC02());
        pstmt.setBigDecimal(10,detailItemVO.getDocNumberDOC02());
        pstmt.setString(11,detailItemVO.getItemCodeItm01DOC02());

        pstmt.setString(12,detailItemVO.getVariantTypeItm06DOC02());
        pstmt.setString(13,detailItemVO.getVariantCodeItm11DOC02());
        pstmt.setString(14,detailItemVO.getVariantTypeItm07DOC02());
        pstmt.setString(15,detailItemVO.getVariantCodeItm12DOC02());
        pstmt.setString(16,detailItemVO.getVariantTypeItm08DOC02());
        pstmt.setString(17,detailItemVO.getVariantCodeItm13DOC02());
        pstmt.setString(18,detailItemVO.getVariantTypeItm09DOC02());
        pstmt.setString(19,detailItemVO.getVariantCodeItm14DOC02());
        pstmt.setString(20,detailItemVO.getVariantTypeItm10DOC02());
        pstmt.setString(21,detailItemVO.getVariantCodeItm15DOC02());

        pstmt.execute();
      }
      pstmt.close();

      // update vat values, activities rows and calculate totals...
      Hashtable actsTaxableIncomeRows = new Hashtable(); // collection of pairs <vatcode,TaxableIncomeVO>
      pstmt = conn.prepareStatement("update DOC13_SELLING_ACTIVITIES set TAXABLE_INCOME=?,VAT_VALUE=?,LAST_UPDATE_USER=?,LAST_UPDATE_DATE=?  where COMPANY_CODE_SYS01=? and DOC_TYPE=? and DOC_YEAR=? and DOC_NUMBER=? and ACTIVITY_CODE_SAL09=?");
      for(int i=0;i<actsRows.size();i++) {
        actVO = (SaleDocActivityVO)actsRows.get(i);

        if (customerVatValue==null) {
          vatCode = actVO.getVatCodeSal09DOC13();
          vatDescr = actVO.getVatDescriptionDOC13();
          vatPerc = actVO.getValueReg01DOC13().doubleValue()*(1d-actVO.getVatDeductibleDOC13().doubleValue()/100d)/100;
        }
        else {
          vatCode = customerVatCode;
          vatDescr = customerVatDescription;
          vatPerc = customerVatValue.doubleValue()/100d;
        }

        actVO.setVatValueDOC13(actVO.getTaxableIncomeDOC13().multiply(new BigDecimal(vatPerc)).setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP));

        totalTaxableIncome = totalTaxableIncome.add(actVO.getTaxableIncomeDOC13());
        totalVat = totalVat.add(actVO.getVatValueDOC13());

        tVO = (TaxableIncomeVO)actsTaxableIncomeRows.get(vatCode);
        if (tVO==null) {
          tVO = new TaxableIncomeVO();
          tVO.setRowType(tVO.ACTIVITY_ROW_TYPE);
          tVO.setVatCode(vatCode);
          tVO.setVatDescription(vatDescr);
          tVO.setVatValue(new BigDecimal(0));
          tVO.setTaxableIncome(new BigDecimal(0));
          actsTaxableIncomeRows.put(vatCode,tVO);
        }
        tVO.setTaxableIncome(tVO.getTaxableIncome().add(actVO.getTaxableIncomeDOC13()).setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP));
        tVO.setVatValue(tVO.getVatValue().add(actVO.getVatValueDOC13()).setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP));

        pstmt.setBigDecimal(1,actVO.getTaxableIncomeDOC13());
        pstmt.setBigDecimal(2,actVO.getVatValueDOC13());
        pstmt.setString(3,username);
        pstmt.setTimestamp(4,new java.sql.Timestamp(System.currentTimeMillis()));
        pstmt.setString(5,actVO.getCompanyCodeSys01DOC13());
        pstmt.setString(6,actVO.getDocTypeDOC13());
        pstmt.setBigDecimal(7,actVO.getDocYearDOC13());
        pstmt.setBigDecimal(8,actVO.getDocNumberDOC13());
        pstmt.setString(9,actVO.getActivityCodeSal09DOC13());
        pstmt.execute();
      }
      pstmt.close();

      // update vat values, value charges rows and calculate totals...
      Hashtable chargesTaxableIncomeRows = new Hashtable(); // collection of pairs <vatcode,TaxableIncomeVO>
      pstmt = conn.prepareStatement("update DOC03_SELLING_CHARGES set TAXABLE_INCOME=?,VAT_VALUE=?,LAST_UPDATE_USER=?,LAST_UPDATE_DATE=?  where COMPANY_CODE_SYS01=? and DOC_TYPE=? and DOC_YEAR=? and DOC_NUMBER=? and CHARGE_CODE_SAL06=?");
      for(int i=0;i<chargesRows.size();i++) {
        chargeVO = (SaleDocChargeVO)chargesRows.get(i);
        if (chargeVO.getValueDOC03()!=null) {
          if (customerVatValue==null) {
            vatCode = chargeVO.getVatCodeSal06DOC03();
            vatDescr = chargeVO.getVatDescriptionDOC03();
            vatPerc = chargeVO.getValueReg01DOC03().doubleValue()*(1d-chargeVO.getVatDeductibleDOC03().doubleValue()/100d)/100;
          }
          else {
            vatCode = customerVatCode;
            vatDescr = customerVatDescription;
            vatPerc = customerVatValue.doubleValue()/100d;
          }

          chargeVO.setVatValueDOC03(chargeVO.getTaxableIncomeDOC03().multiply(new BigDecimal(vatPerc)).setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP));

          totalTaxableIncome = totalTaxableIncome.add(chargeVO.getTaxableIncomeDOC03());
          totalVat = totalVat.add(chargeVO.getVatValueDOC03());

          tVO = (TaxableIncomeVO)chargesTaxableIncomeRows.get(vatCode);
          if (tVO==null) {
            tVO = new TaxableIncomeVO();
            tVO.setRowType(tVO.CHARGE_ROW_TYPE);
            tVO.setVatCode(vatCode);
            tVO.setVatDescription(vatDescr);
            tVO.setVatValue(new BigDecimal(0));
            tVO.setTaxableIncome(new BigDecimal(0));
            chargesTaxableIncomeRows.put(vatCode,tVO);
          }
          tVO.setTaxableIncome(tVO.getTaxableIncome().add(chargeVO.getTaxableIncomeDOC03()).setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP));
          tVO.setVatValue(tVO.getVatValue().add(chargeVO.getVatValueDOC03()).setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP));

          pstmt.setBigDecimal(1,chargeVO.getTaxableIncomeDOC03());
          pstmt.setBigDecimal(2,chargeVO.getVatValueDOC03());
          pstmt.setString(3,username);
          pstmt.setTimestamp(4,new java.sql.Timestamp(System.currentTimeMillis()));
          pstmt.setString(5,chargeVO.getCompanyCodeSys01DOC03());
          pstmt.setString(6,chargeVO.getDocTypeDOC03());
          pstmt.setBigDecimal(7,chargeVO.getDocYearDOC03());
          pstmt.setBigDecimal(8,chargeVO.getDocNumberDOC03());
          pstmt.setString(9,chargeVO.getChargeCodeSal06DOC03());
          pstmt.execute();
        }
      }
      pstmt.close();


      // update document totals..
      pstmt = conn.prepareStatement(
        "update DOC01_SELLING set TAXABLE_INCOME=?,TOTAL_VAT=?,TOTAL=?,LAST_UPDATE_USER=?,LAST_UPDATE_DATE=?  "+
        "where COMPANY_CODE_SYS01=? and DOC_TYPE=? and DOC_YEAR=? and DOC_NUMBER=? and "+
        "TAXABLE_INCOME=? and TOTAL_VAT=? and TOTAL=?"
      );

      BigDecimal total =
        totalTaxableIncome.
        add(totalVat).
        subtract(vo.getAllowanceDOC01()).
        subtract(vo.getDepositDOC01()).
        setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP);

      pstmt.setBigDecimal(1,totalTaxableIncome);
      pstmt.setBigDecimal(2,totalVat);
      pstmt.setBigDecimal(3,total);
      pstmt.setString(4,username);
      pstmt.setTimestamp(5,new java.sql.Timestamp(System.currentTimeMillis()));
      pstmt.setString(6,vo.getCompanyCodeSys01DOC01());
      pstmt.setString(7,vo.getDocTypeDOC01());
      pstmt.setBigDecimal(8,vo.getDocYearDOC01());
      pstmt.setBigDecimal(9,vo.getDocNumberDOC01());
      pstmt.setBigDecimal(10,vo.getTaxableIncomeDOC01());
      pstmt.setBigDecimal(11,vo.getTotalVatDOC01());
      pstmt.setBigDecimal(12,vo.getTotalDOC01());
      int updatedRows = pstmt.executeUpdate();
      if (updatedRows==0)
        return new VOListResponse("record already updated");


View Full Code Here

   * Callback method called when the Form mode is changed.
   * @param currentMode current Form mode
   */
  public void modeChanged(int currentMode) {
    if (currentMode==Consts.INSERT) {
      DetailSaleDocVO vo = (DetailSaleDocVO)frame.getHeaderFormPanel().getVOModel().getValueObject();
      if (vo.getWarehouseCodeWar01DOC01()!=null)
        frame.getWarePanel().getWareController().forceValidate();
    }
  }
View Full Code Here

   * @return an ErrorResponse value object in case of errors, VOResponse if the operation is successfully completed
   */
  public Response insertRecord(ValueObject newPersistentObject) throws Exception {
    Response res = ClientUtils.getData("createInvoiceFromSaleDoc",newPersistentObject);
    if (!res.isError()) {
      DetailSaleDocVO vo = (DetailSaleDocVO)((VOResponse)res).getVo();
      pk = new SaleDocPK(
          vo.getCompanyCodeSys01DOC01(),
          vo.getDocTypeDOC01(),
          vo.getDocYearDOC01(),
          vo.getDocNumberDOC01()
      );

    }
    return res;
  }
View Full Code Here

  public void afterInsertData() {
    if (parentFrame!=null) {
      parentFrame.getGrid().reloadData();
    }

    DetailSaleDocVO vo = (DetailSaleDocVO)frame.getHeaderFormPanel().getVOModel().getValueObject();
    frame.getRowsPanel().setParentVO(vo);
    frame.getRowsPanel().getGrid().getOtherGridParams().put(ApplicationConsts.SALE_DOC_PK,pk);
    frame.getRowsPanel().getGrid().reloadData();

    frame.getDiscPanel().setParentVO(vo);
View Full Code Here

   * @param persistentObject value object to delete
   * @return an ErrorResponse value object in case of errors, VOResponse if the operation is successfully completed
   */
  public Response deleteRecord(ValueObject persistentObject) throws Exception {
    ArrayList pks = new ArrayList();
    DetailSaleDocVO vo = (DetailSaleDocVO)persistentObject;

    pks.add(pk);
    Response res = ClientUtils.getData("deleteSaleDocs",pks);
    if (!res.isError()) {
      if (parentFrame!=null) {
View Full Code Here

   * Callback method called by the Form panel when the Form is set to INSERT mode.
   * The method can pre-set some v.o. attributes, so that some input controls will have a predefined value associated.
   * @param persistentObject new value object
   */
  public void createPersistentObject(ValueObject persistentObject) throws Exception {
    DetailSaleDocVO vo = (DetailSaleDocVO)persistentObject;
    Calendar cal = Calendar.getInstance();
    vo.setDocYearDOC01(new BigDecimal(cal.get(cal.YEAR)));
    vo.setDocDateDOC01(new java.sql.Date(System.currentTimeMillis()));
    vo.setDocTypeDOC01(ApplicationConsts.SALE_INVOICE_FROM_SD_DOC_TYPE);
    vo.setDocStateDOC01(ApplicationConsts.OPENED);


  }
View Full Code Here

   * @return <code>true</code> allows to go to EDIT mode, <code>false</code> the mode change is interrupted
   */
  public boolean beforeEditData(Form form) {
    if (!super.beforeEditData(form))
      return false;
    DetailSaleDocVO vo = (DetailSaleDocVO)frame.getHeaderFormPanel().getVOModel().getValueObject();
    return !vo.getDocStateDOC01().equals(ApplicationConsts.CLOSED);
  }
View Full Code Here

   * @return <code>true</code> allows the deleting to continue, <code>false</code> the deleting is interrupted
   */
  public boolean beforeDeleteData(Form form) {
    if (!super.beforeDeleteData(form))
      return false;
    DetailSaleDocVO vo = (DetailSaleDocVO)frame.getHeaderFormPanel().getVOModel().getValueObject();
    return !vo.getDocStateDOC01().equals(ApplicationConsts.CLOSED);
  }
View Full Code Here

TOP

Related Classes of org.jallinone.sales.documents.java.DetailSaleDocVO

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.