update api and add more features
This commit is contained in:
@@ -6,10 +6,15 @@ use App\Models\Configuration;
|
||||
use App\Models\Enrollment;
|
||||
use App\Models\StudentClass;
|
||||
use App\Models\User;
|
||||
use App\Services\Billing\ChargeService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PaymentEventChargesService
|
||||
{
|
||||
public function __construct(private ChargeService $chargeService)
|
||||
{
|
||||
}
|
||||
|
||||
public function listCharges(?string $schoolYear, ?string $semester): array
|
||||
{
|
||||
$schoolYear = $schoolYear ?: Configuration::getConfig('school_year');
|
||||
@@ -44,34 +49,45 @@ class PaymentEventChargesService
|
||||
{
|
||||
$studentIds = $payload['student_ids'] ?? [];
|
||||
$parentId = (int) $payload['parent_id'];
|
||||
|
||||
$commonData = [
|
||||
'parent_id' => $parentId,
|
||||
'event_name' => $payload['event_name'],
|
||||
'description' => $payload['description'] ?? null,
|
||||
'amount' => (float) $payload['amount'],
|
||||
'semester' => $payload['semester'],
|
||||
'school_year' => $payload['school_year'],
|
||||
'charged' => 0,
|
||||
'updated_by' => $userId,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
$schoolYear = (string) $payload['school_year'];
|
||||
$semester = (string) $payload['semester'];
|
||||
$eventName = (string) $payload['event_name'];
|
||||
$amount = (float) $payload['amount'];
|
||||
|
||||
$count = 0;
|
||||
|
||||
if (!empty($studentIds)) {
|
||||
foreach ($studentIds as $studentId) {
|
||||
DB::table('event_charges')->insert(array_merge($commonData, [
|
||||
$result = $this->chargeService->createEventCharge([
|
||||
'parent_id' => $parentId,
|
||||
'student_id' => (int) $studentId,
|
||||
]));
|
||||
$count++;
|
||||
'event_name' => $eventName,
|
||||
'amount' => $amount,
|
||||
'description' => $payload['description'] ?? null,
|
||||
'school_year' => $schoolYear,
|
||||
'semester' => $semester,
|
||||
'created_by' => $userId,
|
||||
]);
|
||||
|
||||
if ($result['ok'] ?? false) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
} elseif (!empty($payload['student_id'])) {
|
||||
DB::table('event_charges')->insert(array_merge($commonData, [
|
||||
$result = $this->chargeService->createEventCharge([
|
||||
'parent_id' => $parentId,
|
||||
'student_id' => (int) $payload['student_id'],
|
||||
]));
|
||||
$count++;
|
||||
'event_name' => $eventName,
|
||||
'amount' => $amount,
|
||||
'description' => $payload['description'] ?? null,
|
||||
'school_year' => $schoolYear,
|
||||
'semester' => $semester,
|
||||
'created_by' => $userId,
|
||||
]);
|
||||
|
||||
if ($result['ok'] ?? false) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
|
||||
Reference in New Issue
Block a user