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 index()
 {
     $id = $this->_data['stitem_id'];
     $transaction = new STItem();
     $transaction->load($id);
     $this->view->set('transaction', $transaction);
     $outside_ops = new MFOutsideOperationCollection($this->_templateobject);
     $sh = new SearchHandler($outside_ops, false);
     $cc = new ConstraintChain();
     $cc->add(new Constraint('stitem_id', '=', $id));
     $db = DB::Instance();
     $date = Constraint::TODAY;
     $between = $date . ' BETWEEN ' . $db->IfNull('start_date', $date) . ' AND ' . $db->IfNull('end_date', $date);
     $cc->add(new Constraint('', '', '(' . $between . ')'));
     $sh->addConstraintChain($cc);
     $sh->setOrderby('op_no');
     $outside_ops->load($sh);
     $this->view->set('outside_ops', $outside_ops);
     $this->view->set('linkfield', 'id');
     $this->view->set('linkvaluefield', 'id');
     $this->view->set('clickaction', 'view');
     $this->view->set('clickcontroller', 'MFOutsideOperations');
     $this->view->set('no_ordering', true);
     $sidebar = new SidebarController($this->view);
     $sidebar->addList('Show', array('allItems' => array('tag' => 'All Items', 'link' => array_merge($this->_modules, array('controller' => 'STItems', 'action' => 'index'))), 'thisItem' => array('tag' => 'Item Detail', 'link' => array_merge($this->_modules, array('controller' => 'STItems', 'action' => 'view', 'id' => $id))), 'addoperation' => array('tag' => 'Add Outside Operation', 'link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'new', 'stitem_id' => $id)))));
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
 }
Exemple #3
0
 public function getTotals($_project_id = '', $_task_id = '')
 {
     if (empty($_project_id)) {
         return false;
     }
     $cc = new ConstraintChain();
     $cc->add(new Constraint('project_id', '=', $_project_id));
     if (!empty($_task_id)) {
         $cc->add(new Constraint('task_id', '=', $_task_id));
     }
     $costs_charges = array();
     foreach ($this->getEnumOptions('item_type') as $key => $type) {
         $cc1 = new ConstraintChain();
         $cc1->add($cc);
         $cc1->add(new Constraint('item_type', '=', $key));
         switch ($key) {
             case 'PO':
                 $subkey = 'total_costs';
                 $tablename = 'project_purchase_orders';
                 break;
             case 'SI':
                 $subkey = 'total_invoiced';
                 $tablename = 'project_sales_invoices';
                 break;
         }
         $totals = $this->getSumFields(array('net_value'), $cc1, $tablename);
         $costs_charges[$subkey] = $totals['net_value'];
     }
     return $costs_charges;
 }
Exemple #4
0
 function getCalendarList($options = array())
 {
     $calendars = new CalendarCollection(new Calendar());
     $sh = new SearchHandler($calendars, false);
     $cc = new ConstraintChain();
     $cc->add(new Constraint('owner', '=', EGS_USERNAME));
     $cc->add(new Constraint('username', '=', EGS_USERNAME), 'OR');
     $sh->addConstraintChain($cc);
     $sh->setOrderby('name', 'ASC');
     $calendars->load($sh);
     $calendar_list = $calendars->getArray();
     if (count($calendar_list) > 0) {
         foreach ($calendar_list as $key => $value) {
             if (isset($options[$value['id']]['status']) && $options[$value['id']]['status'] == 'on') {
                 $calendar_list[$key]['show'] = true;
             } else {
                 $calendar_list[$key]['show'] = false;
             }
             switch ($value['type']) {
                 case "personal":
                 case "group":
                     $calendar_list[$key]['url'] = "/?module=calendar&controller=index&action=getJSON&id=" . $value['id'];
                     break;
                 case "gcal":
                     $calendar_list[$key]['url'] = $calendar_list[$key]['gcal_url'];
                     break;
             }
             $calendar_list[$key]['className'] = str_replace("#", "", $calendar_list[$key]['colour']);
         }
     }
     return $calendar_list;
 }
 function getvalue()
 {
     $model = $this->get_model();
     if ($this->idField == $this->fieldname) {
         $cc = new ConstraintChain();
         if (substr($this->value, -1) == ')') {
             $cc->add(new Constraint($model->idField, 'IN', $this->value));
         } else {
             $cc->add(new Constraint($model->idField, '=', $this->value));
         }
         $values = $model->getAll($cc);
         if (count($values) > 0) {
             return implode(',', $values);
         }
     } elseif (isset($model->belongsToField[$this->fieldname])) {
         if ($this->value === "'NULL'") {
             return 'NULL';
         }
         $fk = DataObjectFactory::Factory($model->belongsTo[$model->belongsToField[$this->fieldname]]['model']);
         $fk->load($this->value);
         return $fk->getIdentifierValue();
     } elseif ($model->isEnum($this->fieldname)) {
         return $model->getEnum($this->fieldname, $this->value);
     }
     return $this->value;
 }
Exemple #6
0
 public function toConstraintChain()
 {
     $cc = new ConstraintChain();
     if ($this->cleared) {
         return $cc;
     }
     debug('BaseSearch::toConstraintChain Fields: ' . print_r($this->fields, true));
     // Certain hidden fields need to be excluded from the constraint
     foreach ($this->fields as $group => $group_data) {
         foreach ($group_data as $field => $searchField) {
             if ($field == 'purchase_order_number') {
                 $search_value = $searchField->getValue();
                 if (!empty($search_value)) {
                     $invoices = PInvoice::getInvoices($searchField->getValue());
                     if (!empty($invoices)) {
                         $cc->add(new Constraint('id', 'in', '(' . implode(',', array_keys($invoices)) . ')'));
                     }
                 }
             } elseif ($searchField->doConstraint()) {
                 $c = $searchField->toConstraint();
                 if ($c !== false) {
                     $cc->add($c);
                 }
             }
         }
     }
     debug('BaseSearch::toConstraintChain Constraints: ' . print_r($cc, true));
     return $cc;
 }
Exemple #7
0
 public function toConstraintChain()
 {
     $cc = new ConstraintChain();
     if ($this->cleared) {
         return $cc;
     }
     debug('BaseSearch::toConstraintChain Fields: ' . print_r($this->fields, true));
     foreach ($this->fields as $group) {
         foreach ($group as $field => $searchField) {
             if ($field == 'balance') {
                 $cc1 = new ConstraintChain();
                 if ($searchField->getValue() == '') {
                     $cc1->add(new Constraint('balance', '>', '0'));
                 }
                 $cc->add($cc1);
             } elseif ($field != 'parent_id' && $field != 'search_id') {
                 $c = $searchField->toConstraint();
                 if ($c !== false) {
                     $cc->add($c);
                 }
             }
         }
     }
     debug('BaseSearch::toConstraintChain Constraints: ' . print_r($cc, true));
     return $cc;
 }
Exemple #8
0
 public function getBinLocationList($source)
 {
     $WHLocation = DataObjectFactory::Factory('WHLocation');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('whstore_id', '=', $source));
     $cc->add(new Constraint('bin_controlled', '=', 'true'));
     return $WHLocation->getAll($cc);
 }
Exemple #9
0
 function getCompanies($username = '')
 {
     $cc = new ConstraintChain();
     if (!empty($username)) {
         $cc->add(new Constraint('username', '=', $username));
     }
     $cc->add(new Constraint('enabled', 'is', true));
     return $this->getAll($cc);
 }
Exemple #10
0
 static function getCompanyOption($companyname)
 {
     $debugoption = new DebugOption();
     $cc = new ConstraintChain();
     $cc->add(new Constraint('username', 'is', 'NULL'));
     $cc->add(new Constraint('company_id', '=', EGS_COMPANY_ID));
     $debugoption->loadBy($cc);
     return $debugoption;
 }
Exemple #11
0
 function getRoleID($company_id, $accesstype)
 {
     $cc = new ConstraintChain();
     $cc->add(new Constraint('company_id', '=', $company_id));
     $cc->add(new Constraint('"' . $accesstype . '"', 'is', true));
     $this->idField = 'role_id';
     $this->identifierField = 'role_id';
     return $this->getAll($cc);
 }
Exemple #12
0
 function getActions($type = '')
 {
     $cc = new ConstraintChain();
     if (!empty($type)) {
         $cc->add(new Constraint('type', '=', $type));
     }
     $cc->add(new Constraint('defined_rules', '>', 0));
     return $this->getAll($cc, true, true);
 }
Exemple #13
0
 function getRoleID($_username, $_object_type, $_accesstype)
 {
     $cc = new ConstraintChain();
     $cc->add(new Constraint('username', '=', $_username));
     $cc->add(new Constraint('object_type', '=', $_object_type));
     $cc->add(new Constraint('"' . $_accesstype . '"', 'is', true));
     $this->idField = 'role_id';
     $this->identifierField = 'role_id';
     return $this->getAll($cc);
 }
Exemple #14
0
 static function close($periodid, &$errors)
 {
     $result = false;
     $errors = array();
     $period = DataObjectFactory::Factory('GLPeriod');
     $period->load($periodid);
     if ($period->isLoaded()) {
         // Check for any unposted journals for the period to be closed
         $journal_header = DataObjectFactory::Factory('GLTransactionHeader');
         $cc = new ConstraintChain();
         $cc->add(new Constraint('glperiods_id', '=', $period->{$period->idField}));
         $cc->add(new Constraint('status', '=', $journal_header->newStatus()));
         $cc->add(new Constraint('type', '=', $journal_header->standardJournal()));
         if ($journal_header->getCount($cc) > 0) {
             $errors[] = 'Cannot close period due to unposted journals';
             return FALSE;
         }
         // Ensure all assets are depreciated for the the period
         assetHandling::depreciateAll($errors);
         // Close the period if no errors
         if (count($errors) === 0) {
             $result = $period->update($period->id, 'closed', 'true');
         }
         if ($result) {
             // Rollup year-to-datebalances
             $periodendbalances = new GLPeriodEndBalanceCollection(DataObjectFactory::Factory('GLPeriodEndBalance'));
             if ($periodendbalances->create($period) === FALSE) {
                 $errors[] = 'Error creating period end balances';
             }
         } else {
             $errors[] = 'Error closing period';
         }
         // Create the new period for next year
         $newperiod = DataObjectFactory::Factory('GLPeriod');
         $nextyear = date(DATE_FORMAT, strtotime('+12 months', strtotime($period->enddate)));
         $newperiod->loadPeriod($nextyear);
         if ($result && count($errors) === 0 && !$newperiod->isLoaded()) {
             if (!self::createNew($period, $errors)) {
                 $errors[] = 'Error creating new period for next year';
             }
         }
         // If closing last period of the year, do year end
         $glparams = DataObjectFactory::Factory('GLParams');
         if (!is_numeric($glparams->number_of_periods_in_year())) {
             $errors[] = 'GL Parameters No.of periods in year not defined';
         }
         if ($result && count($errors) === 0 && $period->period == $glparams->number_of_periods_in_year()) {
             self::yearEnd($period, $errors);
         }
         return $period;
     } else {
         $errors[] = 'Error loading period details';
         return false;
     }
 }
Exemple #15
0
 static function getSaleLocations($whstore = "")
 {
     $location = DataObjectFactory::Factory('WHLocation');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('saleable', 'is', true));
     if (!empty($whstore)) {
         $cc->add(new Constraint('whstore_id', '=', $whstore));
     }
     $locations = $location->getAll($cc);
     return array_keys($locations);
 }
Exemple #16
0
 function getUsers($roleid)
 {
     $cc = new ConstraintChain();
     if (is_array($roleid)) {
         $cc->add(new Constraint('roleid', 'in', '(' . implode(',', $roleid) . ')'));
     } else {
         $cc->add(new Constraint('roleid', '=', $roleid));
     }
     $this->identifierField = 'username';
     return $this->getAll($cc);
 }
Exemple #17
0
 static function getModelList()
 {
     $module_component = DataObjectFactory::Factory('ModuleComponent');
     $module_component->identifierField = $module_component->orderby = 'title';
     $cc = new ConstraintChain();
     $cc->add(new Constraint('type', '=', 'M'));
     // Really need to identify the DataObject models
     $cc->add(new Constraint('name', 'not like', '%collection'));
     $cc->add(new Constraint('name', 'not like', '%search'));
     return $module_component->getAll($cc);
 }
Exemple #18
0
 public static function supplierItems($search_data = null, &$errors = array(), $defaults = null)
 {
     $search = productlinesSearch::items($search_data, $errors, 'PLSupplier', $defaults);
     $search->addSearchField('comp_class', '', 'hidden', '', 'hidden');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('comp_class', 'is', 'NULL'));
     $cc->add(new Constraint('comp_class', 'in', "('B', 'S')"), 'OR');
     $search->setConstraint('comp_class', $cc);
     $search->setSearchData($search_data, $errors, 'PLSupplierItems');
     return $search;
 }
