@@ -5,38 +5,38 @@ |
||
5 | 5 | |
6 | 6 | class RouteServiceProvider extends ServiceProvider { |
7 | 7 | |
8 | - /** |
|
9 | - * This namespace is applied to the controller routes in your routes file. |
|
10 | - * |
|
11 | - * In addition, it is set as the URL generator's root namespace. |
|
12 | - * |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $namespace = 'App\Http\Controllers'; |
|
8 | + /** |
|
9 | + * This namespace is applied to the controller routes in your routes file. |
|
10 | + * |
|
11 | + * In addition, it is set as the URL generator's root namespace. |
|
12 | + * |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $namespace = 'App\Http\Controllers'; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Define your route model bindings, pattern filters, etc. |
|
19 | - * |
|
20 | - * @param \Illuminate\Routing\Router $router |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function boot(Router $router) |
|
24 | - { |
|
25 | - parent::boot($router); |
|
26 | - } |
|
17 | + /** |
|
18 | + * Define your route model bindings, pattern filters, etc. |
|
19 | + * |
|
20 | + * @param \Illuminate\Routing\Router $router |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function boot(Router $router) |
|
24 | + { |
|
25 | + parent::boot($router); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Define the routes for the application. |
|
30 | - * |
|
31 | - * @param \Illuminate\Routing\Router $router |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public function map(Router $router) |
|
35 | - { |
|
36 | - $router->group(['namespace' => $this->namespace], function($router) |
|
37 | - { |
|
38 | - require app_path('Http/routes.php'); |
|
39 | - }); |
|
40 | - } |
|
28 | + /** |
|
29 | + * Define the routes for the application. |
|
30 | + * |
|
31 | + * @param \Illuminate\Routing\Router $router |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public function map(Router $router) |
|
35 | + { |
|
36 | + $router->group(['namespace' => $this->namespace], function($router) |
|
37 | + { |
|
38 | + require app_path('Http/routes.php'); |
|
39 | + }); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | try { |
19 | 19 | $category = $this->model->find($id); |
20 | 20 | } |
21 | - catch(\Exception $e) { |
|
21 | + catch (\Exception $e) { |
|
22 | 22 | throw new RepositoryException('Could not retrieve category', RepositoryException::DATABASE_ERROR); |
23 | 23 | } |
24 | 24 | |
25 | - if( $category==NULL ) { |
|
25 | + if ($category == NULL) { |
|
26 | 26 | throw new RepositoryException('Category not found', RepositoryException::RESOURCE_NOT_FOUND); |
27 | 27 | } |
28 | 28 | |
@@ -38,6 +38,6 @@ discard block |
||
38 | 38 | AND c.deleted_at IS NULL |
39 | 39 | AND c.group_id = ?'; |
40 | 40 | |
41 | - return DB::select($query, [ Session::get('groupID') ]); |
|
41 | + return DB::select($query, [Session::get('groupID')]); |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -17,8 +17,7 @@ |
||
17 | 17 | |
18 | 18 | try { |
19 | 19 | $category = $this->model->find($id); |
20 | - } |
|
21 | - catch(\Exception $e) { |
|
20 | + } catch(\Exception $e) { |
|
22 | 21 | throw new RepositoryException('Could not retrieve category', RepositoryException::DATABASE_ERROR); |
23 | 22 | } |
24 | 23 |
@@ -19,7 +19,7 @@ |
||
19 | 19 | { |
20 | 20 | $connections = $this->model->where('user_id', '=', $userId)->orderBy('connect_time', 'DESC')->get(); |
21 | 21 | } |
22 | - catch(\Exception $e) |
|
22 | + catch (\Exception $e) |
|
23 | 23 | { |
24 | 24 | throw new RepositoryException('Could not fetch connections for user #'.$userId, RepositoryException::DATABASE_ERROR); |
25 | 25 | } |
@@ -20,8 +20,7 @@ |
||
20 | 20 | try |
21 | 21 | { |
22 | 22 | $settingRecord = $this->model->where('setting_name', '=', $setting_name)->firstOrFail(); |
23 | - } |
|
24 | - catch(\Exception $e) |
|
23 | + } catch(\Exception $e) |
|
25 | 24 | { |
26 | 25 | throw new RepositoryException('Could not retrieve setting '.$setting_name, RepositoryException::DATABASE_ERROR); |
27 | 26 | } |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | return 'App\Models\Groups'; |
13 | 13 | } |
14 | 14 | |
15 | - public function get($groupId=-1) |
|
15 | + public function get($groupId = -1) |
|
16 | 16 | { |
17 | - if( $groupId==-1 ) { |
|
17 | + if ($groupId == -1) { |
|
18 | 18 | $groupId = session('groupID'); |
19 | 19 | } |
20 | 20 | else { |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | try { |
25 | 25 | $group = $this->model->findOrFail($groupId); |
26 | 26 | } |
27 | - catch(Exception $e) { |
|
27 | + catch (Exception $e) { |
|
28 | 28 | throw new RepositoryException('Could not find group with ID '.$groupId, RepositoryException::DATABASE_ERROR); |
29 | 29 | } |
30 | 30 |
@@ -16,15 +16,13 @@ |
||
16 | 16 | { |
17 | 17 | if( $groupId==-1 ) { |
18 | 18 | $groupId = session('groupID'); |
19 | - } |
|
20 | - else { |
|
19 | + } else { |
|
21 | 20 | $this->validateID($groupId); |
22 | 21 | } |
23 | 22 | |
24 | 23 | try { |
25 | 24 | $group = $this->model->findOrFail($groupId); |
26 | - } |
|
27 | - catch(Exception $e) { |
|
25 | + } catch(Exception $e) { |
|
28 | 26 | throw new RepositoryException('Could not find group with ID '.$groupId, RepositoryException::DATABASE_ERROR); |
29 | 27 | } |
30 | 28 |
@@ -20,9 +20,9 @@ discard block |
||
20 | 20 | public function all() { |
21 | 21 | |
22 | 22 | try { |
23 | - return $this->model->group( Session::get('groupID') )->get(); |
|
23 | + return $this->model->group(Session::get('groupID'))->get(); |
|
24 | 24 | } |
25 | - catch(\Exception $e) { |
|
25 | + catch (\Exception $e) { |
|
26 | 26 | throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
27 | 27 | } |
28 | 28 | } |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | $this->validateID($id); |
33 | 33 | |
34 | 34 | try { |
35 | - return $this->model->group( Session::get('groupID') )->where('product_id', $id)->first(); |
|
35 | + return $this->model->group(Session::get('groupID'))->where('product_id', $id)->first(); |
|
36 | 36 | } |
37 | - catch(\Exception $e) { |
|
37 | + catch (\Exception $e) { |
|
38 | 38 | throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
39 | 39 | } |
40 | 40 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | try { |
49 | 49 | $product->save(); |
50 | 50 | } |
51 | - catch(\Exception $e) { |
|
51 | + catch (\Exception $e) { |
|
52 | 52 | throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
53 | 53 | } |
54 | 54 | |
@@ -62,16 +62,16 @@ discard block |
||
62 | 62 | $this->validate($data, false); |
63 | 63 | |
64 | 64 | try { |
65 | - $product = $this->model->group( Session::get('groupID') )->withTrashed()->find($id); |
|
65 | + $product = $this->model->group(Session::get('groupID'))->withTrashed()->find($id); |
|
66 | 66 | } |
67 | - catch(\Exception $e) { |
|
67 | + catch (\Exception $e) { |
|
68 | 68 | throw new RepositoryException('Database error while fetching'.$e->getMessage(), RepositoryException::DATABASE_ERROR); |
69 | 69 | } |
70 | 70 | |
71 | - if( $product == null ) |
|
71 | + if ($product == null) |
|
72 | 72 | throw new RepositoryException('Product with ID '.$id.' not found', RepositoryException::RESOURCE_NOT_FOUND); |
73 | 73 | |
74 | - if( $product->trashed() ) |
|
74 | + if ($product->trashed()) |
|
75 | 75 | throw new RepositoryException('Product with ID '.$id.' has been deleted', RepositoryException::RESOURCE_DENIED); |
76 | 76 | |
77 | 77 | $this->createModel($data, $product); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | try { |
80 | 80 | $product->save(); |
81 | 81 | } |
82 | - catch(\Exception $e) { |
|
82 | + catch (\Exception $e) { |
|
83 | 83 | throw new RepositoryException('Database error while saving', RepositoryException::DATABASE_ERROR); |
84 | 84 | } |
85 | 85 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | try { |
99 | 99 | $product = $this->model->findOrFail($id); |
100 | 100 | |
101 | - if( ($product->quantity-$number) >= 0 ) |
|
101 | + if (($product->quantity - $number)>=0) |
|
102 | 102 | { |
103 | 103 | $product->quantity -= $number; |
104 | 104 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | $product->save(); |
111 | 111 | } |
112 | - catch(\Exception $e) { |
|
112 | + catch (\Exception $e) { |
|
113 | 113 | throw new RepositoryException('Could not decrement product number:'.$e->getMessage(), RepositoryException::DATABASE_ERROR); |
114 | 114 | } |
115 | 115 | |
@@ -121,22 +121,22 @@ discard block |
||
121 | 121 | $this->validateID($id); |
122 | 122 | |
123 | 123 | try { |
124 | - $product = $this->model->group( Session::get('groupID') )->withTrashed()->find($id); |
|
124 | + $product = $this->model->group(Session::get('groupID'))->withTrashed()->find($id); |
|
125 | 125 | } |
126 | - catch(\Exception $e) { |
|
126 | + catch (\Exception $e) { |
|
127 | 127 | throw new RepositoryException('Database error while fetching', RepositoryException::DATABASE_ERROR); |
128 | 128 | } |
129 | 129 | |
130 | - if( $product == null ) |
|
130 | + if ($product == null) |
|
131 | 131 | throw new RepositoryException('Product with ID'.$id.' not found', RepositoryException::RESOURCE_NOT_FOUND); |
132 | 132 | |
133 | - if( $product->trashed() ) |
|
133 | + if ($product->trashed()) |
|
134 | 134 | throw new RepositoryException('Product with ID '.$id.' has been deleted', RepositoryException::RESOURCE_DENIED); |
135 | 135 | |
136 | 136 | try { |
137 | 137 | $product->delete(); |
138 | 138 | } |
139 | - catch(\Exception $e) { |
|
139 | + catch (\Exception $e) { |
|
140 | 140 | throw new RepositoryException('Database error while deleting', RepositoryException::DATABASE_ERROR); |
141 | 141 | } |
142 | 142 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | { |
157 | 157 | $beginDate = Carbon::now()->sub($interval)->addHour(); |
158 | 158 | |
159 | - if( $interval->d>0 ) |
|
159 | + if ($interval->d>0) |
|
160 | 160 | { |
161 | 161 | $beginDate = $beginDate->startOfDay(); |
162 | 162 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | ->withTrashed() |
176 | 176 | ->get(); |
177 | 177 | } |
178 | - catch(\Exception $e) |
|
178 | + catch (\Exception $e) |
|
179 | 179 | { |
180 | 180 | throw new RepositoryException('Could not retrieve product ranking', RepositoryException::DATABASE_ERROR); |
181 | 181 | } |
@@ -191,13 +191,13 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function APIFormat($products) |
193 | 193 | { |
194 | - if($products instanceof Products) { |
|
194 | + if ($products instanceof Products) { |
|
195 | 195 | return [$this->formatRecord($products)]; |
196 | 196 | } |
197 | 197 | |
198 | 198 | $responseArray = []; |
199 | 199 | foreach ($products as $product) { |
200 | - array_push($responseArray, $this->formatRecord( $product )); |
|
200 | + array_push($responseArray, $this->formatRecord($product)); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | return $responseArray; |
@@ -211,11 +211,11 @@ discard block |
||
211 | 211 | * @return void |
212 | 212 | * @throws RepositoryException If the validation failed |
213 | 213 | */ |
214 | - public function validate(array $data, $required=true) |
|
214 | + public function validate(array $data, $required = true) |
|
215 | 215 | { |
216 | 216 | $rules = Products::$validationRules; |
217 | 217 | |
218 | - if( $required === false ) { |
|
218 | + if ($required === false) { |
|
219 | 219 | |
220 | 220 | foreach ($rules as $rule => $value) { |
221 | 221 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | |
226 | 226 | $validator = Validator::make($data, $rules); |
227 | 227 | |
228 | - if( $validator->fails() ) { |
|
228 | + if ($validator->fails()) { |
|
229 | 229 | throw new RepositoryException('Validation failed', RepositoryException::VALIDATION_FAILED); |
230 | 230 | } |
231 | 231 | } |
@@ -237,23 +237,23 @@ discard block |
||
237 | 237 | * @param object $model Existing Eloquent model to update. If NULL, a new model will be created |
238 | 238 | * @return null|$object The new or updated Eloquent model |
239 | 239 | */ |
240 | - private function createModel($data, $model=NULL) |
|
240 | + private function createModel($data, $model = NULL) |
|
241 | 241 | { |
242 | - if( $model == NULL ) |
|
242 | + if ($model == NULL) |
|
243 | 243 | $model = new Products(); |
244 | 244 | |
245 | 245 | $columnAlias = ['category' => 'category_id', |
246 | 246 | 'name' => 'product_name', |
247 | 247 | 'price' => 'price', |
248 | 248 | 'quantity' => 'quantity', |
249 | - 'description' => 'description' ]; |
|
249 | + 'description' => 'description']; |
|
250 | 250 | |
251 | 251 | foreach ($data as $name => $value) { |
252 | 252 | |
253 | - if( !isset( $columnAlias[$name] ) ) |
|
253 | + if (!isset($columnAlias[$name])) |
|
254 | 254 | continue; |
255 | 255 | |
256 | - if( $value !== '' ) |
|
256 | + if ($value !== '') |
|
257 | 257 | $model->$columnAlias[$name] = $value; |
258 | 258 | } |
259 | 259 | |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | $productObject->price = floatval($product->price); |
276 | 276 | $productObject->quantity = intval($product->quantity); |
277 | 277 | |
278 | - $productObject->name = $product->product_name; |
|
278 | + $productObject->name = $product->product_name; |
|
279 | 279 | $productObject->description = $product->description; |
280 | 280 | |
281 | 281 | return $productObject; |
@@ -21,8 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | try { |
23 | 23 | return $this->model->group( Session::get('groupID') )->get(); |
24 | - } |
|
25 | - catch(\Exception $e) { |
|
24 | + } catch(\Exception $e) { |
|
26 | 25 | throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
27 | 26 | } |
28 | 27 | } |
@@ -33,8 +32,7 @@ discard block |
||
33 | 32 | |
34 | 33 | try { |
35 | 34 | return $this->model->group( Session::get('groupID') )->where('product_id', $id)->first(); |
36 | - } |
|
37 | - catch(\Exception $e) { |
|
35 | + } catch(\Exception $e) { |
|
38 | 36 | throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
39 | 37 | } |
40 | 38 | } |
@@ -47,8 +45,7 @@ discard block |
||
47 | 45 | |
48 | 46 | try { |
49 | 47 | $product->save(); |
50 | - } |
|
51 | - catch(\Exception $e) { |
|
48 | + } catch(\Exception $e) { |
|
52 | 49 | throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
53 | 50 | } |
54 | 51 | |
@@ -63,23 +60,23 @@ discard block |
||
63 | 60 | |
64 | 61 | try { |
65 | 62 | $product = $this->model->group( Session::get('groupID') )->withTrashed()->find($id); |
66 | - } |
|
67 | - catch(\Exception $e) { |
|
63 | + } catch(\Exception $e) { |
|
68 | 64 | throw new RepositoryException('Database error while fetching'.$e->getMessage(), RepositoryException::DATABASE_ERROR); |
69 | 65 | } |
70 | 66 | |
71 | - if( $product == null ) |
|
72 | - throw new RepositoryException('Product with ID '.$id.' not found', RepositoryException::RESOURCE_NOT_FOUND); |
|
67 | + if( $product == null ) { |
|
68 | + throw new RepositoryException('Product with ID '.$id.' not found', RepositoryException::RESOURCE_NOT_FOUND); |
|
69 | + } |
|
73 | 70 | |
74 | - if( $product->trashed() ) |
|
75 | - throw new RepositoryException('Product with ID '.$id.' has been deleted', RepositoryException::RESOURCE_DENIED); |
|
71 | + if( $product->trashed() ) { |
|
72 | + throw new RepositoryException('Product with ID '.$id.' has been deleted', RepositoryException::RESOURCE_DENIED); |
|
73 | + } |
|
76 | 74 | |
77 | 75 | $this->createModel($data, $product); |
78 | 76 | |
79 | 77 | try { |
80 | 78 | $product->save(); |
81 | - } |
|
82 | - catch(\Exception $e) { |
|
79 | + } catch(\Exception $e) { |
|
83 | 80 | throw new RepositoryException('Database error while saving', RepositoryException::DATABASE_ERROR); |
84 | 81 | } |
85 | 82 | |
@@ -101,15 +98,13 @@ discard block |
||
101 | 98 | if( ($product->quantity-$number) >= 0 ) |
102 | 99 | { |
103 | 100 | $product->quantity -= $number; |
104 | - } |
|
105 | - else |
|
101 | + } else |
|
106 | 102 | { |
107 | 103 | $product->quantity = 0; |
108 | 104 | } |
109 | 105 | |
110 | 106 | $product->save(); |
111 | - } |
|
112 | - catch(\Exception $e) { |
|
107 | + } catch(\Exception $e) { |
|
113 | 108 | throw new RepositoryException('Could not decrement product number:'.$e->getMessage(), RepositoryException::DATABASE_ERROR); |
114 | 109 | } |
115 | 110 | |
@@ -122,21 +117,21 @@ discard block |
||
122 | 117 | |
123 | 118 | try { |
124 | 119 | $product = $this->model->group( Session::get('groupID') )->withTrashed()->find($id); |
125 | - } |
|
126 | - catch(\Exception $e) { |
|
120 | + } catch(\Exception $e) { |
|
127 | 121 | throw new RepositoryException('Database error while fetching', RepositoryException::DATABASE_ERROR); |
128 | 122 | } |
129 | 123 | |
130 | - if( $product == null ) |
|
131 | - throw new RepositoryException('Product with ID'.$id.' not found', RepositoryException::RESOURCE_NOT_FOUND); |
|
124 | + if( $product == null ) { |
|
125 | + throw new RepositoryException('Product with ID'.$id.' not found', RepositoryException::RESOURCE_NOT_FOUND); |
|
126 | + } |
|
132 | 127 | |
133 | - if( $product->trashed() ) |
|
134 | - throw new RepositoryException('Product with ID '.$id.' has been deleted', RepositoryException::RESOURCE_DENIED); |
|
128 | + if( $product->trashed() ) { |
|
129 | + throw new RepositoryException('Product with ID '.$id.' has been deleted', RepositoryException::RESOURCE_DENIED); |
|
130 | + } |
|
135 | 131 | |
136 | 132 | try { |
137 | 133 | $product->delete(); |
138 | - } |
|
139 | - catch(\Exception $e) { |
|
134 | + } catch(\Exception $e) { |
|
140 | 135 | throw new RepositoryException('Database error while deleting', RepositoryException::DATABASE_ERROR); |
141 | 136 | } |
142 | 137 | |
@@ -174,8 +169,7 @@ discard block |
||
174 | 169 | ->take(10) |
175 | 170 | ->withTrashed() |
176 | 171 | ->get(); |
177 | - } |
|
178 | - catch(\Exception $e) |
|
172 | + } catch(\Exception $e) |
|
179 | 173 | { |
180 | 174 | throw new RepositoryException('Could not retrieve product ranking', RepositoryException::DATABASE_ERROR); |
181 | 175 | } |
@@ -239,8 +233,9 @@ discard block |
||
239 | 233 | */ |
240 | 234 | private function createModel($data, $model=NULL) |
241 | 235 | { |
242 | - if( $model == NULL ) |
|
243 | - $model = new Products(); |
|
236 | + if( $model == NULL ) { |
|
237 | + $model = new Products(); |
|
238 | + } |
|
244 | 239 | |
245 | 240 | $columnAlias = ['category' => 'category_id', |
246 | 241 | 'name' => 'product_name', |
@@ -250,11 +245,13 @@ discard block |
||
250 | 245 | |
251 | 246 | foreach ($data as $name => $value) { |
252 | 247 | |
253 | - if( !isset( $columnAlias[$name] ) ) |
|
254 | - continue; |
|
248 | + if( !isset( $columnAlias[$name] ) ) { |
|
249 | + continue; |
|
250 | + } |
|
255 | 251 | |
256 | - if( $value !== '' ) |
|
257 | - $model->$columnAlias[$name] = $value; |
|
252 | + if( $value !== '' ) { |
|
253 | + $model->$columnAlias[$name] = $value; |
|
254 | + } |
|
258 | 255 | } |
259 | 256 | |
260 | 257 | return $model; |
@@ -17,74 +17,74 @@ discard block |
||
17 | 17 | return 'App\Models\Products'; |
18 | 18 | } |
19 | 19 | |
20 | - public function all() { |
|
20 | + public function all() { |
|
21 | 21 | |
22 | - try { |
|
23 | - return $this->model->group( Session::get('groupID') )->get(); |
|
24 | - } |
|
25 | - catch(\Exception $e) { |
|
26 | - throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
|
27 | - } |
|
28 | - } |
|
22 | + try { |
|
23 | + return $this->model->group( Session::get('groupID') )->get(); |
|
24 | + } |
|
25 | + catch(\Exception $e) { |
|
26 | + throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
|
27 | + } |
|
28 | + } |
|
29 | 29 | |
30 | - public function get($id) { |
|
30 | + public function get($id) { |
|
31 | 31 | |
32 | - $this->validateID($id); |
|
32 | + $this->validateID($id); |
|
33 | 33 | |
34 | - try { |
|
35 | - return $this->model->group( Session::get('groupID') )->where('product_id', $id)->first(); |
|
36 | - } |
|
37 | - catch(\Exception $e) { |
|
38 | - throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
|
39 | - } |
|
40 | - } |
|
34 | + try { |
|
35 | + return $this->model->group( Session::get('groupID') )->where('product_id', $id)->first(); |
|
36 | + } |
|
37 | + catch(\Exception $e) { |
|
38 | + throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - public function store(array $data) { |
|
42 | + public function store(array $data) { |
|
43 | 43 | |
44 | - $this->validate($data); |
|
44 | + $this->validate($data); |
|
45 | 45 | |
46 | - $product = $this->createModel($data); |
|
46 | + $product = $this->createModel($data); |
|
47 | 47 | |
48 | - try { |
|
49 | - $product->save(); |
|
50 | - } |
|
51 | - catch(\Exception $e) { |
|
52 | - throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
|
53 | - } |
|
48 | + try { |
|
49 | + $product->save(); |
|
50 | + } |
|
51 | + catch(\Exception $e) { |
|
52 | + throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
|
53 | + } |
|
54 | 54 | |
55 | - $product->id = DB::getPdo()->lastInsertId(); |
|
56 | - return $product; |
|
57 | - } |
|
55 | + $product->id = DB::getPdo()->lastInsertId(); |
|
56 | + return $product; |
|
57 | + } |
|
58 | 58 | |
59 | - public function update($id, array $data) { |
|
59 | + public function update($id, array $data) { |
|
60 | 60 | |
61 | - $this->validateID($id); |
|
62 | - $this->validate($data, false); |
|
61 | + $this->validateID($id); |
|
62 | + $this->validate($data, false); |
|
63 | 63 | |
64 | - try { |
|
65 | - $product = $this->model->group( Session::get('groupID') )->withTrashed()->find($id); |
|
66 | - } |
|
67 | - catch(\Exception $e) { |
|
68 | - throw new RepositoryException('Database error while fetching'.$e->getMessage(), RepositoryException::DATABASE_ERROR); |
|
69 | - } |
|
64 | + try { |
|
65 | + $product = $this->model->group( Session::get('groupID') )->withTrashed()->find($id); |
|
66 | + } |
|
67 | + catch(\Exception $e) { |
|
68 | + throw new RepositoryException('Database error while fetching'.$e->getMessage(), RepositoryException::DATABASE_ERROR); |
|
69 | + } |
|
70 | 70 | |
71 | - if( $product == null ) |
|
72 | - throw new RepositoryException('Product with ID '.$id.' not found', RepositoryException::RESOURCE_NOT_FOUND); |
|
71 | + if( $product == null ) |
|
72 | + throw new RepositoryException('Product with ID '.$id.' not found', RepositoryException::RESOURCE_NOT_FOUND); |
|
73 | 73 | |
74 | - if( $product->trashed() ) |
|
75 | - throw new RepositoryException('Product with ID '.$id.' has been deleted', RepositoryException::RESOURCE_DENIED); |
|
74 | + if( $product->trashed() ) |
|
75 | + throw new RepositoryException('Product with ID '.$id.' has been deleted', RepositoryException::RESOURCE_DENIED); |
|
76 | 76 | |
77 | - $this->createModel($data, $product); |
|
77 | + $this->createModel($data, $product); |
|
78 | 78 | |
79 | - try { |
|
80 | - $product->save(); |
|
81 | - } |
|
82 | - catch(\Exception $e) { |
|
83 | - throw new RepositoryException('Database error while saving', RepositoryException::DATABASE_ERROR); |
|
84 | - } |
|
79 | + try { |
|
80 | + $product->save(); |
|
81 | + } |
|
82 | + catch(\Exception $e) { |
|
83 | + throw new RepositoryException('Database error while saving', RepositoryException::DATABASE_ERROR); |
|
84 | + } |
|
85 | 85 | |
86 | - return $product; |
|
87 | - } |
|
86 | + return $product; |
|
87 | + } |
|
88 | 88 | |
89 | 89 | public function decrementQuantity($id, $number) { |
90 | 90 | |
@@ -116,32 +116,32 @@ discard block |
||
116 | 116 | return $product->quantity; |
117 | 117 | } |
118 | 118 | |
119 | - public function softDelete($id) { |
|
119 | + public function softDelete($id) { |
|
120 | 120 | |
121 | - $this->validateID($id); |
|
121 | + $this->validateID($id); |
|
122 | 122 | |
123 | - try { |
|
124 | - $product = $this->model->group( Session::get('groupID') )->withTrashed()->find($id); |
|
125 | - } |
|
126 | - catch(\Exception $e) { |
|
127 | - throw new RepositoryException('Database error while fetching', RepositoryException::DATABASE_ERROR); |
|
128 | - } |
|
123 | + try { |
|
124 | + $product = $this->model->group( Session::get('groupID') )->withTrashed()->find($id); |
|
125 | + } |
|
126 | + catch(\Exception $e) { |
|
127 | + throw new RepositoryException('Database error while fetching', RepositoryException::DATABASE_ERROR); |
|
128 | + } |
|
129 | 129 | |
130 | - if( $product == null ) |
|
131 | - throw new RepositoryException('Product with ID'.$id.' not found', RepositoryException::RESOURCE_NOT_FOUND); |
|
130 | + if( $product == null ) |
|
131 | + throw new RepositoryException('Product with ID'.$id.' not found', RepositoryException::RESOURCE_NOT_FOUND); |
|
132 | 132 | |
133 | - if( $product->trashed() ) |
|
134 | - throw new RepositoryException('Product with ID '.$id.' has been deleted', RepositoryException::RESOURCE_DENIED); |
|
133 | + if( $product->trashed() ) |
|
134 | + throw new RepositoryException('Product with ID '.$id.' has been deleted', RepositoryException::RESOURCE_DENIED); |
|
135 | 135 | |
136 | - try { |
|
137 | - $product->delete(); |
|
138 | - } |
|
139 | - catch(\Exception $e) { |
|
140 | - throw new RepositoryException('Database error while deleting', RepositoryException::DATABASE_ERROR); |
|
141 | - } |
|
136 | + try { |
|
137 | + $product->delete(); |
|
138 | + } |
|
139 | + catch(\Exception $e) { |
|
140 | + throw new RepositoryException('Database error while deleting', RepositoryException::DATABASE_ERROR); |
|
141 | + } |
|
142 | 142 | |
143 | - return $product; |
|
144 | - } |
|
143 | + return $product; |
|
144 | + } |
|
145 | 145 | |
146 | 146 | /** |
147 | 147 | * Returns a top-10 from the most sold product in a given interval. |
@@ -183,101 +183,101 @@ discard block |
||
183 | 183 | return $productRank; |
184 | 184 | } |
185 | 185 | |
186 | - /** |
|
187 | - * Format a Product object or an Eloquent Collection to a REST format |
|
188 | - * |
|
189 | - * @param object $products MUST be a Product object or an Eloquent Collection |
|
190 | - * @return array |
|
191 | - */ |
|
192 | - public function APIFormat($products) |
|
186 | + /** |
|
187 | + * Format a Product object or an Eloquent Collection to a REST format |
|
188 | + * |
|
189 | + * @param object $products MUST be a Product object or an Eloquent Collection |
|
190 | + * @return array |
|
191 | + */ |
|
192 | + public function APIFormat($products) |
|
193 | 193 | { |
194 | 194 | if($products instanceof Products) { |
195 | 195 | return [$this->formatRecord($products)]; |
196 | 196 | } |
197 | 197 | |
198 | - $responseArray = []; |
|
199 | - foreach ($products as $product) { |
|
200 | - array_push($responseArray, $this->formatRecord( $product )); |
|
201 | - } |
|
202 | - |
|
203 | - return $responseArray; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Validates an array of data |
|
208 | - * |
|
209 | - * @param array $data Data array of the form: column_alias => value_to_validate |
|
210 | - * @param bool $required Indicates if validation must follow 'required' instructions |
|
211 | - * @return void |
|
212 | - * @throws RepositoryException If the validation failed |
|
213 | - */ |
|
214 | - public function validate(array $data, $required=true) |
|
198 | + $responseArray = []; |
|
199 | + foreach ($products as $product) { |
|
200 | + array_push($responseArray, $this->formatRecord( $product )); |
|
201 | + } |
|
202 | + |
|
203 | + return $responseArray; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Validates an array of data |
|
208 | + * |
|
209 | + * @param array $data Data array of the form: column_alias => value_to_validate |
|
210 | + * @param bool $required Indicates if validation must follow 'required' instructions |
|
211 | + * @return void |
|
212 | + * @throws RepositoryException If the validation failed |
|
213 | + */ |
|
214 | + public function validate(array $data, $required=true) |
|
215 | 215 | { |
216 | - $rules = Products::$validationRules; |
|
216 | + $rules = Products::$validationRules; |
|
217 | 217 | |
218 | - if( $required === false ) { |
|
218 | + if( $required === false ) { |
|
219 | 219 | |
220 | - foreach ($rules as $rule => $value) { |
|
220 | + foreach ($rules as $rule => $value) { |
|
221 | 221 | |
222 | - $rules[$rule] = str_replace('required', '', $value); |
|
223 | - } |
|
224 | - } |
|
222 | + $rules[$rule] = str_replace('required', '', $value); |
|
223 | + } |
|
224 | + } |
|
225 | 225 | |
226 | - $validator = Validator::make($data, $rules); |
|
226 | + $validator = Validator::make($data, $rules); |
|
227 | 227 | |
228 | - if( $validator->fails() ) { |
|
229 | - throw new RepositoryException('Validation failed', RepositoryException::VALIDATION_FAILED); |
|
230 | - } |
|
231 | - } |
|
228 | + if( $validator->fails() ) { |
|
229 | + throw new RepositoryException('Validation failed', RepositoryException::VALIDATION_FAILED); |
|
230 | + } |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * Create or update an Eloquent model with the specified data |
|
235 | - * |
|
236 | - * @param array $data Data array with the new data |
|
237 | - * @param object $model Existing Eloquent model to update. If NULL, a new model will be created |
|
238 | - * @return null|object The new or updated Eloquent model |
|
239 | - */ |
|
240 | - private function createModel($data, $model=NULL) |
|
233 | + /** |
|
234 | + * Create or update an Eloquent model with the specified data |
|
235 | + * |
|
236 | + * @param array $data Data array with the new data |
|
237 | + * @param object $model Existing Eloquent model to update. If NULL, a new model will be created |
|
238 | + * @return null|object The new or updated Eloquent model |
|
239 | + */ |
|
240 | + private function createModel($data, $model=NULL) |
|
241 | 241 | { |
242 | - if( $model == NULL ) |
|
243 | - $model = new Products(); |
|
242 | + if( $model == NULL ) |
|
243 | + $model = new Products(); |
|
244 | 244 | |
245 | - $columnAlias = ['category' => 'category_id', |
|
246 | - 'name' => 'product_name', |
|
247 | - 'price' => 'price', |
|
248 | - 'quantity' => 'quantity', |
|
249 | - 'description' => 'description' ]; |
|
245 | + $columnAlias = ['category' => 'category_id', |
|
246 | + 'name' => 'product_name', |
|
247 | + 'price' => 'price', |
|
248 | + 'quantity' => 'quantity', |
|
249 | + 'description' => 'description' ]; |
|
250 | 250 | |
251 | - foreach ($data as $name => $value) { |
|
251 | + foreach ($data as $name => $value) { |
|
252 | 252 | |
253 | - if( !isset( $columnAlias[$name] ) ) |
|
254 | - continue; |
|
255 | - |
|
256 | - if( $value !== '' ) |
|
257 | - $model->$columnAlias[$name] = $value; |
|
258 | - } |
|
259 | - |
|
260 | - return $model; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Format an Eloquent 'record' into a REST oriented object |
|
265 | - * |
|
266 | - * @param object $product An Eloquent object that represents a record |
|
267 | - * @return object A stdObject which contains some casted attributes |
|
268 | - */ |
|
269 | - private function formatRecord($product) |
|
253 | + if( !isset( $columnAlias[$name] ) ) |
|
254 | + continue; |
|
255 | + |
|
256 | + if( $value !== '' ) |
|
257 | + $model->$columnAlias[$name] = $value; |
|
258 | + } |
|
259 | + |
|
260 | + return $model; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Format an Eloquent 'record' into a REST oriented object |
|
265 | + * |
|
266 | + * @param object $product An Eloquent object that represents a record |
|
267 | + * @return object A stdObject which contains some casted attributes |
|
268 | + */ |
|
269 | + private function formatRecord($product) |
|
270 | 270 | { |
271 | - $productObject = new stdClass(); |
|
271 | + $productObject = new stdClass(); |
|
272 | 272 | |
273 | - $productObject->id = intval($product->product_id); |
|
274 | - $productObject->category = intval($product->category_id); |
|
275 | - $productObject->price = floatval($product->price); |
|
276 | - $productObject->quantity = intval($product->quantity); |
|
273 | + $productObject->id = intval($product->product_id); |
|
274 | + $productObject->category = intval($product->category_id); |
|
275 | + $productObject->price = floatval($product->price); |
|
276 | + $productObject->quantity = intval($product->quantity); |
|
277 | 277 | |
278 | - $productObject->name = $product->product_name; |
|
279 | - $productObject->description = $product->description; |
|
278 | + $productObject->name = $product->product_name; |
|
279 | + $productObject->description = $product->description; |
|
280 | 280 | |
281 | - return $productObject; |
|
282 | - } |
|
281 | + return $productObject; |
|
282 | + } |
|
283 | 283 | } |
284 | 284 | \ No newline at end of file |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use App\Models\SaleDetails; |
5 | 5 | use Validator; |
6 | 6 | |
7 | -class SaleDetailsRepository extends Repository{ |
|
7 | +class SaleDetailsRepository extends Repository { |
|
8 | 8 | |
9 | 9 | public function getModelName() |
10 | 10 | { |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | $detail->save(); |
28 | 28 | } |
29 | - catch(\Exception $e) |
|
29 | + catch (\Exception $e) |
|
30 | 30 | { |
31 | 31 | throw new RepositoryException("Could not store sale detail: ".$e->getMessage(), RepositoryException::DATABASE_ERROR); |
32 | 32 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | ] |
44 | 44 | ); |
45 | 45 | |
46 | - if( $validator->fails() ) { |
|
46 | + if ($validator->fails()) { |
|
47 | 47 | throw new RepositoryException('Sale detail validation failed', RepositoryException::VALIDATION_FAILED); |
48 | 48 | } |
49 | 49 | } |
@@ -20,8 +20,7 @@ |
||
20 | 20 | try |
21 | 21 | { |
22 | 22 | $settingRecord = $this->model->where('setting_name', '=', $setting_name)->firstOrFail(); |
23 | - } |
|
24 | - catch(\Exception $e) |
|
23 | + } catch(\Exception $e) |
|
25 | 24 | { |
26 | 25 | throw new RepositoryException('Could not retrieve setting '.$setting_name, RepositoryException::DATABASE_ERROR); |
27 | 26 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | } |
38 | 38 | catch (Exception $e) |
39 | 39 | { |
40 | - throw new RepositoryException('Could not save sale in database: ' . $e->getMessage(), RepositoryException::DATABASE_ERROR); |
|
40 | + throw new RepositoryException('Could not save sale in database: '.$e->getMessage(), RepositoryException::DATABASE_ERROR); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
@@ -45,16 +45,16 @@ discard block |
||
45 | 45 | { |
46 | 46 | $beginDate = Carbon::now()->sub($interval)->addHour(); |
47 | 47 | |
48 | - if( $interval->d>0 ) |
|
48 | + if ($interval->d>0) |
|
49 | 49 | { |
50 | 50 | $beginDate = $beginDate->startOfDay(); |
51 | 51 | } |
52 | 52 | |
53 | 53 | $intervals = []; |
54 | 54 | $dateCounter = clone $beginDate; |
55 | - while($dateCounter <= Carbon::now()) |
|
55 | + while ($dateCounter<=Carbon::now()) |
|
56 | 56 | { |
57 | - if( $interval->h>0 ) |
|
57 | + if ($interval->h>0) |
|
58 | 58 | { |
59 | 59 | $intervals[$dateCounter->hour] = 0; |
60 | 60 | $dateCounter->addHour(1); |
@@ -72,16 +72,16 @@ discard block |
||
72 | 72 | ->where('time', '>=', $beginDate) |
73 | 73 | ->get(); |
74 | 74 | } |
75 | - catch(Exception $e) |
|
75 | + catch (Exception $e) |
|
76 | 76 | { |
77 | 77 | throw new RepositoryException('Could not get sale data', RepositoryException::DATABASE_ERROR); |
78 | 78 | } |
79 | 79 | |
80 | - foreach($sales as $sale) |
|
80 | + foreach ($sales as $sale) |
|
81 | 81 | { |
82 | 82 | $carbonTimestamp = Carbon::createFromFormat('Y-m-d H:m:s', $sale->time); |
83 | 83 | |
84 | - if( $interval->h>0 ) |
|
84 | + if ($interval->h>0) |
|
85 | 85 | { |
86 | 86 | $intervals[$carbonTimestamp->hour]++; |
87 | 87 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | { |
99 | 99 | $beginDate = Carbon::now()->sub($interval)->addHour(); |
100 | 100 | |
101 | - if( $interval->d>0 ) |
|
101 | + if ($interval->d>0) |
|
102 | 102 | { |
103 | 103 | $beginDate = $beginDate->startOfDay(); |
104 | 104 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | ->take(10) |
115 | 115 | ->get(); |
116 | 116 | } |
117 | - catch(Exception $e) |
|
117 | + catch (Exception $e) |
|
118 | 118 | { |
119 | 119 | throw new RepositoryException('Could not retrieve users', RepositoryException::DATABASE_ERROR); |
120 | 120 | } |
@@ -34,8 +34,7 @@ discard block |
||
34 | 34 | $sale->save(); |
35 | 35 | |
36 | 36 | return DB::getPdo()->lastInsertId(); |
37 | - } |
|
38 | - catch (Exception $e) |
|
37 | + } catch (Exception $e) |
|
39 | 38 | { |
40 | 39 | throw new RepositoryException('Could not save sale in database: ' . $e->getMessage(), RepositoryException::DATABASE_ERROR); |
41 | 40 | } |
@@ -58,8 +57,7 @@ discard block |
||
58 | 57 | { |
59 | 58 | $intervals[$dateCounter->hour] = 0; |
60 | 59 | $dateCounter->addHour(1); |
61 | - } |
|
62 | - else |
|
60 | + } else |
|
63 | 61 | { |
64 | 62 | $intervals[$dateCounter->day] = 0; |
65 | 63 | $dateCounter->addDay(1); |
@@ -71,8 +69,7 @@ discard block |
||
71 | 69 | $sales = $this->model->where('is_active', '=', true) |
72 | 70 | ->where('time', '>=', $beginDate) |
73 | 71 | ->get(); |
74 | - } |
|
75 | - catch(Exception $e) |
|
72 | + } catch(Exception $e) |
|
76 | 73 | { |
77 | 74 | throw new RepositoryException('Could not get sale data', RepositoryException::DATABASE_ERROR); |
78 | 75 | } |
@@ -84,8 +81,7 @@ discard block |
||
84 | 81 | if( $interval->h>0 ) |
85 | 82 | { |
86 | 83 | $intervals[$carbonTimestamp->hour]++; |
87 | - } |
|
88 | - else |
|
84 | + } else |
|
89 | 85 | { |
90 | 86 | $intervals[$carbonTimestamp->day]++; |
91 | 87 | } |
@@ -113,8 +109,7 @@ discard block |
||
113 | 109 | ->orderBy('count', 'DESC') |
114 | 110 | ->take(10) |
115 | 111 | ->get(); |
116 | - } |
|
117 | - catch(Exception $e) |
|
112 | + } catch(Exception $e) |
|
118 | 113 | { |
119 | 114 | throw new RepositoryException('Could not retrieve users', RepositoryException::DATABASE_ERROR); |
120 | 115 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | { |
22 | 22 | $settingRecord = $this->model->where('setting_name', '=', $setting_name)->firstOrFail(); |
23 | 23 | } |
24 | - catch(\Exception $e) |
|
24 | + catch (\Exception $e) |
|
25 | 25 | { |
26 | 26 | throw new RepositoryException('Could not retrieve setting '.$setting_name, RepositoryException::DATABASE_ERROR); |
27 | 27 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | private function validateName($setting_name) |
38 | 38 | { |
39 | - if( !preg_match('/^[a-z0-9_]+$/', $setting_name) ) |
|
39 | + if (!preg_match('/^[a-z0-9_]+$/', $setting_name)) |
|
40 | 40 | { |
41 | 41 | throw new RepositoryException('Setting name is invalid', RepositoryException::VALIDATION_FAILED); |
42 | 42 | } |
@@ -20,8 +20,7 @@ |
||
20 | 20 | try |
21 | 21 | { |
22 | 22 | $settingRecord = $this->model->where('setting_name', '=', $setting_name)->firstOrFail(); |
23 | - } |
|
24 | - catch(\Exception $e) |
|
23 | + } catch(\Exception $e) |
|
25 | 24 | { |
26 | 25 | throw new RepositoryException('Could not retrieve setting '.$setting_name, RepositoryException::DATABASE_ERROR); |
27 | 26 | } |
@@ -26,37 +26,37 @@ discard block |
||
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
29 | - public function fromSnapshot($id) |
|
30 | - { |
|
31 | - $this->validateID($id); |
|
32 | - |
|
33 | - try { |
|
34 | - return $this->model->group( Session::get('groupID') ) |
|
35 | - ->leftJoin('users', 'snapshot_details.user_id', '=', 'users.user_id') |
|
36 | - ->where('snapshot_details.cs_id', '=', $id) |
|
37 | - ->get(); |
|
38 | - } |
|
39 | - catch(Exception $e) { |
|
40 | - throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
|
41 | - } |
|
42 | - } |
|
29 | + public function fromSnapshot($id) |
|
30 | + { |
|
31 | + $this->validateID($id); |
|
32 | + |
|
33 | + try { |
|
34 | + return $this->model->group( Session::get('groupID') ) |
|
35 | + ->leftJoin('users', 'snapshot_details.user_id', '=', 'users.user_id') |
|
36 | + ->where('snapshot_details.cs_id', '=', $id) |
|
37 | + ->get(); |
|
38 | + } |
|
39 | + catch(Exception $e) { |
|
40 | + throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | 44 | public function APIFormat($object) |
45 | - { |
|
46 | - if( !is_object($object) ) |
|
47 | - return null; |
|
45 | + { |
|
46 | + if( !is_object($object) ) |
|
47 | + return null; |
|
48 | 48 | |
49 | - if( get_class($object) === 'SnapshotDetails' ) |
|
50 | - return $this->formatRecord( $object ); |
|
49 | + if( get_class($object) === 'SnapshotDetails' ) |
|
50 | + return $this->formatRecord( $object ); |
|
51 | 51 | |
52 | - $responseArray = []; |
|
53 | - foreach ($object as $record) { |
|
52 | + $responseArray = []; |
|
53 | + foreach ($object as $record) { |
|
54 | 54 | |
55 | - array_push($responseArray, $this->formatRecord( $record )); |
|
56 | - } |
|
55 | + array_push($responseArray, $this->formatRecord( $record )); |
|
56 | + } |
|
57 | 57 | |
58 | - return $responseArray; |
|
59 | - } |
|
58 | + return $responseArray; |
|
59 | + } |
|
60 | 60 | |
61 | 61 | public function store(array $data) |
62 | 62 | { |
@@ -120,18 +120,18 @@ discard block |
||
120 | 120 | |
121 | 121 | private function formatRecord($object) { |
122 | 122 | |
123 | - $formatted = new stdClass(); |
|
123 | + $formatted = new stdClass(); |
|
124 | 124 | |
125 | - $formatted->id = intval($object->csd_id); |
|
126 | - $formatted->user = intval($object->user_id); |
|
127 | - $formatted->sale = intval($object->sale_id); |
|
128 | - $formatted->sum = floatval($object->sum); |
|
125 | + $formatted->id = intval($object->csd_id); |
|
126 | + $formatted->user = intval($object->user_id); |
|
127 | + $formatted->sale = intval($object->sale_id); |
|
128 | + $formatted->sum = floatval($object->sum); |
|
129 | 129 | |
130 | - $formatted->type = $object->type; |
|
131 | - $formatted->comment = $object->comment; |
|
132 | - $formatted->time = $object->timed; |
|
130 | + $formatted->type = $object->type; |
|
131 | + $formatted->comment = $object->comment; |
|
132 | + $formatted->time = $object->timed; |
|
133 | 133 | |
134 | - return $formatted; |
|
135 | - } |
|
134 | + return $formatted; |
|
135 | + } |
|
136 | 136 | |
137 | 137 | } |
138 | 138 | \ No newline at end of file |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | try { |
22 | 22 | return $this->model->findOrFail($id); |
23 | 23 | } |
24 | - catch(\Exception $e) { |
|
24 | + catch (\Exception $e) { |
|
25 | 25 | throw new RepositoryException('Could not retrieve snapshot detail', RepositoryException::DATABASE_ERROR); |
26 | 26 | } |
27 | 27 | } |
@@ -31,28 +31,28 @@ discard block |
||
31 | 31 | $this->validateID($id); |
32 | 32 | |
33 | 33 | try { |
34 | - return $this->model->group( Session::get('groupID') ) |
|
34 | + return $this->model->group(Session::get('groupID')) |
|
35 | 35 | ->leftJoin('users', 'snapshot_details.user_id', '=', 'users.user_id') |
36 | 36 | ->where('snapshot_details.cs_id', '=', $id) |
37 | 37 | ->get(); |
38 | 38 | } |
39 | - catch(Exception $e) { |
|
39 | + catch (Exception $e) { |
|
40 | 40 | throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | public function APIFormat($object) |
45 | 45 | { |
46 | - if( !is_object($object) ) |
|
46 | + if (!is_object($object)) |
|
47 | 47 | return null; |
48 | 48 | |
49 | - if( get_class($object) === 'SnapshotDetails' ) |
|
50 | - return $this->formatRecord( $object ); |
|
49 | + if (get_class($object) === 'SnapshotDetails') |
|
50 | + return $this->formatRecord($object); |
|
51 | 51 | |
52 | 52 | $responseArray = []; |
53 | 53 | foreach ($object as $record) { |
54 | 54 | |
55 | - array_push($responseArray, $this->formatRecord( $record )); |
|
55 | + array_push($responseArray, $this->formatRecord($record)); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | return $responseArray; |
@@ -71,16 +71,16 @@ discard block |
||
71 | 71 | $detail->user_id = Auth::id(); |
72 | 72 | $detail->cs_id = $data['cs_id']; |
73 | 73 | |
74 | - if( $data['type']==='SALE' ) { |
|
74 | + if ($data['type'] === 'SALE') { |
|
75 | 75 | $detail->sale_id = $data['sale_id']; |
76 | 76 | } |
77 | - if( isset($data['comment']) ) { |
|
77 | + if (isset($data['comment'])) { |
|
78 | 78 | $detail->comment = $data['comment']; |
79 | 79 | } |
80 | 80 | |
81 | 81 | $detail->save(); |
82 | 82 | } |
83 | - catch(\Exception $e) { |
|
83 | + catch (\Exception $e) { |
|
84 | 84 | throw new RepositoryException('Could not save snapshot detail in database', RepositoryException::DATABASE_ERROR); |
85 | 85 | } |
86 | 86 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | try { |
93 | 93 | $this->model->destroy($id); |
94 | 94 | } |
95 | - catch(\Exception $e) { |
|
95 | + catch (\Exception $e) { |
|
96 | 96 | throw new RepositoryException('Could not delete snapshot detail', RepositoryException::DATABASE_ERROR); |
97 | 97 | } |
98 | 98 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | public function validate(array $data) |
101 | 101 | { |
102 | 102 | // If it's a sale, it must be positive. Otherwise, it's a cash operation and it can't be 0 |
103 | - $sumExtraValidation = ( $data['type']==='SALE' ) ? '|min:0' : '|not_in:0'; |
|
103 | + $sumExtraValidation = ($data['type'] === 'SALE') ? '|min:0' : '|not_in:0'; |
|
104 | 104 | |
105 | 105 | $validator = Validator::make($data, |
106 | 106 | [ |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | ] |
114 | 114 | ); |
115 | 115 | |
116 | - if( $validator->fails() ) { |
|
116 | + if ($validator->fails()) { |
|
117 | 117 | throw new RepositoryException('Cash snapshot detail validation failed', RepositoryException::VALIDATION_FAILED); |
118 | 118 | } |
119 | 119 | } |
@@ -20,8 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | try { |
22 | 22 | return $this->model->findOrFail($id); |
23 | - } |
|
24 | - catch(\Exception $e) { |
|
23 | + } catch(\Exception $e) { |
|
25 | 24 | throw new RepositoryException('Could not retrieve snapshot detail', RepositoryException::DATABASE_ERROR); |
26 | 25 | } |
27 | 26 | } |
@@ -35,19 +34,20 @@ discard block |
||
35 | 34 | ->leftJoin('users', 'snapshot_details.user_id', '=', 'users.user_id') |
36 | 35 | ->where('snapshot_details.cs_id', '=', $id) |
37 | 36 | ->get(); |
38 | - } |
|
39 | - catch(Exception $e) { |
|
37 | + } catch(Exception $e) { |
|
40 | 38 | throw new RepositoryException('Database error', RepositoryException::DATABASE_ERROR); |
41 | 39 | } |
42 | 40 | } |
43 | 41 | |
44 | 42 | public function APIFormat($object) |
45 | 43 | { |
46 | - if( !is_object($object) ) |
|
47 | - return null; |
|
44 | + if( !is_object($object) ) { |
|
45 | + return null; |
|
46 | + } |
|
48 | 47 | |
49 | - if( get_class($object) === 'SnapshotDetails' ) |
|
50 | - return $this->formatRecord( $object ); |
|
48 | + if( get_class($object) === 'SnapshotDetails' ) { |
|
49 | + return $this->formatRecord( $object ); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | $responseArray = []; |
53 | 53 | foreach ($object as $record) { |
@@ -79,8 +79,7 @@ discard block |
||
79 | 79 | } |
80 | 80 | |
81 | 81 | $detail->save(); |
82 | - } |
|
83 | - catch(\Exception $e) { |
|
82 | + } catch(\Exception $e) { |
|
84 | 83 | throw new RepositoryException('Could not save snapshot detail in database', RepositoryException::DATABASE_ERROR); |
85 | 84 | } |
86 | 85 | } |
@@ -91,8 +90,7 @@ discard block |
||
91 | 90 | |
92 | 91 | try { |
93 | 92 | $this->model->destroy($id); |
94 | - } |
|
95 | - catch(\Exception $e) { |
|
93 | + } catch(\Exception $e) { |
|
96 | 94 | throw new RepositoryException('Could not delete snapshot detail', RepositoryException::DATABASE_ERROR); |
97 | 95 | } |
98 | 96 | } |