Skip to content

Instantly share code, notes, and snippets.

@iniakunhuda
Created December 20, 2018 08:48
Show Gist options
  • Save iniakunhuda/72c9e9441bdfbed4f4ab487ca5790aaa to your computer and use it in GitHub Desktop.
Save iniakunhuda/72c9e9441bdfbed4f4ab487ca5790aaa to your computer and use it in GitHub Desktop.
public function fetch(){
$idYard = $this->_q['idyard'];
if(!$this->_auth) {
$this->setjson(false);
return;
}
$res = [];
$dtInspection = $this->ino_receive->GetInspectionListByYard($idYard);
if(!$dtInspection) {
$this->setjson(false);
return;
}
foreach($dtInspection as $insp){
$_idClient[$insp['owned']] = true;
$_idClient[$insp['customer']] = true;
$_idCarrier[$insp['carrier']] = true;
}
$racks = $this->ino_yard->GetAllRack($idYard);
$i_racks = 0;
foreach($racks as $idrack => $valrack) {
$dt['racks'][$i_racks]['key'] = $idrack;
$dt['racks'][$i_racks]['name'] = $valrack['name'];
$i_racks++;
}
$clients = $this->ino_client->GetMultiId(array_keys($_idClient));
foreach($clients as $client){
$dtClient[(string)$client['_id']] = $client['full_name'];
}
$transports = $this->ino_contractor->GetMultiId(array_keys($_idCarrier));
foreach($transports as $tr){
$dtCarrier[(string)$tr['_id']] = $tr['name'];
}
$count = 0;
foreach($dtInspection as $i => $insp){
if($insp['insp_type'] == 'Return') continue;
if($insp['status'] != 'New' && $insp['status'] != 'Ongoing') continue;
$res[$count]['_id'] = $insp['_id'];
$res[$count]['no'] = $insp['no'];
$res[$count]['batch'] = (isset($insp['owned']) && $insp['owned']!="MITO") ? $insp['batch'] . ' - ' . $insp['owned'] : $insp['batch'];
$res[$count]['owned'] = $insp['owned']; //-- owned
$res[$count]['owned_name'] = $dtClient[$insp['owned']];
$res[$count]['carrier'] = $insp['carrier'];
$res[$count]['carrier_name'] = $dtCarrier[$insp['carrier']];
$res[$count]['insp_type'] = $insp['insp_type'];
$res[$count]['status'] = $insp['status'];
$res[$count]['qty'] = (int) $insp['qty'];
$res[$count]['notes'] = ($insp['notes']['initial']['msg']) ? $insp['notes']['initial']['msg'] : '';
$res[$count]['createdate'] = Inodate::format_date_mongo($insp['createdate']);
$res[$count]['racks'] = $dt['racks'];
//-- Draft Item
$res[$count]['items'] = ($insp['items']) ? $insp['items'] : null;
$res[$count]['notes_yard'] = ($insp['notes']['yard_action']['msg']) ? $insp['notes']['yard_action']['msg'] : '';
$mdr = $this->ino_itemcpo->GetOne(['id_item' => $insp['id_item'], 'batch' => $insp['batch']]);
$tally_pipeno = [];
if(count($mdr['tally']) > 0){
for($i=0;$i<count($mdr['tally']);$i++){
$row = $mdr['tally'][$i];
$tally_pipeno[$i]['pipeno'] = $row['pipe_no'];
$tally_pipeno[$i]['heatno'] = $row['heat'];
}
}
$res[$count]['tally'] = (count($tally_pipeno) > 0) ? $tally_pipeno : null;
$count++;
}
$this->setjson($res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment