Package org.openbravo.database

Examples of org.openbravo.database.ConnectionProvider


  protected OBError doIt(VariablesSecureApp vars) throws ServletException {
    int no = 0;
    OBError myError = new OBError();

    ConnectionProvider conn = null;
    Connection con = null;
    String strcTaxcategoryId = null;
    try {
      conn = getConnection();
      con = conn.getTransactionConnection();
      if (m_deleteOldImported) {
        no = ImportProductData.deleteOld(con, conn, getAD_Client_ID());
        if (log4j.isDebugEnabled())
          log4j.debug("Delete Old Imported = " + no);
      }
      // Set Client, Org, IaActive, Created/Updated, ProductType
      no = ImportProductData.updateRecords(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Reset = " + no);

      // Set Optional BPartner
      no = ImportProductData.updateBPartner(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct BPartner = " + no);

      //
      no = ImportProductData.updateBPartnerError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Invalid BPartner = " + no);

      // EAN/UPC
      no = ImportProductData.updateProductByUPC(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Product Existing UPC = " + no);

      // Value
      no = ImportProductData.updateProductByValue(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Product Existing Value = " + no);

      // BP ProdNo
      no = ImportProductData.updateProductByVendor(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Product Existing Vendor ProductNo = " + no);

      // Copy From Product if Import does not have value
      String[] strFields = new String[] { "Value", "Name", "Description", "DocumentNote", "Help",
          "UPC", "SKU", "Classification", "ProductType", "Discontinued", "DiscontinuedBy",
          "ImageURL", "DescriptionURL" };
      for (int i = 0; i < strFields.length; i++) {
        no = ImportProductData.updateProductField(con, conn, strFields[i], getAD_Client_ID());
        if (log4j.isDebugEnabled())
          log4j.debug("ImportProduct" + strFields[i] + " Default from existing Product=" + no);
      }
      String[] numFields = new String[] { "C_UOM_ID", "M_Product_Category_ID", "Volume", "Weight",
          "ShelfWidth", "ShelfHeight", "ShelfDepth", "UnitsPerPallet" };
      for (int i = 0; i < numFields.length; i++) {
        no = ImportProductData.updateProductNumField(con, conn, numFields[i], getAD_Client_ID());
        if (log4j.isDebugEnabled())
          log4j.debug("ImportProduct" + numFields[i] + " Default from existing Product=" + no);
      }

      // Copy From Product_PO if Import does not have value
      String[] strFieldsPO = new String[] { "UPC", "PriceEffective", "VendorProductNo",
          "VendorCategory", "Manufacturer", "Discontinued", "DiscontinuedBy" };
      for (int i = 0; i < strFieldsPO.length; i++) {
        no = ImportProductData.updateProductFieldPO(con, conn, strFieldsPO[i], getAD_Client_ID());
        if (no != 0)
          if (log4j.isDebugEnabled())
            log4j.debug("ImportProduct" + strFieldsPO[i] + " Default from existing Product=" + no);
      }
      String[] numFieldsPO = new String[] { "C_UOM_ID", "C_Currency_ID", "PriceList", "PricePO",
          "RoyaltyAmt", "Order_Min", "Order_Pack", "CostPerOrder", "DeliveryTime_Promised" };
      for (int i = 0; i < numFieldsPO.length; i++) {
        no = ImportProductData
            .updateProductNumFieldPO(con, conn, numFieldsPO[i], getAD_Client_ID());
        if (no != 0)
          if (log4j.isDebugEnabled())
            log4j.debug("ImportProduct" + numFieldsPO[i] + " Default from existing Product=" + no);
      }

      // Set UOM (System/own)
      no = ImportProductData.updateX12DE355(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Set UOM Default=" + no);
      //
      no = ImportProductData.updateProductUOM(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Set UOM =" + no);
      //
      no = ImportProductData.updateProductInvalidUOM(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Invalid UOM =" + no);

      // Set Product Logger (own)
      no = ImportProductData.updateProductCategoryDefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Set Product Category Default =" + no);
      //
      no = ImportProductData.updateProductCategory(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Set Product Category =" + no);
      //
      no = ImportProductData.updateInvalidCategory(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Invalid Product Category =" + no);

      // Set Currency
      no = ImportProductData.updateCurrencyDefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Set Currency Default =" + no);
      //
      no = ImportProductData.updateCurrency(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Set Currency =" + no);
      //
      no = ImportProductData.updateInvalidCurrency(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Invalid Currency =" + no);

      // Verify ProductType
      no = ImportProductData.updateInvalidProductType(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Invalid ProductType =" + no);

      // Unique UPC/Value
      no = ImportProductData.updateNotUniqueValue(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Not Unique Value =" + no);
      //
      no = ImportProductData.updateNotUniqueUPC(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Not Unique UPC =" + no);

      // Mandatory Value
      no = ImportProductData.updateNoMandatoryValue(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct No Mandatory Value =" + no);

      // Vendor Product No
      no = ImportProductData.updateVendorProductNoSetToValue(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct VendorProductNo Set to Value =" + no);
      //
      no = ImportProductData.updateNotUniqueVendorProductNo(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct Not Unique VendorProductNo =" + no);

      // Get Default Tax Category
      strcTaxcategoryId = ImportProductData.selectTaxCategory(conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportProduct C_TaxCategory_ID =" + strcTaxcategoryId);
      conn.releaseCommitConnection(con);
      if (strcTaxcategoryId == null || strcTaxcategoryId.equals("")) {
        // Default Tax category doesn't exist
        addLog(Utility.messageBD(conn, "MarkDefaultTaxCategory", vars.getLanguage()));
        myError.setType("Error");
        myError.setTitle(Utility.messageBD(conn, "Error", vars.getLanguage()));
        myError.setMessage(Utility.messageBD(conn, "MarkDefaultTaxCategory", vars.getLanguage()));
        return myError;
      }

    } catch (Exception se) {
      try {
        conn.releaseRollbackConnection(con);
      } catch (Exception ignored) {
      }
      se.printStackTrace();
      addLog(Utility.messageBD(conn, "ProcessRunError", vars.getLanguage()));
      myError.setType("Error");
      myError.setTitle(Utility.messageBD(conn, "Error", vars.getLanguage()));
      myError.setMessage(Utility.messageBD(conn, "ProcessRunError", vars.getLanguage()));
      return myError;
    }
    // till here, the edition of the I_ImportProduct table
    // now, the insertion from I_ImportProduct table in M_Product,
    // M_Product_PO...

    int noInsert = 0;
    int noUpdate = 0;
    int noInsertPO = 0;
    int noUpdatePO = 0;
    int noProductError = 0;

    try {
      // Go through Records
      ImportProductData[] data = ImportProductData.selectRecords(conn, getAD_Client_ID());
      for (int i = 0; i < data.length; i++) {
        String I_Product_ID = data[i].iProductId;
        String M_Product_ID = data[i].mProductId;
        String C_BPartner_ID = data[i].cBpartnerId;
        con = conn.getTransactionConnection();
        boolean newProduct = M_Product_ID.equals("");
        // Product
        if (newProduct) { // Insert new Product
          M_Product_ID = SequenceIdData.getUUID();
          try {
            if (log4j.isDebugEnabled())
              log4j.debug("before insert");
            no = ImportProductData.insertProductImport(con, conn, M_Product_ID, strcTaxcategoryId,
                I_Product_ID);
            if (log4j.isDebugEnabled())
              log4j.debug("Insert Product = " + no);
            noInsert++;
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Insert Product - " + ex.toString());
            conn.releaseRollbackConnection(con);
            ImportProductData.insertProductError(conn, ex.toString(), I_Product_ID);
            continue;
          }
        } else { // Update Product
          try {
            no = ImportProductData.updateProductImport(con, conn, I_Product_ID, M_Product_ID);
            if (log4j.isDebugEnabled())
              log4j.debug("Update Product = " + no);
            noUpdate++;
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Update Product - " + ex.toString());
            conn.releaseRollbackConnection(con);
            ImportProductData.updateProductError(conn, ex.toString(), I_Product_ID);
            continue;
          }
        }
        // Do we have PO Info
        if (!C_BPartner_ID.equals("")) {
          no = 0;
          // If Product existed, Try to Update first
          if (!newProduct) {
            try {
              no = ImportProductData.updateProductPOImport(con, conn, I_Product_ID, M_Product_ID,
                  C_BPartner_ID);
              if (log4j.isDebugEnabled())
                log4j.debug("Update Product_PO = " + no);
              noUpdatePO++;
            } catch (ServletException ex) {
              if (log4j.isDebugEnabled())
                log4j.debug("Update Product_PO - " + ex.toString());
              noUpdate--;
              conn.releaseRollbackConnection(con);
              ImportProductData.updateProductPOError(conn, ex.toString(), I_Product_ID);
              continue;
            }
          }
          try {
            if (no == 0) { // Insert PO
              no = ImportProductData.insertProductPOImport(con, conn, M_Product_ID, C_BPartner_ID,
                  I_Product_ID);
              if (log4j.isDebugEnabled())
                log4j.debug("Insert Product_PO = " + no);
              noInsertPO++;
            }
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Insert Product_PO - " + ex.toString());
            noInsert--; // assume that product also did not exist
            ImportProductData.insertProductPOError(conn, ex.toString(), I_Product_ID);
            conn.releaseRollbackConnection(con);
            continue;
          }
        } // C_BPartner_ID != 0
        conn.releaseCommitConnection(con);
        // Update I_Product
        if (log4j.isDebugEnabled())
          log4j.debug("before update: " + M_Product_ID + " -- " + I_Product_ID);
        no = ImportProductData.updateProductSetImportY(conn, M_Product_ID, I_Product_ID);
        if (log4j.isDebugEnabled())
View Full Code Here


      log4j.debug("Creating parameters");
  }

  protected OBError doIt(VariablesSecureApp vars) throws ServletException {
    int no = 0;
    ConnectionProvider conn = null;
    Connection con = null;
    OBError myError = new OBError();

    try {
      conn = getConnection();
      con = conn.getTransactionConnection();
      // Delete imported
      if (m_deleteOldImported) {
        no = ImportBPartnerData.deleteOld(con, conn, getAD_Client_ID());
        if (log4j.isDebugEnabled())
          log4j.debug("Delete Old Imported = " + no);
      }
      // Set Client, Org, IaActive, Created/Updated, ProductType
      no = ImportBPartnerData.updateRecords(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBPartner Reset = " + no);

      // Set BPGroup
      no = ImportBPartnerData.updateBPGroupDefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBPartner BPGroup = " + no);
      no = ImportBPartnerData.updateBPGroupId(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBPartner BPGroupId = " + no);
      no = ImportBPartnerData.updateGroupError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid BPartner group = " + no);

      // Country
      no = ImportBPartnerData.updateCountryCodeDefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBPartner CountryCode = " + no);
      no = ImportBPartnerData.updateCountryId(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBPartner CountryId = " + no);
      no = ImportBPartnerData.updateCountryError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Country = " + no);

      // Region
      no = ImportBPartnerData.updateRegionDefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBPartner Region = " + no);
      no = ImportBPartnerData.updateRegionId(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBPartner RegionId = " + no);
      no = ImportBPartnerData.updateRegionError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Region = " + no);

      // Greeting
      no = ImportBPartnerData.updateGreetingId(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBPartner GreetingId = " + no);
      no = ImportBPartnerData.updateGreetingError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Greeting = " + no);

      // BPartner
      no = ImportBPartnerData.updateBPartnerId(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBPartner BPartnerId = " + no);

      // ADUser
      no = ImportBPartnerData.updateADUserId(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBPartner ADUserId = " + no);

      // Location
      no = ImportBPartnerData.updateLocationId(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBPartner LocationId = " + no);

      conn.releaseCommitConnection(con);
    } catch (Exception se) {
      try {
        conn.releaseRollbackConnection(con);
      } catch (Exception ignored) {
      }
      se.printStackTrace();
      addLog(Utility.messageBD(conn, "ProcessRunError", vars.getLanguage()));
      myError.setType("Error");
      myError.setTitle(Utility.messageBD(conn, "Error", vars.getLanguage()));
      myError.setMessage(Utility.messageBD(conn, "ProcessRunError", vars.getLanguage()));
      return myError;
    }

    // till here, the edition of the I_BPARTNER table
    // now, the insertion from I_BPARTNER table in C_BPartner...

    int noInsert = 0;
    int noUpdate = 0;
    int noBPartnerError = 0;

    try {
      // Go through Records
      ImportBPartnerData[] data = ImportBPartnerData.select(conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Going through " + data.length + " records");
      for (int i = 0; i < data.length; i++) {
        String I_BPartner_ID = data[i].iBpartnerId;
        String C_BPartner_ID = data[i].cBpartnerId;
        boolean newBPartner = (C_BPartner_ID == null || C_BPartner_ID.equals(""));
        String C_BPartner_Location_ID = data[i].cBpartnerLocationId;
        boolean newLocation = data[i].addr != null;
        String AD_User_ID = data[i].adUserId;
        boolean newContact = data[i].contactname != null;

        con = conn.getTransactionConnection();

        // create/update BPartner
        if (newBPartner) { // Insert new BPartner
          C_BPartner_ID = SequenceIdData.getUUID();
          try {
            no = ImportBPartnerData.insertBPartner(con, conn, C_BPartner_ID, I_BPartner_ID);
            if (log4j.isDebugEnabled())
              log4j.debug("Insert BPartner = " + no);
            noInsert++;
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Insert BPartner - " + ex.toString());
            conn.releaseRollbackConnection(con);
            no = ImportBPartnerData.insertBPartnerError(conn, ex.toString(), I_BPartner_ID);
            continue;
          }
        } else { // Update existing BPartner
          try {
            no = ImportBPartnerData.updateBPartner(con, conn, I_BPartner_ID, C_BPartner_ID);
            if (log4j.isDebugEnabled())
              log4j.debug("Update BPartner = " + no);
            noUpdate++;
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Update BPartner - " + ex.toString());
            conn.releaseRollbackConnection(con);
            no = ImportBPartnerData.updateBPartnerError(conn, ex.toString(), I_BPartner_ID);
            continue;
          }
        }

        // create/update BPartner Location
        if (!C_BPartner_Location_ID.equals("")) { // Update Location
        } else if (newLocation) { // New Location
          String C_Location_ID = SequenceIdData.getUUID();
          try {
            no = ImportBPartnerData.insertLocation(con, conn, C_Location_ID, I_BPartner_ID);
            if (log4j.isDebugEnabled())
              log4j.debug("Insert Location = " + no);
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Insert Location - " + ex.toString());
            noInsert--;
            conn.releaseRollbackConnection(con);
            no = ImportBPartnerData.insertLocationError(conn, ex.toString(), I_BPartner_ID);
            continue;
          }
          C_BPartner_Location_ID = SequenceIdData.getUUID();
          try {
            String locationName = parseAddressName(data[i]);

            no = ImportBPartnerData.insertBPLocation(con, conn, C_BPartner_Location_ID,
                locationName, C_BPartner_ID, C_Location_ID, I_BPartner_ID);
            if (log4j.isDebugEnabled())
              log4j.debug("Insert BP Location = " + no);
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Insert BP Location - " + ex.toString());
            noInsert--;
            conn.releaseRollbackConnection(con);
            no = ImportBPartnerData.insertBPLocationError(conn, ex.toString(), I_BPartner_ID);
            continue;
          }
        }

        // Create/Update Contact
        if (!AD_User_ID.equals("")) {
          try {
            // Update existing contact
            no = ImportBPartnerData.updateBPContact(con, conn, I_BPartner_ID, AD_User_ID);
            if (log4j.isDebugEnabled())
              log4j.debug("Update BP Contact = " + no);
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Update BP Contact - " + ex.toString());
            noUpdate--;
            conn.releaseRollbackConnection(con);
            no = ImportBPartnerData.updateBPContactError(conn, ex.toString(), I_BPartner_ID);
            continue;
          }
        } else if (newContact) { // New Contact
          AD_User_ID = SequenceIdData.getUUID();
          try {
            if (data[i].contactname != null && !data[i].contactname.equals("")) {
              no = ImportBPartnerData.insertBPContact(con, conn, AD_User_ID, C_BPartner_ID,
                  (C_BPartner_Location_ID.equals("0")) ? "NULL" : C_BPartner_Location_ID,
                  I_BPartner_ID);
              if (log4j.isDebugEnabled())
                log4j.debug("Insert BP Contact = " + no);
            } else {
              AD_User_ID = "0";
            }
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Insert BP Contact - " + ex.toString());
            noInsert--;
            conn.releaseRollbackConnection(con);
            no = ImportBPartnerData.insertBPContactError(conn, ex.toString(), I_BPartner_ID);
            continue;
          }
        }

        // Update I_BPARTNER
        try {
          no = ImportBPartnerData.setImported(con, conn, C_BPartner_ID, (C_BPartner_Location_ID
              .equals("0")) ? "" : C_BPartner_Location_ID, (AD_User_ID.equals("0")) ? ""
              : AD_User_ID, I_BPartner_ID);
          conn.releaseCommitConnection(con);
        } catch (ServletException ex) {
          if (log4j.isDebugEnabled())
            log4j.debug("Update Imported - " + ex.toString());
          noInsert--;
          conn.releaseRollbackConnection(con);
          no = ImportBPartnerData.updateSetImportedError(conn, ex.toString(), I_BPartner_ID);
          continue;
        }
      }

      // Set Error to indicator to not imported
      noBPartnerError = ImportBPartnerData.updateNotImported(conn, getAD_Client_ID());
    } catch (Exception se) {
      se.printStackTrace();
      addLog(Utility.messageBD(conn, "ProcessRunError", vars.getLanguage()));
      myError.setType("Error");
      myError.setTitle(Utility.messageBD(conn, "Error", vars.getLanguage()));
      myError.setMessage(Utility.messageBD(conn, "ProcessRunError", vars.getLanguage()));
      try {
        conn.releaseCommitConnection(con);
      } catch (Exception e) {
      }
      return myError;
    }
    addLog(Utility.messageBD(conn, "Business partners not imported", vars.getLanguage()) + ": "
View Full Code Here

      log4j.debug("Creating parameters");
  }

  protected OBError doIt(VariablesSecureApp vars) throws ServletException {
    int no = 0;
    ConnectionProvider conn = null;
    Connection con = null;
    OBError myError = new OBError();

    try {
      conn = getConnection();
      con = conn.getTransactionConnection();
      if (m_deleteOldImported) {
        no = ImportTaxData.deleteOld(con, conn, getAD_Client_ID());
        if (log4j.isDebugEnabled())
          log4j.debug("Delete Old Imported = " + no);
      }
      // Set Client, Org, IaActive, Created/Updated
      no = ImportTaxData.updateRecords(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Reset = " + no);

      /*
       * This cannot be done like this, because it can be referred by data inside the file, it has
       * to be done line per line // Tax Category ID no = ImportTaxData.updateTaxCategoryId(con,
       * conn, getAD_Client_ID()); if (log4j.isDebugEnabled()) log4j.debug("Tax Category Id = " +
       * no);
       *
       * // BP Tax Category ID no = ImportTaxData.updateBPTaxCategoryId(con, conn,
       * getAD_Client_ID()); if (log4j.isDebugEnabled()) log4j.debug("BP Tax Category Id = " + no);
       *
       * // Tax ID no = ImportTaxData.updateTaxId(con, conn, getAD_Client_ID()); if
       * (log4j.isDebugEnabled()) log4j.debug("BP Tax Category Id = " + no);
       */

      // Set Country From
      no = ImportTaxData.updateCountryFromId(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Set Country From =" + no);

      no = ImportTaxData.updateCountryFromError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Country From =" + no);

      // Set Country To
      no = ImportTaxData.updateCountryToId(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Set Country to =" + no);

      no = ImportTaxData.updateCountryToError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Country to =" + no);

      // Set Region From
      no = ImportTaxData.updateRegionFromId(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Set Region From =" + no);

      no = ImportTaxData.updateRegionFromError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Region From =" + no);

      // Set Region From
      no = ImportTaxData.updateRegionToId(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Set Region To =" + no);

      no = ImportTaxData.updateRegionToError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Region To =" + no);

      //

      conn.releaseCommitConnection(con);
    } catch (Exception se) {
      try {
        conn.releaseRollbackConnection(con);
      } catch (Exception ignored) {
      }
      se.printStackTrace();
      addLog(Utility.messageBD(conn, "ProcessRunError", vars.getLanguage()));
      myError.setType("Error");
      myError.setTitle(Utility.messageBD(conn, "Error", vars.getLanguage()));
      myError.setMessage(Utility.messageBD(conn, "ProcessRunError", vars.getLanguage()));
      return myError;
    }

    // till here, the edition of the I_ImportBPartner table
    // now, the insertion from I_ImportBPartner table in C_BPartner...

    int noTaxInsert = 0;
    int noTaxUpdate = 0;
    int noTCInsert = 0;
    int noTCUpdate = 0;
    int noBPTCInsert = 0;
    int noBPTCUpdate = 0;
    int noTaxError = 0;

    try {
      // Go through Records
      ImportTaxData[] data = ImportTaxData.select(conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Going through " + data.length + " records");
      for (int i = 0; i < data.length; i++) {
        String I_Tax_ID = data[i].iTaxId;
        String C_TaxCategory_ID = data[i].cTaxcategoryId;
        String C_BPTaxCategory_ID = data[i].cBpTaxcategoryId;
        String C_Tax_ID = data[i].cTaxId;
        String ParentTax_ID = data[i].parentTaxId;
        boolean newTaxCategory = (C_TaxCategory_ID == null || C_TaxCategory_ID.equals(""));
        boolean newBPTaxCategory = (C_BPTaxCategory_ID == null || C_BPTaxCategory_ID.equals(""));
        boolean newTax = (C_Tax_ID == null || C_Tax_ID.equals(""));
        con = conn.getTransactionConnection();

        // create/update TaxCategory
        if (!data[i].tcName.equals("") || !newTaxCategory) { // Inserting
          // taxes
          // this
          // shouldn't
          // be null,
          // but it
          // can be
          // if
          // inserting
          // only BP
          // Tax Cat
          if (newTaxCategory)
            C_TaxCategory_ID = ImportTaxData.selectTaxCategoryId(conn, data[i].tcName,
                getAD_Client_ID());
          newTaxCategory = (C_TaxCategory_ID == null || C_TaxCategory_ID.equals(""));
          if (log4j.isDebugEnabled())
            log4j.debug("TCId: " + C_TaxCategory_ID);
          if (newTaxCategory) { // Insert new TaxCategory
            C_TaxCategory_ID = SequenceIdData.getUUID();
            try {
              no = ImportTaxData.insertTaxCategory(con, conn, C_TaxCategory_ID, I_Tax_ID);
              if (log4j.isDebugEnabled())
                log4j.debug("Insert TaxCategory = " + no);
              noTCInsert++;
            } catch (ServletException ex) {
              String err = "Insert TaxCategory - " + ex.toString();
              if (log4j.isDebugEnabled())
                log4j.debug(err);
              no = ImportTaxData.taxError(conn, err, I_Tax_ID);
              try {
                conn.releaseRollbackConnection(con);
              } catch (Exception ignored) {
              }
              continue;
            }
          } else { // Update existing TaxCategory
            try {
              no = ImportTaxData.updateTaxCategory(con, conn, I_Tax_ID, C_TaxCategory_ID);
              if (log4j.isDebugEnabled())
                log4j.debug("Update TaxCategory = " + no);
              noTCUpdate++;
            } catch (ServletException ex) {
              String err = "Update TaxCategory - " + ex.toString();
              if (log4j.isDebugEnabled())
                log4j.debug(err);
              no = ImportTaxData.taxError(conn, err, I_Tax_ID);
              try {
                conn.releaseRollbackConnection(con);
              } catch (Exception ignored) {
              }
              continue;
            }
          }
        }

        // create/update BPTaxCategory
        if (!data[i].bptcName.equals("") || !newBPTaxCategory) {
          if (newBPTaxCategory)
            C_BPTaxCategory_ID = ImportTaxData.selectBPTaxCategoryId(conn, data[i].bptcName,
                getAD_Client_ID());
          newBPTaxCategory = (C_BPTaxCategory_ID == null || C_BPTaxCategory_ID.equals(""));
          if (newBPTaxCategory) { // Insert new BPTaxCategory
            C_BPTaxCategory_ID = SequenceIdData.getUUID();
            try {
              no = ImportTaxData.insertBPTaxCategory(con, conn, C_BPTaxCategory_ID, I_Tax_ID);
              if (log4j.isDebugEnabled())
                log4j.debug("Insert BPTaxCategory = " + no);
              noBPTCInsert++;
            } catch (ServletException ex) {
              String err = "Insert BPTaxCategory - " + ex.toString();
              if (log4j.isDebugEnabled())
                log4j.debug(err);
              no = ImportTaxData.taxError(conn, err, I_Tax_ID);
              try {
                conn.releaseRollbackConnection(con);
              } catch (Exception ignored) {
              }
              continue;
            }
          } else { // Update existing BPTaxCategory
            try {
              no = ImportTaxData.updateBPTaxCategory(con, conn, I_Tax_ID, C_BPTaxCategory_ID);
              if (log4j.isDebugEnabled())
                log4j.debug("Update BPTaxCategory = " + no);
              noBPTCUpdate++;
            } catch (ServletException ex) {
              String err = "Update BPTaxCategory - " + ex.toString();
              if (log4j.isDebugEnabled())
                log4j.debug(err);
              no = ImportTaxData.taxError(conn, err, I_Tax_ID);
              try {
                conn.releaseRollbackConnection(con);
              } catch (Exception ignored) {
              }
              continue;
            }
          }
        }

        if (!data[i].tName.equals("") || !newTax) { // Update Create Tax
          if (log4j.isDebugEnabled())
            log4j.debug("Tax:" + data[i].tName);

          if (!data[i].parentName.equals("")) { // Parent tax
            ParentTax_ID = ImportTaxData.selectTaxId(conn, "", data[i].parentName,
                getAD_Client_ID()); // Check
            // if
            // parent
            // tax
            // is
            // created,
            // if
            // not
            // create
            // with
            // default
            // values
            if (ParentTax_ID == null || ParentTax_ID.equals("")) { // Insert
              // parent
              // tax
              try {
                ParentTax_ID = SequenceIdData.getUUID();
                if (log4j.isDebugEnabled())
                  log4j.debug("Insert Parent Tax = " + no);
                no = ImportTaxData.insertDefaultTax(con, conn, ParentTax_ID, C_TaxCategory_ID,
                    I_Tax_ID);
                noTaxInsert++;
              } catch (ServletException ex) {
                String err = "Insert Parent Tax - " + ex.toString();
                if (log4j.isDebugEnabled())
                  log4j.debug(err);
                no = ImportTaxData.taxError(conn, err, I_Tax_ID);
                try {
                  conn.releaseRollbackConnection(con);
                } catch (Exception ignored) {
                }
                continue;
              }
            }
          }

          if (newTax)
            C_Tax_ID = ImportTaxData.selectTaxId(conn, data[i].parentName, data[i].tName,
                getAD_Client_ID()); // look for existing taxes
          // (a tax is unique by name
          // and parent)
          newTax = (C_Tax_ID == null || C_Tax_ID.equals(""));
          if (log4j.isDebugEnabled())
            log4j.debug("Tax:" + data[i].tName + " - new:" + newTax);
          if (newTax) { // Insert new Tax
            C_Tax_ID = SequenceIdData.getUUID();
            try {
              no = ImportTaxData.insertTax(con, conn, C_Tax_ID, C_TaxCategory_ID,
                  C_BPTaxCategory_ID, ParentTax_ID, I_Tax_ID);
              if (log4j.isDebugEnabled())
                log4j.debug("Insert Tax = " + no);
              noTaxInsert++;
            } catch (ServletException ex) {
              String err = "Insert Tax - " + ex.toString();
              if (log4j.isDebugEnabled())
                log4j.debug(err);
              no = ImportTaxData.taxError(conn, err, I_Tax_ID);
              try {
                conn.releaseRollbackConnection(con);
              } catch (Exception ignored) {
              }
              continue;
            }
          } else { // Update existing Tax
            try {
              no = ImportTaxData.updateTax(con, conn, I_Tax_ID, C_TaxCategory_ID,
                  C_BPTaxCategory_ID, ParentTax_ID, C_Tax_ID);
              if (log4j.isDebugEnabled())
                log4j.debug("Update Tax = " + no);
              noTaxUpdate++;
            } catch (ServletException ex) {
              String err = "Update Tax - " + ex.toString();
              if (log4j.isDebugEnabled())
                log4j.debug(err);
              no = ImportTaxData.taxError(conn, err, I_Tax_ID);
              try {
                conn.releaseRollbackConnection(con);
              } catch (Exception ignored) {
              }
              continue;
            }
          }

          // Coutry-Region
          if ((!data[i].cCountryId.equals("") || !data[i].cRegionId.equals("")
              || !data[i].toCountryId.equals("0") || !data[i].toRegionId.equals("0"))
              && ImportTaxData.existsLocation(con, conn, I_Tax_ID, C_Tax_ID).equals("0")) {
            if (ImportTaxData.hasLocation(con, conn, C_Tax_ID).equals("0")) { // Update Location in
              // c_tax
              try {
                no = ImportTaxData.updateTaxRegion(con, conn, I_Tax_ID, C_Tax_ID);
                if (log4j.isDebugEnabled())
                  log4j.debug("Update Tax Location (in c_tax) = " + no);
              } catch (ServletException ex) {
                String err = "Update Tax Location (in c_tax)- " + ex.toString();
                if (log4j.isDebugEnabled())
                  log4j.debug(err);
                no = ImportTaxData.taxError(conn, err, I_Tax_ID);
                try {
                  conn.releaseRollbackConnection(con);
                } catch (Exception ignored) {
                }
                continue;
              }
            } else { // create Location in c_tax_zone
              try {
                String C_Tax_Zone_ID = SequenceIdData.getUUID();
                no = ImportTaxData.insertTaxZone(con, conn, C_Tax_Zone_ID, C_Tax_ID, I_Tax_ID);
                if (log4j.isDebugEnabled())
                  log4j.debug("Insert tax Location (in c_tax_zone) = " + no);
              } catch (ServletException ex) {
                String err = "Insert tax Location (in c_tax_zone)- " + ex.toString();
                if (log4j.isDebugEnabled())
                  log4j.debug(err);
                no = ImportTaxData.taxError(conn, err, I_Tax_ID);
                try {
                  conn.releaseRollbackConnection(con);
                } catch (Exception ignored) {
                }
                continue;
              }
            }
          }
        } // tax

        // Update I_Tax
        try {
          no = ImportTaxData.setImported(con, conn, C_TaxCategory_ID, I_Tax_ID);
          conn.releaseCommitConnection(con);
        } catch (Exception ex) {
          if (log4j.isDebugEnabled())
            log4j.debug("Update Imported - " + ex.toString());
          noTCInsert--;
          no = ImportTaxData.updateSetImportedError(conn, I_Tax_ID);
          try {
            conn.releaseRollbackConnection(con);
          } catch (Exception ignored) {
          }
          continue;
        }
      }
View Full Code Here

      log4j.debug("Creating parameters");
  }

  protected OBError doIt(VariablesSecureApp vars) throws ServletException {
    int no = 0;
    ConnectionProvider conn = null;
    Connection con = null;
    OBError myError = new OBError();

    try {
      conn = getConnection();
      con = conn.getTransactionConnection();
      if (m_deleteOldImported) {
        no = ImportAccountData.deleteOld(con, conn, getAD_Client_ID());
        if (log4j.isDebugEnabled())
          log4j.debug("Delete Old Imported = " + no);
      }
      // Set Client, Org, IaActive, Created/Updated
      no = ImportAccountData.updateRecords(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount Reset = " + no);

      // Set element
      if (!m_C_Element_ID.equals("0")) {
        no = ImportAccountData.updateElement(con, conn, m_C_Element_ID, getAD_Client_ID());
        if (log4j.isDebugEnabled())
          log4j.debug("ImportAccount Element = " + no);
      }
      no = ImportAccountData.updateIdByName(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount ids by name = " + no);
      no = ImportAccountData.updateElementError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount element errors = " + no);

      // Set column
      no = ImportAccountData.updateColumn(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount updated columns = " + no);
      no = ImportAccountData.updateColumnError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount column errors = " + no);

      // Set default values for PostActual, PostBudget, PostStatistical,
      // PostEncumbrance, IsSummary, IsDocControlled
      String[] yColumns = new String[] { "PostActual", "PostBudget", "PostStatistical",
          "PostEncumbrance" };
      for (int i = 0; i < yColumns.length; i++) {
        no = ImportAccountData.updateYColumns(con, conn, yColumns[i], getAD_Client_ID());
        if (log4j.isDebugEnabled())
          log4j.debug("ImportAccount " + yColumns[i] + " errors = " + no);
      }
      no = ImportAccountData.updateSummary(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount updated summary = " + no);
      no = ImportAccountData.updateDocControlled(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount updated docControlled = " + no);

      // Check Account Type A (E) L M O R
      no = ImportAccountData.updateAccountType(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount updated AccountType = " + no);
      no = ImportAccountData.updateAccountTypeError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount AccountType errors = " + no);

      // Check Account Sign (N) C B
      no = ImportAccountData.updateAccountSign(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount updated AccountSign = " + no);
      no = ImportAccountData.updateAccountSignError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount AccountSign errors = " + no);

      // Update ElementValue from existing
      no = ImportAccountData.updateCElementValueID(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount updated CElementValueID = " + no);

      // Disable triggers
      ImportAccountData.disableTriggers(con, conn);
      if (log4j.isDebugEnabled())
        log4j.debug("Triggers in C_ValidCombination disabled");

      conn.releaseCommitConnection(con);
      // Default accounts
      String[][] defaults = null;
      defaults = new String[73][2];

      defaults[0][0] = "PPVOFFSET_ACCT";
      defaults[1][0] = "USESUSPENSEBALANCING";// Never used
      defaults[2][0] = "SUSPENSEBALANCING_ACCT";
      defaults[3][0] = "USESUSPENSEERROR";// Never used
      defaults[4][0] = "SUSPENSEERROR_ACCT";
      defaults[5][0] = "USECURRENCYBALANCING";// Never used
      defaults[6][0] = "CURRENCYBALANCING_ACCT";
      defaults[7][0] = "RETAINEDEARNING_ACCT";
      defaults[8][0] = "INTERCOMPANYDUETO_ACCT";
      defaults[9][0] = "INTERCOMPANYDUEFROM_ACCT";
      defaults[10][0] = "CFS_ORDER_ACCT";
      defaults[11][0] = "W_INVENTORY_ACCT";
      defaults[12][0] = "W_INVACTUALADJUST_ACCT";
      defaults[13][0] = "W_DIFFERENCES_ACCT";
      defaults[14][0] = "W_REVALUATION_ACCT";
      defaults[15][0] = "P_REVENUE_ACCT";
      defaults[16][0] = "P_EXPENSE_ACCT";
      defaults[17][0] = "P_ASSET_ACCT";
      defaults[18][0] = "P_INVOICEPRICEVARIANCE_ACCT";
      defaults[19][0] = "P_TRADEDISCOUNTREC_ACCT";
      defaults[20][0] = "P_TRADEDISCOUNTGRANT_ACCT";
      defaults[21][0] = "P_COGS_ACCT";
      defaults[22][0] = "C_RECEIVABLE_ACCT";
      defaults[23][0] = "V_LIABILITY_ACCT";
      defaults[24][0] = "V_LIABILITY_SERVICES_ACCT";
      defaults[25][0] = "V_PREPAYMENT_ACCT";
      defaults[26][0] = "PAYDISCOUNT_EXP_ACCT";
      defaults[27][0] = "WRITEOFF_ACCT";
      defaults[28][0] = "PAYDISCOUNT_REV_ACCT";
      defaults[29][0] = "UNREALIZEDGAIN_ACCT";
      defaults[30][0] = "UNREALIZEDLOSS_ACCT";
      defaults[31][0] = "REALIZEDGAIN_ACCT";
      defaults[32][0] = "REALIZEDLOSS_ACCT";
      defaults[33][0] = "WITHHOLDING_ACCT";
      defaults[34][0] = "E_PREPAYMENT_ACCT";
      defaults[35][0] = "E_EXPENSE_ACCT";
      defaults[36][0] = "PJ_ASSET_ACCT";
      defaults[37][0] = "PJ_WIP_ACCT";
      defaults[38][0] = "T_EXPENSE_ACCT";
      defaults[39][0] = "T_LIABILITY_ACCT";
      defaults[40][0] = "T_RECEIVABLES_ACCT";
      defaults[41][0] = "T_DUE_ACCT";
      defaults[42][0] = "T_CREDIT_ACCT";
      defaults[43][0] = "B_INTRANSIT_ACCT";
      defaults[44][0] = "B_ASSET_ACCT";
      defaults[45][0] = "B_EXPENSE_ACCT";
      defaults[46][0] = "B_INTERESTEXP_ACCT";
      defaults[47][0] = "B_UNIDENTIFIED_ACCT";
      defaults[48][0] = "B_UNALLOCATEDCASH_ACCT";
      defaults[49][0] = "B_PAYMENTSELECT_ACCT";
      defaults[50][0] = "B_SETTLEMENTGAIN_ACCT";
      defaults[51][0] = "B_SETTLEMENTLOSS_ACCT";
      defaults[52][0] = "B_REVALUATIONGAIN_ACCT";
      defaults[53][0] = "B_REVALUATIONLOSS_ACCT";
      defaults[54][0] = "CH_EXPENSE_ACCT";
      defaults[55][0] = "CH_REVENUE_ACCT";
      defaults[56][0] = "UNEARNEDREVENUE_ACCT";
      defaults[57][0] = "NOTINVOICEDRECEIVABLES_ACCT";
      defaults[58][0] = "NOTINVOICEDREVENUE_ACCT";
      defaults[59][0] = "NOTINVOICEDRECEIPTS_ACCT";
      defaults[60][0] = "CB_ASSET_ACCT";
      defaults[61][0] = "CB_CASHTRANSFER_ACCT";
      defaults[62][0] = "CB_DIFFERENCES_ACCT";
      defaults[63][0] = "CB_RECEIPT_ACCT";
      defaults[64][0] = "A_ACCUMDEPRECIATION_ACCT";
      defaults[65][0] = "A_DEPRECIATION_ACCT";
      defaults[66][0] = "A_DISPOSAL_GAIN";
      defaults[67][0] = "INCOMESUMMARY_ACCT";
      defaults[68][0] = "P_PURCHASEPRICEVARIANCE_ACCT";
      defaults[69][0] = "C_PREPAYMENT_ACCT";
      defaults[70][0] = "B_INTERESTREV_ACCT";
      defaults[71][0] = "CB_EXPENSE_ACCT";
      defaults[72][0] = "A_DISPOSAL_LOSS";

      // till here, the edition of the I_ElementValue table
      // now, the insertion from I_ElementValue table in C_ElementValue...

      int noInsert = 0;
      int noUpdate = 0;
      int noAccountError = 0;

      con = conn.getTransactionConnection();
      ImportAccountData[] records = ImportAccountData.selectRecords(conn, getAD_Client_ID());
      for (int i = 0; i < records.length; i++) {
        String I_ElementValue_ID = records[i].iElementvalueId;
        String C_ElementValue_ID = records[i].cElementvalueId;

        if (log4j.isDebugEnabled())
          log4j.debug("I_ElementValue_ID=" + I_ElementValue_ID + ", C_ElementValue_ID="
              + C_ElementValue_ID);
        if (C_ElementValue_ID.equals("0") || C_ElementValue_ID == null
            || C_ElementValue_ID.equals("")) { // insert new
          try {
            C_ElementValue_ID = SequenceIdData.getUUID();
            records[i].cElementvalueId = C_ElementValue_ID;
            no = ImportAccountData.insertElementValue(con, conn, C_ElementValue_ID,
                I_ElementValue_ID);
            if (log4j.isDebugEnabled())
              log4j.debug("Insert ElementValue = " + no);
            noInsert += no;
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Insert ElementValue - " + ex.toString());
            ImportAccountData.insertElementValueError(con, conn, ex.toString(), I_ElementValue_ID);
            continue;
          }
        } else { // update
          try {
            no = ImportAccountData.updateElementValue(con, conn, I_ElementValue_ID,
                C_ElementValue_ID);
            if (log4j.isDebugEnabled())
              log4j.debug("Insert ElementValue = " + no);
            noUpdate += no;
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Update ElementValue - " + ex.toString());
            ImportAccountData.updateElementValueError(con, conn, ex.toString(), I_ElementValue_ID);
            continue;
          }
        }
        ImportAccountData.updateProcessing(con, conn, C_ElementValue_ID, I_ElementValue_ID);
      }
      // records = ImportAccountData.selectRecords(con, conn,
      // getAD_Client_ID());

      for (int i = 0; i < records.length; i++) {
        String I_ElementValue_ID = records[i].iElementvalueId;
        String elementValue = records[i].value;
        boolean found = false;
        for (int j = 0; j < 73 && !found && records[i].defaultAccount != null
            && !(records[i].defaultAccount).equals(""); j++) {
          if (defaults[j][0].equals(records[i].defaultAccount)) {
            defaults[j][1] = records[i].cElementvalueId;
            found = true;
          }
        }

        if (log4j.isDebugEnabled())
          log4j.debug("I_ElementValue_ID=" + I_ElementValue_ID + ", elementValue=" + elementValue);
        try {
          String[][] strOperand = operandProcess(ImportAccountData.selectOperands(con, conn,
              I_ElementValue_ID));
          String strSeqNo = "10";
          for (int j = 0; strOperand != null && j < strOperand.length; j++) {
            String C_ElementValue_Operand_ID = SequenceIdData.getUUID();
            String strAccount = ImportAccountData.selectAccount(con, conn, strOperand[j][0], vars
                .getClient(), m_C_Element_ID);
            String strElementValue = ImportAccountData.selectAccount(con, conn, elementValue, vars
                .getClient(), m_C_Element_ID);
            if (strAccount != null && !strAccount.equals("")) {
              ImportAccountData.insertOperands(con, conn, C_ElementValue_Operand_ID,
                  (strOperand[j][1].equals("+") ? "1" : "-1"), strElementValue, strAccount,
                  strSeqNo, vars.getClient(), vars.getUser());
              strSeqNo = nextSeqNo(strSeqNo);
            } else {
              if (log4j.isDebugEnabled())
                log4j.debug("Operand not inserted - Value = " + strOperand[j][0]);
            }
          }
        } catch (ServletException ex) {
          log4j.warn("ServletException I_ElementValue_ID=" + I_ElementValue_ID);
          ImportAccountData.insertElementValueError(con, conn, ex.toString(), I_ElementValue_ID);
          continue;
        }
      }
      ImportAccountData[] acctSchemas = ImportAccountData.selectAcctSchema(conn, m_C_Element_ID,
          getAD_Client_ID());
      for (int g = 0; g < acctSchemas.length; g++) {
        String defaultsRecordNo = ImportAccountData.selectDefaultsRecord(con, conn,
            acctSchemas[g].cAcctschemaId);
        if (defaultsRecordNo.equals("0")) {
          String C_AcctSchema_Default_ID = SequenceIdData.getUUID();
          ImportAccountData.insertDefaultsRecord(con, conn, acctSchemas[g].cAcctschemaId,
              acctSchemas[g].adClientId, acctSchemas[g].adOrgId, vars.getUser(),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[11][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[12][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[13][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[14][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[15][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[16][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[17][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[68][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[18][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[19][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[20][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[21][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[22][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[69][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[23][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[24][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[25][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[26][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[27][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[28][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[29][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[30][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[31][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[32][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[33][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[34][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[35][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[36][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[37][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[38][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[39][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[40][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[41][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[42][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[43][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[44][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[45][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[70][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[46][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[47][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[48][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[49][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[50][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[51][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[52][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[53][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[54][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[55][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[56][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[57][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[58][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[59][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[60][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[61][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[62][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[71][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[63][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[64][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[65][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[66][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[72][1], vars.getUser()),
              C_AcctSchema_Default_ID);
        }
        String gLRecordNo = ImportAccountData.selectGLRecord(con, conn,
            acctSchemas[g].cAcctschemaId);
        if (gLRecordNo.equals("0"))
          ImportAccountData.insertGLRecord(con, conn, acctSchemas[g].cAcctschemaId,
              acctSchemas[g].adClientId, acctSchemas[g].adOrgId, vars.getUser(),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[2][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[4][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[6][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[7][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[67][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[8][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[9][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[0][1], vars.getUser()),
              getValidCombination(con, conn, acctSchemas[g].adClientId, acctSchemas[g].adOrgId,
                  acctSchemas[g].cAcctschemaId, defaults[10][1], vars.getUser()));
      }
      // Set Error to indicator to not imported
      noAccountError = ImportAccountData.updateNotImported(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Errors: " + noAccountError);
      if (log4j.isDebugEnabled())
        log4j.debug("Inserts: " + noInsert);
      if (log4j.isDebugEnabled())
        log4j.debug("Updates: " + noUpdate);
      addLog(Utility.messageBD(conn, "Elements not imported", vars.getLanguage()) + ": "
          + noAccountError + "; ");
      addLog("Elements inserted: " + noInsert + "; ");
      addLog("Elements updated: " + noUpdate + "; ");

      if (noAccountError == 0) {
        myError.setType("Success");
        myError.setTitle(Utility.messageBD(conn, "Success", vars.getLanguage()));
      } else if (noInsert > 0 || noUpdate > 0) {
        myError.setType("Warning");
        myError.setTitle(Utility.messageBD(conn, "Some elements could not be imported", vars
            .getLanguage()));
      } else {
        myError.setType("Error");
        myError.setTitle(Utility.messageBD(conn, " No elements could be imported", vars
            .getLanguage()));
      }

      conn.releaseCommitConnection(con);

      con = conn.getTransactionConnection();
      // Set parent
      no = ImportAccountData.setParent(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount updated parent = " + no);
      no = ImportAccountData.setParentError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount updated parent errors = " + no);

      int noParentUpdate = 0;
      ImportAccountData[] parents = ImportAccountData.selectParents(con, conn, getAD_Client_ID());
      for (int i = 0; i < parents.length; i++) {
        no = ImportAccountData.updateTree(con, conn, parents[i].parentelementvalueId,
            parents[i].seqno, parents[i].adTreeId, parents[i].cElementvalueId);
        noParentUpdate += no;
      }
      addLog("Parent updates: " + noParentUpdate + " ");
      if (log4j.isDebugEnabled())
        log4j.debug("Parent updates: " + noParentUpdate);

      // Reset Processing Flag
      if (m_updateDefaultAccounts) {
        no = ImportAccountData.updateProcessed(con, conn, getAD_Client_ID(), "clause");
        updateDefaults(con, conn, vars);
      } else {
        no = ImportAccountData.updateProcessed(con, conn, getAD_Client_ID(), "");
      }
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount updated parent = " + no);

      // Re-enable triggers
      ImportAccountData.enableTriggers(con, conn);
      if (log4j.isDebugEnabled())
        log4j.debug("Triggers in C_ValidCombination enabled");
      // Update Description
      no = ImportAccountData.updateDescription(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportAccount updated description = " + no);

      conn.releaseCommitConnection(con);
    } catch (NoConnectionAvailableException ex) {
      throw new ServletException("@CODE=NoConnectionAvailable");
    } catch (SQLException ex2) {
      try {
        conn.releaseRollbackConnection(con);
      } catch (Exception ignored) {
      }
      throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@"
          + ex2.getMessage());
    } catch (Exception ex3) {
      try {
        conn.releaseRollbackConnection(con);
      } catch (Exception ignored) {
      }
      throw new ServletException("@CODE=@" + ex3.getMessage());
    }
View Full Code Here

  }

  protected OBError doIt(VariablesSecureApp vars) throws ServletException {
    int no = 0;
    OBError myError = new OBError();
    ConnectionProvider conn = null;
    Connection con = null;
    try {
      conn = getConnection();
      con = conn.getTransactionConnection();
      if (m_deleteOldImported) {
        no = ImportBudgetData.deleteOld(con, conn, getAD_Client_ID());
        if (log4j.isDebugEnabled())
          log4j.debug("Delete Old Imported = " + no);
      }
      // Set Client, Org, IaActive, Created/Updated, ProductType
      no = ImportBudgetData.updateRecords(con, conn, getAD_Client_ID(), m_Budget_ID);
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget Reset = " + no);

      // BPartner
      no = ImportBudgetData.updateBPartnerId(con, conn, vars.getLanguage(), getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget BPartnerId = " + no);
      no = ImportBudgetData.updatePartnerError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Partner = " + no);

      // Set BPGroup
      no = ImportBudgetData.updateBPGroupId(con, conn, vars.getLanguage(), getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget BPGroupId = " + no);
      no = ImportBudgetData.updateGroupError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid BPartner group = " + no);

      // Product
      no = ImportBudgetData.updateProductId(con, conn, vars.getLanguage(), getAD_Client_ID());
      ImportBudgetData.updateUomId(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget ProductId = " + no);
      no = ImportBudgetData.updateProductError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Product = " + no);

      // Product Category
      no = ImportBudgetData.updateProdCatId(con, conn, vars.getLanguage(), getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget Product Category = " + no);
      no = ImportBudgetData.updateProdCatError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Product Category= " + no);

      // Trx Organization
      no = ImportBudgetData.updateTrxOrgId(con, conn, vars.getLanguage(), getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget Trx Organization = " + no);
      no = ImportBudgetData.updateTrxOrgError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Trx Organization = " + no);

      // Sales Region
      no = ImportBudgetData.updateSalesRegionId(con, conn, vars.getLanguage(), getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget Sales Region = " + no);
      no = ImportBudgetData.updateSalesRegionError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Sales Region = " + no);

      // Project
      no = ImportBudgetData.updateProjectId(con, conn, vars.getLanguage(), getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget Project = " + no);
      no = ImportBudgetData.updateProjectError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Project = " + no);

      // Campaign
      no = ImportBudgetData.updateCampaignId(con, conn, vars.getLanguage(), getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget Campaign = " + no);
      no = ImportBudgetData.updateCampaignError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Campaign = " + no);

      // Activity
      no = ImportBudgetData.updateActivityId(con, conn, vars.getLanguage(), getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget Activity = " + no);
      no = ImportBudgetData.updateActivityError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Activity = " + no);

      // Account ID
      no = ImportBudgetData.updateAccountId(con, conn, vars.getLanguage(), getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget AccountID = " + no);
      no = ImportBudgetData.updateAccountIdError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid AccountID = " + no);

      // Account Schema
      no = ImportBudgetData.updateAcctSchemaId(con, conn, vars.getLanguage(), getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget Account Schema = " + no);
      no = ImportBudgetData.updateAcctSchemaError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Account Schema = " + no);

      // Period
      no = ImportBudgetData.updatePeriodId(con, conn, m_Budget_ID, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget Period = " + no);
      no = ImportBudgetData.updatePeriodError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Period = " + no);

      // Currency
      no = ImportBudgetData.updateCurrencyId(con, conn, vars.getLanguage(), getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget Currency = " + no);
      no = ImportBudgetData.updateCurrencyError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Currency = " + no);

      // Budget Line ¿Exist?
      no = ImportBudgetData.updateBudgetLineId(con, conn, m_Budget_ID, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportBudget BudgetLine = " + no);

      conn.releaseCommitConnection(con);
    } catch (Exception se) {
      try {
        conn.releaseRollbackConnection(con);
      } catch (Exception ignored) {
      }
      se.printStackTrace();
      addLog(Utility.messageBD(conn, "ProcessRunError", vars.getLanguage()));
      myError.setType("Error");
      myError.setTitle(Utility.messageBD(conn, "Error", vars.getLanguage()));
      myError.setMessage(Utility.messageBD(conn, "ProcessRunError", vars.getLanguage()));
      return myError;
    }

    // till here, the edition of the I_BUDGETLINE table
    // now, the insertion from I_BUDGETLINE table in C_BPartner...

    int noInsert = 0;
    int noUpdate = 0;
    int seqNo = 0;
    int noBudgetError = 0;

    try {
      // Go through Records
      ImportBudgetData[] data = ImportBudgetData.select(conn, getAD_Client_ID());
      seqNo = Integer.parseInt(ImportBudgetData.selectSeqNo(conn, m_Budget_ID));
      if (log4j.isDebugEnabled())
        log4j.debug("Going through " + data.length + " records");
      for (int i = 0; i < data.length; i++) {
        String I_BudgetLine_ID = data[i].iBudgetlineId;
        String C_BudgetLine_ID = data[i].cBudgetlineId;
        boolean newBudgetLine = (C_BudgetLine_ID == null || C_BudgetLine_ID.equals(""));

        con = conn.getTransactionConnection();

        // create/update Budget
        if (newBudgetLine) { // Insert new BudgetLine
          C_BudgetLine_ID = SequenceIdData.getUUID();
          try {
            no = ImportBudgetData.insertBudgetLine(con, conn, C_BudgetLine_ID, Integer
                .toString(seqNo), I_BudgetLine_ID);
            if (log4j.isDebugEnabled())
              log4j.debug("Insert BudgetLine = " + no);
            noInsert++;
            seqNo = seqNo + 10;
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Insert BudgetLine - " + ex.toString());
            conn.releaseRollbackConnection(con);
            no = ImportBudgetData.insertBudgetLineError(conn, ex.toString(), I_BudgetLine_ID);
            continue;
          }
        } else { // Update existing BudgetLine
          try {
            no = ImportBudgetData.updateBudgetLine(con, conn, I_BudgetLine_ID, C_BudgetLine_ID);
            if (log4j.isDebugEnabled())
              log4j.debug("Update BudgetLine = " + no);
            noUpdate++;
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Update BudgetLine - " + ex.toString());
            conn.releaseRollbackConnection(con);
            no = ImportBudgetData.updateBudgetLineError(conn, ex.toString(), I_BudgetLine_ID);
            continue;
          }
        }

        // Update I_BudgetLine
        try {
          no = ImportBudgetData.setImported(con, conn, C_BudgetLine_ID, I_BudgetLine_ID);
          conn.releaseCommitConnection(con);
        } catch (ServletException ex) {
          if (log4j.isDebugEnabled())
            log4j.debug("Update Imported - " + ex.toString());
          noInsert--;
          conn.releaseRollbackConnection(con);
          no = ImportBudgetData.updateSetImportedError(conn, ex.toString(), I_BudgetLine_ID);
          continue;
        }
      }
View Full Code Here

  }

  public void init(HttpServlet s) throws AuthenticationException {

    if (s instanceof ConnectionProvider) {
      ConnectionProvider conn = (ConnectionProvider) s;
      m_sAutologonUsername = ConfigParameters.retrieveFrom(s.getServletContext()).getOBProperty(
          "authentication.autologon.username");
      try {
        m_sUserId = AuthenticationData.getUserId(conn, m_sAutologonUsername);
      } catch (ServletException e) {
View Full Code Here

  }

  protected OBError doIt(VariablesSecureApp vars) throws ServletException {
    OBError myError = new OBError();

    ConnectionProvider conn = null;
    Connection con = null;
    try {
      int no = 0;
      conn = getConnection();
      con = conn.getTransactionConnection();
      if (m_deleteOldImported) {
        no = ImportOrderData.deleteOld(con, conn, getAD_Client_ID());
        if (log4j.isDebugEnabled())
          log4j.debug("Delete Old Imported = " + no);
      }
      // Set Client, Org, IsActive, Created/Updated
      no = ImportOrderData.updateRecords(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportOrder updated = " + no);
      no = ImportOrderData.updateInvalidVendor(con, conn, getAD_Org_ID(), getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid vendor errors = " + no);
      // Invalid organization
      no = ImportOrderData.updateRecordsError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid organization errors = " + no);
      // Document Type - PO - SO
      no = ImportOrderData.updateDocTypePO(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated DocTypePO = " + no);
      no = ImportOrderData.updateDocTypeSO(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated DocTypeSO = " + no);
      no = ImportOrderData.updateDocType(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated DocType = " + no);
      no = ImportOrderData.updateDocTypeError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid DocType errors = " + no);
      // DocType Default
      no = ImportOrderData.updateDocTypePODefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated DocTypePO default = " + no);
      no = ImportOrderData.updateDocTypeSODefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated DocTypeSO default = " + no);
      no = ImportOrderData.updateDocTypeDefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated DocType default = " + no);
      no = ImportOrderData.updateDocTypeDefaultError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid DocType default errors = " + no);
      // Set IsSOTrx
      no = ImportOrderData.updateIsSOTrxY(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated IsSOTrx=Y = " + no);
      no = ImportOrderData.updateIsSOTrxN(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated IsSOTrx=N = " + no);
      // Price List
      no = ImportOrderData.updatePriceListCurrencyDefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated PriceList by currency (default) = " + no);
      no = ImportOrderData.updatePriceListNullCurrencyDefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated PriceList with null currency (default) = " + no);
      no = ImportOrderData.updatePriceListCurrency(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated PriceList by currency = " + no);
      no = ImportOrderData.updatePriceListNullCurrency(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated PriceList with null currency = " + no);
      no = ImportOrderData.updatePriceListError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid PriceList errors = " + no);
      // Set Currency
      no = ImportOrderData.updateCurrencyDefaultFromPriceList(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportOrder Set Currency Default =" + no);
      no = ImportOrderData.updateInvalidCurrency(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("ImportOrder Invalid Currency =" + no);
      // Payment Term
      no = ImportOrderData.updatePaymentTerm(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated PaymentTerm = " + no);
      no = ImportOrderData.updatePaymentTermDefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated PaymentTerm default = " + no);
      no = ImportOrderData.updatePaymentTermError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid PaymentTerm errors = " + no);
      // Warehouse
      no = ImportOrderData.updateWarehouse(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated Warehouse = " + no);
      no = ImportOrderData.updateWarehouseOther(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated Warehouse (other) = " + no);
      no = ImportOrderData.updateWarehouseError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Warehouse errors = " + no);
      // BusinessPartner
      // import depending on the external value
      no = ImportOrderData.updateBPartnerFromValue(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated BPartner from value = " + no);
      no = ImportOrderData.updateBPartnerFromEmail(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated BPartner from email = " + no);
      no = ImportOrderData.updateBPartnerFromContact(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated BPartner from contact = " + no);
      no = ImportOrderData.updateBPartnerFromName(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated BPartner from name = " + no);
      no = ImportOrderData.updateBPartnerFromUPC(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated BPartner from upc = " + no);
      no = ImportOrderData.updateBPartnerDefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated BPartner (default) = " + no);
      // update PriceList and PaymentTerm according to BPartner
      no = ImportOrderData.updatePriceListFromBPartner(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated PriceList from BPartner = " + no);
      no = ImportOrderData.updatePOPriceListFromBPartner(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated POPriceList from BPartner = " + no);
      no = ImportOrderData.updatePaymentTermFromBPartner(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated PaymentTerm from BPartner = " + no);
      no = ImportOrderData.updatePOPaymentTermFromBPartner(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated POPaymentTerm from BPartner = " + no);
      // Location
      no = ImportOrderData.updateLocationByUPC(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated Location by UPC = " + no);
      no = ImportOrderData.updateBilltoByUPC(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated bill location by UPC = " + no);
      no = ImportOrderData.updateLocationExisting(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated Location (existing) = " + no);
      no = ImportOrderData.updateBillLocation(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated BillLocation = " + no);
      no = ImportOrderData.updateLocation(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated Location = " + no);
      no = ImportOrderData.updateLocationError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Location errors = " + no);
      // Country
      no = ImportOrderData.updateCountryDefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated Country (default) = " + no);
      no = ImportOrderData.updateCountry(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated Country = " + no);
      no = ImportOrderData.updateCountryError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Country errors = " + no);
      // Set Region
      no = ImportOrderData.updateRegionDefault(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated Region (default) = " + no);
      no = ImportOrderData.updateRegion(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated Region = " + no);
      no = ImportOrderData.updateRegionError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Region errors = " + no);
      // Product
      no = ImportOrderData.updateProductFromValue(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated Product from value = " + no);
      no = ImportOrderData.updateProductFromUpc(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated Product from UPC = " + no);
      no = ImportOrderData.updateProductFromSku(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated Product from SKU = " + no);
      no = ImportOrderData.updateProductError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Product errors = " + no);
      // Tax
      no = ImportOrderData.updateTax(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Updated Tax = " + no);
      no = ImportOrderData.updateTaxError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid Tax errors = " + no);
      conn.releaseCommitConnection(con);

      // till here, the edition of the I_Order table
      // now, the insertion from I_Order table in C_Order
      // New BPartner
      ImportOrderData[] data = ImportOrderData.selectWithoutBP(conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Going through " + data.length + " records");
      for (int i = 0; i < data.length; i++) {
        con = conn.getTransactionConnection();
        String I_Order_ID = data[i].iOrderId;

        if (data[i].bpartnervalue == null || data[i].bpartnervalue.equals("")) {
          if (data[i].email != null && !data[i].email.equals(""))
            data[i].bpartnervalue = data[i].email;
          else if (data[i].name != null && !data[i].name.equals(""))
            data[i].bpartnervalue = data[i].name;
          else
            continue;
        }
        if (data[i].name == null || data[i].name.equals("")) {
          if (data[i].contactname != null && !data[i].contactname.equals(""))
            data[i].name = data[i].contactname;
          else
            data[i].name = data[i].bpartnervalue;
        }
        BPartnerData bp = new BPartnerData();
        bp.cBpartnerId = SequenceIdData.getUUID();
        bp.adClientId = data[i].adClientId;
        bp.adOrgId = data[i].adOrgId;
        bp.value = data[i].bpartnervalue;
        bp.name = data[i].name;
        try {
          bp.insert(con, conn);
        } catch (ServletException ex) {
          if (log4j.isDebugEnabled())
            log4j.debug("Insert Order - " + ex.toString());
          conn.releaseRollbackConnection(con);
          ImportOrderData.importOrderError(conn, ex.toString(), I_Order_ID);
          continue;
        }
        data[i].cBpartnerId = bp.cBpartnerId;
        LocationData loc = new LocationData();
        loc.cLocationId = SequenceIdData.getUUID();
        loc.adClientId = data[i].adClientId;
        loc.adOrgId = data[i].adOrgId;
        loc.address1 = data[i].address1;
        loc.address2 = data[i].address2;
        loc.city = data[i].city;
        loc.postal = data[i].postal;
        if (data[i].cRegionId != null)
          loc.cRegionId = data[i].cRegionId;
        loc.cCountryId = data[i].cCountryId;
        try {
          loc.insert(con, conn);
        } catch (ServletException ex) {
          if (log4j.isDebugEnabled())
            log4j.debug("Insert Order - " + ex.toString());
          conn.releaseRollbackConnection(con);
          ImportOrderData.importOrderError(conn, ex.toString(), I_Order_ID);
          continue;
        }
        data[i].cLocationId = loc.cLocationId;
        BPartnerLocationData bpl = new BPartnerLocationData();
        bpl.cBpartnerLocationId = SequenceIdData.getUUID();
        bpl.adClientId = data[i].adClientId;
        bpl.adOrgId = data[i].adOrgId;
        bpl.cBpartnerId = data[i].cBpartnerId;
        bpl.cLocationId = data[i].cLocationId;
        try {
          bpl.insert(con, conn);
        } catch (ServletException ex) {
          if (log4j.isDebugEnabled())
            log4j.debug("Insert Order - " + ex.toString());
          conn.releaseRollbackConnection(con);
          ImportOrderData.importOrderError(conn, ex.toString(), I_Order_ID);
          continue;
        }
        data[i].cBpartnerLocationId = bpl.cBpartnerLocationId;
        data[i].billtoId = bpl.cBpartnerLocationId;
        if (data[i].contactname != null || data[i].email != null || data[i].phone != null) {
          UserData user = new UserData();
          user.adUserId = SequenceIdData.getUUID();
          user.adClientId = data[i].adClientId;
          user.adOrgId = data[i].adOrgId;
          user.cBpartnerId = data[i].cBpartnerId;
          if (data[i].contactname != null && !data[i].contactname.equals(""))
            user.name = data[i].contactname;
          else
            user.name = data[i].name;
          user.email = data[i].email;
          user.phone = data[i].phone;
          try {
            user.insert(con, conn);
          } catch (ServletException ex) {
            if (log4j.isDebugEnabled())
              log4j.debug("Insert Order - " + ex.toString());
            conn.releaseRollbackConnection(con);
            ImportOrderData.importOrderError(conn, ex.toString(), I_Order_ID);
            continue;
          }
          data[i].adUserId = user.adUserId;
          data[i].updatedby = user.adUserId;
        }
        data[i].update(con, conn);
        conn.releaseCommitConnection(con);
      }
      con = conn.getTransactionConnection();
      no = ImportOrderData.updateBPartnerError(con, conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Invalid BPartner errors = " + no);
      conn.releaseCommitConnection(con);
      // New Order
      int noInsert = 0;
      int noInsertLine = 0;
      int noOrderError = 0;

      data = ImportOrderData.selectNotImported(conn, getAD_Client_ID());
      if (log4j.isDebugEnabled())
        log4j.debug("Going through " + data.length + " records");
      COrderData corder = null;
      String order_documentno = "";
      String corder_corderid = "";
      String corder_mpricelistid = "";
      String corder_ccurrencyid = "";
      String corder_cbpartnerid = "";
      String corder_cbpartnerlocationid = "";
      String strPostMessage = "";
      int lineNo = 0;
      for (int i = 0; i < data.length; i++) {
        con = conn.getTransactionConnection();
        String I_Order_ID = data[i].iOrderId;

        if (!order_documentno.equals(data[i].documentno) || data[i].documentno.equals("")) {
          // if (!C_BPartner_ID.equals(data[i].cBpartnerId) ||
          // !BillTo_ID.equals(data[i].billtoId) ||
          // !C_BPartner_Location_ID.equals(data[i].cBpartnerLocationId))
          // {
          corder = new COrderData();
          if (data[i].documentno != null && !data[i].documentno.equals("")) {
            corder.documentno = data[i].documentno;
          } else {
            String docTargetType = ImportOrderData.cDoctypeTarget(con, conn, Utility.getContext(
                conn, vars, "#User_Client", "ImportOrder"), Utility.getContext(conn, vars,
                "#User_Org", "ImportOrder"));
            corder.documentno = Utility.getDocumentNo(conn, vars, "", "C_Order", docTargetType,
                docTargetType, false, true);
          }
          order_documentno = corder.documentno;
          if (data[i].dateordered == null || data[i].dateordered.equals("")) {
            data[i].dateordered = DateTimeData.today(conn);
          }
          if (data[i].datepromised == null || data[i].datepromised.equals("")) {
            data[i].datepromised = data[i].dateordered;
          }

          // Looking for same order yet inserted
          ImportOrderData[] orderInserted = ImportOrderData.selectOrderInserted(conn,
              getAD_Client_ID(), data[i].adOrgId, data[i].cDoctypeId, data[i].documentno,
              data[i].dateordered, data[i].cBpartnerId);
          if (orderInserted != null && orderInserted.length == 0) {
            corder.cOrderId = SequenceIdData.getUUID();
            if (log4j.isDebugEnabled())
              log4j.debug("Creating new order with id = " + corder.cOrderId);
            corder.adClientId = data[i].adClientId;
            corder.adOrgId = data[i].adOrgId;
            corder.cDoctypetargetId = data[i].cDoctypeId;
            corder.cDoctypeId = "0";
            if (log4j.isDebugEnabled())
              log4j.debug("data[i].cBpartnerLocationId: " + data[i].cBpartnerLocationId);
            corder.cBpartnerLocationId = data[i].cBpartnerLocationId;
            if (log4j.isDebugEnabled())
              log4j.debug("data[i].description: " + data[i].description);
            corder.description = data[i].description;
            if (data[i].description != null && !data[i].description.equals("")) {
              String location_name = ImportOrderData.selectLocationName(con, conn,
                  data[i].description);
              if (log4j.isDebugEnabled())
                log4j.debug("location_name: " + location_name);
              if (location_name != null && !location_name.equals("")) {
                corder.description += " " + location_name;
                if (log4j.isDebugEnabled())
                  log4j.debug("corder.description: " + corder.description);
              }
            }
            corder.issotrx = data[i].issotrx;
            corder.docstatus = "DR";
            corder.docaction = "CO";
            corder.processing = "N";
            corder.cBpartnerId = data[i].cBpartnerId;
            corder.billtoId = data[i].billtoId;
            corder.cBpartnerLocationId = data[i].cBpartnerLocationId;
            if (!data[i].adUserId.equals(""))
              corder.adUserId = data[i].adUserId;
            else
              corder.adUserId = vars.getUser();
            corder.cPaymenttermId = data[i].cPaymenttermId;
            corder.mPricelistId = data[i].mPricelistId;
            corder.mWarehouseId = data[i].mWarehouseId;
            if (!data[i].mShipperId.equals(""))
              corder.mShipperId = data[i].mShipperId;
            if (!data[i].salesrepId.equals(""))
              corder.salesrepId = data[i].salesrepId;
            if (!data[i].adOrgtrxId.equals(""))
              corder.adOrgtrxId = data[i].adOrgtrxId;
            if (!data[i].cActivityId.equals(""))
              corder.cActivityId = data[i].cActivityId;
            if (!data[i].cCampaignId.equals(""))
              corder.cCampaignId = data[i].cCampaignId;
            if (!data[i].cProjectId.equals(""))
              corder.cProjectId = data[i].cProjectId;
            if (data[i].dateordered != null && !data[i].dateordered.equals(""))
              corder.dateordered = data[i].dateordered;
            if (data[i].datepromised != null && !data[i].datepromised.equals(""))
              corder.datepromised = data[i].datepromised;
            if (log4j.isDebugEnabled())
              log4j.debug("getting bp values as default");
            BpartnerMiscData[] data1 = BpartnerMiscData.select(conn, data[i].cBpartnerId);
            String tmpCurrency = COrderData.selectCurrency(conn, vars.getUser(),
                data[i].cBpartnerId);
            corder.isdiscountprinted = "N";
            if (log4j.isDebugEnabled())
              log4j.debug("stablishing default values");
            // corder.cCurrencyId = (tmpCurrency == null ||
            // tmpCurrency.equals(""))?"102":tmpCurrency; // euro as
            // default
            if (tmpCurrency != null && !tmpCurrency.equals("")) {
              corder.cCurrencyId = tmpCurrency;
            } else {
              corder.cCurrencyId = data[i].cCurrencyId;
            }
            if (data1[0].paymentrule != null && !data1[0].paymentrule.equals("")) {
              corder.paymentrule = data1[0].paymentrule;
            } else {
              String defaultPaymentRule = ImportOrderData.defaultValue(con, conn, "C_Order",
                  "PaymentRule");
              corder.paymentrule = (defaultPaymentRule == null || defaultPaymentRule.equals("")) ? "P"
                  : defaultPaymentRule; // P
              // =
              // on
              // credit
            }
            if (log4j.isDebugEnabled())
              log4j.debug("corder.paymentrule = " + corder.paymentrule);
            if (data1[0].invoicerule != null && !data1[0].invoicerule.equals("")) {
              corder.invoicerule = data1[0].invoicerule;
            } else {
              String defaultInvoiceRule = ImportOrderData.defaultValue(con, conn, "C_Order",
                  "InvoiceRule");
              corder.invoicerule = (defaultInvoiceRule == null || defaultInvoiceRule.equals("")) ? "I"
                  : defaultInvoiceRule; // I
              // =
              // immediate
            }
            if (log4j.isDebugEnabled())
              log4j.debug("corder.invoicerule = " + corder.invoicerule);
            if (data1[0].deliveryrule != null && !data1[0].deliveryrule.equals("")) {
              corder.deliveryrule = data1[0].deliveryrule;
            } else {
              String defaultDeliveryRule = ImportOrderData.defaultValue(con, conn, "C_Order",
                  "DeliveryRule");
              corder.deliveryrule = (defaultDeliveryRule == null || defaultDeliveryRule.equals("")) ? "A"
                  : defaultDeliveryRule; // A
              // =
              // availability
            }
            if (log4j.isDebugEnabled())
              log4j.debug("corder.deliveryrule = " + corder.deliveryrule);
            if (data1[0].deliveryviarule != null && !data1[0].deliveryviarule.equals("")) {
              corder.deliveryviarule = data1[0].deliveryviarule;
            } else {
              String defaultDeliveryViaRule = ImportOrderData.defaultValue(con, conn, "C_Order",
                  "DeliveryViaRule");
              corder.deliveryviarule = (defaultDeliveryViaRule == null || defaultDeliveryViaRule
                  .equals("")) ? "S" : defaultDeliveryViaRule; // S
              // =
              // shipper
            }
            if (log4j.isDebugEnabled())
              log4j.debug("corder.deliveryviarule = " + corder.deliveryviarule);
            corder.freightcostrule = "I"; // I = included
            if (log4j.isDebugEnabled())
              log4j.debug("corder.freightcostrule = " + corder.freightcostrule);
            if (data1[0].cPaymenttermId != null && !data1[0].cPaymenttermId.equals("")) {
              corder.cPaymenttermId = data1[0].cPaymenttermId;
            }
            if (log4j.isDebugEnabled())
              log4j.debug("corder.cPaymenttermId = " + corder.cPaymenttermId);
            if (data1[0].salesrepId != null && !data1[0].salesrepId.equals("")) {
              String salesrep = ImportOrderData.selectSalesRep(con, conn, data[i].cBpartnerId);
              corder.salesrepId = salesrep;
            }
            if (log4j.isDebugEnabled())
              log4j.debug("corder.salesrepId = " + corder.salesrepId);
            String user = ImportOrderData.defaultUser(con, conn, data[i].cBpartnerId);
            if (user != null && !user.equals("")) {
              corder.adUserId = user;
            }
            if (log4j.isDebugEnabled())
              log4j.debug("other default values");
            corder.priorityrule = "5"; // medium
            corder_corderid = corder.cOrderId;
            corder_mpricelistid = corder.mPricelistId;
            corder_ccurrencyid = corder.cCurrencyId;
            corder_cbpartnerid = corder.cBpartnerId;
            corder_cbpartnerlocationid = corder.cBpartnerLocationId;
            try {
              corder.insert(con, conn);
            } catch (ServletException ex) {
              if (log4j.isDebugEnabled())
                log4j.debug("Insert Order - " + ex.toString());
              conn.releaseRollbackConnection(con);
              ImportOrderData.importOrderError(conn, ex.toString(), I_Order_ID);
              continue;
            }
            noInsert++;
            lineNo = 10;
          } else {
            // Order with same Org, Doctype, DocumentNo, DateOrdered, BPartner
            // already exists.

            corder_corderid = orderInserted[0].cOrderId;
            order_documentno = orderInserted[0].documentno;
            corder_mpricelistid = orderInserted[0].mPricelistId;
            corder_ccurrencyid = orderInserted[0].cCurrencyId;
            corder_cbpartnerid = orderInserted[0].cBpartnerId;
            corder_cbpartnerlocationid = orderInserted[0].cBpartnerLocationId;
            lineNo = Integer.parseInt(orderInserted[0].linedescription);
          }
        }

        data[i].cOrderId = corder_corderid;
        // New OrderLine
        COrderLineData line = new COrderLineData();
        line.cOrderlineId = SequenceIdData.getUUID();
        line.adClientId = data[i].adClientId;
        line.adOrgId = data[i].adOrgId;
        line.adUserId = vars.getUser();
        line.cOrderId = corder_corderid;
        line.line = Integer.toString(lineNo);
        if (log4j.isDebugEnabled())
          log4j.debug("reading order line number: " + line.line);
        line.description = data[i].linedescription;
        line.cBpartnerId = corder_cbpartnerid;
        line.cBpartnerLocationId = corder_cbpartnerlocationid;
        lineNo += 10;
        if (data[i].mProductId != null && !data[i].mProductId.equals(""))
          line.mProductId = data[i].mProductId;
        line.qtyordered = data[i].qtyordered;
        // set price
        if (line.mProductId != null && !line.mProductId.equals("")) {
          ProductPriceData[] pprice = ProductPriceData.selectPL(conn, line.mProductId,
              corder_mpricelistid);
          if (pprice.length > 0) {
            line.pricestd = pprice[0].pricestd;
            line.priceactual = pprice[0].pricestd;
            line.pricelist = (pprice[0].pricelist == null && pprice[0].pricelist.equals("")) ? "0"
                : pprice[0].pricelist;
            line.pricelimit = (pprice[0].pricelimit == null && pprice[0].pricelimit.equals("")) ? "0"
                : pprice[0].pricelimit;
            line.discount = ((new BigDecimal(pprice[0].pricelist).compareTo(BigDecimal.ZERO) == 0) ? "0"
                : (((new BigDecimal(pprice[0].pricelist).subtract(new BigDecimal(line.priceactual)))
                    .divide(new BigDecimal(pprice[0].pricelist), 12, BigDecimal.ROUND_HALF_EVEN))
                    .multiply(new BigDecimal("100"))).toPlainString()); // ((PL-PA)/PL)*100
            line.cUomId = pprice[0].cUomId;
          } else {
            if (log4j.isDebugEnabled())
              log4j.debug("Could not establish prices");
          }
        } // set price
        if (data[i].priceactual != null && !data[i].priceactual.equals("")
            && new BigDecimal(data[i].priceactual).compareTo(BigDecimal.ZERO) != 0)
          line.priceactual = data[i].priceactual;
        if (data[i].cTaxId != null && !data[i].cTaxId.equals(""))
          line.cTaxId = data[i].cTaxId;
        else {
          try {
            line.cTaxId = Tax.get(conn, data[i].mProductId, DateTimeData.today(conn),
                data[i].adOrgId, data[i].mWarehouseId.equals("") ? vars.getWarehouse()
                    : data[i].mWarehouseId, ImportOrderData.cBPartnerLocationId(conn,
                    data[i].cBpartnerId), ImportOrderData.cBPartnerLocationId(conn,
                    data[i].cBpartnerId), data[i].cProjectId, true);
          } catch (IOException ioe) {
            if (log4j.isDebugEnabled())
              log4j.debug("IOException");
          }
        }
        if (line.cTaxId == null || line.cTaxId.equals(""))
          line.cTaxId = ProductPriceData.selectCTaxId(conn, vars.getClient());
        data[i].cTaxId = line.cTaxId;

        // line.dateordered = data[i].dateordered;
        line.dateordered = data[i].dateordered.equals("") ? DateTimeData.today(conn)
            : data[i].dateordered;
        line.mWarehouseId = (data[i].mWarehouseId == null || data[i].mWarehouseId.equals("")) ? vars
            .getWarehouse()
            : data[i].mWarehouseId;
        if (line.cUomId == null || line.cUomId.equals(""))
          line.cUomId = ProductPriceData.selectCUomIdByProduct(conn, line.mProductId);
        if (line.cUomId == null || line.cUomId.equals(""))
          line.cUomId = ProductPriceData.selectCUomIdDefault(conn);
        line.cCurrencyId = (data[i].cCurrencyId == null || data[i].cCurrencyId.equals("")) ? corder_ccurrencyid
            : data[i].cCurrencyId;
        try {
          line.insert(con, conn);
        } catch (ServletException ex) {
          if (log4j.isDebugEnabled())
            log4j.debug("Insert Order - " + ex.toString());
          conn.releaseRollbackConnection(con);
          ImportOrderData.importOrderError(conn, ex.toString(), I_Order_ID);
          noInsert--;
          continue;
        }
        data[i].cOrderlineId = line.cOrderlineId;
        data[i].iIsimported = "Y";
        data[i].processed = "Y";
        data[i].update(con, conn);
        String[] arrayPayment = { data[i].paymentrule1, data[i].paymentrule2 };
        String[] arrayAmount = { data[i].paymentamount1, data[i].paymentamount2 };
        for (int k = 0; k < arrayPayment.length; k++) {
          if (!arrayPayment[k].equals("")) {
            CDebtpaymentData cdebtpayment = new CDebtpaymentData();
            cdebtpayment.adClientId = data[i].adClientId;
            cdebtpayment.adOrgId = data[i].adOrgId;
            cdebtpayment.createdby = getAD_User_ID();
            cdebtpayment.updatedby = getAD_User_ID();
            cdebtpayment.cBpartnerId = corder_cbpartnerid;
            cdebtpayment.cCurrencyId = corder_ccurrencyid;
            /*
             * cdebtpayment.cBankaccountId = ; cdebtpayment.cCashbookId = ;
             */
            cdebtpayment.paymentrule = arrayPayment[k];
            cdebtpayment.amount = arrayAmount[k];
            cdebtpayment.ispaid = "N";
            cdebtpayment.dateplanned = data[i].dateordered.equals("") ? DateTimeData.today(conn)
                : data[i].dateordered;
            cdebtpayment.ismanual = "N";
            cdebtpayment.isvalid = "Y";
            cdebtpayment.changesettlementcancel = "N";
            cdebtpayment.cancelProcessed = "N";
            cdebtpayment.generateProcessed = "N";
            cdebtpayment.glitemamt = "0";
            cdebtpayment.isdirectposting = "N";
            cdebtpayment.status = "DE";
            cdebtpayment.statusInitial = "DE";
            cdebtpayment.cOrderId = data[i].cOrderId;
            // Looking for same payment yet inserted
            ImportOrderData[] paymentInserted = ImportOrderData.selectPaymentInserted(conn,
                cdebtpayment.adClientId, cdebtpayment.adOrgId, cdebtpayment.createdby,
                cdebtpayment.updatedby, cdebtpayment.cBpartnerId, cdebtpayment.cCurrencyId,
                cdebtpayment.paymentrule, cdebtpayment.amount, cdebtpayment.ispaid,
                cdebtpayment.ismanual, cdebtpayment.isvalid, cdebtpayment.changesettlementcancel,
                cdebtpayment.cancelProcessed, cdebtpayment.generateProcessed,
                cdebtpayment.glitemamt, cdebtpayment.isdirectposting, cdebtpayment.status,
                cdebtpayment.statusInitial, cdebtpayment.cOrderId);
            if (paymentInserted != null && paymentInserted.length == 0) {
              try {
                cdebtpayment.cDebtPaymentId = SequenceIdData.getUUID();
                cdebtpayment.insert(con, conn);
              } catch (ServletException ex) {
                if (log4j.isDebugEnabled())
                  log4j.debug("Insert Order - " + ex.toString());
                conn.releaseRollbackConnection(con);
                ImportOrderData.importOrderError(conn, ex.toString(), I_Order_ID);
                noInsert--;
                continue;
              }
            }
          }
        }

        try {
          if (data[i].performPost.equals("Y") || m_processOrders) {
            if (i != data.length - 1) {
              if (!order_documentno.equals(data[i + 1].documentno))
                strPostMessage += cOrderPost(con, conn, vars, data[i].cOrderId, order_documentno)
                    + "<br>";
            } else {
              strPostMessage += cOrderPost(con, conn, vars, data[i].cOrderId, order_documentno)
                  + "<br>";
            }
          }
        } catch (IOException e) {
          e.printStackTrace();
          log4j.debug("Post error");
          ImportOrderData.updatePostError(con, conn, strPostMessage, data[i].orderReferenceno,
              getAD_Client_ID());
        }
        noInsertLine++;
        conn.releaseCommitConnection(con);
      }
      con = conn.getTransactionConnection();
      noOrderError = ImportOrderData.updateNotImported(con, conn, getAD_Client_ID());

      if (noOrderError > 0) {
        addLog(Utility.messageBD(conn, "Order lines not imported", vars.getLanguage()) + ": "
            + noOrderError + "; ");
      }
      addLog("Orders inserted: " + noInsert + "; ");
      addLog("Orders line inserted: " + noInsertLine + "; " + "<br>");
      if (noInsert > totalProcessed) {
        addLog(Utility.messageBD(conn, "Orders not processed", vars.getLanguage()) + ": "
            + (noInsert - totalProcessed) + "; ");
      }
      addLog("Orders processed: " + Integer.toString(totalProcessed) + "; " + "<br>");
      if (strPostMessage != null && !strPostMessage.equals("")) {
        addLog("Process result: " + "<br>" + strPostMessage);
      }

      if (noOrderError == 0 && noInsert == totalProcessed) {
        myError.setType("Success");
        myError.setTitle(Utility.messageBD(conn, "Success", vars.getLanguage()));
      } else if (noInsert > 0 || noInsertLine > 0) {
        myError.setType("Warning");
        myError.setTitle(Utility.messageBD(conn, "Some orders could not be imported or processed",
            vars.getLanguage()));
      } else {
        myError.setType("Error");
        myError.setTitle(Utility
            .messageBD(conn, " No orders could be imported", vars.getLanguage()));
      }
      myError.setMessage(Utility.messageBD(conn, getLog(), vars.getLanguage()));

      conn.releaseCommitConnection(con);
    } catch (NoConnectionAvailableException ex) {
      throw new ServletException("@CODE=NoConnectionAvailable");
    } catch (SQLException ex2) {
      try {
        conn.releaseRollbackConnection(con);
      } catch (Exception ignored) {
      }
      throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@"
          + ex2.getMessage());
    } catch (Exception ex3) {
      try {
        conn.releaseRollbackConnection(con);
      } catch (Exception ignored) {
      }
      throw new ServletException("@CODE=@" + ex3.getMessage());
    }
    return myError;
View Full Code Here

  public void contextInitialized(ServletContextEvent event) {
    ServletContext context = event.getServletContext();
    ConfigParameters configParameters = ConfigParameters.retrieveFrom(context);

    try {
      ConnectionProvider pool = createPool(configParameters);
      context.setAttribute(POOL_ATTRIBUTE, pool);
    } catch (PoolNotFoundException e) {
      log4j.error("Unable to create a connection pool", e);
    }
View Full Code Here

  public static ConnectionProvider getPool(ServletContext context) {
    return (ConnectionProvider) context.getAttribute(POOL_ATTRIBUTE);
  }

  public static void reloadPool(ServletContext context) throws Exception {
    ConnectionProvider pool = getPool(context);
    if (pool instanceof ConnectionProviderImpl) {
      ConfigParameters configParameters = ConfigParameters.retrieveFrom(context);
      String strPoolFile = configParameters.getPoolFilePath();
      boolean isRelative = !strPoolFile.startsWith("/") && !strPoolFile.substring(1, 1).equals(":");
      ((ConnectionProviderImpl) pool).reload(strPoolFile, isRelative, configParameters.strContext);
View Full Code Here

TOP

Related Classes of org.openbravo.database.ConnectionProvider

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.