コード例 #1
0
ファイル: MFWOStructure.php プロジェクト: uzerpllp/uzerp
 function copyStructure($data, &$errors)
 {
     $mfstructures = new MFStructureCollection(DataObjectFactory::Factory('MFStructure'));
     $cc1 = new ConstraintChain();
     $cc1->add(new Constraint('stitem_id', '=', $data->stitem_id));
     $cc1->add(new Constraint('start_date', '<=', fix_date(date(DATE_FORMAT))));
     $cc2 = new ConstraintChain();
     $cc2->add(new Constraint('end_date', '>=', fix_date(date(DATE_FORMAT))));
     $cc2->add(new Constraint('end_date', 'is', 'NULL'), 'OR');
     $sh = new SearchHandler($mfstructures, false);
     $sh->addConstraintChain($cc1);
     $sh->addConstraintChain($cc2);
     $mfstructures->load($sh);
     $wo_structure = array();
     $wo_structures = array();
     $copyfields = array('line_no', 'qty', 'uom_id', 'remarks', 'waste_pc', 'ststructure_id');
     foreach ($mfstructures as $input) {
         $wo_structure['work_order_id'] = $data->id;
         foreach ($copyfields as $field) {
             $wo_structure[$field] = $input->{$field};
         }
         $wo_structures[$input->line_no] = DataObject::Factory($wo_structure, $errors, 'MFWOStructure');
     }
     return $wo_structures;
 }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
 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);
 }
コード例 #4
0
 public function close_off_current($_employee_id, $_end_date)
 {
     $sh = new SearchHandler($this, FALSE);
     $sh->addConstraint(new Constraint('employee_id', '=', $_employee_id));
     $sh->addConstraintChain(new Constraint('end_date', 'is', 'NULL'));
     return $this->update('end_date', $_end_date, $sh);
 }
コード例 #5
0
 function sumByStatus($cc = '')
 {
     $sh = new SearchHandler($this, FALSE);
     if ($cc instanceof ConstraintChain) {
         $sh->addConstraintChain($cc);
     }
     $sh->setFields(array('status as id', 'status', 'sum(num_days) as num_days'));
     $sh->setGroupBy(array('status as id', 'status'));
     $sh->setOrderBy('status');
     return $this->load($sh);
 }
コード例 #6
0
ファイル: StcostsController.php プロジェクト: uzerpllp/uzerp
 public static function getOutsideOperationCosts(ConstraintChain $cc, $type = 'latest')
 {
     $mfoutsideops = new MFOutsideOperationCollection();
     $sh = new SearchHandler($mfoutsideops, false);
     $sh->addConstraintChain($cc);
     $fields = array('id', 'op_no', 'description', $type . '_osc');
     $sh->setFields($fields);
     $sh->setOrderby('op_no');
     $mfoutsideops->load($sh);
     return $mfoutsideops;
 }
コード例 #7
0
ファイル: STCost.php プロジェクト: uzerpllp/uzerp
 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);
 }
コード例 #8
0
ファイル: POrderCollection.php プロジェクト: uzerpllp/uzerp
 public function getItemDates($cc = "")
 {
     $sh = new SearchHandler($this, false);
     $DisplayFields = array('due_delivery_date', 'stitem_id', 'stitem', 'uom_name', 'on_order');
     $sh->setOrderby('due_delivery_date');
     $sh->setFields($DisplayFields);
     if (!empty($cc) && $cc instanceof ConstraintChain) {
         $sh->addConstraintChain($cc);
     }
     $this->_tablename = 'po_itemdates';
     $this->load($sh);
     return $this;
 }
コード例 #9
0
 function forPayment($cc = '')
 {
     $sh = new SearchHandler($this, false);
     $sh->addConstraint(new Constraint('for_payment', 'is', 'true'));
     $sh->addConstraint(new Constraint('status', '=', 'O'));
     if (!empty($cc) && $cc instanceof ConstraintChain) {
         $sh->addConstraintChain($cc);
     }
     $fields = array('employee_id', 'employee', 'company_id', 'currency', 'payment_type', 'currency_id', 'payment_type_id');
     $sh->setGroupBy($fields);
     $sh->setOrderby('supplier');
     $fields[] = 'sum(os_value) as payment';
     $sh->setFields($fields);
     $this->load($sh);
 }
