Example #1
0
 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 delete_selected()
 {
     if (!$this->checkParams('session_data_key')) {
         $this->dataError();
         sendBack();
     }
     $flash = Flash::Instance();
     $db = DB::Instance();
     $db->StartTrans();
     $errors = array();
     $session_data_key = $this->_data['session_data_key'];
     $page_data = new SessionData($session_data_key);
     foreach ($this->_data[$this->modeltype] as $id => $fields) {
         if (!isset($fields['select']) && isset($fields['_checkbox_exists_select'])) {
             $page_data->deletePageData($id);
         } else {
             $page_data->updatePageData($id, $fields, $errors);
         }
     }
     $data = $page_data->getPageData();
     // Could do with a progress bar here as the number of records could be large
     $delete_count = 0;
     if (count($data) > 0) {
         $progressBar = new Progressbar('soproductline_delete_unused');
         $callback = function ($fields, $id) use(&$delete_count) {
             if ($fields['select'] == 'on') {
                 $productline = DataObjectFactory::Factory('SOProductLine');
                 $productline->load($id);
                 if (!$productline->isLoaded() || !$productline->delete($id, $errors)) {
                     return FALSE;
                 }
                 $delete_count++;
             }
         };
         if ($progressBar->process($data, $callback) === FALSE) {
             $errors[] = 'Failed to delete product line';
         }
     } else {
         $flash->addWarning('Nothing selected to delete');
     }
     // reset timeout to 30 seconds to allow time to redisplay the page
     // hopefully, it will be quicker than this!
     set_time_limit(30);
     if (count($errors) > 0) {
         $flash->addErrors($errors);
         $flash->addError($db->ErrorMsg());
         $db->FailTrans();
         $db->CompleteTrans();
         $this->refresh();
     } else {
         $page_data->clear();
         $db->CompleteTrans();
         $flash->addMessage($delete_count . ' record' . get_plural_string($delete_count) . ' archived successfully');
         sendTo($this->name, 'unused', $this->_modules);
     }
 }