function populate() { $tickets = new TicketCollection(new Ticket()); $pl = new PageList('current_tickets'); $ticket_sh = new SearchHandler($tickets, false); $ticket_sh->setLimit(10); $ticket_sh->setOrderBy('created', 'ASC'); $user = new User(); $user->loadBy('username', EGS_USERNAME); $ticket_sh->addConstraint(new Constraint('originator_person_id', '=', $user->username)); $ticket_sh->addConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID)); // Find open statuses $statuses = new TicketStatusCollection(new TicketStatus()); $status_sh = new SearchHandler($statuses); $status_sh->addConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID)); $status_sh->addConstraint(new Constraint('status_code', '=', 'NEW'), 'OR'); $status_sh->addConstraint(new Constraint('status_code', '=', 'OPEN'), 'OR'); $statuses->load($status_sh); foreach ($statuses->getContents() as $status) { $ticket_sh->addConstraint(new Constraint('client_ticket_status_id', '=', $status->id), 'OR'); } $tickets->load($ticket_sh); $pl->addFromCollection($tickets, array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'view'), array('id'), 'ticket', 'summary'); $this->contents = $pl->getPages()->toArray(); }
function populate() { $pl = new PageList('companies_added_today'); $companies_do = new CompanyCollection(new Company()); $sh = new SearchHandler($companies_do, false); $sh->extract(); $sh->addConstraint(new Constraint('is_lead', '=', 'false')); $sh->addConstraint(new Constraint('created', '>', fix_date(date(DATE_FORMAT)))); $sh->setLimit(10); $companies_do->load($sh); $pl->addFromCollection($companies_do, array('module' => 'contacts', 'controller' => 'companys', 'action' => 'view'), array('id'), 'company', 'name'); $this->contents = $pl->getPages()->toArray(); }
function populate() { $pl = new PageList('open_opportunities'); $open_opportunities = new OpportunityCollection(new Opportunity()); $sh = new SearchHandler($open_opportunities, false); $sh->extract(); $sh->addConstraint(new Constraint('owner', '=', EGS_USERNAME)); $sh->addConstraint(new Constraint('open', '=', 'true')); $sh->setLimit(10); $sh->setOrderBy('cost', 'DESC'); $open_opportunities->load($sh); $pl->addFromCollection($open_opportunities, array('module' => 'crm', 'controller' => 'opportunitys', 'action' => 'view'), array('id'), 'opportunity', 'name'); $this->setData($pl->getPages()->toArray()); }
function populate() { $pl = new PageList('current_activities'); $current_activities = new ActivityCollection(new Activity()); $sh = new SearchHandler($current_activities, false); $sh->extract(); $sh->addConstraint(new Constraint('assigned', '=', EGS_USERNAME)); $sh->addConstraint(new Constraint('completed', 'IS', 'NULL')); $sh->addConstraint(new Constraint('startdate', '<', '(now())')); $sh->setLimit(10); $sh->setOrderBy('created', 'DESC'); $current_activities->load($sh); $pl->addFromCollection($current_activities, array('module' => 'crm', 'controller' => 'activitys', 'action' => 'view'), array('id'), 'activity', 'name'); $this->contents = $pl->getPages()->toArray(); }
function populate() { if (!$this->isCached()) { $pl = new PageList('recently_added_leads'); $companies_do = new CompanyCollection(new Company()); $sh = new SearchHandler($companies_do, false); $sh->extract(); $sh->addConstraint(new Constraint('is_lead', '=', 'true')); $sh->setLimit(10); $sh->setOrderBy('created', 'DESC'); $companies_do->load($sh); $pl->addFromCollection($companies_do, array('module' => 'contacts', 'controller' => 'companys', 'action' => 'view'), array('id'), 'company', 'name'); $this->setCache($pl->getPages()->toArray()); } $this->contents = $this->getCache(); }
function populate() { $pl = new PageList('my_tickets'); $my_tickets = new TicketCollection(new Ticket()); $sh = new SearchHandler($my_tickets, false); $sh->extract(); $sh->addConstraint(new Constraint('assigned_to', 'IS', 'NULL')); $cc = new ConstraintChain(); $cc->add(new Constraint('internal_status_code', '=', 'NEW'), 'OR'); $cc->add(new Constraint('internal_status_code', '=', 'OPEN'), 'OR'); $sh->addConstraintChain($cc); $sh->setLimit(10); $sh->setOrderBy('created', 'DESC'); $my_tickets->load($sh); $pl->addFromCollection($my_tickets, array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'view'), array('id'), 'ticket', 'summary'); $this->contents = $pl->getPages()->toArray(); }
function getYTD($ytd_periods, $print = false, $use_saved_search) { if (count($ytd_periods) > 0) { $sh = new SearchHandler($this, $use_saved_search); if ($print) { $sh->setLimit(0); } else { $sh->extract(); } $fields = array('centre||account', 'centre', 'account'); $sh->setOrderBy($fields); $fields = array_merge($fields, array('glcentre_id', 'glaccount_id')); $sh->setGroupBy($fields); $fields[] = 'sum(value) as value'; $sh->setFields($fields); $sh->addConstraint(new Constraint('glperiods_id', 'in', '(' . implode(',', $ytd_periods) . ')')); $this->load($sh); } }
public function reconcile() { if (!$this->loadData()) { $this->dataError(); sendBack(); } $account = $this->_uses[$this->modeltype]; $s_data = array(); $transactions = new CBTransactionCollection(new CBTransaction()); $sh = new SearchHandler($transactions, false); // $sh->extract(); $sh->setLimit(375); $sh->addConstraint(new Constraint('cb_account_id', '=', $this->_data['id'])); $sh->addConstraint(new Constraint('status', '=', 'N')); $sh->setOrderby(array('transaction_date', 'payment_type', 'reference', 'ext_reference')); parent::index($transactions, $sh); $this->view->set('num_records', $transactions->num_records); $this->view->set('num_pages', 1); $this->view->set('cur_page', 1); $this->view->set('transactions', $transactions); $this->view->set('CBAccount', $account); $this->view->set('clickcontroller', 'cbtransactions'); $this->view->set('clickaction', 'view'); }
public function viewTransactions() { $s_data = array(); if (isset($this->_data['id'])) { $id = $this->_data['id']; $s_data['whlocation_id'] = $id; } elseif (isset($this->_data['Search']['whlocation_id'])) { $id = $this->_data['Search']['whlocation_id']; $s_data['whlocation_id'] = $id; } if (isset($this->_data['stitem_id'])) { $s_data['stitem_id'] = $this->_data['stitem_id']; } elseif (isset($this->_data['Search']['stitem_id'])) { $s_data['stitem_id'] = $this->_data['Search']['stitem_id']; } if (!isset($this->_data['stitem_id'])) { $s_data['created']['from'] = date(DATE_FORMAT, strtotime('-7 days')); $s_data['created']['to'] = date(DATE_FORMAT); } $this->setSearch('whlocationsSearch', 'transactions', $s_data); $id = $this->search->getValue('whlocation_id'); $item = $this->search->getValue('stitem_id'); $showbalances = $this->search->getValue('balance'); $location = $this->_templateobject; $location->load($id); $this->view->set('location', $location); $sttransactions = new STTransactionCollection(); if (!isset($this->_data['orderby']) && !isset($this->_data['page'])) { $sh = new SearchHandler($sttransactions, FALSE); $cc = $this->search->toConstraintChain(); $sh->addConstraintChain($cc); } else { $sh = new SearchHandler($sttransactions); } $sh->extract(); if (isset($this->search) && ($this->isPrintDialog() || $this->isPrinting())) { if (!$this->isPrinting()) { return $this->printCollection(); } else { $sh->setLimit(0); $sttransactions->load($sh); return $this->printCollection($sttransactions); } } else { $sttransactions->load($sh); } $this->view->set('sttransactions', $sttransactions); $this->view->set('clickaction', 'view'); $this->view->set('clickcontroller', 'STItems'); $this->view->set('linkfield', 'id'); $this->view->set('linkvaluefield', 'stitem_id'); $this->view->set('num_records', $sttransactions->num_records); $this->view->set('num_pages', $sttransactions->num_pages); $this->view->set('cur_page', $sttransactions->cur_page); $this->view->set('no_ordering', TRUE); $sidebar = new SidebarController($this->view); $sidebarlist = array(); $sidebarlist['stores'] = array('tag' => 'All Stores', 'link' => array('modules' => $this->_modules, 'controller' => 'WHStores', 'action' => 'index')); $sidebarlist['locations'] = array('tag' => 'Locations for Store ' . $location->whstore, 'link' => array('modules' => $this->_modules, 'controller' => 'WHStores', 'action' => 'view', 'id' => $location->whstore_id)); $sidebarlist['thisLocation'] = array('tag' => 'Location Detail', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'view', 'id' => $location->id)); $sidebar->addList('Show', $sidebarlist); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); }
function getallids() { $personoverview = new PersonCollection($this->_templateobject); $sh = new SearchHandler($personoverview, false); $sh->AddConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID)); $sh->AddConstraint(new Constraint('usernameaccess', '=', EGS_USERNAME)); $sh->setLimit(1); $return = $personoverview->load($sh); echo json_encode($return); exit; }
public function view() { $option = $this->checkValidOption() or sendBack(); $modelname = $this->setup_options[$option]; $col_name = $modelname . 'Collection'; $model = DataObjectFactory::Factory($modelname); $collection = new $col_name(); $sh = new SearchHandler($collection, FALSE); $sh->extract(); $sh->setLimit(0); $collection->load($sh); $this->view->set('collection', $collection); $this->view->set('model', $model); $this->view->set('extrafields', $this->viewFields($option, $model)); $this->view->set('edit_extrafields', $this->newFields($option, $model)); if ($model->isField('position') || $model->isField('index')) { $this->view->set('orderable', TRUE); } // Set the Sidebar options $this->sidebar_options(); $this->setTemplateName('module_setup_view'); }
public function viewTransactions() { $s_data = array(); if (isset($this->_data['id'])) { $s_data['whbin_id'] = $id = $this->_data['id']; } elseif (isset($this->_data['Search']['whbin_id'])) { $s_data['whbin_id'] = $id = $this->_data['Search']['whbin_id']; } if (isset($this->_data['stitem_id'])) { $s_data['stitem_id'] = $this->_data['stitem_id']; } elseif (isset($this->_data['Search']['stitem_id'])) { $s_data['stitem_id'] = $this->_data['Search']['stitem_id']; } if (!isset($this->_data['stitem_id'])) { $s_data['created']['from'] = date(DATE_FORMAT, strtotime('-7 days')); $s_data['created']['to'] = date(DATE_FORMAT); } $this->setSearch('whbinsSearch', 'transactions', $s_data); $id = $this->search->getValue('whbin_id'); $item = $this->search->getValue('stitem_id'); $showbalances = $this->search->getValue('balance'); $bin = $this->_templateobject; $bin->load($id); $this->view->set('bin', $bin); $sttransactions = new STTransactionCollection(); if (!isset($this->_data['orderby']) && !isset($this->_data['page'])) { $sh = new SearchHandler($sttransactions, false); $cc = $this->search->toConstraintChain(); $sh->addConstraintChain($cc); } else { $sh = new SearchHandler($sttransactions); } $sh->extract(); if (isset($this->search) && ($this->isPrintDialog() || $this->isPrinting())) { if (!$this->isPrinting()) { return $this->printCollection(); } else { $sh->setLimit(0); $sttransactions->load($sh); return $this->printCollection($sttransactions); } } else { $sttransactions->load($sh); } $this->view->set('sttransactions', $sttransactions); $this->view->set('clickaction', 'view'); $this->view->set('clickcontroller', 'STItems'); $this->view->set('linkfield', 'id'); $this->view->set('linkvaluefield', 'stitem_id'); $this->view->set('num_pages', $sttransactions->num_pages); $this->view->set('cur_page', $sttransactions->cur_page); $this->view->set('no_ordering', true); $this->view->set('page_title', $this->getPageName('', 'View Transactions for')); $sidebar = new SidebarController($this->view); $whlocation = $this->getLocation($bin->whlocation_id); $sidebarlist = $this->setGeneralSidebar($whlocation, $bin); $sidebar->addList('Show', $sidebarlist); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); }
function getOrderItemSummary($period, $type = '', $page = '', $perpage = '') { $sh = new SearchHandler($this, false); if ($type != '') { $sh->addConstraint(new Constraint('type', '=', $type)); } if (!empty($page)) { if (empty($perpage)) { $perpage = 9; } $sh->setLimit($perpage, ($page - 1) * $perpage); $sh->perpage = $perpage; } $fields = array('stitem'); $sh->setGroupBy($fields); $sh->setOrderby($fields); $fields[] = 'sum(os_qty) as qty'; $fields[] = 'sum(base_net_value) as value'; $sh->setFields($fields); $sh->addConstraint(new Constraint('status', 'in', "('N', 'R', 'S')")); $today = fix_date(date(DATE_FORMAT)); $currentmonthstart = fix_date('01/' . date('m/Y')); switch (prettify($period)) { case 'Overdue': $startdate = fix_date('01/01/1970'); $enddate = fix_date(date(DATE_FORMAT, strtotime("-1 day", strtotime($today)))); break; case 'Today': $startdate = $today; $enddate = $today; break; case 'This Week': $startdate = fix_date(date(DATE_FORMAT, strtotime("+1 days", strtotime($today)))); $enddate = fix_date(date(DATE_FORMAT, strtotime("-1 day", strtotime("next Monday", strtotime($today))))); break; case 'This Month': $startdate = fix_date(date(DATE_FORMAT, strtotime("next Monday", strtotime($today)))); $enddate = fix_date(date(DATE_FORMAT, strtotime("-1 day", strtotime("+1 months", strtotime($currentmonthstart))))); break; case 'Next Month': $startdate = fix_date(date(DATE_FORMAT, strtotime("+1 months", strtotime($currentmonthstart)))); $enddate = fix_date(date(DATE_FORMAT, strtotime("-1 day", strtotime("+2 months", strtotime($currentmonthstart))))); break; } $sh->addConstraint(new Constraint('due_despatch_date', 'between', "'" . $startdate . "' and '" . $enddate . "'")); $this->load($sh); // Construct dynamic title ('Orders', 'Quotes', default) if ($type == 'O') { $this->customersales = array('title' => 'Orders, ' . prettify($period), 'items' => array()); } elseif ($type == 'Q') { $this->customersales = array('title' => 'Quotes, ' . prettify($period), 'items' => array()); } else { $this->customersales = array('title' => prettify($period), 'items' => array()); } foreach ($this as $order) { $this->customersales['items'][$order->id]['value'] = $order->value; $this->customersales['items'][$order->id]['qty'] = $order->qty; } $this->customersales['page'] = $page; $this->customersales['perpage'] = $perpage; $this->customersales['num_pages'] = $this->num_pages == 0 ? 1 : $this->num_pages; $this->customersales['period'] = $period; $this->customersales['type'] = $type; $this->customersales['controller'] = 'Sorders'; return $this->customersales; }
public function viewAwaitingDelivery() { $s_data = array(); // Set context from calling module if (isset($this->_data['plmaster_id'])) { $s_data['plmaster_id'] = $this->_data['plmaster_id']; } if (isset($this->_data['stitem_id'])) { $s_data['stitem_id'] = $this->_data['stitem_id']; } if (isset($this->_data['order_id'])) { $s_data['order_id'] = $this->_data['order_id']; } $this->setSearch('pogoodsreceivedSearch', 'confirmReceipt', $s_data); $s_data['plmaster_id'] = $this->search->getValue('plmaster_id'); $s_data['stitem_id'] = $this->search->getValue('stitem_id'); $s_data['order_id'] = $this->search->getValue('order_id'); $orderlines = new POrderLineCollection(DataObjectFactory::Factory('POrderLine')); if ($s_data['plmaster_id'] > 0 || $s_data['stitem_id'] > 0 || $s_data['order_id'] > 0) { if (isset($this->_data['orderby'])) { $sh = new SearchHandler($orderlines, true); } else { $sh = new SearchHandler($orderlines, false); } $sh->extract(); $sh->setLimit(''); $sh->addConstraint(new Constraint('status', 'in', "('A','P')")); if ($s_data['plmaster_id'] > 0) { $sh->addConstraint(new Constraint('plmaster_id', '=', $s_data['plmaster_id'])); } if ($s_data['stitem_id'] > 0) { $sh->addConstraint(new Constraint('stitem_id', '=', $s_data['stitem_id'])); } if ($s_data['order_id'] > 0) { $sh->addConstraint(new Constraint('order_id', '=', $s_data['order_id'])); } $DisplayFields = array('id'); foreach ($orderlines->getFields() as $field => $attr) { if (!$attr->ignoreField) { $DisplayFields[] = $field; } } $DisplayFields[] = 'receive_action'; $sh->setFields($DisplayFields); $orderlines->load($sh); $this->view->set('num_records', $orderlines->num_records); foreach ($orderlines as $orderline) { $orderline->getAction(); $orderline->whaction_id = $orderline->receive_action; $orderline->from_location_id = $orderline->getFromLocation($orderline->receive_action); $orderline->to_location_id = $orderline->getToLocation($orderline->receive_action); $whlocation = DataObjectFactory::Factory('WHLocation'); $whlocation->load($orderline->to_location_id); if ($whlocation->isLoaded()) { $orderline->to_location = $whlocation->whstore . '/' . $whlocation->description; } else { $orderline->to_location = ''; } $orderline->to_bin_list = $orderline->getToBin($orderline->receive_action); } } $this->_templateName = $this->getTemplateName('confirmreceipt'); $this->view->set('porderlines', $orderlines); $sidebar = new SidebarController($this->view); $actions = array(); $actions['viewnotes'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'index'), 'tag' => 'view goods received notes'); $sidebar->addList('Actions', $actions); $this->view->set('page_title', $this->getPageName('Confirm Delivery of Order', '')); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); // Override output button - there is no point to it here $this->printaction = ''; }
public function detail() { $errors = array(); $s_data = $this->setSearch(); $constrain = FALSE; $fields = array('slmaster_id', 'product_group', 'cs_failurecode_id', 'start', 'end'); // if failure code is 'any' remove it from the search, we've got other criteria to search by... if (isset($this->_data['cs_failurecode_id']) && strtolower($this->_data['cs_failurecode_id']) === 'any') { // don't let the standard search do anything with the cs_failurecode_id field unset($s_data['cs_failurecode_id']); $constrain = TRUE; // constrain where failure code has not been set... $cc1 = new ConstraintChain(); $cc1->add(new Constraint('cs_failurecode_id', 'IS', 'NULL')); // and another constraint chain for the failed order $cc2 = new ConstraintChain(); $cc2->add(new Constraint('despatch_date', '>', '(due_despatch_date)')); $cc2->add(new Constraint('order_qty', '>', '(despatch_qty)'), 'OR'); } $customerservice = new CustomerServiceCollection($this->_templateobject); if (!isset($this->_data['orderby']) && !isset($this->_data['page']) && !($this->isPrintDialog() || $this->isPrinting())) { $sh = $customerservice->setSearch($s_data, false); $sh->setOrderby(array('product_group', 'customer', 'order_number', 'due_despatch_date'), array('ASC', 'ASC', 'DESC', 'DESC')); } else { // $sh = $customerservice->setSearch($s_data, TRUE); // echo '$s_data<pre>'.print_r($s_data, true).'</pre><br>'; $sh = new SearchHandler($customerservice, TRUE); } $this->search = customerServicesSearch::useDefault($s_data, $errors, $customerservice); if (count($errors) > 0) { $flash = Flash::Instance(); $flash->addErrors($errors); $this->search->clear(); } if (isset($this->search) && !isset($this->_data['ajax_print']) && !isset($this->_data['orderby']) && !isset($this->_data['page'])) { // cache the search string $search_string_array = array('fop' => $this->search->toString('fop'), 'html' => $this->search->toString('html')); $_SESSION['search_strings'][EGS_USERNAME][$sh->search_id] = $search_string_array; } if ($constrain === TRUE) { // add the two constraint chains seperately $sh->addConstraintChain($cc1); $sh->addConstraintChain($cc2); } $sh->extractOrdering(); $sh->setFields(array('id', 'product_group', 'customer', 'stitem', 'order_number', 'despatch_number', 'due_despatch_date', 'despatch_date', 'order_qty', 'despatch_qty', 'failurecode', 'cs_failurecode_id', 'cs_failure_note')); if (isset($this->search) && ($this->isPrintDialog() || $this->isPrinting())) { $sh->setLimit(0); $customerservice->load($sh); return parent::printCollection($customerservice); } else { $sh->extractPaging(); $customerservice->load($sh); } $this->view->set('num_records', $customerservice->num_records); $this->view->set('num_pages', $customerservice->num_pages); $this->view->set('cur_page', $customerservice->cur_page); $this->view->set(strtolower($customerservice->getModelName()) . 's', $customerservice); $sidebar = new SidebarController($this->view); $sidebar->addList('Actions', array('all' => array('link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'index')), 'tag' => 'Customer Service Summary'), 'failurecodes' => array('link' => array_merge($this->_modules, array('controller' => 'csfailurecodes', 'action' => 'index')), 'tag' => 'View Failure Codes'))); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); }
/** * fills a collection of the specified model type with the fields specified, * also gives correct click controller, action and edit handlers so * that smarty datatable will work correctly. * finally outputs specified smarty variable as the collection for * datatable to use * used for alternate controller to display specific contents of a different * controller */ public function fillCollection($modelname, $fields, $constraints, $clickcontroller, $clickaction, $editclickaction, $deletecontroller, $smartyname, $tablename = null, $deleteaction = null, $newtext = null, $limit = null, $orderdir = null, $offset = null) { $collectionname = $modelname . 'Collection'; $collection = new $collectionname(); $sh = new SearchHandler($collection); $sh->fields = $fields; $sh->constraints = $constraints; $sh->extractOrdering(); $sh->extractPaging(); $sh->perpage = 900000; if (isset($orderdir)) { $sh->orderdir = $orderdir; } if (isset($limit) && isset($offset)) { $sh->setLimit($limit, $offset); } if (isset($tablename)) { $collection->_tablename = $tablename; } $collection->load($sh); $collection->clickcontroller = $clickcontroller; $collection->clickaction = $clickaction; $collection->editclickaction = $editclickaction; $collection->deletecontroller = $deletecontroller; if (isset($deleteaction)) { $collection->deleteclickaction = $deleteaction; } if (isset($newtext)) { $collection->newtext = $newtext; } $this->view->set($smartyname, $collection); }