Skip to content
Snippets Groups Projects
Verified Commit af3a5dea authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #10529 TIME 2 start print entity separator

parent a61a3160
No related branches found
No related tags found
No related merge requests found
......@@ -169,6 +169,7 @@ $app->get('/entities/{id}/users', \Entity\controllers\EntityController::class .
$app->put('/entities/{id}/reassign/{newEntityId}', \Entity\controllers\EntityController::class . ':reassignEntity');
$app->put('/entities/{id}/status', \Entity\controllers\EntityController::class . ':updateStatus');
$app->get('/entityTypes', \Entity\controllers\EntityController::class . ':getTypes');
$app->post('/entitySeparators', \Entity\controllers\EntitySeparatorController::class . ':create');
//Groups
$app->get('/groups', \Group\controllers\GroupController::class . ':get');
......
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
* @brief Print Separator Controller
* @author dev@maarch.org
*/
namespace Entity\controllers;
use Endroid\QrCode\QrCode;
use Entity\models\EntityModel;
use Group\models\ServiceModel;
use Parameter\models\ParameterModel;
use Respect\Validation\Validator;
use setasign\Fpdi\Tcpdf\Fpdi;
use Slim\Http\Request;
use Slim\Http\Response;
class EntitySeparatorController
{
public function create(Request $request, Response $response)
{
if (!ServiceModel::hasService(['id' => 'entities_print_sep_mlb', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
$bodyData = $request->getParsedBody();
if (!Validator::stringType()->notEmpty()->validate($bodyData['type'])) {
return $response->withStatus(403)->withJson(['errors' => 'type is not set or empty']);
}
if (!in_array($bodyData['type'], ['barcode', 'qrcode'])) {
return $response->withStatus(403)->withJson(['errors' => 'type value must be qrcode or barcode']);
}
$entitiesList = [];
if ($bodyData['target'] == 'generic') {
$entitiesList['COURRIER'] = 'Maarch Courrier';
} else {
if (!Validator::arrayType()->notEmpty()->validate($bodyData['entities'])) {
return $response->withStatus(403)->withJson(['errors' => 'entities is not set or empty']);
}
$entitiesInfo = EntityModel::get([
'select' => ['entity_label', 'entity_id'],
'where' => ['entity_id in (?)'],
'data' => [$bodyData['entities']],
'order_by' => ['entity_label asc']
]);
foreach ($entitiesInfo as $value) {
$entitiesList[$value['entity_id']] = $value['entity_label'];
}
}
$pdf = new Fpdi('P', 'pt');
$pdf->setPrintHeader(false);
foreach ($entitiesList as $entityId => $entityLabel) {
$pdf->AddPage();
$pdf->SetFont('', 'B', 20);
$pdf->Cell(250, 20, _PRINT_SEP_TITLE, 0, 1, 'C');
$pdf->Cell(250, 20, $entityId, 0, 1, 'C');
$pdf->Cell(180, 10, '', 0, 1, 'C');
if ($bodyData['type'] == 'qrcode') {
$parameter = ParameterModel::getById(['select' => ['param_value_int'], 'id' => 'QrCodePrefix']);
$prefix = '';
if ($parameter['param_value_int'] == 1) {
$prefix = 'Maarch_';
}
$qrCode = new QrCode($prefix . $entityId);
// $qrCode->setSize(110);
// $qrCode->setMargin(25);
$pdf->Image('@'.$qrCode->writeString(), 0, 0, 80);
} else {
// $p_cab = $cab_pdf->generateBarCode($type, $code, 40, '', '', '');
// $pdf->Image($_SESSION['config']['tmppath'].DIRECTORY_SEPARATOR.$p_cab, 40, 50, 120);
}
$pdf->Cell(180, 10, '', 0, 1, 'C');
$pdf->Cell(180, 10, '', 0, 1, 'C');
$pdf->Cell(180, 10, '', 0, 1, 'C');
$pdf->Cell(180, 10, '', 0, 1, 'C');
$pdf->Cell(180, 10, '', 0, 1, 'C');
$pdf->Cell(180, 10, '', 0, 1, 'C');
$pdf->Cell(180, 10, '', 0, 1, 'C');
$pdf->Cell(180, 10, '', 0, 1, 'C');
$pdf->Cell(180, 10, utf8_decode(_ENTITY), 1, 1, 'C');
$pdf->SetFont('', 'B', 12);
$pdf->Cell(180, 10, utf8_decode($entityLabel), 1, 1, 'C');
}
$fileContent = $pdf->Output('', 'S');
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$mimeType = $finfo->buffer($fileContent);
$response->write($fileContent);
$response = $response->withAddedHeader('Content-Disposition', "inline; filename=entitySeparator.pdf");
return $response->withHeader('Content-Type', $mimeType);
}
}
......@@ -495,3 +495,6 @@ define("_XPARAPH_ACCOUNT_CREATED", "xParaph account created");
define("_FILE_NOT_ALLOWED_INFO_1", "This extension");
define("_FILE_NOT_ALLOWED_INFO_2", "with MIME-type");
define("_FILE_NOT_ALLOWED_INFO_3", "is not allowed");
define("_ENTITY", "Entity");
define("_PRINT_SEP_TITLE", "Scan separator");
......@@ -495,3 +495,5 @@ define("_XPARAPH_ACCOUNT_CREATED", "Compte xParaph créé");
define("_FILE_NOT_ALLOWED_INFO_1", "L'extension");
define("_FILE_NOT_ALLOWED_INFO_2", "avec le type MIME");
define("_FILE_NOT_ALLOWED_INFO_3", "n'est pas autorisée");
define("_ENTITY", "Entité");
define("_PRINT_SEP_TITLE", "Séparateur de scan");
......@@ -497,3 +497,6 @@ define("_XPARAPH_ACCOUNT_CREATED", "xParaph account created_TO_TRANSLATE");
define("_FILE_NOT_ALLOWED_INFO_1", "This extension_TO_TRANSLATE");
define("_FILE_NOT_ALLOWED_INFO_2", "with MIME-type_TO_TRANSLATE");
define("_FILE_NOT_ALLOWED_INFO_3", "is not allowed_TO_TRANSLATE");
define("_ENTITY", "Entity_TO_TRANSLATE");
define("_PRINT_SEP_TITLE", "Scan separator_TO_TRANSLATE");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment