Код:
async function filter_labor_costs(): Promise<void> {
Context.data.test_report = Context.fields.test_report.create();
var labor_costs = await Namespace.app.test_labor_costs.search()
.where((f,g) => g.and(f.date.gte(Context.data.start_period!), f.date.lte(Context.data.end_period!))).all();
for (let row of labor_costs)
{
const work_task_item = await row.data.work_task!.fetch();
const exist_row = Context.data.test_report.find(tr => tr.work_task!.id == work_task_item!.id);
if (exist_row == undefined)
{
const new_row = Context.data.test_report!.insert();
new_row.contractor = work_task_item.data.contractor!;
new_row.labor_costs_plan = work_task_item.data.plan_labor_costs_count!;
new_row.labor_costs_fact = row.data.labor_hours!;
new_row.work_task = work_task_item;
} else {
if (exist_row!.labor_costs_fact != undefined)
{
exist_row!.labor_costs_fact = exist_row!.labor_costs_fact + row.data.labor_hours!;
} else {
exist_row!.labor_costs_fact = row.data.labor_hours!;
}
}
}
}