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');
$invoice = $client->invoices->where('public_id', intval($publicId))->first();
if ($invoice && $invoice->is_recurring && $invoice->enable_auto_bill > AUTO_BILL_OFF) {
$invoice->auto_bill = $enable ? true : false;
if ($invoice && $invoice->is_recurring && ($invoice->auto_bill == AUTO_BILL_OPT_IN || $invoice->auto_bill == AUTO_BILL_OPT_OUT)) {
$invoice->client_enable_auto_bill = $enable ? true : false;
$invoice->save();
}

View File

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

View File

@ -320,8 +320,8 @@ class Client extends EntityModel
$this->save();
}
public function hasAutoBillInvoices(){
return $this->invoices()->where('auto_bill', 1)->count() > 0;
public function hasAutoBillConfigurableInvoices(){
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 = [
'is_recurring' => 'boolean',
'has_tasks' => 'boolean',
'auto_bill' => 'boolean',
'client_enable_auto_bill' => 'boolean',
'has_expenses' => 'boolean',
];

View File

@ -160,7 +160,7 @@ class InvoiceRepository extends BaseRepository
->where('invoices.is_deleted', '=', false)
->where('clients.deleted_at', '=', null)
->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'))
->select(
DB::raw('COALESCE(clients.currency_id, accounts.currency_id) currency_id'),
@ -174,7 +174,7 @@ class InvoiceRepository extends BaseRepository
'invoices.amount',
'invoices.start_date',
'invoices.end_date',
'invoices.auto_bill',
'invoices.client_enable_auto_bill',
'frequencies.name as frequency'
);
@ -183,8 +183,8 @@ class InvoiceRepository extends BaseRepository
->addColumn('start_date', function ($model) { return Utils::fromSqlDate($model->start_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('auto_bill', function ($model) {
if ($model->auto_bill) {
->addColumn('client_enable_auto_bill', function ($model) {
if ($model->client_enable_auto_bill) {
return trans('texts.enabled') . ' <a href="javascript:setAutoBill('.$model->public_id.',false)">('.trans('texts.disable').')</a>';
} else {
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->start_date = Utils::toSqlDate($data['start_date']);
$invoice->end_date = Utils::toSqlDate($data['end_date']);
$invoice->auto_bill = isset($data['auto_bill']) && $data['auto_bill'] ? true : false;
$invoice->enable_auto_bill = isset($data['enable_auto_bill']) ? intval($data['enable_auto_bill']) : 0;
$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;
if ($invoice->enable_auto_bill != AUTO_BILL_OPT_IN && $invoice->enable_auto_bill != AUTO_BILL_OPT_OUT ) {
// Auto-bill is not enabled
$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 ($invoice->auto_bill < AUTO_BILL_OFF || $invoice->auto_bill > AUTO_BILL_ALWAYS ) {
$invoice->auto_bill = AUTO_BILL_OFF;
}
if (isset($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->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)) {
// update the invoice reference to match its actual state
// this is to ensure a 'payment received' email is sent

View File

@ -13,21 +13,21 @@ class PaymentsChanges extends Migration
public function up()
{
Schema::dropIfExists('payment_statuses');
Schema::create('payment_statuses', function($table)
{
$table->increments('id');
$table->string('name');
});
(new \PaymentStatusSeeder())->run();
Schema::table('payments', function($table)
{
$table->decimal('refunded', 13, 2);
$table->unsignedInteger('payment_status_id')->default(PAYMENT_STATUS_COMPLETED);
$table->foreign('payment_status_id')->references('id')->on('payment_statuses');
$table->unsignedInteger('routing_number')->nullable();
$table->smallInteger('last4')->unsigned()->nullable();
$table->date('expiration')->nullable();
@ -37,12 +37,12 @@ class PaymentsChanges extends Migration
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')
->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');
});
\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) {
$table->dropColumn('enable_auto_bill');
$table->dropColumn('client_enable_auto_bill');
});
Schema::dropIfExists('payment_statuses');

View File

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

View File

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

View File

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

View File

@ -35,7 +35,7 @@
</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">
{!! Button::info(trans("texts.manage_auto_bill"))->asLinkTo(URL::to('/client/invoices/recurring'))->appendIcon(Icon::create('repeat')) !!}
</div>