269 lines
13 KiB
C#
269 lines
13 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.ReferenceData;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
|
|
{
|
|
//=======================================================================
|
|
// Commodity Manager - Commodity Customer.
|
|
//=======================================================================
|
|
partial class SbmCommodityMgr
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
public abstract bool CanManageCommodityCustomers();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Retrieve individual commodityCustomers.
|
|
//-------------------------------------------------------------------
|
|
// CommodityCustomer exists.
|
|
public bool CommodityCustomerExistsById(SysId commodityCustomerId)
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(commodityCustomerId)) return false;
|
|
SbmCommodityCustomer.Params prmCommodityCustomer = new SbmCommodityCustomer.Params();
|
|
prmCommodityCustomer.IdsIncluded.Add(commodityCustomerId);
|
|
prmCommodityCustomer.StatusCat = SbmCommodityCustomer.StatusCat.Any;
|
|
return GetCommodityCustomerCount(prmCommodityCustomer) == 1;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Get commodityCustomers.
|
|
public abstract SbmCommodityCustomer GetCommodityCustomer(SbmCommodityCustomer.Params prm);
|
|
public SbmCommodityCustomer GetCommodityCustomerById(SysId commodityId, SysId assocIdCustomer)
|
|
{
|
|
ClearErrorState();
|
|
if (!CanManageCommodityCustomers())
|
|
{
|
|
SetErrorState("Unable to manage commodity customers");
|
|
return null;
|
|
}
|
|
if (!SysId.IsValid(commodityId) && !SysId.IsValid(assocIdCustomer)) return null;
|
|
SbmCommodityCustomer.Params prmCommodityCustomer = new SbmCommodityCustomer.Params();
|
|
prmCommodityCustomer.CommodityId = commodityId;
|
|
prmCommodityCustomer.AssocIdCustomer = assocIdCustomer;
|
|
prmCommodityCustomer.StatusCat = SbmCommodityCustomer.StatusCat.Any;
|
|
return GetCommodityCustomer(prmCommodityCustomer);
|
|
}
|
|
public SbmCommodityCustomer GetCommodityCustomerByCommodityCustomer(SysId commodityId, SysId assocIdCustomer)
|
|
{
|
|
ClearErrorState();
|
|
if (!CanManageCommodityCustomers())
|
|
{
|
|
SetErrorState("Unable to manage commodity customers");
|
|
return null;
|
|
}
|
|
if (!SysId.IsValid(commodityId) || !SysId.IsValid(assocIdCustomer)) return null;
|
|
//
|
|
SbmCommodityCustomer.Params prmCommodityCustomer = new SbmCommodityCustomer.Params();
|
|
prmCommodityCustomer.CommodityId = commodityId;
|
|
prmCommodityCustomer.AssocIdCustomer = assocIdCustomer;
|
|
prmCommodityCustomer.StatusCat = SbmCommodityCustomer.StatusCat.Any;
|
|
return GetCommodityCustomer(prmCommodityCustomer);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Create commodityCustomers.
|
|
public abstract SbmCommodityCustomer CreateCommodityCustomer(SysId commodityId, SysId assocIdCustomer);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate CommodityCustomer data.
|
|
public bool IsValidCommodityCustomer(SbmCommodityCustomer commodityCustomer)
|
|
{
|
|
ClearErrorState();
|
|
//Validate the identity.
|
|
if (!SysId.IsValid(commodityCustomer.CommodityId)) return SetErrorState("Commodity must be specified");
|
|
if (!SysId.IsValid(commodityCustomer.AssocIdCustomer)) return SetErrorState("Customer must be specified");
|
|
if (commodityCustomer == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
|
return IsValidCommodityCustomerData(commodityCustomer.GetData(), new SbmCommodityCustomer.ErrField());
|
|
}
|
|
public virtual bool IsValidCommodityCustomerData(SbmCommodityCustomer.Data data, SbmCommodityCustomer.ErrField errField)
|
|
{
|
|
ClearErrorState();
|
|
//Validate the identity.
|
|
if (!SysId.IsValid(data.CommodityId)) return SetErrorState("Commodity must be specified");
|
|
if (!SysId.IsValid(data.AssocIdCustomer)) return SetErrorState("Customer must be specified");
|
|
// Validate the text attributes.
|
|
if (errField.ProductCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.ProductCode, GetAttributeCaption(SbmDbDfn.ColumnIdx.CommodityCustomer_ProductCode, "finish code"),
|
|
(long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.CommodityCustomer_ProductCode), true))
|
|
{
|
|
errField.ProductCode = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.PromotionCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.PromotionCode, GetAttributeCaption(SbmDbDfn.ColumnIdx.CommodityCustomer_PromotionCode, "promotion code"), (long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.CommodityCustomer_PromotionCode), true))
|
|
{
|
|
errField.PromotionCode = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.Notes != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Notes, "Notes", (long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.CommodityCustomer_Notes), true))
|
|
{
|
|
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
if (!IsValidValue(data.StatusCode, "status", (long)Internals.GetColTextLen(SbmDbDfn.ColumnIdx.CommodityCustomer_Status), true, true))
|
|
{
|
|
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (!SbmCommodityCustomer.CommodityCustomerStatuses.Contains(data.Status))
|
|
{
|
|
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
|
return SetErrorState(ErrorMessage.InvalidStatus);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Store CommodityCustomer detail.
|
|
public abstract bool StoreCommodityCustomers(List<SbmCommodityCustomer> commodityCustomers);
|
|
public abstract bool StoreCommodityCustomersForCommodity(SysId commodityId, List<SbmCommodityCustomer> commodityCustomers);
|
|
public abstract bool StoreCommodityCustomersForCustomer(SysId assocCustomerId, List<SbmCommodityCustomer> commodityCustomers);
|
|
public abstract bool Store(SbmCommodityCustomer commodityCustomer);
|
|
|
|
//-------------------------------------------------------------------
|
|
// CommodityCustomer database interface.
|
|
public abstract bool InsertCommodityCustomer(SbmCommodityCustomer commodityCustomer, DbUpdateInfo dbUpdateInfo);
|
|
public abstract bool UpdateCommodityCustomer(SbmCommodityCustomer commodityCustomer, DbUpdateInfo dbUpdateInfo);
|
|
public virtual bool CommodityCustomerCanBeDeleted(SbmCommodityCustomer commodityCustomer)
|
|
{
|
|
ClearErrorState();
|
|
return true;
|
|
}
|
|
public abstract bool DeleteCommodityCustomer(SbmCommodityCustomer commodityCustomer, DbUpdateInfo dbUpdateInfo);
|
|
public abstract bool ClearCustomersForCommodity(SysId commodityId);
|
|
public abstract bool ClearCommoditiesForCustomer(SysId assocCustomerId);
|
|
|
|
//-------------------------------------------------------------------
|
|
// CommodityCustomer list.
|
|
public abstract ColumnDfn GetCommodityCustomerColumnDfn(SbmCommodityCustomer.Column columnId, String caption = "", int width = 0);
|
|
public abstract List<String> GetCommodityCustomerQueryFilter(SbmCommodityCustomer.Params prm);
|
|
public abstract long GetCommodityCustomerCount(SbmCommodityCustomer.Params prm);
|
|
public abstract List<SbmCommodityCustomer> GetCommodityCustomerList(SbmCommodityCustomer.Params prm);
|
|
public abstract DbResultSet ExecuteCommodityCustomerQuery(List<ColumnDfn> columns, SbmCommodityCustomer.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 GetCommodityCustomerDataValue(ColumnDfn column, NamedValue.Map values)
|
|
{
|
|
DataValue value = new DataValue();
|
|
switch ((SbmCommodityCustomer.Column)column.Id)
|
|
{
|
|
//-----------------------------------------------------------
|
|
// Commodity Category.
|
|
case SbmCommodityCustomer.Column.Commodity_CategoryDesc:
|
|
{
|
|
String categoryCode = values.GetValue(GetCommodityCustomerColumnDfn(SbmCommodityCustomer.Column.Commodity_CategoryCode).DataName).ToString();
|
|
value = new DataValue(GetCodeTypeCodeDesc(Sbm.ApplCodeType.CommodityCategory, categoryCode));
|
|
break;
|
|
}
|
|
|
|
// ToDo is Commodity DescBrief needed in DataValue? only if its reference ...
|
|
case SbmCommodityCustomer.Column.Commodity_DescBrief:
|
|
{
|
|
//String cmdDescBrief = values.GetValue(column.DataName).ToString();
|
|
value = new DataValue(values.GetValue(column.DataName).ToString());
|
|
break;
|
|
}
|
|
|
|
// Commodity Status.
|
|
case SbmCommodityCustomer.Column.Commodity_StatusDesc:
|
|
case SbmCommodityCustomer.Column.Commodity_StatusInd:
|
|
{
|
|
SaStatus status = SacsSystem.GetStatusForCode(values.GetValue(column.DataName).ToString());
|
|
if (column.Id == (int)SbmCommodityCustomer.Column.Commodity_StatusDesc)
|
|
value = new DataValue(SacsSystem.GetStatusDesc(status));
|
|
else if (column.Id == (int)SbmCommodityCustomer.Column.Commodity_StatusInd)
|
|
value = new DataValue(SbmCommodityCustomer.GetStatusTriState(status));
|
|
}
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
// CmdCustomer Formatted currency values.
|
|
case SbmCommodityCustomer.Column.AmountRetail_Fmt:
|
|
{
|
|
String valFormat = "";
|
|
double cmdcustAmountRetail = values.GetValue(column.DataName).ToNumeric();
|
|
if (Math.Abs(cmdcustAmountRetail) > 0.001 || column.ShowZeroValues)
|
|
{
|
|
valFormat = StringUtil.FormatNumeric(cmdcustAmountRetail, 2, 0, ',');
|
|
SaCurrency currency = GetCurrency(new SysId(StringUtil.ToInt(values.GetValue(GetCommodityCustomerColumnDfn(SbmCommodityCustomer.Column.CurrencyIdRetail).DataName).ToString())));
|
|
if (currency == null) currency = GetDefaultCurrency();
|
|
if (currency != null) valFormat = currency.FormatAmount((decimal)cmdcustAmountRetail);
|
|
}
|
|
value = new DataValue(valFormat);
|
|
break;
|
|
}
|
|
/*ToDo are Currency_Retail needed in DataValue? only if there are reference ...
|
|
//case SbmCommodity.Column.Cust_CurrencyIdRetail:
|
|
case SbmCommodityCustomer.Column.CurrencyIdRetail_Code:
|
|
case SbmCommodityCustomer.Column.CurrencyIdRetail_Symbol:
|
|
{
|
|
String valFormat = "";
|
|
SbmCurrency currency = GetCurrency(new SysId(StringUtil.ToInt(values.GetValue(GetCommodityCustomerColumnDfn(SbmCommodityCustomer.Column.CurrencyIdRetail).DataName).ToString())));
|
|
currency = GetDefaultCurrency();
|
|
if (currency != null)
|
|
{
|
|
if (column.Id == (int)SbmCommodityCustomer.Column.CurrencyIdRetail_Code) valFormat = currency.Code;
|
|
else if (column.Id == (int)SbmCommodityCustomer.Column.CurrencyIdRetail_Symbol) valFormat = currency.Symbol;
|
|
}
|
|
value = new DataValue(valFormat);
|
|
break;
|
|
}*/
|
|
|
|
//-----------------------------------------------------------
|
|
// Promotion Description.
|
|
case SbmCommodityCustomer.Column.PromotionDesc:
|
|
{
|
|
String promotionCode = values.GetValue(column.DataName).ToString();
|
|
value = new DataValue(GetCodeTypeCodeDesc(Sbm.ApplCodeType.CommodityPromotion, promotionCode));
|
|
break;
|
|
}
|
|
|
|
//-----------------------------------------------------------
|
|
// Notes.
|
|
case SbmCommodityCustomer.Column.Notes:
|
|
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
|
break;
|
|
|
|
// Status.
|
|
case SbmCommodityCustomer.Column.Status_Desc:
|
|
case SbmCommodityCustomer.Column.Status_Ind:
|
|
{
|
|
String statusCode = values.GetValue(column.DataName).ToString();
|
|
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
|
if (column.Id == (int)SbmCommodityCustomer.Column.Status_Desc)
|
|
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
|
else if (column.Id == (int)SbmCommodityCustomer.Column.Status_Ind)
|
|
value = new DataValue(SbmCommodityCustomer.GetStatusTriState(status));
|
|
break;
|
|
}
|
|
|
|
//-----------------------------------------------------------
|
|
default:
|
|
value = values.GetValue(column.DataName);
|
|
break;
|
|
|
|
}
|
|
return value;
|
|
}
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|