Привет, ребята, вот мой первый вопрос о переполнении стека.
Я получаю следующее сообщение об ошибке:
Пытаюсь получить свойство не- объект
Когда я пытаюсь просмотреть возвращенный счет в системе. Любая помощь очень ценится! Большое спасибо!
Вот полный код файла:
<?php
namespace App\Http\Controllers;
use App\Addon;
use App\Invoice;
use App\Package;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use App\PackagesCustomPrices;
use App\BookingSlot;
use App\BookingTime;
use App\Booking;
use Dompdf\Dompdf;
use App\Exports\InvoiceExport;
use Excel;
class AdminInvoicesController extends Controller
{
/*
|--------------------------------------------------------------------------
| Admin Invoices Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for providing invoices views to admin.
|
*/
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function export()
{
return Excel::download(new InvoiceExport, 'invoices.xlsx');
}
public function index()
{
$invoices = Invoice::select('invoices.*', 'bookings.first_name as first_name', 'bookings.last_name as last_name', 'bookings.id as booking_id', 'bookings.phone as phone')
->join('bookings', 'bookings.id', 'invoices.booking_id')
->where('invoices.archived', 0)->with('booking')->get();
return view('invoices.index', compact('invoices'));
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$invoice = Invoice::findOrFail($id);
//get package and addons
$package = Package::find($invoice->booking->package->id);
$addons = DB::table('addon_booking')->where('booking_id', '=', $invoice->booking_id)->get();
// $package_custom = PackagesCustomPrices::where('package_id','=',$invoice->booking->package->id)->first();
$exp_booking = explode(" - ",$invoice->booking->booking_time);
list($month,$day,$year) = explode('-', $invoice->booking->booking_date);
$timestamp = mktime(0, 0, 0, $month, $day, $year);
$event_date = date('d-m-Y', $timestamp);
//get day name to select slot timings
$timestamp_for_event = strtotime($event_date);
$today_number = date('N', $timestamp_for_event);
$its_holiday = BookingTime::where('today_is','=',$invoice->booking->booking_date)->first();
if(isset($its_holiday->id))
{
$today_number = $its_holiday->id;
}
$get_slot = BookingSlot::where('opening','=',trim($exp_booking[0]))->where('closing','=',trim($exp_booking[1]))->where('booking_time_id','=',$today_number)->first();
$package_custom = PackagesCustomPrices::where('package_id','=',$invoice->booking->package->id)->where('slot_id','=',$get_slot->id)->first();
if(isset($package_custom->price))
{
$total = $package_custom->price;
}
else
{
$total = $package->price;
}
$invoice->booking->package->price = $total;
//calculate total
//add addons price if any
// foreach($addons as $addon)
// {
// $total = $total + Addon::find($addon->addon_id)->price;
// }
if($invoice->promo_discount)
{
$coupon = \App\CouponCode::where('code', $invoice->promo_used)->first();
if($coupon->extra_items == 0){
if($invoice->promo_discount)
{
$discount = ($invoice->promo_discount / 100) * $total;
$total = $total - $discount;
}
foreach($addons as $addon)
{
$total = $total + Addon::find($addon->addon_id)->price;
}
}
else{
foreach($addons as $addon)
{
$total = $total + Addon::find($addon->addon_id)->price;
}
if($invoice->promo_discount)
{
$discount = ($invoice->promo_discount / 100) * $total;
$total = $total - $discount;
}
}
}
else{
foreach($addons as $addon)
{
$total = $total + Addon::find($addon->addon_id)->price;
}
}
// print_r($total);
// if($invoice->promo_discount)
// {
// $discount = ($invoice->promo_discount / 100) * $total;
// $total = $total - $discount;
// }
// print_r($discount);
// print_r($total);
// exit();
if(!$invoice->promo_discount && config('settings.enable_gst'))
{
$gst_amount = round(( config('settings.gst_percentage') / 100 ) * $total, 2);
}
else if($invoice->promo_discount && config('settings.enable_gst'))
{
if(config('settings.paypal_processing_fee') && $invoice->payment_method == __('app.paypal')){
$total = $invoice->amount - (float) config('settings.paypal_processing_fee');
// print_r($total);
$gst_amount = round(( config('settings.gst_percentage') / 100 ) * $total, 2);
}
elseif (config('settings.stripe_processing_fee') && $invoice->payment_method == __('app.credit_card')) {
$total = $invoice->amount - (float) config('settings.stripe_processing_fee');
// print_r($total);
$gst_amount = round(( config('settings.gst_percentage') / 100 ) * $total, 2);
}
}
else
{
$gst_amount = 0;
}
// exit();
return view('invoices.view', compact('invoice','gst_amount', 'total', 'discount'));
}
public function print($id)
{
$invoice = Invoice::findOrFail($id);
//get package and addons
$package = Package::find($invoice->booking->package->id);
$addons = DB::table('addon_booking')->where('booking_id', '=', $invoice->booking_id)->get();
// $package_custom = PackagesCustomPrices::where('package_id','=',$invoice->booking->package->id)->first();
$exp_booking = explode(" - ",$invoice->booking->booking_time);
list($month,$day,$year) = explode('-', $invoice->booking->booking_date);
$timestamp = mktime(0, 0, 0, $month, $day, $year);
$event_date = date('d-m-Y', $timestamp);
//get day name to select slot timings
$timestamp_for_event = strtotime($event_date);
$today_number = date('N', $timestamp_for_event);
$its_holiday = BookingTime::where('today_is','=',$invoice->booking->booking_date)->first();
if(isset($its_holiday->id))
{
$today_number = $its_holiday->id;
}
$get_slot = BookingSlot::where('opening','=',trim($exp_booking[0]))->where('closing','=',trim($exp_booking[1]))->where('booking_time_id','=',$today_number)->first();
$package_custom = PackagesCustomPrices::where('package_id','=',$invoice->booking->package->id)->where('slot_id','=',$get_slot->id)->first();
if(isset($package_custom->price))
{
$total = $package_custom->price;
}
else
{
$total = $package->price;
}
//calculate total
$invoice->booking->package->price = $total;
//add addons price if any
foreach($addons as $addon)
{
$total = $total + Addon::find($addon->addon_id)->price;
}
if($invoice->promo_discount)
{
$discount = ($invoice->promo_discount / 100) * $total;
$total = $total - $discount;
}
if(config('settings.enable_gst'))
{
$gst_amount = round(( config('settings.gst_percentage') / 100 ) * $total, 2);
}
else
{
$gst_amount = 0;
}
// instantiate and use the dompdf class
// print_r(base_path() . "/vendor/autoload.php");
require base_path() . "/vendor/autoload.php";
$dompdf = new Dompdf();
$dompdf->set_option('isHtml5ParserEnabled', true);
$view_hello = view('invoices.print', compact('invoice','gst_amount', 'total', 'discount'));
$dompdf->loadHtml(utf8_decode($view_hello));
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream("welcome.".date("ymdhis").".pdf", array("Attachment"=>0));
//return view('invoices.view', compact('invoice','gst_amount', 'total', 'discount'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$invoice = Invoice::find($id);
$invoice->update([
'is_paid' => 1
]);
return redirect()->route('invoices.index');
}
public function delete_all(Request $request)
{
$values = explode(',', $request->delete_values);
// print_r($values);
// exit();
foreach ($values as $value) {
if($value === null || empty($value)){
continue;
}
$invoice = Invoice::findorFail($value);
$booking = Booking::find($invoice->booking_id);
if($booking){
$booking->addons()->detach();
$booking->delete();
}
//delete event if google calendar sync is enabled
if(config('settings.sync_events_to_calendar') && config('settings.google_calendar_id') && $booking->google_calendar_event_id != NULL)
{
try {
//remove google calendar event
$event = Event::find($booking->google_calendar_event_id);
$event->delete();
} catch(\Exception $ex) {
//do nothing
}
}
$invoice->delete();
}
Session::flash('booking_deleted', __('backend.invoice_deleted'));
return redirect()->route('invoices.index');
}
}
Строка кода, содержащая ошибку, приведена ниже:
$package_custom = PackagesCustomPrices::where('package_id','=',$invoice->booking->package->id)->where('slot_id','=',$get_slot->id)->first();