Search in sources :

Example 21 with MDocType

use of org.compiere.model.MDocType 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 22 with MDocType

use of org.compiere.model.MDocType 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)

Example 23 with MDocType

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

the class CopyOrder method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message (clear text)
	 *  @throws Exception if not successful
	 */
protected String doIt() throws Exception {
    log.info("C_Order_ID=" + p_C_Order_ID + ", C_DocType_ID=" + p_C_DocType_ID + ", CloseDocument=" + p_IsCloseDocument);
    if (p_C_Order_ID == 0)
        throw new IllegalArgumentException("No Order");
    MDocType dt = MDocType.get(getCtx(), p_C_DocType_ID);
    if (dt.get_ID() == 0)
        throw new IllegalArgumentException("No DocType");
    if (p_DateDoc == null)
        p_DateDoc = new Timestamp(System.currentTimeMillis());
    //
    MOrder from = new MOrder(getCtx(), p_C_Order_ID, get_TrxName());
    MOrder newOrder = MOrder.copyFrom(from, p_DateDoc, dt.getC_DocType_ID(), dt.isSOTrx(), false, true, //	copy ASI
    get_TrxName());
    newOrder.setC_DocTypeTarget_ID(p_C_DocType_ID);
    boolean OK = newOrder.save();
    if (!OK)
        throw new IllegalStateException("Could not create new Order");
    //
    if (p_IsCloseDocument) {
        MOrder original = new MOrder(getCtx(), p_C_Order_ID, get_TrxName());
        original.setDocAction(MOrder.DOCACTION_Complete);
        original.processIt(MOrder.DOCACTION_Complete);
        original.saveEx();
        original.setDocAction(MOrder.DOCACTION_Close);
        original.processIt(MOrder.DOCACTION_Close);
        original.saveEx();
    }
    //	return "@C_Order_ID@ " + newOrder.getDocumentNo();
    return dt.getName() + ": " + newOrder.getDocumentNo();
}
Also used : MDocType(org.compiere.model.MDocType) MOrder(org.compiere.model.MOrder) Timestamp(java.sql.Timestamp)

Example 24 with MDocType

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

the class MDDOrder method prepareIt.

//	invalidateIt
/**************************************************************************
	 *	Prepare Document
	 * 	@return new status (In Progress or Invalid) 
	 */