コード例 #10
0
 function forPayment($cc = '')
 {
     $sh = new SearchHandler($this, false);
     $sh->addConstraint(new Constraint('for_payment', 'is', 'true'));
     $sh->addConstraint(new Constraint('status', '=', 'O'));
     if (!empty($cc) && $cc instanceof ConstraintChain) {
         $sh->addConstraintChain($cc);
     }
     $fields = array('plmaster_id', 'supplier', 'payee_name', 'company_id', 'currency', 'payment_type', 'currency_id', 'payment_type_id');
     $sh->setGroupBy($fields);
     $sh->setOrderby('supplier');
     $fields[] = 'sum(os_value-cast(include_discount as integer)*coalesce(settlement_discount,0)) as payment';
     $sh->setFields($fields);
     $this->load($sh);
 }
コード例 #11
0
 function populate()
 {
     $sttransactions = new STTransactionCollection();
     $sttransactions->setParams();
     $sh = new SearchHandler($sttransactions, false);
     $sh->addConstraint(new Constraint('status', '=', 'E'));
     $cc = new ConstraintChain();
     $cc->add(new Constraint('error_qty', '<', 0));
     $cc->add(new Constraint('qty', '<', 0), 'OR');
     $sh->addConstraintChain($cc);
     $this->setSearchLimit($sh);
     $sh->setOrderBy('created', 'DESC');
     $sttransactions->load($sh);
     $this->contents = $sttransactions;
 }
コード例 #12
0
 function getLocationList($cc = "")
 {
     $sh = new SearchHandler($this, false);
     if ($cc instanceof ConstraintChain) {
         $sh->addConstraintChain($cc);
     }
     $sh->setOrderby(array('whstore', 'location'));
     $this->load($sh);
     $list = array();
     if ($this->count() > 0) {
         foreach ($this as $location) {
             $list[$location->id] = $location->whstore . '/' . $location->location . '-' . $location->description;
         }
     }
     return $list;
 }
コード例 #13
0
ファイル: SOrderCollection.php プロジェクト: uzerpllp/uzerp
 public function getItemOrders($cc = "")
 {
     $sh = new SearchHandler($this, FALSE);
     $DisplayFields = array('id', 'stitem_id', 'due_despatch_date', 'stitem', 'order_number', 'line_number', 'order_id', 'customer', 'slmaster_id', 'stuom', 'required', 'delivery_note', 'despatch_action', 'status', 'account_status', 'status', 'item_description', 'productline_id');
     //		$sh->setOrderby(
     //			array('order_number', 'line_number'),
     //			array('ASC', 'ASC')
     //		);
     $sh->setFields($DisplayFields);
     if (!empty($cc) && $cc instanceof ConstraintChain) {
         $sh->addConstraintChain($cc);
     }
     $this->_tablename = 'so_itemorders';
     $this->load($sh);
     return $this;
 }
コード例 #14
0
 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();
 }
コード例 #15
0
 function checkPermission($permissions, $types, $parent_ids = '')
 {
     $cc = new ConstraintChain();
     if (is_array($permissions)) {
         $permissions = implode("','", $permissions);
     }
     $cc->add(new Constraint('permission', 'in', "('" . $permissions . "')"));
     if (is_array($types)) {
         $types = implode("','", $types);
     }
     $cc->add(new Constraint('type', 'in', "('" . $types . "')"));
     if (!empty($parent_ids)) {
         if (is_array($parent_ids)) {
             $parent_ids = implode(',', $parent_ids);
         }
         $cc->add(new Constraint('parent_id', 'in', '(' . $parent_ids . ')'));
     }
     $sh = new SearchHandler($this, false);
     $sh->addConstraintChain($cc);
     return $this->load($sh, null, RETURN_ROWS);
 }
