mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-31 10:24:00 +00:00
Admin Workflow - Fix Tested Issues - overpaid, underpaid business logic
This commit is contained in:
+53
-10
@@ -4,29 +4,37 @@ 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)
|
||||
public function __construct(FetchesQuestion $fetchesQuestion, ListsQuestions $listsQuestions)
|
||||
{
|
||||
$this->fetchesQuestion = $fetchesQuestion;
|
||||
$this->listsQuestions = $listsQuestions;
|
||||
}
|
||||
|
||||
public function execute(Request $request, $previousAnswer){
|
||||
public function execute(Request $request, $previousAnswer){
|
||||
$isEnd = 0;
|
||||
$questionId = 0;
|
||||
$nextQuestionNumber = 0;
|
||||
$nextNestedQuestion = 0;
|
||||
$nextMainQuestion= 0;
|
||||
$nextQuestionNumber = "";
|
||||
$nextNestedQuestion = "";
|
||||
$nextMainQuestion= "";
|
||||
$questionnaireSetId = 0;
|
||||
$currentQuestion = $request->question;
|
||||
$questionType = QAType::DEFAULT;
|
||||
@@ -54,6 +62,8 @@ class FetchNextQuestionV1AdminWFProcessor
|
||||
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;
|
||||
@@ -61,22 +71,55 @@ class FetchNextQuestionV1AdminWFProcessor
|
||||
else{
|
||||
//Get next question
|
||||
$nextQuestion = null;
|
||||
$question_number = 0;
|
||||
if($nextQuestionNumber !== 0){
|
||||
$question_number = "";
|
||||
if($nextQuestionNumber !== ""){
|
||||
$question_number = $nextQuestionNumber;
|
||||
}
|
||||
else if($nextNestedQuestion !== 0){
|
||||
else if($nextNestedQuestion !== ""){
|
||||
$question_number = $nextNestedQuestion;
|
||||
}
|
||||
else {
|
||||
$question_number = $nextMainQuestion;
|
||||
}
|
||||
|
||||
if($question_number !== 0){
|
||||
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;
|
||||
}
|
||||
@@ -84,4 +127,4 @@ class FetchNextQuestionV1AdminWFProcessor
|
||||
|
||||
return $returnQuestion;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user