118 lines
4.0 KiB
PHP
118 lines
4.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Manual integration script for employeesUplodWithEvents.
|
|
*
|
|
* Usage:
|
|
* php spark test:employee-upload-dates
|
|
*
|
|
* Inserts a real files row using sample enrollment excel and prints stored enrollment dates.
|
|
*/
|
|
|
|
namespace App\Commands;
|
|
|
|
use App\Controllers\EmployeeController;
|
|
use CodeIgniter\CLI\BaseCommand;
|
|
use CodeIgniter\CLI\CLI;
|
|
use Config\Database;
|
|
use Tests\Support\TestUploadedFile;
|
|
|
|
class TestEmployeeUploadDates extends BaseCommand
|
|
{
|
|
protected $group = 'Testing';
|
|
protected $name = 'test:employee-upload-dates';
|
|
protected $description = 'Test employeesUplodWithEvents with d-m-Y and d/m/Y enrollment dates and DB insert';
|
|
protected $usage = 'test:employee-upload-dates [--open=01-07-2026] [--close=31/07/2026]';
|
|
|
|
protected $options = [
|
|
'--open' => 'Enrollment open date (d-m-Y or d/m/Y)',
|
|
'--close' => 'Enrollment close date (d-m-Y or d/m/Y)',
|
|
];
|
|
|
|
public function run(array $params)
|
|
{
|
|
helper('utility');
|
|
|
|
$openDate = CLI::getOption('open') ?? '01-07-2026';
|
|
$closeDate = CLI::getOption('close') ?? '31/07/2026';
|
|
$sample = ROOTPATH . 'public/sample_excel/enrollment.xlsx';
|
|
|
|
if (!is_file($sample)) {
|
|
CLI::error('Sample file not found: ' . $sample);
|
|
|
|
return;
|
|
}
|
|
|
|
require_once ROOTPATH . 'tests/_support/TestUploadedFile.php';
|
|
|
|
$db = Database::connect('default');
|
|
$row = $db->query(
|
|
'SELECT client_id, policy_id, client_branch_id, created_by
|
|
FROM files
|
|
WHERE client_id IS NOT NULL
|
|
AND policy_id IS NOT NULL
|
|
AND client_branch_id IS NOT NULL
|
|
AND created_by IS NOT NULL
|
|
ORDER BY id DESC
|
|
LIMIT 1'
|
|
)->getRowArray();
|
|
|
|
if (empty($row)) {
|
|
CLI::error('No fixture row found in files table.');
|
|
|
|
return;
|
|
}
|
|
|
|
CLI::write('Input dates:', 'yellow');
|
|
CLI::write(" open : {$openDate}");
|
|
CLI::write(" close : {$closeDate}");
|
|
CLI::write('Converted:', 'yellow');
|
|
CLI::write(' open : ' . change_date_format($openDate, null, 'Y-m-d'));
|
|
CLI::write(' close : ' . change_date_format($closeDate, null, 'Y-m-d'));
|
|
|
|
$tmpPath = tempnam(sys_get_temp_dir(), 'enroll_manual_');
|
|
copy($sample, $tmpPath);
|
|
|
|
$uploadedFile = new TestUploadedFile(
|
|
$tmpPath,
|
|
basename($sample),
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
filesize($tmpPath),
|
|
UPLOAD_ERR_OK
|
|
);
|
|
|
|
$postData = [
|
|
'client_id' => (int) $row['client_id'],
|
|
'policy_id' => (int) $row['policy_id'],
|
|
'client_branch_id' => (int) $row['client_branch_id'],
|
|
'created_by' => (int) $row['created_by'],
|
|
'enrollment_open_date' => $openDate,
|
|
'enrollment_close_date' => $closeDate,
|
|
'emplist' => $uploadedFile,
|
|
];
|
|
|
|
$controller = new EmployeeController();
|
|
$result = $controller->employeesUplodWithEvents($postData);
|
|
|
|
CLI::newLine();
|
|
CLI::write('Upload result:', 'green');
|
|
CLI::write(json_encode($result, JSON_PRETTY_PRINT));
|
|
|
|
if (empty($result['file_id'])) {
|
|
return;
|
|
}
|
|
|
|
$file = $db->table('files')->where('id', $result['file_id'])->get()->getRowArray();
|
|
CLI::newLine();
|
|
CLI::write('DB record:', 'green');
|
|
CLI::write(json_encode([
|
|
'id' => $file['id'] ?? null,
|
|
'file_name' => $file['file_name'] ?? null,
|
|
'action' => $file['action'] ?? null,
|
|
'status' => $file['status'] ?? null,
|
|
'enrollment_open_date' => $file['enrollment_open_date'] ?? null,
|
|
'enrollment_close_date' => $file['enrollment_close_date'] ?? null,
|
|
], JSON_PRETTY_PRINT));
|
|
}
|
|
}
|