コード例 #16
0
 function agedDebtor($_slmaster_id = '', $_aged_months = '')
 {
     if (!empty($_aged_months)) {
         $this->agedMonths = $_aged_months;
     }
     $this->_tablename = 'sl_aged_debtors_overview';
     $this->orderby = array('slmaster_id', 'age');
     $sh = new SearchHandler($this, false);
     $cc = new ConstraintChain();
     if (!empty($_slmaster_id)) {
         if (!is_array($_slmaster_id)) {
             $_slmaster_id = array($_slmaster_id);
         }
         $cc = new Constraint('slmaster_id', 'in', '(' . implode(',', $_slmaster_id) . ')');
         $sh->addConstraintChain($cc);
     }
     $this->load($sh);
     for ($i = -1; $i <= $this->agedMonths; $i++) {
         $this->agedBalances[$i]['title'] = 'Month+' . $i;
         $this->agedBalances[$i]['value'] = '0.00';
     }
     $this->agedBalances[-1]['title'] = 'Future';
     $this->agedBalances[0]['title'] = 'Current Month';
     $this->agedBalances[$this->agedMonths + 1]['title'] = 'Older';
     $this->agedBalances[$this->agedMonths + 1]['value'] = '0.00';
     $total = 0;
     foreach ($this as $agedcreditors) {
         $total = bcadd($total, $agedcreditors->value);
         if ($agedcreditors->age > $this->agedMonths) {
             $this->agedBalances[$this->agedMonths]['value'] = BCADD($this->agedBalances[$this->agedMonths]['value'], $agedcreditors->value, 2);
         } elseif ($agedcreditors->age < 0) {
             $this->agedBalances[-1]['value'] = BCADD($this->agedBalances[-1]['value'], $agedcreditors->value, 2);
         } else {
             $this->agedBalances[$agedcreditors->age]['value'] = BCADD($this->agedBalances[$agedcreditors->age]['value'], $agedcreditors->value, 2);
         }
     }
     $this->agedBalances[$this->agedMonths + 2]['title'] = 'Total';
     $this->agedBalances[$this->agedMonths + 2]['value'] = $total;
     return $this->agedBalances;
 }
コード例 #17
0
ファイル: Calendar.php プロジェクト: uzerpllp/uzerp
 /**
  * getWritableCalendars
  * 
  * Used to return an array of calendars that a specific user has write access to
  * This will automatically exclude gcal until write functionality has been developed
  *
  * @return array of writable calendars
  */
 function getWritableCalendars($calendar_id = '')
 {
     $calendar = new CalendarCollection($this);
     $sh = new SearchHandler($calendar, false);
     if (!empty($calendar_id)) {
         $sh->addConstraint(new Constraint('id', '=', $calendar_id));
     }
     $sh->addConstraint(new Constraint('type', '!=', 'gcal'));
     $sh->addConstraint(new Constraint('owner', '=', EGS_USERNAME));
     $cc = new ConstraintChain();
     $cc->add(new Constraint('type', '=', 'group'));
     $cc->add(new Constraint('username', '=', EGS_USERNAME));
     $sh->addConstraintChain($cc, 'OR');
     $sh->setOrderby('name');
     $sh->setGroupBy('id');
     $calendar->load($sh);
     $calendar_id = array();
     foreach ($calendar as $key => $value) {
         $calendar_id[$value->id] = $value->name . " (" . $value->owner . ")";
     }
     return $calendar_id;
 }
コード例 #18
0
 public function getLocationList($stitem_id, $cc = '')
 {
     // Move this to STBalance as getAll - more efficient!
     $sh = new SearchHandler($this, false);
     if (!is_array($stitem_id)) {
         $sh->addConstraint(new Constraint('stitem_id', '=', $stitem_id));
     } else {
         $sh->addConstraint(new Constraint('stitem_id', 'in', '(' . implode(',', $stitem_id) . ')'));
     }
     if ($cc instanceof ConstraintChain) {
         $sh->addConstraintChain($cc);
     }
     $sh->setFields(array('whlocation_id', 'whlocation'));
     // Return rows to loop round array
     $rows = $this->load($sh, '', RETURN_ROWS);
     $list = array();
     if (count($rows) > 0) {
         foreach ($rows as $row) {
             $list[$row['id']] = $row['whlocation'];
         }
     }
     return $list;
 }
