Skip to content

Commit

Permalink
tweak(Sales) add document status change event
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmhh committed Sep 26, 2024
1 parent 65935ed commit bd44c13
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tine20/Sales/Controller/Document/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ protected function _inspectAfterSetRelatedDataCreate($createdRecord, $record)
{
parent::_inspectAfterSetRelatedDataCreate($createdRecord, $record);
$this->_inspectFollowUpStati($createdRecord);

Tinebase_Event::fireEvent(new Sales_Event_DocumentStatusChange($createdRecord));
}

/**
Expand All @@ -289,6 +291,10 @@ protected function _inspectAfterSetRelatedDataUpdate($updatedRecord, $record, $c
{
parent::_inspectAfterSetRelatedDataUpdate($updatedRecord, $record, $currentRecord);
$this->_inspectFollowUpStati($updatedRecord, $currentRecord);

if ($updatedRecord->{$this->_documentStatusField} !== $currentRecord->{$this->_documentStatusField}) {
Tinebase_Event::fireEvent(new Sales_Event_DocumentStatusChange($updatedRecord, $currentRecord));
}
}

/**
Expand Down
31 changes: 31 additions & 0 deletions tine20/Sales/Event/DocumentStatusChange.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare(strict_types=1);
/**
* Tine 2.0
*
* @package Sales
* @subpackage Event
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @copyright Copyright (c) 2024 Metaways Infosystems GmbH (http://www.metaways.de)
* @author Paul Mehrer <p.mehrer@metaways.de>
*/

class Sales_Event_DocumentStatusChange extends Tinebase_Event_Abstract
{
public function __construct(
protected Sales_Model_Document_Abstract $document,
protected ?Sales_Model_Document_Abstract $orgDocument = null
)
{
parent::__construct([]); // use default value to avoid calling default constructor in case of signature change
}

public function getUpdatedDocument(): Sales_Model_Document_Abstract
{
return $this->document;
}

public function getOriginalDocument(): ?Sales_Model_Document_Abstract
{
return $this->orgDocument;
}
}

0 comments on commit bd44c13

Please sign in to comment.