Search in sources :

Example 56 with MInvoice

use of org.compiere.model.MInvoice in project lar_361 by comitsrl.

the class FiscalDocumentPrint method printInvoice.

/**
 * Impresión de una factura.
 *
 * @param document
 *            factura imprimible creada a partir del documento oxp, si es
 *            null se crea una nueva a partir del documento oxp que está
 *            configurado. Dentro de este método se realiza un casting del
 *            documento parámetro hacia {@link Invoice} por lo que debe ser
 *            una instancia de esa clase sino se producirá un error en
 *            tiempo de ejecución.
 */
// TODO - Redesign this method
private void printInvoice(final Document document) throws FiscalPrinterStatusError, FiscalPrinterIOException, Exception {
    MInvoice mInvoice = (MInvoice) getOxpDocument();
    // Se valida el documento OXP.
    validateOxpDocument(mInvoice);
    /*
         * @emmie inicio - Impresion remito En caso de tratarse de una venta en
         * ctacte, se imprime el remito asocido a la factura ANTES de imprimir
         * la factura
         */
    final MOrder order = new MOrder(ctx, mInvoice.getC_Order_ID(), getTrxName());
    boolean printShipment = order.get_ValueAsBoolean("PrintShipment");
    if (printShipment && mInvoice.getC_PaymentTerm_ID() == PosOrderModel.PAYMENTTERMS_Account) {
        // Se recupera el remito de la primera linea (se asume 1 remito)
        int m_InOut_ID = mInvoice.getLines()[0].getM_InOutLine().getM_InOut_ID();
        final MInOut shipment = new MInOut(ctx, m_InOut_ID, getTrxName());
        // Crea el documento no-fiscal y luego obtiene todas las líneas del pedido
        final DNFH dnfh = createDNFH(shipment);
        // Se le indica al documento no-fiscal que no finalice la impresión
        dnfh.setPrintEnded(false);
        // Manda a imprimir el documento en la impresora fiscal
        getFiscalPrinter().printDocument(dnfh);
        // Guarda la info devuelta por el controlador
        saveShipmentData(shipment, dnfh);
    }
    // @emmie fin - Impresion remito
    // Se crea la factura imprimible en caso que no exista como parámetro
    final Invoice printeableInvoice;
    if (document != null) {
        printeableInvoice = (Invoice) document;
    } else {
        printeableInvoice = createInvoice(mInvoice);
    }
    // Se manda a imprimir la factura a la impresora fiscal.
    getFiscalPrinter().printDocument(printeableInvoice);
    // Se actualizan los datos de la factura de oxp.
    saveDocumentData(mInvoice, printeableInvoice);
}
Also used : MInOut(org.compiere.model.MInOut) MOrder(org.compiere.model.MOrder) Invoice(ar.com.ergio.print.fiscal.document.Invoice) MInvoice(org.compiere.model.MInvoice) MInvoice(org.compiere.model.MInvoice) DNFH(ar.com.ergio.print.fiscal.document.DNFH)

Example 57 with MInvoice

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

the class Doc_MatchInv method createFacts.

//  getBalance
/**
	 *  Create Facts (the accounting logic) for
	 *  MXI.
	 * 	(single line)
	 *  <pre>
	 *      NotInvoicedReceipts     DR			(Receipt Org)
	 *      InventoryClearing               CR
	 *      InvoicePV               DR      CR  (difference)
	 *  Commitment
	 * 		Expense							CR
	 * 		Offset					DR
	 *  </pre>
	 *  @param as accounting schema
	 *  @return Fact
	 */
