diff --git a/app/Console/Commands/SendRecurringInvoices.php b/app/Console/Commands/SendRecurringInvoices.php index 533f14d3c0ae..64a877ce3cf9 100644 --- a/app/Console/Commands/SendRecurringInvoices.php +++ b/app/Console/Commands/SendRecurringInvoices.php @@ -115,7 +115,7 @@ class SendRecurringInvoices extends Command try { $invoice = $this->invoiceRepo->createRecurringInvoice($recurInvoice); - if ($invoice && ! $invoice->isPaid()) { + if ($invoice && ! $invoice->isPaid() && $account->auto_email_invoice) { $this->info('Not billed - Sending Invoice'); $this->mailer->sendInvoice($invoice); } elseif ($invoice) { diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 7b7e5cdfa6ba..80cc17f5712c 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -976,6 +976,8 @@ class AccountController extends BaseController $account->invoice_footer = Input::get('invoice_footer'); $account->quote_terms = Input::get('quote_terms'); $account->auto_convert_quote = Input::get('auto_convert_quote'); + $account->auto_archive_invoice = Input::get('auto_archive_invoice'); + $account->auto_email_invoice = Input::get('auto_email_invoice'); $account->recurring_invoice_number_prefix = Input::get('recurring_invoice_number_prefix'); $account->client_number_prefix = trim(Input::get('client_number_prefix')); diff --git a/app/Listeners/InvoiceListener.php b/app/Listeners/InvoiceListener.php index 5f06c4d70213..fbff9274daf8 100644 --- a/app/Listeners/InvoiceListener.php +++ b/app/Listeners/InvoiceListener.php @@ -90,6 +90,11 @@ class InvoiceListener ->first(); $activity->json_backup = $invoice->hidePrivateFields()->toJSON(); $activity->save(); + + if ($invoice->balance == 0 && $payment->account->auto_archive_invoice) { + $invoiceRepo = app('App\Ninja\Repositories\InvoiceRepository'); + $invoiceRepo->archive($invoice); + } } /** diff --git a/app/Models/Account.php b/app/Models/Account.php index c86d525de942..684ab40387aa 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -134,6 +134,8 @@ class Account extends Eloquent 'header_font_id', 'body_font_id', 'auto_convert_quote', + 'auto_archive_invoice', + 'auto_email_invoice', 'all_pages_footer', 'all_pages_header', 'show_currency_code', diff --git a/app/Ninja/Transformers/AccountTransformer.php b/app/Ninja/Transformers/AccountTransformer.php index 8e59e4946bd6..0a886cf5a58b 100644 --- a/app/Ninja/Transformers/AccountTransformer.php +++ b/app/Ninja/Transformers/AccountTransformer.php @@ -237,6 +237,8 @@ class AccountTransformer extends EntityTransformer 'header_font_id' => (int) $account->header_font_id, 'body_font_id' => (int) $account->body_font_id, 'auto_convert_quote' => (bool) $account->auto_convert_quote, + 'auto_archive_invoice' => (bool) $account->auto_archive_invoice, + 'auto_email_invoice' => (bool) $account->auto_email_invoice, 'all_pages_footer' => (bool) $account->all_pages_footer, 'all_pages_header' => (bool) $account->all_pages_header, 'show_currency_code' => (bool) $account->show_currency_code, diff --git a/database/migrations/2018_03_08_150414_add_slack_notifications.php b/database/migrations/2018_03_08_150414_add_slack_notifications.php index 88f4843ffa79..cdfb22bebf4c 100644 --- a/database/migrations/2018_03_08_150414_add_slack_notifications.php +++ b/database/migrations/2018_03_08_150414_add_slack_notifications.php @@ -15,11 +15,15 @@ class AddSlackNotifications extends Migration { Schema::table('users', function ($table) { $table->string('slack_webhook_url')->nullable(); - $table->string('accepted_terms_version')->nullable(); $table->timestamp('accepted_terms_timestamp')->nullable(); $table->string('accepted_terms_ip')->nullable(); }); + + Schema::table('accounts', function ($table) { + $table->boolean('auto_archive_invoice')->default(false)->nullable(); + $table->boolean('auto_email_invoice')->default(true)->nullable(); + }); } /** @@ -31,10 +35,14 @@ class AddSlackNotifications extends Migration { Schema::table('users', function ($table) { $table->dropColumn('slack_webhook_url'); - $table->dropColumn('accepted_terms_version'); $table->dropColumn('accepted_terms_timestamp'); $table->dropColumn('accepted_terms_ip'); }); + + Schema::table('accounts', function ($table) { + $table->dropColumn('auto_archive_invoice'); + $table->dropColumn('auto_email_invoice'); + }); } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 92a336ddfe47..5eb7139e08e9 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -366,6 +366,7 @@ $LANG = array( 'confirm_email_invoice' => 'Are you sure you want to email this invoice?', 'confirm_email_quote' => 'Are you sure you want to email this quote?', 'confirm_recurring_email_invoice' => 'Are you sure you want this invoice emailed?', + 'confirm_recurring_email_invoice_not_sent' => 'Are you sure you want to start the recurrence?', 'cancel_account' => 'Delete Account', 'cancel_account_message' => 'Warning: This will permanently delete your account, there is no undo.', 'go_back' => 'Go Back', @@ -614,6 +615,7 @@ $LANG = array( 'or' => 'or', 'email_error' => 'There was a problem sending the email', 'confirm_recurring_timing' => 'Note: emails are sent at the start of the hour.', + 'confirm_recurring_timing_not_sent' => 'Note: invoices are created at the start of the hour.', 'payment_terms_help' => 'Sets the default invoice due date', 'unlink_account' => 'Unlink Account', 'unlink' => 'Unlink', @@ -978,7 +980,7 @@ $LANG = array( 'bank_account_error' => 'Failed to retreive account details, please check your credentials.', 'status_approved' => 'Approved', 'quote_settings' => 'Quote Settings', - 'auto_convert_quote' => 'Auto convert quote', + 'auto_convert_quote' => 'Auto Convert Quote', 'auto_convert_quote_help' => 'Automatically convert a quote to an invoice when approved by a client.', 'validate' => 'Validate', 'info' => 'Info', @@ -1327,6 +1329,7 @@ $LANG = array( 'debit_cards' => 'Debit Cards', 'warn_start_date_changed' => 'The next invoice will be sent on the new start date.', + 'warn_start_date_changed_not_sent' => 'The next invoice will be created on the new start date.', 'original_start_date' => 'Original start date', 'new_start_date' => 'New start date', 'security' => 'Security', @@ -2773,6 +2776,11 @@ $LANG = array( 'accept' => 'Accept', 'accepted_terms' => 'Successfully accepted the latest terms of service', 'invalid_url' => 'Invalid URL', + 'workflow_settings' => 'Workflow Settings', + 'auto_email_invoice' => 'Auto Email Invoice', + 'auto_email_invoice_help' => 'Automatically email recurring invoices when they are created.', + 'auto_archive_invoice' => 'Auto Archive Invoice', + 'auto_archive_invoice_help' => 'Automatically archive invoices once they are paid.', ); diff --git a/resources/views/accounts/invoice_settings.blade.php b/resources/views/accounts/invoice_settings.blade.php index dca404670e7a..30d6041c6f21 100644 --- a/resources/views/accounts/invoice_settings.blade.php +++ b/resources/views/accounts/invoice_settings.blade.php @@ -23,6 +23,8 @@ {!! Former::open()->rules(['iframe_url' => 'url'])->addClass('warn-on-exit') !!} {{ Former::populate($account) }} {{ Former::populateField('auto_convert_quote', intval($account->auto_convert_quote)) }} + {{ Former::populateField('auto_archive_invoice', intval($account->auto_archive_invoice)) }} + {{ Former::populateField('auto_email_invoice', intval($account->auto_email_invoice)) }} {{ Former::populateField('custom_invoice_taxes1', intval($account->custom_invoice_taxes1)) }} {{ Former::populateField('custom_invoice_taxes2', intval($account->custom_invoice_taxes2)) }} {{ Former::populateField('share_counter', intval($account->share_counter)) }} @@ -316,9 +318,19 @@
-

{!! trans('texts.quote_settings') !!}

+

{!! trans('texts.workflow_settings') !!}

+ {!! Former::checkbox('auto_email_invoice') + ->text(trans('texts.enable')) + ->blockHelp(trans('texts.auto_email_invoice_help')) + ->value(1) !!} + + {!! Former::checkbox('auto_archive_invoice') + ->text(trans('texts.enable')) + ->blockHelp(trans('texts.auto_archive_invoice_help')) + ->value(1) !!} + {!! Former::checkbox('auto_convert_quote') ->text(trans('texts.enable')) ->blockHelp(trans('texts.auto_convert_quote_help')) diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index c076b31e372d..0e155ddd3923 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -1340,13 +1340,22 @@ return false; } - var title = "{!! trans("texts.confirm_recurring_email_invoice") !!}"; + @if ($account->auto_email_invoice) + var title = "{!! trans("texts.confirm_recurring_email_invoice") !!}"; + @else + var title = "{!! trans("texts.confirm_recurring_email_invoice_not_sent") !!}"; + @endif + var text = '\n' + getSendToEmails(); var startDate = moment($('#start_date').datepicker('getDate')); // warn invoice will be emailed when saving new recurring invoice if (model.invoice().start_date() == "{{ Utils::fromSqlDate(date('Y-m-d')) }}") { - text += '\n\n' + "{!! trans("texts.confirm_recurring_timing") !!}"; + @if ($account->auto_email_invoice) + text += '\n\n' + "{!! trans("texts.confirm_recurring_timing") !!}"; + @else + text += '\n\n' + "{!! trans("texts.confirm_recurring_timing_not_sent") !!}"; + @endif // check if the start date is in the future } else if (startDate.isAfter(moment(), 'day')) { var message = "{!! trans("texts.email_will_be_sent_on") !!}"; @@ -1370,7 +1379,11 @@ if (model.invoice().start_date() != model.invoice().start_date_orig()) { var text = "{!! trans("texts.original_start_date") !!}: " + model.invoice().start_date_orig() + '\n' + "{!! trans("texts.new_start_date") !!}: " + model.invoice().start_date(); - var title = "{!! trans("texts.warn_start_date_changed") !!}"; + @if ($account->auto_email_invoice) + var title = "{!! trans("texts.warn_start_date_changed") !!}"; + @else + var title = "{!! trans("texts.warn_start_date_changed_not_sent") !!}"; + @endif sweetConfirm(function() { submitAction(''); }, text, title);