public function view($invitationKey)
{
if (!($invitation = $this->invoiceRepo->findInvoiceByInvitation($invitationKey))) {
return $this->returnError();
}
$invoice = $invitation->invoice;
$client = $invoice->client;
$account = $invoice->account;
if (!$account->checkSubdomain(Request::server('HTTP_HOST'))) {
return response()->view('error', ['error' => trans('texts.invoice_not_found'), 'hideHeader' => true, 'clientViewCSS' => $account->clientViewCSS(), 'clientFontUrl' => $account->getFontsUrl()]);
}
if (!Input::has('phantomjs') && !Input::has('silent') && !Session::has($invitationKey) && (!Auth::check() || Auth::user()->account_id != $invoice->account_id)) {
if ($invoice->isType(INVOICE_TYPE_QUOTE)) {
event(new QuoteInvitationWasViewed($invoice, $invitation));
} else {
event(new InvoiceInvitationWasViewed($invoice, $invitation));
}
}
Session::put($invitationKey, true);
// track this invitation has been seen
Session::put('contact_key', $invitation->contact->contact_key);
// track current contact
$account->loadLocalizationSettings($client);
$invoice->invoice_date = Utils::fromSqlDate($invoice->invoice_date);
$invoice->due_date = Utils::fromSqlDate($invoice->due_date);
$invoice->features = ['customize_invoice_design' => $account->hasFeature(FEATURE_CUSTOMIZE_INVOICE_DESIGN), 'remove_created_by' => $account->hasFeature(FEATURE_REMOVE_CREATED_BY), 'invoice_settings' => $account->hasFeature(FEATURE_INVOICE_SETTINGS)];
$invoice->invoice_fonts = $account->getFontsData();
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']);
$data = [];
$paymentTypes = $this->getPaymentTypes($account, $client, $invitation);
$paymentURL = '';
if (count($paymentTypes) == 1) {
$paymentURL = $paymentTypes[0]['url'];
if ($paymentTypes[0]['gatewayTypeId'] == GATEWAY_TYPE_CUSTOM) {
// do nothing
} elseif (!$account->isGatewayConfigured(GATEWAY_PAYPAL_EXPRESS)) {
$paymentURL = URL::to($paymentURL);
}
}
if ($wepayGateway = $account->getGatewayConfig(GATEWAY_WEPAY)) {
$data['enableWePayACH'] = $wepayGateway->getAchEnabled();
}
$showApprove = $invoice->quote_invoice_id ? false : true;
if ($invoice->due_date) {
$showApprove = time() < strtotime($invoice->due_date);
}
if ($invoice->invoice_status_id >= INVOICE_STATUS_APPROVED) {
$showApprove = false;
}
$data += ['account' => $account, 'showApprove' => $showApprove, 'showBreadcrumbs' => false, 'clientFontUrl' => $account->getFontsUrl(), 'invoice' => $invoice->hidePrivateFields(), 'invitation' => $invitation, 'invoiceLabels' => $account->getInvoiceLabels(), 'contact' => $contact, 'paymentTypes' => $paymentTypes, 'paymentURL' => $paymentURL, 'phantomjs' => Input::has('phantomjs')];
if ($paymentDriver = $account->paymentDriver($invitation, GATEWAY_TYPE_CREDIT_CARD)) {
$data += ['transactionToken' => $paymentDriver->createTransactionToken(), 'partialView' => $paymentDriver->partialView(), 'accountGateway' => $paymentDriver->accountGateway];
}
if ($accountGateway = $account->getGatewayByType(GATEWAY_TYPE_CUSTOM)) {
$data += ['customGatewayName' => $accountGateway->getConfigField('name'), 'customGatewayText' => $accountGateway->getConfigField('text')];
}
if ($account->hasFeature(FEATURE_DOCUMENTS) && $this->canCreateZip()) {
$zipDocs = $this->getInvoiceZipDocuments($invoice, $size);
if (count($zipDocs) > 1) {
$data['documentsZipURL'] = URL::to("client/documents/{$invitation->invitation_key}");
$data['documentsZipSize'] = $size;
}
}
return View::make('invoices.view', $data);
}