Search in sources :

Example 1 with MInvoice

use of org.compiere.model.MInvoice in project adempiere by adempiere.

the class SB_InvoiceGenerateFromOrderLine method doIt.

//	prepare
/**
	 * 	Generate Invoices
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    StringBuffer orderClause = new StringBuffer();
    m_invoices = new ArrayList<MInvoice>();
    if (!p_ConsolidateDocument)
        orderClause.append("C_BPartner_ID, C_Order_ID, line");
    else
        orderClause.append("C_BPartner_ID");
    String whereClause = "EXISTS (SELECT T_Selection_ID FROM T_Selection WHERE  T_Selection.AD_PInstance_ID=? " + " AND T_Selection.T_Selection_ID=c_orderLine.C_OrderLine_ID)";
    m_records = new Query(getCtx(), MOrderLine.Table_Name, whereClause, get_TrxName()).setParameters(getAD_PInstance_ID()).setOrderBy(orderClause.toString()).setClient_ID().list();
    ordersToInvoice = new ArrayList<MOrder>();
    for (MOrderLine orderLine : m_records) {
        Boolean isadded = false;
        for (MOrder order : ordersToInvoice) {
            if (order.getC_Order_ID() == orderLine.getC_Order_ID()) {
                isadded = true;
                break;
            }
        }
        if (!isadded)
            ordersToInvoice.add(orderLine.getParent());
    }
    for (MOrder order : ordersToInvoice) {
        generate(order);
    }
    String result = "Fact. No";
    for (MInvoice inv : m_invoices) {
        Env.setContext(getCtx(), "@WhereClause@", whereClause);
        result = result + ", " + inv.getDocumentInfo();
    }
    return result;
}
Also used : MOrder(org.compiere.model.MOrder) Query(org.compiere.model.Query) MInvoice(org.compiere.model.MInvoice) MOrderLine(org.compiere.model.MOrderLine)

Example 2 with MInvoice

use of org.compiere.model.MInvoice in project adempiere by adempiere.

the class SB_InvoiceGenerateFromOrderLine 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());
}
Also used : MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice)

Example 3 with MInvoice

use of org.compiere.model.MInvoice in project adempiere by adempiere.

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());
    }
    if (!invoice.save()) {
        throw new IllegalStateException("Could not update invoice");
    }
    // Add processing information to process log
    addLog(invoice.getC_Invoice_ID(), invoice.getDateInvoiced(), null, processMsg.toString());
    m_created++;
}
Also used : MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) MRMA(org.compiere.model.MRMA)

Example 4 with MInvoice

use of org.compiere.model.MInvoice in project adempiere by adempiere.

the class BankStatementPayment method createPayment.

//	createPayment
/**
	 * 	Create actual Payment
	 *	@param C_Invoice_ID invoice
	 *	@param C_BPartner_ID partner ignored when invoice exists
	 *	@param C_Currency_ID currency
	 *	@param StmtAmt statement amount
	 *	@param TrxAmt transaction amt
	 *	@param C_BankAccount_ID bank account
	 *	@param DateTrx transaction date
	 *	@param DateAcct	accounting date
	 *	@param Description description
	 *	@param AD_Org_ID org
	 *	@return payment
	 */
