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); + // } + }