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')
{{ $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.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 }} | +
| {{ 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) !!} |
| {{ 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 }} | -