Projet

Général

Profil

reconcil.diff

Laurent GIOVANNONI, 14/09/2020 17:23

Voir les différences:

rest/index.php
87 87
$app->post('/attachments/{id}/mailing', \Attachment\controllers\AttachmentController::class . ':getMailingById');
88 88
$app->get('/attachmentsInformations', \Attachment\controllers\AttachmentController::class . ':getByChrono');
89 89
$app->get('/attachmentsTypes', \Attachment\controllers\AttachmentController::class . ':getAttachmentsTypes');
90
$app->post('/reconcil', \Attachment\controllers\AttachmentController::class . ':reconcil');
90 91

  
91 92
//AutoComplete
92 93
$app->get('/autocomplete/users', \SrcCore\controllers\AutoCompleteController::class . ':getUsers');
rest/index.php
87 87
$app->post('/attachments/{id}/mailing', \Attachment\controllers\AttachmentController::class . ':getMailingById');
88 88
$app->get('/attachmentsInformations', \Attachment\controllers\AttachmentController::class . ':getByChrono');
89 89
$app->get('/attachmentsTypes', \Attachment\controllers\AttachmentController::class . ':getAttachmentsTypes');
90
$app->post('/reconcil', \Attachment\controllers\AttachmentController::class . ':reconcil');
90 91

  
91 92
//AutoComplete
92 93
$app->get('/autocomplete/users', \SrcCore\controllers\AutoCompleteController::class . ':getUsers');
src/app/attachment/controllers/AttachmentController.php
84 84
        return $response->withJson(['id' => $id]);
85 85
    }
86 86

  
87
    public function reconcil(Request $request, Response $response)
88
    {
89
        $body = $request->getParsedBody();
90

  
91
        $control = AttachmentController::controlReconcil(['body' => $body]);
92
        if (!empty($control['errors'])) {
93
            return $response->withStatus(400)->withJson(['errors' => $control['errors']]);
94
        }
95

  
96
        if (!empty($body['chrono'])) {
97
            $originAttachment = AttachmentModel::get([
98
                'select'    => ['res_id', 'res_id_master', 'title'],
99
                'where'     => ['identifier = ? and attachment_type = ?'],
100
                'data'      => [$body['chrono'], 'response_project'],
101
                'orderBy'   => ['res_id DESC']
102
            ]);
103
        }
104

  
105
        if (empty($originAttachment[0]['res_id']) || empty($originAttachment[0]['res_id_master'])) {
106
            return $response->withStatus(400)->withJson(['errors' => '[AttachmentController create] no origin found for reconcil']);
107
        }
108

  
109
        $body['type'] = 'signed_response';
110
        $body['status'] = 'A_TRA';
111
        $body['originId'] = $originAttachment[0]['res_id'];
112
        $body['resIdMaster'] = $originAttachment[0]['res_id_master'];
113
        $body['title'] = $originAttachment[0]['title'];
114

  
115
        $id = StoreController::storeAttachment($body);
116
        if (empty($id) || !empty($id['errors'])) {
117
            return $response->withStatus(500)->withJson(['errors' => '[AttachmentController create] ' . $id['errors']]);
118
        }
119

  
120
        AttachmentModel::update(['set' => ['status' => 'SIGN'], 'where' => ['res_id = ?'], 'data' => [$body['originId']]]);
121

  
122
        ConvertPdfController::convert([
123
            'resId'     => $id,
124
            'collId'    => 'attachments_coll'
125
        ]);
126

  
127
        $customId = CoreConfigModel::getCustomId();
128
        $customId = empty($customId) ? 'null' : $customId;
129
        exec("php src/app/convert/scripts/FullTextScript.php --customId {$customId} --resId {$id} --collId attachments_coll --userId {$GLOBALS['id']} > /dev/null &");
130

  
131
        HistoryController::add([
132
            'tableName' => 'res_attachments',
133
            'recordId'  => $id,
134
            'eventType' => 'ADD',
135
            'info'      => _ATTACHMENT_ADDED,
136
            'moduleId'  => 'attachment',
137
            'eventId'   => 'attachmentAdd'
138
        ]);
139

  
140
        HistoryController::add([
141
            'tableName' => 'res_letterbox',
142
            'recordId'  => $body['resIdMaster'],
143
            'eventType' => 'ADD',
144
            'info'      => _ATTACHMENT_ADDED . " : {$body['title']}",
145
            'moduleId'  => 'attachment',
146
            'eventId'   => 'attachmentAdd'
147
        ]);
148

  
149
        return $response->withJson(['id' => $id]);
150
    }