コード例 #19
0
 function populate()
 {
     $orderline = DataObjectFactory::Factory('SOrderLine');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('status', 'in', "('N', 'S', 'R', 'P')"));
     $cc->add(new Constraint('due_despatch_date', '<', fix_date(date(DATE_FORMAT))));
     $order_total = $orderline->getSum('base_net_value', $cc);
     $orders = new SOrderLineCollection($orderline);
     $orders->setParams();
     $sh = new SearchHandler($orders, FALSE);
     $fields = array('order_id', 'order_number', 'customer', 'order_date', 'due_despatch_date');
     $sh->setGroupBy($fields);
     $sh->setOrderBy(array('due_despatch_date', 'order_number', 'customer'));
     $fields[] = 'sum(base_net_value) as base_net_value';
     $sh->setFields($fields);
     $sh->addConstraintChain($cc);
     $this->setSearchLimit($sh);
     $orders->load($sh);
     $orders->collection_date_label = 'due_despatch_date';
     $orders->collection_total_label = 'Total (Base Net Value) Order Lines Overdue';
     $orders->collection_total = $order_total;
     $this->contents = $orders;
 }
コード例 #20
0
ファイル: ReportsController.php プロジェクト: uzerpllp/uzerp
 public function run()
 {
     // process any search data that may be passed
     if (is_array($this->_data['Search']) && isset($this->_data['Search']['report_id'])) {
         $this->_data[$this->_templateobject->idField] = $this->_data['Search']['report_id'];
         unset($this->_data['Search']['report_id']);
     }
     if (!$this->loadData()) {
         $this->dataError();
         sendBack();
     }
     $flash = Flash::Instance();
     // get the report model, lets not envoke it again... that's not cool
     $report = $this->_uses[$this->modeltype];
     // there's no point in processing all the following data just to display the dialog... display it now
     if (isset($this->_data['printaction']) || isset($this->_data['printAction']) || isset($this->_data['ajax_print'])) {
         // build options array
         $defs = ReportDefinition::getDefinition('PrintCollection');
         $dialog_options = array('type' => array('pdf' => '', 'xml' => '', 'csv' => ''), 'output' => array('print' => '', 'save' => '', 'email' => '', 'view' => ''), 'filename' => strtolower(str_replace(" ", "_", $report->description)) . '_' . date('d-m-Y'));
         // if ajax_print is not set we must be on the dialog
         if (!isset($this->_data['ajax_print'])) {
             return $dialog_options;
         }
     }
     // give smarty the title
     $this->view->set('title', $report->description);
     // unserialise the options from the db
     $options = unserialize($report->options);
     // overlay the defaults so we've got a full set of options
     $options = $this->expand_options($options, $report->tablename);
     // sort options by position
     $options = $this->sort_options($options);
     // vars
     $aggregate_fields = array();
     $at_agg = FALSE;
     $fields = array();
     $display_fields = array();
     $measure_fields = array();
     $search_fields = array();
     $filter_fields = array();
     $aggregate_methods = array();
     // build arrays for use in the view
     foreach ($options as $field => $field_options) {
         // we need to check against legacy search options
         if ($field_options['field_type'] === 'search') {
             $flash->addError('Report has legacy search fields, please edit this report to update');
             sendBack();
         }
         // ignore the filter field... it really isn't a field
         if ($field == 'filter') {
             continue;
         }
         // iron out the field label if it exists
         if (isset($field_options['field_label']) && !empty($field_options['field_label'])) {
             $label = $field_options['field_label'];
         } else {
             $label = $field;
         }
         $position = $field_options['position'];
         // we're always dealing with normal fields now
         // no need for a switch statement
         // ignore fields that aren't meant to be displayed
         if ($field_options['normal_display_field'] !== 'false') {
             // build two arrays, the display fields array will include filter fields... for now
             $original_fields[$position] = $field;
             $display_fields[$position] = $field;
             if ($field_options['normal_break_on'] === "true") {
                 $measure_fields[$position] = $field;
             }
             if (!empty($field_options['normal_method']) && $field_options['normal_method'] !== 'dont_total') {
                 $aggregate_fields[$position] = $field;
                 $aggregate_methods[$position] = $field_options['normal_method'] . '(' . $field . ') as ' . $field;
                 // if we're setting an aggregate field... this must not be a display field
                 unset($display_fields[$position]);
             }
         }
         // if the field is also a search field, add it to the search array
         if (isset($field_options['normal_enable_search']) && $field_options['normal_enable_search'] === 'true') {
             $search_fields[$field] = $field_options;
         }
     }
     // if the filters aren't empty, apply them one by one
     if (!empty($options['filter'])) {
         // loop through filter lines
         foreach (range(1, 3) as $number) {
             if (!isset($filter_cc)) {
                 $filter_cc = new ConstraintChain();
             }
             // filter line 1 will never have an operator
             if ($number === 1) {
                 $operator = 'AND';
             } else {
                 $operator = $options['filter']['filter_' . $number . '_operator'];
             }
             $field = $options['filter']['filter_' . $number . '_field'];
             $condition = $options['filter']['filter_' . $number . '_condition'];
             $value = $options['filter']['filter_' . $number . '_value'];
             // if we're dealing with a valid filter line...
             if (($number === 1 or !empty($operator)) and !empty($value)) {
                 // add the field to the display fields
                 if (!array_search($field, $display_fields)) {
                     $display_fields = array_merge($display_fields, array($field));
                 }
                 // add the filter to the contraint chain
                 $filter_cc->add(new Constraint($field, $condition, $value), $operator);
             }
         }
     }
     // NB: The follow idField is being passed by reference... it isn't passing a value, instead recieving one back
     $do = $report->createDataObject($display_fields, $idField, $this->getColumns($report->tablename));
     $doc = new DataObjectCollection($do);
     $sh = new SearchHandler($doc, FALSE);
     $sh->setGroupby($display_fields);
     $sh->setOrderby($display_fields);
     if (!isset($this->_data['Search'])) {
         $this->_data['Search'] = array();
     }
     // we don't need a condition here... always display the search box
     $this->search = $report->createSearch($search_fields, $this->_data['Search']);
     $cc = $this->search->toConstraintChain();
     $cc->removeByField('report_id');
     $sh->addConstraintChain($cc);
     // if the filter constraint chain has been set, use it
     if (isset($filter_cc)) {
         $sh->addConstraintChain($filter_cc);
     }
     $measure_fields = array_merge(array('' => 'report'), $measure_fields);
     /// merge the aggregate methods array in with the display fields array
     // the aggregate methods array is preset as an array to allow for empty values
     // we don't use the array_merge function as we want to maintain keys (representing position)
     $display_fields = (array) $display_fields + (array) $aggregate_methods;
     if (count($aggregate_fields) === 0) {
         $this->view->set('aggregate_count', 0);
     }
     // sort display fields by key (position)
     ksort($display_fields);
     // prepend the id field to the display fields...
     // at this stage the items are in order, so keys don't matter
     $display_fields = array_merge(array($idField), $display_fields);
     $sh->setFields($display_fields);
     $data = $doc->load($sh, null, RETURN_ROWS);
     $this->view->set('total_records', $doc->total_records);
     $headings = $doc->getHeadings();
     // loop through headings...
     foreach ($headings as $key => $field) {
         if (!array_search($key, $original_fields)) {
             // if item isn't in original fields remove it from headings array
             unset($headings[$key]);
         } else {
             // if label exists, use that for heading
             if (!empty($options[$key]['normal_field_label'])) {
                 $headings[$key] = $options[$key]['normal_field_label'];
             }
         }
     }
     $heading_keys = array_keys($headings);
     $this->view->set('headings', $headings);
     /*
      * Build the data array
      * 
      * There is no point in processing everything just to output the 
      * print dialog OR is we're CSVing the output.
      */
     if (!isset($this->_data['printaction']) && !isset($this->_data['printAction']) || $this->_data['print']['printtype'] !== 'csv') {
         $response = $this->buildArray($data, $headings, $measure_fields, $aggregate_fields, $heading_keys, $options);
         $data_arr = $response['data_arr'];
         $sub_total_keys = $response['sub_total_keys'];
     }
     $this->view->set('options', $options);
     // are we being called from a print dialog or are we actually printing?
     if (isset($this->_data['printaction']) || isset($this->_data['printAction']) || isset($this->_data['ajax_print'])) {
         if ($this->_data['print']['printtype'] === 'csv') {
             $dialog_options['csv_source'] = $this->generate_csv($this->_data['print'], $data_arr, array_keys($headings));
         } else {
             // build xml
             $xml = '';
             $xml .= "<data>" . "\n";
             if (!empty($data_arr)) {
                 foreach ($data_arr as $key => $row) {
                     // if row is a subtotal, construct an appropriate attribute
                     $row_class = '';
                     if (isset($sub_total_keys[$key])) {
                         $row_class = 'sub_total="true"';
                     }
                     // build the xml
                     // cannot utalise all of the output functions as we need to do some specific stuff
                     $xml .= "\t" . "<record " . $row_class . ">" . "\n";
                     foreach ($row as $field => $value) {
                         $cell_class = array();
                         if (isset($options[$field]['normal_red_negative_numbers']) && $options[$field]['normal_red_negative_numbers'] == "true" && $value < 0) {
                             $cell_class[] = 'negative_number="true"';
                         }
                         if ($options[$field]['normal_enable_formatting'] === 'true') {
                             if (isset($options[$field]['normal_justify'])) {
                                 $cell_class[] = 'text-align="' . $options[$field]['normal_justify'] . '"';
                             }
                         }
                         $xml .= "\t\t" . "<" . $field . " " . implode(' ', $cell_class) . ">" . $value . "</" . $field . ">" . "\n";
                     }
                     $xml .= "\t" . "</record>" . "\n";
                 }
             }
             $xml .= "</data>" . "\n";
             // build xsl
             $col_widths = array();
             if (isset($this->_data['col_widths'])) {
                 $col_widths = $this->parse_column_widths($this->_data['col_widths']);
             }
             // Use the report defintion defined in DB, else use the standard list xsl
             if ($report->report_definition) {
                 $def = new ReportDefinition();
                 $def->loadBy('id', $report->report_definition);
                 $report_definition_name = $def->_data['name'];
             } else {
                 $report_definition_name = 'PrintCollection';
             }
             $xsl = $this->build_custom_xsl($doc, $report_definition_name, $report->description, $headings, $col_widths, $options);
             // set resources
             $dialog_options['xmlSource'] = $xml;
             $dialog_options['xslSource'] = $xsl;
             $search_options = $this->search->toString('fop');
             if (!empty($search_options)) {
                 $dialog_options['xslVars']['search_string'] = "Search options: " . $search_options;
             } else {
                 $dialog_options['xslVars']['search_string'] = '';
             }
         }
         $this->_data['print']['attributes']['orientation-requested'] = 'landscape';
         // execute the print output function, echo the returned json for jquery
         echo $this->generate_output($this->_data['print'], $dialog_options);
         exit;
     }
     $this->view->set('report_array', $data_arr);
     $this->view->set('sub_total_keys', $sub_total_keys);
 }
