mirror of
https://github.com/Karaka-Management/oms-Billing.git
synced 2026-01-11 15:18:42 +00:00
fix static analysis
This commit is contained in:
parent
55b0d09005
commit
587718774b
|
|
@ -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';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,17 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* Bill localization.
|
||||
*
|
||||
* @package Modules\Media
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
return [
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Billing\Admin;
|
||||
|
||||
use Modules\Attribute\Models\AttributeTypeMapper;
|
||||
use Modules\Billing\Models\BillTransferType;
|
||||
use Modules\ClientManagement\Models\ClientAttributeTypeMapper;
|
||||
use Modules\ItemManagement\Models\ItemAttributeTypeMapper;
|
||||
use Modules\SupplierManagement\Models\SupplierAttributeTypeMapper;
|
||||
use phpOMS\Application\ApplicationAbstract;
|
||||
use phpOMS\Config\SettingsInterface;
|
||||
|
|
@ -243,26 +243,26 @@ final class Installer extends InstallerAbstract
|
|||
/** @var \Modules\Billing\Controller\ApiController $module */
|
||||
$module = $app->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']);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Billing\Models\Attribute;
|
||||
|
||||
use phpOMS\Stdlib\Base\Enum;
|
||||
|
||||
/**
|
||||
* Attribute value type enum.
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class AttributeValueType extends Enum
|
||||
{
|
||||
public const _INT = 1;
|
||||
|
||||
public const _STRING = 2;
|
||||
|
||||
public const _FLOAT = 3;
|
||||
|
||||
public const _DATETIME = 4;
|
||||
|
||||
public const _BOOL = 5;
|
||||
|
||||
public const _FLOAT_INT = 6;
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Billing\Models\Attribute;
|
||||
|
||||
/**
|
||||
* Bill class.
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class BillAttribute implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Id.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected int $id = 0;
|
||||
|
||||
/**
|
||||
* Bill this attribute belongs to
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public int $bill = 0;
|
||||
|
||||
/**
|
||||
* Attribute type the attribute belongs to
|
||||
*
|
||||
* @var BillAttributeType
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public BillAttributeType $type;
|
||||
|
||||
/**
|
||||
* Attribute value the attribute belongs to
|
||||
*
|
||||
* @var BillAttributeValue
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public BillAttributeValue $value;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,216 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Billing\Models\Attribute;
|
||||
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
||||
/**
|
||||
* Bill Attribute Type class.
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class BillAttributeType implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Id
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected int $id = 0;
|
||||
|
||||
/**
|
||||
* Name/string identifier by which it can be found/categorized
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public string $name = '';
|
||||
|
||||
/**
|
||||
* Which field data type is required (string, int, ...) in the value
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected int $fields = 0;
|
||||
|
||||
/**
|
||||
* Is a custom value allowed (e.g. custom string)
|
||||
*
|
||||
* @var bool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public bool $custom = false;
|
||||
|
||||
public string $validationPattern = '';
|
||||
|
||||
public bool $isRequired = false;
|
||||
|
||||
/**
|
||||
* Datatype of the attribute
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public int $datatype = AttributeValueType::_STRING;
|
||||
|
||||
/**
|
||||
* Localization
|
||||
*
|
||||
* @var BaseStringL11n
|
||||
*/
|
||||
private string | BaseStringL11n $l11n = '';
|
||||
|
||||
/**
|
||||
* Possible default attribute values
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private array $defaults = [];
|
||||
|
||||
/**
|
||||
* Default attribute value
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public int $default = 0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name Name/identifier of the attribute type
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(string $name = '')
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,230 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Billing\Models\Attribute;
|
||||
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
||||
/**
|
||||
* Bill attribute value class.
|
||||
*
|
||||
* The relation with the type/bill is defined in the BillAttribute class.
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class BillAttributeValue implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Id
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected int $id = 0;
|
||||
|
||||
/**
|
||||
* Depending attribute type
|
||||
*
|
||||
* @var null|int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public ?int $dependingAttributeType = null;
|
||||
|
||||
/**
|
||||
* Depending attribute value
|
||||
*
|
||||
* @var null|int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public ?int $dependingAttributeValue = null;
|
||||
|
||||
/**
|
||||
* Int value
|
||||
*
|
||||
* @var null|int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public ?int $valueInt = null;
|
||||
|
||||
/**
|
||||
* String value
|
||||
*
|
||||
* @var null|string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public ?string $valueStr = null;
|
||||
|
||||
/**
|
||||
* Decimal value
|
||||
*
|
||||
* @var null|float
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public ?float $valueDec = null;
|
||||
|
||||
/**
|
||||
* DateTime value
|
||||
*
|
||||
* @var null|\DateTimeInterface
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public ?\DateTimeInterface $valueDat = null;
|
||||
|
||||
/**
|
||||
* Is a default value which can be selected
|
||||
*
|
||||
* @var bool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public bool $isDefault = false;
|
||||
|
||||
/**
|
||||
* Unit of the value
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public string $unit = '';
|
||||
|
||||
/**
|
||||
* Localization
|
||||
*
|
||||
* @var null|BaseStringL11n
|
||||
*/
|
||||
private ?BaseStringL11n $l11n = null;
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getId() : int
|
||||
{
|
||||
return $this->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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Billing\Models\Attribute;
|
||||
|
||||
/**
|
||||
* Null model
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullBillAttribute extends BillAttribute
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return ['id' => $this->id];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Billing\Models\Attribute;
|
||||
|
||||
/**
|
||||
* Null model
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullBillAttributeType extends BillAttributeType
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return ['id' => $this->id];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Billing\Models\Attribute;
|
||||
|
||||
/**
|
||||
* Null model
|
||||
*
|
||||
* @package Modules\Billing\Models\Attribute
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullBillAttributeValue extends BillAttributeValue
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return ['id' => $this->id];
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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' => [
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user