From 1361538f8bf5bf35d946f16f2f9cce91f0033842 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Thu, 7 Jun 2018 09:55:43 +0800 Subject: [PATCH 1/2] solve multiple error --- app/Http/Controllers/SoController.php | 2 +- app/So.php | 7 +++- .../2018_05_07_062017_create_sos_table.php | 6 --- ...add_foreign_key_comid_to_the_sos_table.php | 38 +++++++++++++++++++ database/seeds/SoSeeder.php | 7 ++-- database/seeds/SoitemSeeder.php | 4 +- 6 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 database/migrations/2018_06_06_074452_add_foreign_key_comid_to_the_sos_table.php diff --git a/app/Http/Controllers/SoController.php b/app/Http/Controllers/SoController.php index efb7955..917067c 100644 --- a/app/Http/Controllers/SoController.php +++ b/app/Http/Controllers/SoController.php @@ -44,7 +44,7 @@ class SoController extends Controller //shipping order $so = new So; - $so->ff_id = $request->input('ff_id'); + $so->ff_id = Auth::user()->company()->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'); diff --git a/app/So.php b/app/So.php index e096127..fd5404a 100644 --- a/app/So.php +++ b/app/So.php @@ -17,7 +17,12 @@ class So extends Model public function Soitem() { - return $this->hasMany('App\Soitem', 'so_id'); + return $this->hasMany('App\Soitem'); + } + + public function company() + { + return $this->belongsTo('App\Company'); } diff --git a/database/migrations/2018_05_07_062017_create_sos_table.php b/database/migrations/2018_05_07_062017_create_sos_table.php index ce2adf3..09ba4da 100644 --- a/database/migrations/2018_05_07_062017_create_sos_table.php +++ b/database/migrations/2018_05_07_062017_create_sos_table.php @@ -15,17 +15,11 @@ class CreateSosTable extends Migration { Schema::create('sos', function (Blueprint $table) { $table->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(); diff --git a/database/migrations/2018_06_06_074452_add_foreign_key_comid_to_the_sos_table.php b/database/migrations/2018_06_06_074452_add_foreign_key_comid_to_the_sos_table.php new file mode 100644 index 0000000..7f332f9 --- /dev/null +++ b/database/migrations/2018_06_06_074452_add_foreign_key_comid_to_the_sos_table.php @@ -0,0 +1,38 @@ +unsignedInteger('com_id'); + $table->foreign('com_id') + ->references('id')->on('companies') + ->onDelete('cascade'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('sos', function (Blueprint $table) { + // + }); + } +} diff --git a/database/seeds/SoSeeder.php b/database/seeds/SoSeeder.php index fafe984..ab6dbaf 100644 --- a/database/seeds/SoSeeder.php +++ b/database/seeds/SoSeeder.php @@ -16,14 +16,15 @@ class SoSeeder extends Seeder DB::table('sos')->insert([ 'id' => '9999', - 'ff_id' => '4', + 'ff_id' => '1', 'supplier_company_name' => 'SEED', 'supplier_contact_person' => 'SEED', 'supplier_contact_person_no' => '1234', - 'delivery_id' => '4', - 'warehouse_id' => '4', + 'delivery_id' => '1', + 'warehouse_id' => '1', '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 index 2c61db6..3515a96 100644 --- a/database/seeds/SoitemSeeder.php +++ b/database/seeds/SoitemSeeder.php @@ -32,7 +32,7 @@ class SoitemSeeder extends Seeder 'packaging_width' => '1', 'packaging_depth' => '1', 'packaging_gross' => '1', - 'packaging_nett' => '41', + 'packaging_nett' => '1', 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), @@ -53,7 +53,7 @@ class SoitemSeeder extends Seeder 'packaging_width' => '1', 'packaging_depth' => '1', 'packaging_gross' => '1', - 'packaging_nett' => '41', + 'packaging_nett' => '1', 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), ]), From 59d9588fdcce371daccf0c714420f0cb7988ae01 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Thu, 7 Jun 2018 11:03:46 +0800 Subject: [PATCH 2/2] updated codes --- app/Http/Controllers/SoController.php | 108 +++++++++----------------- routes/api.php | 2 +- tests/Unit/ShippingorderTest.php | 47 ----------- 3 files changed, 37 insertions(+), 120 deletions(-) diff --git a/app/Http/Controllers/SoController.php b/app/Http/Controllers/SoController.php index 917067c..32f2a45 100644 --- a/app/Http/Controllers/SoController.php +++ b/app/Http/Controllers/SoController.php @@ -9,31 +9,9 @@ use App\Soitem; class SoController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - //get the shipping order - public function showso($so_id) - { - $so_id = So::find($so_id); - return response()->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. + * Store shipping order item. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response @@ -42,8 +20,8 @@ class SoController extends Controller public function store(Request $request) { - //shipping order $so = new So; + $so = So::where("user_id", Auth::user()->com_id)->first(); $so->ff_id = Auth::user()->company()->id; $so->supplier_company_name = $request->input('supplier_company_name'); $so->supplier_contact_person = $request->input('supplier_contact_person'); @@ -53,7 +31,7 @@ class SoController extends Controller $so->save(); //shipping order item - $soitems = $request->input("soitem"); + $soitems = $request->input('soitem'); foreach ($soitems as $soitem) { $new_soitem = new Soitem(array( @@ -91,12 +69,12 @@ class SoController extends Controller //post the cancel order public function cancelOrder(Request $request) { - // + } /** - * Update the specified resource in storage. + * Update the shipping order and item. * * @param \Illuminate\Http\Request $request * @param int $id @@ -104,54 +82,48 @@ class SoController extends Controller */ 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 = So::find($id); + $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(); - $so_id->save(); + $soitems = $request->input('soitem'); + foreach ($soitems as $soitem) + { + $new_soitem = Soitem::where('so_id', $id)->first(); + $new_soitem->status = $soitem['status']; + $new_soitem->order_id = $soitem['order_id']; + $new_soitem->brand_no = $soitem['brand_no']; + $new_soitem->model_no = $soitem['model_no']; + $new_soitem->item_code = $soitem['item_code']; + $new_soitem->quantity_of_item = $soitem['quantity_of_item']; + $new_soitem->uom = $soitem['uom']; + $new_soitem->quantity_of_carton = $soitem['quantity_of_carton']; + $new_soitem->packaging_type = $soitem['packaging_type']; + $new_soitem->packaging_height = $soitem['packaging_height']; + $new_soitem->packaging_width = $soitem['packaging_width']; + $new_soitem->packaging_depth = $soitem['packaging_depth']; + $new_soitem->packaging_gross = $soitem['packaging_gross']; + $new_soitem->packaging_nett = $soitem['packaging_nett']; + $new_soitem->save(); - return response()->json(['so_id'=>$so_id],200); + } + + return response()->json(['so'=>$so],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. + * Remove the shipping order and item * * @param int $id * @return \Illuminate\Http\Response */ - // delete the shipping order public function delete(So $so_id) { $so_id->delete($so_id); @@ -160,12 +132,4 @@ class SoController extends Controller } - // 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 581a776..04fffa0 100644 --- a/routes/api.php +++ b/routes/api.php @@ -17,7 +17,7 @@ use Illuminate\Http\Request; 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::put('/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 diff --git a/tests/Unit/ShippingorderTest.php b/tests/Unit/ShippingorderTest.php index 60219ab..aa6cad6 100644 --- a/tests/Unit/ShippingorderTest.php +++ b/tests/Unit/ShippingorderTest.php @@ -13,19 +13,6 @@ class ShippingorderTest extends TestCase * * @return void */ - public function testGETtheindex() - { - $response = $this->json('GET', '/api/so'); - - $response->assertStatus(200); - } - - public function testGET() - { - $response = $this->json('GET', '/api/so/{so_id}'); - - $response->assertStatus(200); - } public function testPOSTso() { @@ -88,13 +75,6 @@ class ShippingorderTest extends TestCase $response->assertStatus(204); } - public function testDELETEsoitem() - { - $response = $this->json('DELETE', '/api/so/soitem/3'); - - $response->assertStatus(204); - } - public function testPUTso() { @@ -114,31 +94,4 @@ class ShippingorderTest extends TestCase $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); - } - }