Skip to content

Commit

Permalink
Introduced class Types to allow accessing types enums values easily
Browse files Browse the repository at this point in the history
  • Loading branch information
rahal committed Jan 1, 2024
1 parent 9c5f23b commit a917e0b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}
],
"scripts": {
"test": "vendor/bin/phpunit test/InvoiceTest.php"
"test": "vendor/bin/phpunit test"
},
"autoload": {
"psr-4": {
Expand Down
39 changes: 39 additions & 0 deletions src/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,39 @@
// Types curtesy of tiime
// Do we really need to put them in seperate files?
/**
* Helper trait to allow exporting the enum values as an array
*/
trait EnumToArray
{
/**
* Returns enum values as a clean array.
*/
public static function valueArray(): array
{
foreach (self::cases() as $enum) {
$values[$enum->value] = str_replace( '_' , ' ', $enum->name);
}

return $values;
}
}

/**
* Helper Types class to access type enum values.
* Can be used to generate select boxes easily.
*/
class Types {

public static function getInternationalCodes(){
return InternationalCodeDesignator::valueArray();
}
}

enum PaymentMeansCode: string
{
use EnumToArray;

case INSTRUMENT_NOT_DEFINED = "1";
case AUTOMATED_CLEARING_HOUSE_CREDIT = "2";
case AUTOMATED_CLEARING_HOUSE_DEBIT = "3";
Expand Down Expand Up @@ -2262,6 +2291,8 @@ enum UnitOfMeasurement: string

enum CurrencyCode: string
{
use EnumToArray;

case UAE_DIRHAM = "AED";
case AFGHANI = "AFN";
case LEK = "ALL";
Expand Down Expand Up @@ -2447,6 +2478,8 @@ enum CurrencyCode: string

enum InvoiceTypeCode: string
{
use EnumToArray;

// https://service.unece.org/trade/untdid/d16b/tred/tred1001.htm
case DEBIT_NOTE_RELATED_TO_GOODS_OR_SERVICES = '80';
case CREDIT_NOTE_RELATED_TO_GOODS_OR_SERVICES = '81';
Expand Down Expand Up @@ -2496,6 +2529,8 @@ enum InvoiceTypeCode: string

enum VatCategory: string
{
use EnumToArray;

case VAT_REVERSE_CHARGE = "AE";
case EXEMPT_FROM_TAX = "E";
case FREE_EXPORT_ITEM_TAX_NOT_CHARGED = "G";
Expand All @@ -2511,12 +2546,16 @@ enum VatCategory: string

enum TaxTypeCodeContent: string
{
use EnumToArray;

case VAT = "VAT";
}


enum InternationalCodeDesignator: string
{
use EnumToArray;

case SYSTEM_INFORMATION_ET_REPERTOIRE_DES_ENTREPRISE_ET_DES_ETABLISSEMENTS_SIRENE = "0002";
case CODIFICATION_NUMERIQUE_DES_ETABLISSMENTS_FINANCIERS_EN_BELGIQUE = "0003";
case NBS_OSI_NETWORK = "0004";
Expand Down
1 change: 0 additions & 1 deletion src/XmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public function setBuyerAddress(string $lineOne, string $postCode, string $city,
public function addItem(string $name, float $price, float $taxRatePercent, float $quantity, UnitOfMeasurement $unit, ?string $globalID = null, ?string $globalIDCode =null ): float;
public function addNote(string $content, ?string $subjectCode = null, ?string $contentCode = null);
public function addPaymentMean(PaymentMeansCode $typeCode , ?string $ibanId = null,?string $accountName = null, ?string $bicId = null);

}


Expand Down
19 changes: 19 additions & 0 deletions test/TypesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace DigitalInvoice\Tests;

use DigitalInvoice\Types;


use PHPUnit\Framework\TestCase;

class TypesTest extends TestCase
{

public function testInternationnalCodes()
{
$codes = Types::getInternationalCodes();
$this->assertEquals('SIRET CODE', $codes['0009']);
}

}

0 comments on commit a917e0b

Please sign in to comment.