use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class ImportPayrollMovements method fillIdValues.
// doIt
/**
* Fill mandatory information
*
* @param importPayrollMovement
*/
private void fillIdValues(X_I_HR_Movement importPayrollMovement) {
StringBuilder messageError = new StringBuilder();
importPayrollMovement.setI_ErrorMsg("");
Integer processId = getId(MHRProcess.Table_Name, MHRProcess.COLUMNNAME_Name + "=?", importPayrollMovement.getProcessName());
if (processId < 0)
messageError.append("@HR_Process_ID@ @NotFound@ ");
else {
MHRProcess process = new MHRProcess(getCtx(), processId, importPayrollMovement.get_TrxName());
if (MHRProcess.DOCSTATUS_Drafted.equals(process.getDocStatus()) && MHRProcess.DOCSTATUS_InProgress.equals(process.getDocStatus()))
messageError.append("@DocStatus@ @NotValid@");
}
Integer partnerId = getId(MBPartner.Table_Name, MBPartner.COLUMNNAME_Value + "=?", importPayrollMovement.getBPartner_Value());
if (partnerId < 0)
messageError.append(", ").append("@C_BPartner_ID@ @NotFound@");
else {
MBPartner partner = new MBPartner(getCtx(), partnerId, importPayrollMovement.get_TrxName());
if (!partner.isEmployee())
messageError.append(", ").append("@IsEmployee@ @NotValid@ @C_BPartner_ID@ " + partner.getName());
}
StringBuilder whereClause = new StringBuilder("");
whereClause.append(MHRConcept.COLUMNNAME_Value).append("=? AND ").append(MHRConcept.COLUMNNAME_IsManual).append("=? AND ").append(MHRConcept.COLUMNNAME_IsActive).append("=? ");
Integer conceptId = getId(MHRConcept.Table_Name, whereClause.toString(), importPayrollMovement.getConceptValue().trim(), true, true);
if (conceptId < 0)
setImportError(importPayrollMovement, "@HR_Concept_ID@ " + importPayrollMovement.getConceptValue() + " @NotFound@").saveEx(importPayrollMovement.get_TrxName());
else {
MHRConcept concept = new MHRConcept(getCtx(), conceptId, importPayrollMovement.get_TrxName());
if (MHRConcept.TYPE_RuleEngine.equals(concept.getType()))
messageError.append(", ").append("@HR_Concept_ID@ " + concept.getName() + " @NotValid@ ");
}
if (importPayrollMovement.getValidFrom() == null)
messageError.append(", ").append("@ValidFrom@ @FillMandatory@ ");
if (importPayrollMovement.getValidTo() == null)
importPayrollMovement.setValidTo(importPayrollMovement.getValidFrom());
if (messageError != null && messageError.length() > 0)
setImportError(importPayrollMovement, messageError.toString()).saveEx(importPayrollMovement.get_TrxName());
importPayrollMovement.setHR_Process_ID(processId);
importPayrollMovement.setHR_Concept_ID(conceptId);
importPayrollMovement.setC_BPartner_ID(partnerId);
importPayrollMovement.saveEx(importPayrollMovement.get_TrxName());
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class InvoiceGenerateFromShipment method createInvoiceLineFromShipmentLine.
/**
* Create Invoice Line from Shipment Line
* @param order order
* @param inOut shipment header
* @param inOutLine shipment line
*/
private MInvoice createInvoiceLineFromShipmentLine(MInvoice invoice, MOrder order, MInOut inOut, MInOutLine inOutLine) {
if (invoice == null) {
invoice = new MInvoice(inOut, p_DateInvoiced);
if (!invoice.save())
throw new IllegalStateException("Could not create Invoice (s)");
}
// Create Shipment Comment Line
if (m_ship == null || m_ship.getM_InOut_ID() != inOut.getM_InOut_ID()) {
MDocType dt = MDocType.get(getCtx(), inOut.getC_DocType_ID());
if (m_bp == null || m_bp.getC_BPartner_ID() != inOut.getC_BPartner_ID())
m_bp = new MBPartner(getCtx(), inOut.getC_BPartner_ID(), get_TrxName());
// Reference: Delivery: 12345 - 12.12.12
MClient client = MClient.get(getCtx(), order.getAD_Client_ID());
String AD_Language = client.getAD_Language();
if (client.isMultiLingualDocument() && m_bp.getAD_Language() != null)
AD_Language = m_bp.getAD_Language();
if (AD_Language == null)
AD_Language = Language.getBaseAD_Language();
java.text.SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.Date, Language.getLanguage(AD_Language));
String referenceDescr = dt.getPrintName(m_bp.getAD_Language()) + ": " + inOut.getDocumentNo() + " - " + format.format(inOut.getMovementDate());
m_ship = inOut;
//
MInvoiceLine descInvLine = new MInvoiceLine(invoice);
descInvLine.setIsDescription(true);
descInvLine.setDescription(referenceDescr);
descInvLine.setLine(m_line + inOutLine.getLine() - 2);
if (!descInvLine.save())
throw new IllegalStateException("Could not create Invoice Comment Line (sh)");
// Optional Ship Address if not Bill Address
if (order.getBill_Location_ID() != inOut.getC_BPartner_Location_ID()) {
MLocation addr = MLocation.getBPLocation(getCtx(), inOut.getC_BPartner_Location_ID(), null);
descInvLine = new MInvoiceLine(invoice);
descInvLine.setIsDescription(true);
descInvLine.setDescription(addr.toString());
descInvLine.setLine(m_line + inOutLine.getLine() - 1);
if (!descInvLine.save())
throw new IllegalStateException("Could not create Invoice Comment Line 2 (sh)");
}
}
//
MInvoiceLine invLine = new MInvoiceLine(invoice);
invLine.setShipLine(inOutLine);
if (inOutLine.sameOrderLineUOM())
invLine.setQtyEntered(inOutLine.getQtyEntered());
else
invLine.setQtyEntered(inOutLine.getMovementQty());
invLine.setQtyInvoiced(inOutLine.getMovementQty());
invLine.setLine(m_line + inOutLine.getLine());
//@Trifon - special handling when ShipLine.ToBeInvoiced='N'
String toBeInvoiced = inOutLine.get_ValueAsString("ToBeInvoiced");
if ("N".equals(toBeInvoiced) || "false".equals(toBeInvoiced)) {
invLine.setPriceEntered(Env.ZERO);
invLine.setPriceActual(Env.ZERO);
invLine.setPriceList(Env.ZERO);
invLine.setPriceLimit(Env.ZERO);
//setC_Tax_ID(oLine.getC_Tax_ID());
invLine.setLineNetAmt(Env.ZERO);
invLine.setIsDescription(true);
}
if (!invLine.save())
throw new IllegalStateException("Could not create Invoice Line (s)");
// Link
inOutLine.setIsInvoiced(true);
if (!inOutLine.save())
throw new IllegalStateException("Could not update Shipment Line");
log.fine(invLine.toString());
return invoice;
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class SB_InvoiceGenerateFromOrderLine method createLine.
// createLine
/**
* Create Invoice Line from Shipment
* @param order order
* @param ship shipment header
* @param sLine shipment line
*/
private void createLine(MOrder order, MInOut ship, MInOutLine sLine) {
if (m_invoice == null) {
m_invoice = new MInvoice(order, 0, p_DateInvoiced);
if (!m_invoice.save())
throw new IllegalStateException("Could not create Invoice (s)");
}
// Create Shipment Comment Line
if (m_ship == null || m_ship.getM_InOut_ID() != ship.getM_InOut_ID()) {
MDocType dt = MDocType.get(getCtx(), ship.getC_DocType_ID());
if (m_bp == null || m_bp.getC_BPartner_ID() != ship.getC_BPartner_ID())
m_bp = new MBPartner(getCtx(), ship.getC_BPartner_ID(), get_TrxName());
// Reference: Delivery: 12345 - 12.12.12
MClient client = MClient.get(getCtx(), order.getAD_Client_ID());
String AD_Language = client.getAD_Language();
if (client.isMultiLingualDocument() && m_bp.getAD_Language() != null)
AD_Language = m_bp.getAD_Language();
if (AD_Language == null)
AD_Language = Language.getBaseAD_Language();
java.text.SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.Date, Language.getLanguage(AD_Language));
String reference = dt.getPrintName(m_bp.getAD_Language()) + ": " + ship.getDocumentNo() + " - " + format.format(ship.getMovementDate());
m_ship = ship;
//
MInvoiceLine line = new MInvoiceLine(m_invoice);
line.setIsDescription(true);
line.setDescription(reference);
line.setLine(m_line + sLine.getLine() - 2);
if (!line.save())
throw new IllegalStateException("Could not create Invoice Comment Line (sh)");
// Optional Ship Address if not Bill Address
if (order.getBill_Location_ID() != ship.getC_BPartner_Location_ID()) {
MLocation addr = MLocation.getBPLocation(getCtx(), ship.getC_BPartner_Location_ID(), null);
line = new MInvoiceLine(m_invoice);
line.setIsDescription(true);
line.setDescription(addr.toString());
line.setLine(m_line + sLine.getLine() - 1);
if (!line.save())
throw new IllegalStateException("Could not create Invoice Comment Line 2 (sh)");
}
}
//
MInvoiceLine line = new MInvoiceLine(m_invoice);
line.setShipLine(sLine);
if (sLine.sameOrderLineUOM())
line.setQtyEntered(sLine.getQtyEntered());
else
line.setQtyEntered(sLine.getMovementQty());
line.setQtyInvoiced(sLine.getMovementQty());
line.setLine(m_line + sLine.getLine());
//@Trifon - special handling when ShipLine.ToBeInvoiced='N'
String toBeInvoiced = sLine.get_ValueAsString("ToBeInvoiced");
if ("N".equals(toBeInvoiced)) {
line.setPriceEntered(Env.ZERO);
line.setPriceActual(Env.ZERO);
line.setPriceLimit(Env.ZERO);
line.setPriceList(Env.ZERO);
//setC_Tax_ID(oLine.getC_Tax_ID());
line.setLineNetAmt(Env.ZERO);
line.setIsDescription(true);
}
if (!line.save())
throw new IllegalStateException("Could not create Invoice Line (s)");
// Link
sLine.setIsInvoiced(true);
if (!sLine.save())
throw new IllegalStateException("Could not update Shipment Line");
log.fine(line.toString());
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class InvoiceGenerateFromShipment method generate.
//@Trifon
private String generate(PreparedStatement pstmt) {
ResultSet rs = null;
MInvoice invoice = null;
try {
rs = pstmt.executeQuery();
while (rs.next()) {
MInOut inOut = new MInOut(getCtx(), rs, get_TrxName());
if (// ignore incomplete or reversals
!inOut.isComplete() || inOut.getDocStatus().equals(MInOut.DOCSTATUS_Reversed)) {
continue;
}
MOrder order = new MOrder(getCtx(), inOut.getC_Order_ID(), get_TrxName());
// New Invoice Location
if (!p_ConsolidateDocument || (invoice != null && invoice.getC_BPartner_Location_ID() != order.getBill_Location_ID())) {
invoice = completeInvoice(invoice);
}
// boolean completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.equals(order.getInvoiceRule());
// Schedule After Delivery
boolean doInvoice = false;
if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.equals(order.getInvoiceRule())) {
m_bp = new MBPartner(getCtx(), order.getBill_BPartner_ID(), null);
if (m_bp.getC_InvoiceSchedule_ID() == 0) {
log.warning("BPartner has no Schedule - set to After Delivery");
order.setInvoiceRule(MOrder.INVOICERULE_AfterDelivery);
order.save();
} else {
MInvoiceSchedule is = MInvoiceSchedule.get(getCtx(), m_bp.getC_InvoiceSchedule_ID(), get_TrxName());
if (is.canInvoice(order.getDateOrdered(), order.getGrandTotal()))
doInvoice = true;
else
continue;
}
}
// After Delivery - Invoice per Delivery
if (doInvoice || MOrder.INVOICERULE_AfterDelivery.equals(order.getInvoiceRule())) {
MInOutLine[] shipLines = inOut.getLines(false);
for (int j = 0; j < shipLines.length; j++) {
MInOutLine inOutLine = shipLines[j];
if (!inOutLine.isInvoiced()) {
invoice = createInvoiceLineFromShipmentLine(invoice, order, inOut, inOutLine);
}
}
m_line += 1000;
} else // After Order Delivered, Immediate
{
throw new AdempiereException("Not supported Invoice Rules[Immediate, AfterOrderDelivered]");
}
}
// for all Shipments
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
} finally {
DB.close(rs, pstmt);
pstmt = null;
}
completeInvoice(invoice);
return "@Created@ = " + m_created;
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class CommissionAPInvoice method doIt.
// prepare
/**
* Perform process.
* @return Message (variables are parsed)
* @throws Exception if not successful
*/
protected String doIt() throws Exception {
log.info("doIt - C_CommissionRun_ID=" + getRecord_ID());
// Load Data
MCommissionRun comRun = new MCommissionRun(getCtx(), getRecord_ID(), get_TrxName());
if (comRun.get_ID() == 0)
throw new IllegalArgumentException("CommissionAPInvoice - No Commission Run");
if (Env.ZERO.compareTo(comRun.getGrandTotal()) == 0)
throw new IllegalArgumentException("@GrandTotal@ = 0");
MCommission com = new MCommission(getCtx(), comRun.getC_Commission_ID(), get_TrxName());
if (com.get_ID() == 0)
throw new IllegalArgumentException("CommissionAPInvoice - No Commission");
if (com.getC_Charge_ID() == 0)
throw new IllegalArgumentException("CommissionAPInvoice - No Charge on Commission");
MBPartner bp = new MBPartner(getCtx(), com.getC_BPartner_ID(), get_TrxName());
if (bp.get_ID() == 0)
throw new IllegalArgumentException("CommissionAPInvoice - No BPartner");
// Create Invoice
MInvoice invoice = new MInvoice(getCtx(), 0, null);
invoice.setClientOrg(com.getAD_Client_ID(), com.getAD_Org_ID());
// API
invoice.setC_DocTypeTarget_ID(MDocType.DOCBASETYPE_APInvoice);
invoice.setBPartner(bp);
// invoice.setDocumentNo (comRun.getDocumentNo()); // may cause unique constraint
// caller
invoice.setSalesRep_ID(getAD_User_ID());
//
if (com.getC_Currency_ID() != invoice.getC_Currency_ID())
throw new IllegalArgumentException("CommissionAPInvoice - Currency of PO Price List not Commission Currency");
//
if (!invoice.save())
throw new IllegalStateException("CommissionAPInvoice - cannot save Invoice");
// Create Invoice Line
MInvoiceLine iLine = new MInvoiceLine(invoice);
iLine.setC_Charge_ID(com.getC_Charge_ID());
iLine.setQty(1);
iLine.setPrice(comRun.getGrandTotal());
iLine.setTax();
if (!iLine.save())
throw new IllegalStateException("CommissionAPInvoice - cannot save Invoice Line");
//
return "@C_Invoice_ID@ = " + invoice.getDocumentNo();
}
Aggregations