public function execute()
 {
     $dayBo = new CalemDashWoOrigDayBo();
     $mdBo = new CalemDashWoOrigMdBo();
     $woDbo = CalemFactory::getDbo('workorder');
     $woDbo->deleteBySql('delete from dash_wo_orig_day');
     $woDbo->deleteBySql('delete from dash_wo_orig_md');
     //Now recals based on wo info
     try {
         $rows = $woDbo->fetchBySql("select * from workorder");
     } catch (CalemDboDataNotFoundException $e) {
         return "No data in workorder. WO count is reset.";
     }
     global $_CALEM_conf;
     $lastDay = strtotime($_CALEM_conf['dash_conf']['dash_wo_orig_day']['limit'] . " day ago");
     $lastSvrDay = CalemText::getServerDatetime($lastDay);
     foreach ($rows as $row) {
         $mdBo->onDataInserted_CalemWoDbo(array('baseData' => $row));
         if ($row['orig_time'] < $lastSvrDay) {
             continue;
         }
         //Too far back not considering
         $dayBo->onDataInserted_CalemWoDbo(array('baseData' => $row));
     }
     return "WO count updated successfully.";
 }
예제 #2
0
 public function __construct()
 {
     $this->logger =& LoggerManager::getLogger("CalemSchedulerJobBo");
     $this->dbo = CalemFactory::getDbo('scheduler_job');
     $this->dboRun = CalemFactory::getDbo('scheduler_job_log');
     $this->taskDbo = CalemFactory::getDbo('scheduler_task');
 }
예제 #3
0
 public function setupDatabase()
 {
     $dbHandler = CalemFactory::getDbHandler();
     $dbSetup = new CalemDbSetup();
     //Using a fake database for the test...
     global $_CALEM_conf;
     //Let's check if the db exists
     $conn = $dbHandler->getDatabaseAdminConnection();
     try {
         //Will not drop a db by code
         $dbSetup->setupDatabaseAndUser($dbHandler, $conn);
         //Release the connection for admin
         $dbHandler->releaseDatabaseAdminConnection();
         //Let's create schema
         $conn = $dbHandler->getCalemConnection();
         $dbSetup->setupSchema($dbHandler, $conn);
         //Let's verify that workorder table is in the database
         //Adding a record to work order and select it out.
         $conn->beginTransaction();
         $inserted = $conn->exec("insert into workorder (id, wo_no) values('1111111111-test', 'wo1')");
         $conn->commit();
         //Make sure we delete this record
         $conn->beginTransaction();
         $deleted = $conn->exec("delete from workorder where id='1111111111-test'");
         $conn->commit();
         if ($inserted == $deleted && $inserted == 1) {
             $this->logger->info("setupCalemDatabase is complete. Database is successfully created");
         } else {
             throw new Exception("Error in validating database setup. workorder inserted=" . $inserted . ", deleted=" . $deleted);
         }
     } catch (Exception $e) {
         $this->logger->error("Error in setting up db, error=" . $e->getMessage());
     }
 }
예제 #4
0
 public function init($param)
 {
     $this->param = $param;
     $this->dbHdlr = CalemFactory::getDbHandler();
     $this->dbSetup = new CalemDbSetup();
     $this->conn = $this->dbHdlr->getCalemConnection();
 }
