Ejemplo n.º 1
0
 function moveStock($whtransfer, &$errors)
 {
     $data = array();
     $data['stitem_id'] = $this->stitem_id;
     $data['whaction_id'] = $whtransfer->transfer_action;
     $data['process_name'] = 'T';
     $data['process_id'] = $whtransfer->id;
     $data['remarks'] = $this->remarks;
     $data['from_whlocation_id'] = $this->from_whlocation_id;
     $data['to_whlocation_id'] = $this->to_whlocation_id;
     $data['qty'] = $this->transfer_qty;
     $db = DB::Instance();
     $db->StartTrans();
     $transactions = array();
     $transactions = STTransaction::prepareMove($data, $errors);
     if (count($transactions) > 0 && count($errors) == 0) {
         foreach ($transactions as $transaction) {
             if (!$transaction->save($errors)) {
                 $errors[] = 'Error saving transaction';
                 break;
             }
         }
     }
     if (count($errors) > 0) {
         $db->FailTrans();
     } else {
         $db->CompleteTrans();
     }
 }
Ejemplo n.º 2
0
 public function __construct(DB $db = null)
 {
     if ($db == null) {
         $this->db = DB::Instance();
     } else {
         $this->db = $db;
     }
     $config = $this->db->getConfig();
     $this->config = $config[$config['driver']];
     if ($this->table_name == null) {
         $this->table_name = strtolower(get_called_class());
         if (isset($this->config['prefix']) && !empty($this->config['prefix'])) {
             $this->table_name = $this->config['prefix'] . $this->table_name;
         }
     }
     if ($config['driver'] == 'mysql') {
         $this->driver = new Drivers\MySqlDriver();
     } elseif ($config['driver'] == 'sqlite') {
         $this->driver = new Drivers\SQLiteDriver();
     } else {
         $this->driver = new Drivers\DbDriver();
     }
     if (method_exists($this, "init")) {
         $this->init();
     }
 }
Ejemplo n.º 3
0
 function populate()
 {
     $orders = new CustomerServiceCollection(new SInvoiceLine());
     $customersales = $orders->getServiceHistory();
     $db =& DB::Instance();
     $types = array('ontime' => 'On Time', 'infull' => 'In Full', 'ontime_infull' => 'On Time / In Full');
     $label = array();
     $type_counter = 0;
     $sales_counter = 0;
     foreach ($types as $key => $title) {
         $data = array();
         $sales_counter = 0;
         foreach ($customersales['previous'] as $period => $value) {
             $data['x'][] = $period;
             $data['y'][] = (double) number_format($value[$key . '%'], 2);
             $label[$type_counter][$sales_counter] = $title . ': ' . number_format($value[$key . '%'], 2);
             $sales_counter++;
         }
         $options['seriesList'][] = array('label' => $title, 'legendEntry' => TRUE, 'data' => $data, 'markers' => array('visible' => TRUE, 'type' => 'circle'));
         $type_counter++;
     }
     $options['type'] = 'line';
     $options['identifier'] = __CLASS__;
     $options['labels'] = $label;
     $this->contents = json_encode($options);
 }
Ejemplo n.º 4
0
 static function getTransferId()
 {
     $db =& DB::Instance();
     $query = "SELECT NEXTVAL('wh_transfer_id_seq') as transfer_id";
     $result = $db->Execute($query);
     return $result->fetchObj();
 }
Ejemplo n.º 5
0
 public function save()
 {
     $flash = Flash::Instance();
     $errors = array();
     $db = DB::Instance();
     $db->StartTrans();
     if (isset($this->_data['permission'])) {
         $permissions = $this->_data['permission'];
         unset($this->_data['permission']);
     } else {
         $permissions = array();
     }
     if (isset($this->_data['admin'])) {
         $admin = $this->_data['admin'];
         unset($this->_data['admin']);
     } else {
         $admin = array();
     }
     if (parent::save('Role')) {
         $role = $this->saved_model;
         if (isset($this->_data['Role']['users']) && is_array($this->_data['Role']['users'])) {
             $users = $this->_data['Role']['users'];
             Role::setUsers($role, $users, $errors);
             $flash->addErrors($errors);
         }
         if ($role->setPermissions($permissions, $errors) && $role->setAdmin($admin)) {
             $db->CompleteTrans();
             sendTo('Roles', 'index', array('admin'));
         }
     }
     //	$db->FailTrans();
     //	$db->CompleteTrans();
     $this->refresh();
 }
