Projet

Général

Profil

Fonctionnalité #5241 » reconcil.diff

Laurent GIOVANNONI, 14/09/2020 17:23

Voir les différences:

rest/index.php
$app->post('/attachments/{id}/mailing', \Attachment\controllers\AttachmentController::class . ':getMailingById');
$app->get('/attachmentsInformations', \Attachment\controllers\AttachmentController::class . ':getByChrono');
$app->get('/attachmentsTypes', \Attachment\controllers\AttachmentController::class . ':getAttachmentsTypes');
$app->post('/reconcil', \Attachment\controllers\AttachmentController::class . ':reconcil');
//AutoComplete
$app->get('/autocomplete/users', \SrcCore\controllers\AutoCompleteController::class . ':getUsers');
rest/index.php
$app->post('/attachments/{id}/mailing', \Attachment\controllers\AttachmentController::class . ':getMailingById');
$app->get('/attachmentsInformations', \Attachment\controllers\AttachmentController::class . ':getByChrono');
$app->get('/attachmentsTypes', \Attachment\controllers\AttachmentController::class . ':getAttachmentsTypes');
$app->post('/reconcil', \Attachment\controllers\AttachmentController::class . ':reconcil');
//AutoComplete
$app->get('/autocomplete/users', \SrcCore\controllers\AutoCompleteController::class . ':getUsers');
src/app/attachment/controllers/AttachmentController.php
return $response->withJson(['id' => $id]);
}
public function reconcil(Request $request, Response $response)
{
$body = $request->getParsedBody();
$control = AttachmentController::controlReconcil(['body' => $body]);
if (!empty($control['errors'])) {
return $response->withStatus(400)->withJson(['errors' => $control['errors']]);
}
if (!empty($body['chrono'])) {
$originAttachment = AttachmentModel::get([
'select' => ['res_id', 'res_id_master', 'title'],
'where' => ['identifier = ? and attachment_type = ?'],
'data' => [$body['chrono'], 'response_project'],
'orderBy' => ['res_id DESC']
]);
}
if (empty($originAttachment[0]['res_id']) || empty($originAttachment[0]['res_id_master'])) {
return $response->withStatus(400)->withJson(['errors' => '[AttachmentController create] no origin found for reconcil']);
}
$body['type'] = 'signed_response';
$body['status'] = 'A_TRA';
$body['originId'] = $originAttachment[0]['res_id'];
$body['resIdMaster'] = $originAttachment[0]['res_id_master'];
$body['title'] = $originAttachment[0]['title'];
$id = StoreController::storeAttachment($body);
if (empty($id) || !empty($id['errors'])) {
return $response->withStatus(500)->withJson(['errors' => '[AttachmentController create] ' . $id['errors']]);
}
AttachmentModel::update(['set' => ['status' => 'SIGN'], 'where' => ['res_id = ?'], 'data' => [$body['originId']]]);
ConvertPdfController::convert([
'resId' => $id,
'collId' => 'attachments_coll'
]);
$customId = CoreConfigModel::getCustomId();
$customId = empty($customId) ? 'null' : $customId;
exec("php src/app/convert/scripts/FullTextScript.php --customId {$customId} --resId {$id} --collId attachments_coll --userId {$GLOBALS['id']} > /dev/null &");
HistoryController::add([
'tableName' => 'res_attachments',
'recordId' => $id,
'eventType' => 'ADD',
'info' => _ATTACHMENT_ADDED,
'moduleId' => 'attachment',
'eventId' => 'attachmentAdd'
]);
HistoryController::add([
'tableName' => 'res_letterbox',
'recordId' => $body['resIdMaster'],
'eventType' => 'ADD',
'info' => _ATTACHMENT_ADDED . " : {$body['title']}",
'moduleId' => 'attachment',
'eventId' => 'attachmentAdd'
]);
return $response->withJson(['id' => $id]);
}
public function getById(Request $request, Response $response, array $args)
{
$attachment = AttachmentModel::getById([
......
return true;
}
private static function controlReconcil(array $args)
{
$body = $args['body'];
if (empty($body)) {
return ['errors' => 'Body is not set or empty'];
} elseif (!Validator::notEmpty()->validate($body['encodedFile'])) {
return ['errors' => 'Body encodedFile is empty'];
} elseif (!Validator::stringType()->notEmpty()->validate($body['format'])) {
return ['errors' => 'Body format is empty or not a string'];
} elseif (!Validator::stringType()->notEmpty()->validate($body['chrono'])) {
return ['errors' => 'Body chrono is empty or not a string'];
}
$control = AttachmentController::controlFileData(['body' => $body]);
if (!empty($control['errors'])) {
return ['errors' => $control['errors']];
}
return true;
}
private static function controlFileData(array $args)
{
src/app/contentManagement/controllers/MergeController.php
include_once('vendor/tinybutstrong/opentbs/tbs_plugin_opentbs.php');
include_once('vendor/rafikhaceb/pi-barcode/pi_barcode.php');
require_once('apps/maarch_entreprise/tools/phpqrcode/qrlib.php');
class MergeController
{
......
public static function mergeChronoDocument(array $args)
{
ValidatorModel::stringType($args, ['path', 'content', 'chrono', 'type']);
ValidatorModel::stringType($args, ['path', 'content', 'chrono', 'type', 'resIdMaster', 'resId']);
$tbs = new \clsTinyButStrong();
$tbs->NoErr = true;
......
$args['path'] = null;
}
$barcodeFile = CoreConfigModel::getTmpPath() . mt_rand() ."_{$args['userId']}_barcode.png";
$generator = new \PiBarCode();
$barcodeFile = CoreConfigModel::getTmpPath() . mt_rand() ."_{$args['resIdMaster']}_barcode.png";
/*$generator = new \PiBarCode();
$generator->setCode($args['chrono']);
$generator->setType('C128');
$generator->setSize(30, 50);
$generator->setText($args['chrono']);
$generator->hideCodeType();
$generator->setFiletype('PNG');
$generator->writeBarcodeFile($barcodeFile);
$generator->writeBarcodeFile($barcodeFile);*/
$data = 'MAARCH_' . $args['chrono'];
//$data = 'MAARCH_' . $args['resIdMaster'] . '_' . $args['chrono'];
\QRcode::png($data, $barcodeFile, QR_ECLEVEL_L, 10);
if (!empty($args['path'])) {
if ($extension == 'odt') {
src/app/resource/controllers/StoreController.php
$uniqueId = CoreConfigModel::uniqueId();
$tmpFilename = "storeTmp_{$GLOBALS['id']}_{$uniqueId}.{$args['format']}";
file_put_contents($tmpPath . $tmpFilename, $fileContent);
$fileContent = MergeController::mergeChronoDocument(['chrono' => $data['identifier'], 'path' => $tmpPath . $tmpFilename, 'type' => 'attachment']);
//print_r($data);
$fileContent = MergeController::mergeChronoDocument(['resIdMaster' => (string) $data['res_id_master'], 'chrono' => $data['identifier'], 'path' => $tmpPath . $tmpFilename, 'type' => 'attachment']);
$fileContent = base64_decode($fileContent['encodedDocument']);
unlink($tmpPath . $tmpFilename);
}
(3-3/3)