Search in sources :

Example 31 with MOrderLine

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

the class VProductConfigurationBOM method cmd_saveOrder.

/**
	 * 	Save to Order
	 *	@param C_Order_ID id
	 *	@return true if saved
	 */
private boolean cmd_saveOrder(int C_Order_ID) {
    log.config("C_Order_ID=" + C_Order_ID);
    MOrder order = new MOrder(Env.getCtx(), C_Order_ID, null);
    if (order.get_ID() == 0) {
        log.log(Level.SEVERE, "Not found - C_Order_ID=" + C_Order_ID);
        return false;
    }
    //FIXME:  Change to search for correct product, but because
    //we only have the one product to use, that is automatically
    //chosen.
    m_qty = (BigDecimal) productQty.getValue();
    log.fine("printing product config tree");
    printTree(this.m_RadioButtonTreeCellRenderer.root);
    while (pruneProductConfig()) ;
    int M_Product_ID = -1;
    boolean replaceResult = replaceProductConfigBOMwithProductFromChoices();
    log.fine("replaceResult: " + replaceResult);
    if (replaceResult) {
        log.fine("After replacement product config tree");
        printTree(this.m_RadioButtonTreeCellRenderer.root);
        M_Product_ID = findProductInstance();
    }
    log.fine("M_Product_ID: " + M_Product_ID);
    if (M_Product_ID < 0 || !replaceResult) {
        log.fine("No product instance found for the configuration chosen");
        String warningMsg = "No product instance found for the configuration chosen, create one?";
        String warningTitle = "Warning";
        int response = JOptionPane.showConfirmDialog(null, warningMsg, warningTitle, JOptionPane.YES_NO_OPTION);
        if (response == JOptionPane.YES_OPTION) {
            log.fine("create product instance");
        }
    }
    MOrderLine ol = new MOrderLine(order);
    ol.setM_Product_ID(m_product.get_ID(), true);
    ol.setQty(m_qty);
    ol.setPrice();
    ol.setTax();
    if (ol.save())
        log.fine("order line saved");
    else
        log.log(Level.SEVERE, "Line not saved");
    int lineCount = 0;
    //	for all bom lines
    /* FIXME: This needs to be changed to search for a product
                   that is a production configuration BOM instance of all
                   the choices made.  This product configuration BOM instance
		   would then be associated with one product which would be
		   added to the sales order.
		for (int i = 0; i < m_selectionList.size(); i++)
		{
			if (isSelectionSelected(m_selectionList.get(i)))
			{
				BigDecimal qty = (BigDecimal)((VNumber)m_qtyList.get(i)).getValue();
		//	for all bom lines
		for (int i = 0; i < m_selectionList.size(); i++)
		{
			if (isSelectionSelected(m_selectionList.get(i)))
			{
				int M_Product_ID = ((Integer)m_productList.get(i)).intValue();
			}	//	line selected
		}	//	for all bom lines

				int M_Product_ID = ((Integer)m_productList.get(i)).intValue();
				//	Create Line
				MOrderLine ol = new MOrderLine (order);
				ol.setM_Product_ID(M_Product_ID, true);
				ol.setQty(qty);
				ol.setPrice();
				ol.setTax();
				if (ol.save())
					lineCount++;
				else
					log.log(Level.SEVERE, "Line not saved");
			}	//	line selected
		}	//	for all bom lines
		*/
    log.config("#" + lineCount);
    return true;
}
Also used : MOrder(org.compiere.model.MOrder) MOrderLine(org.compiere.model.MOrderLine) ALayoutConstraint(org.compiere.apps.ALayoutConstraint)

Example 32 with MOrderLine

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

the class ProjectGenPO method createPO.

//	doIt
/**
	 * 	Create PO from Planned Amt/Qty
	 * 	@param projectLine project line
	 */
