Browse Source

Add type_id attribute in subscriptions table restructure lang file

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
ca241c9f84
  1. 5
      app/Entities/Subscriptions/Subscription.php
  2. 8
      app/Http/Controllers/SubscriptionsController.php
  3. 1
      app/Http/Requests/Subscriptions/CreateRequest.php
  4. 1
      database/factories/ModelFactory.php
  5. 7
      database/migrations/2016_07_08_182606_create_subscriptions_table.php
  6. 68
      resources/lang/id/subscription.php
  7. 21
      resources/views/subscriptions/create.blade.php
  8. 69
      tests/Feature/ManageSubscriptionsTest.php
  9. 21
      tests/Unit/Models/SubscriptionTest.php

5
app/Entities/Subscriptions/Subscription.php

@ -26,4 +26,9 @@ class Subscription extends Model
{
return $this->status_id ? trans('app.active') : trans('app.in_active');
}
public function getTypeAttribute()
{
return $this->type_id == 1 ? trans('subscription.types.domain') : trans('subscription.types.hosting');
}
}

8
app/Http/Controllers/SubscriptionsController.php

@ -29,7 +29,13 @@ class SubscriptionsController extends Controller
{
$projects = $this->repo->getProjectsList();
$vendors = $this->repo->getVendorsList();
return view('subscriptions.create', compact('projects', 'vendors'));
$subscriptionTypes = [
1 => trans('subscription.types.domain'),
2 => trans('subscription.types.hosting'),
];
return view('subscriptions.create', compact('projects', 'vendors', 'subscriptionTypes'));
}
public function store(CreateRequest $request)

1
app/Http/Requests/Subscriptions/CreateRequest.php

@ -34,6 +34,7 @@ class CreateRequest extends Request
'due_date' => 'required|date|date_format:Y-m-d',
'project_id' => 'required|numeric',
'vendor_id' => 'required|numeric',
'type_id' => 'required|numeric',
'remark' => 'max:255',
];
}

1
database/factories/ModelFactory.php

