use of org.compiere.FA.exceptions.AssetException in project adempiere by adempiere.
the class MDepreciationEntry method completeIt.
// rejectIt
public String completeIt() {
// Re-Check
if (!m_justPrepared) {
String status = prepareIt();
if (!DocAction.STATUS_InProgress.equals(status))
return status;
}
// Implicit Approval
if (!isApproved()) {
approveIt();
}
final MPeriod period = MPeriod.get(getCtx(), getC_Period_ID());
final ArrayList<Exception> errors = new ArrayList<Exception>();
final Iterator<MDepreciationExp> it = getLinesIterator(true);
//
while (it.hasNext()) {
try {
Trx.run(get_TrxName(), new TrxRunnable() {
public void run(String trxName) {
MDepreciationExp depexp = it.next();
// Check if is in Period
if (!period.isInPeriod(depexp.getDateAcct())) {
throw new AssetException("The date is not within this Period" + " (" + depexp + ", Data=" + depexp.getDateAcct() + ", Period=" + period.getName() + // TODO: translate
")");
}
depexp.process();
}
});
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
errors.add(e);
}
}
//
if (errors.size() > 0) {
throw new AssetArrayException(errors);
}
// User Validation
String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE);
if (valid != null) {
m_processMsg = valid;
return DocAction.STATUS_Invalid;
}
setProcessed(true);
setDocAction(DOCACTION_Close);
return DocAction.STATUS_Completed;
}
use of org.compiere.FA.exceptions.AssetException in project adempiere by adempiere.
the class MAssetAddition method updateSourceDocument.
// afterSave
/**
* Update Source Document (Invoice, Project etc) Status
* @param isReversal is called from a reversal action (like Void, Reverse-Correct).
* We need this flag because that when we call the method from voidIt()
* the document is not marked as voided yet. Same thing applies for reverseCorrectIt too.
*/
private void updateSourceDocument(final boolean isReversalParam) {
boolean isReversal = isReversalParam;
// Check if this document is reversed/voided
String docStatus = getDocStatus();
if (!isReversal && (DOCSTATUS_Reversed.equals(docStatus) || DOCSTATUS_Voided.equals(docStatus))) {
isReversal = true;
}
final String sourceType = getA_SourceType();
// Invoice: mark C_InvoiceLine.A_Processed='Y' and set C_InvoiceLine.A_Asset_ID
if (A_SOURCETYPE_Invoice.equals(sourceType) && isProcessed()) {
int C_InvoiceLine_ID = getC_InvoiceLine_ID();
MInvoiceLine invoiceLine = new MInvoiceLine(getCtx(), C_InvoiceLine_ID, get_TrxName());
invoiceLine.setA_Processed(!isReversal);
invoiceLine.setA_Asset_ID(isReversal ? 0 : getA_Asset_ID());
invoiceLine.saveEx();
} else // Project
if (A_SOURCETYPE_Project.equals(sourceType) && isProcessed()) {
if (isReversal) {
// Project remains closed. We just void/reverse/reactivate the Addition
} else {
//TODO decide whether to close project first or later
int project_id = getC_Project_ID();
ProcessInfo pi = new ProcessInfo("", 0, MProject.Table_ID, project_id);
pi.setAD_Client_ID(getAD_Client_ID());
pi.setAD_User_ID(Env.getAD_User_ID(getCtx()));
//
ProjectClose proc = new ProjectClose();
proc.startProcess(getCtx(), pi, Trx.get(get_TrxName(), false));
if (pi.isError()) {
throw new AssetException(pi.getSummary());
}
}
} else // Import
if (A_SOURCETYPE_Imported.equals(sourceType) && !isProcessed()) {
if (is_new() && getI_FixedAsset_ID() > 0) {
MIFixedAsset ifa = getI_FixedAsset(false);
if (ifa != null) {
ifa.setI_IsImported(true);
ifa.setA_Asset_ID(getA_Asset_ID());
ifa.saveEx(get_TrxName());
}
}
} else // Manual
if (A_SOURCETYPE_Manual.equals(sourceType) && isProcessed()) {
// nothing to do
log.fine("Nothing to do");
}
}
use of org.compiere.FA.exceptions.AssetException in project adempiere by adempiere.
the class MAssetAddition method prepareIt.
// invalidateIt
public String prepareIt() {
if (log.isLoggable(Level.INFO))
log.info(toString());
// Call model validators
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
if (m_processMsg != null) {
return DocAction.STATUS_Invalid;
}
//Goodwill - new asset doctype
MPeriod.testPeriodOpen(getCtx(), getDateAcct(), "FAA", getAD_Org_ID());
// Goodwill - setting Create Asset checkbox
setA_CreateAsset();
// Check AssetValueAmt != 0
if (getAssetValueAmt().signum() == 0) {
m_processMsg = "@Invalid@ @AssetValueAmt@=0";
return DocAction.STATUS_Invalid;
}
MAsset asset = getA_Asset(true);
MDepreciationWorkfile assetwk = MDepreciationWorkfile.get(getCtx(), getA_Asset_ID(), getPostingType(), get_TrxName());
// Goodwill - Check asset disposal status
if (MAsset.A_ASSET_STATUS_Disposed.equals(asset.getA_Asset_Status())) {
m_processMsg = "Asset aldready disposed";
return DocAction.STATUS_Invalid;
}
// Goodwill - Check if asset already depreciated
if (!MAsset.A_ASSET_STATUS_New.equals(asset.getA_Asset_Status()) && assetwk != null && assetwk.getDateAcct() != null && assetwk.isDepreciated(getDateAcct())) {
m_processMsg = "Asset already depreciated for this period";
return DocAction.STATUS_Invalid;
}
// Goodwill - Validation on Asset Addition Date
if (getDateDoc().before(asset.getA_Asset_CreateDate())) {
throw new AssetCheckDocumentException("Document is date older than Asset Create Date");
} else if (asset.getAssetServiceDate() != null && getDateDoc().before(asset.getAssetServiceDate())) {
throw new AssetCheckDocumentException("Document is date older than Asset Service Date");
}
// If new assets (not renewals) must have nonzero values
if (isA_CreateAsset() && hasZeroValues()) {
throw new AssetException("New document must have non-zero values");
}
// Goodwill - can add asset value without adding asset usable life
if (!isA_CreateAsset() && getDeltaUseLifeYears() < 0) {
throw new AssetException("Delta Use Life Years cannot be negative values");
}
// Goodwill - Validation on Depreciated Asset
if (MAsset.A_ASSET_STATUS_Depreciated.equals(asset.getA_Asset_Status())) {
throw new AssetException("Asset is fully depreciated");
}
// Only New assets can be activated
if (isA_CreateAsset() && !MAsset.A_ASSET_STATUS_New.equals(asset.getA_Asset_Status())) {
throw new AssetException("Only new assets can be activated");
}
// Validate Source - Invoice
if (A_SOURCETYPE_Invoice.equals(getA_SourceType())) {
int C_Invoice_ID = getC_Invoice_ID();
MInvoice invoice = new MInvoice(getCtx(), C_Invoice_ID, get_TrxName());
if (MInvoice.DOCSTATUS_Voided.equals(invoice.getDocStatus())) {
throw new AssetException("You cannot add asset from voided document(s)");
}
}
// Validate Source - Project
if (A_SOURCETYPE_Project.equals(getA_SourceType())) {
if (getC_Project_ID() <= 0) {
throw new FillMandatoryException(COLUMNNAME_C_Project_ID);
}
final String whereClause = COLUMNNAME_C_Project_ID + "=?" + " AND DocStatus IN ('IP','CO','CL')" + " AND " + COLUMNNAME_A_Asset_Addition_ID + "<>?";
List<MAssetAddition> list = new Query(getCtx(), Table_Name, whereClause, get_TrxName()).setParameters(new Object[] { getC_Project_ID(), get_ID() }).list();
if (list.size() > 0) {
StringBuilder sb = new StringBuilder("You can not create project for this asset," + " Project already has assets. View: ");
for (MAssetAddition aa : list) {
sb.append(aa.getDocumentInfo()).append("; ");
}
throw new AssetException(sb.toString());
}
}
// Call model validators
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE);
if (m_processMsg != null) {
return DocAction.STATUS_Invalid;
}
// Done
m_justPrepared = true;
if (!DOCACTION_Complete.equals(getDocAction()))
setDocAction(DOCACTION_Complete);
return DocAction.STATUS_InProgress;
}
use of org.compiere.FA.exceptions.AssetException in project adempiere by adempiere.
the class A_Asset_CreateFromMatchInv method doIt.
// prepare
protected String doIt() throws Exception {
MMatchInv match = new MMatchInv(getCtx(), p_M_MatchInv_ID, get_TrxName());
if (match == null || match.get_ID() <= 0) {
throw new AssetException("@NotFound@ @M_MatchInv_ID@=" + match + "(ID=" + p_M_MatchInv_ID + ")");
}
MAssetAddition assetAdd = MAssetAddition.createAsset(match);
return "@A_Asset_Addition_ID@ - " + assetAdd;
}
Aggregations