Skip to content
Snippets Groups Projects
Commit c34c7776 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #12510 TIME 3:00 working export and summary sheet in search result list

parent 1b40b8ce
No related branches found
No related tags found
No related merge requests found
......@@ -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',
......
......@@ -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>
......
......@@ -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()) {
......
......@@ -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');
......
......@@ -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;
}
}
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