added relationship for invoice and booking

added confirm invoice feature (after user upload the image)
This commit is contained in:
Jack Goh
2018-06-28 15:22:25 +08:00
parent 105b61eab3
commit 4e448afc60
5 changed files with 73 additions and 82 deletions
+6
View File
@@ -47,5 +47,11 @@ class Booking extends Model
public function purchaseOrder(){ public function purchaseOrder(){
return $this->hasOne(PurchaseOrder::class); return $this->hasOne(PurchaseOrder::class);
} }
public function invoice(){
return $this->hasOne(Invoice::class);
}
} }
+31 -14
View File
@@ -423,19 +423,6 @@ class BookingController extends Controller
return response()->json(['message'=>'Success'],200); return response()->json(['message'=>'Success'],200);
} }
public function confirmPurchaseOrder($id){
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
$purchase_order = $booking->purchaseOrder()->first();
if(!$purchase_order){
return response()->json(["message"=> "Please upload your purchase order"],400);
}
$booking->status = 6;
$booking->save();
return response()->json(['message'=>'Success'],200);
}
public function showPurchaseOrder($id){ public function showPurchaseOrder($id){
$booking = Booking::where('id',$id)->first(); $booking = Booking::where('id',$id)->first();
@@ -657,8 +644,38 @@ class BookingController extends Controller
if($booking->save()){ if($booking->save()){
return response()->json(['message'=>"Success"],200); return response()->json(['message'=>"Success"],200);
} }
}
public function confirmPurchaseOrder($id){
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
$purchase_order = $booking->purchaseOrder()->first();
if(!$purchase_order){
return response()->json(["message"=> "Please upload your purchase order"],400);
}
$booking->status = 6;
$booking->save();
return response()->json(['message'=>'Success'],200);
}
public function confirmInvoice(Request $request, $id)
{
$booking = Booking::where('id', $id)->firstOrFail();
$invoice = $booking->invoice()->first;
if(!$invoice){
return response()->json(["message"=> "Please upload your invoice"],400);
}
$booking->status = 7; // processing transfer
$booking->admin_status = 6; // upload china bankslip
if($booking->save()){
return response()->json(['message'=>"Success"],200);
}
} }
} }
+4
View File
@@ -7,4 +7,8 @@ use Illuminate\Database\Eloquent\Model;
class Invoice extends Model class Invoice extends Model
{ {
protected $fillable = ['invoice_url','amount','booking_id']; protected $fillable = ['invoice_url','amount','booking_id'];
public function booking(){
return $this->hasOne('App\Booking');
}
} }
@@ -5,7 +5,7 @@
<div align="center"> <div align="center">
<h4 style="margin-top:5%;"></h4> <h4 style="margin-top:5%;"></h4>
<br> <br>
<div v-if="user_po_path"> <div v-if="user_po_path !== null">
<h4>Upload Invoice</h4> <h4>Upload Invoice</h4>
</div> </div>
<div v-else> <div v-else>
@@ -173,42 +173,24 @@
<!----> <!---->
<!----> <!---->
</div> </div>
<!---->
<!---->
<!---->
<!---->
<div class="el-table__column-resize-proxy" style="display: none;"></div> <div class="el-table__column-resize-proxy" style="display: none;"></div>
</div> </div>
</div> </div>
</div> </div>
<!-- <el-row :gutter="12">
<el-col :span="12">
<el-table :data="bookingConfirmTable" :show-header="false" align="center">
<el-table-column prop="data1" align="right" width="200" />
<el-table-column prop="data2" align="left" width="200" />
</el-table>
</el-col>
<el-col :span="12">
<el-table :data="bookingConfirmTable2" :show-header="false" align="center">
<el-table-column prop="data1" align="right" width="200" />
<el-table-column prop="data2" align="left" width="200" />
</el-table>
</el-col>
</el-row> -->
</el-card> </el-card>
</el-row> </el-row>
<br> <br>
<el-row :gutter="12" justify="center" align="center"> <el-row v-if="user_po_path !== null" :gutter="12" justify="center" align="center">
<el-col :span="12"> <el-col :span="12">
<el-card class="box-card"> <el-card class="box-card">
<div slot="header" class="clearfix"> <div slot="header" class="clearfix">
<span>Upload Invoice</span> <span>Upload Invoice</span>
<!-- <el-button style="float: right; padding: 3px 0" type="text">Operation button</el-button> --> <!-- <el-button style="float: right; padding: 3px 0" type="text">Operation button</el-button> -->
</div> </div>
<!-- upload image --> <!-- upload image -->
<el-upload :action="'/api/booking/' + booking_id + '/upload-po'" :on-exceed="handleExceed" :on-preview="handlePreview" <el-upload :action="'/api/booking/' + booking_id + '/upload-invoice'" :on-exceed="handleExceed" :on-preview="handlePreview"
:on-remove="handleRemove" :on-remove="handleRemove"
class="upload-demo" class="upload-demo"
drag drag
@@ -223,7 +205,7 @@
<br> <br>
<div class="bottom clearfix" style="text-align:right;"> <div class="bottom clearfix" style="text-align:right;">
<el-button :loading="loading" type="primary" @click="uploadPo">Submit</el-button> <el-button :loading="loading_btn" type="primary" @click="confirmInvoice">Submit</el-button>
</div> </div>
<!-- upload image end --> <!-- upload image end -->
@@ -357,50 +339,32 @@
}, },
methods: { methods: {
uploadPo(formName) { confirmInvoice () {
this.loading_btn = true this.loading_btn = true
axios
this.$refs[formName].validate((valid) => { .post('/api/booking/' + this.$route.params.id + '/confirm-invoice')
if (valid) { .then((response) => {
let newChinaSlip = { console.log(response)
date: this.chinaSlipForm.date, this.$message({
actual_transfer_amount: this.chinaSlipForm.actual_transfer_amount, showClose: true,
details: this.chinaSlipForm.details, message: 'Your invoice has been uploaded. Order completed !',
} type: 'success',
duration: 5000
axios.patch('/api/booking/' + this.booking_id + '/update-china-bankslip', newChinaSlip) })
.then((response) => { this.$router.push({
this.$message({ name: 'home'
showClose: true, })
message: 'Your bankinslip has been submitted, please wait admin to approve.', this.loading_btn = false
type: 'success', }).catch((error) => {
duration: 5000 this.$message({
}) showClose: true,
message: 'Please upload invoice',
console.log(response) type: 'error',
this.$router.push({ duration: 30000
name: 'home' })
}) this.loading_btn = false
})
.catch((error) => {
this.loading = false
this.$message({
showClose: true,
message: 'Please upload your bankin slip first.',
type: 'warning',
duration: 10000
})
console.log(error)
this.loading_btn = false
})
} else {
this.loading_btn = false
}
}) })
},
},
handleRemove(file, fileList) { handleRemove(file, fileList) {
console.log(file, fileList); console.log(file, fileList);
}, },
+2 -2
View File
@@ -63,7 +63,6 @@ Route::group(['middleware' => 'guest:api'], function () {
Route::group(['middleware' => ['role:admin']], function() { Route::group(['middleware' => ['role:admin']], function() {
Route::get('admin/booking/', 'BookingController@adminIndex'); Route::get('admin/booking/', 'BookingController@adminIndex');
Route::get('admin/booking/{id}', 'BookingController@adminShow'); Route::get('admin/booking/{id}', 'BookingController@adminShow');
Route::post('booking/{id}/upload-invoice', 'BookingController@uploadInvoice');
Route::post('update-rate', 'RateController@store'); Route::post('update-rate', 'RateController@store');
Route::put('update-rate/{rate}', 'RateController@update'); Route::put('update-rate/{rate}', 'RateController@update');
@@ -104,8 +103,9 @@ Route::group(['middleware' => ['role:admin']], function() {
Route::post('/booking/{id}/upload-china-bankslip','ChinaBankSlipController@store'); Route::post('/booking/{id}/upload-china-bankslip','ChinaBankSlipController@store');
Route::patch('/booking/{id}/update-china-bankslip','ChinaBankSlipController@update'); Route::patch('/booking/{id}/update-china-bankslip','ChinaBankSlipController@update');
Route::get('/booking/{id}/po', 'BookingController@showPurchaseOrder'); Route::get('/booking/{id}/po', 'BookingController@showPurchaseOrder');
Route::post('booking/{id}/upload-invoice', 'BookingController@uploadInvoice');
Route::post('booking/{id}/confirm-invoice', 'BookingController@confirmInvoice');
}); });