Update UI for configuring auto bill

This commit is contained in:
Joshua Dwire 2016-05-09 16:29:02 -04:00
parent 0fc44962d4
commit 20f6f32a06
10 changed files with 63 additions and 48 deletions

View File

@ -963,8 +963,8 @@ class PublicClientController extends BaseController
$enable = Input::get('enable'); $enable = Input::get('enable');
$invoice = $client->invoices->where('public_id', intval($publicId))->first(); $invoice = $client->invoices->where('public_id', intval($publicId))->first();
if ($invoice && $invoice->is_recurring && $invoice->enable_auto_bill > AUTO_BILL_OFF) { if ($invoice && $invoice->is_recurring && ($invoice->auto_bill == AUTO_BILL_OPT_IN || $invoice->auto_bill == AUTO_BILL_OPT_OUT)) {
$invoice->auto_bill = $enable ? true : false; $invoice->client_enable_auto_bill = $enable ? true : false;
$invoice->save(); $invoice->save();
} }

View File

@ -698,6 +698,7 @@ if (!defined('CONTACT_EMAIL')) {
define('AUTO_BILL_OFF', 0); define('AUTO_BILL_OFF', 0);
define('AUTO_BILL_OPT_IN', 1); define('AUTO_BILL_OPT_IN', 1);
define('AUTO_BILL_OPT_OUT', 2); define('AUTO_BILL_OPT_OUT', 2);
define('AUTO_BILL_ALWAYS', 3);
// These must be lowercase // These must be lowercase
define('PLAN_FREE', 'free'); define('PLAN_FREE', 'free');

View File

@ -320,8 +320,8 @@ class Client extends EntityModel
$this->save(); $this->save();
} }
public function hasAutoBillInvoices(){ public function hasAutoBillConfigurableInvoices(){
return $this->invoices()->where('auto_bill', 1)->count() > 0; return $this->invoices()->whereIn('auto_bill', [AUTO_BILL_OPT_IN, AUTO_BILL_OPT_OUT])->count() > 0;
} }
} }

View File

@ -35,7 +35,7 @@ class Invoice extends EntityModel implements BalanceAffecting
protected $casts = [ protected $casts = [
'is_recurring' => 'boolean', 'is_recurring' => 'boolean',
'has_tasks' => 'boolean', 'has_tasks' => 'boolean',
'auto_bill' => 'boolean', 'client_enable_auto_bill' => 'boolean',
'has_expenses' => 'boolean', 'has_expenses' => 'boolean',
]; ];

View File

