mirror of
https://gitlab.com/omair-personal/exchange.git
synced 2026-08-19 04:24:08 +00:00
added update transfer amount function
changed bankslip_url to file for upload user bankslip
This commit is contained in:
@@ -15,5 +15,9 @@ class Booking extends Model
|
||||
public function user(){
|
||||
return $this->belongsTo('app\User');
|
||||
}
|
||||
|
||||
public function userBankSlip(){
|
||||
return $this->hasOne('app\UserBankSlip');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -152,40 +152,36 @@ class BookingController extends Controller
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
||||
|
||||
/* Validation*/
|
||||
if (!$booking)
|
||||
{
|
||||
return response()->json(['message'=>'Access denied'], 200);
|
||||
}
|
||||
if (!$booking)
|
||||
{
|
||||
return response()->json(['message'=>'Access denied'], 200);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'bankslip_url' => 'image|mimes:jpg,jpeg,bmp,png'
|
||||
]);
|
||||
$validator = Validator::make($request->all(), [
|
||||
'file' => 'image|mimes:jpg,jpeg,bmp,png'
|
||||
]);
|
||||
|
||||
if($validator->fails())
|
||||
{
|
||||
return response()->json(['message'=>'Incorrect format'],200);
|
||||
}
|
||||
if($validator->fails())
|
||||
{
|
||||
return response()->json(['message'=>'Incorrect format'],200);
|
||||
}
|
||||
|
||||
if(!$bankslip_file = $request->file('bankslip_url'))
|
||||
{
|
||||
return response()->json(['message' => 'No file detected'], 400);
|
||||
}
|
||||
if(!$bankslip_file = $request->file('file'))
|
||||
{
|
||||
return response()->json(['message' => 'No file detected'], 400);
|
||||
}
|
||||
/* End Validation */
|
||||
|
||||
$filename = $bankslip_file->getClientOriginalName();
|
||||
$ext = $bankslip_file->getClientOriginalExtension();
|
||||
$input['bankslip_url'] = $filename;
|
||||
$input['file'] = $filename;
|
||||
|
||||
$unique_name = 'bank_slip_' . md5($filename. time());
|
||||
$unique_name = 'bank_slip_' . md5($filename. time()); // probably not a good idea
|
||||
$unique_image_url = $unique_name. '.' .$ext;
|
||||
Storage::putFileAs(
|
||||
'bankslip_url',/*folder name*/ $bankslip_file, $unique_image_url
|
||||
'user_bankslip', $bankslip_file, $unique_image_url
|
||||
);
|
||||
|
||||
// why ?
|
||||
$booking->cust_marking = $request->input('cust_marking');
|
||||
$booking->bank_slip_type = $request->input('bank_slip_type');
|
||||
|
||||
$user_bankslip = new UserBankSlip;
|
||||
$user_bankslip->book_id = $booking->id;
|
||||
$user_bankslip->bankslip_url = $unique_image_url;
|
||||
@@ -195,6 +191,14 @@ class BookingController extends Controller
|
||||
return response()->json(['message'=>"Success"],200);
|
||||
}
|
||||
|
||||
public function updateBankSlipAmount($id){
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
||||
$user_bankslip = $booking->userBankSlip()->first();
|
||||
$user_bankslip->transfer_amount = $request->input('transfer_amount');
|
||||
$user_bankslip->save();
|
||||
return response()->json(['message'=>"Success"],200);
|
||||
}
|
||||
|
||||
public function uploadPurchaseOrder(Request $request, $id)
|
||||
{
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
||||
|
||||
@@ -7,4 +7,9 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class UserBankSlip extends Model
|
||||
{
|
||||
protected $fillable = ['bank_slip_type','bankslip_url','transfer_amount','book_id','cust_marking'];
|
||||
|
||||
public function booking()
|
||||
{
|
||||
return $this->belongsTo(Booking::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
|
||||
<!-- upload image -->
|
||||
<el-upload action="https://jsonplaceholder.typicode.com/posts/" :on-preview="handlePictureCardPreview" :on-remove="handleRemove"
|
||||
<el-upload v-bind:action="'/api/booking/' + booking_id + '/upload-user-bankslip'" :on-preview="handlePictureCardPreview" :on-remove="handleRemove"
|
||||
list-type="picture-card" align="center">
|
||||
<i class="el-icon-plus" />
|
||||
</el-upload>
|
||||
@@ -56,19 +56,29 @@
|
||||
<el-form-item label="Amount (RM) :"> -->
|
||||
<div align="center">
|
||||
Bankin Amount (RM) :
|
||||
<el-input placeholder="Enter Amount" style="width: 20%" />
|
||||
<el-form :model="user_slip_form" :rules="rules" ref="user_slip_form">
|
||||
<div align="center">
|
||||
<el-form-item prop="transfer_amount">
|
||||
<el-input v-model="user_slip_form.transfer_amount" type="text" placeholder="Transfer Amount" style="width: 20%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<div align="center">
|
||||
<el-button type="submit" @click="submitUserSlip('user_slip_form')">Submit</el-button>
|
||||
<router-link :to="{ name: 'home' }" class="small ml-auto my-auto">
|
||||
Upload Later
|
||||
</router-link>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form>
|
||||
<br>
|
||||
<br>
|
||||
</div>
|
||||
<!-- </el-form-item>
|
||||
</el-form> -->
|
||||
|
||||
<div align="center">
|
||||
<el-button type="submit" @click="submitUserSlip">Submit</el-button>
|
||||
<router-link :to="{ name: 'home' }" class="small ml-auto my-auto">
|
||||
Upload Later
|
||||
</router-link>
|
||||
</div>
|
||||
|
||||
|
||||
</el-main>
|
||||
</template>
|
||||
@@ -95,11 +105,21 @@
|
||||
start: false,
|
||||
dialogImageUrl: '',
|
||||
dialogVisible: false,
|
||||
booking_id: this.$route.params.id,
|
||||
user_slip_form:{
|
||||
transfer_amount : ''
|
||||
},
|
||||
booking: {
|
||||
amount: '',
|
||||
bankin_amount: '',
|
||||
timeout: 1
|
||||
},
|
||||
rules: {
|
||||
transfer_amount: [{
|
||||
required: true,
|
||||
message: 'Please input amount',
|
||||
trigger: 'change'
|
||||
}, ],}
|
||||
}
|
||||
},
|
||||
beforeCreate() {
|
||||
@@ -128,32 +148,6 @@
|
||||
})
|
||||
|
||||
},
|
||||
mounted() {
|
||||
// const loading = this.$loading({
|
||||
// lock: true,
|
||||
// text: 'Please wait..',
|
||||
// spinner: 'el-icon-loading',
|
||||
// background: 'rgba(0, 0, 0, 0.7)'
|
||||
// })
|
||||
|
||||
// axios
|
||||
// .get('/api/booking/'+ this.$route.params.id)
|
||||
// .then((response) => {
|
||||
// console.log(response)
|
||||
// this.booking.amount = response.data.amount
|
||||
// this.booking.bankin_amount = response.data.bia
|
||||
// this.booking.timeout = response.data.timeout
|
||||
// this.start = true;
|
||||
// loading.close()
|
||||
// }).catch((error) => {
|
||||
// console.log(error)
|
||||
// loading.close()
|
||||
// this.$router.push({
|
||||
// name: 'notfound'
|
||||
// })
|
||||
// })
|
||||
//this.$refs.countdown.start()
|
||||
},
|
||||
methods: {
|
||||
handleRemove(file, fileList) {
|
||||
console.log(file, fileList)
|
||||
@@ -162,16 +156,39 @@
|
||||
this.dialogImageUrl = file.url
|
||||
this.dialogVisible = true
|
||||
},
|
||||
submitUserSlip() {
|
||||
this.$message({
|
||||
showClose: true,
|
||||
message: 'Your bankinslip has been submitted, please wait admin to approve.',
|
||||
type: 'success',
|
||||
duration: 5000,
|
||||
});
|
||||
this.$router.push({
|
||||
name: 'home'
|
||||
})
|
||||
submitUserSlip(formName) {
|
||||
this.$refs[formName].validate((valid) => {
|
||||
if (valid) {
|
||||
let newConfirmation = {
|
||||
amount: this.booking.amount,
|
||||
term: this.term
|
||||
}
|
||||
}
|
||||
else{
|
||||
return
|
||||
}
|
||||
});
|
||||
let newUserSlip = {
|
||||
transfer_amount : this.user_slip_form.transfer_amount
|
||||
}
|
||||
axios.post('/booking/'+ this.booking_id +'/bankslip-amount', newUserSlip)
|
||||
.then((response) => {
|
||||
this.$message({
|
||||
showClose: true,
|
||||
message: 'Your bankinslip has been submitted, please wait admin to approve.',
|
||||
type: 'success',
|
||||
duration: 5000,
|
||||
});
|
||||
// console.log(response)
|
||||
// this.$router.push({
|
||||
// name: 'home'
|
||||
// })
|
||||
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error)
|
||||
return
|
||||
})
|
||||
},
|
||||
handleTimeExpire() {
|
||||
alert('Booking expired')
|
||||
|
||||
+5
-5
@@ -32,11 +32,14 @@ Route::group(['middleware' => 'auth:api'], function () {
|
||||
/*Route for the booking */
|
||||
Route::get('/booking', 'BookingController@index');
|
||||
Route::get('/booking/{book_id}', 'BookingController@show');
|
||||
Route::post('/booking', 'BookingController@store');
|
||||
Route::put('/booking/{book_id}', 'BookingController@update');
|
||||
Route::delete('/booking/{book_id}', 'BookingController@delete');
|
||||
Route::post('/booking', 'BookingController@store');
|
||||
Route::post('/booking/calculation', 'BookingController@calculation');
|
||||
|
||||
Route::post('booking/{book_id}/cancel', 'BookingController@cancel');
|
||||
Route::post('booking/{id}/upload-user-bankslip', 'BookingController@uploadbankslip');
|
||||
Route::post('booking/{id}/upload-po', 'BookingController@uploadPurchaseOrder');
|
||||
Route::put('booking/{id}/bankslip-amount', 'BookingController@updateBankSlipAmount');
|
||||
Route::get('/user', function (Request $request) {
|
||||
return $request->user();
|
||||
});
|
||||
@@ -83,6 +86,3 @@ Route::delete('setting-supplier/{supplier}', 'SettingSupplierController@delete')
|
||||
|
||||
Route::post('upload-china-bankslip', 'ChinaBankSlipController@store');
|
||||
|
||||
Route::post('booking/{book_id}/cancel', 'BookingController@cancel');
|
||||
Route::post('booking/{id}/upload-user-bankslip', 'BookingController@uploadbankslip');
|
||||
Route::post('booking/{id}/upload-po', 'BookingController@uploadPurchaseOrder');
|
||||
|
||||
@@ -65,7 +65,7 @@ class BookingTest extends TestCase
|
||||
|
||||
public function testuploadbankslip()
|
||||
{
|
||||
Storage::fake('bankslip_url');
|
||||
Storage::fake('file');
|
||||
$bankslip_url = UploadedFile::fake()->image('comp.jpg');
|
||||
|
||||
if(!file_exists($bankslip_url)){
|
||||
|
||||
Reference in New Issue
Block a user