@@ -18,117 +18,122 @@ public function setFormat($format)
18
18
return $ this ;
19
19
}
20
20
21
- public function download ($ filename )
22
- {
23
- if ($ this ->simpleVersion ) {
24
- return $ this ->simpleDownload ($ filename );
25
- }
26
-
27
- return App::make ('excel ' )->create ($ filename , function ($ excel ) use ($ filename ) {
28
- $ excel ->sheet ('Sheet 1 ' , function ($ sheet ) {
29
- $ headers = $ this ->headers ;
30
- $ query = $ this ->query ;
31
- $ columns = $ this ->columns ;
32
- $ limit = $ this ->limit ;
33
- $ groupByArr = $ this ->groupByArr ;
34
- $ orientation = $ this ->orientation ;
35
- $ editColumns = $ this ->editColumns ;
36
- $ showTotalColumns = $ this ->showTotalColumns ;
37
- $ styles = $ this ->styles ;
38
- $ showHeader = $ this ->showHeader ;
39
- $ showMeta = $ this ->showMeta ;
40
- $ applyFlush = $ this ->applyFlush ;
41
- $ showNumColumn = $ this ->showNumColumn ;
42
-
43
- $ sheet ->setColumnFormat (['A:Z ' => '@ ' ]);
44
-
45
- if ($ this ->withoutManipulation ) {
46
- $ sheet ->loadView ('report-generator-view::without-manipulation-excel-template ' ,
47
- compact ('headers ' , 'columns ' , 'showTotalColumns ' , 'query ' , 'limit ' , 'orientation ' , 'showHeader ' ,
48
- 'showMeta ' , 'applyFlush ' , 'showNumColumn ' ));
49
- } else {
50
- $ sheet ->loadView ('report-generator-view::general-excel-template ' ,
51
- compact ('headers ' , 'columns ' , 'editColumns ' , 'showTotalColumns ' , 'styles ' , 'query ' , 'limit ' ,
52
- 'groupByArr ' , 'orientation ' , 'showHeader ' , 'showMeta ' , 'applyFlush ' , 'showNumColumn ' ));
53
- }
54
- });
55
- })->export ($ this ->format );
56
- }
57
-
58
- public function simpleDownload ($ filename )
21
+ public function make ($ filename , $ simpleVersion = false )
59
22
{
60
- return App::make ('excel ' )->create ($ filename , function ($ excel ) use ($ filename ) {
61
- $ excel ->sheet ('Sheet 1 ' , function ($ sheet ) {
62
- $ sheet ->setColumnFormat (['A:Z ' => '@ ' ]);
63
- $ ctr = 1 ;
64
- foreach ($ this ->showTotalColumns as $ column => $ type ) {
65
- $ this ->total [$ column ] = 0 ;
66
- }
67
-
68
- $ chunkRecordCount = ($ this ->limit == null || $ this ->limit > 50000 ) ? 50000 : $ this ->limit + 1 ;
23
+ if ($ simpleVersion ) {
24
+ return App::make ('excel ' )->create ($ filename , function ($ excel ) use ($ filename ) {
25
+ $ excel ->sheet ('Sheet 1 ' , function ($ sheet ) {
26
+ $ sheet ->setColumnFormat (['A:Z ' => '@ ' ]);
27
+ $ ctr = 1 ;
28
+ foreach ($ this ->showTotalColumns as $ column => $ type ) {
29
+ $ this ->total [$ column ] = 0 ;
30
+ }
69
31
70
- $ sheet ->appendRow ([$ this ->headers ['title ' ]]);
71
- $ sheet ->appendRow ([' ' ]);
32
+ $ chunkRecordCount = ($ this ->limit == null || $ this ->limit > 50000 ) ? 50000 : $ this ->limit + 1 ;
72
33
73
- if ($ this ->showMeta ) {
74
- foreach ($ this ->headers ['meta ' ] as $ key => $ value ) {
75
- $ sheet ->appendRow ([
76
- $ key ,
77
- $ value
78
- ]);
79
- }
34
+ $ sheet ->appendRow ([$ this ->headers ['title ' ]]);
80
35
$ sheet ->appendRow ([' ' ]);
81
- }
82
36
83
- if ($ this ->showHeader ) {
84
- $ columns = array_keys ($ this ->columns );
85
- if (!$ this ->withoutManipulation && $ this ->showNumColumn ) {
86
- array_unshift ($ columns , 'No ' );
37
+ if ($ this ->showMeta ) {
38
+ foreach ($ this ->headers ['meta ' ] as $ key => $ value ) {
39
+ $ sheet ->appendRow ([
40
+ $ key ,
41
+ $ value
42
+ ]);
43
+ }
44
+ $ sheet ->appendRow ([' ' ]);
87
45
}
88
- $ sheet ->appendRow ($ columns );
89
- }
90
46
91
- $ this ->query ->chunk ($ chunkRecordCount , function ($ results ) use (&$ ctr , $ sheet ) {
92
- foreach ($ results as $ result ) {
93
- if ($ this ->limit != null && $ ctr == $ this ->limit + 1 ) {
94
- return false ;
95
- }
96
- if ($ this ->withoutManipulation ) {
97
- $ sheet ->appendRow ($ result ->toArray ());
98
- } else {
99
- $ formattedRows = $ this ->formatRow ($ result );
100
- if ($ this ->showNumColumn ) {
101
- array_unshift ($ formattedRows , $ ctr );
102
- }
103
- $ sheet ->appendRow ($ formattedRows );
47
+ if ($ this ->showHeader ) {
48
+ $ columns = array_keys ($ this ->columns );
49
+ if (!$ this ->withoutManipulation && $ this ->showNumColumn ) {
50
+ array_unshift ($ columns , 'No ' );
104
51
}
105
- $ ctr ++ ;
52
+ $ sheet -> appendRow ( $ columns ) ;
106
53
}
107
54
108
- if ($ this ->applyFlush ) {
109
- flush ();
110
- }
111
- });
55
+ $ this ->query ->chunk ($ chunkRecordCount , function ($ results ) use (&$ ctr , $ sheet ) {
56
+ foreach ($ results as $ result ) {
57
+ if ($ this ->limit != null && $ ctr == $ this ->limit + 1 ) {
58
+ return false ;
59
+ }
60
+ if ($ this ->withoutManipulation ) {
61
+ $ sheet ->appendRow ($ result ->toArray ());
62
+ } else {
63
+ $ formattedRows = $ this ->formatRow ($ result );
64
+ if ($ this ->showNumColumn ) {
65
+ array_unshift ($ formattedRows , $ ctr );
66
+ }
67
+ $ sheet ->appendRow ($ formattedRows );
68
+ }
69
+ $ ctr ++;
70
+ }
112
71
113
- if ($ this ->showTotalColumns ) {
114
- $ totalRows = collect (['Total ' ]);
115
- array_shift ($ columns );
116
- foreach ($ columns as $ columnName ) {
117
- if (array_key_exists ($ columnName , $ this ->showTotalColumns )) {
118
- if ($ this ->showTotalColumns [$ columnName ] == 'point ' ) {
119
- $ totalRows ->push (number_format ($ this ->total [$ columnName ], 2 , '. ' , ', ' ));
72
+ if ($ this ->applyFlush ) {
73
+ flush ();
74
+ }
75
+ });
76
+
77
+ if ($ this ->showTotalColumns ) {
78
+ $ totalRows = collect (['Grand Total ' ]);
79
+ array_shift ($ columns );
80
+ foreach ($ columns as $ columnName ) {
81
+ if (array_key_exists ($ columnName , $ this ->showTotalColumns )) {
82
+ if ($ this ->showTotalColumns [$ columnName ] == 'point ' ) {
83
+ $ totalRows ->push (number_format ($ this ->total [$ columnName ], 2 , '. ' , ', ' ));
84
+ } else {
85
+ $ totalRows ->push (strtoupper ($ this ->showTotalColumns [$ columnName ]) . ' ' . number_format ($ this ->total [$ columnName ],
86
+ 2 , '. ' , ', ' ));
87
+ }
120
88
} else {
121
- $ totalRows ->push (strtoupper ($ this ->showTotalColumns [$ columnName ]) . ' ' . number_format ($ this ->total [$ columnName ],
122
- 2 , '. ' , ', ' ));
89
+ $ totalRows ->push (null );
123
90
}
124
- } else {
125
- $ totalRows ->push (null );
126
91
}
92
+ $ sheet ->appendRow ($ totalRows ->toArray ());
127
93
}
128
- $ sheet ->appendRow ($ totalRows ->toArray ());
129
- }
94
+ });
95
+ });
96
+ } else {
97
+ return App::make ('excel ' )->create ($ filename , function ($ excel ) use ($ filename ) {
98
+ $ excel ->sheet ('Sheet 1 ' , function ($ sheet ) {
99
+ $ headers = $ this ->headers ;
100
+ $ query = $ this ->query ;
101
+ $ columns = $ this ->columns ;
102
+ $ limit = $ this ->limit ;
103
+ $ groupByArr = $ this ->groupByArr ;
104
+ $ orientation = $ this ->orientation ;
105
+ $ editColumns = $ this ->editColumns ;
106
+ $ showTotalColumns = $ this ->showTotalColumns ;
107
+ $ styles = $ this ->styles ;
108
+ $ showHeader = $ this ->showHeader ;
109
+ $ showMeta = $ this ->showMeta ;
110
+ $ applyFlush = $ this ->applyFlush ;
111
+ $ showNumColumn = $ this ->showNumColumn ;
112
+
113
+ $ sheet ->setColumnFormat (['A:Z ' => '@ ' ]);
114
+
115
+ if ($ this ->withoutManipulation ) {
116
+ $ sheet ->loadView ('report-generator-view::without-manipulation-excel-template ' ,
117
+ compact ('headers ' , 'columns ' , 'showTotalColumns ' , 'query ' , 'limit ' , 'orientation ' ,
118
+ 'showHeader ' , 'showMeta ' , 'applyFlush ' , 'showNumColumn ' ));
119
+ } else {
120
+ $ sheet ->loadView ('report-generator-view::general-excel-template ' ,
121
+ compact ('headers ' , 'columns ' , 'editColumns ' , 'showTotalColumns ' , 'styles ' , 'query ' , 'limit ' ,
122
+ 'groupByArr ' , 'orientation ' , 'showHeader ' , 'showMeta ' , 'applyFlush ' , 'showNumColumn ' ));
123
+ }
124
+ });
130
125
});
131
- })->export ($ this ->format );
126
+ }
127
+ }
128
+
129
+ public function download ($ filename )
130
+ {
131
+ return $ this ->make ($ filename , $ this ->simpleVersion )->export ($ this ->format );
132
+ }
133
+
134
+ public function simpleDownload ($ filename )
135
+ {
136
+ return $ this ->make ($ filename , true )->export ($ this ->format );
132
137
}
133
138
134
139
private function formatRow ($ result )
@@ -161,4 +166,4 @@ private function formatRow($result)
161
166
162
167
return $ rows ;
163
168
}
164
- }
169
+ }
0 commit comments