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

FEAT #9107 info preprocess shipping

parent ea04534f
No related branches found
No related tags found
No related merge requests found
...@@ -34,6 +34,7 @@ use SrcCore\models\DatabaseModel; ...@@ -34,6 +34,7 @@ use SrcCore\models\DatabaseModel;
use Template\models\TemplateModel; use Template\models\TemplateModel;
use User\models\UserEntityModel; use User\models\UserEntityModel;
use User\models\UserModel; use User\models\UserModel;
//use setasign\Fpdi\Tcpdf\Fpdi;
class PreProcessActionController class PreProcessActionController
{ {
...@@ -334,10 +335,10 @@ class PreProcessActionController ...@@ -334,10 +335,10 @@ class PreProcessActionController
{ {
$currentUser = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]); $currentUser = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$errors = ResourceListController::listControl(['groupId' => $aArgs['groupId'], 'userId' => $aArgs['userId'], 'basketId' => $aArgs['basketId'], 'currentUserId' => $currentUser['id']]); // $errors = ResourceListController::listControl(['groupId' => $aArgs['groupId'], 'userId' => $aArgs['userId'], 'basketId' => $aArgs['basketId'], 'currentUserId' => $currentUser['id']]);
if (!empty($errors['errors'])) { // if (!empty($errors['errors'])) {
return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]); // return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]);
} // }
$data = $request->getParsedBody(); $data = $request->getParsedBody();
...@@ -356,12 +357,15 @@ class PreProcessActionController ...@@ -356,12 +357,15 @@ class PreProcessActionController
'data' => [$data['resources']] 'data' => [$data['resources']]
]); ]);
$entities = []; $aTemplates = [];
$entities = [];
$resources = [];
$canNotSend = [];
foreach ($aDestination as $values) { foreach ($aDestination as $values) {
$entities[] = $values['destination']; $entities[] = $values['destination'];
} }
$aTemplates = [];
if (!empty($entities)) { if (!empty($entities)) {
$aEntities = EntityModel::get(['select' => ['id'], 'where' => ['entity_id in (?)'], 'data' => $entities]); $aEntities = EntityModel::get(['select' => ['id'], 'where' => ['entity_id in (?)'], 'data' => $entities]);
...@@ -383,37 +387,39 @@ class PreProcessActionController ...@@ -383,37 +387,39 @@ class PreProcessActionController
} }
} }
$aAttachments = AttachmentModel::getAttachmentToSend(['ids' => $data['resources']]); if (!empty($aTemplates)) {
$aAttachments = AttachmentModel::getAttachmentToSend(['ids' => $data['resources']]);
$resources = []; foreach ($data['resources'] as $valueResId) {
$canNotSend = []; $resIdFound = false;
foreach ($aAttachments as $key => $attachment) {
foreach ($data['resources'] as $valueResId) { if ($attachment['res_id_master'] == $valueResId) {
$resIdFound = false; // TODO Check Contact;
foreach ($aAttachments as $key => $attachment) { $resources[$valueResId][] = $attachment;
if ($attachment['res_id_master'] == $valueResId) { $resIdFound = true;
// TODO Check Contact; unset($aAttachments[$key]);
$resources[$valueResId][] = $attachment; break;
$resIdFound = true; }
unset($aAttachments[$key]); }
break; if (!$resIdFound) {
$resInfo = ResModel::getExtById(['select' => ['alt_identifier'], 'resId' => $valueResId]);
$canNotSend[] = [$valueResId, $resInfo['alt_identifier'], 'Not attachment to send'];
} }
} }
if (!$resIdFound) {
$resInfo = ResModel::getExtById(['select' => ['alt_identifier'], 'resId' => $valueResId]); foreach ($aTemplates as $key => $value) {
$canNotSend[$valueResId] = [$resInfo['alt_identifier'], 'Not attachment to send']; $infoFee = $value['fee'];
PreProcessActionController::calculFee([
'fee' => $infoFee,
'resources' => $resources
]);
} }
} }
// TODO calcul fee
$fee = 0;
return $response->withJson([ return $response->withJson([
'shippingTemplates' => $aTemplates, 'shippingTemplates' => $aTemplates,
'entities' => $entities, 'entities' => $entities,
'resources' => $resources, 'resources' => $resources,
'canNotSend' => $canNotSend, 'canNotSend' => $canNotSend
'fee' => $fee
]); ]);
} }
...@@ -439,4 +445,26 @@ class PreProcessActionController ...@@ -439,4 +445,26 @@ class PreProcessActionController
return $response->withJson(['isDestinationChanging' => $changeDestination]); return $response->withJson(['isDestinationChanging' => $changeDestination]);
} }
public static function calculFee(array $aArgs)
{
foreach ($aArgs['resources'] as $value) {
$realId = 0;
if ($value['res_id'] == 0) {
$realId = $value['res_id_version'];
$isVersion = true;
} elseif ($value['res_id_version'] == 0) {
$realId = $value['res_id'];
$isVersion = false;
}
$convertedAttachment = ConvertPdfController::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $value['res_id'], 'collId' => 'attachments_coll', 'isVersion' => $isVersion]);
$docserver = DocserverModel::getByDocserverId(['docserverId' => $convertedAttachment['docserver_id'], 'select' => ['path_template']]);
$pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $convertedAttachment['path']) . $convertedAttachment['filename'];
$pdf = new Fpdi('P', 'pt');
$pageCount = $pdf->setSourceFile($pathToDocument);
}
return $fee;
}
} }
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