123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- use Illuminate\Support\Facades\Cookie;
- if (!function_exists('toHumanReadable')) {
- function toHumanReadable($name)
- {
- return ucwords(preg_replace("/[^0-9a-z]/i", " ", $name));
- }
- }
- if(!function_exists('myPersonas')) {
- function myPersonas(\App\Models\User $user) {
- $user->refresh();
- $roles = [];
- if($user) { // -- will always be true!
- if($user->is_super_admin) $roles[] = 'Admin';
- if($user->is_agreed_as_manager) $roles[] = 'Manager';
- if($user->is_agreed_as_rep) $roles[] = 'Reseller';
- }
- return $roles;
- }
- }
- if(!function_exists('myPersona')) {
- function myPersona(\App\Models\User $user) {
- $user->refresh();
- $roles = [];
- if($user) { // -- will always be true!
- if($user->is_super_admin) $roles[] = 'Admin';
- if($user->is_agreed_as_manager) $roles[] = 'Manager';
- if($user->is_agreed_as_rep) $roles[] = 'Reseller';
- }
- $role = count($roles)?$roles[0]:null;
- if(!$role){
- return null;
- }else{
- return request()->session()->get('my_persona', $role);
- }
- }
- }
- if (!function_exists('toHumanReadable')) {
- function toHumanReadable($name)
- {
- return ucwords(preg_replace("/[^0-9a-z]/i", " ", $name));
- }
- }
- if(!function_exists('friendly_date_time')) {
- function friendly_date_time($value, $includeTime = true, $default = '-', $long_year=false) {
- if(!$value || empty($value)) return $default;
- try {
- if($includeTime) {
- $realTimezone = 'US/Eastern';
- $date = new DateTime($value);
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format("m/d/y" . ($includeTime ? ", h:ia" : "")) . ($includeTime ? ' EST' : '');
- }
- else {
- $result = strtotime($value);
- if($long_year){
- $result = date("m/d/Y" . ($includeTime ? ", h:ia" : ""), $result);
- }else{
- $result = date("m/d/y" . ($includeTime ? ", h:ia" : ""), $result);
- }
- return $result;
- }
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendly_date')) {
- function friendly_date($value) {
- if(!$value || empty($value)) return '';
- try {
- $result = strtotime($value);
- $result = date("m/d/Y", $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if (!function_exists('parseRender')) {
- function parseRender($_data)
- {
- $excludeWhole = [
- 'uid', 'id', 'password'
- ];
- $excludeEndsWith = [
- '_token', '_json', '_id', '_set_at'
- ];
- if ($_data) {
- $type = gettype($_data);
- if (is_string($_data) || is_numeric($_data)) {
- echo $_data;
- } else {
- echo "<table class='table table-sm table-bordered border w-100 mb-0'>";
- foreach ($_data as $k => $v) {
- if(in_array($k, $excludeWhole)) continue;
- if(\Illuminate\Support\Str::endsWith($k, $excludeEndsWith)) continue;
- echo "<tr>";
- echo "<td class='bg-light px-2'><b class='text-secondary'>" . toHumanReadable($k) . "</b></td>";
- echo "<td class='w-50 w-lg-75 px-2'>";
- if (is_object($v)) {
- parseRender($v);
- } elseif (is_array($v)) {
- foreach ($v as $k2 => $v2) {
- parseRender($v2);
- }
- } else {
- if(\Illuminate\Support\Str::endsWith($k, '_at')) {
- echo friendly_date_time($v);
- }
- elseif(\Illuminate\Support\Str::endsWith($k, 'date')) {
- echo friendly_date($v);
- }
- elseif($k == 'tracking_number') {
- echo "<a href='https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1={$v}'>{$v}</a>";
- }
- else {
- echo $v;
- }
- }
- echo "</td>";
- echo "</tr>";
- }
- echo "</table>";
- }
- }
- }
- }
- if(!function_exists('is_wanted_as_color_class')) {
- function is_wanted_as_color_class($status) {
- if($status == 'APPROVED') return 'bg-success';
- if($status == 'REJECTED') return 'bg-danger';
- if($status == 'UNDEFINED') return 'bg-white';
- }
- }
- if(!function_exists('getFirstSectionUID')) {
- function getFirstSectionUID($uid) {
- $sections = explode('-', $uid);
- return strtoupper(@$sections[0]);
- }
- }
- if (!function_exists('displayAmount')) {
- function displayAmount($prefix, $number)
- {
- return $prefix . '' . number_format($number, 2);
- }
- }
- if (!function_exists('is_future_date')) {
- function is_future_date($date)
- {
- $startDate = strtotime(date('Y-m-d', strtotime($date) ) );
-
- $currentDate = strtotime(date('Y-m-d'));
- if($startDate > $currentDate) {
- return true;
- }
- return false;
- }
- }
- if (!function_exists('days_until_this_date')) {
- function days_until_this_date($date)
- {
- $futureDate = $date;
- $d = new DateTime($futureDate);
- $days = $d->diff(new DateTime())->format('%a');
- if($days == 0) return 'Few hours';
- return $days . ' days';
- }
- }
- ?>
|