fixed recurring command #315
This commit is contained in:
parent
26d25f41ae
commit
0a5136bd40
@ -3,13 +3,8 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Company\Company;
|
||||
use App\Models\Common\Recurring;
|
||||
use App\Models\Expense\Bill;
|
||||
use App\Models\Expense\BillHistory;
|
||||
use App\Models\Expense\Payment;
|
||||
use App\Models\Income\Invoice;
|
||||
use App\Models\Income\InvoiceHistory;
|
||||
use App\Models\Income\Revenue;
|
||||
use App\Notifications\Expense\Bill as BillNotification;
|
||||
use App\Notifications\Income\Invoice as InvoiceNotification;
|
||||
use App\Traits\Incomes;
|
||||
@ -68,9 +63,7 @@ class RecurringCheck extends Command
|
||||
|
||||
$company->setSettings();
|
||||
|
||||
$recurring = $company->recurring();
|
||||
|
||||
foreach ($recurring as $recur) {
|
||||
foreach ($company->recurring as $recur) {
|
||||
$current = Date::parse($recur->schedule()->current()->getStart()->format('Y-m-d'));
|
||||
|
||||
// Check if should recur today
|
||||
@ -78,29 +71,30 @@ class RecurringCheck extends Command
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = end(explode('\\', $recur->recurable_type));
|
||||
|
||||
$model = $type::find($recur->recurable_id);
|
||||
$model = $recur->recurable;
|
||||
|
||||
if (!$model) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'Bill':
|
||||
switch ($recur->recurable_type) {
|
||||
case 'App\Models\Expense\Bill':
|
||||
$this->recurBill($company, $model);
|
||||
break;
|
||||
case 'Invoice':
|
||||
case 'App\Models\Income\Invoice':
|
||||
$this->recurInvoice($company, $model);
|
||||
break;
|
||||
case 'Payment':
|
||||
case 'Revenue':
|
||||
case 'App\Models\Expense\Payment':
|
||||
case 'App\Models\Income\Revenue':
|
||||
$model->cloneable_relations = [];
|
||||
|
||||
// Create new record
|
||||
$clone = $model->duplicate();
|
||||
|
||||
// Update date
|
||||
$clone->parent_id = $model->id;
|
||||
$clone->paid_at = $this->today->format('Y-m-d');
|
||||
$clone->save();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -112,9 +106,14 @@ class RecurringCheck extends Command
|
||||
|
||||
protected function recurInvoice($company, $model)
|
||||
{
|
||||
$model->cloneable_relations = ['items', 'totals'];
|
||||
|
||||
// Create new record
|
||||
$clone = $model->duplicate();
|
||||
|
||||
// Set original invoice id
|
||||
$clone->parent_id = $model->id;
|
||||
|
||||
// Days between invoiced and due date
|
||||
$diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->invoiced_at));
|
||||
|
||||
@ -152,9 +151,14 @@ class RecurringCheck extends Command
|
||||
|
||||
protected function recurBill($company, $model)
|
||||
{
|
||||
$model->cloneable_relations = ['items', 'totals'];
|
||||
|
||||
// Create new record
|
||||
$clone = $model->duplicate();
|
||||
|
||||
// Set original bill id
|
||||
$clone->parent_id = $model->id;
|
||||
|
||||
// Days between invoiced and due date
|
||||
$diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->invoiced_at));
|
||||
|
||||
|
@ -469,6 +469,7 @@ class Bills extends Controller
|
||||
*/
|
||||
public function destroy(Bill $bill)
|
||||
{
|
||||
$bill->recurring()->delete();
|
||||
$bill->delete();
|
||||
|
||||
/*
|
||||
|
@ -222,6 +222,7 @@ class Payments extends Controller
|
||||
return redirect('expenses/payments');
|
||||
}
|
||||
|
||||
$payment->recurring()->delete();
|
||||
$payment->delete();
|
||||
|
||||
$message = trans('messages.success.deleted', ['type' => trans_choice('general.payments', 1)]);
|
||||
|
@ -490,6 +490,7 @@ class Invoices extends Controller
|
||||
*/
|
||||
public function destroy(Invoice $invoice)
|
||||
{
|
||||
$invoice->recurring()->delete();
|
||||
$invoice->delete();
|
||||
|
||||
/*
|
||||
|
@ -172,6 +172,8 @@ class Revenues extends Controller
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
$a = $revenue->recurring->schedule()->next();
|
||||
|
||||
return view('incomes.revenues.edit', compact('revenue', 'accounts', 'currencies', 'account_currency_code', 'customers', 'categories', 'payment_methods'));
|
||||
}
|
||||
|
||||
@ -224,6 +226,7 @@ class Revenues extends Controller
|
||||
return redirect('incomes/revenues');
|
||||
}
|
||||
|
||||
$revenue->recurring()->delete();
|
||||
$revenue->delete();
|
||||
|
||||
$message = trans('messages.success.deleted', ['type' => trans_choice('general.revenues', 1)]);
|
||||
|
@ -23,7 +23,7 @@ class Recurring extends Model
|
||||
|
||||
|
||||
/**
|
||||
* Get all of the owning recurrable models.
|
||||
* Get all of the owning recurable models.
|
||||
*/
|
||||
public function recurable()
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ class Bill extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'bill_number', 'order_number', 'bill_status_code', 'billed_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'vendor_id', 'vendor_name', 'vendor_email', 'vendor_tax_number', 'vendor_phone', 'vendor_address', 'notes', 'category_id'];
|
||||
protected $fillable = ['company_id', 'bill_number', 'order_number', 'bill_status_code', 'billed_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'vendor_id', 'vendor_name', 'vendor_email', 'vendor_tax_number', 'vendor_phone', 'vendor_address', 'notes', 'category_id', 'parent_id'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
@ -59,7 +59,7 @@ class Bill extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $cloneable_relations = ['items', 'recurring', 'totals'];
|
||||
public $cloneable_relations = ['items', 'recurring', 'totals'];
|
||||
|
||||
public function category()
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ class Payment extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'vendor_id', 'description', 'category_id', 'payment_method', 'reference'];
|
||||
protected $fillable = ['company_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'vendor_id', 'description', 'category_id', 'payment_method', 'reference', 'parent_id'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
@ -50,7 +50,7 @@ class Payment extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $cloneable_relations = ['recurring'];
|
||||
public $cloneable_relations = ['recurring'];
|
||||
|
||||
public function account()
|
||||
{
|
||||
|
@ -31,7 +31,7 @@ class Invoice extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'invoice_number', 'order_number', 'invoice_status_code', 'invoiced_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'customer_id', 'customer_name', 'customer_email', 'customer_tax_number', 'customer_phone', 'customer_address', 'notes', 'category_id'];
|
||||
protected $fillable = ['company_id', 'invoice_number', 'order_number', 'invoice_status_code', 'invoiced_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'customer_id', 'customer_name', 'customer_email', 'customer_tax_number', 'customer_phone', 'customer_address', 'notes', 'category_id', 'parent_id'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
@ -60,7 +60,7 @@ class Invoice extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $cloneable_relations = ['items', 'recurring', 'totals'];
|
||||
public $cloneable_relations = ['items', 'recurring', 'totals'];
|
||||
|
||||
public function category()
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ class Revenue extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'customer_id', 'description', 'category_id', 'payment_method', 'reference'];
|
||||
protected $fillable = ['company_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'customer_id', 'description', 'category_id', 'payment_method', 'reference', 'parent_id'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
@ -51,7 +51,7 @@ class Revenue extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $cloneable_relations = ['recurring'];
|
||||
public $cloneable_relations = ['recurring'];
|
||||
|
||||
public function user()
|
||||
{
|
||||
|
54
database/migrations/2018_04_30_000000_add_parent_column.php
Normal file
54
database/migrations/2018_04_30_000000_add_parent_column.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddParentColumn extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoices', function ($table) {
|
||||
$table->integer('parent_id')->default(0);
|
||||
});
|
||||
|
||||
Schema::table('revenues', function ($table) {
|
||||
$table->integer('parent_id')->default(0);
|
||||
});
|
||||
|
||||
Schema::table('bills', function ($table) {
|
||||
$table->integer('parent_id')->default(0);
|
||||
});
|
||||
|
||||
Schema::table('payments', function ($table) {
|
||||
$table->integer('parent_id')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function ($table) {
|
||||
$table->dropColumn('parent_id');
|
||||
});
|
||||
|
||||
Schema::table('revenues', function ($table) {
|
||||
$table->dropColumn('parent_id');
|
||||
});
|
||||
|
||||
Schema::table('bills', function ($table) {
|
||||
$table->dropColumn('parent_id');
|
||||
});
|
||||
|
||||
Schema::table('payments', function ($table) {
|
||||
$table->dropColumn('parent_id');
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user