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 new file mode 100644 index 0000000..efb7955 --- /dev/null +++ b/app/Http/Controllers/SoController.php @@ -0,0 +1,171 @@ +json($so_id, 200); + + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + // + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + //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) + { + $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'=>$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) + { + // + } + + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param int $id + * @return \Illuminate\Http\Response + */ + public function update(Request $request, $id) + { + //for shipping order + $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'); + $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->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'); + $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); + + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + // delete the shipping order + 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/app/So.php b/app/So.php new file mode 100644 index 0000000..e096127 --- /dev/null +++ b/app/So.php @@ -0,0 +1,24 @@ +hasMany('App\Soitem', 'so_id'); + } + + +} diff --git a/app/Soitem.php b/app/Soitem.php new file mode 100644 index 0000000..bd4433b --- /dev/null +++ b/app/Soitem.php @@ -0,0 +1,35 @@ +belongsTo('App\So', 'id'); + } + + + +} diff --git a/database/migrations/2018_05_07_062017_create_sos_table.php b/database/migrations/2018_05_07_062017_create_sos_table.php new file mode 100644 index 0000000..ce2adf3 --- /dev/null +++ b/database/migrations/2018_05_07_062017_create_sos_table.php @@ -0,0 +1,44 @@ +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_15_034032_create_soitems_table.php b/database/migrations/2018_05_15_034032_create_soitems_table.php new file mode 100644 index 0000000..668348a --- /dev/null +++ b/database/migrations/2018_05_15_034032_create_soitems_table.php @@ -0,0 +1,59 @@ +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'); + $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/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 4a81932..f10d079 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -11,7 +11,12 @@ class DatabaseSeeder extends Seeder */ public function run() { +<<<<<<< HEAD $this->call(LaratrustSeeder::class); $this->call(UsersTableSeeder::class); +======= + //$this->call(UsersTableSeeder::class); + $this->call(SoSeeder::class); +>>>>>>> 9619cab40743a5e70ea341c611c68500f2a047fe } } diff --git a/database/seeds/SoSeeder.php b/database/seeds/SoSeeder.php new file mode 100644 index 0000000..fafe984 --- /dev/null +++ b/database/seeds/SoSeeder.php @@ -0,0 +1,29 @@ +insert([ + + 'id' => '9999', + '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..2c61db6 --- /dev/null +++ b/database/seeds/SoitemSeeder.php @@ -0,0 +1,63 @@ +insert([ + + ([ + + 'so_id' => '9999', + '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'), + + ]), + ([ + + 'so_id' => '9999', + '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 1beaaec..021b548 100644 --- a/routes/api.php +++ b/routes/api.php @@ -12,6 +12,19 @@ use App\Company; | 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/{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::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 + + /* Authentication */ Route::post('login', 'AuthController@login'); diff --git a/tests/Unit/ShippingorderTest.php b/tests/Unit/ShippingorderTest.php new file mode 100644 index 0000000..60219ab --- /dev/null +++ b/tests/Unit/ShippingorderTest.php @@ -0,0 +1,144 @@ +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', + + [ + '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'); + + $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); + } + +}