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