public function _new()
 {
     parent::_new();
     $resource = $this->_uses[$this->modeltype];
     $db = DB::Instance();
     if ($resource->isLoaded()) {
         $this->_data['work_schedule_id'] = $resource->work_schedule_id;
         $this->view->set('workschedule', $resource->work_schedule_detail);
     } elseif (isset($this->_data['work_schedule_id'])) {
         $resource->work_schedule_id = $this->_data['work_schedule_id'];
         $this->view->set('workschedule', $resource->work_schedule_detail);
     } else {
         $workschedule = DataObjectFactory::Factory('WorkSchedule');
         $cc = new ConstraintChain();
         $cc->add(new Constraint('status', '!=', $workschedule->completedStatus()));
         $cc->add(new Constraint('status', '!=', $workschedule->cancelledStatus()));
         $this->view->set('workschedules', $workschedule->getAll($cc));
     }
     $person = DataObjectFactory::Factory('Person');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('company_id', '=', COMPANY_ID));
     $this->view->set('people', $person->getAll($cc));
     $resources = new EngineeringResourceCollection($this->_templateobject);
     $sh = $this->setSearchHandler($resources);
     $sh->addConstraint(new Constraint('work_schedule_id', '=', $resource->work_schedule_id));
     parent::index($resources, $sh);
     $this->view->set('clickaction', 'edit');
 }
Пример #2
0
 public function getDataOptions($model = '', $cc = '')
 {
     if (empty($model)) {
         $model = $this->getModel();
         if (!$model) {
             return false;
         }
     }
     $attribute = $this->internal_attribute;
     if ($model->idField == $attribute) {
         return $model->getAll($cc);
     } elseif (isset($model->belongsToField[$attribute])) {
         $x = $model->belongsTo[$model->belongsToField[$attribute]]["model"];
         if (empty($cc) || !$cc instanceof ConstraintChain) {
             $cc = new ConstraintChain();
         }
         if ($model->belongsTo[$model->belongsToField[$attribute]]["cc"] instanceof ConstraintChain) {
             $cc->add($model->belongsTo[$model->belongsToField[$attribute]]["cc"]);
         }
         $x = new $x();
         return $x->getAll($cc);
     } else {
         return array();
     }
 }
Пример #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;
 }
Пример #4
0
 function getTypesForEmployee($_employee_id)
 {
     $cc = new ConstraintChain();
     $cc->add(new Constraint('employee_id', '=', $_employee_id));
     $this->identifierField = 'authorisation_type';
     return $this->getAll($cc);
 }
Пример #5
0
 static function getBinList($whlocation_id)
 {
     $bins = new WHBin();
     $cc = new ConstraintChain();
     $cc->add(new Constraint('whlocation_id', '=', $whlocation_id));
     return $bins->getAll($cc);
 }
 public function getCentres()
 {
     $mf_centre = DataObjectFactory::Factory('MFCentre');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('production_recording', 'is', 'true'));
     return $mf_centre->getAll($cc);
 }
Пример #7
0
 public function _new()
 {
     $resource = $this->_uses[$this->modeltype];
     if (!$resource->isLoaded()) {
         if (empty($this->_data['project_id'])) {
             $project = new Project();
             $projects = $project->getAll();
             $project_id = key($projects);
         } else {
             $project_id = $this->_data['project_id'];
         }
         $this->view->set('project_id', $project_id);
         $tasks = $this->getTaskList($project_id);
         $dates = $this->getStartEndDate($project_id);
         $this->view->set('start_date', $dates['start_date']['data']);
         $this->view->set('end_date', $dates['end_date']['data']);
     } else {
         $tasks = $this->getTaskList($resource->project_id);
     }
     $this->view->set('tasks', $tasks);
     $person = new Person();
     $cc = new ConstraintChain();
     $cc->add(new Constraint('company_id', '=', COMPANY_ID));
     $this->view->set('people', $person->getAll($cc));
     parent::_new();
 }
