Merge branch 'master' of gitlab.com:CIEFWorldwideSdnBhd/exchange into fix/bug

# Conflicts:
#	app/Http/Controllers/BookingController.php
#	resources/assets/js/pages/home.vue
This commit is contained in:
Jack Goh
2018-07-26 15:50:49 +08:00
12 changed files with 479 additions and 86 deletions
+93 -33
View File
@@ -13,6 +13,7 @@ use App\Invoice;
use App\SettingCredit;
use App\SettingTaxRate;
use App\SettingBillingCharge;
use App\Notification;
use Auth;
use Validator;
use DateTime;
@@ -80,7 +81,7 @@ class BookingController extends Controller
$user = Auth::user();
$bookings = Booking::select('user_id', 'id', 'created_at', 'admin_status', 'rate', 'term', 'amount', 'bia', 'verification_status')
->orderby('updated_at','desc')
->get();
->paginate(10);
// reformat to fit frontend structure
foreach ($bookings as $booking) {
@@ -248,7 +249,9 @@ class BookingController extends Controller
$term = $request->input('term');
$amount = $request->input("amount"); // in RMB
$rates = Rate::orderby('updated_at','desc')->first();
$creditLimit = SettingCredit::orderby('updated_at','desc')->first();
$creditLimit = SettingCredit::orderby('updated_at','desc')->first();
$taxrate = SettingTaxRate::latest()->first()->tax_rate;
$billingChargeRate = SettingBillingCharge::latest()->first()->billing_charge_rate;
if (!$creditLimit){
return response()->json("Credit limit not set, please contact admin", 405);
@@ -290,27 +293,31 @@ class BookingController extends Controller
}
// Service charge (RMB) : if amount higher than 10,000, no service charge. if amount lower than 10,000, 20.00 service charge
if ($amount >= 10000 && ($term == 'x2_cash' || $term == 'x2_cheque' || $term == 'x2_ba')) {
if ($amount >= 10000 && ($term == 'x2_cash' || $term == 'x2_cheque' || $term == 'x2_ba')) {
$svcharge = 0;
} else {
$svcharge = 20.00;
}
// initial rmb to myr amount
$RMBinMYR = (($amount + $svcharge) / $rate);
// TODO : Should be remove this ?
// gst 0%
$gst = 0 * $RMBinMYR;
// Sales tax : 10 %
$sales_tax = 0.10 * $RMBinMYR;
// Billing fees : 1.5%
$billing = 0.015 * $RMBinMYR;
// Bank in amount
$bia = round($RMBinMYR + $gst + $sales_tax + $billing, 2);
$subtotal = round(($amount + $svcharge) / $rate,2);
// TODO : refactor
if ($taxrate !=0){
$taxAmount = round($subtotal * $taxrate - $subtotal,2);
}
else{
$taxAmount = 0;
}
if ($billingChargeRate !=0){
$billingChargeAmount = round(($amount + $svcharge) * $billingChargeRate - ($amount + $svcharge), 2);
}
else{
$billingChargeAmount = 0;
}
$billingChargeAmount = round((($amount / $rate) * $billingChargeRate) - ($amount / $rate), 2);
$bankin_amount = round($subtotal + $taxAmount + $billingChargeAmount , 2);
$booking = new Booking();
$booking->account_name = $request->input('account_name');
@@ -323,9 +330,9 @@ class BookingController extends Controller
$booking->term = $term;
$booking->rate_id = $rates->id;
$booking->rate = $rate;
$booking->rmb_book_amount = $request->input('amount');
$booking->rmb_book_amount = $request->input('amount'); // BIG TODO : amount change variable name to rmb_book_amount
$booking->status = 2;
$booking->bia = $bia;
$booking->bia = $bankin_amount; // BID TODO : change bia viariable name
// $booking->user_id = $user->id;
$booking->user()->associate($user);
@@ -456,9 +463,16 @@ class BookingController extends Controller
$booking->admin_status = 2;
$booking->save();
// Add notification message to admin
$adminNotification = new Notification;
$adminNotification->detail = "A bankslip is uploaded for booking " . $booking->id;
$adminNotification->link = "/booking/" . $booking->id . "/verification";
$adminNotification->user_id = User::withRole('admin')->first()->id;
$adminNotification->save();
$user_bankslip->transfer_amount = $request->input('transfer_amount');
$user_bankslip->save();
return response()->json(["message"=> "Success"],200);
return response()->json($adminNotification,200);
}
public function uploadPurchaseOrder(Request $request, $id)
@@ -570,7 +584,6 @@ class BookingController extends Controller
if($amount > $creditLimit->rmb_credit_limit){
return response()->json(["message" => "Exceed credit limit, please contact our sales team for larger quantitiy"], 400);
}
switch ($term) {
case "x1_cash":
@@ -604,16 +617,31 @@ class BookingController extends Controller
], 422);
break;
}
if (($amount >= 10000) && ($term == 'x2_cash' || $term == 'x2_cheque' || $term == 'x2_ba')) {
if ($amount >= 10000 && ($term == 'x2_cash' || $term == 'x2_cheque' || $term == 'x2_ba')) {
$svcharge = 0;
} else {
$svcharge = 20.00;
}
$subtotal = round($amount + $svcharge / $rate,2);
$taxAmount = round($subtotal * $taxrate,2);
$billingChargeAmount = round(($amount + $svcharge) * $billingChargeRate, 2);
$subtotal = round(($amount + $svcharge) / $rate,2);
// TODO : refactor
if ($taxrate !=0){
$taxAmount = round($subtotal * $taxrate - $subtotal,2);
}
else{
$taxAmount = 0;
}
if ($billingChargeRate !=0){
$billingChargeAmount = round(($amount + $svcharge) * $billingChargeRate - ($amount + $svcharge), 2);
}
else{
$billingChargeAmount = 0;
}
$billingChargeAmount = round((($amount / $rate) * $billingChargeRate) - ($amount / $rate), 2);
$bankin_amount = round($subtotal + $taxAmount + $billingChargeAmount , 2);
return response()->json([
@@ -630,6 +658,8 @@ class BookingController extends Controller
'taxAmount' => $taxAmount,
'billingChargeAmount' => $billingChargeAmount,
'bankin_amount' => $bankin_amount,
'acc_name' => $request->input('acc_name'),
'acc_no' => $request->input('acc_no')
], 200);
}
@@ -660,11 +690,26 @@ class BookingController extends Controller
// update booking status
$booking->status = 4;
if($booking->term !== "x1_ba" || $booking->term !== "x2_cheque")
if($booking->term !== "x1_ba" || $booking->term !== "x2_cheque"){
$booking->admin_status = 3;
else
// Add notification message to user
$userNotification = new Notification;
$userNotification->detail = "Your bankslip for booking " . $booking->id . " is approved.";
$userNotification->link = "/booking/" . $booking->id . "/transfer";
$userNotification->user_id = $booking->user_id;
$userNotification->save();
}
else{
$booking->admin_status = 5;
// Add notification message to user
$userNotification = new Notification;
$userNotification->detail = "Your bankslip for booking " . $booking->id . " is approved.";
$userNotification->link = "/booking/" . $booking->id . "/supplier";
$userNotification->user_id = $booking->user_id;
$userNotification->save();
}
$booking->save();
return response()->json(['message'=>'Success'],200);
}
@@ -760,6 +805,11 @@ class BookingController extends Controller
$booking->admin_status = 5; // upload china bankslip
if($booking->save()){
$userNotification = new Notification;
$userNotification->detail = "Supplier booking report for booking " . $booking->id . " is completed.";
$userNotification->link = "/booking/" . $booking->id . "/transfer";
$userNotification->user_id = $booking->user_id;
$userNotification->save();
return response()->json(['message'=>"Success"],200);
}
}
@@ -768,16 +818,21 @@ class BookingController extends Controller
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
$purchase_order = $booking->purchaseOrder()->first();
return($purchase_order);
if(!$purchase_order){
return response()->json(["message"=> "Please upload your purchase order"],400);
}
$booking->status = 6; // wait invoice
$booking->admin_status = 6; // upload invoice
$booking->save();
return response()->json(['message'=>'Success'],200);
$adminNotification = new Notification;
$adminNotification->detail = "Purchase Order for booking " . $booking->id . " is uploaded.";
$adminNotification->link = "/booking/" . $booking->id . "/upload-invoice";
$adminNotification->user_id = User::withRole('admin')->first()->id;
$adminNotification->save();
return response()->json($purchase_order,200);
}
public function confirmInvoice(Request $request, $id)
@@ -794,6 +849,11 @@ class BookingController extends Controller
$booking->admin_status = 7; // completed
if($booking->save()){
$adminNotification = new Notification;
$adminNotification->detail = "Invoice for booking " . $booking->id . " is uploaded.";
$adminNotification->link = "/booking/" . $booking->id . "/complete";
$adminNotification->user_id = $booking->user_id;
$adminNotification->save();
return response()->json(['message'=>"Success"],200);
}
}
@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
use App\ChinaBankSlip;
use App\Booking;
use App\User;
use App\Notification;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Validator;
@@ -80,6 +82,13 @@ class ChinaBankSlipController extends Controller
$booking->admin_status = 6;
$booking->save();
$userNotification = new Notification;
$userNotification->detail = "Your china bankslip for booking " . $booking->id . " is uploaded.";
$userNotification->link = "/booking/" . $booking->id . "/upload-po";
$userNotification->user_id = $booking->user_id;
$userNotification->save();
return response()->json(["message"=> "Success"],200);
}
@@ -0,0 +1,65 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Notification;
use Illuminate\Support\Facades\DB;
use Auth;
class NotificationController extends Controller
{
public function index()
{
return Notification::all()->orderby('updated_at','desc');
}
public function show(Notification $notification)
{
return $notification;
}
public function store(Request $request)
{
$notification = Notification::create($request->all());
return response()->json($notification, 201);
}
public function update(Request $request, Notification $notification)
{
$notification->update($request->all());
return response()->json($notification, 200);
}
public function delete(Notification $notification)
{
$notification->delete();
return response()->json(null, 204);
}
public function getUserMessage()
{
$user_all_notification = Notification::Where("user_id",Auth::user()->id)->orderby('updated_at','desc')->get();
return response()->json([
"message" =>$user_all_notification,
"unread_message" =>Notification::Where([
["user_id",Auth::user()->id],
["is_read",0]
])->orderby('updated_at','desc')->get()
],200);
}
public function readNotification($notification_id){
$affected = DB::table('notifications')
->Where('id', $notification_id)
->update(array('is_read' => 1));
return response()->json("Read message", 200);
}
}
+77
View File
@@ -0,0 +1,77 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Notification extends Model
{
protected $fillable = ['detail','user_id','is_read'];
protected $appends = ['time_interval'];
public function getTimeIntervalAttribute()
{
$created_time = $this->created_at;
date_default_timezone_set('Asia/Kuala_Lumpur'); //Change as per your default time
$str = strtotime($created_time);
$today = strtotime(date('Y-m-d H:i:s'));
// It returns the time difference in Seconds...
$time_differnce = $today-$str;
// To Calculate the time difference in Years...
$years = 60*60*24*365;
// To Calculate the time difference in Months...
$months = 60*60*24*30;
// To Calculate the time difference in Days...
$days = 60*60*24;
// To Calculate the time difference in Hours...
$hours = 60*60;
// To Calculate the time difference in Minutes...
$minutes = 60;
if(intval($time_differnce/$years) > 1)
{
return intval($time_differnce/$years)." years ago";
}else if(intval($time_differnce/$years) > 0)
{
return intval($time_differnce/$years)." year ago";
}else if(intval($time_differnce/$months) > 1)
{
return intval($time_differnce/$months)." months ago";
}else if(intval(($time_differnce/$months)) > 0)
{
return intval(($time_differnce/$months))." month ago";
}else if(intval(($time_differnce/$days)) > 1)
{
return intval(($time_differnce/$days))." days ago";
}else if (intval(($time_differnce/$days)) > 0)
{
return intval(($time_differnce/$days))." day ago";
}else if (intval(($time_differnce/$hours)) > 1)
{
return intval(($time_differnce/$hours))." hours ago";
}else if (intval(($time_differnce/$hours)) > 0)
{
return intval(($time_differnce/$hours))." hour ago";
}else if (intval(($time_differnce/$minutes)) > 1)
{
return intval(($time_differnce/$minutes))." minutes ago";
}else if (intval(($time_differnce/$minutes)) > 0)
{
return intval(($time_differnce/$minutes))." minute ago";
}else if (intval(($time_differnce)) > 1)
{
return intval(($time_differnce))." seconds ago";
}else
{
return "few seconds ago";
}
}
}