public function summary_report() { $users = array(); if (isModuleAdmin()) { $u = DataObjectFactory::Factory('User'); $users = $u->getAll(); } $this->view->set('users', $users); if (isset($this->_data['filter'])) { $cc = new ConstraintChain(); if (!empty($this->_data['from_date'])) { $cc->add(new Constraint('enddate', '>', fix_date($this->_data['from_date']))); } if (!empty($this->_data['to_date'])) { $cc->add(new Constraint('enddate', '<', fix_date($this->_data['to_date']))); } if (!isModuleAdmin()) { $cc->add(new Constraint('assigned', '=' . EGS_USERNAME)); } elseif (!empty($this->_data['assigned'])) { $cc->add(new Constraint('assigned', '=', $this->_data['assigned'])); } $opp_sh = new SearchHandler(new OpportunityCollection($this->_templateobject), false); $opp_sh->addConstraintChain($cc); $opp_sh->extract(); $os = DataObjectFactory::Factory('Opportunitystatus'); $os->addSearchHandler('opportunities', $opp_sh); $statuses = new OpportunitystatusCollection($os); $sh = new SearchHandler($statuses, false); $sh->extract(); $statuses->load($sh); $this->view->set('statuses', $statuses); $this->view->set('report_headings', array('name', 'company', 'person', 'enddate', 'type', 'cost', 'assigned')); $this->view->set('cc', $cc); } }
public function view() { if (!$this->loadData()) { $this->dataError(); sendBack(); } $transaction = $this->_uses[$this->modeltype]; $id = $transaction->id; $this->view->set('transaction', $transaction); $elements = new WHTransferruleCollection(new WHTransferrule()); $sh = new SearchHandler($elements, false); $sh->extract(); $sh->addConstraint(new Constraint('whaction_id', '=', $id)); $sh->extractOrdering(); $sh->extractPaging(); $elements->load($sh); $this->view->set('elements', $elements); $sidebar = new SidebarController($this->view); $sidebar->addList('Show', array('all' => array('tag' => 'All Actions', 'link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'index'))), 'locations' => array('tag' => 'All Stores', 'link' => array_merge($this->_modules, array('controller' => 'WHStores', 'action' => 'index'))))); $sidebarlist = array(); $sidebarlist['edit'] = array('tag' => 'Edit', 'link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'edit', 'id' => $id))); $sidebarlist['delete'] = array('tag' => 'Delete', 'link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'delete', 'id' => $id))); if (is_null($transaction->max_rules) || $elements->count() < $transaction->max_rules) { $sidebarlist['Add'] = array('tag' => 'Add Rule', 'link' => array_merge($this->_modules, array('controller' => 'WHTransferrules', 'action' => 'new', 'whaction_id' => $id))); } $sidebar->addList('This Action', $sidebarlist); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); $this->view->set('clickaction', 'view'); $this->view->set('clickcontroller', 'WHTransferrules'); $this->view->set('no_ordering', true); }
public function _new() { parent::_new(); // For new actions the stitem_id and from_uom_id will be set // For edit actions, the id will be set pointing to the uom conversion to be edited if ($this->_data['action'] == 'edit') { $stuom = $this->_uses[$this->modeltype]; $stitem_id = $stuom->stitem_id; $stitem_uom_id = $stuom->from_uom_id; $stitem_uom_name = $stuom->from_uom_name; } else { $stitem = new STitem(); $stitem->load($this->_data['stitem_id']); $stitem_id = $stitem->id; $stitem_uom_id = $stitem->uom_id; $stitem_uom_name = $stitem->uom_name; } $this->view->set('stitem_id', $stitem_id); $this->view->set('stitem_uom_id', $stitem_uom_id); $this->view->set('stitem_uom_name', $stitem_uom_name); $this->view->set('stitem', Stuomconversion::getStockItem($stitem_id)); $elements = new STuomconversionCollection(new STuomconversion()); $sh = new SearchHandler($elements, false); $sh->extract(); $sh->addConstraint(new Constraint('stitem_id', '=', $stitem_id)); $sh->setOrderBy('from_uom_name'); $sh->extractOrdering(); $sh->extractPaging(); $elements->load($sh); $this->view->set('elements', $elements); $this->view->set('no_ordering', true); }
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(); }
public function index() { $moduleobjects = new ModuleObjectCollection($this->_templateobject); $sh = new SearchHandler($moduleobjects, false); $sh->extract(); parent::index(new ModuleObjectCollection($this->_templateobject), $sh); $this->view->set('clickaction', 'view'); $sidebar = new SidebarController($this->view); $sidebarlist['new'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'new'), 'tag' => 'New'); $sidebar->addList('Actions', $sidebarlist); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); }
public function view() { $id = $this->_data['id']; global $smarty; $this->view->set('clickaction', 'viewuser'); $collection = new HasRoleCollection($this->_templateobject); $sh = new SearchHandler($collection); $sh->extract(); $sh->addConstraint(new Constraint('roleid', '=', $id)); $collection->load($sh); $this->view->set(strtolower($collection->getModelName()) . 's', $collection); $this->view->set('num_pages', $collection->num_pages); $this->view->set('cur_page', $collection->cur_page); }
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(); }
public function index() { $collection = new TicketCollection($this->_templateobject); $sh = new SearchHandler($collection, false); $sh->extract(); $sh->setFields(array('id' => 'id', 'summary' => 'summary', 'originator_person' => 'originator_person', 'client_ticket_status' => 'client_ticket_status', 'client_ticket_priority' => 'client_ticket_priority', 'client_ticket_severity' => 'client_ticket_severity', 'created' => 'created', 'lastupdated' => 'lastupdated')); $this->setSearch('TicketsSearch', 'useClient'); parent::index($collection, $sh); $this->view->set('no_delete', true); $this->view->set('clickaction', 'view'); $sidebar = new SidebarController($this->view); $sidebar->addList('Actions', array('new' => array('link' => array('module' => 'ticketing', 'controller' => 'client', 'action' => 'new'), 'tag' => 'New Ticket'))); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); }
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(); }
public function showclicks() { $clicks = new NewsletterurlclickCollection(new Newsletterurlclick()); $sh = new SearchHandler($clicks, false); $sh->extract(); $sh->addConstraint(new Constraint('newsletter_id', '=', $this->_data['newsletter_id'])); if (isset($sh->fields['newsletter'])) { unset($sh->fields['newsletter']); } $clicks->load($sh); $this->setTemplateName('view_related'); $this->view->set('clickaction', 'viewperson'); $this->view->set('paging_link', array('module' => 'crm', 'controller' => 'newsletters', 'action' => 'showclicks', 'newsletter_id' => $this->_data['newsletter_id'])); $this->view->set('no_ordering', true); $this->view->set('related_collection', $clicks); $this->view->set('num_pages', $clicks->num_pages); $this->view->set('cur_page', $clicks->cur_page); }
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 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 view_my_expenses() { $flash = Flash::Instance(); $employee_id = $this->get_employee_id(); if (!empty($employee_id)) { $this->_templateName = $this->getTemplateName('index'); $errors = array(); $s_data = array(); // Set context from calling module $this->setSearch('expenseSearch', 'myExpenses', $s_data); unset($this->_templateobject->defaultDisplayFields['person']); $he = new ExpenseCollection($this->_templateobject); $sh = new SearchHandler($he, false); $sh->extract(); $sh->addConstraint(new Constraint('employee_id', '=', $employee_id)); parent::index($he, $sh); $sidebarlist = array(); $sidebarlist['new'] = array('tag' => 'New', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'new', 'employee_id' => $employee_id)); $sidebar = new SidebarController($this->view); $sidebar->addList('actions', $sidebarlist); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); $this->view->set('clickaction', 'view'); } else { $flash->addError('You have not been set up as an employee'); sendBack(); } }
public function view() { if (!$this->loadData()) { $this->dataError(); sendBack(); } $transaction = $this->_uses[$this->modeltype]; $id = $transaction->id; $this->view->set('transaction', $transaction); $elements = new MFOperationCollection(new MFOperation()); if (!isset($this->_data['orderby']) && !isset($this->_data['page'])) { $sh = new SearchHandler($elements, false); $sh->addConstraint(new Constraint('mfresource_id', '=', $id)); } else { $sh = new SearchHandler($elements); } $sh->extract(); parent::index($elements, $sh); $sidebar = new SidebarController($this->view); $sidebarlist = array(); $sidebarlist['view'] = array('tag' => 'View all resources', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'index')); $sidebarlist['edit'] = array('tag' => 'Edit', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'edit', 'id' => $id)); if ($elements->count() == 0) { $sidebarlist['delete'] = array('tag' => 'Delete', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'delete', 'id' => $id)); } $sidebar->addList('This Resource', $sidebarlist); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); }
public function select_products() { $s_data = array(); // so set context from calling module if (isset($this->_data['slmaster_id'])) { $s_data['slmaster_id'] = $this->_data['slmaster_id']; } if (isset($this->_data['parent_id'])) { $s_data['parent_id'] = $this->_data['parent_id']; } $this->setSearch('sordersSearch', 'selectProduct', $s_data); $slmaster_id = $this->search->getValue('slmaster_id'); $this->view->set('slmaster_id', $slmaster_id); $slcustomer = DataObjectFactory::Factory('SLCustomer'); if ($slmaster_id > 0) { $slcustomer->load($slmaster_id); } // Get the list of Product Headers for the selected item $product_ids = SelectorCollection::getTargets('sales_order', $this->search->getValue('parent_id')); $product = DataObjectFactory::Factory('SOProductLine'); $product->identifierField = 'productline_header_id'; $cc = new ConstraintChain(); $customer_lines = array(); if ($slcustomer->isLoaded()) { // Get any lines specific for this customer $this->view->set('slcustomer', $slcustomer->companydetail->name); $cc1 = new ConstraintChain(); $cc1->add(new Constraint('slmaster_id', '=', $slcustomer->id)); if (is_null($slcustomer->so_price_type_id)) { $cc1->add(new Constraint('so_price_type_id', 'is', 'NULL')); $cc->add(new Constraint('so_price_type_id', 'is', 'NULL')); } else { $cc1->add(new Constraint('so_price_type_id', '=', $slcustomer->so_price_type_id)); $cc->add(new Constraint('so_price_type_id', '=', $slcustomer->so_price_type_id)); } $cc1->add($product->currentConstraint()); if (!empty($product_ids)) { $cc1->add(new Constraint('productline_header_id', 'in', '(' . implode(',', array_keys($product_ids)) . ')')); } else { $cc1->add(new Constraint('productline_header_id', '=', '-1')); } $customer_lines = $product->getAll($cc1, true, true); // Now exclude any lines for a header where the line for the customer exists if (count($customer_lines) > 0) { $cc->add(new Constraint('productline_header_id', 'not in', '(' . implode(',', $customer_lines) . ')')); } } else { $this->view->set('slcustomer', 'Not Set'); } // Get the non-customer lines, excluding any lines for a header found above for a customer $cc->add(new Constraint('slmaster_id', 'is', 'NULL')); if (!empty($product_ids)) { $cc->add(new Constraint('productline_header_id', 'in', '(' . implode(',', array_keys($product_ids)) . ')')); } else { $cc->add(new Constraint('productline_header_id', '=', '-1')); } $cc->add($product->currentConstraint()); $lines = $product->getAll($cc, true, true); $lines += $customer_lines; $products = new SOProductLineCollection($product); if (!isset($this->_data['orderby']) && !isset($this->_data['page'])) { $sh = new SearchHandler($products, false); $cc2 = new ConstraintChain(); if (count($lines) > 0) { $cc2->add(new Constraint('id', 'in', '(' . implode(',', array_keys($lines)) . ')')); } else { // No lines found, so ensure no rows returned $cc2->add(new Constraint('id', '=', -1)); } $sh->addConstraint($cc2); } else { $sh = new SearchHandler($products); } $sh->extract(); $fields = array('id', 'description', 'price', 'currency', 'uom_name', 'so_price_type', 'stitem_id', 'slmaster_id', 'prod_group_id'); $sh->setFields($fields); $sh->setGroupby($fields); $sh->setOrderby(array('description', 'so_price_type')); parent::index($products, $sh); $this->view->set('stitem', DataObjectFactory::Factory('STItem')); if (empty($this->_data['sorders'])) { $this->_data['sorders'] = array(); } $this->view->set('selected', $this->_data['sorders']); foreach ($this->_modules as $key => $value) { $modules[] = $key . '=' . $value; } $link = implode('&', $modules) . '&controller=' . $this->name . '&action=showProducts'; $this->view->set('link', $link); $selectedproduct = empty($_SESSION['selectedproducts']) ? array() : $_SESSION['selectedproducts']; $selectedproducts = new SOProductLineCollection(DataObjectFactory::Factory('SOProductLine')); if (!empty($selectedproduct)) { $sh = new SearchHandler($selectedproducts, false); $sh->addConstraint(new Constraint('id', 'in', '(' . implode(',', array_keys($selectedproduct)) . ')')); $selectedproducts->load($sh); } $this->view->set('selected', $selectedproduct); $this->view->set('productlines', $selectedproducts); $this->view->set('page_title', $this->getPageName('', 'Select Products for')); }
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 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); }
/** * Allows for the getting of the values of DB-fields * (potentially over-ridden by child-classes as a way to modify public variables?) * * @return mixed The value of the corresponding field * * @todo need to use this method for lazy-loading of relationships */ public function __get($var) { $this->debug('DataObject(' . get_class($this) . ')::__get field ' . $var); // echo 'DataObject('.get_class($this).')::__get field '.$var.'<br>'; $var = strtolower($var); if ($this->isField($var, 1)) { if (is_string($this->_fields[$var])) { return $this->_fields[$var]; } $attempt = $this->_fields[$var]->value; if (!empty($attempt) || $attempt === 0 || $attempt === '0') { return $attempt; } } if ($var == $this->parent_relname) { $p_name = get_class($this); $parent_model = DataObjectFactory::Factory($p_name); $parent_id = $this->getParent(); $parent_model->load($parent_id); $parent = $parent_model->{$this->getIdentifier()}; return $parent; } if (isset($this->isCached[$var])) { return $this->isCached[$var]; } if (isset($this->aliases[$var])) { $model = DataObjectFactory::Factory($this->aliases[$var]['modelName']); $fkvalue = $this->subClass ? $this->{$this->fkField} : $this->{$this->idField}; // $fkvalue=$this->{$this->idField}; if (!is_null($fkvalue)) { $cc = $this->aliases[$var]['constraints']; $fkfield = empty($this->aliases[$var]['fkfield']) ? get_class($this) . '_id' : $this->aliases[$var]['fkfield']; if ($cc instanceof SearchHandler) { $cc->addConstraint(new Constraint($fkfield, '=', $fkvalue)); } else { $cc->add(new Constraint($fkfield, '=', $fkvalue)); } $model->loadby($cc); $this->isCached[$var] = $model; } return $model; } // if(isset($this->compositesField[$var])) { // $model=new $this->composites[$this->compositesField[$var]]['modelName']; // $model->load($this->{$this->composites[$this->compositesField[$var]]['field']}); // return $model->$var; // } if (isset($this->composites[$var])) { $model = DataObjectFactory::Factory($this->composites[$var]['modelName']); $model->load($this->{$this->composites[$var]['field']}); $this->isCached[$var] = $model; return $model; } if (isset($this->concatenations[$var])) { $string = ''; foreach ($this->concatenations[$var]['fields'] as $fieldname) { // $string.=$this->$fieldname.' '; $s = $this->{$fieldname}; if (!empty($s)) { $string .= $this->{$fieldname} . $this->concatenations[$var]['separator']; } } return $string; } if (isset($this->hasManyThrough[$var])) { $jo = $this->hasManyThrough[$var]['jo']; $collectionname = $jo . 'Collection'; $collection = new $collectionname(DataObjectFactory::Factory($jo)); if (!isset($handlers[$var])) { $sh = new SearchHandler($collection, FALSE); $sh->extract(); } else { $sh = $handlers[$var]; } unset($sh->fields[strtolower(get_class($this))]); unset($sh->fields[strtolower(get_class($this)) . '_id']); $sh->addConstraint(new Constraint(get_class($this) . '_id', '=', $this->{$this->idField})); $collection->load($sh); return $collection; } if (isset($this->habtm[$var])) { $db = DB::Instance(); $r_model = DataObjectFactory::Factory($this->habtm[$var]['model']); $a = strtolower(get_class($this)) . '_id'; $b = strtolower($this->habtm[$var]['model']) . '_id'; $query = 'SELECT remote.* FROM ' . $this->_tablename . ' AS local JOIN ' . $this->habtm[$var]['table'] . ' AS middle ON (local.' . $this->idField . '=middle.' . $a . ') JOIN ' . $r_model->_tablename . ' AS remote ON (middle.' . $b . '=remote.' . $r_model->idField . ') WHERE local.' . $this->idField . '=' . $db->qstr($this->{$this->idField}); $c_query = str_replace('remote.*', 'count(*)', $query); $c_name = $this->habtm[$var]['model'] . 'Collection'; $collection = new $c_name($r_model); $collection->load($query, $c_query); $this->isCached[$var] = $collection; return $collection; } if (isset($this->hasMany[$var])) { $do = $this->hasMany[$var]['do']; $collectionname = $do . 'Collection'; $collection = new $collectionname(DataObjectFactory::Factory($do)); if (!$this->isLoaded()) { return $collection; } $handlers = $this->searchHandlers; if (!isset($handlers[$var])) { $sh = new SearchHandler($collection, FALSE); } else { $sh = $handlers[$var]; } unset($sh->fields[strtolower(get_class($this))]); unset($sh->fields[strtolower(get_class($this)) . '_id']); if (is_array($this->hasMany[$var]['fkfield'])) { foreach ($this->hasMany[$var]['fkfield'] as $index => $fkfield) { $sh->addConstraint(new Constraint($fkfield, '=', $this->{$this->hasMany[$var]['field'][$index]})); } } elseif (!is_array($this->hasMany[$var]['field'])) { $sh->addConstraint(new Constraint($this->hasMany[$var]['fkfield'], '=', $this->{$this->hasMany[$var]['field']})); } $collection->load($sh); $this->isCached[$var] = $collection; return $collection; } if (isset($this->hasOne[$var])) { $field = $this->hasOne[$var]['field']; $fkfield = $this->hasOne[$var]['fkfield']; if (isset($this->hasOne[$var]['cached'])) { if (is_null($fkfield)) { $id = $this->hasOne[$var]['cached']->idField; } else { $id = $fkfield; } if ($this->hasOne[$var]['cached']->{$id} == $this->{$field}) { // return the cached object as it hasn't changed return $this->hasOne[$var]['cached']; } } // no cached object or cached object has changed $model = DataObjectFactory::Factory($this->hasOne[$var]['model']); if (is_null($fkfield)) { $model->load($this->{$field}); } else { $model->loadBy($fkfield, $this->{$field}); } $this->hasOne[$var]['cached'] = $model; return $model; } if (isset($this->belongsTo[$var])) { $fields = $this->_fields; if (isset($fields[$var])) { $value = $this->_fields[$var]->value; } if (empty($value)) { $model = DataObjectFactory::Factory($this->belongsTo[$var]['model']); // Remove any policies to ensure the FK can be resolved to get the FK value $model->_policyConstraint = null; $model->load($this->{$this->belongsTo[$var]['field']}); if (!empty($this->belongsTo[$var]['identifierField'])) { $model->identifierField = $this->belongsTo[$var]['identifierField']; } $field = $model->getField($model->getIdentifier()); //$this->_fields[$var] = clone $field; $field->tag = prettify($var); $value = $field->value; if (empty($value)) { $value = $model->{$model->getIdentifier()}; } } return $value; } if ($var == 'identifierField') { return $this->getIdentifier(); } if ($var == $this->getIdentifier()) { return $this->getIdentifierValue(); } if ($var == 'loaded' || $var == 'modified' || $var == 'tablename') { return $this->{'_' . $var}; } foreach ($this->hashes as $fieldname => $objects) { if (isset($objects[$var])) { return unserialize($objects[$var]); } } }
function getVAT($data, $glperiod_ids, $control_accounts, $sum = false, $paging = false) { if (count($glperiod_ids) > 0) { $glperiods = implode(', ', $glperiod_ids); // Set data source switch ($data['box']) { // Tax overview case 1: case 4: case 7: case 6: $this->_tablename = 'gltransactions_vat'; break; // EU sales // EU sales case 8: $this->_tablename = 'gl_taxeusales'; break; // EU purchases // EU purchases case 2: case 9: $this->_tablename = 'gl_taxeupurchases'; break; } // Set constraints $cc = new ConstraintChain(); $cc->add(new Constraint('glperiods_id', ' IN', '(' . $glperiods . ')')); switch ($data['box']) { // VAT output case 1: $cc->add(new Constraint('glaccount_id', '=', $control_accounts['vat_output'])); break; // EU acquisitions // EU acquisitions case 2: case 9: $cc->add(new Constraint('glaccount_id', '=', $control_accounts['eu_acquisitions'])); break; // VAT input - also requires value from box 2 // VAT input - also requires value from box 2 case 4: $cc->add(new Constraint('glaccount_id', '=', $control_accounts['vat_input'])); break; // VAT output // VAT output case 6: case 8: $cc->add(new Constraint('glaccount_id', '=', $control_accounts['vat_output'])); break; // VAT input // VAT input case 7: $cc->add(new Constraint('glaccount_id', '=', $control_accounts['vat_input'])); break; } if (isset($data['page'])) { $sh = new SearchHandler($this, true); } else { $sh = new SearchHandler($this, false); } if ($sum) { $fields = array('1'); $sh->setGroupBy($fields); $sh->setOrderby($fields); // Set aggregate field switch ($data['box']) { // VAT output case 1: $fields[] = 'SUM(vat) * -1 AS sum'; break; // EU acquisitions (positive values only) // EU acquisitions (positive values only) case 2: // VAT input/EU acquisitions (positive values only) // VAT input/EU acquisitions (positive values only) case 4: $fields[] = 'SUM(vat) AS sum'; break; // VAT output // VAT output case 6: case 8: $fields[] = 'SUM(net) * -1 AS sum'; break; // VAT input // VAT input case 7: case 9: $fields[] = 'SUM(net) AS sum'; break; } } else { // $this->num_pages = 1; // $this->cur_page = 1; $fields = array('id', 'docref', 'glaccount_id', 'glcentre_id', 'glperiods_id', 'transaction_date', 'source', 'comment', 'type', 'usercompanyid'); switch ($data['box']) { // VAT output case 1: case 6: case 8: $fields[] = 'vat * -1 AS vat'; $fields[] = 'net * -1 AS net'; break; default: $fields[] = 'vat'; $fields[] = 'net'; break; } $sh->setOrderby(array('transaction_date', 'docref')); if ($paging) { $sh->extract(); } } $sh->setFields($fields); $sh->addConstraintChain($cc); $this->load($sh); } }
public function output_detail() { $header = DataObjectFactory::Factory('OutputHeader'); $header->load($this->_data['id']); $this->view->set('outputheader', $header); $output_details = new OutputDetailCollection(DataObjectFactory::Factory('OutputDetail')); if (!isset($this->_data['orderby']) && !isset($this->_data['page'])) { $sh = new SearchHandler($output_details, FALSE); } else { $sh = new SearchHandler($output_details); } $sh->addConstraintChain(new Constraint('output_header_id', '=', $this->_data['id'])); $sh->extract(); $output_details->load($sh); $this->view->set('outputdetails', $output_details); $this->view->set('num_records', $output_details->num_records); $this->view->set('num_pages', $output_details->num_pages); $this->view->set('cur_page', $output_details->cur_page); $sidebar = new SidebarController($this->view); $sidebarlist = array(); $sidebarlist['summary'] = array('tag' => 'Show ' . $header->type . 's Summary List', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'output_summary', 'type' => $header->type)); $sidebarlist['edilog'] = array('tag' => 'EDI Log', 'link' => array('module' => 'edi', 'controller' => 'editransactionlogs', 'action' => 'index')); $sidebar->addList('action', $sidebarlist); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); }
public function showFulfilled() { $mfworkorders = new MFWorkorderCollection($this->_templateobject); $sh = new SearchHandler($mfworkorders); $sh->extract(); $sh->addConstraint(new Constraint('status', '=', 'O')); $sh->addConstraint(new Constraint('made_qty', '>=', '(order_qty)')); $sh->extractOrdering(); $sh->extractPaging(); $mfworkorders->load($sh); $this->view->set('clickaction', 'view'); $this->view->set('mfworkorders', $mfworkorders); $sidebar = new SidebarController($this->view); $sidebarlist = array(); $sidebarlist['viewAll'] = array('tag' => 'View', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'index')); $sidebar->addList('All Works Orders', $sidebarlist); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); }
public function getOutstandingTransactions($extract = true, $cc = '') { $transactions = new ELTransactionCollection(); $sh = new SearchHandler($transactions, false); if ($extract) { $sh->extract(); } $sh->addConstraint(new Constraint('status', '=', 'O')); if ($this->id) { $sh->addConstraint(new Constraint('employee_id', '=', $this->id)); } if (!empty($cc) && $cc instanceof ConstraintChain) { $sh->addConstraintChain($cc); } $sh->setOrderby(array('employee', 'our_reference')); $transactions->load($sh); return $transactions; }
/** * Index * * Handles the logic behind overview pages * called from extension-classes, which are left to handle actions and setting up the search fields * * @param DataObjectCollection $collection */ public function setSearchHandler(DataObjectCollection $collection, $search_id = NULL, $force_use_session = false) { if (!is_null($search_id)) { // leave the search as it is } elseif (isset($this->_data['search_id'])) { $search_id = $this->_data['search_id']; } elseif (isset($_GET['search_id'])) { $search_id = $_GET['search_id']; } else { $search_id = ''; } // included a parameter to force it to use the session, not sure if that's if ($force_use_session || isset($this->search) && isset($this->_data['ajax_print']) || isset($this->_data['orderby']) || isset($this->_data['page'])) { $sh = new SearchHandler($collection, true, false, $search_id); $sh->extractOrdering(); $sh->extractPaging(); } else { $sh = new SearchHandler($collection, false, false, $search_id); $sh->extract(); if (isset($this->_data['Search']['display_fields'])) { // Set the 'id' field $fields[key($sh->fields)] = current($sh->fields); // Add the requested search fields foreach ($this->_data['Search']['display_fields'] as $fieldname => $tag) { $fields[$fieldname] = new DataField($fieldname); $fields[$fieldname]->name = $fieldname; $fields[$fieldname]->tag = $tag; } // Now get any id fields foreach ($sh->fields as $fieldname => $field) { if ($fieldname == 'usercompanyid' || substr($fieldname, -3) == '_id') { $fields[$fieldname] = $field; } } $sh->setFields($fields); } } return $sh; }
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 viewBranches() { $branches = new CompanyCollection($this->_templateobject); $sh = new SearchHandler($branches, false); $sh->extract(); $sh->addConstraint(new Constraint('parent_id', '=', $this->_data['parent_id'])); $branches->load($sh); $this->_templateName = $this->getTemplateName('view_related'); $this->view->set('clickaction', 'view'); $this->view->set('related_collection', $branches); $this->view->set('num_pages', $branches->num_pages); $this->view->set('cur_page', $branches->cur_page); $this->view->set('no_ordering', true); }