This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using AyaNova.Biz;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Util;
|
||||
using System.Linq;
|
||||
namespace AyaNova.PickList
|
||||
{
|
||||
internal class ServiceRatePickList : AyaPickList
|
||||
internal class ServiceRatePickList : AyaPickList, IAyaPickListVariant
|
||||
{
|
||||
public ServiceRatePickList()
|
||||
{
|
||||
@@ -43,14 +47,86 @@ namespace AyaNova.PickList
|
||||
IsRowId = true
|
||||
});
|
||||
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
||||
{
|
||||
TKey = "Tags",
|
||||
FieldKey = "Tags",
|
||||
ColumnDataType = UiFieldDataType.Tags,
|
||||
SqlValueColumnName = "aservicerate.tags"
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public string GetVariantCriteria(string variant)
|
||||
{
|
||||
/*
|
||||
Need variant that shows only rates with contractonly=true (for selection in contract)
|
||||
Need variant that shows only rates for a specific contract (limit to contract rates contract in effect on workorder)
|
||||
Need variant that shows all rates *without* any contract rates (no contract workorder)
|
||||
Need variant that shows all regular rates and also specific contract rates
|
||||
Perhaps all of these will work with the addition of just the contract id?
|
||||
can join in the contract table and items and only show if present or whatever the query needs to be
|
||||
return results are same just the where criteria or server criteria and FROM part of query
|
||||
As non contract scenario is just all items minus any contract only rates
|
||||
Contract may or may not be all items plus contract or just contract (different queries)
|
||||
But it all needs to go through same picklist code for client simplicity
|
||||
*/
|
||||
|
||||
//No variant = all items
|
||||
//"contractrates" variant = all items defined as contract only = true
|
||||
//"contractid:[id]" variant = whatever the contract allows, could be only limited items or all items plus special contract or just all items nothing special
|
||||
|
||||
string defaultNoContractRatesCriteria = "aservicerate.contractonly=false";
|
||||
|
||||
//variant empty, return all that are not contract rates
|
||||
if (string.IsNullOrWhiteSpace(variant))
|
||||
return defaultNoContractRatesCriteria;
|
||||
|
||||
if (variant == "contractrates")
|
||||
return "aservicerate.contractonly=true";
|
||||
|
||||
if (!variant.Contains(":"))
|
||||
throw new System.ArgumentOutOfRangeException($"ServiceRatePickList variant specified \"{variant}\" not valid");
|
||||
|
||||
var v = variant.Split(":");
|
||||
switch (v[0])
|
||||
{
|
||||
case "contractid":
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(v[1]))
|
||||
return defaultNoContractRatesCriteria;
|
||||
long contractId = 0;
|
||||
if (!long.TryParse(v[1], out contractId))
|
||||
return defaultNoContractRatesCriteria;
|
||||
if (contractId == 0)
|
||||
return defaultNoContractRatesCriteria;
|
||||
|
||||
//have a contract id, let's pull it and build the rate id's needed
|
||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
{
|
||||
var c = ct.Contract
|
||||
.AsNoTracking()
|
||||
.Where(z => z.Id == contractId)
|
||||
.FirstOrDefault();
|
||||
if (c == null)
|
||||
return defaultNoContractRatesCriteria;
|
||||
|
||||
//only fetch items that are in the contract rates
|
||||
if (c.ContractServiceRatesOnly)
|
||||
return $"aservicerate.id in ({string.Join(",", c.ServiceRateItems.Select(z => z.ServiceRateId).ToArray())})";
|
||||
|
||||
//contract allows any items plus contract items if exist
|
||||
//If no service rate items in contract then short circuit to regular list
|
||||
if (c.ServiceRateItems.Count == 0)
|
||||
return defaultNoContractRatesCriteria;
|
||||
|
||||
//Ok, a bit more complex then, all non contract rates plus a select few contract rates
|
||||
return $"(aservicerate.contractonly=false) or (aservicerate.id in ({string.Join(",", c.ServiceRateItems.Select(z => z.ServiceRateId).ToArray())}))";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return defaultNoContractRatesCriteria;
|
||||
}
|
||||
}//eoc
|
||||
}//eons
|
||||
Reference in New Issue
Block a user