@ -160,7 +160,7 @@ class InvoiceRepository extends BaseRepository
->where('invoices.is_deleted', '=', false) ->where('invoices.is_deleted', '=', false)
->where('clients.deleted_at', '=', null) ->where('clients.deleted_at', '=', null)
->where('invoices.is_recurring', '=', true) ->where('invoices.is_recurring', '=', true)
->where('invoices.enable_auto_bill', '>', AUTO_BILL_OFF) ->whereIn('invoices.auto_bill', [AUTO_BILL_OPT_IN, AUTO_BILL_OPT_OUT])
//->where('invoices.start_date', '>=', date('Y-m-d H:i:s')) //->where('invoices.start_date', '>=', date('Y-m-d H:i:s'))
->select( ->select(
DB::raw('COALESCE(clients.currency_id, accounts.currency_id) currency_id'), DB::raw('COALESCE(clients.currency_id, accounts.currency_id) currency_id'),
@ -174,7 +174,7 @@ class InvoiceRepository extends BaseRepository
'invoices.amount', 'invoices.amount',
'invoices.start_date', 'invoices.start_date',
'invoices.end_date', 'invoices.end_date',
'invoices.auto_bill', 'invoices.client_enable_auto_bill',
'frequencies.name as frequency' 'frequencies.name as frequency'
); );
@ -183,8 +183,8 @@ class InvoiceRepository extends BaseRepository
->addColumn('start_date', function ($model) { return Utils::fromSqlDate($model->start_date); }) ->addColumn('start_date', function ($model) { return Utils::fromSqlDate($model->start_date); })
->addColumn('end_date', function ($model) { return Utils::fromSqlDate($model->end_date); }) ->addColumn('end_date', function ($model) { return Utils::fromSqlDate($model->end_date); })
->addColumn('amount', function ($model) { return Utils::formatMoney($model->amount, $model->currency_id, $model->country_id); }) ->addColumn('amount', function ($model) { return Utils::formatMoney($model->amount, $model->currency_id, $model->country_id); })
->addColumn('auto_bill', function ($model) { ->addColumn('client_enable_auto_bill', function ($model) {
if ($model->auto_bill) { if ($model->client_enable_auto_bill) {
return trans('texts.enabled') . ' <a href="javascript:setAutoBill('.$model->public_id.',false)">('.trans('texts.disable').')</a>'; return trans('texts.enabled') . ' <a href="javascript:setAutoBill('.$model->public_id.',false)">('.trans('texts.disable').')</a>';
} else { } else {
return trans('texts.disabled') . ' <a href="javascript:setAutoBill('.$model->public_id.',true)">('.trans('texts.enable').')</a>'; return trans('texts.disabled') . ' <a href="javascript:setAutoBill('.$model->public_id.',true)">('.trans('texts.enable').')</a>';
@ -317,17 +317,12 @@ class InvoiceRepository extends BaseRepository
$invoice->frequency_id = $data['frequency_id'] ? $data['frequency_id'] : 0; $invoice->frequency_id = $data['frequency_id'] ? $data['frequency_id'] : 0;
$invoice->start_date = Utils::toSqlDate($data['start_date']); $invoice->start_date = Utils::toSqlDate($data['start_date']);
$invoice->end_date = Utils::toSqlDate($data['end_date']); $invoice->end_date = Utils::toSqlDate($data['end_date']);
$invoice->auto_bill = isset($data['auto_bill']) && $data['auto_bill'] ? true : false; $invoice->client_enable_auto_bill = isset($data['client_enable_auto_bill']) && $data['client_enable_auto_bill'] ? true : false;
$invoice->enable_auto_bill = isset($data['enable_auto_bill']) ? intval($data['enable_auto_bill']) : 0; $invoice->auto_bill = isset($data['auto_bill']) ? intval($data['auto_bill']) : 0;
if ($invoice->enable_auto_bill != AUTO_BILL_OPT_IN && $invoice->enable_auto_bill != AUTO_BILL_OPT_OUT ) { if ($invoice->auto_bill < AUTO_BILL_OFF || $invoice->auto_bill > AUTO_BILL_ALWAYS ) {
// Auto-bill is not enabled $invoice->auto_bill = AUTO_BILL_OFF;
$invoice->enable_auto_bill = AUTO_BILL_OFF;
$invoice->auto_bill = false;
} elseif ($isNew) {
$invoice->auto_bill = $invoice->enable_auto_bill == AUTO_BILL_OPT_OUT;
} }
if (isset($data['recurring_due_date'])) { if (isset($data['recurring_due_date'])) {
$invoice->due_date = $data['recurring_due_date']; $invoice->due_date = $data['recurring_due_date'];
@ -811,7 +806,7 @@ class InvoiceRepository extends BaseRepository
$recurInvoice->last_sent_date = date('Y-m-d'); $recurInvoice->last_sent_date = date('Y-m-d');
$recurInvoice->save(); $recurInvoice->save();
if ($recurInvoice->auto_bill) { if ($recurInvoice->auto_bill == AUTO_BILL_ALWAYS || ($recurInvoice->auto_bill != AUTO_BILL_OFF && $recurInvoice->client_enable_auto_bill)) {
if ($this->paymentService->autoBillInvoice($invoice)) { if ($this->paymentService->autoBillInvoice($invoice)) {
// update the invoice reference to match its actual state // update the invoice reference to match its actual state
// this is to ensure a 'payment received' email is sent // this is to ensure a 'payment received' email is sent

View File

@ -13,21 +13,21 @@ class PaymentsChanges extends Migration
public function up() public function up()
{ {
Schema::dropIfExists('payment_statuses'); Schema::dropIfExists('payment_statuses');
Schema::create('payment_statuses', function($table) Schema::create('payment_statuses', function($table)
{ {
$table->increments('id'); $table->increments('id');
$table->string('name'); $table->string('name');
}); });
(new \PaymentStatusSeeder())->run(); (new \PaymentStatusSeeder())->run();
Schema::table('payments', function($table) Schema::table('payments', function($table)
{ {
$table->decimal('refunded', 13, 2); $table->decimal('refunded', 13, 2);
$table->unsignedInteger('payment_status_id')->default(PAYMENT_STATUS_COMPLETED); $table->unsignedInteger('payment_status_id')->default(PAYMENT_STATUS_COMPLETED);
$table->foreign('payment_status_id')->references('id')->on('payment_statuses'); $table->foreign('payment_status_id')->references('id')->on('payment_statuses');
$table->unsignedInteger('routing_number')->nullable(); $table->unsignedInteger('routing_number')->nullable();
$table->smallInteger('last4')->unsigned()->nullable(); $table->smallInteger('last4')->unsigned()->nullable();
$table->date('expiration')->nullable(); $table->date('expiration')->nullable();
@ -37,12 +37,12 @@ class PaymentsChanges extends Migration
Schema::table('invoices', function($table) Schema::table('invoices', function($table)
{ {
$table->tinyInteger('enable_auto_bill')->default(AUTO_BILL_OFF); $table->boolean('client_enable_auto_bill')->default(false);
}); });
\DB::table('invoices') \DB::table('invoices')
->where('auto_bill', '=', 1) ->where('auto_bill', '=', 1)
->update(array('enable_auto_bill' => AUTO_BILL_OPT_OUT)); ->update(array('client_enable_auto_bill' => 1, 'auto_bill' => AUTO_BILL_OPT_OUT));
} }
/** /**
@ -65,8 +65,22 @@ class PaymentsChanges extends Migration
$table->dropColumn('email'); $table->dropColumn('email');
}); });
\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('client_enable_auto_bill', '=', 1);
});
})
->update(array('auto_bill' => 1));
\DB::table('invoices')
->where('auto_bill', '!=', 1)
->update(array('auto_bill' => 0));
Schema::table('invoices', function ($table) { Schema::table('invoices', function ($table) {
$table->dropColumn('enable_auto_bill'); $table->dropColumn('client_enable_auto_bill');
}); });
Schema::dropIfExists('payment_statuses'); Schema::dropIfExists('payment_statuses');

View File

@ -1272,8 +1272,9 @@ $LANG = array(
'off' => 'Off', 'off' => 'Off',
'opt_in' => 'Opt-in', 'opt_in' => 'Opt-in',
'opt_out' => 'Opt-out', 'opt_out' => 'Opt-out',
'enabled_by_client' => 'Enabled by client', 'always' => 'Always',
'disabled_by_client' => 'Disabled by client', 'opted_out' => 'Opted out',
'opted_in' => 'Opted in',
'manage_auto_bill' => 'Manage Auto-bill', 'manage_auto_bill' => 'Manage Auto-bill',
'enabled' => 'Enabled', 'enabled' => 'Enabled',
'paypal' => 'PayPal', 'paypal' => 'PayPal',

View File

@ -159,23 +159,27 @@
</span> </span>
@if($account->getTokenGatewayId()) @if($account->getTokenGatewayId())
<span data-bind="visible: is_recurring()" style="display: none"> <span data-bind="visible: is_recurring()" style="display: none">
{!! Former::radios('enable_auto_bill')->radios([ <div data-bind="visible: !(auto_bill() == 1 &amp;&amp; client_enable_auto_bill()) &amp;&amp; !(auto_bill() == 2 &amp;&amp; !client_enable_auto_bill())" style="display: none">
trans('texts.off') => array('name' => 'enable_auto_bill', 'value' => 0, 'data-bind' => "checked: enable_auto_bill, valueUpdate: 'afterkeydown', checkedValue:0"), {!! Former::select('auto_bill')
trans('texts.opt_in') => array('name' => 'enable_auto_bill', 'value' => 1, 'data-bind' => "checked: enable_auto_bill, valueUpdate: 'afterkeydown', checkedValue:1"), ->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)}}")
trans('texts.opt_out') => array('name' => 'enable_auto_bill', 'value' => 2, 'data-bind' => "checked: enable_auto_bill, valueUpdate: 'afterkeydown', checkedValue:2"), ->options([
])->inline() 0 => trans('texts.off'),
->label(trans('texts.auto_bill')) !!} 1 => trans('texts.opt_in'),
<input type="hidden" name="auto_bill" data-bind="attr: { value: auto_bill() }" /> 2 => trans('texts.opt_out'),
<div class="row"> 3 => trans('texts.always'),
<div class="col-sm-8 col-sm-offset-4"> ]) !!}
<div style="margin:-10px 0 10px;"> </div>
<div data-bind="visible: enable_auto_bill() == 1 &amp;&amp; auto_bill() &amp;&amp; public_id() != 0" style="display: none"> <input type="hidden" name="client_enable_auto_bill" data-bind="attr: { value: client_enable_auto_bill() }" />
{{trans('texts.enabled_by_client')}} <a href="#" data-bind="click:function(){auto_bill(false)}">({{trans('texts.disable')}})</a> <div class="form-group" data-bind="visible: auto_bill() == 1 &amp;&amp; client_enable_auto_bill()">
</div> <div class="col-sm-4 control-label">{{trans('texts.auto_bill')}}</div>
<div data-bind="visible: enable_auto_bill() == 2 &amp;&amp; !auto_bill() &amp;&amp; public_id() != 0" style="display: none"> <div class="col-sm-8" style="padding-top:10px;padding-bottom:9px">
{{trans('texts.disabled_by_client')}} <a href="#" data-bind="click:function(){auto_bill(true)}">({{trans('texts.enable')}})</a> {{trans('texts.opted_in')}} - <a href="#" data-bind="click:function(){client_enable_auto_bill(false)}">({{trans('texts.disable')}})</a>
</div> </div>
</div> </div>
<div class="form-group" data-bind="visible: auto_bill() == 2 &amp;&amp; !client_enable_auto_bill()">
<div class="col-sm-4 control-label">{{trans('texts.auto_bill')}}</div>
<div class="col-sm-8" style="padding-top:10px;padding-bottom:9px">
{{trans('texts.opted_out')}} - <a href="#" data-bind="click:function(){client_enable_auto_bill(true)}">({{trans('texts.enable')}})</a>
</div> </div>
</div> </div>
</span> </span>

View File

@ -188,8 +188,8 @@ function InvoiceModel(data) {
self.tax_rate2 = ko.observable(); self.tax_rate2 = ko.observable();
self.is_recurring = ko.observable(0); self.is_recurring = ko.observable(0);
self.is_quote = ko.observable({{ $entityType == ENTITY_QUOTE ? '1' : '0' }}); self.is_quote = ko.observable({{ $entityType == ENTITY_QUOTE ? '1' : '0' }});
self.auto_bill = ko.observable(false); self.auto_bill = ko.observable(0);
self.enable_auto_bill = ko.observable(0); self.client_enable_auto_bill = ko.observable(false);
self.invoice_status_id = ko.observable(0); self.invoice_status_id = ko.observable(0);
self.invoice_items = ko.observableArray(); self.invoice_items = ko.observableArray();
self.documents = ko.observableArray(); self.documents = ko.observableArray();

View File

@ -35,7 +35,7 @@
</div> </div>
--> -->
@if($entityType == ENTITY_INVOICE && $account->getTokenGatewayId() && $client->hasAutoBillInvoices()) @if($entityType == ENTITY_INVOICE && $account->getTokenGatewayId() && $client->hasAutoBillConfigurableInvoices())
<div class="pull-right" style="margin-top:5px"> <div class="pull-right" style="margin-top:5px">
{!! Button::info(trans("texts.manage_auto_bill"))->asLinkTo(URL::to('/client/invoices/recurring'))->appendIcon(Icon::create('repeat')) !!} {!! Button::info(trans("texts.manage_auto_bill"))->asLinkTo(URL::to('/client/invoices/recurring'))->appendIcon(Icon::create('repeat')) !!}
</div> </div>