diff --git a/app/Entities/BaseRepository.php b/app/Entities/BaseRepository.php index b7fdc15..493ad6f 100755 --- a/app/Entities/BaseRepository.php +++ b/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() diff --git a/app/Entities/Partners/Customer.php b/app/Entities/Partners/Partner.php similarity index 86% rename from app/Entities/Partners/Customer.php rename to app/Entities/Partners/Partner.php index 027eabb..d79fd8f 100644 --- a/app/Entities/Partners/Customer.php +++ b/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']; } diff --git a/app/Entities/Payments/Payment.php b/app/Entities/Payments/Payment.php index c63b388..843c5d2 100755 --- a/app/Entities/Payments/Payment.php +++ b/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() diff --git a/app/Entities/Projects/Project.php b/app/Entities/Projects/Project.php index 78735ef..fc63637 100755 --- a/app/Entities/Projects/Project.php +++ b/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; } diff --git a/app/Entities/Projects/ProjectsRepository.php b/app/Entities/Projects/ProjectsRepository.php index baeaa39..575fafb 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\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(); diff --git a/app/Entities/Subscriptions/Subscription.php b/app/Entities/Subscriptions/Subscription.php index b4a69f5..df01d27 100755 --- a/app/Entities/Subscriptions/Subscription.php +++ b/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() diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 3c7602d..fcb8eb6 100644 --- a/app/Exceptions/Handler.php +++ b/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(); diff --git a/app/Http/Controllers/Partners/CustomersController.php b/app/Http/Controllers/Partners/CustomersController.php deleted file mode 100644 index a003c86..0000000 --- a/app/Http/Controllers/Partners/CustomersController.php +++ /dev/null @@ -1,104 +0,0 @@ -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(); - } -} diff --git a/app/Http/Controllers/Partners/PartnersController.php b/app/Http/Controllers/Partners/PartnersController.php new file mode 100644 index 0000000..ba56dbe --- /dev/null +++ b/app/Http/Controllers/Partners/PartnersController.php @@ -0,0 +1,104 @@ +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(); + } +} diff --git a/app/Policies/Partners/CustomerPolicy.php b/app/Policies/Partners/PartnerPolicy.php similarity index 53% rename from app/Policies/Partners/CustomerPolicy.php rename to app/Policies/Partners/PartnerPolicy.php index 20992f6..a428d60 100644 --- a/app/Policies/Partners/CustomerPolicy.php +++ b/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; } } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 73d1580..6e83131 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/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', ]; /** diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index c1cc3d7..b65530d 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -1,7 +1,7 @@ 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; }, ]; }); diff --git a/database/factories/CustomerFactory.php b/database/factories/PartnerFactory.php similarity index 50% rename from database/factories/CustomerFactory.php rename to database/factories/PartnerFactory.php index 6047205..e37d1b8 100644 --- a/database/factories/CustomerFactory.php +++ b/database/factories/PartnerFactory.php @@ -1,9 +1,9 @@ define(Customer::class, function (Faker $faker) { +$factory->define(Partner::class, function (Faker $faker) { return [ 'name' => $faker->company, diff --git a/database/factories/PaymentFactory.php b/database/factories/PaymentFactory.php index c07d299..bd0b5be 100644 --- a/database/factories/PaymentFactory.php +++ b/database/factories/PaymentFactory.php @@ -1,6 +1,6 @@ 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; }, ]; }); diff --git a/database/migrations/2017_10_26_134455_create_customers_table.php b/database/migrations/2017_10_26_134455_create_partners_table.php similarity index 83% rename from database/migrations/2017_10_26_134455_create_customers_table.php rename to database/migrations/2017_10_26_134455_create_partners_table.php index f9e55a1..ed122fc 100644 --- a/database/migrations/2017_10_26_134455_create_customers_table.php +++ b/database/migrations/2017_10_26_134455_create_partners_table.php @@ -1,10 +1,10 @@ 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'); } } diff --git a/resources/lang/id/customer.php b/resources/lang/id/customer.php deleted file mode 100644 index f7f0891..0000000 --- a/resources/lang/id/customer.php +++ /dev/null @@ -1,29 +0,0 @@ - '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', -]; diff --git a/resources/lang/id/partner.php b/resources/lang/id/partner.php new file mode 100644 index 0000000..0c1eddc --- /dev/null +++ b/resources/lang/id/partner.php @@ -0,0 +1,29 @@ + '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', +]; diff --git a/resources/views/customers/forms.blade.php b/resources/views/partners/forms.blade.php similarity index 56% rename from resources/views/customers/forms.blade.php rename to resources/views/partners/forms.blade.php index fb88d52..f9b0f53 100644 --- a/resources/views/customers/forms.blade.php +++ b/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)
{{ $editableCustomer->name }}
+ +{{ $editablePartner->name }}
-{{ $editableCustomer->email }}
+{{ $editablePartner->email }}
-{{ $editableCustomer->phone }}
+{{ $editablePartner->phone }}
-{{ $editableCustomer->address }}
+{{ $editablePartner->address }}
-{{ $editableCustomer->is_active }}
+{{ $editablePartner->is_active }}
-{{ $editableCustomer->notes }}
- {!! $errors->first('customer_id', ':message') !!} +{{ $editablePartner->notes }}
+ {!! $errors->first('partner_id', ':message') !!}| {{ trans('app.table_no') }} | -{{ trans('customer.name') }} | +{{ trans('partner.name') }} | {{ trans('contact.email') }} | {{ trans('contact.phone') }} | {{ trans('app.status') }} | @@ -32,36 +32,36 @@|||||
|---|---|---|---|---|---|---|---|---|---|---|
| {{ $customers->firstItem() + $key }} | -{{ $customer->name }} | -{{ $customer->email }} | -{{ $customer->phone }} | -{{ $customer->is_active }} | +{{ $partners->firstItem() + $key }} | +{{ $partner->name }} | +{{ $partner->email }} | +{{ $partner->phone }} | +{{ $partner->is_active }} | {!! 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] ) !!} |