From 7c0c86e4fe8c4fc52cd495a3596860127683a859 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Fri, 4 May 2018 16:39:17 +0800 Subject: [PATCH 01/13] added route for shipping-order --- routes/api.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/routes/api.php b/routes/api.php index aff41ed..cf9e51c 100644 --- a/routes/api.php +++ b/routes/api.php @@ -12,6 +12,15 @@ use Illuminate\Http\Request; | is assigned the "api" middleware group. Enjoy building your API! | */ +//Route for the shipping order +Route::get('/so', 'SoController@index');// get the list of the shipping order +Route::get('/so/{id}', 'SoController@index');//get the shipping order + +Route::post('/so', 'SoController@store');//create shipping order +Route::post('/so/{id}/cancel-order', 'SoController@store');//post the cancel order + +Route::delete('/so/{id}', 'SoController@delete');// delete the shipping order +Route::put('/so/{id}', 'SoController@update');//update the shipping order //Route::middleware('auth:api')->get('/user', function (Request $request) { // return $request->user(); From 9162d865125688578e0ddde70b21897f86e3109d Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Mon, 7 May 2018 16:24:59 +0800 Subject: [PATCH 02/13] added migration, model, controller --- app/Http/Controllers/SoControlller.php | 84 +++++++++++++++++++ app/So.php | 19 +++++ app/Soitem.php | 27 ++++++ .../2018_05_07_062017_create_sos_table.php | 44 ++++++++++ ...2018_05_07_075445_create_soitems_table.php | 52 ++++++++++++ routes/api.php | 13 +-- 6 files changed, 234 insertions(+), 5 deletions(-) create mode 100644 app/Http/Controllers/SoControlller.php create mode 100644 app/So.php create mode 100644 app/Soitem.php create mode 100644 database/migrations/2018_05_07_062017_create_sos_table.php create mode 100644 database/migrations/2018_05_07_075445_create_soitems_table.php diff --git a/app/Http/Controllers/SoControlller.php b/app/Http/Controllers/SoControlller.php new file mode 100644 index 0000000..9761d26 --- /dev/null +++ b/app/Http/Controllers/SoControlller.php @@ -0,0 +1,84 @@ +increments('id'); + + //Order details + $table->integer('ff_id'); + $table->string('supplier_company_name'); + $table->string('supplier_contact_person'); + $table->integer('supplier_contact_person_no'); + + //Delivery details + $table->integer('delivery_id'); + + //Warehouse details + $table->integer('warehouse_id'); + $table->timestamps(); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('sos'); + } +} diff --git a/database/migrations/2018_05_07_075445_create_soitems_table.php b/database/migrations/2018_05_07_075445_create_soitems_table.php new file mode 100644 index 0000000..86334f3 --- /dev/null +++ b/database/migrations/2018_05_07_075445_create_soitems_table.php @@ -0,0 +1,52 @@ +increments('id'); + + //Item details + $table->integer('order_id'); + $table->integer('brand_no'); + $table->integer('model_no'); + $table->integer('item_code'); + $table->string('quantity_of_item'); + $table->string('uom'); + + //Packaging details + $table->integer('quantity_of_carton'); + $table->string('packaging_type'); + + //Measurement details + $table->double('packaging_height'); + $table->double('packaging_width'); + $table->double('packaging_depth'); + + //Weight details + $table->double('packaging_gross'); + $table->double('packaging_nett'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('soitems'); + } +} diff --git a/routes/api.php b/routes/api.php index cf9e51c..d522ca7 100644 --- a/routes/api.php +++ b/routes/api.php @@ -14,13 +14,16 @@ use Illuminate\Http\Request; */ //Route for the shipping order Route::get('/so', 'SoController@index');// get the list of the shipping order -Route::get('/so/{id}', 'SoController@index');//get the shipping order +Route::get('/so/{so_id}', 'SoController@sodata');//get the shipping order + +Route::post('/so/{so_id}', 'SoController@store');//create shipping order +Route::post('/so/{so_id}/cancel-order', 'SoController@cancel');//post the cancel order + +Route::delete('/so/{so_id}', 'SoController@delete');// delete the shipping order +Route::put('/so/{so_id}', 'SoController@update');//update the shipping order + -Route::post('/so', 'SoController@store');//create shipping order -Route::post('/so/{id}/cancel-order', 'SoController@store');//post the cancel order -Route::delete('/so/{id}', 'SoController@delete');// delete the shipping order -Route::put('/so/{id}', 'SoController@update');//update the shipping order //Route::middleware('auth:api')->get('/user', function (Request $request) { // return $request->user(); From 796373e671bbd91ce0f30b89a8abbfda235a8556 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Sun, 13 May 2018 23:38:19 +0800 Subject: [PATCH 03/13] added POST for so --- .../{SoControlller.php => SoController.php} | 33 ++++++++++++++++++- routes/api.php | 5 +-- 2 files changed, 35 insertions(+), 3 deletions(-) rename app/Http/Controllers/{SoControlller.php => SoController.php} (67%) diff --git a/app/Http/Controllers/SoControlller.php b/app/Http/Controllers/SoController.php similarity index 67% rename from app/Http/Controllers/SoControlller.php rename to app/Http/Controllers/SoController.php index 9761d26..d64138c 100644 --- a/app/Http/Controllers/SoControlller.php +++ b/app/Http/Controllers/SoController.php @@ -3,15 +3,29 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use App\So; +use App\Soitem; -class SoControlller extends Controller +class SoController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ + // get the list of the shipping order public function index() + { + return view('welcome'); + } + + /** + * Display a listing of the resource. + * + * @return \Illuminate\Http\Response + */ + //get the shipping order + public function so() { // } @@ -32,7 +46,23 @@ class SoControlller extends Controller * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ + //post shipping order public function store(Request $request) + { + $so = So::create($request->all()); + + return response()->json($so, 201); + + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + //post the cancel order + public function cancelorder(Request $request) { // } @@ -77,6 +107,7 @@ class SoControlller extends Controller * @param int $id * @return \Illuminate\Http\Response */ + // delete the shipping order public function destroy($id) { // diff --git a/routes/api.php b/routes/api.php index d522ca7..9ed6b9f 100644 --- a/routes/api.php +++ b/routes/api.php @@ -2,6 +2,7 @@ use Illuminate\Http\Request; + /* |-------------------------------------------------------------------------- | API Routes @@ -14,10 +15,10 @@ use Illuminate\Http\Request; */ //Route for the shipping order Route::get('/so', 'SoController@index');// get the list of the shipping order -Route::get('/so/{so_id}', 'SoController@sodata');//get the shipping order +Route::get('/so/{so_id}', 'SoController@so');//get the shipping order Route::post('/so/{so_id}', 'SoController@store');//create shipping order -Route::post('/so/{so_id}/cancel-order', 'SoController@cancel');//post the cancel order +Route::post('/so/{so_id}/cancel-order', 'SoController@cancelorder');//post the cancel order Route::delete('/so/{so_id}', 'SoController@delete');// delete the shipping order Route::put('/so/{so_id}', 'SoController@update');//update the shipping order From 182ac3e653976224edf75bbc454faa09e19b47bf Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Mon, 14 May 2018 00:14:23 +0800 Subject: [PATCH 04/13] added PUT, DELETE, GET --- app/Http/Controllers/SoController.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/SoController.php b/app/Http/Controllers/SoController.php index d64138c..251f534 100644 --- a/app/Http/Controllers/SoController.php +++ b/app/Http/Controllers/SoController.php @@ -96,9 +96,20 @@ class SoController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function update(Request $request, $id) + public function update(Request $request, $so_id) { - // + $so_id = So::find($so_id); + + $so_id->ff_id = $request->input('ff_id'); + $so_id->supplier_company_name = $request->input('supplier_company_name'); + $so_id->supplier_contact_person = $request->input('supplier_contact_person'); + $so_id->supplier_contact_person_no = $request->input('supplier_contact_person_no'); + $so_id->delivery_id = $request->input('delivery_id'); + $so_id->warehouse_id = $request->input('warehouse_id'); + $so_id->save(); + + return response()->json(['so_id'=>$so_id],200); + } /** @@ -108,8 +119,11 @@ class SoController extends Controller * @return \Illuminate\Http\Response */ // delete the shipping order - public function destroy($id) + public function delete(So $so_id) { - // + $so_id->delete($so_id); + + return response()->json($so_id, 204); + } } From 6057f48d9ec1f6fd9e0d738b7ecd03794f931187 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Mon, 14 May 2018 15:00:12 +0800 Subject: [PATCH 05/13] updated controller for both SO and SOitem --- app/Http/Controllers/SoController.php | 55 +++++++++++++++++++++++++-- routes/api.php | 6 ++- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/SoController.php b/app/Http/Controllers/SoController.php index 251f534..c329bdc 100644 --- a/app/Http/Controllers/SoController.php +++ b/app/Http/Controllers/SoController.php @@ -25,9 +25,11 @@ class SoController extends Controller * @return \Illuminate\Http\Response */ //get the shipping order - public function so() + public function so($so_id) { - // + $so_id = So::find($so_id); + return response()->json($so_id, 200); + } /** @@ -49,12 +51,24 @@ class SoController extends Controller //post shipping order public function store(Request $request) { + //for shipping order $so = So::create($request->all()); return response()->json($so, 201); } + //post shipping order item + public function storeitem(Request $request) + { + + //for shipping order item + $soitem = Soitem::create($request->all()); + + return response()->json($soitem, 201); + + } + /** * Store a newly created resource in storage. * @@ -98,14 +112,40 @@ class SoController extends Controller */ public function update(Request $request, $so_id) { + //for shipping order $so_id = So::find($so_id); - $so_id->ff_id = $request->input('ff_id'); $so_id->supplier_company_name = $request->input('supplier_company_name'); $so_id->supplier_contact_person = $request->input('supplier_contact_person'); $so_id->supplier_contact_person_no = $request->input('supplier_contact_person_no'); $so_id->delivery_id = $request->input('delivery_id'); $so_id->warehouse_id = $request->input('warehouse_id'); + + $so_id->save(); + + return response()->json(['so_id'=>$so_id],200); + + } + + public function updateitem(Request $request, $so_id) + { + + //for shipping order item + $so_id = Soitem::find($so_id); + $so_id->order_id = $request->input('order_id'); + $so_id->brand_no = $request->input('brand_no'); + $so_id->model_no = $request->input('model_no'); + $so_id->item_code = $request->input('item_code'); + $so_id->quantity_of_item = $request->input('quantity_of_item'); + $so_id->uom = $request->input('uom'); + $so_id->quantity_of_carton = $request->input('quantity_of_carton'); + $so_id->packaging_type = $request->input('packaging_type'); + $so_id->packaging_height = $request->input('packaging_height'); + $so_id->packaging_width = $request->input('packaging_width'); + $so_id->packaging_depth = $request->input('packaging_depth'); + $so_id->packaging_gross = $request->input('packaging_gross'); + $so_id->packaging_nett = $request->input('packaging_nett'); + $so_id->save(); return response()->json(['so_id'=>$so_id],200); @@ -122,7 +162,16 @@ class SoController extends Controller public function delete(So $so_id) { $so_id->delete($so_id); + + return response()->json($so_id, 204); + } + + // delete the shipping order item + public function deleteitem(Soitem $so_id) + { + $so_id->delete($so_id); + return response()->json($so_id, 204); } diff --git a/routes/api.php b/routes/api.php index 9ed6b9f..8cc89af 100644 --- a/routes/api.php +++ b/routes/api.php @@ -16,13 +16,15 @@ use Illuminate\Http\Request; //Route for the shipping order Route::get('/so', 'SoController@index');// get the list of the shipping order Route::get('/so/{so_id}', 'SoController@so');//get the shipping order - Route::post('/so/{so_id}', 'SoController@store');//create shipping order Route::post('/so/{so_id}/cancel-order', 'SoController@cancelorder');//post the cancel order - Route::delete('/so/{so_id}', 'SoController@delete');// delete the shipping order Route::put('/so/{so_id}', 'SoController@update');//update the shipping order +//Route for the shipping order item +Route::post('/so/soitem/{so_id}', 'SoController@storeitem');//create shipping order item +Route::delete('/so/soitem/{so_id}', 'SoController@deleteitem');//delete the shipping order item +Route::put('/so/soitem/{so_id}', 'SoController@updateitem');//update the shipping order item From 4d7b9b931f4edc82eccb8a94a0dda305252c22bf Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Tue, 15 May 2018 12:13:06 +0800 Subject: [PATCH 06/13] complete the model, controller, and migration --- app/So.php | 6 +++++- app/Soitem.php | 9 ++++++++- ...le.php => 2018_05_15_034032_create_soitems_table.php} | 8 ++++++++ routes/api.php | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) rename database/migrations/{2018_05_07_075445_create_soitems_table.php => 2018_05_15_034032_create_soitems_table.php} (81%) diff --git a/app/So.php b/app/So.php index 9fad772..0dec710 100644 --- a/app/So.php +++ b/app/So.php @@ -7,7 +7,6 @@ use Illuminate\Database\Eloquent\Model; class So extends Model { protected $fillable = [ - 'id', 'ff_id', 'supplier_company_name', 'supplier_contact_person', @@ -16,4 +15,9 @@ class So extends Model 'warehouse_id', ]; + public function Soitem() + { + return $this->hasMany(Soitem::class); + } + } diff --git a/app/Soitem.php b/app/Soitem.php index c17bc3c..4ef8b82 100644 --- a/app/Soitem.php +++ b/app/Soitem.php @@ -7,7 +7,8 @@ use Illuminate\Database\Eloquent\Model; class Soitem extends Model { protected $fillable = [ - 'id', + 'so_id', + 'status', 'order_id', 'brand_no', 'model_no', @@ -24,4 +25,10 @@ class Soitem extends Model ]; + public function So() + { + return $this->belongsTo(So::class); + } + + } diff --git a/database/migrations/2018_05_07_075445_create_soitems_table.php b/database/migrations/2018_05_15_034032_create_soitems_table.php similarity index 81% rename from database/migrations/2018_05_07_075445_create_soitems_table.php rename to database/migrations/2018_05_15_034032_create_soitems_table.php index 86334f3..827de63 100644 --- a/database/migrations/2018_05_07_075445_create_soitems_table.php +++ b/database/migrations/2018_05_15_034032_create_soitems_table.php @@ -16,6 +16,14 @@ class CreateSoitemsTable extends Migration Schema::create('soitems', function (Blueprint $table) { $table->increments('id'); + // foreign key for the so table + $table->unsignedInteger('so_id'); + $table->foreign('so_id') + ->references('id')->on('sos') + ->onDelete('cascade') + ->onUpdate('cascade'); + $table->Integer('status')->default('0'); + //Item details $table->integer('order_id'); $table->integer('brand_no'); diff --git a/routes/api.php b/routes/api.php index 8cc89af..da283a7 100644 --- a/routes/api.php +++ b/routes/api.php @@ -16,7 +16,7 @@ use Illuminate\Http\Request; //Route for the shipping order Route::get('/so', 'SoController@index');// get the list of the shipping order Route::get('/so/{so_id}', 'SoController@so');//get the shipping order -Route::post('/so/{so_id}', 'SoController@store');//create shipping order +Route::post('/so/{so_id}', 'SoController@store');//store shipping order Route::post('/so/{so_id}/cancel-order', 'SoController@cancelorder');//post the cancel order Route::delete('/so/{so_id}', 'SoController@delete');// delete the shipping order Route::put('/so/{so_id}', 'SoController@update');//update the shipping order From bf8e67327f6869dea55eb416c302d0b67f41dae0 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Tue, 15 May 2018 12:48:25 +0800 Subject: [PATCH 07/13] completed testing --- tests/Feature/ExampleTest.php | 21 ----- tests/Unit/ExampleTest.php | 19 ----- tests/Unit/ShippingorderTest.php | 132 +++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 40 deletions(-) delete mode 100644 tests/Feature/ExampleTest.php delete mode 100644 tests/Unit/ExampleTest.php create mode 100644 tests/Unit/ShippingorderTest.php diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index f31e495..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,21 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } -} diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index e9fe19c..0000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertTrue(true); - } -} diff --git a/tests/Unit/ShippingorderTest.php b/tests/Unit/ShippingorderTest.php new file mode 100644 index 0000000..5ffb8a0 --- /dev/null +++ b/tests/Unit/ShippingorderTest.php @@ -0,0 +1,132 @@ +json('GET', '/api/so'); + + $response->assertStatus(200); + } + + public function testGET() + { + $response = $this->json('GET', '/api/so/{so_id}'); + + $response->assertStatus(200); + } + + public function testPOSTso() + { + $response = $this->json('POST', '/api/so/{so_id}', [ + + 'id' => '1', + 'ff_id' => '1', + 'supplier_company_name' => 'Testing', + 'supplier_contact_person' => 'Testing', + 'supplier_contact_person_no' => '1234', + 'delivery_id' => '1', + 'warehouse_id' => '1', + + ]); + + $response->assertStatus(201); + } + + public function testPOSTsoITEM() + { + $response = $this->json('POST', '/api/so/soitem/{so_id}', [ + + 'so_id' => '2', + 'status' => '1', + 'order_id' => '2', + 'brand_no' => '2', + 'model_no' => '2', + 'item_code' => '2', + 'quantity_of_item' => '2', + 'uom' => 'test', + 'quantity_of_carton' => '2', + 'packaging_type' => 'Testing', + 'packaging_height' => '123', + 'packaging_width' => '123', + 'packaging_depth' => '123', + 'packaging_gross' => '123', + 'packaging_nett' => '123', + + ]); + + $response->assertStatus(201); + } + + public function testDELETEso() + { + $response = $this->json('DELETE', '/api/so/8'); + + $response->assertStatus(204); + } + + public function testDELETEsoitem() + { + $response = $this->json('DELETE', '/api/so/soitem/3'); + + $response->assertStatus(204); + } + + public function testPUTso() + { + + + $response = $this->json('PUT', '/api/so/2', [ + + 'id' => '1', + 'ff_id' => '1', + 'supplier_company_name' => 'Testinggggggggggggggggggggg', + 'supplier_contact_person' => 'Testing', + 'supplier_contact_person_no' => '1234', + 'delivery_id' => '1', + 'warehouse_id' => '1', + + ]); + + $response->assertStatus(200); + } + + public function testPUTsoitem() + { + + + $response = $this->json('PUT', '/api/so/soitem/1', [ + + 'so_id' => '2', + 'status' => '1', + 'order_id' => '2', + 'brand_no' => '2', + 'model_no' => '2', + 'item_code' => '2', + 'quantity_of_item' => '2', + 'uom' => 'test', + 'quantity_of_carton' => '2', + 'packaging_type' => 'Testinggggggggggggggggggg', + 'packaging_height' => '123', + 'packaging_width' => '123', + 'packaging_depth' => '123', + 'packaging_gross' => '123', + 'packaging_nett' => '123', + + ]); + + $response->assertStatus(200); + } + +} From 137b9dc5764f964f033ab9c93ec7e6279ab3e62c Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Thu, 17 May 2018 09:18:03 +0800 Subject: [PATCH 08/13] remove id at store, rename cancel order --- app/Http/Controllers/SoController.php | 2 +- routes/api.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/SoController.php b/app/Http/Controllers/SoController.php index c329bdc..5e6c7a9 100644 --- a/app/Http/Controllers/SoController.php +++ b/app/Http/Controllers/SoController.php @@ -76,7 +76,7 @@ class SoController extends Controller * @return \Illuminate\Http\Response */ //post the cancel order - public function cancelorder(Request $request) + public function cancelOrder(Request $request) { // } diff --git a/routes/api.php b/routes/api.php index da283a7..55a466a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -16,8 +16,8 @@ use Illuminate\Http\Request; //Route for the shipping order Route::get('/so', 'SoController@index');// get the list of the shipping order Route::get('/so/{so_id}', 'SoController@so');//get the shipping order -Route::post('/so/{so_id}', 'SoController@store');//store shipping order -Route::post('/so/{so_id}/cancel-order', 'SoController@cancelorder');//post the cancel order +Route::post('/so', 'SoController@store');//store shipping order +Route::post('/so/{so_id}/cancelOrder', 'SoController@cancelOrder');//post the cancel order Route::delete('/so/{so_id}', 'SoController@delete');// delete the shipping order Route::put('/so/{so_id}', 'SoController@update');//update the shipping order From 0969c8647bf6cbb117b5813fe7a8879d6d850d5b Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Mon, 21 May 2018 17:01:07 +0800 Subject: [PATCH 09/13] can insert both so and soitem into db, but have an error --- 0, | 0 1, | 0 2, | 0 41, | 0 8, | 0 SEED, | 0 app/Http/Controllers/SoController.php | 63 +++++--- app/So.php | 3 +- app/Soitem.php | 5 +- ...2018_05_15_034032_create_soitems_table.php | 1 - database/seeds/DatabaseSeeder.php | 3 +- database/seeds/SoSeeder.php | 29 ++++ database/seeds/SoitemSeeder.php | 64 ++++++++ routes/api.php | 4 +- tests/Unit/ShippingorderTest.php | 146 ++++++++++-------- 15 files changed, 229 insertions(+), 89 deletions(-) create mode 100644 0, create mode 100644 1, create mode 100644 2, create mode 100644 41, create mode 100644 8, create mode 100644 SEED, create mode 100644 database/seeds/SoSeeder.php create mode 100644 database/seeds/SoitemSeeder.php diff --git a/0, b/0, new file mode 100644 index 0000000..e69de29 diff --git a/1, b/1, new file mode 100644 index 0000000..e69de29 diff --git a/2, b/2, new file mode 100644 index 0000000..e69de29 diff --git a/41, b/41, new file mode 100644 index 0000000..e69de29 diff --git a/8, b/8, new file mode 100644 index 0000000..e69de29 diff --git a/SEED, b/SEED, new file mode 100644 index 0000000..e69de29 diff --git a/app/Http/Controllers/SoController.php b/app/Http/Controllers/SoController.php index 5e6c7a9..47d6073 100644 --- a/app/Http/Controllers/SoController.php +++ b/app/Http/Controllers/SoController.php @@ -25,7 +25,7 @@ class SoController extends Controller * @return \Illuminate\Http\Response */ //get the shipping order - public function so($so_id) + public function showso($so_id) { $so_id = So::find($so_id); return response()->json($so_id, 200); @@ -48,25 +48,51 @@ class SoController extends Controller * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ - //post shipping order + //post shipping order amd item public function store(Request $request) { - //for shipping order - $so = So::create($request->all()); + + //shipping order + $so = new So; + + $so->ff_id = $request->input('ff_id'); + $so->supplier_company_name = $request->input('supplier_company_name'); + $so->supplier_contact_person = $request->input('supplier_contact_person'); + $so->supplier_contact_person_no = $request->input('supplier_contact_person_no'); + $so->delivery_id = $request->input('delivery_id'); + $so->warehouse_id = $request->input('warehouse_id'); + + $so->save(); + + + //shipping order item + $soitems = $request->input("soitem"); + + foreach ($soitems as $soitem) + { + $new_soitem = new Soitem(array( + 'so_id'=>$soitem['so_id'], + 'status'=>$soitem['status'], + 'order_id'=>$soitem['order_id'], + 'brand_no'=>$soitem['brand_no'], + 'model_no'=>$soitem['model_no'], + 'item_code'=>$soitem['item_code'], + 'quantity_of_item'=>$soitem['quantity_of_item'], + 'uom'=>$soitem['uom'], + 'quantity_of_carton'=>$soitem['quantity_of_carton'], + 'packaging_type'=>$soitem['packaging_type'], + 'packaging_height'=>$soitem['packaging_height'], + 'packaging_width'=>$soitem['packaging_width'], + 'packaging_depth'=>$soitem['packaging_depth'], + 'packaging_gross'=>$soitem['packaging_gross'], + 'packaging_nett'=>$soitem['packaging_nett'], + )); + $new_soitem->save(); - return response()->json($so, 201); - - } - - //post shipping order item - public function storeitem(Request $request) - { - - //for shipping order item - $soitem = Soitem::create($request->all()); - - return response()->json($soitem, 201); + } + return response()->json(['so'=>$so],['soitem'=>$soitems], 201); + } /** @@ -110,10 +136,10 @@ class SoController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function update(Request $request, $so_id) + public function update(Request $request, $id) { //for shipping order - $so_id = So::find($so_id); + $so_id = So::find($id); $so_id->ff_id = $request->input('ff_id'); $so_id->supplier_company_name = $request->input('supplier_company_name'); $so_id->supplier_contact_person = $request->input('supplier_contact_person'); @@ -132,6 +158,7 @@ class SoController extends Controller //for shipping order item $so_id = Soitem::find($so_id); + $so_id->status = $request->input('status'); $so_id->order_id = $request->input('order_id'); $so_id->brand_no = $request->input('brand_no'); $so_id->model_no = $request->input('model_no'); diff --git a/app/So.php b/app/So.php index 0dec710..e096127 100644 --- a/app/So.php +++ b/app/So.php @@ -17,7 +17,8 @@ class So extends Model public function Soitem() { - return $this->hasMany(Soitem::class); + return $this->hasMany('App\Soitem', 'so_id'); } + } diff --git a/app/Soitem.php b/app/Soitem.php index 4ef8b82..bd4433b 100644 --- a/app/Soitem.php +++ b/app/Soitem.php @@ -27,8 +27,9 @@ class Soitem extends Model public function So() { - return $this->belongsTo(So::class); + return $this->belongsTo('App\So', 'id'); } - + + } diff --git a/database/migrations/2018_05_15_034032_create_soitems_table.php b/database/migrations/2018_05_15_034032_create_soitems_table.php index 827de63..668348a 100644 --- a/database/migrations/2018_05_15_034032_create_soitems_table.php +++ b/database/migrations/2018_05_15_034032_create_soitems_table.php @@ -15,7 +15,6 @@ class CreateSoitemsTable extends Migration { Schema::create('soitems', function (Blueprint $table) { $table->increments('id'); - // foreign key for the so table $table->unsignedInteger('so_id'); $table->foreign('so_id') diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index e119db6..5d1cff1 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -11,6 +11,7 @@ class DatabaseSeeder extends Seeder */ public function run() { - // $this->call(UsersTableSeeder::class); + //$this->call(UsersTableSeeder::class); + $this->call(SoSeeder::class); } } diff --git a/database/seeds/SoSeeder.php b/database/seeds/SoSeeder.php new file mode 100644 index 0000000..90256c1 --- /dev/null +++ b/database/seeds/SoSeeder.php @@ -0,0 +1,29 @@ +insert([ + + // 'id' => '8', + 'ff_id' => '4', + 'supplier_company_name' => 'SEED', + 'supplier_contact_person' => 'SEED', + 'supplier_contact_person_no' => '1234', + 'delivery_id' => '4', + 'warehouse_id' => '4', + 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), + 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), + ]); + } +} diff --git a/database/seeds/SoitemSeeder.php b/database/seeds/SoitemSeeder.php new file mode 100644 index 0000000..2613c08 --- /dev/null +++ b/database/seeds/SoitemSeeder.php @@ -0,0 +1,64 @@ +insert([ + + ([ + + // 'id' => '8', + 'so_id' => '2', + 'status' => '0', + 'order_id' => '1', + 'brand_no' => '1', + 'model_no' => '1', + 'item_code' => '1', + 'quantity_of_item' => '1', + 'uom' => 'SEED', + 'quantity_of_carton' => '1', + 'packaging_type' => '1', + 'packaging_height' => '1', + 'packaging_width' => '1', + 'packaging_depth' => '1', + 'packaging_gross' => '1', + 'packaging_nett' => '41', + 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), + 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), + + ]), + ([ + // 'id' => '8', + 'so_id' => '2', + 'status' => '0', + 'order_id' => '1', + 'brand_no' => '1', + 'model_no' => '1', + 'item_code' => '1', + 'quantity_of_item' => '1', + 'uom' => 'SEED', + 'quantity_of_carton' => '1', + 'packaging_type' => '1', + 'packaging_height' => '1', + 'packaging_width' => '1', + 'packaging_depth' => '1', + 'packaging_gross' => '1', + 'packaging_nett' => '41', + 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), + 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), + ]), + + ]); + } +} diff --git a/routes/api.php b/routes/api.php index 55a466a..9a9f224 100644 --- a/routes/api.php +++ b/routes/api.php @@ -15,14 +15,14 @@ use Illuminate\Http\Request; */ //Route for the shipping order Route::get('/so', 'SoController@index');// get the list of the shipping order -Route::get('/so/{so_id}', 'SoController@so');//get the shipping order +Route::get('/so/{so_id}', 'SoController@showso');//get the shipping order Route::post('/so', 'SoController@store');//store shipping order Route::post('/so/{so_id}/cancelOrder', 'SoController@cancelOrder');//post the cancel order Route::delete('/so/{so_id}', 'SoController@delete');// delete the shipping order Route::put('/so/{so_id}', 'SoController@update');//update the shipping order //Route for the shipping order item -Route::post('/so/soitem/{so_id}', 'SoController@storeitem');//create shipping order item + Route::delete('/so/soitem/{so_id}', 'SoController@deleteitem');//delete the shipping order item Route::put('/so/soitem/{so_id}', 'SoController@updateitem');//update the shipping order item diff --git a/tests/Unit/ShippingorderTest.php b/tests/Unit/ShippingorderTest.php index 5ffb8a0..1b623ae 100644 --- a/tests/Unit/ShippingorderTest.php +++ b/tests/Unit/ShippingorderTest.php @@ -27,27 +27,28 @@ class ShippingorderTest extends TestCase $response->assertStatus(200); } - public function testPOSTso() - { - $response = $this->json('POST', '/api/so/{so_id}', [ + // public function testPOSTso() + // { + // $response = $this->json('POST', '/api/so/{so_id}', [ - 'id' => '1', - 'ff_id' => '1', - 'supplier_company_name' => 'Testing', - 'supplier_contact_person' => 'Testing', - 'supplier_contact_person_no' => '1234', - 'delivery_id' => '1', - 'warehouse_id' => '1', + // 'id' => '1', + // 'ff_id' => '1', + // 'supplier_company_name' => 'Testing', + // 'supplier_contact_person' => 'Testing', + // 'supplier_contact_person_no' => '1234', + // 'delivery_id' => '1', + // 'warehouse_id' => '1', - ]); + // ]); - $response->assertStatus(201); - } + // $response->assertStatus(201); + // } public function testPOSTsoITEM() { - $response = $this->json('POST', '/api/so/soitem/{so_id}', [ - + $response = $this->json('POST', '/api/so/soitem/{so_id}', + + [ 'so_id' => '2', 'status' => '1', 'order_id' => '2', @@ -63,51 +64,9 @@ class ShippingorderTest extends TestCase 'packaging_depth' => '123', 'packaging_gross' => '123', 'packaging_nett' => '123', - - ]); - - $response->assertStatus(201); - } - - public function testDELETEso() - { - $response = $this->json('DELETE', '/api/so/8'); - - $response->assertStatus(204); - } - - public function testDELETEsoitem() - { - $response = $this->json('DELETE', '/api/so/soitem/3'); - - $response->assertStatus(204); - } - - public function testPUTso() - { - - - $response = $this->json('PUT', '/api/so/2', [ - - 'id' => '1', - 'ff_id' => '1', - 'supplier_company_name' => 'Testinggggggggggggggggggggg', - 'supplier_contact_person' => 'Testing', - 'supplier_contact_person_no' => '1234', - 'delivery_id' => '1', - 'warehouse_id' => '1', - - ]); - - $response->assertStatus(200); - } - - public function testPUTsoitem() - { - - - $response = $this->json('PUT', '/api/so/soitem/1', [ - + ], + + [ 'so_id' => '2', 'status' => '1', 'order_id' => '2', @@ -117,16 +76,75 @@ class ShippingorderTest extends TestCase 'quantity_of_item' => '2', 'uom' => 'test', 'quantity_of_carton' => '2', - 'packaging_type' => 'Testinggggggggggggggggggg', + 'packaging_type' => 'Testing', 'packaging_height' => '123', 'packaging_width' => '123', 'packaging_depth' => '123', 'packaging_gross' => '123', 'packaging_nett' => '123', - ]); - - $response->assertStatus(200); + + $response->assertStatus(201); } + // public function testDELETEso() + // { + // $response = $this->json('DELETE', '/api/so/8'); + + // $response->assertStatus(204); + // } + + // public function testDELETEsoitem() + // { + // $response = $this->json('DELETE', '/api/so/soitem/3'); + + // $response->assertStatus(204); + // } + + // public function testPUTso() + // { + + + // $response = $this->json('PUT', '/api/so/2', [ + + // 'id' => '1', + // 'ff_id' => '1', + // 'supplier_company_name' => 'Testinggggggggggggggggggggg', + // 'supplier_contact_person' => 'Testing', + // 'supplier_contact_person_no' => '1234', + // 'delivery_id' => '1', + // 'warehouse_id' => '1', + + // ]); + + // $response->assertStatus(200); + // } + + // public function testPUTsoitem() + // { + + + // $response = $this->json('PUT', '/api/so/soitem/1', [ + + // 'so_id' => '2', + // 'status' => '1', + // 'order_id' => '2', + // 'brand_no' => '2', + // 'model_no' => '2', + // 'item_code' => '2', + // 'quantity_of_item' => '2', + // 'uom' => 'test', + // 'quantity_of_carton' => '2', + // 'packaging_type' => 'Testinggggggggggggggggggg', + // 'packaging_height' => '123', + // 'packaging_width' => '123', + // 'packaging_depth' => '123', + // 'packaging_gross' => '123', + // 'packaging_nett' => '123', + + // ]); + + // $response->assertStatus(200); + // } + } From 16c1a22ebfff34fde55aeab97c309fda597cc354 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Mon, 21 May 2018 17:04:24 +0800 Subject: [PATCH 10/13] can insert both so and soitem into db, but have an error --- 0, | 0 1, | 0 2, | 0 41, | 0 8, | 0 5 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 0, delete mode 100644 1, delete mode 100644 2, delete mode 100644 41, delete mode 100644 8, diff --git a/0, b/0, deleted file mode 100644 index e69de29..0000000 diff --git a/1, b/1, deleted file mode 100644 index e69de29..0000000 diff --git a/2, b/2, deleted file mode 100644 index e69de29..0000000 diff --git a/41, b/41, deleted file mode 100644 index e69de29..0000000 diff --git a/8, b/8, deleted file mode 100644 index e69de29..0000000 From 302238047dc8a5e218e2e1f83a5efab4b1d26a33 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Mon, 21 May 2018 17:12:01 +0800 Subject: [PATCH 11/13] completed add multiple item --- app/Http/Controllers/SoController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/SoController.php b/app/Http/Controllers/SoController.php index 47d6073..42dd12d 100644 --- a/app/Http/Controllers/SoController.php +++ b/app/Http/Controllers/SoController.php @@ -91,7 +91,7 @@ class SoController extends Controller } - return response()->json(['so'=>$so],['soitem'=>$soitems], 201); + return response()->json(['so'=>$so], 201); } From 32db666e0920ca39d08a46c0a4dc6bd733ebbe73 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Tue, 22 May 2018 09:12:38 +0800 Subject: [PATCH 12/13] completed multiple item order --- app/Http/Controllers/SoController.php | 1 + routes/api.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/SoController.php b/app/Http/Controllers/SoController.php index 42dd12d..f5e2495 100644 --- a/app/Http/Controllers/SoController.php +++ b/app/Http/Controllers/SoController.php @@ -95,6 +95,7 @@ class SoController extends Controller } + /** * Store a newly created resource in storage. * diff --git a/routes/api.php b/routes/api.php index 9a9f224..581a776 100644 --- a/routes/api.php +++ b/routes/api.php @@ -22,7 +22,6 @@ Route::delete('/so/{so_id}', 'SoController@delete');// delete the shipping order Route::put('/so/{so_id}', 'SoController@update');//update the shipping order //Route for the shipping order item - Route::delete('/so/soitem/{so_id}', 'SoController@deleteitem');//delete the shipping order item Route::put('/so/soitem/{so_id}', 'SoController@updateitem');//update the shipping order item From 8c8c66572c76a22c470fdcfcf96460054a912dd7 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Wed, 23 May 2018 09:41:53 +0800 Subject: [PATCH 13/13] added testing for shipping order and shipping order item --- app/Http/Controllers/SoController.php | 16 +-- tests/Unit/ShippingorderTest.php | 188 +++++++++++++------------- 2 files changed, 97 insertions(+), 107 deletions(-) diff --git a/app/Http/Controllers/SoController.php b/app/Http/Controllers/SoController.php index f5e2495..1a6528f 100644 --- a/app/Http/Controllers/SoController.php +++ b/app/Http/Controllers/SoController.php @@ -50,25 +50,21 @@ class SoController extends Controller */ //post shipping order amd item public function store(Request $request) - { - + { + //shipping order $so = new So; - $so->ff_id = $request->input('ff_id'); $so->supplier_company_name = $request->input('supplier_company_name'); $so->supplier_contact_person = $request->input('supplier_contact_person'); $so->supplier_contact_person_no = $request->input('supplier_contact_person_no'); $so->delivery_id = $request->input('delivery_id'); $so->warehouse_id = $request->input('warehouse_id'); - $so->save(); - - //shipping order item - $soitems = $request->input("soitem"); - - foreach ($soitems as $soitem) + //shipping order item + $soitems = $request->input("soitem"); + foreach ($soitems as $soitem) { $new_soitem = new Soitem(array( 'so_id'=>$soitem['so_id'], @@ -87,7 +83,7 @@ class SoController extends Controller 'packaging_gross'=>$soitem['packaging_gross'], 'packaging_nett'=>$soitem['packaging_nett'], )); - $new_soitem->save(); + $new_soitem->save(); } diff --git a/tests/Unit/ShippingorderTest.php b/tests/Unit/ShippingorderTest.php index 1b623ae..60219ab 100644 --- a/tests/Unit/ShippingorderTest.php +++ b/tests/Unit/ShippingorderTest.php @@ -27,124 +27,118 @@ class ShippingorderTest extends TestCase $response->assertStatus(200); } - // public function testPOSTso() - // { - // $response = $this->json('POST', '/api/so/{so_id}', [ - - // 'id' => '1', - // 'ff_id' => '1', - // 'supplier_company_name' => 'Testing', - // 'supplier_contact_person' => 'Testing', - // 'supplier_contact_person_no' => '1234', - // 'delivery_id' => '1', - // 'warehouse_id' => '1', - - // ]); - - // $response->assertStatus(201); - // } - - public function testPOSTsoITEM() + public function testPOSTso() { - $response = $this->json('POST', '/api/so/soitem/{so_id}', - - [ - 'so_id' => '2', - 'status' => '1', - 'order_id' => '2', - 'brand_no' => '2', - 'model_no' => '2', - 'item_code' => '2', - 'quantity_of_item' => '2', - 'uom' => 'test', - 'quantity_of_carton' => '2', - 'packaging_type' => 'Testing', - 'packaging_height' => '123', - 'packaging_width' => '123', - 'packaging_depth' => '123', - 'packaging_gross' => '123', - 'packaging_nett' => '123', - ], + $response = $this->json('POST', '/api/so', [ - 'so_id' => '2', - 'status' => '1', - 'order_id' => '2', - 'brand_no' => '2', - 'model_no' => '2', - 'item_code' => '2', - 'quantity_of_item' => '2', - 'uom' => 'test', - 'quantity_of_carton' => '2', - 'packaging_type' => 'Testing', - 'packaging_height' => '123', - 'packaging_width' => '123', - 'packaging_depth' => '123', - 'packaging_gross' => '123', - 'packaging_nett' => '123', - ]); + 'id' => '3', + 'ff_id' => '3', + 'supplier_company_name' => 'Testing', + 'supplier_contact_person' => 'Testing', + 'supplier_contact_person_no' => '1234', + 'delivery_id' => '3', + 'warehouse_id' => '3', + + 'soitem' => [ + 0 => [ + 'so_id' => '3', + 'status' => '1', + 'order_id' => '3', + 'brand_no' => '3', + 'model_no' => '3', + 'item_code' => '3', + 'quantity_of_item' => '3', + 'uom' => 'test', + 'quantity_of_carton' => '3', + 'packaging_type' => 'Testing', + 'packaging_height' => '123', + 'packaging_width' => '123', + 'packaging_depth' => '123', + 'packaging_gross' => '123', + 'packaging_nett' => '123', + ], + 1 => [ + 'so_id' => '2', + 'status' => '1', + 'order_id' => '2', + 'brand_no' => '2', + 'model_no' => '2', + 'item_code' => '2', + 'quantity_of_item' => '2', + 'uom' => 'test', + 'quantity_of_carton' => '2', + 'packaging_type' => 'Testing', + 'packaging_height' => '123', + 'packaging_width' => '123', + 'packaging_depth' => '123', + 'packaging_gross' => '123', + 'packaging_nett' => '123', + ] + ] + ]); $response->assertStatus(201); } - // public function testDELETEso() - // { - // $response = $this->json('DELETE', '/api/so/8'); + public function testDELETEso() + { + $response = $this->json('DELETE', '/api/so/8'); - // $response->assertStatus(204); - // } + $response->assertStatus(204); + } - // public function testDELETEsoitem() - // { - // $response = $this->json('DELETE', '/api/so/soitem/3'); + public function testDELETEsoitem() + { + $response = $this->json('DELETE', '/api/so/soitem/3'); - // $response->assertStatus(204); - // } + $response->assertStatus(204); + } - // public function testPUTso() - // { + public function testPUTso() + { - // $response = $this->json('PUT', '/api/so/2', [ + $response = $this->json('PUT', '/api/so/2', [ - // 'id' => '1', - // 'ff_id' => '1', - // 'supplier_company_name' => 'Testinggggggggggggggggggggg', - // 'supplier_contact_person' => 'Testing', - // 'supplier_contact_person_no' => '1234', - // 'delivery_id' => '1', - // 'warehouse_id' => '1', + 'id' => '1', + 'ff_id' => '1', + 'supplier_company_name' => 'Testinggggggggggggggggggggg', + 'supplier_contact_person' => 'Testing', + 'supplier_contact_person_no' => '1234', + 'delivery_id' => '1', + 'warehouse_id' => '1', - // ]); + ]); - // $response->assertStatus(200); - // } + $response->assertStatus(200); + } - // public function testPUTsoitem() - // { + public function testPUTsoitem() + { - // $response = $this->json('PUT', '/api/so/soitem/1', [ + $response = $this->json('PUT', '/api/so/soitem/1', [ - // 'so_id' => '2', - // 'status' => '1', - // 'order_id' => '2', - // 'brand_no' => '2', - // 'model_no' => '2', - // 'item_code' => '2', - // 'quantity_of_item' => '2', - // 'uom' => 'test', - // 'quantity_of_carton' => '2', - // 'packaging_type' => 'Testinggggggggggggggggggg', - // 'packaging_height' => '123', - // 'packaging_width' => '123', - // 'packaging_depth' => '123', - // 'packaging_gross' => '123', - // 'packaging_nett' => '123', + 'so_id' => '2', + 'status' => '1', + 'order_id' => '2', + 'brand_no' => '2', + 'model_no' => '2', + 'item_code' => '2', + 'quantity_of_item' => '2', + 'uom' => 'test', + 'quantity_of_carton' => '2', + 'packaging_type' => 'Testinggggggggggggggggggg', + 'packaging_height' => '123', + 'packaging_width' => '123', + 'packaging_depth' => '123', + 'packaging_gross' => '123', + 'packaging_nett' => '123', - // ]); + ]); - // $response->assertStatus(200); - // } + $response->assertStatus(200); + } }