private void createPO(MProject project, MProjectLine projectLine) {
    if (projectLine.getM_Product_ID() == 0) {
        addLog(projectLine.getLine(), null, null, "Line has no Product");
        return;
    }
    if (projectLine.getC_OrderPO_ID() != 0) {
        addLog(projectLine.getLine(), null, null, "Line was ordered previously");
        return;
    }
    //	PO Record
    MProductPO[] pos = MProductPO.getOfProduct(getCtx(), projectLine.getM_Product_ID(), get_TrxName());
    if (pos == null || pos.length == 0) {
        addLog(projectLine.getLine(), null, null, "Product has no PO record");
        return;
    }
    //	Create to Order
    MOrder order = null;
    //	try to find PO to C_BPartner
    for (int i = 0; i < m_pos.size(); i++) {
        MOrder test = (MOrder) m_pos.get(i);
        if (test.getC_BPartner_ID() == pos[0].getC_BPartner_ID()) {
            order = test;
            break;
        }
    }
    if (//	create new Order
    order == null) {
        //	Vendor
        MBPartner bp = new MBPartner(getCtx(), pos[0].getC_BPartner_ID(), get_TrxName());
        //	New Order
        order = new MOrder(project, false, null);
        int AD_Org_ID = projectLine.getAD_Org_ID();
        if (AD_Org_ID == 0) {
            log.warning("createPOfromProjectLine - AD_Org_ID=0");
            AD_Org_ID = Env.getAD_Org_ID(getCtx());
            if (AD_Org_ID != 0)
                projectLine.setAD_Org_ID(AD_Org_ID);
        }
        order.setClientOrg(projectLine.getAD_Client_ID(), AD_Org_ID);
        order.setBPartner(bp);
        order.save();
        //	optionally save for consolidation
        if (m_ConsolidateDocument)
            m_pos.add(order);
    }
    //	Create Line
    MOrderLine orderLine = new MOrderLine(order);
    orderLine.setM_Product_ID(projectLine.getM_Product_ID(), true);
    orderLine.setQty(projectLine.getPlannedQty());
    orderLine.setDescription(projectLine.getDescription());
    //	(Vendor) PriceList Price
    orderLine.setPrice();
    if (orderLine.getPriceActual().signum() == 0) {
        //	Try to find purchase price
        BigDecimal poPrice = pos[0].getPricePO();
        int C_Currency_ID = pos[0].getC_Currency_ID();
        //
        if (poPrice == null || poPrice.signum() == 0)
            poPrice = pos[0].getPriceLastPO();
        if (poPrice == null || poPrice.signum() == 0)
            poPrice = pos[0].getPriceList();
        //	We have a price
        if (poPrice != null && poPrice.signum() != 0) {
            if (order.getC_Currency_ID() != C_Currency_ID)
                poPrice = MConversionRate.convert(getCtx(), poPrice, C_Currency_ID, order.getC_Currency_ID(), order.getDateAcct(), order.getC_ConversionType_ID(), order.getAD_Client_ID(), order.getAD_Org_ID());
            orderLine.setPrice(poPrice);
        }
    }
    orderLine.setTax();
    orderLine.saveEx();
    //	update ProjectLine
    projectLine.setC_OrderPO_ID(order.getC_Order_ID());
    projectLine.saveEx();
    addLog(projectLine.getLine(), null, projectLine.getPlannedQty(), order.getDocumentNo());
}
Also used : MOrder(org.compiere.model.MOrder) MProductPO(org.compiere.model.MProductPO) MBPartner(org.compiere.model.MBPartner) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Example 33 with MOrderLine

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

the class OrderPOCreate method createPOFromSO.

//	doIt
/**
	 * 	Create PO From SO
	 *	@param so sales order
	 *	@return number of POs created
	 * @throws Exception 
	 */