예제 #5
0
 /**
  * Find record by Id
  */
 public static function findById($id)
 {
     $dbo = CalemFactory::getDbo('users');
     $row = $dbo->fetchById($id);
     $dbo->resetRow($row);
     return $dbo;
 }
 public function onDataDeleted($table, $id)
 {
     //Get the latest reading
     $clear = false;
     try {
         $sql = "select * from meter_transaction where meter_id= ? order by time_taken DESC";
         $mrs = $this->fetchBySqlParam($sql, $this->row['meter_id'], true);
         $mrRec = $mrs[0];
     } catch (CalemDboDataNotFoundException $nd) {
         $clear = true;
         if ($this->logger->isDebugEnabled()) {
             $this->logger->info("No meter reading for {$table} and meter: " . $this->row['meter_id'] . ", to clear reading");
         }
     }
     //Get asset meter's DBO
     $meterDbo = CalemFactory::getDbo('asset_meter');
     //Get meter rec.
     $mtRec = $meterDbo->fetchById($this->row['meter_id']);
     $ar = array();
     if ($mtRec['is_rollover']) {
         $ar['rollover_count'] = max(0, $ar['rollover_count'] - 1);
     }
     if ($clear) {
         $ar['time_taken'] = null;
         $ar['reading'] = null;
         $ar['is_rollover'] = null;
     } else {
         $ar['time_taken'] = $mrRec['time_taken'];
         $ar['reading'] = $mrRec['reading'];
         $ar['is_rollover'] = $mrRec['is_rollover'];
     }
     $meterDbo->setChangeBulk($ar);
     $meterDbo->setIdForUpdate($this->row['meter_id']);
     $meterDbo->update();
 }
예제 #7
0
 public function validateInput()
 {
     $this->setDbType($_REQUEST['fi_dbtype']);
     $this->setDbHost($_REQUEST['fi_dbhost']);
     $this->setUsername($_REQUEST['fi_username']);
     $this->setPassword($_REQUEST['fi_password']);
     $this->setDbName($_REQUEST['fi_dbname']);
     //Now validate the info to see if we can load it.
     $rtn = $this->getDbType() && $this->getDbHost() && $this->getUsername() && $this->getDbName();
     if (!$rtn) {
         $this->setErrorMsg($this->calemLang->getMsg('db_info_required'));
         $rtn = false;
     } else {
         //Let's try connecting to the database
         $this->controller->setupDbInfo();
         require_once _CALEM_DIR_ . 'server/include/core/CalemFactory.php';
         try {
             $dbHdlr = CalemFactory::getDbHandler();
             $conn = $dbHdlr->getCalemConnection();
         } catch (Exception $e) {
             $msg = $this->calemLang->getMsg('db_info_exception') . " <br /> " . $e->getMessage();
             $GLOBALS['logger']->error("Error at CalemInstDbinfoController.validateInput: " . $e->getMessage());
             $this->setErrorMsg($msg);
             $rtn = false;
         }
     }
     return $rtn;
 }
예제 #8
0
 public function __construct()
 {
     parent::__construct();
     //Get configuration
     global $_CALEM_conf;
     $this->conf = $_CALEM_conf['in_conf'];
     $this->uomDbo = CalemFactory::getDbo('uom_map');
 }
예제 #9
0
 public function __construct()
 {
     parent::__construct();
     $this->dbo = CalemFactory::getDbo('workorder');
     $this->ddDbo = CalemFactory::getDropdown('wo_priority');
     $this->sb = CalemFactory::getSb($this->conf['sb']);
     $this->_initIt();
 }
예제 #10
0
 public function beforeUpdate($baseTable, $baseCurrent, $baseUpdate)
 {
     if (isset($baseUpdate['function_id']) && $baseUpdate['function_id']) {
         $dbo = CalemFactory::getDbo('rcm_function');
         $row = $dbo->fetchById($baseUpdate['function_id']);
         $baseUpdate['template_id'] = $row['template_id'];
     }
     return $baseUpdate;
 }
 public static function getNotifiers($list, $map)
 {
     $nl = array();
     foreach ($list as $el) {
         $nf = $map[$el];
         $nl[] = CalemFactory::createInstance($nf);
     }
     return $nl;
 }
예제 #12
0
 public function updateDowntimeHours($woId, $hours)
 {
     $woDbo = CalemFactory::getDbo('workorder');
     //Get meter rec.
     $woRec = $woDbo->fetchById($woId);
     $fld = $this->getFieldName();
     $hours = $woRec[$fld] + $hours;
     $woDbo->setValue($fld, $hours);
     $woDbo->setIdForUpdate($woId);
     $woDbo->update();
 }
 public function getNotifier($it)
 {
     global $_CALEM_conf;
     $conf = $_CALEM_conf['in_conf']['tran_notifier_map'];
     if (isset($it['checkout_type_id']) && $it['checkout_type_id']) {
         $notifier = CalemFactory::createInstance($conf[$it['checkout_type_id']]);
     } else {
         $notifier = new CalemInTranNotifierNone();
     }
     return $notifier;
 }