public String prepareIt() {
    log.info(toString());
    processMessage = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
    if (processMessage != null)
        return DocAction.STATUS_Invalid;
    MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
    //	Std Period open?
    if (!MPeriod.isOpen(getCtx(), getDateOrdered(), dt.getDocBaseType(), getAD_Org_ID())) {
        processMessage = "@PeriodClosed@";
        return DocAction.STATUS_Invalid;
    }
    List<MDDOrderLine> orderLines = getLines(true, "M_Product_ID");
    if (orderLines.isEmpty()) {
        processMessage = "@NoLines@";
        return DocAction.STATUS_Invalid;
    }
    // Bug 1564431
    if (getDeliveryRule() != null && getDeliveryRule().equals(MDDOrder.DELIVERYRULE_CompleteOrder)) {
        /*for (int i = 0; i < lines.length; i++)
			{
				MDDOrderLine line = lines[i];
				MProduct product = line.getProduct();
				if (product != null && product.isExcludeAutoDelivery())
				{
					processMessage = "@M_Product_ID@ "+product.getValue()+" @IsExcludeAutoDelivery@";
					return DocAction.STATUS_Invalid;
				}
			}*/
        orderLines.stream().filter(orderLine -> orderLine.getProduct() != null && orderLine.getProduct().isExcludeAutoDelivery()).map(orderLine -> {
            processMessage = "@M_Product_ID@ " + orderLine.getProduct().getValue() + " @IsExcludeAutoDelivery@";
            return DocAction.STATUS_Invalid;
        });
    }
    //	Mandatory Product Attribute Set Instance
    //	IN ('Y','S')
    String mandatoryType = "='Y'";
    String sql = "SELECT COUNT(*) " + "FROM DD_OrderLine ol" + " INNER JOIN M_Product p ON (ol.M_Product_ID=p.M_Product_ID)" + " INNER JOIN M_AttributeSet pas ON (p.M_AttributeSet_ID=pas.M_AttributeSet_ID) " + "WHERE pas.MandatoryType" + mandatoryType + " AND ol.M_AttributeSetInstance_ID IS NULL" + " AND ol.DD_Order_ID=?";
    int no = DB.getSQLValue(get_TrxName(), sql, getDD_Order_ID());
    if (no != 0) {
        processMessage = "@LinesWithoutProductAttribute@ (" + no + ")";
        return DocAction.STATUS_Invalid;
    }
    reserveStock(orderLines);
    processMessage = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE);
    if (processMessage != null)
        return DocAction.STATUS_Invalid;
    justPrepared = true;
    return DocAction.STATUS_InProgress;
}
Also used : DocumentEngine(org.compiere.process.DocumentEngine) Arrays(java.util.Arrays) MProject(org.compiere.model.MProject) Date(java.util.Date) Env(org.compiere.util.Env) ProcessBuilder(org.eevolution.service.dsl.ProcessBuilder) MStorage(org.compiere.model.MStorage) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) MBPartnerLocation(org.compiere.model.MBPartnerLocation) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) Query(org.compiere.model.Query) DB(org.compiere.util.DB) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MBPartner(org.compiere.model.MBPartner) Msg(org.compiere.util.Msg) ResultSet(java.sql.ResultSet) MPeriod(org.compiere.model.MPeriod) ProcessInfo(org.compiere.process.ProcessInfo) DocAction(org.compiere.process.DocAction) Util(org.compiere.util.Util) Properties(java.util.Properties) GenerateMovement(org.eevolution.process.GenerateMovement) Timestamp(java.sql.Timestamp) MDocType(org.compiere.model.MDocType) MRefList(org.compiere.model.MRefList) File(java.io.File) ZoneId(java.time.ZoneId) ReportEngine(org.compiere.print.ReportEngine) ModelValidator(org.compiere.model.ModelValidator) List(java.util.List) AdempiereException(org.adempiere.exceptions.AdempiereException) MMovement(org.compiere.model.MMovement) LocalDate(java.time.LocalDate) I_C_DocType(org.compiere.model.I_C_DocType) Optional(java.util.Optional) MLocator(org.compiere.model.MLocator) PO(org.compiere.model.PO) ModelValidationEngine(org.compiere.model.ModelValidationEngine) GenerateMovementMaterial(org.eevolution.process.GenerateMovementMaterial) MDocType(org.compiere.model.MDocType)

Example 25 with MDocType

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

the class CollectDetail method getOpenAmtCreditMemo.

public BigDecimal getOpenAmtCreditMemo() {
    BigDecimal m_PayAmt = Env.ZERO;
    if (m_C_Invoice_ID == 0)
        return m_PayAmt;
    m_CreditMemo = MInvoice.get(Env.getCtx(), m_C_Invoice_ID);
    MDocType dt = MDocType.get(m_CreditMemo.getCtx(), m_CreditMemo.getC_DocType_ID());
    m_PayAmt = m_CreditMemo.getOpenAmt();
    if (MDocType.DOCBASETYPE_APInvoice.equals(dt.getDocBaseType()) || MDocType.DOCBASETYPE_ARCreditMemo.equals(dt.getDocBaseType()))
        m_PayAmt = m_PayAmt.negate();
    if (m_PayAmt.compareTo(getPayAmt()) > 0) {
        m_PayAmt = getPayAmt();
    }
    return m_PayAmt;
}
Also used : MDocType(org.compiere.model.MDocType) BigDecimal(java.math.BigDecimal)

Aggregations

MDocType (org.compiere.model.MDocType)29 MInvoice (org.compiere.model.MInvoice)5 ResultSet (java.sql.ResultSet)4 Timestamp (java.sql.Timestamp)4 MBPartner (org.compiere.model.MBPartner)4 BigDecimal (java.math.BigDecimal)3 PreparedStatement (java.sql.PreparedStatement)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MClient (org.compiere.model.MClient)3 MInvoiceLine (org.compiere.model.MInvoiceLine)3 MLocation (org.compiere.model.MLocation)3 MOrder (org.compiere.model.MOrder)3 Query (org.compiere.model.Query)3 MInOutLine (org.compiere.model.MInOutLine)2 MMatchInv (org.compiere.model.MMatchInv)2 MOrderLine (org.compiere.model.MOrderLine)2 MProduct (org.compiere.model.MProduct)2 MWarehouse (org.compiere.model.MWarehouse)2 ProcessInfo (org.compiere.process.ProcessInfo)2 AdempiereSystemError (org.compiere.util.AdempiereSystemError)2