Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 50 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| VipClients | |
0.00% |
0 / 50 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| list_vip_clients | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| create_vip_client | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
6 | |||
| update_vip_client | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| delete_vip_client | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers; |
| 4 | |
| 5 | use App\Models\TblCompanies; |
| 6 | use App\Models\TblVipClients; |
| 7 | use Illuminate\Http\Request; |
| 8 | use Illuminate\Support\Facades\App; |
| 9 | |
| 10 | class VipClients extends Controller |
| 11 | { |
| 12 | public function __construct() |
| 13 | { |
| 14 | App::setLocale(@getallheaders()['Locale-ID']); |
| 15 | } |
| 16 | |
| 17 | public function list_vip_clients(Request $request) |
| 18 | { |
| 19 | |
| 20 | try { |
| 21 | $region = urldecode($request->header('Region')); |
| 22 | |
| 23 | $company = TblCompanies::where('region', $region)->first(); |
| 24 | |
| 25 | $data = TblVipClients::where('company_id', $company->company_id)->orderBy('id', 'desc')->get(); |
| 26 | |
| 27 | return response([ |
| 28 | 'message' => 'OK', |
| 29 | 'data' => $data, |
| 30 | ]); |
| 31 | |
| 32 | } catch (\Exception $e) { |
| 33 | /** @disregard P1014 */ |
| 34 | $e->exceptionCode = 'LIST_VIP_CLIENTS_EXCEPTION'; |
| 35 | report($e); |
| 36 | |
| 37 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 38 | } |
| 39 | |
| 40 | } |
| 41 | |
| 42 | public function create_vip_client(Request $request) |
| 43 | { |
| 44 | |
| 45 | try { |
| 46 | |
| 47 | $data = $request->all(); |
| 48 | $region = urldecode(@getallheaders()['Region']); |
| 49 | |
| 50 | $company = TblCompanies::where('region', $region)->first(); |
| 51 | |
| 52 | $vipClient = TblVipClients::create([ |
| 53 | 'id_client' => $data['id_client'] ?? null, |
| 54 | 'company_id' => $company->company_id, |
| 55 | 'name' => $data['name'], |
| 56 | 'cif' => $data['cif'] ?? null, |
| 57 | 'email' => $data['email'] ?? null, |
| 58 | 'phone' => $data['phone'] ?? null, |
| 59 | ]); |
| 60 | |
| 61 | return response([ |
| 62 | 'message' => 'OK', |
| 63 | 'data' => $vipClient, |
| 64 | ]); |
| 65 | |
| 66 | } catch (\Exception $e) { |
| 67 | /** @disregard P1014 */ |
| 68 | $e->exceptionCode = 'CREATE_VIP_CLIENT_EXCEPTION'; |
| 69 | report($e); |
| 70 | |
| 71 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 72 | } |
| 73 | |
| 74 | } |
| 75 | |
| 76 | public function update_vip_client(Request $request, $id) |
| 77 | { |
| 78 | |
| 79 | try { |
| 80 | |
| 81 | $data = $request->all(); |
| 82 | |
| 83 | $region = urldecode(@getallheaders()['Region']); |
| 84 | |
| 85 | $company = TblCompanies::where('region', $region)->first(); |
| 86 | |
| 87 | TblVipClients::where('id', $id)->where('company_id', $company->company_id)->update($data); |
| 88 | |
| 89 | return response([ |
| 90 | 'message' => 'OK', |
| 91 | ]); |
| 92 | |
| 93 | } catch (\Exception $e) { |
| 94 | /** @disregard P1014 */ |
| 95 | $e->exceptionCode = 'UPDATE_VIP_CLIENT_EXCEPTION'; |
| 96 | report($e); |
| 97 | |
| 98 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 99 | } |
| 100 | |
| 101 | } |
| 102 | |
| 103 | public function delete_vip_client($id) |
| 104 | { |
| 105 | |
| 106 | try { |
| 107 | TblVipClients::where('id', $id)->delete(); |
| 108 | |
| 109 | return response([ |
| 110 | 'message' => 'OK', |
| 111 | ]); |
| 112 | |
| 113 | } catch (\Exception $e) { |
| 114 | /** @disregard P1014 */ |
| 115 | $e->exceptionCode = 'DELETE_VIP_CLIENT_EXCEPTION'; |
| 116 | report($e); |
| 117 | |
| 118 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 119 | } |
| 120 | |
| 121 | } |
| 122 | } |