$lookups = (new Lookup)
->query()
->select([
'lookup_id',
'record_id',
'lookup_list_id',
'linked_record_id',
'data',
'element_label',
'field_name',
'sequence_order',
'field_no',
'archive'
])
->where('company_id', UserData::getDataUser()->company_id)
->where('lookup_list_id', $lookup_list_id)
->orderBy('sequence_order')
->get()
->groupBy(function($item, $key) {
return $item->record_id;
});
$lookups = (new Lookup)
->query()
->select([
'lookup_id',
'record_id',
'lookup_list_id',
'linked_record_id',
'data',
'element_label',
'field_name',
'sequence_order',
'field_no',
'archive'
])
->where('company_id', UserData::getDataUser()->company_id)
->where('lookup_list_id', $lookup_list_id)
->orderBy('sequence_order')
->get()
->groupBy(function($item, $key) {
if($item->linked_record_id > 0)
{
$link = (new Lookup)
->query()
->select([
'lookup_id',
'record_id',
'lookup_list_id',
'linked_record_id',
'data',
'element_label',
'field_name',
'sequence_order',
'field_no',
'archive'
])
->where('company_id', UserData::getDataUser()->company_id)
->where('record_id', $item->linked_record_id)
->orderBy('sequence_order')
->get()->toArray();
$item->linked_data = $link;
}
return $item->record_id;
});
$lookups = (new Lookup)
->query()
->select([
'lookup_id',
'record_id',
'lookup_list_id',
'linked_record_id',
'data',
'element_label',
'field_name',
'sequence_order',
'field_no',
'archive'
])
->where('company_id', UserData::getDataUser()->company_id)
->where('lookup_list_id', $lookup_list_id)
->orderBy('sequence_order')
->get()
->groupBy(function($item, $key) {
/*if($item->linked_record_id > 0)
{
$link = (new Lookup)
->query()
->select([
'lookup_id',
'record_id',
'lookup_list_id',
'linked_record_id',
'data',
'element_label',
'field_name',
'sequence_order',
'field_no',
'archive'
])
->where('company_id', UserData::getDataUser()->company_id)
->where('record_id', $item->linked_record_id)
->orderBy('sequence_order')
->get()->toArray();
$item->linked_data = $link;
}*/
return $item->record_id;
});
$records = [];
foreach ($lookups as $record_id => $node)
{
$record = [];
foreach ($node as $lookup)
{
$record['data'] = $node;
if($lookup->linked_record_id > 0)
{
$link = (new Lookup)
->query()
->select([
'lookup_id',
'record_id',
'lookup_list_id',
'linked_record_id',
'data',
'element_label',
'field_name',
'sequence_order',
'field_no',
'archive'
])
->where('company_id', UserData::getDataUser()->company_id)
->where('record_id', $lookup->linked_record_id)
->orderBy('sequence_order')
->get()->toArray();
$record['link_data'] = $link;
break;
}
}
$records[$record_id] = $record;
}
$shops = query("Select * from shop where city='Moscow'");
$shops = indexBy("id",$shops);
$employes = query("Select * from employe join shop on(shop.id = employe.id_shop) where shop.city='Moscow'");
foreach($employes as $eml){
$shops[$emp["id_shop"]]["employes"][] = $emp;
}
$linkeds = [];
$lookups = (new Lookup)
->query()
->select([
'lookup_id',
'record_id',
'lookup_list_id',
'linked_record_id',
'data',
'element_label',
'field_name',
'sequence_order',
'field_no',
'archive'
])
->where('company_id', UserData::getDataUser()->company_id)
->where('lookup_list_id', $lookup_list_id)
->orderBy('sequence_order')
->get()
->groupBy(function($item, $key) use (&$linkeds) {
if($item->linked_record_id > 0)
{
$linkeds[$item->record_id] = $item->linked_record_id;
}
return $item->record_id;
});
$records = [];
foreach ($lookups as $record_id => $node)
{
$records[$record_id]['data'] = $node;
if(isset($linkeds[$record_id]))
{
$link = (new Lookup)
->query()
->select([
'lookup_id',
'record_id',
'lookup_list_id',
'linked_record_id',
'data',
'element_label',
'field_name',
'sequence_order',
'field_no',
'archive'
])
->where('company_id', UserData::getDataUser()->company_id)
->where('record_id', $linkeds[$record_id])
->orderBy('sequence_order')
->get()->toArray();
$records[$record_id]['link_data'] = $link;
}
}