コード例 #1
0
ファイル: MyValidator.java プロジェクト: xinliuswie/idempiere
  /**
   * Initialize Validation
   *
   * @param engine validation engine
   * @param client client
   */
  public void initialize(ModelValidationEngine engine, MClient client) {
    // client = null for global validator
    if (client != null) {
      m_AD_Client_ID = client.getAD_Client_ID();
      if (log.isLoggable(Level.INFO)) log.info(client.toString());
    } else {
      if (log.isLoggable(Level.INFO)) log.info("Initializing global validator: " + this.toString());
    }

    //	We want to be informed when C_Order is created/changed
    engine.addModelChange(MOrder.Table_Name, this);
    //	We want to validate Order before preparing
    engine.addDocValidate(MOrder.Table_Name, this);
  } //	initialize
コード例 #2
0
 /**
  * ************************************************************************ Receive notification
  * of the start of an element.
  *
  * @param uri namespace
  * @param localName simple name
  * @param qName qualified name
  * @param attributes attributes
  * @throws org.xml.sax.SAXException
  */
 public void startElement(String uri, String localName, String qName, Attributes attributes)
     throws org.xml.sax.SAXException {
   //	log.fine( "TranslationHandler.startElement", qName);	// + " - " + uri + " - " + localName);
   if (qName.equals(Translation.XML_TAG)
       || qName.equals(Translation.XML_TAG2)
       || qName.equals(Translation.XML_TAG3)) {
     m_AD_Language = attributes.getValue(Translation.XML_ATTRIBUTE_LANGUAGE);
     m_isBaseLanguage = Language.isBaseLanguage(m_AD_Language);
     m_TableName = attributes.getValue(Translation.XML_ATTRIBUTE_TABLE);
     m_updateSQL = "UPDATE " + m_TableName;
     if (!m_isBaseLanguage) m_updateSQL += "_Trl";
     m_updateSQL += " SET ";
     if (log.isLoggable(Level.FINE))
       log.fine(
           "AD_Language="
               + m_AD_Language
               + ", Base="
               + m_isBaseLanguage
               + ", TableName="
               + m_TableName);
   } else if (qName.equals(Translation.XML_ROW_TAG)) {
     m_curID = attributes.getValue(Translation.XML_ROW_ATTRIBUTE_ID);
     m_curUUID = attributes.getValue(Translation.XML_ROW_ATTRIBUTE_UUID);
     m_trl = attributes.getValue(Translation.XML_ROW_ATTRIBUTE_TRANSLATED);
     //	log.finest( "ID=" + m_curID);
     m_sql = new StringBuffer();
   } else if (qName.equals(Translation.XML_VALUE_TAG)) {
     m_curColumnName = attributes.getValue(Translation.XML_VALUE_ATTRIBUTE_COLUMN);
     //	log.finest( "ColumnName=" + m_curColName);
   } else log.severe("UNKNOWN TAG: " + qName);
   m_curValue = new StringBuffer();
 } //	startElement
コード例 #3
0
ファイル: MyValidator.java プロジェクト: xinliuswie/idempiere
 /**
  * Model Change of a monitored Table. Called after PO.beforeSave/PO.beforeDelete when you called
  * addModelChange for the table
  *
  * @param po persistent object
  * @param type TYPE_
  * @return error message or null
  * @exception Exception if the recipient wishes the change to be not accept.
  */
 public String modelChange(PO po, int type) throws Exception {
   if (po.get_TableName().equals("C_Order") && type == TYPE_CHANGE) {
     @SuppressWarnings("unused")
     MOrder order = (MOrder) po;
     if (log.isLoggable(Level.INFO)) log.info(po.toString());
   }
   return null;
 } //	modelChange
コード例 #4
0
ファイル: MyValidator.java プロジェクト: xinliuswie/idempiere
  /**
   * Validate Document. Called as first step of DocAction.prepareIt when you called addDocValidate
   * for the table. Note that totals, etc. may not be correct.
   *
   * @param po persistent object
   * @param timing see TIMING_ constants
   * @return error message or null
   */
  public String docValidate(PO po, int timing) {
    if (log.isLoggable(Level.INFO)) log.info(po.get_TableName() + " Timing: " + timing);

    //	Ignore all after Complete events
    if (timing == TIMING_AFTER_COMPLETE) return null;

    if (timing == TIMING_BEFORE_PREPARE) {
      if (po.get_TableName().equals(MOrder.Table_Name)) {
        /**
         * Order Discount Example * MOrder order = (MOrder)po; String error = orderDiscount(order);
         * if (error != null) return error; /** Order Discount Example
         */
        if (log.isLoggable(Level.INFO)) log.info(po.toString());
      }
    }

    return null;
  } //	docValidate