private int createPOFromSO(MOrder so) throws Exception {
    log.info(so.toString());
    MOrderLine[] soLines = so.getLines(true, null);
    if (soLines == null || soLines.length == 0) {
        log.warning("No Lines - " + so);
        return 0;
    }
    //
    int counter = 0;
    //	Order Lines with a Product which has a current vendor 
    String sql = "SELECT MIN(po.C_BPartner_ID), po.M_Product_ID " + "FROM M_Product_PO po" + " INNER JOIN C_OrderLine ol ON (po.M_Product_ID=ol.M_Product_ID) " + "WHERE ol.C_Order_ID=? AND po.IsCurrentVendor='Y' " + ((p_Vendor_ID > 0) ? " AND po.C_BPartner_ID=? " : "") + "GROUP BY po.M_Product_ID " + "ORDER BY 1";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    MOrder po = null;
    try {
        pstmt = DB.prepareStatement(sql, get_TrxName());
        pstmt.setInt(1, so.getC_Order_ID());
        if (p_Vendor_ID != 0)
            pstmt.setInt(2, p_Vendor_ID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            //	New Order
            int C_BPartner_ID = rs.getInt(1);
            if (po == null || po.getBill_BPartner_ID() != C_BPartner_ID) {
                po = createPOForVendor(rs.getInt(1), so);
                addLog(0, null, null, po.getDocumentNo());
                counter++;
            }
            //	Line
            int M_Product_ID = rs.getInt(2);
            for (int i = 0; i < soLines.length; i++) {
                if (soLines[i].getM_Product_ID() == M_Product_ID) {
                    MOrderLine poLine = new MOrderLine(po);
                    poLine.setLink_OrderLine_ID(soLines[i].getC_OrderLine_ID());
                    poLine.setM_Product_ID(soLines[i].getM_Product_ID());
                    poLine.setC_Charge_ID(soLines[i].getC_Charge_ID());
                    poLine.setM_AttributeSetInstance_ID(soLines[i].getM_AttributeSetInstance_ID());
                    poLine.setC_UOM_ID(soLines[i].getC_UOM_ID());
                    poLine.setQtyEntered(soLines[i].getQtyEntered());
                    poLine.setQtyOrdered(soLines[i].getQtyOrdered());
                    poLine.setDescription(soLines[i].getDescription());
                    poLine.setDatePromised(soLines[i].getDatePromised());
                    poLine.setPrice();
                    poLine.saveEx();
                    soLines[i].setLink_OrderLine_ID(poLine.getC_OrderLine_ID());
                    soLines[i].saveEx();
                }
            }
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
        throw e;
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //	Set Reference to PO
    if (counter == 1 && po != null) {
        so.setLink_Order_ID(po.getC_Order_ID());
        so.saveEx();
    }
    return counter;
}
Also used : MOrder(org.compiere.model.MOrder) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MOrderLine(org.compiere.model.MOrderLine)

Example 34 with MOrderLine

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

the class ProjectPhaseGenOrder method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message (clear text)
	 *  @throws Exception if not successful
	 */
protected String doIt() throws Exception {
    m_C_ProjectPhase_ID = getRecord_ID();
    log.info("doIt - C_ProjectPhase_ID=" + m_C_ProjectPhase_ID);
    if (m_C_ProjectPhase_ID == 0)
        throw new IllegalArgumentException("C_ProjectPhase_ID == 0");
    MProjectPhase fromPhase = new MProjectPhase(getCtx(), m_C_ProjectPhase_ID, get_TrxName());
    MProject fromProject = ProjectGenOrder.getProject(getCtx(), fromPhase.getC_Project_ID(), get_TrxName());
    MOrder order = new MOrder(fromProject, true, MOrder.DocSubTypeSO_OnCredit);
    order.setDescription(order.getDescription() + " - " + fromPhase.getName());
    if (!order.save())
        throw new Exception("Could not create Order");
    //	Create an order on Phase Level
    if (fromPhase.getM_Product_ID() != 0) {
        MOrderLine ol = new MOrderLine(order);
        ol.setLine(fromPhase.getSeqNo());
        StringBuffer sb = new StringBuffer(fromPhase.getName());
        if (fromPhase.getDescription() != null && fromPhase.getDescription().length() > 0)
            sb.append(" - ").append(fromPhase.getDescription());
        ol.setDescription(sb.toString());
        //
        ol.setM_Product_ID(fromPhase.getM_Product_ID(), true);
        ol.setQty(fromPhase.getQty());
        ol.setPrice();
        if (fromPhase.getPriceActual() != null && fromPhase.getPriceActual().compareTo(Env.ZERO) != 0)
            ol.setPrice(fromPhase.getPriceActual());
        ol.setTax();
        if (!ol.save())
            log.log(Level.SEVERE, "doIt - Lines not generated");
        return "@C_Order_ID@ " + order.getDocumentNo() + " (1)";
    }
    //	Project Phase Lines
    int count = 0;
    MProjectLine[] lines = fromPhase.getLines();
    for (int i = 0; i < lines.length; i++) {
        MOrderLine ol = new MOrderLine(order);
        ol.setLine(lines[i].getLine());
        ol.setDescription(lines[i].getDescription());
        //
        ol.setM_Product_ID(lines[i].getM_Product_ID(), true);
        ol.setQty(lines[i].getPlannedQty().subtract(lines[i].getInvoicedQty()));
        ol.setPrice();
        if (lines[i].getPlannedPrice() != null && lines[i].getPlannedPrice().compareTo(Env.ZERO) != 0)
            ol.setPrice(lines[i].getPlannedPrice());
        ol.setDiscount();
        ol.setTax();
        if (ol.save())
            count++;
    }
    //	for all lines
    if (lines.length != count)
        log.log(Level.SEVERE, "Lines difference - ProjectLines=" + lines.length + " <> Saved=" + count);
    //	Project Tasks
    MProjectTask[] tasks = fromPhase.getTasks();
    for (int i = 0; i < tasks.length; i++) {
        MOrderLine ol = new MOrderLine(order);
        ol.setLine(tasks[i].getSeqNo());
        StringBuffer sb = new StringBuffer(tasks[i].getName());
        if (tasks[i].getDescription() != null && tasks[i].getDescription().length() > 0)
            sb.append(" - ").append(tasks[i].getDescription());
        ol.setDescription(sb.toString());
        //
        ol.setM_Product_ID(tasks[i].getM_Product_ID(), true);
        ol.setQty(tasks[i].getQty());
        ol.setPrice();
        ol.setTax();
        if (ol.save())
            count++;
    }
    //	for all lines
    if (tasks.length != count - lines.length)
        log.log(Level.SEVERE, "doIt - Lines difference - ProjectTasks=" + tasks.length + " <> Saved=" + count);
    return "@C_Order_ID@ " + order.getDocumentNo() + " (" + count + ")";
}
Also used : MOrder(org.compiere.model.MOrder) MProjectTask(org.compiere.model.MProjectTask) MProjectPhase(org.compiere.model.MProjectPhase) MOrderLine(org.compiere.model.MOrderLine) MProject(org.compiere.model.MProject) MProjectLine(org.compiere.model.MProjectLine)

Example 35 with MOrderLine

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

the class MPPOrder method updateMakeToKit.

/**
	 * Create Auto Receipt and Issue based on Quantity
	 * @param qtyShipment
	 */
public void updateMakeToKit(BigDecimal qtyShipment) {
    MPPOrderBOM orderBOM = (MPPOrderBOM) getMPPOrderBOM();
    getLines(true);
    // Auto receipt and issue for kit
    if (MPPOrderBOM.BOMTYPE_Make_To_Kit.equals(orderBOM.getBOMType()) && MPPOrderBOM.BOMUSE_Manufacturing.equals(orderBOM.getBOMUse())) {
        Timestamp today = new Timestamp(System.currentTimeMillis());
        ArrayList[][] issue = new ArrayList[m_lines.length][1];
        for (int i = 0; i < getLines().length; i++) {
            MPPOrderBOMLine line = m_lines[i];
            KeyNamePair id = null;
            if (MPPOrderBOMLine.ISSUEMETHOD_Backflush.equals(line.getIssueMethod())) {
                id = new KeyNamePair(line.get_ID(), "Y");
            } else
                id = new KeyNamePair(line.get_ID(), "N");
            ArrayList<Object> data = new ArrayList<Object>();
            BigDecimal qtyToDeliver = qtyShipment.multiply(line.getQtyMultiplier());
            //0 - MPPOrderBOMLine ID
            data.add(id);
            //1 - Critical
            data.add(line.isCritical());
            MProduct product = (MProduct) line.getM_Product();
            //2 - Value
            data.add(product.getValue());
            KeyNamePair productKey = new KeyNamePair(product.get_ID(), product.getName());
            //3 - KeyNamePair Product
            data.add(productKey);
            //4 - QtyToDeliver			
            data.add(qtyToDeliver);
            //5 - QtyScrapComponent
            data.add(Env.ZERO);
            issue[i][0] = data;
        }
        boolean forceIssue = false;
        MOrderLine orderLine = (MOrderLine) getC_OrderLine();
        if (MOrder.DELIVERYRULE_CompleteLine.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_CompleteOrder.equals(orderLine.getParent().getDeliveryRule())) {
            boolean isCompleteQtyDeliver = MPPOrder.isQtyAvailable(this, issue, today);
            if (!isCompleteQtyDeliver) {
                throw new AdempiereException("@NoQtyAvailable@");
            }
        } else if (MOrder.DELIVERYRULE_Availability.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_AfterReceipt.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_Manual.equals(orderLine.getParent().getDeliveryRule())) {
            throw new AdempiereException("@DeliveryRule@ " + orderLine.getParent().getDeliveryRule() + "@ActionNotSupported@");
        } else if (MOrder.DELIVERYRULE_Force.equals(orderLine.getParent().getDeliveryRule())) {
            forceIssue = true;
        }
        for (int i = 0; i < issue.length; i++) {
            int attributeSetInstanceId = 0;
            KeyNamePair key = (KeyNamePair) issue[i][0].get(0);
            Boolean isCritical = (Boolean) issue[i][0].get(1);
            String value = (String) issue[i][0].get(2);
            KeyNamePair productkey = (KeyNamePair) issue[i][0].get(3);
            int productId = productkey.getKey();
            MProduct product = MProduct.get(getCtx(), productId);
            BigDecimal qtyToDeliver = (BigDecimal) issue[i][0].get(4);
            BigDecimal qtyScrapComponent = (BigDecimal) issue[i][0].get(5);
            MPPOrderBOMLine orderBOMLine = null;
            int orderBOMLineId = (Integer) key.getKey();
            if (orderBOMLineId > 0) {
                orderBOMLine = new MPPOrderBOMLine(getCtx(), orderBOMLineId, get_TrxName());
                //Validate if AttributeSet generate instance
                attributeSetInstanceId = orderBOMLine.getM_AttributeSetInstance_ID();
            }
            MStorage[] storages = MPPOrder.getStorages(getCtx(), productId, getM_Warehouse_ID(), attributeSetInstanceId, today, get_TrxName());
            MPPOrder.createIssue(this, orderBOMLine, today, qtyToDeliver, qtyScrapComponent, Env.ZERO, storages, forceIssue);
        }
        MPPOrder.createReceipt(this, today, getQtyDelivered(), qtyShipment, getQtyScrap(), getQtyReject(), getM_Locator_ID(), getM_AttributeSetInstance_ID());
    }
}
Also used : MProduct(org.compiere.model.MProduct) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) AdempiereException(org.adempiere.exceptions.AdempiereException) KeyNamePair(org.compiere.util.KeyNamePair) MOrderLine(org.compiere.model.MOrderLine)

Aggregations

MOrderLine (org.compiere.model.MOrderLine)87 BigDecimal (java.math.BigDecimal)44 MOrder (org.compiere.model.MOrder)42 MInOutLine (org.compiere.model.MInOutLine)16 MProduct (org.compiere.model.MProduct)15 MBPartner (org.compiere.model.MBPartner)14 MInOut (org.compiere.model.MInOut)11 ResultSet (java.sql.ResultSet)10 ArrayList (java.util.ArrayList)8 Query (org.compiere.model.Query)8 PreparedStatement (java.sql.PreparedStatement)7 MInvoice (org.compiere.model.MInvoice)7 MInvoiceLine (org.compiere.model.MInvoiceLine)7 AdempiereException (org.adempiere.exceptions.AdempiereException)6 SQLException (java.sql.SQLException)5 MLocator (org.compiere.model.MLocator)5 Timestamp (java.sql.Timestamp)4 MRMALine (org.compiere.model.MRMALine)4 MBPartnerLocation (org.compiere.model.MBPartnerLocation)3 MDocType (org.compiere.model.MDocType)3