コード例 #21
0
ファイル: Employee.php プロジェクト: uzerpllp/uzerp
 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;
 }
コード例 #22
0
 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);
     }
 }
コード例 #23
0
 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);
 }
コード例 #24
0
ファイル: AccessObject.php プロジェクト: uzerpllp/uzerp
 public function getUserModules($username = EGS_USERNAME, $cc = null)
 {
     // Get the roles for the user
     $hasrole = DataObjectFactory::Factory('HasRole');
     $roles = $hasrole->getRoleID($username);
     $hp = new HasPermissionCollection();
     if (!$cc instanceof ConstraintChain) {
         $cc = new ConstraintChain();
     }
     // Only interested in top level permissions
     $cc->add(new Constraint('type', 'in', "('g', 'm')"));
     if (!empty($roles)) {
         $cc->add(new Constraint('roleid', 'in', '(' . implode(',', $roles) . ')'));
     }
     $sh = new SearchHandler($hp, FALSE);
     $sh->addConstraintChain($cc);
     return $hp->load($sh, null, RETURN_ROWS);
 }
コード例 #25
0
 public function select_for_payment()
 {
     $errors = array();
     $supplier = DataObjectFactory::Factory('plsupplier');
     if (isset($this->_data['plmaster_id'])) {
         $supplier->load($this->_data['plmaster_id']);
     }
     // Search
     $s_data = array();
     // Set context from calling module
     if ($supplier) {
         $s_data['plmaster_id'] = $supplier->id;
     }
     $params = DataObjectFactory::Factory('GLParams');
     $s_data['currency_id'] = $params->base_currency();
     $paytype = DataObjectFactory::Factory('PaymentType');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('method_id', 'is not', 'NULL'));
     $paytypes = $paytype->getAll($cc);
     $paytype_ids = array_keys($paytypes);
     $s_data['payment_type_id'] = $paytype_ids[0];
     $this->setSearch('pltransactionsSearch', 'select_payments', $s_data);
     // End of search
     $cc = '';
     if (isset($this->search)) {
         $cc = new ConstraintChain();
         $cc = $this->search->toConstraintChain();
     }
     $transaction = DataObjectFactory::Factory('PLTransaction');
     $transactions = new PLTransactionCollection($transaction, 'pl_allocation_overview');
     $sh = new SearchHandler($transactions, false);
     $sh->addConstraint(new Constraint('status', '=', 'O'));
     $sh->addConstraintChain($cc);
     $sh->setOrderby(array('supplier', 'our_reference'));
     $transactions->load($sh);
     $this->view->set('transactions', $transactions);
     $this->view->set('no_ordering', true);
     $sidebar = new SidebarController($this->view);
     $sidebarlist = array();
     $this->sidebarIndex($sidebarlist);
     $this->sidebarAllPayments($sidebarlist);
     $sidebar->addList('Actions', $sidebarlist);
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
 }
