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');
 }
 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();
 }
예제 #4
0
 /**
  * Find record by Id
  */
 public static function findById($id)
 {
     $dbo = CalemFactory::getDbo('users');
     $row = $dbo->fetchById($id);
     $dbo->resetRow($row);
     return $dbo;
 }
예제 #5
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();
 }
예제 #6
0
 public function __construct()
 {
     parent::__construct();
     //Get configuration
     global $_CALEM_conf;
     $this->conf = $_CALEM_conf['in_conf'];
     $this->uomDbo = CalemFactory::getDbo('uom_map');
 }
예제 #7
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;
 }
예제 #8
0
 /**
  * To use this object in installation so cannot assume db is available to start with.
  */
 private function initDbo()
 {
     if (!$this->dbo) {
         $this->dbo = CalemFactory::getDbo('version');
     }
     if (!$this->dboLog) {
         $this->dboLog = CalemFactory::getDbo('version_upgrade_log');
     }
 }
예제 #9
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();
 }
예제 #10
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);
     }
 }
예제 #11
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();
 }
예제 #12
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) {
     }
 }
 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();
 }
예제 #14
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();
 }
예제 #15
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();
 }
예제 #16
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;
     }
 }
예제 #17
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();
 }
예제 #18
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();
 }
예제 #19
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']);
 }
예제 #20
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;
 }
예제 #21
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());
     }
 }
예제 #22
0
 public function setPmReleaseDate($dueDate, $pmRow, $pmAssetRow, $setLastClosed = false)
 {
     $schedBo = new CalemPmScheduleBo($pmRow['release_schedule']);
     $nextDueDate = $schedBo->getNextDueDate($dueDate);
     if (!$nextDueDate) {
         $nextDueDate = $dueDate;
     }
     //In case there's no schedule planned
     $pmAssetDbo = CalemFactory::getDbo('pm_asset');
     $pmAssetRow = $pmAssetDbo->fetchById($pmAssetRow['id']);
     $pmAssetDbo->setChangeBulk(array('last_released' => CalemText::getServerDate($dueDate), 'next_due_date' => CalemText::getServerDate($nextDueDate), 'release_count' => $pmAssetRow['release_count'] + 1));
     $pmAssetDbo->setIdForUpdate($pmAssetRow['id']);
     $pmAssetDbo->update();
     //Going through meters if any
     $pmMeterDbo = CalemFactory::getDbo("pm_meter");
     try {
         $pmMeterRows = $pmMeterDbo->fetchBySqlParam('select * from pm_meter where pm_asset_id=?', $pmAssetRow['id']);
         $assetMeterDbo = CalemFactory::getDbo('asset_meter');
         foreach ($pmMeterRows as $pmMeterRow) {
             if ($pmMeterRow['release_by_meter']) {
                 try {
                     $assetMeterRow = $assetMeterDbo->fetchById($pmMeterRow['meter_id']);
                     $pmMeterDbo->setChangeBulk(array('reading_released' => $assetMeterRow['reading'], 'rollover_count' => $assetMeterRow['rollover_count']));
                     $pmMeterDbo->setIdForUpdate($pmMeterRow['id']);
                     $pmMeterDbo->update();
                 } catch (CalemDboDataNotFoundException $ex) {
                 }
             }
         }
     } catch (CalemDboDataNotFoundException $ex) {
     }
 }
예제 #23
0
 public function __construct()
 {
     parent::__construct();
     $this->dbo = CalemFactory::getDbo('dash_wo_orig_md');
 }
예제 #24
0
 /**
  * There're standing PMs in the workorder table.
  */
 public function hasStandingPm($pmAssetRow, $bypassStandingPm = false)
 {
     if ($bypassStandingPm) {
         return false;
     }
     $woDbo = CalemFactory::getDbo('workorder');
     $cnt = $woDbo->getCountBySqlParam($this->standingPmSql, array($pmAssetRow['pm_id'], $pmAssetRow['asset_id']));
     return $cnt > 0;
 }
예제 #25
0
 /**
  * Decide if a PM is due
  * @return an array ('due'=>true/false, 'due_date'=>new_due_date)
  */
 public function schedulePm($pmId, $dep)
 {
     //Check for PM status first and release type.
     try {
         $pmRow = $this->pmDbo->fetchById($pmId);
         //Check at PM level if we should try to schedule it.
         if (!$this->isAutoSchedulePm($pmRow)) {
             return;
         }
         //Schedule is strictly done by pmAssets
         $pmAssetRows = $this->pmAssetDbo->fetchBySqlParam('select * from pm_asset where pm_id=?', $pmId);
         $assetDbo = CalemFactory::getDbo('asset');
         foreach ($pmAssetRows as $pmAssetRow) {
             //Ensure asset is in service before releasing PM
             if (!$this->isAutoScheduleAsset($pmAssetRow, $assetDbo)) {
                 continue;
             }
             //Skip assets that are not valid
             $dueDates = $this->scheduleBo->schedulePm($pmRow, $pmAssetRow, $this->endDate);
             $this->releasePm($dueDates, $pmRow, $pmAssetRow, $dep);
         }
     } catch (CalemDboDataNotFoundException $ex) {
     }
 }
예제 #26
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);
             }
         }
     }
 }
예제 #27
0
 public function getPoApprovalLevel($userId)
 {
     $userDbo = CalemFactory::getDbo('users');
     $userDbo->loadRecordById($userId);
     return $userDbo->getPoApprovalLevel();
 }
예제 #28
0
 /**
  * WO labor cost
  */
 public function getWoLaborCost($startDate, $endDate)
 {
     $woLaborDbo = CalemFactory::getDbo('wo_labor');
     $lc = $woLaborDbo->getCountBySqlParam("select sum(w.line_cost) from wo_labor w where w.start_time >=? and w.start_time <=?", array($startDate, $endDate));
     return $lc;
 }
예제 #29
0
 public function __construct()
 {
     parent::__construct();
     $this->dbo = CalemFactory::getDbo('workorder');
     $this->ddDbo = CalemFactory::getDropdown('wo_status');
 }
예제 #30
0
 /**
  * constructor
  */
 public function __construct($sid = null, $data = null)
 {
     $this->dbo = CalemFactory::getDbo('semaphore');
     $this->logger =& LoggerManager::getLogger("CalemSemaphoreBo");
 }