コード例 #5
0
 /** Fill Table */
 private Vector<Vector<Object>> fillTable(String sql, int parameter) {
   if (log.isLoggable(Level.FINE)) log.fine(sql + "; Parameter=" + parameter);
   Vector<Vector<Object>> data = new Vector<Vector<Object>>();
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
     pstmt = DB.prepareStatement(sql, null);
     pstmt.setInt(1, parameter);
     rs = pstmt.executeQuery();
     while (rs.next()) {
       Vector<Object> line = new Vector<Object>(6);
       //	0-Name, 1-PriceActual, 2-QtyInvoiced, 3-Discount, 4-DocumentNo, 5-DateInvoiced
       line.add(rs.getString(1)); //  Name
       line.add(rs.getBigDecimal(2)); // 	Price
       line.add(rs.getString(3)); // 	Currency
       line.add(new Double(rs.getDouble(5))); //  Qty
       BigDecimal discountBD = rs.getBigDecimal(9);
       if (discountBD == null) {
         double priceList = rs.getDouble(4);
         double priceActual = rs.getDouble(2);
         if (priceList != 0) {
           discountBD = BigDecimal.valueOf((priceList - priceActual) / priceList * 100);
           // Rounding:
           int precision = MPriceList.getStandardPrecision(Env.getCtx(), rs.getInt(10));
           if (discountBD.scale() > precision)
             discountBD = discountBD.setScale(precision, RoundingMode.HALF_UP);
         } else discountBD = Env.ZERO;
       }
       line.add(discountBD); //  Discount
       line.add(rs.getString(7)); //  DocNo
       line.add(rs.getTimestamp(6)); //  Date
       line.add(rs.getString(8)); // 	Org/Warehouse
       data.add(line);
     }
   } catch (SQLException e) {
     log.log(Level.SEVERE, sql, e);
   } finally {
     DB.close(rs, pstmt);
     rs = null;
     pstmt = null;
   }
   if (log.isLoggable(Level.FINE)) log.fine("#" + data.size());
   return data;
 } //	fillTable
コード例 #6
0
  /**
   * Receive notification of the end of an element.
   *
   * @param uri namespace
   * @param localName simple name
   * @param qName qualified name
   * @throws SAXException
   */
  public void endElement(String uri, String localName, String qName) throws SAXException {
    //	Log.trace(Log.l6_Database+1, "TranslationHandler.endElement", qName);
    if (qName.equals(Translation.XML_TAG)
        || qName.equals(Translation.XML_TAG2)
        || qName.equals(Translation.XML_TAG3)) {

    } else if (qName.equals(Translation.XML_ROW_TAG)) {
      //	Set section
      if (m_sql.length() > 0) m_sql.append(",");
      m_sql.append("Updated=").append(DB.TO_DATE(m_time, false));
      if (!m_isBaseLanguage) {
        if (m_trl != null && ("Y".equals(m_trl) || "N".equals(m_trl)))
          m_sql.append(",IsTranslated='").append(m_trl).append("'");
        else m_sql.append(",IsTranslated='Y'");
      }
      //	Where section
      m_sql.append(" WHERE ");
      if (m_curUUID != null) {
        StringBuilder sql =
            new StringBuilder("SELECT ")
                .append(m_TableName)
                .append("_ID")
                .append(" FROM ")
                .append(m_TableName)
                .append(" WHERE ")
                .append(m_TableName)
                .append("_UU =?");
        int ID = DB.getSQLValueEx(null, sql.toString(), m_curUUID);
        m_sql.append(m_TableName).append("_ID=").append(ID);
      } else {
        m_sql.append(m_TableName).append("_ID=").append(m_curID);
      }
      if (!m_isBaseLanguage) m_sql.append(" AND AD_Language='").append(m_AD_Language).append("'");
      if (m_AD_Client_ID >= 0) m_sql.append(" AND AD_Client_ID=").append(m_AD_Client_ID);
      //	Update section
      m_sql.insert(0, m_updateSQL);

      //	Execute
      int no = DB.executeUpdate(m_sql.toString(), null);
      if (no == 1) {
        if (log.isLoggable(Level.FINE)) log.fine(m_sql.toString());
        m_updateCount++;
      } else if (no == 0) log.warning("Not Found - " + m_sql.toString());
      else log.severe("Update Rows=" + no + " (Should be 1) - " + m_sql.toString());
    } else if (qName.equals(Translation.XML_VALUE_TAG)) {
      if (m_sql.length() > 0) m_sql.append(",");
      m_sql.append(m_curColumnName).append("=").append(DB.TO_STRING(m_curValue.toString()));
    }
  } //	endElement
