Skip to content

Commit

Permalink
add more fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
ad3n committed Nov 1, 2017
1 parent 7ec3c40 commit 347eef5
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .php_cs.cache

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion config/semart/twig_extension.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
services:
KejawenLab\Application\SemartHris\Twig\SemartHrisAttendanceTwigExtension:
KejawenLab\Application\SemartHris\Twig\AttendanceExtension:
lazy: true
arguments:
- '@KejawenLab\Application\SemartHris\Repository\EmployeeRepository'
- '@KejawenLab\Application\SemartHris\Repository\ReasonRepository'
- 'KejawenLab\Application\SemartHris\Entity\Attendance'
tags:
- { name: 'twig.extension' }

KejawenLab\Application\SemartHris\Twig\HolidayExtension:
lazy: true
arguments:
- '@KejawenLab\Application\SemartHris\Repository\HolidayRepository'
tags:
- { name: 'twig.extension' }
2 changes: 1 addition & 1 deletion data/company.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- { code: 'SSI', name: 'PT. SEMART SOLUSI INDONESIA', birthDay: 'date:2017-11-27', email: 'admin@kejawenlab.com', taxNumber: '338-00-0912-244' }
- { code: 'SSI', name: 'PT. SEMART SOLUSI INDONESIA', birthDay: 'date:17-11-1977', email: 'admin@kejawenlab.com', taxNumber: '338-00-0912-244' }
1 change: 1 addition & 0 deletions data/holiday.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- { holidayDate: 'year:10-11', name: 'HARI PAHLAWAN' }
2 changes: 1 addition & 1 deletion src/Component/Attendance/Service/AttendanceProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __construct(
public function process(EmployeeInterface $employee, \DateTimeInterface $date): void
{
$cutOff = getenv(self::CUT_OFF_KEY);
if ((int) $cutOff === self::CUT_OFF_LAST_DATE) {
if (self::CUT_OFF_LAST_DATE === (int) $cutOff) {
$this->processFullMonth($employee, $date);
} else {
$this->processPartialMonth($employee, $date, $cutOff);
Expand Down
15 changes: 15 additions & 0 deletions src/Component/Holiday/Repository/HolidayRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace KejawenLab\Application\SemartHris\Component\Holiday\Repository;
use KejawenLab\Application\SemartHris\Component\Holiday\Model\HolidayInterface;

/**
* @author Muhamad Surya Iksanudin <surya.iksanudin@kejawenlab.com>
Expand All @@ -13,4 +14,18 @@ interface HolidayRepositoryInterface
* @return bool
*/
public function isHoliday(\DateTimeInterface $date): bool;

/**
* @param \DateTimeInterface $date
*
* @return bool
*/
public function isWeekendHoliday(\DateTimeInterface $date): bool;

/**
* @param \DateTimeInterface $date
*
* @return HolidayInterface|null
*/
public function getHoliday(\DateTimeInterface $date): ? HolidayInterface;
}
7 changes: 6 additions & 1 deletion src/DataFixtures/ORM/Fixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\Bundle\FixturesBundle\Fixture as Base;
use Doctrine\Common\Persistence\ObjectManager;
use KejawenLab\Application\SemartHris\Util\Setting;
use KejawenLab\Application\SemartHris\Util\StringUtil;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Yaml\Yaml;
Expand Down Expand Up @@ -44,7 +45,11 @@ public function load(ObjectManager $manager)
}

if (false !== strpos($value, 'date:')) {
$value = \DateTime::createFromFormat('Y-m-d', str_replace('date:', '', $value));
$value = \DateTime::createFromFormat(Setting::get(Setting::DATE_FORMAT), str_replace('date:', '', $value));
}

if (is_string($value) && false !== strpos($value, 'year')) {
$value = \DateTime::createFromFormat(Setting::get(Setting::DATE_FORMAT), sprintf('%s-%s', str_replace('year:', '', $value), date('Y')));
}

$accessor->setValue($entity, $key, $value);
Expand Down
35 changes: 35 additions & 0 deletions src/DataFixtures/ORM/HolidayFixtures.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace KejawenLab\Application\SemartHris\DataFixtures\ORM;

use KejawenLab\Application\SemartHris\Entity\Holiday;

/**
* @author Muhamad Surya Iksanudin <surya.iksanudin@kejawenlab.id>
*/
class HolidayFixtures extends Fixture
{
/**
* @return string
*/
protected function getFixtureFilePath(): string
{
return 'holiday.yaml';
}

/**
* @return mixed
*/
protected function createNew()
{
return new Holiday();
}

/**
* @return string
*/
protected function getReferenceKey(): string
{
return 'holiday';
}
}
27 changes: 26 additions & 1 deletion src/Repository/HolidayRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace KejawenLab\Application\SemartHris\Repository;

use KejawenLab\Application\SemartHris\Component\Holiday\Model\HolidayInterface;
use KejawenLab\Application\SemartHris\Component\Holiday\Repository\HolidayRepositoryInterface;

/**
Expand Down Expand Up @@ -32,7 +33,7 @@ public function __construct(string $offDayPerWeek)
*/
public function isHoliday(\DateTimeInterface $date): bool
{
if (in_array($date->format('N'), $this->offDayPerWeek)) {
if ($this->isWeekendHoliday($date)) {
return true;
}

Expand All @@ -47,4 +48,28 @@ public function isHoliday(\DateTimeInterface $date): bool

return false;
}

/**
* @param \DateTimeInterface $date
*
* @return bool
*/
public function isWeekendHoliday(\DateTimeInterface $date): bool
{
if (in_array($date->format('N'), $this->offDayPerWeek)) {
return true;
}

return false;
}

/**
* @param \DateTimeInterface $date
*
* @return HolidayInterface|null
*/
public function getHoliday(\DateTimeInterface $date): ? HolidayInterface
{
return $this->entityManager->getRepository($this->entityClass)->findOneBy(['holidayDate' => $date]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* @author Muhamad Surya Iksanudin <surya.iksanudin@kejawenlab.com>
*/
class SemartHrisAttendanceTwigExtension extends \Twig_Extension
class AttendanceExtension extends \Twig_Extension
{
/**
* @var EmployeeRepositoryInterface
Expand Down
72 changes: 72 additions & 0 deletions src/Twig/HolidayExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace KejawenLab\Application\SemartHris\Twig;

use KejawenLab\Application\SemartHris\Component\Holiday\Model\HolidayInterface;
use KejawenLab\Application\SemartHris\Component\Holiday\Repository\HolidayRepositoryInterface;

/**
* @author Muhamad Surya Iksanudin <surya.iksanudin@kejawenlab.com>
*/
class HolidayExtension extends \Twig_Extension
{
/**
* @var HolidayRepositoryInterface
*/
private $holidayRepository;

/**
* @param HolidayRepositoryInterface $repository
*/
public function __construct(HolidayRepositoryInterface $repository)
{
$this->holidayRepository = $repository;
}

/**
* @return array
*/
public function getFunctions(): array
{
return array(
new \Twig_SimpleFunction('semarthris_is_holiday', array($this, 'isHoliday')),
new \Twig_SimpleFunction('semarthris_holiday', array($this, 'getHoliday')),
new \Twig_SimpleFunction('semarthris_is_weekend_holiday', array($this, 'isWeekendHoliday')),
);
}

/**
* @param \DateTimeInterface $date
*
* @return bool
*/
public function isHoliday(\DateTimeInterface $date): bool
{
$holiday = $this->holidayRepository->isWeekendHoliday($date);
if (!$holiday) {
$holiday = $this->holidayRepository->isHoliday($date);
}

return $holiday;
}

/**
* @param \DateTimeInterface $date
*
* @return HolidayInterface|null
*/
public function getHoliday(\DateTimeInterface $date): ? HolidayInterface
{
return $this->holidayRepository->getHoliday($date);
}

/**
* @param \DateTimeInterface $date
*
* @return bool
*/
public function isWeekendHoliday(\DateTimeInterface $date): bool
{
return $this->holidayRepository->isWeekendHoliday($date);
}
}
9 changes: 6 additions & 3 deletions templates/app/attendance/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
%}

{% set _entity_config = easyadmin_entity(app.request.query.get('entity')) %}

{% set startDate = app.request.get('startDate', date() | date('01-m-Y')) %}

{% set endDate = app.request.get('endDate', date() | date('t-m-Y')) %}

{% set _request_parameters = _request_parameters|default({})|merge({
Expand Down Expand Up @@ -152,7 +150,12 @@
{% else %}
<tr data-id="{{ key }}">
<td>{{ key }}</td>
<td colspan="8" class="label label-primary text-center">{{ 'semarthris.holiday' | trans({}, 'messages') | upper }}</span>
<td colspan="8" class="label label-primary text-center">
{% if semarthris_is_weekend_holiday(key | date(date_format)) %}
{{ 'semarthris.weekend_holiday' | trans({}, 'messages') | upper }}
{% else %}
{{ semarthris_holiday(key | date(date_format)) | upper }}
{% endif %}
</td>
</tr>
{% endif %}
Expand Down
6 changes: 3 additions & 3 deletions translations/messages.id.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@
<source>semarthris.setting_key</source>
<target>Parameter</target>
</trans-unit>
<trans-unit id="semarthris.holiday">
<source>semarthris.holiday</source>
<target>Hari Libur</target>
<trans-unit id="semarthris.weekend_holiday">
<source>semarthris.weekend_holiday</source>
<target>Libur Akhir Pekan</target>
</trans-unit>
<trans-unit id="semarthris.setting_value">
<source>semarthris.setting_value</source>
Expand Down

0 comments on commit 347eef5

Please sign in to comment.