done restructure calculation retribution

This commit is contained in:
arifal
2025-06-19 13:48:35 +07:00
parent 4c3443c2d6
commit 285e89d5d0
27 changed files with 791 additions and 3161 deletions

View File

@@ -6,7 +6,8 @@ use App\Models\BigdataResume;
use App\Models\DataSetting;
use App\Models\ImportDatasource;
use App\Models\PbgTaskGoogleSheet;
use App\Models\RetributionProposal;
use App\Models\SpatialPlanning;
use App\Models\RetributionCalculation;
use Carbon\Carbon;
use Exception;
use Google\Client as Google_Client;
@@ -237,7 +238,7 @@ class ServiceGoogleSheet
$result = [];
foreach ($sections as $key => $identifier) {
$values = $this->get_values_from_section(2, $identifier, [10, 11]);
$values = $this->get_values_from_section($identifier, [10, 11], 2);
if (!empty($values)) {
$result[$key] = [
@@ -276,8 +277,8 @@ class ServiceGoogleSheet
'process_in_technical_office_count' => $this->convertToInteger($result['PROSES_DINAS_TEKNIS']['total'] ?? null) ?? 0,
'process_in_technical_office_sum' => $this->convertToDecimal($result['PROSES_DINAS_TEKNIS']['nominal'] ?? null) ?? 0,
// TATA RUANG
'spatial_count' => RetributionProposal::count(),
'spatial_sum' => RetributionProposal::sum('total_retribution_amount'),
'spatial_count' => $this->getSpatialPlanningWithCalculationCount(),
'spatial_sum' => $this->getSpatialPlanningCalculationSum()
]);
// Save data settings
@@ -370,12 +371,12 @@ class ServiceGoogleSheet
/**
* Get specific values from a row that contains a specific text/section identifier
* @param int $no_sheet Sheet number (0-based)
* @param string $section_identifier Text to search for in the row
* @param array $column_indices Array of column indices to extract values from
* @param int $no_sheet Sheet number (0-based)
* @return array Array of values from specified columns, or empty array if section not found
*/
private function get_values_from_section($no_sheet = 1, $section_identifier, $column_indices = []) {
private function get_values_from_section(string $section_identifier, array $column_indices = [], int $no_sheet = 1) {
try {
$sheet_data = $this->get_data_by_sheet($no_sheet);
@@ -469,6 +470,48 @@ class ServiceGoogleSheet
return is_numeric($value) ? (float) number_format((float) $value, 2, '.', '') : null;
}
/**
* Get count of spatial plannings that have active retribution calculations
*/
public function getSpatialPlanningWithCalculationCount(): int
{
try {
return SpatialPlanning::whereHas('retributionCalculations', function ($query) {
$query->where('is_active', true);
})->count();
} catch (\Exception $e) {
Log::error("Error getting spatial planning with calculation count", ['error' => $e->getMessage()]);
return 0;
}
}
/**
* Get total sum of retribution amounts for spatial plannings with active calculations
*/
public function getSpatialPlanningCalculationSum(): float
{
try {
// Get all spatial plannings that have active calculations
$spatialPlannings = SpatialPlanning::whereHas('retributionCalculations', function ($query) {
$query->where('is_active', true);
})->with(['retributionCalculations.retributionCalculation'])
->get();
$totalSum = 0;
foreach ($spatialPlannings as $spatialPlanning) {
$activeCalculation = $spatialPlanning->activeRetributionCalculation;
if ($activeCalculation && $activeCalculation->retributionCalculation) {
$totalSum += $activeCalculation->retributionCalculation->retribution_amount;
}
}
return (float) $totalSum;
} catch (\Exception $e) {
Log::error("Error getting spatial planning calculation sum", ['error' => $e->getMessage()]);
return 0.0;
}
}
private function convertToDate($dateString)
{
try {