From 990dc3930fb82d08c40c6b17fcef20a8e5716bc9 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Wed, 1 Nov 2017 15:30:55 +0800 Subject: [PATCH] Change Partner entity back to Customer entity --- app/Entities/BaseRepository.php | 8 +- .../Partners/{Partner.php => Customer.php} | 6 +- app/Entities/Payments/Payment.php | 3 +- app/Entities/Projects/Project.php | 4 +- app/Entities/Projects/ProjectsRepository.php | 4 +- app/Entities/Subscriptions/Subscription.php | 2 +- .../Controllers/Partners/CustomersController.php | 140 ++++++++++++++++++++ .../Controllers/Partners/PartnersController.php | 145 --------------------- app/Http/Controllers/PaymentsController.php | 4 +- app/Policies/Partners/CustomerPolicy.php | 64 +++++++++ app/Policies/Partners/PartnerPolicy.php | 64 --------- app/Providers/AuthServiceProvider.php | 8 +- .../{PartnerFactory.php => CustomerFactory.php} | 6 +- database/factories/ModelFactory.php | 4 +- database/factories/PaymentFactory.php | 4 +- database/factories/ProjectFactory.php | 4 +- ...> 2017_10_26_134455_create_customers_table.php} | 6 +- resources/lang/id/customer.php | 34 +++++ resources/lang/id/partner.php | 40 ------ .../views/{partners => customers}/create.blade.php | 16 +-- .../views/{partners => customers}/edit.blade.php | 22 ++-- .../views/{partners => customers}/forms.blade.php | 26 ++-- resources/views/customers/index.blade.php | 50 +++++++ .../views/{partners => customers}/show.blade.php | 30 ++--- resources/views/layouts/partials/sidebar.blade.php | 2 +- resources/views/partners/index.blade.php | 50 ------- routes/web.php | 4 +- tests/Feature/InvoiceEntryTest.php | 4 +- tests/Feature/ManageFeaturesTest.php | 10 +- tests/Feature/ManagePartnersTest.php | 109 ---------------- tests/Feature/ManageProjectsTest.php | 56 ++++---- tests/Feature/ManageSubscriptionsTest.php | 14 +- tests/Feature/Partners/ManageCustomersTest.php | 109 ++++++++++++++++ tests/Feature/Payments/ManagePaymentsTest.php | 12 +- tests/Feature/Payments/PaymentSearchTest.php | 8 +- tests/Unit/Models/CustomerTest.php | 46 +++++++ tests/Unit/Models/PartnerTest.php | 46 ------- tests/Unit/Models/PaymentTest.php | 4 +- tests/Unit/Models/ProjectTest.php | 6 +- tests/Unit/Models/SubscriptionTest.php | 4 +- tests/Unit/Policies/CustomerPolicyTest.php | 40 ++++++ tests/Unit/Policies/PartnerPolicyTest.php | 40 ------ 42 files changed, 623 insertions(+), 635 deletions(-) rename app/Entities/Partners/{Partner.php => Customer.php} (77%) create mode 100644 app/Http/Controllers/Partners/CustomersController.php delete mode 100644 app/Http/Controllers/Partners/PartnersController.php create mode 100644 app/Policies/Partners/CustomerPolicy.php delete mode 100644 app/Policies/Partners/PartnerPolicy.php rename database/factories/{PartnerFactory.php => CustomerFactory.php} (70%) rename database/migrations/{2017_10_26_134455_create_partners_table.php => 2017_10_26_134455_create_customers_table.php} (84%) create mode 100644 resources/lang/id/customer.php delete mode 100644 resources/lang/id/partner.php rename resources/views/{partners => customers}/create.blade.php (65%) rename resources/views/{partners => customers}/edit.blade.php (59%) rename resources/views/{partners => customers}/forms.blade.php (58%) create mode 100644 resources/views/customers/index.blade.php rename resources/views/{partners => customers}/show.blade.php (55%) delete mode 100644 resources/views/partners/index.blade.php delete mode 100644 tests/Feature/ManagePartnersTest.php create mode 100644 tests/Feature/Partners/ManageCustomersTest.php create mode 100644 tests/Unit/Models/CustomerTest.php delete mode 100644 tests/Unit/Models/PartnerTest.php create mode 100644 tests/Unit/Policies/CustomerPolicyTest.php delete mode 100644 tests/Unit/Policies/PartnerPolicyTest.php diff --git a/app/Entities/BaseRepository.php b/app/Entities/BaseRepository.php index 7078a59..c4cdaca 100755 --- a/app/Entities/BaseRepository.php +++ b/app/Entities/BaseRepository.php @@ -2,7 +2,7 @@ namespace App\Entities; -use App\Entities\Partners\Partner; +use App\Entities\Partners\Customer; 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 Partner::orderBy('name')->pluck('name', 'id'); + return Customer::orderBy('name')->pluck('name', 'id'); } public function getCustomersAndVendorsList() { - return Partner::orderBy('name')->pluck('name', 'id'); + return Customer::orderBy('name')->pluck('name', 'id'); } public function getWorkersList() @@ -30,7 +30,7 @@ abstract class BaseRepository extends EloquentRepository public function getVendorsList() { - return Partner::orderBy('name')->pluck('name', 'id'); + return Customer::orderBy('name')->pluck('name', 'id'); } public function getProjectsList() diff --git a/app/Entities/Partners/Partner.php b/app/Entities/Partners/Customer.php similarity index 77% rename from app/Entities/Partners/Partner.php rename to app/Entities/Partners/Customer.php index 32d82fb..424b570 100644 --- a/app/Entities/Partners/Partner.php +++ b/app/Entities/Partners/Customer.php @@ -5,7 +5,7 @@ namespace App\Entities\Partners; use App\Traits\OwnedByAgency; use Illuminate\Database\Eloquent\Model; -class Partner extends Model +class Customer extends Model { use OwnedByAgency; @@ -23,10 +23,10 @@ class Partner extends Model public function nameLink() { - return link_to_route('partners.show', $this->name, [$this->id], [ + return link_to_route('customers.show', $this->name, [$this->id], [ 'title' => trans( 'app.show_detail_title', - ['name' => $this->name, 'type' => trans('partner.partner')] + ['name' => $this->name, 'type' => trans('customer.customer')] ), ]); } diff --git a/app/Entities/Payments/Payment.php b/app/Entities/Payments/Payment.php index b01d2bf..bcf44aa 100755 --- a/app/Entities/Payments/Payment.php +++ b/app/Entities/Payments/Payment.php @@ -2,7 +2,6 @@ namespace App\Entities\Payments; -use App\Entities\Partners\Partner; use App\Entities\Payments\PaymentPresenter; use App\Entities\Projects\Project; use Illuminate\Database\Eloquent\Builder; @@ -35,7 +34,7 @@ class Payment extends Model public function partner() { - return $this->belongsTo(Partner::class, 'partner_id'); + return $this->belongsTo('App\Entities\Partners\Customer', 'partner_id'); } public function type() diff --git a/app/Entities/Projects/Project.php b/app/Entities/Projects/Project.php index 5ef96ab..72ebc9e 100755 --- a/app/Entities/Projects/Project.php +++ b/app/Entities/Projects/Project.php @@ -4,7 +4,7 @@ namespace App\Entities\Projects; use App\Entities\Agencies\Agency; use App\Entities\Invoices\Invoice; -use App\Entities\Partners\Partner; +use App\Entities\Partners\Customer; use App\Entities\Payments\Payment; use App\Entities\Projects\ProjectPresenter; use App\Entities\Projects\Task; @@ -63,7 +63,7 @@ class Project extends Model public function customer() { - return $this->belongsTo(Partner::class); + return $this->belongsTo(Customer::class); } public function owner() diff --git a/app/Entities/Projects/ProjectsRepository.php b/app/Entities/Projects/ProjectsRepository.php index 3150e60..2131ced 100755 --- a/app/Entities/Projects/ProjectsRepository.php +++ b/app/Entities/Projects/ProjectsRepository.php @@ -3,7 +3,7 @@ namespace App\Entities\Projects; use App\Entities\BaseRepository; -use App\Entities\Partners\Partner; +use App\Entities\Partners\Customer; use DB; /** @@ -60,7 +60,7 @@ class ProjectsRepository extends BaseRepository public function createNewCustomer($customerName, $customerEmail) { - $newCustomer = new Partner; + $newCustomer = new Customer; $newCustomer->name = $customerName; $newCustomer->email = $customerEmail; $newCustomer->owner_id = auth()->user()->agency->id; diff --git a/app/Entities/Subscriptions/Subscription.php b/app/Entities/Subscriptions/Subscription.php index ba3d77a..90eee3f 100755 --- a/app/Entities/Subscriptions/Subscription.php +++ b/app/Entities/Subscriptions/Subscription.php @@ -19,7 +19,7 @@ class Subscription extends Model public function vendor() { - return $this->belongsTo('App\Entities\Partners\Partner'); + return $this->belongsTo('App\Entities\Partners\Customer'); } public function status() diff --git a/app/Http/Controllers/Partners/CustomersController.php b/app/Http/Controllers/Partners/CustomersController.php new file mode 100644 index 0000000..16ef193 --- /dev/null +++ b/app/Http/Controllers/Partners/CustomersController.php @@ -0,0 +1,140 @@ +where('name', 'like', '%'.request('q').'%'); + }) + ->withCount('projects') + ->paginate(25); + + if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) { + $editableCustomer = Customer::find(request('id')); + } + + return view('customers.index', compact('customers', 'editableCustomer')); + } + + /** + * Show the create customer form. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + return view('customers.create'); + } + + /** + * 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', + ]); + + $newCustomerData['owner_id'] = auth()->user()->agency->id; + + Customer::create($newCustomerData); + + flash(trans('customer.created'), 'success'); + + return redirect()->route('customers.index'); + } + + /** + * Show the specified customer. + * + * @param \App\Entities\Partners\Customer $customer + * @return \Illuminate\Http\Response + */ + public function show(Customer $customer) + { + return view('customers.show', compact('customer')); + } + + /** + * Show the edit customer form. + * + * @param \App\Entities\Partners\Customer $customer + * @return \Illuminate\Http\Response + */ + public function edit(Customer $customer) + { + return view('customers.edit', compact('customer')); + } + + /** + * 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', + ]); + + $customer->update($customerData); + + flash(trans('customer.updated'), 'success'); + + return redirect()->route('customers.show', $customer->id); + } + + /** + * 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(); + } +} diff --git a/app/Http/Controllers/Partners/PartnersController.php b/app/Http/Controllers/Partners/PartnersController.php deleted file mode 100644 index 79c3320..0000000 --- a/app/Http/Controllers/Partners/PartnersController.php +++ /dev/null @@ -1,145 +0,0 @@ - trans('partner.types.customer'), - 2 => trans('partner.types.vendor'), - ]; - - $partners = Partner::where(function ($query) { - $query->where('name', 'like', '%'.request('q').'%'); - }) - ->withCount('projects') - ->paginate(25); - - if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) { - $editablePartner = Partner::find(request('id')); - } - - return view('partners.index', compact('partners', 'partnerTypes', 'editablePartner')); - } - - /** - * Show the create partner form. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - return view('partners.create'); - } - - /** - * 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', - ]); - - $newPartnerData['owner_id'] = auth()->user()->agency->id; - - Partner::create($newPartnerData); - - flash(trans('partner.created'), 'success'); - - return redirect()->route('partners.index'); - } - - /** - * Show the specified partner. - * - * @param \App\Entities\Partners\Partner $partner - * @return \Illuminate\Http\Response - */ - public function show(Partner $partner) - { - return view('partners.show', compact('partner')); - } - - /** - * Show the edit partner form. - * - * @param \App\Entities\Partners\Partner $partner - * @return \Illuminate\Http\Response - */ - public function edit(Partner $partner) - { - return view('partners.edit', compact('partner')); - } - - /** - * 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', - ]); - - $partner->update($partnerData); - - flash(trans('partner.updated'), 'success'); - - return redirect()->route('partners.show', $partner->id); - } - - /** - * 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(); - } -} diff --git a/app/Http/Controllers/PaymentsController.php b/app/Http/Controllers/PaymentsController.php index 2e2d90a..6e88ab2 100755 --- a/app/Http/Controllers/PaymentsController.php +++ b/app/Http/Controllers/PaymentsController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\Entities\Partners\Partner; +use App\Entities\Partners\Customer; use App\Entities\Payments\Payment; use App\Entities\Payments\PaymentsRepository; use App\Http\Requests\Payments\CreateRequest; @@ -22,7 +22,7 @@ class PaymentsController extends Controller public function index(Request $request) { $payments = $this->repo->getPayments($request->only('q', 'partner_id')); - $partnersList = Partner::pluck('name', 'id')->all(); + $partnersList = Customer::pluck('name', 'id')->all(); return view('payments.index', compact('payments', 'partnersList')); } diff --git a/app/Policies/Partners/CustomerPolicy.php b/app/Policies/Partners/CustomerPolicy.php new file mode 100644 index 0000000..f5d9322 --- /dev/null +++ b/app/Policies/Partners/CustomerPolicy.php @@ -0,0 +1,64 @@ + 'App\Policies\Partners\PartnerPolicy', - 'App\Entities\Projects\Project' => 'App\Policies\Projects\ProjectPolicy', - 'App\Entities\Agencies\Agency' => 'App\Policies\AgencyPolicy', - 'App\Entities\Users\Event' => 'App\Policies\EventPolicy', + 'App\Entities\Partners\Customer' => 'App\Policies\Partners\CustomerPolicy', + 'App\Entities\Projects\Project' => 'App\Policies\Projects\ProjectPolicy', + 'App\Entities\Agencies\Agency' => 'App\Policies\AgencyPolicy', + 'App\Entities\Users\Event' => 'App\Policies\EventPolicy', ]; /** diff --git a/database/factories/PartnerFactory.php b/database/factories/CustomerFactory.php similarity index 70% rename from database/factories/PartnerFactory.php rename to database/factories/CustomerFactory.php index 0e165f1..dd2bcb1 100644 --- a/database/factories/PartnerFactory.php +++ b/database/factories/CustomerFactory.php @@ -1,10 +1,10 @@ define(Partner::class, function (Faker $faker) { +$factory->define(Customer::class, function (Faker $faker) { return [ 'name' => $faker->company, @@ -12,4 +12,4 @@ $factory->define(Partner::class, function (Faker $faker) { return factory(Agency::class)->create()->id; }, ]; -}); \ No newline at end of file +}); diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 3482f98..b6148a0 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -1,7 +1,7 @@ define(Subscription::class, function (Faker\Generator $faker) { 'due_date' => $startDate->addYears(1)->format('Y-m-d'), 'remark' => $faker->paragraph, 'vendor_id' => function () { - return factory(Partner::class)->create()->id; + return factory(Customer::class)->create()->id; }, ]; }); diff --git a/database/factories/PaymentFactory.php b/database/factories/PaymentFactory.php index 7398b4f..fdf57a4 100644 --- a/database/factories/PaymentFactory.php +++ b/database/factories/PaymentFactory.php @@ -1,6 +1,6 @@ define(Payment::class, function (Faker $faker) { 'date' => $faker->dateTimeBetween('-1 year', '-1 month')->format('Y-m-d'), 'description' => $faker->paragraph, 'partner_id' => function () { - return factory(Partner::class)->create()->id; + return factory(Customer::class)->create()->id; }, ]; }); diff --git a/database/factories/ProjectFactory.php b/database/factories/ProjectFactory.php index a289003..746cb09 100644 --- a/database/factories/ProjectFactory.php +++ b/database/factories/ProjectFactory.php @@ -1,7 +1,7 @@ define(Project::class, function (Faker $faker) { return factory(Agency::class)->create()->id; }, 'customer_id' => function () { - return factory(Partner::class)->create()->id; + return factory(Customer::class)->create()->id; }, ]; }); diff --git a/database/migrations/2017_10_26_134455_create_partners_table.php b/database/migrations/2017_10_26_134455_create_customers_table.php similarity index 84% rename from database/migrations/2017_10_26_134455_create_partners_table.php rename to database/migrations/2017_10_26_134455_create_customers_table.php index 9c55395..37678f2 100644 --- a/database/migrations/2017_10_26_134455_create_partners_table.php +++ b/database/migrations/2017_10_26_134455_create_customers_table.php @@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreatePartnersTable extends Migration +class CreateCustomersTable extends Migration { /** * Run the migrations. @@ -13,7 +13,7 @@ class CreatePartnersTable extends Migration */ public function up() { - Schema::create('partners', function (Blueprint $table) { + Schema::create('customers', function (Blueprint $table) { $table->increments('id'); $table->string('name', 60); $table->string('email')->nullable()->unique(); @@ -34,6 +34,6 @@ class CreatePartnersTable extends Migration */ public function down() { - Schema::dropIfExists('partners'); + Schema::dropIfExists('customers'); } } diff --git a/resources/lang/id/customer.php b/resources/lang/id/customer.php new file mode 100644 index 0000000..09fceb6 --- /dev/null +++ b/resources/lang/id/customer.php @@ -0,0 +1,34 @@ + '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', + 'type' => 'Jenis Customer', + 'detail' => 'Detail Customer', + 'contact' => 'Kontak 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', + 'pic' => 'PIC', + 'projects_count' => 'Jml Project', +]; diff --git a/resources/lang/id/partner.php b/resources/lang/id/partner.php deleted file mode 100644 index 1c2c72f..0000000 --- a/resources/lang/id/partner.php +++ /dev/null @@ -1,40 +0,0 @@ - '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', - 'type' => 'Jenis Partner', - 'detail' => 'Detail Partner', - 'contact' => 'Kontak 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', - 'pic' => 'PIC', - 'projects_count' => 'Jml Project', - - // Types - 'types' => [ - 'customer' => 'Customer', - 'vendor' => 'Vendor', - ], -]; diff --git a/resources/views/partners/create.blade.php b/resources/views/customers/create.blade.php similarity index 65% rename from resources/views/partners/create.blade.php rename to resources/views/customers/create.blade.php index cc94a6e..b1ac436 100644 --- a/resources/views/partners/create.blade.php +++ b/resources/views/customers/create.blade.php @@ -1,28 +1,28 @@ @extends('layouts.app') -@section('title', trans('partner.create')) +@section('title', trans('customer.create')) @section('content')

- {{ link_to_route('partners.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} + {{ link_to_route('customers.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
- {{ trans('partner.create') }} + {{ trans('customer.create') }}

-{!! Form::open(['route' => 'partners.store']) !!} +{!! Form::open(['route' => 'customers.store']) !!}
- @lang('partner.detail') + @lang('customer.detail') {!! FormField::text('name', ['required' => true]) !!} {!! FormField::textarea('notes') !!}
- @lang('partner.contact') + @lang('customer.contact') {!! FormField::text('pic') !!}
{!! FormField::email('email') !!}
@@ -33,8 +33,8 @@
diff --git a/resources/views/partners/edit.blade.php b/resources/views/customers/edit.blade.php similarity index 59% rename from resources/views/partners/edit.blade.php rename to resources/views/customers/edit.blade.php index d312c62..772b8ac 100644 --- a/resources/views/partners/edit.blade.php +++ b/resources/views/customers/edit.blade.php @@ -1,25 +1,25 @@ @extends('layouts.app') -@section('title', trans('partner.edit').' '.$partner->name) +@section('title', trans('customer.edit').' '.$customer->name) @section('content')

- {{ link_to_route('partners.show', trans('partner.back_to_show'), [$partner->id], ['class' => 'btn btn-default']) }} + {{ link_to_route('customers.show', trans('customer.back_to_show'), [$customer->id], ['class' => 'btn btn-default']) }}
- {{ $partner->name }} {{ trans('partner.edit') }} + {{ $customer->name }} {{ trans('customer.edit') }}

-@includeWhen(Request::has('action'), 'partners.forms') +@includeWhen(Request::has('action'), 'customers.forms') -{!! Form::model($partner, ['route' => ['partners.update', $partner->id],'method' => 'patch']) !!} +{!! Form::model($customer, ['route' => ['customers.update', $customer->id],'method' => 'patch']) !!}
- @lang('partner.detail') + @lang('customer.detail') {!! FormField::text('name', ['required' => true]) !!}
{!! FormField::radios('is_active', ['Non Aktif', 'Aktif']) !!}
@@ -27,7 +27,7 @@ {!! FormField::textarea('notes') !!}
- @lang('partner.contact') + @lang('customer.contact') {!! FormField::text('pic') !!}
{!! FormField::email('email') !!}
@@ -38,10 +38,10 @@
diff --git a/resources/views/partners/forms.blade.php b/resources/views/customers/forms.blade.php similarity index 58% rename from resources/views/partners/forms.blade.php rename to resources/views/customers/forms.blade.php index 0110ab0..2cd2e5c 100644 --- a/resources/views/partners/forms.blade.php +++ b/resources/views/customers/forms.blade.php @@ -1,37 +1,37 @@ -@if (Request::get('action') == 'delete' && $partner) +@if (Request::get('action') == 'delete' && $customer)
-

{{ trans('partner.delete') }}

+

{{ trans('customer.delete') }}

- -

{{ $partner->name }}

+ +

{{ $customer->name }}

-

{{ $partner->email }}

+

{{ $customer->email }}

-

{{ $partner->phone }}

+

{{ $customer->phone }}

-

{{ $partner->address }}

+

{{ $customer->address }}

-

{{ $partner->is_active }}

+

{{ $customer->is_active }}

-

{{ $partner->notes }}

- {!! $errors->first('partner_id', ':message') !!} +

{{ $customer->notes }}

+ {!! $errors->first('customer_id', ':message') !!}

{{ trans('app.delete_confirm') }}
diff --git a/resources/views/customers/index.blade.php b/resources/views/customers/index.blade.php new file mode 100644 index 0000000..911d4d4 --- /dev/null +++ b/resources/views/customers/index.blade.php @@ -0,0 +1,50 @@ +@extends('layouts.app') + +@section('title', trans('customer.list')) + +@section('content') +

+
+ {{ link_to_route('customers.create', trans('customer.create'), [], ['class' => 'btn btn-success']) }} +
+ {{ trans('customer.list') }} + {{ trans('app.total') }} : {{ $customers->total() }} {{ trans('customer.customer') }} +

+ +
+
+ {{ 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')) }} + {{ Form::close() }} +
+ + + + + + + + + + + + + @foreach($customers as $key => $customer) + + + + + + + + + @endforeach + +
{{ trans('app.table_no') }}{{ trans('customer.name') }}{{ trans('contact.email') }}{{ trans('contact.phone') }}{{ trans('customer.projects_count') }}{{ trans('app.status') }}
{{ $customers->firstItem() + $key }}{{ $customer->nameLink() }}{{ $customer->email }}{{ $customer->phone }}{{ $customer->projects_count }}{{ $customer->is_active }}
+
{{ $customers->appends(Request::except('page'))->render() }}
+
+
+
+@endsection diff --git a/resources/views/partners/show.blade.php b/resources/views/customers/show.blade.php similarity index 55% rename from resources/views/partners/show.blade.php rename to resources/views/customers/show.blade.php index 780e869..bfcb784 100755 --- a/resources/views/partners/show.blade.php +++ b/resources/views/customers/show.blade.php @@ -1,29 +1,29 @@ @extends('layouts.app') -@section('title', trans('partner.show')) +@section('title', trans('customer.show')) @section('content')

- {!! link_to_route('partners.edit', trans('partner.edit'), [$partner->id], ['id' => 'edit-partner-' . $partner->id, 'class' => 'btn btn-warning']) !!} - {!! link_to_route('partners.index', trans('partner.back_to_index'), [], ['class' => 'btn btn-default']) !!} + {!! link_to_route('customers.edit', trans('customer.edit'), [$customer->id], ['id' => 'edit-customer-' . $customer->id, 'class' => 'btn btn-warning']) !!} + {!! link_to_route('customers.index', trans('customer.back_to_index'), [], ['class' => 'btn btn-default']) !!}
- {{ $partner->name }} {{ trans('partner.show') }} + {{ $customer->name }} {{ trans('customer.show') }}

-

{{ trans('partner.show') }}

+

{{ trans('customer.show') }}

- - - - - - - + + + + + + +
{{ trans('partner.name') }}{{ $partner->name }}
{{ trans('contact.email') }}{{ $partner->email }}
{{ trans('contact.phone') }}{{ $partner->phone }}
{{ trans('partner.pic') }}{{ $partner->pic }}
{{ trans('address.address') }}{{ $partner->address }}
{{ trans('app.status') }}{{ $partner->is_active }}
{{ trans('app.notes') }}{!! nl2br($partner->notes) !!}
{{ trans('customer.name') }}{{ $customer->name }}
{{ trans('contact.email') }}{{ $customer->email }}
{{ trans('contact.phone') }}{{ $customer->phone }}
{{ trans('customer.pic') }}{{ $customer->pic }}
{{ trans('address.address') }}{{ $customer->address }}
{{ trans('app.status') }}{{ $customer->is_active }}
{{ trans('app.notes') }}{!! nl2br($customer->notes) !!}
@@ -31,14 +31,14 @@
- +
-
{{ $partner->projects()->count() }}
-
@lang('partner.projects_count')
+
{{ $customer->projects()->count() }}
+
@lang('customer.projects_count')
diff --git a/resources/views/layouts/partials/sidebar.blade.php b/resources/views/layouts/partials/sidebar.blade.php index 9fadcbc..f69da37 100755 --- a/resources/views/layouts/partials/sidebar.blade.php +++ b/resources/views/layouts/partials/sidebar.blade.php @@ -67,7 +67,7 @@
  • {!! html_link_to_route('payments.index', trans('payment.payments'), [], ['icon' => 'money']) !!}
  • @endcan @can('manage', auth()->user()->agency) -
  • {!! html_link_to_route('partners.index', trans('partner.list'), [], ['icon' => 'users']) !!}
  • +
  • {!! html_link_to_route('customers.index', trans('customer.list'), [], ['icon' => 'users']) !!}
  • @endcan @can('manage_users')
  • {!! html_link_to_route('users.index', trans('user.users'), [], ['icon' => 'users']) !!}
  • diff --git a/resources/views/partners/index.blade.php b/resources/views/partners/index.blade.php deleted file mode 100644 index 118a36b..0000000 --- a/resources/views/partners/index.blade.php +++ /dev/null @@ -1,50 +0,0 @@ -@extends('layouts.app') - -@section('title', trans('partner.list')) - -@section('content') -

    -
    - {{ link_to_route('partners.create', trans('partner.create'), [], ['class' => 'btn btn-success']) }} -
    - {{ trans('partner.list') }} - {{ trans('app.total') }} : {{ $partners->total() }} {{ trans('partner.partner') }} -

    - -
    -
    - {{ Form::open(['method' => 'get','class' => 'form-inline']) }} - {!! 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() }} -
    - - - - - - - - - - - - - @foreach($partners as $key => $partner) - - - - - - - - - @endforeach - -
    {{ trans('app.table_no') }}{{ trans('partner.name') }}{{ trans('contact.email') }}{{ trans('contact.phone') }}{{ trans('partner.projects_count') }}{{ trans('app.status') }}
    {{ $partners->firstItem() + $key }}{{ $partner->nameLink() }}{{ $partner->email }}{{ $partner->phone }}{{ $partner->projects_count }}{{ $partner->is_active }}
    -
    {{ $partners->appends(Request::except('page'))->render() }}
    -
    -
    -
    -@endsection diff --git a/routes/web.php b/routes/web.php index 9214bde..e5c95a0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -22,7 +22,7 @@ Route::group(['middleware' => ['web', 'auth']], function () { Route::resource('backups', 'BackupsController', ['except' => ['create', 'show', 'edit']]); /* - * Partners Routes + * Customers Routes */ - Route::resource('partners', 'Partners\PartnersController'); + Route::resource('customers', 'Partners\CustomersController'); }); diff --git a/tests/Feature/InvoiceEntryTest.php b/tests/Feature/InvoiceEntryTest.php index c82b016..e9e0f7f 100644 --- a/tests/Feature/InvoiceEntryTest.php +++ b/tests/Feature/InvoiceEntryTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature; -use App\Entities\Partners\Partner; +use App\Entities\Partners\Customer; use App\Entities\Projects\Project; use App\Services\InvoiceDrafts\InvoiceDraft; use App\Services\InvoiceDrafts\InvoiceDraftCollection; @@ -139,7 +139,7 @@ class InvoiceEntryTest extends TestCase $item2 = new Item(['description' => 'Deskripsi item invoice', 'amount' => 2000]); $user = $this->adminUserSigningIn(); - $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); // Add items to draft diff --git a/tests/Feature/ManageFeaturesTest.php b/tests/Feature/ManageFeaturesTest.php index 5e0ca0e..61936e5 100644 --- a/tests/Feature/ManageFeaturesTest.php +++ b/tests/Feature/ManageFeaturesTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature; use App\Entities\Agencies\Agency; -use App\Entities\Partners\Partner; +use App\Entities\Partners\Customer; use App\Entities\Projects\Feature; use App\Entities\Projects\Project; use App\Entities\Projects\Task; @@ -17,7 +17,7 @@ class ManageFeaturesTest extends TestCase { $user = $this->adminUserSigningIn(); - $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); $worker = $this->createUser(); @@ -52,7 +52,7 @@ class ManageFeaturesTest extends TestCase $agency = factory(Agency::class)->create(['owner_id' => $user[0]->id]); $this->actingAs($user[0]); - $customer = factory(Partner::class)->create(['owner_id' => $agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $agency->id]); $project = factory(Project::class)->create(['owner_id' => $agency->id, 'customer_id' => $customer->id]); $feature = factory(Feature::class)->create(['worker_id' => $user[1]->id, 'project_id' => $project->id]); @@ -83,7 +83,7 @@ class ManageFeaturesTest extends TestCase public function admin_can_delete_a_feature() { $user = $this->adminUserSigningIn(); - $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); $feature = factory(Feature::class)->create(['project_id' => $project->id]); $tasks = factory(Task::class, 2)->create(['feature_id' => $feature->id]); @@ -136,7 +136,7 @@ class ManageFeaturesTest extends TestCase public function admin_may_clone_many_features_from_other_projects() { $user = $this->adminUserSigningIn(); - $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $projects = factory(Project::class, 2)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); $features = factory(Feature::class, 3)->create(['project_id' => $projects[0]->id]); $tasks1 = factory(Task::class, 3)->create(['feature_id' => $features[0]->id]); diff --git a/tests/Feature/ManagePartnersTest.php b/tests/Feature/ManagePartnersTest.php deleted file mode 100644 index 6b3d09a..0000000 --- a/tests/Feature/ManagePartnersTest.php +++ /dev/null @@ -1,109 +0,0 @@ -adminUserSigningIn(); - $partner1 = factory(Partner::class)->create(['owner_id' => $user->agency->id]); - $partner2 = factory(Partner::class)->create(['owner_id' => $user->agency->id]); - - $this->visit(route('partners.index')); - $this->see($partner1->name); - $this->see($partner2->name); - } - - /** @test */ - public function user_can_create_a_partner() - { - $user = $this->adminUserSigningIn(); - $this->visit(route('partners.index')); - - $this->click(trans('partner.create')); - $this->seePageIs(route('partners.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->see(trans('partner.created')); - - $this->seeInDatabase('partners', [ - 'name' => 'Partner 1 name', - 'email' => 'partner1@mail.com', - 'phone' => '081234567890', - 'pic' => 'Nama PIC Partner', - 'address' => 'Alamat partner 1', - 'notes' => null, - 'owner_id' => $user->agency->id, - ]); - } - - /** @test */ - public function user_can_edit_a_partner() - { - $user = $this->adminUserSigningIn(); - $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id, 'name' => 'Testing 123']); - - $this->visit(route('partners.show', [$partner->id])); - $this->click('edit-partner-'.$partner->id); - $this->seePageIs(route('partners.edit', [$partner->id])); - - $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.show', $partner->id)); - - $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() - { - $user = $this->adminUserSigningIn(); - $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id]); - - $this->visit(route('partners.edit', [$partner->id])); - $this->click('del-partner-'.$partner->id); - $this->seePageIs(route('partners.edit', [$partner->id, 'action' => 'delete'])); - - $this->seeInDatabase('partners', [ - 'id' => $partner->id, - ]); - - $this->press(trans('app.delete_confirm_button')); - - $this->dontSeeInDatabase('partners', [ - 'id' => $partner->id, - ]); - } -} diff --git a/tests/Feature/ManageProjectsTest.php b/tests/Feature/ManageProjectsTest.php index 0234f66..1984513 100644 --- a/tests/Feature/ManageProjectsTest.php +++ b/tests/Feature/ManageProjectsTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature; -use App\Entities\Partners\Partner; +use App\Entities\Partners\Customer; 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_partner() + public function admin_can_input_new_project_with_existing_customer() { - $user = $this->adminUserSigningIn(); - $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $user = $this->adminUserSigningIn(); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $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($partner->id, 'customer_id'); + $this->select($customer->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_partner() + public function admin_can_input_new_project_with_new_customer() { $user = $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('Partner Baru', 'customer_name'); - $this->type('email@partner.baru', 'customer_email'); + $this->type('Customer Baru', 'customer_name'); + $this->type('email@customer.baru', 'customer_email'); $this->press(trans('project.create')); $this->see(trans('project.created')); $this->see('Project Baru'); - $this->seeInDatabase('partners', [ - 'name' => 'Partner Baru', - 'email' => 'email@partner.baru', + $this->seeInDatabase('customers', [ + 'name' => 'Customer Baru', + 'email' => 'email@customer.baru', ]); - $newPartner = Partner::whereName('Partner Baru')->whereEmail('email@partner.baru')->first(); + $newCustomer = Customer::whereName('Customer Baru')->whereEmail('email@customer.baru')->first(); $this->seeInDatabase('projects', [ 'name' => 'Project Baru', 'proposal_value' => '2000000', - 'customer_id' => $newPartner->id, + 'customer_id' => $newCustomer->id, 'owner_id' => $user->agency->id, ]); } @@ -75,10 +75,10 @@ class ManageProjectsTest extends TestCase /** @test */ public function admin_can_delete_a_project() { - $user = $this->adminUserSigningIn(); - $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $user = $this->adminUserSigningIn(); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $partner->id]); + $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); $feature = factory(Feature::class)->create(['project_id' => $project->id]); $task = factory(Task::class)->create(['feature_id' => $feature->id]); $payment = factory(Payment::class)->create(['project_id' => $project->id]); @@ -112,9 +112,9 @@ class ManageProjectsTest extends TestCase /** @test */ public function admin_can_edit_a_project() { - $user = $this->adminUserSigningIn(); - $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $partner->id]); + $user = $this->adminUserSigningIn(); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); $this->visit('projects/'.$project->id.'/edit'); $this->seePageIs('projects/'.$project->id.'/edit'); @@ -126,7 +126,7 @@ class ManageProjectsTest extends TestCase $this->type(2000000, 'proposal_value'); $this->type(2000000, 'project_value'); $this->select(4, 'status_id'); - $this->select($partner->id, 'customer_id'); + $this->select($customer->id, 'customer_id'); $this->type('Edit deskripsi project', 'description'); $this->press(trans('project.update')); @@ -136,7 +136,7 @@ class ManageProjectsTest extends TestCase 'proposal_date' => '2016-04-15', 'start_date' => '2016-04-25', 'end_date' => '2016-05-05', - 'customer_id' => $partner->id, + 'customer_id' => $customer->id, 'description' => 'Edit deskripsi project', ]); } @@ -144,15 +144,15 @@ class ManageProjectsTest extends TestCase /** @test */ public function form_is_validated_on_invalid_project_entry() { - $user = $this->adminUserSigningIn(); - $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $user = $this->adminUserSigningIn(); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $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($partner->id, 'customer_id'); + $this->select($customer->id, 'customer_id'); $this->type('2016-04-15aa', 'proposal_date'); $this->type('', 'proposal_value'); $this->type('Deskripsi project baru', 'description'); @@ -165,11 +165,11 @@ class ManageProjectsTest extends TestCase /** @test */ public function admin_can_update_project_status_on_project_detail_page() { - $user = $this->adminUserSigningIn(); - $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create([ + $user = $this->adminUserSigningIn(); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create([ 'owner_id' => $user->agency->id, - 'customer_id' => $partner->id, + 'customer_id' => $customer->id, 'status_id' => 1, ]); diff --git a/tests/Feature/ManageSubscriptionsTest.php b/tests/Feature/ManageSubscriptionsTest.php index d4acc39..e7c5bfd 100644 --- a/tests/Feature/ManageSubscriptionsTest.php +++ b/tests/Feature/ManageSubscriptionsTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature; -use App\Entities\Partners\Partner; +use App\Entities\Partners\Customer; use App\Entities\Projects\Project; use App\Entities\Subscriptions\Subscription; use Tests\TestCase; @@ -13,8 +13,8 @@ class ManageSubscriptionsTest extends TestCase public function admin_can_entry_subscription() { $user = $this->adminUserSigningIn(); - $vendor = factory(Partner::class)->create(['owner_id' => $user->agency->id]); - $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $vendor = factory(Customer::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); $this->visit(route('subscriptions.index')); @@ -52,8 +52,8 @@ class ManageSubscriptionsTest extends TestCase { $eppCode = str_random(10); $user = $this->adminUserSigningIn(); - $vendor = factory(Partner::class)->create(['owner_id' => $user->agency->id]); - $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $vendor = factory(Customer::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); $subscription = factory(Subscription::class)->create(['project_id' => $project->id]); @@ -89,7 +89,7 @@ class ManageSubscriptionsTest extends TestCase public function admin_can_delete_a_subscription() { $user = $this->adminUserSigningIn(); - $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); $subscription = factory(Subscription::class)->create(['project_id' => $project->id]); @@ -107,7 +107,7 @@ class ManageSubscriptionsTest extends TestCase public function admin_can_see_a_subscription() { $user = $this->adminUserSigningIn(); - $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); $subscription = factory(Subscription::class)->create(['project_id' => $project->id]); diff --git a/tests/Feature/Partners/ManageCustomersTest.php b/tests/Feature/Partners/ManageCustomersTest.php new file mode 100644 index 0000000..8760b40 --- /dev/null +++ b/tests/Feature/Partners/ManageCustomersTest.php @@ -0,0 +1,109 @@ +adminUserSigningIn(); + $customer1 = factory(Customer::class)->create(['owner_id' => $user->agency->id]); + $customer2 = factory(Customer::class)->create(['owner_id' => $user->agency->id]); + + $this->visit(route('customers.index')); + $this->see($customer1->name); + $this->see($customer2->name); + } + + /** @test */ + public function user_can_create_a_customer() + { + $user = $this->adminUserSigningIn(); + $this->visit(route('customers.index')); + + $this->click(trans('customer.create')); + $this->seePageIs(route('customers.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->see(trans('customer.created')); + + $this->seeInDatabase('customers', [ + 'name' => 'Customer 1 name', + 'email' => 'customer1@mail.com', + 'phone' => '081234567890', + 'pic' => 'Nama PIC Customer', + 'address' => 'Alamat customer 1', + 'notes' => null, + 'owner_id' => $user->agency->id, + ]); + } + + /** @test */ + public function user_can_edit_a_customer() + { + $user = $this->adminUserSigningIn(); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id, 'name' => 'Testing 123']); + + $this->visit(route('customers.show', [$customer->id])); + $this->click('edit-customer-'.$customer->id); + $this->seePageIs(route('customers.edit', [$customer->id])); + + $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.show', $customer->id)); + + $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() + { + $user = $this->adminUserSigningIn(); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); + + $this->visit(route('customers.edit', [$customer->id])); + $this->click('del-customer-'.$customer->id); + $this->seePageIs(route('customers.edit', [$customer->id, 'action' => 'delete'])); + + $this->seeInDatabase('customers', [ + 'id' => $customer->id, + ]); + + $this->press(trans('app.delete_confirm_button')); + + $this->dontSeeInDatabase('customers', [ + 'id' => $customer->id, + ]); + } +} diff --git a/tests/Feature/Payments/ManagePaymentsTest.php b/tests/Feature/Payments/ManagePaymentsTest.php index 1db9b2c..6b81d24 100644 --- a/tests/Feature/Payments/ManagePaymentsTest.php +++ b/tests/Feature/Payments/ManagePaymentsTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Payments; -use App\Entities\Partners\Partner; +use App\Entities\Partners\Customer; 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(Partner::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); $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(Partner::class)->create(['owner_id' => $user->agency->id]); + $vendor = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); $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(Partner::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); $payment = factory(Payment::class)->create([ @@ -107,7 +107,7 @@ class ManagePaymentsTest extends TestCase public function admin_can_delete_a_payment() { $user = $this->adminUserSigningIn(); - $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); $payment = factory(Payment::class)->create(['project_id' => $project->id, 'partner_id' => $customer->id]); @@ -123,7 +123,7 @@ class ManagePaymentsTest extends TestCase public function admin_can_see_a_payment() { $user = $this->adminUserSigningIn(); - $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); $payment = factory(Payment::class)->create(['project_id' => $project->id, 'partner_id' => $customer->id]); diff --git a/tests/Feature/Payments/PaymentSearchTest.php b/tests/Feature/Payments/PaymentSearchTest.php index 6f488a6..58f5c7c 100644 --- a/tests/Feature/Payments/PaymentSearchTest.php +++ b/tests/Feature/Payments/PaymentSearchTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Payments; -use App\Entities\Partners\Partner; +use App\Entities\Partners\Customer; use App\Entities\Payments\Payment; use App\Entities\Projects\Project; use Tests\TestCase; @@ -13,7 +13,7 @@ class PaymentSearchTest extends TestCase public function user_can_find_payment_by_project_name() { $admin = $this->adminUserSigningIn(); - $customer = factory(Partner::class)->create(['owner_id' => $admin->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $admin->agency->id]); $project = factory(Project::class)->create(['owner_id' => $admin->agency->id, 'customer_id' => $customer->id, 'name' => 'Project']); $payment = factory(Payment::class)->create(['project_id' => $project->id, 'partner_id' => $customer->id]); $project2 = factory(Project::class)->create(['owner_id' => $admin->agency->id, 'customer_id' => $customer->id]); @@ -40,10 +40,10 @@ class PaymentSearchTest extends TestCase $unShownPayment = factory(Payment::class)->create(['project_id' => $project2->id]); $admin = $this->adminUserSigningIn(); - $customer = factory(Partner::class)->create(['owner_id' => $admin->agency->id]); + $customer = factory(Customer::class)->create(['owner_id' => $admin->agency->id]); $project = factory(Project::class)->create(['owner_id' => $admin->agency->id, 'customer_id' => $customer->id, 'name' => 'Project']); $payment = factory(Payment::class)->create(['project_id' => $project->id, 'partner_id' => $customer->id]); - $customer2 = factory(Partner::class)->create(['owner_id' => $admin->agency->id]); + $customer2 = factory(Customer::class)->create(['owner_id' => $admin->agency->id]); $project2 = factory(Project::class)->create(['owner_id' => $admin->agency->id, 'customer_id' => $customer2->id]); $unShownPayment = factory(Payment::class)->create(['project_id' => $project2->id, 'partner_id' => $customer2->id]); diff --git a/tests/Unit/Models/CustomerTest.php b/tests/Unit/Models/CustomerTest.php new file mode 100644 index 0000000..46d3c1f --- /dev/null +++ b/tests/Unit/Models/CustomerTest.php @@ -0,0 +1,46 @@ +create(); + $customer = factory(Customer::class)->create(['owner_id' => $agency->id]); + + $this->assertTrue($customer->owner instanceof Agency); + $this->assertEquals($customer->owner->id, $agency->id); + } + + /** @test */ + public function a_customer_has_many_projects() + { + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(['customer_id' => $customer->id]); + + $this->assertTrue($customer->projects instanceof Collection); + $this->assertTrue($customer->projects->first() instanceof Project); + } + + /** @test */ + public function a_customer_has_name_link_method() + { + $customer = factory(Customer::class)->make(); + $this->assertEquals( + link_to_route('customers.show', $customer->name, [$customer->id], [ + 'title' => trans( + 'app.show_detail_title', + ['name' => $customer->name, 'type' => trans('customer.customer')] + ), + ]), $customer->nameLink() + ); + } +} diff --git a/tests/Unit/Models/PartnerTest.php b/tests/Unit/Models/PartnerTest.php deleted file mode 100644 index 467ae07..0000000 --- a/tests/Unit/Models/PartnerTest.php +++ /dev/null @@ -1,46 +0,0 @@ -create(); - $partner = factory(Partner::class)->create(['owner_id' => $agency->id]); - - $this->assertTrue($partner->owner instanceof Agency); - $this->assertEquals($partner->owner->id, $agency->id); - } - - /** @test */ - public function a_partner_has_many_projects() - { - $partner = factory(Partner::class)->create(); - $project = factory(Project::class)->create(['customer_id' => $partner->id]); - - $this->assertTrue($partner->projects instanceof Collection); - $this->assertTrue($partner->projects->first() instanceof Project); - } - - /** @test */ - public function a_partner_has_name_link_method() - { - $partner = factory(Partner::class)->make(); - $this->assertEquals( - link_to_route('partners.show', $partner->name, [$partner->id], [ - 'title' => trans( - 'app.show_detail_title', - ['name' => $partner->name, 'type' => trans('partner.partner')] - ), - ]), $partner->nameLink() - ); - } -} diff --git a/tests/Unit/Models/PaymentTest.php b/tests/Unit/Models/PaymentTest.php index 480f431..64f4647 100644 --- a/tests/Unit/Models/PaymentTest.php +++ b/tests/Unit/Models/PaymentTest.php @@ -2,7 +2,7 @@ namespace Tests\Unit\Models; -use App\Entities\Partners\Partner; +use App\Entities\Partners\Customer; 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 Partner); + $this->assertTrue($payment->partner instanceof Customer); } } diff --git a/tests/Unit/Models/ProjectTest.php b/tests/Unit/Models/ProjectTest.php index bb6f7e3..69ee3e7 100644 --- a/tests/Unit/Models/ProjectTest.php +++ b/tests/Unit/Models/ProjectTest.php @@ -3,7 +3,7 @@ namespace Tests\Unit\Models; use App\Entities\Agencies\Agency; -use App\Entities\Partners\Partner; +use App\Entities\Partners\Customer; use App\Entities\Payments\Payment; use App\Entities\Projects\Feature; use App\Entities\Projects\Project; @@ -72,10 +72,10 @@ class ProjectTest extends TestCase /** @test */ public function a_project_belongs_to_a_customer() { - $customer = factory(Partner::class)->create(); + $customer = factory(Customer::class)->create(); $project = factory(Project::class)->create(['customer_id' => $customer->id]); - $this->assertTrue($project->customer instanceof Partner); + $this->assertTrue($project->customer instanceof Customer); $this->assertEquals($project->customer_id, $customer->id); } diff --git a/tests/Unit/Models/SubscriptionTest.php b/tests/Unit/Models/SubscriptionTest.php index 6e5eed6..f80d37c 100644 --- a/tests/Unit/Models/SubscriptionTest.php +++ b/tests/Unit/Models/SubscriptionTest.php @@ -2,7 +2,7 @@ namespace Tests\Unit\Models; -use App\Entities\Partners\Partner; +use App\Entities\Partners\Customer; use App\Entities\Projects\Project; use App\Entities\Subscriptions\Subscription; use Tests\TestCase as TestCase; @@ -27,6 +27,6 @@ class SubscriptionTest extends TestCase public function it_has_vendor_relation() { $subscription = factory(Subscription::class)->create(); - $this->assertTrue($subscription->vendor instanceof Partner); + $this->assertTrue($subscription->vendor instanceof Customer); } } diff --git a/tests/Unit/Policies/CustomerPolicyTest.php b/tests/Unit/Policies/CustomerPolicyTest.php new file mode 100644 index 0000000..e9e0ce1 --- /dev/null +++ b/tests/Unit/Policies/CustomerPolicyTest.php @@ -0,0 +1,40 @@ +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)); + } +} diff --git a/tests/Unit/Policies/PartnerPolicyTest.php b/tests/Unit/Policies/PartnerPolicyTest.php deleted file mode 100644 index 201e76a..0000000 --- a/tests/Unit/Policies/PartnerPolicyTest.php +++ /dev/null @@ -1,40 +0,0 @@ -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)); - } -}