Exemple #19
0
 public function getPayPeriodByDate($_period_start_date, $_pay_basis = '')
 {
     $db = DB::Instance();
     $cc = new ConstraintChain();
     $cc->add(new Constraint('period_start_date', '<=', $_period_start_date));
     $cc->add(new Constraint('period_end_date', '>', $_period_start_date));
     if (!empty($_pay_basis)) {
         $cc->add(new Constraint('pay_basis', '=', $_pay_basis));
     }
     $this->loadBy($cc);
 }
Exemple #20
0
 public function getLatest($_employee_id, $_payment_type_id)
 {
     $cc = new ConstraintChain();
     $cc->add(new Constraint('employee_id', '=', $_employee_id));
     $cc->add(new Constraint('payment_type_id', '=', $_payment_type_id));
     $start_date = $this->getMax('start_date', $cc);
     if (!empty($start_date)) {
         $cc->add(new Constraint('start_date', '=', $start_date));
     }
     $this->loadBy($cc);
 }
Exemple #21
0
 public static function getMostRecent($stitem_id, $type)
 {
     $cc = new ConstraintChain();
     $cc->add(new Constraint('stitem_id', '=', $stitem_id));
     $cc->add(new Constraint('type', '=', $type));
     $sh = new SearchHandler(new STCostCollection(), false);
     $sh->addConstraintChain($cc);
     $sh->setOrderBy(array('lastupdated', 'id'), array('DESC', 'DESC'));
     $stcost = new STCost();
     return $stcost->loadBy($sh);
 }
