public static function usedBy($search_data = null, &$errors = array(), $defaults = null, $params = array()) { $search = new SelectorItemSearch($defaults); $search->addSearchField('target_id', 'Target', 'hidden', '', 'hidden'); // Search by Product $config = SelectorCollection::getTypeDetails($params['type']); $search->addSearchField('parent_id', implode('/', $config['itemFields']), 'treesearch', -1, 'basic'); if (empty($search_data)) { $search_data = null; } $search->setSearchData($search_data, $errors, 'selectProduct'); // Populate the parent_id field using the last selected value // it will be -1 if no previous selected value $parent_id = $search->getValue('parent_id'); $cc = new ConstraintChain(); if ($parent_id != '-1') { $cc->add(new Constraint('parent_id', '=', $parent_id)); } else { $cc->add(new Constraint('parent_id', 'IS', 'NULL')); } $model = new DataObject('so_product_selector'); $options = array($parent_id => 'Select an option'); $options += $model->getAll($cc); $search->setOptions('parent_id', $options); if ($parent_id != '-1') { $data = array('target_id' => $search->getValue('target_id')); $search->setBreadcrumbs('parent_id', $model, 'parent_id', $parent_id, 'name', 'description', $data); } return $search; }
public static function selectProduct($search_data = null, &$errors = array(), $defaults = null) { $search = new sordersSearch($defaults); // Search by Customer $customer = DataObjectFactory::Factory('SLCustomer'); $customers = $customer->getAll(null, false, true, '', ''); $options = array('NULL' => 'None'); $options += $customers; if (!isset($search->defaults['slmaster_id'])) { $search->defaults['slmaster_id'] = key($options); } $search->addSearchField('slmaster_id', 'Customer', 'select', $search->defaults['slmaster_id'], 'basic'); $search->setOptions('slmaster_id', $options); // Search by Product Group $prod_group = DataObjectFactory::Factory('STProductgroup'); $prod_group_list = $prod_group->getAll(); $search->addSearchField('prod_group_id', 'Product Group', 'select', '', 'basic'); $options = array('' => 'None'); $options += $prod_group_list; $search->setOptions('prod_group_id', $options); // Search by Description $search->addSearchField('description', 'description contains', 'contains', '', 'basic'); // Search by Product $config = SelectorCollection::getTypeDetails('sales_order'); $search->addSearchField('parent_id', implode('/', $config['itemFields']), 'treesearch', -1, 'basic'); if (empty($search_data)) { $search_data = null; } $search->setSearchData($search_data, $errors, 'selectProduct'); // Populate the parent_id field using the last selected value // it will be -1 if no previous selected value $parent_id = $search->getValue('parent_id'); $cc = new ConstraintChain(); if ($parent_id != '-1') { $cc->add(new Constraint('parent_id', '=', $parent_id)); } else { $cc->add(new Constraint('parent_id', 'IS', 'NULL')); } $model = new DataObject('so_product_selector'); $options = array($parent_id => 'Select an option'); $options += $model->getAll($cc); $search->setOptions('parent_id', $options); if ($parent_id != '-1') { $data = array('slmaster_id' => $search->getValue('slmaster_id')); $search->setBreadcrumbs('parent_id', $model, 'parent_id', $parent_id, 'name', 'description', $data); } return $search; }
public function view_so_product() { if (!isset($this->_data['productline_header_id']) && !isset($this->_data['Search']['productline_header_id'])) { $this->DataError(); sendBack(); } $this->view->set('clickaction', 'edit'); $s_data = array(); // Set context from calling module if (!isset($this->_data['Search']) || isset($this->_data['Search']['clear'])) { $s_data['start_date/end_date'] = date(DATE_FORMAT); $s_data['productline_header_id'] = $this->_data['productline_header_id']; } if (isset($this->_data['productline_header_id'])) { $productline_header_id = $this->_data['productline_header_id']; } elseif (isset($this->_data['Search']['productline_header_id'])) { $productline_header_id = $this->_data['Search']['productline_header_id']; } $this->setSearch('productlinesSearch', 'soheaderLines', $s_data); // Load the Product Header $product = DataObjectFactory::Factory('SOProductlineHeader'); $product->load($productline_header_id); $this->view->set('SOProductlineHeader', $product); // Load the associated lines parent::index(new SOProductlineCollection($this->_templateobject)); $sidebar = new SidebarController($this->view); $sidebarlist = array(); $sidebarlist['view_all_products'] = array('link' => array('modules' => $this->_modules, 'controller' => 'soproductlineheaders', 'action' => 'index'), 'tag' => 'View All Products'); $sidebarlist['view_all_lines'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'index'), 'tag' => 'View All Product Lines'); $sidebar->addList('All Products', $sidebarlist); $sidebarlist = array(); $sidebarlist['view'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'view_so_product', 'productline_header_id' => $productline_header_id), 'tag' => 'view'); $sidebarlist['new'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'new', 'productline_header_id' => $productline_header_id), 'tag' => 'new price'); $sidebarlist['orders'] = array('link' => array('modules' => $this->_modules, 'controller' => 'soproductlineheaders', 'action' => 'view_orders', 'id' => $productline_header_id), 'tag' => 'view orders'); $sidebarlist['invoices'] = array('link' => array('modules' => $this->_modules, 'controller' => 'soproductlineheaders', 'action' => 'view_invoices', 'id' => $productline_header_id), 'tag' => 'view invoices'); $sidebarlist['prices'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'price_uplift', 'productline_header_id' => $productline_header_id), 'tag' => 'amend prices'); $sidebar->addList('this Product', $sidebarlist); $sidebarlist = array(); if (SelectorCollection::TypeDetailsExist($this->modeltype)) { $sidebarlist['items'] = array('link' => array('modules' => $this->_modules, 'controller' => 'soproductselectors', 'action' => 'used_by', 'target_id' => $productline_header_id), 'new' => array('modules' => $this->_modules, 'controller' => 'soproductselectors', 'action' => 'select_items', 'target_id' => $productline_header_id), 'tag' => 'used by'); } $sidebar->addList('related_items', $sidebarlist); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); $this->view->set('linkmodule', $this->module); $this->view->set('linkcontroller', 'soproductlineheaders'); }
/** * Check if type exists in selector configuration YAML file * * @param string $type * @return bool */ static function TypeDetailsExist($type) { $manifest = SelectorCollection::loadConfig(); foreach ($manifest as $definition) { if ($definition['targetModel'] == $type) { return TRUE; } } return FALSE; }
protected function setSidebarView($so_pl_header) { $sidebar = new SidebarController($this->view); $this->sidebarActions($sidebar, $so_pl_header, array('delete' => false)); $sidebarlist = array(); $sidebarlist['all_lines'] = array('link' => array('modules' => $this->_modules, 'controller' => 'soproductlines', 'action' => 'index'), 'tag' => 'view all SO product lines'); $sidebar->addList('All Actions', $sidebarlist); $sidebarlist = array(); $sidebarlist['orders'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'view_orders', 'id' => $so_pl_header->id), 'tag' => 'view orders'); $sidebarlist['invoices'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'view_invoices', 'id' => $so_pl_header->id), 'tag' => 'view invoices'); $sidebarlist['prices'] = array('link' => array('modules' => $this->_modules, 'controller' => 'soproductlines', 'action' => 'price_uplift', 'productline_header_id' => $so_pl_header->id), 'tag' => 'amend prices'); $sidebar->addList('this ' . $so_pl_header->getTitle(), $sidebarlist); $sidebarlist = array(); if (SelectorCollection::TypeDetailsExist($this->modeltype)) { $sidebarlist['items'] = array('link' => array('modules' => $this->_modules, 'controller' => 'soproductselectors', 'action' => 'used_by', 'target_id' => $so_pl_header->id), 'new' => array('modules' => $this->_modules, 'controller' => 'soproductselectors', 'action' => 'select_items', 'target_id' => $so_pl_header->id), 'tag' => 'used by'); } $sidebar->addList('related_items', $sidebarlist); $this->sidebarRelatedItems($sidebar, $so_pl_header); $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 select_item_component_output($status = 'generate') { // build options array $options = array('type' => array('csv' => '', 'pdf' => '', 'xml' => ''), 'output' => array('print' => '', 'save' => '', 'email' => '', 'view' => ''), 'filename' => 'Item_Component_list_' . fix_date(date(DATE_FORMAT))); // simply return the options if we're only at the dialog stage if (strtolower($status) === "dialog") { return $options; } $flash = Flash::Instance(); $s_data = array(); $params['options']['parent_id'] = $this->_templateobject->getDisplayFieldNames(); // so set context from calling module if (isset($this->_data['parent_id'])) { $s_data['parent_id'] = $this->_data['parent_id']; } elseif (!isset($this->_data['Search']['parent_id'])) { $s_data['parent_id'] = NULL; } $params['type'] = $this->module; parent::setSearch('SelectorItemSearch', 'useDefault', $s_data, $params); // load the default display fields into the session, we need these as we cannot rely on getting the headings from the data itself $_SESSION['selected_items']['headings'] = $this->_templateobject->getDisplayFieldNames(); $this->_templateobject->idField = 'id'; $this->_templateobject->orderby = $this->itemFields; $collection = new SelectorCollection(clone $this->_templateobject); $collection->setTableName($collection->selectorLinkOverview($this->itemFields, $this->linkTableName, $this->targetModel, $this->targetFields)); $sh = $this->setSearchHandler($collection); $sh->setFields(array_merge(array('id', 'item_id', 'target_id'), $this->itemFields, $this->targetFields)); if (!isset($this->_data['orderby']) && !isset($this->_data['page'])) { $sh->addConstraint(SelectorCollection::getItemHierarchy($this->module, $this->search->getValue('parent_id'))); } // set the query count sql - if no constraints, then just get count from link table $criteria = $sh->constraints->__toString(); if (empty($criteria)) { $c_query = 'select count(*) as count from ' . $this->linkTableName . ' link'; } // get list of items matching search criteria parent::index($collection, $sh, $c_query); $this->view->set('collection', $collection); $this->setTemplateName('selector_index'); }