public function render($dados)
 {
     $this->Cell(array_sum($this->columnsWidth), 9, utf8_decode('Total de Registros: ' . count($dados)), 1, 0, 'L', 0);
     $this->Ln();
     $this->tableHeader();
     $this->SetFont('Arial', '', 8);
     $this->SetFillColor(224, 235, 255);
     $x = 0;
     foreach ($dados as $tratamento) {
         $inclusao = \DateTime::createFromFormat('Y-m-d', $tratamento->tto_data_inicio);
         $hoje = new \DateTimeImmutable();
         $nascimento = \DateTime::createFromFormat('Y-m-d', $tratamento->pac_nascimento);
         $idade = $hoje->diff($nascimento);
         $duracao = $hoje->diff($inclusao);
         $arTr = explode(' ', $tratamento->prof_nome);
         $fill = $x % 2 === 0;
         $this->SetLineWidth('.3');
         $this->Cell($this->columnsWidth[0], $this->lineHeight, $x + 1, 1, 0, 'L', $fill);
         $this->Cell($this->columnsWidth[1], $this->lineHeight, utf8_decode($tratamento->pac_nome), 1, 0, 'L', $fill);
         $this->Cell($this->columnsWidth[2], $this->lineHeight, utf8_decode($tratamento->pac_cns), 1, 0, 'L', $fill);
         $this->Cell($this->columnsWidth[3], $this->lineHeight, $tratamento->tto_diagnostico, 1, 0, 'L', $fill);
         $this->Cell($this->columnsWidth[4], $this->lineHeight, $tratamento->pac_sexo, 1, 0, 'L', $fill);
         $this->Cell($this->columnsWidth[5], $this->lineHeight, $inclusao->format('d-m-Y'), 1, 0, 'L', $fill);
         $this->Cell($this->columnsWidth[6], $this->lineHeight, utf8_decode($tratamento->tto_turno), 1, 0, 'L', $fill);
         $this->Cell($this->columnsWidth[7], $this->lineHeight, utf8_decode($arTr[0]), 1, 0, 'L', $fill);
         $this->Cell($this->columnsWidth[8], $this->lineHeight, utf8_decode($duracao->format('%a dias')), 1, 0, 'L', $fill);
         $this->Cell($this->columnsWidth[9], $this->lineHeight, utf8_decode($idade->format('%Y Anos')), 1, 0, 'L', $fill);
         $this->Cell($this->columnsWidth[10], $this->lineHeight, utf8_decode(html_entity_decode($tratamento->ubs_nome)), 1, 0, 'L', $fill);
         $this->Ln();
         $x++;
     }
     $this->Cell(array_sum($this->columnsWidth), 0, '', 'T');
 }
Exemplo n.º 2
0
 /**
  * @param boolean $ago Do we add 'ago' to interval.
  *
  * @return string
  * @since 2015-08-07
  */
 public function ago($ago = true)
 {
     $l = $this->lang;
     $s = $l->seperator();
     $to = $this->to;
     if ($to === null) {
         $to = new \DateTimeImmutable('now', $this->from->getTimezone());
     }
     $int = $this->from->diff($to);
     $ret = $l->format($int, $ago);
     return $ret;
 }
Exemplo n.º 3
0
 /**
  * @dataProvider dateIntervalStrings
  * @param string $intervalSpec
  * @param array $parts
  */
 public function testFromDateInterval($intervalSpec, array $parts)
 {
     $interval = DateInterval::fromDateInterval(new \DateInterval($intervalSpec));
     self::assertInstanceOf(DateInterval::class, $interval);
     self::assertEquals($parts[0], $interval->y);
     self::assertEquals($parts[1], $interval->m);
     self::assertEquals($parts[2], $interval->d);
     self::assertEquals($parts[3], $interval->h);
     self::assertEquals($parts[4], $interval->i);
     self::assertEquals($parts[5], $interval->s);
     // Test for extreme case when diff between winter and summer time returns interval with negative hour
     $phpDate1 = new \DateTimeImmutable('2016-11-22 11:00:00');
     $phpDate2 = new \DateTimeImmutable('2016-08-22 12:00:00');
     $phpInterval = $phpDate1->diff($phpDate2);
     $interval = DateInterval::fromDateInterval($phpInterval);
     self::assertEquals('P3MT-1H', (string) $interval);
 }
Exemplo n.º 4
0
 /**
  * @param \DateTimeInterface $dateTime
  * @param bool $absolute
  * @return DateInterval
  */
 public function diff($dateTime, $absolute = false)
 {
     return DateInterval::fromDateInterval(parent::diff($dateTime, $absolute));
 }
Exemplo n.º 5
0
 /**
  * Checks if the token is expired comparing
  * with the given lifetime.
  *
  * @param int $lifetime The lifetime of the token
  *
  * @return bool
  */
 public function isExpired($lifetime)
 {
     $interval = $this->createdOn->diff(new \DateTimeImmutable());
     return $interval->s >= (int) $lifetime;
 }
Exemplo n.º 6
0
function generatePriceReturning()
{
    $isValidInput = true;
    $_SESSION['typeReturning'] = true;
    $dbhandle = mysql_connect("localhost", "root", "") or die("Could not connect to database");
    $selected = mysql_select_db("airone", $dbhandle);
    $query1 = 'SELECT DistanceIndex FROM cities WHERE CityName = "' . $_GET['from'] . '"';
    $distanceIndex1 = mysql_query($query1) or die(mysql_error() . "[" . $query1 . "]");
    $distanceIndex1fetched = mysql_fetch_array($distanceIndex1);
    $distance1 = intval($distanceIndex1fetched['DistanceIndex']);
    $query2 = 'SELECT DistanceIndex FROM cities WHERE CityName = "' . $_GET['To'] . '"';
    $distanceIndex2 = mysql_query($query2) or die(mysql_error() . "[" . $query2 . "]");
    $distanceIndex2fetched = mysql_fetch_array($distanceIndex2);
    $distance2 = intval($distanceIndex2fetched['DistanceIndex']);
    mysql_close();
    if ($distance2 > $distance1) {
        $priceIndex = $distance2 - $distance1;
    } else {
        $priceIndex = $distance1 - $distance2;
    }
    switch ($priceIndex) {
        case 0:
            $defaultPrice = 60;
            break;
        case 1:
            $defaultPrice = 70;
            break;
        case 2:
            $defaultPrice = 80;
            break;
        case 3:
            $defaultPrice = 90;
            break;
        case 4:
            $defaultPrice = 100;
            break;
        case 5:
            $defaultPrice = 120;
            break;
        case 6:
            $defaultPrice = 140;
            break;
        case 7:
            $defaultPrice = 170;
            break;
        case 8:
            $defaultPrice = 200;
            break;
    }
    switch ($_GET['flightClass']) {
        case 'Business':
            $defaultPrice *= 1.4;
            break;
    }
    $returningDateInput = str_replace('/', '-', $_GET['returning']);
    $departingDateInput = str_replace('/', '-', $_GET['departing']);
    $returningDate = new DateTimeImmutable($returningDateInput);
    $minus3days = $returningDate->modify('-3 days');
    $minus2days = $returningDate->modify('-2 days');
    $minus1day = $returningDate->modify('-1 day');
    $plus1day = $returningDate->modify('+1 day');
    $plus2days = $returningDate->modify('+2 days');
    $plus3days = $returningDate->modify('+3 days');
    $todayInit = date('Y-m-d');
    $today = new DateTime($todayInit);
    $timeDifferenceReturning = $returningDate->diff($today)->format("%a");
    $timeDifferenceReturning = intval($timeDifferenceReturning);
    if ($timeDifferenceReturning <= 30) {
        $defaultPrice *= 1.1;
    } else {
        if ($timeDifferenceReturning > 30 && $timeDifferenceReturning <= 60) {
            $defaultPrice -= 1;
        } else {
            if ($timeDifferenceReturning > 60 && $timeDifferenceReturning <= 90) {
                $defaultPrice *= 0.9;
            } else {
                $defaultPrice *= 0.75;
            }
        }
    }
    $defaultPrice = floor($defaultPrice);
    switch ($timeDifferenceReturning) {
        case $timeDifferenceReturning < 0:
            echo "Returning date cannot be earlier than departing date!";
            $isValidInput = false;
            break;
        case 0:
            $minus3daysPrice = "";
            $minus2daysPrice = "";
            $minus1dayPrice = "";
            $plus1dayPrice = '<input type="radio" name="book-returning"  onclick="ticketInfoReturning(this.value)"
                    value="' . $defaultPrice . '_' . $plus1day->format('d M Y') . '">' . $defaultPrice . "€";
            $plus2daysPrice = '<input type="radio" name="book-returning"  onclick="ticketInfoReturning(this.value)"
                    value="' . $defaultPrice . '_' . $plus2days->format('d M Y') . '">' . $defaultPrice . "€";
            $plus3daysPrice = '<input type="radio" name="book-returning"  onclick="ticketInfoReturning(this.value)"
                     value="' . floor($defaultPrice * 0.95) . '_' . $plus3days->format('d M Y') . '">' . floor($defaultPrice * 0.95) . "€";
            $defaultPrice = "";
            break;
        case 1:
            $minus3daysPrice = "";
            $minus2daysPrice = "";
            $minus1dayPrice = '<input type="radio" name="book-returning"  onclick="ticketInfoReturning(this.value)"
                    value="' . floor($defaultPrice * 1.02) . '_' . $minus1day->format('d M Y') . '">' . floor($defaultPrice * 1.02) . "€";
            $day0Price = '<input type="radio" name="book-returning"  onclick="ticketInfoReturning(this.value)"
                    value="' . $defaultPrice . '_' . $returningDate->format('d M Y') . '">' . $defaultPrice . "€";
            $plus1dayPrice = '<input type="radio" name="book-returning"  onclick="ticketInfoReturning(this.value)"
                    value="' . $defaultPrice . '_' . $plus1day->format('d M Y') . '">' . $defaultPrice . "€";
            $plus2daysPrice = '<input type="radio" name="book-returning"  onclick="ticketInfoReturning(this.value)"
                    value="' . $defaultPrice . '_' . $plus2days->format('d M Y') . '">' . $defaultPrice . "€";
            $plus3daysPrice = '<input type="radio" name="book-returning"  onclick="ticketInfoReturning(this.value)"
                    value="' . floor($defaultPrice * 0.95) . '_' . $plus3days->format('d M Y') . '">' . floor($defaultPrice * 0.95) . "€";
            break;
        case 2:
            $minus3daysPrice = "";
            $minus2daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                     value="' . floor($defaultPrice * 1.02) . '_' . $minus2days->format('d M Y') . '">' . floor($defaultPrice * 1.02) . "€";
            $minus1dayPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                     value="' . floor($defaultPrice * 1.02) . '_' . $minus1day->format('d M Y') . '">' . floor($defaultPrice * 1.02) . "€";
            $day0Price = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                     value="' . $defaultPrice . '_' . $returningDate->format('d M Y') . '">' . $defaultPrice . "€";
            $plus1dayPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                    value="' . $defaultPrice . '_' . $plus1day->format('d M Y') . '">' . $defaultPrice . "€";
            $plus2daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                    value="' . $defaultPrice . '_' . $plus2days->format('d M Y') . '">' . $defaultPrice . "€";
            $plus3daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                     value="' . floor($defaultPrice * 0.95) . '_' . $plus3days->format('d M Y') . '">' . floor($defaultPrice * 0.95) . "€";
            break;
        case 3:
            $minus3daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                    value="' . floor($defaultPrice * 1.07) . '_' . $minus3days->format('d M Y') . '">' . floor($defaultPrice * 1.07) . "€";
            $minus2daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                    value="' . floor($defaultPrice * 1.05) . '_' . $minus2days->format('d M Y') . '">' . floor($defaultPrice * 1.05) . "€";
            $minus1dayPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                    value="' . floor($defaultPrice * 1.05) . '_' . $minus1day->format('d M Y') . '">' . floor($defaultPrice * 1.05) . "€";
            $day0Price = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                    value="' . $defaultPrice . '_' . $returningDate->format('d M Y') . '">' . $defaultPrice . "€";
            $plus1dayPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                    value="' . $defaultPrice . '_' . $plus1day->format('d M Y') . '">' . $defaultPrice . "€";
            $plus2daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                     value="' . $defaultPrice . '_' . $plus2days->format('d M Y') . '">' . $defaultPrice . "€";
            $plus3daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                     value="' . floor($defaultPrice * 0.95) . '_' . $plus3days->format('d M Y') . '">' . floor($defaultPrice * 0.95) . "€";
            break;
        default:
            $minus3daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                    value="' . floor($defaultPrice * 1.05) . '_' . $minus3days->format('d M Y') . '">' . floor($defaultPrice * 1.05) . "€";
            $minus2daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                     value="' . floor($defaultPrice * 1.02) . '_' . $minus2days->format('d M Y') . '">' . floor($defaultPrice * 1.02) . "€";
            $minus1dayPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                    value="' . floor($defaultPrice * 1.02) . '_' . $minus1day->format('d M Y') . '">' . floor($defaultPrice * 1.02) . "€";
            $day0Price = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                     value="' . $defaultPrice . '_' . $returningDate->format('d M Y') . '">' . $defaultPrice . "€";
            $plus1dayPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                     value="' . $defaultPrice . '_' . $plus1day->format('d M Y') . '">' . $defaultPrice . "€";
            $plus2daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                     value="' . $defaultPrice . '_' . $plus2days->format('d M Y') . '">' . $defaultPrice . "€";
            $plus3daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
                     value="' . floor($defaultPrice * 0.95) . '_' . $plus3days->format('d M Y') . '">' . floor($defaultPrice * 0.95) . "€";
    }
    if ($isValidInput) {
        echo '<p>' . $_GET['To'] . ' - ' . $_GET['from'] . '</p>';
        echo '<table class="flightTimetable"><tr>';
        echo "<th>" . $minus3days->format('d M Y') . "</th>";
        echo "<th>" . $minus2days->format('d M Y') . "</th>";
        echo "<th>" . $minus1day->format('d M Y') . "</th>";
        echo "<th>" . $returningDate->format('d M Y') . "</th>";
        echo "<th>" . $plus1day->format('d M Y') . "</th>";
        echo "<th>" . $plus2days->format('d M Y') . "</th>";
        echo "<th>" . $plus3days->format('d M Y') . "</th>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>" . $minus3daysPrice . "</td>";
        echo "<td>" . $minus2daysPrice . "</td>";
        echo "<td>" . $minus1dayPrice . "</td>";
        echo "<td>" . $day0Price . "</td>";
        echo "<td>" . $plus1dayPrice . "</td>";
        echo "<td>" . $plus2daysPrice . "</td>";
        echo "<td>" . $plus3daysPrice . "</td>";
        echo "</tr></table>";
    }
}
Exemplo n.º 7
0
 /**
  * Create a PeriodLib object from a Year and a Quarter.
  *
  * @param PeriodLib $period
  *
  * @return \DateInterval
  */
 public function dateIntervalDiff(PeriodLib $period)
 {
     return $this->endDate->diff($this->withDuration($period->getTimestampInterval())->endDate);
 }