code fixes

This commit is contained in:
Dennis Eichhorn 2024-03-15 20:24:38 +00:00
parent ec1d64cf96
commit 77481c127f
8 changed files with 66 additions and 27 deletions

View File

@ -18,10 +18,10 @@ use Modules\ClientManagement\Models\SettingsEnum;
return [
[
"description" => "Default item segmentation (segment, section, sales group, product group)",
'type' => 'setting',
'name' => SettingsEnum::DEFAULT_SEGMENTATION,
'content' => '{"segment":1, "section":1, "client_group":1}',
'pattern' => '',
'module' => ApiController::NAME,
'type' => 'setting',
'name' => SettingsEnum::DEFAULT_SEGMENTATION,
'content' => '{"segment":1, "section":1, "client_group":1}',
'pattern' => '',
'module' => ApiController::NAME,
],
];

View File

@ -245,6 +245,7 @@
{ "value": "FI" },
{ "value": "FR" },
{ "value": "DE" },
{ "value": "DE_0" },
{ "value": "GR" },
{ "value": "HU" },
{ "value": "IE" },

View File

@ -62,8 +62,9 @@ final class Installer extends InstallerAbstract
$attrValues = self::createClientAttributeValues($app, $attrTypes, $attributes);
$data = include __DIR__ . '/Install/Admin.install.php';
$content = \json_decode($data[0]['content'], true);
/** @var array $content */
$content = \json_decode($data[0]['content'], true);
foreach ($content as $type => $_) {
$content[$type] = \reset($attrValues[$type])['id'];
}

View File

@ -88,6 +88,16 @@ final class ApiController extends Controller
return $client->id === 0 ? null : $client;
}
/**
* Set VAT for client
*
* @param RequestAbstract $request Request
* @param Client $client Client
*
* @return void
*
* @since 1.0.0
*/
public function setVAT(RequestAbstract $request, Client $client) : void
{
/** @var \Modules\Attribute\Models\AttributeType $type */
@ -105,6 +115,16 @@ final class ApiController extends Controller
->apiClientAttributeCreate($internalRequest, $internalResponse);
}
/**
* Validate VAT of client
*
* @param RequestAbstract $request Request
* @param Client $client Client
*
* @return array
*
* @since 1.0.0
*/
public function validateVAT(RequestAbstract $request, Client $client) : array
{
/** @var \Modules\Organization\Models\Unit $unit */
@ -146,6 +166,16 @@ final class ApiController extends Controller
return $validate;
}
/**
* Set tax code for client
*
* @param RequestAbstract $request Request
* @param Client $client Client
*
* @return void
*
* @since 1.0.0
*/
public function defineTaxCode(RequestAbstract $request, Client $client) : void
{
/** @var \Modules\Organization\Models\Unit $unit */
@ -246,16 +276,31 @@ final class ApiController extends Controller
$this->createStandardCreateResponse($request, $response, $client);
}
/**
* Create client segmentation.
*
* Default: segment->section->sales_group and to the side client_type
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param Client $client Client
*
* @return void
*
* @since 1.0.0
*/
private function createClientSegmentation(RequestAbstract $request, ResponseAbstract $response, Client $client) : void
{
/** @var \Model\Setting $settings */
$settings = $this->app->appSettings->get(null, SettingsEnum::DEFAULT_SEGMENTATION);
/** @var array $segmentation */
$segmentation = \json_decode($settings->content, true);
if ($segmentation === false || $segmentation === null) {
return;
}
/** @var \Modules\Attribute\Models\AttributeType[] $types */
$types = ClientAttributeTypeMapper::getAll()
->where('name', \array_keys($segmentation), 'IN')
->execute();

View File

@ -226,7 +226,6 @@ final class BackendController extends Controller
$pkValue = $request->getDataString('number');
}
/** @var \Modules\ClientManagement\Models\Client */
$view->data['client'] = ClientMapper::get()
->with('account')
->with('account/addresses')
@ -253,7 +252,6 @@ final class BackendController extends Controller
$view->data['attributeView'] = new \Modules\Attribute\Theme\Backend\Components\AttributeView($this->app->l11nManager, $request, $response);
$view->data['attributeView']->data['default_localization'] = $this->app->l11nServer;
/** @var \Modules\Attribute\Models\AttributeType[] */
$view->data['attributeTypes'] = ClientAttributeTypeMapper::getAll()
->with('l11n')
->where('l11n/language', $response->header->l11n->language)
@ -292,7 +290,6 @@ final class BackendController extends Controller
$view->data['hasBilling'] = $this->app->moduleManager->isActive('Billing');
/** @var \Modules\Billing\Models\Price\Price[] */
$view->data['prices'] = $view->data['hasBilling']
? \Modules\Billing\Models\Price\PriceMapper::getAll()
->where('client', $view->data['client']->id)
@ -300,6 +297,7 @@ final class BackendController extends Controller
->execute()
: [];
/** @var \Modules\Attribute\Models\AttributeType[] $tmp */
$tmp = ItemAttributeTypeMapper::getAll()
->with('defaults')
->with('defaults/l11n')
@ -308,8 +306,8 @@ final class BackendController extends Controller
'sales_tax_code', 'purchase_tax_code',
], 'IN')
->where('defaults/l11n', (new Where($this->app->dbPool->get()))
->where(ItemAttributeValueL11nMapper::getColumnByMember('ref'), '=', null)
->orWhere(ItemAttributeValueL11nMapper::getColumnByMember('language'), '=', $response->header->l11n->language))
->where(ItemAttributeValueL11nMapper::getColumnByMember('ref') ?? '', '=', null)
->orWhere(ItemAttributeValueL11nMapper::getColumnByMember('language') ?? '', '=', $response->header->l11n->language))
->execute();
$defaultAttributeTypes = [];
@ -319,6 +317,7 @@ final class BackendController extends Controller
$view->data['defaultAttributeTypes'] = $defaultAttributeTypes;
/** @var \Modules\Attribute\Models\AttributeType[] $tmp */
$tmp = ClientAttributeTypeMapper::getAll()
->with('defaults')
->with('defaults/l11n')
@ -327,8 +326,8 @@ final class BackendController extends Controller
'sales_tax_code',
], 'IN')
->where('defaults/l11n', (new Where($this->app->dbPool->get()))
->where(ClientAttributeValueL11nMapper::getColumnByMember('ref'), '=', null)
->orWhere(ClientAttributeValueL11nMapper::getColumnByMember('language'), '=', $response->header->l11n->language))
->where(ClientAttributeValueL11nMapper::getColumnByMember('ref') ?? '', '=', null)
->orWhere(ClientAttributeValueL11nMapper::getColumnByMember('language') ?? '', '=', $response->header->l11n->language))
->execute();
$clientSegmentationTypes = [];
@ -359,7 +358,6 @@ final class BackendController extends Controller
// @todo join audit with files, attributes, localization, prices, notes, ...
/** @var \Modules\Media\Models\Media[] */
$view->data['files'] = MediaMapper::getAll()
->with('types')
->join('id', ClientMapper::class, 'files') // id = media id, files = client relations

