api dashboard

This commit is contained in:
afiq
2021-11-26 21:10:28 +08:00
parent 4652ab7fce
commit 9083f9ad47
4 changed files with 44 additions and 2 deletions
@@ -676,4 +676,23 @@ class CustomerController extends Controller
return response()->json($custcawangan);
}
public function getTotalNewCustomerToday(){
$current = Carbon::now();
$current = new Carbon();
$harini = $current->toDateString();
$lastweek = $current->subWeek()->toDateString();
$newcustomertoday = Customer::on('mysql7')->where('tarikhdaftar',$harini)->count();
$newcustomerlastweek = Customer::on('mysql7')->where('tarikhdaftar',$lastweek)->count();
$diffCustomerPercent = 0;
if($newcustomerlastweek != 0){
$diffCustomerPercent = (($newcustomertoday - $newcustomerlastweek)/$newcustomerlastweek)*100;
}
$dataCustomer = [];
array_push($dataCustomer,['newCustomerToday'=>$newcustomertoday,'percentDiff'=>$diffCustomerPercent]);
return response()->json($dataCustomer);
}
}