diff --git a/app/BookingSupplier.php b/app/BookingSupplier.php index f2838cb3..aed75bc1 100644 --- a/app/BookingSupplier.php +++ b/app/BookingSupplier.php @@ -17,6 +17,12 @@ class BookingSupplier extends Model public function bookingSupplier() { - return $this->hasMany('App\Booking'); + return $this->hasOne('App\Booking'); } + + public function supplierbookingitem() + { + return $this->hasMany('App\SupplierBookingItem'); + } + } diff --git a/app/Http/Controllers/BookingSupplierController.php b/app/Http/Controllers/BookingSupplierController.php index cdb3938e..0d783f8c 100644 --- a/app/Http/Controllers/BookingSupplierController.php +++ b/app/Http/Controllers/BookingSupplierController.php @@ -7,6 +7,8 @@ use App\Booking; use App\Rate; use App\User; use App\UserBankSlip; +use App\SettingBeneficiary; +use App\SupplierBookingItem; use Illuminate\Http\Request; class BookingSupplierController extends Controller @@ -15,20 +17,19 @@ class BookingSupplierController extends Controller public function index() { $bookingsupplier = BookingSupplier::all(); - + $response = [ 'supplier-booking' => $bookingsupplier ]; return response()->json($response, 200); } - // function show($id) public function show($id) { $bookingsupplier = BookingSupplier::has('supplier-booking')->findOrFail($id); $response = [ - 'supplier-booking' => $booking + 'supplier-booking' => $bookingsupplier ]; return response()->json($response, 200); } @@ -40,7 +41,7 @@ class BookingSupplierController extends Controller // TODO: admin can access only // get current booking - $booking = Booking::where("admin_id", Auth::user()->id)->where('id', $id)->first(); + // $booking = Booking::where("admin_id", Auth::user()->id)->where('id', $id)->first(); if (!$booking) { return response()->json(['message'=>'Access denied'], 200); @@ -50,7 +51,6 @@ class BookingSupplierController extends Controller } - public function store(Request $request, $id) { //Calculation part @@ -59,11 +59,11 @@ class BookingSupplierController extends Controller $rate = $request->input("rate"); $rebate = $request->input("rebate"); - $amountInRMB = $amount * $rate; - $billing = 0.015 * $amount; - $sales_tax = 0.10 * $amount; - $gst = 0 * $amount; - $customerBankInAmount = round($amount + $gst + $sales_tax + $billing,2); + $amountInRMB = $payment_amount * $rate; + $billing = 0.015 * $payment_amount; + $sales_tax = 0.10 * $payment_amount; + $gst = 0 * $payment_amount; + $customerBankInAmount = round($payment_amount + $gst + $sales_tax + $billing,2); $rmbBankAmount = $customerBankInAmount + $rebate; $user = Auth::user(); @@ -80,45 +80,34 @@ class BookingSupplierController extends Controller $bookingsupplier->user()->associate($user); $bookingsupplier->amountInRMB = $amountInRMB; $bookingsupplier->rmbBankAmount = $rmbBankAmount; - $bookingsupplier->save(); - //one bookingsupplier has many booking - foreach ($bookingsupplier as $booking) - { - $manybooking = new Booking(array( - 'book_id' => $booking->id, - 'term' => $booking['term'], - 'amount' => $booking['amount'], - 'account_name' => $booking['account_name'], - 'account_num' => $booking['account_num'], - 'bank_name' => $booking['bank_name'], - 'bank_branch' => $booking['account_name'], - 'company_name' => $booking['company_name'], - 'company_address' => $booking['company_address'], - 'bank_address' => $booking['bank_address'], - 'swift_code' => $booking['swift_code'], - 'cnap' => $booking['cnap'], - 'verification_status' => $booking['verification_status'], - 'rmb_book_amount' => $booking['rmb_book_amount'], - 'rmb_book_pay_method' => $booking['rmb_book_pay_method'], - 'rmb_book_account_name' => $booking['rmb_book_account_name'], - 'rmb_book_bank_name' => $booking['rmb_book_bank_name'], - 'rmb_book_acc_no' => $booking['rmb_book_acc_no'], - 'rmb_book_bank_branch' => $booking['rmb_book_bank_branch'], - )); + //// one bookingsupplier has many booking + // $bookings = $request->input("booking"); + // foreach ($bookings as $booking) + // { + // $bookingsupplierbooking = new Booking(array( + // 'book_id' => $booking->id, + // 'supplierbooking_id' => $supplier->id + // )); + // $bookingsupplierbooking->save(); - $manybooking->save(); - } + // $new_supplierbooking = new SupplierBookingItem(array( + // 'book_id' => $booking->id, + // 'bank_in_amount'=>$booking['bank_in_amount'], + // 'date'=>$booking['date'], + // 'details'=>$booking['details'], + // 'supplierbooking_id' => $supplier->id + // )); + // $new_supplierbooking->save(); + // } return response()->json($bookingsupplier, 201); - - } + public function update(Request $request, $id) { - $bookingsupplier = BookingSupplier::find($id); $bookingsupplier->payment_method = $request->input('payment_method'); $bookingsupplier->payment_amount = $request->input('payment_amount'); @@ -138,6 +127,16 @@ class BookingSupplierController extends Controller $bookingsupplier->rmbBankAmount = $rmbBankAmount; $bookingsupplier->save(); + // $supplierbookingitems = $request->input("supplierbookingitem"); + // foreach ($bookings as $booking) + // { + // $update_supplierbookingitem = SupplierBookingItem::where('supplierbooking_id', $id)->first(); + // $update_supplierbookingitem->china_bankslip_url = $booking['china_bankslip_url']; + // $update_supplierbookingitem->bank_in_amount = $booking['bank_in_amount']; + // $update_supplierbookingitem->date = $booking['date']; + // $update_supplierbookingitem->details = $booking['details']; + // $update_supplierbookingitem->save(); + // } return response()->json(['book_id'=>$book_id],201); } @@ -153,10 +152,27 @@ class BookingSupplierController extends Controller { return response()->json(['message'=>'Access denied'], 200); } - - + // //get customer booking id, date,amount, rate, total, gst, rebate, bank in amount, beneficiary account number, bank slip. + // return BookingSupplier::find($id); + // //display report + // $bookingsupplier = BookingSupplier::with (['supplier_bookings' => function($query){ + // $query -> select ('book_id','date','transfer_amount','rate','rebate', 'amountInRMB', 'rmbBankAmount'); + // }])->get(); + + // //get uploaded customer booking bank slip + // $userbankslip = UserBankSlip::with (['user_bank_slips' => function($query){ + // $query -> select ('book_id','bankslip_url'); + // }])->get(); + + // //get active beneficiary account + // $beneficiary = SettingBeneficiary::with (['setting_beneficiaries' => function($query){ + // $query -> select ('bank_name','acc_no'); + // }])->get(); + + $supplier_booking = $booking->supplierBooking()->first(); + $user_bankslip = $booking->userBankSlip()->first(); } diff --git a/app/SupplierBookingItem.php b/app/SupplierBookingItem.php new file mode 100644 index 00000000..c0073d18 --- /dev/null +++ b/app/SupplierBookingItem.php @@ -0,0 +1,25 @@ +belongsTo('App\BookingSupplier'); + } + + +} diff --git a/database/factories/SupplierBookingItemFactory.php b/database/factories/SupplierBookingItemFactory.php new file mode 100644 index 00000000..514eae24 --- /dev/null +++ b/database/factories/SupplierBookingItemFactory.php @@ -0,0 +1,9 @@ +define(App\SupplierBookingItem::class, function (Faker $faker) { + return [ + // + ]; +}); diff --git a/database/migrations/2018_06_21_024658_supplierbooking_customerbooking_table.php b/database/migrations/2018_06_21_024658_supplierbooking_customerbooking_table.php new file mode 100644 index 00000000..bf18bb6a --- /dev/null +++ b/database/migrations/2018_06_21_024658_supplierbooking_customerbooking_table.php @@ -0,0 +1,34 @@ +integer('supplierbooking_id')->unsigned(); + $table->integer('booking_id')->unsigned(); + + $table->foreign('supplierbooking_id')->references('id')->on('supplier_bookings'); + $table->foreign('booking_id')->references('id')->on('bookings'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('supplierbooking_customerbooking'); + } +} diff --git a/database/migrations/2018_06_21_025734_supplier_booking_table.php b/database/migrations/2018_06_21_025734_supplier_booking_table.php new file mode 100644 index 00000000..3d32b506 --- /dev/null +++ b/database/migrations/2018_06_21_025734_supplier_booking_table.php @@ -0,0 +1,44 @@ +increments('id'); + $table->string('payment_method'); + $table->double('transfer_amount'); + $table->double('rate'); + $table->double('rebate'); + $table->double('amountInRMB'); + $table->double('rmbBankAmount'); + + $table->integer('book_id')->unsigned(); + $table->foreign('book_id')->references('id')->on('bookings'); + + $table->integer('supplier_id')->unsigned(); + $table->foreign('supplier_id')->references('id')->on('setting_suppliers'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('booking_suppliers'); + } +} diff --git a/database/migrations/2018_06_25_120731_create_supplier_booking_items_table.php b/database/migrations/2018_06_25_120731_create_supplier_booking_items_table.php new file mode 100644 index 00000000..552f39f8 --- /dev/null +++ b/database/migrations/2018_06_25_120731_create_supplier_booking_items_table.php @@ -0,0 +1,39 @@ +increments('id'); + $table->string('china_bankslip_url'); + $table->integer('book_id')->unsigned(); + $table->foreign('book_id')->references('id')->on('bookings'); + $table->double('bank_in_amount'); + $table->increments('date'); + $table->increments('details'); + $table->integer('supplierbooking_id')->unsigned(); + $table->foreign('supplierbooking_id')->references('id')->on('supplier_bookings'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('supplier_booking_items'); + } +} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index df4e674a..8879d5e3 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -7,6 +7,7 @@ $baseDir = dirname($vendorDir); return array( 'App\\Booking' => $baseDir . '/app/Booking.php', + 'App\\BookingSupplier' => $baseDir . '/app/BookingSupplier.php', 'App\\ChinaBankSlip' => $baseDir . '/app/ChinaBankSlip.php', 'App\\Console\\Kernel' => $baseDir . '/app/Console/Kernel.php', 'App\\Exceptions\\EmailTakenException' => $baseDir . '/app/Exceptions/EmailTakenException.php', @@ -17,8 +18,10 @@ return array( 'App\\Http\\Controllers\\Auth\\RegisterController' => $baseDir . '/app/Http/Controllers/Auth/RegisterController.php', 'App\\Http\\Controllers\\Auth\\ResetPasswordController' => $baseDir . '/app/Http/Controllers/Auth/ResetPasswordController.php', 'App\\Http\\Controllers\\BookingController' => $baseDir . '/app/Http/Controllers/BookingController.php', + 'App\\Http\\Controllers\\BookingSupplierController' => $baseDir . '/app/Http/Controllers/BookingSupplierController.php', 'App\\Http\\Controllers\\ChinaBankSlipController' => $baseDir . '/app/Http/Controllers/ChinaBankSlipController.php', 'App\\Http\\Controllers\\Controller' => $baseDir . '/app/Http/Controllers/Controller.php', + 'App\\Http\\Controllers\\MarkingController' => $baseDir . '/app/Http/Controllers/MarkingController.php', 'App\\Http\\Controllers\\RateController' => $baseDir . '/app/Http/Controllers/RateController.php', 'App\\Http\\Controllers\\SettingBeneficiaryController' => $baseDir . '/app/Http/Controllers/SettingBeneficiaryController.php', 'App\\Http\\Controllers\\SettingCreditController' => $baseDir . '/app/Http/Controllers/SettingCreditController.php', @@ -35,6 +38,7 @@ return array( 'App\\Http\\Middleware\\TrimStrings' => $baseDir . '/app/Http/Middleware/TrimStrings.php', 'App\\Http\\Middleware\\TrustProxies' => $baseDir . '/app/Http/Middleware/TrustProxies.php', 'App\\Http\\Middleware\\VerifyCsrfToken' => $baseDir . '/app/Http/Middleware/VerifyCsrfToken.php', + 'App\\Marking' => $baseDir . '/app/Marking.php', 'App\\Notifications\\ResetPassword' => $baseDir . '/app/Notifications/ResetPassword.php', 'App\\OAuthProvider' => $baseDir . '/app/OAuthProvider.php', 'App\\Permission' => $baseDir . '/app/Permission.php', @@ -49,6 +53,7 @@ return array( 'App\\SettingBeneficiary' => $baseDir . '/app/SettingBeneficiary.php', 'App\\SettingCredit' => $baseDir . '/app/SettingCredit.php', 'App\\SettingSupplier' => $baseDir . '/app/SettingSupplier.php', + 'App\\SupplierBookingItem' => $baseDir . '/app/SupplierBookingItem.php', 'App\\User' => $baseDir . '/app/User.php', 'App\\UserBankSlip' => $baseDir . '/app/UserBankSlip.php', 'BookTableSeeder' => $baseDir . '/database/seeds/BookTableSeeder.php', @@ -4128,12 +4133,15 @@ return array( 'Tests\\Browser\\WelcomeTest' => $baseDir . '/tests/Browser/WelcomeTest.php', 'Tests\\CreatesApplication' => $baseDir . '/tests/CreatesApplication.php', 'Tests\\DuskTestCase' => $baseDir . '/tests/DuskTestCase.php', + 'Tests\\Feature\\BookingTest' => $baseDir . '/tests/Feature/BookingTest.php', 'Tests\\Feature\\LocaleTest' => $baseDir . '/tests/Feature/LocaleTest.php', 'Tests\\Feature\\LoginTest' => $baseDir . '/tests/Feature/LoginTest.php', + 'Tests\\Feature\\MarkingTest' => $baseDir . '/tests/Feature/MarkingTest.php', + 'Tests\\Feature\\RateTest' => $baseDir . '/tests/Feature/RateTest.php', 'Tests\\Feature\\RegisterTest' => $baseDir . '/tests/Feature/RegisterTest.php', + 'Tests\\Feature\\SettingCreditTest' => $baseDir . '/tests/Feature/SettingCreditTest.php', 'Tests\\Feature\\SettingsTest' => $baseDir . '/tests/Feature/SettingsTest.php', 'Tests\\TestCase' => $baseDir . '/tests/TestCase.php', - 'Tests\\Unit\\BookingTest\\BookingTest' => $baseDir . '/tests/Feature/BookingTest.php', 'Text_Template' => $vendorDir . '/phpunit/php-text-template/src/Template.php', 'TheSeer\\Tokenizer\\Exception' => $vendorDir . '/theseer/tokenizer/src/Exception.php', 'TheSeer\\Tokenizer\\NamespaceUri' => $vendorDir . '/theseer/tokenizer/src/NamespaceUri.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index e2b83946..2ab5c4dc 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit6dcfe61ea7999ade723f072fea748b5a +class ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc { public static $files = array ( '6124b4c8570aa390c21fafd04a26c69f' => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php', @@ -435,6 +435,7 @@ class ComposerStaticInit6dcfe61ea7999ade723f072fea748b5a public static $classMap = array ( 'App\\Booking' => __DIR__ . '/../..' . '/app/Booking.php', + 'App\\BookingSupplier' => __DIR__ . '/../..' . '/app/BookingSupplier.php', 'App\\ChinaBankSlip' => __DIR__ . '/../..' . '/app/ChinaBankSlip.php', 'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.php', 'App\\Exceptions\\EmailTakenException' => __DIR__ . '/../..' . '/app/Exceptions/EmailTakenException.php', @@ -445,8 +446,10 @@ class ComposerStaticInit6dcfe61ea7999ade723f072fea748b5a 'App\\Http\\Controllers\\Auth\\RegisterController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/RegisterController.php', 'App\\Http\\Controllers\\Auth\\ResetPasswordController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/ResetPasswordController.php', 'App\\Http\\Controllers\\BookingController' => __DIR__ . '/../..' . '/app/Http/Controllers/BookingController.php', + 'App\\Http\\Controllers\\BookingSupplierController' => __DIR__ . '/../..' . '/app/Http/Controllers/BookingSupplierController.php', 'App\\Http\\Controllers\\ChinaBankSlipController' => __DIR__ . '/../..' . '/app/Http/Controllers/ChinaBankSlipController.php', 'App\\Http\\Controllers\\Controller' => __DIR__ . '/../..' . '/app/Http/Controllers/Controller.php', + 'App\\Http\\Controllers\\MarkingController' => __DIR__ . '/../..' . '/app/Http/Controllers/MarkingController.php', 'App\\Http\\Controllers\\RateController' => __DIR__ . '/../..' . '/app/Http/Controllers/RateController.php', 'App\\Http\\Controllers\\SettingBeneficiaryController' => __DIR__ . '/../..' . '/app/Http/Controllers/SettingBeneficiaryController.php', 'App\\Http\\Controllers\\SettingCreditController' => __DIR__ . '/../..' . '/app/Http/Controllers/SettingCreditController.php', @@ -463,6 +466,7 @@ class ComposerStaticInit6dcfe61ea7999ade723f072fea748b5a 'App\\Http\\Middleware\\TrimStrings' => __DIR__ . '/../..' . '/app/Http/Middleware/TrimStrings.php', 'App\\Http\\Middleware\\TrustProxies' => __DIR__ . '/../..' . '/app/Http/Middleware/TrustProxies.php', 'App\\Http\\Middleware\\VerifyCsrfToken' => __DIR__ . '/../..' . '/app/Http/Middleware/VerifyCsrfToken.php', + 'App\\Marking' => __DIR__ . '/../..' . '/app/Marking.php', 'App\\Notifications\\ResetPassword' => __DIR__ . '/../..' . '/app/Notifications/ResetPassword.php', 'App\\OAuthProvider' => __DIR__ . '/../..' . '/app/OAuthProvider.php', 'App\\Permission' => __DIR__ . '/../..' . '/app/Permission.php', @@ -477,6 +481,7 @@ class ComposerStaticInit6dcfe61ea7999ade723f072fea748b5a 'App\\SettingBeneficiary' => __DIR__ . '/../..' . '/app/SettingBeneficiary.php', 'App\\SettingCredit' => __DIR__ . '/../..' . '/app/SettingCredit.php', 'App\\SettingSupplier' => __DIR__ . '/../..' . '/app/SettingSupplier.php', + 'App\\SupplierBookingItem' => __DIR__ . '/../..' . '/app/SupplierBookingItem.php', 'App\\User' => __DIR__ . '/../..' . '/app/User.php', 'App\\UserBankSlip' => __DIR__ . '/../..' . '/app/UserBankSlip.php', 'BookTableSeeder' => __DIR__ . '/../..' . '/database/seeds/BookTableSeeder.php', @@ -4556,12 +4561,15 @@ class ComposerStaticInit6dcfe61ea7999ade723f072fea748b5a 'Tests\\Browser\\WelcomeTest' => __DIR__ . '/../..' . '/tests/Browser/WelcomeTest.php', 'Tests\\CreatesApplication' => __DIR__ . '/../..' . '/tests/CreatesApplication.php', 'Tests\\DuskTestCase' => __DIR__ . '/../..' . '/tests/DuskTestCase.php', + 'Tests\\Feature\\BookingTest' => __DIR__ . '/../..' . '/tests/Feature/BookingTest.php', 'Tests\\Feature\\LocaleTest' => __DIR__ . '/../..' . '/tests/Feature/LocaleTest.php', 'Tests\\Feature\\LoginTest' => __DIR__ . '/../..' . '/tests/Feature/LoginTest.php', + 'Tests\\Feature\\MarkingTest' => __DIR__ . '/../..' . '/tests/Feature/MarkingTest.php', + 'Tests\\Feature\\RateTest' => __DIR__ . '/../..' . '/tests/Feature/RateTest.php', 'Tests\\Feature\\RegisterTest' => __DIR__ . '/../..' . '/tests/Feature/RegisterTest.php', + 'Tests\\Feature\\SettingCreditTest' => __DIR__ . '/../..' . '/tests/Feature/SettingCreditTest.php', 'Tests\\Feature\\SettingsTest' => __DIR__ . '/../..' . '/tests/Feature/SettingsTest.php', 'Tests\\TestCase' => __DIR__ . '/../..' . '/tests/TestCase.php', - 'Tests\\Unit\\BookingTest\\BookingTest' => __DIR__ . '/../..' . '/tests/Feature/BookingTest.php', 'Text_Template' => __DIR__ . '/..' . '/phpunit/php-text-template/src/Template.php', 'TheSeer\\Tokenizer\\Exception' => __DIR__ . '/..' . '/theseer/tokenizer/src/Exception.php', 'TheSeer\\Tokenizer\\NamespaceUri' => __DIR__ . '/..' . '/theseer/tokenizer/src/NamespaceUri.php', @@ -4752,10 +4760,10 @@ class ComposerStaticInit6dcfe61ea7999ade723f072fea748b5a public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit6dcfe61ea7999ade723f072fea748b5a::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit6dcfe61ea7999ade723f072fea748b5a::$prefixDirsPsr4; - $loader->prefixesPsr0 = ComposerStaticInit6dcfe61ea7999ade723f072fea748b5a::$prefixesPsr0; - $loader->classMap = ComposerStaticInit6dcfe61ea7999ade723f072fea748b5a::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc::$prefixDirsPsr4; + $loader->prefixesPsr0 = ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc::$prefixesPsr0; + $loader->classMap = ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc::$classMap; }, null, ClassLoader::class); }