Merge pull request 'added agl uploading and datatable UI update' (#26) from paulcortezl5 into main

Reviewed-on: #26
pull/27/head
paul 6 months ago
commit e19ac486ff

@ -18,6 +18,15 @@ class MiscLib
return $template;
}
public static function adminLTEDataTable1Template($tableID)
{
$template = [
'table_open' => '<table id="'.$tableID.'" class="table table-bordered table-hover">'
];
return $template;
}
public static function adminLTEDataTableTemplate($tableID)
{
$template = [
@ -33,4 +42,23 @@ class MiscLib
return ($key !== false) ? $data[$key] : null;
}
public static function getAttFileInfo($name)
{
$fileInfo = [];
$name = strtolower($name);
if(str_contains($name, 'agl'))
$fileInfo = ['code'=>'AGL',
'skipcount'=>2];
else if(str_contains($name, 'attlog'))
$fileInfo = ['code'=>'ATTLOG',
'skipcount'=>1];
else
$fileInfo = ['code'=>'ATTLOG',
'skipcount'=>1];
return $fileInfo;
}
}

@ -142,16 +142,18 @@ class TKController extends BaseController
if($data['selectedBranch'] != null && $data['attFromTo'] != null)
{
$data['attendanceLog'] = (new RawAttLogModel())->where(['log_date >='=>$data['attFrom'], 'log_date <='=>$data['attTo']])->findAll();
$data['attendanceLog'] = (new RawAttLogModel())->where(['branch_code' => $data['selectedBranch'], 'log_date >='=>$data['attFrom'], 'log_date <='=>$data['attTo']])->findAll();
$attLogHTMLTable = new \CodeIgniter\View\Table();
$attLogHTMLTable->setTemplate(MiscLib::adminLTETableTemplate());
// tblAttLog ID should be initialize in view under JS
$attLogHTMLTable->setTemplate(MiscLib::adminLTEDataTable1Template('tblAttLog'));
if($data['attendanceLog'] == null)
$data['tblAttLog'] = '<p>No attendance log found.</p>';
else
{
$attLogHTMLTable->addRow('Employee ID', 'Log Date', 'Log Time', 'In/Out', 'Branch');
$attLogHTMLTable->setHeading('Employee ID', 'Log Date', 'Log Time', 'In/Out', 'Branch');
foreach($data['attendanceLog'] as $attLog)
{
$attLogHTMLTable->addRow($attLog->company_issued_id, $attLog->log_date, $attLog->log_time, ($attLog->log_type) ? 'Out' : 'In', $attLog->branch_code);
@ -182,33 +184,84 @@ class TKController extends BaseController
if($fileHandle)
{
while (($line = fgets($fileHandle)) !== false)
$lineCounter = 0;
$fileInfo = MiscLib::getAttFileInfo($name);
if($fileInfo['code'] == "AGL")
{
if(trim($line) == '') continue;
// Create DateTime objects for comparison
$dateFromFile = Time::createFromFormat('Y-m-d', substr($line, 10, 10));
$attFrom = Time::createFromFormat('Y-m-d', $attendanceFrom);
$attTo = Time::createFromFormat('Y-m-d', $attendanceTo);
// Check if the date from file falls within the specified range
if ($dateFromFile < $attFrom || $dateFromFile > $attTo) continue;
$batchRawAttLog[] = [
'company_issued_id' => trim(substr($line, 0, 9)),
'log_date' => substr($line, 10, 10),
'log_time' => substr($line, 21, 8),
'ucol1' => substr($line, 30, 1),
'log_type' => substr($line, 32, 1),
'ucol2' => substr($line, 34, 1),
'ucol3' => substr($line, 36, 1),
'branch_code' => $selectedBranch,
'att_from' => $attendanceFrom,
'att_to' => $attendanceTo,
'created_at' => Time::now(),
'created_by' => auth()->user()->employee_id,
];
// 1182 2019-10-29 10:32:41 1 0 1 0
while (($line = fgets($fileHandle)) !== false)
{
if($lineCounter < $fileInfo['skipcount'])
{
$lineCounter++;
continue;
}
$lineData = explode("\t", $line);
$dateTime = explode(' ', $lineData[6]);
// Create DateTime objects for comparison
$dateFromFile = Time::createFromFormat('m/d/Y', $dateTime[0]);
$attFrom = Time::createFromFormat('Y-m-d', $attendanceFrom);
$attTo = Time::createFromFormat('Y-m-d', $attendanceTo);
// Check if the date from file falls within the specified range
if ($dateFromFile < $attFrom || $dateFromFile > $attTo) {
$lineCounter++;
continue;
}
$batchRawAttLog[] = [
'company_issued_id' => trim(substr($line, 8, 4)),
'log_date' => $dateFromFile,
'log_time' => $dateTime[1],
'log_type' => (trim(substr($line, 38, 2)) == "23") ? 0 : 1,
'branch_code' => $selectedBranch,
'att_from' => $attendanceFrom,
'att_to' => $attendanceTo,
'created_at' => Time::now(),
'created_by' => auth()->user()->employee_id,
];
//54325 3 1372 3 26 12/30/2023 22:00:21
$lineCounter++;
}
}
else if($fileInfo['code'] == "ATTLOG")
{
while (($line = fgets($fileHandle)) !== false)
{
if($lineCounter < $fileInfo['skipcount'])
{
$lineCounter++;
continue;
}
// Create DateTime objects for comparison
$dateFromFile = Time::createFromFormat('Y-m-d', substr($line, 10, 10));
$attFrom = Time::createFromFormat('Y-m-d', $attendanceFrom);
$attTo = Time::createFromFormat('Y-m-d', $attendanceTo);
// Check if the date from file falls within the specified range
if ($dateFromFile < $attFrom || $dateFromFile > $attTo) {
$lineCounter++;
continue;
}
$batchRawAttLog[] = [
'company_issued_id' => trim(substr($line, 0, 9)),
'log_date' => substr($line, 10, 10),
'log_time' => substr($line, 21, 8),
'log_type' => substr($line, 32, 1),
'branch_code' => $selectedBranch,
'att_from' => $attendanceFrom,
'att_to' => $attendanceTo,
'created_at' => Time::now(),
'created_by' => auth()->user()->employee_id,
];
// 1182 2019-10-29 10:32:41 1 0 1 0
$lineCounter++;
}
}
fclose($fileHandle);

@ -0,0 +1,45 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class RemoveUColonRawAttLog extends Migration
{
public function up()
{
$fields = [
'ucol1',
'ucol2',
'ucol3'
];
$this->forge->dropColumn('raw_att_log', $fields);
}
public function down()
{
$fields = [
'ucol1' => [
'type' => 'VARCHAR',
'constraint' => 2,
'null' => true,
'after' => 'log_time'
],
'ucol2' => [
'type' => 'VARCHAR',
'constraint' => 2,
'null' => true,
'after' => 'log_type'
],
'ucol3' => [
'type' => 'VARCHAR',
'constraint' => 2,
'null' => true,
'after' => 'ucol2'
],
];
$this->forge->addColumn('raw_att_log', $fields);
}
}

@ -10,10 +10,7 @@ class RawAttLog extends Entity
'company_issue_id' => null,
'log_date' => null,
'log_time' => null,
'ucol1' => null,
'log_type' => null,
'ucol2' => null,
'ucol3' => null,
'branch_code' => null,
'att_from' => null,
'att_to' => null,

@ -15,10 +15,7 @@ class RawAttLogModel extends Model
protected $allowedFields = ['company_issued_id',
'log_date',
'log_time',
'ucol1',
'log_type',
'ucol2',
'ucol3',
'branch_code',
'att_from',
'att_to',];

@ -8,6 +8,11 @@
<!-- CSS of the page -->
<?= $this->section('css') ?>
<!-- DataTables -->
<link rel="stylesheet" href="<?= base_url() ?>adminlte/plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="<?= base_url() ?>adminlte/plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
<?= $this->endSection() ?>
<!-- .CSS -->
@ -133,7 +138,7 @@
<?php if($attendanceSummarySaved): ?>
<p>Summary is saved already. If captured data is erronous, delete the saved data and recapture again.</p>
<?php endif; ?>
<table class="table table-bordered table-striped">
<table id="tblAttSummary" class="table table-bordered table-hover">
<thead>
<tr>
<th>Employee ID</th>
@ -177,8 +182,25 @@
<?= $this->section('js') ?>
<!-- DataTables & Plugins -->
<script src="<?= base_url() ?>adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?= base_url() ?>adminlte/plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="<?= base_url() ?>adminlte/plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="<?= base_url() ?>adminlte/plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script>
$(document).ready(function() {
$('#tblAttSummary').DataTable({
"paging": true,
"lengthChange": false,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": false,
"responsive": true,
});
});

@ -12,6 +12,10 @@
<!-- daterange picker -->
<link rel="stylesheet" href="<?= base_url() ?>adminlte/plugins/daterangepicker/daterangepicker.css">
<!-- DataTables -->
<link rel="stylesheet" href="<?= base_url() ?>adminlte/plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="<?= base_url() ?>adminlte/plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
<?= $this->endSection() ?>
<!-- .CSS -->
@ -157,6 +161,12 @@
<!-- bs-custom-file-input -->
<script src="<?= base_url() ?>adminlte/plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
<!-- DataTables & Plugins -->
<script src="<?= base_url() ?>adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?= base_url() ?>adminlte/plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="<?= base_url() ?>adminlte/plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="<?= base_url() ?>adminlte/plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script>
$(document).ready(function() {
@ -172,6 +182,16 @@ $(document).ready(function() {
$("#hdnAttendanceFrom").val(from);
$("#hdnAttendanceTo").val(to);
});
$('#tblAttLog').DataTable({
"paging": true,
"lengthChange": false,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": false,
"responsive": true,
});
});

Loading…
Cancel
Save