use of org.compiere.model.MInvoice in project adempiere by adempiere.
the class InfoInvoice method initInfo.
// statInit
/**
* General Init
*/
protected void initInfo(int record_id, String value) {
//
if (!(record_id == 0) && value != null && value.length() > 0) {
log.severe("Received both a record_id and a value: " + record_id + " - " + value);
}
// Set values
if (// A record is defined
!(record_id == 0)) {
fieldID = record_id;
// Have to set isPaid and isSOTrx to match or the query will return no results
String trxName = Trx.createTrxName();
MInvoice mi = new MInvoice(Env.getCtx(), record_id, trxName);
fIsPaid.setSelected(mi.isPaid());
fIsSOTrx.setSelected(mi.isSOTrx());
mi = null;
Trx.get(trxName, false).close();
} else // Try to find other criteria in the context
{
String id;
// C_BPartner_ID
id = Env.getContext(Env.getCtx(), p_WindowNo, p_TabNo, "C_BPartner_ID", true);
if (id != null && id.length() != 0 && (new Integer(id).intValue() > 0))
fBPartner_ID.setValue(new Integer(id));
// C_Order_ID
id = Env.getContext(Env.getCtx(), p_WindowNo, p_TabNo, "C_Order_ID", true);
if (id != null && id.length() != 0 && (new Integer(id).intValue() > 0))
fOrder_ID.setValue(new Integer(id));
// IsSOTrx - Window context
id = Env.getContext(Env.getCtx(), p_WindowNo, "IsSOTrx", true);
if (id != null && id.length() != 0 && (id == "Y" || id == "N")) {
fIsSOTrx.setSelected(id == "Y");
}
// The value passed in from the field
if (value != null && value.length() > 0) {
fDocumentNo.setValue(value);
} else {
// C_Invoice_ID
id = Env.getContext(Env.getCtx(), p_WindowNo, p_TabNo, "C_Invoice_ID", true);
if (id != null && id.length() != 0 && (new Integer(id).intValue() > 0)) {
fieldID = new Integer(id).intValue();
// Have to set isPaid and isSOTrx to match or the query will return no results
String trxName = Trx.createTrxName();
MInvoice mi = new MInvoice(Env.getCtx(), record_id, trxName);
fIsPaid.setSelected(mi.isPaid());
fIsSOTrx.setSelected(mi.isSOTrx());
mi = null;
Trx.get(trxName, false).close();
}
}
}
return;
}
use of org.compiere.model.MInvoice in project adempiere by adempiere.
the class ModelValidator method docValidate.
public String docValidate(PO po, int timing) {
log.info(po.get_TableName() + " Timing: " + timing);
String result = null;
// TABLE C_Invoice
String tableName = po.get_TableName();
if (tableName.equals(MInvoice.Table_Name)) {
// Invoice - Validate Fixed Assets Invoice (LRO)
if (timing == TIMING_AFTER_PREPARE) {
MInvoice invoice = (MInvoice) po;
validateFixedAssetsInvoice_LRO(invoice);
}
if (timing == TIMING_AFTER_COMPLETE) {
MInvoice mi = (MInvoice) po;
if (mi.isSOTrx()) {
MInvoiceLine[] mils = mi.getLines();
for (MInvoiceLine mil : mils) {
if (mil.isA_CreateAsset() && !mil.isA_Processed()) {
MAssetDisposed.createAssetDisposed(mil);
}
}
}
}
if (timing == TIMING_AFTER_VOID) {
MInvoice invoice = (MInvoice) po;
String error = afterVoid(invoice);
if (error != null)
return error;
}
if (timing == TIMING_BEFORE_REVERSECORRECT) {
MInvoice invoice = (MInvoice) po;
String error = beforeReverseCorrect(invoice);
if (error != null)
return error;
}
}
if (tableName.equals(MInOut.Table_Name)) {
if (timing == TIMING_AFTER_COMPLETE) {
MInOut inOut = (MInOut) po;
for (MInOutLine inOutLine : inOut.getLines()) {
MProduct product = inOutLine.getProduct();
// Create Asset for SO
if (product != null && inOut.isSOTrx() && product.isCreateAsset() && !product.getM_Product_Category().getA_Asset_Group().isFixedAsset() && inOutLine.getMovementQty().signum() > 0 && !inOut.isReversal()) {
log.fine("Asset");
//info.append("@A_Asset_ID@: ");
int noAssets = inOutLine.getMovementQty().intValue();
if (!product.isOneAssetPerUOM())
noAssets = 1;
for (int i = 0; i < noAssets; i++) {
//if (i > 0)
// info.append(" - ");
int deliveryCount = i + 1;
if (!product.isOneAssetPerUOM())
deliveryCount = 0;
MAsset asset = new MAsset(inOut, inOutLine, deliveryCount);
if (!asset.save(inOut.get_TrxName())) {
//return DocAction.STATUS_Invalid;
throw new IllegalStateException("Could not create Asset");
}
//info.append(asset.getValue());
}
}
}
// Asset
}
if (timing == TIMING_AFTER_REVERSECORRECT) {
MInOut inOut = (MInOut) po;
I_M_InOut inOutReversal = inOut.getReversal();
for (MInOutLine inOutLine : inOut.getLines()) {
// De-Activate Asset
MAsset asset = MAsset.getFromShipment(inOut.getCtx(), inOutLine.getM_InOutLine_ID(), inOut.get_TrxName());
if (asset != null) {
asset.setIsActive(false);
asset.setDescription(asset.getDescription() + " (" + inOutReversal.getDocumentNo() + " #" + inOutLine.getLine() + "<-)");
asset.saveEx();
}
}
}
}
return result;
}
use of org.compiere.model.MInvoice in project adempiere by adempiere.
the class ProcessingInvoiceSelection method createInboundLineFrom.
/**
* Create inboud lines from invoice
* @param invoices
*/
private void createInboundLineFrom(List<MInvoice> invoices) {
MWMInOutBound inOutBound = (MWMInOutBound) getInstance(get_TrxName());
AtomicInteger lineNo = new AtomicInteger(10);
invoices.stream().filter(invoice -> invoice != null).flatMap(invoice -> Arrays.stream(invoice.getLines(true))).forEach(invoiceLine -> {
MWMInOutBoundLine outBoundLine = MWMInOutBoundLine.getByInvoiceLine(invoiceLine);
if (outBoundLine == null) {
outBoundLine = new MWMInOutBoundLine(inOutBound, invoiceLine);
outBoundLine.setLine(lineNo.get());
outBoundLine.saveEx();
lineNo.updateAndGet(line -> line + 10);
}
});
}
use of org.compiere.model.MInvoice in project adempiere by adempiere.
the class AllocationAuto method allocateBPPaymentWithInfo.
// getInvoices
/**************************************************************************
* Allocate Individual Payments with payment references
* @return number of allocations
*/
private int allocateBPPaymentWithInfo() {
int count = 0;
//**** See if there is a direct link (Invoice or Pay Selection)
for (int p = 0; p < m_payments.length; p++) {
MPayment payment = m_payments[p];
if (payment.isAllocated())
continue;
BigDecimal allocatedAmt = payment.getAllocatedAmt();
log.info(payment + ", Allocated=" + allocatedAmt);
if (allocatedAmt != null && allocatedAmt.signum() != 0)
continue;
BigDecimal availableAmt = payment.getPayAmt().add(payment.getDiscountAmt()).add(payment.getWriteOffAmt()).add(payment.getOverUnderAmt());
if (!payment.isReceipt())
availableAmt = availableAmt.negate();
log.fine("Available=" + availableAmt);
//
if (payment.getC_Invoice_ID() != 0) {
for (int i = 0; i < m_invoices.length; i++) {
MInvoice invoice = m_invoices[i];
if (invoice.isPaid())
continue;
// log.fine("allocateIndividualPayments - " + invoice);
if (payment.getC_Invoice_ID() == invoice.getC_Invoice_ID()) {
if (payment.getC_Currency_ID() == invoice.getC_Currency_ID()) {
BigDecimal openAmt = invoice.getOpenAmt(true, null);
if (!invoice.isSOTrx())
openAmt = openAmt.negate();
log.fine(invoice + ", Open=" + openAmt);
// With Discount, etc.
if (availableAmt.compareTo(openAmt) == 0) {
if (payment.allocateIt()) {
addLog(0, payment.getDateAcct(), openAmt, payment.getDocumentNo() + " [1]");
count++;
}
break;
}
} else // Mixed Currency
{
}
}
// invoice found
}
// for all invoices
} else // payment has invoice
// No direct invoice
{
MPaySelectionCheck psCheck = MPaySelectionCheck.getOfPayment(getCtx(), payment.getC_Payment_ID(), get_TrxName());
if (psCheck == null)
continue;
//
BigDecimal totalInvoice = Env.ZERO;
List<MPaySelectionLine> paySelectionLines = psCheck.getPaySelectionLinesAsList(false);
//for (int i = 0; i < psLines.length; i++)
for (MPaySelectionLine paySelectionLine : paySelectionLines) {
MInvoice invoice = paySelectionLine.getInvoice();
if (payment.getC_Currency_ID() == invoice.getC_Currency_ID()) {
BigDecimal invoiceAmt = invoice.getOpenAmt(true, null);
BigDecimal overUnder = paySelectionLine.getOpenAmt().subtract(paySelectionLine.getPayAmt()).subtract(paySelectionLine.getDiscountAmt()).subtract(paySelectionLine.getDifferenceAmt());
invoiceAmt = invoiceAmt.subtract(paySelectionLine.getDiscountAmt()).subtract(paySelectionLine.getDifferenceAmt()).subtract(overUnder);
if (!invoice.isSOTrx())
invoiceAmt = invoiceAmt.negate();
log.fine(invoice + ", Invoice=" + invoiceAmt);
totalInvoice = totalInvoice.add(invoiceAmt);
} else // Multi-Currency
{
}
}
if (availableAmt.compareTo(totalInvoice) == 0) {
if (payment.allocateIt()) {
addLog(0, payment.getDateAcct(), availableAmt, payment.getDocumentNo() + " [n]");
count++;
}
}
}
// No direct invoice
}
return count;
}
use of org.compiere.model.MInvoice in project adempiere by adempiere.
the class AllocationAuto method getInvoices.
// getPayments
/**
* Get Invoices of BP
* @param C_BPartner_ID id
* @return unallocated Invoices
*/
private MInvoice[] getInvoices(int C_BPartner_ID) {
ArrayList<MInvoice> list = new ArrayList<MInvoice>();
String sql = "SELECT * FROM C_Invoice " + "WHERE IsPaid='N' AND Processed='Y' AND C_BPartner_ID=? ";
if (ONLY_AP.equals(p_APAR))
sql += "AND IsSOTrx='N' ";
else if (ONLY_AR.equals(p_APAR))
sql += "AND IsSOTrx='Y' ";
sql += "ORDER BY DateInvoiced";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, C_BPartner_ID);
rs = pstmt.executeQuery();
while (rs.next()) {
MInvoice invoice = new MInvoice(getCtx(), rs, get_TrxName());
if (invoice.getOpenAmt(false, null).signum() == 0) {
invoice.setIsPaid(true);
invoice.saveEx();
} else
list.add(invoice);
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
m_invoices = new MInvoice[list.size()];
list.toArray(m_invoices);
return m_invoices;
}
Aggregations