use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class SearchServlet method getAllPartners.
/**
* Get all Business Partners
* NOTE: I think this logic is elsewhere already, so making it private until the correct call can be made
*
* @param ctx context
* @return partners
*/
private MBPartner[] getAllPartners(Properties ctx) {
ArrayList<MBPartner> list = new ArrayList<MBPartner>();
String sql = "SELECT * FROM C_BPartner";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
while (rs.next()) {
MBPartner partner = new MBPartner(ctx, rs, null);
//s_cache.put (new Integer (partner.getAD_Client_ID()), partner);
list.add(partner);
}
} catch (Exception e) {
//s_log.log(Level.SEVERE, sql, e);
log.severe(e.getMessage());
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
MBPartner[] retValue = new MBPartner[list.size()];
list.toArray(retValue);
return retValue;
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class WBPartner method loadBPartner.
// getGreeting
/**
* Load BPartner
* @param C_BPartner_ID - existing BPartner or 0 for new
* @return true if loaded
*/
public boolean loadBPartner(int C_BPartner_ID) {
log.config("C_BPartner_ID=" + C_BPartner_ID);
// New bpartner
if (C_BPartner_ID == 0) {
m_partner = null;
m_pLocation = null;
m_user = null;
return true;
}
m_partner = new MBPartner(Env.getCtx(), C_BPartner_ID, null);
if (m_partner.get_ID() == 0) {
FDialog.error(m_WindowNo, this, "BPartnerNotFound");
return false;
}
// BPartner - Load values
fValue.setText(m_partner.getValue());
KeyNamePair keynamepair = getGreeting(m_partner.getC_Greeting_ID());
for (int i = 0; i < fGreetingBP.getItemCount(); i++) {
ListItem listitem = fGreetingBP.getItemAtIndex(i);
KeyNamePair compare = (KeyNamePair) listitem.getValue();
if (compare == keynamepair) {
fGreetingBP.setSelectedIndex(i);
break;
}
}
fName.setText(m_partner.getName());
fName2.setText(m_partner.getName2());
fTaxId.setText(m_partner.getTaxID());
// Contact - Load values
m_pLocation = m_partner.getLocation(Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_BPartner_Location_ID"));
if (m_pLocation != null) {
int location = m_pLocation.getC_Location_ID();
fAddress.setValue(new Integer(location));
fPhone.setText(m_pLocation.getPhone());
fPhone2.setText(m_pLocation.getPhone2());
fFax.setText(m_pLocation.getFax());
}
// User - Load values
m_user = m_partner.getContact(Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_User_ID"));
if (m_user != null) {
keynamepair = getGreeting(m_user.getC_Greeting_ID());
for (int i = 0; i < fGreetingC.getItemCount(); i++) {
ListItem listitem = fGreetingC.getItemAtIndex(i);
KeyNamePair compare = (KeyNamePair) listitem.getValue();
if (compare == keynamepair) {
fGreetingC.setSelectedIndex(i);
break;
}
}
fContact.setText(m_user.getName());
fTitle.setText(m_user.getTitle());
fEMail.setText(m_user.getEMail());
fPhone.setText(m_user.getPhone());
fPhone2.setText(m_user.getPhone2());
fFax.setText(m_user.getFax());
}
return true;
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class PaySelectionCreateCheck method createCheck.
// doIt
/**
* Create Check from line
* @param line
* @throws Exception for invalid bank accounts
*/
private void createCheck(MPaySelectionLine line) throws Exception {
// Try to find one
for (int i = 0; i < paySelectionChecks.size(); i++) {
MPaySelectionCheck check = (MPaySelectionCheck) paySelectionChecks.get(i);
// Add to existing
if (check.getC_BPartner_ID() == line.getInvoice().getC_BPartner_ID()) {
check.addLine(line);
if (!check.save())
throw new IllegalStateException("Cannot save MPaySelectionCheck");
line.setC_PaySelectionCheck_ID(check.getC_PaySelectionCheck_ID());
line.setProcessed(true);
if (!line.save())
throw new IllegalStateException("Cannot save MPaySelectionLine");
return;
}
}
// Create new
String PaymentRule = line.getPaymentRule();
if (p_PaymentRule != null) {
if (!X_C_Order.PAYMENTRULE_DirectDebit.equals(PaymentRule))
PaymentRule = p_PaymentRule;
}
MPaySelectionCheck check = new MPaySelectionCheck(line, PaymentRule);
if (!check.isValid()) {
int C_BPartner_ID = check.getC_BPartner_ID();
MBPartner bp = MBPartner.get(getCtx(), C_BPartner_ID);
String msg = "@NotFound@ @C_BP_BankAccount@: " + bp.getName();
throw new AdempiereUserError(msg);
}
if (!check.save())
throw new IllegalStateException("Cannot save MPaySelectionCheck");
line.setC_PaySelectionCheck_ID(check.getC_PaySelectionCheck_ID());
line.setProcessed(true);
if (!line.save())
throw new IllegalStateException("Cannot save MPaySelectionLine");
paySelectionChecks.add(check);
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class ProjectGenPO method createPO.
// doIt
/**
* Create PO from Planned Amt/Qty
* @param projectLine project line
*/
private void createPO(MProject project, MProjectLine projectLine) {
if (projectLine.getM_Product_ID() == 0) {
addLog(projectLine.getLine(), null, null, "Line has no Product");
return;
}
if (projectLine.getC_OrderPO_ID() != 0) {
addLog(projectLine.getLine(), null, null, "Line was ordered previously");
return;
}
// PO Record
MProductPO[] pos = MProductPO.getOfProduct(getCtx(), projectLine.getM_Product_ID(), get_TrxName());
if (pos == null || pos.length == 0) {
addLog(projectLine.getLine(), null, null, "Product has no PO record");
return;
}
// Create to Order
MOrder order = null;
// try to find PO to C_BPartner
for (int i = 0; i < m_pos.size(); i++) {
MOrder test = (MOrder) m_pos.get(i);
if (test.getC_BPartner_ID() == pos[0].getC_BPartner_ID()) {
order = test;
break;
}
}
if (// create new Order
order == null) {
// Vendor
MBPartner bp = new MBPartner(getCtx(), pos[0].getC_BPartner_ID(), get_TrxName());
// New Order
order = new MOrder(project, false, null);
int AD_Org_ID = projectLine.getAD_Org_ID();
if (AD_Org_ID == 0) {
log.warning("createPOfromProjectLine - AD_Org_ID=0");
AD_Org_ID = Env.getAD_Org_ID(getCtx());
if (AD_Org_ID != 0)
projectLine.setAD_Org_ID(AD_Org_ID);
}
order.setClientOrg(projectLine.getAD_Client_ID(), AD_Org_ID);
order.setBPartner(bp);
order.save();
// optionally save for consolidation
if (m_ConsolidateDocument)
m_pos.add(order);
}
// Create Line
MOrderLine orderLine = new MOrderLine(order);
orderLine.setM_Product_ID(projectLine.getM_Product_ID(), true);
orderLine.setQty(projectLine.getPlannedQty());
orderLine.setDescription(projectLine.getDescription());
// (Vendor) PriceList Price
orderLine.setPrice();
if (orderLine.getPriceActual().signum() == 0) {
// Try to find purchase price
BigDecimal poPrice = pos[0].getPricePO();
int C_Currency_ID = pos[0].getC_Currency_ID();
//
if (poPrice == null || poPrice.signum() == 0)
poPrice = pos[0].getPriceLastPO();
if (poPrice == null || poPrice.signum() == 0)
poPrice = pos[0].getPriceList();
// We have a price
if (poPrice != null && poPrice.signum() != 0) {
if (order.getC_Currency_ID() != C_Currency_ID)
poPrice = MConversionRate.convert(getCtx(), poPrice, C_Currency_ID, order.getC_Currency_ID(), order.getDateAcct(), order.getC_ConversionType_ID(), order.getAD_Client_ID(), order.getAD_Org_ID());
orderLine.setPrice(poPrice);
}
}
orderLine.setTax();
orderLine.saveEx();
// update ProjectLine
projectLine.setC_OrderPO_ID(order.getC_Order_ID());
projectLine.saveEx();
addLog(projectLine.getLine(), null, projectLine.getPlannedQty(), order.getDocumentNo());
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class MDDOrder method setBPartner.
// setShip_User_ID
/**
* Set Business Partner Defaults & Details.
* SOTrx should be set.
* @param bp business partner
*/
public void setBPartner(MBPartner bp) {
if (bp == null)
return;
setC_BPartner_ID(bp.getC_BPartner_ID());
// Defaults Payment Term
int ii = 0;
if (isSOTrx())
ii = bp.getC_PaymentTerm_ID();
else
ii = bp.getPO_PaymentTerm_ID();
// Default Price List
if (isSOTrx())
ii = bp.getM_PriceList_ID();
else
ii = bp.getPO_PriceList_ID();
// Default Delivery/Via Rule
String ss = bp.getDeliveryRule();
if (ss != null)
setDeliveryRule(ss);
ss = bp.getDeliveryViaRule();
if (ss != null)
setDeliveryViaRule(ss);
// Default Invoice/Payment Rule
ss = bp.getInvoiceRule();
if (getSalesRep_ID() == 0) {
ii = Env.getAD_User_ID(getCtx());
if (ii != 0)
setSalesRep_ID(ii);
}
// Set Locations
/*
MBPartnerLocation[] locs = bp.getLocations(false);
if (locs != null)
{
for (int i = 0; i < locs.length; i++)
{
if (locs[i].isShipTo())
{
super.setC_BPartner_Location_ID(locs[i].getC_BPartner_Location_ID());
}
}
// set to first
if (getC_BPartner_Location_ID() == 0 && locs.length > 0)
{
super.setC_BPartner_Location_ID(locs[0].getC_BPartner_Location_ID());
}
}
*/
List<MBPartnerLocation> partnerLocations = Arrays.asList(bp.getLocations(false));
// search the Ship To Location
MBPartnerLocation partnerLocation = // create steam
partnerLocations.stream().filter(pl -> pl.isShipTo()).reduce(// get of last Ship to location
(first, last) -> last).orElse(// if not exist Ship to location else get first partner location
partnerLocations.stream().findFirst().orElseThrow(() -> new AdempiereException("@IsShipTo@ @NotFound@")));
setC_BPartner_Location_ID(partnerLocation.getC_BPartner_Location_ID());
if (getC_BPartner_Location_ID() == 0) {
log.log(Level.SEVERE, "MDDOrder.setBPartner - Has no Ship To Address: " + bp);
}
// Set Contact
/*MUser[] contacts = bp.getContacts(false);
if (contacts != null && contacts.length == 1)
{
setAD_User_ID(contacts[0].getAD_User_ID());
}*/
Arrays.asList(bp.getContacts(false)).stream().findFirst().ifPresent(user -> setAD_User_ID(user.getAD_User_ID()));
}
Aggregations