124 lines
No EOL
4.6 KiB
PHP
124 lines
No EOL
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
|
use App\Models\Lead;
|
|
use App\Models\LeadNotice;
|
|
use App\Models\LeadParticipant;
|
|
use App\Models\StatusHistory;
|
|
|
|
class LeadRepository extends BaseRepository {
|
|
|
|
|
|
public function __construct(Lead $model)
|
|
{
|
|
$this->model = $model;
|
|
}
|
|
|
|
public function update($data)
|
|
{
|
|
|
|
return $this->model;
|
|
}
|
|
|
|
public function updateNotice($id, $data){
|
|
|
|
$model = Lead::findOrFail($id);
|
|
if($data['action'] === 'edit_notice' && isset($data['notice_id'])){
|
|
$BookingNotice = LeadNotice::findOrFail($data['notice_id']);
|
|
$BookingNotice->message = isset($data['lead_notice']) ? $data['lead_notice'] : "";
|
|
$BookingNotice->edit_at = now();
|
|
$BookingNotice->save();
|
|
}else{
|
|
//save_notice
|
|
LeadNotice::create([
|
|
'lead_id' => $model->id,
|
|
'from_user_id' => \Auth::user()->id,
|
|
'message' => isset($data['lead_notice']) ? $data['lead_notice'] : "",
|
|
]
|
|
);
|
|
}
|
|
|
|
return $model;
|
|
}
|
|
|
|
public function updateLead($id, $data)
|
|
{
|
|
$this->model = Lead::findOrFail($id);
|
|
|
|
|
|
$fill = [
|
|
'request_date' => _reformat_date($data['request_date']),
|
|
'travelperiod_start' => $data['travelperiod_start'] ? _reformat_date($data['travelperiod_start']) : null,
|
|
'travelperiod_end' => $data['travelperiod_end'] ? _reformat_date($data['travelperiod_end']) : null,
|
|
'travelperiod_length' => $data['travelperiod_length'],
|
|
'travelcountry_id' => $data['travelcountry_id'] ? $data['travelcountry_id'] : null,
|
|
'travelagenda_id' => $data['travelagenda_id'] ? $data['travelagenda_id'] : null,
|
|
'remarks' => $data['remarks'],
|
|
'sf_guard_user_id' => $data['sf_guard_user_id'],
|
|
'travelcategory_id' => $data['travelcategory_id'] ? $data['travelcategory_id'] : null,
|
|
'pax' => $data['pax'],
|
|
];
|
|
$this->model->fill($fill);
|
|
$this->model->save();
|
|
|
|
|
|
return $this->model;
|
|
}
|
|
|
|
public function updateLeadStatus($id, $data)
|
|
{
|
|
$this->model = Lead::findOrFail($id);
|
|
|
|
if(isset($data['status'])){
|
|
if($data['status']['id'] != $this->model->status_id || $data['status']['remarks'] !== null){
|
|
$this->model->status_id = $data['status']['id'];
|
|
$this->model->save();
|
|
|
|
$date = $data['status']['date'] ? _reformat_date($data['status']['date']) : _reformat_date(now());
|
|
$this->model->updateNextDueDate($date);
|
|
|
|
$fill = [
|
|
'status_id' => $data['status']['id'],
|
|
'lead_id' => $this->model->id,
|
|
'sf_guard_user_id' => $this->model->sf_guard_user_id,
|
|
'date' => $date,
|
|
'remarks' => $data['status']['remarks'],
|
|
'target_date' => $this->model->next_due_date,
|
|
'created_at' => now(),
|
|
];
|
|
|
|
StatusHistory::create($fill);
|
|
}
|
|
}
|
|
return $this->model;
|
|
}
|
|
|
|
public function updateLeadParticipant($id, $data){
|
|
$this->model = Lead::findOrFail($id);
|
|
if(isset($data['participant'])){
|
|
foreach($data['participant'] as $p_id => $fill){
|
|
$Participant = LeadParticipant::findOrFail($p_id);
|
|
if($Participant->lead_id !== $this->model->id){
|
|
abort(500);
|
|
}
|
|
$fill['participant_child'] = isset($fill['participant_child']) ? true : false;
|
|
$fill['participant_birthdate'] = isset($fill['participant_birthdate']) ? _reformat_date($fill['participant_birthdate']) : null;
|
|
$Participant->fill($fill);
|
|
$Participant->save();
|
|
}
|
|
}
|
|
//main
|
|
$this->model->participant_salutation_id = isset($data['participant_salutation_id']) ? $data['participant_salutation_id'] : null;
|
|
$this->model->participant_name = isset($data['participant_name']) ? $data['participant_name'] : null;
|
|
$this->model->participant_firstname = isset($data['participant_firstname']) ? $data['participant_firstname'] : null;
|
|
//$this->model->nationality_id = isset($data['nationality_id']) ? $data['nationality_id'] : null;
|
|
$this->model->participant_birthdate = isset($data['participant_birthdate']) ? _reformat_date($data['participant_birthdate']) : null;
|
|
|
|
$this->model->save();
|
|
return $this->model;
|
|
}
|
|
|
|
|
|
} |