Update clients module
This commit is contained in:
miroman-afk
2022-01-13 01:22:59 +03:00
parent 51a27b005e
commit def1ac1986

View File

@@ -22,10 +22,12 @@ class POSTClient extends HRCCommand implements HRCCommandInterface {
$client->name = urldecode($input['name']); $client->name = urldecode($input['name']);
$client->unloaded = 0; $client->unloaded = 0;
$clientGroup = ClientsGroup::where('id', $input['group_id'])->first(); $clientGroup = ClientsGroup::find($input['group_id']);
$client->group_id = urldecode($clientGroup->code); $client->group_id = urldecode($clientGroup['code']);
$clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first(); $clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first();
if ($clientPhone) {
$clientPhone = ClientsPhone::find($clientPhone['id']);
if ($input['phone'] !== '') { if ($input['phone'] !== '') {
if (substr($input['phone'], 0, 1) == '+') { if (substr($input['phone'], 0, 1) == '+') {
$phoneData = urldecode($input['phone']); $phoneData = urldecode($input['phone']);
@@ -34,24 +36,47 @@ class POSTClient extends HRCCommand implements HRCCommandInterface {
$clientPhone->phone = '+375 (' . substr($phoneData, 0, 2) . ') ' . substr($phoneData, 2, 3) . '-' . substr($phoneData, 5, 2) . '-' . substr($phoneData, 7, 2); $clientPhone->phone = '+375 (' . substr($phoneData, 0, 2) . ') ' . substr($phoneData, 2, 3) . '-' . substr($phoneData, 5, 2) . '-' . substr($phoneData, 7, 2);
} }
} else { } else {
$clientPhone->phone = ''; $clientPhone->phone = '+375 ( ) - -';
}
$clientPhone->save();
} }
$clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first(); $clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first();
if ($clientEmail) {
$clientEmail = ClientsEmail::find($clientEmail['id']);
if ($input['email'] !== '') {
$clientEmail->email = urldecode($input['email']); $clientEmail->email = urldecode($input['email']);
} else {
$clientEmail->email = '';
}
$clientEmail->save();
}
$clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first(); $clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first();
if ($clientAddress) {
$clientAddress = ClientsAddress::find($clientAddress['id']);
if ($input['address'] !== '') {
$clientAddress->address = urldecode($input['address']); $clientAddress->address = urldecode($input['address']);
} else {
$clientAddress->address = '';
}
$clientAddress->save();
}
$clientBarcode = ClientsBarcode::where('client_guid', $client->user_code)->first(); $clientBarcode = ClientsBarcode::where('client_guid', $client->user_code)->first();
if ($clientBarcode) {
$clientBarcode = ClientsBarcode::find($clientBarcode['id']);
if ($input['barcode'] !== '') {
$clientBarcode->code_id = urldecode($input['barcode']); $clientBarcode->code_id = urldecode($input['barcode']);
} else {
$clientBarcode->code_id = '';
}
$clientBarcode->save();
}
$client->save(); $client->save();
$clientGroup->save(); $clientGroup->save();
$clientPhone->save();
$clientEmail->save();
$clientAddress->save();
$clientBarcode->save();
return [ return [
'status' => 'success', 'status' => 'success',
'client' => $client, 'client' => $client,
@@ -64,16 +89,31 @@ class POSTClient extends HRCCommand implements HRCCommandInterface {
} }
if ($input['task'] == 'delete') { if ($input['task'] == 'delete') {
$client = Client::where('id', '=', $input['id'])->first(); $client = Client::find($input['id']);
$clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first(); $clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first();
$clientPhone = ClientsPhone::find($clientPhone['id']);
$clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first(); $clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first();
$clientEmail = ClientsEmail::find($clientEmail['id']);
$clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first(); $clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first();
$clientAddress = ClientsAddress::find($clientAddress['id']);
$clientBarcode = ClientsBarcode::where('client_guid', $client->user_code)->first(); $clientBarcode = ClientsBarcode::where('client_guid', $client->user_code)->first();
$clientBarcode = ClientsBarcode::find($clientBarcode['id']);
if ($clientPhone) {
$clientPhone->delete(); $clientPhone->delete();
}
if ($clientEmail) {
$clientEmail->delete(); $clientEmail->delete();
}
if ($clientAddress) {
$clientAddress->delete(); $clientAddress->delete();
}
if ($clientBarcode) {
$clientBarcode->delete(); $clientBarcode->delete();
}
if ($client) {
$client->delete(); $client->delete();
}
return [ return [
'status' => 'success', 'status' => 'success',
'message' => 'Клиент удален', 'message' => 'Клиент удален',