public ArrayList<Fact> createFacts(MAcctSchema as) {
    ArrayList<Fact> facts = new ArrayList<Fact>();
    //  Nothing to do
    if (//	no Product
    getM_Product_ID() == 0 || getQty().signum() == 0 || //	Qty = 0
    m_receiptLine.getMovementQty().signum() == 0) {
        log.fine("No Product/Qty - M_Product_ID=" + getM_Product_ID() + ",Qty=" + getQty() + ",InOutQty=" + m_receiptLine.getMovementQty());
        return facts;
    }
    MCostType ct = MCostType.get(as, getM_Product_ID(), getAD_Org_ID());
    //  create Fact Header
    Fact fact = new Fact(this, as, Fact.POST_Actual);
    setC_Currency_ID(as.getC_Currency_ID());
    boolean isInterOrg = isInterOrg(as);
    /**	Needs to be handeled in PO Matching as no Receipt info
		if (m_pc.isService())
		{
			log.fine("Service - skipped");
			return fact;
		}
		**/
    if (!m_receiptLine.getM_Product().isStocked())
        return facts;
    //  NotInvoicedReceipt      DR
    //  From Receipt
    BigDecimal multiplier = getQty().divide(m_receiptLine.getMovementQty(), 12, BigDecimal.ROUND_HALF_UP).abs();
    FactLine dr = fact.createLine(null, getAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as), as.getC_Currency_ID(), Env.ONE, // updated below
    null);
    if (dr == null) {
        p_Error = "No Product Costs";
        return null;
    }
    dr.setM_Product_ID(m_receiptLine.getM_Product_ID());
    String documentBaseTypeReceipt = DB.getSQLValueString(m_receiptLine.get_TrxName(), "SELECT DocBaseType FROM C_DocType WHERE C_DocType_ID=?", m_receiptLine.getParent().getC_DocType_ID());
    BigDecimal quantityReceipt = MDocType.DOCBASETYPE_MaterialReceipt.equals(documentBaseTypeReceipt) ? getQty() : getQty().negate();
    dr.setQty(quantityReceipt);
    BigDecimal temp = dr.getAcctBalance();
    //	Set AmtAcctCr/Dr from Receipt (sets also Project)
    if (!//	Amt updated
    dr.updateReverseLine(//	Amt updated
    MInOut.Table_ID, m_receiptLine.getM_InOut_ID(), m_receiptLine.getM_InOutLine_ID(), quantityReceipt, multiplier)) {
        p_Error = "Mat.Receipt not posted yet";
        return null;
    }
    log.fine("CR - Amt(" + temp + "->" + dr.getAcctBalance() + ") - " + dr.toString());
    //  InventoryClearing               CR
    //  From Invoice
    MAccount expense = m_pc.getAccount(ProductCost.ACCTTYPE_P_InventoryClearing, as);
    if (m_pc.isService())
        expense = m_pc.getAccount(ProductCost.ACCTTYPE_P_Expense, as);
    BigDecimal LineNetAmt = m_invoiceLine.getLineNetAmt();
    multiplier = getQty().divide(m_invoiceLine.getQtyInvoiced(), 12, BigDecimal.ROUND_HALF_UP).abs();
    if (multiplier.compareTo(Env.ONE) != 0)
        LineNetAmt = LineNetAmt.multiply(multiplier);
    if (m_pc.isService())
        //	book out exact receipt amt
        LineNetAmt = dr.getAcctBalance();
    FactLine cr = null;
    if (as.isAccrual()) {
        cr = fact.createLine(null, expense, as.getC_Currency_ID(), null, //	updated below
        LineNetAmt);
        if (cr == null) {
            log.fine("Line Net Amt=0 - M_Product_ID=" + getM_Product_ID() + ",Qty=" + getQty() + ",InOutQty=" + m_receiptLine.getMovementQty());
            //  Invoice Price Variance
            BigDecimal ipv = dr.getSourceBalance().negate();
            if (ipv.signum() != 0) {
                BigDecimal costs = MCostDetail.getByDocLineMatchInv(m_invoiceLine, m_receiptLine, as.getC_AcctSchema_ID(), as.getM_CostType_ID());
                int ACCTTYPE_P = 0;
                if (MCostType.COSTINGMETHOD_StandardCosting.equals(ct.getCostingMethod()) || MCostType.COSTINGMETHOD_AverageInvoice.equals(ct.getCostingMethod()))
                    ACCTTYPE_P = ProductCost.ACCTTYPE_P_IPV;
                else
                    ACCTTYPE_P = ProductCost.ACCTTYPE_P_Asset;
                BigDecimal diff = ipv.subtract(costs);
                MInvoice m_invoice = m_invoiceLine.getParent();
                int C_Currency_ID = m_invoice.getC_Currency_ID();
                FactLine pv = fact.createLine(null, m_pc.getAccount(ACCTTYPE_P, as), C_Currency_ID, ipv);
                pv.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
                pv.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
                pv.setC_Project_ID(m_invoiceLine.getC_Project_ID());
                pv.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
                pv.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
                pv.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
                pv.setUser1_ID(m_invoiceLine.getUser1_ID());
                pv.setUser2_ID(m_invoiceLine.getUser2_ID());
                pv.setUser3_ID(m_invoiceLine.getUser3_ID());
                pv.setUser4_ID(m_invoiceLine.getUser4_ID());
                if (diff.compareTo(Env.ZERO) != 0 && MCostType.COSTINGMETHOD_AverageInvoice.equals(ct.getCostingMethod())) {
                    FactLine diffline = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as), C_Currency_ID, diff.negate());
                    diffline.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
                    diffline.setC_Project_ID(m_invoiceLine.getC_Project_ID());
                    diffline.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
                    diffline.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
                    diffline.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
                    diffline.setUser1_ID(m_invoiceLine.getUser1_ID());
                    diffline.setUser2_ID(m_invoiceLine.getUser2_ID());
                    diffline.setUser3_ID(m_invoiceLine.getUser3_ID());
                    diffline.setUser4_ID(m_invoiceLine.getUser4_ID());
                }
            }
            log.fine("IPV=" + ipv + "; Balance=" + fact.getSourceBalance());
            facts.add(fact);
            return facts;
        }
        cr.setM_Product_ID(m_invoiceLine.getM_Product_ID());
        temp = cr.getAcctBalance();
        String documentBaseTypeInvoice = DB.getSQLValueString(m_invoiceLine.get_TrxName(), "SELECT DocBaseType FROM C_DocType WHERE C_DocType_ID=?", m_invoiceLine.getParent().getC_DocType_ID());
        BigDecimal quantityInvoice = MDocType.DOCBASETYPE_APInvoice.equals(documentBaseTypeInvoice) ? getQty().negate() : getQty();
        cr.setQty(quantityInvoice);
        //	Set AmtAcctCr/Dr from Invoice (sets also Project)
        if (as.isAccrual() && !//	Amt updated
        cr.updateReverseLine(//	Amt updated
        MInvoice.Table_ID, m_invoiceLine.getC_Invoice_ID(), m_invoiceLine.getC_InvoiceLine_ID(), quantityInvoice, multiplier)) {
            p_Error = "Invoice not posted yet";
            return null;
        }
        log.fine("DR - Amt(" + temp + "->" + cr.getAcctBalance() + ") - " + cr.toString());
    } else //	Cash Acct
    {
        MInvoice invoice = m_invoiceLine.getParent();
        if (as.getC_Currency_ID() != invoice.getC_Currency_ID())
            LineNetAmt = MConversionRate.convert(getCtx(), LineNetAmt, invoice.getC_Currency_ID(), as.getC_Currency_ID(), invoice.getDateAcct(), invoice.getC_ConversionType_ID(), invoice.getAD_Client_ID(), invoice.getAD_Org_ID());
        cr = fact.createLine(null, expense, as.getC_Currency_ID(), null, LineNetAmt);
        cr.setQty(getQty().multiply(multiplier).negate());
    }
    cr.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
    cr.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
    cr.setC_Project_ID(m_invoiceLine.getC_Project_ID());
    cr.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
    cr.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
    cr.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
    cr.setUser1_ID(m_invoiceLine.getUser1_ID());
    cr.setUser2_ID(m_invoiceLine.getUser2_ID());
    cr.setUser3_ID(m_invoiceLine.getUser3_ID());
    cr.setUser4_ID(m_invoiceLine.getUser4_ID());
    //see also Fact.java: checking for isMultiCurrency()
    if (dr.getC_Currency_ID() != cr.getC_Currency_ID())
        setIsMultiCurrency(true);
    //end AZ
    // Avoid usage of clearing accounts
    // If both accounts Not Invoiced Receipts and Inventory Clearing are equal
    // then remove the posting
    // not_invoiced_receipts
    MAccount acct_db = dr.getAccount();
    // inventory_clearing
    MAccount acct_cr = cr.getAccount();
    if ((!as.isPostIfClearingEqual()) && acct_db.equals(acct_cr) && (!isInterOrg)) {
        BigDecimal debit = dr.getAmtSourceDr();
        BigDecimal credit = cr.getAmtSourceCr();
        if (debit.compareTo(credit) == 0) {
            fact.remove(dr);
            fact.remove(cr);
        }
    }
    // End Avoid usage of clearing accounts
    //  Invoice Price Variance 	difference
    BigDecimal ipv = cr.getAcctBalance().add(dr.getAcctBalance()).negate();
    if (ipv.compareTo(Env.ZERO) == 0) {
        facts.add(fact);
        return facts;
    }
    if (!MCostType.COSTINGMETHOD_AverageInvoice.equals(ct.getCostingMethod())) {
        int ACCTTYPE_P = 0;
        if (MCostType.COSTINGMETHOD_StandardCosting.equals(ct.getCostingMethod()) || MCostType.COSTINGMETHOD_AverageInvoice.equals(ct.getCostingMethod()))
            ACCTTYPE_P = ProductCost.ACCTTYPE_P_IPV;
        else
            ACCTTYPE_P = ProductCost.ACCTTYPE_P_Asset;
        FactLine pv = fact.createLine(null, m_pc.getAccount(ACCTTYPE_P, as), as.getC_Currency_ID(), ipv);
        pv.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
        pv.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
        pv.setC_Project_ID(m_invoiceLine.getC_Project_ID());
        pv.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
        pv.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
        pv.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
        pv.setUser1_ID(m_invoiceLine.getUser1_ID());
        pv.setUser2_ID(m_invoiceLine.getUser2_ID());
        pv.setUser3_ID(m_invoiceLine.getUser3_ID());
        pv.setUser4_ID(m_invoiceLine.getUser4_ID());
    //
    } else {
        BigDecimal costs = MCostDetail.getByDocLineMatchInv(m_invoiceLine, m_receiptLine, as.getC_AcctSchema_ID(), as.getM_CostType_ID());
        FactLine pv = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_Asset, as), as.getC_Currency_ID(), costs);
        if (pv != null) {
            pv.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
            pv.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
            pv.setC_Project_ID(m_invoiceLine.getC_Project_ID());
            pv.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
            pv.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
            pv.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
            pv.setUser1_ID(m_invoiceLine.getUser1_ID());
            pv.setUser2_ID(m_invoiceLine.getUser2_ID());
            pv.setUser3_ID(m_invoiceLine.getUser3_ID());
            pv.setUser4_ID(m_invoiceLine.getUser4_ID());
        }
        BigDecimal diff = ipv.subtract(costs);
        MInvoice m_invoice = m_invoiceLine.getParent();
        if (diff.compareTo(Env.ZERO) != 0) {
            FactLine diffline = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as), as.getC_Currency_ID(), diff);
            if (diffline != null) {
                diffline.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
                diffline.setC_Project_ID(m_invoiceLine.getC_Project_ID());
                diffline.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
                diffline.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
                diffline.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
                diffline.setUser1_ID(m_invoiceLine.getUser1_ID());
                diffline.setUser2_ID(m_invoiceLine.getUser2_ID());
                diffline.setUser3_ID(m_invoiceLine.getUser3_ID());
                diffline.setUser4_ID(m_invoiceLine.getUser4_ID());
            }
        }
    }
    log.fine("IPV=" + ipv + "; Balance=" + fact.getSourceBalance());
    facts.add(fact);
    /** Commitment release										****/
    if (as.isAccrual() && as.isCreatePOCommitment()) {
        fact = Doc_Order.getCommitmentRelease(as, this, getQty(), m_invoiceLine.getC_InvoiceLine_ID(), Env.ONE);
        if (fact == null)
            return null;
        facts.add(fact);
    }
    return facts;
}
Also used : MAccount(org.compiere.model.MAccount) ArrayList(java.util.ArrayList) MInvoice(org.compiere.model.MInvoice) MCostType(org.compiere.model.MCostType) BigDecimal(java.math.BigDecimal)

Example 58 with MInvoice

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;
}
Also used : MOrder(org.compiere.model.MOrder) MPayment(org.compiere.model.MPayment) MInvoice(org.compiere.model.MInvoice) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement) MCashLine(org.compiere.model.MCashLine)

Example 59 with MInvoice

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;
}
Also used : MDocType(org.compiere.model.MDocType) MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) MBPartner(org.compiere.model.MBPartner) MLocation(org.compiere.model.MLocation) MClient(org.compiere.model.MClient)

Example 60 with MInvoice

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());
}
Also used : MDocType(org.compiere.model.MDocType) MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) MBPartner(org.compiere.model.MBPartner) MLocation(org.compiere.model.MLocation) MClient(org.compiere.model.MClient)

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