Scaffolding Invoice

This commit is contained in:
David Bomba 2019-04-15 10:10:54 +10:00
parent 5e86fa33c1
commit c5e0d2a8d9
10 changed files with 177 additions and 3 deletions

View File

@ -6,7 +6,7 @@ use App\Models\Invoice;
class InvoiceFactory
{
public static function create() :\stdClass
public static function create(int $company_id, int $user_id) :\stdClass
{
$invoice = new \stdClass;
$invoice->invoice_status_id = Invoice::STATUS_DRAFT;
@ -31,6 +31,8 @@ class InvoiceFactory
$invoice->amount = 0;
$invoice->balance = 0;
$invoice->partial = 0;
$invoice->user_id = $user_id;
$invoice->company_id = $company_id;
return $invoice;
}

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Factory\InvoiceFactory;
use App\Models\Invoice;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
@ -57,7 +58,9 @@ class InvoiceController extends BaseController
*/
public function create()
{
//
$invoice = InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id);
return $this->itemResponse($invoice);
}
/**

View File

@ -15,7 +15,7 @@ class CreateClientRequest extends Request
public function authorize() : bool
{
return auth()->user()->can('create', Client::Class);
return auth()->user()->can('create', Client::class);
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Http\Requests\Invoice;
use App\Http\Requests\Request;
use App\Models\Invoice;
class CreateInvoiceRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('create', Invoice::class);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Http\Requests\Invoice;
use App\Http\Requests\Request;
use App\Models\Invoice;
class EditInvoiceRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->user()->can('edit', $this->invoice);
}
public function sanitize()
{
$input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
//$this->replace($input);
return $this->all();
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Http\Requests\Invoice;
use App\Http\Requests\Request;
use App\Models\Invoice;
class ShowInvoiceRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('view', $this->invoice);
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace App\Http\Requests\Invoice;
use App\Http\Requests\Request;
use App\Models\Invoice;
class StoreInvoiceRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('create', Invoice::class);
}
public function rules()
{
}
public function messages()
{
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace App\Http\Requests\Invoice;
use App\Http\Requests\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\Rule;
class UpdateInvoiceRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
// return ! auth()->user(); //todo permissions
}
public function rules()
{
}
public function messages()
{
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Policies;
use App\Models\Invoice;
use App\Models\User;
/**
* Class InvoicePolicy
* @package App\Policies
*/
class InvoicePolicy extends EntityPolicy
{
/**
* Checks if the user has create permissions
*
* @param User $user
* @return bool
*/
public function create(User $user) : bool
{
return $user->isAdmin() || $user->hasPermission('create_invoice');
}
}

View File

@ -3,8 +3,10 @@
namespace App\Providers;
use App\Models\Client;
use App\Models\Invoice;
use App\Models\Product;
use App\Policies\ClientPolicy;
use App\Policies\InvoicePolicy;
use App\Policies\ProductPolicy;
use Auth;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
@ -20,6 +22,7 @@ class AuthServiceProvider extends ServiceProvider
protected $policies = [
Client::class => ClientPolicy::class,
Product::class => ProductPolicy::class,
Invoice::class => InvoicePolicy::class,
];
/**