started recurring

This commit is contained in:
denisdulici 2018-04-26 02:17:55 +03:00
parent 89f56079d1
commit ad202645b8
6 changed files with 96 additions and 12 deletions

View File

@ -107,9 +107,17 @@ class Invoices extends Controller
$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'));
}
/**

View File

@ -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();
}
}

View File

@ -66,19 +66,14 @@ class Invoice extends Model
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()
@ -86,9 +81,9 @@ class Invoice extends Model
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()
@ -96,9 +91,19 @@ class Invoice extends Model
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)

View File

@ -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');
}
}

View File

@ -0,0 +1,11 @@
<?php
return [
'recurring' => 'Recurring',
'weekly' => 'Weekly',
'monthly' => 'Monthly',
'yearly' => 'Yearly',
'custom' => 'Custom',
];

View File

@ -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')) }}
@ -210,6 +212,10 @@
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',