use of org.compiere.model.MInvoiceLine in project adempiere by adempiere.
the class InOutCreateInvoice method doIt.
// prepare
/**
* Create Invoice.
* @return document no
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("M_InOut_ID=" + p_M_InOut_ID + ", M_PriceList_ID=" + p_M_PriceList_ID + ", InvoiceDocumentNo=" + p_InvoiceDocumentNo);
if (p_M_InOut_ID == 0)
throw new IllegalArgumentException("No Shipment");
//
MInOut ship = new MInOut(getCtx(), p_M_InOut_ID, get_TrxName());
if (ship.get_ID() == 0)
throw new IllegalArgumentException("Shipment not found");
if (!MInOut.DOCSTATUS_Completed.equals(ship.getDocStatus()))
throw new IllegalArgumentException("Shipment not completed");
MInvoice invoice = new MInvoice(ship, null);
// Should not override pricelist for RMA
if (p_M_PriceList_ID != 0 && ship.getM_RMA_ID() == 0)
invoice.setM_PriceList_ID(p_M_PriceList_ID);
if (p_InvoiceDocumentNo != null && p_InvoiceDocumentNo.length() > 0)
invoice.setDocumentNo(p_InvoiceDocumentNo);
if (!invoice.save())
throw new IllegalArgumentException("Cannot save Invoice");
MInOutLine[] shipLines = ship.getLines(false);
for (int i = 0; i < shipLines.length; i++) {
MInOutLine sLine = shipLines[i];
MInvoiceLine line = new MInvoiceLine(invoice);
line.setShipLine(sLine);
if (sLine.sameOrderLineUOM())
line.setQtyEntered(sLine.getQtyEntered());
else
line.setQtyEntered(sLine.getMovementQty());
line.setQtyInvoiced(sLine.getMovementQty());
if (!line.save())
throw new IllegalArgumentException("Cannot save Invoice Line");
}
return invoice.getDocumentNo();
}
use of org.compiere.model.MInvoiceLine 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;
}
use of org.compiere.model.MInvoiceLine in project adempiere by adempiere.
the class InvoiceCreateInOut method doIt.
// prepare
/**
* Create Shipment
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("C_Invoice_ID=" + p_C_Invoice_ID + ", M_Warehouse_ID=" + p_M_Warehouse_ID);
if (p_C_Invoice_ID <= 0)
throw new FillMandatoryException("C_Invoice_ID");
if (p_M_Warehouse_ID == 0)
throw new FillMandatoryException(PARAM_M_Warehouse_ID);
//
MInvoice invoice = new MInvoice(getCtx(), p_C_Invoice_ID, null);
if (invoice.get_ID() <= 0)
throw new AdempiereException("@NotFound@ @C_Invoice_ID@");
if (!MInvoice.DOCSTATUS_Completed.equals(invoice.getDocStatus()))
throw new AdempiereException("@InvoiceCreateDocNotCompleted@");
//
for (MInvoiceLine invoiceLine : invoice.getLines(false)) {
createLine(invoice, invoiceLine);
}
if (m_inout == null)
throw new InvoiceFullyMatchedException();
//
return m_inout.getDocumentNo();
}
use of org.compiere.model.MInvoiceLine in project adempiere by adempiere.
the class InvoiceGenerate 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.MInvoiceLine in project adempiere by adempiere.
the class InvoiceGenerate method createLine.
// generate
/**************************************************************************
* Create Invoice Line from Order Line
* @param order order
* @param orderLine line
* @param qtyInvoiced qty
* @param qtyEntered qty
*/
private void createLine(MOrder order, MOrderLine orderLine, BigDecimal qtyInvoiced, BigDecimal qtyEntered) {
if (m_invoice == null) {
m_invoice = new MInvoice(order, 0, p_DateInvoiced);
if (!m_invoice.save())
throw new IllegalStateException("Could not create Invoice (o)");
}
//
MInvoiceLine line = new MInvoiceLine(m_invoice);
line.setOrderLine(orderLine);
line.setQtyInvoiced(qtyInvoiced);
line.setQtyEntered(qtyEntered);
line.setLine(m_line + orderLine.getLine());
if (!line.save())
throw new IllegalStateException("Could not create Invoice Line (o)");
log.fine(line.toString());
}
Aggregations