Files
raven/server/AyaNova/PickList/CustomerPickList.cs
2023-11-02 22:31:18 +00:00

146 lines
5.3 KiB
C#

using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using AyaNova.Biz;
using System.Linq;
namespace AyaNova.PickList
{
internal class CustomerPickList : AyaPickList, IAyaPickListVariant
{
public CustomerPickList()
{
DefaultListAType = AyaType.Customer;
SQLFrom = "from acustomer ";
AllowedRoles = BizRoles.GetRoleSet(DefaultListAType).Select;
dynamic dTemplate = new JArray();
dynamic cm = new JObject();
cm.fld = "customername";
dTemplate.Add(cm);
cm = new JObject();
cm.fld = "CustomerPhone1";
dTemplate.Add(cm);
cm = new JObject();
cm.fld = "CustomerEmail";
dTemplate.Add(cm);
base.DefaultTemplate = dTemplate.ToString(Newtonsoft.Json.Formatting.None);
//NOTE: Due to the join, all the sql id and name fields that can conflict with the joined table need to be specified completely
ColumnDefinitions = new List<AyaPickListFieldDefinition>();
ColumnDefinitions.Add(new AyaPickListFieldDefinition
{
TKey = "Active",
FieldKey = "customeractive",
ColumnDataType = UiFieldDataType.Bool,
SqlValueColumnName = "acustomer.active",
IsActiveColumn = true
});
ColumnDefinitions.Add(new AyaPickListFieldDefinition
{
TKey = "Name",
FieldKey = "customername",
ColumnDataType = UiFieldDataType.Text,
SqlIdColumnName = "acustomer.id",
SqlValueColumnName = "acustomer.name",
IsRowId = true
});
ColumnDefinitions.Add(new AyaPickListFieldDefinition
{
TKey = "Tags",
FieldKey = "customertags",
ColumnDataType = UiFieldDataType.Tags,
SqlValueColumnName = "acustomer.tags"
});
ColumnDefinitions.Add(new AyaPickListFieldDefinition
{
TKey = "CustomerPhone1",
FieldKey = "CustomerPhone1",
ColumnDataType = UiFieldDataType.PhoneNumber,
SqlValueColumnName = "acustomer.phone1"
});
ColumnDefinitions.Add(new AyaPickListFieldDefinition
{
TKey = "CustomerPhone2",
FieldKey = "CustomerPhone2",
ColumnDataType = UiFieldDataType.PhoneNumber,
SqlValueColumnName = "acustomer.phone2"
});
ColumnDefinitions.Add(new AyaPickListFieldDefinition
{
TKey = "CustomerPhone3",
FieldKey = "CustomerPhone3",
ColumnDataType = UiFieldDataType.PhoneNumber,
SqlValueColumnName = "acustomer.phone3"
});
ColumnDefinitions.Add(new AyaPickListFieldDefinition
{
TKey = "CustomerPhone4",
FieldKey = "CustomerPhone4",
ColumnDataType = UiFieldDataType.PhoneNumber,
SqlValueColumnName = "acustomer.phone4"
});
ColumnDefinitions.Add(new AyaPickListFieldDefinition
{
TKey = "CustomerPhone5",
FieldKey = "CustomerPhone5",
ColumnDataType = UiFieldDataType.PhoneNumber,
SqlValueColumnName = "acustomer.phone5"
});
ColumnDefinitions.Add(new AyaPickListFieldDefinition
{
TKey = "CustomerAccountNumber",
FieldKey = "CustomerAccountNumber",
ColumnDataType = UiFieldDataType.Text,
SqlValueColumnName = "acustomer.accountnumber"
});
ColumnDefinitions.Add(new AyaPickListFieldDefinition
{
TKey = "CustomerEmail",
FieldKey = "CustomerEmail",
ColumnDataType = UiFieldDataType.EmailAddress,
SqlValueColumnName = "acustomer.emailaddress"
});
}
public string GetVariantCriteria(string variant)
{
//Currently the only variant is a object type and id to indicate headoffice
//ClientCriteria format for this list is "OBJECTID,AYATYPE"
var crit = (variant ?? "").Split(',').Select(z => z.Trim()).ToArray();
if (crit.Length > 1)
{
int nType = 0;
if (!int.TryParse(crit[1], out nType)) return string.Empty;
AyaType forType = (AyaType)nType;
if (forType != AyaType.HeadOffice) return string.Empty;
long lId = 0;
if (!long.TryParse(crit[0], out lId)) return string.Empty;
if (lId == 0) return string.Empty;
//Have valid type, have an id, so filter away
switch (forType)
{
case AyaType.HeadOffice:
{
return $"acustomer.headofficeid = {lId}";
}
}
}
return string.Empty;
}
}//eoc
}//eons