Add discounts, fields, and PDF/email support to manual invoices.

This commit is contained in:
2025-12-04 15:02:19 +01:00
parent 924f8c7f87
commit e310ae4bf8
13 changed files with 812 additions and 125 deletions

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class AddManualinvoiceAdditionalFields extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("ManualInvoice");
$table->addColumn("leistungszeitraum", "string", ["null" => true, "default" => null, "length" => 255, "after" => "invoice_date"]);
$table->addColumn("einleitender_text", "text", ["null" => true, "default" => null, "after" => "leistungszeitraum"]);
$table->addColumn("externe_referenz", "string", ["null" => true, "default" => null, "length" => 255, "after" => "einleitender_text"]);
$table->addColumn("gesamtrabatt", "decimal", ["null" => false, "default" => 0, "precision" => 6, "scale" => 2, "after" => "externe_referenz"]);
$table->save();
$positionTable = $this->table("ManualInvoiceposition");
$positionTable->addColumn("discount", "decimal", ["null" => false, "default" => 0, "precision" => 6, "scale" => 2, "after" => "price"]);
$positionTable->save();
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$this->table("ManualInvoiceposition")->removeColumn("discount")->save();
$this->table("ManualInvoice")
->removeColumn("leistungszeitraum")
->removeColumn("einleitender_text")
->removeColumn("externe_referenz")
->removeColumn("gesamtrabatt")
->save();
}
}
}

View File

@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class UpdateManualinvoicepositionStructure extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("ManualInvoiceposition");
$table->addColumn("position_group", "string", ["null" => true, "default" => null, "length" => 255, "after" => "manualinvoice_id"]);
$table->removeColumn("start_date");
$table->removeColumn("end_date");
$table->removeColumn("billing_period");
$table->save();
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("ManualInvoiceposition");
$table->addColumn("start_date", "date", ["null" => false, "after" => "contract_id"]);
$table->addColumn("end_date", "date", ["null" => true, "default" => null, "after" => "start_date"]);
$table->addColumn("billing_period", "integer", ["null" => false, "default" => 0, "after" => "fibu_taxcode"]);
$table->removeColumn("position_group");
$table->save();
}
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class AddUnitToManualinvoiceposition extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("ManualInvoiceposition");
$table->addColumn("unit", "string", [
"null" => false,
"default" => "Stk.",
"length" => 10,
"after" => "amount"
]);
$table->save();
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$this->table("ManualInvoiceposition")->removeColumn("unit")->save();
}
}
}

View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreateManualInvoiceJournal extends AbstractMigration
{
public function change(): void
{
if ($this->getEnvironment() == "thetool") {
$table = $this->table('ManualInvoiceJournal');
$table->addColumn('manualinvoiceId', 'integer', ['signed' => false])
->addColumn('text', 'text', ['null' => true])
->addColumn('data', 'json', ['null' => true])
->addColumn('statusChange', 'string', ['limit' => 255, 'null' => true])
->addColumn('fileIds', 'json', ['null' => true])
->addColumn('createBy', 'integer', ['signed' => false])
->addColumn('create', 'integer')
->addForeignKey('manualinvoiceId', 'ManualInvoice', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
->addIndex(['manualinvoiceId'], ['name' => 'manualinvoiceId_idx'])
->create();
}
}
}

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class UpdateManualInvoiceStatusValues extends AbstractMigration
{
public function up(): void
{
if ($this->getEnvironment() == "thetool") {
// Change status column from enum to varchar to support new values
$this->execute("ALTER TABLE ManualInvoice MODIFY COLUMN status VARCHAR(50) NOT NULL DEFAULT 'erstellt'");
// Update existing values to new ones
$this->execute("UPDATE ManualInvoice SET status = 'erstellt' WHERE status = 'draft'");
$this->execute("UPDATE ManualInvoice SET status = 'gesendet' WHERE status = 'finalized'");
$this->execute("UPDATE ManualInvoice SET status = 'exportiert' WHERE status = 'exported'");
}
}
public function down(): void
{
if ($this->getEnvironment() == "thetool") {
// Revert values back
$this->execute("UPDATE ManualInvoice SET status = 'draft' WHERE status = 'erstellt'");
$this->execute("UPDATE ManualInvoice SET status = 'finalized' WHERE status = 'gesendet'");
$this->execute("UPDATE ManualInvoice SET status = 'exported' WHERE status = 'exportiert'");
// Change back to enum
$this->execute("ALTER TABLE ManualInvoice MODIFY COLUMN status ENUM('draft', 'finalized', 'exported') NOT NULL DEFAULT 'draft'");
}
}
}