use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class PayrollViaEMail method doIt.
// prepare
/**
* Perform process.
* @return Message
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("R_MailText_ID=" + mailTextId);
// Mail Test
mailText = new MMailText(getCtx(), mailTextId, get_TrxName());
if (mailText.getR_MailText_ID() == 0)
throw new Exception("@R_MailText_ID@=" + mailTextId + " @NotFound@ ");
// Client Info
client = MClient.get(getCtx());
if (client.getAD_Client_ID() == 0)
throw new Exception(" @AD_Client_ID@ @NotFound@ ");
if (client.getSMTPHost() == null || client.getSMTPHost().length() == 0)
throw new Exception("@SMTPHost@ @NotFound@ ");
//
long start = System.currentTimeMillis();
if (bPartnerId > 0) {
employee = new MBPartner(getCtx(), bPartnerId, get_TrxName());
if (employee == null)
throw new Exception("@C_BPartner_ID@=" + bPartnerId + " @NotFound@");
sendIndividualMail(bPartnerId, null);
} else
sendBPGroup();
log.fine("From " + employee);
return "@Created@=" + m_counter + ", @Errors@=" + m_errors + " - " + (System.currentTimeMillis() - start) + "ms";
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class HRCreateInvoice method doIt.
// prepare
/**
* Process
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
MHRProcess process = new MHRProcess(getCtx(), getPayrollProcessId(), get_TrxName());
final Timestamp dateInvoice = getDateInvoiced() != null ? getDateInvoiced() : process.getHR_Period_ID() > 0 ? process.getHR_Period().getStartDate() : process.getDateAcct();
Arrays.stream(getEmployeeIds(process)).filter(partnerId -> partnerId > 0).forEach(partnerId -> {
Trx.run(trxName -> {
int lastPartnerId = 0;
MHREmployee employee = null;
MInvoice invoice = null;
for (MHRMovement movement : getPayrollMovement(getPayrollProcessId(), partnerId, trxName)) {
MBPartner partner = new MBPartner(getCtx(), partnerId, trxName);
MHRAttribute attribute = MHRAttribute.getByConceptIdAndPartnerId(movement.getCtx(), movement.getHR_Concept_ID(), movement.getC_BPartner_ID(), movement.getValidFrom(), trxName);
if (attribute != null && attribute.getC_DocType_ID() == 0) {
log.log(Level.SEVERE, "@HR_Employee_ID@ " + partner.getName() + " @HR_Concept_ID@ " + movement.getHR_Concept().getName() + " @C_DocType_ID@ @NotFound@ : ");
addLog(0, null, null, "@HR_Employee_ID@ " + partner.getName() + " @HR_Concept_ID@ " + movement.getHR_Concept().getName() + " @C_DocType_ID@ @NotFound@ : ");
continue;
}
if (attribute != null && attribute.getC_Charge_ID() == 0) {
log.log(Level.SEVERE, "@HR_Employee_ID@ " + partner.getName() + " @HR_Concept_ID@ " + movement.getHR_Concept().getName() + " @C_Charge_ID@ @NotFound@ : ");
addLog(0, null, null, "@HR_Employee_ID@ " + partner.getName() + " @HR_Concept_ID@ " + movement.getHR_Concept().getName() + " @C_Charge_ID@ @NotFound@ : ");
continue;
}
if (movement.getC_BPartner_ID() != lastPartnerId) {
lastPartnerId = movement.getC_BPartner_ID();
employee = MHREmployee.getActiveEmployee(getCtx(), partner.getC_BPartner_ID(), trxName);
invoice = createInvoice(process, partner, employee, attribute.getC_DocType_ID(), dateInvoice);
if (invoice == null)
continue;
}
if (invoice != null)
createInvoiceLine(invoice, employee, movement, attribute.getC_Charge_ID());
}
});
});
return "@OK@";
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class RfQCreateSO method doIt.
// prepare
/**
* Process.
* A Sales Order is created for the entered Business Partner.
* A sales order line is created for each RfQ line quantity,
* where "Offer Quantity" is selected.
* If on the RfQ Line Quantity, an offer amount is entered (not 0),
* that price is used.
* If a magin is entered on RfQ Line Quantity, it overwrites the
* general margin. The margin is the percentage added to the
* Best Response Amount.
* @return message
*/
protected String doIt() throws Exception {
MRfQ rfq = new MRfQ(getCtx(), p_C_RfQ_ID, get_TrxName());
if (rfq.get_ID() == 0)
throw new IllegalArgumentException("No RfQ found");
log.info("doIt - " + rfq);
if (rfq.getC_BPartner_ID() == 0 || rfq.getC_BPartner_Location_ID() == 0)
throw new Exception("No Business Partner/Location");
MBPartner bp = new MBPartner(getCtx(), rfq.getC_BPartner_ID(), get_TrxName());
MOrder order = new MOrder(getCtx(), 0, get_TrxName());
order.setIsSOTrx(true);
if (p_C_DocType_ID != 0)
order.setC_DocTypeTarget_ID(p_C_DocType_ID);
else
order.setC_DocTypeTarget_ID();
order.setBPartner(bp);
order.setC_BPartner_Location_ID(rfq.getC_BPartner_Location_ID());
order.setSalesRep_ID(rfq.getSalesRep_ID());
if (rfq.getDateWorkComplete() != null)
order.setDatePromised(rfq.getDateWorkComplete());
order.saveEx();
MRfQLine[] lines = rfq.getLines();
for (int i = 0; i < lines.length; i++) {
MRfQLine line = lines[i];
MRfQLineQty[] qtys = line.getQtys();
for (int j = 0; j < qtys.length; j++) {
MRfQLineQty qty = qtys[j];
if (qty.isActive() && qty.isOfferQty()) {
MOrderLine ol = new MOrderLine(order);
ol.setM_Product_ID(line.getM_Product_ID(), qty.getC_UOM_ID());
ol.setDescription(line.getDescription());
ol.setQty(qty.getQty());
//
BigDecimal price = qty.getOfferAmt();
if (price == null || price.signum() == 0) {
price = qty.getBestResponseAmt();
if (price == null || price.signum() == 0) {
price = Env.ZERO;
log.warning(" - BestResponse=0 - " + qty);
} else {
BigDecimal margin = qty.getMargin();
if (margin == null || margin.signum() == 0)
margin = rfq.getMargin();
if (margin != null && margin.signum() != 0) {
margin = margin.add(ONEHUNDRED);
price = price.multiply(margin).divide(ONEHUNDRED, 2, BigDecimal.ROUND_HALF_UP);
}
}
}
// price
ol.setPrice(price);
ol.saveEx();
}
// Offer Qty
}
// All Qtys
}
// All Lines
//
rfq.setC_Order_ID(order.getC_Order_ID());
rfq.saveEx();
return order.getDocumentNo();
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class MUserTest method testCreateMBPartner.
public void testCreateMBPartner() {
try {
m_partner = new MBPartner(getCtx(), 0, getTrxName());
m_partner.setValue("");
m_partner.setName("Test MBPartner with contact");
m_partner.setName2(null);
m_partner.setDUNS("");
m_partner.setFirstSale(null);
//
m_partner.setSO_CreditLimit(Env.ZERO);
m_partner.setSO_CreditUsed(Env.ZERO);
m_partner.setTotalOpenBalance(Env.ZERO);
// s_m_partner.setRating(null);
//
m_partner.setActualLifeTimeValue(Env.ZERO);
m_partner.setPotentialLifeTimeValue(Env.ZERO);
m_partner.setAcqusitionCost(Env.ZERO);
m_partner.setShareOfCustomer(0);
m_partner.setSalesVolume(0);
MBPGroup m_group = new MBPGroup(getCtx(), 0, getTrxName());
// N
m_group.setName("Test Group Name");
// N
m_group.setIsConfidentialInfo(false);
m_group.setIsDefault(false);
m_group.setPriorityBase(MBPGroup.PRIORITYBASE_Same);
m_group.saveEx();
m_partner.setBPGroup(m_group);
// Reset Created, Updated to current system time ( teo_sarca )
if (m_partner.save()) {
m_contact = new MUser(getCtx(), 0, getTrxName());
m_contact.setName("Test Contact Name");
m_contact.setIsActive(true);
m_contact.setC_BPartner_ID(m_partner.get_ID());
m_contact.saveEx();
}
commit();
} catch (Exception e) {
fail(e.getLocalizedMessage());
}
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class POTest method testAD_OrgBP_ID_Issue.
/**
* BF [ 2859125 ] Can't set AD_OrgBP_ID
* https://sourceforge.net/tracker/index.php?func=detail&aid=2859125&group_id=176962&atid=879332#
*/
public void testAD_OrgBP_ID_Issue() throws Exception {
// Store Central
MBPartner bp = new MBPartner(getCtx(), 50004, getTrxName());
//
// Try to change AD_OrgBP_ID field value to a new value
final int old_org_id = bp.getAD_OrgBP_ID_Int();
// Store East Org
int new_org_id = 50005;
if (old_org_id == new_org_id) {
// Store Central
new_org_id = 12;
}
bp.setAD_OrgBP_ID(new_org_id);
//
// Following line throws:
// java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
// at org.compiere.model.X_C_BPartner.getAD_OrgBP_ID(X_C_BPartner.java:165)
// at org.compiere.model.MBPartner.getAD_OrgBP_ID_Int(MBPartner.java:602)
// at test.functional.POTest.testAD_OrgBP_ID_Issue(POTest.java:192)
bp.getAD_OrgBP_ID_Int();
//
// Test save:
bp.saveEx();
}
Aggregations