use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.
the class CommissionCopy method doIt.
// prepare
/**
* Process - copy
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("doIt - C_Commission_ID=" + p_C_Commission_ID + " - copy to " + p_C_CommissionTo_ID);
MCommission comFrom = new MCommission(getCtx(), p_C_Commission_ID, get_TrxName());
if (comFrom.get_ID() == 0)
throw new AdempiereUserError("No From Commission");
MCommission comTo = new MCommission(getCtx(), p_C_CommissionTo_ID, get_TrxName());
if (comTo.get_ID() == 0)
throw new AdempiereUserError("No To Commission");
//
int no = comTo.copyLinesFrom(comFrom);
return "@Copied@: " + no;
}
use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.
the class ConvertLead method doIt.
@Override
protected String doIt() throws Exception {
if (p_AD_User_ID <= 0)
throw new FillMandatoryException("AD_User_ID");
MUser lead = new MUser(getCtx(), p_AD_User_ID, get_TrxName());
if (!lead.isSalesLead() || lead.getC_BPartner_ID() != 0)
throw new AdempiereUserError("Lead already converted");
MBPartner bp = MBPartner.getTemplate(getCtx(), getAD_Client_ID());
bp.set_TrxName(get_TrxName());
if (!Util.isEmpty(lead.getBPName()))
bp.setName(lead.getBPName());
else
bp.setName(lead.getName());
bp.saveEx();
addLog("Business Partner created.");
lead.setC_BPartner_ID(bp.getC_BPartner_ID());
if (lead.getC_Location_ID() != 0) {
MLocation leadAddress = (MLocation) lead.getC_Location();
MBPartnerLocation loc = new MBPartnerLocation(bp);
MLocation address = new MLocation(getCtx(), 0, get_TrxName());
PO.copyValues(leadAddress, address);
address.saveEx();
loc.setC_Location_ID(address.getC_Location_ID());
loc.setPhone(lead.getPhone());
loc.setPhone2(lead.getPhone2());
loc.setFax(lead.getFax());
loc.saveEx();
lead.setC_BPartner_Location_ID(loc.getC_BPartner_Location_ID());
addLog("Contact Location added.");
}
// company address
if (lead.getBP_Location_ID() != 0) {
MLocation leadAddress = (MLocation) lead.getBP_Location();
MBPartnerLocation loc = new MBPartnerLocation(bp);
MLocation address = new MLocation(getCtx(), 0, get_TrxName());
PO.copyValues(leadAddress, address);
address.saveEx();
loc.setC_Location_ID(address.getC_Location_ID());
loc.saveEx();
addLog("BP Address added.");
}
if (p_createOpportunity) {
MOpportunity op = new MOpportunity(getCtx(), 0, get_TrxName());
op.setAD_User_ID(lead.getAD_User_ID());
op.setC_BPartner_ID(bp.getC_BPartner_ID());
op.setExpectedCloseDate(p_expectedCloseDate != null ? p_expectedCloseDate : new Timestamp(System.currentTimeMillis()));
op.setOpportunityAmt(p_opportunityAmt != null ? p_opportunityAmt : Env.ZERO);
if (p_C_SalesStage_ID > 0)
op.setC_SalesStage_ID(p_C_SalesStage_ID);
String sql = "SELECT Probability FROM C_SalesStage WHERE C_SalesStage_ID = ?";
BigDecimal probability = DB.getSQLValueBD(get_TrxName(), sql, p_C_SalesStage_ID);
op.setProbability(probability != null ? probability : Env.ZERO);
op.setDescription(p_Description);
if (p_C_Currency_ID > 0)
op.setC_Currency_ID(p_C_Currency_ID);
else
op.setC_Currency_ID(Env.getContextAsInt(getCtx(), "$C_Currency_ID"));
if (p_SalesRep_ID > 0)
op.setSalesRep_ID(p_SalesRep_ID);
else if (lead.getSalesRep_ID() > 0)
op.setSalesRep_ID(lead.getSalesRep_ID());
else
op.setSalesRep_ID(Env.getContextAsInt(getCtx(), "#SalesRep_ID"));
op.setC_Campaign_ID(lead.getC_Campaign_ID());
op.saveEx();
addLog("Opportunity created.");
}
lead.setIsSalesLead(false);
lead.setLeadStatus(MUser.LEADSTATUS_Converted);
lead.saveEx();
addLog("Lead converted.");
return "@OK@";
}
use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.
the class BPartnerValidate method doIt.
// prepare
/**
* Process
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("C_BPartner_ID=" + p_C_BPartner_ID + ", C_BP_Group_ID=" + p_C_BP_Group_ID);
if (p_C_BPartner_ID == 0 && p_C_BP_Group_ID == 0)
throw new AdempiereUserError("No Business Partner/Group selected");
if (p_C_BP_Group_ID == 0) {
MBPartner bp = new MBPartner(getCtx(), p_C_BPartner_ID, get_TrxName());
if (bp.get_ID() == 0)
throw new AdempiereUserError("Business Partner not found - C_BPartner_ID=" + p_C_BPartner_ID);
checkBP(bp);
} else {
final String whereClause = "C_BP_Group_ID=?";
Iterator<MBPartner> it = new Query(getCtx(), I_C_BPartner.Table_Name, whereClause, get_TrxName()).setParameters(p_C_BP_Group_ID).setOnlyActiveRecords(true).iterate();
while (it.hasNext()) {
checkBP(it.next());
}
}
//
return "OK";
}
use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.
the class CostCreate method doIt.
// prepare
/**
* Perform process.
* @return Message (text with variables)
* @throws Exception if not successful
*/
protected String doIt() throws Exception {
log.info("M_Product_ID=" + p_M_Product_ID);
if (p_M_Product_ID == 0)
throw new AdempiereUserError("@NotFound@: @M_Product_ID@ = " + p_M_Product_ID);
MProduct product = MProduct.get(getCtx(), p_M_Product_ID);
if (product.get_ID() != p_M_Product_ID)
throw new AdempiereUserError("@NotFound@: @M_Product_ID@ = " + p_M_Product_ID);
//if (MCostDetail.processProduct(product, get_TrxName()))
return "@OK@";
//return "@Error@";
}
use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.
the class InvoiceBatchProcess method doIt.
// prepare
/**
* Process Invoice Batch
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("C_InvoiceBatch_ID=" + p_C_InvoiceBatch_ID + ", DocAction=" + p_DocAction);
if (p_C_InvoiceBatch_ID == 0)
throw new AdempiereUserError("C_InvoiceBatch_ID = 0");
MInvoiceBatch batch = new MInvoiceBatch(getCtx(), p_C_InvoiceBatch_ID, get_TrxName());
if (batch.get_ID() == 0)
throw new AdempiereUserError("@NotFound@: @C_InvoiceBatch_ID@ - " + p_C_InvoiceBatch_ID);
if (batch.isProcessed())
throw new AdempiereUserError("@Processed@");
//
if (batch.getControlAmt().signum() != 0 && batch.getControlAmt().compareTo(batch.getDocumentAmt()) != 0)
throw new AdempiereUserError("@ControlAmt@ <> @DocumentAmt@");
//
MInvoiceBatchLine[] lines = batch.getLines(false);
for (int i = 0; i < lines.length; i++) {
MInvoiceBatchLine line = lines[i];
if (line.getC_Invoice_ID() != 0 || line.getC_InvoiceLine_ID() != 0)
continue;
if ((m_oldDocumentNo != null && !m_oldDocumentNo.equals(line.getDocumentNo())) || m_oldC_BPartner_ID != line.getC_BPartner_ID() || m_oldC_BPartner_Location_ID != line.getC_BPartner_Location_ID())
completeInvoice();
// New Invoice
if (m_invoice == null) {
m_invoice = new MInvoice(batch, line);
if (!m_invoice.save())
throw new AdempiereUserError("Cannot save Invoice");
//
m_oldDocumentNo = line.getDocumentNo();
m_oldC_BPartner_ID = line.getC_BPartner_ID();
m_oldC_BPartner_Location_ID = line.getC_BPartner_Location_ID();
}
if (line.isTaxIncluded() != m_invoice.isTaxIncluded()) {
// rollback
throw new AdempiereUserError("Line " + line.getLine() + " TaxIncluded inconsistent");
}
// Add Line
MInvoiceLine invoiceLine = new MInvoiceLine(m_invoice);
invoiceLine.setDescription(line.getDescription());
invoiceLine.setC_Charge_ID(line.getC_Charge_ID());
// Entered/Invoiced
invoiceLine.setQty(line.getQtyEntered());
invoiceLine.setPrice(line.getPriceEntered());
invoiceLine.setC_Tax_ID(line.getC_Tax_ID());
invoiceLine.setTaxAmt(line.getTaxAmt());
invoiceLine.setLineNetAmt(line.getLineNetAmt());
invoiceLine.setLineTotalAmt(line.getLineTotalAmt());
if (!invoiceLine.save()) {
// rollback
throw new AdempiereUserError("Cannot save Invoice Line");
}
// Update Batch Line
line.setC_Invoice_ID(m_invoice.getC_Invoice_ID());
line.setC_InvoiceLine_ID(invoiceLine.getC_InvoiceLine_ID());
line.saveEx();
}
// for all lines
completeInvoice();
//
batch.setProcessed(true);
batch.saveEx();
return "#" + m_count;
}
Aggregations