diff --git a/tests/tine20/Sales/InvoiceJsonTests.php b/tests/tine20/Sales/InvoiceJsonTests.php index c2449174ee1..219f9db4555 100644 --- a/tests/tine20/Sales/InvoiceJsonTests.php +++ b/tests/tine20/Sales/InvoiceJsonTests.php @@ -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()); } } @@ -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 */ diff --git a/tine20/Timetracker/Controller/Timesheet.php b/tine20/Timetracker/Controller/Timesheet.php index 96610985790..6b9d5147867 100644 --- a/tine20/Timetracker/Controller/Timesheet.php +++ b/tine20/Timetracker/Controller/Timesheet.php @@ -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; + } } } } diff --git a/tine20/Timetracker/js/TimesheetEditDialog.js b/tine20/Timetracker/js/TimesheetEditDialog.js index d97b3c4ffaf..ddc1c25b972 100644 --- a/tine20/Timetracker/js/TimesheetEditDialog.js +++ b/tine20/Timetracker/js/TimesheetEditDialog.js @@ -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'), @@ -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);