Browse Source

Change customer model to partner

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
bd0e47060c
  1. 8
      app/Entities/BaseRepository.php
  2. 2
      app/Entities/Partners/Partner.php
  3. 4
      app/Entities/Payments/Payment.php
  4. 9
      app/Entities/Projects/Project.php
  5. 4
      app/Entities/Projects/ProjectsRepository.php
  6. 2
      app/Entities/Subscriptions/Subscription.php
  7. 8
      app/Exceptions/Handler.php
  8. 104
      app/Http/Controllers/Partners/CustomersController.php
  9. 104
      app/Http/Controllers/Partners/PartnersController.php
  10. 28
      app/Policies/Partners/PartnerPolicy.php
  11. 4
      app/Providers/AuthServiceProvider.php
  12. 8
      database/factories/ModelFactory.php
  13. 4
      database/factories/PartnerFactory.php
  14. 4
      database/factories/PaymentFactory.php
  15. 10
      database/migrations/2017_10_26_134455_create_partners_table.php
  16. 29
      resources/lang/id/customer.php
  17. 29
      resources/lang/id/partner.php
  18. 40
      resources/views/partners/forms.blade.php
  19. 44
      resources/views/partners/index.blade.php
  20. 2
      routes/web.php
  21. 108
      tests/Feature/ManageCustomersTest.php
  22. 108
      tests/Feature/ManagePartnersTest.php
  23. 40
      tests/Feature/ManageProjectsTest.php
  24. 10
      tests/Feature/ManageSubscriptionsTest.php
  25. 8
      tests/Feature/Payments/ManagePaymentsTest.php
  26. 8
      tests/Unit/Models/PartnerTest.php
  27. 4
      tests/Unit/Models/PaymentTest.php
  28. 13
      tests/Unit/Models/ProjectTest.php
  29. 4
      tests/Unit/Models/SubscriptionTest.php
  30. 43
      tests/Unit/Policies/CustomerPolicyTest.php
  31. 43
      tests/Unit/Policies/PartnerPolicyTest.php

8
app/Entities/BaseRepository.php

@ -2,7 +2,7 @@
namespace App\Entities;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use App\Entities\Projects\Feature;
use App\Entities\Projects\Project;
use App\Entities\Users\User;
@ -15,12 +15,12 @@ abstract class BaseRepository extends EloquentRepository
public function getCustomersList()
{
return Customer::orderBy('name')->pluck('name', 'id');
return Partner::orderBy('name')->pluck('name', 'id');
}
public function getCustomersAndVendorsList()
{
return Customer::orderBy('name')->pluck('name', 'id');
return Partner::orderBy('name')->pluck('name', 'id');
}
public function getWorkersList()
@ -30,7 +30,7 @@ abstract class BaseRepository extends EloquentRepository
public function getVendorsList()
{
return Customer::orderBy('name')->pluck('name', 'id');
return Partner::orderBy('name')->pluck('name', 'id');
}
public function getProjectsList()

2
app/Entities/Partners/Customer.php → app/Entities/Partners/Partner.php

@ -4,7 +4,7 @@ namespace App\Entities\Partners;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model
class Partner extends Model
{
protected $fillable = ['name', 'email', 'phone', 'pic', 'address', 'notes', 'is_active'];
}

4
app/Entities/Payments/Payment.php

@ -2,7 +2,7 @@
namespace App\Entities\Payments;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use App\Entities\Payments\PaymentPresenter;
use App\Entities\Projects\Project;
use Illuminate\Database\Eloquent\Model;
@ -23,7 +23,7 @@ class Payment extends Model
public function partner()
{
return $this->belongsTo(Customer::class, 'partner_id');
return $this->belongsTo(Partner::class, 'partner_id');
}
public function type()

9
app/Entities/Projects/Project.php

@ -3,12 +3,11 @@
namespace App\Entities\Projects;
use App\Entities\Invoices\Invoice;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use App\Entities\Payments\Payment;
use App\Entities\Projects\ProjectPresenter;
use App\Entities\Projects\Task;
use App\Entities\Subscriptions\Subscription;
use App\Entities\Users\User;
use Illuminate\Database\Eloquent\Model;
use Laracasts\Presenter\PresentableTrait;
@ -18,7 +17,7 @@ class Project extends Model
use PresentableTrait;
protected $presenter = ProjectPresenter::class;
protected $guarded = ['id', 'created_at', 'updated_at'];
protected $guarded = ['id', 'created_at', 'updated_at'];
// protected $dates = ['start_date','end_date'];
public function nameLink()
@ -63,7 +62,7 @@ class Project extends Model
public function customer()
{
return $this->belongsTo(Customer::class);
return $this->belongsTo(Partner::class);
}
public function cashInTotal()
@ -88,7 +87,7 @@ class Project extends Model
foreach ($this->features as $feature) {
$progress = $feature->tasks->avg('progress');
$index = $totalPrice ? ($feature->price / $totalPrice) : 1;
$index = $totalPrice ? ($feature->price / $totalPrice) : 1;
$overalProgress += $progress * $index;
}

4
app/Entities/Projects/ProjectsRepository.php

