Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions ProcessMaker/Models/CaseNumber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace ProcessMaker\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
* Class to generate a case number.
*
* For example to generate a unique id for a process request that is a parent process
* and non system. E.g.
*
* $sequence = CaseNumber::generate($request->id);
*/
class CaseNumber extends Model
{
use HasFactory;

protected $fillable = ['process_request_id'];

/**
* Generate a unique sequence for a given name.
*
* @param int|string $id of the request
* @return int The next value in the sequence.
*/
public static function generate($requestId): int
{
// Create a new sequence with the given name
$sequence = self::create(['process_request_id' => $requestId]);

// Return the id of the sequence as the next value in the sequence
return $sequence->id;
}
}
13 changes: 13 additions & 0 deletions ProcessMaker/Models/ProcessRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* @property string $participant_id
* @property string $name
* @property string $case_title
* @property int $case_number
* @property string $status
* @property array $data
* @property string $collaboration_uuid
Expand All @@ -61,6 +62,7 @@
* @OA\Property(property="status", type="string", enum={"ACTIVE", "COMPLETED", "ERROR", "CANCELED"}),
* @OA\Property(property="name", type="string"),
* @OA\Property(property="case_title", type="string"),
* @OA\Property(property="case_number", type="integer"),
* @OA\Property(property="process_id", type="integer"),
* @OA\Property(property="process", type="object"),
* ),
Expand Down Expand Up @@ -934,4 +936,15 @@ public function evaluateCaseTitle(array $data): string
$mustache = new MustacheExpressionEvaluator();
return $mustache->render($mustacheTitle, $data);
}

public function isSystem()
{
$systemCategories = ProcessCategory::where('is_system', true)->pluck('id');
return DB::table('category_assignments')
->where('assignable_type', Process::class)
->where('assignable_id', $this->process_id)
->where('category_type', ProcessCategory::class)
->whereIn('category_id', $systemCategories)
->exists();
}
}
1 change: 1 addition & 0 deletions ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ private function serializeState(ProcessRequest $instance)

return [
'id' => $request->uuid,
'request_id' => $request->getKey(),
'process_version_id' => $request->process_version_id,
'callable_id' => $request->callable_id,
'collaboration_uuid' => $request->collaboration_uuid,
Expand Down
3 changes: 3 additions & 0 deletions ProcessMaker/Nayra/Repositories/Deserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ public function unserializeInstance(array $serialized): ExecutionInstanceInterfa
// Set process request properties
$properties = array_merge($instance->getProperties(), $properties);
$instance->setProperties($properties);
if (isset($properties['parent_request_id'])) {
$instance->parent_request_id = $properties['parent_request_id'];
}

// Set request data
if (!empty($serialized['data']) && is_array($serialized['data'])) {
Expand Down
39 changes: 38 additions & 1 deletion ProcessMaker/Observers/ProcessRequestObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ProcessMaker\Events\RequestAction;
use ProcessMaker\Events\RequestError;
use ProcessMaker\Models\CaseNumber;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\ProcessRequestToken;
use ProcessMaker\Models\ScheduledTask;
Expand Down Expand Up @@ -64,7 +65,43 @@ public function saving(ProcessRequest $request)
// When data is updated we update the case_title
if ($request->isDirty('data')) {
$data = $request->data;
$request->case_title = $request->evaluateCaseTitle($data);
// If request is a parent process, inherit the case title to the child requests
if (!$request->parent_request_id) {
$request->case_title = $request->evaluateCaseTitle($data);
// Copy the case title to the child requests
if (!empty($request->id)) {
ProcessRequest::where('parent_request_id', $request->id)
->update(['case_title' => $request->case_title]);
}
} else {
// If request is a subprocess, inherit the case title from the parent
$request->case_title = ProcessRequest::whereId($request->parent_request_id)
->select('case_title')
->first()
->case_title;
}
}
}

public function created(ProcessRequest $request)
{
// If request is System, don't generate a case number
if ($request->isSystem()) {
return;
}
// If request is a subprocess, inherit the case number from the parent
if ($request->parent_request_id) {
$request->case_number = ProcessRequest::whereId($request->parent_request_id)
->select('case_number')
->first()
->case_number;

$request->save();

return;
}
// If request is not a subprocess and not a system process, generate a case number
$request->case_number = CaseNumber::generate($request->id);
$request->save();
}
}
6 changes: 6 additions & 0 deletions ProcessMaker/Repositories/ExecutionInstanceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ public function persistInstanceCreated(ExecutionInstanceInterface $instance)
return;
}

// Check if
$parent = $data['_parent'] ?? null;
if (!empty($parent) && is_numeric($parent['request_id'])) {
$instance->parent_request_id = $parent['request_id'];
}

// Save process request
$instance->callable_id = $process->getId();
$instance->collaboration_uuid = $instance->getProperty('collaboration_uuid', null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('case_numbers', function (Blueprint $table) {
$table->id();
$table->unsignedInteger('process_request_id')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('case_numbers');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('process_requests', function (Blueprint $table) {
$table->unsignedInteger('case_number')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('process_requests', function (Blueprint $table) {
$table->dropColumn('case_number');
});
}
};
20 changes: 19 additions & 1 deletion resources/js/requests/components/RequestsListing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
#{{ props.rowData.id }}
</b-link>
</template>
<template
slot="case_number"
slot-scope="props"
>
<b-link
class="text-nowrap"
:href="openRequest(props.rowData, props.rowIndex)"
>
#{{ props.rowData.case_number }}
</b-link>
</template>
<template
slot="name"
slot-scope="props"
Expand Down Expand Up @@ -157,7 +168,7 @@ export default {
field.name = "__slot:name";
break;
default:
field.name = column.field;
field.name = column.name || column.field;
}

if (!field.field) {
Expand Down Expand Up @@ -200,6 +211,13 @@ export default {
sortable: true,
default: true,
},
{
label: "Case #",
field: "case_number",
name: "__slot:case_number",
sortable: true,
default: true,
},
{
label: "Case Title",
field: "case_title",
Expand Down