151

  
87 152
    public function getById(Request $request, Response $response, array $args)
88 153
    {
89 154
        $attachment = AttachmentModel::getById([
......
895 960

  
896 961
        return true;
897 962
    }
963
    private static function controlReconcil(array $args)
964
    {
965
        $body = $args['body'];
966

  
967
        if (empty($body)) {
968
            return ['errors' => 'Body is not set or empty'];
969
        } elseif (!Validator::notEmpty()->validate($body['encodedFile'])) {
970
            return ['errors' => 'Body encodedFile is empty'];
971
        } elseif (!Validator::stringType()->notEmpty()->validate($body['format'])) {
972
            return ['errors' => 'Body format is empty or not a string'];
973
        } elseif (!Validator::stringType()->notEmpty()->validate($body['chrono'])) {
974
            return ['errors' => 'Body chrono is empty or not a string'];
975
        }
976

  
977
        $control = AttachmentController::controlFileData(['body' => $body]);
978
        if (!empty($control['errors'])) {
979
            return ['errors' => $control['errors']];
980
        }
981

  
982
        return true;
983
    }
898 984

  
899 985
    private static function controlFileData(array $args)
900 986
    {
src/app/contentManagement/controllers/MergeController.php
33 33

  
34 34
include_once('vendor/tinybutstrong/opentbs/tbs_plugin_opentbs.php');
35 35
include_once('vendor/rafikhaceb/pi-barcode/pi_barcode.php');
36

  
36
require_once('apps/maarch_entreprise/tools/phpqrcode/qrlib.php');
37 37

  
38 38
class MergeController
39 39
{
......
348 348

  
349 349
    public static function mergeChronoDocument(array $args)
350 350
    {
351
        ValidatorModel::stringType($args, ['path', 'content', 'chrono', 'type']);
351
        ValidatorModel::stringType($args, ['path', 'content', 'chrono', 'type', 'resIdMaster', 'resId']);
352 352

  
353 353
        $tbs = new \clsTinyButStrong();
354 354
        $tbs->NoErr = true;
......
363 363
            $args['path'] = null;
364 364
        }
365 365

  
366
        $barcodeFile = CoreConfigModel::getTmpPath() . mt_rand() ."_{$args['userId']}_barcode.png";
367
        $generator = new \PiBarCode();
366
        $barcodeFile = CoreConfigModel::getTmpPath() . mt_rand() ."_{$args['resIdMaster']}_barcode.png";
367
        /*$generator = new \PiBarCode();
368 368
        $generator->setCode($args['chrono']);
369 369
        $generator->setType('C128');
370 370
        $generator->setSize(30, 50);
371 371
        $generator->setText($args['chrono']);
372 372
        $generator->hideCodeType();
373 373
        $generator->setFiletype('PNG');
374
        $generator->writeBarcodeFile($barcodeFile);
374
        $generator->writeBarcodeFile($barcodeFile);*/
375

  
376
        $data = 'MAARCH_' . $args['chrono'];
377
        //$data = 'MAARCH_' . $args['resIdMaster'] . '_' . $args['chrono'];
378
        \QRcode::png($data, $barcodeFile, QR_ECLEVEL_L, 10);
375 379

  
376 380
        if (!empty($args['path'])) {
377 381
            if ($extension == 'odt') {
src/app/resource/controllers/StoreController.php
103 103
                    $uniqueId = CoreConfigModel::uniqueId();
104 104
                    $tmpFilename = "storeTmp_{$GLOBALS['id']}_{$uniqueId}.{$args['format']}";
105 105
                    file_put_contents($tmpPath . $tmpFilename, $fileContent);
106
                    $fileContent = MergeController::mergeChronoDocument(['chrono' => $data['identifier'], 'path' => $tmpPath . $tmpFilename, 'type' => 'attachment']);
106
                    //print_r($data);
107
                    $fileContent = MergeController::mergeChronoDocument(['resIdMaster' => (string) $data['res_id_master'], 'chrono' => $data['identifier'], 'path' => $tmpPath . $tmpFilename, 'type' => 'attachment']);
107 108
                    $fileContent = base64_decode($fileContent['encodedDocument']);
108 109
                    unlink($tmpPath . $tmpFilename);
109 110
                }