fix pbg payments
This commit is contained in:
@@ -314,20 +314,19 @@ class BigdataResume extends Model
|
||||
])
|
||||
]);
|
||||
|
||||
// Get sum values using proper aggregation to handle multiple retributions
|
||||
// Calculate totals using count-based formula
|
||||
// Business: $business_count * 200 * 44300
|
||||
// Non-Business: $non_business_count * 72 * 16000
|
||||
$business_total = $business_count * 200 * 44300;
|
||||
$non_business_total = $non_business_count * 72 * 16000;
|
||||
$non_verified_total = $business_total + $non_business_total;
|
||||
|
||||
// Get other sum values using proper aggregation to handle multiple retributions
|
||||
$stats = PbgTask::leftJoin('pbg_task_retributions as ptr', 'pbg_task.uuid', '=', 'ptr.pbg_task_uid')
|
||||
->where('pbg_task.is_valid', true)
|
||||
->whereYear('pbg_task.task_created_at', $year)
|
||||
->selectRaw("
|
||||
SUM(CASE WHEN pbg_task.status in (".implode(',', PbgTaskStatus::getVerified()).") THEN COALESCE(ptr.nilai_retribusi_bangunan, 0) ELSE 0 END) AS verified_total,
|
||||
SUM(CASE WHEN pbg_task.status in (".implode(',', PbgTaskStatus::getNonVerified()).") THEN COALESCE(ptr.nilai_retribusi_bangunan, 0) ELSE 0 END) AS non_verified_total,
|
||||
SUM(CASE WHEN (LOWER(TRIM(pbg_task.function_type)) LIKE '%fungsi usaha%'
|
||||
OR LOWER(TRIM(pbg_task.function_type)) LIKE '%sebagai tempat usaha%')
|
||||
AND pbg_task.status in (".implode(',', PbgTaskStatus::getNonVerified()).") THEN COALESCE(ptr.nilai_retribusi_bangunan, 0) ELSE 0 END) AS business_total,
|
||||
SUM(CASE WHEN (LOWER(TRIM(pbg_task.function_type)) NOT LIKE '%fungsi usaha%'
|
||||
AND LOWER(TRIM(pbg_task.function_type)) NOT LIKE '%sebagai tempat usaha%'
|
||||
AND pbg_task.status in (".implode(',', PbgTaskStatus::getNonVerified())."))
|
||||
OR (pbg_task.function_type IS NULL AND pbg_task.status in (".implode(',', PbgTaskStatus::getNonVerified()).")) THEN COALESCE(ptr.nilai_retribusi_bangunan, 0) ELSE 0 END) AS non_business_total,
|
||||
SUM(CASE WHEN pbg_task.status in (".implode(',', PbgTaskStatus::getWaitingClickDpmptsp()).") THEN COALESCE(ptr.nilai_retribusi_bangunan, 0) ELSE 0 END) AS waiting_click_dpmptsp_total,
|
||||
SUM(CASE WHEN pbg_task.status in (".implode(',', PbgTaskStatus::getIssuanceRealizationPbg()).") THEN COALESCE(ptr.nilai_retribusi_bangunan, 0) ELSE 0 END) AS issuance_realization_pbg_total,
|
||||
SUM(CASE WHEN pbg_task.status in (".implode(',', PbgTaskStatus::getProcessInTechnicalOffice()).") THEN COALESCE(ptr.nilai_retribusi_bangunan, 0) ELSE 0 END) AS process_in_technical_office_total,
|
||||
@@ -338,7 +337,11 @@ class BigdataResume extends Model
|
||||
->first();
|
||||
|
||||
\Log::info('Stats calculation result', [
|
||||
'non_verified_total' => $stats->non_verified_total ?? 'NULL',
|
||||
'business_count' => $business_count,
|
||||
'non_business_count' => $non_business_count,
|
||||
'business_total' => $business_total,
|
||||
'non_business_total' => $non_business_total,
|
||||
'non_verified_total' => $non_verified_total,
|
||||
'non_verified_tasks_count' => $stats->non_verified_tasks_count ?? 'NULL',
|
||||
'non_verified_with_retribution_count' => $stats->non_verified_with_retribution_count ?? 'NULL'
|
||||
]);
|
||||
@@ -352,13 +355,13 @@ class BigdataResume extends Model
|
||||
'potention_count' => $potention_count,
|
||||
'potention_sum' => ($stats->potention_total ?? 0),
|
||||
'non_verified_count' => $non_verified_count,
|
||||
'non_verified_sum' => $stats->non_verified_total ?? 0.00,
|
||||
'non_verified_sum' => $non_verified_total,
|
||||
'verified_count' => $verified_count,
|
||||
'verified_sum' => $stats->verified_total ?? 0.00,
|
||||
'business_count' => $business_count,
|
||||
'business_sum' => $stats->business_total ?? 0.00,
|
||||
'business_sum' => $business_total,
|
||||
'non_business_count' => $non_business_count,
|
||||
'non_business_sum' => $stats->non_business_total ?? 0.00,
|
||||
'non_business_sum' => $non_business_total,
|
||||
'year' => $year,
|
||||
'waiting_click_dpmptsp_count' => $waiting_click_dpmptsp_count,
|
||||
'waiting_click_dpmptsp_sum' => $stats->waiting_click_dpmptsp_total ?? 0.00,
|
||||
|
||||
72
app/Models/PbgTaskPayment.php
Normal file
72
app/Models/PbgTaskPayment.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class PbgTaskPayment extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'pbg_task_id',
|
||||
'pbg_task_uid',
|
||||
'registration_number',
|
||||
'sts_form_number',
|
||||
'payment_date',
|
||||
'pad_amount'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'payment_date' => 'date',
|
||||
'pad_amount' => 'decimal:2'
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the PBG task that owns this payment
|
||||
*/
|
||||
public function pbgTask(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PbgTask::class, 'pbg_task_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean and convert registration number for matching
|
||||
*/
|
||||
public static function cleanRegistrationNumber(string $registrationNumber): string
|
||||
{
|
||||
return trim($registrationNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert pad amount string to decimal
|
||||
*/
|
||||
public static function convertPadAmount(?string $padAmount): float
|
||||
{
|
||||
if (empty($padAmount)) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// Remove dots (thousands separator) and convert to float
|
||||
$cleaned = str_replace('.', '', $padAmount);
|
||||
$cleaned = str_replace(',', '.', $cleaned); // Handle comma as decimal separator if present
|
||||
|
||||
return is_numeric($cleaned) ? (float) $cleaned : 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert date string to proper format
|
||||
*/
|
||||
public static function convertPaymentDate(?string $dateString): ?string
|
||||
{
|
||||
if (empty($dateString)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return Carbon::parse($dateString)->format('Y-m-d');
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user