public function outstanding_transactions() { if (!$this->loadData()) { $this->dataError(); sendBack(); } $customer = $this->_uses[$this->modeltype]; $category = DataObjectFactory::Factory('LedgerCategory'); $categories = $category->checkCompanyUsage($customer->company_id); // Check for Sales Ledger account and Contra Control account $glparams = DataObjectFactory::Factory('GLParams'); // Does this SL Customer also have a PL Supplier account // and does the Contras Control Account also exist // if so, then allow contras $can_contra = isset($categories['PL']['exists']) && $categories['PL']['exists'] && $glparams->contras_control_account() != FALSE; $this->view->set('can_contra', $can_contra); $transaction = DataObjectFactory::Factory('SLTransaction'); $transactions = new SLTransactionCollection($transaction); $db = DB::Instance(); $sh = $this->setSearchHandler($transactions); $sh->addConstraint(new Constraint('status', 'in', '(' . $db->qstr($transaction->open()) . ',' . $db->qstr($transaction->partPaid()) . ')')); $sh->addConstraint(new Constraint('slmaster_id', '=', $customer->id)); parent::index($transactions, $sh); if ($can_contra) { // create session object to handle paged data input $contras_sessionobject = new SessionData('sl_contras'); if (!$contras_sessionobject->PageDataExists()) { // session object does not exist so register it $contras_sessionobject->registerPageData(array('os_value', 'contra')); } // Check for form input due to paging or ordering if (isset($this->_data['SLTransaction'])) { foreach ($this->_data['SLTransaction'] as $id => $fields) { if ($fields['contra'] == 'on') { $contras_sessionobject->updatePageData($id, $fields, $errors); } else { $contras_sessionobject->deletePageData($id); } } } $contras_data = $contras_sessionobject->getPageData($errors); $contra_total = 0; foreach ($contras_data as $value) { if (isset($value['contra']) && $value['contra']) { $contra_total += $value['os_value']; } } $this->view->set('contra_total', $contra_total); $this->view->set('page_data', $contras_data); } $this->view->set('ledger_account', $customer); $this->view->set('collection', $transactions); $this->view->set('clickaction', 'view'); $this->view->set('clickcontroller', 'sltransactions'); $this->view->set('invoice_module', 'sales_invoicing'); $this->view->set('invoice_controller', 'sinvoices'); $this->_templateName = $this->getTemplateName('view_ledger_trans'); }
public function unused() { $errors = array(); $s_data = array(); if (!isset($this->_data['session_data_key'])) { // session is not set so this is the first entry $this->_data['session_data_key'] = get_class($this->_templateobject) . '-delete-unused'; $page_data = new SessionData($this->_data['session_data_key']); $page_data->registerPageData(array('select')); } else { $page_data = new SessionData($this->_data['session_data_key']); } // Update page data if paging if (isset($this->_data[$this->modeltype]) && (isset($this->_data['page']) || isset($this->_data['orderby']))) { foreach ($this->_data[$this->modeltype] as $id => $fields) { if ($fields['select'] == 'on') { $page_data->updatePageData($id, $fields, $errors); } else { $page_data->deletePageData($id); } } } $data = $page_data->getPageData(); // Set context from calling module $this->setSearch('productlinesSearch', 'customerDefault', $s_data); $productlines = new SOProductlineCollection($this->_templateobject); $sh = $this->setSearchHandler($productlines); if (count($errors) > 0) { $flash = Flash::Instance(); $flash->addErrors($errors); sendback(); } $sh->addConstraint(new Constraint('not exists', '', '(select 1 from so_lines where productline_id=so_productlines_overview.id)')); $sh->addConstraint(new Constraint('not exists', '', '(select 1 from si_lines where productline_id=so_productlines_overview.id)')); parent::index($productlines, $sh); if (isset($this->_data['select_all'])) { if (count($data) > 0) { $page_data->clearPageData(); } else { $productline = DataObjectFactory::Factory($this->modeltype, 'so_productlines_overview'); // We already have the constraints from above in the search handler $cc = $sh->constraints; // Just need to get the ids foreach ($productline->getAll($cc) as $id => $productline) { $page_data->updatePageData($id, array('select' => 'on'), $errors); } } $data = $page_data->getPageData(); } $sidebar = new SidebarController($this->view); $actions = array(); $actions['all_products'] = array('link' => array('modules' => $this->_modules, 'controller' => 'soproductlineheaders', 'action' => 'index'), 'tag' => 'view all products'); $actions['all_lines'] = array('link' => array('modules' => $this->_modules, 'controller' => 'soproductlines', 'action' => 'index'), 'tag' => 'view all lines'); $sidebar->addList('Actions', $actions); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); $this->view->set('collection', $productlines); $this->view->set('clickaction', 'view_so_product'); $this->view->set('linkfield', 'productline_header_id'); $this->view->set('linkvaluefield', 'productline_header_id'); // set the generic variables for the paging_select template $this->view->set('session_data_key', $this->_data['session_data_key']); $this->view->set('selected', $data); $this->view->set('count_selected', count($data)); if (count($data) > 0) { $this->view->set('select_all_text', 'Clear All'); } else { $this->view->set('select_all_text', 'Select All'); } $this->view->set('submit_text', 'Delete Selected'); $this->view->set('form_action', 'delete_selected'); $this->setTemplateName('paging_select'); }