Added option to create a new person target together with a new booking
This commit is contained in:
@@ -7,6 +7,8 @@ use App\SubBooking;
|
||||
use App\PersonTarget;
|
||||
use App\Project;
|
||||
use App\AccountType;
|
||||
use App\Person;
|
||||
|
||||
use App\Http\Requests\StoreBooking;
|
||||
use App\Http\Requests\UpdateBooking;
|
||||
|
||||
@@ -69,7 +71,18 @@ class BookingsController extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('bookings.create', BookingsController::loadFormArrays());
|
||||
$formArrays = BookingsController::loadFormArrays();
|
||||
|
||||
$persons = Person::select('id', 'name_or_company', 'surname')
|
||||
->orderBy('name_or_company')->get();
|
||||
|
||||
$personsArray = [];
|
||||
|
||||
foreach ($persons as $person) {
|
||||
$personsArray[$person->id] = $person->fullName(true);
|
||||
}
|
||||
|
||||
return view('bookings.create', array_merge(compact('personsArray'), $formArrays));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,6 +93,7 @@ class BookingsController extends Controller
|
||||
*/
|
||||
public function store(StoreBooking $request)
|
||||
{
|
||||
// Booking
|
||||
$booking = new Booking;
|
||||
|
||||
$booking->date = request('date');
|
||||
@@ -89,14 +103,32 @@ class BookingsController extends Controller
|
||||
|
||||
$booking->save();
|
||||
|
||||
// SubBooking
|
||||
$subBooking = new SubBooking;
|
||||
|
||||
$subBooking->reference = request('reference');
|
||||
$subBooking->amount = swapComma(request('amount'));
|
||||
$subBooking->account_type_id = request('account_type_id');
|
||||
$subBooking->person_target_id = request('person_target_id');
|
||||
$subBooking->project_id = request('project_id');
|
||||
|
||||
if (is_null(request('personTarget'))) {
|
||||
$subBooking->person_target_id = request('person_target_id');
|
||||
} else {
|
||||
$personTarget = new personTarget();
|
||||
|
||||
$personTarget->io_type_id = $subBooking->ioType()->id;
|
||||
$personTarget->amount = request('amount');
|
||||
$personTarget->reference = request('reference');
|
||||
$personTarget->person_id = request('personTarget')['person_id'];
|
||||
$personTarget->date = is_null(request('personTarget')['date']) ?
|
||||
request('date') :
|
||||
request('personTarget')['date'];
|
||||
|
||||
$personTarget->save();
|
||||
|
||||
$subBooking->person_target_id = $personTarget->id;
|
||||
}
|
||||
|
||||
$booking->subBookings()->save($subBooking);
|
||||
|
||||
return redirect('/bookings/year-' . Carbon::parse(request('date'))->format('Y'));
|
||||
|
||||
Reference in New Issue
Block a user