Warn user when editing an ACH auto bill invoice

This commit is contained in:
Joshua Dwire 2016-05-25 11:07:20 -04:00
parent c701c5563c
commit d19a3715f9
5 changed files with 26 additions and 20 deletions

View File

@ -54,20 +54,12 @@ class SendRecurringInvoices extends Command
$invoice->account->auto_bill_on_due_date;
$autoBillLater = false;
if ($invoice->account->auto_bill_on_due_date) {
if ($invoice->account->auto_bill_on_due_date || $this->paymentService->getClientRequiresDelayedAutoBill($invoice->client)) {
$autoBillLater = true;
} elseif ($paymentMethod = $this->paymentService->getClientDefaultPaymentMethod($invoice->client)) {
if ($paymentMethod && $paymentMethod->requiresDelayedAutoBill()) {
$autoBillLater = true;
}
}
if($autoBillLater) {
if (empty($paymentMethod)) {
$paymentMethod = $this->paymentService->getClientDefaultPaymentMethod($invoice->client);
}
if($paymentMethod) {
if($paymentMethod = $this->paymentService->getClientDefaultPaymentMethod($invoice->client)) {
$invoice->autoBillPaymentMethod = $paymentMethod;
}
}
@ -93,15 +85,7 @@ class SendRecurringInvoices extends Command
$billNow = false;
if ($autoBill && !$invoice->isPaid()) {
$billNow = $invoice->account->auto_bill_on_due_date;
if (!$billNow) {
$paymentMethod = $this->paymentService->getClientDefaultPaymentMethod($invoice->client);
if ($paymentMethod && $paymentMethod->requiresDelayedAutoBill()) {
$billNow = true;
}
}
$billNow = $invoice->account->auto_bill_on_due_date || $this->paymentService->getClientRequiresDelayedAutoBill($invoice->client);
}
$this->info('Processing Invoice '.$invoice->id.' - Should bill '.($billNow ? 'YES' : 'NO'));

View File

@ -26,6 +26,7 @@ use App\Ninja\Repositories\InvoiceRepository;
use App\Ninja\Repositories\ClientRepository;
use App\Ninja\Repositories\DocumentRepository;
use App\Services\InvoiceService;
use App\Services\PaymentService;
use App\Services\RecurringInvoiceService;
use App\Http\Requests\InvoiceRequest;
@ -39,10 +40,11 @@ class InvoiceController extends BaseController
protected $clientRepo;
protected $documentRepo;
protected $invoiceService;
protected $paymentService;
protected $recurringInvoiceService;
protected $entityType = ENTITY_INVOICE;
public function __construct(Mailer $mailer, InvoiceRepository $invoiceRepo, ClientRepository $clientRepo, InvoiceService $invoiceService, DocumentRepository $documentRepo, RecurringInvoiceService $recurringInvoiceService)
public function __construct(Mailer $mailer, InvoiceRepository $invoiceRepo, ClientRepository $clientRepo, InvoiceService $invoiceService, DocumentRepository $documentRepo, RecurringInvoiceService $recurringInvoiceService, PaymentService $paymentService)
{
// parent::__construct();
@ -51,6 +53,7 @@ class InvoiceController extends BaseController
$this->clientRepo = $clientRepo;
$this->invoiceService = $invoiceService;
$this->recurringInvoiceService = $recurringInvoiceService;
$this->paymentService = $paymentService;
}
public function index()
@ -196,6 +199,10 @@ class InvoiceController extends BaseController
'lastSent' => $lastSent);
$data = array_merge($data, self::getViewModel($invoice));
if ($invoice->isSent() && $invoice->getAutoBillEnabled() && !$invoice->isPaid()) {
$data['autoBillChangeWarning'] = $this->paymentService->getClientRequiresDelayedAutoBill($invoice->client);
}
if ($clone) {
$data['formIsChanged'] = true;
}

View File

@ -903,6 +903,12 @@ class PaymentService extends BaseService
return $accountGatewayToken->default_payment_method;
}
public function getClientRequiresDelayedAutoBill($client) {
$defaultPaymentMethod = $this->getClientDefaultPaymentMethod($client);
return $defaultPaymentMethod?$defaultPaymentMethod->requiresDelayedAutoBill():null;
}
public function getDatatable($clientPublicId, $search)
{
$datatable = new PaymentDatatable( ! $clientPublicId, $clientPublicId);

View File

@ -1325,6 +1325,7 @@ $LANG = array(
'auto_bill_on_due_date' => 'Auto bill on due date instead of send date',
'auto_bill_ach_date_help' => 'ACH auto bill will always happen on the due date',
'warn_change_auto_bill' => 'Due to NACHA rules, changes to this invoice may prevent ACH auto bill.',
);
return $LANG;

View File

@ -1200,6 +1200,10 @@
}
function onSaveClick() {
@if(!empty($autoBillChangeWarning))
if(!confirm("{!! trans('texts.warn_change_auto_bill') !!}"))return;
@endif
if (model.invoice().is_recurring()) {
// warn invoice will be emailed when saving new recurring invoice
if ({{ $invoice->exists() ? 'false' : 'true' }}) {
@ -1324,6 +1328,10 @@
@if ($invoice->id)
function onPaymentClick() {
@if(!empty($autoBillChangeWarning))
if(!confirm("{!! trans('texts.warn_change_auto_bill') !!}"))return;
@endif
window.location = '{{ URL::to('payments/create/' . $invoice->client->public_id . '/' . $invoice->public_id ) }}';
}