Ejemplo n.º 6
0
 public function doLogin()
 {
     $username = $_POST['username'];
     $password = $_POST['password'];
     $db = DB::Instance();
     return $this->gateway->Authenticate(array('username' => $username, 'password' => $password, 'db' => $db));
 }
Ejemplo n.º 7
0
 function populate()
 {
     $orders = new SInvoiceCollection(new SInvoice());
     $customersales = $orders->getSalesHistory();
     $db =& DB::Instance();
     $param = new GLParams();
     $currency_symbol = utf8_decode($param->base_currency_symbol());
     $options = array();
     $options['header']['text'] = 'Sales this month ' . $param->base_currency_symbol() . $customersales['current']['this_month_to_date']['value'];
     $options['header']['text'] .= ' : this week ' . $param->base_currency_symbol() . $customersales['current']['this_week']['value'];
     $options['header']['text'] .= ' : last week ' . $param->base_currency_symbol() . $customersales['current']['last_week']['value'];
     $options['header']['textStyle']['font-size'] = '14pt';
     ksort($customersales['previous']);
     $options['date_axis'] = TRUE;
     $sales_counter = 0;
     // build up data array
     foreach ($customersales['previous'] as $period => $value) {
         $date = explode('/', $period);
         $data['x'][] = $date[1] . "/1/" . $date[0];
         $data['y'][] = (double) $value['value'];
         $label[0][$sales_counter++] = number_format($value['value'], 2);
     }
     $options['seriesList'][] = array('legendEntry' => FALSE, 'data' => $data, 'date_axis' => array('x' => TRUE), 'markers' => array('visible' => TRUE, 'type' => 'circle'));
     $options['type'] = 'line';
     $options['identifier'] = __CLASS__;
     $options['labels'] = $label;
     $this->contents = json_encode($options);
 }
 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');
 }