View File

@ -48,7 +48,7 @@ final class SearchController extends Controller
*/
public function searchGeneral(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void
{
$names = \explode(' ', ($request->getDataString('search') ?? ''));
$names = \explode(' ', ($request->getDataString('search') ?? ''));
$names[] = ($request->getDataString('search') ?? '');
$mapper = ClientMapper::getAll()
@ -72,7 +72,7 @@ final class SearchController extends Controller
// Get item profile image
// @feature Create a new read mapper function that returns relation models instead of its own model
// https://github.com/Karaka-Management/phpOMS/issues/320
$query = new Builder($this->app->dbPool->get());
$query = new Builder($this->app->dbPool->get());
$iResults = $query->selectAs(ClientMapper::HAS_MANY['files']['external'], 'file')
->from(ClientMapper::TABLE)
->leftJoin(ClientMapper::HAS_MANY['files']['table'])
@ -92,16 +92,16 @@ final class SearchController extends Controller
->execute();
$results[] = [
'title' => $account->account->name1 . ' ' . $account->account->name2,
'link' => '{/base}/sales/client/view?id=' . $account->id,
'title' => $account->account->name1 . ' ' . $account->account->name2,
'link' => '{/base}/sales/client/view?id=' . $account->id,
'email' => $account->account->getContactByType(ContactType::EMAIL)->content,
'phone' => $account->account->getContactByType(ContactType::PHONE)->content,
'city' => $account->mainAddress?->city,
'city' => $account->mainAddress->city,
'image' => $image->id === 0
? 'Web/Backend/img/logo_grey.png'
: $image->getPath(),
'type' => 'list_accounts',
'module' => 'Client Management',
'type' => 'list_accounts',
'module' => 'Client Management',
];
}

View File

@ -77,7 +77,6 @@ return ['ClientManagement' => [
'Purchase' => 'Kaufen',
'Quantity' => 'Menge',
'RecentInvoices' => 'Neuste Rechnungen',
'Region' => 'Region',
'Sales' => 'Umsatz',
'Segment' => 'Segment',
'Segments' => 'Segmente',
@ -92,7 +91,6 @@ return ['ClientManagement' => [
'YTDSales' => 'Ytd Sales',
'Zip' => 'Postleitzahl',
'ItemProductGroup' => 'Artikel Produktgruppe',
'ItemSalesGroup' => 'Artikel Umsatzgruppe',
'Promocode' => 'Promocode',
'Region' => 'Region',
'Materials' => 'Materialien',
@ -104,7 +102,6 @@ return ['ClientManagement' => [
'PrimarySupplier' => 'Hauptlieferant',
'LeadTime' => 'Lieferzeit',
'UnitQuantity' => 'Einheitsmenge',
'UnitPrice' => 'Einheitspreis',
'Lieferanten' => 'Lieferanten',
'CostCenter' => 'Kostenstelle',
'CostObject' => 'Kostenträger',

View File

@ -79,7 +79,6 @@ return ['ClientManagement' => [
'Purchase' => 'Purchase',
'Quantity' => 'Quantity',
'RecentInvoices' => 'Recent Invoices',
'Region' => 'Region',
'Sales' => 'Sales',
'Segment' => 'Segment',
'Segments' => 'Segments',
@ -88,13 +87,11 @@ return ['ClientManagement' => [
'Title' => 'Title',
'TotalPrice' => 'Total price',
'Type' => 'Type',
'UnitPrice' => 'Unit price',
'Website' => 'Website',
'Wire' => 'Wire',
'YTDSales' => 'YTD Sales',
'Zip' => 'Zip',
'ItemProductGroup' => 'Item Product Group',
'ItemSalesGroup' => 'Item Sales Group',
'Promocode' => 'Promocode',
'Region' => 'Region',
'Materials' => 'Materials',