-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from dcorroyer/5-crud-incomes
5 crud incomes
- Loading branch information
Showing
15 changed files
with
808 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version1_0_1 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE TABLE charge_lines (id INT AUTO_INCREMENT NOT NULL, charge_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, amount DOUBLE PRECISION NOT NULL, type VARCHAR(255) NOT NULL, INDEX IDX_592580BE55284914 (charge_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('CREATE TABLE charges (id INT AUTO_INCREMENT NOT NULL, amount DOUBLE PRECISION NOT NULL, date DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('CREATE TABLE incomes (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, amount DOUBLE PRECISION NOT NULL, date DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', type VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('ALTER TABLE charge_lines ADD CONSTRAINT FK_592580BE55284914 FOREIGN KEY (charge_id) REFERENCES charges (id)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE charge_lines DROP FOREIGN KEY FK_592580BE55284914'); | ||
$this->addSql('DROP TABLE charge_lines'); | ||
$this->addSql('DROP TABLE charges'); | ||
$this->addSql('DROP TABLE incomes'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DataFixtures; | ||
|
||
use App\Factory\ChargeFactory; | ||
use App\Factory\ChargeLineFactory; | ||
use Doctrine\Bundle\FixturesBundle\Fixture; | ||
use Doctrine\Persistence\ObjectManager; | ||
|
||
class ChargeFixtures extends Fixture | ||
{ | ||
public function load(ObjectManager $manager): void | ||
{ | ||
$charge = ChargeFactory::new()->create()->object(); | ||
|
||
for ($i = 0; $i < rand(3, 5); ++$i) { | ||
$chargeLine = ChargeLineFactory::new()->create()->object(); | ||
|
||
$charge->addChargeLine($chargeLine); | ||
} | ||
|
||
$manager->persist($charge); | ||
$manager->flush(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DataFixtures; | ||
|
||
use App\Factory\IncomeFactory; | ||
use Doctrine\Bundle\FixturesBundle\Fixture; | ||
use Doctrine\Persistence\ObjectManager; | ||
|
||
class IncomeFixtures extends Fixture | ||
{ | ||
public function load(ObjectManager $manager): void | ||
{ | ||
IncomeFactory::new()->create(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Entity; | ||
|
||
use App\Repository\ChargeRepository; | ||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Lcobucci\Clock\SystemClock; | ||
|
||
#[ORM\Entity(repositoryClass: ChargeRepository::class)] | ||
#[ORM\Table(name: 'charges')] | ||
class Charge | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column] | ||
private int $id; | ||
|
||
#[ORM\Column] | ||
private float $amount; | ||
|
||
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)] | ||
private \DateTimeImmutable $date; | ||
|
||
/** | ||
* @var Collection<int, ChargeLine> | ||
*/ | ||
#[ORM\OneToMany(mappedBy: 'charge', targetEntity: ChargeLine::class)] | ||
private Collection $chargeLines; | ||
|
||
public function __construct() | ||
{ | ||
$this->chargeLines = new ArrayCollection(); | ||
$clock = SystemClock::fromSystemTimezone(); | ||
$this->date = $clock->now(); | ||
} | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setId(int $id): self | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
public function getAmount(): float | ||
{ | ||
return $this->amount; | ||
} | ||
|
||
public function setAmount(float $amount): self | ||
{ | ||
$this->amount = $amount; | ||
|
||
return $this; | ||
} | ||
|
||
public function getDate(): \DateTimeImmutable | ||
{ | ||
return $this->date; | ||
} | ||
|
||
public function setDate(\DateTimeImmutable $date): self | ||
{ | ||
$this->date = $date; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return Collection<int, ChargeLine> | ||
*/ | ||
public function getChargeLines(): Collection | ||
{ | ||
return $this->chargeLines; | ||
} | ||
|
||
public function addChargeLine(ChargeLine $chargeLine): self | ||
{ | ||
if (! $this->chargeLines->contains($chargeLine)) { | ||
$this->chargeLines->add($chargeLine); | ||
$chargeLine->setCharge($this); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function removeChargeLine(ChargeLine $chargeLine): self | ||
{ | ||
if ($this->chargeLines->removeElement($chargeLine)) { | ||
// set the owning side to null (unless already changed) | ||
if ($chargeLine->getCharge() === $this) { | ||
$chargeLine->setCharge(null); | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Entity; | ||
|
||
use App\Repository\ChargeLineRepository; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity(repositoryClass: ChargeLineRepository::class)] | ||
#[ORM\Table(name: 'charge_lines')] | ||
class ChargeLine | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column] | ||
private int $id; | ||
|
||
#[ORM\Column(length: 255)] | ||
private string $name; | ||
|
||
#[ORM\Column] | ||
private float $amount; | ||
|
||
#[ORM\Column(length: 255)] | ||
private string $type; | ||
|
||
#[ORM\ManyToOne(inversedBy: 'chargeLines')] | ||
private ?Charge $charge = null; | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setId(int $id): self | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(string $name): self | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function getAmount(): float | ||
{ | ||
return $this->amount; | ||
} | ||
|
||
public function setAmount(float $amount): self | ||
{ | ||
$this->amount = $amount; | ||
|
||
return $this; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function setType(string $type): self | ||
{ | ||
$this->type = $type; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCharge(): ?Charge | ||
{ | ||
return $this->charge; | ||
} | ||
|
||
public function setCharge(?Charge $charge): self | ||
{ | ||
$this->charge = $charge; | ||
|
||
return $this; | ||
} | ||
} |
Oops, something went wrong.