コード例 #7
0
  /**
   * Process the HTTP Get request. (logout, deleteCookie) Sends Web Request Page
   *
   * @param request request
   * @param response response
   * @throws ServletException
   * @throws IOException
   */
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    if (log.isLoggable(Level.INFO))
      log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr());

    String url = "/invoices.jsp";
    //
    HttpSession session = request.getSession(false);
    if (session == null || session.getAttribute(WebInfo.NAME) == null) url = "/login.jsp";
    else {
      session.removeAttribute(WebSessionCtx.HDR_MESSAGE);
      WebInfo info = (WebInfo) session.getAttribute(WebInfo.NAME);
      if (info != null) info.setMessage("");

      //	Parameter = Invoice_ID - if invoice is valid and belongs to wu then create PDF & stream it
      String msg = streamInvoice(request, response);
      if (msg == null || msg.length() == 0) return;
      if (info != null) info.setMessage(msg);
    }

    if (log.isLoggable(Level.INFO)) log.info("Forward to " + url);
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
    dispatcher.forward(request, response);
  } //	doGet
コード例 #8
0
ファイル: DocLine.java プロジェクト: jabbp/idempierecartao
 /**
  * Get SalesRegion. - get Sales Region from BPartner
  *
  * @return C_SalesRegion_ID
  */
 public int getC_SalesRegion_ID() {
   if (m_C_SalesRegion_ID == -1) // 	never tried
   {
     if (getC_BPartner_Location_ID() != 0)
     //	&& m_acctSchema.isAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_SalesRegion))
     {
       String sql =
           "SELECT COALESCE(C_SalesRegion_ID,0) FROM C_BPartner_Location WHERE C_BPartner_Location_ID=?";
       m_C_SalesRegion_ID = DB.getSQLValue(null, sql, getC_BPartner_Location_ID());
       if (log.isLoggable(Level.FINE))
         log.fine("C_SalesRegion_ID=" + m_C_SalesRegion_ID + " (from BPL)");
       if (m_C_SalesRegion_ID == 0) m_C_SalesRegion_ID = -2; // 	don't try again
     } else m_C_SalesRegion_ID = -2; // 	don't try again
   }
   if (m_C_SalesRegion_ID < 0) // 	invalid
   return 0;
   return m_C_SalesRegion_ID;
 } //  getC_SalesRegion_ID
コード例 #9
0
ファイル: MyValidator.java プロジェクト: xinliuswie/idempiere
 /**
  * User Login. Called when preferences are set
  *
  * @param AD_Org_ID org
  * @param AD_Role_ID role
  * @param AD_User_ID user
  * @return error message or null
  */
 public String login(int AD_Org_ID, int AD_Role_ID, int AD_User_ID) {
   if (log.isLoggable(Level.INFO)) log.info("AD_User_ID=" + AD_User_ID);
   m_AD_User_ID = AD_User_ID;
   m_AD_Role_ID = AD_Role_ID;
   return null;
 } //	login
