242 lines
9.6 KiB
C#
242 lines
9.6 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 System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
|
|
{
|
|
//=======================================================================
|
|
// Price manager - Prices.
|
|
//=======================================================================
|
|
partial class SbmPriceMgr
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Create price.
|
|
public abstract SbmPrice CreatePrice(SysId priceSetId, SysId commodityId, Sbm.PriceType priceType);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item exists.
|
|
public bool PriceExistsByPriceSetCommodity(SysId priceSetId, SysId commodityId)
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(priceSetId) || !SysId.IsValid(commodityId)) return false;
|
|
SbmPrice.Params prmPrice = new SbmPrice.Params();
|
|
prmPrice.PriceSetId = priceSetId;
|
|
prmPrice.CommodityId = commodityId;
|
|
prmPrice.StatusCat = SbmPrice.StatusCat.Any;
|
|
return GetPriceCount(prmPrice) == 1;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Get item.
|
|
public abstract SbmPrice GetPrice(SbmPrice.Params prm);
|
|
public SbmPrice GetPriceByPriceSetCommodity(SysId priceSetId, SysId commodityId)
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(priceSetId) || !SysId.IsValid(commodityId)) return null;
|
|
SbmPrice.Params prmPrice = new SbmPrice.Params();
|
|
prmPrice.PriceSetId = priceSetId;
|
|
prmPrice.CommodityId = commodityId;
|
|
prmPrice.StatusCat = SbmPrice.StatusCat.Any;
|
|
return GetPrice(prmPrice);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate price data.
|
|
public bool IsValidPrice(SbmPrice price)
|
|
{
|
|
ClearErrorState();
|
|
if (price == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
|
return IsValidPriceData(price.GetData(), new SbmPrice.ErrField());
|
|
}
|
|
public virtual bool IsValidPriceData(SbmPrice.Data data, SbmPrice.ErrField errField)
|
|
{
|
|
// Price properties.
|
|
ClearErrorState();
|
|
if (data == null) return SetErrorState(ErrorMessage.InvalidStatus);
|
|
// Price set.
|
|
if (errField.PriceSetId != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.PriceSetId))
|
|
{
|
|
errField.Type = SacsHierarchyItem.ValidValue.Invalid;
|
|
return SetErrorState("Price set must be specified");
|
|
}
|
|
// Validate the type.
|
|
if (errField.Type != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
if ((int)data.PriceType < 1)
|
|
{
|
|
errField.Type = SacsHierarchyItem.ValidValue.Invalid;
|
|
return SetErrorState("Price type must be supplied");
|
|
}
|
|
}
|
|
// Common properties.
|
|
if (!IsValidValue(data.Notes, "notes", (long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.SaPrice_Notes)))
|
|
{
|
|
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
if (!IsValidValue(data.StatusCode, "status", (long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.SaPrice_Status), true, true))
|
|
{
|
|
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (!SbmPrice.ValidStatuses.Contains(data.Status))
|
|
{
|
|
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
|
return SetErrorState(ErrorMessage.InvalidStatus);
|
|
}
|
|
}
|
|
|
|
// Validate associated data.
|
|
if (errField.PriceSetId != SacsHierarchyItem.ValidValue.Ignore && SysId.IsValid(data.PriceSetId))
|
|
{
|
|
/* ToDo Validate Price Set
|
|
errField.PriceIdParent = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
*/
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Price database interface.
|
|
public abstract bool InsertPrice(SbmPrice price, DbUpdateInfo dbUpdateInfo);
|
|
public abstract bool UpdatePrice(SbmPrice price, DbUpdateInfo dbUpdateInfo);
|
|
public virtual bool PriceCanBeDeleted(SbmPrice price)
|
|
{
|
|
ClearErrorState();
|
|
if (price == null) return SetErrorState(ErrorMessage.InvalidStatus);
|
|
return true;
|
|
}
|
|
public abstract bool DeletePrice(SbmPrice price, DbUpdateInfo dbUpdateInfo);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Price list.
|
|
public abstract ColumnDfn GetPriceColumnDfn(SbmPrice.Column columnId, String caption = "", int width = 0);
|
|
public abstract List<String> GetPriceQueryFilter(SbmPrice.Params prm);
|
|
public abstract long GetPriceCount(SbmPrice.Params prm);
|
|
public abstract List<SbmPrice> GetPriceList(SbmPrice.Params prm);
|
|
public abstract DbResultSet ExecutePriceQuery(List<ColumnDfn> columns, SbmPrice.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 GetPriceDataValue(ColumnDfn column, NamedValue.Map values)
|
|
{
|
|
DataValue value = new DataValue();
|
|
switch ((SbmPrice.Column)column.Id)
|
|
{
|
|
//-----------------------------------------------------------
|
|
// Price type.
|
|
case SbmPrice.Column.PriceType_Desc:
|
|
{
|
|
Sbm.PriceType priceType = (Sbm.PriceType)values.GetValue(column.DataName).AsLong();
|
|
value = new DataValue(PriceTypes.GetDescForType(priceType, priceType > 0 ? priceType.ToString() : ""));
|
|
break;
|
|
}
|
|
|
|
//-----------------------------------------------------------
|
|
// Calculation method.
|
|
case SbmPrice.Column.CalculationMethod_Desc:
|
|
{
|
|
Sbm.PriceCalcMethod calculationMethod = (Sbm.PriceCalcMethod)values.GetValue(column.DataName).AsLong();
|
|
value = new DataValue(PriceCalculationMethods.GetDescForType(calculationMethod, calculationMethod > 0 ? calculationMethod.ToString() : ""));
|
|
break;
|
|
}
|
|
|
|
//-----------------------------------------------------------
|
|
// Rounder method.
|
|
case SbmPrice.Column.RounderMethod_Desc:
|
|
{
|
|
Sbm.PriceRounderMethod rounderMethod = (Sbm.PriceRounderMethod)values.GetValue(column.DataName).AsLong();
|
|
value = new DataValue(PriceRounderMethods.GetDescForType(rounderMethod, rounderMethod > 0 ? rounderMethod.ToString() : ""));
|
|
break;
|
|
}
|
|
|
|
// Rounder direction.
|
|
case SbmPrice.Column.RounderDirection_Desc:
|
|
{
|
|
Sbm.PriceRounderDirection rounderDirection = (Sbm.PriceRounderDirection)values.GetValue(column.DataName).AsLong();
|
|
value = new DataValue(PriceRounderDirections.GetDescForType(rounderDirection, rounderDirection > 0 ? rounderDirection.ToString() : ""));
|
|
break;
|
|
}
|
|
|
|
//-----------------------------------------------------------
|
|
// Sales dicount.
|
|
case SbmPrice.Column.SalesDiscountPercent:
|
|
{
|
|
Sbm.PriceCalcMethod calculationMethod = (Sbm.PriceCalcMethod)values.GetValue(GetPriceColumnDfn(SbmPrice.Column.CalculationMethod).DataName).AsLong();
|
|
decimal calculationValue = values.GetValue(GetPriceColumnDfn(SbmPrice.Column.CalculationValue).DataName).AsDecimal();
|
|
decimal salesPrice = values.GetValue(GetPriceColumnDfn(SbmPrice.Column.Commodity_SalesPrice).DataName).AsDecimal();
|
|
decimal salesDiscountPercent = 0.0m;
|
|
if ((Math.Abs(calculationValue) > 0.001m && Math.Abs(salesPrice) > 0.001m) || column.ShowZeroValues)
|
|
{
|
|
if (Math.Abs(calculationValue) > 0.001m && Math.Abs(salesPrice) > 0.001m)
|
|
{
|
|
if (calculationMethod == Sbm.PriceCalcMethod.Fixed)
|
|
salesDiscountPercent = ((salesPrice - calculationValue) / salesPrice) * 100.0m;
|
|
else if (calculationMethod == Sbm.PriceCalcMethod.DecreasePercent)
|
|
salesDiscountPercent = calculationValue;
|
|
else if (calculationMethod == Sbm.PriceCalcMethod.DecreaseValue)
|
|
salesDiscountPercent = (calculationValue / salesPrice) * 100.0m;
|
|
//else if (calculationMethod == Sbm.PriceCalcMethod.MarkupCost)
|
|
// salesDiscountPercent = calculationValue * -1.0m;
|
|
//else if (calculationMethod == Sbm.PriceCalcMethod.MarkupValue)
|
|
// salesDiscountPercent = (calculationValue / salesPrice) * -100.0m;
|
|
else if (calculationMethod == Sbm.PriceCalcMethod.MarkupSales)
|
|
salesDiscountPercent = calculationValue * -1.0m;
|
|
}
|
|
}
|
|
value = new DataValue(salesDiscountPercent);
|
|
break;
|
|
}
|
|
|
|
//-----------------------------------------------------------
|
|
// Notes.
|
|
case SbmPrice.Column.Notes:
|
|
{
|
|
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
|
break;
|
|
}
|
|
|
|
// Status.
|
|
case SbmPrice.Column.Status_Desc:
|
|
case SbmPrice.Column.Status_Ind:
|
|
{
|
|
String statusCode = values.GetValue(column.DataName).ToString();
|
|
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
|
if (column.Id == (int)SbmPrice.Column.Status_Desc)
|
|
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
|
else if (column.Id == (int)SbmPrice.Column.Status_Ind)
|
|
value = new DataValue(SbmPrice.GetStatusTriState(status));
|
|
break;
|
|
}
|
|
|
|
//-----------------------------------------------------------
|
|
default:
|
|
value = values.GetValue(column.DataName);
|
|
break;
|
|
|
|
}
|
|
return value;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|