Ejemplo n.º 9
0
 function handle(DataObject $model)
 {
     $db = DB::Instance();
     $query = "SELECT id FROM glperiods WHERE enddate > now() ORDER BY enddate DESC LIMIT 1";
     $return = $db->GetOne($query);
     return intval($return);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 11
0
 /**
  * @param void
  * @return Constraint
  *
  * Produces a Constraint between two dates
  */
 public function toConstraint()
 {
     $db = DB::Instance();
     $c = false;
     $to = '';
     $from = '';
     if ($this->value_set) {
         $from = $this->value['from'];
         $to = $this->value['to'];
     } else {
         $from = $this->default['from'];
         $to = $this->default['to'];
     }
     switch ($this->type) {
         case 'between':
             if (!empty($from)) {
                 if (!empty($to)) {
                     $c = new Constraint($this->fieldname, 'between', $db->qstr(fix_date($from)) . ' and ' . $db->qstr(fix_date($to)));
                 } else {
                     $c = new Constraint($this->fieldname, '>=', $db->qstr(fix_date($from)));
                 }
             } else {
                 if (!empty($to)) {
                     $c = new Constraint($this->fieldname, '<=', $db->qstr(fix_date($to)));
                 }
             }
             break;
     }
     return $c;
 }
Ejemplo n.º 12
0
 function revalue($data, &$errors = array())
 {
     if (empty($data['transaction_date'])) {
         $data['transaction_date'] = date(DATE_FORMAT);
     }
     $glperiod = GLPeriod::getPeriod(fix_date($data['transaction_date']));
     if (!$glperiod || count($glperiod) == 0) {
         $errors[] = 'No period exists for this date';
         return false;
     }
     $data['value'] = bcsub($this->glbalance(), $data['new_balance']);
     $data['glperiods_id'] = $glperiod['id'];
     $data['source'] = 'C';
     $data['type'] = 'V';
     $data['glaccount_id'] = $this->currency_detail->writeoff_glaccount_id;
     $data['glcentre_id'] = $this->currency_detail->glcentre_id;
     GLTransaction::setTwinCurrency($data);
     $gl_trans[] = GLTransaction::Factory($data, $errors);
     $data['value'] = bcmul($data['value'], -1);
     $data['glaccount_id'] = $this->glaccount_id;
     $data['glcentre_id'] = $this->glcentre_id;
     GLTransaction::setTwinCurrency($data);
     $gl_trans[] = GLTransaction::Factory($data, $errors);
     $db = DB::Instance();
     $db->StartTrans();
     if (count($errors) == 0 && GLTransaction::saveTransactions($gl_trans, $errors)) {
         return $db->CompleteTrans();
     }
     $errors[] = 'Failed to save GL Transaction';
     $db->FailTrans();
     $db->CompleteTrans();
     return false;
 }
Ejemplo n.º 13
0
 function handle(DataObject $model)
 {
     $db = DB::Instance();
     $query = 'SELECT max(complaint_number) FROM ' . $model->getTableName() . ' WHERE usercompanyid=' . EGS_COMPANY_ID . ' AND "type"=' . $db->qstr($model->type);
     $current = $db->GetOne($query);
     return $current + 1;
 }
Ejemplo n.º 14
0
 function getFromUoM($from_uom_id)
 {
     $db = DB::Instance();
     $query = "select uom_name from st_uoms where id=" . $db->qstr($from_uom_id);
     $getFromUoM = $db->GetOne($query);
     return $getFromUoM;
 }
Ejemplo n.º 15
0
function GetCurPageParams()
{
    $PageId = ToolMethod::Instance()->GetPageId();
    $sql = "select PageId,ParamsId,ParamsType,ParamsName,FieldsId,FieldsName\n\t\t\tfrom config_page_param\n\t\t\twhere PageId='" . $PageId . "'";
    $tmp = DB::Instance()->GetFirstRow($sql);
    $ParamsId = explode(",", $tmp["ParamsId"]);
    // , 隔开
    $ParamsType = explode(",", $tmp["ParamsType"]);
    $ParamsName = explode(",", $tmp["ParamsName"]);
    $FieldsId = explode(",", $tmp["FieldsId"]);
    $FieldsName = explode(",", $tmp["FieldsName"]);
    if (count($ParamsId) == count($ParamsType) && count($ParamsId) == count($ParamsName) && count($ParamsType) == count($ParamsName) && count($FieldsId) == count($FieldsName)) {
        $sql = "select tb2.BtnId,tb2.BtnClass,tb2.BtnName,tb2.BtnIcon\n\t\t\t\tfrom(\n\t\t\t\t     select * from config_page_btn\n\t\t\t\t     where IsActive=1 and PageId='" . $PageId . "'\n\t\t\t\t     order by Seq\n\t\t\t\t) as tb1\n\t\t\t\tinner join(\n\t\t\t\t     select * from config_btn\n\t\t\t\t     where IsActive=1\n\t\t\t\t) as tb2\n\t\t\t\ton tb1.BtnId=tb2.BtnId";
        $tmp_Btn = DB::Instance()->GetJson($sql);
        $tmp_Params = "";
        for ($i = 0; $i < count($ParamsId); $i++) {
            if ($ParamsId[$i] != "" && $ParamsType[$i] != "" && $ParamsName[$i] != "") {
                $tmp_Params .= '{' . '"id":' . json_encode($ParamsId[$i]) . ',' . '"type":' . json_encode($ParamsType[$i]) . ',' . '"name":' . json_encode($ParamsName[$i]) . '' . '},';
            }
        }
        $tmp_Params = rtrim($tmp_Params, ",");
        $tmp_Fields = "";
        for ($i = 0; $i < count($FieldsId); $i++) {
            if ($FieldsId[$i] != "" && $FieldsName[$i] != "") {
                $tmp_Fields .= '{' . '"id":' . json_encode($FieldsId[$i]) . ',' . '"name":' . json_encode($FieldsName[$i]) . '' . '},';
            }
        }
        $tmp_Fields = rtrim($tmp_Fields, ",");
        echo '{' . '"PageId":' . json_encode($PageId) . ',' . '"Params":[' . $tmp_Params . '],' . '"Fields":[' . $tmp_Fields . '],' . '"Btns":' . $tmp_Btn . '' . '}';
    } else {
        throw new Exception("Params Error");
        //配置失败
    }
}
Ejemplo n.º 16
0
 function populate()
 {
     if (!isModuleAdmin()) {
         $flash = Flash::Instance();
         $flash->addError('You don\'t have permission to view the Sales Team summary EGlets');
         $this->should_render = false;
         return false;
     }
     $db =& DB::Instance();
     $query = 'SELECT s.id,s.name FROM opportunitystatus s WHERE usercompanyid=' . $db->qstr(EGS_COMPANY_ID) . ' ORDER BY position DESC';
     $statuses = $db->GetAssoc($query);
     $query = 'SELECT DISTINCT assigned FROM opportunities o WHERE o.usercompanyid=' . EGS_COMPANY_ID . ' AND extract(\'' . $this->timeframe . '\' FROM o.enddate)=extract(\'' . $this->timeframe . '\' FROM now())';
     $users = $db->GetCol($query);
     $options = array();
     foreach ($users as $username) {
         if (empty($username)) {
             continue;
         }
         $data = array();
         foreach ($statuses as $id => $status) {
             $query = 'SELECT COALESCE(sum(cost),0) FROM opportunities o WHERE o.assigned=' . $db->qstr($username) . ' AND o.status_id=' . $db->qstr($id) . ' AND o.usercompanyid=' . EGS_COMPANY_ID . ' AND extract(\'' . $this->timeframe . '\' FROM o.enddate)=extract(\'' . $this->timeframe . '\' FROM now())';
             $data['x'][] = $status;
             $data['y'][] = (double) $db->GetOne($query);
         }
         $options['seriesList'][] = array('label' => $username, 'legendEntry' => TRUE, 'data' => $data);
     }
     if (!isset($options['seriesList']) || empty($options['seriesList'])) {
         return false;
     }
     $options['type'] = 'bar';
     $options['identifier'] = __CLASS__ . $this->timeframe;
     $this->contents = json_encode($options);
 }
Ejemplo n.º 17
0
 function insert($ids = null, $person_id = null, &$errors = array())
 {
     if (empty($ids) || empty($person_id)) {
         $errors[] = 'Invalid/incomplete data trying to insert Person Categories';
         return FALSE;
     }
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $categories = array();
     foreach ($ids as $id) {
         $category = DataObject::Factory(array('category_id' => $id, 'person_id' => $person_id), $errors, get_class($this));
         if ($category) {
             $categories[] = $category;
         } else {
             $errors[] = 'Error validating Person Category';
             return FALSE;
         }
     }
     $db = DB::Instance();
     foreach ($categories as $category) {
         if (!$category->save()) {
             $errors[] = $db->ErrorMsg();
             $db->FailTrans();
             $db->completeTrans();
             return FALSE;
         }
     }
     return $db->completeTrans();
 }
Ejemplo n.º 18
0
 function test(DataObject $do, array &$errors)
 {
     $dependency = true;
     $db = DB::Instance();
     foreach ($this->cc as $c) {
         $str = $db->qstr($do->getField($c['constraint']->fieldname)->finalvalue) . ' ' . $c['constraint']->operator . ' ' . $c['constraint']->value;
         eval("\$a={$str};");
         if (!$a) {
             $dependency = false;
         }
     }
     if ($dependency) {
         foreach ($this->fields as $field) {
             $value = $do->getField($field)->finalvalue;
             if (empty($value) && $value !== 0 && $value !== '0') {
                 if (count($this->fields) == 1) {
                     $errors[$this->fields[0]] = sprintf($this->message_stub, $do->getField($field)->tag);
                 } else {
                     $fieldlist = '';
                     foreach ($this->fields as $fieldname) {
                         $fieldlist .= $do->getField($fieldname)->tag . ',';
                     }
                     $fieldlist = substr($fieldlist, 0, -1);
                     $errors[$this->fields[0]] = sprintf($this->message_stub2, $fieldlist);
                 }
                 return false;
             }
         }
     }
     return $do;
 }
Ejemplo n.º 19
0
    /**
     * Tasks with subtasks take on the start_date, end_date, duration and progress based on their children
     * - earliest start_date
     * - latest end_date
     * - sum(duration)
     * - (sum(progress*duration))/sum(duration) for progress
     */
    public function updateProperties()
    {
        $db = DB::Instance();
        $query = 'SELECT t.start_date FROM tasks t WHERE t.parent_id=' . $db->qstr($this->id) . ' ORDER BY start_date ASC';
        $this->start_date = $db->GetOne($query);
        $query = 'SELECT t.end_date FROM tasks t WHERE t.parent_id=' . $db->qstr($this->id) . ' ORDER BY end_date DESC';
        $this->end_date = $db->GetOne($query);
        $query = 'SELECT sum(duration) AS duration FROM tasks t WHERE t.parent_id=' . $db->qstr($this->id);
        $this->duration = $db->GetOne($query);
        $query = 'SELECT coalesce(
					(
						sum(
							(progress::float/100)*(extract(hours from duration))
						)
					)
					/
					(
						sum(
							extract (hours from duration)
						)
					)
				,0)*100 AS progress FROM tasks t WHERE parent_id=' . $db->qstr($this->id);
        $this->progress = $db->GetOne($query);
        $this->save();
        $this->updateParent();
    }