Exemple #22
0
 function getIds($object_id, $object_type, $accesstype = '')
 {
     $cc = new ConstraintChain();
     $cc->add(new Constraint('object_id', '=', $object_id));
     $cc->add(new Constraint('object_type', '=', $object_type));
     if (!empty($accesstype)) {
         $cc->add(new Constraint('"' . $accesstype . '"', 'is', true));
     }
     $this->idField = 'id';
     $this->identifierField = 'id';
     return $this->getAll($cc);
 }
 public function getLatest($_employee_id, $_from_pay_frequency_id, $_to_pay_frequency_id)
 {
     $cc = new ConstraintChain();
     $cc->add(new Constraint('employee_id', '=', $_employee_id));
     $cc->add(new Constraint('from_pay_frequency_id', '=', $_from_pay_frequency_id));
     $cc->add(new Constraint('to_pay_frequency_id', '=', $_to_pay_frequency_id));
     $start_date = $this->getMax('start_date', $cc);
     if (!empty($start_date)) {
         $cc->add(new Constraint('start_date', '=', $start_date));
     }
     $this->loadBy($cc);
 }
 public function getChargeTotals($_project_id = '', $_task_id = '')
 {
     if (empty($_project_id)) {
         return array();
     }
     $cc = new ConstraintChain();
     $cc->add(new Constraint('project_id', '=', $_project_id));
     if (!empty($_task_id)) {
         $cc->add(new Constraint('task_id', '=', $_task_id));
     }
     $totals = $this->getSumFields(array('total_costs', 'total_charges'), $cc, 'project_equipment_charges');
     return $totals;
 }
