Skip to content

Commit

Permalink
started recurring
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Apr 25, 2018
1 parent 89f5607 commit ad20264
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 12 deletions.
10 changes: 9 additions & 1 deletion app/Http/Controllers/Incomes/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,17 @@ public function create()

$categories = Category::enabled()->type('income')->pluck('name', 'id');

$recurrings = [
'0' => trans('general.no'),
'1' => trans('recurring.weekly'),
'2' => trans('recurring.monthly'),
'3' => trans('recurring.yearly'),
'4' => trans('recurring.custom'),
];

$number = $this->getNextInvoiceNumber();

return view('incomes.invoices.create', compact('customers', 'currencies', 'items', 'taxes', 'categories', 'number'));
return view('incomes.invoices.create', compact('customers', 'currencies', 'items', 'taxes', 'categories', 'recurrings', 'number'));
}

/**
Expand Down
17 changes: 17 additions & 0 deletions app/Models/Common/Recurring.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Models\Common;

use App\Models\Model;

class Recurring extends Model
{

/**
* Get all of the owning recurrable models.
*/
public function recurrable()
{
return $this->morphTo();
}
}
27 changes: 16 additions & 11 deletions app/Models/Income/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,39 +66,44 @@ public function category()
return $this->belongsTo('App\Models\Setting\Category');
}

public function customer()
{
return $this->belongsTo('App\Models\Income\Customer');
}

public function currency()
{
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
}

public function status()
public function customer()
{
return $this->belongsTo('App\Models\Income\InvoiceStatus', 'invoice_status_code', 'code');
return $this->belongsTo('App\Models\Income\Customer');
}

public function items()
{
return $this->hasMany('App\Models\Income\InvoiceItem');
}

public function totals()
public function histories()
{
return $this->hasMany('App\Models\Income\InvoiceTotal');
return $this->hasMany('App\Models\Income\InvoiceHistory');
}

public function payments()
{
return $this->hasMany('App\Models\Income\InvoicePayment');
}

public function histories()
public function recurrings()
{
return $this->hasMany('App\Models\Income\InvoiceHistory');
return $this->morphMany('App\Models\Common\Recurring', 'recurrable');
}

public function status()
{
return $this->belongsTo('App\Models\Income\InvoiceStatus', 'invoice_status_code', 'code');
}

public function totals()
{
return $this->hasMany('App\Models\Income\InvoiceTotal');
}

public function scopeDue($query, $date)
Expand Down
37 changes: 37 additions & 0 deletions database/migrations/2018_04_26_000000_create_recurrings_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateRecurringsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('recurrings', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->morphs('recurrable');
$table->string('frequency');
$table->integer('interval')->default(1);
$table->date('started_at');
$table->integer('count')->default(1);
$table->timestamps();
$table->softDeletes();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('recurrings');
}
}
11 changes: 11 additions & 0 deletions resources/lang/en-GB/recurring.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [

'recurring' => 'Recurring',
'weekly' => 'Weekly',
'monthly' => 'Monthly',
'yearly' => 'Yearly',
'custom' => 'Custom',

];
6 changes: 6 additions & 0 deletions resources/views/incomes/invoices/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
{!! $errors->first('category_id', '<p class="help-block">:message</p>') !!}
</div>

{{ Form::selectGroup('recurring_id', trans('recurring.recurring'), 'refresh', $recurrings, 0, []) }}

{{ Form::textareaGroup('notes', trans_choice('general.notes', 2)) }}

{{ Form::fileGroup('attachment', trans('general.attachment')) }}
Expand Down Expand Up @@ -210,6 +212,10 @@ function addItem() {
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.categories', 1)]) }}"
});
$("#recurring_id").select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans('recurring.recurring')]) }}"
});
$('#attachment').fancyfile({
text : '{{ trans('general.form.select.file') }}',
style : 'btn-default',
Expand Down

0 comments on commit ad20264

Please sign in to comment.