public function getDataSet($postData, $dcTable, $facility_id, $occur_date, $properties) { $date_end = $postData['date_end']; $date_end = \Helper::parseDate($date_end); $auditTrail = AuditTrail::getTableName(); $codeAuditReason = CodeAuditReason::getTableName(); $beginDate = $occur_date; if ($postData['IntObjectType'] > 0) { $objectName = IntObjectType::where("ID", $postData['IntObjectType'])->select("CODE")->first(); $objectName = $objectName ? $objectName->CODE : ""; $objectType = strtoupper(str_replace(' ', '_', $objectName)) . '_%'; } else { $objectType = '%'; } // $result = array(); // \DB::enableQueryLog(); $dataSet = AuditTrail::leftjoin($codeAuditReason, "{$auditTrail}.REASON", '=', "{$codeAuditReason}.ID")->where(["{$auditTrail}.FACILITY_ID" => $facility_id])->whereDate("{$auditTrail}.WHEN", '>=', $occur_date)->whereDate("{$auditTrail}.WHEN", '<=', $date_end)->where('TABLE_NAME', 'like', $objectType)->select(['ACTION', 'WHO', 'WHEN', 'TABLE_NAME', 'COLUMN_NAME', 'RECORD_ID', 'OBJECT_DESC', 'OLD_VALUE', 'NEW_VALUE', "{$codeAuditReason}.NAME AS REASON"])->get(); // \Log::info(\DB::getQueryLog()); /* foreach ($loadAudittrail as $v){ $v->WHEN = date('m-d-Y', strtotime($v->WHEN)); array_push($result, $v); } return response ()->json ( array ( 'result' => $result ) ); */ /* $dataSet = $mdl::whereDate("$dcTable.BEGIN_DATE",'>=',$occur_date) ->whereDate("$dcTable.BEGIN_DATE",'<=',$date_end) ->select( "$dcTable.ID as $dcTable", "$dcTable.ID as DT_RowId", "$dcTable.*") ->get(); */ return ['dataSet' => $dataSet]; }
public function updateAudit($attributes, $values, $postData) { if ($this->disableUpdateAudit) { return; } $current = Carbon::now(); $current_username = auth()->user()->username; $rowID = $attributes[static::$idField]; $facility_id = $postData['Facility']; $objectDesc = $this->getObjectDesc($rowID); $oldValue = null; $newValue = null; $records = array(); $shouldInsertAudit = true; if ($this->wasRecentlyCreated) { $action = "New record"; $columns = ['New']; } else { $action = "Update value"; $columns = $values; } foreach ($columns as $column => $columnValue) { if (!$this->wasRecentlyCreated) { $shouldInsertAudit = false; if (!in_array($column, $this->excludeColumns)) { if (isset($this->oldValues)) { $original = $this->oldValues; if (array_key_exists($column, $original)) { $oldValue = $original[$column]; $newValue = $this->{$column}; $shouldInsertAudit = $oldValue != $newValue; } } } } if ($shouldInsertAudit) { $records[] = array('ACTION' => $action, 'FACILITY_ID' => $facility_id, 'WHO' => $current_username, 'WHEN' => $current, 'TABLE_NAME' => $this->table, 'COLUMN_NAME' => $column, 'RECORD_ID' => $rowID, 'OBJECT_DESC' => $objectDesc->NAME, 'REASON' => 1, 'OLD_VALUE' => $oldValue, 'NEW_VALUE' => $newValue); } } if (count($records) > 0) { AuditTrail::insert($records); } }