Exemple #25
0
 public function getAssignedRoles($_report_id = '', $_permissions_id = '')
 {
     $this->idField = 'role_id';
     $this->identifierField = 'role';
     $cc = new ConstraintChain();
     if (!empty($_report_id)) {
         $cc->add(new Constraint('report_id', '=', $_report_id));
     }
     if (!empty($_permissions_id)) {
         $cc->add(new Constraint('permissions_id', '=', $_permissions_id));
     }
     return $this->getAll($cc, true, true);
 }
Exemple #26
0
 function getToLocations($whaction_id, $from_whlocation_id)
 {
     $cc = new ConstraintChain();
     $cc->add(new Constraint('whaction_id', '=', $whaction_id));
     if (!is_array($from_whlocation_id)) {
         $from_whlocation_id = array($from_whlocation_id);
     }
     if (count($from_whlocation_id) > 0) {
         $cc->add(new Constraint('from_whlocation_id', '=', '(' . implode(',', $from_whlocation_id) . ')'));
     }
     $this->idField = 'to_whlocation_id';
     $this->identifierField = 'to_location';
     return $this->getAll($cc, FALSE, TRUE);
 }
Exemple #27
0
 function setConstraints($_employee_id = '', $_start_date = '', $_end_date = '')
 {
     $cc = new ConstraintChain();
     if (!empty($_employee_id)) {
         $cc->add(new Constraint('employee_id', '=', $_employee_id));
     }
     if (!empty($_start_date)) {
         $cc->add(new Constraint('start_date', '>=', $_start_date));
     }
     if (!empty($_end_date)) {
         $cc->add(new Constraint('end_date', '<=', $_end_date));
     }
     return $cc;
 }
 public function getBalance()
 {
     // Function called by Ajax Request to return balance for selected item, location, bin
     $balance = new STBalance();
     $cc = new ConstraintChain();
     $cc->add(new Constraint('stitem_id', '=', $this->_data['stitem_id']));
     $cc->add(new Constraint('whlocation_id', '=', $this->_data['location_id']));
     if (isset($this->_data['bin_id']) && !empty($this->_data['bin_id'])) {
         $cc->add(new Constraint('whbin_id', '=', $this->_data['bin_id']));
     }
     $balance->loadBy($cc);
     echo json_encode($balance->balance ? $balance->balance : 0);
     exit;
 }
