PMCORE-2282

This commit is contained in:
Julio Cesar Laura Avendaño
2020-10-27 20:53:39 +00:00
parent 48f1088ec7
commit 7eeda4ef57
2 changed files with 46 additions and 0 deletions

View File

@@ -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']);

View File

@@ -1,8 +1,12 @@
<?php
namespace ProcessMaker\BusinessModel;
use AppSequence;
use Cases;
use Criteria;
use Illuminate\Support\Facades\DB;
use ProcessMaker\Core\System;
use ProcessMaker\Model\Application;
use ResultSet;
use WebEntryPeer;
@@ -1125,5 +1129,44 @@ class WebEntry
}
return $message;
}
/**
* Swap temporary web entry application number to a normal application number
*
* @param string $appUid
* @return int
*/
public function swapTemporaryAppNumber($appUid)
{
// Get the application
$application = Application::query()->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;
}
}
}