diff --git a/workflow/engine/methods/cases/cases_Step.php b/workflow/engine/methods/cases/cases_Step.php index ff9ceec99..78742db18 100644 --- a/workflow/engine/methods/cases/cases_Step.php +++ b/workflow/engine/methods/cases/cases_Step.php @@ -1061,6 +1061,9 @@ try { $tplFile = 'webentry/cases_ScreenDerivation'; $caseId = $currentTask['APP_UID']; $delIndex = $currentTask['DEL_INDEX']; + // Swap temporary APP_NUMBER + $newAppNumber = $bmWebEntry->swapTemporaryAppNumber($caseId); + $Fields['APP_NUMBER'] = $Fields['APP_DATA']['APP_NUMBER'] = $newAppNumber; $derivationResponse = PMFDerivateCase($caseId, $delIndex, true); if ($derivationResponse) { $webEntryUrl = $bmWebEntry->getCallbackUrlByTask($currentTask['TAS_UID']); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/WebEntry.php b/workflow/engine/src/ProcessMaker/BusinessModel/WebEntry.php index 3c86b451a..8dc69e36d 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/WebEntry.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/WebEntry.php @@ -1,8 +1,12 @@ select(['APP_NUMBER'])->where('APP_UID', '=', $appUid)->first()->toArray(); + + // If application exists, swap the number + if (!empty($application)) { + // Get a normal sequence number + $appSequence = new AppSequence(); + $appNumber = $appSequence->sequenceNumber(AppSequence::APP_TYPE_NORMAL); + + // Update case with the new application number + $cases = new Cases(); + $casesData = $cases->loadCase($appUid); + $casesData['APP_NUMBER'] = $casesData['APP_DATA']['APP_NUMBER'] = $appNumber; + $cases->updateCase($appUid, $casesData); + + // Build the query to update related tables and fields + $query = "UPDATE `APPLICATION` SET `APP_TITLE` = '#{$appNumber}' WHERE `APP_UID` = '{$appUid}';"; + $query .= "UPDATE `APP_DATA_CHANGE_LOG` SET `APP_NUMBER` = {$appNumber} WHERE `APP_NUMBER` = {$application['APP_NUMBER']};"; + $query .= "UPDATE `APP_DELEGATION` SET `APP_NUMBER` = {$appNumber} WHERE `APP_UID` = '{$appUid}';"; + $query .= "UPDATE `LIST_INBOX` SET `APP_NUMBER` = {$appNumber}, `APP_TITLE` = '#{$appNumber}' WHERE `APP_UID` = '{$appUid}';"; + $query .= "UPDATE `LIST_PARTICIPATED_HISTORY` SET `APP_NUMBER` = {$appNumber}, `APP_TITLE` = '#{$appNumber}' WHERE `APP_UID` = '{$appUid}';"; + $query .= "UPDATE `LIST_PARTICIPATED_LAST` SET `APP_NUMBER` = {$appNumber}, `APP_TITLE` = '#{$appNumber}' WHERE `APP_UID` = '{$appUid}';"; + + // Execute the query + DB::connection('workflow')->unprepared($query); + + // Return new application number + return $appNumber; + } + } }