mein-sterntours/app/Repositories/LeadRepository.php
2021-05-07 17:44:02 +02:00

99 lines
No EOL
3.1 KiB
PHP

<?php
namespace App\Repositories;
use App\Models\Lead;
use App\Models\LeadNotice;
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;
}
}