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(){
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);
}
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){
$booking = Booking::where('id',$id)->first();
@@ -657,8 +644,38 @@ class BookingController extends Controller
if($booking->save()){
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
{
protected $fillable = ['invoice_url','amount','booking_id'];
public function booking(){
return $this->hasOne('App\Booking');
}
}