Ejemplo n.º 20
0
 function getPermissionsAsTree($id = NULL, $parent, $sitetree, $types = NULL, $name = NULL)
 {
     $db = DB::Instance();
     $cc = new ConstraintChain();
     if (empty($id)) {
         $cc->add(new Constraint('parent_id', 'is', 'NULL'));
     } else {
         $cc->add(new Constraint('parent_id', '=', $id));
     }
     if (!empty($types)) {
         $cc->add(new Constraint('type', 'in', '(' . $types . ')'));
     }
     if (!empty($name)) {
         $cc->add(new Constraint('id', '=', $name));
     }
     $this->identifierField = 'title';
     $this->orderby = 'position';
     $thislevel = $this->getAll($cc);
     if ($thislevel) {
         foreach ($thislevel as $pageid => $name) {
             $element = $sitetree->createElement('Permission', $name);
             $element->setAttribute('id', $pageid);
             $this->getPermissionsAsTree($pageid, $element, $sitetree, $types);
             $parent->appendChild($element);
         }
     } else {
         return FALSE;
     }
 }
Ejemplo n.º 21
0
 function populate()
 {
     $db = DB::Instance();
     $query = "\n\t\t\tSELECT\n\t\t\t\tpe.name,\n\t\t\t\tpe.id,\n\t\t\t\tpe.red,\n\t\t\t\tpe.amber,\n\t\t\t\tpe.green,\n\t\t\t\tpe.usable_hours,\n\t\t\t\tpe.available,\n\t\t\t\tSUM(EXTRACT(HOURS FROM t.duration)) AS total\n\t\t\tFROM\n\t\t\t\ttasks t\n\t\t\tLEFT JOIN\n\t\t\t\tprojects p ON (t.project_id = p.id)\n\t\t\tLEFT JOIN\n\t\t\t\tproject_equipment pe ON (t.equipment_id = pe.id)\n\t\t\tWHERE\n\t\t\t\tp.usercompanyid = " . $db->qstr(EGS_COMPANY_ID) . "\n\t\t\tAND\n\t\t\t\t(t.start_date > NOW())\n\t\t\tAND\n\t\t\t\t(t.start_date < (NOW() + '30 days'::interval))\n\t\t\tAND\n\t\t\t\tt.equipment_id IS NOT NULL\n\t\t\tGROUP BY\n\t\t\t\tpe.id,\n\t\t\t\tpe.name,\n\t\t\t\tpe.red,\n\t\t\t\tpe.amber,\n\t\t\t\tpe.green,\n\t\t\t\tpe.usable_hours,\n\t\t\t\tpe.available\n\t;";
     $results = $db->GetAssoc($query);
     if ($results) {
         foreach ($results as $name => $result) {
             $result['name'] = $name;
             $utilisation = $result['total'] / ($result['usable_hours'] * 30);
             // 30 days of periods
             //		var_dump(array($utilisation, $result['red'], $result['amber'], $result['green']));
             if ($utilisation >= $result['red'] / 100) {
                 $colour = 'red';
             } elseif ($utilisation >= $result['amber'] / 100) {
                 $colour = 'amber';
             } elseif ($utilisation >= $result['green'] / 100) {
                 $colour = 'green';
             } else {
                 $colour = 'disabled';
             }
             $this->contents[] = array('id' => $result['id'], 'name' => $result['name'], 'colour' => $colour, 'disabled' => $result['available'] == 't' ? false : true);
         }
     }
     if (!empty($this->contents)) {
         $this->contents = array_slice($this->contents, 0, $this->limit);
     }
 }
