Add Credits to Schema (#3169)

* Fix formatting and variable insertion for email templates

* Refactoring for invoice emails

* Fixes for midddleware

* Improve refresh includes

* change setting name
This commit is contained in:
David Bomba 2019-12-25 23:22:10 +11:00 committed by GitHub
parent 4c2cbb2dee
commit 6bf4cfe395
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 132 additions and 10 deletions

View File

@ -110,7 +110,7 @@ class CompanySettings extends BaseSettings
public $invoice_terms = '';
public $quote_terms = '';
public $invoice_taxes = 0;
public $invoice_item_taxes = 0;
public $enabled_item_tax_rates = 0;
public $invoice_design_id = '1';
public $quote_design_id = '1';
public $invoice_footer = '';
@ -321,7 +321,7 @@ class CompanySettings extends BaseSettings
'invoice_design_id' => 'string',
'invoice_fields' => 'string',
'invoice_taxes' => 'int',
'invoice_item_taxes' => 'int',
'enabled_item_tax_rates' => 'int',
'invoice_footer' => 'string',
'invoice_labels' => 'string',
'invoice_terms' => 'string',

View File

@ -66,7 +66,7 @@
* @OA\Property(property="invoice_terms", type="string", example="Invoice Terms are...", description="The default invoice terms"),
* @OA\Property(property="quote_terms", type="string", example="Quote Terms are...", description="The default quote terms"),
* @OA\Property(property="invoice_taxes", type="number", example="1", description="Taxes can be applied to the invoice"),
* @OA\Property(property="invoice_item_taxes", type="number", example="1", description="Taxes can be applied to the invoice items"),
* @OA\Property(property="enabled_item_tax_rates", type="number", example="1", description="Taxes can be applied to the invoice items"),
* @OA\Property(property="invoice_design_id", type="string", example="1", description="The default design id (invoice, quote etc)"),
* @OA\Property(property="quote_design_id", type="string", example="1", description="The default design id (invoice, quote etc)"),
* @OA\Property(property="invoice_footer", type="string", example="1", description="The default invoice footer"),

View File

@ -17,6 +17,7 @@ use App\Models\Client;
use App\Models\CompanyGateway;
use App\Models\CompanyUser;
use App\Models\Country;
use App\Models\Credit;
use App\Models\Currency;
use App\Models\Expense;
use App\Models\GroupSetting;
@ -138,6 +139,23 @@ class Company extends BaseModel
return $this->hasMany(Invoice::class)->withTrashed();
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function quotes()
{
return $this->hasMany(Quote::class)->withTrashed();
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function credits()
{
return $this->hasMany(Credit::class)->withTrashed();
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
@ -231,7 +249,7 @@ class Company extends BaseModel
*/
public function expenses()
{
return $this->hasMany(Expense::class, 'account_id', 'id')->withTrashed();
return $this->hasMany(Expense::class)->withTrashed();
}
/**
@ -239,7 +257,7 @@ class Company extends BaseModel
*/
public function payments()
{
return $this->hasMany(Payment::class, 'account_id', 'id')->withTrashed();
return $this->hasMany(Payment::class)->withTrashed();
}
public function tokens()

View File

@ -11,10 +11,20 @@
namespace App\Models;
use App\Models\Filterable;
use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Credit extends BaseModel
{
use MakesHash;
use Filterable;
use MakesDates;
use SoftDeletes;
public function assigned_user()
{
return $this->belongsTo(User::class ,'assigned_user_id', 'id');

View File

@ -19,13 +19,10 @@ use App\Models\Company;
use App\Models\CompanyGateway;
use App\Models\CompanyUser;
use App\Models\GroupSetting;
use App\Models\Payment;
use App\Models\Product;
use App\Models\TaxRate;
use App\Models\User;
use App\Transformers\ActivityTransformer;
use App\Transformers\CompanyGatewayTransformer;
use App\Transformers\CompanyUserTransformer;
use App\Transformers\GroupSettingTransformer;
use App\Transformers\TaxRateTransformer;
use App\Utils\Traits\MakesHash;
/**
@ -170,4 +167,22 @@ class CompanyTransformer extends EntityTransformer
return $this->includeCollection($company->tax_rates, $transformer, TaxRate::class);
}
public function includeProducts(Company $company)
{
$transformer = new ProductTransformer($this->serializer);
return $this->includeCollection($company->products, $transformer, Product::class);
}
public function includePayments(Company $company)
{
$transformer = new PaymentTransformer($this->serializer);
return $this->includeCollection($company->payments, $transformer, Payment::class);
}
}

View File

@ -18,6 +18,8 @@ use App\Models\CompanyUser;
use App\Models\User;
use App\Transformers\AccountTransformer;
use App\Transformers\CompanyTokenTransformer;
use App\Transformers\UserTransformer;
use App\Transformers\CompanyTransformer;
class CompanyUserTransformer extends EntityTransformer
{

View File

@ -511,6 +511,83 @@ class CreateUsersTable extends Migration
$t->unique(['company_id', 'number']);
});
Schema::create('credits', function ($t) {
$t->increments('id');
$t->unsignedInteger('client_id')->index();
$t->unsignedInteger('user_id');
$t->unsignedInteger('assigned_user_id')->nullable();
$t->unsignedInteger('company_id')->index();
$t->unsignedInteger('status_id');
$t->unsignedInteger('project_id')->nullable();
$t->unsignedInteger('vendor_id')->nullable();
$t->unsignedInteger('recurring_id')->nullable();
$t->unsignedInteger('design_id')->nullable();
$t->string('number')->nullable();
$t->float('discount')->default(0);
$t->boolean('is_amount_discount')->default(0);
$t->string('po_number')->nullable();
$t->date('date')->nullable();
$t->date('last_sent_date')->nullable();
$t->datetime('due_date')->nullable();
$t->boolean('is_deleted')->default(false);
$t->mediumText('line_items')->nullable();
$t->mediumText('backup')->nullable();
$t->text('footer')->nullable();
$t->text('public_notes')->nullable();
$t->text('private_notes')->nullable();
$t->text('terms')->nullable();
$t->string('tax_name1')->nullable();
$t->decimal('tax_rate1', 13, 3)->default(0);
$t->string('tax_name2')->nullable();
$t->decimal('tax_rate2', 13, 3)->default(0);
$t->string('tax_name3')->nullable();
$t->decimal('tax_rate3', 13, 3)->default(0);
$t->decimal('total_taxes', 13, 3)->default(0);
$t->boolean('uses_inclusive_taxes')->default(0);
$t->string('custom_value1')->nullable();
$t->string('custom_value2')->nullable();
$t->string('custom_value3')->nullable();
$t->string('custom_value4')->nullable();
$t->datetime('next_send_date')->nullable();
$t->string('custom_surcharge1')->nullable();
$t->string('custom_surcharge2')->nullable();
$t->string('custom_surcharge3')->nullable();
$t->string('custom_surcharge4')->nullable();
$t->boolean('custom_surcharge_tax1')->default(false);
$t->boolean('custom_surcharge_tax2')->default(false);
$t->boolean('custom_surcharge_tax3')->default(false);
$t->boolean('custom_surcharge_tax4')->default(false);
$t->decimal('amount', 16, 4);
$t->decimal('balance', 16, 4);
$t->decimal('partial', 16, 4)->nullable();
$t->datetime('partial_due_date')->nullable();
$t->datetime('last_viewed')->nullable();
$t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
$t->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$t->timestamps(6);
$t->softDeletes('deleted_at', 6);
$t->unique(['company_id', 'number']);
});
Schema::create('recurring_invoices', function ($t) {
$t->increments('id');
$t->unsignedInteger('client_id')->index();