예제 #14
0
 public function load()
 {
     $dbo = CalemFactory::getDbo('version');
     try {
         $dbo->fetchById(VERSION_ID);
         //version found, nothing to perform.
     } catch (CalemDboDataNotFoundException $dnf) {
         $bo = new CalemVersionBo();
         $nVer = $bo->getNewVersion();
         $bo->save($nVer);
     }
 }
예제 #15
0
 public function updateTaxCode($id, $rate)
 {
     $dbo = CalemFactory::getDbo('tax_code');
     try {
         $row = $dbo->fetchById($id);
         $nRate = max(0, $row['tax_rate_total'] + $rate);
         $dbo->setValue('tax_rate_total', $nRate);
         $dbo->setIdForUpdate($id);
         $dbo->update();
     } catch (CalemDboDataNotFoundException $ex) {
     }
 }
예제 #16
0
 public function updateLaborCost($id, $hours, $cost)
 {
     $assetDbo = CalemFactory::getDbo('asset');
     $row = $assetDbo->fetchById($id);
     $ar = array();
     $ar['maint_labor_hours'] = $row['maint_labor_hours'] + $hours;
     $ar['maint_labor_cost'] = $row['maint_labor_cost'] + $cost;
     $ar['maint_cost'] = $row['maint_material_cost'] + $ar['maint_labor_cost'];
     $assetDbo->setChangeBulk($ar);
     $assetDbo->setIdForUpdate($id);
     $assetDbo->update();
 }
 public function on_itt_return_icg_tool($it)
 {
     $id = $it['checkout_to_id'];
     $assetDbo = CalemFactory::getDbo('asset');
     $assetDbo->executeBySqlParam('select id from asset where id=? for update', $id);
     $row = $assetDbo->fetchById($id);
     $mc = $row['maint_material_cost'] + $it['tran_total'];
     $mt = $mc + $row['maint_labor_cost'];
     $assetDbo->setValue('maint_material_cost', $mc);
     $assetDbo->setValue('maint_cost', $mt);
     $assetDbo->setIdForUpdate($id);
     $assetDbo->update();
 }
예제 #18
0
 public function updateLaborHours($woId, $hours)
 {
     $woDbo = CalemFactory::getDbo('workorder');
     //Get meter rec.
     $woRec = $woDbo->fetchById($woId);
     $fld = $this->getWoHourField();
     $woRec[$fld] += $hours;
     if ($woRec[$fld] < 0) {
         $woRec[$fld] = 0;
     }
     $woDbo->setValue($fld, $woRec[$fld]);
     $woDbo->setIdForUpdate($woId);
     $woDbo->update();
 }
예제 #19
0
 public function updateDowntimeHours($pmId, $hours)
 {
     //Get pm's DBO
     $pmDbo = CalemFactory::getDbo('pm');
     //Get meter rec.
     $pmRec = $pmDbo->fetchById($pmId);
     $pmRec['downtime_hours'] += $hours;
     if ($pmRec['downtime_hours'] < 0) {
         $pmRec['downtime_hours'] = 0;
     }
     $pmDbo->setValue('downtime_hours', $pmRec['downtime_hours']);
     $pmDbo->setIdForUpdate($pmId);
     $pmDbo->update();
 }
