204 lines
No EOL
7.7 KiB
PHP
204 lines
No EOL
7.7 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
|
use App\Models\Lead;
|
|
use App\Models\Booking;
|
|
use App\Models\LeadNotice;
|
|
use App\Models\Participant;
|
|
use App\Models\StatusHistory;
|
|
use App\Models\LeadParticipant;
|
|
|
|
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;
|
|
/*if($this->model->lead_participants->count() > 0){
|
|
$this->model->pax = $this->model->lead_participants->count();
|
|
}*/
|
|
$this->model->save();
|
|
return $this->model;
|
|
}
|
|
|
|
public function createBooking($id, $data){
|
|
$this->model = Lead::findOrFail($id);
|
|
|
|
if ($this->model->bookings->count() > 0){
|
|
abort(403, 'Die Anfrage hat bereits eine Buchnung.');
|
|
}
|
|
|
|
$data = [
|
|
'booking_date' => date('Y-m-d'), //now
|
|
'customer_id' => $this->model->customer->id,
|
|
'inquiry_id' => $this->model->id,
|
|
'new_drafts' => 1,
|
|
'sf_guard_user_id' => $this->model->sf_guard_user_id,
|
|
'branch_id' => 4,
|
|
'pax' => $this->model->pax,
|
|
'title' => "",
|
|
'comfort' => false,
|
|
'start_date' => $this->model->travelperiod_start,
|
|
'end_date' => $this->model->travelperiod_end,
|
|
'website_id' => 1,
|
|
'travel_number' => null,
|
|
'participant_name' => null,
|
|
'participant_firstname' => null,
|
|
'participant_birthdate' => null,
|
|
'participant_salutation_id' => null,
|
|
'nationality_id' => null,
|
|
'price' => $this->model->price,
|
|
'price_total' => null,
|
|
'deposit_total' => null,
|
|
'final_payment' => null,
|
|
'final_payment_date' => null,
|
|
'travel_country_id' => $this->model->travelcountry_id,
|
|
'travel_category_id' => $this->model->travelcategory_id,
|
|
'travelagenda_id' => $this->model->travelagenda_id,
|
|
'travel_company_id' => 4,
|
|
];
|
|
|
|
//createBooking
|
|
$booking = Booking::create($data);
|
|
|
|
// copy participants
|
|
if($this->model->lead_participants){
|
|
foreach($this->model->lead_participants as $participant){
|
|
Participant::create([
|
|
'booking_id' => $booking->id,
|
|
'participant_name' => $participant->participant_name,
|
|
'participant_firstname' => $participant->participant_firstname,
|
|
'participant_birthdate' => $participant->participant_birthdate,
|
|
'participant_salutation_id' => $participant->participant_salutation_id,
|
|
'participant_child' => $participant->participant_child,
|
|
'nationality_id' => $participant->nationality_id,
|
|
]);
|
|
}
|
|
}
|
|
|
|
//inquiries
|
|
//offers ???
|
|
/*if($lead->getInquiry()->count() > 0)
|
|
{
|
|
foreach($lead->getInquiry() as $inquiry)
|
|
{
|
|
$arrangement = new Arrangement();
|
|
$arrangement->setArrangementType($inquiry->getInquiryType()->getArrangementType());
|
|
$arrangement->setBegin($inquiry->getBegin());
|
|
$arrangement->setEnd($inquiry->getEnd());
|
|
$arrangement->setDataS($inquiry->getDataS());
|
|
$arrangement->setInPdf($inquiry->getInPdf());
|
|
$arrangement->setBooking($booking);
|
|
$arrangement->save();
|
|
}
|
|
}*/
|
|
|
|
return $this->model;
|
|
}
|
|
|
|
|
|
|
|
} |