168 lines
8.3 KiB
C#
168 lines
8.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using AyaNova.Biz;
|
|
using AyaNova.Models;
|
|
|
|
namespace AyaNova.DataList
|
|
{
|
|
internal class PartInventoryDataList : DataListProcessingBase, IDataListInternalCriteria
|
|
{
|
|
public PartInventoryDataList()
|
|
{
|
|
DefaultListAType = AyaType.PartInventory;
|
|
|
|
SQLFrom = "from vpartinventorylist ";
|
|
/*
|
|
"CREATE VIEW vpartinventorylist AS select apart.partnumber,apartwarehouse.name as whsname,vpartinventorynow.*,vpartsonorder.quantityonorder,"
|
|
+"vpartsonordercommitted.quantityonordercommitted,apart.name as prtname, apart.active, apart.cost, apartstocklevel.minimumquantity,apart.retail, aws.name AS whslrname, aaws.name AS altwhslrname, "
|
|
+"GREATEST( COALESCE(apartstocklevel.minimumquantity, 0) - (COALESCE(vpartinventorynow.balance, 0) + COALESCE(vpartsonorder.quantityonorder, 0) - "
|
|
+"COALESCE(vpartsonordercommitted.quantityonordercommitted, 0)) ,0) AS reorderquantity FROM vpartinventorynow LEFT JOIN vpartsonordercommitted ON "
|
|
+"vpartinventorynow.partid = vpartsonordercommitted.partid AND vpartinventorynow.partwarehouseid = vpartsonordercommitted.partwarehouseid "
|
|
+"LEFT JOIN vpartsonorder ON vpartinventorynow.partid = vpartsonorder.partid AND vpartinventorynow.partwarehouseid = vpartsonorder.partwarehouseid "
|
|
+"LEFT JOIN apart ON (vpartinventorynow.partid = apart.id) LEFT JOIN apartwarehouse ON (vpartinventorynow.partwarehouseid = apartwarehouse.id) "
|
|
+"left join avendor AS aws on (apart.wholesalerid = aws.id) left join avendor AS aaws on (apart.alternativewholesalerid = aaws.id) "
|
|
+"left join apartstocklevel on (apartstocklevel.partid = apart.id AND apartstocklevel.partwarehouseid = vpartinventorynow.partwarehouseid);"
|
|
|
|
|
|
|
|
|
|
await ExecQueryAsync("CREATE VIEW vpartinventorylist AS select vpartinventorynow.*, vpartsonordercommitted.quantityonordercommitted, vpartsonorder.quantityonorder from vpartinventorynow "
|
|
+ "left join vpartsonordercommitted on (vpartinventorynow.partid = vpartsonordercommitted.partid and vpartinventorynow.partwarehouseid = vpartsonordercommitted.partwarehouseid)"
|
|
+ "left join vpartsonorder on (vpartinventorynow.partid = vpartsonorder.partid and vpartinventorynow.partwarehouseid = vpartsonorder.partwarehouseid)");
|
|
|
|
*/
|
|
|
|
//NEEDED COLUMNS
|
|
/*
|
|
partid, partnumber, partname, partactive, partcost, partretail, partwarehouseid, partwarehousename,wholesalername,wholesalerid,altwholesalername,altwholesalerid,
|
|
onhandqty, onorderqty, onordercommittedqty, restocklevel/minimumqty, reorderqty, vpartinventorynow.description, vpartinventorynow.id
|
|
*/
|
|
|
|
var RoleSet = BizRoles.GetRoleSet(DefaultListAType);
|
|
AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
|
|
DefaultColumns = new List<string>() { "PartPartNumber", "PartWarehouseName", "PartInventoryBalance", "PartByWarehouseInventoryQuantityOnOrder", "PartByWarehouseInventoryQtyOnOrderCommitted" };
|
|
DefaultSortBy = new Dictionary<string, string>() { { "PartPartNumber", "+" }, { "PartWarehouseName", "+" } };
|
|
FieldDefinitions = new List<DataListFieldDefinition>();
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "PartPartNumber",
|
|
FieldKey = "PartPartNumber",
|
|
AType = (int)AyaType.Part,
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlIdColumnName = "apart.id",
|
|
SqlValueColumnName = "apart.partnumber"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "PartName",
|
|
FieldKey = "PartName",
|
|
AType = (int)AyaType.Part,
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlIdColumnName = "apart.id",
|
|
SqlValueColumnName = "vpartinventorylist.vpartinventorylist"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "PartWarehouseName",
|
|
FieldKey = "PartWarehouseName",
|
|
AType = (int)AyaType.PartWarehouse,
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlIdColumnName = "apartwarehouse.id",
|
|
SqlValueColumnName = "apartwarehouse.name"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "PartInventoryTransactionDescription",
|
|
FieldKey = "PartInventoryTransactionDescription",
|
|
AType = (int)AyaType.PartInventory,
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlIdColumnName = "vpartinventorylist.id",//NEW: vpartinventorynow.id is actually apartinventory.id required for reporting purposes
|
|
SqlValueColumnName = "vpartinventorylist.description",//NEW: vpartinventorynow.description which is actually apartinventory.description
|
|
IsMeta = true,//only so it doesn't show in the UI but is required for report
|
|
IsRowId = true
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "PartInventoryBalance",
|
|
FieldKey = "PartInventoryBalance",
|
|
UiFieldDataType = (int)UiFieldDataType.Decimal,
|
|
SqlValueColumnName = "vpartinventorylist.balance"
|
|
});
|
|
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "PartByWarehouseInventoryQuantityOnOrder",
|
|
FieldKey = "PartByWarehouseInventoryQuantityOnOrder",
|
|
UiFieldDataType = (int)UiFieldDataType.Decimal,
|
|
SqlValueColumnName = "vpartinventorylist.quantityonorder"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "PartByWarehouseInventoryQtyOnOrderCommitted",
|
|
FieldKey = "PartByWarehouseInventoryQtyOnOrderCommitted",
|
|
UiFieldDataType = (int)UiFieldDataType.Decimal,
|
|
SqlValueColumnName = "vpartinventorylist.quantityonordercommitted"
|
|
});
|
|
|
|
|
|
//META
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
|
|
FieldKey = "metapartnumber",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlIdColumnName = "apart.id",
|
|
SqlValueColumnName = "apart.partnumber",
|
|
IsMeta = true
|
|
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
FieldKey = "metawarehouse",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlIdColumnName = "apartwarehouse.id",
|
|
SqlValueColumnName = "apartwarehouse.name",
|
|
IsMeta = true
|
|
});
|
|
|
|
}
|
|
|
|
public List<DataListFilterOption> DataListInternalCriteria(long currentUserId, AuthorizationRoles userRoles, string clientCriteria)
|
|
{
|
|
List<DataListFilterOption> ret = new List<DataListFilterOption>();
|
|
|
|
//ClientCriteria is optional for this list
|
|
//Format for this list is "PARTID,WAREHOUSENAME" where the id is 0 if not filtered or the id to filter
|
|
//and bizarrely the warehousename is text or empty if not filtered
|
|
var crit = (clientCriteria ?? "").Split(',').Select(z => z.Trim()).ToArray();
|
|
if (crit.Length > 1)
|
|
{
|
|
//Part criteria
|
|
if (crit[0] != "0")
|
|
{
|
|
DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metapartnumber" };
|
|
FilterOption.Items.Add(new DataListColumnFilter() { value = crit[0], op = DataListFilterComparisonOperator.Equality });
|
|
ret.Add(FilterOption);
|
|
}
|
|
|
|
//Warehouse criteria
|
|
if (!string.IsNullOrWhiteSpace(crit[1]))
|
|
{
|
|
DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metawarehouse" };
|
|
FilterOption.Items.Add(new DataListColumnFilter() { value = crit[1], op = DataListFilterComparisonOperator.Equality });
|
|
ret.Add(FilterOption);
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
}//eoc
|
|
}//eons |