예제 #20
0
 public function batchSchedule($tran)
 {
     $users = array();
     if (isset($tran['user_id'])) {
         $users[] = $tran['user_id'];
     } else {
         $userDbo = CalemFactory::getDbo('users');
         $rows = $userDbo->fetchBySqlParam('select id from users where team_id=?', $tran['team_id']);
         foreach ($rows as $row) {
             $users[] = $row['id'];
         }
     }
     //Adding schedule for each user.
     try {
         $this->schedUserDbo->beginTransaction();
         $startDate = CalemText::parseServerDate($tran['start_date']);
         $endDate = CalemText::parseServerDate($tran['end_date']);
         $shiftRow = $this->shiftData[$tran['shift_id']];
         while ($startDate <= $endDate) {
             $dtStr = date('Y-m-d', $startDate);
             foreach ($users as $user) {
                 if ($this->logger->isDebugEnabled()) {
                     $this->logger->debug("Add schedule: user_id=" . $user . ", startDate=" . $dtStr . ", shift=" . $tran['shift_id']);
                 }
                 try {
                     $rows = $this->schedUserDbo->fetchBySqlParam('select * from sched_user where user_id=? and sched_date=? and shift_id=?', array($user, $dtStr, $tran['shift_id']));
                     //No processing here.
                 } catch (CalemDboDataNotFoundException $ex) {
                     $ar['user_id'] = $user;
                     $ar['sched_date'] = $dtStr;
                     $ar['shift_id'] = $tran['shift_id'];
                     $ar['total_hours'] = $shiftRow['total_hours'];
                     $ar['sched_hours'] = $shiftRow['sched_hours'];
                     $this->schedUserDbo->setChangeBulk($ar);
                     $this->schedUserDbo->insert();
                     $this->schedUserDbo->unsetId();
                 }
             }
             //Adding a day
             $startDate = strtotime("+1 day", $startDate);
         }
         $this->schedUserDbo->commit();
     } catch (Exception $ex) {
         $this->schedUserDbo->rollback();
         throw $ex;
     }
 }
예제 #21
0
 public function validateInput()
 {
     $this->setLoadSample($_REQUEST['fi_load_sample']);
     $this->setUpgrade($_REQUEST['fi_upgrade']);
     $this->setVerifyDb($_REQUEST['fi_verifydb']);
     //Allow sufficient time
     set_time_limit(0);
     //Now creating DB first
     $rtn = true;
     try {
         /**
          * Creating database tables first
          */
         require_once _CALEM_DIR_ . 'server/include/core/database/CalemDbSetup.php';
         $dbSetup = new CalemDbSetup();
         $dbHandler = CalemFactory::getDbHandler();
         $conn = $dbHandler->getCalemConnection();
         $dbSetup->setupSchema($dbHandler, $conn);
         //Verify db setup
         if ($this->getVerifyDb()) {
             $dbSetup->validate();
         }
         //What about upgrade
         if ($this->upgradeHdlr) {
             $GLOBALS['logger']->debug('DbSetupModel: doing an upgrade; hdlr=' . get_class($this->upgradeHdlr));
             $results = $this->upgradeHdlr->upgrade();
             $GLOBALS['logger']->info("upgrade results: " . var_export($results, true));
         }
         //Load Init data
         require_once _CALEM_DIR_ . 'server/setup/CalemLoadInitData.php';
         $loader = new CalemLoadInitData();
         $loader->load();
         //Load sample data if set
         if ($this->getLoadSample()) {
             require_once _CALEM_DIR_ . 'server/setup/CalemLoadSampleData.php';
             $loader = new CalemLoadSampleData();
             $loader->load();
         }
     } catch (Exception $e) {
         $msg = $this->calemLang->getMsg('db_conf_exception') . " <br /> " . $e->getMessage();
         $GLOBALS['logger']->error("Error at CalemInstDbSetupController.validateInput: " . $e->getMessage());
         $this->setErrorMsg($msg);
         $rtn = false;
     }
     return $rtn;
 }
예제 #22
0
 public function load()
 {
     $dbo = new CalemAclGroupDbo();
     $rows = $dbo->getAll();
     $data = array();
     foreach ($rows as $row) {
         $dataRow = array();
         foreach ($row as $key => $val) {
             $dataRow[] = $val;
         }
         $data[] = $dataRow;
         $this->addParent($row['id'], $row['parent_group_id']);
     }
     //Searializing the object
     $group = array('data' => $data, 'parentMap' => $this->parentMap);
     $cache = CalemFactory::getDataCacheManager();
     $cache->save($group, 'acl_group');
 }
