Parcourir la source

fixed next payment date

Josh il y a 4 ans
Parent
commit
8567cfd8f1
1 fichiers modifiés avec 19 ajouts et 0 suppressions
  1. 19 0
      app/Http/Controllers/HomeController.php

+ 19 - 0
app/Http/Controllers/HomeController.php

@@ -2,6 +2,8 @@
 
 namespace App\Http\Controllers;
 
+use DateTime;
+
 use App\Models\Client;
 use App\Models\Bill;
 use App\Models\Note;
@@ -64,6 +66,23 @@ class HomeController extends Controller
             $reimbursement["lastPaymentDate"] = '--';
         }
 
+         //if today is < 15th, next payment is 15th, else nextPayment is 
+         $today = strtotime(date('Y-m-d'));
+         $todayDate = date('j', $today);
+
+         $todayMonth =  date('m', $today);
+         $todayYear = date('Y', $today);
+         if($todayDate < 15){
+             $nextPaymentDate = new DateTime();
+             $nextPaymentDate->setDate($todayYear, $todayMonth, 15);
+             $reimbursement['nextPaymentDate'] = $nextPaymentDate->format('m/d/Y');
+         }else{
+             $nextPaymentDate = new \DateTime();
+             $lastDayOfMonth = date('t', $today);
+             $nextPaymentDate->setDate($todayYear, $todayMonth, $lastDayOfMonth);
+             $reimbursement['nextPaymentDate'] = $nextPaymentDate->format('m/d/Y');;
+         }
+
         $clientsWithAppointments = Client::where("mcp_pro_id", $performerProID)
             ->whereNotNull('next_mcp_appointment')->get();