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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user