function find($criteria = null, $order = null, $limit = 1000, $from = 0) { $result = $this->database->query($this->buildFindQuery($criteria, $order, $limit, $from)); if (!is_null($result->getError())) { return $result->getError(); } $eventHistorys = array(); while ($row = $result->fetchRow()) { $eventHistory = new EventHistory(); $value = $row[0]; $eventHistory->setId($value); $value = $row[1]; $eventHistory->setPid($value); $value = $row[2]; $eventHistory->setCid($value); $value = $row[3]; $eventHistory->setSid($value); $value = $row[4]; $eventHistory->setEid($value); $value = $row[5]; $eventHistory->setValid_date($value); $value = $row[6]; $eventHistory->setReminde_date($value); $value = $row[7]; $eventHistory->setAmount($value); $value = $row[8]; $eventHistory->setState($value); $value = $row[9]; $eventHistory->setComment($value); $value = $row[10]; $eventHistory->setBalance($value); $value = $row[11]; $eventHistory->setR_date($value); $value = $row[12]; $eventHistory->setDescription($value); if ($order != null) { array_push($eventHistorys, $eventHistory); } else { $eventHistorys[$eventHistory->getId()] = $eventHistory; } } return $eventHistorys; }
function checkDelays() { $criteria = new AndStatement(); $field = $this->eventDao->getQStateName(); $criteria->addStatement($field . "=1"); $field = $this->eventDao->getQValid_dateName(); $criteria->addStatement($field . "< NOW()"); $field = $this->eventDao->getQDelayName(); $criteria->addStatement($field . "=0"); $events = $this->eventDao->find($criteria, null); if (is_null($events) || is_string($events) || count($events) == 0) { return false; } foreach ($events as $event) { $project = $this->getProject($event->getPid()); if (!is_object($project)) { $mail = new Mail(); $mail->setTo("*****@*****.**"); $mail->setSubject("WorkFlow.lt Klaida nuskaitant projekta | checkDelays"); if (is_string($project)) { $mail->setText($project); } $mail->sendMail(); continue; } $stage = $this->getStageById($event->getSid()); if (!is_object($stage)) { $mail = new Mail(); $mail->setTo("*****@*****.**"); $mail->setSubject("WorkFlow.lt Klaida nuskaitant etapa | checkDelays"); if (is_string($stage)) { $mail->setText($stage); } $mail->sendMail(); continue; } $client = $this->getClientById($event->getCid()); if (!is_object($client)) { $mail = new Mail(); $mail->setTo("*****@*****.**"); $mail->setSubject("WorkFlow.lt Klaida nuskaitant klienta | checkDelays"); if (is_string($client)) { $mail->setText($client); } //$mail->sendMail(); continue; } if (!$client->isActive() || $client->isEnded() || $client->isEnded_eve() || $client->isMoved()) { continue; } $event->setDelays($event->getDelays() + 1); $event->setDelay(true); $this->storeEvent($event); $rss = new Rss($project->getRsskey()); $eventRss = new EventRss(); $eventRss->title = $eventRss->getText("warningTitle", array($project->getName())); $eventRss->description = $eventRss->getText("warningDescription", array($project->getName(), $stage->getName(), $this->formatClientInfo($client))); $eventRss->link = addslashes(htmlspecialchars($this->partnerUrl)) . addslashes(htmlspecialchars($project->getCruid())); $eventRss->pubDate = Carbon::now()->toRssString(); $eventRss->PID = $project->getId(); $eventRss->CID = $client->getId(); $eventRss->SID = $stage->getId(); if (!$rss->addEvent($project, $eventRss)) { $mail = new Mail(); $mail->setTo("*****@*****.**"); $mail->setSubject("WorkFlow.lt Klaida kuriant RSS irasa | checkDelays"); $mail->setText(print_r($eventRss, true)); $mail->sendMail(); } $eventHistory = new EventHistory(); $eventHistory->setPid($event->getPid()); $eventHistory->setCid($event->getCid()); $eventHistory->setSid($event->getSid()); $eventHistory->setEid($event->getId()); $eventHistory->setR_date(Carbon::Now()->toDateTimeString()); $eventHistory->setDescription("Pradėtas vieluoti etapas"); $eventHistory->setValid_date($event->getValid_date()); $this->storeEventHistory($eventHistory); } }
function actionSaveEvent($currentProject) { $backUrl = $this->context->getFlowScopeAttr("backUrl"); $arUzbaigtas = $this->context->getRequestAttr("uzbaigtas"); $renderNew = $this->context->getRequestAttr("rendernew"); $renderNew = $renderNew == "1" ? $renderNew : "0"; $timeZone = new DateTimeZone("Europe/Vilnius"); $time = new DateTime("now", $timeZone); $eventErrs = array(); $eventID = $this->context->getRequestAttr("id"); $state = $this->context->getRequestAttr("state"); if (is_null($eventID)) { $this->context->setRequestScopeAttr("errortxt", "stage.error.notfound"); if (!is_null($backUrl)) { header("Location: " . $backUrl); return true; } return false; } $event = $this->eventDao->get($eventID); if (is_null($event)) { $this->context->setRequestScopeAttr("error", "stage.error.notfound"); $this->cancelEditEvent(); return false; } else { if (is_string($event)) { $this->context->setRequestScopeAttr("error", "error.dberror"); $this->context->setRequestScopeAttr("errortxt", $event); $event = null; $this->cancelEditEvent(); return false; } } $stage = $this->stageDao->get($event->getSid()); if (!is_object($stage)) { $this->context->setRequestScopeAttr("error", "stage.error.notfound"); $this->cancelEditEvent(); return false; } $client = $this->clientDaol->get($event->getCid()); if (!is_object($client)) { $this->context->setRequestScopeAttr("error", "client.error.notfound"); $this->cancelEditEvent(); return false; } $event->setR_date($time->format("Y-m-d H:i:s")); $event->setComment($this->context->getRequestAttr("comment")); if (!is_null($event->getComment())) { $event->setComment(trim($event->getComment())); if (strlen($event->getComment()) < 1) { $event->setComment(null); } } #region BALANCE $eventCopy = clone $event; $event->setIncome($this->context->getRequestAttr("income")); if (!is_null($event->getIncome())) { $event->setIncome(trim($event->getIncome())); if (strlen($event->getIncome()) < 1) { $event->setIncome(null); } } if (!is_null($event->getIncome()) && !is_numeric($event->getIncome())) { $eventErrs['balanse'] = true; } $event->setCost($this->context->getRequestAttr("cost")); if (!is_null($event->getCost())) { $event->setCost(trim($event->getCost())); if (strlen($event->getCost()) < 1) { $event->setCost(null); } } if (!is_null($event->getCost()) && !is_numeric($event->getCost())) { $eventErrs['balanse'] = true; } $event->setWasted_time($this->context->getRequestAttr("wasted_time")); if (!is_null($event->getWasted_time())) { $event->setWasted_time(trim($event->getWasted_time())); if (strlen($event->getWasted_time()) < 1) { $event->setWasted_time(null); } } if (!is_null($event->getWasted_time()) && !is_numeric($event->getWasted_time())) { $eventErrs['balanse'] = true; } $this->context->setFlashScopeAttr("event", $event); $this->context->setFlashScopeAttr("eventErrs", $eventErrs); if (count($eventErrs) >= 1) { if (!is_null($backUrl)) { header("Location: " . $backUrl); return true; } return false; } $event->setState(2); /* PELNAS */ $income = !is_null($event->getIncome()) ? $event->getIncome() : 0; $cost = !is_null($event->getCost()) ? $event->getCost() : 0; if ($income != 0 || $cost != 0) { $profit = $income - $cost; } if ($profit) { $event->setProfit($profit); } if (!is_null($eventCopy->getIncome())) { if (!is_null($event->getIncome())) { $event->setIncome($eventCopy->getIncome() + $event->getIncome()); } else { $event->setIncome($eventCopy->getIncome()); } } if (!is_null($eventCopy->getCost())) { if (!is_null($event->getCost())) { $event->setCost($eventCopy->getCost() + $event->getCost()); } else { $event->setCost($eventCopy->getCost()); } } if (!is_null($eventCopy->getProfit())) { if (!is_null($event->getProfit())) { $event->setProfit($eventCopy->getProfit() + $event->getProfit()); } else { $event->setProfit($eventCopy->getProfit()); } } if (!is_null($eventCopy->getWasted_time())) { if (!is_null($event->getWasted_time())) { $event->setWasted_time($eventCopy->getWasted_time() + $event->getWasted_time()); } else { $event->setWasted_time($eventCopy->getWasted_time()); } } #endregion $store = $this->storeEvent($event, $stage, $renderNew); if (!$store) { if (!is_null($backUrl)) { header("Location: " . $backUrl); return true; } return false; } $eventHistory = new EventHistory(); $eventHistory->setDescription("Etapo užbaigimas"); $eventHistory->setPid($event->getPid()); $eventHistory->setCid($event->getCid()); $eventHistory->setSid($event->getSid()); $eventHistory->setEid($event->getId()); $eventHistory->setValid_date($event->getValid_date()); $eventHistory->setReminde_date($event->getReminde_date()); $eventHistory->setState($event->getState()); $eventHistory->setComment($event->getComment()); $eventHistory->setR_date($event->getR_date()); $balance = ""; if (!is_null($event->getIncome())) { $balance .= (!empty($balance) ? "<br />" : "") . 'Pajamos - ' . $event->getIncome() . '€'; } if (!is_null($event->getCost())) { $balance .= (!empty($balance) ? "<br />" : "") . 'Išlaidos - ' . $event->getCost() . '€'; } if (!is_null($event->getProfit())) { $balance .= (!empty($balance) ? "<br />" : "") . 'Pelnas (nuostolis) - ' . $event->getProfit() . '€'; } if (!is_null($event->getWasted_time())) { $balance .= (!empty($balance) ? "<br />" : "") . 'Sugaištas laikas - ' . $event->getWasted_time() . 'min.'; } if (!empty($balance)) { $eventHistory->setBalance($balance); } $this->storeEventHistory($eventHistory); if ($stage->getEnded_stage() != 0) { $action = $stage->getEnded_stage() == 1 ? "copy" : "move"; $projects = explode(",", $stage->getEnded_stage_pid()); foreach ($projects as $projectId) { $this->moveCopyClient($client, $projectId, $action); } } $this->cancelEditEvent(); if (!is_null($backUrl)) { header("Location: " . $backUrl); return true; } return false; }