diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 80cc17f5712c..e98034e5e347 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -976,6 +976,7 @@ 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_quote = Input::get('auto_archive_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'); diff --git a/app/Models/Account.php b/app/Models/Account.php index 684ab40387aa..0a211d00326e 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -134,6 +134,7 @@ class Account extends Eloquent 'header_font_id', 'body_font_id', 'auto_convert_quote', + 'auto_archive_quote', 'auto_archive_invoice', 'auto_email_invoice', 'all_pages_footer', diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 92aef492f6a1..c9907fd80e0d 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -369,7 +369,7 @@ class Invoice extends EntityModel implements BalanceAffecting */ public function quote() { - return $this->belongsTo('App\Models\Invoice'); + return $this->belongsTo('App\Models\Invoice')->withTrashed(); } /** diff --git a/app/Ninja/Transformers/AccountTransformer.php b/app/Ninja/Transformers/AccountTransformer.php index 0a886cf5a58b..456a72db6917 100644 --- a/app/Ninja/Transformers/AccountTransformer.php +++ b/app/Ninja/Transformers/AccountTransformer.php @@ -237,6 +237,7 @@ 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_quote' => (bool) $account->auto_archive_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, diff --git a/app/Services/InvoiceService.php b/app/Services/InvoiceService.php index 282fd00a8558..dbaf86574a36 100644 --- a/app/Services/InvoiceService.php +++ b/app/Services/InvoiceService.php @@ -110,7 +110,14 @@ class InvoiceService extends BaseService */ public function convertQuote($quote) { - return $this->invoiceRepo->cloneInvoice($quote, $quote->id); + $account = $quote->account; + $invoice = $this->invoiceRepo->cloneInvoice($quote, $quote->id); + + if ($account->auto_archive_quote) { + $this->invoiceRepo->archive($quote); + } + + return $invoice; } /** @@ -141,6 +148,10 @@ class InvoiceService extends BaseService $quote->markApproved(); } + if ($account->auto_archive_quote) { + $this->invoiceRepo->archive($quote); + } + return $invitation->invitation_key; } 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 cdfb22bebf4c..75a097976c42 100644 --- a/database/migrations/2018_03_08_150414_add_slack_notifications.php +++ b/database/migrations/2018_03_08_150414_add_slack_notifications.php @@ -22,6 +22,7 @@ class AddSlackNotifications extends Migration Schema::table('accounts', function ($table) { $table->boolean('auto_archive_invoice')->default(false)->nullable(); + $table->boolean('auto_archive_quote')->default(false)->nullable(); $table->boolean('auto_email_invoice')->default(true)->nullable(); }); } @@ -42,6 +43,7 @@ class AddSlackNotifications extends Migration Schema::table('accounts', function ($table) { $table->dropColumn('auto_archive_invoice'); + $table->dropColumn('auto_archive_quote'); $table->dropColumn('auto_email_invoice'); }); } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 5eb7139e08e9..7ea494af83fd 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -980,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', 'auto_convert_quote_help' => 'Automatically convert a quote to an invoice when approved by a client.', 'validate' => 'Validate', 'info' => 'Info', @@ -2777,10 +2777,14 @@ $LANG = array( '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' => 'Auto Email', '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.', + 'auto_archive_invoice' => 'Auto Archive', + 'auto_archive_invoice_help' => 'Automatically archive invoices when they are paid.', + 'auto_archive_quote' => 'Auto Archive', + 'auto_archive_quote_help' => 'Automatically archive quotes when they are converted.', + 'invoice_workflow' => 'Invoice Workflow', + 'quote_workflow' => 'Quote Workflow', ); diff --git a/resources/views/accounts/invoice_settings.blade.php b/resources/views/accounts/invoice_settings.blade.php index 30d6041c6f21..1c0791f292ff 100644 --- a/resources/views/accounts/invoice_settings.blade.php +++ b/resources/views/accounts/invoice_settings.blade.php @@ -23,8 +23,9 @@ {!! 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_archive_quote', intval($account->auto_archive_quote)) }} {{ Former::populateField('auto_email_invoice', intval($account->auto_email_invoice)) }} + {{ Former::populateField('auto_archive_invoice', intval($account->auto_archive_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)) }} @@ -321,20 +322,46 @@