123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- <?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';
- }
- }
- if(!function_exists('friendly_date_est')) {
- function friendly_date_est($value, $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $realTimezone = resolve_timezone('EASTERN');
- $date = new DateTime($value);
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format("m/d/y");
- }
- catch (Exception $e) {
- return $e->getMessage();
- }
- }
- }
- if(!function_exists('resolve_timezone')) {
- function resolve_timezone($value) {
- try {
- switch ($value) {
- case 'ALASKA': {
- return 'US/Alaska';
- }
- case 'CENTRAL': {
- return 'US/Central';
- }
- case 'EASTERN': {
- return 'US/Eastern';
- }
- case 'HAWAII': {
- return 'US/Hawaii';
- }
- case 'MOUNTAIN': {
- return 'US/Mountain';
- }
- case 'PACIFIC': {
- return 'US/Pacific';
- }
- case 'PUERTO_RICO': {
- return 'America/Puerto_Rico';
- }
- case 'UTC': {
- return 'UTC';
- }
- }
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendly_time_by_time_zone')) {
- function friendly_time_by_time_zone($value, $default = '-', $fromTz = 'UCT', $toTz = 'US/Eastern') {
- if(!$value || empty($value)) return $default;
- try {
- $date = new DateTime($value, new DateTimeZone($fromTz));
- $date->setTimezone(new DateTimeZone($toTz));
- return $date->format('h:i a') . ' ' . friendly_timezone($toTz);
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendly_timezone')) {
- function friendly_timezone($value) {
- try {
- switch ($value) {
- case 'US/Eastern': {
- return 'EST';
- }
- }
- }catch(Exception $e){
- return $value;
- }
- }
- }
- if (!function_exists('generate_password')) {
- function generate_password($length = 20)
- {
- $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' .
- '0123456789`-=~!@#$%^&*()_+,./<>?;:[]{}\|';
- $str = '';
- $max = strlen($chars) - 1;
- for ($i = 0; $i < $length; $i++)
- $str .= $chars[random_int(0, $max)];
- return $str;
- }
- }
- if (!function_exists('selected_lab_html_address')) {
- function selected_lab_html_address($selectedLab)
- {
- return '<div>
- <span style="font-weight: bold">'.$selectedLab->lab_title.'</span><br />
- <span>'.$selectedLab->street.'</span><br />
- <span>'.$selectedLab->city.', '.$selectedLab->state.' '.$selectedLab->postcode.'</span>
- </div>';
- }
- }
- function getTestInfo($key){
- $lbsTests = (array) config('constants.lbs_tests');
- $test = @$lbsTests[$key];
- if($test) return $test;
- return null;
- }
- function getTestDisplayName($key){
- $test = (array) getTestInfo($key);
-
- if(isset($test['label'])) return $test['label'];
- return toHumanReadable($key);
- }
- function getAllTests(){
- return (array) config('constants.lbs_tests');
- }
- function getTest($testKey) {
- return @getAllTests()[$testKey];
- }
- function getTestLabelByKey( $testKey ) {
- $label = getTestLabel(getTest($testKey));
- if($label) return $label;
- return toHumanReadable($testKey);
- }
- function getTestLabel( $test ) {
- return @$test[ 'label' ];
- }
- function getTestPrice( $testKey ) {
- return floatval( config( 'app.'.$testKey ) );
- }
- if ( !function_exists( 'get_lab_station_summary2' ) ) {
- function get_lab_station_summary2( $lab ) {
- $states = config( 'constants.states' );
- $data = json_decode( $lab->data );
- return [
- 'id' => @$data->id,
- 'city' => @$data->city,
- 'distance' => '', //todo use zips table to get distance between zips
- 'fax_number' => @$data->fax_number,
- 'lab_title' => @$data->title,
- 'latitude' => @$data->latitude,
- 'longitude' => @$data->longitude,
- 'phone_number' => @$data->phone_number,
- 'postcode' => @$data->zip_code,
- 'state' => @$data->state,
- 'street' => @$data->address,
- // 'services' => json_decode( $lab->services ),
- 'hrs_of_operation' => @$data->opening_hours,
- 'show_hrs_of_operation' => false,
- 'augmented' => @$data->augmented
- ];
- }
- }
- ?>
|