Search in sources :

Example 1 with MProjectIssue

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

the class ProjectIssue method issueProjectLine.

//	issueExpense
/**
	 *	Issue Project Line
	 *	@return Message (clear text)
	 */
private String issueProjectLine() {
    MProjectLine pl = new MProjectLine(getCtx(), m_C_ProjectLine_ID, get_TrxName());
    if (pl.getM_Product_ID() == 0)
        throw new IllegalArgumentException("Projet Line has no Product");
    if (pl.getC_ProjectIssue_ID() != 0)
        throw new IllegalArgumentException("Projet Line already been issued");
    if (m_M_Locator_ID == 0)
        throw new IllegalArgumentException("No Locator");
    //	Set to Qty 1
    if (pl.getPlannedQty() == null || pl.getPlannedQty().signum() == 0)
        pl.setPlannedQty(Env.ONE);
    //
    MProjectIssue pi = new MProjectIssue(m_project);
    pi.setMandatory(m_M_Locator_ID, pl.getM_Product_ID(), pl.getPlannedQty());
    if (//	default today
    m_MovementDate != null)
        pi.setMovementDate(m_MovementDate);
    if (m_Description != null && m_Description.length() > 0)
        pi.setDescription(m_Description);
    else if (pl.getDescription() != null)
        pi.setDescription(pl.getDescription());
    pi.process();
    //	Update Line
    pl.setMProjectIssue(pi);
    pl.saveEx();
    addLog(pi.getLine(), pi.getMovementDate(), pi.getMovementQty(), null);
    return "@Created@ 1";
}
Also used : MProjectIssue(org.compiere.model.MProjectIssue) MProjectLine(org.compiere.model.MProjectLine)

Example 2 with MProjectIssue

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

the class CostEngine method clearAccounting.

/**
     * clear Accounting
     * @param accountSchema
     * @param transaction
     */
public void clearAccounting(MAcctSchema accountSchema, MTransaction transaction) {
    if (transaction.getM_InOutLine_ID() > 0) {
        MInOutLine line = (MInOutLine) transaction.getM_InOutLine();
        if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
            return;
        // get Purchase matches
        List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
        for (MMatchPO match : orderMatches) {
            if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), match, transaction.getM_Product_ID(), line.getDateAcct()))
                return;
        }
        // get invoice matches
        List<MMatchInv> invoiceMatches = MMatchInv.getInOutLine(line);
        for (MMatchInv match : invoiceMatches) {
            if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), match, transaction.getM_Product_ID(), line.getDateAcct()))
                return;
        }
    } else if (transaction.getC_ProjectIssue_ID() > 0) {
        MProjectIssue line = (MProjectIssue) transaction.getC_ProjectIssue();
        if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getMovementDate()))
            return;
    } else if (transaction.getM_InventoryLine_ID() > 0) {
        MInventoryLine line = (MInventoryLine) transaction.getM_InventoryLine();
        if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
            return;
    } else if (transaction.getM_MovementLine_ID() > 0) {
        MMovementLine line = (MMovementLine) transaction.getM_MovementLine();
        if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
            return;
    } else if (transaction.getM_ProductionLine_ID() > 0) {
        MProductionLine line = (MProductionLine) transaction.getM_ProductionLine();
        MProduction production = (MProduction) line.getM_ProductionPlan().getM_Production();
        if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), production, transaction.getM_Product_ID(), production.getMovementDate()))
            return;
    } else if (transaction.getPP_Cost_Collector_ID() > 0) {
        MPPCostCollector costCollector = (MPPCostCollector) transaction.getPP_Cost_Collector();
        if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), costCollector, costCollector.getM_Product_ID(), costCollector.getDateAcct()))
            ;
        return;
    } else {
        log.info("Document does not exist :" + transaction);
    }
}
Also used : MProjectIssue(org.compiere.model.MProjectIssue) MInOutLine(org.compiere.model.MInOutLine) MMatchPO(org.compiere.model.MMatchPO) MInventoryLine(org.compiere.model.MInventoryLine) MProductionLine(org.compiere.model.MProductionLine) MMatchInv(org.compiere.model.MMatchInv) MPPCostCollector(org.eevolution.model.MPPCostCollector) MMovementLine(org.compiere.model.MMovementLine) MProduction(org.compiere.model.MProduction)