Пример #8
0
 public function view()
 {
     if (!$this->loadData()) {
         sendback();
     }
     $ledgercategory = $this->_uses[$this->modeltype];
     $idfield = $ledgercategory->idField;
     $id = $ledgercategory->{$idfield};
     // Check if Ledger Category is used by Ledger Accounts
     $ledgeraccount = new LedgerCategory('ledger_category_accounts');
     $ledgeraccount->idField = 'company_id';
     $ledgeraccount->identifierField = 'name';
     $cc = new ConstraintChain();
     $cc->add(new Constraint('category_id', '=', $ledgercategory->category_id));
     $ledgeraccounts = $ledgeraccount->getAll($cc);
     $sidebar = new SidebarController($this->view);
     $sidebarlist = array();
     $sidebarlist['all'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'index'), 'tag' => 'view_ledger_categories');
     $sidebarlist['new'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'new'), 'tag' => 'new_ledger_category');
     if (count($ledgeraccounts) == 0) {
         $sidebarlist['edit'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'edit', $idfield => $ledgercategory->{$idfield}), 'tag' => 'edit_ledger_category');
         $sidebarlist['delete'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'delete', $idfield => $ledgercategory->{$idfield}), 'tag' => 'delete_ledger_category');
     }
     $sidebar->addList('Actions', $sidebarlist);
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
     $this->view->set('model', $ledgercategory);
     $this->view->set('count', count($ledgeraccounts));
 }
Пример #9
0
 public static function useDefault($search_data = null, &$errors = array(), $defaults = null)
 {
     $search = new poauthlimitsSearch($defaults);
     // Search by Person
     $search->addSearchField('username', 'Person', 'select', '');
     $people = DataObjectFactory::Factory('Usercompanyaccess');
     $people->idField = 'username';
     $people->identifierField = 'username';
     $people->orderby = 'username';
     $options = array('0' => 'All');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('usercompanyid', '=', EGS_COMPANY_ID));
     $peoplelist = $people->getAll($cc);
     $options += $peoplelist;
     $search->setOptions('username', $options);
     // Search by GL Centre
     $search->addSearchField('glcentre_id', 'GL Centre', 'select', 0);
     $options = array('0' => 'All');
     $centres = DataObjectFactory::Factory('GLCentre');
     $centrelist = $centres->getAll();
     $options += $centrelist;
     $search->setOptions('glcentre_id', $options);
     $search->setSearchData($search_data, $errors);
     return $search;
 }
Пример #10
0
 function load($sh, $c_query = null)
 {
     $db = DB::Instance();
     $qb = new QueryBuilder($db, $this->_doname);
     if ($sh instanceof SearchHandler) {
         if ($this->_templateobject->isAccessControlled()) {
             if (isModuleAdmin()) {
                 $cc = new ConstraintChain();
                 $cc->add(new Constraint('usercompanyid', '=', EGS_COMPANY_ID));
                 $cc->add(new Constraint('id', '=', EGS_COMPANY_ID), 'OR');
                 $sh->addConstraintChain($cc);
                 $qb->setDistinct();
             } else {
                 $cc = new ConstraintChain();
                 $cc->add(new Constraint('usernameaccess', '=', EGS_USERNAME));
                 $cc->add(new Constraint('owner', '=', EGS_USERNAME), 'OR');
                 $cc2 = new ConstraintChain();
                 $cc2->add(new Constraint('usercompanyid', '=', EGS_COMPANY_ID));
                 $sh->addConstraintChain($cc);
                 $sh->addConstraintChain($cc2);
                 $qb->setDistinct();
             }
         }
         $this->sh = $sh;
     }
     $this->_load($sh, $qb, $c_query);
 }
 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);
 }
Пример #12
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;
 }
Пример #13
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;
 }
