public static function useDefault($search_data = null, &$errors = array(), $defaults = null) { $search = new VatSearch($defaults); $search->addSearchField('box', 'Box', 'hidden', '', 'hidden'); $default_year = date('Y'); $default_tax_period = 1; $glperiod = GLPeriod::getPeriod(date('Y-m-d')); if ($glperiod && count($glperiod) > 0) { $default_year = $glperiod['year']; $default_tax_period = $glperiod['tax_period']; } $search->addSearchField('year', 'Year', 'select', $default_year, 'basic'); $search->addSearchField('tax_period', 'Tax Period', 'select', $default_tax_period, 'basic'); $glperiods = new GLPeriodCollection(); $sh = new SearchHandler($glperiods, false); $sh->setOrderBy('year'); $glperiods->load($sh); $glperiods = $glperiods->getContents(); $options = array(); foreach ($glperiods as $glperiod) { if (!array_key_exists($glperiod->year, $options)) { $options[$glperiod->year] = $glperiod->year; } } $search->setOptions('year', $options); $tax_periods = GLPeriod::getTaxPeriods(); $options = array_combine($tax_periods, $tax_periods); $search->setOptions('tax_period', $options); $search->setSearchData($search_data, $errors); return $search; }
function populate() { $tickets = new TicketCollection(new Ticket()); $pl = new PageList('current_tickets'); $ticket_sh = new SearchHandler($tickets, false); $ticket_sh->setLimit(10); $ticket_sh->setOrderBy('created', 'ASC'); $user = new User(); $user->loadBy('username', EGS_USERNAME); $ticket_sh->addConstraint(new Constraint('originator_person_id', '=', $user->username)); $ticket_sh->addConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID)); // Find open statuses $statuses = new TicketStatusCollection(new TicketStatus()); $status_sh = new SearchHandler($statuses); $status_sh->addConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID)); $status_sh->addConstraint(new Constraint('status_code', '=', 'NEW'), 'OR'); $status_sh->addConstraint(new Constraint('status_code', '=', 'OPEN'), 'OR'); $statuses->load($status_sh); foreach ($statuses->getContents() as $status) { $ticket_sh->addConstraint(new Constraint('client_ticket_status_id', '=', $status->id), 'OR'); } $tickets->load($ticket_sh); $pl->addFromCollection($tickets, array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'view'), array('id'), 'ticket', 'summary'); $this->contents = $pl->getPages()->toArray(); }
public function _new() { parent::_new(); // For new actions the stitem_id and from_uom_id will be set // For edit actions, the id will be set pointing to the uom conversion to be edited if ($this->_data['action'] == 'edit') { $stuom = $this->_uses[$this->modeltype]; $stitem_id = $stuom->stitem_id; $stitem_uom_id = $stuom->from_uom_id; $stitem_uom_name = $stuom->from_uom_name; } else { $stitem = new STitem(); $stitem->load($this->_data['stitem_id']); $stitem_id = $stitem->id; $stitem_uom_id = $stitem->uom_id; $stitem_uom_name = $stitem->uom_name; } $this->view->set('stitem_id', $stitem_id); $this->view->set('stitem_uom_id', $stitem_uom_id); $this->view->set('stitem_uom_name', $stitem_uom_name); $this->view->set('stitem', Stuomconversion::getStockItem($stitem_id)); $elements = new STuomconversionCollection(new STuomconversion()); $sh = new SearchHandler($elements, false); $sh->extract(); $sh->addConstraint(new Constraint('stitem_id', '=', $stitem_id)); $sh->setOrderBy('from_uom_name'); $sh->extractOrdering(); $sh->extractPaging(); $elements->load($sh); $this->view->set('elements', $elements); $this->view->set('no_ordering', true); }
function __construct($tablename = 'projects') { // Register non-persistent attributes // Contruct the object parent::__construct($tablename); // Set specific characteristics $this->idField = 'id'; $this->identifierField = array('job_no', 'name'); $this->orderby = 'job_no'; // Define relationships $this->belongsTo('Company', 'company_id', 'company'); $this->belongsTo('User', 'owner', 'project_owner'); $this->belongsTo('User', 'altered_by', 'altered'); $this->belongsTo('Person', 'person_id', 'person', null, "surname || ', ' || firstname"); $cc = new ConstraintChain(); $cc->add(new Constraint('company_id', '=', EGS_COMPANY_ID)); $this->belongsTo('Person', 'key_contact_id', 'key_contact', $cc, "surname || ', ' || firstname"); $this->belongsTo('Opportunity', 'opportunity_id', 'opportunity'); $this->belongsTo('Projectcategory', 'category_id', 'category'); $this->belongsTo('Projectworktype', 'work_type_id', 'work_type'); $this->belongsTo('Projectphase', 'phase_id', 'phase'); $this->hasMany('ProjectBudget', 'budgets'); $this->hasMany('Task', 'tasks'); // $this->hasMany('ProjectIssue','issues'); $this->hasMany('ProjectNote', 'notes'); $this->hasMany('Hour', 'hours'); $this->hasMany('Expense', 'expenses'); $this->hasMany('Resource', 'resources'); // Note: 'projectattachment' model does not exist - it is here to generate // the sidebar related link to projectattachmentcontroller $this->hasMany('projectattachment', 'attachments'); $this->hasMany('LoggedCall', 'calls'); $this->hasMany('ProjectEquipmentAllocation', 'equipment_allocations', 'project_id'); $this->hasMany('ProjectCostCharge', 'actuals', 'project_id'); // $this->hasMany('ProjectCostCharge', 'purchase_orders', 'project_id'); // $this->hasMany('ProjectCostCharge', 'sales_invoices', 'project_id'); $this->hasMany('POrder', 'porders'); $this->hasMany('PInvoice', 'pinvoices'); $this->hasMany('SOrder', 'sorders'); $this->hasMany('SInvoice', 'sinvoices'); $this->hasMany('MFWorkorder', 'mfworkorders'); $tasks = new TaskCollection(new Task()); $sh = new SearchHandler($tasks, false); $sh->addConstraint(new Constraint('parent_id', ' is ', 'NULL')); $sh->setOrderBy('start_date'); $this->addSearchHandler('tasks', $sh); // Define field formats $this->getField('cost')->setFormatter(new PriceFormatter()); $this->getField('value')->setFormatter(new PriceFormatter()); // Define field defaults $this->getField('status')->setDefault('N'); // Define validation $this->validateUniquenessOf(array("job_no")); // Define enumerated types $this->setEnum('status', array('N' => 'New', 'A' => 'Active', 'C' => 'Complete', 'X' => 'Cancelled')); // Define link rules for sidebar related view $this->linkRules = array('expenses' => array('modules' => array('link' => array('module' => 'hr'), 'new' => array('module' => 'hr')), 'actions' => array('link', 'new'), 'rules' => array()), 'mfworkorders' => array('modules' => array('link' => array('module' => 'manufacturing')), 'actions' => array('link'), 'rules' => array(), 'label' => 'Show Works Orders'), 'porders' => array('modules' => array('link' => array('module' => 'purchase_order'), 'new' => array('module' => 'purchase_order')), 'actions' => array('link', 'new'), 'rules' => array(), 'label' => 'Show Purchase Orders'), 'pinvoices' => array('modules' => array('link' => array('module' => 'purchase_invoicing'), 'new' => array('module' => 'purchase_invoicing')), 'actions' => array('link', 'new'), 'rules' => array(), 'label' => 'Show Purchase Invoices'), 'sorders' => array('modules' => array('link' => array('module' => 'sales_order'), 'new' => array('module' => 'sales_order')), 'actions' => array('link'), 'rules' => array(), 'label' => 'Show Sales Orders'), 'sinvoices' => array('modules' => array('link' => array('module' => 'sales_invoicing'), 'new' => array('module' => 'sales_invoicing')), 'actions' => array('link'), 'rules' => array(), 'label' => 'Show Sales Invoices')); }
public function showParts($id) { $elements = new MFWOStructureCollection(new MFWOStructure()); $sh = new SearchHandler($elements, false); $sh->addConstraint(new Constraint('work_order_id', '=', $id)); $sh->setOrderBy('line_no'); $sh->extractOrdering(); $elements->load($sh); return $elements; }
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); }
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); }
public function getAuthSummary($_order_id) { $sh = new SearchHandler($this, false); $fields = array("glcentre||' '||glaccount", 'glcentre_id', 'glaccount_id'); $sh->setGroupBy($fields); $sh->setOrderBy($fields); $fields[] = 'sum(base_net_value) as net_value'; $sh->setFields($fields); $sh->addConstraint(new Constraint('order_id', '=', $_order_id)); $sh->addConstraint(new Constraint('status', '!=', $this->_templateobject->cancelStatus())); $this->load($sh); }
function populate() { $pl = new PageList('open_opportunities'); $open_opportunities = new OpportunityCollection(new Opportunity()); $sh = new SearchHandler($open_opportunities, false); $sh->extract(); $sh->addConstraint(new Constraint('owner', '=', EGS_USERNAME)); $sh->addConstraint(new Constraint('open', '=', 'true')); $sh->setLimit(10); $sh->setOrderBy('cost', 'DESC'); $open_opportunities->load($sh); $pl->addFromCollection($open_opportunities, array('module' => 'crm', 'controller' => 'opportunitys', 'action' => 'view'), array('id'), 'opportunity', 'name'); $this->setData($pl->getPages()->toArray()); }
function populate() { $pl = new PageList('current_activities'); $current_activities = new ActivityCollection(new Activity()); $sh = new SearchHandler($current_activities, false); $sh->extract(); $sh->addConstraint(new Constraint('assigned', '=', EGS_USERNAME)); $sh->addConstraint(new Constraint('completed', 'IS', 'NULL')); $sh->addConstraint(new Constraint('startdate', '<', '(now())')); $sh->setLimit(10); $sh->setOrderBy('created', 'DESC'); $current_activities->load($sh); $pl->addFromCollection($current_activities, array('module' => 'crm', 'controller' => 'activitys', 'action' => 'view'), array('id'), 'activity', 'name'); $this->contents = $pl->getPages()->toArray(); }
function getAuthList($account = '', $centre = '', $value = '') { $this->_tablename = "po_authlist"; $sh = new SearchHandler($this, false); if (!empty($account)) { $sh->addConstraint(new Constraint('glaccount_id', '=', $account)); } if (!empty($centre)) { $sh->addConstraint(new Constraint('glcentre_id', '=', $centre)); } if (!empty($value)) { $sh->addConstraint(new Constraint('order_limit', '>=', $value)); } $sh->setOrderBy('username'); $this->load($sh); }
function populate() { if (!$this->isCached()) { $pl = new PageList('recently_added_leads'); $companies_do = new CompanyCollection(new Company()); $sh = new SearchHandler($companies_do, false); $sh->extract(); $sh->addConstraint(new Constraint('is_lead', '=', 'true')); $sh->setLimit(10); $sh->setOrderBy('created', 'DESC'); $companies_do->load($sh); $pl->addFromCollection($companies_do, array('module' => 'contacts', 'controller' => 'companys', 'action' => 'view'), array('id'), 'company', 'name'); $this->setCache($pl->getPages()->toArray()); } $this->contents = $this->getCache(); }
function populate() { $pl = new PageList('my_tickets'); $my_tickets = new TicketCollection(new Ticket()); $sh = new SearchHandler($my_tickets, false); $sh->extract(); $sh->addConstraint(new Constraint('assigned_to', 'IS', 'NULL')); $cc = new ConstraintChain(); $cc->add(new Constraint('internal_status_code', '=', 'NEW'), 'OR'); $cc->add(new Constraint('internal_status_code', '=', 'OPEN'), 'OR'); $sh->addConstraintChain($cc); $sh->setLimit(10); $sh->setOrderBy('created', 'DESC'); $my_tickets->load($sh); $pl->addFromCollection($my_tickets, array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'view'), array('id'), 'ticket', 'summary'); $this->contents = $pl->getPages()->toArray(); }
function statusSummary($orderline_id) { // Returns an array of the statuses of POReceived lines // for the supplied orderline_id // i.e. there can be more than one received line (part delivery) for an order line $sh = new SearchHandler($this, false); $sh->addConstraint(new Constraint('orderline_id', '=', $orderline_id)); $sh->setFields(array('status', 'sum(received_qty) as received_qty')); $sh->setGroupBy(array('status')); $sh->setOrderBy(array('status')); $rows = $this->load($sh, null, RETURN_ROWS); $status = array(); foreach ($rows as $line) { $status[$line['id']] = $line['received_qty']; } return $status; }
function populate() { $module = DataObjectFactory::Factory('ModuleObject'); $module->loadBy('name', $_GET['module']); $files = new EntityAttachmentCollection(); $files->setParams(); $pl = new PageList(' Documents'); $sh = new SearchHandler($files, FALSE); $fields = array('id', 'file as document', 'revision', 'note', 'file_id'); $sh->setOrderBy('file'); $sh->setFields($fields); $sh->addConstraint(new Constraint('entity_id', '=', $module->id)); $sh->addConstraint(new Constraint('data_model', '=', 'moduleobject')); $this->setSearchLimit($sh); $files->load($sh); $this->contents = $files; $ao = AccessObject::Instance(); $this->contents->can_upload = $ao->hasPermission($_GET['module'], 'attachments', 'new'); }
public function view() { if (!$this->loadData()) { $this->dataError(); sendBack(); } $ticket = $this->_uses[$this->modeltype]; $sidebar = new SidebarController($this->view); $sidebar->addList('Actions', array('all' => array('tag' => 'View All Tickets', 'link' => array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'index')))); $sidebar->addList('currently_viewing', array($ticket->summary => array('tag' => $ticket->summary, 'link' => array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'view', 'id' => $ticket->id)), 'edit' => array('tag' => 'Edit', 'link' => array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'edit', 'id' => $ticket->id)), 'add_response' => array('tag' => 'Add Response', 'link' => array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'add_response', 'id' => $ticket->id)), 'extract_change_log' => array('tag' => 'extract_change_log', 'link' => array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'extract_change_log', 'id' => $ticket->id)))); $sidebar->addList('related_items', array('attachments' => array('tag' => 'Attachments', 'link' => array('module' => 'ticketing', 'controller' => 'attachments', 'action' => 'viewticket', 'ticket_id' => $ticket->id), 'new' => array('module' => 'ticketing', 'controller' => 'attachments', 'action' => 'new', 'ticket_id' => $ticket->id)), 'hours' => array('tag' => 'Hours', 'link' => array('module' => 'ticketing', 'controller' => 'hours', 'action' => 'viewticket', 'ticket_id' => $ticket->id), 'new' => array('module' => 'ticketing', 'controller' => 'hours', 'action' => 'new', 'ticket_id' => $ticket->id)), 'components' => array('tag' => 'Components Affected', 'link' => array('module' => 'ticketing', 'controller' => 'ticketmoduleversions', 'action' => 'viewticket', 'ticket_id' => $ticket->id)))); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); $responses = new TicketResponseCollection(new TicketResponse()); $sh = new SearchHandler($responses, false); $sh->AddConstraint(new Constraint('ticket_id', '=', $ticket->id)); $sh->setOrderBy('created', 'asc'); $responses->load($sh); $pageResponses = array(); foreach ($responses->getContents() as $response) { if ($response->internal === 't') { $response->type = 'internal'; } $pageResponses[] = $response; } $this->view->set('responses', $pageResponses); $ao = AccessObject::Instance(); $this->view->set('ticketing_client', false); if ($ao->hasPermission('ticketing_client')) { $this->view->set('ticketing_client', true); } $db = DB::Instance(); $query = 'SELECT ceil((EXTRACT(hour FROM SUM(duration)) + (EXTRACT(minute FROM SUM (duration))/60))*4)/4 AS duration FROM hours WHERE ticket_id = ' . $db->qstr($ticket->id); $duration = $db->GetOne($query); if ($duration === null) { $this->view->set('duration', 0 . ' hours'); } else { $this->view->set('duration', $duration . ' hours'); } }
function getServiceHistory() { $enddate = fix_date('01/' . date('m/Y')); $startdate = fix_date(date(DATE_FORMAT, strtotime("-12 months", strtotime($enddate)))); $enddate = fix_date(date(DATE_FORMAT)); $this->_tablename = 'customer_service_summary'; $sh = new SearchHandler($this, FALSE); $sh->addConstraint(new Constraint('despatch_date', 'between', "'" . $startdate . "' and '" . $enddate . "'")); $sh->setFields(array('year_month', 'sum(ontime) as ontime', 'sum(infull) as infull', 'sum(otif) as otif', 'sum(count) as count')); $sh->setGroupBy("year_month"); $sh->setOrderBy("year_month"); $this->load($sh); for ($i = 0; $i < 13; $i++) { $date = date('Y/m', strtotime("+" . $i . " months", strtotime($startdate))); $this->customerorders['previous'][$date]['ontime'] = 0; $this->customerorders['previous'][$date]['infull'] = 0; $this->customerorders['previous'][$date]['ontime_infull'] = 0; $this->customerorders['previous'][$date]['count'] = 0; } foreach ($this as $despatch) { if (isset($this->customerorders['previous'][$despatch->id])) { $this->customerorders['previous'][$despatch->id]['ontime'] = $despatch->ontime; $this->customerorders['previous'][$despatch->id]['infull'] = $despatch->infull; $this->customerorders['previous'][$despatch->id]['ontime_infull'] = $despatch->otif; $this->customerorders['previous'][$despatch->id]['count'] = $despatch->count; } } foreach ($this->customerorders['previous'] as $date => $month) { if ($month['count'] == 0) { $this->customerorders['previous'][$date]['ontime%'] = 0; $this->customerorders['previous'][$date]['infull%'] = 0; $this->customerorders['previous'][$date]['ontime_infull%'] = 0; } else { $this->customerorders['previous'][$date]['ontime%'] = $month['ontime'] * 100 / $month['count']; $this->customerorders['previous'][$date]['infull%'] = $month['infull'] * 100 / $month['count']; $this->customerorders['previous'][$date]['ontime_infull%'] = $month['ontime_infull'] * 100 / $month['count']; } } return $this->customerorders; }
function getYearEndBalances($glperiod_ids, $type) { if (count($glperiod_ids) > 0) { $sh = new SearchHandler($this, false); switch ($type) { case 'P': $fields = array('actype'); break; case 'B': $fields = array('glcentre_id||\'-\'||glaccount_id', 'glcentre_id', 'glaccount_id'); break; } $sh->setGroupBy($fields); $sh->setOrderBy($fields); $fields[] = 'sum(value) as value'; $sh->setFields($fields); $periodsYTD = '(' . implode(',', $glperiod_ids) . ')'; $sh->addConstraint(new Constraint('actype', '=', $type)); $sh->addConstraint(new Constraint('glperiods_id', 'in', $periodsYTD)); $this->load($sh); } }
function populate() { $orderline = DataObjectFactory::Factory('SOrderLine'); $cc = new ConstraintChain(); $cc->add(new Constraint('status', 'in', "('D', 'P')")); $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', 'actual_despatch_date'); $sh->setGroupBy($fields); $sh->setOrderBy(array('actual_despatch_date', 'order_number', 'customer')); $fields[] = 'sum(base_net_value) as base_net_value'; $sh->setFields($fields); $sh->addConstraint($cc); $this->setSearchLimit($sh); $orders->load($sh); $orders->collection_date_label = 'actual_despatch_date'; $orders->collection_total_label = 'Total (Base Net Value) Order Lines not Invoiced'; $orders->collection_total = $order_total; $this->contents = $orders; }
protected function getLineStatuses($_orderline, $_orderlines) { $linestatus = array(); $statuses = $_orderline->getEnumOptions('status'); foreach ($statuses as $key => $name) { $linestatus['linecount'] = 0; $linestatus['count'][$key] = 0; $linestatus['value'][$name] = 0; } $sh = new SearchHandler($_orderlines, false); $sh->setFields(array('status', 'sum(net_value) as net_value', 'count(*) as count')); $sh->setGroupBy('status'); $sh->setOrderBy('status'); $sh->addConstraint(new Constraint('order_id', '=', $this->id)); $_orderlines->load($sh); if ($_orderlines->count() > 0) { foreach ($_orderlines as $status) { $linestatus['linecount'] += $status->count; $linestatus['count'][$status->id] = $status->count; $linestatus['value'][$statuses[$status->id]] = $status->net_value; } } return $linestatus; }
public function getTaxPeriodEnd($tax_period, $year) { $cc = new ConstraintChain(); $cc->add(new Constraint('tax_period', '=', $tax_period)); $cc->add(new Constraint('year', '=', $year)); $sh = new SearchHandler(new GLPeriodCollection($this), false); $sh->addConstraintChain($cc); $sh->setOrderBy('enddate', 'DESC'); $this->loadBy($sh); }
public function getHours($_start_date = '', $_end_date = '', $_user = '') { // Used by Ajax to get a list of hours for a user between two dates if (isset($this->_data['ajax'])) { if (!empty($this->_data['start_date'])) { $_start_date = fix_date($this->_data['start_date']); } if (!empty($this->_data['end_date'])) { $_end_date = $this->_data['end_date']; } if (!empty($this->_data['person_id'])) { $_user = $this->_data['person_id']; } } if (empty($_start_date)) { $_start_date = fix_date(date(DATE_FORMAT)); } if (empty($_end_date)) { $_end_date = fix_date(date(DATE_FORMAT, strtotime("+1 day", strtotime($_start_date)))); } if (empty($_user)) { $user = getCurrentUser(); if (!is_null($user->person_id)) { $_user = $user->person_id; } } $hours = new HourCollection(); if (!empty($_user)) { $sh = new SearchHandler($hours, false); $sh->addConstraint(new Constraint('person_id', '=', $_user)); $sh->addConstraint(new Constraint('start_time', 'between', "'" . $_start_date . "' and '" . $_end_date . "'")); $sh->setFields(array('id', 'start_time', 'type', 'duration')); $sh->setOrderBy('start_time', 'ASC'); $hours->load($sh); } if (isset($this->_data['ajax'])) { $this->view->set('no_ordering', true); $this->view->set('collection', $hours); $this->view->set('showheading', true); $this->setTemplateName('datatable_inline'); } else { return $hours; } }
public function getChildrenAsDOC($doc = null, $sh = null) { if ($doc == null) { $doc = new TaskCollection($this); } if ($sh == null) { $sh = new SearchHandler($doc, false); $sh->setOrderBy('start_date'); } return parent::getChildrenAsDOC($doc, $sh); }
function getSalesHistory() { $db = DB::Instance(); $startmonth = fix_date('01/' . date('m/Y')); $currentmonth = date('Y/m'); $startdate = fix_date(date(DATE_FORMAT, strtotime("-12 months", strtotime($startmonth)))); $today = fix_date(date(DATE_FORMAT)); $enddate = $today; $lastweekend = fix_date(date(DATE_FORMAT, strtotime("last sunday"))); $lastweekstart = fix_date(date(DATE_FORMAT, strtotime("-6 days", strtotime($lastweekend)))); $thisweekend = fix_date(date(DATE_FORMAT, strtotime("next sunday"))); $thisweekstart = fix_date(date(DATE_FORMAT, strtotime("-6 days", strtotime($thisweekend)))); $glperiod = DataObjectFactory::Factory('GLPeriod'); $currentperiod = $glperiod->loadPeriod(date(DATE_FORMAT)); $glperiod->loadBy(array('year', 'period'), array($currentperiod->year, 1)); $yearstart = fix_date($glperiod->getPeriodStartDate($currentperiod->id)); for ($i = 11; $i >= 0; $i--) { $date = date('Y/m', strtotime("+" . $i . " months", strtotime($startdate))); $this->customerorders['previous'][$date]['start_date'] = fix_date(date(DATE_FORMAT, strtotime("+" . $i . " months", strtotime($startdate)))); $this->customerorders['previous'][$date]['end_date'] = fix_date(date(DATE_FORMAT, strtotime("+" . ($i + 1) . " months", strtotime($startdate)) - 1)); $this->customerorders['previous'][$date]['value'] = '0.00'; } $this->customerorders['current']['today']['start_date'] = $today; $this->customerorders['current']['today']['end_date'] = $today; $this->customerorders['current']['today']['value'] = '0.00'; $this->customerorders['current']['this_week']['start_date'] = $thisweekstart; $this->customerorders['current']['this_week']['end_date'] = $thisweekend; $this->customerorders['current']['this_week']['value'] = '0.00'; $this->customerorders['current']['last_week']['start_date'] = $lastweekstart; $this->customerorders['current']['last_week']['end_date'] = $lastweekend; $this->customerorders['current']['last_week']['value'] = '0.00'; $this->customerorders['current']['this_month_to_date']['start_date'] = $startmonth; $this->customerorders['current']['this_month_to_date']['end_date'] = $today; $this->customerorders['current']['this_month_to_date']['value'] = '0.00'; $this->customerorders['current']['year_to_date']['start_date'] = $yearstart; $this->customerorders['current']['year_to_date']['end_date'] = $today; $this->customerorders['current']['year_to_date']['value'] = '0.00'; $current = DataObjectFactory::Factory('SInvoice'); $transaction_types = $current->getEnumOptions('transaction_type'); $multipliers = $current->getMultipliers(); foreach ($transaction_types as $transaction_type => $transaction_type_title) { $sh = new SearchHandler($this, false); $sh->setFields(array("to_char(invoice_date, 'YYYY/MM')", 'sum(base_net_value) as value')); $sh->setGroupBy("to_char(invoice_date, 'YYYY/MM')"); $sh->setOrderBy("to_char(invoice_date, 'YYYY/MM')"); $sh->addConstraint(new Constraint('invoice_date', 'between', "'" . $startdate . "' and '" . $enddate . "'")); $sh->addConstraint(new Constraint('transaction_type', '=', $transaction_type)); $this->load($sh); foreach ($this as $invoice) { $value = bcmul($invoice->value, $multipliers[$transaction_type]); if ($invoice->id == $currentmonth) { $this->customerorders['current']['this_month_to_date']['value'] = bcadd($value, $this->customerorders['current']['this_month_to_date']['value']); } else { $this->customerorders['previous'][$invoice->id]['value'] = bcadd($value, $this->customerorders['previous'][$invoice->id]['value']); } } $this->clear(); } foreach ($transaction_types as $transaction_type => $transaction_type_title) { $cc = new ConstraintChain(); $cc->add(new Constraint('invoice_date', 'between', "'" . $lastweekstart . "' and '" . $lastweekend . "'")); $cc->add(new Constraint('transaction_type', '=', $transaction_type)); $value = bcmul($current->getSum('base_net_value', $cc), $multipliers[$transaction_type]); $this->customerorders['current']['last_week']['value'] = bcadd($value, $this->customerorders['current']['last_week']['value']); } foreach ($transaction_types as $transaction_type => $transaction_type_title) { $cc = new ConstraintChain(); $cc->add(new Constraint('invoice_date', 'between', "'" . $thisweekstart . "' and '" . $thisweekend . "'")); $cc->add(new Constraint('transaction_type', '=', $transaction_type)); $value = bcmul($current->getSum('base_net_value', $cc), $multipliers[$transaction_type]); $this->customerorders['current']['this_week']['value'] = bcadd($value, $this->customerorders['current']['this_week']['value']); } foreach ($transaction_types as $transaction_type => $transaction_type_title) { $cc = new ConstraintChain(); $cc->add(new Constraint('invoice_date', '=', $db->qstr(fix_date(date(DATE_FORMAT))))); $cc->add(new Constraint('transaction_type', '=', $transaction_type)); $value = bcmul($current->getSum('base_net_value', $cc), $multipliers[$transaction_type]); $this->customerorders['current']['today']['value'] = bcadd($value, $this->customerorders['current']['today']['value']); } foreach ($transaction_types as $transaction_type => $transaction_type_title) { $cc = new ConstraintChain(); $cc->add(new Constraint('invoice_date', 'between', "'" . $yearstart . "' and '" . $thisweekend . "'")); $cc->add(new Constraint('transaction_type', '=', $transaction_type)); $value = bcmul($current->getSum('base_net_value', $cc), $multipliers[$transaction_type]); $this->customerorders['current']['year_to_date']['value'] = bcadd($value, $this->customerorders['current']['year_to_date']['value']); } return $this->customerorders; }
public function getEquipmentAllocation($_equipment_id = '', $_start_date = '', $_end_date = '') { if (!empty($this->_data['project_equipment_id'])) { $_equipment_id = $this->_data['project_equipment_id']; } if (!empty($this->_data['start_date'])) { $_start_date = $this->_data['start_date']; } if (!empty($this->_data['end_date'])) { $_end_date = $this->_data['end_date']; } $projectallocation = new ProjectEquipmentAllocation(); $allocationdates = new ProjectEquipmentAllocationCollection($projectallocation); $sh = new SearchHandler($allocationdates); $sh->addConstraint(new Constraint('project_equipment_id', '=', $_equipment_id)); $cc = new ConstraintChain(); $cc->add(new Constraint('start_date', 'between', "'" . fix_date($_start_date) . "' and '" . fix_date($_end_date) . "'")); $cc->add(new Constraint('end_date', 'between', "'" . fix_date($_start_date) . "' and '" . fix_date($_end_date) . "'"), 'OR'); $sh->addConstraintChain($cc); $sh->setFields(array('id', 'project', 'task', 'start_date', 'end_date')); $sh->setOrderBy('start_date'); $allocationdates->load($sh, false); $this->view->set('no_ordering', true); $this->view->set('collection', $allocationdates); $this->view->set('showheading', true); if (isset($this->_data['ajax'])) { $this->setTemplateName('datatable_inline'); } else { return $allocationdates; } }