Ejemplo n.º 1
0
 static function generate($request)
 {
     App::uses('LilCurrentUser', 'Lil.Lib');
     $currentUser = LilCurrentUser::getInstance();
     $tasks['title'] = __d('lil_tasks', 'Tasks');
     $tasks['visible'] = $currentUser->get('id');
     $tasks['active'] = in_array($request->params['controller'], array('tasks'));
     $tasks['url'] = array('admin' => true, 'plugin' => 'lil_tasks', 'controller' => 'tasks', 'action' => 'index');
     $selected_date = null;
     if (!empty($request->query['filter']['date'])) {
         $selected_date = $request->query['filter']['date'];
     }
     App::uses('LilDateEngine', 'Lil.Lib');
     $LilDate = LilDateEngine::getInstance();
     $tasks['items'] = array('lil_tasks' => array('visible' => true, 'title' => __d('lil_tasks', 'Tasks'), 'url' => array('plugin' => 'lil_tasks', 'controller' => 'tasks', 'action' => 'index', 'admin' => true), 'params' => array(), 'active' => in_array($request->params['controller'], array('tasks')) && (empty($selected_date) || !($LilDate->isToday($selected_date) || $LilDate->isTomorrow($selected_date) || in_array($selected_date, array('7d', '30d')))), 'expand' => true, 'submenu' => array('tasks_today' => array('visible' => true, 'title' => __d('lil_tasks', 'Today'), 'url' => array('plugin' => 'lil_tasks', 'controller' => 'tasks', 'admin' => true, 'action' => 'index', '?' => array('filter' => array('date' => strftime('%Y-%m-%d')))), 'active' => $LilDate->isToday($selected_date)), 'tasks_tomorrow' => array('visible' => true, 'title' => __d('lil_tasks', 'Tomorrow'), 'url' => array('plugin' => 'lil_tasks', 'controller' => 'tasks', 'admin' => true, 'action' => 'index', '?' => array('filter' => array('date' => strftime('%Y-%m-%d', time() + 24 * 60 * 60)))), 'active' => $LilDate->isTomorrow($selected_date)), 'tasks_7d' => array('visible' => true, 'title' => __d('lil_tasks', 'Next 7 days'), 'url' => array('plugin' => 'lil_tasks', 'controller' => 'tasks', 'admin' => true, 'action' => 'index', '?' => array('filter' => array('date' => '7d'))), 'active' => $selected_date == '7d'), 'tasks_30d' => array('visible' => true, 'title' => __d('lil_tasks', 'Next 30 days'), 'url' => array('plugin' => 'lil_tasks', 'controller' => 'tasks', 'admin' => true, 'action' => 'index', '?' => array('filter' => array('date' => '30d'))), 'active' => $selected_date == '30d'))));
     return $tasks;
 }
Ejemplo n.º 2
0
 /**
  * filter
  *
  * @access public
  */
 public function filter(&$filter)
 {
     $ret = array();
     if (isset($filter['date'])) {
         App::uses('LilDateEngine', 'Lil.Lib');
         $LilDate = LilDateEngine::getInstance();
         if ($filter['date'] == '7d') {
             $ret['conditions']['OR'] = array(array('Task.completed >=' => $LilDate->toSql(time(), false), 'Task.completed <=' => $LilDate->toSql(time() + 7 * 24 * 60 * 60, false)), array('Task.completed' => null, 'Task.start <=' => $LilDate->toSql(time() + 7 * 24 * 60 * 60, false)), array('Task.completed' => null, 'Task.start' => null));
         } else {
             if ($filter['date'] == '30d') {
                 $ret['conditions']['OR'] = array(array('Task.completed >=' => $LilDate->toSql(time(), false), 'Task.completed <=' => $LilDate->toSql(time() + 30 * 24 * 60 * 60, false)), array('Task.completed' => null, 'Task.start <=' => $LilDate->toSql(time() + 30 * 24 * 60 * 60, false)), array('Task.completed' => null, 'Task.start' => null));
             } else {
                 if ($filter['date'] == 'today' || !$LilDate->isSql($filter['date'])) {
                     $filter['date'] = time();
                 } else {
                     $filter['date'] = strtotime($filter['date']);
                 }
                 $ret['conditions']['OR'] = array(array('Task.completed BETWEEN ? AND ?' => array($LilDate->toSql($filter['date'], false), $LilDate->toSql($filter['date'] + 24 * 60 * 60, false))), array('Task.completed' => null, 'Task.start <=' => $LilDate->toSql($filter['date'], false)), array('Task.completed' => null, 'Task.start' => null));
                 $filter['date'] = $LilDate->toSql($filter['date'], false);
             }
         }
     }
     if (isset($filter['completed'])) {
         if ($filter['completed'] == 1) {
             $ret['conditions']['NOT']['Task.completed'] = null;
         } else {
             $filter['completed'] = 0;
             $ret['conditions']['Task.completed'] = null;
         }
     }
     if (isset($filter['Project'])) {
         $ret['conditions']['Task.project_id'] = (array) $filter['Project'];
     }
     // filter by user
     if ($this->currentUser->role('admin')) {
         if (isset($filter['User'])) {
             $ret['conditions']['Task.user_id'] = (array) $filter['User'];
         }
     } else {
         $filter['User'] = $ret['conditions']['Task.user_id'] = $this->currentUser->get('id');
     }
     return $ret;
 }