Exemple #29
0
 /**
  * @param void
  * @return Constraint
  *
  * Produces a Constraint that uses either < or > for a comparison
  * @TODO: implement 'between'
  */
 public function toConstraint()
 {
     $c = FALSE;
     $value = '';
     if ($this->value_set) {
         $value = $this->value;
     } else {
         $value = $this->default;
     }
     if (!empty($value)) {
         switch ($this->type) {
             case 'before':
                 $c = new Constraint($this->fieldname, '<', fix_date($value));
                 break;
             case 'after':
                 $c = new Constraint($this->fieldname, '>', fix_date($value));
                 break;
             case 'betweenfields':
                 $fields = explode('/', $this->fieldname);
                 if (count($fields) != 2) {
                     break;
                 }
                 $c = new ConstraintChain();
                 $c->add(new Constraint($fields[0], '<=', fix_date($value)));
                 $c1 = new ConstraintChain();
                 $c1->add(new Constraint($fields[1], '>=', fix_date($value)));
                 $c1->add(new Constraint($fields[1], 'is', 'NULL'), 'OR');
                 $c->add($c1);
                 break;
             case 'beforeornull':
                 $c = new ConstraintChain();
                 $c->add(new Constraint($this->fieldname, '<', fix_date($value)));
                 $c->add(new Constraint($this->fieldname, 'is', 'NULL'), 'OR');
                 break;
             case 'afterornull':
                 $c = new ConstraintChain();
                 $c->add(new Constraint($this->fieldname, '>', fix_date($value)));
                 $c->add(new Constraint($this->fieldname, 'is', 'NULL'), 'OR');
                 break;
             case 'from':
                 $c = new Constraint($this->fieldname, '>=', fix_date($value));
                 break;
             case 'to':
                 $c = new Constraint($this->fieldname, '<=', fix_date($value));
                 break;
         }
     }
     return $c;
 }
 function getCompanyID($category_id, $cc = null)
 {
     if (!$cc instanceof ConstraintChain) {
         $cc = new ConstraintChain();
     }
     if (is_array($category_id)) {
         $cc->add(new Constraint('category_id', 'in', '(' . implode(',', $category_id) . ')'));
     } else {
         $cc->add(new Constraint('category_id', '=', $category_id));
     }
     $this->idField = 'company_id';
     $this->identifierField = 'company';
     $this->orderby = 'company';
     return $this->getAll($cc, true, true);
 }