Ejemplo n.º 22
0
 public static function globalRollOver()
 {
     $db = DB::Instance();
     $date = date('Y-m-d');
     $query = "UPDATE mf_operations\n\t\t\t\t\tSET std_cost=latest_cost,std_lab=latest_lab,std_ohd=latest_ohd\n\t\t\t\t\tWHERE (start_date <= '" . $date . "' OR start_date IS NULL) AND (end_date > '" . $date . "' OR end_date IS NULL) AND usercompanyid=" . EGS_COMPANY_ID;
     return $db->Execute($query) !== false;
 }
Ejemplo n.º 23
0
 public function __construct($modelName, $fetch = true)
 {
     if ($modelName == null) {
         throw new Exception(sprintf('Argument \\"%s\\" is null', $modelName));
     }
     $this->modelName = $modelName;
     if ($fetch) {
         $matches = [];
         preg_match('/[A-Za-z0-9_]+$/', $this->modelName, $matches);
         $tableName = $matches[0];
         // Query and fetch
         $db = \DB::Instance();
         $data = $db->select($tableName, '*');
         foreach ($data as $row) {
             $keys_in_row = array_keys($row);
             $modelClass = sprintf("\\Models\\%s", $this->modelName);
             $model = new $modelClass();
             foreach ($keys_in_row as $key) {
                 $key = strtolower($key);
                 $model->{$key} = $row[$key];
             }
             $this->add($model);
         }
     }
     reset($this->list);
 }