Ejemplo n.º 3
0
 public static function execute($type, $filter, $inline)
 {
     $Invoice = ClassRegistry::init('LilInvoices.Invoice');
     App::uses('LilDateEngine', 'Lil.Lib');
     $LilDate = LilDateEngine::getInstance();
     $default_params = array('contain' => array('InvoicesItem', 'InvoicesCounter', 'InvoicesTax', 'Client' => array('PrimaryAddress', 'PrimaryAccount', 'PrimaryEmail'), 'InvoicesAttachment'));
     $ret = true;
     $params = array_merge_recursive($default_params, $Invoice->filter($filter));
     if ($invoices = $Invoice->find('all', $params)) {
         switch ($type) {
             case 'pdf':
                 App::uses('LilReport', 'Lil.Lib');
                 $report = new LilReport('Invoice');
                 $report->helpers(array('Lil.Lil', 'Lil.LilDate', 'Lil.LilFloat', 'Html'));
                 App::uses('Sanitize', 'Utility');
                 // define filename
                 if (sizeof($invoices) == 1) {
                     $filename = Sanitize::paranoid(__d('lil_invoices', 'invoice') . '_' . $invoices[0]['Invoice']['no'], array('-', '_'));
                 } else {
                     $filename = Sanitize::paranoid(__d('lil_invoices', 'invoices') . '_' . $LilDate->toSql(null, true), array('_'));
                 }
                 $Vat = ClassRegistry::init('LilInvoices.Vat');
                 $vats = $Vat->findList();
                 $i = 1;
                 foreach ($invoices as $data) {
                     $report->template('LilInvoices.' . $data['InvoicesCounter']['layout'], 'LilInvoices.lil_invoices_pdf');
                     $report->reset();
                     $report->set(compact('data', 'vats'));
                     $report->render(null);
                     if ($i < sizeof($invoices)) {
                         $report->addPage();
                     }
                     $i++;
                 }
                 $report->output($filename, $inline ? 'I' : 'D');
                 break;
             case 'envelope':
             case 'eslog':
             case 'sepaxml':
                 App::uses('LilCurrentUser', 'Lil.Lib');
                 $currentUser = LilCurrentUser::getInstance();
                 if (($company_id = $currentUser->get('company_id')) && ($Contact = ClassRegistry::init('LilCrm.Contact'))) {
                     if (!($Company = $Contact->find('first', array('conditions' => array('Contact.id' => $company_id), 'contain' => array('PrimaryAccount', 'PrimaryAddress'))))) {
                         $errors[] = __d('lil_invoices', 'Cannot fetch your employer!');
                     }
                 } else {
                     $errors[] = __d('lil_invoices', 'Please provide your employer!');
                 }
                 $Vat = ClassRegistry::init('LilInvoices.Vat');
                 $vats = $Vat->findList();
                 $errors = array();
                 if (empty($Company['PrimaryAccount'])) {
                     $errors[] = __d('lil_invoices', 'Please provide your default account!');
                 }
                 if (empty($Company['PrimaryAddress'])) {
                     $errors[] = __d('lil_invoices', 'Please provide your address!');
                 }
                 if (empty($Company['Contact']['tax_no'])) {
                     $errors[] = __d('lil_invoices', 'Please provide your tax no!');
                 }
                 foreach ($invoices as $data) {
                     if ($type == 'sepaxml' && empty($data['Client']['PrimaryAccount'])) {
                         $errors[] = __d('lil_invoices', 'Please provide client\'s "%s" default account!', $data['Client']['title']);
                     }
                     if (empty($data['Client']['PrimaryAddress'])) {
                         $errors[] = __d('lil_invoices', 'Please provide client\'s "%s" default address!', $data['Client']['title']);
                     }
                     if ($data['Client']['kind'] == 'C' && empty($data['Client']['tax_no'])) {
                         $errors[] = __d('lil_invoices', 'Please provide client\'s "%s" tax no!', $data['Client']['title']);
                     }
                     if ($type == 'sepaxml' && (empty($data['Invoice']['pmt_type']) || empty($data['Invoice']['pmt_module']) || empty($data['Invoice']['pmt_ref']))) {
                         $errors[] = __d('lil_invoices', 'Please provide payment details for invoice "%1$s - %2$s"', $data['Invoice']['no'], $data['Invoice']['title']);
                     }
                 }
                 if (empty($errors)) {
                     $View = new View(null);
                     $View->viewPath = 'Invoices';
                     $View->plugin = 'LilInvoices';
                     $View->helpers = array('Session', 'Html');
                     $View->set('invoices', $invoices);
                     $View->set('Company', $Company);
                     $View->set('vats', $vats);
                     switch ($type) {
                         case 'eslog':
                             $template = 'admin_export_eslog';
                             break;
                         case 'envelope':
                             $template = 'admin_export_envelope';
                             break;
                         default:
                             $template = 'admin_export_sepaxml';
                     }
                     echo $View->render($template, 'xml');
                 } else {
                     $ret = __d('lil_invoices', 'EXPORT ERROR(s):') . '<br />' . implode('<br />', $errors);
                 }
                 break;
         }
     } else {
         return __d('lil_invoices', 'Export error: No invoices found.');
     }
     return $ret;
 }
