diff --git a/.env.prod b/.env.prod new file mode 100644 index 00000000..4b60c95c --- /dev/null +++ b/.env.prod @@ -0,0 +1,80 @@ +APP_NAME=IZYIM +APP_ENV=production +APP_KEY=base64:Fu2YulXExzm9HJ5LgVmZUmcbRkchHkc82q02MorN5GQ= +APP_DEBUG=true +APP_URL=http://localhost + +LOG_CHANNEL=stack + +DB_CONNECTION=mysql +DB_HOST=mysql +DB_PORT=3306 +DB_DATABASE=default +DB_USERNAME=default +DB_PASSWORD=secret + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +SESSION_DRIVER=file +SESSION_LIFETIME=120 +QUEUE_DRIVER=sync + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_DRIVER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER=mt1 + +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" +APP_NAME=exchange +APP_ENV=local +APP_KEY=base64:Fu2YulXExzm9HJ5LgVmZUmcbRkchHkc82q02MorN5GQ= +APP_DEBUG=true +APP_URL=http://localhost + +LOG_CHANNEL=stack + +DB_CONNECTION=mysql +DB_HOST=mysql +DB_PORT=3306 +DB_DATABASE=default +DB_USERNAME=default +DB_PASSWORD=secret + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +SESSION_DRIVER=file +SESSION_LIFETIME=120 +QUEUE_DRIVER=sync + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_DRIVER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER=mt1 + +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" + +JWT_SECRET=FwYZ3SPFgjpEDqAwcaSIV6eEmQiMtGWt \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index edff056f..c1fb53e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,5 +13,7 @@ RUN php artisan clear-compiled COPY wait.sh /usr/local/bin/wait.sh RUN chmod +x /usr/local/bin/wait.sh -CMD /usr/local/bin/wait.sh && composer update --no-scripts && composer dumpautoload && php artisan storage:link && php artisan migrate && php artisan serve --host=0.0.0.0 --port=8000 +RUN php artisan storage:link + +CMD /usr/local/bin/wait.sh && composer update --no-scripts && composer dumpautoload && php artisan migrate && php artisan serve --host=0.0.0.0 --port=8000 EXPOSE 8000 diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php index 6efd7281..844754e1 100644 --- a/app/Http/Controllers/BookingController.php +++ b/app/Http/Controllers/BookingController.php @@ -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; @@ -70,6 +71,7 @@ class BookingController extends Controller default: $status_desc = ""; } + $booking->status_desc = $status_desc; $booking->marking = $booking->user->marking; } @@ -248,7 +250,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 +294,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'); @@ -318,12 +326,14 @@ class BookingController extends Controller $booking->bank_name = $request->input('bank_name'); $booking->bank_branch = $request->input('bank_branch'); $booking->amount = $request->input('amount'); + $booking->order_no = $request->input('order_no'); + $booking->payment_for = $request->input('payment_for'); $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); @@ -350,8 +360,9 @@ class BookingController extends Controller // $booking->usd_book_cnap = $request->input('usd_book_cnap'); // $booking->usd_book_bank_branch = $request->input('usd_book_bank_branch'); // $booking->verification_status = $request->input('verification_status'); + // return response()->json($booking, 201); $booking->save(); - //return response()->json('error', 400); + // return response()->json('error', 400); return response()->json($booking, 201); } @@ -415,19 +426,26 @@ class BookingController extends Controller 'user_bankslip', $bankslip_file, $unique_image_path ); - $user_bankslip = $booking->userBankSlip()->first(); + if($upload_path){ + $user_bankslip = $booking->userBankSlip()->first(); - // if user bankslip not exist, create new one - if(!$user_bankslip){ - $user_bankslip = new UserBankSlip; + // if user bankslip not exist, create new one + if(!$user_bankslip){ + $user_bankslip = new UserBankSlip; + } + $user_bankslip->booking_id = $booking->id; + $user_bankslip->bankslip_path = $upload_path; + $user_bankslip->transfer_amount = $request->input('transfer_amount'); + $user_bankslip->save(); + + + return response()->json(['message'=>"Success"],200); + } + else{ + return response()->json(['message' => 'File not uploaded. Please contact support'], 400); } - $user_bankslip->booking_id = $booking->id; - $user_bankslip->bankslip_path = $upload_path; - $user_bankslip->transfer_amount = $request->input('transfer_amount'); - $user_bankslip->save(); - return response()->json(['message'=>"Success"],200); } else { return response()->json(['message' => 'No file detected'], 400); @@ -447,9 +465,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) @@ -545,6 +570,8 @@ class BookingController extends Controller $amount = $request->input('amount'); $term = $request->input('term'); $china_beneficiary = $request->input('china_beneficiary'); + $order_no = $request->input('order_no'); + $payment_for = $request->input('payment_for'); $rates = Rate::orderby('updated_at','desc')->first(); $marking = $user = Auth::user()->marking; $taxrate = SettingTaxRate::latest()->first()->tax_rate; @@ -559,16 +586,15 @@ 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": $rate = $rates->x1_cash; - $payment_method = "cash"; + $payment_method = "CASH"; break; case "x1_cheque": $rate = $rates->x1_cheque; - $payment_method = "Cheque"; + $payment_method = "CHEQUE"; break; case "x1_ba": $rate = $rates->x1_ba; @@ -576,11 +602,11 @@ class BookingController extends Controller break; case "x2_cash": $rate = $rates->x2_cash; - $payment_method = "Cash"; + $payment_method = "CASH"; break; case "x2_cheque": $rate = $rates->x2_cheque; - $payment_method = "Cheque"; + $payment_method = "CHEQUE"; break; case "x2_ba": $rate = $rates->x2_ba; @@ -594,19 +620,36 @@ class BookingController extends Controller 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([ 'date' => date('Y-m-d'), + 'order_no' => $order_no, + 'payment_for' => $payment_for, 'marking' => $marking, 'payment_method' => $payment_method, 'china_beneficary' => $china_beneficiary, @@ -617,6 +660,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); } @@ -647,11 +692,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); } @@ -747,6 +807,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); } } @@ -755,16 +820,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) @@ -781,27 +851,32 @@ 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); } } - // public function adminShowCompletedOrders() - // { - // $bookings = Booking::select('id','created_at','user_id','rate','amount', 'bia', 'admin_status') - // ->where('admin_status', 7) - // ->orderBy('id', 'desc') - // ->get(); + public function adminShowCompletedOrders() + { + $bookings = Booking::select('id','created_at','user_id','rate','amount', 'bia', 'admin_status') + ->where('admin_status', 7) + ->orderBy('id', 'desc') + ->get(); - // foreach ($bookings as $booking) { - // $booking->id; - // $booking->created_at; - // $booking->marking = $booking->user->marking; - // $booking->rate; - // $booking->amount; - // $booking->bia; - // $booking->admin_status = "(". $booking->admin_status ."/7)";; - // } - // return $bookings; - // } + foreach ($bookings as $booking) { + $booking->id; + $booking->created_at; + $booking->marking = $booking->user->marking; + $booking->rate; + $booking->amount; + $booking->bia; + $booking->admin_status = "(". $booking->admin_status ."/7)";; + } + return $bookings; + } } diff --git a/app/Http/Controllers/BookingSupplierController.php b/app/Http/Controllers/BookingSupplierController.php index 93caaf06..7f84c087 100644 --- a/app/Http/Controllers/BookingSupplierController.php +++ b/app/Http/Controllers/BookingSupplierController.php @@ -11,6 +11,8 @@ use App\UserBankSlip; use App\SettingBeneficiary; use App\SupplierBookingItem; use App\SettingSupplier; +use App\SettingTaxRate; +use App\SettingActiveBank; use Illuminate\Http\Request; class BookingSupplierController extends Controller @@ -30,15 +32,66 @@ class BookingSupplierController extends Controller public function show($id) { $booking = Booking::where('id', $id)->first(); + $bankin_amount = round($booking->amount / $booking->rate, 2); if (!$booking){ return response()->json(['message' => 'Booking not found'], 404); } + switch ($booking->term) { + case "x1_cash": + $payment_method = "CASH"; + break; + case "x1_cheque": + + $payment_method = "CHEQUE"; + break; + case "x1_ba": + + $payment_method = "BA"; + break; + case "x2_cash": + + $payment_method = "CASH"; + break; + case "x2_cheque": + $payment_method = "CHEQUE"; + break; + case "x2_ba": + $payment_method = "BA"; + break; + default: + return response()->json([ + 'success' => false, + 'message' => 'Invalid input', + ], 422); + break; + } + + $supplier_booking = $booking->supplierBooking()->first(); $dt = new \DateTime($supplier_booking->created_at); $supplier_booking->date = $dt->format('j F Y'); - + $supplier_booking->marking = $booking->user->marking; + $supplier_booking->payment_for = $booking->payment_for; + $supplier_booking->order_no = $booking->order_no; + $supplier_booking->payment_method = $payment_method; + + $active_bank = SettingActiveBank::first(); + + // if setting is set to use customer's beneficiary + if ($active_bank->beneficiary_id == 0){ + $supplier_booking->acc_name = $booking->account_name; + $supplier_booking->acc_no = $booking->account_num; // TODO : standardize acc_no + $supplier_booking->bank_name = $booking->bank_name; + } + + else{ + $beneficiary = SettingBeneficiary::find($active_bank->beneficiary_id); + $supplier_booking->acc_name = $beneficiary->company_name; + $supplier_booking->acc_no = $beneficiary->acc_no; + $supplier_booking->bank_name = $beneficiary->bank_name; + } return response()->json($supplier_booking ,200); } @@ -47,41 +100,58 @@ class BookingSupplierController extends Controller // TODO : Multiple booking public function store(Request $request) { - $transfer_amount = $request->input("transfer_amount"); + //$transfer_amount = $request->input("transfer_amount"); $supplier_id = $request->input("supplier_id"); $booking_id = $request->input("booking_id"); - $rate = $request->input('rate'); + $rate = $request->input('rate'); // costing rate $rebate = $request->input('rebate'); - - // Calculation - $amountInRMB = $transfer_amount * $rate; - $billing = 0.015 * $transfer_amount; - $sales_tax = 0.10 * $transfer_amount; - $gst = 0 * $transfer_amount; // do we still need this ? - $customerBankInAmount = round($transfer_amount + $gst + $sales_tax + $billing,2); - $rmbBankAmount = $customerBankInAmount + $rebate; - - $user = Auth::user(); $supplier = SettingSupplier::find($supplier_id); $booking = Booking::find($booking_id); + + + // Calculation (backup) + // $amountInRMB = $transfer_amount * $rate; + // $billing = 0.015 * $transfer_amount; + // $sales_tax = 0.0 * $transfer_amount; + // $gst = 0 * $transfer_amount; // do we still need this ? + // $customerBankInAmount = round($transfer_amount + $gst + $sales_tax + $billing,2); + // $rmbBankAmount = round($customerBankInAmount + $rebate, 2); + + // Update: changes in 1.1 according to new supplier booking report + $transfer_amount = $booking->amount; + + $amount_in_myr = round($transfer_amount / $rate, 2); + $amountInRMB = $transfer_amount; + $tax_rate = SettingTaxRate::latest()->first()->tax_rate; + $sales_tax = round($tax_rate * $amount_in_myr - $amount_in_myr, 2); + $amount_after_tax = round($amount_in_myr * $tax_rate,2); + //$billing = 0.015 * $transfer_amount; + // + //$gst = 0 * $transfer_amount; // do we still need this ? + //$customerBankInAmount = round($transfer_amount + $gst + $sales_tax + $billing,2); + //$rmbBankAmount = round($customerBankInAmount + $rebate, 2); + // update existing booking supplier if exist $bookingsupplier = SupplierBooking::where('booking_id', $booking_id)->first(); if (!$bookingsupplier){ $bookingsupplier = new SupplierBooking(); - } $bookingsupplier->supplier_id = $supplier->id; - $bookingsupplier->payment_method = $request->input('payment_method'); - $bookingsupplier->transfer_amount = $transfer_amount; + $bookingsupplier->amountInRMB = $amountInRMB; // TODO : rename to underscore + $bookingsupplier->amount_in_myr = $amount_in_myr; + $bookingsupplier->tax_rate = $tax_rate; + $bookingsupplier->amount_after_tax = $amount_after_tax; $bookingsupplier->rate = $rate; - $bookingsupplier->billing_amount = $billing; - $bookingsupplier->salestax_amount = $sales_tax; - $bookingsupplier->rebate = $rebate; - $bookingsupplier->amountInRMB = $amountInRMB; - $bookingsupplier->rmbBankAmount = $rmbBankAmount; + $bookingsupplier->rebate = $rebate; + $bookingsupplier->salestax_amount = $sales_tax; + //$bookingsupplier->payment_method = $request->input('payment_method'); // TODO : remove from db + //$bookingsupplier->transfer_amount = $transfer_amount; // TODO : remove from db + //$bookingsupplier->billing_amount = $billing; // TODO : remove from db + + //$bookingsupplier->rmbBankAmount = $rmbBankAmount; // TODO : remove from db $bookingsupplier->booking_id = $booking->id; $bookingsupplier->save(); @@ -89,47 +159,12 @@ class BookingSupplierController extends Controller $booking->status = 4; $booking->admin_status = 4; $booking->save(); + + return response()->json($bookingsupplier, 201); } - - public function update(Request $request, $id) - { - $bookingsupplier = SupplierBooking::find($id); - $bookingsupplier->payment_method = $request->input('payment_method'); - $bookingsupplier->transfer_amount = $request->input('transfer_amount'); - $bookingsupplier->rate = $request->input('rate'); - $bookingsupplier->rebate = $request->input('rebate'); - // calculation - $amountInRMB = $amount * $rate; - $billing = 0.015 * $amount; - $sales_tax = 0.10 * $amount; - $gst = 0 * $amount; - $customerBankInAmount = round($amount + $gst + $sales_tax + $billing,2); - $rmbBankAmount = $customerBankInAmount + $rebate; - - // save amount in rmb - $bookingsupplier->amountInRMB = $amountInRMB; - // save rmb bank amount - $bookingsupplier->rmbBankAmount = $rmbBankAmount; - $bookingsupplier->save(); - - /* For multiple booking */ - // $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); - } - - public function report(Request $request, $id) { $supplier_booking = Booking::firstOrFail($id)->supplierBooking()->firstOrFail(); diff --git a/app/Http/Controllers/ChinaBankSlipController.php b/app/Http/Controllers/ChinaBankSlipController.php index eabfe4a5..58aad3a0 100644 --- a/app/Http/Controllers/ChinaBankSlipController.php +++ b/app/Http/Controllers/ChinaBankSlipController.php @@ -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); } diff --git a/app/Http/Controllers/NotificationController.php b/app/Http/Controllers/NotificationController.php new file mode 100644 index 00000000..7c8aa8a7 --- /dev/null +++ b/app/Http/Controllers/NotificationController.php @@ -0,0 +1,66 @@ +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') + ->paginate(5); + $user_unread_notification = Notification::Where([["user_id",Auth::user()->id],["is_read",0]]) + ->orderby('updated_at','desc') + ->get(); + + return response()->json([ + "message" =>$user_all_notification, + "unread_message" =>$user_unread_notification + ],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); + } + + +} \ No newline at end of file diff --git a/app/Http/Controllers/SettingBeneficiaryController.php b/app/Http/Controllers/SettingBeneficiaryController.php index fdec75f7..eef947b1 100644 --- a/app/Http/Controllers/SettingBeneficiaryController.php +++ b/app/Http/Controllers/SettingBeneficiaryController.php @@ -12,8 +12,12 @@ class SettingBeneficiaryController extends Controller return SettingBeneficiary::all(); } - public function show(SettingBeneficiary $beneficiary) + public function show($beneficiary) { + if ($beneficiary == 0){ + response()->json(["company_name"=>"123", "account_number"=>"123"] , 201); + } + $beneficiary = SettingBeneficiary::find($beneficiary); return $beneficiary; } diff --git a/app/Notification.php b/app/Notification.php new file mode 100644 index 00000000..0ac7488f --- /dev/null +++ b/app/Notification.php @@ -0,0 +1,77 @@ +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"; + } + } + +} diff --git a/caddy/Caddyfile b/caddy/Caddyfile index 00750dea..304f45c1 100644 --- a/caddy/Caddyfile +++ b/caddy/Caddyfile @@ -1,6 +1,5 @@ -# Docs: https://caddyserver.com/docs/caddyfile https://exchange-staging.izyim.com { - root /var/www/public + root /app/public fastcgi / 127.0.0.1:9000 php { index index.php } @@ -9,10 +8,17 @@ https://exchange-staging.izyim.com { # ext / .html rewrite { - to {path} {path}/ /index.php?{query} + r .* + ext / + to /index.php?{query} } + + header / { + Cache-Control no-cache + } + gzip - browse + # browse log stdout errors stdout on startup php-fpm --nodaemonize diff --git a/caddy/Dockerfile b/caddy/Dockerfile index 675a39b5..f2c15948 100644 --- a/caddy/Dockerfile +++ b/caddy/Dockerfile @@ -10,8 +10,9 @@ RUN curl --silent --show-error --fail --location \ && /usr/bin/caddy -version \ && docker-php-ext-install mbstring pdo pdo_mysql +ADD . /var/www COPY Caddyfile /etc/Caddyfile -WORKDIR /var/www/public +WORKDIR /var/www CMD ["/usr/bin/caddy", "--conf", "/etc/Caddyfile", "--log", "stdout"] \ No newline at end of file diff --git a/config/jwt.php b/config/jwt.php index c4ea92db..b9fffd28 100644 --- a/config/jwt.php +++ b/config/jwt.php @@ -100,7 +100,7 @@ return [ | */ - 'ttl' => env('JWT_TTL', 60), + 'ttl' => env('JWT_TTL', 60 * 12), /* |-------------------------------------------------------------------------- diff --git a/database/migrations/2018_07_20_145804_make_china_beneficiary_acc_nulabble_in_beneficiarysetting_table.php b/database/migrations/2018_07_20_145804_make_china_beneficiary_acc_nulabble_in_beneficiarysetting_table.php new file mode 100644 index 00000000..9fbde388 --- /dev/null +++ b/database/migrations/2018_07_20_145804_make_china_beneficiary_acc_nulabble_in_beneficiarysetting_table.php @@ -0,0 +1,33 @@ +dropForeign('setting_active_banks_beneficiary_id_foreign'); + $table->integer('beneficiary_id')->nullable()->unsigned()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('beneficiarysetting', function (Blueprint $table) { + // + }); + } +} diff --git a/database/migrations/2018_07_20_175339_add_orderno_n_paymentfor_field_to_bookings_table.php b/database/migrations/2018_07_20_175339_add_orderno_n_paymentfor_field_to_bookings_table.php new file mode 100644 index 00000000..18a24a7e --- /dev/null +++ b/database/migrations/2018_07_20_175339_add_orderno_n_paymentfor_field_to_bookings_table.php @@ -0,0 +1,33 @@ +string('order_no')->nullable(); + $table->string('payment_for'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('bookings', function (Blueprint $table) { + // + }); + } +} diff --git a/database/migrations/2018_07_21_102920_create_notification_table.php b/database/migrations/2018_07_21_102920_create_notification_table.php new file mode 100644 index 00000000..7e3be228 --- /dev/null +++ b/database/migrations/2018_07_21_102920_create_notification_table.php @@ -0,0 +1,39 @@ +increments('id'); + $table->string('detail'); + $table->string('link'); + $table->unsignedInteger('user_id'); + $table->boolean('is_read')->default(0); + $table->timestamps(); + + $table->foreign('user_id') + ->references('id')->on('users') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('notifications'); + } +} diff --git a/database/migrations/2018_07_26_094305_add_fields_into_supplier_bookings_table.php b/database/migrations/2018_07_26_094305_add_fields_into_supplier_bookings_table.php new file mode 100644 index 00000000..c7320caa --- /dev/null +++ b/database/migrations/2018_07_26_094305_add_fields_into_supplier_bookings_table.php @@ -0,0 +1,32 @@ +string('amount_in_myr')->nullable(); + $table->string('tax_rate')->nullable(); + $table->string('amount_after_tax')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/database/seeds/BookTableSeeder.php b/database/seeds/BookTableSeeder.php index 5dfc3fd9..9bbc0d9a 100644 --- a/database/seeds/BookTableSeeder.php +++ b/database/seeds/BookTableSeeder.php @@ -18,8 +18,8 @@ class BookTableSeeder extends Seeder $rate = Rate::all()->last(); DB::table('bookings')->insert([ - 'account_name' => 'milah', - 'account_num' => '99898', + 'account_name' => 'EXCHANGE SDN BHD', + 'account_num' => '99898239298123', 'bank_name' => 'maybank', 'bank_branch' => 'rembau', 'company_name' => 'ICEF', @@ -36,6 +36,8 @@ class BookTableSeeder extends Seeder 'user_id' => $user->id, 'status' => 2, 'admin_status' => 2, + 'order_no' => '001', + 'payment_for' => 'FULL PAYMENT', 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), ]); diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index ebc04e05..e0ba98e9 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -28,6 +28,7 @@ class DatabaseSeeder extends Seeder $this->call(SettingActiveBankSeeder::class); $this->call(SettingTaxRateSeeder::class); $this->call(SettingBillingChargeSeeder::class); + $this->call(NotificationSeeder::class); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); } } diff --git a/database/seeds/NotificationSeeder.php b/database/seeds/NotificationSeeder.php new file mode 100644 index 00000000..ac238997 --- /dev/null +++ b/database/seeds/NotificationSeeder.php @@ -0,0 +1,35 @@ +first(); + $admin = User::where("email", "admin@example.com")->first(); + + DB::table('notifications')->insert([ + 'detail' => 'This is an user seeder notification', + 'user_id' => $user->id, + 'link' => 'http://www.google.com', + 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), + 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), + ]); + + DB::table('notifications')->insert([ + 'detail' => 'This is an admin seeder notification', + 'user_id' => $admin->id, + 'link' => 'http://www.google.com', + 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), + 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), + ]); + } +} diff --git a/database/seeds/SettingActiveBankSeeder.php b/database/seeds/SettingActiveBankSeeder.php index 59ed5afd..953de4f3 100644 --- a/database/seeds/SettingActiveBankSeeder.php +++ b/database/seeds/SettingActiveBankSeeder.php @@ -13,8 +13,8 @@ class SettingActiveBankSeeder extends Seeder */ public function run() { - $bankx1 = SettingMalaysiaBank::where('acc_no', "=" ,'malaysiaacc01')->first(); - $bankx2 = SettingMalaysiaBank::where('acc_no', "=",'malaysiaacc02')->first(); + $bankx1 = SettingMalaysiaBank::find(1); + $bankx2 = SettingMalaysiaBank::find(2); $chinabank = SettingBeneficiary::where('acc_no', "=" ,'123456789')->first(); DB::table('setting_active_banks')->truncate(); diff --git a/database/seeds/SettingMalaysiaBankSeeder.php b/database/seeds/SettingMalaysiaBankSeeder.php index 21cc374a..7fed97fe 100644 --- a/database/seeds/SettingMalaysiaBankSeeder.php +++ b/database/seeds/SettingMalaysiaBankSeeder.php @@ -15,8 +15,8 @@ class SettingMalaysiaBankSeeder extends Seeder DB::table('setting_malaysia_banks')->truncate(); DB::table('setting_malaysia_banks')->insert([ 'company_name' => 'CIEF', - 'bank_name' => 'Maybank', - 'acc_no' => 'malaysiaacc01', + 'bank_name' => 'MAYBANK', + 'acc_no' => '75930284783', 'bank_address' => 'Jalan putrajaya', 'swift' => 'ABC123', 'cnap' => 'CED234', @@ -24,8 +24,8 @@ class SettingMalaysiaBankSeeder extends Seeder ]); DB::table('setting_malaysia_banks')->insert([ 'company_name' => 'CIEF', - 'bank_name' => 'Maybank', - 'acc_no' => 'malaysiaacc02', + 'bank_name' => 'MAYBANK', + 'acc_no' => '85839298348', 'bank_address' => 'Jalan putrajaya', 'swift' => 'ABC123', 'cnap' => 'CED234', diff --git a/package.json b/package.json index 5b860ffb..33534d51 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@fortawesome/fontawesome-free-brands": "^5.0.8", "@fortawesome/fontawesome-free-regular": "^5.0.8", "@fortawesome/fontawesome-free-solid": "^5.0.8", - "@fortawesome/vue-fontawesome": "^0.0.22", + "@fortawesome/vue-fontawesome": "0.0.22", "@xkeshi/vue-countdown": "^0.6.0", "axios": "^0.18.0", "bootstrap": "^4.0.0", @@ -27,7 +27,6 @@ "npm": "^6.0.1", "popper.js": "^1.14.1", "sweetalert2": "^7.15.1", - "vee-validate": "^2.1.0-beta.5", "vform": "^1.0.0", "vue": "^2.5.16", "vue-axios": "^2.1.1", diff --git a/public/banklogo.png b/public/banklogo.png deleted file mode 100644 index 90b6a8c8..00000000 Binary files a/public/banklogo.png and /dev/null differ diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 5b2beb01..e0e5bcc2 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -10,7 +10,6 @@ import locale from 'element-ui/lib/locale/lang/en' import '~/plugins' import '~/components' -import VeeValidate from 'vee-validate'; const config = { errorBagName: 'errors', // change if property conflicts. fieldsBagName: 'fields', @@ -29,7 +28,6 @@ const config = { events: 'blur', inject: true }; -Vue.use(VeeValidate, config); Vue.config.productionTip = false diff --git a/resources/assets/js/components/LocaleDropdown.vue b/resources/assets/js/components/LocaleDropdown.vue index 745d1b98..010328c6 100644 --- a/resources/assets/js/components/LocaleDropdown.vue +++ b/resources/assets/js/components/LocaleDropdown.vue @@ -132,7 +132,7 @@ export default { this.rate = response.data }) }, - createRate: function () { + createRate: function () { // TODO : we do not have create rate, only update rate. Delete this ? this.loading = true, this.dialogFormVisible1 = true let newRate = { diff --git a/resources/assets/js/components/Navbar.vue b/resources/assets/js/components/Navbar.vue index e8d970e7..6725d8c5 100644 --- a/resources/assets/js/components/Navbar.vue +++ b/resources/assets/js/components/Navbar.vue @@ -68,11 +68,37 @@ height: 2rem; margin: -.375rem 0; } + .el-dropdown-menu{ + height: 50%; + } + #notification{ + overflow-y: scroll; + overflow-x: hidden; + max-height: 100%; + } + #notification-load-more{ + position: absolute; + width: 100%; + min-height: 20px; + background: white; + border: 1px solid #dcdfe6; + } + .el-dropdown-menu__item { + line-height: 26px; + } + .opacity80{ + opacity: 0.8 ; + } + ::-webkit-scrollbar { + width: 0px; + background: transparent; /* make scrollbar transparent */ + } + \ No newline at end of file diff --git a/resources/assets/js/pages/booking/uploadUserBankSlip.vue b/resources/assets/js/pages/booking/uploadUserBankSlip.vue index 7f9ac8fd..ab9f8f99 100644 --- a/resources/assets/js/pages/booking/uploadUserBankSlip.vue +++ b/resources/assets/js/pages/booking/uploadUserBankSlip.vue @@ -222,7 +222,7 @@ export default { console.log(error); this.$message({ showClose: true, - message: 'Fetch data fail', + message: 'Fetch bank details fail', type: 'error', duration: 10000 }); @@ -265,8 +265,10 @@ export default { let newUserSlip = { transfer_amount: this.user_slip_form.transfer_amount } - axios.patch('/api/booking/' + this.booking_id + '/bankslip-amount', newUserSlip) + axios.patch('/api/booking/' + this.booking_id + '/bankslip-amount/', newUserSlip) .then((response) => { + console.log(response); + this.$message({ showClose: true, message: 'Your bankinslip has been submitted, please wait admin to approve.', @@ -277,6 +279,7 @@ export default { this.$router.push({ name: 'home' }) + }) .catch((error) => { this.loading = false diff --git a/resources/assets/js/pages/home.vue b/resources/assets/js/pages/home.vue index 81c89ecd..b0593a56 100644 --- a/resources/assets/js/pages/home.vue +++ b/resources/assets/js/pages/home.vue @@ -22,7 +22,7 @@