コード例 #10
0
  /** Query Unconfirmed */
  private void initUnconfirmedTab() {
    //	Done already
    if (m_modelUnconfirmed != null) return;

    //	Header
    Vector<String> columnNames = new Vector<String>();
    columnNames.add(
        Msg.translate(Env.getCtx(), m_C_BPartner_ID == 0 ? "C_BPartner_ID" : "M_Product_ID"));
    columnNames.add(Msg.translate(Env.getCtx(), "MovementQty"));
    columnNames.add(Msg.translate(Env.getCtx(), "MovementDate"));
    columnNames.add(Msg.translate(Env.getCtx(), "IsSOTrx"));
    columnNames.add(Msg.translate(Env.getCtx(), "DocumentNo"));
    columnNames.add(Msg.translate(Env.getCtx(), "M_Warehouse_ID"));

    //	Fill Data
    String sql = null;
    int parameter = 0;
    if (m_C_BPartner_ID == 0) {
      sql =
          "SELECT bp.Name,"
              + " CASE WHEN io.IsSOTrx='Y' THEN iol.MovementQty*-1 ELSE iol.MovementQty END AS MovementQty,"
              + " io.MovementDate,io.IsSOTrx,"
              + " dt.PrintName || ' ' || io.DocumentNo As DocumentNo,"
              + " w.Name "
              + "FROM M_InOutLine iol"
              + " INNER JOIN M_InOut io ON (iol.M_InOut_ID=io.M_InOut_ID)"
              + " INNER JOIN C_BPartner bp  ON (io.C_BPartner_ID=bp.C_BPartner_ID)"
              + " INNER JOIN C_DocType dt ON (io.C_DocType_ID=dt.C_DocType_ID)"
              + " INNER JOIN M_Warehouse w ON (io.M_Warehouse_ID=w.M_Warehouse_ID)"
              + " INNER JOIN M_InOutLineConfirm lc ON (iol.M_InOutLine_ID=lc.M_InOutLine_ID) "
              + "WHERE iol.M_Product_ID=?"
              + " AND lc.Processed='N' "
              + "ORDER BY io.MovementDate,io.IsSOTrx";
      parameter = m_M_Product_ID;
    } else {
      sql =
          "SELECT p.Name,"
              + " CASE WHEN io.IsSOTrx='Y' THEN iol.MovementQty*-1 ELSE iol.MovementQty END AS MovementQty,"
              + " io.MovementDate,io.IsSOTrx,"
              + " dt.PrintName || ' ' || io.DocumentNo As DocumentNo,"
              + " w.Name "
              + "FROM M_InOutLine iol"
              + " INNER JOIN M_InOut io ON (iol.M_InOut_ID=io.M_InOut_ID)"
              + " INNER JOIN M_Product p  ON (iol.M_Product_ID=p.M_Product_ID)"
              + " INNER JOIN C_DocType dt ON (io.C_DocType_ID=dt.C_DocType_ID)"
              + " INNER JOIN M_Warehouse w ON (io.M_Warehouse_ID=w.M_Warehouse_ID)"
              + " INNER JOIN M_InOutLineConfirm lc ON (iol.M_InOutLine_ID=lc.M_InOutLine_ID) "
              + "WHERE io.C_BPartner_ID=?"
              + " AND lc.Processed='N' "
              + "ORDER BY io.MovementDate,io.IsSOTrx";
      parameter = m_C_BPartner_ID;
    }
    Vector<Vector<Object>> data = new Vector<Vector<Object>>();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      pstmt.setInt(1, parameter);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        Vector<Object> line = new Vector<Object>(6);
        //	1-Name, 2-MovementQty, 3-MovementDate, 4-IsSOTrx, 5-DocumentNo
        line.add(rs.getString(1)); //  Name
        line.add(new Double(rs.getDouble(2))); //  Qty
        line.add(rs.getTimestamp(3)); //  Date
        line.add(new Boolean("Y".equals(rs.getString(4)))); //  IsSOTrx
        line.add(rs.getString(5)); //  DocNo
        line.add(rs.getString(6)); //  Warehouse
        data.add(line);
      }
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }
    if (log.isLoggable(Level.FINE)) log.fine("#" + data.size());

    //  Table
    m_modelUnconfirmed = new ListModelTable(data);
    m_tableUnconfirmed.setData(m_modelUnconfirmed, columnNames);
    //
    m_tableUnconfirmed.setColumnClass(0, String.class, true); //  Product/Partner
    m_tableUnconfirmed.setColumnClass(1, Double.class, true); //  MovementQty
    m_tableUnconfirmed.setColumnClass(2, Timestamp.class, true); //  MovementDate
    m_tableUnconfirmed.setColumnClass(3, Boolean.class, true); //  IsSOTrx
    m_tableUnconfirmed.setColumnClass(4, String.class, true); //  DocNo
    //
    m_tableUnconfirmed.autoSize();
  } //	initUnconfirmedTab
