Merge branch 'feature/HarimOffice' into 'develop'
create controller and rote and form request for harim office See merge request witelgroup/rms_v2!147
This commit is contained in:
25
app/Enums/HarimAction.php
Normal file
25
app/Enums/HarimAction.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum HarimAction: int
|
||||
{
|
||||
case FEEDBACK = 1;
|
||||
case YES = 2;
|
||||
case NO = 3;
|
||||
case CONFIRM = 4;
|
||||
case REJECT = 5;
|
||||
|
||||
public static function name(int $state): string
|
||||
{
|
||||
$mapArray = [
|
||||
1 => "بازخورد",
|
||||
2 => "بله",
|
||||
3 => "خیر",
|
||||
4 => "تائید کردن",
|
||||
5 => "رد درخواست",
|
||||
];
|
||||
|
||||
return $mapArray[$state];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Harim;
|
||||
|
||||
use App\Enums\HarimAction;
|
||||
use App\Enums\HarimStates;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\Dashboard\Harim\HarimOffice\YesRequest;
|
||||
use App\Http\Requests\V3\Dashboard\Harim\HarimOffice\NoRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Harim;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class HarimOfficeController extends Controller
|
||||
{
|
||||
use ApiResponse ;
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$query = Harim::query()->where('edareh_shahri_id', '=', auth()->user()->edarate_shahri_id);
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
);
|
||||
return response()->json($data);
|
||||
}
|
||||
public function yes(YesRequest $request, Harim $harim ): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request,$harim) {
|
||||
$action = HarimAction::YES->value;
|
||||
$harim->histories()->create([
|
||||
'user_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$state = HarimStates::Baresi_Imeni_Rah_Tavasot_Moaven->value;
|
||||
|
||||
$harim ->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => HarimStates::name($state),
|
||||
]);
|
||||
});
|
||||
return $this->successResponse();
|
||||
}
|
||||
public function no(NoRequest $request, Harim $harim ): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request,$harim) {
|
||||
$action = HarimAction::NO->value;
|
||||
$harim->histories()->create([
|
||||
'user_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$state = HarimStates::Baresi_Imeni_Rah_Tavasot_Moaven->value;
|
||||
|
||||
$harim ->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => HarimStates::name($state),
|
||||
]);
|
||||
});
|
||||
return $this->successResponse();
|
||||
}
|
||||
public function show(Harim $harim): JsonResponse
|
||||
{
|
||||
return $this->successResponse($harim);
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,18 @@
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Harim;
|
||||
|
||||
use App\Enums\HarimAction;
|
||||
use App\Enums\HarimStates;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\Dashboard\Harim\FeedBackRequest;
|
||||
use App\Http\Requests\V3\Dashboard\Harim\ProvinceOffice\FeedBackRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Harim;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ProvinceOfficesController extends Controller
|
||||
class ProvinceOfficeController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
@@ -36,7 +37,9 @@ class ProvinceOfficesController extends Controller
|
||||
'user_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => HarimAction::FEEDBACK->value,
|
||||
'action_name' => HarimAction::FEEDBACK->name,
|
||||
]);
|
||||
|
||||
$state = HarimStates::Baresi_Imeni_Rah_Tavasot_Daftar_Harim->value;
|
||||
@@ -48,4 +51,10 @@ class ProvinceOfficesController extends Controller
|
||||
});
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function show(Harim $harim): JsonResponse
|
||||
{
|
||||
return $this->successResponse($harim);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\Dashboard\Harim\HarimOffice;
|
||||
|
||||
use App\Enums\HarimStates;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class NoRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->harim->edare_shahri_id == auth()->user()->edarate_shahri_id &&
|
||||
$this->harim->state_id == HarimStates::Baresi_Imeni_Rah_Tavasot_Daftar_Harim->value; }
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'expert_description' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\Dashboard\Harim\HarimOffice;
|
||||
|
||||
use App\Enums\HarimStates;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class YesRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->harim->edare_shahri_id == auth()->user()->edarate_shahri_id &&
|
||||
$this->harim->state_id == HarimStates::Baresi_Imeni_Rah_Tavasot_Daftar_Harim->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'expert_description' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\Dashboard\Harim;
|
||||
namespace App\Http\Requests\V3\Dashboard\Harim\ProvinceOffice;
|
||||
|
||||
use App\Enums\HarimStates;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
@@ -15,10 +15,10 @@ class HarimActionSeeder extends Seeder
|
||||
{
|
||||
DB::table('harim_actions')->insert([
|
||||
['id' => 1, 'name' => 'feedback', 'created_at' => now(), 'updated_at' => now(),],
|
||||
['id' => 1, 'name' => 'yes', 'created_at' => now(), 'updated_at' => now(),],
|
||||
['id' => 2, 'name' => 'no', 'created_at' => now(), 'updated_at' => now(),],
|
||||
['id' => 3, 'name' => 'confirm', 'created_at' => now(), 'updated_at' => now(),],
|
||||
['id' => 4, 'name' => 'refer', 'created_at' => now(), 'updated_at' => now(),],
|
||||
['id' => 2, 'name' => 'yes', 'created_at' => now(), 'updated_at' => now(),],
|
||||
['id' => 3, 'name' => 'no', 'created_at' => now(), 'updated_at' => now(),],
|
||||
['id' => 4, 'name' => 'confirm', 'created_at' => now(), 'updated_at' => now(),],
|
||||
['id' => 5, 'name' => 'reject', 'created_at' => now(), 'updated_at' => now(),],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ use App\Http\Controllers\V3\Dashboard\Accident\AccidentReceiptReportController;
|
||||
use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshController;
|
||||
use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshSampleController;
|
||||
use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshTypeController;
|
||||
use App\Http\Controllers\V3\Dashboard\Harim\ProvinceOfficesController;
|
||||
use App\Http\Controllers\V3\Dashboard\Harim\HarimOfficeController;
|
||||
use App\Http\Controllers\V3\Dashboard\Harim\ProvinceOfficeController;
|
||||
use App\Http\Controllers\V3\Dashboard\ItemsManagementController;
|
||||
use App\Http\Controllers\V3\Dashboard\Mission\ControlUnitController;
|
||||
use App\Http\Controllers\V3\Dashboard\Mission\DetailController;
|
||||
@@ -512,10 +513,20 @@ Route::prefix('harim')
|
||||
->group(function () {
|
||||
Route::prefix('province_office')
|
||||
->name('province_office.')
|
||||
->controller(ProvinceOfficesController::class)
|
||||
->controller(ProvinceOfficeController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::post('/feedback', 'feedback')->name('feedback');
|
||||
Route::post('/feedback/{harim}', 'feedback')->name('feedback');
|
||||
Route::get('/{harim}', 'show')->name('show');
|
||||
});
|
||||
Route::prefix('harim_office')
|
||||
->name('harim_office.')
|
||||
->controller(HarimOfficeController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::post('/yes/{harim}', 'yes')->name('yes');
|
||||
Route::post('/no/{harim}', 'no')->name('no');
|
||||
Route::get('/{harim}', 'show')->name('show');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user