|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Common; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use DateTime; |
|
7
|
|
|
use DateTimeZone; |
|
8
|
|
|
use Illuminate\Http\Request; |
|
9
|
|
|
use Spatie\Activitylog\Models\Activity; |
|
10
|
|
|
use App\Http\Controllers\Order\ExtendedOrderController; |
|
11
|
|
|
|
|
12
|
|
|
class BaseSettingsController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Get the logged activity. |
|
16
|
|
|
*/ |
|
17
|
|
|
public function getNewEntry($properties, $model) |
|
18
|
|
|
{ |
|
19
|
|
|
$properties = (array_key_exists('attributes', $properties->toArray())) |
|
20
|
|
|
? ($model->properties['attributes']) : null; |
|
21
|
|
|
|
|
22
|
|
|
$display = []; |
|
23
|
|
|
|
|
24
|
|
|
if ($properties != null) { |
|
25
|
|
|
if (array_key_exists('parent', $properties)) { |
|
26
|
|
|
unset($properties['parent']); |
|
27
|
|
|
} |
|
28
|
|
|
foreach ($properties as $key => $value) { |
|
29
|
|
|
$display[] = '<strong>'.'ucfirst'($key).'</strong>'.' : '.$value.'<br/>'; |
|
30
|
|
|
} |
|
31
|
|
|
$updated = (count($properties) > 0) ? implode('', $display) : '--'; |
|
32
|
|
|
|
|
33
|
|
|
return $updated; |
|
34
|
|
|
} else { |
|
35
|
|
|
return '--'; |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Get the older Entries. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getOldEntry($data, $model) |
|
43
|
|
|
{ |
|
44
|
|
|
$oldData = ''; |
|
45
|
|
|
$oldData = (array_key_exists('old', $data->toArray())) ? ($model->properties['old']) : null; |
|
46
|
|
|
if ($oldData != null) { |
|
47
|
|
|
if ((count($oldData) > 0)) { |
|
48
|
|
|
foreach ($oldData as $key => $value) { |
|
49
|
|
|
$display[] = '<strong>'.'ucfirst'($key).'</strong>'.' : '.$value.'<br/>'; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
$old = (count($oldData) > 0) ? implode('', $display) : '--'; |
|
53
|
|
|
|
|
54
|
|
|
return $old; |
|
55
|
|
|
} else { |
|
56
|
|
|
return '--'; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get Date. |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getDate($dbdate) |
|
64
|
|
|
{ |
|
65
|
|
|
$created = new DateTime($dbdate); |
|
66
|
|
|
$tz = \Auth::user()->timezone()->first()->name; |
|
67
|
|
|
$created->setTimezone(new DateTimeZone($tz)); |
|
68
|
|
|
$date = $created->format('M j, Y, g:i a ');//5th October, 2018, 11:17PM |
|
69
|
|
|
$newDate = $date; |
|
70
|
|
|
|
|
71
|
|
|
return $newDate; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function destroyEmail(Request $request) |
|
75
|
|
|
{ |
|
76
|
|
|
try { |
|
77
|
|
|
$ids = $request->input('select'); |
|
78
|
|
|
if (!empty($ids)) { |
|
79
|
|
|
foreach ($ids as $id) { |
|
80
|
|
|
$email = \DB::table('email_log')->where('id', $id)->delete(); |
|
81
|
|
|
if ($email) { |
|
82
|
|
|
// $email->delete(); |
|
83
|
|
|
} else { |
|
84
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
|
85
|
|
|
<i class='fa fa-ban'></i> |
|
86
|
|
|
|
|
87
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
|
88
|
|
|
/* @scrutinizer ignore-type */ \Lang::get('message.failed').' |
|
89
|
|
|
|
|
90
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
91
|
|
|
'./* @scrutinizer ignore-type */\Lang::get('message.no-record').' |
|
92
|
|
|
</div>'; |
|
93
|
|
|
//echo \Lang::get('message.no-record') . ' [id=>' . $id . ']'; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
echo "<div class='alert alert-success alert-dismissable'> |
|
97
|
|
|
<i class='fa fa-ban'></i> |
|
98
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> ' |
|
99
|
|
|
./* @scrutinizer ignore-type */\Lang::get('message.success').' |
|
100
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
101
|
|
|
'./* @scrutinizer ignore-type */ \Lang::get('message.deleted-successfully').' |
|
102
|
|
|
</div>'; |
|
103
|
|
|
} else { |
|
104
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
|
105
|
|
|
<i class='fa fa-ban'></i> |
|
106
|
|
|
<b>"./* @scrutinizer ignore-type */ \Lang::get('message.alert'). |
|
107
|
|
|
'!</b> './* @scrutinizer ignore-type */\Lang::get('message.failed').' |
|
108
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
109
|
|
|
'./* @scrutinizer ignore-type */ \Lang::get('message.select-a-row').' |
|
110
|
|
|
</div>'; |
|
111
|
|
|
//echo \Lang::get('message.select-a-row'); |
|
112
|
|
|
} |
|
113
|
|
|
} catch (\Exception $e) { |
|
114
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
|
115
|
|
|
<i class='fa fa-ban'></i> |
|
116
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
|
117
|
|
|
/* @scrutinizer ignore-type */\Lang::get('message.failed').' |
|
118
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
119
|
|
|
'.$e->getMessage().' |
|
120
|
|
|
</div>'; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function advanceSearch($from='',$till='',$delFrom='',$delTill='') |
|
125
|
|
|
{ |
|
126
|
|
|
$join = new Activity(); |
|
127
|
|
|
if ($from) { |
|
128
|
|
|
$from = $this->getDateFormat($from); |
|
129
|
|
|
$tills = $this->getDateFormat(); |
|
130
|
|
|
$tillDate = (new ExtendedOrderController)->getTillDate($from, $till, $tills); |
|
131
|
|
|
$join= $join->whereBetween('created_at', [$from, $tillDate]); |
|
132
|
|
|
} |
|
133
|
|
|
if ($till) { |
|
134
|
|
|
$till = $this->getDateFormat($till); |
|
135
|
|
|
$froms = Activity::first()->created_at; |
|
136
|
|
|
$fromDate = (new ExtendedOrderController)->getFromDate($from, $froms); |
|
137
|
|
|
$join = $join->whereBetween('created_at', [$fromDate, $till]); |
|
138
|
|
|
} |
|
139
|
|
|
if($delFrom) { |
|
140
|
|
|
$from = $this->getDateFormat($delFrom); |
|
141
|
|
|
$tills = $this->getDateFormat(); |
|
142
|
|
|
$tillDate = (new ExtendedOrderController)->getTillDate($from, $delTill, $tills); |
|
143
|
|
|
$join->whereBetween('created_at', [$from, $tillDate])->delete(); |
|
144
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
if($delTill) { |
|
147
|
|
|
$till = $this->getDateFormat($delTill); |
|
148
|
|
|
$froms=Activity::first()->created_at; |
|
149
|
|
|
$fromDate = (new ExtendedOrderController)->getFromDate($delFrom, $froms); |
|
150
|
|
|
$join->whereBetween('created_at', [$fromDate, $till])->delete();; |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
$join = $join->orderBy('created_at', 'desc') |
|
153
|
|
|
->select('id', 'log_name', 'description', |
|
154
|
|
|
'subject_id', 'subject_type', 'causer_id', 'properties', 'created_at'); |
|
155
|
|
|
return $join; |
|
156
|
|
|
|
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function getDateFormat($dbdate='') |
|
160
|
|
|
{ |
|
161
|
|
|
$created = new DateTime($dbdate); |
|
162
|
|
|
$tz = \Auth::user()->timezone()->first()->name; |
|
163
|
|
|
$created->setTimezone(new DateTimeZone($tz)); |
|
164
|
|
|
$date = $created->format('Y-m-d H:m:i'); |
|
165
|
|
|
return $date; |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|
Let’s take a look at an example: