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..914423e --- /dev/null +++ b/app/Http/Controllers/SoController.php @@ -0,0 +1,167 @@ +json($so_id, 200); + + } + + /** + * 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'=>$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 = 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(); + + $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'=>$so],201); + + } + + + /** + * 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/Http/Controllers/WarehousearrangementController.php b/app/Http/Controllers/WarehousearrangementController.php index 4a78d60..58226c0 100644 --- a/app/Http/Controllers/WarehousearrangementController.php +++ b/app/Http/Controllers/WarehousearrangementController.php @@ -46,6 +46,7 @@ class WarehousearrangementController extends Controller $warehouseitems = $request->input("warehouseitem"); foreach ($warehouseitems as $warehouseitem) { + $new_warehouseitem = new Warehouseitem(array( 'description'=>$warehouseitem['description'], 'nominal_ctn'=>$warehouseitem['nominal_ctn'], @@ -58,8 +59,7 @@ class WarehousearrangementController extends Controller 'isDamaged'=>$warehouseitem['isDamaged'], 'status'=>$warehouseitem['status'], 'image'=>$warehouseitem['image'], - 'wa_id'=>$warehouseitem['wa_id'], - 'soitem_id'=>$warehouseitem['soitem_id'], + 'wa_id'=>$warehousearr->id, )); $new_warehouseitem->save(); @@ -93,8 +93,7 @@ class WarehousearrangementController extends Controller $warehousearr->save(); //store warehouse receive note item - $warehouseitems = $request->input('warehouseitem'); - + $warehouseitems = $request->input('warehouseitem'); foreach ($warehouseitems as $warehouseitem) { $ex_warehouseitem = Warehouseitem::where('wa_id', $id)->first(); @@ -109,11 +108,7 @@ class WarehousearrangementController extends Controller $ex_warehouseitem->isDamaged = $warehouseitem['isDamaged']; $ex_warehouseitem->status = $warehouseitem['status']; $ex_warehouseitem->actual_measurement = $warehouseitem['actual_measurement']; - $ex_warehouseitem->image = $warehouseitem['image']; - - // $ex_warehouseitem->wa_id = $warehouseitem['wa_id']; - // $ex_warehouseitem->soitem_id = $warehouseitem['soitem_id']; - + $ex_warehouseitem->image = $warehouseitem['image']; $ex_warehouseitem->save(); } diff --git a/app/So.php b/app/So.php new file mode 100644 index 0000000..eeaec8a --- /dev/null +++ b/app/So.php @@ -0,0 +1,28 @@ +hasMany('App\Soitem'); + } + public function warehousearr() + { + return $this->hasMany('App\Warehousearr'); + } + + +} diff --git a/app/Soitem.php b/app/Soitem.php new file mode 100644 index 0000000..3d65e3a --- /dev/null +++ b/app/Soitem.php @@ -0,0 +1,35 @@ +belongsTo('App\So'); + } + + + +} diff --git a/config/database.php b/config/database.php index af32da1..62f4632 100644 --- a/config/database.php +++ b/config/database.php @@ -54,6 +54,21 @@ return [ 'engine' => null, ], + 'testing' => [ + 'driver' => 'mysql', + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '3306'), + 'database' => 'testingizyim', + 'username' => 'root', + 'password' => '', + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'strict' => true, + 'engine' => null, + ], + 'pgsql' => [ 'driver' => 'pgsql', 'host' => env('DB_HOST', '127.0.0.1'), diff --git a/database/factories/SoFactory.php b/database/factories/SoFactory.php new file mode 100644 index 0000000..ef461df --- /dev/null +++ b/database/factories/SoFactory.php @@ -0,0 +1,25 @@ +define(App\So::class, function (Faker $faker) { + return [ + 'ff_id'=>'testing', + 'supplier_company_name'=>'testing', + 'supplier_contact_person'=>'testing', + 'supplier_contact_person_no'=>'12345', + 'delivery_id'=>'12345', + 'warehouse_id'=>'testing', + ]; +}); 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/migrations/2018_05_30_015110_drop_foreign_key_in_warehouseitems_table.php b/database/migrations/2018_05_30_015110_drop_foreign_key_in_warehouseitems_table.php index f2fe981..29a5610 100644 --- a/database/migrations/2018_05_30_015110_drop_foreign_key_in_warehouseitems_table.php +++ b/database/migrations/2018_05_30_015110_drop_foreign_key_in_warehouseitems_table.php @@ -27,8 +27,8 @@ class DropForeignKeyInWarehouseitemsTable extends Migration { Schema::table('warehouseitems', function (Blueprint $table) { - // $table->dropColumn('soitem_id'); - // $table->dropForeign('warehouseitems_soitem_id_foreign'); + $table->dropColumn('soitem_id'); + $table->dropForeign('warehouseitems_soitem_id_foreign'); }); } diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 4a81932..1785f6c 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -13,5 +13,7 @@ class DatabaseSeeder extends Seeder { $this->call(LaratrustSeeder::class); $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..5118d7f --- /dev/null +++ b/database/seeds/SoSeeder.php @@ -0,0 +1,29 @@ +insert([ + + 'ff_id' => '1', + 'supplier_company_name' => 'SEED', + 'supplier_contact_person' => 'SEED', + 'supplier_contact_person_no' => '1234', + '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 new file mode 100644 index 0000000..c865d1e --- /dev/null +++ b/database/seeds/SoitemSeeder.php @@ -0,0 +1,64 @@ +insert([ + + ([ + + + 'so_id' => '3', + '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' => '3', + '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/phpunit.xml b/phpunit.xml index 9ee3e73..bb33592 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -27,6 +27,7 @@ + diff --git a/routes/api.php b/routes/api.php index 8db69ea..4a1d439 100644 --- a/routes/api.php +++ b/routes/api.php @@ -2,6 +2,8 @@ use Illuminate\Http\Request; use App\Company; + + /* |-------------------------------------------------------------------------- | API Routes @@ -13,6 +15,17 @@ use App\Company; | */ +/* Wshipping-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 + + + + /* Warehouse-receive-note */ //Route::get('/so/{so_id}','warehousearrangementController@index');//view the list of wrn Route::get('/warehousearr','WarehousearrangementController@index');//view the wrn diff --git a/tests/Unit/ShippingorderTest.php b/tests/Unit/ShippingorderTest.php new file mode 100644 index 0000000..dadcac0 --- /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' => '1', + 'ff_id' => '1', + 'supplier_company_name' => 'Testing', + 'supplier_contact_person' => 'Testing', + 'supplier_contact_person_no' => '1234', + 'delivery_id' => '1', + 'warehouse_id' => '1', + + 'soitem' => [ + 0 => [ + 'so_id' => '1', + 'status' => '1', + 'order_id' => '1', + 'brand_no' => '1', + 'model_no' => '1', + 'item_code' => '1', + 'quantity_of_item' => '1', + 'uom' => 'test', + 'quantity_of_carton' => '1', + 'packaging_type' => 'Testing', + 'packaging_height' => '123', + 'packaging_width' => '123', + 'packaging_depth' => '123', + 'packaging_gross' => '123', + 'packaging_nett' => '123', + ], + 1 => [ + 'so_id' => '1', + 'status' => '1', + 'order_id' => '1', + 'brand_no' => '1', + 'model_no' => '1', + 'item_code' => '1', + 'quantity_of_item' => '1', + 'uom' => 'test', + 'quantity_of_carton' => '1', + '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); + } + +} diff --git a/tests/Unit/WarehouseReceiveNoteTest.php b/tests/Unit/WarehouseReceiveNoteTest.php index 2f98d05..ee2dd13 100644 --- a/tests/Unit/WarehouseReceiveNoteTest.php +++ b/tests/Unit/WarehouseReceiveNoteTest.php @@ -7,6 +7,9 @@ use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; +use App\Warehousearr; +use App\Warehouseitem; +use Artisan; class WarehouseReceiveNoteTest extends TestCase @@ -16,13 +19,13 @@ class WarehouseReceiveNoteTest extends TestCase * * @return void */ - public function testGET() - { - $response = $this->json('GET', '/api/warehousearr'); + // public function testGET() + // { + // $response = $this->json('GET', '/api/warehousearr'); - $response->assertStatus(200); + // $response->assertStatus(200); - } + // } public function testPOST() { @@ -51,11 +54,10 @@ class WarehouseReceiveNoteTest extends TestCase 'isDamaged'=> '1', 'status'=> 'ok', 'image'=> 'test.jpg', - 'wa_id'=> '4', - 'soitem_id'=> '4' + 'wa_id'=> '11', ], 1 => [ - 'description'=> 'CIEFhuhuuh', + 'description'=> 'CIE', 'nominal_ctn'=> '1', 'actual_ctn'=> '1', 'nominal_measurement'=> '1', @@ -66,14 +68,13 @@ class WarehouseReceiveNoteTest extends TestCase 'isDamaged'=> '1', 'status'=> 'ok', 'image'=> 'test.jpg', - 'wa_id'=> '4', - 'soitem_id'=> '4' + 'wa_id'=> '11', ] ] ]); - dd($response->getContent()); - // $response->assertStatus(201); + // dd($response->getContent()); + $response->assertStatus(201); } @@ -120,12 +121,23 @@ class WarehouseReceiveNoteTest extends TestCase // Storage::fake('warehouse_picture'); // $response = $this->actingAs($this->user) - // ->json('POST', '/warehousearr/warehouse_picture/{wa_id}', [ - // 'warehouse_picture' => UploadedFile::fake()->image('comp.jpg') + // ->json('POST', '/warehousearr/warehouse_picture/1', [ + // 'warehouse_picture' => UploadedFile::fake()->image('test.jpg') // ]); // // dd($response->getContent()); // $response->assertStatus(201); // } + // public function testUploadWarehouseItemImage() + // { + // Storage::fake('warehouse_picture'); + + // $response = $this->actingAs($this->user) + // ->json('POST', '/warehousearr/warehouse_item_picture/1', [ + // 'warehouse_item_picture' => UploadedFile::fake()->image('test.jpg') + // ]); + // // dd($response->getContent()); + // $response->assertStatus(201); + // } } \ No newline at end of file