コード例 #26
0
ファイル: Party.php プロジェクト: uzerpllp/uzerp
 public function getContactMethods($type = '', $cc = '')
 {
     $cms = new PartyContactMethodCollection();
     $sh = new SearchHandler($cms, false);
     $sh->setOrderby(array('type', 'name'));
     if (!empty($type)) {
         $sh->addConstraint(new Constraint('type', '=', $type));
     }
     $sh->addConstraint(new Constraint('party_id', '=', $this->party_id));
     if (!empty($cc) && $cc instanceof ConstraintChain) {
         $sh->addConstraintChain($cc);
     }
     $cms->load($sh);
     return $cms;
 }
コード例 #27
0
ファイル: IndexController.php プロジェクト: uzerpllp/uzerp
 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;
 }
コード例 #28
0
ファイル: DatasetsController.php プロジェクト: uzerpllp/uzerp
 function save_field()
 {
     if (!isset($this->_data['DatasetField'])) {
         $this->dataError();
         sendBack();
     }
     $dataset = $this->_uses[$this->modeltype];
     $data = $this->_data['DatasetField'];
     $data['old_name'] = $data['name'];
     $data['name'] = strtolower(str_replace(' ', '_', $data['title']));
     if (!empty($data['module_component_id'])) {
         $data['name'] .= '_id';
         $data['type'] = $dataset::get_fk_field_type();
     }
     $booleans = array('mandatory', 'searchable', 'display_in_list');
     foreach ($booleans as $field) {
         if (!isset($data[$field])) {
             $data[$field] = FALSE;
         } else {
             $data[$field] = TRUE;
         }
     }
     $db = DB::Instance();
     $flash = Flash::Instance();
     $errors = array();
     if (empty($data['id'])) {
         $action = 'add';
     } else {
         $action = 'alter';
         $current_field = DataObjectFactory::Factory('DatasetField');
         $current_field->load($data['id']);
     }
     $db->StartTrans();
     $dataset->load($data['dataset_id']);
     if ($data['mandatory']) {
         $model = $this->newModel($dataset);
         $cc = new ConstraintChain();
         if ($action == 'alter') {
             $cc->add(new Constraint($data['name'], 'IS', 'NULL'));
         }
         if ($model->getCount($cc) > 0) {
             if (!$action == 'alter') {
                 $errors[] = 'Data exists so first add the field then make it mandatory';
             } elseif ($data['default_value'] == '') {
                 $errors[] = 'Default Value required to make this field mandatory';
             } else {
                 $collection = new DataObjectCollection($model);
                 $sh = new SearchHandler($collection);
                 $sh->addConstraintChain($cc);
                 if (!$collection->update($data['name'], $data['default_value'], $sh)) {
                     $errors[] = 'Error updating existing data for ' . $data['title'] . ' with default value';
                 }
             }
         }
     }
     $datasetfield = DataObject::Factory($data, $errors, 'DatasetField');
     // TODO: if this is an update, only change table if field details have changed
     // otherwise do the change table to add the new field
     if (count($errors) > 0 || !$datasetfield || !$datasetfield->save() || !$this->change_table($data, $action)) {
         $errors[] = 'Error ' . (action == 'alter' ? 'updating' : 'inserting') . ' ' . $data['title'] . ' field definition : ' . $db->ErrorMsg();
         $db->FailTrans();
         $db->CompleteTrans();
     } else {
         $db->CompleteTrans();
         $this->createOverview($dataset, $errors);
     }
     if (count($errors) > 0) {
         $flash->addErrors($errors);
     } else {
         $flash->addMessage('"' . $data['title'] . '" field saved OK');
     }
     sendTo($this->name, 'view', $this->_modules, array($dataset->idField => $data['dataset_id']));
 }