@ -3,7 +3,7 @@
namespace App\Entities\Projects;
use App\Entities\BaseRepository;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use DB;
/**
@ -61,7 +61,7 @@ class ProjectsRepository extends BaseRepository
public function createNewCustomer($customerName, $customerEmail)
{
$newCustomer = new Customer;
$newCustomer = new Partner;
$newCustomer->name = $customerName;
$newCustomer->email = $customerEmail;
$newCustomer->save();

2
app/Entities/Subscriptions/Subscription.php

@ -19,7 +19,7 @@ class Subscription extends Model
public function customer()
{
return $this->belongsTo('App\Entities\Partners\Customer');
return $this->belongsTo('App\Entities\Partners\Partner');
}
public function status()

8
app/Exceptions/Handler.php

@ -45,10 +45,13 @@ class Handler extends ExceptionHandler
*/
public function render($request, Exception $exception)
{
// throw $exception;
if ($exception instanceof AuthorizationException) {
if ($request->expectsJson())
if ($request->expectsJson()) {
return response()->json(['error' => 'Forbidden Action.'], 403);
}
flash()->error('Invalid access');
return redirect()->home();
@ -56,8 +59,9 @@ class Handler extends ExceptionHandler
if ($exception instanceof EntityNotFoundException) {
if ($request->expectsJson())
if ($request->expectsJson()) {
return response()->json(['error' => 'Data not found.'], 404);
}
flash()->error('Data not found.');
return redirect()->home();

104
app/Http/Controllers/Partners/CustomersController.php

@ -1,104 +0,0 @@
<?php
namespace App\Http\Controllers\Partners;
use App\Entities\Partners\Customer;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class CustomersController extends Controller
{
/**
* Display a listing of the customer.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$editableCustomer = null;
$customers = Customer::where(function ($query) {
$query->where('name', 'like', '%'.request('q').'%');
})->paginate(25);
if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) {
$editableCustomer = Customer::find(request('id'));
}
return view('customers.index', compact('customers', 'editableCustomer'));
}
/**
* Store a newly created customer in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$newCustomerData = $this->validate($request, [
'name' => 'required|max:60',
'email' => 'nullable|email|unique:customers,email',
'phone' => 'nullable|max:255',
'pic' => 'nullable|max:255',
'address' => 'nullable|max:255',
'notes' => 'nullable|max:255',
]);
Customer::create($newCustomerData);
flash(trans('customer.created'), 'success');
return redirect()->route('customers.index');
}
/**
* Update the specified customer in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Entities\Partners\Customer $customer
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Customer $customer)
{
$customerData = $this->validate($request, [
'name' => 'required|max:60',
'email' => 'nullable|email|unique:customers,email,'.$customer->id,
'phone' => 'nullable|max:255',
'pic' => 'nullable|max:255',
'address' => 'nullable|max:255',
'notes' => 'nullable|max:255',
'is_active' => 'required|boolean',
]);
$routeParam = request()->only('page', 'q');
$customer = $customer->update($customerData);
flash(trans('customer.updated'), 'success');
return redirect()->route('customers.index', $routeParam);
}
/**
* Remove the specified customer from storage.
*
* @param \App\Entities\Partners\Customer $customer
* @return \Illuminate\Http\Response
*/
public function destroy(Customer $customer)
{
// TODO: user cannot delete customer that has been used in other table
$this->validate(request(), [
'customer_id' => 'required',
]);
$routeParam = request()->only('page', 'q');
if (request('customer_id') == $customer->id && $customer->delete()) {
flash(trans('customer.deleted'), 'warning');
return redirect()->route('customers.index', $routeParam);
}
flash(trans('customer.undeleted'), 'danger');
return back();
}
}

104
app/Http/Controllers/Partners/PartnersController.php

@ -0,0 +1,104 @@
<?php
namespace App\Http\Controllers\Partners;
use App\Entities\Partners\Partner;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PartnersController extends Controller
{
/**
* Display a listing of the partner.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$editablePartner = null;
$partners = Partner::where(function ($query) {
$query->where('name', 'like', '%'.request('q').'%');
})->paginate(25);
if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) {
$editablePartner = Partner::find(request('id'));
}
return view('partners.index', compact('partners', 'editablePartner'));
}
/**
* Store a newly created partner in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$newPartnerData = $this->validate($request, [
'name' => 'required|max:60',
'email' => 'nullable|email|unique:partners,email',
'phone' => 'nullable|max:255',
'pic' => 'nullable|max:255',
'address' => 'nullable|max:255',
'notes' => 'nullable|max:255',
]);
Partner::create($newPartnerData);
flash(trans('partner.created'), 'success');
return redirect()->route('partners.index');
}
/**
* Update the specified partner in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Entities\Partners\Partner $partner
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Partner $partner)
{
$partnerData = $this->validate($request, [
'name' => 'required|max:60',
'email' => 'nullable|email|unique:partners,email,'.$partner->id,
'phone' => 'nullable|max:255',
'pic' => 'nullable|max:255',
'address' => 'nullable|max:255',
'notes' => 'nullable|max:255',
'is_active' => 'required|boolean',
]);
$routeParam = request()->only('page', 'q');
$partner = $partner->update($partnerData);
flash(trans('partner.updated'), 'success');
return redirect()->route('partners.index', $routeParam);
}
/**
* Remove the specified partner from storage.
*
* @param \App\Entities\Partners\Partner $partner
* @return \Illuminate\Http\Response
*/
public function destroy(Partner $partner)
{
// TODO: user cannot delete partner that has been used in other table
$this->validate(request(), [
'partner_id' => 'required',
]);
$routeParam = request()->only('page', 'q');
if (request('partner_id') == $partner->id && $partner->delete()) {
flash(trans('partner.deleted'), 'warning');
return redirect()->route('partners.index', $routeParam);
}
flash(trans('partner.undeleted'), 'danger');
return back();
}
}

28
app/Policies/Partners/CustomerPolicy.php → app/Policies/Partners/PartnerPolicy.php

@ -2,11 +2,11 @@
namespace App\Policies\Partners;
use App\Entities\Partners\Partner;
use App\Entities\Users\User;
use App\Entities\Partners\Customer;
use Illuminate\Auth\Access\HandlesAuthorization;
class CustomerPolicy
class PartnerPolicy
{
use HandlesAuthorization;
@ -14,12 +14,12 @@ class CustomerPolicy
* Determine whether the user can view the project.
*
* @param \App\Entities\Users\User $user
* @param \App\Entities\Partners\Customer $customer
* @param \App\Entities\Partners\Partner $partner
* @return mixed
*/
public function view(User $user, Customer $customer)
public function view(User $user, Partner $partner)
{
// Update $user authorization to view $customer here.
// Update $user authorization to view $partner here.
return true;
}
@ -27,12 +27,12 @@ class CustomerPolicy
* Determine whether the user can create projects.
*
* @param \App\Entities\Users\User $user
* @param \App\Entities\Partners\Customer $customer
* @param \App\Entities\Partners\Partner $partner
* @return mixed
*/
public function create(User $user, Customer $customer)
public function create(User $user, Partner $partner)
{
// Update $user authorization to create $customer here.
// Update $user authorization to create $partner here.
return true;
}
@ -40,12 +40,12 @@ class CustomerPolicy
* Determine whether the user can update the project.
*
* @param \App\Entities\Users\User $user
* @param \App\Entities\Partners\Customer $customer
* @param \App\Entities\Partners\Partner $partner
* @return mixed
*/
public function update(User $user, Customer $customer)
public function update(User $user, Partner $partner)
{
// Update $user authorization to update $customer here.
// Update $user authorization to update $partner here.
return true;
}
@ -53,12 +53,12 @@ class CustomerPolicy
* Determine whether the user can delete the project.
*
* @param \App\Entities\Users\User $user
* @param \App\Entities\Partners\Customer $customer
* @param \App\Entities\Partners\Partner $partner
* @return mixed
*/
public function delete(User $user, Customer $customer)
public function delete(User $user, Partner $partner)
{
// Update $user authorization to delete $customer here.
// Update $user authorization to delete $partner here.
return true;
}
}

4
app/Providers/AuthServiceProvider.php

@ -14,8 +14,8 @@ class AuthServiceProvider extends ServiceProvider
* @var array
*/
protected $policies = [
'App\Entities\Partners\Customer' => 'App\Policies\Partners\CustomerPolicy',
'App\Entities\Users\Event' => 'App\Policies\EventPolicy',
'App\Entities\Partners\Partner' => 'App\Policies\Partners\PartnerPolicy',
'App\Entities\Users\Event' => 'App\Policies\EventPolicy',
];
/**

8
database/factories/ModelFactory.php

@ -1,7 +1,7 @@
<?php
use App\Entities\Invoices\Invoice;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use App\Entities\Projects\Feature;
use App\Entities\Projects\Project;
use App\Entities\Projects\Task;
@ -38,7 +38,7 @@ $factory->define(Project::class, function (Faker\Generator $faker) {
return factory(User::class)->create()->id;
},
'customer_id' => function () {
return factory(Customer::class)->create()->id;
return factory(Partner::class)->create()->id;
},
];
});
@ -61,10 +61,10 @@ $factory->define(Subscription::class, function (Faker\Generator $faker) {
'due_date' => $startDate->addYears(1)->format('Y-m-d'),
'remark' => $faker->paragraph,
'customer_id' => function () {
return factory(Customer::class)->create()->id;
return factory(Partner::class)->create()->id;
},
'vendor_id' => function () {
return factory(Customer::class)->create()->id;
return factory(Partner::class)->create()->id;
},
];
});

4
database/factories/CustomerFactory.php → database/factories/PartnerFactory.php

@ -1,9 +1,9 @@
<?php
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use Faker\Generator as Faker;
$factory->define(Customer::class, function (Faker $faker) {
$factory->define(Partner::class, function (Faker $faker) {
return [
'name' => $faker->company,

4
database/factories/PaymentFactory.php

@ -1,6 +1,6 @@
<?php
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use App\Entities\Payments\Payment;
use App\Entities\Projects\Project;
use App\Entities\Users\User;
@ -21,7 +21,7 @@ $factory->define(Payment::class, function (Faker $faker) {
return factory(User::class)->create()->id;
},
'partner_id' => function () {
return factory(Customer::class)->create()->id;
return factory(Partner::class)->create()->id;
},
];
});

10
database/migrations/2017_10_26_134455_create_customers_table.php → database/migrations/2017_10_26_134455_create_partners_table.php

@ -1,10 +1,10 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCustomersTable extends Migration
class CreatePartnersTable extends Migration
{
/**
* Run the migrations.
@ -13,7 +13,7 @@ class CreateCustomersTable extends Migration
*/
public function up()
{
Schema::create('customers', function (Blueprint $table) {
Schema::create('partners', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 60);
$table->string('email')->nullable()->unique();
@ -33,6 +33,6 @@ class CreateCustomersTable extends Migration
*/
public function down()
{
Schema::dropIfExists('customers');
Schema::dropIfExists('partners');
}
}

29
resources/lang/id/customer.php

@ -1,29 +0,0 @@
<?php
return [
// Labels
'customer' => 'Customer',
'list' => 'Daftar Customer',
'search' => 'Cari Customer',
'not_found' => 'Customer tidak ditemukan',
'empty' => 'Belum ada Customer',
'back_to_show' => 'Kembali ke detail Customer',
'back_to_index' => 'Kembali ke daftar Customer',
// Actions
'create' => 'Input Customer Baru',
'created' => 'Input Customer baru telah berhasil.',
'show' => 'Detail Customer',
'edit' => 'Edit Customer',
'update' => 'Update Customer',
'updated' => 'Update data Customer telah berhasil.',
'delete' => 'Hapus Customer',
'delete_confirm' => 'Anda yakin akan menghapus Customer ini?',
'deleted' => 'Hapus data Customer telah berhasil.',
'undeleted' => 'Data Customer gagal dihapus.',
'undeleteable' => 'Data Customer tidak dapat dihapus.',
// Attributes
'name' => 'Nama Customer',
'description' => 'Deskripsi Customer',
];

29
resources/lang/id/partner.php

@ -0,0 +1,29 @@
<?php
return [
// Labels
'partner' => 'Partner',
'list' => 'Daftar Partner',
'search' => 'Cari Partner',
'not_found' => 'Partner tidak ditemukan',
'empty' => 'Belum ada Partner',
'back_to_show' => 'Kembali ke detail Partner',
'back_to_index' => 'Kembali ke daftar Partner',
// Actions
'create' => 'Input Partner Baru',
'created' => 'Input Partner baru telah berhasil.',
'show' => 'Detail Partner',
'edit' => 'Edit Partner',
'update' => 'Update Partner',
'updated' => 'Update data Partner telah berhasil.',
'delete' => 'Hapus Partner',
'delete_confirm' => 'Anda yakin akan menghapus Partner ini?',
'deleted' => 'Hapus data Partner telah berhasil.',
'undeleted' => 'Data Partner gagal dihapus.',
'undeleteable' => 'Data Partner tidak dapat dihapus.',
// Attributes
'name' => 'Nama Partner',
'description' => 'Deskripsi Partner',
];

40
resources/views/customers/forms.blade.php → resources/views/partners/forms.blade.php

@ -1,17 +1,17 @@
@if (Request::get('action') == 'create')
{!! Form::open(['route' => 'customers.store']) !!}
{!! Form::open(['route' => 'partners.store']) !!}
{!! FormField::text('name', ['required' => true]) !!}
{!! FormField::email('email') !!}
{!! FormField::text('phone') !!}
{!! FormField::text('pic') !!}
{!! FormField::textarea('address') !!}
{!! FormField::textarea('notes') !!}
{!! Form::submit(trans('customer.create'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('customers.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::submit(trans('partner.create'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('partners.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::close() !!}
@endif
@if (Request::get('action') == 'edit' && $editableCustomer)
{!! Form::model($editableCustomer, ['route' => ['customers.update', $editableCustomer->id],'method' => 'patch']) !!}
@if (Request::get('action') == 'edit' && $editablePartner)
{!! Form::model($editablePartner, ['route' => ['partners.update', $editablePartner->id],'method' => 'patch']) !!}
{!! FormField::text('name', ['required' => true]) !!}
{!! FormField::email('email') !!}
{!! FormField::text('phone') !!}
@ -25,42 +25,42 @@
@if (request('page'))
{{ Form::hidden('page', request('page')) }}
@endif
{!! Form::submit(trans('customer.update'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('customers.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::submit(trans('partner.update'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('partners.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::close() !!}
@endif
@if (Request::get('action') == 'delete' && $editableCustomer)
@if (Request::get('action') == 'delete' && $editablePartner)
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('customer.delete') }}</h3></div>
<div class="panel-heading"><h3 class="panel-title">{{ trans('partner.delete') }}</h3></div>
<div class="panel-body">
<label class="control-label">{{ trans('customer.name') }}</label>
<p>{{ $editableCustomer->name }}</p>
<label class="control-label">{{ trans('partner.name') }}</label>
<p>{{ $editablePartner->name }}</p>
<label class="control-label">{{ trans('contact.email') }}</label>
<p>{{ $editableCustomer->email }}</p>
<p>{{ $editablePartner->email }}</p>
<label class="control-label">{{ trans('contact.phone') }}</label>
<p>{{ $editableCustomer->phone }}</p>
<p>{{ $editablePartner->phone }}</p>
<label class="control-label">{{ trans('app.address') }}</label>
<p>{{ $editableCustomer->address }}</p>
<p>{{ $editablePartner->address }}</p>
<label class="control-label">{{ trans('app.status') }}</label>
<p>{{ $editableCustomer->is_active }}</p>
<p>{{ $editablePartner->is_active }}</p>
<label class="control-label">{{ trans('app.notes') }}</label>
<p>{{ $editableCustomer->notes }}</p>
{!! $errors->first('customer_id', '<span class="form-error small">:message</span>') !!}
<p>{{ $editablePartner->notes }}</p>
{!! $errors->first('partner_id', '<span class="form-error small">:message</span>') !!}
</div>
<hr style="margin:0">
<div class="panel-body">{{ trans('app.delete_confirm') }}</div>
<div class="panel-footer">
{!! FormField::delete(
['route'=>['customers.destroy',$editableCustomer->id]],
['route'=>['partners.destroy',$editablePartner->id]],
trans('app.delete_confirm_button'),
['class'=>'btn btn-danger'],
[
'customer_id' => $editableCustomer->id,
'partner_id' => $editablePartner->id,
'page' => request('page'),
'q' => request('q'),
]
) !!}
{{ link_to_route('customers.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{{ link_to_route('partners.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
</div>
</div>
@endif

44
resources/views/customers/index.blade.php → resources/views/partners/index.blade.php

@ -1,30 +1,30 @@
@extends('layouts.app')
@section('title', trans('customer.list'))
@section('title', trans('partner.list'))
@section('content')
<h1 class="page-header">
<div class="pull-right">
{{ link_to_route('customers.index', trans('customer.create'), ['action' => 'create'], ['class' => 'btn btn-success']) }}
{{ link_to_route('partners.index', trans('partner.create'), ['action' => 'create'], ['class' => 'btn btn-success']) }}
</div>
{{ trans('customer.list') }}
<small>{{ trans('app.total') }} : {{ $customers->total() }} {{ trans('customer.customer') }}</small>
{{ trans('partner.list') }}
<small>{{ trans('app.total') }} : {{ $partners->total() }} {{ trans('partner.partner') }}</small>
</h1>
<div class="row">
<div class="col-md-9">
<div class="panel panel-default table-responsive">
<div class="panel-heading">
{{ Form::open(['method' => 'get','class' => 'form-inline']) }}
{!! FormField::text('q', ['value' => request('q'), 'label' => trans('customer.search'), 'class' => 'input-sm']) !!}
{{ Form::submit(trans('customer.search'), ['class' => 'btn btn-sm']) }}
{{ link_to_route('customers.index', trans('app.reset')) }}
{!! FormField::text('q', ['value' => request('q'), 'label' => trans('partner.search'), 'class' => 'input-sm']) !!}
{{ Form::submit(trans('partner.search'), ['class' => 'btn btn-sm']) }}
{{ link_to_route('partners.index', trans('app.reset')) }}
{{ Form::close() }}
</div>
<table class="table table-condensed">
<thead>
<tr>
<th class="text-center">{{ trans('app.table_no') }}</th>
<th>{{ trans('customer.name') }}</th>
<th>{{ trans('partner.name') }}</th>
<th>{{ trans('contact.email') }}</th>
<th>{{ trans('contact.phone') }}</th>
<th class="text-center">{{ trans('app.status') }}</th>
@ -32,36 +32,36 @@
</tr>
</thead>
<tbody>
@foreach($customers as $key => $customer)
@foreach($partners as $key => $partner)
<tr>
<td class="text-center">{{ $customers->firstItem() + $key }}</td>
<td>{{ $customer->name }}</td>
<td>{{ $customer->email }}</td>
<td>{{ $customer->phone }}</td>
<td class="text-center">{{ $customer->is_active }}</td>
<td class="text-center">{{ $partners->firstItem() + $key }}</td>
<td>{{ $partner->name }}</td>
<td>{{ $partner->email }}</td>
<td>{{ $partner->phone }}</td>
<td class="text-center">{{ $partner->is_active }}</td>
<td class="text-center">
{!! link_to_route(
'customers.index',
'partners.index',
trans('app.edit'),
['action' => 'edit', 'id' => $customer->id] + Request::only('page', 'q'),
['id' => 'edit-customer-' . $customer->id]
['action' => 'edit', 'id' => $partner->id] + Request::only('page', 'q'),
['id' => 'edit-partner-' . $partner->id]
) !!} |
{!! link_to_route(
'customers.index',
'partners.index',
trans('app.delete'),
['action' => 'delete', 'id' => $customer->id] + Request::only('page', 'q'),
['id' => 'del-customer-' . $customer->id]
['action' => 'delete', 'id' => $partner->id] + Request::only('page', 'q'),
['id' => 'del-partner-' . $partner->id]
) !!}
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="panel-body">{{ $customers->appends(Request::except('page'))->render() }}</div>
<div class="panel-body">{{ $partners->appends(Request::except('page'))->render() }}</div>
</div>
</div>
<div class="col-md-3">
@includeWhen(Request::has('action'), 'customers.forms')
@includeWhen(Request::has('action'), 'partners.forms')
</div>
</div>
@endsection

2
routes/web.php

@ -22,4 +22,4 @@ Route::group(['middleware' => ['web', 'role:admin']], function () {
Route::resource('backups', 'BackupsController', ['except' => ['create', 'show', 'edit']]);
});
Route::apiResource('customers', 'Partners\CustomersController');
Route::apiResource('partners', 'Partners\PartnersController');

108
tests/Feature/ManageCustomersTest.php

@ -1,108 +0,0 @@
<?php
namespace Tests\Feature;
use App\Entities\Partners\Customer;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase as TestCase;
class ManageCustomersTest extends TestCase
{
use DatabaseMigrations;
/** @test */
public function user_can_see_customer_list_in_customer_index_page()
{
$customer1 = factory(Customer::class)->create();
$customer2 = factory(Customer::class)->create();
$this->adminUserSigningIn();
$this->visit(route('customers.index'));
$this->see($customer1->name);
$this->see($customer2->name);
}
/** @test */
public function user_can_create_a_customer()
{
$this->adminUserSigningIn();
$this->visit(route('customers.index'));
$this->click(trans('customer.create'));
$this->seePageIs(route('customers.index', ['action' => 'create']));
$this->submitForm(trans('customer.create'), [
'name' => 'Customer 1 name',
'email' => 'customer1@mail.com',
'phone' => '081234567890',
'pic' => 'Nama PIC Customer',
'address' => 'Alamat customer 1',
'notes' => '',
]);
$this->seePageIs(route('customers.index'));
$this->seeInDatabase('customers', [
'name' => 'Customer 1 name',
'email' => 'customer1@mail.com',
'phone' => '081234567890',
'pic' => 'Nama PIC Customer',
'address' => 'Alamat customer 1',
'notes' => null,
]);
}
/** @test */
public function user_can_edit_a_customer_within_search_query()
{
$this->adminUserSigningIn();
$customer = factory(Customer::class)->create(['name' => 'Testing 123']);
$this->visit(route('customers.index', ['q' => '123']));
$this->click('edit-customer-'.$customer->id);
$this->seePageIs(route('customers.index', ['action' => 'edit', 'id' => $customer->id, 'q' => '123']));
$this->submitForm(trans('customer.update'), [
'name' => 'Customer 1 name',
'email' => 'customer1@mail.com',
'phone' => '081234567890',
'pic' => 'Nama PIC Customer',
'address' => 'Alamat customer 1',
'notes' => '',
'is_active' => 0,
]);
$this->seePageIs(route('customers.index', ['q' => '123']));
$this->seeInDatabase('customers', [
'name' => 'Customer 1 name',
'email' => 'customer1@mail.com',
'phone' => '081234567890',
'pic' => 'Nama PIC Customer',
'address' => 'Alamat customer 1',
'notes' => null,
'is_active' => 0,
]);
}
/** @test */
public function user_can_delete_a_customer()
{
$this->adminUserSigningIn();
$customer = factory(Customer::class)->create();
$this->visit(route('customers.index', [$customer->id]));
$this->click('del-customer-'.$customer->id);
$this->seePageIs(route('customers.index', ['action' => 'delete', 'id' => $customer->id]));
$this->seeInDatabase('customers', [
'id' => $customer->id,
]);
$this->press(trans('app.delete_confirm_button'));
$this->dontSeeInDatabase('customers', [
'id' => $customer->id,
]);
}
}

108
tests/Feature/ManagePartnersTest.php

@ -0,0 +1,108 @@
<?php
namespace Tests\Feature;
use App\Entities\Partners\Partner;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase as TestCase;
class ManagePartnersTest extends TestCase
{
use DatabaseMigrations;
/** @test */
public function user_can_see_partner_list_in_partner_index_page()
{
$partner1 = factory(Partner::class)->create();
$partner2 = factory(Partner::class)->create();
$this->adminUserSigningIn();
$this->visit(route('partners.index'));
$this->see($partner1->name);
$this->see($partner2->name);
}
/** @test */
public function user_can_create_a_partner()
{
$this->adminUserSigningIn();
$this->visit(route('partners.index'));
$this->click(trans('partner.create'));
$this->seePageIs(route('partners.index', ['action' => 'create']));
$this->submitForm(trans('partner.create'), [
'name' => 'Partner 1 name',
'email' => 'partner1@mail.com',
'phone' => '081234567890',
'pic' => 'Nama PIC Partner',
'address' => 'Alamat partner 1',
'notes' => '',
]);
$this->seePageIs(route('partners.index'));
$this->seeInDatabase('partners', [
'name' => 'Partner 1 name',
'email' => 'partner1@mail.com',
'phone' => '081234567890',
'pic' => 'Nama PIC Partner',
'address' => 'Alamat partner 1',
'notes' => null,
]);
}
/** @test */
public function user_can_edit_a_partner_within_search_query()
{
$this->adminUserSigningIn();
$partner = factory(Partner::class)->create(['name' => 'Testing 123']);
$this->visit(route('partners.index', ['q' => '123']));
$this->click('edit-partner-'.$partner->id);
$this->seePageIs(route('partners.index', ['action' => 'edit', 'id' => $partner->id, 'q' => '123']));
$this->submitForm(trans('partner.update'), [
'name' => 'Partner 1 name',
'email' => 'partner1@mail.com',
'phone' => '081234567890',
'pic' => 'Nama PIC Partner',
'address' => 'Alamat partner 1',
'notes' => '',
'is_active' => 0,
]);
$this->seePageIs(route('partners.index', ['q' => '123']));
$this->seeInDatabase('partners', [
'name' => 'Partner 1 name',
'email' => 'partner1@mail.com',
'phone' => '081234567890',
'pic' => 'Nama PIC Partner',
'address' => 'Alamat partner 1',
'notes' => null,
'is_active' => 0,
]);
}
/** @test */
public function user_can_delete_a_partner()
{
$this->adminUserSigningIn();
$partner = factory(Partner::class)->create();
$this->visit(route('partners.index', [$partner->id]));
$this->click('del-partner-'.$partner->id);
$this->seePageIs(route('partners.index', ['action' => 'delete', 'id' => $partner->id]));
$this->seeInDatabase('partners', [
'id' => $partner->id,
]);
$this->press(trans('app.delete_confirm_button'));
$this->dontSeeInDatabase('partners', [
'id' => $partner->id,
]);
}
}

40
tests/Feature/ManageProjectsTest.php

@ -2,7 +2,7 @@
namespace Tests\Feature;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use App\Entities\Payments\Payment;
use App\Entities\Projects\Feature;
use App\Entities\Projects\Project;
@ -12,17 +12,17 @@ use Tests\TestCase;
class ManageProjectsTest extends TestCase
{
/** @test */
public function admin_can_input_new_project_with_existing_customer()
public function admin_can_input_new_project_with_existing_partner()
{
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create();
$user = $this->adminUserSigningIn();
$partner = factory(Partner::class)->create();
$this->visit(route('projects.index'));
$this->seePageIs(route('projects.index'));
$this->click(trans('project.create'));
$this->seePageIs(route('projects.create'));
$this->type('Project Baru', 'name');
$this->select($customer->id, 'customer_id');
$this->select($partner->id, 'customer_id');
$this->type('2016-04-15', 'proposal_date');
$this->type('2000000', 'proposal_value');
$this->type('Deskripsi project baru', 'description');
@ -34,7 +34,7 @@ class ManageProjectsTest extends TestCase
}
/** @test */
public function admin_can_input_new_project_with_new_customer()
public function admin_can_input_new_project_with_new_partner()
{
$this->adminUserSigningIn();
@ -53,21 +53,21 @@ class ManageProjectsTest extends TestCase
$this->seePageIs(route('projects.create'));
$this->notSeeInDatabase('projects', ['name' => 'Project Baru', 'proposal_value' => '2000000']);
$this->type('Customer Baru', 'customer_name');
$this->type('email@customer.baru', 'customer_email');
$this->type('Partner Baru', 'customer_name');
$this->type('email@partner.baru', 'customer_email');
$this->press(trans('project.create'));
$this->see(trans('project.created'));
$this->see('Project Baru');
$this->seeInDatabase('customers', [
'name' => 'Customer Baru',
'email' => 'email@customer.baru',
$this->seeInDatabase('partners', [
'name' => 'Partner Baru',
'email' => 'email@partner.baru',
]);
$newCustomer = Customer::whereName('Customer Baru')->whereEmail('email@customer.baru')->first();
$newPartner = Partner::whereName('Partner Baru')->whereEmail('email@partner.baru')->first();
$this->seeInDatabase('projects', [
'name' => 'Project Baru',
'proposal_value' => '2000000',
'customer_id' => $newCustomer->id,
'customer_id' => $newPartner->id,
]);
}
@ -110,9 +110,9 @@ class ManageProjectsTest extends TestCase
/** @test */
public function admin_can_edit_a_project()
{
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create();
$project = factory(Project::class)->create(['owner_id' => $user->id]);
$user = $this->adminUserSigningIn();
$partner = factory(Partner::class)->create();
$project = factory(Project::class)->create(['owner_id' => $user->id]);
$this->visit('projects/'.$project->id.'/edit');
$this->seePageIs('projects/'.$project->id.'/edit');
@ -124,7 +124,7 @@ class ManageProjectsTest extends TestCase
$this->type(2000000, 'proposal_value');
$this->type(2000000, 'project_value');
$this->select(4, 'status_id');
$this->select($customer->id, 'customer_id');
$this->select($partner->id, 'customer_id');
$this->type('Edit deskripsi project', 'description');
$this->press(trans('project.update'));
@ -134,7 +134,7 @@ class ManageProjectsTest extends TestCase
'proposal_date' => '2016-04-15',
'start_date' => '2016-04-25',
'end_date' => '2016-05-05',
'customer_id' => $customer->id,
'customer_id' => $partner->id,
'description' => 'Edit deskripsi project',
]);
}
@ -144,14 +144,14 @@ class ManageProjectsTest extends TestCase
{
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create();
$partner = factory(Partner::class)->create();
$this->visit(route('projects.index'));
$this->seePageIs(route('projects.index'));
$this->click(trans('project.create'));
$this->seePageIs(route('projects.create'));
$this->type('', 'name');
$this->select($customer->id, 'customer_id');
$this->select($partner->id, 'customer_id');
$this->type('2016-04-15aa', 'proposal_date');
$this->type('', 'proposal_value');
$this->type('Deskripsi project baru', 'description');

10
tests/Feature/ManageSubscriptionsTest.php

@ -2,7 +2,7 @@
namespace Tests\Feature;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use App\Entities\Projects\Project;
use App\Entities\Subscriptions\Subscription;
use Tests\TestCase;
@ -13,9 +13,9 @@ class ManageSubscriptionsTest extends TestCase
public function admin_can_entry_subscription()
{
$user = $this->adminUserSigningIn();
$vendor = factory(Customer::class)->create();
$vendor = factory(Partner::class)->create();
$project = factory(Project::class)->create();
$customer = factory(Customer::class)->create();
$customer = factory(Partner::class)->create();
$this->visit(route('subscriptions.index'));
$this->click(trans('subscription.create'));
@ -53,10 +53,10 @@ class ManageSubscriptionsTest extends TestCase
public function admin_can_edit_subscription_data()
{
$user = $this->adminUserSigningIn();
$vendor = factory(Customer::class)->create();
$vendor = factory(Partner::class)->create();
$eppCode = str_random(10);
$project = factory(Project::class)->create();
$customer = factory(Customer::class)->create();
$customer = factory(Partner::class)->create();
$subscription = factory(Subscription::class)->create(['customer_id' => $customer->id, 'project_id' => $project->id]);

8
tests/Feature/Payments/ManagePaymentsTest.php

@ -2,7 +2,7 @@
namespace Tests\Feature\Payments;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use App\Entities\Payments\Payment;
use App\Entities\Projects\Project;
use Tests\TestCase;
@ -13,7 +13,7 @@ class ManagePaymentsTest extends TestCase
public function admin_can_entry_project_an_income_payment()
{
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create();
$customer = factory(Partner::class)->create();
$project = factory(Project::class)->create();
$this->visit(route('payments.index'));
@ -44,7 +44,7 @@ class ManagePaymentsTest extends TestCase
public function admin_can_entry_project_an_expanse_payment()
{
$user = $this->adminUserSigningIn();
$vendor = factory(Customer::class)->create();
$vendor = factory(Partner::class)->create();
$project = factory(Project::class)->create();
$this->visit(route('payments.index'));
@ -76,7 +76,7 @@ class ManagePaymentsTest extends TestCase
public function admin_can_edit_payment_data()
{
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create();
$customer = factory(Partner::class)->create();
$project = factory(Project::class)->create();
$payment = factory(Payment::class)->create([

8
tests/Unit/Models/CustomerTest.php → tests/Unit/Models/PartnerTest.php

@ -2,18 +2,18 @@
namespace Tests\Unit\Models;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase as TestCase;
class CustomerTest extends TestCase
class PartnerTest extends TestCase
{
use DatabaseMigrations;
/** @test */
public function it_has_name_attribute()
{
$customer = factory(Customer::class)->create(['name' => 'Customer 1 name']);
$this->assertEquals('Customer 1 name', $customer->name);
$partner = factory(Partner::class)->create(['name' => 'Partner 1 name']);
$this->assertEquals('Partner 1 name', $partner->name);
}
}

4
tests/Unit/Models/PaymentTest.php

@ -2,7 +2,7 @@
namespace Tests\Unit\Models;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use App\Entities\Payments\Payment;
use Tests\TestCase;
@ -12,6 +12,6 @@ class PaymentTest extends TestCase
public function it_has_partner_relation()
{
$payment = factory(Payment::class)->create();
$this->assertTrue($payment->partner instanceof Customer);
$this->assertTrue($payment->partner instanceof Partner);
}
}

13
tests/Unit/Models/ProjectTest.php

@ -2,13 +2,12 @@
namespace Tests\Unit\Models;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use App\Entities\Payments\Payment;
use App\Entities\Projects\Feature;
use App\Entities\Projects\Project;
use App\Entities\Projects\Task;
use App\Entities\Subscriptions\Subscription;
use App\Entities\Users\User;
use Illuminate\Support\Collection;
use Tests\TestCase;
@ -46,7 +45,7 @@ class ProjectTest extends TestCase
{
$project = factory(Project::class)->create();
$feature = factory(Feature::class)->create(['project_id' => $project->id, 'type_id' => 2]);
$tasks = factory(Task::class, 2)->create(['feature_id' => $feature->id]);
$tasks = factory(Task::class, 2)->create(['feature_id' => $feature->id]);
$this->assertTrue($project->tasks instanceof Collection);
$this->assertTrue($project->tasks->first() instanceof Task);
}
@ -63,7 +62,7 @@ class ProjectTest extends TestCase
/** @test */
public function a_project_has_many_subscriptions()
{
$project = factory(Project::class)->create();
$project = factory(Project::class)->create();
$subscription = factory(Subscription::class)->create(['project_id' => $project->id]);
$this->assertTrue($project->subscriptions instanceof Collection);
$this->assertTrue($project->subscriptions->first() instanceof Subscription);
@ -73,13 +72,13 @@ class ProjectTest extends TestCase
public function a_project_belongs_to_a_customer()
{
$project = factory(Project::class)->create();
$this->assertTrue($project->customer instanceof Customer);
$this->assertTrue($project->customer instanceof Partner);
}
/** @test */
public function a_project_has_cash_in_total_method()
{
$project = factory(Project::class)->create();
$project = factory(Project::class)->create();
$payments = factory(Payment::class, 2)->create(['project_id' => $project->id, 'in_out' => 1, 'amount' => 20000]);
$this->assertEquals(40000, $project->cashInTotal());
}
@ -87,7 +86,7 @@ class ProjectTest extends TestCase
/** @test */
public function a_project_has_cash_out_total_method()
{
$project = factory(Project::class)->create();
$project = factory(Project::class)->create();
$payments = factory(Payment::class, 2)->create(['project_id' => $project->id, 'in_out' => 0, 'amount' => 10000]);
factory(Payment::class)->create(['project_id' => $project->id, 'in_out' => 1, 'amount' => 10000]);
$this->assertEquals(20000, $project->cashOutTotal());

4
tests/Unit/Models/SubscriptionTest.php

@ -2,7 +2,7 @@
namespace Tests\Unit\Models;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Partner;
use App\Entities\Subscriptions\Subscription;
use Tests\TestCase as TestCase;
@ -19,6 +19,6 @@ class SubscriptionTest extends TestCase
public function it_has_customer_relation()
{
$subscription = factory(Subscription::class)->create();
$this->assertTrue($subscription->customer instanceof Customer);
$this->assertTrue($subscription->customer instanceof Partner);
}
}

43
tests/Unit/Policies/CustomerPolicyTest.php

@ -1,43 +0,0 @@
<?php
namespace Tests\Unit\Policies;
use App\Entities\Partners\Customer;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase as TestCase;
class CustomerTest extends TestCase
{
use DatabaseMigrations;
/** @test */
public function user_can_create_customer()
{
$user = $this->adminUserSigningIn();
$this->assertTrue($user->can('create', new Customer));
}
/** @test */
public function user_can_view_customer()
{
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create(['name' => 'Customer 1 name']);
$this->assertTrue($user->can('view', $customer));
}
/** @test */
public function user_can_update_customer()
{
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create(['name' => 'Customer 1 name']);
$this->assertTrue($user->can('update', $customer));
}
/** @test */
public function user_can_delete_customer()
{
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create(['name' => 'Customer 1 name']);
$this->assertTrue($user->can('delete', $customer));
}
}

43
tests/Unit/Policies/PartnerPolicyTest.php

@ -0,0 +1,43 @@
<?php
namespace Tests\Unit\Policies;
use App\Entities\Partners\Partner;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase as TestCase;
class PartnerTest extends TestCase
{
use DatabaseMigrations;
/** @test */
public function user_can_create_partner()
{
$user = $this->adminUserSigningIn();
$this->assertTrue($user->can('create', new Partner));
}
/** @test */
public function user_can_view_partner()
{
$user = $this->adminUserSigningIn();
$partner = factory(Partner::class)->create(['name' => 'Partner 1 name']);
$this->assertTrue($user->can('view', $partner));
}
/** @test */
public function user_can_update_partner()
{
$user = $this->adminUserSigningIn();
$partner = factory(Partner::class)->create(['name' => 'Partner 1 name']);
$this->assertTrue($user->can('update', $partner));
}
/** @test */
public function user_can_delete_partner()
{
$user = $this->adminUserSigningIn();
$partner = factory(Partner::class)->create(['name' => 'Partner 1 name']);
$this->assertTrue($user->can('delete', $partner));
}
}
Loading…
Cancel
Save