public function view($invitationKey) { $invitation = $this->invoiceRepo->findInvoiceByInvitation($invitationKey); $invoice = $invitation->invoice; $client = $invoice->client; $account = $invoice->account; if (!$account->checkSubdomain(Request::server('HTTP_HOST'))) { app()->abort(404, trans('texts.invoice_not_found')); } if (!Input::has('phantomjs') && !Session::has($invitationKey) && (!Auth::check() || Auth::user()->account_id != $invoice->account_id)) { Activity::viewInvoice($invitation); Event::fire(new InvoiceViewed($invoice)); } Session::set($invitationKey, true); // track this invitation has been seen Session::set('invitation_key', $invitationKey); // track current invitation $account->loadLocalizationSettings($client); $invoice->invoice_date = Utils::fromSqlDate($invoice->invoice_date); $invoice->due_date = Utils::fromSqlDate($invoice->due_date); $invoice->is_pro = $account->isPro(); if ($invoice->invoice_design_id == CUSTOM_DESIGN) { $invoice->invoice_design->javascript = $account->custom_design; } else { $invoice->invoice_design->javascript = $invoice->invoice_design->pdfmake; } $contact = $invitation->contact; $contact->setVisible(['first_name', 'last_name', 'email', 'phone']); $paymentTypes = $this->getPaymentTypes($client, $invitation); $paymentURL = ''; if (count($paymentTypes)) { $paymentURL = $paymentTypes[0]['url']; if (!$account->isGatewayConfigured(GATEWAY_PAYPAL_EXPRESS)) { $paymentURL = URL::to($paymentURL); } } $showApprove = $invoice->quote_invoice_id ? false : true; if ($invoice->due_date) { $showApprove = time() < strtotime($invoice->due_date); } $data = array('showApprove' => $showApprove, 'showBreadcrumbs' => false, 'hideLogo' => $account->isWhiteLabel(), 'hideHeader' => $account->isNinjaAccount(), 'invoice' => $invoice->hidePrivateFields(), 'invitation' => $invitation, 'invoiceLabels' => $account->getInvoiceLabels(), 'contact' => $contact, 'paymentTypes' => $paymentTypes, 'paymentURL' => $paymentURL, 'phantomjs' => Input::has('phantomjs')); return View::make('invoices.view', $data); }
public function view($invitationKey) { $invitation = Invitation::where('invitation_key', '=', $invitationKey)->firstOrFail(); $invoice = $invitation->invoice; if (!$invoice || $invoice->is_deleted) { return View::make('invoices.deleted'); } $invoice->load('user', 'invoice_items', 'invoice_design', 'account.country', 'client.contacts', 'client.country'); $client = $invoice->client; $account = $client->account; if (!$client || $client->is_deleted) { return View::make('invoices.deleted'); } if ($account->subdomain) { $server = explode('.', Request::server('HTTP_HOST')); $subdomain = $server[0]; if (!in_array($subdomain, ['app', 'www']) && $subdomain != $account->subdomain) { return View::make('invoices.deleted'); } } if (!Session::has($invitationKey) && (!Auth::check() || Auth::user()->account_id != $invoice->account_id)) { Activity::viewInvoice($invitation); Event::fire(new InvoiceViewed($invoice)); } Session::set($invitationKey, true); Session::set('invitation_key', $invitationKey); $account->loadLocalizationSettings(); $invoice->invoice_date = Utils::fromSqlDate($invoice->invoice_date); $invoice->due_date = Utils::fromSqlDate($invoice->due_date); $invoice->is_pro = $account->isPro(); if ($invoice->invoice_design_id == CUSTOM_DESIGN) { $invoice->invoice_design->javascript = $account->custom_design; } else { $invoice->invoice_design->javascript = $invoice->invoice_design->pdfmake; } $contact = $invitation->contact; $contact->setVisible(['first_name', 'last_name', 'email', 'phone']); // Determine payment options $paymentTypes = []; if ($client->getGatewayToken()) { $paymentTypes[] = ['url' => URL::to("payment/{$invitation->invitation_key}/token"), 'label' => trans('texts.use_card_on_file')]; } foreach (Gateway::$paymentTypes as $type) { if ($account->getGatewayByType($type)) { $typeLink = strtolower(str_replace('PAYMENT_TYPE_', '', $type)); $paymentTypes[] = ['url' => URL::to("/payment/{$invitation->invitation_key}/{$typeLink}"), 'label' => trans('texts.' . strtolower($type))]; } } $paymentURL = ''; if (count($paymentTypes)) { $paymentURL = $paymentTypes[0]['url']; } $data = array('isConverted' => $invoice->quote_invoice_id ? true : false, 'showBreadcrumbs' => false, 'hideLogo' => $account->isWhiteLabel(), 'invoice' => $invoice->hidePrivateFields(), 'invitation' => $invitation, 'invoiceLabels' => $account->getInvoiceLabels(), 'contact' => $contact, 'paymentTypes' => $paymentTypes, 'paymentURL' => $paymentURL); return View::make('invoices.view', $data); }