diff --git a/Admin/Install/Media/bill.pdf.php b/Admin/Install/Media/bill.pdf.php index e2895b1..4b29464 100755 --- a/Admin/Install/Media/bill.pdf.php +++ b/Admin/Install/Media/bill.pdf.php @@ -25,7 +25,7 @@ $bill = $this->getData('bill') ?? new NullBill(); // Set up default pdf template /** @phpstan-import-type DefaultPdf from ../../../../Admin/Install/Media/PdfDefaultTemplate/pdfTemplate.pdf.php */ -$pdf = new DefaultPdf('P', 'mm', 'A4', true, 'UTF-8', false); +$pdf = new DefaultPdf(); $lang = include __DIR__ . '/lang.php'; diff --git a/Admin/Install/Media/lang.php b/Admin/Install/Media/lang.php index 252fa3e..a5ae0f2 100644 --- a/Admin/Install/Media/lang.php +++ b/Admin/Install/Media/lang.php @@ -1,5 +1,17 @@ moduleManager->getModuleInstance('Billing'); - /** @var \Modules\ItemManagement\Models\ItemAttributeType $itemAttributeSales */ - $itemAttributeSales = ItemAttributeTypeMapper::get() + /** @var \Modules\Attribute\Models\AttributeType $AttributeSales */ + $AttributeSales = AttributeTypeMapper::get() ->with('defaults') ->where('name', 'sales_tax_code') ->execute(); - /** @var \Modules\ClientManagement\Models\ClientAttributeType $clientAttributeSales */ + /** @var \Modules\Attribute\Models\AttributeType $clientAttributeSales */ $clientAttributeSales = ClientAttributeTypeMapper::get() ->with('defaults') ->where('name', 'sales_tax_code') ->execute(); - /** @var \Modules\SupplierManagement\Models\SupplierAttributeType $supplierAttributeSales */ + /** @var \Modules\Attribute\Models\AttributeType $supplierAttributeSales */ $supplierAttributeSales = SupplierAttributeTypeMapper::get() ->with('defaults') ->where('name', 'purchase_tax_code') ->execute(); foreach ($taxes as $tax) { - $itemValue = $itemAttributeSales->getDefaultByValue($tax['item_code']); + $itemValue = $AttributeSales->getDefaultByValue($tax['item_code']); $accountValue = $tax['type'] === 1 ? $clientAttributeSales->getDefaultByValue($tax['account_code']) : $supplierAttributeSales->getDefaultByValue($tax['account_code']); diff --git a/Controller/ApiAttributeController.php b/Controller/ApiAttributeController.php index f2bc070..e2f4395 100755 --- a/Controller/ApiAttributeController.php +++ b/Controller/ApiAttributeController.php @@ -14,16 +14,16 @@ declare(strict_types=1); namespace Modules\Billing\Controller; -use Modules\Billing\Models\Attribute\BillAttribute; +use Modules\Attribute\Models\Attribute; +use Modules\Attribute\Models\AttributeType; +use Modules\Attribute\Models\AttributeValue; +use Modules\Attribute\Models\NullAttributeType; +use Modules\Attribute\Models\NullAttributeValue; use Modules\Billing\Models\Attribute\BillAttributeMapper; -use Modules\Billing\Models\Attribute\BillAttributeType; use Modules\Billing\Models\Attribute\BillAttributeTypeL11nMapper; use Modules\Billing\Models\Attribute\BillAttributeTypeMapper; -use Modules\Billing\Models\Attribute\BillAttributeValue; use Modules\Billing\Models\Attribute\BillAttributeValueL11nMapper; use Modules\Billing\Models\Attribute\BillAttributeValueMapper; -use Modules\Billing\Models\Attribute\NullBillAttributeType; -use Modules\Billing\Models\Attribute\NullBillAttributeValue; use phpOMS\Localization\BaseStringL11n; use phpOMS\Localization\ISO639x1Enum; use phpOMS\Message\Http\RequestStatusCode; @@ -75,18 +75,18 @@ final class ApiAttributeController extends Controller * * @param RequestAbstract $request Request * - * @return BillAttribute + * @return Attribute * * @since 1.0.0 */ - private function createBillAttributeFromRequest(RequestAbstract $request) : BillAttribute + private function createBillAttributeFromRequest(RequestAbstract $request) : Attribute { - $attribute = new BillAttribute(); - $attribute->bill = (int) $request->getData('bill'); - $attribute->type = new NullBillAttributeType((int) $request->getData('type')); + $attribute = new Attribute(); + $attribute->ref = (int) $request->getData('ref'); + $attribute->type = new NullAttributeType((int) $request->getData('type')); if ($request->hasData('value')) { - $attribute->value = new NullBillAttributeValue((int) $request->getData('value')); + $attribute->value = new NullAttributeValue((int) $request->getData('value')); } else { $newRequest = clone $request; $newRequest->setData('value', $request->getData('custom'), true); @@ -223,13 +223,13 @@ final class ApiAttributeController extends Controller * * @param RequestAbstract $request Request * - * @return BillAttributeType + * @return AttributeType * * @since 1.0.0 */ - private function createBillAttributeTypeFromRequest(RequestAbstract $request) : BillAttributeType + private function createBillAttributeTypeFromRequest(RequestAbstract $request) : AttributeType { - $attrType = new BillAttributeType($request->getDataString('name') ?? ''); + $attrType = new AttributeType($request->getDataString('name') ?? ''); $attrType->datatype = $request->getDataInt('datatype') ?? 0; $attrType->custom = $request->getDataBool('custom') ?? false; $attrType->isRequired = (bool) ($request->getData('is_required') ?? false); @@ -303,20 +303,20 @@ final class ApiAttributeController extends Controller * * @param RequestAbstract $request Request * - * @return BillAttributeValue + * @return AttributeValue * * @since 1.0.0 */ - private function createBillAttributeValueFromRequest(RequestAbstract $request) : BillAttributeValue + private function createBillAttributeValueFromRequest(RequestAbstract $request) : AttributeValue { - /** @var BillAttributeType $type */ + /** @var \Modules\Attribute\Models\AttributeType $type */ $type = BillAttributeTypeMapper::get() ->where('id', $request->getDataInt('type') ?? 0) ->execute(); - $attrValue = new BillAttributeValue(); + $attrValue = new AttributeValue(); $attrValue->isDefault = $request->getDataBool('default') ?? false; - $attrValue->setValue($request->getData('value'), $type->datatype); + $attrValue->setValue($request->getDataString('value'), $type->datatype); if ($request->hasData('title')) { $attrValue->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN); diff --git a/Controller/ApiBillController.php b/Controller/ApiBillController.php index 6872e64..4f9c799 100755 --- a/Controller/ApiBillController.php +++ b/Controller/ApiBillController.php @@ -25,13 +25,9 @@ use Modules\Billing\Models\BillMapper; use Modules\Billing\Models\BillStatus; use Modules\Billing\Models\BillTypeMapper; use Modules\Billing\Models\SettingsEnum; -use Modules\Billing\Models\Tax\TaxCombinationMapper; use Modules\ClientManagement\Models\Client; use Modules\ClientManagement\Models\ClientMapper; -use Modules\Finance\Models\TaxCode; -use Modules\Finance\Models\TaxCodeMapper; use Modules\ItemManagement\Models\Item; -use Modules\ItemManagement\Models\ItemL11nMapper; use Modules\ItemManagement\Models\ItemMapper; use Modules\Media\Models\CollectionMapper; use Modules\Media\Models\MediaMapper; @@ -44,7 +40,6 @@ use phpOMS\Autoloader; use phpOMS\Localization\ISO3166TwoEnum; use phpOMS\Localization\ISO4217CharEnum; use phpOMS\Localization\ISO639x1Enum; -use phpOMS\Localization\Money; use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; @@ -181,8 +176,8 @@ final class ApiBillController extends Controller /** * Create a base Bill object with default values * - * @param Client $client The client object for whom the bill is being created - * @param RequestAbstract $request The request object that contains the header account + * @param Client $client The client object for whom the bill is being created + * @param RequestAbstract $request The request object that contains the header account * * @return Bill The new Bill object with default values * @@ -197,19 +192,20 @@ final class ApiBillController extends Controller public function createBaseBill(Client $client, RequestAbstract $request) : Bill { // @todo: validate vat before creation - $bill = new Bill(); + $bill = new Bill(); + $bill->createdBy = new NullAccount($request->header->account); + $bill->billDate = new \DateTime('now'); // @todo: Date of payment + $bill->performanceDate = new \DateTime('now'); // @todo: Date of payment + $bill->accountNumber = $client->number; $bill->setStatus(BillStatus::DRAFT); - $bill->createdBy = new NullAccount($request->header->account); - $bill->billDate = new \DateTime('now'); // @todo: Date of payment - $bill->performanceDate = new \DateTime('now'); // @todo: Date of payment - $bill->accountNumber = $client->number; - $bill->shipping = 0; + $bill->shipping = 0; $bill->shippingText = ''; - $bill->payment = 0; + $bill->payment = 0; $bill->paymentText = ''; + /** @var \Modules\Billing\Modles\BillType */ $bill->type = BillTypeMapper::get() ->where('name', 'sales_invoice') ->execute(); @@ -268,6 +264,18 @@ final class ApiBillController extends Controller return $bill; } + /** + * Create a base BillElement object with default values + * + * @param Client $client The client object for whom the bill is being created + * @param Item $item The item object for which the bill element is being created + * @param Bill $bill The bill object for which the bill element is being created + * @param RequestAbstract $request The request object that contains the header account + * + * @return BillElement + * + * @since 1.0.0 + */ public function createBaseBillElement(Client $client, Item $item, Bill $bill, RequestAbstract $request) : BillElement { $taxCode = $this->app->moduleManager->get('Billing', 'ApiTax')->getTaxCodeFromClientItem($client, $item, $request->getCountry()); @@ -317,26 +325,26 @@ final class ApiBillController extends Controller ->where('id', $request->getDataInt('type') ?? 1) ->execute(); - /* @var \Modules\Account\Models\Account $account */ - $bill = new Bill(); - $bill->createdBy = new NullAccount($request->header->account); - $bill->type = $billType; // @todo: use defaultInvoiceAddress or mainAddress. also consider to use billto1, billto2, billto3 (for multiple lines e.g. name2, fao etc.) - $bill->billTo = (string) ($request->getDataString('billto') + /** @var \Modules\SupplierManagement\Models\Supplier|\Modules\ClientManagement\Models\Client $account */ + $bill = new Bill(); + $bill->createdBy = new NullAccount($request->header->account); + $bill->type = $billType; + $bill->billTo = (string) ($request->getDataString('billto') ?? ($account->account->name1 . (!empty($account->account->name2) ? ', ' . $account->account->name2 : '' ))); - $bill->billAddress = (string) ($request->getDataString('billaddress') ?? $account->mainAddress->address); - $bill->billZip = (string) ($request->getDataString('billtopostal') ?? $account->mainAddress->postal); - $bill->billCity = (string) ($request->getDataString('billtocity') ?? $account->mainAddress->city); - $bill->billCountry = (string) ( + $bill->billAddress = (string) ($request->getDataString('billaddress') ?? $account->mainAddress->address); + $bill->billZip = (string) ($request->getDataString('billtopostal') ?? $account->mainAddress->postal); + $bill->billCity = (string) ($request->getDataString('billtocity') ?? $account->mainAddress->city); + $bill->billCountry = (string) ( $request->getDataString('billtocountry') ?? ( ($country = $account->mainAddress->getCountry()) === ISO3166TwoEnum::_XXX ? '' : $country) ); $bill->client = !$request->hasData('client') ? null : $account; $bill->supplier = !$request->hasData('supplier') ? null : $account; - $bill->performanceDate = new \DateTime($request->getDataString('performancedate') ?? 'now'); + $bill->performanceDate = $request->getDataDateTime('performancedate') ?? new \DateTime('now'); $bill->setStatus($request->getDataInt('status') ?? BillStatus::ACTIVE); return $bill; @@ -560,6 +568,7 @@ final class ApiBillController extends Controller * * @param RequestAbstract $request Request * @param ResponseAbstract $response Response + * @param Bill $bill Bill to create element for * @param mixed $data Generic data * * @return BillElement @@ -610,6 +619,19 @@ final class ApiBillController extends Controller return []; } + /** + * Api method to create a bill preview + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ public function apiPreviewRender(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { /** @var \Modules\Billing\Models\Bill $bill */ diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 351877d..abd758a 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -101,6 +101,19 @@ final class ApiController extends Controller $this->app->moduleManager->get('Billing', 'ApiBill')->apiBillElementCreate($request, $response, $data); } + /** + * Api method to create a bill preview + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ public function apiPreviewRender(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { $this->app->moduleManager->get('Billing', 'ApiBill')->apiPreviewRender($request, $response, $data); diff --git a/Controller/ApiPriceController.php b/Controller/ApiPriceController.php index c881cdc..87b1193 100755 --- a/Controller/ApiPriceController.php +++ b/Controller/ApiPriceController.php @@ -16,16 +16,15 @@ declare(strict_types=1); namespace Modules\Billing\Controller; +use Modules\Attribute\Models\NullAttributeValue; use Modules\Billing\Models\Price\Price; use Modules\Billing\Models\Price\PriceMapper; use Modules\Billing\Models\Price\PriceType; use Modules\Billing\Models\Tax\TaxCombinationMapper; use Modules\ClientManagement\Models\ClientMapper; use Modules\ClientManagement\Models\NullClient; -use Modules\ClientManagement\Models\NullClientAttributeValue; use Modules\ItemManagement\Models\ItemMapper; use Modules\ItemManagement\Models\NullItem; -use Modules\ItemManagement\Models\NullItemAttributeValue; use Modules\SupplierManagement\Models\NullSupplier; use Modules\SupplierManagement\Models\SupplierMapper; use phpOMS\Localization\ISO4217CharEnum; @@ -209,11 +208,11 @@ final class ApiPriceController extends Controller $tax = ($request->getDataInt('price_type') ?? PriceType::SALES) === PriceType::SALES ? TaxCombinationMapper::get() ->where('itemCode', $request->getDataInt('price_item')) - ->where('clientCode', $account->getAttribute('client_code')->getId()) + ->where('clientCode', $account->getAttribute('client_code')?->value->getId()) ->execute() : TaxCombinationMapper::get() ->where('itemCode', $request->getDataInt('price_item')) - ->where('supplierCode', $account->getAttribute('supplier_code')->getId()) + ->where('supplierCode', $account->getAttribute('supplier_code')?->value->getId()) ->execute(); $response->header->set('Content-Type', MimeType::M_JSON, true); @@ -267,16 +266,16 @@ final class ApiPriceController extends Controller $price->promocode = $request->getDataString('promocode') ?? ''; $price->item = new NullItem((int) $request->getData('item')); - $price->itemgroup = new NullItemAttributeValue((int) $request->getData('itemgroup')); - $price->itemsegment = new NullItemAttributeValue((int) $request->getData('itemsegment')); - $price->itemsection = new NullItemAttributeValue((int) $request->getData('itemsection')); - $price->itemtype = new NullItemAttributeValue((int) $request->getData('itemtype')); + $price->itemgroup = new NullAttributeValue((int) $request->getData('itemgroup')); + $price->itemsegment = new NullAttributeValue((int) $request->getData('itemsegment')); + $price->itemsection = new NullAttributeValue((int) $request->getData('itemsection')); + $price->itemtype = new NullAttributeValue((int) $request->getData('itemtype')); $price->client = new NullClient((int) $request->getData('client')); - $price->clientgroup = new NullClientAttributeValue((int) $request->getData('clientgroup')); - $price->clientsegment = new NullClientAttributeValue((int) $request->getData('clientsegment')); - $price->clientsection = new NullClientAttributeValue((int) $request->getData('clientsection')); - $price->clienttype = new NullClientAttributeValue((int) $request->getData('clienttype')); + $price->clientgroup = new NullAttributeValue((int) $request->getData('clientgroup')); + $price->clientsegment = new NullAttributeValue((int) $request->getData('clientsegment')); + $price->clientsection = new NullAttributeValue((int) $request->getData('clientsection')); + $price->clienttype = new NullAttributeValue((int) $request->getData('clienttype')); $price->supplier = new NullSupplier((int) $request->getData('supplier')); $price->unit = (int) $request->getData('unit'); @@ -289,8 +288,8 @@ final class ApiPriceController extends Controller $price->bonus = (int) $request->getData('bonus'); $price->multiply = $request->getDataBool('multiply') ?? false; $price->currency = $request->getDataString('currency') ?? ISO4217CharEnum::_EUR; - $price->start = $request->hasData('start') ? new \DateTime($request->getDataString('start')) : null; - $price->end = $request->hasData('end') ? new \DateTime($request->getDataString('end')) : null; + $price->start = $request->getDataDateTime('start') ?? null; + $price->end = $request->getDataDateTime('end') ?? null; return $price; } diff --git a/Controller/ApiTaxController.php b/Controller/ApiTaxController.php index de00f16..d029c2a 100755 --- a/Controller/ApiTaxController.php +++ b/Controller/ApiTaxController.php @@ -17,19 +17,17 @@ declare(strict_types=1); namespace Modules\Billing\Controller; use Modules\Admin\Models\Address; +use Modules\Attribute\Models\AttributeValue; +use Modules\Attribute\Models\NullAttributeValue; use Modules\Billing\Models\Tax\TaxCombination; use Modules\Billing\Models\Tax\TaxCombinationMapper; use Modules\ClientManagement\Models\Client; use Modules\ClientManagement\Models\ClientAttributeTypeMapper; -use Modules\ClientManagement\Models\ClientAttributeValue; -use Modules\ClientManagement\Models\NullClientAttributeValue; use Modules\Finance\Models\NullTaxCode; use Modules\Finance\Models\TaxCode; use Modules\Finance\Models\TaxCodeMapper; use Modules\ItemManagement\Models\Item; -use Modules\ItemManagement\Models\NullItemAttributeValue; use Modules\Organization\Models\UnitMapper; -use Modules\SupplierManagement\Models\NullSupplierAttributeValue; use phpOMS\Localization\ISO3166CharEnum; use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\NotificationLevel; @@ -47,6 +45,17 @@ use phpOMS\Model\Message\FormValidation; */ final class ApiTaxController extends Controller { + /** + * Get tax code from client and item. + * + * @param Client $client Client to get tax code from + * @param Item $item Item toget tax code from + * @param string $defaultCountry Default country to use if no valid tax code could be found and if the unit country code shouldn't be used. + * + * @return TaxCode + * + * @since 1.0.0 + */ public function getTaxCodeFromClientItem(Client $client, Item $item, string $defaultCountry = '') : TaxCode { // @todo: define default sales tax code if none available?! @@ -71,7 +80,7 @@ final class ApiTaxController extends Controller ->execute(); // Create dummy client - $client = new Client(); + $client = new Client(); $client->mainAddress = $unit->mainAddress; if (!empty($defaultCountry)) { @@ -81,7 +90,6 @@ final class ApiTaxController extends Controller $taxCodeAttribute = $this->getClientTaxCode($client, $unit->mainAddress); /** @var \Modules\Billing\Models\Tax\TaxCombination $taxCombination */ - $t = $item->getAttribute('sales_tax_code'); $taxCombination = TaxCombinationMapper::get() ->where('itemCode', $item->getAttribute('sales_tax_code')?->value->getId()) ->where('clientCode', $taxCodeAttribute->getId()) @@ -96,6 +104,17 @@ final class ApiTaxController extends Controller return $taxCode; } + /** + * Create a tax combination for a client and item + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Data + * + * @return void + * + * @since 1.0.0 + */ public function apiTaxCombinationCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { if (!empty($val = $this->validateTaxCombinationCreate($request))) { @@ -125,12 +144,12 @@ final class ApiTaxController extends Controller $tax = new TaxCombination(); $tax->taxType = $request->getDataInt('tax_type') ?? 1; $tax->taxCode = (string) $request->getData('tax_code'); - $tax->itemCode = new NullItemAttributeValue((int) $request->getData('item_code')); + $tax->itemCode = new NullAttributeValue((int) $request->getData('item_code')); if ($tax->taxType === 1) { - $tax->clientCode = new NullClientAttributeValue((int) $request->getData('account_code')); + $tax->clientCode = new NullAttributeValue((int) $request->getData('account_code')); } else { - $tax->supplierCode = new NullSupplierAttributeValue((int) $request->getData('account_code')); + $tax->supplierCode = new NullAttributeValue((int) $request->getData('account_code')); } return $tax; @@ -165,19 +184,19 @@ final class ApiTaxController extends Controller * @param Client $client The client to get the tax code for * @param Address $taxOfficeAddress The tax office address used to determine the tax code * - * @return ClientAttributeValue The client's tax code + * @return AttributeValue The client's tax code * * @since 1.0.0 */ - public function getClientTaxCode(Client $client, Address $taxOfficeAddress) : ClientAttributeValue + public function getClientTaxCode(Client $client, Address $taxOfficeAddress) : AttributeValue { - /** @var \Modules\ClientManagement\Models\ClientAttributeType $codes */ + /** @var \Modules\Attribute\Models\AttributeType $codes */ $codes = ClientAttributeTypeMapper::get() ->with('defaults') ->where('name', 'sales_tax_code') ->execute(); - $taxCode = new NullClientAttributeValue(); + $taxCode = new NullAttributeValue(); if ($taxOfficeAddress->getCountry() === $client->mainAddress->getCountry()) { $taxCode = $codes->getDefaultByValue($client->mainAddress->getCountry()); diff --git a/Controller/CliController.php b/Controller/CliController.php index 87c2b28..881ed0e 100755 --- a/Controller/CliController.php +++ b/Controller/CliController.php @@ -81,6 +81,7 @@ final class CliController extends Controller $identifierContent = '{}'; } + /** @var array $identifiers */ $identifiers = \json_decode($identifierContent, true); /* Supplier */ @@ -341,8 +342,6 @@ final class CliController extends Controller * * @return int * - * @todo: This can be optimized by a lot!!! - * * @since 1.0.0 */ private function matchSupplier(string $content, array $suppliers) : int @@ -352,8 +351,8 @@ final class CliController extends Controller // bill_match_pattern foreach ($suppliers as $supplier) { // @todo: consider to support regex? - if ((!empty($supplier->getAttributeByTypeName('bill_match_pattern')->value->valueStr) - && \stripos($content, $supplier->getAttributeByTypeName('bill_match_pattern')->value->valueStr) !== false) + if ((!empty($supplier->getAttribute('bill_match_pattern')->value->valueStr) + && \stripos($content, $supplier->getAttribute('bill_match_pattern')->value->valueStr) !== false) ) { return $supplier->getId(); } @@ -407,9 +406,9 @@ final class CliController extends Controller */ private function parseDate(string $date, Supplier $supplier, array $formats) : ?\DateTime { - if ((!empty($supplier->getAttributeByTypeName('bill_date_format')->value->valueStr))) { + if ((!empty($supplier->getAttribute('bill_date_format')->value->valueStr))) { return \DateTime::createFromFormat( - $supplier->getAttributeByTypeName('bill_date_format')->value->valueStr, + $supplier->getAttribute('bill_date_format')?->value->valueStr ?? '', $date ); } diff --git a/Models/Attribute/AttributeValueType.php b/Models/Attribute/AttributeValueType.php deleted file mode 100755 index b6b4780..0000000 --- a/Models/Attribute/AttributeValueType.php +++ /dev/null @@ -1,40 +0,0 @@ -type = new NullBillAttributeType(); - $this->value = new NullBillAttributeValue(); - } - - /** - * Get id - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'bill' => $this->bill, - 'type' => $this->type, - 'value' => $this->value, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/Attribute/BillAttributeMapper.php b/Models/Attribute/BillAttributeMapper.php index 5b34b5f..09fd5c4 100755 --- a/Models/Attribute/BillAttributeMapper.php +++ b/Models/Attribute/BillAttributeMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\Billing\Models\Attribute; +use Modules\Attribute\Models\Attribute; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** @@ -34,7 +35,7 @@ final class BillAttributeMapper extends DataMapperFactory */ public const COLUMNS = [ 'billing_bill_attr_id' => ['name' => 'billing_bill_attr_id', 'type' => 'int', 'internal' => 'id'], - 'billing_bill_attr_bill' => ['name' => 'billing_bill_attr_bill', 'type' => 'int', 'internal' => 'bill'], + 'billing_bill_attr_bill' => ['name' => 'billing_bill_attr_bill', 'type' => 'int', 'internal' => 'ref'], 'billing_bill_attr_type' => ['name' => 'billing_bill_attr_type', 'type' => 'int', 'internal' => 'type'], 'billing_bill_attr_value' => ['name' => 'billing_bill_attr_value', 'type' => 'int', 'internal' => 'value'], ]; @@ -56,6 +57,14 @@ final class BillAttributeMapper extends DataMapperFactory ], ]; + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = Attribute::class; + /** * Primary table. * diff --git a/Models/Attribute/BillAttributeType.php b/Models/Attribute/BillAttributeType.php deleted file mode 100755 index e09757e..0000000 --- a/Models/Attribute/BillAttributeType.php +++ /dev/null @@ -1,216 +0,0 @@ -name = $name; - } - - /** - * Get id - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - - public function getDefaultByValue(mixed $value) : BillAttributeValue - { - foreach ($this->defaults as $default) { - if ($default->getValue() === $value) { - return $default; - } - } - - return new NullBillAttributeValue(); - } - - /** - * Set l11n - * - * @param string|BaseStringL11n $l11n Tag article l11n - * @param string $lang Language - * - * @return void - * - * @since 1.0.0 - */ - public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void - { - if ($l11n instanceof BaseStringL11n) { - $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } else { - $this->l11n = new BaseStringL11n(); - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getL11n() : string - { - if (!isset($this->l11n)) { - return ''; - } - - return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; - } - - /** - * Set fields - * - * @param int $fields Fields - * - * @return void - * - * @since 1.0.0 - */ - public function setFields(int $fields) : void - { - $this->fields = $fields; - } - - /** - * Get default values - * - * @return array - * - * @sicne 1.0.0 - */ - public function getDefaults() : array - { - return $this->defaults; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'name' => $this->name, - 'validationPattern' => $this->validationPattern, - 'custom' => $this->custom, - 'isRequired' => $this->isRequired, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/Attribute/BillAttributeTypeMapper.php b/Models/Attribute/BillAttributeTypeMapper.php index ac44163..64761ed 100755 --- a/Models/Attribute/BillAttributeTypeMapper.php +++ b/Models/Attribute/BillAttributeTypeMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\Billing\Models\Attribute; +use Modules\Attribute\Models\AttributeType; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** @@ -64,6 +65,14 @@ final class BillAttributeTypeMapper extends DataMapperFactory ], ]; + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = AttributeType::class; + /** * Primary table. * diff --git a/Models/Attribute/BillAttributeValue.php b/Models/Attribute/BillAttributeValue.php deleted file mode 100755 index aa3855e..0000000 --- a/Models/Attribute/BillAttributeValue.php +++ /dev/null @@ -1,230 +0,0 @@ -id; - } - - /** - * Set l11n - * - * @param string|BaseStringL11n $l11n Tag article l11n - * @param string $lang Language - * - * @return void - * - * @since 1.0.0 - */ - public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void - { - if ($l11n instanceof BaseStringL11n) { - $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } else { - $this->l11n = new BaseStringL11n(); - $this->l11n->content = $l11n; - $this->l11n->ref = $this->id; - $this->l11n->setLanguage($lang); - } - } - - /** - * Get localization - * - * @return null|string - * - * @since 1.0.0 - */ - public function getL11n() : ?string - { - return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; - } - - /** - * Set value - * - * @param int|string|float $value Value - * @param int $datatype Datatype - * - * @return void - * - * @since 1.0.0 - */ - public function setValue(mixed $value, int $datatype) : void - { - if ($datatype === AttributeValueType::_STRING) { - $this->valueStr = (string) $value; - } elseif ($datatype === AttributeValueType::_INT - || $datatype === AttributeValueType::_FLOAT_INT - || $datatype === AttributeValueType::_BOOL - ) { - $this->valueInt = (int) $value; - } elseif ($datatype === AttributeValueType::_FLOAT) { - $this->valueDec = (float) $value; - } elseif ($datatype === AttributeValueType::_DATETIME) { - $this->valueDat = new \DateTime((string) $value); - } - } - - /** - * Get value - * - * @return null|int|string|float|\DateTimeInterface - * - * @since 1.0.0 - */ - public function getValue() : mixed - { - if (!empty($this->valueStr)) { - return $this->valueStr; - } elseif (!empty($this->valueInt)) { - return $this->valueInt; - } elseif (!empty($this->valueDec)) { - return $this->valueDec; - } elseif ($this->valueDat instanceof \DateTimeInterface) { - return $this->valueDat; - } - - return null; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'valueInt' => $this->valueInt, - 'valueStr' => $this->valueStr, - 'valueDec' => $this->valueDec, - 'valueDat' => $this->valueDat, - 'isDefault' => $this->isDefault, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/Attribute/BillAttributeValueMapper.php b/Models/Attribute/BillAttributeValueMapper.php index 92e8090..1fe664e 100755 --- a/Models/Attribute/BillAttributeValueMapper.php +++ b/Models/Attribute/BillAttributeValueMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\Billing\Models\Attribute; +use Modules\Attribute\Models\AttributeValue; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** @@ -59,6 +60,14 @@ final class BillAttributeValueMapper extends DataMapperFactory ], ]; + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = AttributeValue::class; + /** * Primary table. * diff --git a/Models/Attribute/NullBillAttribute.php b/Models/Attribute/NullBillAttribute.php deleted file mode 100755 index 2f2a716..0000000 --- a/Models/Attribute/NullBillAttribute.php +++ /dev/null @@ -1,47 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/Attribute/NullBillAttributeType.php b/Models/Attribute/NullBillAttributeType.php deleted file mode 100755 index 04e178c..0000000 --- a/Models/Attribute/NullBillAttributeType.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/Attribute/NullBillAttributeValue.php b/Models/Attribute/NullBillAttributeValue.php deleted file mode 100755 index 4f9f338..0000000 --- a/Models/Attribute/NullBillAttributeValue.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/Bill.php b/Models/Bill.php index 3fdb03d..77fd1c8 100755 --- a/Models/Bill.php +++ b/Models/Bill.php @@ -442,7 +442,7 @@ class Bill implements \JsonSerializable /** * Attributes. * - * @var BillAttribute[] + * @var \Modules\Attribute\Models\Attribute[] * @since 1.0.0 */ private array $attributes = []; @@ -525,52 +525,6 @@ class Bill implements \JsonSerializable return $this->number; } - /** - * Add attribute to client - * - * @param BillAttribute $attribute Attribute - * - * @return void - * - * @since 1.0.0 - */ - public function addAttribute(BillAttribute $attribute) : void - { - $this->attributes[] = $attribute; - } - - /** - * Get attributes - * - * @return BillAttribute[] - * - * @since 1.0.0 - */ - public function getAttributes() : array - { - return $this->attributes; - } - - /** - * Get attribute - * - * @param string $attrName Attribute name - * - * @return null|BillAttribute - * - * @since 1.0.0 - */ - public function getAttribute(string $attrName) : ?BillAttribute - { - foreach ($this->attributes as $attribute) { - if ($attribute->type->name === $attrName) { - return $attribute; - } - } - - return null; - } - /** * Get status * @@ -892,4 +846,6 @@ class Bill implements \JsonSerializable { return $this->toArray(); } + + use \Modules\Attribute\Models\AttributeHolderTrait; } diff --git a/Models/BillElement.php b/Models/BillElement.php index 8e215fc..792db58 100755 --- a/Models/BillElement.php +++ b/Models/BillElement.php @@ -101,7 +101,7 @@ class BillElement implements \JsonSerializable /** * Tax percentage * - * @var null|FloatInt + * @var FloatInt * @since 1.0.0 */ public FloatInt $taxR; @@ -176,6 +176,15 @@ class BillElement implements \JsonSerializable return $this->id; } + /** + * Set the element quantity. + * + * @param int $quantity Quantity + * + * @return void + * + * @since 1.0.0 + */ public function setQuantity(int $quantity) : void { if ($this->quantity === $quantity) { @@ -186,6 +195,13 @@ class BillElement implements \JsonSerializable // @todo: recalculate all the prices!!! } + /** + * Get quantity. + * + * @return int + * + * @since 1.0.0 + */ public function getQuantity() : int { return $this->quantity; @@ -205,14 +221,25 @@ class BillElement implements \JsonSerializable $this->item = $item; } + /** + * Create element from item + * + * @param Item $item Item + * @param TaxCode $code Tax code used for gross amount calculation + * @param int $quantity Quantity + * + * @return self + * + * @since 1.0.0 + */ public static function fromItem(Item $item, TaxCode $code, int $quantity = 1) : self { - $element = new self(); - $element->item = $item->getId(); - $element->itemNumber = $item->number; - $element->itemName = $item->getL11n('name1')->description; + $element = new self(); + $element->item = $item->getId(); + $element->itemNumber = $item->number; + $element->itemName = $item->getL11n('name1')->description; $element->itemDescription = $item->getL11n('description_short')->description; - $element->quantity = $quantity; + $element->quantity = $quantity; // @todo: Use pricing instead of the default sales price // @todo: discounts might be in quantities @@ -226,7 +253,7 @@ class BillElement implements \JsonSerializable $element->singleProfitNet->setInt($element->singleSalesPriceNet->getInt() - $element->singlePurchasePriceNet->getInt()); $element->totalProfitNet->setInt($element->quantity * ($element->totalSalesPriceNet->getInt() - $element->totalPurchasePriceNet->getInt())); - $element->taxP = new FloatInt((int) (($code->percentageInvoice * $element->totalSalesPriceNet->getInt()) / 10000)); + $element->taxP = new Money((int) (($code->percentageInvoice * $element->totalSalesPriceNet->getInt()) / 10000)); $element->taxR = new FloatInt($code->percentageInvoice); $element->taxCode = $code->abbr; diff --git a/Models/BillType.php b/Models/BillType.php index b127d86..6c91103 100755 --- a/Models/BillType.php +++ b/Models/BillType.php @@ -66,7 +66,7 @@ class BillType implements \JsonSerializable */ public function __construct(string $name = '') { - $this->name = $name; + $this->name = $name; } /** @@ -96,7 +96,7 @@ class BillType implements \JsonSerializable if ($l11n instanceof BaseStringL11n) { $this->l11n = $l11n; } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; + $this->l11n->content = $l11n; $this->l11n->setLanguage($lang); } else { $this->l11n = new BaseStringL11n(); @@ -120,11 +120,27 @@ class BillType implements \JsonSerializable return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; } + /** + * Add rendering template + * + * @param Collection $template Template + * + * @return void + * + * @since 1.0.0 + */ public function addTemplate(Collection $template) : void { $this->templates[] = $template; } + /** + * Get templates + * + * @return Collection[] + * + * @since 1.0.0 + */ public function getTemplates() : array { return $this->templates; diff --git a/Models/Price/Price.php b/Models/Price/Price.php index 11d56b0..4129810 100755 --- a/Models/Price/Price.php +++ b/Models/Price/Price.php @@ -14,14 +14,12 @@ declare(strict_types=1); namespace Modules\Billing\Models\Price; +use Modules\Attribute\Models\AttributeValue; +use Modules\Attribute\Models\NullAttributeValue; use Modules\ClientManagement\Models\Client; -use Modules\ClientManagement\Models\ClientAttributeValue; use Modules\ClientManagement\Models\NullClient; -use Modules\ClientManagement\Models\NullClientAttributeValue; use Modules\ItemManagement\Models\Item; -use Modules\ItemManagement\Models\ItemAttributeValue; use Modules\ItemManagement\Models\NullItem; -use Modules\ItemManagement\Models\NullItemAttributeValue; use Modules\SupplierManagement\Models\NullSupplier; use Modules\SupplierManagement\Models\Supplier; use phpOMS\Localization\ISO4217CharEnum; @@ -50,23 +48,23 @@ class Price implements \JsonSerializable public Item $item; - public ItemAttributeValue $itemgroup; + public AttributeValue $itemgroup; - public ItemAttributeValue $itemsegment; + public AttributeValue $itemsegment; - public ItemAttributeValue $itemsection; + public AttributeValue $itemsection; - public ItemAttributeValue $itemtype; + public AttributeValue $itemtype; public Client $client; - public ClientAttributeValue $clientgroup; + public AttributeValue $clientgroup; - public ClientAttributeValue $clientsegment; + public AttributeValue $clientsegment; - public ClientAttributeValue $clientsection; + public AttributeValue $clientsection; - public ClientAttributeValue $clienttype; + public AttributeValue $clienttype; public ?string $clientcountry = null; @@ -93,21 +91,22 @@ class Price implements \JsonSerializable public string $currency = ISO4217CharEnum::_EUR; public ?\DateTime $start = null; + public ?\DateTime $end = null; public function __construct() { $this->item = new NullItem(); - $this->itemgroup = new NullItemAttributeValue(); - $this->itemsegment = new NullItemAttributeValue(); - $this->itemsection = new NullItemAttributeValue(); - $this->itemtype = new NullItemAttributeValue(); + $this->itemgroup = new NullAttributeValue(); + $this->itemsegment = new NullAttributeValue(); + $this->itemsection = new NullAttributeValue(); + $this->itemtype = new NullAttributeValue(); $this->client = new NullClient(); - $this->clientgroup = new NullClientAttributeValue(); - $this->clientsegment = new NullClientAttributeValue(); - $this->clientsection = new NullClientAttributeValue(); - $this->clienttype = new NullClientAttributeValue(); + $this->clientgroup = new NullAttributeValue(); + $this->clientsegment = new NullAttributeValue(); + $this->clientsection = new NullAttributeValue(); + $this->clienttype = new NullAttributeValue(); $this->supplier = new NullSupplier(); } diff --git a/Models/Price/PriceMapper.php b/Models/Price/PriceMapper.php index 4eaef80..a9ebd83 100755 --- a/Models/Price/PriceMapper.php +++ b/Models/Price/PriceMapper.php @@ -16,7 +16,7 @@ namespace Modules\Billing\Models\Price; use Modules\ClientManagement\Models\ClientAttributeValueMapper; use Modules\ClientManagement\Models\ClientMapper; -use Modules\ItemManagement\Models\ItemAttributeValueMapper; +use Modules\Attribute\Models\AttributeValueMapper; use Modules\ItemManagement\Models\ItemMapper; use Modules\SupplierManagement\Models\SupplierMapper; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; @@ -80,19 +80,19 @@ final class PriceMapper extends DataMapperFactory 'external' => 'billing_price_item', ], 'itemgroup' => [ - 'mapper' => ItemAttributeValueMapper::class, + 'mapper' => AttributeValueMapper::class, 'external' => 'billing_price_itemgroup', ], 'itemsegment' => [ - 'mapper' => ItemAttributeValueMapper::class, + 'mapper' => AttributeValueMapper::class, 'external' => 'billing_price_itemsegment', ], 'itemsection' => [ - 'mapper' => ItemAttributeValueMapper::class, + 'mapper' => AttributeValueMapper::class, 'external' => 'billing_price_itemsection', ], 'itemtype' => [ - 'mapper' => ItemAttributeValueMapper::class, + 'mapper' => AttributeValueMapper::class, 'external' => 'billing_price_itemtype', ], 'client' => [ diff --git a/Models/Tax/TaxCombination.php b/Models/Tax/TaxCombination.php index 7473578..333392c 100755 --- a/Models/Tax/TaxCombination.php +++ b/Models/Tax/TaxCombination.php @@ -14,12 +14,8 @@ declare(strict_types=1); namespace Modules\Billing\Models\Tax; -use Modules\ClientManagement\Models\ClientAttributeValue; -use Modules\ClientManagement\Models\NullClientAttributeValue; -use Modules\ItemManagement\Models\ItemAttributeValue; -use Modules\ItemManagement\Models\NullItemAttributeValue; -use Modules\SupplierManagement\Models\NullSupplierAttributeValue; -use Modules\SupplierManagement\Models\SupplierAttributeValue; +use Modules\Attribute\Models\AttributeValue; +use Modules\Attribute\Models\NullAttributeValue; /** * Billing class. @@ -39,11 +35,11 @@ class TaxCombination implements \JsonSerializable */ protected int $id = 0; - public ?ClientAttributeValue $clientCode = null; + public ?AttributeValue $clientCode = null; - public ?SupplierAttributeValue $supplierCode = null; + public ?AttributeValue $supplierCode = null; - public ItemAttributeValue $itemCode; + public AttributeValue $itemCode; public string $taxCode = ''; @@ -72,7 +68,7 @@ class TaxCombination implements \JsonSerializable */ public function __construct() { - $this->itemCode = new NullItemAttributeValue(); + $this->itemCode = new NullAttributeValue(); } /** diff --git a/Models/Tax/TaxCombinationMapper.php b/Models/Tax/TaxCombinationMapper.php index e1b0a0f..dbf1c99 100755 --- a/Models/Tax/TaxCombinationMapper.php +++ b/Models/Tax/TaxCombinationMapper.php @@ -15,7 +15,7 @@ declare(strict_types=1); namespace Modules\Billing\Models\Tax; use Modules\ClientManagement\Models\ClientAttributeValueMapper; -use Modules\ItemManagement\Models\ItemAttributeValueMapper; +use Modules\Attribute\Models\AttributeValueMapper; use Modules\SupplierManagement\Models\SupplierAttributeValueMapper; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; @@ -67,7 +67,7 @@ final class TaxCombinationMapper extends DataMapperFactory 'external' => 'billing_tax_supplier_code', ], 'itemCode' => [ - 'mapper' => ItemAttributeValueMapper::class, + 'mapper' => AttributeValueMapper::class, 'external' => 'billing_tax_item_code', ], ];