/**
  * Construct invoices controller
  *
  * @param Request $request
  * @return InvoicesController
  */
 function __construct($request)
 {
     parent::__construct($request);
     if (!$this->logged_user->getSystemPermission('can_manage_invoices')) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     // Warning message about invoices folder existance / writability
     if (is_dir(INVOICES_WORK_PATH)) {
         if (!folder_is_writable(INVOICES_WORK_PATH)) {
             $this->wireframe->addPageMessage(lang('/work/invoices exists, but it is not writable. PDF files will not be generated'), 'error');
         }
         // if
     } else {
         $this->wireframe->addPageMessage(lang('/work/invoices folder does not exist. PDF files will not be generated!'), 'error');
     }
     // if
     $invoice_id = $this->request->getId('invoice_id');
     if ($invoice_id) {
         $this->active_invoice = Invoices::findById($invoice_id);
     }
     // if
     $this->wireframe->addBreadCrumb(lang('Invoices'), assemble_url('invoices'));
     if (instance_of($this->active_invoice, 'Invoice')) {
         $this->wireframe->addBreadCrumb($this->active_invoice->getName(), $this->active_invoice->getViewUrl());
     } else {
         $this->active_invoice = new Invoice();
     }
     // if
     if (Invoice::canAdd($this->logged_user)) {
         $add_invoice_url = assemble_url('invoices_add');
         $this->wireframe->addPageAction(lang('New Invoice'), $add_invoice_url);
     } else {
         $add_invoice_url = false;
     }
     // if
     $this->wireframe->current_menu_item = 'invoicing';
     $this->smarty->assign(array('active_invoice' => $this->active_invoice, 'add_invoice_url' => $add_invoice_url, 'drafts_count' => Invoices::countDrafts()));
     js_assign('invoicing_precision', INVOICE_PRECISION);
 }