Search in sources :

Example 11 with MProjectLine

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

the class ProjectGenOrder method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message (clear text)
	 *  @throws Exception if not successful
	 */
protected String doIt() throws Exception {
    log.info("C_Project_ID=" + m_C_Project_ID);
    if (m_C_Project_ID == 0)
        throw new IllegalArgumentException("C_Project_ID == 0");
    MProject fromProject = getProject(getCtx(), m_C_Project_ID, get_TrxName());
    //	Set SO context
    Env.setSOTrx(getCtx(), true);
    /** @todo duplicate invoice prevention */
    MOrder order = new MOrder(fromProject, true, MOrder.DocSubTypeSO_OnCredit);
    if (!order.save())
        throw new Exception("Could not create Order");
    //	***	Lines ***
    int count = 0;
    //	Service Project	
    if (MProject.PROJECTCATEGORY_ServiceChargeProject.equals(fromProject.getProjectCategory())) {
        /** @todo service project invoicing */
        throw new Exception("Service Charge Projects are on the TODO List");
    } else //	Service Lines
    //	Order Lines
    {
        MProjectLine[] lines = fromProject.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);
    }
    return "@C_Order_ID@ " + order.getDocumentNo() + " (" + count + ")";
}
Also used : MOrder(org.compiere.model.MOrder) MOrderLine(org.compiere.model.MOrderLine) MProject(org.compiere.model.MProject) MProjectLine(org.compiere.model.MProjectLine)

Example 12 with MProjectLine

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

the class VProductConfigurationBOM method cmd_saveProject.

//	cmd_saveInvoice
/**
	 * 	Save to Project
	 *	@param C_Project_ID id
	 *	@return true if saved
	 */
private boolean cmd_saveProject(int C_Project_ID) {
    log.config("C_Project_ID=" + C_Project_ID);
    MProject project = new MProject(Env.getCtx(), C_Project_ID, null);
    if (project.get_ID() == 0) {
        log.log(Level.SEVERE, "Not found - C_Project_ID=" + C_Project_ID);
        return false;
    }
    int lineCount = 0;
    //	for all bom lines
    for (int i = 0; i < m_selectionList.size(); i++) {
        if (isSelectionSelected(m_selectionList.get(i))) {
            BigDecimal qty = (BigDecimal) ((VNumber) m_qtyList.get(i)).getValue();
            int M_Product_ID = ((Integer) m_productList.get(i)).intValue();
            //	Create Line
            MProjectLine pl = new MProjectLine(project);
            pl.setM_Product_ID(M_Product_ID);
            pl.setPlannedQty(qty);
            //	pl.setPlannedPrice();
            if (pl.save())
                lineCount++;
            else
                log.log(Level.SEVERE, "Line not saved");
        }
    //	line selected
    }
    //	for all bom lines
    log.config("#" + lineCount);
    return true;
}
Also used : ALayoutConstraint(org.compiere.apps.ALayoutConstraint) BigDecimal(java.math.BigDecimal) MProject(org.compiere.model.MProject) MProjectLine(org.compiere.model.MProjectLine)

Aggregations

MProjectLine (org.compiere.model.MProjectLine)12 MProject (org.compiere.model.MProject)8 MProjectIssue (org.compiere.model.MProjectIssue)4 BigDecimal (java.math.BigDecimal)3 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)2 MOrder (org.compiere.model.MOrder)2 MOrderLine (org.compiere.model.MOrderLine)2 MInOut (org.compiere.model.MInOut)1 MInOutLine (org.compiere.model.MInOutLine)1 MProductPricing (org.compiere.model.MProductPricing)1 MProjectPhase (org.compiere.model.MProjectPhase)1 MProjectTask (org.compiere.model.MProjectTask)1 MTimeExpense (org.compiere.model.MTimeExpense)1 MTimeExpenseLine (org.compiere.model.MTimeExpenseLine)1