public static function fordepproducts($out) { $previus = null; foreach ($out as $key => $value) { $type = $value['NR_KLASY']; $return[$value['ID_PROD']][$type][$value['WALUTA']]['desc'] = $value['OPIS']; $return[$value['ID_PROD']][$type][$value['WALUTA']]['symbol'] = $value['SYMBOL']; for ($i = 1; $i <= (int) $value['ILOSC_PROGOW']; $i++) { if ($value[$i] != null && $value['COL' . $i] != null) { if (substr($value[$i], 0, 1) == ',') { $interest = '0' . $value[$i]; } else { $interest = $value[$i]; } if (substr($out[$key + 1]['KWOTA_POCZATKOWA'], 0, 1) == ',') { $out[$key + 1]['KWOTA_POCZATKOWA'] = '0' . $out[$key + 1]['KWOTA_POCZATKOWA']; } if (substr($value['KWOTA_POCZATKOWA'], 0, 1) == ',') { $value['KWOTA_POCZATKOWA'] = '0' . $value['KWOTA_POCZATKOWA']; } $return[$value['ID_PROD']][$type][$value['WALUTA']]['interest_data'][str_replace(',', '.', $value['KWOTA_POCZATKOWA'] . '-' . ($out[$key + 1]['KWOTA_POCZATKOWA'] == null || $out[$key + 1]['KWOTA_POCZATKOWA'] == '0' || $value['WALUTA'] != $out[$key + 1]['WALUTA'] || $value['ID_PROD'] != $out[$key + 1]['ID_PROD'] || $out[$key + 1]['TYP_KLIENTA'] != $value['TYP_KLIENTA'] ? '0' : $out[$key + 1]['KWOTA_POCZATKOWA'] - 1))][Logic_DateUtils::decriptPeriodToDays((string) $value['COL' . $i] . (string) ($value['TYP_OKRESU'] == "MIESIAC" ? 'M' : 'D'))] = str_replace(',', '.', $interest); } } $previus = $value['KWOTA_POCZATKOWA']; } return $return; }
protected function processAction() { $writer = new Zend_Log_Writer_Stream('php://stdout'); $logger = new Zend_Log($writer); $settings = Settings::getInstance(); try { $view = $this->application->getBootstrap()->getResource('view'); $view->setScriptPath(APPLICATION_PATH . '/views/scripts'); $adapter = Zend_Db_Table::getDefaultAdapter(); $stmt = $adapter->query(<<<SQL SELECT id, (CASE WHEN awaits_from is null THEN created_at ELSE awaits_from END) "awaits_from", customer_considering, closing_time FROM negotiations.negotiation_step WHERE closing_time is null AND created_at > '2013-08-01'::date SQL ); // $toProcess = $stmt->fetchAll(); $logger->info('Found ' . count($toProcess) . ' ongoing negotiations.'); $errs = 0; $to_exp = 0; $now = date('Y-m-d', time()); $model = new NegotiationStep(); $adapter->query(<<<SQL ALTER TABLE negotiations.negotiation_step DISABLE TRIGGER negotiation_step_last_update_refresh SQL ); foreach ($toProcess as $nid) { if ($nid['customer_considering'] == 'true' || $nid['customer_considering'] == 'TRUE' || $nid['customer_considering'] == 't') { switch ('working') { case 'working': $date = @Logic_DateUtils::getDateByWorkingDays(5, $nid['awaits_from']) . ' 23:59:59'; break; case 'calendar': $date = date('Y-m-d', strtotime($nid['awaits_from'] . ' +' . 5 . ' days')) . ' 23:59:59'; break; default: throw new Exception('Misconfiguration in negotiations.settings table'); } } else { switch ('working') { case 'working': $date = @Logic_DateUtils::getDateByWorkingDays(5, $nid['awaits_from']) . ' 23:59:59'; break; case 'calendar': $date = date('Y-m-d', strtotime($nid['awaits_from'] . ' +' . 5 . ' days')) . ' 23:59:59'; break; default: throw new Exception('Misconfiguration in negotiations.settings table'); } } $to_exp++; try { $model->update(array('closing_time' => $date), 'id = \'' . $nid['id'] . '\''); } catch (Exception $e) { $errs++; } echo $to_exp . "\t" . $errs . "\n"; } $adapter->query(<<<SQL ALTER TABLE negotiations.negotiation_step ENABLE TRIGGER negotiation_step_last_update_refresh SQL ); if ($errs == 0) { $logger->info('Successfuly expired all qualifying negotiations (' . $to_exp . ')'); } else { $logger->warn('Negotiations qualifying for expiration processed with errors. ' . $errs . '/' . count($to_exp) . ' failed. Check previous log messages for details.'); } } catch (Exception $e) { $logger->crit($e->getMessage()); } $logger->info('Script executed succesfully'); exit(0); }
public function dateUtilsCache() { $cache = $this->getResource('cachemanager')->getCache('dictcache'); Logic_DateUtils::setCache($cache); }
public function getExitrationDate($considering = FALSE, $start = null) { if ($start === null) { $start = date('Y-m-d H:i:s', time()); } $start = explode(' ', $start); if (@Logic_DateUtils::isWorkingDay($start[0])) { $work = -1; } else { $work = 0; } if ($considering !== FALSE) { switch ($this->get('dsk_decision_validity_days_type')) { case 'working': return @Logic_DateUtils::getDateByWorkingDays($this->get('dsk_decision_validity_days') + $work, $start[0]) . " 23:59:59"; break; case 'calendar': return date('Y-m-d', strtotime($start[0] . ' + ' . ($this->get('dsk_decision_validity_days') - 1) . ' days')) . ' ' . $start[1]; break; default: throw new Exception('No time utils present in database', '00'); } } else { switch ($this->get('no_response_dsk_decision_validity_days_type')) { case 'working': return @Logic_DateUtils::getDateByWorkingDays($this->get('no_response_dsk_decision_validity_days') + $work, $start[0]) . " 23:59:59"; break; case 'calendar': return date('Y-m-d', strtotime($start[0] . ' + ' . ($this->get('no_response_dsk_decision_validity_days') - 1) . ' days')) . ' ' . $start[0]; break; default: throw new Exception('No time utils present in database', '00'); } } }
/** * @param Zend_Cache_Core $cache */ public static function setCache(Zend_Cache_Core $cache = null) { self::$_cache = $cache; }