diff --git a/app/Http/Controllers/Incomes/Invoices.php b/app/Http/Controllers/Incomes/Invoices.php index 6dc279ff2..0be49efa2 100644 --- a/app/Http/Controllers/Incomes/Invoices.php +++ b/app/Http/Controllers/Incomes/Invoices.php @@ -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')); } /** diff --git a/app/Models/Common/Recurring.php b/app/Models/Common/Recurring.php new file mode 100644 index 000000000..feb8af816 --- /dev/null +++ b/app/Models/Common/Recurring.php @@ -0,0 +1,17 @@ +morphTo(); + } +} diff --git a/app/Models/Income/Invoice.php b/app/Models/Income/Invoice.php index 6f4cd5b21..139323f98 100644 --- a/app/Models/Income/Invoice.php +++ b/app/Models/Income/Invoice.php @@ -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) diff --git a/database/migrations/2018_04_26_000000_create_recurrings_table.php b/database/migrations/2018_04_26_000000_create_recurrings_table.php new file mode 100644 index 000000000..518e921ff --- /dev/null +++ b/database/migrations/2018_04_26_000000_create_recurrings_table.php @@ -0,0 +1,37 @@ +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'); + } +} diff --git a/resources/lang/en-GB/recurring.php b/resources/lang/en-GB/recurring.php new file mode 100644 index 000000000..5b97bdeed --- /dev/null +++ b/resources/lang/en-GB/recurring.php @@ -0,0 +1,11 @@ + 'Recurring', + 'weekly' => 'Weekly', + 'monthly' => 'Monthly', + 'yearly' => 'Yearly', + 'custom' => 'Custom', + +]; diff --git a/resources/views/incomes/invoices/create.blade.php b/resources/views/incomes/invoices/create.blade.php index 7b6a78787..7233a6114 100644 --- a/resources/views/incomes/invoices/create.blade.php +++ b/resources/views/incomes/invoices/create.blade.php @@ -110,6 +110,8 @@ {!! $errors->first('category_id', '
:message
') !!} + {{ 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',