diff --git a/apps/maarch_entreprise/indexing_searching/documents_list_mlb_search_adv.php b/apps/maarch_entreprise/indexing_searching/documents_list_mlb_search_adv.php index 5ecea6f38ddd5d1f42c7c48ec4bf5213b6f574ac..4ea767a751faf8a3d080a49f376c4a175c043780 100755 --- a/apps/maarch_entreprise/indexing_searching/documents_list_mlb_search_adv.php +++ b/apps/maarch_entreprise/indexing_searching/documents_list_mlb_search_adv.php @@ -374,6 +374,8 @@ if ($mode == 'normal') { //Result array $tabI = count($tab); + $resIdList = []; + for ($i = 0; $i < $tabI; ++$i) { $tabJ = count($tab[$i]); for ($j = 0; $j < $tabJ; ++$j) { @@ -399,6 +401,7 @@ if ($mode == 'normal') { } if ($tab[$i][$j][$value] == 'res_id') { + $resIdList[] = intval($tab[$i][$j]['value']); $tab[$i][$j]['res_id'] = $tab[$i][$j]['value']; $tab[$i][$j]['label'] = _GED_NUM; $tab[$i][$j]['size'] = '4'; @@ -792,28 +795,30 @@ if ($mode == 'normal') { // Contacts if ($tab[$i][$j][$value] == 'real_dest') { $resId = $tab[$i][$j]['value']; -// $tab[$i][$j]['value'] = \Resource\models\ResourceContactModel::getFormattedByResId2(['resId' => $resId, 'type' => 'recipients']); $contactList = \Contact\controllers\ContactController::getFormattedContacts(['resId' => $resId, 'mode' => 'recipient', 'onlyContact' => true]); $formattedRecipients = implode("<br>", $contactList); - $formattedRecipients = '<b>'._FOR_CONTACT_C.'</b>'.$formattedRecipients; - $contactList = \Contact\controllers\ContactController::getFormattedContacts(['resId' => $resId, 'mode' => 'sender', 'onlyContact' => true]); $formattedSenders = implode("<br>", $contactList); - $formattedSenders = '<b>'._TO_CONTACT_C.'</b>'.$formattedSenders; - $tab[$i][$j]['value'] = $formattedSenders . "<br>" . $formattedRecipients; + $tab[$i][$j]['value'] = ''; + + if (!empty($formattedSenders)) { + $formattedSenders = '<b>'._TO_CONTACT_C.'</b>'.$formattedSenders; + $tab[$i][$j]['value'] .= $formattedSenders; + + if (!empty($formattedRecipients)) { + $tab[$i][$j]['value'] .= "<br>"; + } + } + if (!empty($formattedRecipients)) { + $formattedRecipients = '<b>'._FOR_CONTACT_C.'</b>'.$formattedRecipients; + $tab[$i][$j]['value'] .= $formattedRecipients; + } -// if (empty(trim($tab[$i][$j]['value']))) { -// $tab[$i][$j]['value'] = null; -// } elseif ($_SESSION['mlb_search_current_category_id'] == 'outgoing') { -// $tab[$i][$j]['value'] = '<b>'._TO_CONTACT_C.'</b>'.$tab[$i][$j]['value']; -// } else { -// $tab[$i][$j]['value'] = '<b>'._FOR_CONTACT_C.'</b>'.$tab[$i][$j]['value']; -// } $tab[$i][$j]['order'] = false; } } @@ -900,8 +905,11 @@ if ($nbTab > 0) { } if ($printTool) { + $resIdList = json_encode($resIdList); + $urlPrint = $_SESSION['config']['businessappurl'] . '../../rest/resourcesList/summarySheets?resources=' . $resIdList; $print = array( - 'script' => "window.open('".$_SESSION['config']['businessappurl']."index.php?display=true&page=print', '_blank');", +// 'script' => "window.open('".$_SESSION['config']['businessappurl']."index.php?display=true&page=print', '_blank');", + 'script' => "window.open('" . $urlPrint . "', '_blank');", 'icon' => 'link', 'tooltip' => _PRINT_DOC_FROM_LIST, 'disabledRules' => $nbTab.' == 0', diff --git a/apps/maarch_entreprise/xml/export.xml b/apps/maarch_entreprise/xml/export.xml index 26968e689709c4d63ae0f35363d9e85d04ea28b7..d1b67bddd8038d21f2e8e0963baea68ee0fc917d 100755 --- a/apps/maarch_entreprise/xml/export.xml +++ b/apps/maarch_entreprise/xml/export.xml @@ -20,18 +20,18 @@ <LIBELLE>Date d'arrivée</LIBELLE> <DATABASE_FIELD>doc_date</DATABASE_FIELD> </FIELD> - <FIELD> - <LIBELLE>Prénom de l'expéditeur</LIBELLE> - <DATABASE_FIELD>contact_firstname</DATABASE_FIELD> - </FIELD> - <FIELD> - <LIBELLE>Nom de l'expéditeur</LIBELLE> - <DATABASE_FIELD>contact_lastname</DATABASE_FIELD> - </FIELD> - <FIELD> - <LIBELLE>Société de l'expéditeur</LIBELLE> - <DATABASE_FIELD>contact_society</DATABASE_FIELD> - </FIELD> +<!-- <FIELD>--> +<!-- <LIBELLE>Prénom de l'expéditeur</LIBELLE>--> +<!-- <DATABASE_FIELD>contact_firstname</DATABASE_FIELD>--> +<!-- </FIELD>--> +<!-- <FIELD>--> +<!-- <LIBELLE>Nom de l'expéditeur</LIBELLE>--> +<!-- <DATABASE_FIELD>contact_lastname</DATABASE_FIELD>--> +<!-- </FIELD>--> +<!-- <FIELD>--> +<!-- <LIBELLE>Société de l'expéditeur</LIBELLE>--> +<!-- <DATABASE_FIELD>contact_society</DATABASE_FIELD>--> +<!-- </FIELD>--> <FIELD> <LIBELLE>Service destinataire</LIBELLE> <DATABASE_FIELD>destination</DATABASE_FIELD> @@ -61,10 +61,10 @@ <LIBELLE>Services en copie</LIBELLE> <CALL>retrieve_copies</CALL> </FUNCTION> - <FUNCTION> - <LIBELLE>Page détail</LIBELLE> - <CALL>makeLink_detail</CALL> - </FUNCTION> +<!-- <FUNCTION>--> +<!-- <LIBELLE>Page détail</LIBELLE>--> +<!-- <CALL>makeLink_detail</CALL>--> +<!-- </FUNCTION>--> <!-- <FUNCTION> <LIBELLE>Thème</LIBELLE> diff --git a/core/class/ExportControler.php b/core/class/ExportControler.php index 46679dd4d0bb303d1640fe06b3f8e650bf95c7a1..44a215c345ad2ed3eb8b22b3a2ce3dd3c62be3c0 100755 --- a/core/class/ExportControler.php +++ b/core/class/ExportControler.php @@ -274,8 +274,8 @@ class ExportFunctions $collection = $this->collection; - $query = 'SELECT item_id, ue.entity_id FROM listinstance l LEFT JOIN users_entities ue on l.item_id = ue.user_id WHERE l.res_id = ? AND l.coll_id = ? AND l.item_mode = ?'; - $stmt = $db->query($query, array($res_id, $this->collection, 'cc')); + $query = 'SELECT item_id, ue.entity_id FROM listinstance l LEFT JOIN users_entities ue on l.item_id = ue.user_id WHERE l.res_id = ? AND l.item_mode = ?'; + $stmt = $db->query($query, array($res_id, 'cc')); $arr_copy = []; while ($result = $stmt->fetchObject()) { diff --git a/rest/index.php b/rest/index.php index 763aac0e415639918cafb0389b042465da7750cd..1d89396000df20f37cbc76f02ae298606df3d07a 100755 --- a/rest/index.php +++ b/rest/index.php @@ -348,6 +348,7 @@ $app->put('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/exp $app->post('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/summarySheets', \Resource\controllers\SummarySheetController::class . ':createList'); $app->put('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/actions/{actionId}', \Resource\controllers\ResourceListController::class . ':setAction'); $app->get('/resourcesList/exportTemplate', \Resource\controllers\ExportController::class . ':getExportTemplates'); +$app->get('/resourcesList/summarySheets', \Resource\controllers\SummarySheetController::class . ':createListWithAll'); $app->post('/acknowledgementReceipt', \AcknowledgementReceipt\controllers\AcknowledgementReceiptController::class . ':createPaperAcknowledgement'); //PreProcess $app->post('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/checkAcknowledgementReceipt', \Action\controllers\PreProcessActionController::class . ':checkAcknowledgementReceipt'); diff --git a/src/app/resource/controllers/SummarySheetController.php b/src/app/resource/controllers/SummarySheetController.php index d5f668722d4166025ad94e5024a81df50b6356d2..c33cc8cc616faacb1762e18ac11b1a87bec4a356 100755 --- a/src/app/resource/controllers/SummarySheetController.php +++ b/src/app/resource/controllers/SummarySheetController.php @@ -103,49 +103,120 @@ class SummarySheetController $pdf = new Fpdi('P', 'pt'); $pdf->setPrintHeader(false); - $tmpIds = []; + $resourcesIds = array_column($resources, 'res_id'); + + // Data for resources + $data = SummarySheetController::prepareData(['units' => $units, 'resourcesIds' => $resourcesIds]); + foreach ($resources as $resource) { - $tmpIds[] = $resource['res_id']; + SummarySheetController::createSummarySheet($pdf, ['resource' => $resource, 'units' => $units, 'login' => $GLOBALS['userId'], 'data' => $data]); } - // Data for resources - $data = []; - foreach ($units as $unit) { - if ($unit['unit'] == 'notes') { - $data['notes'] = NoteModel::get([ - 'select' => ['id', 'note_text', 'user_id', 'creation_date', 'identifier'], - 'where' => ['identifier in (?)'], - 'data' => [$tmpIds], - 'order_by' => ['identifier']]); + $fileContent = $pdf->Output('', 'S'); + $finfo = new \finfo(FILEINFO_MIME_TYPE); + $mimeType = $finfo->buffer($fileContent); - $userEntities = EntityModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['entity_id']]); - $data['userEntities'] = []; - foreach ($userEntities as $userEntity) { - $data['userEntities'][] = $userEntity['entity_id']; - } - } elseif ($unit['unit'] == 'opinionWorkflow') { - $data['listInstancesOpinion'] = ListInstanceModel::get([ - 'select' => ['item_id', 'process_date', 'res_id'], - 'where' => ['difflist_type = ?', 'res_id in (?)'], - 'data' => ['AVIS_CIRCUIT', $tmpIds], - 'orderBy' => ['listinstance_id'] - ]); - } elseif ($unit['unit'] == 'visaWorkflow') { - $data['listInstancesVisa'] = ListInstanceModel::get([ - 'select' => ['item_id', 'requested_signature', 'process_date', 'res_id'], - 'where' => ['difflist_type = ?', 'res_id in (?)'], - 'data' => ['VISA_CIRCUIT', $tmpIds], - 'orderBy' => ['listinstance_id'] - ]); - } elseif ($unit['unit'] == 'diffusionList') { - $data['listInstances'] = ListInstanceModel::get([ - 'select' => ['item_id', 'item_type', 'item_mode', 'res_id'], - 'where' => ['difflist_type = ?', 'res_id in (?)'], - 'data' => ['entity_id', $tmpIds], - 'orderBy' => ['listinstance_id'] - ]); + $response->write($fileContent); + $response = $response->withAddedHeader('Content-Disposition', "inline; filename=maarch.pdf"); + + return $response->withHeader('Content-Type', $mimeType); + } + + public function createListWithAll(Request $request, Response $response) + { + set_time_limit(240); + + $bodyData = $request->getQueryParams(); + $units = [ + [ + "unit" => "qrcode", + "label" => "" + ], + [ + "unit" => "primaryInformations", + "label" => "Informations pricipales" + ], + [ + "unit" => "senderRecipientInformations", + "label" => "Informations de destination" + ], + [ + "unit" => "secondaryInformations", + "label" => "Informations secondaires" + ], + [ + "unit" => "diffusionList", + "label" => "Liste de diffusion" + ], + [ + "unit" => "opinionWorkflow", + "label" => "Circuit d'avis" + ], + [ + "unit" => "visaWorkflow", + "label" => "Circuit de visa" + ], + [ + "unit" => "notes", + "label" => "Annotation(s)" + ] + ]; + + $resourcesData = json_decode($bodyData['resources']); + + if (!Validator::arrayType()->notEmpty()->validate($resourcesData)) { + return $response->withStatus(403)->withJson(['errors' => 'Resources is not set or empty']); + } + + $resourcesData = array_slice($resourcesData, 0, 500); + + $rawResourcesInBasket = ResModel::getOnView([ + 'select' => ['res_id'], + 'where' => ['res_view_letterbox.res_id in (?)'], + 'data' => [$resourcesData] + ]); + $allResourcesInBasket = array_column($rawResourcesInBasket, 'res_id'); + + $order = 'CASE res_view_letterbox.res_id '; + foreach ($resourcesData as $key => $resId) { + if (!in_array($resId, $allResourcesInBasket)) { + return $response->withStatus(403)->withJson(['errors' => 'Resources out of perimeter']); } + $order .= "WHEN {$resId} THEN {$key} "; } + $order .= 'END'; + + $select = [ + 'res_id', + 'subject', + 'alt_identifier', + 'admission_date', + 'creation_date', + 'doc_date', + 'type_label', + 'initiator', + 'typist', + 'category_id', + 'priority', + 'process_limit_date', + 'status', + 'destination' + ]; + + $resources = ResModel::getOnView([ + 'select' => $select, + 'where' => ['res_view_letterbox.res_id in (?)'], + 'data' => [$resourcesData], + 'orderBy' => [$order] + ]); + + $pdf = new Fpdi('P', 'pt'); + $pdf->setPrintHeader(false); + + $resourcesIds = array_column($resources, 'res_id'); + + // Data for resources + $data = SummarySheetController::prepareData(['units' => $units, 'resourcesIds' => $resourcesIds]); foreach ($resources as $resource) { SummarySheetController::createSummarySheet($pdf, ['resource' => $resource, 'units' => $units, 'login' => $GLOBALS['userId'], 'data' => $data]); @@ -510,4 +581,50 @@ class SummarySheetController } } } + + private static function prepareData(array $args) + { + $units = $args['units']; + $tmpIds = $args['resourcesIds']; + + $data = []; + foreach ($units as $unit) { + if ($unit['unit'] == 'notes') { + $data['notes'] = NoteModel::get([ + 'select' => ['id', 'note_text', 'user_id', 'creation_date', 'identifier'], + 'where' => ['identifier in (?)'], + 'data' => [$tmpIds], + 'order_by' => ['identifier']]); + + $userEntities = EntityModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['entity_id']]); + $data['userEntities'] = []; + foreach ($userEntities as $userEntity) { + $data['userEntities'][] = $userEntity['entity_id']; + } + } elseif ($unit['unit'] == 'opinionWorkflow') { + $data['listInstancesOpinion'] = ListInstanceModel::get([ + 'select' => ['item_id', 'process_date', 'res_id'], + 'where' => ['difflist_type = ?', 'res_id in (?)'], + 'data' => ['AVIS_CIRCUIT', $tmpIds], + 'orderBy' => ['listinstance_id'] + ]); + } elseif ($unit['unit'] == 'visaWorkflow') { + $data['listInstancesVisa'] = ListInstanceModel::get([ + 'select' => ['item_id', 'requested_signature', 'process_date', 'res_id'], + 'where' => ['difflist_type = ?', 'res_id in (?)'], + 'data' => ['VISA_CIRCUIT', $tmpIds], + 'orderBy' => ['listinstance_id'] + ]); + } elseif ($unit['unit'] == 'diffusionList') { + $data['listInstances'] = ListInstanceModel::get([ + 'select' => ['item_id', 'item_type', 'item_mode', 'res_id'], + 'where' => ['difflist_type = ?', 'res_id in (?)'], + 'data' => ['entity_id', $tmpIds], + 'orderBy' => ['listinstance_id'] + ]); + } + } + + return $data; + } }