can insert both so and soitem into db, but have an error

This commit is contained in:
Zain Fauzan Rofie Azizi
2018-05-21 17:01:07 +08:00
parent 137b9dc576
commit 0969c8647b
15 changed files with 229 additions and 89 deletions
View File
View File
View File
View File
View File
View File
+45 -18
View File
@@ -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');
+2 -1
View File
@@ -17,7 +17,8 @@ class So extends Model
public function Soitem()
{
return $this->hasMany(Soitem::class);
return $this->hasMany('App\Soitem', 'so_id');
}
}
+3 -2
View File
@@ -27,8 +27,9 @@ class Soitem extends Model
public function So()
{
return $this->belongsTo(So::class);
return $this->belongsTo('App\So', 'id');
}
}
@@ -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')
+2 -1
View File
@@ -11,6 +11,7 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// $this->call(UsersTableSeeder::class);
//$this->call(UsersTableSeeder::class);
$this->call(SoSeeder::class);
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Seeder;
use App\So;
use Carbon\Carbon;
class SoSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('sos')->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'),
]);
}
}
+64
View File
@@ -0,0 +1,64 @@
<?php
use Illuminate\Database\Seeder;
use App\Soitems;
use Carbon\Carbon;
class SoitemSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('soitems')->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'),
]),
]);
}
}
+2 -2
View File
@@ -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
+82 -64
View File
@@ -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);
// }
}