DONE: add accumulated amount display

This commit is contained in:
ISMAIL MASSERAN
2026-05-18 11:52:32 +08:00
parent e8d4f03627
commit fe9223cae1
11 changed files with 482 additions and 242 deletions
@@ -51,8 +51,10 @@ class UpdateVoterPelaburanFromJson extends Command
continue;
}
$pelaburanRaw = $row['pelaburan'] ?? 0;
$map[$noAnggota] = $this->cleanNumber($pelaburanRaw);
$map[$noAnggota] = [
'pelaburan' => $this->cleanNumber($row['pelaburan'] ?? 0),
'accumulated_amount' => $this->cleanNumber($row['accumulated_amount'] ?? 0),
];
}
if (count($map) === 0) {
@@ -78,7 +80,7 @@ class UpdateVoterPelaburanFromJson extends Command
$bar->start();
DB::table('voter')
->select(['id', 'no_anggota', 'pelaburan'])
->select(['id', 'no_anggota', 'pelaburan', 'accumulated_amount'])
->where('election_id', $electionId)
->orderBy('id')
->chunkById(500, function ($chunk) use ($map, $dryRun, &$updated, &$matched, &$missingInJson, &$unchanged, $bar) {
@@ -92,11 +94,15 @@ class UpdateVoterPelaburanFromJson extends Command
}
$matched++;
$jsonRow = $map[$noAnggota];
$newPelaburan = $map[$noAnggota];
$oldPelaburan = $voter->pelaburan !== null ? (float) $voter->pelaburan : 0.0;
$oldAccumulated = $voter->accumulated_amount !== null ? (float) $voter->accumulated_amount : 0.0;
if (abs($oldPelaburan - $newPelaburan) < 0.00001) {
if (
abs($oldPelaburan - $jsonRow['pelaburan']) < 0.00001
&& abs($oldAccumulated - $jsonRow['accumulated_amount']) < 0.00001
) {
$unchanged++;
$bar->advance();
continue;
@@ -106,7 +112,8 @@ class UpdateVoterPelaburanFromJson extends Command
DB::table('voter')
->where('id', $voter->id)
->update([
'pelaburan' => $newPelaburan,
'pelaburan' => $jsonRow['pelaburan'],
'accumulated_amount' => $jsonRow['accumulated_amount'],
'updated_at' => now(),
]);
}
@@ -129,7 +136,6 @@ class UpdateVoterPelaburanFromJson extends Command
private function resolvePath(string $path): string
{
// absolute path
if (strpos($path, DIRECTORY_SEPARATOR) === 0) {
return $path;
}
@@ -155,4 +161,3 @@ class UpdateVoterPelaburanFromJson extends Command
return is_numeric($value) ? (float) $value : 0.0;
}
}
+1 -1
View File
@@ -11,7 +11,7 @@ class Voter extends Authenticatable
protected $table = 'voter';
protected $fillable = ['name', 'no_kp', 'no_anggota','unit', 'election_id', 'alamat', 'telefon', 'saham', 'yuran', 'kehadiran','status_penyata','persetujuan','tarikh_sah','cadangan','pelaburan','tergempar','barangan','peribadi','berjamin_yuran','roadtax','pelbagai'];
protected $fillable = ['name', 'no_kp', 'no_anggota','unit', 'election_id', 'alamat', 'telefon', 'saham', 'yuran', 'kehadiran','status_penyata','persetujuan','tarikh_sah','cadangan','pelaburan', 'accumulated_amount', 'tergempar','barangan','peribadi','berjamin_yuran','roadtax','pelbagai'];
protected $casts = [
'fizikal_registration_verified_at' => 'datetime',