コード例 #29
0
 public function make_inactive()
 {
     if (!$this->loadData()) {
         $this->dataError();
         sendBack();
     }
     $customer = $this->_uses[$this->modeltype];
     $flash = Flash::Instance();
     // Check to make sure no-one has updated the customer
     if ($customer->hasCurrentActivity()) {
         $flash->addError('Error making customer inactive - customer is still active');
     } else {
         $customer->date_inactive = fix_date(date(DATE_FORMAT));
         $db = DB::Instance();
         $db->StartTrans();
         if (!$customer->save()) {
             $flash->addError('Error making customer inactive: ' . $db->ErrorMsg());
             $db->FailTrans();
         } else {
             // Now close off any open SO Product Lines for the Customer
             $soproductline = DataObjectFactory::Factory('SOProductline');
             $soproductlines = new SOProductlineCollection($soproductline);
             $sh = new SearchHandler($soproductlines, FALSE);
             $sh->addConstraintChain($soproductline->currentConstraint());
             $sh->addConstraint(new Constraint('slmaster_id', '=', $customer->id));
             if ($soproductlines->update('end_date', $customer->date_inactive, $sh) !== FALSE) {
                 $flash->addMessage('Customer marked as inactive');
             } else {
                 $flash->addError('Error closing off customer product lines: ' . $db->ErrorMsg());
                 $db->FailTrans();
             }
         }
         $db->CompleteTrans();
     }
     sendBack();
 }
コード例 #30
0
ファイル: WhbinsController.php プロジェクト: uzerpllp/uzerp
 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);
 }