Ejemplo n.º 24
0
 public function __toString()
 {
     $s = $this->q;
     foreach (array_reverse($this->params) as $v) {
         $s = str_replace(':' . $v->name, DB::Instance()->quote($v->val), $s);
     }
     return $s;
 }
Ejemplo n.º 25
0
 public function save()
 {
     if (!$this->CheckParams($this->modeltype)) {
         sendBack();
     }
     $flash = Flash::Instance();
     $errors = array();
     $db = DB::Instance();
     $db->StartTrans();
     $current_accounts = array();
     if (isset($this->_data[$this->modeltype]['id'])) {
         $centre = $this->_templateobject;
         $centre->load($this->_data[$this->modeltype]['id']);
         if ($centre->isLoaded()) {
             foreach ($centre->accounts as $accountcentre) {
                 // Delete any existing entries not in the supplied list
                 if (!empty($this->_data[$this->modeltype]['account_id']) && in_array($accountcentre->glaccount_id, $this->_data[$this->modeltype]['account_id'])) {
                     $current_accounts[$accountcentre->glaccount_id] = $accountcentre->glaccount_id;
                 } elseif (!$accountcentre->delete(null, $errors)) {
                     $errors[] = 'Failed to update Account Centre Reference ' . $accountcentre->glaccount;
                 }
             }
         }
     }
     if (count($errors) === 0 && parent::save_model($this->modeltype)) {
         if (isset($this->_data[$this->modeltype]['account_id'])) {
             foreach ($this->_data[$this->modeltype]['account_id'] as $account_id) {
                 if (!key_exists($account_id, $current_accounts)) {
                     $data = array();
                     $data['glaccount_id'] = $account_id;
                     $data['glcentre_id'] = $this->saved_model->id;
                     $accountcentre = GLAccountCentre::Factory($data, $errors, 'GLAccountCentre');
                     if ($accountcentre) {
                         $accountcentre->save();
                         if (!$accountcentre) {
                             $errors[] = 'Failed to save reference to Account';
                             break;
                         }
                     } else {
                         $errors[] = 'Failed to save reference to Account';
                         break;
                     }
                 }
             }
         }
         if (count($errors) == 0) {
             $db->CompleteTrans();
             sendTo($this->name, 'index', $this->_modules);
         }
     } else {
         $errors[] = 'Failed to save GL Centre';
     }
     $db->FailTrans();
     $flash->addErrors($errors);
     $this->refresh();
 }
