diff --git a/.env.example b/.env.example index 4e0ec85b..f9adb344 100644 --- a/.env.example +++ b/.env.example @@ -50,6 +50,13 @@ PAYMENT_USERNAME= PAYMENT_PASSWORD= PAYMENT_LINK= +HARIM_PAYMENT_USERNAME= +HARIM_PAYMENT_PASSWORD= +HARIM_PAYMENT_URL= +HARIM_PAYMENT_SERIAL= +HARIM_PAYMENT_INSTANCE_ID= + + RMS_VERSION=3.0 RMS_CTO_PHONE_NUMBER= diff --git a/app/Console/Commands/GetMachinesInfoListCommand.php b/app/Console/Commands/GetMachinesInfoListCommand.php index a11742cd..98ce995f 100644 --- a/app/Console/Commands/GetMachinesInfoListCommand.php +++ b/app/Console/Commands/GetMachinesInfoListCommand.php @@ -57,6 +57,7 @@ class GetMachinesInfoListCommand extends Command 'province_id' => $entry['UnitGroupCode'] ?? null, 'city_id' => $entry['UnitCode'] ?? null, 'station_id' => $entry['Layer3Code'] ?? null, + 'driver_name' => $entry['DriverName'] ?? null, ]); ++$updatedRows; diff --git a/app/Enums/HarimStates.php b/app/Enums/HarimStates.php index 426cb23a..580e2020 100644 --- a/app/Enums/HarimStates.php +++ b/app/Enums/HarimStates.php @@ -21,6 +21,10 @@ enum HarimStates: int case BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MODIR_KOL = 15; case MOKHALEFAT_BA_DASTGAH = 16; case ETMAM_FARAYAND = 17; + case SODOR_FACTOR = 18; + case PARDAKHT_FACTOR = 19; + case SABT_FISH = 20; + public function label(): string { @@ -42,6 +46,9 @@ enum HarimStates: int self::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MODIR_KOL => "تائید عرصه و اعیان ارسال شده توسط مدیر", self::MOKHALEFAT_BA_DASTGAH => "مخالفت با درخواست", self::ETMAM_FARAYAND => "اتمام فرایند", + self::SODOR_FACTOR => "صدور فاکتور", + self::PARDAKHT_FACTOR => "پرداخت فاکتور", + self::SABT_FISH => "ثبت فیش", }; } } \ No newline at end of file diff --git a/app/Http/Controllers/V3/Dashboard/Harim/DetailController.php b/app/Http/Controllers/V3/Dashboard/Harim/DetailController.php index 2b63341a..a3a6b019 100644 --- a/app/Http/Controllers/V3/Dashboard/Harim/DetailController.php +++ b/app/Http/Controllers/V3/Dashboard/Harim/DetailController.php @@ -2,12 +2,18 @@ namespace App\Http\Controllers\V3\Dashboard\Harim; +use App\Facades\Sms\Sms; +use App\Enums\HarimStates; use App\Exceptions\ProhibitedAction; use App\Http\Controllers\Controller; +use App\Http\Requests\V3\Dashboard\Harim\Detail\HarimSubmitInvoiceRequest; use App\Http\Traits\ApiResponse; use App\Models\Harim; use App\Models\HarimState; +use App\Services\Cartables\Harim\HarimPaymentService; use Illuminate\Http\JsonResponse; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\DB; use Throwable; class DetailController extends Controller @@ -30,4 +36,58 @@ class DetailController extends Controller ->orderBy('id', 'desc') ->get(['id', 'expert_description', 'action_name', 'previous_state_name'])); } + + /** + * @throws Throwable + * @throws ProhibitedAction + */ + public function submitInvoice(Harim $harim, HarimPaymentService $harimpaymentService, HarimSubmitInvoiceRequest $request): JsonResponse + { + $lock = Cache::lock("harimPayment-{$harim->id}", 10); + throw_if(! $lock->get(), new ProhibitedAction('امکان درخواست مجدد تا 10 ثانیه دیگر وجود ندارد')); + + $payment_amount = $harim->payment_amount; + + $bill_code = $harimpaymentService->invoiceBillApi($harim->national_id, $payment_amount); + + DB::transaction(function () use ($bill_code, $harim) { + + $harim->histories()->update([ +// 'bill_code' => $bill_code, + 'status' => HarimStates::SODOR_FACTOR->value, + 'status_fa' => HarimStates::SODOR_FACTOR->label(), + ]); + + }); + + $msg = "فاکتور با شناسه پرداخت \n" . explode("/", $harim->bill_code)[0]. "\n برای پرداخت از لینک زیر اقدام نمایید.\n\n" + . config('harim_web_services.Harim_Payment.LINK')."/#/pay/".explode("/", $harim->bill_code)[0]."/$payment_amount"; + + Sms::sendSms($harim->phone_number, $msg); + + $lock->release(); + + return $this->successResponse(); + } + + /** + * @throws Throwable + */ + public function checkPaymentStatus(Harim $harim, HarimPaymentService $harimpaymentService): JsonResponse + { + DB::transaction(function () use ($harim, $harimpaymentService) { + + $response = json_decode($harimpaymentService->callPaymentStatusBillApi(explode('/', $harim->bill_code)[0])); + + throw_if(! $response->isPayed, new ProhibitedAction('پرداخت انجام نشده است')); + + $harim->histories()->update([ + 'status' => HarimStates::PARDAKHT_FACTOR->value, + 'status_fa' => HarimStates::PARDAKHT_FACTOR->label(), + ]); + + }); + + return $this->successResponse($harim); + } } diff --git a/app/Http/Requests/V3/Dashboard/Harim/Detail/HarimSubmitInvoiceRequest.php b/app/Http/Requests/V3/Dashboard/Harim/Detail/HarimSubmitInvoiceRequest.php new file mode 100644 index 00000000..4ae854f4 --- /dev/null +++ b/app/Http/Requests/V3/Dashboard/Harim/Detail/HarimSubmitInvoiceRequest.php @@ -0,0 +1,30 @@ +harim->state_id == HarimStates::SABT_FISH->value; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php b/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php index d5cc2956..de093022 100644 --- a/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php +++ b/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php @@ -36,13 +36,13 @@ class AllocateRequest extends FormRequest return [ function (Validator $validator) { $duplicateMission = Mission::query()->where('machine_id', '=', $this->machine_id) - ->whereBetween('start_date', [$this->mission->start_date, $this->mission->end_date]) - ->orWhereBetween('end_date', [$this->mission->start_date, $this->mission->end_date]) + ->where('start_date', '<=', $this->mission->end_date) + ->where('end_date', '>=', $this->mission->start_date) ->exists(); if ($duplicateMission) { $validator->errors()->add( - 'machine', + 'machine_id', 'خودروی مورد نظر در این زمان رزرو می باشد' ); } diff --git a/app/Services/Cartables/Harim/HarimPaymentService.php b/app/Services/Cartables/Harim/HarimPaymentService.php new file mode 100644 index 00000000..ef78b702 --- /dev/null +++ b/app/Services/Cartables/Harim/HarimPaymentService.php @@ -0,0 +1,67 @@ + config('harim_web_services.Harim_Payment.username'), + 'password' => config('harim_web_services.Harim_Payment.PASSWORD'), + 'amount' => $payment_amount, + 'serial' => config('harim_web_services.Harim_Payment.serial'), + 'type' => 1, + 'instanceid' => config('harim_web_services.Harim_Payment.instanceid'), + 'ownerid' => $national_id, + 'calculationBox' => "{\"rows\":[{\"amount\":" . $payment_amount . ",\"code\":\"7070011026200593\"}]}" + ); + + $response = Http::withBody(http_build_query($payload)) + ->throw() + ->withoutVerifying() + ->post(config('harim_web_services.Harim_Payment.url')); + + return $response->body(); + + } + catch (\Throwable $th) { + throw new ProhibitedAction('خطا در ارتباط با سرویس پرداخت'); + } + } + return 0; + } + + public function callPaymentStatusBillApi($bill_code) + { + if (App::isProduction()) + { + try { + $username = config('harim_web_services.Harim_Payment.username'); + $password = config('harim_web_services.Harim_Payment.PASSWORD'); + $url = config('harim_web_services.Harim_Payment.url'); + + $result = "{$url}/{$username}/{$password}/{$bill_code}"; + + return Http::get($result) + ->throw() + ->body(); + + }catch (\Throwable $th) { + throw new ProhibitedAction('خطا در دریافت'); + } + } + return json_encode(['isPayed' => 1]); + } +} diff --git a/config/harim_web_services.php b/config/harim_web_services.php index dc3f4686..8c377bf0 100644 --- a/config/harim_web_services.php +++ b/config/harim_web_services.php @@ -38,5 +38,10 @@ return [ 'Harim_Payment' => [ 'fee' => env('HARIM_AMOUNT_FEE'), + 'username' => env('HARIM_ENCRYPTION_USERNAME'), + 'password' => env('HARIM_ENCRYPTION_PASSWORD'), + 'url' => env('HARIM_ENCRYPTION_URL'), + 'serial' => env('HARIM_ENCRYPTION_SERIAL'), + 'instanceid' => env('HARIM_ENCRYPTION_INSTANCE_ID'), ] ]; diff --git a/database/migrations/2025_12_14_103256_add_driver_name_to_cmms_machines_table.php b/database/migrations/2025_12_14_103256_add_driver_name_to_cmms_machines_table.php new file mode 100644 index 00000000..80699afb --- /dev/null +++ b/database/migrations/2025_12_14_103256_add_driver_name_to_cmms_machines_table.php @@ -0,0 +1,28 @@ +string('driver_name')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('cmms_machines', function (Blueprint $table) { + $table->dropColumn('driver_name'); + }); + } +}; diff --git a/resources/views/version2/dashboard.blade.php b/resources/views/version2/dashboard.blade.php index 92a36e6c..bf8b5ac9 100644 --- a/resources/views/version2/dashboard.blade.php +++ b/resources/views/version2/dashboard.blade.php @@ -19,7 +19,7 @@ رسیدگی به شکایات واکنش سریع @endcan @can('add-safety-and-privacy') - ثبت نگهداری حریم راه + ثبت نگهداری حریم راه @endcan @endsection