326 lines
12 KiB
C#
326 lines
12 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Dbas;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
|
|
{
|
|
//=======================================================================
|
|
// Asset manager - Assets.
|
|
//=======================================================================
|
|
partial class SbmAssetMgr
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Associated data.
|
|
|
|
public abstract bool AssetHasProcesses(SysId assetId);
|
|
public abstract bool AssetHasRequirements(SysId assetId);
|
|
public abstract bool AssetHasInterfaceDataItems(SysId assetId);
|
|
public abstract bool AssetHasAssociatedDetails(SysId assetId);
|
|
|
|
public abstract bool ClearAssetDependentData(SbmAsset asset, DbUpdateInfo dbUpdateInfo);
|
|
|
|
//---------------------------------------------------------------
|
|
// Asset Processes.
|
|
public abstract List<SbmItemProcess> GetAssetProcesses(SysId assetId, bool bActiveOnly);
|
|
public abstract bool StoreAssetProcesses(SbmAsset asset, List<SbmItemProcess> itemProcesses);
|
|
/// <summary>Store processes against Asset as defined by Asset Category (for assets created by processes, eg. vehicle import).</summary>
|
|
public abstract bool PopulateAssetDefaultProcesses(SbmAsset asset);
|
|
|
|
//---------------------------------------------------------------
|
|
// Asset Payments.
|
|
public abstract bool AssetHasPrices(SysId assetId);
|
|
public abstract List<SbmItemPrice> GetAssetPrices(SysId assetId);
|
|
public abstract bool StoreAssetPrices(SbmAsset asset, List<SbmItemPrice> itemPrices);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Retrieve individual assets.
|
|
//-------------------------------------------------------------------
|
|
// Asset exists.
|
|
public bool AssetExistsById(SysId assetId)
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(assetId)) return false;
|
|
SbmAsset.Params prmAsset = new SbmAsset.Params();
|
|
prmAsset.IdsIncluded.Add(assetId);
|
|
prmAsset.StatusCat = SbmAsset.StatusCat.Any;
|
|
return GetAssetCount(prmAsset) == 1;
|
|
}
|
|
|
|
public bool AssetExistsBySerial(SysId assetCatId, String serialNumber)
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(assetCatId) || StringUtil.IsEmpty(serialNumber)) return false;
|
|
SbmAsset.Params prm = new SbmAsset.Params
|
|
{
|
|
AssetCategoryId = assetCatId,
|
|
SerialNumber = serialNumber,
|
|
StatusCat = SbmAsset.StatusCat.Any
|
|
};
|
|
return GetAssetCount(prm) == 1;
|
|
}
|
|
|
|
//----------------------------------------------------------
|
|
// Get assets.
|
|
public abstract SbmAsset GetAsset(SbmAsset.Params prm);
|
|
|
|
public SbmAsset GetAssetById(SysId assetId)
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(assetId)) return null;
|
|
SbmAsset.Params prmAsset = new SbmAsset.Params();
|
|
prmAsset.IdsIncluded.Add(assetId);
|
|
prmAsset.StatusCat = SbmAsset.StatusCat.Any;
|
|
return GetAsset(prmAsset);
|
|
}
|
|
|
|
public SbmAsset GetAssetBySerial(SysId assetCatId, String serialNumber)
|
|
{
|
|
SbmAsset asset = null;
|
|
if (!SysId.IsValid(assetCatId) || StringUtil.IsEmpty(serialNumber)) return asset;
|
|
SbmAsset.Params prmAsset = new SbmAsset.Params
|
|
{
|
|
AssetCategoryId = assetCatId,
|
|
SerialNumber = serialNumber,
|
|
StatusCat = SbmAsset.StatusCat.Any
|
|
};
|
|
return GetAsset(prmAsset);
|
|
}
|
|
|
|
//----------------------------------------------------------
|
|
// Create assets.
|
|
public abstract SbmAsset CreateAsset(SysId assetCatId);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate asset data.
|
|
public bool IsValidAsset(SbmAsset asset)
|
|
{
|
|
ClearErrorState();
|
|
if (asset == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
|
return IsValidAssetData(asset.GetData(), new SbmAsset.ErrField());
|
|
}
|
|
public virtual bool IsValidAssetData(SbmAsset.Data data, SbmAsset.ErrField errField)
|
|
{
|
|
ClearErrorState();
|
|
// Asset properties.
|
|
if (errField.AssetCategoryId != SacsHierarchyItem.ValidValue.Ignore && SysId.ToInt(data.AssetCategoryId) < 1)
|
|
{
|
|
errField.AssetCategoryId = SacsHierarchyItem.ValidValue.Invalid;
|
|
return SetErrorState("Aff Id Owner must be supplied");
|
|
}
|
|
if (errField.SerialNumber != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.SerialNumber, "SerialNumber", (long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.SaAsset_SerialNumber), true))
|
|
{
|
|
errField.SerialNumber = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.RefExt != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.RefExt, "RefExt", (long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.SaAsset_RefExt)))
|
|
{
|
|
errField.RefExt = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.DescBrief != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.DescBrief, "DescBrief", (long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.SaAsset_DescBrief)))
|
|
{
|
|
errField.DescBrief = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
|
|
// Item.
|
|
if (errField.ItemType != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.ItemId != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
|
|
// Purchase.
|
|
if (errField.PurchaseOn != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.AssocIdSupplier != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.PurchaseInvoiceRef != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.PurchaseInvoiceRef, "Purchase Invoice Ref", (long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.SaAsset_PurchaseInvoiceRef)))
|
|
{
|
|
errField.PurchaseInvoiceRef = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.PaymentTerms != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.AmountPurchase != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.TaxCodeIdPurchase != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.AmountPurchaseGross != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.AmountSettlementGross != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.AmountEnhancementGross != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
|
|
// Sale.
|
|
if (errField.AssocIdCustomer != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.SellCategoryCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.SellCategoryCode, "Sell category code", (long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.SaAsset_SellCategoryCode)))
|
|
{
|
|
errField.SellCategoryCode = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.AmountSell != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.TaxCodeIdSell != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.AmountSellGross != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.TaxCodeIdProfit != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.SoldOn != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.AmountSold != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.AmountSoldGross != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
|
|
// Disposal.
|
|
if (errField.DisposeCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.DisposeCode, "dispose code", (long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.SaAsset_DisposeCode)))
|
|
{
|
|
errField.DisposeCode = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.DisposeOn != SacsHierarchyItem.ValidValue.Ignore && DateUtil.IsValid(data.DisposeOn))
|
|
{
|
|
}
|
|
|
|
// Rental.
|
|
if (errField.DueBackOn != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.AmountRentalCost != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.UomIdRentalCost != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.TaxCodeIdRentalCost != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.AmountRentalPrice != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.UomIdRentalPrice != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
if (errField.TaxCodeIdRentalPrice != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
|
|
// Processes.
|
|
if (errField.ProcessIdNext != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
}
|
|
|
|
// Common.
|
|
if (!IsValidValue(data.Notes, "notes", (long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.SaAsset_Notes)))
|
|
{
|
|
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
if (!IsValidValue(data.StatusCode, "status", (long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.SaAsset_Status), true, true))
|
|
{
|
|
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (!SbmAsset.ValidStatuses.Contains(data.Status))
|
|
{
|
|
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
|
return SetErrorState(ErrorMessage.InvalidStatus);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Asset database interface.
|
|
public abstract bool InsertAsset(SbmAsset asset, DbUpdateInfo dbUpdateInfo);
|
|
public abstract bool UpdateAsset(SbmAsset asset, DbUpdateInfo dbUpdateInfo);
|
|
public virtual bool AssetCanBeDeleted(SbmAsset asset)
|
|
{
|
|
ClearErrorState();
|
|
return true;
|
|
}
|
|
public abstract bool DeleteAsset(SbmAsset asset, DbUpdateInfo dbUpdateInfo);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Asset list.
|
|
public abstract ColumnDfn GetAssetColumnDfn(SbmAsset.Column columnId, String caption = "", int width = 0);
|
|
public abstract List<String> GetAssetQueryFilter(SbmAsset.Params prm);
|
|
public abstract long GetAssetCount(SbmAsset.Params prm);
|
|
public abstract List<SbmAsset> GetAssetList(SbmAsset.Params prm);
|
|
public abstract DbResultSet ExecuteAssetQuery(List<ColumnDfn> columns, SbmAsset.Params prm);
|
|
|
|
//-------------------------------------------------------------------
|
|
// D a t a V a l u e s
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Extract and format result set data value where specific handling is required.
|
|
/// <para>Where response is an invalid data value, format value using column.FormatValue(values).</para>
|
|
/// </summary>
|
|
public DataValue GetAssetDataValue(ColumnDfn column, NamedValue.Map values)
|
|
{
|
|
DataValue value = new DataValue();
|
|
switch ((SbmAsset.Column)column.Id)
|
|
{
|
|
//-----------------------------------------------------------
|
|
// Notes.
|
|
case SbmAsset.Column.Notes:
|
|
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
|
break;
|
|
|
|
// Status.
|
|
case SbmAsset.Column.Status_Desc:
|
|
case SbmAsset.Column.Status_Ind:
|
|
{
|
|
String statucode = values.GetValue(column.DataName).ToString();
|
|
SaStatus status = SacsSystem.GetStatusForCode(statucode);
|
|
if (column.Id == (int)SbmAsset.Column.Status_Desc)
|
|
value = new DataValue(SacsSystem.GetStatusDescForCode(statucode));
|
|
else if (column.Id == (int)SbmAsset.Column.Status_Ind)
|
|
value = new DataValue(SbmAsset.GetStatusTriState(status));
|
|
}
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
default:
|
|
value = values.GetValue(column.DataName);
|
|
break;
|
|
|
|
}
|
|
return value;
|
|
}
|
|
}
|
|
//=======================================================================
|
|
} |