diff --git a/src/DataFixtures/ReservationFixtures.php b/src/DataFixtures/ReservationFixtures.php index 9e4e791..ed84524 100644 --- a/src/DataFixtures/ReservationFixtures.php +++ b/src/DataFixtures/ReservationFixtures.php @@ -1,148 +1,148 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace App\DataFixtures; - -use Doctrine\Bundle\FixturesBundle\Fixture; -use Doctrine\Common\Persistence\ObjectManager; -use Symfony\Contracts\Translation\TranslatorInterface; -use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface; -use Doctrine\Common\DataFixtures\DependentFixtureInterface; -use App\DataFixtures\SettingsFixtures; - -use App\Entity\ReservationOrigin; -use App\Entity\Appartment; -use App\Entity\Price; -use App\Entity\Reservation; -use App\Entity\Customer; -use App\Entity\Invoice; -use App\Entity\InvoiceAppartment; -use App\Entity\InvoicePosition; -use App\Entity\CustomerAddresses; - -class ReservationFixtures extends Fixture implements FixtureGroupInterface, DependentFixtureInterface -{ - private $translator; - public function __construct(TranslatorInterface $translator) { - $this->translator = $translator; - } - - public static function getGroups(): array - { - return ['reservation', 'invoices']; - } - - public function getDependencies() - { - return array( - SettingsFixtures::class, - ); - } - - public function load(ObjectManager $manager) - { - - $apps = $manager->getRepository(Appartment::class)->findAll(); - $origins = $manager->getRepository(ReservationOrigin::class)->findAll(); - $customer = $manager->getRepository(Customer::class)->findOneBy(['lastname' => 'Mustermann']); - - if(!($customer instanceof Customer)) { - return; - } - /* @var $app Appartment */ - foreach($apps as $app) { - $start = new \DateTime(); - - $intvall1 = new \DateInterval('P'. rand(1,10) .'D'); - $intvall2 = new \DateInterval('P'. rand(0,5) .'D'); - $start->add($intvall2); - $end = clone $start; - $end->add($intvall1); - - $res = new Reservation(); - $res->setReservationOrigin($origins[0]); - $res->setBooker($customer); - $res->addCustomer($customer); - $res->setPersons($app->getBedsMax()); - $res->setStatus(1); - $res->setStartDate($start); - $res->setEndDate($end); - $res->setAppartment($app); - $res->setReservationDate(new \DateTime()); - - $manager->persist($res); - } - - $manager->flush(); - - $this->createInvoices($manager); - - $manager->flush(); - } - - private function createInvoices(ObjectManager $manager) { - $res = $manager->getRepository(Reservation::class)->findAll(); - /* @var $bPrice Price */ - $bPrice = $manager->getRepository(Price::class)->findOneBy(['type' => 1]); - $invoiceId = 100; - /* @var $re Reservation */ - foreach($res as $re) { - /* @var $aPrice Price */ - $aPrice = $manager->getRepository(Price::class)->findOneBy(['type' => 2, 'numberOfPersons' => $re->getPersons()]); - - $interval = $re->getStartDate()->diff($re->getEndDate()); - $days = $interval->format('%a'); - - $miscPos = new InvoicePosition(); - $appPos = new InvoiceAppartment(); - $invoice = new Invoice(); - - $miscPos->setVat($bPrice->getVat()); - $miscPos->setPrice($bPrice->getPrice()); - $miscPos->setAmount($days * $re->getPersons()); - $miscPos->setDescription($bPrice->getDescription()); - - $manager->persist($miscPos); - - $appPos->setBeds($re->getPersons()); - $appPos->setDescription($aPrice->getDescription()); - $appPos->setStartDate($re->getStartDate()); - $appPos->setEndDate($re->getEndDate()); - $appPos->setVat($aPrice->getVat()); - $appPos->setPrice($aPrice->getPrice()); - $appPos->setPersons($re->getPersons()); - $appPos->setNumber($re->getAppartment()->getNumber()); - - $manager->persist($appPos); - - /* @var $address CustomerAddresses */ - $address = $re->getBooker()->getCustomerAddresses()[0]; - $invoice->setAddress($address->getAddress()); - $invoice->setCity($address->getCity()); - $invoice->setDate(new \DateTime()); - $invoice->setFirstname($re->getBooker()->getFirstname()); - $invoice->setLastname($re->getBooker()->getLastname()); - $invoice->setNumber($invoiceId++); - $invoice->setSalutation($re->getBooker()->getSalutation()); - $invoice->setZip($address->getZip()); - $invoice->setStatus(1); - - $manager->persist($invoice); - - $miscPos->setInvoice($invoice); - $appPos->setInvoice($invoice); - $re->addInvoice($invoice); - - $manager->persist($re); - $manager->persist($appPos); - $manager->persist($miscPos); - } - } -} + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace App\DataFixtures; + +use Doctrine\Bundle\FixturesBundle\Fixture; +use Doctrine\Persistence\ObjectManager; +use Symfony\Contracts\Translation\TranslatorInterface; +use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface; +use Doctrine\Common\DataFixtures\DependentFixtureInterface; +use App\DataFixtures\SettingsFixtures; + +use App\Entity\ReservationOrigin; +use App\Entity\Appartment; +use App\Entity\Price; +use App\Entity\Reservation; +use App\Entity\Customer; +use App\Entity\Invoice; +use App\Entity\InvoiceAppartment; +use App\Entity\InvoicePosition; +use App\Entity\CustomerAddresses; + +class ReservationFixtures extends Fixture implements FixtureGroupInterface, DependentFixtureInterface +{ + private $translator; + public function __construct(TranslatorInterface $translator) { + $this->translator = $translator; + } + + public static function getGroups(): array + { + return ['reservation', 'invoices']; + } + + public function getDependencies() + { + return array( + SettingsFixtures::class, + ); + } + + public function load(ObjectManager $manager) + { + + $apps = $manager->getRepository(Appartment::class)->findAll(); + $origins = $manager->getRepository(ReservationOrigin::class)->findAll(); + $customer = $manager->getRepository(Customer::class)->findOneBy(['lastname' => 'Mustermann']); + + if(!($customer instanceof Customer)) { + return; + } + /* @var $app Appartment */ + foreach($apps as $app) { + $start = new \DateTime(); + + $intvall1 = new \DateInterval('P'. rand(1,10) .'D'); + $intvall2 = new \DateInterval('P'. rand(0,5) .'D'); + $start->add($intvall2); + $end = clone $start; + $end->add($intvall1); + + $res = new Reservation(); + $res->setReservationOrigin($origins[0]); + $res->setBooker($customer); + $res->addCustomer($customer); + $res->setPersons($app->getBedsMax()); + $res->setStatus(1); + $res->setStartDate($start); + $res->setEndDate($end); + $res->setAppartment($app); + $res->setReservationDate(new \DateTime()); + + $manager->persist($res); + } + + $manager->flush(); + + $this->createInvoices($manager); + + $manager->flush(); + } + + private function createInvoices(ObjectManager $manager) { + $res = $manager->getRepository(Reservation::class)->findAll(); + /* @var $bPrice Price */ + $bPrice = $manager->getRepository(Price::class)->findOneBy(['type' => 1]); + $invoiceId = 100; + /* @var $re Reservation */ + foreach($res as $re) { + /* @var $aPrice Price */ + $aPrice = $manager->getRepository(Price::class)->findOneBy(['type' => 2, 'numberOfPersons' => $re->getPersons()]); + + $interval = $re->getStartDate()->diff($re->getEndDate()); + $days = $interval->format('%a'); + + $miscPos = new InvoicePosition(); + $appPos = new InvoiceAppartment(); + $invoice = new Invoice(); + + $miscPos->setVat($bPrice->getVat()); + $miscPos->setPrice($bPrice->getPrice()); + $miscPos->setAmount($days * $re->getPersons()); + $miscPos->setDescription($bPrice->getDescription()); + + $manager->persist($miscPos); + + $appPos->setBeds($re->getPersons()); + $appPos->setDescription($aPrice->getDescription()); + $appPos->setStartDate($re->getStartDate()); + $appPos->setEndDate($re->getEndDate()); + $appPos->setVat($aPrice->getVat()); + $appPos->setPrice($aPrice->getPrice()); + $appPos->setPersons($re->getPersons()); + $appPos->setNumber($re->getAppartment()->getNumber()); + + $manager->persist($appPos); + + /* @var $address CustomerAddresses */ + $address = $re->getBooker()->getCustomerAddresses()[0]; + $invoice->setAddress($address->getAddress()); + $invoice->setCity($address->getCity()); + $invoice->setDate(new \DateTime()); + $invoice->setFirstname($re->getBooker()->getFirstname()); + $invoice->setLastname($re->getBooker()->getLastname()); + $invoice->setNumber($invoiceId++); + $invoice->setSalutation($re->getBooker()->getSalutation()); + $invoice->setZip($address->getZip()); + $invoice->setStatus(1); + + $manager->persist($invoice); + + $miscPos->setInvoice($invoice); + $appPos->setInvoice($invoice); + $re->addInvoice($invoice); + + $manager->persist($re); + $manager->persist($appPos); + $manager->persist($miscPos); + } + } +} diff --git a/src/DataFixtures/SettingsFixtures.php b/src/DataFixtures/SettingsFixtures.php index 940aa6f..ddda858 100644 --- a/src/DataFixtures/SettingsFixtures.php +++ b/src/DataFixtures/SettingsFixtures.php @@ -1,169 +1,169 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace App\DataFixtures; - -use Doctrine\Bundle\FixturesBundle\Fixture; -use Doctrine\Common\Persistence\ObjectManager; -use Symfony\Contracts\Translation\TranslatorInterface; -use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface; - -use App\Entity\RoomCategory; -use App\Entity\ReservationOrigin; -use App\Entity\Appartment; -use App\Entity\Subsidiary; -use App\Entity\Price; -use App\Entity\Customer; -use App\Entity\CustomerAddresses; - -class SettingsFixtures extends Fixture implements FixtureGroupInterface -{ - private $translator; - public function __construct(TranslatorInterface $translator) { - $this->translator = $translator; - } - - public static function getGroups(): array - { - return ['settings', 'customer']; - } - - public function load(ObjectManager $manager) - { - $this->createRoomCategories($manager); - $this->createOrigins($manager); - - $manager->flush(); - - $categories = $manager->getRepository(RoomCategory::class)->findAll(); - $subsid = $manager->getRepository(Subsidiary::class)->find(1); // assuemes app:first-run was executed already - - $this->createRooms($manager, $categories, $subsid); - - $origins = $manager->getRepository(ReservationOrigin::class)->findAll(); - - $this->createPrices($manager, $categories, $origins); - - $this->createCustomer($manager); - - $manager->flush(); - } - - private function createRoomCategories(ObjectManager $manager) { - $roomCats = [ - $this->translator->trans('category.single'), - $this->translator->trans('category.double') - ]; - foreach($roomCats as $roomCat) { - $cat = new RoomCategory(); - $cat->setName( $roomCat ); - $manager->persist($cat); - } - } - - private function createOrigins(ObjectManager $manager) { - $origins = [ - $this->translator->trans('reservationorigin.private'), - $this->translator->trans('reservationorigin.business') - ]; - foreach($origins as $origin) { - $o = new ReservationOrigin(); - $o->setName( $origin ); - $manager->persist($o); - } - } - - private function createRooms(ObjectManager $manager, $roomCats, Subsidiary $subsidiary) { - // create 10 room, 5 single, 5 double - for($i = 1; $i <= 10; $i++) { - $app = new Appartment(); - $app->setNumber($i); - $app->setObject($subsidiary); - if($i > 5) { - $app->setBedsMax(2); - $app->setRoomCategory($roomCats[1]); - $app->setDescription($this->translator->trans('category.double')); - } else { - $app->setBedsMax(1); - $app->setRoomCategory($roomCats[0]); - $app->setDescription($this->translator->trans('category.single')); - } - $manager->persist($app); - } - } - - private function createPrices(ObjectManager $manager, $roomCats, $origins) { - $persons = 1; - $amount = 30; - foreach($roomCats as $roomCat) { - $price = new Price(); - $price->setActive(true); - $price->setRoomCategory($roomCat); - $price->setType(2); - $price->setMinStay(1); - $price->setAllDays(true); - $price->setAllPeriods(true); - $price->setNumberOfPersons($persons); - $price->setVat(7); - $price->setPrice($amount); - $amount += 20; - if($persons === 1) { - $price->setDescription( $this->translator->trans('price.single') ); - } else { - $price->setDescription( $this->translator->trans('price.double') ); - } - foreach($origins as $origin) { - $price->addReservationOrigin($origin); - } - - $manager->persist($price); - $persons++; - } - - // breakfast - $price = new Price(); - $price->setActive(true); - $price->setType(1); - $price->setAllDays(true); - $price->setAllPeriods(true); - $price->setVat(19); - $price->setPrice(10); - $price->setDescription( $this->translator->trans('price.breakfast') ); - foreach($origins as $origin) { - $price->addReservationOrigin($origin); - } - - $manager->persist($price); - } - - private function createCustomer(ObjectManager $manager) { - $address = new CustomerAddresses(); - $address->setAddress("Musterstr. 1"); - $address->setCity("Musterhausen"); - $address->setCountry("DE"); - $address->setEmail("max.mustermann@muster.de"); - $address->setType('CUSTOMER_ADDRESS_TYPE_PRIVATE'); - $address->setFax("123456789"); - $address->setMobilePhone("0176123456"); - $address->setPhone("987654321"); - $address->setZip("12345"); - - $manager->persist($address); - - $cus = new Customer(); - $cus->addCustomerAddress($address); - $cus->setFirstname("Max"); - $cus->setLastname("Mustermann"); - $cus->setBirthday(new \DateTime("1987-12-01")); - $cus->setSalutation("Herr"); - - $manager->persist($cus); - } -} + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace App\DataFixtures; + +use Doctrine\Bundle\FixturesBundle\Fixture; +use Doctrine\Persistence\ObjectManager; +use Symfony\Contracts\Translation\TranslatorInterface; +use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface; + +use App\Entity\RoomCategory; +use App\Entity\ReservationOrigin; +use App\Entity\Appartment; +use App\Entity\Subsidiary; +use App\Entity\Price; +use App\Entity\Customer; +use App\Entity\CustomerAddresses; + +class SettingsFixtures extends Fixture implements FixtureGroupInterface +{ + private $translator; + public function __construct(TranslatorInterface $translator) { + $this->translator = $translator; + } + + public static function getGroups(): array + { + return ['settings', 'customer']; + } + + public function load(ObjectManager $manager) + { + $this->createRoomCategories($manager); + $this->createOrigins($manager); + + $manager->flush(); + + $categories = $manager->getRepository(RoomCategory::class)->findAll(); + $subsid = $manager->getRepository(Subsidiary::class)->find(1); // assuemes app:first-run was executed already + + $this->createRooms($manager, $categories, $subsid); + + $origins = $manager->getRepository(ReservationOrigin::class)->findAll(); + + $this->createPrices($manager, $categories, $origins); + + $this->createCustomer($manager); + + $manager->flush(); + } + + private function createRoomCategories(ObjectManager $manager) { + $roomCats = [ + $this->translator->trans('category.single'), + $this->translator->trans('category.double') + ]; + foreach($roomCats as $roomCat) { + $cat = new RoomCategory(); + $cat->setName( $roomCat ); + $manager->persist($cat); + } + } + + private function createOrigins(ObjectManager $manager) { + $origins = [ + $this->translator->trans('reservationorigin.private'), + $this->translator->trans('reservationorigin.business') + ]; + foreach($origins as $origin) { + $o = new ReservationOrigin(); + $o->setName( $origin ); + $manager->persist($o); + } + } + + private function createRooms(ObjectManager $manager, $roomCats, Subsidiary $subsidiary) { + // create 10 room, 5 single, 5 double + for($i = 1; $i <= 10; $i++) { + $app = new Appartment(); + $app->setNumber($i); + $app->setObject($subsidiary); + if($i > 5) { + $app->setBedsMax(2); + $app->setRoomCategory($roomCats[1]); + $app->setDescription($this->translator->trans('category.double')); + } else { + $app->setBedsMax(1); + $app->setRoomCategory($roomCats[0]); + $app->setDescription($this->translator->trans('category.single')); + } + $manager->persist($app); + } + } + + private function createPrices(ObjectManager $manager, $roomCats, $origins) { + $persons = 1; + $amount = 30; + foreach($roomCats as $roomCat) { + $price = new Price(); + $price->setActive(true); + $price->setRoomCategory($roomCat); + $price->setType(2); + $price->setMinStay(1); + $price->setAllDays(true); + $price->setAllPeriods(true); + $price->setNumberOfPersons($persons); + $price->setVat(7); + $price->setPrice($amount); + $amount += 20; + if($persons === 1) { + $price->setDescription( $this->translator->trans('price.single') ); + } else { + $price->setDescription( $this->translator->trans('price.double') ); + } + foreach($origins as $origin) { + $price->addReservationOrigin($origin); + } + + $manager->persist($price); + $persons++; + } + + // breakfast + $price = new Price(); + $price->setActive(true); + $price->setType(1); + $price->setAllDays(true); + $price->setAllPeriods(true); + $price->setVat(19); + $price->setPrice(10); + $price->setDescription( $this->translator->trans('price.breakfast') ); + foreach($origins as $origin) { + $price->addReservationOrigin($origin); + } + + $manager->persist($price); + } + + private function createCustomer(ObjectManager $manager) { + $address = new CustomerAddresses(); + $address->setAddress("Musterstr. 1"); + $address->setCity("Musterhausen"); + $address->setCountry("DE"); + $address->setEmail("max.mustermann@muster.de"); + $address->setType('CUSTOMER_ADDRESS_TYPE_PRIVATE'); + $address->setFax("123456789"); + $address->setMobilePhone("0176123456"); + $address->setPhone("987654321"); + $address->setZip("12345"); + + $manager->persist($address); + + $cus = new Customer(); + $cus->addCustomerAddress($address); + $cus->setFirstname("Max"); + $cus->setLastname("Mustermann"); + $cus->setBirthday(new \DateTime("1987-12-01")); + $cus->setSalutation("Herr"); + + $manager->persist($cus); + } +} diff --git a/src/DataFixtures/TemplatesFixtures.php b/src/DataFixtures/TemplatesFixtures.php index 22093f9..d9d0f87 100644 --- a/src/DataFixtures/TemplatesFixtures.php +++ b/src/DataFixtures/TemplatesFixtures.php @@ -1,74 +1,74 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace App\DataFixtures; - -use Doctrine\Bundle\FixturesBundle\Fixture; -use Doctrine\Common\Persistence\ObjectManager; -use Symfony\Contracts\Translation\TranslatorInterface; -use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface; -use Symfony\Component\HttpClient\HttpClient; - -use App\Entity\Template; -use App\Entity\TemplateType; - -class TemplatesFixtures extends Fixture implements FixtureGroupInterface -{ - private $translator; - public function __construct(TranslatorInterface $translator) { - $this->translator = $translator; - } - - public static function getGroups(): array - { - return ['templates']; - } - - public function load(ObjectManager $manager) - { - $baseUrl = 'https://raw.githubusercontent.com/developeregrem/fewohbee-examples/master/templates/'; - $templates = [ - 'TEMPLATE_GDPR_PDF' => 'dsgvo-export.txt', - 'TEMPLATE_CASHJOURNAL_PDF' => 'kassenblatt.txt', - 'TEMPLATE_RESERVATION_EMAIL' => 'email-buchungsbestätigung.txt', - 'TEMPLATE_RESERVATION_PDF' => 'pdf-reservierungsbestätigung.txt', - 'TEMPLATE_INVOICE_PDF' => 'rechnung-default.txt' - ]; - $types = $manager->getRepository(TemplateType::class)->findAll(); - $client = HttpClient::create(); - /* @var $type TemplateType */ - foreach($types as $type) { - $name = $type->getName(); - if(!array_key_exists($name, $templates)) { - continue; - } - - $response = $client->request('GET', $baseUrl.$templates[$name]); - if (200 !== $response->getStatusCode()) { - echo "Could not load $name"; - continue; - } - - $content = $response->getContent(); - - $template = new Template(); - $template->setParams('{"orientation": "P", "marginLeft": 25, "marginRight": 20, "marginTop": 20, "marginBottom": 20, "marginHeader": 9, "marginFooter": 9}'); - $template->setIsDefault(true); - $template->setName($this->translator->trans($name)); - $template->setTemplateType($type); - $template->setText($content); - - $manager->persist($template); - } - - - $manager->flush(); - } -} + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace App\DataFixtures; + +use Doctrine\Bundle\FixturesBundle\Fixture; +use Doctrine\Persistence\ObjectManager; +use Symfony\Contracts\Translation\TranslatorInterface; +use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface; +use Symfony\Component\HttpClient\HttpClient; + +use App\Entity\Template; +use App\Entity\TemplateType; + +class TemplatesFixtures extends Fixture implements FixtureGroupInterface +{ + private $translator; + public function __construct(TranslatorInterface $translator) { + $this->translator = $translator; + } + + public static function getGroups(): array + { + return ['templates']; + } + + public function load(ObjectManager $manager) + { + $baseUrl = 'https://raw.githubusercontent.com/developeregrem/fewohbee-examples/master/templates/'; + $templates = [ + 'TEMPLATE_GDPR_PDF' => 'dsgvo-export.txt', + 'TEMPLATE_CASHJOURNAL_PDF' => 'kassenblatt.txt', + 'TEMPLATE_RESERVATION_EMAIL' => 'email-buchungsbestätigung.txt', + 'TEMPLATE_RESERVATION_PDF' => 'pdf-reservierungsbestätigung.txt', + 'TEMPLATE_INVOICE_PDF' => 'rechnung-default.txt' + ]; + $types = $manager->getRepository(TemplateType::class)->findAll(); + $client = HttpClient::create(); + /* @var $type TemplateType */ + foreach($types as $type) { + $name = $type->getName(); + if(!array_key_exists($name, $templates)) { + continue; + } + + $response = $client->request('GET', $baseUrl.$templates[$name]); + if (200 !== $response->getStatusCode()) { + echo "Could not load $name"; + continue; + } + + $content = $response->getContent(); + + $template = new Template(); + $template->setParams('{"orientation": "P", "marginLeft": 25, "marginRight": 20, "marginTop": 20, "marginBottom": 20, "marginHeader": 9, "marginFooter": 9}'); + $template->setIsDefault(true); + $template->setName($this->translator->trans($name)); + $template->setTemplateType($type); + $template->setText($content); + + $manager->persist($template); + } + + + $manager->flush(); + } +} diff --git a/src/Migrations/Version20200803113108.php b/src/Migrations/Version20200803113108.php deleted file mode 100644 index 0ff36ee..0000000 --- a/src/Migrations/Version20200803113108.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('DROP TABLE migration_versions'); - $this->addSql('ALTER TABLE opengeodb_de_plz CHANGE plz plz VARCHAR(5) NOT NULL'); - } - - public function down(Schema $schema) : void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE TABLE migration_versions (version VARCHAR(14) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, executed_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(version)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); - $this->addSql('ALTER TABLE opengeodb_de_plz CHANGE plz plz VARCHAR(5) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`'); - } -}