/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(CreateInvoiceRequest $request)
 {
     $data = $request->input();
     $data['documents'] = $request->file('documents');
     $action = Input::get('action');
     $entityType = Input::get('entityType');
     $invoice = $this->invoiceService->save($data);
     $entityType = $invoice->getEntityType();
     $message = trans("texts.created_{$entityType}");
     $input = $request->input();
     $clientPublicId = isset($input['client']['public_id']) ? $input['client']['public_id'] : false;
     if ($clientPublicId == '-1') {
         $message = $message . ' ' . trans('texts.and_created_client');
     }
     Session::flash('message', $message);
     if ($action == 'email') {
         $this->emailInvoice($invoice, Input::get('pdfupload'));
     }
     return url($invoice->getRoute());
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(CreateInvoiceRequest $request)
 {
     $data = $request->input();
     $data['documents'] = $request->file('documents');
     $action = Input::get('action');
     $entityType = Input::get('entityType');
     $invoice = $this->invoiceService->save($data);
     $entityType = $invoice->getEntityType();
     $message = trans("texts.created_{$entityType}");
     // check if we created a new client with the invoice
     // TODO: replace with HistoryListener
     $input = $request->input();
     $clientPublicId = isset($input['client']['public_id']) ? $input['client']['public_id'] : false;
     if ($clientPublicId == '-1') {
         $message = $message . ' ' . trans('texts.and_created_client');
         $trackUrl = URL::to('clients/' . $invoice->client->public_id);
         Utils::trackViewed($invoice->client->getDisplayName(), ENTITY_CLIENT, $trackUrl);
     }
     Session::flash('message', $message);
     if ($action == 'email') {
         return $this->emailInvoice($invoice, Input::get('pdfupload'));
     }
     return redirect()->to($invoice->getRoute());
 }