diff --git a/database/factories/AppNotesFactory.php b/database/factories/AppNotesFactory.php index 0f6cdd446..c034a285e 100644 --- a/database/factories/AppNotesFactory.php +++ b/database/factories/AppNotesFactory.php @@ -5,6 +5,7 @@ use Faker\Generator as Faker; $factory->define(\ProcessMaker\Model\AppNotes::class, function (Faker $faker) { return [ 'APP_UID' => G::generateUniqueID(), + 'APP_NUMBER' => $faker->unique()->numberBetween(5000), 'USR_UID' => G::generateUniqueID(), 'NOTE_DATE' => $faker->dateTime(), 'NOTE_CONTENT' => $faker->sentence(3), @@ -26,6 +27,7 @@ $factory->state(\ProcessMaker\Model\AppNotes::class, 'foreign_keys', function (F // Return with default values return [ 'APP_UID' => $application->APP_UID, + 'APP_NUMBER' => $application->APP_NUMBER, 'USR_UID' => $user->USR_UID, 'NOTE_DATE' => $faker->dateTime(), 'NOTE_CONTENT' => $faker->sentence(3), diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/AppNotesTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/AppNotesTest.php index cf5fa88c0..9c0f1fd0b 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/AppNotesTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/AppNotesTest.php @@ -16,32 +16,71 @@ class AppNotesTest extends TestCase { use DatabaseTransactions; + /** + * Create notes + * + * @param int + * + * @return array + */ + public function createCaseNotes($rows = 10) + { + $application = factory(Application::class)->create(); + $notes = factory(AppNotes::class, $rows)->states('foreign_keys')->create([ + 'APP_UID' => $application->APP_UID, + 'APP_NUMBER' => $application->APP_NUMBER + ]); + + return $notes; + } + /** * Review get cases notes related to the case * + * @covers \ProcessMaker\Model\AppNotes::getNotes() * @test */ public function it_test_get_case_notes() { - $appNotes = factory(AppNotes::class)->states('foreign_keys')->create(); + // Create factories + $cases = $this->createCaseNotes(); + // Create an instance $notes = new AppNotes(); - $res = $notes->getNotes($appNotes->APP_UID); + $res = $notes->getNotes($cases[0]['APP_UID']); $this->assertNotEmpty($res); } /** * Review get total cases notes by cases * + * @covers \ProcessMaker\Model\AppNotes::getTotal() + * @covers \ProcessMaker\Model\AppNotes::scopeAppUid() * @test */ public function it_test_get_total_case_notes() { - $application = factory(Application::class)->create(); - $appNotes = factory(AppNotes::class, 10)->states('foreign_keys')->create([ - 'APP_UID' => $application->APP_UID - ]); + // Create factories + $cases = $this->createCaseNotes(); + // Create an instance $notes = new AppNotes(); - $total = $notes->getTotal($application->APP_UID); + $total = $notes::getTotal($cases[0]['APP_UID']); + $this->assertEquals(10, $total); + } + + /** + * Review get total cases notes by cases + * + * @covers \ProcessMaker\Model\AppNotes::total() + * @covers \ProcessMaker\Model\AppNotes::scopeAppNumber() + * @test + */ + public function it_test_count_case_notes() + { + // Create factories + $cases = $this->createCaseNotes(); + // Create an instance + $notes = new AppNotes(); + $total = $notes::total($cases[0]['APP_NUMBER']); $this->assertEquals(10, $total); } } \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php index e39ad6519..5462ad727 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php @@ -2,6 +2,7 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\Model; +use G; use Illuminate\Foundation\Testing\DatabaseTransactions; use ProcessMaker\Model\Application; use ProcessMaker\Model\Process; @@ -49,6 +50,18 @@ class ApplicationTest extends TestCase $this->assertInstanceOf(User::class, $application->creatoruser); } + /** + * This checks if return the columns used + * + * @covers \ProcessMaker\Model\Application::scopeStatusId() + * @test + */ + public function it_return_cases_by_status_id() + { + $table = factory(Application::class)->create(); + $this->assertCount(1, $table->statusId($table->APP_STATUS_ID)->get()); + } + /** * This checks if return the columns used * @@ -81,6 +94,24 @@ class ApplicationTest extends TestCase $this->assertArrayHasKey('APP_INIT_USER', $result); } + /** + * This review if get the case number + * + * @covers \ProcessMaker\Model\Application::getCaseNumber() + * @test + */ + public function it_get_case_number() + { + $application = factory(Application::class)->create(); + $result = Application::getCaseNumber($application->APP_UID); + // When the application exist + $this->assertEquals($result, $application->APP_NUMBER); + // When the application does not exist + $appFake = G::generateUniqueID(); + $result = Application::getCaseNumber($appFake); + $this->assertEquals($result, 0); + } + /** * This checks if the columns was updated correctly * @@ -110,4 +141,20 @@ class ApplicationTest extends TestCase $this->assertArrayHasKey('APP_CUR_USER', $result); } + /** + * Count cases per process + * + * @covers \ProcessMaker\Model\Application::getCountByProUid() + * @covers \ProcessMaker\Model\Application::scopeProUid() + * @covers \ProcessMaker\Model\Application::scopeStatusId() + * @covers \ProcessMaker\Model\Application::scopePositivesCases() + * @test + */ + public function it_count_cases_by_process() + { + $process = factory(Process::class)->create(); + factory(Application::class, 5)->create(['PRO_UID' => $process->PRO_UID]); + $result = Application::getCountByProUid($process->PRO_UID); + $this->assertEquals($result, 5); + } } diff --git a/workflow/engine/classes/WorkspaceTools.php b/workflow/engine/classes/WorkspaceTools.php index 17f07b6f4..548f4dcf1 100644 --- a/workflow/engine/classes/WorkspaceTools.php +++ b/workflow/engine/classes/WorkspaceTools.php @@ -85,6 +85,7 @@ class WorkspaceTools 'APP_DOCUMENT', 'APP_HISTORY', 'APP_MESSAGE', + 'APP_NOTES', 'GROUP_USER', 'LOGIN_LOG' ]; @@ -4283,6 +4284,20 @@ class WorkspaceTools APP_MSG_TYPE_ID = 0"); $con->commit(); + // Populating APP_NOTES.APP_NUMBER + CLI::logging("-> Populating APP_NOTES.APP_NUMBER \n"); + $con->begin(); + $stmt = $con->createStatement(); + $rs = $stmt->executeQuery("UPDATE APP_NOTES AS AN + INNER JOIN ( + SELECT APPLICATION.APP_UID, APPLICATION.APP_NUMBER + FROM APPLICATION + ) AS APP + ON (AN.APP_UID = APP.APP_UID) + SET AN.APP_NUMBER = APP.APP_NUMBER + WHERE AN.APP_NUMBER = 0"); + $con->commit(); + // Populating TAS.TAS_TITLE with BPMN_EVENT.EVN_NAME /*----------------------------------********---------------------------------*/ CLI::logging("-> Populating TASK.TAS_TITLE with BPMN_EVENT.EVN_NAME\n"); diff --git a/workflow/engine/classes/WsBase.php b/workflow/engine/classes/WsBase.php index a80bb3417..cd14d4f88 100644 --- a/workflow/engine/classes/WsBase.php +++ b/workflow/engine/classes/WsBase.php @@ -3475,7 +3475,7 @@ class WsBase return $result; } - //Add note case + // Define the Case for register a case note $appNote = new BmCases(); $response = $appNote->addNote($caseUid, $userUid, $note, $sendMail, $files); diff --git a/workflow/engine/classes/model/map/AppNotesMapBuilder.php b/workflow/engine/classes/model/map/AppNotesMapBuilder.php index 90f497a0b..c4b1ffff0 100644 --- a/workflow/engine/classes/model/map/AppNotesMapBuilder.php +++ b/workflow/engine/classes/model/map/AppNotesMapBuilder.php @@ -67,6 +67,8 @@ class AppNotesMapBuilder $tMap->addColumn('NOTE_ID', 'NoteId', 'int', CreoleTypes::INTEGER, true, null); + $tMap->addColumn('APP_NUMBER', 'AppNumber', 'int', CreoleTypes::INTEGER, false, null); + $tMap->addColumn('APP_UID', 'AppUid', 'string', CreoleTypes::VARCHAR, true, 32); $tMap->addColumn('USR_UID', 'UsrUid', 'string', CreoleTypes::VARCHAR, true, 32); diff --git a/workflow/engine/classes/model/om/BaseAppNotes.php b/workflow/engine/classes/model/om/BaseAppNotes.php index 4eba38105..3c1686352 100644 --- a/workflow/engine/classes/model/om/BaseAppNotes.php +++ b/workflow/engine/classes/model/om/BaseAppNotes.php @@ -33,6 +33,12 @@ abstract class BaseAppNotes extends BaseObject implements Persistent */ protected $note_id; + /** + * The value for the app_number field. + * @var int + */ + protected $app_number = 0; + /** * The value for the app_uid field. * @var string @@ -118,6 +124,17 @@ abstract class BaseAppNotes extends BaseObject implements Persistent return $this->note_id; } + /** + * Get the [app_number] column value. + * + * @return int + */ + public function getAppNumber() + { + + return $this->app_number; + } + /** * Get the [app_uid] column value. * @@ -271,6 +288,28 @@ abstract class BaseAppNotes extends BaseObject implements Persistent } // setNoteId() + /** + * Set the value of [app_number] column. + * + * @param int $v new value + * @return void + */ + public function setAppNumber($v) + { + + // Since the native PHP type for this column is integer, + // we will cast the input value to an int (if it is not). + if ($v !== null && !is_int($v) && is_numeric($v)) { + $v = (int) $v; + } + + if ($this->app_number !== $v || $v === 0) { + $this->app_number = $v; + $this->modifiedColumns[] = AppNotesPeer::APP_NUMBER; + } + + } // setAppNumber() + /** * Set the value of [app_uid] column. * @@ -517,32 +556,34 @@ abstract class BaseAppNotes extends BaseObject implements Persistent $this->note_id = $rs->getInt($startcol + 0); - $this->app_uid = $rs->getString($startcol + 1); + $this->app_number = $rs->getInt($startcol + 1); - $this->usr_uid = $rs->getString($startcol + 2); + $this->app_uid = $rs->getString($startcol + 2); - $this->note_date = $rs->getTimestamp($startcol + 3, null); + $this->usr_uid = $rs->getString($startcol + 3); - $this->note_content = $rs->getString($startcol + 4); + $this->note_date = $rs->getTimestamp($startcol + 4, null); - $this->note_type = $rs->getString($startcol + 5); + $this->note_content = $rs->getString($startcol + 5); - $this->note_availability = $rs->getString($startcol + 6); + $this->note_type = $rs->getString($startcol + 6); - $this->note_origin_obj = $rs->getString($startcol + 7); + $this->note_availability = $rs->getString($startcol + 7); - $this->note_affected_obj1 = $rs->getString($startcol + 8); + $this->note_origin_obj = $rs->getString($startcol + 8); - $this->note_affected_obj2 = $rs->getString($startcol + 9); + $this->note_affected_obj1 = $rs->getString($startcol + 9); - $this->note_recipients = $rs->getString($startcol + 10); + $this->note_affected_obj2 = $rs->getString($startcol + 10); + + $this->note_recipients = $rs->getString($startcol + 11); $this->resetModified(); $this->setNew(false); // FIXME - using NUM_COLUMNS may be clearer. - return $startcol + 11; // 11 = AppNotesPeer::NUM_COLUMNS - AppNotesPeer::NUM_LAZY_LOAD_COLUMNS). + return $startcol + 12; // 12 = AppNotesPeer::NUM_COLUMNS - AppNotesPeer::NUM_LAZY_LOAD_COLUMNS). } catch (Exception $e) { throw new PropelException("Error populating AppNotes object", $e); @@ -750,33 +791,36 @@ abstract class BaseAppNotes extends BaseObject implements Persistent return $this->getNoteId(); break; case 1: - return $this->getAppUid(); + return $this->getAppNumber(); break; case 2: - return $this->getUsrUid(); + return $this->getAppUid(); break; case 3: - return $this->getNoteDate(); + return $this->getUsrUid(); break; case 4: - return $this->getNoteContent(); + return $this->getNoteDate(); break; case 5: - return $this->getNoteType(); + return $this->getNoteContent(); break; case 6: - return $this->getNoteAvailability(); + return $this->getNoteType(); break; case 7: - return $this->getNoteOriginObj(); + return $this->getNoteAvailability(); break; case 8: - return $this->getNoteAffectedObj1(); + return $this->getNoteOriginObj(); break; case 9: - return $this->getNoteAffectedObj2(); + return $this->getNoteAffectedObj1(); break; case 10: + return $this->getNoteAffectedObj2(); + break; + case 11: return $this->getNoteRecipients(); break; default: @@ -800,16 +844,17 @@ abstract class BaseAppNotes extends BaseObject implements Persistent $keys = AppNotesPeer::getFieldNames($keyType); $result = array( $keys[0] => $this->getNoteId(), - $keys[1] => $this->getAppUid(), - $keys[2] => $this->getUsrUid(), - $keys[3] => $this->getNoteDate(), - $keys[4] => $this->getNoteContent(), - $keys[5] => $this->getNoteType(), - $keys[6] => $this->getNoteAvailability(), - $keys[7] => $this->getNoteOriginObj(), - $keys[8] => $this->getNoteAffectedObj1(), - $keys[9] => $this->getNoteAffectedObj2(), - $keys[10] => $this->getNoteRecipients(), + $keys[1] => $this->getAppNumber(), + $keys[2] => $this->getAppUid(), + $keys[3] => $this->getUsrUid(), + $keys[4] => $this->getNoteDate(), + $keys[5] => $this->getNoteContent(), + $keys[6] => $this->getNoteType(), + $keys[7] => $this->getNoteAvailability(), + $keys[8] => $this->getNoteOriginObj(), + $keys[9] => $this->getNoteAffectedObj1(), + $keys[10] => $this->getNoteAffectedObj2(), + $keys[11] => $this->getNoteRecipients(), ); return $result; } @@ -845,33 +890,36 @@ abstract class BaseAppNotes extends BaseObject implements Persistent $this->setNoteId($value); break; case 1: - $this->setAppUid($value); + $this->setAppNumber($value); break; case 2: - $this->setUsrUid($value); + $this->setAppUid($value); break; case 3: - $this->setNoteDate($value); + $this->setUsrUid($value); break; case 4: - $this->setNoteContent($value); + $this->setNoteDate($value); break; case 5: - $this->setNoteType($value); + $this->setNoteContent($value); break; case 6: - $this->setNoteAvailability($value); + $this->setNoteType($value); break; case 7: - $this->setNoteOriginObj($value); + $this->setNoteAvailability($value); break; case 8: - $this->setNoteAffectedObj1($value); + $this->setNoteOriginObj($value); break; case 9: - $this->setNoteAffectedObj2($value); + $this->setNoteAffectedObj1($value); break; case 10: + $this->setNoteAffectedObj2($value); + break; + case 11: $this->setNoteRecipients($value); break; } // switch() @@ -902,43 +950,47 @@ abstract class BaseAppNotes extends BaseObject implements Persistent } if (array_key_exists($keys[1], $arr)) { - $this->setAppUid($arr[$keys[1]]); + $this->setAppNumber($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { - $this->setUsrUid($arr[$keys[2]]); + $this->setAppUid($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { - $this->setNoteDate($arr[$keys[3]]); + $this->setUsrUid($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { - $this->setNoteContent($arr[$keys[4]]); + $this->setNoteDate($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { - $this->setNoteType($arr[$keys[5]]); + $this->setNoteContent($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { - $this->setNoteAvailability($arr[$keys[6]]); + $this->setNoteType($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { - $this->setNoteOriginObj($arr[$keys[7]]); + $this->setNoteAvailability($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { - $this->setNoteAffectedObj1($arr[$keys[8]]); + $this->setNoteOriginObj($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { - $this->setNoteAffectedObj2($arr[$keys[9]]); + $this->setNoteAffectedObj1($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { - $this->setNoteRecipients($arr[$keys[10]]); + $this->setNoteAffectedObj2($arr[$keys[10]]); + } + + if (array_key_exists($keys[11], $arr)) { + $this->setNoteRecipients($arr[$keys[11]]); } } @@ -956,6 +1008,10 @@ abstract class BaseAppNotes extends BaseObject implements Persistent $criteria->add(AppNotesPeer::NOTE_ID, $this->note_id); } + if ($this->isColumnModified(AppNotesPeer::APP_NUMBER)) { + $criteria->add(AppNotesPeer::APP_NUMBER, $this->app_number); + } + if ($this->isColumnModified(AppNotesPeer::APP_UID)) { $criteria->add(AppNotesPeer::APP_UID, $this->app_uid); } @@ -1055,6 +1111,8 @@ abstract class BaseAppNotes extends BaseObject implements Persistent $copyObj->setNoteId($this->note_id); + $copyObj->setAppNumber($this->app_number); + $copyObj->setAppUid($this->app_uid); $copyObj->setUsrUid($this->usr_uid); diff --git a/workflow/engine/classes/model/om/BaseAppNotesPeer.php b/workflow/engine/classes/model/om/BaseAppNotesPeer.php index 858e32b61..f7e24d691 100644 --- a/workflow/engine/classes/model/om/BaseAppNotesPeer.php +++ b/workflow/engine/classes/model/om/BaseAppNotesPeer.php @@ -25,7 +25,7 @@ abstract class BaseAppNotesPeer const CLASS_DEFAULT = 'classes.model.AppNotes'; /** The total number of columns. */ - const NUM_COLUMNS = 11; + const NUM_COLUMNS = 12; /** The number of lazy-loaded columns. */ const NUM_LAZY_LOAD_COLUMNS = 0; @@ -34,6 +34,9 @@ abstract class BaseAppNotesPeer /** the column name for the NOTE_ID field */ const NOTE_ID = 'APP_NOTES.NOTE_ID'; + /** the column name for the APP_NUMBER field */ + const APP_NUMBER = 'APP_NOTES.APP_NUMBER'; + /** the column name for the APP_UID field */ const APP_UID = 'APP_NOTES.APP_UID'; @@ -75,10 +78,10 @@ abstract class BaseAppNotesPeer * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ private static $fieldNames = array ( - BasePeer::TYPE_PHPNAME => array ('NoteId', 'AppUid', 'UsrUid', 'NoteDate', 'NoteContent', 'NoteType', 'NoteAvailability', 'NoteOriginObj', 'NoteAffectedObj1', 'NoteAffectedObj2', 'NoteRecipients', ), - BasePeer::TYPE_COLNAME => array (AppNotesPeer::NOTE_ID, AppNotesPeer::APP_UID, AppNotesPeer::USR_UID, AppNotesPeer::NOTE_DATE, AppNotesPeer::NOTE_CONTENT, AppNotesPeer::NOTE_TYPE, AppNotesPeer::NOTE_AVAILABILITY, AppNotesPeer::NOTE_ORIGIN_OBJ, AppNotesPeer::NOTE_AFFECTED_OBJ1, AppNotesPeer::NOTE_AFFECTED_OBJ2, AppNotesPeer::NOTE_RECIPIENTS, ), - BasePeer::TYPE_FIELDNAME => array ('NOTE_ID', 'APP_UID', 'USR_UID', 'NOTE_DATE', 'NOTE_CONTENT', 'NOTE_TYPE', 'NOTE_AVAILABILITY', 'NOTE_ORIGIN_OBJ', 'NOTE_AFFECTED_OBJ1', 'NOTE_AFFECTED_OBJ2', 'NOTE_RECIPIENTS', ), - BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ) + BasePeer::TYPE_PHPNAME => array ('NoteId', 'AppNumber', 'AppUid', 'UsrUid', 'NoteDate', 'NoteContent', 'NoteType', 'NoteAvailability', 'NoteOriginObj', 'NoteAffectedObj1', 'NoteAffectedObj2', 'NoteRecipients', ), + BasePeer::TYPE_COLNAME => array (AppNotesPeer::NOTE_ID, AppNotesPeer::APP_NUMBER, AppNotesPeer::APP_UID, AppNotesPeer::USR_UID, AppNotesPeer::NOTE_DATE, AppNotesPeer::NOTE_CONTENT, AppNotesPeer::NOTE_TYPE, AppNotesPeer::NOTE_AVAILABILITY, AppNotesPeer::NOTE_ORIGIN_OBJ, AppNotesPeer::NOTE_AFFECTED_OBJ1, AppNotesPeer::NOTE_AFFECTED_OBJ2, AppNotesPeer::NOTE_RECIPIENTS, ), + BasePeer::TYPE_FIELDNAME => array ('NOTE_ID', 'APP_NUMBER', 'APP_UID', 'USR_UID', 'NOTE_DATE', 'NOTE_CONTENT', 'NOTE_TYPE', 'NOTE_AVAILABILITY', 'NOTE_ORIGIN_OBJ', 'NOTE_AFFECTED_OBJ1', 'NOTE_AFFECTED_OBJ2', 'NOTE_RECIPIENTS', ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ) ); /** @@ -88,10 +91,10 @@ abstract class BaseAppNotesPeer * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0 */ private static $fieldKeys = array ( - BasePeer::TYPE_PHPNAME => array ('NoteId' => 0, 'AppUid' => 1, 'UsrUid' => 2, 'NoteDate' => 3, 'NoteContent' => 4, 'NoteType' => 5, 'NoteAvailability' => 6, 'NoteOriginObj' => 7, 'NoteAffectedObj1' => 8, 'NoteAffectedObj2' => 9, 'NoteRecipients' => 10, ), - BasePeer::TYPE_COLNAME => array (AppNotesPeer::NOTE_ID => 0, AppNotesPeer::APP_UID => 1, AppNotesPeer::USR_UID => 2, AppNotesPeer::NOTE_DATE => 3, AppNotesPeer::NOTE_CONTENT => 4, AppNotesPeer::NOTE_TYPE => 5, AppNotesPeer::NOTE_AVAILABILITY => 6, AppNotesPeer::NOTE_ORIGIN_OBJ => 7, AppNotesPeer::NOTE_AFFECTED_OBJ1 => 8, AppNotesPeer::NOTE_AFFECTED_OBJ2 => 9, AppNotesPeer::NOTE_RECIPIENTS => 10, ), - BasePeer::TYPE_FIELDNAME => array ('NOTE_ID' => 0, 'APP_UID' => 1, 'USR_UID' => 2, 'NOTE_DATE' => 3, 'NOTE_CONTENT' => 4, 'NOTE_TYPE' => 5, 'NOTE_AVAILABILITY' => 6, 'NOTE_ORIGIN_OBJ' => 7, 'NOTE_AFFECTED_OBJ1' => 8, 'NOTE_AFFECTED_OBJ2' => 9, 'NOTE_RECIPIENTS' => 10, ), - BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ) + BasePeer::TYPE_PHPNAME => array ('NoteId' => 0, 'AppNumber' => 1, 'AppUid' => 2, 'UsrUid' => 3, 'NoteDate' => 4, 'NoteContent' => 5, 'NoteType' => 6, 'NoteAvailability' => 7, 'NoteOriginObj' => 8, 'NoteAffectedObj1' => 9, 'NoteAffectedObj2' => 10, 'NoteRecipients' => 11, ), + BasePeer::TYPE_COLNAME => array (AppNotesPeer::NOTE_ID => 0, AppNotesPeer::APP_NUMBER => 1, AppNotesPeer::APP_UID => 2, AppNotesPeer::USR_UID => 3, AppNotesPeer::NOTE_DATE => 4, AppNotesPeer::NOTE_CONTENT => 5, AppNotesPeer::NOTE_TYPE => 6, AppNotesPeer::NOTE_AVAILABILITY => 7, AppNotesPeer::NOTE_ORIGIN_OBJ => 8, AppNotesPeer::NOTE_AFFECTED_OBJ1 => 9, AppNotesPeer::NOTE_AFFECTED_OBJ2 => 10, AppNotesPeer::NOTE_RECIPIENTS => 11, ), + BasePeer::TYPE_FIELDNAME => array ('NOTE_ID' => 0, 'APP_NUMBER' => 1, 'APP_UID' => 2, 'USR_UID' => 3, 'NOTE_DATE' => 4, 'NOTE_CONTENT' => 5, 'NOTE_TYPE' => 6, 'NOTE_AVAILABILITY' => 7, 'NOTE_ORIGIN_OBJ' => 8, 'NOTE_AFFECTED_OBJ1' => 9, 'NOTE_AFFECTED_OBJ2' => 10, 'NOTE_RECIPIENTS' => 11, ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ) ); /** @@ -194,6 +197,8 @@ abstract class BaseAppNotesPeer $criteria->addSelectColumn(AppNotesPeer::NOTE_ID); + $criteria->addSelectColumn(AppNotesPeer::APP_NUMBER); + $criteria->addSelectColumn(AppNotesPeer::APP_UID); $criteria->addSelectColumn(AppNotesPeer::USR_UID); diff --git a/workflow/engine/config/schema.xml b/workflow/engine/config/schema.xml index 485caeea9..9cd5cd150 100755 --- a/workflow/engine/config/schema.xml +++ b/workflow/engine/config/schema.xml @@ -3331,6 +3331,7 @@ + @@ -3364,6 +3365,9 @@ + + + diff --git a/workflow/engine/controllers/appProxy.php b/workflow/engine/controllers/appProxy.php index 0038f01d3..4ab16596e 100644 --- a/workflow/engine/controllers/appProxy.php +++ b/workflow/engine/controllers/appProxy.php @@ -164,10 +164,10 @@ class AppProxy extends HttpProxyController //Disabling the controller response because we handle a special behavior $this->setSendResponse(false); - //Add note case - $cases = new BmCases(); try { $sendMail = intval($httpData->swSendMail); + // Define the Case for register a case note + $cases = new BmCases(); $response = $cases->addNote($appUid, $usrUid, $noteContent, $sendMail); } catch (CaseNoteUploadFile $e) { $response = new stdclass(); diff --git a/workflow/engine/data/mysql/schema.sql b/workflow/engine/data/mysql/schema.sql index cb86f5edc..ac7e4eecb 100644 --- a/workflow/engine/data/mysql/schema.sql +++ b/workflow/engine/data/mysql/schema.sql @@ -1590,6 +1590,7 @@ DROP TABLE IF EXISTS `APP_NOTES`; CREATE TABLE `APP_NOTES` ( `NOTE_ID` INTEGER NOT NULL AUTO_INCREMENT, + `APP_NUMBER` INTEGER default 0, `APP_UID` VARCHAR(32) default '' NOT NULL, `USR_UID` VARCHAR(32) default '' NOT NULL, `NOTE_DATE` DATETIME NOT NULL, @@ -1602,7 +1603,8 @@ CREATE TABLE `APP_NOTES` `NOTE_RECIPIENTS` MEDIUMTEXT, UNIQUE KEY `NOTE_ID` (`NOTE_ID`), KEY `indexAppNotesDate`(`APP_UID`, `NOTE_DATE`), - KEY `indexAppNotesUser`(`APP_UID`, `USR_UID`) + KEY `indexAppNotesUser`(`APP_UID`, `USR_UID`), + KEY `indexAppNumber`(`APP_NUMBER`) )ENGINE=InnoDB DEFAULT CHARSET='utf8' COMMENT='Application Notes'; #----------------------------------------------------------------------------- #-- DASHLET diff --git a/workflow/engine/methods/cases/ajaxListener.php b/workflow/engine/methods/cases/ajaxListener.php index 7bbe44e95..2eb4e250e 100644 --- a/workflow/engine/methods/cases/ajaxListener.php +++ b/workflow/engine/methods/cases/ajaxListener.php @@ -574,11 +574,10 @@ class Ajax $result->msg = $response->message; // Register in cases notes if (!empty($_POST['NOTE_REASON'])) { - $appNotes = new AppNotes(); $noteContent = addslashes($_POST['NOTE_REASON']); - $appNotes->postNewNote( - $appUid, $usrUid, $noteContent, $_POST['NOTIFY_CANCEL'] - ); + // Define the Case for register a case note + $cases = new BmCases(); + $response = $cases->addNote($appUid, $usrUid, $noteContent); } } else { $result->status = false; @@ -634,6 +633,13 @@ class Ajax echo G::json_encode($response); } + /** + * Reassign case from actions menu + * + * @link https://wiki.processmaker.com/3.3/Cases/Actions#Reassign_2 + * + * @return void + */ public function reassignCase() { $cases = new Cases(); @@ -677,6 +683,7 @@ class Ajax if (!empty($_POST['NOTE_REASON'])) { $noteContent = addslashes($_POST['NOTE_REASON']); $notifyReassign = $_POST['NOTIFY_REASSIGN'] === 'true' ? true: false; + // Define the Case for register a case note $cases = new BmCases(); $response = $cases->addNote($_SESSION['APPLICATION'], $_SESSION['USER_LOGGED'], $noteContent, $notifyReassign); } @@ -688,36 +695,43 @@ class Ajax print G::json_encode($result); } + /** + * Pause case from actions menu + * + * @link https://wiki.processmaker.com/3.3/Cases/Actions#Pause + * + * @return void + */ public function pauseCase() { $result = new stdclass(); try { $unpauseDate = $_REQUEST['unpauseDate'] . ' '. $_REQUEST['unpauseTime']; - $oCase = new Cases(); + if (isset($_POST['APP_UID']) && isset($_POST['DEL_INDEX'])) { - $APP_UID = $_POST['APP_UID']; - $DEL_INDEX = $_POST['DEL_INDEX']; + $appUid = $_POST['APP_UID']; + $delIndex = $_POST['DEL_INDEX']; } elseif (isset($_POST['sApplicationUID']) && isset($_POST['iIndex'])) { - $APP_UID = $_POST['sApplicationUID']; - $DEL_INDEX = $_POST['iIndex']; + $appUid = $_POST['sApplicationUID']; + $delIndex = $_POST['iIndex']; } else { - $APP_UID = $_SESSION['APPLICATION']; - $DEL_INDEX = $_SESSION['INDEX']; + $appUid = $_SESSION['APPLICATION']; + $delIndex = $_SESSION['INDEX']; } // Save the note pause reason if ($_REQUEST['NOTE_REASON'] != '') { - require_once("classes/model/AppNotes.php"); - $appNotes = new AppNotes(); $noteContent = addslashes($_REQUEST['NOTE_REASON']); - $appNotes->postNewNote($APP_UID, $_SESSION['USER_LOGGED'], $noteContent, $_REQUEST['NOTIFY_PAUSE']); + // Define the Case for register a case note + $cases = new BmCases(); + $response = $cases->addNote($appUid, $_SESSION['USER_LOGGED'], $noteContent, $_REQUEST['NOTIFY_PAUSE']); } // End save - - $oCase->pauseCase($APP_UID, $DEL_INDEX, $_SESSION['USER_LOGGED'], $unpauseDate); + $case = new Cases(); + $case->pauseCase($appUid, $delIndex, $_SESSION['USER_LOGGED'], $unpauseDate); $app = new Application(); - $caseData = $app->load($APP_UID); + $caseData = $app->load($appUid); $data['APP_NUMBER'] = $caseData['APP_NUMBER']; $data['UNPAUSE_DATE'] = $unpauseDate; diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index 487b0b1f4..d01e9de2e 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -2110,8 +2110,8 @@ class Cases } $note_content = addslashes($note_content); - $appNote = new \AppNotes(); - $appNote->addCaseNote($app_uid, $usr_uid, $note_content, intval($send_mail)); + // Define the Case for register a case note + $response = $this->addNote($app_uid, $usr_uid, $note_content, intval($send_mail)); } /** @@ -3869,14 +3869,28 @@ class Cases * @param string $note * @param bool $sendMail * @param array $files + * @param int $appNUmber + * + * @see Ajax::cancelCase() + * @see Ajax::pauseCase() + * @see Ajax::reassignCase() + * @see AppProxy::postNote() + * @see WsBase::addCaseNote() + * @see Cases::saveCaseNote() * * @return array */ - public function addNote($appUid, $userUid, $note, $sendMail = false, $files = []) + public function addNote($appUid, $userUid, $note, $sendMail = false, $files = [], $appNumber = 0) { + // Get the appNumber if was not send + if ($appNumber === 0) { + $appNumber = ModelApplication::getCaseNumber($appUid); + } + // Register the note $attributes = [ "APP_UID" => $appUid, + "APP_NUMBER" => $appNumber, "USR_UID" => $userUid, "NOTE_DATE" => date("Y-m-d H:i:s"), "NOTE_CONTENT" => $note, diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php index e35ed3a66..36f2c276e 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php @@ -3,6 +3,7 @@ namespace ProcessMaker\BusinessModel\Cases; use ProcessMaker\Model\Application; +use ProcessMaker\Model\AppNotes; use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Task; @@ -164,8 +165,8 @@ class Participated extends AbstractCases $startDate = (string)$item['APP_CREATE_DATE']; $endDate = !empty($item['APP_FINISH_DATE']) ? $item['APP_FINISH_DATE'] : date("Y-m-d H:i:s"); $item['DURATION'] = getDiffBetweenDates($startDate, $endDate); - // todo: we will to complete the real count with other ticket - $item['CASE_NOTES_COUNT'] = 0; + // Get total case notes + $item['CASE_NOTES_COUNT'] = AppNotes::total($item['APP_NUMBER']); // Define data according to the filters switch ($filter) { case 'STARTED': @@ -178,8 +179,8 @@ class Participated extends AbstractCases $result[$i]['tas_title'] = $thread['TAS_TITLE']; $result[$i]['user_id'] = $thread['USR_ID']; $result[$i]['due_date'] = $thread['DEL_TASK_DUE_DATE']; - $result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($thread['DEL_TASK_DUE_DATE']) : ''; - $result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : ''; + $result[$i]['tas_color'] = (!empty($thread['DEL_TASK_DUE_DATE'])) ? $this->getTaskColor($thread['DEL_TASK_DUE_DATE']) : ''; + $result[$i]['tas_color_label'] = (!empty($result[$i]['tas_color'])) ? self::TASK_COLORS[$result[$i]['tas_color']] : ''; $i++; } $item['PENDING'] = $result; @@ -187,8 +188,8 @@ class Participated extends AbstractCases $result[$i]['tas_title'] = $item['TAS_TITLE']; $result[$i]['user_id'] = $item['USR_ID']; $result[$i]['due_date'] = $item['DEL_TASK_DUE_DATE']; - $result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($item['DEL_TASK_DUE_DATE']) : ''; - $result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : ''; + $result[$i]['tas_color'] = (!empty($thread['DEL_TASK_DUE_DATE'])) ? $this->getTaskColor($item['DEL_TASK_DUE_DATE']) : ''; + $result[$i]['tas_color_label'] = (!empty($result[$i]['tas_color'])) ? self::TASK_COLORS[$result[$i]['tas_color']] : ''; $item['PENDING'] = $result; } break; @@ -205,8 +206,8 @@ class Participated extends AbstractCases $result[$i]['tas_title'] = $item['TAS_TITLE']; $result[$i]['user_id'] = $item['USR_ID']; $result[$i]['due_date'] = $item['DEL_TASK_DUE_DATE']; - $result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($item['DEL_TASK_DUE_DATE']) : ''; - $result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : ''; + $result[$i]['tas_color'] = (!empty($thread['DEL_TASK_DUE_DATE'])) ? $this->getTaskColor($item['DEL_TASK_DUE_DATE']) : ''; + $result[$i]['tas_color_label'] = (!empty($result[$i]['tas_color'])) ? self::TASK_COLORS[$result[$i]['tas_color']] : ''; $item['PENDING'] = $result; break; } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php index b395ef11c..ac175ef45 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php @@ -4,6 +4,7 @@ namespace ProcessMaker\BusinessModel\Cases; use G; use ProcessMaker\Model\Application; +use ProcessMaker\Model\AppNotes; use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Task; use ProcessMaker\Model\User; @@ -177,8 +178,8 @@ class Search extends AbstractCases $startDate = (string)$item['APP_CREATE_DATE']; $endDate = !empty($item['APP_FINISH_DATE']) ? $item['APP_FINISH_DATE'] : date("Y-m-d H:i:s"); $item['DURATION'] = getDiffBetweenDates($startDate, $endDate); - // todo: we will to complete the real count with other ticket - $item['CASE_NOTES_COUNT'] = 0; + // Get total case notes + $item['CASE_NOTES_COUNT'] = AppNotes::total($item['APP_NUMBER']); // Get the detail related to the open thread if (!empty($item['THREADS'])) { $result = $this->prepareTaskPending($item['THREADS'], false); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php index f00af48e1..ebe20cbdc 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php @@ -2,6 +2,7 @@ namespace ProcessMaker\BusinessModel\Cases; +use ProcessMaker\Model\AppNotes; use ProcessMaker\Model\Delegation; use ProcessMaker\Model\ProcessUser; @@ -154,8 +155,8 @@ class Supervising extends AbstractCases $startDate = (string)$item['APP_CREATE_DATE']; $endDate = !empty($item['APP_FINISH_DATE']) ? $item['APP_FINISH_DATE'] : date("Y-m-d H:i:s"); $item['DURATION'] = getDiffBetweenDates($startDate, $endDate); - // todo: we will to complete the real count with other ticket - $item['CASE_NOTES_COUNT'] = 0; + // Get total case notes + $item['CASE_NOTES_COUNT'] = AppNotes::total($item['APP_NUMBER']); // Get the detail related to the open thread if (!empty($item['PENDING'])) { $result = $this->prepareTaskPending($item['PENDING']); diff --git a/workflow/engine/src/ProcessMaker/Model/AppNotes.php b/workflow/engine/src/ProcessMaker/Model/AppNotes.php index b5195e9c5..0631dabfc 100644 --- a/workflow/engine/src/ProcessMaker/Model/AppNotes.php +++ b/workflow/engine/src/ProcessMaker/Model/AppNotes.php @@ -34,6 +34,7 @@ class AppNotes extends Model */ protected $fillable = [ 'APP_UID', + 'APP_NUMBER', 'USR_UID', 'NOTE_DATE', 'NOTE_CONTENT', @@ -57,6 +58,18 @@ class AppNotes extends Model return $query->where('APP_UID', $appUid); } + /** + * Scope a query to filter an specific case id + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $appNumber + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeAppNumber($query, int $appNumber) + { + return $query->where('APP_NUMBER', $appNumber); + } + /** * Return the documents related to the case * @@ -72,6 +85,7 @@ class AppNotes extends Model $query = AppNotes::query()->select([ 'NOTE_ID', 'APP_UID', + 'APP_NUMBER', 'NOTE_DATE', 'NOTE_CONTENT', 'NOTE_TYPE', @@ -106,7 +120,7 @@ class AppNotes extends Model * * @param string $appUid * - * @return array + * @return int */ public static function getTotal(string $appUid) { @@ -116,4 +130,19 @@ class AppNotes extends Model return $total; } + + /** + * Return the total notes by case + * + * @param int $appNumber + * + * @return int + */ + public static function total(int $appNumber) + { + $query = AppNotes::query()->select(['NOTE_ID']); + $query->appNumber($appNumber); + + return $query->get()->count(); + } } diff --git a/workflow/engine/src/ProcessMaker/Model/Application.php b/workflow/engine/src/ProcessMaker/Model/Application.php index 4148c8e32..ebbac64dd 100644 --- a/workflow/engine/src/ProcessMaker/Model/Application.php +++ b/workflow/engine/src/ProcessMaker/Model/Application.php @@ -125,6 +125,27 @@ class Application extends Model return $firstElement; } + /** + * Get app number + * + * @param string $appUid + * + * @return int + */ + public static function getCaseNumber($appUid) + { + $query = Application::query()->select(['APP_NUMBER']) + ->appUid($appUid) + ->limit(1); + $results = $query->get(); + $caseNumber = 0; + $results->each(function ($item) use (&$caseNumber) { + $caseNumber = $item->APP_NUMBER; + }); + + return $caseNumber; + } + /** * Update properties * @@ -164,6 +185,6 @@ class Application extends Model ->statusId($status) ->positivesCases(); - return $query->get()->count(); + return $query->get()->count(['APP_NUMBER']); } }