Есть query.
У него 4 датасорса InventTable, InventDimCombination, InventDim, InventSum
InventDimCombination связан с InventTable по ItemId
InventDim связан с InventDimCombination по полям InventColorId и InventSizeId
InventSum связан с InventDim по InventDimId
а еще его хочется связать с InventTable по полю ItemId
просто while select работает отлично, а вот в query переложить никак не могу.
пробовал связать через addDynaLink - не выходит, причем вроде запрос получается верный, но данные не выбираются
ниже привожу код.. первый через while select - все работает; второй через query нет
помогите пожалуйста, а?
PHP код:
while select ItemId, ItemName from InventTable
group by ItemId, ItemName
join InventSizeId, InventColorId from InventDimCombination
group by InventSizeId, InventColorId
where InventTable.ItemId==InventDimCombination.ItemId &&
InventDimCombination.InventSizeId!=""
join InventDimId, wMSLocationId from InventDim group by InventDimId, wMSLocationId
where InventDim.InventColorId == InventDimCombination.InventColorId &&
InventDim.InventSizeId == InventDimCombination.InventSizeId &&
InventDim.InventLocationId=="??" &&
InventDim.wMSLocationId=="00.01.1.1"
join AvailPhysical from InventSum group by AvailPhysical
where InventSum.InventDimId == InventDim.inventDimId &&
InventSum.ItemId == InventTable.ItemId &&
InventSum.AvailPhysical > 0
{
print InventTable.ItemId+" "+InventTable.ItemName+" "+InventDim.wMSLocationId;
}
а это через query (метод инит на отчете, где этот квери используется переопределил)
PHP код:
public void init()
{
InventTable inventTable;
InventDimCombination inventDimCombination;
InventDim inventDim;
InventSum inventSum;
Query q;
QueryRun qr;
QueryBuildDataSource inventTableDS;
QueryBuildDataSource inventDimCombinationDS;
QueryBuildDataSource inventDimDS;
QueryBuildDataSource inventSumDS;
DictRelation relation;
QueryBuildRange qbr;
;
super();
q = this.query();
inventTableDS = q.dataSourceTable(tablenum(InventTable));
inventDimCombinationDS = q.dataSourceTable(tablenum(InventDimCombination));
inventDimDS = q.dataSourceTable(tablenum(InventDim));
inventSumDS = q.dataSourceTable(tablenum(inventSum));
inventTableDS.orderMode(OrderMode::GroupBy);
inventTableDS.addSelectionField(fieldnum(InventTable, ItemId));
inventTableDS.addSelectionField(fieldnum(InventTable, itemName));
inventTableDS.addSortField(fieldnum(InventTable, ItemId));
inventTableDS.addSortField(fieldnum(InventTable, itemName));
inventDimCombinationDS.orderMode(OrderMode::GroupBy);
inventDimCombinationDS.addSelectionField(fieldnum(InventDimCombination, InventSizeId));
inventDimCombinationDS.addSelectionField(fieldnum(InventDimCombination, InventColorId));
inventDimCombinationDS.addSortField(fieldnum(InventDimCombination, InventSizeId));
inventDimCombinationDS.addSortField(fieldnum(InventDimCombination, InventColorId));
inventDimCombinationDS.addLink(fieldnum(InventTable, ItemId), fieldnum(InventDimCombination, ItemId));
qbr = inventDimCombinationDS.findRange(fieldnum(InventDimCombination, InventSizeId));
if(!qbr)
qbr = inventDimCombinationDS.addRange(fieldnum(InventDimCombination, InventSizeId));
qbr.value("!\"\"");
inventDimDS.orderMode(OrderMode::GroupBy);
inventDimDS.addSelectionField(fieldnum(InventDim, InventDimId));
inventDimDS.addSelectionField(fieldnum(InventDim, wMSLocationId));
inventDimDS.addSortField(fieldnum(InventDim, InventDimId));
inventDimDS.addSortField(fieldnum(InventDim, wMSLocationId));
inventDimDS.addLink(fieldnum(InventDimCombination, InventColorId), fieldnum(InventDim, InventColorId));
inventDimDS.addLink(fieldnum(InventDimCombination, InventSizeId), fieldnum(InventDim, InventSizeId));
qbr = inventDimDS.findRange(fieldnum(InventDim, InventLocationId));
if(!qbr)
qbr = inventDimDS.addRange(fieldnum(InventDim, InventLocationId));
qbr.value("??");
qbr = inventDimDS.findRange(fieldnum(InventDim, wMSLocationId));
if(!qbr)
qbr = inventDimDS.addRange(fieldnum(InventDim, wMSLocationId));
qbr.value("!\"\"");
inventSumDS.orderMode(OrderMode::GroupBy);
inventSumDS.addSelectionField(fieldnum(InventSum,AvailPhysical));
inventSumDS.addSortField(fieldnum(InventSum,AvailPhysical));
inventSumDS.addSelectionField(fieldnum(InventSum,ItemId));
inventSumDS.addSortField(fieldnum(InventSum,ItemId));
inventSumDS.addDynaLink(fieldnum(InventSum, ItemId), InventTable, fieldnum(InventTable, ItemId));
inventSumDS.addLink(fieldnum(InventDim, inventDimId), fieldnum(InventSum, inventDimId));
inventSumDS.addRange(fieldnum(InventSum, AvailPhysical)).value(strfmt("(%1)>0", fieldstr(InventSum, AvailPhysical)));
print "test";
}