@ -27,6 +27,7 @@ $factory->define(Subscription::class, function (Faker\Generator $faker) {
'project_id' => function () {
return factory(Project::class)->create()->id;
},
'type_id' => 1,
'status_id' => 1,
'domain_name' => 'www.'.str_random(10).'.com',
'domain_price' => 125000,

7
database/migrations/2016_07_08_182606_create_subscriptions_table.php

@ -14,11 +14,12 @@ class CreateSubscriptionsTable extends Migration
{
Schema::create('subscriptions', function (Blueprint $table) {
$table->increments('id');
$table->integer('project_id')->unsigned();
$table->integer('vendor_id')->unsigned();
$table->unsignedInteger('project_id');
$table->unsignedInteger('vendor_id');
$table->unsignedTinyInteger('type_id');
$table->string('domain_name', 60);
$table->string('epp_code', 60)->nullable();
$table->integer('domain_price')->unsigned();
$table->unsignedInteger('domain_price');
$table->string('hosting_capacity', 60)->nullable();
$table->boolean('status_id')->unsigned()->default(1);
$table->integer('hosting_price')->unsigned()->nullable();

68
resources/lang/id/subscription.php

@ -1,32 +1,44 @@
<?php
return [
'subscription' => 'Langganan',
'subscriptions' => 'Daftar Langganan',
'domain_name' => 'Domain',
'domain_price' => 'Harga Domain',
'epp_code' => 'Kode EPP',
// Labels
'subscription' => 'Langganan',
'subscriptions' => 'Daftar Langganan',
'search' => 'Cari Langganan',
'found' => 'Langganan ditemukan',
'not_found' => 'Langganan tidak ditemukan',
'empty' => 'Belum ada Langganan',
'back_to_index' => 'Kembali ke daftar Langganan',
// Actions
'create' => 'Input Langganan Baru',
'created' => 'Input Langganan baru telah berhasil.',
'show' => 'Detail Langganan',
'edit' => 'Edit Langganan',
'update' => 'Update Langganan',
'updated' => 'Update data Langganan telah berhasil.',
'delete' => 'Hapus Langganan',
'deleted' => 'Hapus data Langganan telah berhasil.',
'undeleted' => 'Data Langganan gagal dihapus.',
// Attributes
'domain_name' => 'Domain',
'domain_price' => 'Harga Domain',
'epp_code' => 'Kode EPP',
'hosting_capacity' => 'Kapasitas Hosting',
'hosting_price' => 'Harga Hosting',
'start_date' => 'Mulai Sewa',
'due_date' => 'Perpanjangan',
'extension_price' => 'Biaya Perpanjangan',
'create' => 'Input Langganan Baru',
'created' => 'Input Langganan baru telah berhasil.',
'show' => 'Detail Langganan',
'edit' => 'Edit Langganan',
'update' => 'Update Langganan',
'updated' => 'Update data Langganan telah berhasil.',
'delete' => 'Hapus Langganan',
'deleted' => 'Hapus data Langganan telah berhasil.',
'undeleted' => 'Data Langganan gagal dihapus.',
'remark' => 'Catatan',
'search' => 'Cari Langganan',
'found' => 'Langganan ditemukan',
'not_found' => 'Langganan tidak ditemukan',
'empty' => 'Belum ada Langganan',
'back_to_index' => 'Kembali ke daftar Langganan',
'customer' => 'Customer',
'project' => 'Project',
'vendor' => 'Vendor',
];
'hosting_price' => 'Harga Hosting',
'start_date' => 'Mulai Sewa',
'due_date' => 'Perpanjangan',
'extension_price' => 'Biaya Perpanjangan',
'project' => 'Project',
'vendor' => 'Vendor',
'remark' => 'Catatan',
'type' => 'Jenis Langganan',
// Types
'types' => [
'domain' => 'Domain',
'hosting' => 'Hosting',
],
];

21
resources/views/subscriptions/create.blade.php

@ -16,32 +16,33 @@
<div class="panel-body">
<div class="row">
<div class="col-sm-6">
{!! FormField::text('domain_name',['label'=> trans('subscription.domain_name')]) !!}
{!! FormField::text('domain_name', ['label' => trans('subscription.domain_name')]) !!}
</div>
<div class="col-sm-6">
{!! FormField::price('domain_price',['label'=> trans('subscription.domain_price')]) !!}
{!! FormField::price('domain_price', ['label' => trans('subscription.domain_price')]) !!}
</div>
</div>
{!! FormField::text('epp_code',['label'=> trans('subscription.epp_code')]) !!}
{!! FormField::text('epp_code', ['label' => trans('subscription.epp_code')]) !!}
<div class="row">
<div class="col-sm-6">
{!! FormField::text('hosting_capacity',['label'=> trans('subscription.hosting_capacity')]) !!}
{!! FormField::text('hosting_capacity', ['label' => trans('subscription.hosting_capacity')]) !!}
</div>
<div class="col-sm-6">
{!! FormField::price('hosting_price',['label'=> trans('subscription.hosting_price')]) !!}
{!! FormField::price('hosting_price', ['label' => trans('subscription.hosting_price')]) !!}
</div>
</div>
<div class="row">
<div class="col-sm-6">
{!! FormField::text('start_date',['label'=> trans('subscription.start_date')]) !!}
{!! FormField::text('start_date', ['label' => trans('subscription.start_date')]) !!}
</div>
<div class="col-sm-6">
{!! FormField::text('due_date',['label'=> trans('subscription.due_date')]) !!}
{!! FormField::text('due_date', ['label' => trans('subscription.due_date')]) !!}
</div>
</div>
{!! FormField::select('project_id', $projects,['label'=> trans('subscription.project'),'value' => Request::get('project_id')]) !!}
{!! FormField::select('vendor_id', $vendors,['label'=> trans('subscription.vendor'),'value' => Request::get('vendor_id')]) !!}
{!! FormField::textarea('remark',['label'=> trans('subscription.remark')]) !!}
{!! FormField::select('project_id', $projects, ['label' => trans('subscription.project'), 'value' => Request::get('project_id')]) !!}
{!! FormField::select('vendor_id', $vendors, ['label' => trans('subscription.vendor'), 'value' => Request::get('vendor_id')]) !!}
{!! FormField::radios('type_id', $subscriptionTypes, ['label' => trans('subscription.type'), 'value' => Request::get('type_id')]) !!}
{!! FormField::textarea('remark', ['label' => trans('subscription.remark')]) !!}
</div>
<div class="panel-footer">

69
tests/Feature/ManageSubscriptionsTest.php

@ -2,7 +2,6 @@
namespace Tests\Feature;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Vendor;
use App\Entities\Projects\Project;
use App\Entities\Subscriptions\Subscription;
@ -21,17 +20,19 @@ class ManageSubscriptionsTest extends TestCase
$this->click(trans('subscription.create'));
// Fill Form
$this->type('www.domain.com', 'domain_name');
$this->type(100000, 'domain_price');
$this->type('EPPCODE', 'epp_code');
$this->type('3GB', 'hosting_capacity');
$this->type(500000, 'hosting_price');
$this->type('2015-05-02', 'start_date');
$this->type('2016-05-02', 'due_date');
$this->select($project->id, 'project_id');
$this->select($vendor->id, 'vendor_id');
$this->type('', 'remark');
$this->press(trans('subscription.create'));
$this->submitForm(trans('subscription.create'), [
'domain_name' => 'www.domain.com',
'domain_price' => 100000,
'epp_code' => 'EPPCODE',
'hosting_capacity' => '3GB',
'hosting_price' => 500000,
'start_date' => '2015-05-02',
'due_date' => '2016-05-02',
'project_id' => $project->id,
'vendor_id' => $vendor->id,
'type_id' => 1,
'remark' => '',
]);
$this->see(trans('subscription.created'));
$this->seePageIs(route('subscriptions.index'));
@ -44,37 +45,38 @@ class ManageSubscriptionsTest extends TestCase
'start_date' => '2015-05-02',
'due_date' => '2016-05-02',
'vendor_id' => $vendor->id,
'type_id' => 1,
]);
}
/** @test */
public function admin_can_edit_subscription_data()
{
$eppCode = str_random(10);
$user = $this->adminUserSigningIn();
$vendor = factory(Vendor::class)->create();
$customer = factory(Customer::class)->create();
$project = factory(Project::class)->create(['customer_id' => $customer->id]);
$user = $this->adminUserSigningIn();
$vendor = factory(Vendor::class)->create();
$project = factory(Project::class)->create();
$subscription = factory(Subscription::class)->create(['project_id' => $project->id]);
$this->visit(route('subscriptions.edit', $subscription->id));
// Fill Form
$this->type($eppCode, 'epp_code');
$this->type('4GB', 'hosting_capacity');
$this->type(500000, 'hosting_price');
$this->type('2015-05-02', 'start_date');
$this->type('2016-05-02', 'due_date');
$this->select($project->id, 'project_id');
$this->select($vendor->id, 'vendor_id');
$this->select(1, 'status_id');
$this->press(trans('subscription.update'));
$this->submitForm(trans('subscription.update'), [
'epp_code' => 'EPPCODE1',
'hosting_capacity' => '4GB',
'hosting_price' => 500000,
'start_date' => '2015-05-02',
'due_date' => '2016-05-02',
'project_id' => $project->id,
'vendor_id' => $vendor->id,
'status_id' => 1,
]);
$this->seePageIs(route('subscriptions.edit', $subscription->id));
$this->see(trans('subscription.updated'));
$this->seeInDatabase('subscriptions', [
'epp_code' => $eppCode,
'epp_code' => 'EPPCODE1',
'project_id' => $project->id,
'status_id' => 1,
'hosting_capacity' => '4GB',
@ -88,15 +90,13 @@ class ManageSubscriptionsTest extends TestCase
/** @test */
public function admin_can_delete_a_subscription()
{
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create();
$project = factory(Project::class)->create(['customer_id' => $customer->id]);
$subscription = factory(Subscription::class)->create(['project_id' => $project->id]);
$user = $this->adminUserSigningIn();
$subscription = factory(Subscription::class)->create();
$this->visit(route('subscriptions.edit', $subscription->id));
$this->click(trans('subscription.delete'));
$this->press(trans('app.delete_confirm_button'));
$this->seePageIs(route('subscriptions.index'));
$this->see(trans('subscription.deleted'));
@ -107,10 +107,7 @@ class ManageSubscriptionsTest extends TestCase
public function admin_can_see_a_subscription()
{
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create();
$project = factory(Project::class)->create();
$project = factory(Project::class)->create(['customer_id' => $customer->id]);
$subscription = factory(Subscription::class)->create(['project_id' => $project->id]);
$subscription = factory(Subscription::class)->create();
$this->visit(route('subscriptions.show', $subscription->id));

21
tests/Unit/Models/SubscriptionTest.php

@ -20,16 +20,27 @@ class SubscriptionTest extends TestCase
public function it_has_project_relation()
{
$subscription = factory(Subscription::class)->create();
$this->assertTrue($subscription->project instanceof Project);
$this->assertInstanceOf(Project::class, $subscription->project);
}
/** @test */
public function it_has_vendor_relation()
{
$subscription = factory(Subscription::class)->create();
$this->assertTrue(
$subscription->vendor instanceof Vendor,
'A subscription must belongs to a App\Entities\Partners\Vendor model as it\'s vendor.'
);
$this->assertInstanceOf(Vendor::class, $subscription->vendor);
}
/** @test */
public function a_subscription_has_type_attribute()
{
$subscription = factory(Subscription::class)->create();
$this->assertEquals(1, $subscription->type_id);
$this->assertEquals(trans('subscription.types.domain'), $subscription->type);
$subscription = factory(Subscription::class)->create(['type_id' => 2]);
$this->assertEquals(2, $subscription->type_id);
$this->assertEquals(trans('subscription.types.hosting'), $subscription->type);
}
}
Loading…
Cancel
Save