private MPayment createPayment(int C_Invoice_ID, int C_BPartner_ID, int C_Currency_ID, BigDecimal StmtAmt, BigDecimal TrxAmt, int C_BankAccount_ID, Timestamp DateTrx, Timestamp DateAcct, String Description, int AD_Org_ID) {
    //	Trx Amount = Payment overwrites Statement Amount if defined
    BigDecimal PayAmt = TrxAmt;
    if (PayAmt == null || Env.ZERO.compareTo(PayAmt) == 0)
        PayAmt = StmtAmt;
    if (C_Invoice_ID == 0 && (PayAmt == null || Env.ZERO.compareTo(PayAmt) == 0))
        throw new IllegalStateException("@PayAmt@ = 0");
    if (PayAmt == null)
        PayAmt = Env.ZERO;
    //
    MPayment payment = new MPayment(getCtx(), 0, get_TrxName());
    payment.setAD_Org_ID(AD_Org_ID);
    payment.setC_BankAccount_ID(C_BankAccount_ID);
    payment.setTenderType(MPayment.TENDERTYPE_Check);
    if (DateTrx != null)
        payment.setDateTrx(DateTrx);
    else if (DateAcct != null)
        payment.setDateTrx(DateAcct);
    if (DateAcct != null)
        payment.setDateAcct(DateAcct);
    else
        payment.setDateAcct(payment.getDateTrx());
    payment.setDescription(Description);
    //
    if (C_Invoice_ID != 0) {
        MInvoice invoice = new MInvoice(getCtx(), C_Invoice_ID, null);
        //	Receipt
        payment.setC_DocType_ID(invoice.isSOTrx());
        payment.setC_Invoice_ID(invoice.getC_Invoice_ID());
        payment.setC_BPartner_ID(invoice.getC_BPartner_ID());
        if (//	explicit Amount
        PayAmt.signum() != 0) {
            payment.setC_Currency_ID(C_Currency_ID);
            if (invoice.isSOTrx())
                payment.setPayAmt(PayAmt);
            else
                //	payment is likely to be negative
                payment.setPayAmt(PayAmt.negate());
            payment.setOverUnderAmt(invoice.getGrandTotal(true).subtract(payment.getPayAmt()));
        } else // set Pay Amout from Invoice
        {
            payment.setC_Currency_ID(invoice.getC_Currency_ID());
            payment.setPayAmt(invoice.getGrandTotal(true));
        }
    } else if (C_BPartner_ID != 0) {
        payment.setC_BPartner_ID(C_BPartner_ID);
        payment.setC_Currency_ID(C_Currency_ID);
        if (//	Payment
        PayAmt.signum() < 0) {
            payment.setPayAmt(PayAmt.abs());
            payment.setC_DocType_ID(false);
        } else //	Receipt
        {
            payment.setPayAmt(PayAmt);
            payment.setC_DocType_ID(true);
        }
    } else
        return null;
    payment.saveEx();
    //
    payment.processIt(MPayment.DOCACTION_Complete);
    payment.saveEx();
    return payment;
}
Also used : MPayment(org.compiere.model.MPayment) MInvoice(org.compiere.model.MInvoice) BigDecimal(java.math.BigDecimal)

Example 5 with MInvoice

use of org.compiere.model.MInvoice in project adempiere by adempiere.

the class BPartnerValidate method checkInvoices.

//	checkPayments
/**
	 * 	Check Invoices
	 *	@param bp business partner
	 */
private void checkInvoices(MBPartner bp) {
    //	See also VMerge.postMerge
    int changed = 0;
    MInvoice[] invoices = MInvoice.getOfBPartner(getCtx(), bp.getC_BPartner_ID(), get_TrxName());
    for (int i = 0; i < invoices.length; i++) {
        MInvoice invoice = invoices[i];
        if (invoice.testAllocation()) {
            invoice.saveEx();
            changed++;
        }
    }
    if (changed != 0)
        addLog(0, null, new BigDecimal(invoices.length), Msg.getElement(getCtx(), "C_Invoice_ID") + " - #" + changed);
}
Also used : MInvoice(org.compiere.model.MInvoice) BigDecimal(java.math.BigDecimal)

Aggregations

MInvoice (org.compiere.model.MInvoice)98 BigDecimal (java.math.BigDecimal)29 MInvoiceLine (org.compiere.model.MInvoiceLine)27 MPayment (org.compiere.model.MPayment)16 MBPartner (org.compiere.model.MBPartner)15 MOrder (org.compiere.model.MOrder)15 MInOut (org.compiere.model.MInOut)14 ResultSet (java.sql.ResultSet)13 PreparedStatement (java.sql.PreparedStatement)12 Timestamp (java.sql.Timestamp)11 MDocType (org.compiere.model.MDocType)9 MInOutLine (org.compiere.model.MInOutLine)8 MOrderLine (org.compiere.model.MOrderLine)7 SQLException (java.sql.SQLException)6 ArrayList (java.util.ArrayList)6 AdempiereException (org.adempiere.exceptions.AdempiereException)5 MClient (org.compiere.model.MClient)5 MLocation (org.compiere.model.MLocation)5 KeyNamePair (org.compiere.util.KeyNamePair)5 ValueNamePair (org.compiere.util.ValueNamePair)5