示例#1
0
 public function getSecondaryDataSet($postData, $table, $facility_id, $occur_date, $properties)
 {
     $personnel = Personnel::getTableName();
     $codePersonnelTitle = CodePersonnelTitle::getTableName();
     $codePersonnelType = CodePersonnelType::getTableName();
     $personnelSumDay = PersonnelSumDay::getTableName();
     //     	\DB::enableQueryLog();
     $query = Personnel::where("{$personnel}.FACILITY_ID", '=', $facility_id)->where("{$personnel}.OCCUR_DATE", '=', $occur_date)->whereRaw(\DB::raw("{$personnel}.TYPE = {$codePersonnelType}.ID"))->whereRaw(\DB::raw("{$personnel}.TITLE = {$codePersonnelTitle}.ID"))->select(\DB::raw('count(*)'));
     $entryCount = $query->toSql();
     $binding = $query->getBindings();
     $dataSet = CodePersonnelTitle::join($codePersonnelType, "{$codePersonnelType}.ID", '=', "{$codePersonnelType}.ID")->select(\DB::raw("CONCAT({$codePersonnelType}.ID,{$codePersonnelTitle}.ID) as DT_RowId"), "{$codePersonnelType}.ID as TYPE", "{$codePersonnelTitle}.ID as TITLE", "{$codePersonnelType}.NAME as TYPE_NAME", "{$codePersonnelTitle}.NAME as TITLE_NAME", "{$personnelSumDay}.NOTE", \DB::raw("({$entryCount}) as NUMBER"))->addBinding($binding)->leftJoin($personnelSumDay, function ($join) use($personnelSumDay, $codePersonnelType, $codePersonnelTitle, $facility_id, $occur_date) {
         $join->on("{$personnelSumDay}.TYPE", '=', "{$codePersonnelType}.ID");
         $join->on("{$personnelSumDay}.TITLE", '=', "{$codePersonnelTitle}.ID");
         $join->where('FACILITY_ID', '=', $facility_id);
         $join->where('OCCUR_DATE', '=', $occur_date);
     })->orderBy("{$codePersonnelType}.ID")->orderBy("{$codePersonnelTitle}.ID")->get();
     // 		\Log::info(\DB::getQueryLog());
     return $dataSet;
 }