feat: Enhance Cost Calculator with StayType integration and cost management features
This commit is contained in:
@@ -13,6 +13,7 @@ use Modules\CourseFinder\Models\ProgramLevel;
|
||||
use Modules\CostCalculator\Models\CostCalculator;
|
||||
use Modules\CostCalculator\Services\CostCalculatorService;
|
||||
use Modules\CourseFinder\Models\Program;
|
||||
use Modules\CostCalculator\Models\StayType;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class CostCalculatorController extends Controller
|
||||
@@ -65,10 +66,10 @@ class CostCalculatorController extends Controller
|
||||
{
|
||||
$data['title'] = 'Create Cost Calculator';
|
||||
$data['editable'] = false;
|
||||
$data['countryOptions'] = Country::where('status', 1)->pluck('title', 'id');
|
||||
$data['countryOptions'] = Country::where('status', 1)->where('parent_id', null)->pluck('title', 'id');
|
||||
$data['programLevelOptions'] = ProgramLevel::where('status', 1)->pluck('title', 'id');
|
||||
$data['programOptions'] = Program::where('status', 1)->pluck('title', 'id');
|
||||
$data['livingStatusOptions'] = config('constants.living_status');
|
||||
$data['livingStatusOptions'] = StayType::where('status', 1)->pluck('title', 'id');
|
||||
|
||||
return view('costcalculator::cost.create', $data);
|
||||
}
|
||||
@@ -78,18 +79,57 @@ class CostCalculatorController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
||||
$request->validate([
|
||||
'country_id' => 'required',
|
||||
'programlevel_id' => 'required',
|
||||
'living_status_id' => 'required',
|
||||
]);
|
||||
|
||||
$input = $request->all();
|
||||
$input = $request->except(['living_cost', 'accomodation_cost', 'onetime_cost', 'service_cost']);
|
||||
|
||||
DB::transaction(function () use ($input, $request) {
|
||||
|
||||
CostCalculator::create($input);
|
||||
$costs = CostCalculator::create($input);
|
||||
|
||||
$attachLivingData = [];
|
||||
$attachAccData = [];
|
||||
$attachOnetimeData = [];
|
||||
$attachServiceData = [];
|
||||
|
||||
foreach ($request->living_cost as $item) {
|
||||
$attachLivingData[$item['stay_type_id']] = [
|
||||
'monthly' => $item['monthly'],
|
||||
'yearly' => $item['yearly'],
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($request->accomodation_cost as $item) {
|
||||
$attachAccData[$item['stay_type_id']] = [
|
||||
'monthly' => $item['monthly'],
|
||||
'yearly' => $item['yearly'],
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($request->onetime_cost as $item) {
|
||||
$attachLivingData[$item['stay_type_id']] = [
|
||||
'visa' => $item['visa'],
|
||||
'biometrics' => $item['biometrics'],
|
||||
'sevis' => $item['sevis'],
|
||||
'application' => $item['application'],
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($request->service_cost as $item) {
|
||||
$attachLivingData[$item['stay_type_id']] = [
|
||||
'flight_ticket' => $item['flight_ticket'],
|
||||
'insurance' => $item['insurance'],
|
||||
'extra' => $item['extra'],
|
||||
];
|
||||
}
|
||||
|
||||
$costs->stayTypeLiving()->sync($attachLivingData);
|
||||
$costs->stayTypeAccomodation()->sync($attachAccData);
|
||||
$costs->stayTypeOnetime()->sync($attachOnetimeData);
|
||||
$costs->stayTypeService()->sync($attachServiceData);
|
||||
|
||||
flash()->success('Cost Calculation has been created!');
|
||||
});
|
||||
|
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Modules\CCMS\Models\Country;
|
||||
use Modules\CourseFinder\Models\Program;
|
||||
use Modules\CourseFinder\Models\ProgramLevel;
|
||||
use Modules\CostCalculator\Models\StayType;
|
||||
|
||||
// use Modules\CostCalculator\Database\Factories\CostCalculatorFactory;
|
||||
|
||||
@@ -15,19 +16,16 @@ class CostCalculator extends Model
|
||||
use HasFactory;
|
||||
use \Staudenmeir\EloquentJsonRelations\HasJsonRelationships;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'living_cost' => 'object',
|
||||
'accomodation_cost' => 'object',
|
||||
'onetime_cost' => 'object',
|
||||
'other_services' => 'object',
|
||||
'service_cost' => 'object'
|
||||
];
|
||||
|
||||
public function institution()
|
||||
public function country()
|
||||
{
|
||||
return $this->belongsTo(Country::class, 'country_id');
|
||||
}
|
||||
@@ -41,4 +39,24 @@ class CostCalculator extends Model
|
||||
{
|
||||
return $this->belongsTo(Program::class, 'program_id');
|
||||
}
|
||||
|
||||
public function stayTypeLiving(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(StayType::class, 'living_costs', 'cost_calculator_id', 'stay_type_id')->withPivot('id', 'monthly', 'yearly')->withTimestamps();
|
||||
}
|
||||
|
||||
public function stayTypeAccomodation(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(StayType::class, 'accomodation_costs', 'cost_calculator_id', 'stay_type_id')->withPivot('id', 'monthly', 'yearly')->withTimestamps();
|
||||
}
|
||||
|
||||
public function stayTypeOnetime(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(StayType::class, 'onetime_costs', 'cost_calculator_id', 'stay_type_id')->withPivot('id', 'visa', 'biometrics', 'sevis', 'application')->withTimestamps();
|
||||
}
|
||||
|
||||
public function stayTypeService(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(StayType::class, 'service_costs', 'cost_calculator_id', 'stay_type_id')->withPivot('id', 'flight_ticket', 'insurance', 'extra')->withTimestamps();
|
||||
}
|
||||
}
|
||||
|
@@ -16,16 +16,51 @@ return new class extends Migration
|
||||
$table->unsignedInteger('country_id')->nullable();
|
||||
$table->unsignedInteger('programlevel_id')->nullable();
|
||||
$table->unsignedInteger('program_id')->nullable();
|
||||
$table->unsignedInteger('living_status_id')->nullable();
|
||||
$table->json('living_cost')->nullable();
|
||||
$table->json('accomodation_cost')->nullable();
|
||||
$table->json('onetime_cost')->nullable();
|
||||
$table->json('other_services')->nullable();
|
||||
$table->unsignedInteger('createdby')->nullable();
|
||||
$table->unsignedInteger('updatedby')->nullable();
|
||||
$table->boolean('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('living_costs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedInteger('cost_calculator_id')->nullable();
|
||||
$table->unsignedInteger('stay_type_id')->nullable();
|
||||
$table->string('monthly')->nullable();
|
||||
$table->string('yearly')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('accomodation_costs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedInteger('cost_calculator_id')->nullable();
|
||||
$table->unsignedInteger('stay_type_id')->nullable();
|
||||
$table->string('monthly')->nullable();
|
||||
$table->string('yearly')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('onetime_costs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedInteger('cost_calculator_id')->nullable();
|
||||
$table->unsignedInteger('stay_type_id')->nullable();
|
||||
$table->string('visa')->nullable();
|
||||
$table->string('biometrics')->nullable();
|
||||
$table->string('sevis')->nullable();
|
||||
$table->string('application')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('service_costs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedInteger('cost_calculator_id')->nullable();
|
||||
$table->unsignedInteger('stay_type_id')->nullable();
|
||||
$table->string('flight_ticket')->nullable();
|
||||
$table->string('insurance')->nullable();
|
||||
$table->string('extra')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,5 +69,9 @@ return new class extends Migration
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cost_calculators');
|
||||
Schema::dropIfExists('living_costs');
|
||||
Schema::dropIfExists('accomodation_costs');
|
||||
Schema::dropIfExists('onetime_costs');
|
||||
Schema::dropIfExists('service_costs');
|
||||
}
|
||||
};
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<tr class="accomodation-cost">
|
||||
<td>
|
||||
{{ html()->select('accomodation_cost[' . $numInc . '][status]', $livingStatusOptions)->class('form-select')->placeholder('-Select-')->value($value->id ?? null)->required() }}
|
||||
{{ html()->select('accomodation_cost[' . $numInc . '][stay_type_id]', $livingStatusOptions)->class('form-select')->placeholder('-Select-')->value($value->id ?? null)->required() }}
|
||||
{{ html()->div('Please enter living status')->class('invalid-feedback') }}
|
||||
|
||||
</td>
|
||||
|
@@ -32,13 +32,13 @@
|
||||
<div class="col-md-6">
|
||||
{{ html()->label('Program Level')->class('form-label')->for('programlevel_id') }}
|
||||
{{ html()->span('*')->class('text-danger') }}
|
||||
{{ html()->select('programlevel_id', $programLevelOptions)->placeholder('Select')->class('form-select choices-select')->required() }}
|
||||
{{ html()->select('programlevel_id', $programLevelOptions)->placeholder('Select')->class('form-select choices-select') }}
|
||||
{{ html()->div('Please select program level')->class('invalid-feedback') }}
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
{{ html()->label('Program')->class('form-label')->for('program_id') }}
|
||||
{{ html()->select('program_id', $programOptions)->placeholder('Select')->class('form-select choices-select')->required() }}
|
||||
{{ html()->select('program_id', $programOptions)->placeholder('Select')->class('form-select choices-select') }}
|
||||
{{ html()->div('Please select program')->class('invalid-feedback') }}
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<tr class="living-cost">
|
||||
<td>
|
||||
{{ html()->select('living_cost[' . $numInc . '][status]', $livingStatusOptions)->class('form-select')->placeholder('-Select-')->value($value->id ?? null)->required() }}
|
||||
{{ html()->select('living_cost[' . $numInc . '][stay_type_id]', $livingStatusOptions)->class('form-select')->placeholder('-Select-')->value($value->id ?? null)->required() }}
|
||||
{{ html()->div('Please enter living status')->class('invalid-feedback') }}
|
||||
|
||||
</td>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<tr class="onetime-cost">
|
||||
<td>
|
||||
{{ html()->select('onetime_cost[' . $numInc . '][status]', $livingStatusOptions)->class('form-select')->placeholder('-Select-')->value($value->id ?? null)->required() }}
|
||||
{{ html()->select('onetime_cost[' . $numInc . '][stay_type_id]', $livingStatusOptions)->class('form-select')->placeholder('-Select-')->value($value->id ?? null)->required() }}
|
||||
{{ html()->div('Please enter living status')->class('invalid-feedback') }}
|
||||
</td>
|
||||
|
||||
|
@@ -1,20 +1,20 @@
|
||||
<tr class="onetime-cost">
|
||||
<td>
|
||||
{{ html()->select('other_services[' . $numInc . '][status]', $livingStatusOptions)->class('form-select')->placeholder('-Select-')->value($value->id ?? null)->required() }}
|
||||
{{ html()->select('service_cost[' . $numInc . '][stay_type_id]', $livingStatusOptions)->class('form-select')->placeholder('-Select-')->value($value->id ?? null)->required() }}
|
||||
{{ html()->div('Please enter living status')->class('invalid-feedback') }}
|
||||
|
||||
</td>
|
||||
|
||||
<td class="d-flex flex-column gap-2">
|
||||
{{ html()->text('other_services[' . $numInc . '][flight_ticket]')->class('form-control')->value($value->flight_ticket ?? null)->placeholder('Flight Ticket') }}
|
||||
{{ html()->text('service_cost[' . $numInc . '][flight_ticket]')->class('form-control')->value($value->flight_ticket ?? null)->placeholder('Flight Ticket') }}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
{{ html()->text('other_services[' . $numInc . '][insurance]')->class('form-control')->value($value->insurance ?? null)->placeholder('Health Insurance') }}
|
||||
{{ html()->text('service_cost[' . $numInc . '][insurance]')->class('form-control')->value($value->insurance ?? null)->placeholder('Health Insurance') }}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
{{ html()->text('other_services[' . $numInc . '][extra]')->class('form-control')->value($value->extra ?? null)->placeholder('Extra') }}
|
||||
{{ html()->text('service_cost[' . $numInc . '][extra]')->class('form-control')->value($value->extra ?? null)->placeholder('Extra') }}
|
||||
</td>
|
||||
|
||||
<td class="align-middle">
|
||||
|
@@ -19,4 +19,5 @@ Route::get('destination/{alias}', [WebsiteController::class, 'countrySingle'])->
|
||||
Route::get('/home/resources', [WebsiteController::class, 'resources']);
|
||||
Route::get('getCoursesList', [ProgramController::class, 'getCoursesList'])->name('program.getCoursesList');
|
||||
Route::post('enquiry', [EnquiryController::class, 'store'])->name('enquiry.store');
|
||||
|
||||
Route::get('{parent}/{slug?}', [WebsiteController::class, 'loadPage'])->name('page.load');
|
||||
|
Reference in New Issue
Block a user