Search in sources :

Example 16 with MBPartnerLocation

use of org.compiere.model.MBPartnerLocation in project adempiere by adempiere.

the class WebUser method load.

/**
	 * 	Load Contact
	 * 	@param email email
	 *	@param password optional password
	 */
private void load(String email, String password) {
    log.info(email + " - AD_Client_ID=" + m_AD_Client_ID);
    String sql = "SELECT * " + "FROM AD_User " + "WHERE AD_Client_ID=?" + " AND TRIM(EMail)=?";
    if (email == null)
        email = "";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, m_AD_Client_ID);
        pstmt.setString(2, email.trim());
        rs = pstmt.executeQuery();
        if (rs.next()) {
            m_bpc = new MUser(m_ctx, rs, null);
            log.fine("Found BPC=" + m_bpc);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //	Check Password
    m_passwordOK = false;
    //	We have a password
    if (m_bpc != null && password != null && authenticateHash(password))
        m_passwordOK = true;
    if (m_passwordOK || m_bpc == null)
        m_passwordMessage = null;
    else
        setPasswordOK(false, password);
    //	Load BPartner
    if (m_bpc != null) {
        m_bp = new MBPartner(m_ctx, m_bpc.getC_BPartner_ID(), null);
        log.fine("Found BP=" + m_bp);
    } else
        m_bp = null;
    //	Load Loacation
    if (m_bpc != null) {
        if (m_bpc.getC_BPartner_Location_ID() != 0) {
            m_bpl = new MBPartnerLocation(m_ctx, m_bpc.getC_BPartner_Location_ID(), null);
            log.fine("Found BPL=" + m_bpl);
        } else {
            MBPartnerLocation[] bpls = m_bp.getLocations(false);
            if (bpls != null && bpls.length > 0) {
                m_bpl = bpls[0];
                log.fine("Found BPL=" + m_bpl);
            }
        }
        if (m_bpl != null) {
            m_loc = MLocation.get(m_ctx, m_bpl.getC_Location_ID(), null);
            log.fine("Found LOC=" + m_loc);
        } else
            m_loc = null;
    } else {
        m_bpl = null;
        m_loc = null;
    }
    //	Make sure that all entities exist
    if (m_bpc == null) {
        m_bpc = new MUser(m_ctx, 0, null);
        m_bpc.setEMail(email);
        m_bpc.setPassword(password);
    }
    if (m_bp == null) {
        //	template
        m_bp = new MBPartner(m_ctx);
        m_bp.setIsCustomer(true);
    }
    if (m_bpl == null)
        m_bpl = new MBPartnerLocation(m_bp);
    if (m_loc == null)
        m_loc = new MLocation(m_ctx, 0, null);
    //
    log.config(m_bp + " - " + m_bpc);
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MBPartner(org.compiere.model.MBPartner) MUser(org.compiere.model.MUser) MLocation(org.compiere.model.MLocation) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Example 17 with MBPartnerLocation

use of org.compiere.model.MBPartnerLocation in project adempiere by adempiere.

the class WebUser method load.

//	load
/**
	 * 	Load Contact
	 * 	@param AD_User_ID BP Contact
	 */
private void load(int AD_User_ID) {
    log.info("ID=" + AD_User_ID + ", AD_Client_ID=" + m_AD_Client_ID);
    String sql = "SELECT * " + "FROM AD_User " + "WHERE AD_Client_ID=?" + " AND AD_User_ID=?";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, m_AD_Client_ID);
        pstmt.setInt(2, AD_User_ID);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            m_bpc = new MUser(m_ctx, rs, null);
            log.fine("= found BPC=" + m_bpc);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //	Password not entered
    m_passwordOK = false;
    m_loggedIn = false;
    //	Load BPartner
    if (m_bpc != null) {
        m_bp = new MBPartner(m_ctx, m_bpc.getC_BPartner_ID(), null);
        log.fine("= Found BP=" + m_bp);
    } else
        m_bp = null;
    //	Load Loacation
    if (m_bpc != null) {
        if (m_bpc.getC_BPartner_Location_ID() != 0) {
            m_bpl = new MBPartnerLocation(m_ctx, m_bpc.getC_BPartner_Location_ID(), null);
            log.fine("= Found BPL=" + m_bpl);
        } else {
            MBPartnerLocation[] bpls = m_bp.getLocations(false);
            if (bpls != null && bpls.length > 0) {
                m_bpl = bpls[0];
                log.fine("= Found BPL=" + m_bpl);
            }
        }
        if (m_bpl != null) {
            m_loc = MLocation.get(m_ctx, m_bpl.getC_Location_ID(), null);
            log.fine("= Found LOC=" + m_loc);
        } else
            m_loc = null;
    } else {
        m_bpl = null;
        m_loc = null;
    }
    //	Make sure that all entities exist
    if (m_bpc == null) {
        m_bpc = new MUser(m_ctx, 0, null);
        m_bpc.setEMail("?");
        m_bpc.setPassword("?");
    }
    if (m_bp == null) {
        //	template
        m_bp = new MBPartner(m_ctx);
        m_bp.setIsCustomer(true);
    }
    if (m_bpl == null)
        m_bpl = new MBPartnerLocation(m_bp);
    if (m_loc == null)
        m_loc = new MLocation(m_ctx, 0, null);
    //
    log.info("= " + m_bp + " - " + m_bpc);
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MBPartner(org.compiere.model.MBPartner) MUser(org.compiere.model.MUser) MLocation(org.compiere.model.MLocation) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Example 18 with MBPartnerLocation

use of org.compiere.model.MBPartnerLocation in project adempiere by adempiere.

the class InventoryUtil method getCreatePartner.

public static MBPartner getCreatePartner(String value) {
    Properties ctx = Env.getCtx();
    final String whereClause = MBPartner.COLUMNNAME_Value + "=?";
    MBPartner bp = new Query(ctx, I_C_BPartner.Table_Name, whereClause, null).setParameters(value).setClient_ID().firstOnly();
    if (bp == null) {
        bp = new MBPartner(ctx, 0, null);
    }
    bp.setValue(value);
    bp.setName(value);
    setGeneratedTag(bp);
    bp.setIsCustomer(true);
    bp.setIsVendor(true);
    bp.setC_BP_Group_ID(MBPGroup.getDefault(ctx).get_ID());
    bp.saveEx();
    //
    if (bp.getLocations(false).length == 0) {
        MLocation loc = new MLocation(ctx, 0, null);
        loc.saveEx();
        //
        MBPartnerLocation bpl = new MBPartnerLocation(bp);
        bpl.setC_Location_ID(loc.get_ID());
        bpl.saveEx();
    }
    return bp;
}
Also used : Query(org.compiere.model.Query) MBPartner(org.compiere.model.MBPartner) Properties(java.util.Properties) MLocation(org.compiere.model.MLocation) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Aggregations

MBPartnerLocation (org.compiere.model.MBPartnerLocation)18 MBPartner (org.compiere.model.MBPartner)13 MLocation (org.compiere.model.MLocation)10 MUser (org.compiere.model.MUser)9 ResultSet (java.sql.ResultSet)6 BigDecimal (java.math.BigDecimal)5 PreparedStatement (java.sql.PreparedStatement)5 SQLException (java.sql.SQLException)4 Query (org.compiere.model.Query)4 Properties (java.util.Properties)3 Timestamp (java.sql.Timestamp)2 MInvoice (org.compiere.model.MInvoice)2 MLocator (org.compiere.model.MLocator)2 MOrderLine (org.compiere.model.MOrderLine)2 MOrg (org.compiere.model.MOrg)2 AdempiereUserError (org.compiere.util.AdempiereUserError)2 KeyNamePair (org.compiere.util.KeyNamePair)2 File (java.io.File)1 LocalDate (java.time.LocalDate)1 ZoneId (java.time.ZoneId)1