diff --git a/app/Http/routes.php b/app/Http/routes.php index 4f362a3c6d..8a69b8d53e 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -707,10 +707,10 @@ if (!defined('CONTACT_EMAIL')) { define('RESELLER_REVENUE_SHARE', 'A'); define('RESELLER_LIMITED_USERS', 'B'); - define('AUTO_BILL_OFF', 0); - define('AUTO_BILL_OPT_IN', 1); - define('AUTO_BILL_OPT_OUT', 2); - define('AUTO_BILL_ALWAYS', 3); + define('AUTO_BILL_OFF', 1); + define('AUTO_BILL_OPT_IN', 2); + define('AUTO_BILL_OPT_OUT', 3); + define('AUTO_BILL_ALWAYS', 4); // These must be lowercase define('PLAN_FREE', 'free'); diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index fd493ba16d..979304ed01 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -324,7 +324,7 @@ class InvoiceRepository extends BaseRepository $invoice->start_date = Utils::toSqlDate($data['start_date']); $invoice->end_date = Utils::toSqlDate($data['end_date']); $invoice->client_enable_auto_bill = isset($data['client_enable_auto_bill']) && $data['client_enable_auto_bill'] ? true : false; - $invoice->auto_bill = isset($data['auto_bill']) ? intval($data['auto_bill']) : 0; + $invoice->auto_bill = isset($data['auto_bill']) ? intval($data['auto_bill']) : AUTO_BILL_OFF; if ($invoice->auto_bill < AUTO_BILL_OFF || $invoice->auto_bill > AUTO_BILL_ALWAYS ) { $invoice->auto_bill = AUTO_BILL_OFF; diff --git a/database/migrations/2016_04_23_182223_payments_changes.php b/database/migrations/2016_04_23_182223_payments_changes.php index 1c277d8da6..35a1b6134e 100644 --- a/database/migrations/2016_04_23_182223_payments_changes.php +++ b/database/migrations/2016_04_23_182223_payments_changes.php @@ -78,6 +78,11 @@ class PaymentsChanges extends Migration ->where('auto_bill', '=', 1) ->update(array('client_enable_auto_bill' => 1, 'auto_bill' => AUTO_BILL_OPT_OUT)); + \DB::table('invoices') + ->where('auto_bill', '=', 0) + ->where('is_recurring', '=', 1) + ->update(array('auto_bill' => AUTO_BILL_OFF)); + Schema::table('account_gateway_tokens', function($table) { @@ -113,11 +118,15 @@ class PaymentsChanges extends Migration $table->dropColumn('payment_method_id'); }); + \DB::table('invoices') + ->where('auto_bill', '=', AUTO_BILL_OFF) + ->update(array('auto_bill' => 0)); + \DB::table('invoices') ->where(function($query){ $query->where('auto_bill', '=', AUTO_BILL_ALWAYS); $query->orwhere(function($query){ - $query->where('auto_bill', '!=', AUTO_BILL_OFF); + $query->where('auto_bill', '!=', 0); $query->where('client_enable_auto_bill', '=', 1); }); }) diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 5e503b1d76..82204e7aca 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -166,24 +166,24 @@ @if($account->getTokenGatewayId()) -
+
{!! Former::select('auto_bill') - ->data_bind("value: auto_bill, valueUpdate: 'afterkeydown', event:{change:function(){if(auto_bill()==1)client_enable_auto_bill(0);if(auto_bill()==2)client_enable_auto_bill(1)}}") + ->data_bind("value: auto_bill, valueUpdate: 'afterkeydown', event:{change:function(){if(auto_bill()==".AUTO_BILL_OPT_IN.")client_enable_auto_bill(0);if(auto_bill()==".AUTO_BILL_OPT_OUT.")client_enable_auto_bill(1)}}") ->options([ - 0 => trans('texts.off'), - 1 => trans('texts.opt_in'), - 2 => trans('texts.opt_out'), - 3 => trans('texts.always'), + AUTO_BILL_OFF => trans('texts.off'), + AUTO_BILL_OPT_IN => trans('texts.opt_in'), + AUTO_BILL_OPT_OUT => trans('texts.opt_out'), + AUTO_BILL_ALWAYS => trans('texts.always'), ]) !!}
-
+
{{trans('texts.auto_bill')}}
{{trans('texts.opted_in')}} - ({{trans('texts.disable')}})
-
+
{{trans('texts.auto_bill')}}
{{trans('texts.opted_out')}} - ({{trans('texts.enable')}})