Ejemplo n.º 26
0
 function handle(DataObject $model)
 {
     $jn = $model->job_no;
     if (empty($jn)) {
         $db = DB::Instance();
         $query = 'SELECT max(despatch_number) FROM ' . $model->getTableName() . ' WHERE usercompanyid=' . EGS_COMPANY_ID;
         $current = $db->GetOne($query);
         return $current + 1;
     }
 }
Ejemplo n.º 27
0
 function handle(DataObject $model)
 {
     $jn = $model->job_no;
     if (empty($jn)) {
         $db = DB::Instance();
         $query = 'SELECT max(job_no) FROM projects WHERE usercompanyid=' . EGS_COMPANY_ID;
         $current = $db->GetOne($query);
         return $current + 1;
     }
 }
 function handle(DataObject $model)
 {
     $field = $model->{$this->field};
     if (empty($field)) {
         $db = DB::Instance();
         $query = 'SELECT max(' . $this->field . ') FROM ' . $this->table . ' WHERE usercompanyid=' . EGS_COMPANY_ID;
         $current = $db->GetOne($query);
         return $current + 1;
     }
 }
Ejemplo n.º 29
0
 /**
  * Check that the authenticated user exists
  *
  * @return bool
  * @see LoginHandler::doLogin()
  */
 public function doLogin()
 {
     // get the authenticated username
     $username = $_SERVER['PHP_AUTH_USER'];
     $db = DB::Instance();
     $is_authorised = $this->gateway->Authenticate(array('username' => $username, 'db' => $db));
     if ($is_authorised) {
         return $is_authorised;
     }
     return false;
 }
Ejemplo n.º 30
0
 function handle(DataObject $model)
 {
     $db =& DB::Instance();
     $query = 'SELECT max(' . $this->position_field . ') FROM ' . $model->getTableName();
     if ($model->isField('usercompanyid')) {
         $query .= ' WHERE usercompanyid=' . $db->qstr(EGS_COMPANY_ID);
     }
     $position = $db->GetOne($query);
     $position++;
     return $position;
 }