use of org.compiere.model.MInvoice in project adempiere by adempiere.
the class Doc_AllocationTax method isInterOrg.
// createFact
/** Verify if the posting involves two or more organizations
@return true if there are more than one org involved on the posting
*/
private boolean isInterOrg(MAcctSchema as) {
MAcctSchemaElement elementorg = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Organization);
if (elementorg == null || !elementorg.isBalanced()) {
// no org element or not need to be balanced
return false;
}
if (p_lines.length <= 0) {
// no lines
return false;
}
int startorg = p_lines[0].getAD_Org_ID();
// validate if the allocation involves more than one org
for (int i = 0; i < p_lines.length; i++) {
DocLine_Allocation line = (DocLine_Allocation) p_lines[i];
int orgpayment = startorg;
MPayment payment = null;
if (line.getC_Payment_ID() != 0) {
payment = new MPayment(getCtx(), line.getC_Payment_ID(), getTrxName());
orgpayment = payment.getAD_Org_ID();
}
int orginvoice = startorg;
MInvoice invoice = null;
if (line.getC_Invoice_ID() != 0) {
invoice = new MInvoice(getCtx(), line.getC_Invoice_ID(), getTrxName());
orginvoice = invoice.getAD_Org_ID();
}
int orgcashline = startorg;
MCashLine cashline = null;
if (line.getC_CashLine_ID() != 0) {
cashline = new MCashLine(getCtx(), line.getC_CashLine_ID(), getTrxName());
orgcashline = cashline.getAD_Org_ID();
}
int orgorder = startorg;
MOrder order = null;
if (line.getC_Order_ID() != 0) {
order = new MOrder(getCtx(), line.getC_Order_ID(), getTrxName());
orgorder = order.getAD_Org_ID();
}
if (line.getAD_Org_ID() != startorg || orgpayment != startorg || orginvoice != startorg || orgcashline != startorg || orgorder != startorg)
return true;
}
return false;
}
use of org.compiere.model.MInvoice 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.MInvoice 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.MInvoice 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.MInvoice in project adempiere by adempiere.
the class InvoiceGenerateRMA method createInvoice.
private MInvoice createInvoice(MRMA rma) {
int docTypeId = getInvoiceDocTypeId(rma.get_ID());
if (docTypeId == -1) {
throw new IllegalStateException("Could not get invoice document type for Vendor RMA");
}
MInvoice invoice = new MInvoice(getCtx(), 0, get_TrxName());
invoice.setRMA(rma);
invoice.setC_DocTypeTarget_ID(docTypeId);
if (!invoice.save()) {
throw new IllegalStateException("Could not create invoice");
}
return invoice;
}
Aggregations