コード例 #11
0
 /** Set Label to product or bp name */
 private void fillLabel(String sql, int parameter) {
   if (log.isLoggable(Level.FINE)) log.fine(sql + "; Parameter=" + parameter);
   String retValue = DB.getSQLValueString(null, sql, parameter);
   if (retValue != null) label.setText(retValue);
 } //	fillLabel
コード例 #12
0
  /**
   * Stream invoice
   *
   * @param request request
   * @param response response
   * @return "" or error message
   */
  private String streamInvoice(HttpServletRequest request, HttpServletResponse response) {
    int MIN_SIZE = 2000; // 	if not created size is 1015

    //	Get Invoice ID
    int C_Invoice_ID = WebUtil.getParameterAsInt(request, "Invoice_ID");
    if (C_Invoice_ID == 0) {
      log.fine("No ID)");
      return "No Invoice ID";
    }

    //	Get Invoice
    Properties ctx = JSPEnv.getCtx(request);
    MInvoice invoice = new MInvoice(ctx, C_Invoice_ID, null);
    if (invoice.getC_Invoice_ID() != C_Invoice_ID) {
      if (log.isLoggable(Level.FINE)) log.fine("Invoice not found - ID=" + C_Invoice_ID);
      return "Invoice not found";
    }
    //	Get WebUser & Compare with invoice
    HttpSession session = request.getSession(true);
    WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
    if (wu.getC_BPartner_ID() != invoice.getC_BPartner_ID()) {
      log.warning(
          "Invoice from BPartner - C_Invoice_ID="
              + C_Invoice_ID
              + " - BP_Invoice="
              + invoice.getC_BPartner_ID()
              + " = BP_Web="
              + wu.getC_BPartner_ID());
      return "Your invoice not found";
    }

    //	Check Directory
    String dirName = ctx.getProperty("documentDir", ".");
    try {
      File dir = new File(dirName);
      if (!dir.exists()) dir.mkdir();
    } catch (Exception ex) {
      log.log(Level.SEVERE, "Could not create directory " + dirName, ex);
      return "Streaming error - directory";
    }
    //	Check if Invoice already created
    String fileName = invoice.getPDFFileName(dirName);
    File file = new File(fileName);
    if (file.exists() && file.isFile() && file.length() > MIN_SIZE) {
      if (log.isLoggable(Level.INFO))
        log.info("Existing: " + file + " - " + new Timestamp(file.lastModified()));
    } else {
      if (log.isLoggable(Level.INFO)) log.info("New: " + fileName);
      file = invoice.createPDF(file);
      if (file != null) {
        invoice.setDatePrinted(new Timestamp(System.currentTimeMillis()));
        invoice.saveEx();
      }
    }
    //	Issue Error
    if (file == null || !file.exists() || file.length() < MIN_SIZE) {
      log.warning("File does not exist - " + file);
      return "Streaming error - file";
    }

    //	Send PDF
    try {
      int bufferSize = 2048; // 	2k Buffer
      int fileLength = (int) file.length();
      //
      response.setContentType("application/pdf");
      response.setBufferSize(bufferSize);
      response.setContentLength(fileLength);
      //
      if (log.isLoggable(Level.FINE)) log.fine(file.getAbsolutePath() + ", length=" + fileLength);
      long time = System.currentTimeMillis(); // 	timer start
      //
      FileInputStream in = new FileInputStream(file);
      ServletOutputStream out = response.getOutputStream();
      byte[] buffer = new byte[bufferSize];
      double totalSize = 0;
      int count = 0;
      do {
        count = in.read(buffer, 0, bufferSize);
        if (count > 0) {
          totalSize += count;
          out.write(buffer, 0, count);
        }
      } while (count != -1);
      out.flush();
      out.close();
      //
      in.close();
      time = System.currentTimeMillis() - time;
      double speed = (totalSize / 1024) / ((double) time / 1000);
      if (log.isLoggable(Level.FINE))
        log.fine("Length=" + totalSize + " - " + time + " ms - " + speed + " kB/sec");
    } catch (IOException ex) {
      log.log(Level.SEVERE, ex.toString());
      return "Streaming error";
    }

    return null;
  } //	streamInvoice
コード例 #13
0
 /**
  * Process the HTTP Post request
  *
  * @param request request
  * @param response response
  * @throws ServletException
  * @throws IOException
  */
 public void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   if (log.isLoggable(Level.INFO))
     log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr());
   doGet(request, response);
 } //	doPost