private function save($publicId = null)
{
$action = Input::get('action');
$entityType = Input::get('entityType');
$input = json_decode(Input::get('data'));
if (in_array($action, ['archive', 'delete', 'mark', 'restore'])) {
return InvoiceController::bulk($entityType);
}
if ($errors = $this->invoiceRepo->getErrors($input->invoice)) {
Session::flash('error', trans('texts.invoice_error'));
return Redirect::to("{$entityType}s/create")->withInput()->withErrors($errors);
} else {
$invoice = $this->saveInvoice($publicId, $input, $entityType);
$url = "{$entityType}s/" . $invoice->public_id . '/edit';
$message = trans($publicId ? "texts.updated_{$entityType}" : "texts.created_{$entityType}");
// check if we created a new client with the invoice
if ($input->invoice->client->public_id == '-1') {
$message = $message . ' ' . trans('texts.and_created_client');
$url = URL::to('clients/' . $client->public_id);
Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT, $url);
}
if ($action == 'clone') {
return $this->cloneInvoice($publicId);
} elseif ($action == 'convert') {
return $this->convertQuote($publicId);
} elseif ($action == 'email') {
return $this->emailInvoice($invoice, Input::get('pdfupload'));
}
Session::flash('message', $message);
return Redirect::to($url);
}
}