📄 mprojectline.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.model;
import java.math.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Project Line Model
*
* @author Jorg Janke
* @version $Id: MProjectLine.java,v 1.15 2005/07/18 03:47:42 jjanke Exp $
*/
public class MProjectLine extends X_C_ProjectLine
{
/**
* Standard Constructor
* @param ctx context
* @param C_ProjectLine_ID id
*/
public MProjectLine (Properties ctx, int C_ProjectLine_ID, String trxName)
{
super (ctx, C_ProjectLine_ID, trxName);
if (C_ProjectLine_ID == 0)
{
// setC_Project_ID (0);
// setC_ProjectLine_ID (0);
setLine (0);
setIsPrinted(true);
setProcessed(false);
setInvoicedAmt (Env.ZERO);
setInvoicedQty (Env.ZERO);
//
setPlannedAmt (Env.ZERO);
setPlannedMarginAmt (Env.ZERO);
setPlannedPrice (Env.ZERO);
setPlannedQty (Env.ONE);
}
} // MProjectLine
/**
* Load Constructor
* @param ctx context
* @param rs result set
*/
public MProjectLine (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MProjectLine
/**
* Parent Constructor
* @param project parent
*/
public MProjectLine (MProject project)
{
this (project.getCtx(), 0, project.get_TrxName());
setClientOrg(project);
setC_Project_ID (project.getC_Project_ID()); // Parent
setLine();
} // MProjectLine
/** Parent */
private MProject m_parent = null;
/**
* Get the next Line No
*/
private void setLine()
{
setLine(DB.getSQLValue(get_TrxName(),
"SELECT COALESCE(MAX(Line),0)+10 FROM C_ProjectLine WHERE C_Project_ID=?", getC_Project_ID()));
} // setLine
/**
* Set Product, committed qty, etc.
* @param pi project issue
*/
public void setMProjectIssue (MProjectIssue pi)
{
setC_ProjectIssue_ID(pi.getC_ProjectIssue_ID());
setM_Product_ID(pi.getM_Product_ID());
setCommittedQty(pi.getMovementQty());
if (getDescription() != null)
setDescription(pi.getDescription());
} // setMProjectIssue
/**
* Set PO
* @param C_OrderPO_ID po id
*/
public void setC_OrderPO_ID (int C_OrderPO_ID)
{
super.setC_OrderPO_ID(C_OrderPO_ID);
} // setC_OrderPO_ID
/**
* Get Project
* @return parent
*/
public MProject getProject()
{
if (m_parent == null && getC_Project_ID() != 0)
{
m_parent = new MProject (getCtx(), getC_Project_ID(), get_TrxName());
if (get_TrxName() != null)
m_parent.load(get_TrxName());
}
return m_parent;
} // getProject
/**
* Get Limit Price if exists
* @return limit
*/
public BigDecimal getLimitPrice()
{
BigDecimal limitPrice = getPlannedPrice();
if (getM_Product_ID() == 0)
return limitPrice;
if (getProject() == null)
return limitPrice;
boolean isSOTrx = true;
MProductPricing pp = new MProductPricing (getM_Product_ID(),
m_parent.getC_BPartner_ID(), getPlannedQty(), isSOTrx);
pp.setM_PriceList_ID(m_parent.getM_PriceList_ID());
if (pp.calculatePrice())
limitPrice = pp.getPriceLimit();
return limitPrice;
} // getLimitPrice
/**
* Before Save
* @param newRecord new
* @return true
*/
protected boolean beforeSave (boolean newRecord)
{
if (getLine() == 0)
setLine();
// Planned Amount
setPlannedAmt(getPlannedQty().multiply(getPlannedPrice()));
// Planned Margin
if (is_ValueChanged("M_Product_ID") || is_ValueChanged("M_Product_Category_ID")
|| is_ValueChanged("PlannedQty") || is_ValueChanged("PlannedPrice"))
{
if (getM_Product_ID() != 0)
{
BigDecimal marginEach = getPlannedPrice().subtract(getLimitPrice());
setPlannedMarginAmt(marginEach.multiply(getPlannedQty()));
}
else if (getM_Product_Category_ID() != 0)
{
MProductCategory category = MProductCategory.get(getCtx(), getM_Product_Category_ID());
BigDecimal marginEach = category.getPlannedMargin();
setPlannedMarginAmt(marginEach.multiply(getPlannedQty()));
}
}
return true;
} // beforeSave
/**
* After Save
* @param newRecord new
* @param success success
* @return success
*/
protected boolean afterSave (boolean newRecord, boolean success)
{
updateHeader();
return success;
} // afterSave
/**
* After Delete
* @param success success
* @return success
*/
protected boolean afterDelete (boolean success)
{
updateHeader();
return success;
} // afterDelete
/**
* Update Header
*/
private void updateHeader()
{
String sql = "UPDATE C_Project p "
+ "SET (PlannedAmt,PlannedQty,PlannedMarginAmt,"
+ " CommittedAmt,CommittedQty,"
+ " InvoicedAmt, InvoicedQty) = "
+ "(SELECT COALESCE(SUM(pl.PlannedAmt),0),COALESCE(SUM(pl.PlannedQty),0),COALESCE(SUM(pl.PlannedMarginAmt),0),"
+ " COALESCE(SUM(pl.CommittedAmt),0),COALESCE(SUM(pl.CommittedQty),0),"
+ " COALESCE(SUM(pl.InvoicedAmt),0), COALESCE(SUM(pl.InvoicedQty),0) "
+ "FROM C_ProjectLine pl "
+ "WHERE pl.C_Project_ID=p.C_Project_ID AND pl.IsActive='Y') "
+ "WHERE C_Project_ID=" + getC_Project_ID();
int no = DB.executeUpdate(sql, get_TrxName());
if (no != 1)
log.log(Level.SEVERE, "updateHeader - #" + no);
} // updateHeader
} // MProjectLine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -