mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Enabled viewing previous versions of invoices and quotes
This commit is contained in:
parent
fa371d2a77
commit
31b4e17c18
@ -11,7 +11,6 @@ class ActivityController extends \BaseController
|
||||
->select('activities.id', 'activities.message', 'activities.created_at', 'clients.currency_id', 'activities.balance', 'activities.adjustment');
|
||||
|
||||
return Datatable::query($query)
|
||||
//->addColumn('blank', function($model) { return ''; })
|
||||
->addColumn('id', function ($model) { return Utils::timestampToDateTimeString(strtotime($model->created_at)); })
|
||||
->addColumn('message', function ($model) { return Utils::decodeActivity($model->message); })
|
||||
->addColumn('balance', function ($model) { return Utils::formatMoney($model->balance, $model->currency_id); })
|
||||
|
@ -494,4 +494,50 @@ class InvoiceController extends \BaseController
|
||||
|
||||
return self::edit($publicId, true);
|
||||
}
|
||||
|
||||
public function invoiceHistory($publicId)
|
||||
{
|
||||
$invoice = Invoice::withTrashed()->scope($publicId)->firstOrFail();
|
||||
$invoice->load('user', 'invoice_items', 'account.country', 'client.contacts', 'client.country');
|
||||
$invoice->invoice_date = Utils::fromSqlDate($invoice->invoice_date);
|
||||
$invoice->due_date = Utils::fromSqlDate($invoice->due_date);
|
||||
$invoice->is_pro = Auth::user()->isPro();
|
||||
$invoice->is_quote = intval($invoice->is_quote);
|
||||
|
||||
$activityTypeId = $invoice->is_quote ? ACTIVITY_TYPE_UPDATE_QUOTE : ACTIVITY_TYPE_UPDATE_INVOICE;
|
||||
$activities = Activity::scope(false, $invoice->account_id)->with(['user' => function($query) {
|
||||
$query->select(['id', 'first_name', 'last_name']);
|
||||
}])->where('activity_type_id', '=', $activityTypeId)->orderBy('id', 'desc')->get(['id', 'created_at', 'user_id', 'json_backup']);
|
||||
|
||||
$versionsJson = [];
|
||||
$versionsSelect = [];
|
||||
$lastId = false;
|
||||
|
||||
foreach ($activities as $activity) {
|
||||
$backup = json_decode($activity->json_backup);
|
||||
$backup->invoice_date = Utils::fromSqlDate($backup->invoice_date);
|
||||
$backup->due_date = Utils::fromSqlDate($backup->due_date);
|
||||
$backup->is_pro = Auth::user()->isPro();
|
||||
$backup->is_quote = intval($backup->is_quote);
|
||||
|
||||
$versionsJson[$activity->id] = $backup;
|
||||
|
||||
$key = Utils::timestampToDateTimeString(strtotime($activity->created_at)) . ' - ' . $activity->user->getDisplayName();
|
||||
$versionsSelect[$lastId ? $lastId : 0] = $key;
|
||||
$lastId = $activity->id;
|
||||
}
|
||||
|
||||
$versionsSelect[$lastId] = Utils::timestampToDateTimeString(strtotime($invoice->created_at)) . ' - ' . $invoice->user->getDisplayName();
|
||||
//dd($versionsSelect);
|
||||
//dd($activities);
|
||||
|
||||
$data = [
|
||||
'invoice' => $invoice,
|
||||
'versionsJson' => json_encode($versionsJson),
|
||||
'versionsSelect' => $versionsSelect,
|
||||
'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE, 'invoice_designs_cache_'.Auth::user()->maxInvoiceDesignId())->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(),
|
||||
];
|
||||
|
||||
return View::make('invoices.history', $data);
|
||||
}
|
||||
}
|
||||
|
@ -491,4 +491,10 @@ return array(
|
||||
'discount_percent' => 'Percent',
|
||||
'discount_amount' => 'Amount',
|
||||
|
||||
'invoice_history' => 'Invoice History',
|
||||
'quote_history' => 'Quote History',
|
||||
'current_version' => 'Current version',
|
||||
'select_versiony' => 'Select version',
|
||||
'view_history' => 'View History',
|
||||
|
||||
);
|
||||
|
@ -1,40 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
define("ACTIVITY_TYPE_CREATE_CLIENT", 1);
|
||||
define("ACTIVITY_TYPE_ARCHIVE_CLIENT", 2);
|
||||
define("ACTIVITY_TYPE_DELETE_CLIENT", 3);
|
||||
|
||||
define("ACTIVITY_TYPE_CREATE_INVOICE", 4);
|
||||
define("ACTIVITY_TYPE_UPDATE_INVOICE", 5);
|
||||
define("ACTIVITY_TYPE_EMAIL_INVOICE", 6);
|
||||
define("ACTIVITY_TYPE_VIEW_INVOICE", 7);
|
||||
define("ACTIVITY_TYPE_ARCHIVE_INVOICE", 8);
|
||||
define("ACTIVITY_TYPE_DELETE_INVOICE", 9);
|
||||
|
||||
define("ACTIVITY_TYPE_CREATE_PAYMENT", 10);
|
||||
define("ACTIVITY_TYPE_UPDATE_PAYMENT", 11);
|
||||
define("ACTIVITY_TYPE_ARCHIVE_PAYMENT", 12);
|
||||
define("ACTIVITY_TYPE_DELETE_PAYMENT", 13);
|
||||
|
||||
define("ACTIVITY_TYPE_CREATE_CREDIT", 14);
|
||||
define("ACTIVITY_TYPE_UPDATE_CREDIT", 15);
|
||||
define("ACTIVITY_TYPE_ARCHIVE_CREDIT", 16);
|
||||
define("ACTIVITY_TYPE_DELETE_CREDIT", 17);
|
||||
|
||||
define("ACTIVITY_TYPE_CREATE_QUOTE", 18);
|
||||
define("ACTIVITY_TYPE_UPDATE_QUOTE", 19);
|
||||
define("ACTIVITY_TYPE_EMAIL_QUOTE", 20);
|
||||
define("ACTIVITY_TYPE_VIEW_QUOTE", 21);
|
||||
define("ACTIVITY_TYPE_ARCHIVE_QUOTE", 22);
|
||||
define("ACTIVITY_TYPE_DELETE_QUOTE", 23);
|
||||
|
||||
define("ACTIVITY_TYPE_RESTORE_QUOTE", 24);
|
||||
define("ACTIVITY_TYPE_RESTORE_INVOICE", 25);
|
||||
define("ACTIVITY_TYPE_RESTORE_CLIENT", 26);
|
||||
define("ACTIVITY_TYPE_RESTORE_PAYMENT", 27);
|
||||
define("ACTIVITY_TYPE_RESTORE_CREDIT", 28);
|
||||
|
||||
class Activity extends Eloquent
|
||||
{
|
||||
public $timestamps = true;
|
||||
@ -50,6 +15,11 @@ class Activity extends Eloquent
|
||||
return $this->belongsTo('Account');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('User');
|
||||
}
|
||||
|
||||
private static function getBlank($entity = false)
|
||||
{
|
||||
$activity = new Activity();
|
||||
|
@ -144,6 +144,7 @@ class InvoiceRepository
|
||||
if (!$model->deleted_at || $model->deleted_at == '0000-00-00') {
|
||||
$str .= '<li><a href="'.\URL::to("{$entityType}s/".$model->public_id.'/edit').'">'.trans("texts.edit_{$entityType}").'</a></li>
|
||||
<li><a href="'.\URL::to("{$entityType}s/".$model->public_id.'/clone').'">'.trans("texts.clone_{$entityType}").'</a></li>
|
||||
<li><a href="' . \URL::to("{$entityType}s/{$entityType}_history/{$model->public_id}") . '">' . trans("texts.view_history") . '</a></li>
|
||||
<li class="divider"></li>';
|
||||
|
||||
if ($model->invoice_status_id < INVOICE_STATUS_SENT) {
|
||||
|
@ -113,6 +113,9 @@ Route::group(array('before' => 'auth'), function() {
|
||||
Route::get('recurring_invoices', 'InvoiceController@recurringIndex');
|
||||
Route::get('api/recurring_invoices/{client_id?}', array('as'=>'api.recurring_invoices', 'uses'=>'InvoiceController@getRecurringDatatable'));
|
||||
|
||||
Route::get('invoices/invoice_history/{invoice_id}', 'InvoiceController@invoiceHistory');
|
||||
Route::get('quotes/quote_history/{invoice_id}', 'InvoiceController@invoiceHistory');
|
||||
|
||||
Route::resource('invoices', 'InvoiceController');
|
||||
Route::get('api/invoices/{client_id?}', array('as'=>'api.invoices', 'uses'=>'InvoiceController@getDatatable'));
|
||||
Route::get('invoices/create/{client_id?}', 'InvoiceController@create');
|
||||
@ -192,6 +195,40 @@ define('ACCOUNT_CHART_BUILDER', 'chart_builder');
|
||||
define('ACCOUNT_USER_MANAGEMENT', 'user_management');
|
||||
define('ACCOUNT_DATA_VISUALIZATIONS', 'data_visualizations');
|
||||
|
||||
define("ACTIVITY_TYPE_CREATE_CLIENT", 1);
|
||||
define("ACTIVITY_TYPE_ARCHIVE_CLIENT", 2);
|
||||
define("ACTIVITY_TYPE_DELETE_CLIENT", 3);
|
||||
|
||||
define("ACTIVITY_TYPE_CREATE_INVOICE", 4);
|
||||
define("ACTIVITY_TYPE_UPDATE_INVOICE", 5);
|
||||
define("ACTIVITY_TYPE_EMAIL_INVOICE", 6);
|
||||
define("ACTIVITY_TYPE_VIEW_INVOICE", 7);
|
||||
define("ACTIVITY_TYPE_ARCHIVE_INVOICE", 8);
|
||||
define("ACTIVITY_TYPE_DELETE_INVOICE", 9);
|
||||
|
||||
define("ACTIVITY_TYPE_CREATE_PAYMENT", 10);
|
||||
define("ACTIVITY_TYPE_UPDATE_PAYMENT", 11);
|
||||
define("ACTIVITY_TYPE_ARCHIVE_PAYMENT", 12);
|
||||
define("ACTIVITY_TYPE_DELETE_PAYMENT", 13);
|
||||
|
||||
define("ACTIVITY_TYPE_CREATE_CREDIT", 14);
|
||||
define("ACTIVITY_TYPE_UPDATE_CREDIT", 15);
|
||||
define("ACTIVITY_TYPE_ARCHIVE_CREDIT", 16);
|
||||
define("ACTIVITY_TYPE_DELETE_CREDIT", 17);
|
||||
|
||||
define("ACTIVITY_TYPE_CREATE_QUOTE", 18);
|
||||
define("ACTIVITY_TYPE_UPDATE_QUOTE", 19);
|
||||
define("ACTIVITY_TYPE_EMAIL_QUOTE", 20);
|
||||
define("ACTIVITY_TYPE_VIEW_QUOTE", 21);
|
||||
define("ACTIVITY_TYPE_ARCHIVE_QUOTE", 22);
|
||||
define("ACTIVITY_TYPE_DELETE_QUOTE", 23);
|
||||
|
||||
define("ACTIVITY_TYPE_RESTORE_QUOTE", 24);
|
||||
define("ACTIVITY_TYPE_RESTORE_INVOICE", 25);
|
||||
define("ACTIVITY_TYPE_RESTORE_CLIENT", 26);
|
||||
define("ACTIVITY_TYPE_RESTORE_PAYMENT", 27);
|
||||
define("ACTIVITY_TYPE_RESTORE_CREDIT", 28);
|
||||
|
||||
define('DEFAULT_INVOICE_NUMBER', '0001');
|
||||
define('RECENTLY_VIEWED_LIMIT', 8);
|
||||
define('LOGGED_ERROR_LIMIT', 100);
|
||||
|
@ -288,6 +288,7 @@
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="javascript:onSaveClick()" id="saveButton">{{ trans("texts.save_{$entityType}") }}</a></li>
|
||||
<li><a href="javascript:onCloneClick()">{{ trans("texts.clone_{$entityType}") }}</a></li>
|
||||
<li><a href="{{ URL::to("{$entityType}s/{$entityType}_history/{$invoice->public_id}") }}">{{ trans("texts.view_history") }}</a></li>
|
||||
|
||||
@if ($invoice && $entityType == ENTITY_QUOTE)
|
||||
<li class="divider"></li>
|
||||
@ -1347,7 +1348,7 @@
|
||||
|
||||
@if (Utils::isConfirmed())
|
||||
if (self.invitation_link()) {
|
||||
str += '<br/><a href="' + self.invitation_link() + '" target="_blank">{{ trans('texts.view_as_recipient') }}</a>';
|
||||
str += '<br/><a href="' + self.invitation_link() + '" target="_blank" style="padding-left:20px">{{ trans('texts.view_as_recipient') }}</a>';
|
||||
}
|
||||
@endif
|
||||
|
||||
|
59
app/views/invoices/history.blade.php
Normal file
59
app/views/invoices/history.blade.php
Normal file
@ -0,0 +1,59 @@
|
||||
@extends('header')
|
||||
|
||||
@section('head')
|
||||
@parent
|
||||
|
||||
<script src="{{ asset('js/pdf_viewer.js') }}" type="text/javascript"></script>
|
||||
<script src="{{ asset('js/compatibility.js') }}" type="text/javascript"></script>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
var invoiceDesigns = {{ $invoiceDesigns }};
|
||||
var currentInvoice = {{ $invoice }};
|
||||
var versionsJson = {{ $versionsJson }};
|
||||
|
||||
function getPDFString() {
|
||||
|
||||
var version = $('#version').val();
|
||||
var invoice;
|
||||
|
||||
if (parseInt(version)) {
|
||||
invoice = versionsJson[version];
|
||||
} else {
|
||||
invoice = currentInvoice;
|
||||
}
|
||||
|
||||
var invoiceDesignId = parseInt(invoice.invoice_design_id);
|
||||
var invoiceDesign = _.findWhere(invoiceDesigns, {id: invoiceDesignId});
|
||||
if (!invoiceDesign) {
|
||||
invoiceDesign = invoiceDesigns[0];
|
||||
}
|
||||
|
||||
var doc = generatePDF(invoice, invoiceDesign.javascript, true);
|
||||
if (!doc) {
|
||||
return;
|
||||
}
|
||||
return doc.output('datauristring');
|
||||
}
|
||||
|
||||
$(function() {
|
||||
refreshPDF();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
@stop
|
||||
|
||||
@section('content')
|
||||
|
||||
{{ Former::open()->addClass('form-inline')->onchange('refreshPDF()') }}
|
||||
{{ Former::select('version')->options($versionsSelect)->label(trans('select_version')) }}
|
||||
{{ Button::success_link(URL::to($invoice->getEntityType() . 's/' . $invoice->public_id . '/edit'), trans('texts.edit_' . $invoice->getEntityType()), array('class' => 'pull-right')) }}
|
||||
{{ Former::close() }}
|
||||
|
||||
<br/> <br/>
|
||||
|
||||
@include('invoices.pdf', ['account' => Auth::user()->account, 'pdfHeight' => 800])
|
||||
|
||||
@stop
|
@ -2880,6 +2880,7 @@ box-shadow: 0px 0px 15px 0px rgba(0, 5, 5, 0.2);
|
||||
.plans-table .pro {margin-top: 40px;}
|
||||
}
|
||||
|
||||
/* bootstrap 3.2.0 fix */
|
||||
/* https://github.com/twbs/bootstrap/issues/13984 */
|
||||
.radio input[type="radio"],
|
||||
.checkbox input[type="checkbox"] {
|
||||
@ -2887,15 +2888,12 @@ margin-left: 0;
|
||||
margin-right: 5px;
|
||||
height: inherit;
|
||||
width: inherit;
|
||||
/* bootstrap 3.2.0 fix */
|
||||
float: left;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
/*.recommended-gateway {*/
|
||||
/* #recommendedGateway_id2 { */
|
||||
label[for=recommendedGateway_id2].radio{
|
||||
min-height: 60px;
|
||||
}
|
||||
|
@ -32343,7 +32343,7 @@ function displayGrid(doc, invoice, data, x, y, layout, options) {
|
||||
doc.text(marginLeft, y, value);
|
||||
|
||||
doc.setFontType('normal');
|
||||
if (invoice.is_quote) {
|
||||
if (parseInt(invoice.is_quote)) {
|
||||
if (key == 'invoice_number') {
|
||||
key = 'quote_number';
|
||||
} else if (key == 'invoice_date') {
|
||||
|
@ -772,6 +772,7 @@ box-shadow: 0px 0px 15px 0px rgba(0, 5, 5, 0.2);
|
||||
.plans-table .pro {margin-top: 40px;}
|
||||
}
|
||||
|
||||
/* bootstrap 3.2.0 fix */
|
||||
/* https://github.com/twbs/bootstrap/issues/13984 */
|
||||
.radio input[type="radio"],
|
||||
.checkbox input[type="checkbox"] {
|
||||
@ -779,15 +780,12 @@ margin-left: 0;
|
||||
margin-right: 5px;
|
||||
height: inherit;
|
||||
width: inherit;
|
||||
/* bootstrap 3.2.0 fix */
|
||||
float: left;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
/*.recommended-gateway {*/
|
||||
/* #recommendedGateway_id2 { */
|
||||
label[for=recommendedGateway_id2].radio{
|
||||
min-height: 60px;
|
||||
}
|
||||
|
@ -820,7 +820,7 @@ function displayGrid(doc, invoice, data, x, y, layout, options) {
|
||||
doc.text(marginLeft, y, value);
|
||||
|
||||
doc.setFontType('normal');
|
||||
if (invoice.is_quote) {
|
||||
if (parseInt(invoice.is_quote)) {
|
||||
if (key == 'invoice_number') {
|
||||
key = 'quote_number';
|
||||
} else if (key == 'invoice_date') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user