Example 3 with MProjectIssue

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

the class ProjectIssue method issueExpense.

//	issueReceipt
/**
	 *	Issue Expense Report
	 *	@return Message (clear text)
	 */
private String issueExpense() {
    //	Get Expense Report
    MTimeExpense expense = new MTimeExpense(getCtx(), m_S_TimeExpense_ID, get_TrxName());
    if (!expense.isProcessed())
        throw new IllegalArgumentException("Time+Expense not processed - " + expense);
    //	for all expense lines
    MTimeExpenseLine[] expenseLines = expense.getLines(false);
    int counter = 0;
    for (int i = 0; i < expenseLines.length; i++) {
        //	Need to have a Product
        if (expenseLines[i].getM_Product_ID() == 0)
            continue;
        //	Need to have Quantity
        if (expenseLines[i].getQty() == null || expenseLines[i].getQty().signum() == 0)
            continue;
        //	Need to the same project
        if (expenseLines[i].getC_Project_ID() != m_project.getC_Project_ID())
            continue;
        //	not issued yet
        if (projectIssueHasExpense(expenseLines[i].getS_TimeExpenseLine_ID()))
            continue;
        //	Find Location
        int M_Locator_ID = 0;
        //	MProduct product = new MProduct (getCtx(), expenseLines[i].getM_Product_ID());
        //	if (product.isStocked())
        M_Locator_ID = MStorage.getM_Locator_ID(expense.getM_Warehouse_ID(), //	no ASI
        expenseLines[i].getM_Product_ID(), //	no ASI
        0, expenseLines[i].getQty(), null);
        if (//	Service/Expense - get default (and fallback)
        M_Locator_ID == 0)
            M_Locator_ID = expense.getM_Locator_ID();
        //	Create Issue
        MProjectIssue pi = new MProjectIssue(m_project);
        pi.setMandatory(M_Locator_ID, expenseLines[i].getM_Product_ID(), expenseLines[i].getQty());
        if (//	default today
        m_MovementDate != null)
            pi.setMovementDate(m_MovementDate);
        if (m_Description != null && m_Description.length() > 0)
            pi.setDescription(m_Description);
        else if (expenseLines[i].getDescription() != null)
            pi.setDescription(expenseLines[i].getDescription());
        pi.setS_TimeExpenseLine_ID(expenseLines[i].getS_TimeExpenseLine_ID());
        pi.process();
        //	Find/Create Project Line
        MProjectLine pl = new MProjectLine(m_project);
        //	setIssue
        pl.setMProjectIssue(pi);
        pl.saveEx();
        addLog(pi.getLine(), pi.getMovementDate(), pi.getMovementQty(), null);
        counter++;
    }
    return "@Created@ " + counter;
}
Also used : MProjectIssue(org.compiere.model.MProjectIssue) MTimeExpense(org.compiere.model.MTimeExpense) MTimeExpenseLine(org.compiere.model.MTimeExpenseLine) MProjectLine(org.compiere.model.MProjectLine)

Example 4 with MProjectIssue

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

the class ProjectIssue method issueInventory.

//	issueProjectLine
/**
	 *	Issue from Inventory
	 *	@return Message (clear text)
	 */
private String issueInventory() {
    if (m_M_Locator_ID == 0)
        throw new IllegalArgumentException("No Locator");
    if (m_M_Product_ID == 0)
        throw new IllegalArgumentException("No Product");
    //	Set to Qty 1
    if (m_MovementQty == null || m_MovementQty.signum() == 0)
        m_MovementQty = Env.ONE;
    //
    MProjectIssue pi = new MProjectIssue(m_project);
    pi.setMandatory(m_M_Locator_ID, m_M_Product_ID, m_MovementQty);
    if (//	default today
    m_MovementDate != null)
        pi.setMovementDate(m_MovementDate);
    if (m_Description != null && m_Description.length() > 0)
        pi.setDescription(m_Description);
    pi.process();
    //	Create Project Line
    MProjectLine pl = new MProjectLine(m_project);
    pl.setMProjectIssue(pi);
    pl.saveEx();
    addLog(pi.getLine(), pi.getMovementDate(), pi.getMovementQty(), null);
    return "@Created@ 1";
}
Also used : MProjectIssue(org.compiere.model.MProjectIssue) MProjectLine(org.compiere.model.MProjectLine)

