Initial xentral_oss_20.3.c9ffacf
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\EPost;
|
||||
|
||||
use Xentral\Core\DependencyInjection\ContainerInterface;
|
||||
use Xentral\Modules\DocuvitaApi\Exception\ConfigurationMissingException;
|
||||
|
||||
final class Bootstrap
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function registerServices()
|
||||
{
|
||||
return [
|
||||
'EPostService' => 'onInitEPostService',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
*
|
||||
* @throws ConfigurationMissingException
|
||||
*
|
||||
* @return EPostService
|
||||
*/
|
||||
public static function onInitEPostService(ContainerInterface $container)
|
||||
{
|
||||
return new EPostService($container);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\EPost\DataTable;
|
||||
|
||||
use ApplicationCore;
|
||||
use Xentral\Components\Database\Database;
|
||||
use Xentral\Components\Database\SqlQuery\SelectQuery;
|
||||
use Xentral\Widgets\DataTable\Column\Column;
|
||||
use Xentral\Widgets\DataTable\Column\ColumnCollection;
|
||||
use Xentral\Widgets\DataTable\Feature\DebugFeature;
|
||||
use Xentral\Widgets\DataTable\Feature\FeatureCollection;
|
||||
use Xentral\Widgets\DataTable\Filter\CustomFilter;
|
||||
use Xentral\Widgets\DataTable\Filter\FilterCollection;
|
||||
use Xentral\Widgets\DataTable\Options\DataTableOptions;
|
||||
use Xentral\Widgets\DataTable\Request\DataTableRequest;
|
||||
use Xentral\Widgets\DataTable\Type\AbstractDataTableType;
|
||||
|
||||
class EPostListTable extends AbstractDataTableType
|
||||
{
|
||||
public function configureOptions(DataTableOptions $options)
|
||||
{
|
||||
parent::configureOptions($options); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
public function configureQuery(SelectQuery $query)
|
||||
{
|
||||
parent::configureQuery($query); // TODO: Change the autogenerated stub
|
||||
$app = new ApplicationCore();
|
||||
$query
|
||||
->from('rechnung AS a')
|
||||
->cols([
|
||||
'a.id',
|
||||
'CONCAT(\'<input type="checkbox" name="select-\', a.id, \'">\') AS auswahl',
|
||||
'a.belegnr',
|
||||
'IF(e.id IS NULL AND false, "-", DATE_FORMAT(a.datum,\'%d.%m.%Y\')) AS datum',
|
||||
'IF(e.id IS NULL, "nicht uebertragen", e.status) AS status',
|
||||
'IF(e.id IS NULL, "-", e.datei) AS datei',
|
||||
'IF(e.id IS NULL,
|
||||
CONCAT(\'<a href="index.php?module=epost&action=uebertragen&rechnung=\', a.id, \'"><img src="themes/new/images/forward.png"></a>\'),
|
||||
CONCAT(\'<a href="index.php?module=epost&action=download&id=\', e.id, \'"><img src="themes/new/images/download.png"></a>\')
|
||||
) AS download',
|
||||
'a.name',
|
||||
'a.kundennummer',
|
||||
'a.land',
|
||||
'a.projekt',
|
||||
'a.zahlungsweise',
|
||||
'a.zahlungsstatus',
|
||||
'a.status AS belegstatus',
|
||||
'a.soll AS betrag',
|
||||
'p.abkuerzung AS projekt',
|
||||
'a.soll - a.ist AS differenz'
|
||||
])
|
||||
->leftJoin(
|
||||
'epost_files AS e',
|
||||
'a.id=e.rechnung'
|
||||
)
|
||||
->leftJoin(
|
||||
'projekt AS p',
|
||||
'a.projekt = p.id'
|
||||
);
|
||||
}
|
||||
|
||||
public function configureColumns(ColumnCollection $columns)
|
||||
{
|
||||
parent::configureColumns($columns); // TODO: Change the autogenerated stub
|
||||
|
||||
$columns->add(Column::visible('auswahl', 'Auswahl'));
|
||||
$columns->add(Column::searchable('belegnr', 'Rechnung'));
|
||||
$columns->add(Column::sortable('datum', 'Vom'));
|
||||
$columns->add(Column::searchable('kundennummer', 'Kd-Nr.'));
|
||||
$columns->add(Column::searchable('name', 'Kunde'));
|
||||
$columns->add(Column::searchable('land', 'Land'));
|
||||
$columns->add(Column::searchable('projekt', 'Projekt'));
|
||||
$columns->add(Column::searchable('zahlungsweise', 'Zahlung'));
|
||||
$columns->add(Column::searchable('betrag', 'Betrag (Brutto)'));
|
||||
$columns->add(Column::searchable('zahlungsstatus', 'Zahlstatus'));
|
||||
$columns->add(Column::sortable('differenz', 'Differenz'));
|
||||
$columns->add(Column::searchable('belegstatus', 'Belegstatus'));
|
||||
$columns->add(Column::sortable('status', 'Status'));
|
||||
$columns->add(Column::sortable('datei', 'Datei'));
|
||||
$columns->add(Column::visible('download', 'Download'));
|
||||
}
|
||||
|
||||
public function configureFeatures(FeatureCollection $features)
|
||||
{
|
||||
parent::configureFeatures($features); // TODO: Change the autogenerated stub
|
||||
// $features->add(new DebugFeature());
|
||||
}
|
||||
|
||||
public function configureFilters(FilterCollection $filters)
|
||||
{
|
||||
$closure = function (SelectQuery $query, DataTableRequest $request) {
|
||||
$filter = $request->getParams()->getFilterValues();
|
||||
if ($filter['epost_auch_versendete'] === 'false') {
|
||||
$query->where('a.status != "versendet"');
|
||||
}
|
||||
if (!empty($filter['epost_date'])) {
|
||||
$date = new \DateTime($filter['epost_date']);
|
||||
$query->where('DATE(a.datum) = :date')
|
||||
->bindValue('date', $date->format('Y-m-d'));
|
||||
}
|
||||
};
|
||||
$filters->add(new CustomFilter($closure));
|
||||
}
|
||||
|
||||
protected function addDefaultFeatures(FeatureCollection $featureCollection)
|
||||
{
|
||||
parent::addDefaultFeatures($featureCollection); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\EPost;
|
||||
|
||||
use ApplicationCore;
|
||||
use RuntimeException;
|
||||
use Xentral\Engine\Application;
|
||||
use Xentral\Engine\Container;
|
||||
use Xentral\Components\Database\Database;
|
||||
|
||||
class EPostService
|
||||
{
|
||||
/** @var Database */
|
||||
private $database;
|
||||
|
||||
/** @var \Application */
|
||||
private $app;
|
||||
|
||||
/**
|
||||
* EPostService constructor.
|
||||
*
|
||||
* @param Container $container
|
||||
*/
|
||||
public function __construct($container)
|
||||
{
|
||||
$this->database = $container->get('Database');
|
||||
$this->app = $container->get('LegacyApplication');
|
||||
}
|
||||
|
||||
public function getSyncedFiles(){
|
||||
$query = $this->database->select()
|
||||
->from('epost_files')
|
||||
->cols([
|
||||
'auftrag',
|
||||
'datum',
|
||||
'status',
|
||||
'datei'
|
||||
]);
|
||||
|
||||
return $this->database->fetchAll($query->getStatement(), $query->getBindValues());
|
||||
}
|
||||
|
||||
public function outputFileById($id){
|
||||
$query = $this->database->select()
|
||||
->from('epost_files')
|
||||
->cols(['datei'])
|
||||
->where("id={$id}");
|
||||
|
||||
$filePath = $this->database->fetchValue($query->getStatement(), $query->getBindValues());
|
||||
|
||||
if(!file_exists($filePath)){
|
||||
throw new RuntimeException("Datei {$filePath} existiert nicht");
|
||||
}
|
||||
|
||||
header('Content-Type: application/pdf');
|
||||
header('Content-Disposition: attachment; filename="' . basename($filePath) . '"');
|
||||
|
||||
echo file_get_contents($filePath);
|
||||
|
||||
$this->app->ExitXentral();
|
||||
}
|
||||
|
||||
private function syncReceipt($receiptId, $belegNr, $projectId, $styleSettings, $outputDir, $markAsSent){
|
||||
$receipt = new \RechnungPDF($this->app, $projectId, $styleSettings);
|
||||
$receipt->GetRechnung($receiptId);
|
||||
|
||||
$tempFile = $receipt->displayTMP();
|
||||
|
||||
if($outputDir[strlen($outputDir) - 1] != '/') $outputDir .= '/';
|
||||
$outputFile = $outputDir . 'RE' .$belegNr . '_' . uniqid() . '.pdf';
|
||||
rename($tempFile, $outputFile);
|
||||
|
||||
if(file_exists($tempFile)) throw new RuntimeException("Fehler beim Verschieben der datei {$tempFile}");
|
||||
if(!file_exists($outputFile)) throw new RuntimeException("Fehler beim Erstellen der Datei {$outputFile}");
|
||||
|
||||
$query = $this->database->insert()
|
||||
->into('epost_files')
|
||||
->cols([
|
||||
'status' => 'erfolgreich',
|
||||
'rechnung' => $receiptId,
|
||||
'datei' => $outputFile
|
||||
]);
|
||||
|
||||
$this->database->perform($query->getStatement(), $query->getBindValues());
|
||||
|
||||
if($markAsSent){
|
||||
$query = $this->database->update()
|
||||
->table('rechnung')
|
||||
->cols([
|
||||
'status' => 'versendet',
|
||||
'versendet' => 1,
|
||||
'schreibschutz' => 1
|
||||
])
|
||||
->where('id=:id')
|
||||
->bindValue('id', $receiptId);
|
||||
|
||||
$this->database->perform($query->getStatement(), $query->getBindValues());
|
||||
}
|
||||
$this->app->erp->RechnungProtokoll($receiptId, 'An EPost übertragen');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $receiptIds
|
||||
* @param array $styleSettings
|
||||
* @param string $outputDir
|
||||
* @param bool $markAsSent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function syncReceipts($receiptIds, $styleSettings, $outputDir, $markAsSent){
|
||||
if(empty($outputDir) || !file_exists($outputDir) || !is_dir($outputDir)) throw new RuntimeException('Bitte gültigen Ablageordner angeben!');
|
||||
if(empty($receiptIds)) throw new RuntimeException('Keine Aufträge ausgewählt');
|
||||
|
||||
$query = $this->database->select()
|
||||
->cols(['id', 'belegnr', 'projekt'])
|
||||
->from('rechnung');
|
||||
|
||||
foreach ($receiptIds as $receiptId){
|
||||
$query = $query->orWhere("id={$receiptId}");
|
||||
}
|
||||
|
||||
$receipts = $this->database->fetchAssoc($query->getStatement(), $query->getBindValues());
|
||||
|
||||
foreach ($receiptIds as $receipt) {
|
||||
$this->syncReceipt(
|
||||
$receipt,
|
||||
$receipts[$receipt]['belegnr'],
|
||||
$receipts[$receipt]['projekt'],
|
||||
$styleSettings,
|
||||
$outputDir,
|
||||
$markAsSent
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user