Ejemplo n.º 4
0
 /**
  * admin_report_unpaid_invoices method
  *
  * @return void
  */
 public function admin_report_unpaid_invoices()
 {
     // need to filter by counters that produce payments
     $Counter = ClassRegistry::init('LilInvoices.InvoicesCounter');
     $counters = $Counter->find('list', array('conditions' => array('InvoicesCounter.expense' => true, 'InvoicesCounter.active' => true)));
     if (!empty($this->request->query)) {
         $filter = $this->request->query;
         App::uses('LilDateEngine', 'Lil.Lib');
         $LilDate = LilDateEngine::getInstance();
         $Invoice = ClassRegistry::init('LilInvoices.Invoice');
         $Invoice->virtualFields['payments_amount'] = 'SELECT COALESCE(SUM(Payment.amount), 0) ' . 'FROM payments_expenses AS PaymentsExpense ' . 'INNER JOIN payments AS Payment ON Payment.id = PaymentsExpense.payment_id ' . 'WHERE PaymentsExpense.expense_id = Expense.id';
         if (!empty($filter['counter'])) {
             $filter['counter'] = array_intersect_key((array) $filter['counter'], array_keys($counters));
         }
         if (!empty($filter['start'])) {
             $filter['start'] = $LilDate->delocalize($filter['start']);
         }
         if (!empty($filter['end'])) {
             $filter['end'] = $LilDate->delocalize($filter['end']);
         }
         $data = $Invoice->find('all', Set::merge($Invoice->filter($filter), array('conditions' => array_merge(!empty($filter['counter']) ? array() : array('Invoice.counter_id' => array_keys($counters)), empty($filter['overdue']) ? array() : array('Invoice.dat_expire <=' => $LilDate->toSql(null, false))), 'contain' => array('Client', 'Expense', 'InvoicesCounter'), 'order' => 'InvoicesCounter.title, Invoice.counter', 'group' => 'Invoice.id HAVING (ABS(ABS(Invoice.total) - ABS(Invoice__payments_amount)) > 0.001)')));
         $this->response->type('pdf');
         App::uses('LilReport', 'Lil.Lib');
         $report = new LilReport('expenses_unpaid_invoices');
         $report->template('LilExpenses.unpaid_invoices')->helpers(array('Lil.Lil', 'Lil.LilDate', 'Lil.LilFloat', 'Html'));
         $report->set(compact('data', 'filter', 'counters'))->render('unpaid_invoices');
     }
     $this->set(compact('counters'));
 }
 function __HeartbeatNotifications($console, $users)
 {
     App::uses('LilDateEngine', 'Lil.Lib');
     $LilDate = LilDateEngine::getInstance();
     $Task = ClassRegistry::init('LilTasks.Task');
     $View = new View(null);
     $View->viewPath = 'Emails';
     $View->plugin = 'LilTasks';
     $View->layout = false;
     foreach ($users as $k => $user) {
         if ($tasks = $Task->find('all', array('conditions' => array('Task.completed' => null, 'Task.deadline <=' => strftime('%Y-%m-%d'), 'OR' => array(0 => array('Task.user_id' => $user['User']['id']), 1 => array('Task.user_id' => null), 2 => array('Task.user_id' => ''))), 'order' => array('Task.completed', 'Task.deadline DESC', 'Task.modified DESC'), 'recursive' => -1))) {
             if ($LilDate->isToday($tasks[0]['Task']['deadline'])) {
                 $View->viewVars = array('tasks' => $tasks);
                 $users[$k]['panels']['tasks']['title'] = __d('lil_tasks', 'Due tasks');
                 $users[$k]['panels']['tasks']['text'] = $View->render('text' . DS . 'notification_daily');
             }
         }
     }
     return $users;
 }