use of org.compiere.model.MInvoiceLine in project lar_361 by comitsrl.
the class FiscalDocumentPrint method loadShipmentOrderNumbers.
/**
* Retrieve shipment and sales order numbers, if they exists.
*
* @param mInvoice ADempiere invoice document
* @param document fiscal printer document
*/
private void loadShipmentOrderNumbers(final MInvoice mInvoice, final Invoice document) {
final I_C_Order order = mInvoice.getC_Order();
if (order.getC_Order_ID() > 0)
document.addObservation(Msg.translate(ctx, "C_Order_ID") + ": " + order.getDocumentNo());
final MInvoiceLine[] iLines = mInvoice.getLines();
for (final MInvoiceLine line : iLines) {
final I_M_InOutLine ioline = line.getM_InOutLine();
if (ioline.getM_InOutLine_ID() > 0) {
String obs = ioline.getM_InOut().getDocumentNo();
if (!document.getObservations().contains(obs))
document.addObservation(obs);
}
}
}
use of org.compiere.model.MInvoiceLine in project lar_361 by comitsrl.
the class FiscalDocumentPrint method loadDocumentLines.
// loadDNFHLines
/**
* Carga las líneas que se encuentran en el documento de ADempiere hacia
* el documento de impresoras fiscales.
* @param mInvoice Documento de ADempiere.
* @param document Documento de impresoras fiscales.
*/
private void loadDocumentLines(final MInvoice mInvoice, final Document document) {
// Se obtiene el indicador de si los precios contienen los impuestos incluido
boolean taxIncluded = MPriceList.get(ctx, mInvoice.getM_PriceList_ID(), getTrxName()).isTaxIncluded();
// Se obtiene el redondeo para precios de la moneda de la factura
// int scale = MCurrency.get(oxpDocument.getCtx(), oxpDocument.getC_Currency_ID()).getCostingPrecision();
MInvoiceLine[] lines = mInvoice.getLines();
BigDecimal totalLineAmt = BigDecimal.ZERO;
// String description = "";
for (int i = 0; i < lines.length; i++) {
MInvoiceLine mLine = lines[i];
BigDecimal qtyEntered = mLine.getQtyEntered();
// @emmie - avoid "special" invoice lines (as shipments comments lines)
if (qtyEntered.compareTo(BigDecimal.ZERO) > 0) {
DocumentLine docLine = new DocumentLine();
docLine.setLineNumber(mLine.getLine());
docLine.setDescription(manageLineDescription(docLine, mLine));
// TODO - Review discounts at invoice behavior
// Calcula el precio unitario de la línea.
// Aquí tenemos dos casos de línea: Con Bonificaciones o Sin
// Bonificaciones
// 1. Sin Bonificaciones
// El precio unitario es entonces simplemente el precio actual
// de la
// línea, es decir el PriceActual.
// if (!mLine.hasBonus()) {
BigDecimal unitPrice = mLine.getPriceActual();
totalLineAmt = totalLineAmt.add(unitPrice);
// } else {
// 2. Con Bonificaciones
// Aquí NO se puede utilizar el mLine.getPriceActual() ya que el
// mismo tiene contemplado las bonificaciones mientras que en la
// impresión del ticket, las bonificaciones se restan al final
// del mismo. De esta forma, el precio unitario para el ticket
// va a ser mayor que el PriceActual de la línea en caso de que
// la misma contenga bonificaciones.
// El cálculo a realizar es:
// (PriceList * Qty - LineDiscountAmt) / Qty
//
// unitPrice =
// (mLine.getPriceList().multiply(mLine.getQtyEntered())
// .subtract(mLine.getLineDiscountAmt())).divide(
// mLine.getQtyEntered(), scale, RoundingMode.HALF_UP);
// }
// LAR - Process discount for invoice
final I_C_OrderLine ol = mLine.getC_OrderLine();
final BigDecimal discountRate = ol.getDiscount();
if (discountRate.compareTo(BigDecimal.ZERO) > 0) {
final BigDecimal originalAmt = BigDecimal.valueOf(100).multiply(unitPrice).divide(BigDecimal.valueOf(100).subtract(discountRate), 2, BigDecimal.ROUND_FLOOR);
final DiscountLine discountLine = new DiscountLine("Dto aplicado", originalAmt.subtract(unitPrice).multiply(mLine.getQtyEntered()), true, false, discountRate);
// Add discount to document line
docLine.setDiscount(discountLine);
// Set proper unitPrice
unitPrice = originalAmt;
}
// LAR - Process discount for invoice
docLine.setUnitPrice(unitPrice);
docLine.setQuantity(mLine.getQtyEntered());
docLine.setPriceIncludeIva(taxIncluded);
// Se obtiene la tasa del IVA de la línea
// Se asume que el impuesto es siempre IVA, a futuro se verá
// que hacer si el producto tiene otro impuesto que no sea IVA.
MTax mTax = MTax.get(Env.getCtx(), mLine.getC_Tax_ID());
docLine.setIvaRate(mTax.getRate());
// Se agrega la línea al documento.
document.addLine(docLine);
}
}
// TODO - Improve this behavior
BigDecimal amt = mInvoice.get_Value("WithHoldingAmt") == null ? Env.ZERO : // LAR perception are negative
((BigDecimal) mInvoice.get_Value("WithHoldingAmt")).negate();
if (amt.compareTo(BigDecimal.ZERO) > 0) {
// TODO Corregir el calculo del porcentaje de percepción.
// BigDecimal rate = amt.divide(totalLineAmt, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
// @mzuniga - Se agrega la provincia correspondiente a la Percepción en la descripción de la línea
String sql = "SELECT l.RegionName FROM AD_OrgInfo oi JOIN C_Location l ON oi.C_Location_ID = l.C_Location_ID WHERE oi.AD_Org_ID=?";
String prov = DB.getSQLValueString(mInvoice.get_TrxName(), sql, (Integer) mInvoice.get_Value("AD_Org_ID"));
// String.format("Percepci\u00f3n", rate);
String desc = "Perc. IIBB " + prov;
// @mzuniga
PerceptionLine perceptionLine = new PerceptionLine(desc, amt, null);
document.setPerceptionLine(perceptionLine);
}
}
use of org.compiere.model.MInvoiceLine in project lar_361 by comitsrl.
the class LCO_Validator method modelChange.
// initialize
/**
* Model Change of a monitored Table.
* Called after PO.beforeSave/PO.beforeDelete
* when you called addModelChange for the table
* @param po persistent object
* @param type TYPE_
* @return error message or null
* @exception Exception if the recipient wishes the change to be not accept.
*/
public String modelChange(PO po, int type) throws Exception {
log.info(po.get_TableName() + " Type: " + type);
String msg;
if (po.get_TableName().equals(MInvoice.Table_Name) && type == ModelValidator.TYPE_BEFORE_CHANGE) {
msg = clearInvoiceWithholdingAmtFromInvoice((MInvoice) po);
if (msg != null)
return msg;
}
// in order to force a regeneration
if (po.get_TableName().equals(MInvoiceLine.Table_Name) && (type == ModelValidator.TYPE_BEFORE_NEW || type == ModelValidator.TYPE_BEFORE_CHANGE || type == ModelValidator.TYPE_BEFORE_DELETE)) {
msg = clearInvoiceWithholdingAmtFromInvoiceLine((MInvoiceLine) po, type);
if (msg != null)
return msg;
}
// Check Digit based on TaxID
if (po.get_TableName().equals(MBPartner.Table_Name) && (type == TYPE_BEFORE_NEW || type == TYPE_BEFORE_CHANGE)) {
MBPartner bpartner = (MBPartner) po;
msg = mcheckTaxIdDigit(bpartner);
if (msg != null)
return msg;
msg = mfillName(bpartner);
if (msg != null)
return msg;
}
if (po.get_TableName().equals(X_LCO_TaxIdType.Table_Name) && (type == TYPE_BEFORE_NEW || type == TYPE_BEFORE_CHANGE)) {
X_LCO_TaxIdType taxidtype = (X_LCO_TaxIdType) po;
if ((!taxidtype.isUseTaxIdDigit()) && taxidtype.isDigitChecked())
taxidtype.setIsDigitChecked(false);
}
if (po.get_TableName().equals(X_LCO_WithholdingCalc.Table_Name) && (type == ModelValidator.TYPE_BEFORE_CHANGE || type == ModelValidator.TYPE_BEFORE_NEW)) {
X_LCO_WithholdingCalc lwc = (X_LCO_WithholdingCalc) po;
if (lwc.isCalcOnInvoice() && lwc.isCalcOnPayment())
lwc.setIsCalcOnPayment(false);
}
return null;
}
use of org.compiere.model.MInvoiceLine in project lar_361 by comitsrl.
the class InvoiceGenerateRMA method generateInvoice.
private void generateInvoice(int M_RMA_ID) {
MRMA rma = new MRMA(getCtx(), M_RMA_ID, get_TrxName());
MInvoice invoice = createInvoice(rma);
MInvoiceLine[] invoiceLines = createInvoiceLines(rma, invoice);
if (invoiceLines.length == 0) {
log.log(Level.WARNING, "No invoice lines created: M_RMA_ID=" + M_RMA_ID + ", M_Invoice_ID=" + invoice.get_ID());
}
StringBuffer processMsg = new StringBuffer(invoice.getDocumentNo());
if (!invoice.processIt(p_docAction)) {
processMsg.append(" (NOT Processed)");
log.warning("Invoice Processing failed: " + invoice + " - " + invoice.getProcessMsg());
throw new IllegalStateException("Invoice Processing failed: " + invoice + " - " + invoice.getProcessMsg());
}
if (!invoice.save()) {
throw new IllegalStateException("Could not update invoice");
} else // @fchiappano Impresion Fiscal, si se completa la factura.
{
if (p_docAction.equals(MInvoice.DOCACTION_Complete) && LAR_Utils.isFiscalDocType(invoice.getC_DocType_ID())) {
final InvoiceFiscalDocumentPrintManager manager = new InvoiceFiscalDocumentPrintManager(invoice);
manager.print();
}
}
// Add processing information to process log
addLog(invoice.getC_Invoice_ID(), invoice.getDateInvoiced(), null, invoice.getDocumentNo());
m_created++;
}
Aggregations