예제 #23
0
 public function execute()
 {
     $table = $this->param['table'];
     $flds = $this->param['fields'];
     $tbDd = CalemFactory::getTableDd($table);
     $results = '';
     foreach ($flds as $fld) {
         $fldReq = array('id' => $fld, 'tableId' => $table);
         $fldInfo = $tbDd->getField($fld);
         $fldReq = array_merge($fldReq, $fldInfo);
         try {
             $this->dbHdlr->addField($fldReq);
             $results .= "Added field {$table}.{$fld}\n";
         } catch (CalemDataBoException $de) {
             $results .= "Added field {$table}.{$fld} with exception: " . $de->getEx()->getMessage() . "\n";
         }
     }
     return $results;
 }
예제 #24
0
 /**
  * Update budget actual
  */
 public function updateBudgetActual($tran)
 {
     $budgetDbo = CalemFactory::getDbo('budget');
     $bRow = $budgetDbo->fetchById($tran['budget_id']);
     $startDate = $bRow['start_date'];
     $endDate = $bRow['end_date'];
     if (!$startDate || !$endDate || !($startDate < $endDate)) {
         throw new CalemUiException('CalemBudgetUpdateInvalidDateException');
     }
     //Get material cost
     $inBo = new CalemInBo();
     $mc = $inBo->getInCheckoutCost($startDate, $endDate);
     $woBo = new CalemWoBo();
     $lc = $woBo->getWoLaborCost($startDate, $endDate);
     //Actual cost
     $ac = $mc + $lc;
     $budgetDbo->setValue('app', $ac);
     $budgetDbo->setIdForUpdate($tran['budget_id']);
     $budgetDbo->update();
 }
예제 #25
0
 /**
  * At receive time, recalculate avgUnitCost
  */
 public function setUnitCostByReceive($inId, $rcUnitCost, $qty)
 {
     if ($qty == 0) {
         return;
     }
     //Nothing to do.
     $inDbo = CalemFactory::getDbo('inventory');
     $inDbo->setIdForUpdate($inId);
     $inDbo->loadRecord();
     $unitCost = $inDbo->getValue('avg_unit_cost');
     //Now get the total qty in stock
     $total = $inDbo->getCountBySqlParam('select sum(qty) from in_stock where in_id=?', array($inId));
     if ($total + $qty == 0) {
         $this->logger->info("Total qty is 0 so unit cost is not calculated: total=" . $total . ", qty=" . $qty . ", inId=" . $inId);
         return;
     }
     $newUnitCost = ($total * $unitCost + $rcUnitCost * $qty) / ($total + $qty);
     $inDbo->setValue('avg_unit_cost', $newUnitCost);
     $inDbo->update();
 }
예제 #26
0
 public function getCurrentVersion($useFirst = true)
 {
     $rtn = $useFirst ? $rtn = $this->firstVersion : null;
     try {
         $this->initDbo();
         $dh = CalemFactory::getDbHandler();
         if (!$dh->tableExists($this->dbo, 'version')) {
             return $rtn;
         }
         $row = $this->dbo->fetchById(VERSION_ID);
         if ($this->logger->isInfoEnabled()) {
             $this->logger->info('Version row=' . var_export($row, true));
         }
         $rtn = CalemVersion::decode($row);
     } catch (CalemDboDataNotFoundException $dn) {
         require_once _CALEM_DIR_ . 'server/include/util/CalemDebug.php';
         $this->logger->warn('Data not found: ' . CalemDebug::toStackTrace($dn));
     }
     return $rtn;
 }