Пример #14
0
 public function edit()
 {
     $this->view->set('field_name', $this->_data['field_name']);
     $modulecomponent = new ModuleComponent();
     $modulecomponent->load($this->_data['module_components_id']);
     $model = new $modulecomponent->name();
     $field = $model->getField($this->_data['field_name']);
     $this->view->set('field', $field);
     if (isset($model->belongsToField[$field->name])) {
         $x = $model->belongsTo[$model->belongsToField[$field->name]]["model"];
         $cc = new ConstraintChain();
         if ($model->belongsTo[$model->belongsToField[$field->name]]["cc"] instanceof ConstraintChain) {
             $cc->add($model->belongsTo[$model->belongsToField[$field->name]]["cc"]);
         }
         $x = new $x();
         $this->view->set('options', $x->getAll($cc));
         $field->type = 'select';
     }
     if ($model->isEnum($field->name)) {
         $this->view->set('options', $model->getEnumOptions($field->name));
         $field->type = 'select';
     }
     if (empty($this->_data['id'])) {
         //			sendTo($this->name,'new',$this->_modules);
         unset($this->_data['id']);
         $this->view->set('module_components_id', $this->_data['module_components_id']);
         parent::_new();
         $this->_templateName = $this->getTemplateName('new');
     } else {
         parent::edit();
     }
 }
Пример #15
0
 public static function confirmReceipt($search_data = null, &$errors = array(), $defaults = null)
 {
     $search = new pogoodsreceivedSearch($defaults);
     // Search by Customer
     $search->addSearchField('plmaster_id', 'Supplier', 'select', 0);
     $supplier = new PLSupplier();
     $options = array('0' => 'Select Supplier');
     $suppliers = $supplier->getAll(null, false, true);
     $options += $suppliers;
     $search->setOptions('plmaster_id', $options);
     // Search by Stock Item
     $search->addSearchField('stitem_id', 'Stock Item', 'select', 0);
     $stitems = new STItem();
     $options = array('0' => 'All');
     $stitems = $stitems->getAll();
     $options += $stitems;
     $search->setOptions('stitem_id', $options);
     // Search by Order Number
     $search->addSearchField('order_id', 'order_number', 'select', 0);
     $orderlines = new POrder();
     $cc = new ConstraintChain();
     $cc->add(new Constraint('status', 'in', "('A','O','P')"));
     $orderlines->orderby = 'order_number';
     $options = array('0' => 'All');
     $orderlines = $orderlines->getAll($cc);
     $options += $orderlines;
     $search->setOptions('order_id', $options);
     $search->setSearchData($search_data, $errors, 'confirmReceipt');
     // Do not save the order_id
     // - if the order is confirmed, then it will not be in the list on re-query
     if (isset($_SESSION['searches'][get_class($search)]['confirmReceipt']['order_id'])) {
         unset($_SESSION['searches'][get_class($search)]['confirmReceipt']['order_id']);
     }
     return $search;
 }
Пример #16
0
 public function view_allocations()
 {
     $flash = Flash::Instance();
     $collection = new SLTransactionCollection($this->_templateobject);
     $this->_templateobject->setAdditional('payment_value', 'numeric');
     $allocation = DataObjectFactory::Factory('SLAllocation');
     $allocationcollection = new SLAllocationCollection($allocation);
     $collection->_tablename = $allocationcollection->_tablename;
     $sh = $this->setSearchHandler($collection);
     $fields = array("our_reference||'-'||transaction_type as id", 'customer', 'slmaster_id', 'transaction_date', 'transaction_type', 'our_reference', 'ext_reference', 'currency', 'gross_value', 'allocation_date');
     $sh->setGroupBy($fields);
     $fields[] = 'sum(payment_value) as payment_value';
     $sh->setFields($fields);
     if (isset($this->_data['trans_id'])) {
         $allocation->identifierField = 'allocation_id';
         $cc = new ConstraintChain();
         $cc->add(new Constraint('transaction_id', '=', $this->_data['trans_id']));
         $alloc_ids = $allocation->getAll($cc);
         if (count($alloc_ids) > 0) {
             $sh->addConstraint(new Constraint('allocation_id', 'in', '(' . implode(',', $alloc_ids) . ')'));
         } else {
             $flash->addError('Error loading allocation');
             sendBack();
         }
     }
     parent::index($collection, $sh);
     $this->view->set('collection', $collection);
     $this->view->set('invoice_module', 'sales_invoicing');
     $this->view->set('invoice_controller', 'sinvoices');
     $this->view->set('clickaction', 'view');
     $this->view->set('clickcontroller', 'slcustomers');
     $this->view->set('linkvaluefield', 'slmaster_id');
 }
