Further exchange draft implementation

This commit is contained in:
Dennis Eichhorn 2018-05-31 17:39:12 +02:00
parent 8a183c5452
commit 6626529307
7 changed files with 108 additions and 41 deletions

View File

@ -187,21 +187,20 @@ final class Controller extends ModuleAbstract implements WebInterface
return;
}
$import = $this->importDataFromRequest($request);
$import = $this->importDataFromRequest($request);
$status = NotificationLevel::ERROR;
$message = 'Import failed.';
if ($import) {
$response->set($request->getUri()->__toString(), [
'status' => NotificationLevel::OK,
'title' => 'Exchange',
'message' => 'Import succeeded.'
]);
} else {
$response->set($request->getUri()->__toString(), [
'status' => NotificationLevel::ERROR,
'title' => 'Exchange',
'message' => 'Import failed.'
]);
$status = NotificationLevel::OK;
$message = 'Import succeeded.';
}
$response->set($request->getUri()->__toString(), [
'status' => status,
'title' => 'Exchange',
'message' => $message
]);
}
/**
@ -217,11 +216,11 @@ final class Controller extends ModuleAbstract implements WebInterface
{
$interfaces = InterfaceManagerMapper::getAll();
foreach ($interfaces as $interface) {
if ($request->getData('exchange') === $interface->getInterfacePath()) {
if ($request->getData('exchange') ?? '' === $interface->getInterfacePath()) {
$class = '\\Modules\\Exchange\\Interfaces\\' . $interface->getInterfacePath() . '\\Importer';
$importer = new $class();
$importer = new $class($this->app->dbPool->get());
return $importer->importRequest($request);
return $importer->importFromRequest($request);
}
}

View File

@ -12,12 +12,12 @@
*/
declare(strict_types=1);
namespace Interfaces\GSD;
namespace Modules\Exchange\Interfaces\GSD;
use Interfaces\ImporterAbstract;
use Interfaces\GSD\Model\GSDCostCenterMapper;
use Interfaces\GSD\Model\GSDCostObjectMapper;
use Interfaces\GSD\Model\GSDCustomerMapper;
use Modules\Exchange\Models\ImporterAbstract;
use Modules\Exchange\Interfaces\GSD\Model\GSDCostCenterMapper;
use Modules\Exchange\Interfaces\GSD\Model\GSDCostObjectMapper;
use Modules\Exchange\Interfaces\GSD\Model\GSDCustomerMapper;
use Modules\Accounting\Models\CostCenterMapper;
use Modules\Accounting\Models\CostCenter;
@ -28,17 +28,28 @@ use Modules\ClientManagement\Models\ClientMapper;
use Modules\ClientManagement\Models\Client;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\Connection\ConnectionFactory;
use phpOMS\DataStorage\Database\DatabaseStatus;
use phpOMS\Message\RequestAbstract;
/**
* GSD import class
*
* @package Interfaces\GSD
* @package Modules\Exchange\Models\Interfaces\GSD
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
final class Importer extends ImporterAbstract
{
/**
* Database connection.
*
* @var ConnectionInterface
* @since 1.0.0
*/
private $remote = null;
/**
* Import all data in time span
*
@ -63,6 +74,57 @@ final class Importer extends ImporterAbstract
$this->importBatchPosting($start, $end);
}
public function importFromRequest(RequestAbstract $request) : bool
{
$start = new \DateTime($request->getData('start') ?? 'now');
$end = new \DateTime($request->getData('end') ?? 'now');
$this->remote = ConnectionFactory::create([
'db' => $request->getData('db') ?? '',
'host' => $request->getData('host') ?? '',
'port' => (int) ($request->getData('port') ?? 0),
'database' => $request->getData('database') ?? '',
'login' => $request->getData('login') ?? '',
'password' => $request->getData('password') ?? '',
]);
if ($this->remote->getStatus() !== DatabaseStatus::OK) {
return false;
}
if (((bool) ($request->getData('customers') ?? false))) {
$this->importAddress($start, $end);
$this->importCustomer($start, $end);
}
if (((bool) ($request->getData('suppliers') ?? false))) {
$this->importAddress($start, $end);
$this->importSupplier($start, $end);
}
if (((bool) ($request->getData('accounts') ?? false))) {
$this->importAccount($start, $end);
}
if (((bool) ($request->getData('costcenters') ?? false))) {
$this->importCostCenter($start, $end);
}
if (((bool) ($request->getData('costobjects') ?? false))) {
$this->importCostObject($start, $end);
}
if (((bool) ($request->getData('articles') ?? false))) {
$this->importArticle($start, $end);
}
if (((bool) ($request->getData('invoices') ?? false))) {
$this->importInvoice($start, $end);
}
return true;
}
/**
* Import cost centers
*
@ -75,11 +137,11 @@ final class Importer extends ImporterAbstract
*/
public function importCostCenter(\DateTime $start, \DateTime $end) : void
{
DataMapperAbstract::setConnection($this->app->dbPool->get('gsd'));
DataMapperAbstract::setConnection($this->remote);
$costCenters = GSDCostCenterMapper::getAll();
$obj = new CostCenter();
DataMapperAbstract::setConnection($this->app->dbPool->get('oms'));
DataMapperAbstract::setConnection($this->local);
foreach ($costCenters as $cc) {
$obj->setCostCenter((int) $cc->getCostCenter());
@ -101,11 +163,11 @@ final class Importer extends ImporterAbstract
*/
public function importCostObject(\DateTime $start, \DateTime $end) : void
{
DataMapperAbstract::setConnection($this->app->dbPool->get('gsd'));
DataMapperAbstract::setConnection($this->remote);
$costObjects = GSDCostObjectMapper::getAll();
$obj = new CostObject();
DataMapperAbstract::setConnection($this->app->dbPool->get('oms'));
DataMapperAbstract::setConnection($this->local);
foreach ($costObjects as $co) {
$obj->setCostObject((int) $co->getCostObject());

View File

@ -35,7 +35,7 @@ final class GSDCostCenterMapper extends DataMapperAbstract
*/
protected static $columns = [
'ROW_ID' => ['name' => 'ROW_ID', 'type' => 'int', 'internal' => 'id'],
'row_create_time' => ['name' => 'row_create_time', 'type' => '\DateTime', 'internal' => 'createdAt'],
'row_create_time' => ['name' => 'row_create_time', 'type' => 'DateTime', 'internal' => 'createdAt'],
'row_create_user' => ['name' => 'row_create_user', 'type' => 'int', 'internal' => 'createdBy'],
'KST' => ['name' => 'KST', 'type' => 'string', 'internal' => 'costcenter'],
'Bezeichnung' => ['name' => 'Bezeichnung', 'type' => 'string', 'internal' => 'description'],

View File

@ -35,7 +35,7 @@ final class GSDCostObjectMapper extends DataMapperAbstract
*/
protected static $columns = [
'ROW_ID' => ['name' => 'ROW_ID', 'type' => 'int', 'internal' => 'id'],
'row_create_time' => ['name' => 'row_create_time', 'type' => '\DateTime', 'internal' => 'createdAt'],
'row_create_time' => ['name' => 'row_create_time', 'type' => 'DateTime', 'internal' => 'createdAt'],
'row_create_user' => ['name' => 'row_create_user', 'type' => 'int', 'internal' => 'createdBy'],
'KTR' => ['name' => 'KTR', 'type' => 'string', 'internal' => 'costobject'],
'Bezeichnung' => ['name' => 'Bezeichnung', 'type' => 'string', 'internal' => 'description'],

View File

@ -7,6 +7,16 @@
<form id="fImport" method="POST" action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/admin/exchange/import/profile?{?}&exchange=GSD&csrf={$CSRF}'); ?>">
<table class="layout wf-100" style="table-layout: fixed">
<tbody>
<tr><td><label for="iHost"><?= $this->getHtml('Host') ?></label>
<tr><td><input type="text" id="iHost" name="host" placeholder="&#xf040; <?= $this->getHtml('Host') ?>" required><input type="hidden" id="iDb" name="db" value="<?= \phpOMS\DataStorage\Database\DatabaseType::SQLSRV; ?>" required>
<tr><td><label for="iPort"><?= $this->getHtml('Port') ?></label>
<tr><td><input type="text" id="iPort" name="port" value="1433" required>
<tr><td><label for="iDatabase"><?= $this->getHtml('Database') ?></label>
<tr><td><input type="text" id="iDatabase" name="database" placeholder="&#xf040; <?= $this->getHtml('Database') ?>" required>
<tr><td><label for="iLogin"><?= $this->getHtml('Login') ?></label>
<tr><td><input type="text" id="iLogin" name="login" placeholder="&#xf040; <?= $this->getHtml('Login') ?>" required>
<tr><td><label for="iPassword"><?= $this->getHtml('Password') ?></label>
<tr><td><input type="password" id="iPassword" name="password" placeholder="&#xf040; <?= $this->getHtml('Password') ?>" required>
<tr><td><label for="iStart"><?= $this->getHtml('Start') ?></label>
<tr><td><input type="datetime-local" id="iStart" name="start" value="<?= $this->printHtml((new \DateTime('NOW'))->format('Y-m-d\TH:i:s')); ?>">
<tr><td><label for="iEnd"><?= $this->getHtml('End') ?></label>

View File

@ -12,7 +12,7 @@
*/
declare(strict_types=1);
namespace Interfaces;
namespace Modules\Exchange\Models;
use phpOMS\DataStorage\Database\Connection\ConnectionInterface;
@ -34,14 +34,6 @@ abstract class ImporterAbstract
*/
private $local = null;
/**
* Database connection.
*
* @var ConnectionInterface
* @since 1.0.0
*/
private $remote = null;
/**
* Constructor
*
@ -50,9 +42,8 @@ abstract class ImporterAbstract
*
* @since 1.0.0
*/
public function __construct(ConnectionInterface $local, ConnectionInterface $remote)
public function __construct(ConnectionInterface $local)
{
$this->remote = $remote;
$this->local = $local;
}
}

View File

@ -11,13 +11,18 @@
* @link http://website.orange-management.de
*/
return ['Exchange' => [
'End' => 'End',
'Database' => 'Database',
'End' => 'End',
'Exchange' => 'Exchange',
'Export' => 'Export',
'Export' => 'Export',
'Exports' => 'Exports',
'Import' => 'Import',
'Host' => 'Host',
'Import' => 'Import',
'Imports' => 'Imports',
'Login' => 'Login',
'Options' => 'Options',
'Password' => 'Password',
'Port' => 'Port',
'Start' => 'Start',
'Title' => 'Title',
'Website' => 'Website',