예제 #27
0
 /**
  * Manual-gen a req
  */
 public function manualGenOrderRequest($inId, $reqRow)
 {
     $inDbo = CalemFactory::getDbo('inventory');
     $inRow = $inDbo->fetchById($inId);
     if (!$inRow['qty_to_order']) {
         return;
     }
     //In case it's processed already
     //Figure out the due date
     $initRow = $this->conf['in_order_gen']['req_manual']['init'];
     foreach ($initRow as $key => $val) {
         if (!$reqRow[$key]) {
             $reqRow[$key] = $val;
         }
     }
     $dueDate = $this->getReqDueDateByWo($inId);
     if ($dueDate) {
         $reqRow['due_date'] = CalemText::datetimeToDate($dueDate);
     }
     $reqRow['request_time'] = CalemText::getServerDateTime();
     $reqBo = new CalemReqBo();
     $reqId = $reqBo->createInOrderRequest($reqRow, $inId, $inRow['qty_to_order'], $inRow['uom_id']);
 }
예제 #28
0
 /**
  * build PDM
  */
 public function buildPdm()
 {
     $pdm = array();
     $dbo = CalemFactory::getDbo('pm_dependency');
     $childAr = array();
     $parentAr = array();
     $sortAr = array();
     try {
         $rows = $dbo->fetchBySql('select * from pm_dependency');
         //Constructing child/parent ars.
         foreach ($rows as $row) {
             $childAr = $this->addChild($row, $childAr);
             $parentAr = $this->addParent($row, $parentAr);
         }
         //Now scan the parentAr to come up with order.
         while (true) {
             if (count($parentAr) == 0) {
                 break;
             }
             $tempAr = array();
             $newParentAr = array();
             foreach ($parentAr as $key => $ar) {
                 $ar = $this->removeParents($ar, $sortAr);
                 if (count($ar) == 0) {
                     $tempAr[$key] = 1;
                 } else {
                     $newParentAr[$key] = $ar;
                 }
             }
             $sortAr = $sortAr + $tempAr;
             $parentAr = $newParentAr;
         }
         $pdm = array('sort' => $sortAr, 'map' => $childAr);
     } catch (CalemDboDataNotFoundException $ex) {
     }
     return $pdm;
 }
예제 #29
0
 public function loadFile($tableDd, $file)
 {
     @(include $file);
     if (!isset($data)) {
         $this->logger->error("No data in " . $file . ' - continue loading');
         return;
         //No data or error in getting the data.
     }
     //Going through each row
     foreach ($data as $row) {
         //Loop through each row
         //@todo to create id on the fly if needed.
         //Use CalemDbo to do the work here.
         $dbo = CalemFactory::getDbo($tableDd->getTableName());
         $dbo->setChangeBulk($row);
         try {
             $dbo->insert();
             $this->incInsertion($tableDd);
         } catch (Exception $e) {
             $err = $dbo->getErrorInfo();
             $this->conn->rollback();
             $this->logger->warn("error in inserting '" . $tableDd->getTableName() . "', error=" . var_export($err, true) . ', row=' . var_export($row, true));
             if (is_a($e, 'CalemDboDuplicateKeyException') && $this->conf->getOverwrite()) {
                 //Let's try update if needed
                 $this->updateRecord($tableDd, $row);
             } else {
                 $this->incIgnore($tableDd);
             }
         }
     }
 }
예제 #30
0
 public function _deleteBySql($stmt, $sql, $recycle = false)
 {
     if ($recycle) {
         //Fetch data first.
         $rows = $this->fetchBySqlParam($this->getSqlFetchById(), $this->getId());
     }
     $this->conn->beginTransaction();
     try {
         $stmt->execute();
         //add to recycle-bin
         if ($recycle) {
             $rbDbo = CalemFactory::getDbo("recycle_bin");
             $rbDbo->setDeletedInfo($this->tableName, $rows[0], $this->getIdName());
             $rbDbo->setDescription('CalemDbo');
             $rbDbo->insert();
         }
         $this->conn->commit();
     } catch (CalemDboDuplicateKeyException $dk) {
         throw $dk;
     } catch (Exception $e) {
         $this->errorInfo = $stmt->errorInfo();
         $this->logger->error("Deletion exception: " . $e->getMessage() . ", errorInfo: " . var_export($stmt->errorInfo(), true));
         $this->logErrorDebug($sql);
         throw new CalemDboDeletionException($e->getMessage());
     }
 }