Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 633 |
|
0.00% |
0 / 61 |
CRAP | |
0.00% |
0 / 1 |
| Configurations | |
0.00% |
0 / 633 |
|
0.00% |
0 / 61 |
24806 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| list_customer_types | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| list_segments | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| list_reasons | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| list_budget_types | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| list_budget_type_groups | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| list_visit_types | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| list_visit_type_groups | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| list_budget_status | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| list_source | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| list_reason_for_not_following_up | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| list_reason_for_rejection | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| customer_types | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| segments | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| reasons | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| budget_types | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| budget_type_groups | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| visit_types | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| visit_type_groups | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| budget_status | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| source | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| reason_for_not_following_up | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| reason_for_rejection | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| add_customer_types | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| add_segments | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| add_reasons | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| add_budget_types | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| add_budget_type_groups | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| add_visit_types | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| add_visit_type_groups | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| add_budget_status | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| add_source | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| add_reason_for_not_following_up | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| add_reason_for_rejection | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| update_customer_types | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| update_segments | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| update_reasons | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| update_budget_types | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
30 | |||
| update_budget_type_groups | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
30 | |||
| update_visit_types | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| update_visit_type_groups | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
30 | |||
| update_budget_status | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| update_source | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| update_reason_for_not_following_up | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| update_reason_for_rejection | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| delete_customer_types | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| delete_segments | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| delete_reasons | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| delete_budget_types | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| delete_budget_type_groups | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| delete_visit_types | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| delete_visit_type_groups | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| delete_budget_status | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| delete_source | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| delete_reason_for_not_following_up | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| delete_reason_for_rejection | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| list_work_status | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| work_status | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| update_work_status | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| delete_work_status | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| add_work_status | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers; |
| 4 | |
| 5 | use App\Models\TblBudgetStatus; |
| 6 | use App\Models\TblBudgetTypeGroups; |
| 7 | use App\Models\TblBudgetTypes; |
| 8 | use App\Models\TblCustomerTypes; |
| 9 | use App\Models\TblOngoingJobs; |
| 10 | use App\Models\TblPipelines; |
| 11 | use App\Models\TblQuotations; |
| 12 | use App\Models\TblReasonForNotFollowingUp; |
| 13 | use App\Models\TblReasonForRejection; |
| 14 | use App\Models\TblReasons; |
| 15 | use App\Models\TblSegments; |
| 16 | use App\Models\TblSources; |
| 17 | use App\Models\TblVisitTypeGroups; |
| 18 | use App\Models\TblVisitTypes; |
| 19 | use App\Models\TblWorkStatus; |
| 20 | use Illuminate\Http\Request; |
| 21 | use Illuminate\Support\Facades\App; |
| 22 | use Illuminate\Support\Facades\Cache; |
| 23 | use Illuminate\Support\Facades\DB; |
| 24 | use Illuminate\Contracts\Routing\ResponseFactory; |
| 25 | use Illuminate\Http\Response; |
| 26 | use App\Exceptions\AppException; |
| 27 | |
| 28 | class Configurations extends Controller |
| 29 | { |
| 30 | private $locale; |
| 31 | private $customer_types = []; |
| 32 | private $segments = []; |
| 33 | private $reasons = []; |
| 34 | private $budget_types = []; |
| 35 | private $budget_status = []; |
| 36 | private $budget_type_groups = []; |
| 37 | private $source = []; |
| 38 | private $reason_for_not_following_up = []; |
| 39 | private $reason_for_rejection = []; |
| 40 | private $work_status = []; |
| 41 | private $visit_types = []; |
| 42 | private $visit_type_groups = []; |
| 43 | |
| 44 | public function __construct(){ |
| 45 | $this->locale = request()->header('Locale-Id'); |
| 46 | |
| 47 | App::setLocale($this->locale); |
| 48 | } |
| 49 | |
| 50 | function list_customer_types(): ResponseFactory|Response{ |
| 51 | |
| 52 | try { |
| 53 | |
| 54 | $this->customer_types(); |
| 55 | |
| 56 | return response([ |
| 57 | 'message' => 'OK', |
| 58 | 'data' => $this->customer_types, |
| 59 | ]); |
| 60 | |
| 61 | } catch (\Exception $e) { |
| 62 | report(AppException::fromException($e, 'LIST_CUSTOMER_TYPES_EXCEPTION')); |
| 63 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 64 | } |
| 65 | |
| 66 | } |
| 67 | |
| 68 | function list_segments(): ResponseFactory|Response{ |
| 69 | |
| 70 | try { |
| 71 | |
| 72 | $this->segments(); |
| 73 | |
| 74 | return response([ |
| 75 | 'message' => 'OK', |
| 76 | 'data' => $this->segments, |
| 77 | ]); |
| 78 | |
| 79 | } catch (\Exception $e) { |
| 80 | report(AppException::fromException($e, 'LIST_SEGMENTS_EXCEPTION')); |
| 81 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 82 | } |
| 83 | |
| 84 | } |
| 85 | |
| 86 | function list_reasons(): ResponseFactory|Response{ |
| 87 | |
| 88 | try { |
| 89 | |
| 90 | $this->reasons(); |
| 91 | |
| 92 | return response([ |
| 93 | 'message' => 'OK', |
| 94 | 'data' => $this->reasons, |
| 95 | ]); |
| 96 | |
| 97 | } catch (\Exception $e) { |
| 98 | report(AppException::fromException($e, 'LIST_REASONS_EXCEPTION')); |
| 99 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 100 | } |
| 101 | |
| 102 | } |
| 103 | |
| 104 | function list_budget_types(): ResponseFactory|Response{ |
| 105 | |
| 106 | try { |
| 107 | |
| 108 | $this->budget_types(); |
| 109 | |
| 110 | return response([ |
| 111 | 'message' => 'OK', |
| 112 | 'data' => $this->budget_types, |
| 113 | ]); |
| 114 | |
| 115 | } catch (\Exception $e) { |
| 116 | report(AppException::fromException($e, 'LIST_BUDGET_TYPES_EXCEPTION')); |
| 117 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 118 | } |
| 119 | |
| 120 | } |
| 121 | |
| 122 | function list_budget_type_groups(): ResponseFactory|Response{ |
| 123 | |
| 124 | try { |
| 125 | |
| 126 | $this->budget_type_groups(); |
| 127 | |
| 128 | return response([ |
| 129 | 'message' => 'OK', |
| 130 | 'data' => $this->budget_type_groups, |
| 131 | ]); |
| 132 | |
| 133 | } catch (\Exception $e) { |
| 134 | report(AppException::fromException($e, 'LIST_BUDGET_TYPE_GROUPS_EXCEPTION')); |
| 135 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 136 | } |
| 137 | |
| 138 | } |
| 139 | |
| 140 | function list_visit_types(): ResponseFactory|Response{ |
| 141 | |
| 142 | try { |
| 143 | |
| 144 | $this->visit_types(); |
| 145 | |
| 146 | return response([ |
| 147 | 'message' => 'OK', |
| 148 | 'data' => $this->visit_types, |
| 149 | ]); |
| 150 | |
| 151 | } catch (\Exception $e) { |
| 152 | report(AppException::fromException($e, 'LIST_VISIT_TYPES_EXCEPTION')); |
| 153 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 154 | } |
| 155 | |
| 156 | } |
| 157 | |
| 158 | function list_visit_type_groups(): ResponseFactory|Response{ |
| 159 | |
| 160 | try { |
| 161 | |
| 162 | $this->visit_type_groups(); |
| 163 | |
| 164 | return response([ |
| 165 | 'message' => 'OK', |
| 166 | 'data' => $this->visit_type_groups, |
| 167 | ]); |
| 168 | |
| 169 | } catch (\Exception $e) { |
| 170 | report(AppException::fromException($e, 'LIST_VISIT_TYPE_GROUPS_EXCEPTION')); |
| 171 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 172 | } |
| 173 | |
| 174 | } |
| 175 | |
| 176 | function list_budget_status(): ResponseFactory|Response{ |
| 177 | |
| 178 | try { |
| 179 | |
| 180 | $this->budget_status(); |
| 181 | |
| 182 | return response([ |
| 183 | 'message' => 'OK', |
| 184 | 'data' => $this->budget_status, |
| 185 | ]); |
| 186 | |
| 187 | } catch (\Exception $e) { |
| 188 | report(AppException::fromException($e, 'LIST_BUDGET_STATUS_EXCEPTION')); |
| 189 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 190 | } |
| 191 | |
| 192 | } |
| 193 | |
| 194 | function list_source(): ResponseFactory|Response{ |
| 195 | |
| 196 | try { |
| 197 | |
| 198 | $this->source(); |
| 199 | |
| 200 | return response([ |
| 201 | 'message' => 'OK', |
| 202 | 'data' => $this->source, |
| 203 | ]); |
| 204 | |
| 205 | } catch (\Exception $e) { |
| 206 | report(AppException::fromException($e, 'LIST_SOURCE_EXCEPTION')); |
| 207 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 208 | } |
| 209 | |
| 210 | } |
| 211 | |
| 212 | function list_reason_for_not_following_up(): ResponseFactory|Response{ |
| 213 | |
| 214 | try { |
| 215 | |
| 216 | $this->reason_for_not_following_up(); |
| 217 | |
| 218 | return response([ |
| 219 | 'message' => 'OK', |
| 220 | 'data' => $this->reason_for_not_following_up, |
| 221 | ]); |
| 222 | |
| 223 | } catch (\Exception $e) { |
| 224 | report(AppException::fromException($e, 'LIST_REASON_FOR_NOT_FOLLOWING_UP_EXCEPTION')); |
| 225 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 226 | } |
| 227 | |
| 228 | } |
| 229 | |
| 230 | function list_reason_for_rejection(): ResponseFactory|Response{ |
| 231 | |
| 232 | try { |
| 233 | |
| 234 | $this->reason_for_rejection(); |
| 235 | |
| 236 | return response([ |
| 237 | 'message' => 'OK', |
| 238 | 'data' => $this->reason_for_rejection, |
| 239 | ]); |
| 240 | |
| 241 | } catch (\Exception $e) { |
| 242 | report(AppException::fromException($e, 'LIST_REASON_FOR_REJECTION_EXCEPTION')); |
| 243 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 244 | } |
| 245 | |
| 246 | } |
| 247 | |
| 248 | function customer_types(): void{ |
| 249 | |
| 250 | $this->customer_types = TblCustomerTypes::orderByRaw('ISNULL(priority), priority ASC')->get(); |
| 251 | |
| 252 | } |
| 253 | |
| 254 | function segments(): void{ |
| 255 | |
| 256 | $this->segments = TblSegments::orderByRaw('ISNULL(priority), priority ASC')->get(); |
| 257 | |
| 258 | } |
| 259 | |
| 260 | function reasons(): void{ |
| 261 | |
| 262 | $this->reasons = TblReasons::orderByRaw('ISNULL(priority), priority ASC')->get(); |
| 263 | |
| 264 | } |
| 265 | |
| 266 | function budget_types(): void{ |
| 267 | |
| 268 | $query = "SELECT |
| 269 | bt.budget_type_id, |
| 270 | bt.name, |
| 271 | bt.duration, |
| 272 | bt.priority, |
| 273 | bt.color, |
| 274 | bt.include, |
| 275 | bt.budget_type_group_id, |
| 276 | btg.name budget_type_group, |
| 277 | bt.disabled, |
| 278 | bt.created_by, |
| 279 | bt.created_at |
| 280 | FROM tbl_budget_types bt |
| 281 | LEFT JOIN tbl_budget_type_groups btg |
| 282 | ON bt.budget_type_group_id = btg.budget_type_group_id |
| 283 | WHERE bt.name != '' |
| 284 | ORDER BY ISNULL(bt.priority), bt.priority ASC"; |
| 285 | |
| 286 | $this->budget_types = DB::select($query); |
| 287 | |
| 288 | } |
| 289 | |
| 290 | function budget_type_groups(): void{ |
| 291 | $this->budget_type_groups = TblBudgetTypeGroups::orderByRaw('ISNULL(priority), priority ASC')->get(); |
| 292 | } |
| 293 | |
| 294 | function visit_types(): void{ |
| 295 | |
| 296 | $query = 'SELECT |
| 297 | vt.visit_type_id, |
| 298 | vt.name, |
| 299 | vt.priority, |
| 300 | vt.visit_type_group_id, |
| 301 | vtg.name visit_type_group, |
| 302 | vt.disabled, |
| 303 | vt.created_by, |
| 304 | vt.created_at |
| 305 | FROM tbl_visit_types vt |
| 306 | LEFT JOIN tbl_visit_type_groups vtg |
| 307 | ON vt.visit_type_group_id = vtg.visit_type_group_id |
| 308 | ORDER BY ISNULL(vt.priority), vt.priority ASC'; |
| 309 | |
| 310 | $this->visit_types = DB::select($query); |
| 311 | |
| 312 | } |
| 313 | |
| 314 | function visit_type_groups(): void{ |
| 315 | $this->visit_type_groups = TblVisitTypeGroups::orderByRaw('ISNULL(priority), priority ASC')->get(); |
| 316 | } |
| 317 | |
| 318 | function budget_status(): void{ |
| 319 | $this->budget_status = TblBudgetStatus::orderByRaw('ISNULL(priority), priority ASC')->get(); |
| 320 | } |
| 321 | |
| 322 | function source(): void{ |
| 323 | $this->source = TblSources::orderByRaw('ISNULL(priority), priority ASC')->get(); |
| 324 | } |
| 325 | |
| 326 | function reason_for_not_following_up(): void{ |
| 327 | $this->reason_for_not_following_up = TblReasonForNotFollowingUp::orderByRaw('ISNULL(priority), priority ASC')->get(); |
| 328 | } |
| 329 | |
| 330 | function reason_for_rejection(): void{ |
| 331 | |
| 332 | $this->reason_for_rejection = TblReasonForRejection::orderByRaw('ISNULL(priority), priority ASC')->get(); |
| 333 | |
| 334 | } |
| 335 | |
| 336 | function add_customer_types(Request $request): ResponseFactory|Response{ |
| 337 | |
| 338 | try { |
| 339 | |
| 340 | $data = $request->all(); |
| 341 | |
| 342 | TblCustomerTypes::create($data); |
| 343 | |
| 344 | $this->customer_types(); |
| 345 | |
| 346 | return response([ |
| 347 | 'message' => 'OK', |
| 348 | 'data' => $this->customer_types, |
| 349 | ]); |
| 350 | |
| 351 | } catch (\Exception $e) { |
| 352 | report(AppException::fromException($e, 'ADD_CUSTOMER_TYPES_EXCEPTION')); |
| 353 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 354 | } |
| 355 | |
| 356 | } |
| 357 | |
| 358 | function add_segments(Request $request): ResponseFactory|Response{ |
| 359 | |
| 360 | try { |
| 361 | |
| 362 | $data = $request->all(); |
| 363 | |
| 364 | TblSegments::create($data); |
| 365 | |
| 366 | $this->segments(); |
| 367 | |
| 368 | return response([ |
| 369 | 'message' => 'OK', |
| 370 | 'data' => $this->segments, |
| 371 | ]); |
| 372 | |
| 373 | } catch (\Exception $e) { |
| 374 | report(AppException::fromException($e, 'ADD_SEGMENTS_EXCEPTION')); |
| 375 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 376 | } |
| 377 | |
| 378 | } |
| 379 | |
| 380 | function add_reasons(Request $request): ResponseFactory|Response{ |
| 381 | |
| 382 | try { |
| 383 | |
| 384 | $data = $request->all(); |
| 385 | |
| 386 | TblReasons::create($data); |
| 387 | |
| 388 | $this->reasons(); |
| 389 | |
| 390 | return response([ |
| 391 | 'message' => 'OK', |
| 392 | 'data' => $this->reasons, |
| 393 | ]); |
| 394 | |
| 395 | } catch (\Exception $e) { |
| 396 | report(AppException::fromException($e, 'ADD_REASONS_EXCEPTION')); |
| 397 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 398 | } |
| 399 | |
| 400 | } |
| 401 | |
| 402 | function add_budget_types(Request $request): ResponseFactory|Response{ |
| 403 | |
| 404 | try { |
| 405 | |
| 406 | $data = $request->all(); |
| 407 | |
| 408 | TblBudgetTypes::create($data); |
| 409 | |
| 410 | $this->budget_types(); |
| 411 | |
| 412 | return response([ |
| 413 | 'message' => 'OK', |
| 414 | 'data' => $this->budget_types, |
| 415 | ]); |
| 416 | |
| 417 | } catch (\Exception $e) { |
| 418 | report(AppException::fromException($e, 'ADD_BUDGET_TYPES_EXCEPTION')); |
| 419 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 420 | } |
| 421 | |
| 422 | } |
| 423 | |
| 424 | function add_budget_type_groups(Request $request): ResponseFactory|Response{ |
| 425 | |
| 426 | try { |
| 427 | |
| 428 | $data = $request->all(); |
| 429 | |
| 430 | TblBudgetTypeGroups::create($data); |
| 431 | |
| 432 | $this->budget_type_groups(); |
| 433 | |
| 434 | return response([ |
| 435 | 'message' => 'OK', |
| 436 | 'data' => $this->budget_type_groups, |
| 437 | ]); |
| 438 | |
| 439 | } catch (\Exception $e) { |
| 440 | report(AppException::fromException($e, 'ADD_BUDGET_TYPE_GROUPS_EXCEPTION')); |
| 441 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 442 | } |
| 443 | |
| 444 | } |
| 445 | |
| 446 | function add_visit_types(Request $request): ResponseFactory|Response{ |
| 447 | |
| 448 | try { |
| 449 | |
| 450 | $data = $request->all(); |
| 451 | |
| 452 | TblVisitTypes::create($data); |
| 453 | |
| 454 | $this->visit_types(); |
| 455 | |
| 456 | return response([ |
| 457 | 'message' => 'OK', |
| 458 | 'data' => $this->visit_types, |
| 459 | ]); |
| 460 | |
| 461 | } catch (\Exception $e) { |
| 462 | report(AppException::fromException($e, 'ADD_VISIT_TYPES_EXCEPTION')); |
| 463 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 464 | } |
| 465 | |
| 466 | } |
| 467 | |
| 468 | function add_visit_type_groups(Request $request): ResponseFactory|Response{ |
| 469 | |
| 470 | try { |
| 471 | |
| 472 | $data = $request->all(); |
| 473 | |
| 474 | TblVisitTypeGroups::create($data); |
| 475 | |
| 476 | $this->visit_type_groups(); |
| 477 | |
| 478 | return response([ |
| 479 | 'message' => 'OK', |
| 480 | 'data' => $this->visit_type_groups, |
| 481 | ]); |
| 482 | |
| 483 | } catch (\Exception $e) { |
| 484 | report(AppException::fromException($e, 'ADD_VISIT_TYPE_GROUPS_EXCEPTION')); |
| 485 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 486 | } |
| 487 | |
| 488 | } |
| 489 | |
| 490 | function add_budget_status(Request $request): ResponseFactory|Response{ |
| 491 | |
| 492 | try { |
| 493 | |
| 494 | $data = $request->all(); |
| 495 | |
| 496 | TblBudgetStatus::create($data); |
| 497 | |
| 498 | $this->budget_status(); |
| 499 | |
| 500 | return response([ |
| 501 | 'message' => 'OK', |
| 502 | 'data' => $this->budget_status, |
| 503 | ]); |
| 504 | |
| 505 | } catch (\Exception $e) { |
| 506 | report(AppException::fromException($e, 'ADD_BUDGET_STATUS_EXCEPTION')); |
| 507 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 508 | } |
| 509 | |
| 510 | } |
| 511 | |
| 512 | function add_source(Request $request): ResponseFactory|Response{ |
| 513 | |
| 514 | try { |
| 515 | |
| 516 | $data = $request->all(); |
| 517 | |
| 518 | TblSources::create($data); |
| 519 | |
| 520 | $this->source(); |
| 521 | |
| 522 | return response([ |
| 523 | 'message' => 'OK', |
| 524 | 'data' => $this->source, |
| 525 | ]); |
| 526 | |
| 527 | } catch (\Exception $e) { |
| 528 | report(AppException::fromException($e, 'ADD_SOURCE_EXCEPTION')); |
| 529 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 530 | } |
| 531 | |
| 532 | } |
| 533 | |
| 534 | function add_reason_for_not_following_up(Request $request): ResponseFactory|Response{ |
| 535 | |
| 536 | try { |
| 537 | |
| 538 | $data = $request->all(); |
| 539 | |
| 540 | TblReasonForNotFollowingUp::create($data); |
| 541 | |
| 542 | $this->reason_for_not_following_up(); |
| 543 | |
| 544 | return response([ |
| 545 | 'message' => 'OK', |
| 546 | 'data' => $this->reason_for_not_following_up, |
| 547 | ]); |
| 548 | |
| 549 | } catch (\Exception $e) { |
| 550 | report(AppException::fromException($e, 'ADD_REASON_FOR_NOT_FOLLOWING_UP_EXCEPTION')); |
| 551 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 552 | } |
| 553 | |
| 554 | } |
| 555 | |
| 556 | function add_reason_for_rejection(Request $request): ResponseFactory|Response{ |
| 557 | |
| 558 | try { |
| 559 | |
| 560 | $data = $request->all(); |
| 561 | |
| 562 | TblReasonForRejection::create($data); |
| 563 | |
| 564 | $this->reason_for_rejection(); |
| 565 | |
| 566 | return response([ |
| 567 | 'message' => 'OK', |
| 568 | 'data' => $this->reason_for_rejection, |
| 569 | ]); |
| 570 | |
| 571 | } catch (\Exception $e) { |
| 572 | report(AppException::fromException($e, 'ADD_REASON_FOR_REJECTION_EXCEPTION')); |
| 573 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 574 | } |
| 575 | |
| 576 | } |
| 577 | |
| 578 | function update_customer_types(Request $request, $customerTypeId): ResponseFactory|Response{ |
| 579 | |
| 580 | try { |
| 581 | |
| 582 | $data = $request->all(); |
| 583 | $customerTypeId = addslashes((string) $customerTypeId); |
| 584 | |
| 585 | if (isset($data['data'])) { |
| 586 | $priority = $data['data']; |
| 587 | if (count($priority) > 0) { |
| 588 | foreach ($priority as $item) { |
| 589 | TblCustomerTypes::where('customer_type_id', $item['customer_type_id'])->update(['priority' => $item['priority']]); |
| 590 | } |
| 591 | } |
| 592 | } else { |
| 593 | TblCustomerTypes::where('customer_type_id', $customerTypeId)->update($data); |
| 594 | } |
| 595 | |
| 596 | $this->customer_types(); |
| 597 | |
| 598 | return response([ |
| 599 | 'message' => 'OK', |
| 600 | 'data' => $this->customer_types, |
| 601 | ]); |
| 602 | |
| 603 | } catch (\Exception $e) { |
| 604 | report(AppException::fromException($e, 'UPDATE_CUSTOMER_TYPES_EXCEPTION')); |
| 605 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 606 | } |
| 607 | |
| 608 | } |
| 609 | |
| 610 | function update_segments(Request $request, $segmentId): ResponseFactory|Response{ |
| 611 | |
| 612 | try { |
| 613 | |
| 614 | $data = $request->all(); |
| 615 | $segmentId = addslashes((string) $segmentId); |
| 616 | |
| 617 | if (isset($data['data'])) { |
| 618 | $priority = $data['data']; |
| 619 | if (count($priority) > 0) { |
| 620 | foreach ($priority as $item) { |
| 621 | TblSegments::where('segment_id', $item['segment_id'])->update(['priority' => $item['priority']]); |
| 622 | } |
| 623 | } |
| 624 | } else { |
| 625 | TblSegments::where('segment_id', $segmentId)->update($data); |
| 626 | } |
| 627 | |
| 628 | $this->segments(); |
| 629 | |
| 630 | return response([ |
| 631 | 'message' => 'OK', |
| 632 | 'data' => $this->segments, |
| 633 | ]); |
| 634 | |
| 635 | } catch (\Exception $e) { |
| 636 | report(AppException::fromException($e, 'UPDATE_SEGMENTS_EXCEPTION')); |
| 637 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 638 | } |
| 639 | |
| 640 | } |
| 641 | |
| 642 | function update_reasons(Request $request, $reasonId): ResponseFactory|Response{ |
| 643 | |
| 644 | try { |
| 645 | |
| 646 | $data = $request->all(); |
| 647 | $reasonId = addslashes((string) $reasonId); |
| 648 | |
| 649 | if (isset($data['data'])) { |
| 650 | $priority = $data['data']; |
| 651 | if (count($priority) > 0) { |
| 652 | foreach ($priority as $item) { |
| 653 | TblReasons::where('reason_id', $item['reason_id'])->update(['priority' => $item['priority']]); |
| 654 | } |
| 655 | } |
| 656 | } else { |
| 657 | TblReasons::where('reason_id', $reasonId)->update($data); |
| 658 | } |
| 659 | |
| 660 | $this->reasons(); |
| 661 | |
| 662 | return response([ |
| 663 | 'message' => 'OK', |
| 664 | 'data' => $this->reasons, |
| 665 | ]); |
| 666 | |
| 667 | } catch (\Exception $e) { |
| 668 | report(AppException::fromException($e, 'UPDATE_REASONS_EXCEPTION')); |
| 669 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 670 | } |
| 671 | |
| 672 | } |
| 673 | |
| 674 | |
| 675 | function update_budget_types(Request $request, $budgetTypeId): ResponseFactory|Response{ |
| 676 | |
| 677 | try { |
| 678 | |
| 679 | $data = $request->all(); |
| 680 | $budgetTypeId = addslashes((string) $budgetTypeId); |
| 681 | |
| 682 | if (isset($data['data'])) { |
| 683 | $priority = $data['data']; |
| 684 | if (count($priority) > 0) { |
| 685 | foreach ($priority as $item) { |
| 686 | TblBudgetTypes::where('budget_type_id', $item['budget_type_id'])->update(['priority' => $item['priority']]); |
| 687 | } |
| 688 | } |
| 689 | } else { |
| 690 | TblBudgetTypes::where('budget_type_id', $budgetTypeId)->update($data); |
| 691 | } |
| 692 | |
| 693 | Cache::flush(); |
| 694 | $this->budget_types(); |
| 695 | |
| 696 | return response([ |
| 697 | 'message' => 'OK', |
| 698 | 'data' => $this->budget_types, |
| 699 | ]); |
| 700 | |
| 701 | } catch (\Exception $e) { |
| 702 | report(AppException::fromException($e, 'UPDATE_BUDGET_TYPES_EXCEPTION')); |
| 703 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 704 | } |
| 705 | |
| 706 | } |
| 707 | |
| 708 | function update_budget_type_groups(Request $request, $budgetTypeGroupId): ResponseFactory|Response{ |
| 709 | |
| 710 | try { |
| 711 | |
| 712 | $data = $request->all(); |
| 713 | $budgetTypeGroupId = addslashes((string) $budgetTypeGroupId); |
| 714 | |
| 715 | if (isset($data['data'])) { |
| 716 | $priority = $data['data']; |
| 717 | if (count($priority) > 0) { |
| 718 | foreach ($priority as $item) { |
| 719 | TblBudgetTypeGroups::where('budget_type_group_id', $item['budget_type_group_id'])->update(['priority' => $item['priority']]); |
| 720 | } |
| 721 | } |
| 722 | } else { |
| 723 | TblBudgetTypeGroups::where('budget_type_group_id', $budgetTypeGroupId)->update($data); |
| 724 | } |
| 725 | |
| 726 | Cache::flush(); |
| 727 | $this->budget_type_groups(); |
| 728 | |
| 729 | return response([ |
| 730 | 'message' => 'OK', |
| 731 | 'data' => $this->budget_type_groups, |
| 732 | ]); |
| 733 | |
| 734 | } catch (\Exception $e) { |
| 735 | report(AppException::fromException($e, 'UPDATE_BUDGET_TYPE_GROUPS_EXCEPTION')); |
| 736 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 737 | } |
| 738 | |
| 739 | } |
| 740 | |
| 741 | function update_visit_types(Request $request, $visitTypeId): ResponseFactory|Response{ |
| 742 | |
| 743 | try { |
| 744 | |
| 745 | $data = $request->all(); |
| 746 | $visitTypeId = addslashes((string) $visitTypeId); |
| 747 | |
| 748 | if (isset($data['data'])) { |
| 749 | $priority = $data['data']; |
| 750 | if (count($priority) > 0) { |
| 751 | foreach ($priority as $item) { |
| 752 | TblVisitTypes::where('visit_type_id', $item['visit_type_id'])->update(['priority' => $item['priority']]); |
| 753 | } |
| 754 | } |
| 755 | } else { |
| 756 | TblVisitTypes::where('visit_type_id', $visitTypeId)->update($data); |
| 757 | } |
| 758 | |
| 759 | $this->visit_types(); |
| 760 | |
| 761 | return response([ |
| 762 | 'message' => 'OK', |
| 763 | 'data' => $this->visit_types, |
| 764 | ]); |
| 765 | |
| 766 | } catch (\Exception $e) { |
| 767 | report(AppException::fromException($e, 'UPDATE_VISIT_TYPES_EXCEPTION')); |
| 768 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 769 | } |
| 770 | |
| 771 | } |
| 772 | |
| 773 | function update_visit_type_groups(Request $request, $visitTypeGroupId): ResponseFactory|Response{ |
| 774 | |
| 775 | try { |
| 776 | |
| 777 | $data = $request->all(); |
| 778 | $visitTypeGroupId = addslashes((string) $visitTypeGroupId); |
| 779 | |
| 780 | if (isset($data['data'])) { |
| 781 | $priority = $data['data']; |
| 782 | if (count($priority) > 0) { |
| 783 | foreach ($priority as $item) { |
| 784 | TblVisitTypeGroups::where('visit_type_group_id', $item['visit_type_group_id'])->update(['priority' => $item['priority']]); |
| 785 | } |
| 786 | } |
| 787 | } else { |
| 788 | TblVisitTypeGroups::where('visit_type_group_id', $visitTypeGroupId)->update($data); |
| 789 | } |
| 790 | |
| 791 | Cache::flush(); |
| 792 | $this->visit_type_groups(); |
| 793 | |
| 794 | return response([ |
| 795 | 'message' => 'OK', |
| 796 | 'data' => $this->visit_type_groups, |
| 797 | ]); |
| 798 | |
| 799 | } catch (\Exception $e) { |
| 800 | report(AppException::fromException($e, 'UPDATE_VISIT_TYPE_GROUPS_EXCEPTION')); |
| 801 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 802 | } |
| 803 | |
| 804 | } |
| 805 | |
| 806 | function update_budget_status(Request $request, $budgetStatusId): ResponseFactory|Response{ |
| 807 | |
| 808 | try { |
| 809 | |
| 810 | $data = $request->all(); |
| 811 | $budgetStatusId = addslashes((string) $budgetStatusId); |
| 812 | |
| 813 | if (isset($data['data'])) { |
| 814 | $priority = $data['data']; |
| 815 | if (count($priority) > 0) { |
| 816 | foreach ($priority as $item) { |
| 817 | TblBudgetStatus::where('budget_status_id', $item['budget_status_id'])->update(['priority' => $item['priority']]); |
| 818 | } |
| 819 | } |
| 820 | } else { |
| 821 | TblBudgetStatus::where('budget_status_id', $budgetStatusId)->update($data); |
| 822 | } |
| 823 | |
| 824 | $this->budget_status(); |
| 825 | |
| 826 | return response([ |
| 827 | 'message' => 'OK', |
| 828 | 'data' => $this->budget_status, |
| 829 | ]); |
| 830 | |
| 831 | } catch (\Exception $e) { |
| 832 | report(AppException::fromException($e, 'UPDATE_BUDGET_STATUS_EXCEPTION')); |
| 833 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 834 | } |
| 835 | |
| 836 | } |
| 837 | |
| 838 | |
| 839 | function update_source(Request $request, $sourceId): ResponseFactory|Response{ |
| 840 | |
| 841 | try { |
| 842 | |
| 843 | $data = $request->all(); |
| 844 | $sourceId = addslashes((string) $sourceId); |
| 845 | |
| 846 | if(isset($data['data'])){ |
| 847 | $priority = $data['data']; |
| 848 | if (count($priority) > 0) { |
| 849 | foreach ($priority as $item) { |
| 850 | TblSources::where('source_id', $item['source_id'])->update(['priority' => $item['priority']]); |
| 851 | } |
| 852 | } |
| 853 | } else { |
| 854 | TblSources::where('source_id', $sourceId)->update($data); |
| 855 | } |
| 856 | |
| 857 | $this->source(); |
| 858 | |
| 859 | return response([ |
| 860 | 'message' => 'OK', |
| 861 | 'data' => $this->source, |
| 862 | ]); |
| 863 | |
| 864 | } catch (\Exception $e) { |
| 865 | report(AppException::fromException($e, 'UPDATE_SOURCE_EXCEPTION')); |
| 866 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 867 | } |
| 868 | |
| 869 | } |
| 870 | |
| 871 | function update_reason_for_not_following_up(Request $request, $reasonForNotFollowingUpId): ResponseFactory|Response{ |
| 872 | |
| 873 | try { |
| 874 | |
| 875 | $data = $request->all(); |
| 876 | $reasonForNotFollowingUpId = addslashes((string) $reasonForNotFollowingUpId); |
| 877 | |
| 878 | if(isset($data['data'])){ |
| 879 | $priority = $data['data']; |
| 880 | if (count($priority) > 0) { |
| 881 | foreach ($priority as $item) { |
| 882 | TblSources::where('reason_for_not_following_up_id', $item['reason_for_not_following_up_id'])->update(['priority' => $item['priority']]); |
| 883 | } |
| 884 | } |
| 885 | } else { |
| 886 | TblReasonForNotFollowingUp::where('reason_for_not_following_up_id', $reasonForNotFollowingUpId)->update($data); |
| 887 | } |
| 888 | |
| 889 | $this->reason_for_not_following_up(); |
| 890 | |
| 891 | return response([ |
| 892 | 'message' => 'OK', |
| 893 | 'data' => $this->reason_for_not_following_up, |
| 894 | ]); |
| 895 | |
| 896 | } catch (\Exception $e) { |
| 897 | report(AppException::fromException($e, 'UPDATE_REASON_FOR_NOT_FOLLOWING_UP_EXCEPTION')); |
| 898 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 899 | } |
| 900 | |
| 901 | } |
| 902 | |
| 903 | |
| 904 | function update_reason_for_rejection(Request $request, $reasonForRejectionId): ResponseFactory|Response{ |
| 905 | |
| 906 | try { |
| 907 | |
| 908 | $data = $request->all(); |
| 909 | $reasonForRejectionId = addslashes((string) $reasonForRejectionId); |
| 910 | |
| 911 | if(isset($data['data'])){ |
| 912 | $priority = $data['data']; |
| 913 | if (count($priority) > 0) { |
| 914 | foreach ($priority as $item) { |
| 915 | TblReasonForRejection::where('reason_for_rejection_id', $item['reason_for_rejection_id'])->update(['priority' => $item['priority']]); |
| 916 | } |
| 917 | } |
| 918 | } else { |
| 919 | TblReasonForRejection::where('reason_for_rejection_id', $reasonForRejectionId)->update($data); |
| 920 | } |
| 921 | |
| 922 | $this->reason_for_rejection(); |
| 923 | |
| 924 | return response([ |
| 925 | 'message' => 'OK', |
| 926 | 'data' => $this->reason_for_rejection, |
| 927 | ]); |
| 928 | |
| 929 | } catch (\Exception $e) { |
| 930 | report(AppException::fromException($e, 'UPDATE_REASON_FOR_REJECTION_EXCEPTION')); |
| 931 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 932 | } |
| 933 | |
| 934 | } |
| 935 | |
| 936 | function delete_customer_types($customerTypeId): ResponseFactory|Response{ |
| 937 | |
| 938 | try { |
| 939 | |
| 940 | |
| 941 | $customerTypeId = addslashes((string) $customerTypeId); |
| 942 | |
| 943 | $budgets = TblQuotations::where('customer_type_id', $customerTypeId)->count(); |
| 944 | |
| 945 | if ($budgets > 0) { |
| 946 | return response([ |
| 947 | 'message' => 'KO', |
| 948 | 'error' => __('language.customer_types.delete_message.message1').' '.$budgets.' '.__('language.customer_types.delete_message.message2'), |
| 949 | ]); |
| 950 | } |
| 951 | |
| 952 | $customerType = TblCustomerTypes::where('customer_type_id', $customerTypeId)->first(); |
| 953 | TblCustomerTypes::where('customer_type_id', $customerTypeId)->delete(); |
| 954 | |
| 955 | $this->customer_types(); |
| 956 | |
| 957 | return response([ |
| 958 | 'message' => 'OK', |
| 959 | 'data' => $this->customer_types, |
| 960 | ]); |
| 961 | |
| 962 | } catch (\Exception $e) { |
| 963 | report(AppException::fromException($e, 'DELETE_CUSTOMER_TYPES_EXCEPTION')); |
| 964 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 965 | } |
| 966 | |
| 967 | } |
| 968 | |
| 969 | function delete_segments($segmentId): ResponseFactory|Response{ |
| 970 | |
| 971 | try { |
| 972 | |
| 973 | |
| 974 | $segmentId = addslashes((string) $segmentId); |
| 975 | |
| 976 | $budgets = TblQuotations::where('segment_id', $segmentId)->count(); |
| 977 | |
| 978 | if ($budgets > 0) { |
| 979 | return response([ |
| 980 | 'message' => 'KO', |
| 981 | 'error' => __('language.segments.delete_message.message1').' '.$budgets.' '.__('language.segments.delete_message.message2'), |
| 982 | ]); |
| 983 | } |
| 984 | |
| 985 | $segment = TblSegments::where('segment_id', $segmentId)->first(); |
| 986 | TblSegments::where('segment_id', $segmentId)->delete(); |
| 987 | |
| 988 | $this->segments(); |
| 989 | |
| 990 | return response([ |
| 991 | 'message' => 'OK', |
| 992 | 'data' => $this->segments, |
| 993 | ]); |
| 994 | |
| 995 | } catch (\Exception $e) { |
| 996 | report(AppException::fromException($e, 'DELETE_SEGMENTS_EXCEPTION')); |
| 997 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 998 | } |
| 999 | |
| 1000 | } |
| 1001 | |
| 1002 | function delete_reasons($reasonId): ResponseFactory|Response{ |
| 1003 | |
| 1004 | try { |
| 1005 | |
| 1006 | |
| 1007 | $reasonId = addslashes((string) $reasonId); |
| 1008 | |
| 1009 | $budgets = TblQuotations::where('reason_id', $reasonId)->count(); |
| 1010 | |
| 1011 | if ($budgets > 0) { |
| 1012 | return response([ |
| 1013 | 'message' => 'KO', |
| 1014 | 'error' => __('language.reasons.delete_message.message1').' '.$budgets.' '.__('language.reasons.delete_message.message2'), |
| 1015 | ]); |
| 1016 | } |
| 1017 | |
| 1018 | $reasons = TblReasons::where('reason_id', $reasonId)->first(); |
| 1019 | TblReasons::where('reason_id', $reasonId)->delete(); |
| 1020 | |
| 1021 | $this->reasons(); |
| 1022 | |
| 1023 | return response([ |
| 1024 | 'message' => 'OK', |
| 1025 | 'data' => $this->reasons, |
| 1026 | ]); |
| 1027 | |
| 1028 | } catch (\Exception $e) { |
| 1029 | report(AppException::fromException($e, 'DELETE_REASONS_EXCEPTION')); |
| 1030 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 1031 | } |
| 1032 | |
| 1033 | } |
| 1034 | |
| 1035 | function delete_budget_types($budgetTypeId): ResponseFactory|Response{ |
| 1036 | |
| 1037 | try { |
| 1038 | |
| 1039 | |
| 1040 | $budgetTypeId = addslashes((string) $budgetTypeId); |
| 1041 | |
| 1042 | $budgets = TblQuotations::where('budget_type_id', $budgetTypeId)->count(); |
| 1043 | |
| 1044 | if ($budgets > 0) { |
| 1045 | return response([ |
| 1046 | 'message' => 'KO', |
| 1047 | 'error' => __('language.budget_types.delete_message.message1').' '.$budgets.' '.__('language.budget_types.delete_message.message2'), |
| 1048 | ]); |
| 1049 | } |
| 1050 | |
| 1051 | $budgetType = TblBudgetTypes::where('budget_type_id', $budgetTypeId)->first(); |
| 1052 | TblBudgetTypes::where('budget_type_id', $budgetTypeId)->delete(); |
| 1053 | |
| 1054 | $this->budget_types(); |
| 1055 | |
| 1056 | return response([ |
| 1057 | 'message' => 'OK', |
| 1058 | 'data' => $this->budget_types, |
| 1059 | ]); |
| 1060 | |
| 1061 | } catch (\Exception $e) { |
| 1062 | report(AppException::fromException($e, 'DELETE_BUDGET_TYPES_EXCEPTION')); |
| 1063 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 1064 | } |
| 1065 | |
| 1066 | } |
| 1067 | |
| 1068 | function delete_budget_type_groups($budgetTypeGroupId): ResponseFactory|Response{ |
| 1069 | |
| 1070 | try { |
| 1071 | |
| 1072 | |
| 1073 | $budgetTypeGroupId = addslashes((string) $budgetTypeGroupId); |
| 1074 | |
| 1075 | $budgets = TblBudgetTypes::where('budget_type_group_id', $budgetTypeGroupId)->count(); |
| 1076 | |
| 1077 | if ($budgets > 0) { |
| 1078 | return response([ |
| 1079 | 'message' => 'KO', |
| 1080 | 'error' => __('language.budget_type_groups.delete_message.message1').' '.$budgets.' '.__('language.budget_type_groups.delete_message.message2'), |
| 1081 | ]); |
| 1082 | } |
| 1083 | |
| 1084 | $budgetTypeGroups = TblBudgetTypeGroups::where('budget_type_group_id', $budgetTypeGroupId)->first(); |
| 1085 | TblBudgetTypeGroups::where('budget_type_group_id', $budgetTypeGroupId)->delete(); |
| 1086 | |
| 1087 | $this->budget_type_groups(); |
| 1088 | |
| 1089 | return response([ |
| 1090 | 'message' => 'OK', |
| 1091 | 'data' => $this->budget_type_groups, |
| 1092 | ]); |
| 1093 | |
| 1094 | } catch (\Exception $e) { |
| 1095 | report(AppException::fromException($e, 'DELETE_BUDGET_TYPE_GROUPS_EXCEPTION')); |
| 1096 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 1097 | } |
| 1098 | |
| 1099 | } |
| 1100 | |
| 1101 | function delete_visit_types($visitTypeId): ResponseFactory|Response{ |
| 1102 | |
| 1103 | try { |
| 1104 | |
| 1105 | |
| 1106 | $visitTypeId = addslashes((string) $visitTypeId); |
| 1107 | |
| 1108 | $pipeline = TblPipelines::where('visit_type_id', $visitTypeId)->count(); |
| 1109 | |
| 1110 | if ($pipeline > 0) { |
| 1111 | return response([ |
| 1112 | 'message' => 'KO', |
| 1113 | 'error' => __('language.visit_types.delete_message.message1').' '.$pipeline.' '.__('language.visit_types.delete_message.message2'), |
| 1114 | ]); |
| 1115 | } |
| 1116 | |
| 1117 | $visitType = TblVisitTypes::where('visit_type_id', $visitTypeId)->first(); |
| 1118 | TblVisitTypes::where('visit_type_id', $visitTypeId)->delete(); |
| 1119 | |
| 1120 | $this->visit_types(); |
| 1121 | |
| 1122 | return response([ |
| 1123 | 'message' => 'OK', |
| 1124 | 'data' => $this->visit_types, |
| 1125 | ]); |
| 1126 | |
| 1127 | } catch (\Exception $e) { |
| 1128 | report(AppException::fromException($e, 'DELETE_VISIT_TYPES_EXCEPTION')); |
| 1129 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 1130 | } |
| 1131 | |
| 1132 | } |
| 1133 | |
| 1134 | function delete_visit_type_groups($visitTypeGroupId): ResponseFactory|Response{ |
| 1135 | |
| 1136 | try { |
| 1137 | |
| 1138 | |
| 1139 | $visitTypeGroupId = addslashes((string) $visitTypeGroupId); |
| 1140 | |
| 1141 | $visitType = TblVisitTypes::where('visit_type_group_id', $visitTypeGroupId)->count(); |
| 1142 | |
| 1143 | if ($visitType > 0) { |
| 1144 | return response([ |
| 1145 | 'message' => 'KO', |
| 1146 | 'error' => __('language.visit_type_groups.delete_message.message1').' '.$visitType.' '.__('language.visit_type_groups.delete_message.message2'), |
| 1147 | ]); |
| 1148 | } |
| 1149 | |
| 1150 | $visitTypeGroups = TblVisitTypeGroups::where('visit_type_group_id', $visitTypeGroupId)->first(); |
| 1151 | TblVisitTypeGroups::where('visit_type_group_id', $visitTypeGroupId)->delete(); |
| 1152 | |
| 1153 | $this->visit_type_groups(); |
| 1154 | |
| 1155 | return response([ |
| 1156 | 'message' => 'OK', |
| 1157 | 'data' => $this->visit_type_groups, |
| 1158 | ]); |
| 1159 | |
| 1160 | } catch (\Exception $e) { |
| 1161 | report(AppException::fromException($e, 'DELETE_VISIT_TYPE_GROUPS_EXCEPTION')); |
| 1162 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 1163 | } |
| 1164 | |
| 1165 | } |
| 1166 | |
| 1167 | function delete_budget_status($budgetStatusId): ResponseFactory|Response{ |
| 1168 | |
| 1169 | try { |
| 1170 | |
| 1171 | $budgetStatusId = addslashes((string) $budgetStatusId); |
| 1172 | |
| 1173 | $budgets = TblQuotations::where('budget_status_id', $budgetStatusId)->count(); |
| 1174 | |
| 1175 | if ($budgets > 0) { |
| 1176 | return response([ |
| 1177 | 'message' => 'KO', |
| 1178 | 'error' => __('language.budget_status.delete_message.message1').' '.$budgets.' '.__('language.budget_status.delete_message.message2'), |
| 1179 | ]); |
| 1180 | } |
| 1181 | |
| 1182 | $budgetStatus = TblBudgetStatus::where('budget_status_id', $budgetStatusId)->first(); |
| 1183 | TblBudgetStatus::where('budget_status_id', $budgetStatusId)->delete(); |
| 1184 | |
| 1185 | $this->budget_status(); |
| 1186 | |
| 1187 | return response([ |
| 1188 | 'message' => 'OK', |
| 1189 | 'data' => $this->budget_status, |
| 1190 | ]); |
| 1191 | |
| 1192 | } catch (\Exception $e) { |
| 1193 | report(AppException::fromException($e, 'DELETE_BUDGET_STATUS_EXCEPTION')); |
| 1194 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 1195 | } |
| 1196 | |
| 1197 | } |
| 1198 | |
| 1199 | function delete_source($sourceId): ResponseFactory|Response{ |
| 1200 | |
| 1201 | try { |
| 1202 | |
| 1203 | |
| 1204 | $sourceId = addslashes((string) $sourceId); |
| 1205 | |
| 1206 | $budgets = TblQuotations::where('source_id', $sourceId)->count(); |
| 1207 | |
| 1208 | if ($budgets > 0) { |
| 1209 | return response([ |
| 1210 | 'message' => 'KO', |
| 1211 | 'error' => __('language.source.delete_message.message1').' '.$budgets.' '.__('language.source.delete_message.message2'), |
| 1212 | ]); |
| 1213 | } |
| 1214 | |
| 1215 | $source = TblSources::where('source_id', $sourceId)->first(); |
| 1216 | TblSources::where('source_id', $sourceId)->delete(); |
| 1217 | |
| 1218 | $this->source(); |
| 1219 | |
| 1220 | return response([ |
| 1221 | 'message' => 'OK', |
| 1222 | 'data' => $this->source, |
| 1223 | ]); |
| 1224 | |
| 1225 | } catch (\Exception $e) { |
| 1226 | report(AppException::fromException($e, 'DELETE_SOURCE_EXCEPTION')); |
| 1227 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 1228 | } |
| 1229 | |
| 1230 | } |
| 1231 | |
| 1232 | function delete_reason_for_not_following_up($reasonForNotFollowingUpId): ResponseFactory|Response{ |
| 1233 | |
| 1234 | try { |
| 1235 | |
| 1236 | |
| 1237 | $reasonForNotFollowingUpId = addslashes((string) $reasonForNotFollowingUpId); |
| 1238 | |
| 1239 | $budgets = TblQuotations::where('reason_for_not_following_up_id', $reasonForNotFollowingUpId)->count(); |
| 1240 | |
| 1241 | if ($budgets > 0) { |
| 1242 | return response([ |
| 1243 | 'message' => 'KO', |
| 1244 | 'error' => __('language.source.delete_message.message1').' '.$budgets.' '.__('language.source.delete_message.message2'), |
| 1245 | ]); |
| 1246 | } |
| 1247 | |
| 1248 | $reasonForNotFollowingUp = TblReasonForNotFollowingUp::where('reason_for_not_following_up_id', $reasonForNotFollowingUpId)->first(); |
| 1249 | TblReasonForNotFollowingUp::where('reason_for_not_following_up_id', $reasonForNotFollowingUpId)->delete(); |
| 1250 | |
| 1251 | $this->reason_for_not_following_up(); |
| 1252 | |
| 1253 | return response([ |
| 1254 | 'message' => 'OK', |
| 1255 | 'data' => $this->reason_for_not_following_up, |
| 1256 | ]); |
| 1257 | |
| 1258 | } catch (\Exception $e) { |
| 1259 | report(AppException::fromException($e, 'DELETE_REASON_FOR_NOT_FOLLOWING_UP_EXCEPTION')); |
| 1260 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 1261 | } |
| 1262 | |
| 1263 | } |
| 1264 | |
| 1265 | function delete_reason_for_rejection($reasonForRejectionId): ResponseFactory|Response{ |
| 1266 | |
| 1267 | try { |
| 1268 | |
| 1269 | |
| 1270 | $reasonForRejectionId = addslashes((string) $reasonForRejectionId); |
| 1271 | |
| 1272 | $budgets = TblQuotations::where('reason_for_rejection_id', $reasonForRejectionId)->count(); |
| 1273 | |
| 1274 | if ($budgets > 0) { |
| 1275 | return response([ |
| 1276 | 'message' => 'KO', |
| 1277 | 'error' => __('language.source.delete_message.message1').' '.$budgets.' '.__('language.source.delete_message.message2'), |
| 1278 | ]); |
| 1279 | } |
| 1280 | |
| 1281 | $reasonForRejection = TblReasonForRejection::where('reason_for_rejection_id', $reasonForRejectionId)->first(); |
| 1282 | TblReasonForRejection::where('reason_for_rejection_id', $reasonForRejectionId)->delete(); |
| 1283 | |
| 1284 | $this->reason_for_rejection(); |
| 1285 | |
| 1286 | return response([ |
| 1287 | 'message' => 'OK', |
| 1288 | 'data' => $this->reason_for_rejection, |
| 1289 | ]); |
| 1290 | |
| 1291 | } catch (\Exception $e) { |
| 1292 | report(AppException::fromException($e, 'DELETE_REASON_FOR_REJECTION_EXCEPTION')); |
| 1293 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 1294 | } |
| 1295 | |
| 1296 | } |
| 1297 | |
| 1298 | function list_work_status(): ResponseFactory|Response{ |
| 1299 | |
| 1300 | try { |
| 1301 | |
| 1302 | $this->work_status(); |
| 1303 | |
| 1304 | return response([ |
| 1305 | 'message' => 'OK', |
| 1306 | 'data' => $this->work_status, |
| 1307 | ]); |
| 1308 | |
| 1309 | } catch (\Exception $e) { |
| 1310 | report(AppException::fromException($e, 'LIST_WORK_STATUS_EXCEPTION')); |
| 1311 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 1312 | } |
| 1313 | |
| 1314 | } |
| 1315 | |
| 1316 | |
| 1317 | function work_status(): void{ |
| 1318 | |
| 1319 | $this->work_status = TblWorkStatus::orderByRaw('ISNULL(priority), priority ASC')->get(); |
| 1320 | |
| 1321 | } |
| 1322 | |
| 1323 | |
| 1324 | function update_work_status(Request $request, $workStatusId): ResponseFactory|Response{ |
| 1325 | |
| 1326 | try { |
| 1327 | |
| 1328 | $data = $request->all(); |
| 1329 | $workStatusId = addslashes((string) $workStatusId); |
| 1330 | |
| 1331 | if(isset($data['data'])){ |
| 1332 | $priority = $data['data']; |
| 1333 | if (count($priority) > 0) { |
| 1334 | foreach ($priority as $item) { |
| 1335 | TblWorkStatus::where('work_status_id', $item['work_status_id'])->update(['priority' => $item['priority']]); |
| 1336 | } |
| 1337 | } |
| 1338 | } else { |
| 1339 | TblWorkStatus::where('work_status_id', $workStatusId)->update($data); |
| 1340 | } |
| 1341 | |
| 1342 | $this->work_status(); |
| 1343 | |
| 1344 | return response([ |
| 1345 | 'message' => 'OK', |
| 1346 | 'data' => $this->work_status, |
| 1347 | ]); |
| 1348 | |
| 1349 | } catch (\Exception $e) { |
| 1350 | report(AppException::fromException($e, 'UPDATE_WORK_STATUS_EXCEPTION')); |
| 1351 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 1352 | } |
| 1353 | |
| 1354 | } |
| 1355 | |
| 1356 | function delete_work_status($workStatusId): ResponseFactory|Response{ |
| 1357 | |
| 1358 | try { |
| 1359 | |
| 1360 | |
| 1361 | $workStatusId = addslashes((string) $workStatusId); |
| 1362 | |
| 1363 | $job = TblOngoingJobs::where('work_status_id', $workStatusId)->count(); |
| 1364 | |
| 1365 | if ($job > 0) { |
| 1366 | return response([ |
| 1367 | 'message' => 'KO', |
| 1368 | 'error' => __('language.work_status.delete_message.message1').' '.$job.' '.__('language.work_status.delete_message.message2'), |
| 1369 | ]); |
| 1370 | } |
| 1371 | |
| 1372 | $workStatus = TblWorkStatus::where('work_status_id', $workStatusId)->first(); |
| 1373 | TblWorkStatus::where('work_status_id', $workStatusId)->delete(); |
| 1374 | |
| 1375 | $this->work_status(); |
| 1376 | |
| 1377 | return response([ |
| 1378 | 'message' => 'OK', |
| 1379 | 'data' => $this->work_status, |
| 1380 | ]); |
| 1381 | |
| 1382 | } catch (\Exception $e) { |
| 1383 | report(AppException::fromException($e, 'DELETE_WORK_STATUS_EXCEPTION')); |
| 1384 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 1385 | } |
| 1386 | |
| 1387 | } |
| 1388 | |
| 1389 | function add_work_status(Request $request): ResponseFactory|Response{ |
| 1390 | |
| 1391 | try { |
| 1392 | |
| 1393 | $data = $request->all(); |
| 1394 | |
| 1395 | TblWorkStatus::create($data); |
| 1396 | |
| 1397 | $this->work_status(); |
| 1398 | |
| 1399 | return response([ |
| 1400 | 'message' => 'OK', |
| 1401 | 'data' => $this->work_status, |
| 1402 | ]); |
| 1403 | |
| 1404 | } catch (\Exception $e) { |
| 1405 | report(AppException::fromException($e, 'ADD_WORK_STATUS_EXCEPTION')); |
| 1406 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 1407 | } |
| 1408 | |
| 1409 | } |
| 1410 | } |