Example 5 with MProjectIssue

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

the class ProjectIssue method issueReceipt.

//	doIt
/**
	 *	Issue Receipt
	 *	@return Message (clear text)
	 */
private String issueReceipt() {
    MInOut inOut = new MInOut(getCtx(), m_M_InOut_ID, null);
    if (inOut.isSOTrx() || !inOut.isProcessed() || !(MInOut.DOCSTATUS_Completed.equals(inOut.getDocStatus()) || MInOut.DOCSTATUS_Closed.equals(inOut.getDocStatus())))
        throw new IllegalArgumentException("Receipt not valid - " + inOut);
    log.info(inOut.toString());
    //	Set Project of Receipt
    if (inOut.getC_Project_ID() == 0) {
        inOut.setC_Project_ID(m_project.getC_Project_ID());
        inOut.saveEx();
    } else if (inOut.getC_Project_ID() != m_project.getC_Project_ID())
        throw new IllegalArgumentException("Receipt for other Project (" + inOut.getC_Project_ID() + ")");
    MInOutLine[] inOutLines = inOut.getLines(false);
    int counter = 0;
    for (int i = 0; i < inOutLines.length; i++) {
        //	Need to have a Product
        if (inOutLines[i].getM_Product_ID() == 0)
            continue;
        //	Need to have Quantity
        if (inOutLines[i].getMovementQty() == null || inOutLines[i].getMovementQty().signum() == 0)
            continue;
        //	not issued yet
        if (projectIssueHasReceipt(inOutLines[i].getM_InOutLine_ID()))
            continue;
        //	Create Issue
        MProjectIssue pi = new MProjectIssue(m_project);
        pi.setMandatory(inOutLines[i].getM_Locator_ID(), inOutLines[i].getM_Product_ID(), inOutLines[i].getMovementQty());
        if (//	default today
        m_MovementDate != null)
            pi.setMovementDate(m_MovementDate);
        if (m_Description != null && m_Description.length() > 0)
            pi.setDescription(m_Description);
        else if (inOutLines[i].getDescription() != null)
            pi.setDescription(inOutLines[i].getDescription());
        else if (inOut.getDescription() != null)
            pi.setDescription(inOut.getDescription());
        pi.setM_InOutLine_ID(inOutLines[i].getM_InOutLine_ID());
        pi.process();
        //	Find/Create Project Line
        MProjectLine pl = null;
        MProjectLine[] pls = m_project.getLines();
        for (int ii = 0; ii < pls.length; ii++) {
            //	The Order we generated is the same as the Order of the receipt
            if (pls[ii].getC_OrderPO_ID() == inOut.getC_Order_ID() && pls[ii].getM_Product_ID() == inOutLines[i].getM_Product_ID() && //	not issued
            pls[ii].getC_ProjectIssue_ID() == 0) {
                pl = pls[ii];
                break;
            }
        }
        if (pl == null)
            pl = new MProjectLine(m_project);
        //	setIssue
        pl.setMProjectIssue(pi);
        pl.saveEx();
        addLog(pi.getLine(), pi.getMovementDate(), pi.getMovementQty(), null);
        counter++;
    }
    return "@Created@ " + counter;
}
Also used : MInOut(org.compiere.model.MInOut) MProjectIssue(org.compiere.model.MProjectIssue) MInOutLine(org.compiere.model.MInOutLine) MProjectLine(org.compiere.model.MProjectLine)

Aggregations

MProjectIssue (org.compiere.model.MProjectIssue)5 MProjectLine (org.compiere.model.MProjectLine)4 MInOutLine (org.compiere.model.MInOutLine)2 MInOut (org.compiere.model.MInOut)1 MInventoryLine (org.compiere.model.MInventoryLine)1 MMatchInv (org.compiere.model.MMatchInv)1 MMatchPO (org.compiere.model.MMatchPO)1 MMovementLine (org.compiere.model.MMovementLine)1 MProduction (org.compiere.model.MProduction)1 MProductionLine (org.compiere.model.MProductionLine)1 MTimeExpense (org.compiere.model.MTimeExpense)1 MTimeExpenseLine (org.compiere.model.MTimeExpenseLine)1 MPPCostCollector (org.eevolution.model.MPPCostCollector)1