mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-23 06:24:03 +00:00
130 lines
5.4 KiB
PHP
130 lines
5.4 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Questionnaires\Processors;
|
|
|
|
|
|
use App\Classes\Modules\Questionnaires\Services\FetchesQuestion;
|
|
use App\Classes\Modules\Questionnaires\Services\ListsQuestions;
|
|
use Illuminate\Http\Request;
|
|
use App\Classes\ValueObjects\Constants\QAType;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class FetchNextQuestionV1AdminWFProcessor
|
|
{
|
|
/** @var FetchesQuestion */
|
|
private $fetchesQuestion;
|
|
|
|
/** @var ListsQuestions */
|
|
private $listsQuestions;
|
|
|
|
/**
|
|
* FetchNextQuestionV1AdminWFProcessor constructor.
|
|
* @param FetchesQuestion $fetchesQuestion
|
|
* @param ListsQuestions $listsQuestions
|
|
*/
|
|
public function __construct(FetchesQuestion $fetchesQuestion, ListsQuestions $listsQuestions)
|
|
{
|
|
$this->fetchesQuestion = $fetchesQuestion;
|
|
$this->listsQuestions = $listsQuestions;
|
|
}
|
|
|
|
public function execute(Request $request, $previousAnswer){
|
|
$isEnd = 0;
|
|
$questionId = 0;
|
|
$nextQuestionNumber = "";
|
|
$nextNestedQuestion = "";
|
|
$nextMainQuestion= "";
|
|
$questionnaireSetId = 0;
|
|
$currentQuestion = $request->question;
|
|
$questionType = QAType::DEFAULT;
|
|
$returnQuestion = null;
|
|
|
|
if ($currentQuestion && array_key_exists('id', $currentQuestion)) {
|
|
$questionId = $currentQuestion['id'];
|
|
$isEnd = $currentQuestion['is_end'];
|
|
$questionType = $currentQuestion['question_type'];
|
|
$nextNestedQuestion = $currentQuestion['next_nested_question'];
|
|
$nextMainQuestion = $currentQuestion['next_main_question'];
|
|
$questionnaireSetId = $currentQuestion['questionnaire_set_id'];
|
|
}
|
|
|
|
if ($request->has('answerObj') && $request->answerObj['next_question_number']) {
|
|
$nextQuestionNumber = $request->answerObj['next_question_number'];
|
|
}
|
|
|
|
if ($request->has('isPrevious')) {
|
|
if($previousAnswer)
|
|
{
|
|
$previousAnswer->delete();
|
|
}
|
|
else{
|
|
return null;
|
|
}
|
|
|
|
Log::info("Previous Answer question id: ".$previousAnswer['question_id']);
|
|
|
|
//Get previous question
|
|
$previousQuestion = $this->fetchesQuestion->execute(['questionnaire_set_id' => $questionnaireSetId, 'id' => $previousAnswer['question_id']]);
|
|
$returnQuestion = $previousQuestion;
|
|
}
|
|
else{
|
|
//Get next question
|
|
$nextQuestion = null;
|
|
$question_number = "";
|
|
if($nextQuestionNumber !== ""){
|
|
$question_number = $nextQuestionNumber;
|
|
}
|
|
else if($nextNestedQuestion !== ""){
|
|
$question_number = $nextNestedQuestion;
|
|
}
|
|
else {
|
|
$question_number = $nextMainQuestion;
|
|
}
|
|
|
|
if($question_number !== ""){
|
|
//Check if question exists
|
|
$questions = $this->listsQuestions->execute(['questionnaire_set_id' => $questionnaireSetId, 'question_number' => $question_number]);
|
|
|
|
if($previousAnswer['answer'] === '1688_underpaid_overpaid' && count($questions) == 0){
|
|
$extra = $request->extra;
|
|
$questionMetadata = $extra['questionMetadata'] ?? null;
|
|
$processed = round((floatval($questionMetadata['amount_processed']) + PHP_FLOAT_EPSILON) * 1000) / 1000;
|
|
$amount = round((floatval($questionMetadata['amount']) + PHP_FLOAT_EPSILON) * 1000) / 1000;
|
|
|
|
//1688_underpaid_order_1, 1688_underpaid_order_2,1688_overpaid_order
|
|
if ($processed === $amount) {
|
|
Log::info('The amounts are exactly the same:', [
|
|
'amount_processed' => $questionMetadata['amount_processed'],
|
|
'amount' => $questionMetadata['amount']
|
|
]);
|
|
$question_number = '1688_underpaid_order_1';
|
|
} elseif ($processed < $amount) {
|
|
Log::info('The processed amount is under the expected amount:', [
|
|
'amount_processed' => $questionMetadata['amount_processed'],
|
|
'amount' => $questionMetadata['amount']
|
|
]);
|
|
$question_number = '1688_underpaid_order_2';
|
|
} else {
|
|
Log::info('The processed amount is over the expected amount:', [
|
|
'amount_processed' => $questionMetadata['amount_processed'],
|
|
'amount' => $questionMetadata['amount']
|
|
]);
|
|
$question_number = '1688_overpaid_order';
|
|
}
|
|
}
|
|
|
|
$nextQuestion = $this->fetchesQuestion->execute(['questionnaire_set_id' => $questionnaireSetId, 'question_number' => $question_number]);
|
|
$returnQuestion = $nextQuestion;
|
|
}
|
|
//cief todo: 74
|
|
else if (array_key_exists('id', $request->input('question'))) {
|
|
dd('cbal todo');
|
|
$nextQuestion = $this->fetchesQuestion->execute(['questionnaire_set_id' => $questionnaireSetId, 'id_next' => $questionId, 'next_main_question' => null]);
|
|
$returnQuestion = $nextQuestion;
|
|
}
|
|
}
|
|
|
|
return $returnQuestion;
|
|
}
|
|
} |