Пример #17
0
 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;
 }
Пример #18
0
 public static function getReportTypes()
 {
     $report_type = DataObjectFactory::Factory('ReportType');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('public', 'IS', TRUE));
     return $report_type->getAll($cc);
 }
Пример #19
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;
 }
Пример #20
0
 public function reset_passwords()
 {
     if (!isset($this->_data['users'])) {
         $user = DataObjectFactory::Factory('User');
         $cc = new ConstraintChain();
         $cc->add(new Constraint('usercompanyid', '=', EGS_COMPANY_ID));
         $results = $user->getAll($cc);
         $this->view->set('users', $results);
     } else {
         foreach ($this->_data['users'] as $username) {
             $user = DataObjectFactory::Factory('User');
             $user->load($username);
             $password = '';
             if (isset($this->_data['password'])) {
                 $password = $this->_data['password'];
             }
             $password = $user->setPassword($password);
             $message = "Your password for " . SERVER_ROOT . " has been reset\n" . "Your username is {$user->username}\n" . "Your password is {$password}\n" . "Thank you";
             $subject = 'Password reset';
             $person = DataObjectFactory::Factory('Person');
             $person->load($user->person_id);
             $to = $person->email->contactmethod;
             $headers = 'From: ' . get_config('ADMIN_EMAIL') . "\r\n" . 'X-Mailer: PHP/' . phpversion();
             if ($to != '') {
                 mail($to, $subject, $message, $headers);
             }
         }
         sendBack();
     }
 }
Пример #21
0
 function getAddresses($_company_id, $cc = '')
 {
     if (empty($cc)) {
         $cc = new ConstraintChain();
     }
     $cc->add(new Constraint('company_id', '=', $_company_id));
     return $this->getAll($cc, true, true);
 }
Пример #22
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);
 }
Пример #23
0
 function ticket_count()
 {
     $cc = new ConstraintChain();
     $cc->add(new Constraint('ticket_release_version_id', '=', $this->id));
     $ticket = new Ticket();
     $tickets = $ticket->getAll($cc);
     return count($tickets);
 }
Пример #24
0
 public static function getReportsByType($_report_type_id)
 {
     $report_definition = DataObjectFactory::Factory('ReportDefinition');
     $report_definition->idField = 'name';
     $cc = new ConstraintChain();
     $cc->add(new Constraint('report_type_id', '=', $_report_type_id));
     return $report_definition->getAll($cc);
 }
Пример #25
0
 public function getWasteTypes()
 {
     $centrewastetypes = DataObjectFactory::Factory('MFCentreWasteType');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('mf_centre_id', '=', $this->mf_centre_id));
     $centrewastetypes->identifierField = 'waste_type';
     return $centrewastetypes->getAll($cc, null, true);
 }
Пример #26
0
 function getModuleNames($role_id)
 {
     $this->idField = 'module_name';
     $this->identifierField = 'role_id';
     $cc = new ConstraintChain();
     $cc->add(new Constraint('role_id', '=', $role_id));
     return $this->getAll($cc);
 }
Пример #27
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);
 }
Пример #28
0
 function getContext()
 {
     $permission = DataObjectFactory::Factory('Permission');
     $permission->identifierField = 'title';
     $permission->orderby = 'title';
     $cc = new ConstraintChain();
     $cc->add(new Constraint('type', 'in', "('g', 'm')"));
     return $permission->getAll($cc, false);
 }
Пример #29
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);
 }
Пример #30
0
 function __construct($tablename = 'sypaytypes')
 {
     parent::__construct($tablename);
     $this->idField = 'id';
     $cc = new ConstraintChain();
     $cc->add(new Constraint('category', '=', 'PT'));
     $this->belongsTo('InjectorClass', 'method_id', 'method', $cc);
     $this->hasOne('InjectorClass', 'method_id', 'payment_class');
 }