Skip to content

Commit

Permalink
tweak(Timetracker/Timesheet): send confirmation when update cleared t…
Browse files Browse the repository at this point in the history
…imesheet
  • Loading branch information
ccheng-dev authored and pschuele committed Nov 6, 2024
1 parent d5801a9 commit f50bc8d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
8 changes: 4 additions & 4 deletions tests/tine20/Sales/InvoiceJsonTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ public function testClearing()
try {
$timesheets[0]->start_time = '10:00:00';
$tsController->update($timesheets[0]);
self::fail('should throw Sales_Exception_InvoiceAlreadyClearedEdit!');
} catch (Sales_Exception_InvoiceAlreadyClearedEdit $seiace) {
self::assertEquals('The Invoice you tried to edit is cleared already, so no editing is possible anymore!', $seiace->getMessage());
self::fail('should throw Tinebase_Exception_Confirmation!');
} catch (Tinebase_Exception_Confirmation $seiace) {
self::assertEquals('The Invoice you tried to edit is cleared already, change date will rebill the invoice, do you still want to execute this action?', $seiace->getMessage());
}
}

Expand Down Expand Up @@ -344,7 +344,7 @@ public function testClearingDeleteTS()
self::assertEquals('The Invoice you tried to delete is cleared already, so deleting is not possible anymore!', $seiacd->getMessage());
}
}

/**
* tests if product_id gets converted to string
*/
Expand Down
21 changes: 19 additions & 2 deletions tine20/Timetracker/Controller/Timesheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,25 @@ protected function _inspectBeforeUpdate($_record, $_oldRecord)
$this->_calcClearedAmount($_record, $_oldRecord);

if ($this->_isTSDateChanged($_record, $_oldRecord)) {
if ($_record->is_cleared === 1 && !empty($_record->invoice_id)) {
throw new Sales_Exception_InvoiceAlreadyClearedEdit();
if ($_record->is_cleared && !empty($_record->invoice_id)) {
$context = $this->getRequestContext();

if ($context && is_array($context) &&
(array_key_exists('clientData', $context) && array_key_exists('confirm', $context['clientData'])
|| array_key_exists('confirm', $context))) {

$relation = Tinebase_Relations::getInstance()->getRelations('Sales_Model_Invoice', 'Sql', $_record->invoice_id, 'sibling', array('CONTRACT'), 'Sales_Model_Contract')->getFirstRecord();
$contract = Sales_Controller_Contract::getInstance()->get($relation->related_id);

//Sales_Controller_Invoice::getInstance()->delete(array($_record->invoice_id));
Sales_Controller_Invoice::getInstance()->createAutoInvoices(null, $contract, true);
} else {
$translation = Tinebase_Translation::getTranslation($this->_applicationName);
$exception = new Tinebase_Exception_Confirmation(
$translation->_('The Invoice you tried to edit is cleared already, change date will rebill the invoice, do you still want to execute this action?')
);
throw $exception;
}
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions tine20/Timetracker/js/TimesheetEditDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,14 @@ Tine.Timetracker.TimesheetEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog
/**
* show error if request fails
*
* @param {} response
* @param {} request
* @param response
* @param request
* @private
*/
onRequestFailed: function(response, request) {
this.saving = false;

if (response.code && response.code == 902) {
if (response.code && response.code === 902) {
// deadline exception
Ext.MessageBox.alert(
this.app.i18n._('Failed'),
Expand All @@ -637,6 +637,10 @@ Tine.Timetracker.TimesheetEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog
String.format(this.app.i18n._('The selected Time Account is already closed.'))
);
}
} if (response.code === 650) {
Tine.Tinebase.ExceptionHandler.handleRequestException(response, function () {
this.onAfterApplyChanges(true);
}, this);
} else {
// call default exception handler
Tine.Tinebase.ExceptionHandler.handleRequestException(response);
Expand Down

0 comments on commit f50bc8d

Please sign in to comment.