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."; }
public function beforeUpdate($baseTable, $baseCurrent, $baseUpdate) { if (isset($baseUpdate['abc_id']) && !isset($baseUpdate['abc_time'])) { $baseUpdate['abc_time'] = CalemText::getServerDatetime(); } return $baseUpdate; }
public function getTimeDue($releaseDay, $releaseTime) { $tm = null; if ($releaseDay && $releaseTime) { $schedDay = CalemScheduleInfo::decode($releaseDay); $schedTime = CalemScheduleTimeInfo::decode($releaseTime); $dueTime = $schedTime->getNextDueTime(null, $schedDay); $tm = $dueTime ? CalemText::getServerDateTime($dueTime) : null; } return $tm; }
/** * Figure out next time due */ public function updateNextDueTime($jobRow) { $schedDay = CalemScheduleInfo::decode($jobRow['release_day']); $schedTime = CalemScheduleInfo::decode($jobRow['release_time']); $dueTime = CalemText::parseServerDateTime($jobRow['time_due']); $newTime = $schedTime->getNextDueTime($dueTime, $schedDay); try { $this->dbo->setValue('time_due', CalemText::getServerDateTime($newTime)); $this->dbo->setIdForUpdate($jobRow['id']); $this->dbo->update(); } catch (Exception $e) { $this->logger->error("Error in updating job row=" . var_export($jobRow, true) . ", msg=" . $e->getMessage()); } }
public function set($sem) { $ar = array("expire_time" => CalemText::getServerDateTime($sem->getExpireTime())); try { $ps = $this->dbo->fetchById($sem->getId()); //Doing an update here. $this->dbo->setChangeBulk($ar); $this->dbo->setIdForUpdate($sem->getId()); $this->dbo->update(); } catch (CalemDboDataNotFoundException $e) { //Doing an insertion here. $ar['id'] = $sem->getId(); $this->dbo->setChangeBulk($ar); $this->dbo->insert(); } }
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; } }
/** * PM dependency map to load up */ public function getPdm() { $pdm = null; $cache = CalemFactory::getDataCacheManager(); $pdmInfo = $cache->load('pdm'); if ($pdmInfo) { if ($this->pdmUpToDate($pdmInfo)) { $pdm = $pdmInfo['pdm']; } } if (!$pdm) { //Create PDM and save it. $timestamp = CalemText::getServerDateTime(); $pdm = $this->buildPdm(); $cache->save(array('timestamp' => $timestamp, 'pdm' => $pdm), 'pdm'); } return $pdm; }
/** * If the scheduler cannot secure a semaphore do not proceed. */ public function execute() { $sem = $this->semBo->get(self::SemSchedulerId); if ($sem != null && $sem->getExpireTime() > gmmktime()) { $this->logger->debug("A semaphore is still on. Abort this run."); return; } //Secure a semaphore for this run $this->setSemaphore(); //Cycle through jobs try { $jobs = $this->jobBo->getDueJobList(); if (!$jobs) { $this->semBo->clear(self::SemSchedulerId); return; } foreach ($jobs as $job) { //Extend script time and semaphore if ($this->conf['task_script_time']) { set_time_limit($this->conf['task_script_time']); } $this->setSemaphore(); //run one job. if ($this->logger->isDebugEnabled()) { $this->logger->debug("starting job: " . var_export($job, true)); } try { $this->jobBo->updateNextDueTime($job); $startTime = CalemText::getServerDateTime(); $rtn = $this->jobBo->executeJob($job); $endTime = CalemText::getServerDateTime(); $this->jobBo->addJobRun($job, $startTime, $endTime, $rtn); } catch (Exception $e) { $this->logger->error("Error in starting job=" . $job['id'] . ", msg=" . $e->getMessage()); } } } catch (Exception $e) { $this->logger->error("Error in starting jobs, msg=" . $e->getMessage()); } $this->semBo->clear(self::SemSchedulerId); }
public function upgrade() { $startTime = CalemText::getServerDatetime(); $cmds = $this->getCmds(); $succ = true; $results = ''; try { foreach ($cmds as $key => $cmdInfo) { require_once 'command/' . $cmdInfo['cmd'] . '.php'; $cmd = new $cmdInfo['cmd'](); $cmd->init($cmdInfo['param']); $result = $cmd->execute(); $results .= $result; } $results = 'Done upgrade. Commands executed: ' . count($cmds) . "\n" . $results; } catch (Exception $e) { $results = 'Exception in upgrade: ' . $e->getMessage(); $succ = false; } //Now let's log the version upgrade results if any. try { $this->id = $this->verBo->startUpgrade($this->newVer, $this->currVer); if ($succ) { $this->verBo->save($this->newVer); $this->verBo->completeUpgrade($this->id, $results); } else { $this->verBo->failUpgrade($this->id, $results); } } catch (Exception $e) { $results .= '; exception in save log: ' . $e->getMessage(); $succ = false; $this->logger->error("Error in creating upgrade log, error=" . $e->getMessage()); } if (!$succ) { throw new Exception($results); } return $results; }
/** * 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']); }
/** * When updating a PO * -- fill-in vendor if changed * -- fill-in buyer if changed */ public function beforeUpdate($baseTable, $baseCurrent, $baseUpdate) { //vendor if (isset($baseUpdate['vendor_id'])) { $baseUpdate = $this->fillInVendor($baseUpdate['vendor_id'], $baseUpdate); } //buyer if (isset($baseUpdate['buyer_id'])) { $baseUpdate = $this->fillInBuyer($baseUpdate['buyer_id'], $baseUpdate); } /** * Status change handling * 1) change a PO to voided, remove the REQ from the PO * 2) change a PO from voided to another status, remove all the PO items - have to start over. * 3) set up po_date if status is changed to 'approved' and po_date is not set */ if (isset($baseUpdate['status_id'])) { if ($baseUpdate['status_id'] == 'po_status_voided') { //Changing to voided. $this->removeAllReqFromPo($baseCurrent['id']); } else { if ($baseCurrent['status_id'] == 'po_status_voided') { //Coming out of voided. $this->resetPoItems($baseCurrent['id']); //Reset cost info $baseUpdate['po_item_total'] = 0; $baseUpdate['tax_charge'] = 0; $baseUpdate['total_charge'] = 0; } } //Checking for po date if ($baseUpdate['status_id'] == 'po_status_approved' && !$baseUpdate['po_date'] && !$baseCurrent['po_date']) { $baseUpdate['po_date'] = CalemText::getServerDate(); } } return $baseUpdate; }
/** * Order generation check */ public function generateOrderRequest($inRow) { if ($inRow['qty_to_order'] > 0 && $inRow['order_gen_id'] == 'inog_auto') { $inOrderGenBo = new CalemInOrderGenBo(); $inOrderGenBo->autoGenOrderRequest($inRow['id'], $inRow['qty_to_order'], $inRow['uom_id'], $inRow['owner_user_id'], CalemText::getServerDateTime()); } }
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) { } }
public function getMdByServerDatetime($dt) { $dt = CalemText::parseServerDatetime($dt); return gmdate('Y-m-01', $dt); }
public function getLastReleaseDate($pmAssetRow) { return CalemText::parseServerDate($pmAssetRow['last_released']); }
public function getSemaphore() { try { $row = $this->semDbo->fetchById($this->conf['semaphore_id']); if ($row['expiration']) { $time = CalemText::parseServerDateTime($row['expiration']); } else { $time = 0; } if ($time > mktime()) { if ($this->logger->isInfoEnabled()) { $this->logger->info("Cannot start wo generation, semaphore is not expired: " . date('Y-m-d H:i:s', $time)); } return false; } $this->extendSemaphore(); } catch (CalemDboDataNotFoundException $ex) { $this->semDbo->setChangeBulk(array('id' => $this->conf['semaphore_id'], 'expiration' => CalemText::getServerDateTime($this->getSemExpiration()))); $this->semDbo->insert(); } return true; }
public function onDataDeleted_CalemWoDbo($dataPkt) { $id = CalemText::datetimeToDate($dataPkt['baseData']['orig_time']); $orig = $dataPkt['baseData']['origin_id']; if ($id && $orig) { $this->decCount($id, $orig); } }
public function setLogStatus($id, $statusId, $results) { $this->initDbo(); $this->dboLog->setChangeBulk(array('status_id' => $statusId, 'end_time' => CalemText::getServerDatetime(), 'results' => $results)); $this->dboLog->setIdForUpdate($id); $this->dboLog->update(); }
public function getValue() { return CalemText::formatCurrencyString($this->value); }
public static function getCurrencyFormat() { return CalemText::getFormat('currencyfmt'); }
public function onDataUpdated($baseTable, $baseCurrent, $baseUpdate, $customTable, $customCurrent, $customUpdate) { //Must have a status change if (isset($baseUpdate['status_id'])) { //Managing status changes if ($baseUpdate['status_id'] == 'wos_closed') { if ($baseCurrent['pm_id']) { //Now update PM to set the date $pmDbo = CalemFactory::getDbo('pm_asset'); $pmDbo->updateBySqlParam('update pm_asset set last_closed=? where pm_id=? and asset_id=?', array(CalemText::getServerDate(), $baseCurrent['pm_id'], $baseCurrent['asset_id'])); } //Clear reserved $reserveBo = new CalemWoReservedBo(); $reserveBo->removeReservedByWo($baseCurrent['id']); } } //Other listeners $this->notifyDataUpdated($baseTable, $baseCurrent, $baseUpdate, $customTable, $customCurrent, $customUpdate); }
public function adjustReleaseDate($ndt) { if ($this->weekNo) { $data = getdate($ndt); $wk = CalemScheduleMonths::$WEEKNO_MAP[$this->weekNo]; $d = $wk * 7 + 1; $ndt = mktime(0, 0, 0, $data['mon'], $d, $data['year']); if ($this->dow) { $ndt = CalemText::getDateByDow($ndt, CalemScheduleWeekly::$DOW_MAP[$this->dow], true); } } return $ndt; }
/** * Update schedUser */ public function updateSchedUser($uid, $startTime, $shiftId, $hours) { $schedBo = new CalemSchedBo(); $schedBo->scheduleUser($uid, CalemText::datetimeToDate($startTime), $shiftId, $hours); }