mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 12:12:48 +01:00
Enabled setting reminder before/after due date or invoice date
This commit is contained in:
parent
9943c824dd
commit
2ead34fef0
@ -44,7 +44,7 @@ class SendReminders extends Command
|
||||
$this->info($account->name . ': ' . count($invoices).' invoices found');
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
if ($reminder = $invoice->getReminder()) {
|
||||
if ($reminder = $account->getInvoiceReminder($invoice)) {
|
||||
$this->info('Send to ' . $invoice->id);
|
||||
$this->mailer->sendInvoice($invoice, $reminder);
|
||||
}
|
||||
|
@ -450,8 +450,9 @@ class AccountController extends BaseController
|
||||
$account->$enableField = Input::get($enableField) ? true : false;
|
||||
|
||||
if ($account->$enableField) {
|
||||
$numDaysField = "num_days_{$type}";
|
||||
$account->$numDaysField = Input::get($numDaysField);
|
||||
$account->{"num_days_{$type}"} = Input::get("num_days_{$type}");
|
||||
$account->{"field_{$type}"} = Input::get("field_{$type}");
|
||||
$account->{"direction_{$type}"} = Input::get("field_{$type}") == REMINDER_FIELD_INVOICE_DATE ? REMINDER_DIRECTION_AFTER : Input::get("direction_{$type}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ Route::group(['middleware' => 'auth'], function() {
|
||||
Route::post('tasks/bulk', 'TaskController@bulk');
|
||||
|
||||
Route::get('api/recurring_invoices/{client_id?}', array('as'=>'api.recurring_invoices', 'uses'=>'InvoiceController@getRecurringDatatable'));
|
||||
|
||||
|
||||
Route::get('invoices/invoice_history/{invoice_id}', 'InvoiceController@invoiceHistory');
|
||||
Route::get('quotes/quote_history/{invoice_id}', 'InvoiceController@invoiceHistory');
|
||||
|
||||
@ -490,6 +490,12 @@ if (!defined('CONTACT_EMAIL')) {
|
||||
define('REMINDER2', 'reminder2');
|
||||
define('REMINDER3', 'reminder3');
|
||||
|
||||
define('REMINDER_DIRECTION_AFTER', 1);
|
||||
define('REMINDER_DIRECTION_BEFORE', 2);
|
||||
|
||||
define('REMINDER_FIELD_DUE_DATE', 1);
|
||||
define('REMINDER_FIELD_INVOICE_DATE', 2);
|
||||
|
||||
define('SOCIAL_GOOGLE', 'Google');
|
||||
define('SOCIAL_FACEBOOK', 'Facebook');
|
||||
define('SOCIAL_GITHUB', 'GitHub');
|
||||
|
@ -768,6 +768,32 @@ class Account extends Eloquent
|
||||
}
|
||||
}
|
||||
|
||||
public function getReminderDate($reminder)
|
||||
{
|
||||
if ( ! $this->{"enable_reminder{$reminder}"}) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$numDays = $this->{"num_days_reminder{$reminder}"};
|
||||
$plusMinus = $this->{"direction_reminder{$reminder}"} == REMINDER_DIRECTION_AFTER ? '-' : '+';
|
||||
|
||||
return date('Y-m-d', strtotime("$plusMinus $numDays days"));
|
||||
}
|
||||
|
||||
public function getInvoiceReminder($invoice)
|
||||
{
|
||||
for ($i=1; $i<=3; $i++) {
|
||||
if ($date = $this->getReminderDate($i)) {
|
||||
$field = $this->{"field_reminder{$i}"} == REMINDER_FIELD_DUE_DATE ? 'due_date' : 'invoice_date';
|
||||
if ($this->$field == $date) {
|
||||
return "reminder{$i}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function showTokenCheckbox()
|
||||
{
|
||||
if (!$this->isGatewayConfigured(GATEWAY_STRIPE)) {
|
||||
|
@ -595,24 +595,6 @@ class Invoice extends EntityModel implements BalanceAffecting
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getReminder()
|
||||
{
|
||||
for ($i=1; $i<=3; $i++) {
|
||||
$field = "enable_reminder{$i}";
|
||||
if (!$this->account->$field) {
|
||||
continue;
|
||||
}
|
||||
$field = "num_days_reminder{$i}";
|
||||
$date = date('Y-m-d', strtotime("- {$this->account->$field} days"));
|
||||
|
||||
if ($this->due_date == $date) {
|
||||
return "reminder{$i}";
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getPDFString()
|
||||
{
|
||||
if (!env('PHANTOMJS_CLOUD_KEY')) {
|
||||
|
@ -639,16 +639,15 @@ class InvoiceRepository extends BaseRepository
|
||||
public function findNeedingReminding($account)
|
||||
{
|
||||
$dates = [];
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$field = "enable_reminder{$i}";
|
||||
if (!$account->$field) {
|
||||
continue;
|
||||
|
||||
for ($i=1; $i<=3; $i++) {
|
||||
if ($date = $account->getReminderDate($i)) {
|
||||
$field = $account->{"field_reminder{$i}"} == REMINDER_FIELD_DUE_DATE ? 'due_date' : 'invoice_date';
|
||||
$dates[] = "$field = '$date'";
|
||||
}
|
||||
$field = "num_days_reminder{$i}";
|
||||
$dates[] = "due_date = '".date('Y-m-d', strtotime("- {$account->$field} days"))."'";
|
||||
}
|
||||
$sql = implode(' OR ', $dates);
|
||||
|
||||
$sql = implode(' OR ', $dates);
|
||||
$invoices = Invoice::whereAccountId($account->id)
|
||||
->where('balance', '>', 0)
|
||||
->whereRaw('('.$sql.')')
|
||||
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddReminderSettings extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('accounts', function ($table) {
|
||||
$table->smallInteger('direction_reminder1')->default(1);
|
||||
$table->smallInteger('direction_reminder2')->default(1);
|
||||
$table->smallInteger('direction_reminder3')->default(1);
|
||||
|
||||
$table->smallInteger('field_reminder1')->default(1);
|
||||
$table->smallInteger('field_reminder2')->default(1);
|
||||
$table->smallInteger('field_reminder3')->default(1);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('accounts', function ($table) {
|
||||
$table->dropColumn('direction_reminder1');
|
||||
$table->dropColumn('direction_reminder2');
|
||||
$table->dropColumn('direction_reminder3');
|
||||
|
||||
$table->dropColumn('field_reminder1');
|
||||
$table->dropColumn('field_reminder2');
|
||||
$table->dropColumn('field_reminder3');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
4
public/css/built.css
vendored
4
public/css/built.css
vendored
@ -3368,6 +3368,10 @@ ul.user-accounts a:hover div.remove {
|
||||
width: 350px;
|
||||
}
|
||||
|
||||
.smaller {
|
||||
font-size: .9em;
|
||||
}
|
||||
|
||||
/* Show selected section in settings nav */
|
||||
.list-group-item.selected:before {
|
||||
position: absolute;
|
||||
|
4
public/css/style.css
vendored
4
public/css/style.css
vendored
@ -1017,6 +1017,10 @@ ul.user-accounts a:hover div.remove {
|
||||
width: 350px;
|
||||
}
|
||||
|
||||
.smaller {
|
||||
font-size: .9em;
|
||||
}
|
||||
|
||||
/* Show selected section in settings nav */
|
||||
.list-group-item.selected:before {
|
||||
position: absolute;
|
||||
|
@ -984,4 +984,10 @@ return array(
|
||||
'next_invoice_number' => 'The next invoice number is :number.',
|
||||
'next_quote_number' => 'The next quote number is :number.',
|
||||
|
||||
'days_before' => 'days before',
|
||||
'days_after' => 'days after',
|
||||
'field_due_date' => 'due date',
|
||||
'field_invoice_date' => 'invoice date',
|
||||
'schedule' => 'Schedule',
|
||||
|
||||
);
|
||||
|
@ -1,13 +1,34 @@
|
||||
<div role="tabpanel" class="tab-pane {{ isset($active) && $active ? 'active' : '' }}" id="{{ $field }}">
|
||||
<div class="panel-body" style="padding-bottom: 0px">
|
||||
@if (isset($isReminder) && $isReminder)
|
||||
<div class="row">
|
||||
|
||||
{!! Former::populateField('enable_' . $field, intval($account->{'enable_' . $field})) !!}
|
||||
|
||||
<div class="row" style="padding-bottom:20px">
|
||||
<div class="col-md-6">
|
||||
{!! Former::checkbox('enable_' . $field)
|
||||
->text(trans('texts.enable'))->label('') !!}
|
||||
{!! Former::input('num_days_' . $field)
|
||||
->label(trans('texts.num_days_reminder'))
|
||||
->addClass('enable-' . $field) !!}
|
||||
|
||||
{!! Former::plaintext('schedule')
|
||||
->value(
|
||||
Former::input('num_days_' . $field)
|
||||
->addClass('enable-' . $field)
|
||||
->style('float:left;width:20%')
|
||||
->raw() .
|
||||
Former::select('direction_' . $field)
|
||||
->addOption(trans('texts.days_before'), REMINDER_DIRECTION_BEFORE)
|
||||
->addOption(trans('texts.days_after'), REMINDER_DIRECTION_AFTER)
|
||||
->addClass('enable-' . $field)
|
||||
->style('float:left;width:40%')
|
||||
->raw() .
|
||||
'<div id="days_after_'. $field .'" style="float:left;width:40%;display:none;padding-top:8px;padding-left:16px;font-size:16px;">' . trans('texts.days_after') . '</div>' .
|
||||
Former::select('field_' . $field)
|
||||
->addOption(trans('texts.field_due_date'), REMINDER_FIELD_DUE_DATE)
|
||||
->addOption(trans('texts.field_invoice_date'), REMINDER_FIELD_INVOICE_DATE)
|
||||
->addClass('enable-' . $field)
|
||||
->style('float:left;width:40%')
|
||||
->raw()
|
||||
) !!}
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@ -70,10 +91,17 @@
|
||||
NINJA.formIsChanged = true;
|
||||
});
|
||||
editors['{{ $field }}'] = editor;
|
||||
|
||||
$('#field_{{ $field }}').change(function() {
|
||||
setDirectionShown('{{ $field }}');
|
||||
})
|
||||
setDirectionShown('{{ $field }}');
|
||||
|
||||
$('.email-subject .input-group-addon').click(function() {
|
||||
$('#templateHelpModal').modal('show');
|
||||
});
|
||||
});
|
||||
|
||||
$('.email-subject .input-group-addon').click(function() {
|
||||
$('#templateHelpModal').modal('show');
|
||||
});
|
||||
|
||||
|
||||
</script>
|
@ -33,11 +33,6 @@
|
||||
@endforeach
|
||||
@endforeach
|
||||
|
||||
{!! Former::populateField('enable_reminder1', intval($account->enable_reminder1)) !!}
|
||||
{!! Former::populateField('enable_reminder2', intval($account->enable_reminder2)) !!}
|
||||
{!! Former::populateField('enable_reminder3', intval($account->enable_reminder3)) !!}
|
||||
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">{!! trans('texts.email_templates') !!}</h3>
|
||||
@ -188,6 +183,17 @@
|
||||
$('.enable-reminder' + id).attr('disabled', !checked)
|
||||
}
|
||||
|
||||
function setDirectionShown(field) {
|
||||
var val = $('#field_' + field).val();
|
||||
if (val == {{ REMINDER_FIELD_INVOICE_DATE }}) {
|
||||
$('#days_after_' + field).show();
|
||||
$('#direction_' + field).hide();
|
||||
} else {
|
||||
$('#days_after_' + field).hide();
|
||||
$('#direction_' + field).show();
|
||||
}
|
||||
}
|
||||
|
||||
function processVariables(str) {
|
||||
if (!str) {
|
||||
return '';
|
||||
|
@ -131,6 +131,7 @@
|
||||
@if ($invoice->recurring_invoice)
|
||||
{!! trans('texts.created_by_invoice', ['invoice' => link_to('/invoices/'.$invoice->recurring_invoice->public_id, trans('texts.recurring_invoice'))]) !!}
|
||||
@elseif ($invoice->id)
|
||||
<span class="smaller">
|
||||
@if (isset($lastSent) && $lastSent)
|
||||
{!! trans('texts.last_sent_on', ['date' => link_to('/invoices/'.$lastSent->public_id, $invoice->last_sent_date, ['id' => 'lastSent'])]) !!} <br/>
|
||||
@endif
|
||||
@ -138,6 +139,7 @@
|
||||
{!! trans('texts.next_send_on', ['date' => '<span data-bind="tooltip: {title: \''.$invoice->getPrettySchedule().'\', html: true}">'.$account->formatDate($invoice->getNextSendDate()).
|
||||
'<span class="glyphicon glyphicon-info-sign" style="padding-left:10px;color:#B1B5BA"></span></span>']) !!}
|
||||
@endif
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user