diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 7972918cf86c..77f3116f7faa 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -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', diff --git a/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php b/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php index dedfa1b499c9..71aee10d09bc 100644 --- a/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php +++ b/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php @@ -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"), diff --git a/app/Models/Company.php b/app/Models/Company.php index ba4b23ee3b03..32b45740af37 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -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() diff --git a/app/Models/Credit.php b/app/Models/Credit.php index dd0947ee815c..655d8d8a8aae 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -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'); diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index de0af6c4415b..8f5d6245bc0c 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -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); + + } } diff --git a/app/Transformers/CompanyUserTransformer.php b/app/Transformers/CompanyUserTransformer.php index 07a7caa9b698..c0ccbb004b5c 100644 --- a/app/Transformers/CompanyUserTransformer.php +++ b/app/Transformers/CompanyUserTransformer.php @@ -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 { diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index b70bd73f3092..3d4411da8bcc 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -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();