diff --git a/src/API/Data/ClientData.php b/src/API/Data/ClientData.php index 7c52848..62bea6e 100644 --- a/src/API/Data/ClientData.php +++ b/src/API/Data/ClientData.php @@ -15,11 +15,22 @@ class ClientData extends EntityData { public const USE_PROPERTIES = [ 'name', - 'description', - 'unitPrice', - 'unit', - 'quantity', - // 'tax.name', + 'code', + ]; + + public const CREATE_PROPERTIES = [ + 'name', + 'code', + 'email', + 'address', + 'city', + 'postalCode', + 'country', + 'fiscalId', + 'website', + 'phone', + 'fax', + 'observations', ]; public function __construct( @@ -45,9 +56,4 @@ public function __construct( public null|Optional|TaxExemptionCodeEnum $taxExemptionCode, public null|Optional|string $openAccountLink, ) {} - - public static function getUseProperties(): array - { - return self::USE_PROPERTIES; - } } diff --git a/src/API/Data/EntityData.php b/src/API/Data/EntityData.php index 498cc11..fe30de5 100644 --- a/src/API/Data/EntityData.php +++ b/src/API/Data/EntityData.php @@ -9,6 +9,12 @@ abstract class EntityData extends Data { public Optional|int $id; + public const CREATE_PROPERTIES = null; + + public const UPDATE_PROPERTIES = null; + + public const USE_PROPERTIES = null; + public function getId(): ?int { return $this->id instanceof Optional ? null : $this->id; @@ -23,12 +29,23 @@ protected static function prefixProperties(string $prefix, array $properties): a public function toCreateData(): static { - return $this; + return static::CREATE_PROPERTIES + ? static::from($this)->only(...static::CREATE_PROPERTIES) + : static::from($this); } public function toUpdateData(): static { - return $this; + return static::UPDATE_PROPERTIES + ? static::from($this)->only(...static::UPDATE_PROPERTIES) + : static::from($this); + } + + public function toUseData(): static + { + return static::USE_PROPERTIES + ? static::from($this)->only(...static::USE_PROPERTIES) + : static::from($this); } public function toModelData(): static diff --git a/src/API/Data/InvoiceData.php b/src/API/Data/InvoiceData.php index fa90adb..78fd041 100644 --- a/src/API/Data/InvoiceData.php +++ b/src/API/Data/InvoiceData.php @@ -85,15 +85,15 @@ public function __construct( public static function getCreateProperties(): array { return array_merge( - self::CREATE_PROPERTIES, - self::prefixProperties('items', ItemData::getUseProperties()), - self::prefixProperties('client', ClientData::getUseProperties()), + static::CREATE_PROPERTIES, + static::prefixProperties('items', ItemData::getUseProperties()), + static::prefixProperties('client', ClientData::CREATE_PROPERTIES), ); } public function toCreateData(): static { return static::from($this) - ->only(...self::getCreateProperties()); + ->only(...static::getCreateProperties()); } } diff --git a/src/API/Data/TaxData.php b/src/API/Data/TaxData.php index 75dffb2..4adf064 100644 --- a/src/API/Data/TaxData.php +++ b/src/API/Data/TaxData.php @@ -32,4 +32,20 @@ public function __construct( #[WithTransformer(BoolToIntTransformer::class)] public Optional|bool $defaultTax, ) {} + + public static function IVA23(): self + { + return self::from([ + 'name' => 'IVA23', + 'code' => 'NOR' + ]); + } + + public static function IVA0(): self + { + return self::from([ + 'name' => 'IVA0', + 'code' => 'ISE', + ]); + } } diff --git a/src/API/Endpoints/Concerns/CreatesWithType.php b/src/API/Endpoints/Concerns/CreatesWithType.php index fbe3bd9..acee658 100644 --- a/src/API/Endpoints/Concerns/CreatesWithType.php +++ b/src/API/Endpoints/Concerns/CreatesWithType.php @@ -26,7 +26,7 @@ public function create(EntityTypeEnum $entityType, EntityData $data): EntityData $response = $this->call( action: static::CREATE, urlParams: ['type' => $entityType->toUrlVariable()], - bodyData: [$entityType->value => $data->toCreateData()] + bodyData: [$entityType->value => $data->toCreateData()->toArray()] ); return $this->responseToDataObject($response[$entityType->value]);