Fixed reports
This commit is contained in:
miroman-afk
2023-05-02 15:21:54 +03:00
parent 70120653f7
commit fb46c8e739
78 changed files with 21233 additions and 1892 deletions

View File

@@ -12,119 +12,295 @@ use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
use Illuminate\Support\Facades\Log;
class POSTClient extends HRCCommand implements HRCCommandInterface {
protected $signature = 'postclient';
class POSTClient extends HRCCommand implements HRCCommandInterface
{
protected $signature = 'postclient';
public function command($input, $output = null) {
public function command($input, $output = null)
{
if (isset($input['task']) && isset($input['id'])) {
if ($input['task'] == 'update') {
$phone = urldecode($input['phone']);
$client = Client::find($input['id']);
$client->name = urldecode($input['name']);
$client->unloaded = 0;
$clientGroup = ClientsGroup::where('id', $input['group_id'])->first();
$client->group_id = urldecode($clientGroup['code']);
$clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first();
if ($clientPhone) {
$clientPhone = ClientsPhone::find($clientPhone['id']);
if ($phone !== '' && $phone !== '+375 ( ) - -') {
if (substr($phone, 0, 1) == '+') {
$phoneData = urldecode($input['phone']);
} else {
$phoneData = urldecode($input['phone']);
$clientPhone->phone = '+375 (' . substr($phoneData, 0, 2) . ') ' . substr($phoneData, 2, 3) . '-' . substr($phoneData, 5, 2) . '-' . substr($phoneData, 7, 2);
}
} else {
$clientPhone->phone = '+375 ( ) - -';
}
$clientPhone->save();
}
if (isset($input['task'])) {
if ($input['task'] == 'update') {
log::debug($input);
if (isset($input['id'])) {
$id = $input['id'];
} else if (isset($input['client_guid'])) {
$fClient = Client::where('user_code', $input['client_guid'])->first();
if (!isset($fClient)) {
return [
'status' => 'success',
'error_message' => 'Клиент не найден',
];
}
$id = $fClient['id'];
} else {
return [
'status' => 'success',
'error_message' => 'Проверьте введенные данные',
];
}
if (isset($input['group_id']) && !isset($input['group_guid'])) {
$group_id = $input['group_id'];
} else if (isset($input['group_guid']) && !isset($input['group_id'])) {
$fGroup = ClientsGroup::where('code', $input['group_guid'])->first();
if (!isset($fGroup)) {
return [
'status' => 'success',
'error_message' => 'Группа не найдена',
];
}
$group_id = $fGroup['id'];
} else if (isset($input['group_id']) && isset($input['group_guid'])) {
$fGroup = ClientsGroup::where('code', $input['group_guid'])->first();
if (!isset($fGroup)) {
$fGroup = ClientsGroup::where('id', isset($input['group_id']))->first();
if (!isset($fGroup)) {
return [
'status' => 'success',
'error_message' => 'Группа не найдена',
];
}
}
$group_id = $fGroup['id'];
} else {
return [
'status' => 'success',
'error_message' => 'Проверьте введенные данные',
];
}
$client = Client::find($id);
$client->name = urldecode($input['name']);
$client->unloaded = 0;
$clientGroup = ClientsGroup::where('id', $group_id)->first();
$client->group_id = $clientGroup['code'];
$clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first();
if ($clientEmail) {
$clientEmail = ClientsEmail::find($clientEmail['id']);
if ($input['email'] !== '') {
$clientEmail->email = urldecode($input['email']);
} else {
$clientEmail->email = '';
}
$clientEmail->save();
}
if (isset($input['phone'])) {
$phone = $input['phone'];
Log::debug($phone);
$clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first();
Log::debug($clientPhone);
if (isset($clientPhone)) {
$clientPhone = ClientsPhone::find($clientPhone['id']);
if ($phone !== '' && $phone !== '+375 ( ) - -') {
if (substr($phone, 0, 1) == '+') {
$clientPhone->phone = '+375 (' . substr($phone, 4, 2) . ') ' . substr($phone, 6, 3) . '-' . substr($phone, 9, 2) . '-' . substr($phone, 11, 2);
log::debug('UPD Substr true: ' . $phone);
} else {
log::debug('UPD Substr false: ' . $phone);
$clientPhone->phone = '+375 (' . substr($phone, 0, 2) . ') ' . substr($phone, 2, 3) . '-' . substr($phone, 5, 2) . '-' . substr($phone, 7, 2);
}
} else {
$clientPhone->phone = '+375 ( ) - -';
}
} else {
$clientPhone = new ClientsPhone;
if ($phone !== '' && $phone !== '+375 ( ) - -') {
if (substr($phone, 0, 1) == '+') {
$clientPhone->phone = '+375 (' . substr($phone, 4, 2) . ') ' . substr($phone, 6, 3) . '-' . substr($phone, 9, 2) . '-' . substr($phone, 11, 2);
log::debug('CR Substr true: ' . $phone);
} else {
log::debug('CR Substr false: ' . $phone);
$clientPhone->phone = '+375 (' . substr($phone, 0, 2) . ') ' . substr($phone, 2, 3) . '-' . substr($phone, 5, 2) . '-' . substr($phone, 7, 2);
}
} else {
$clientPhone->phone = '+375 ( ) - -';
}
}
$clientPhone->client_guid = $client->user_code;
$clientPhone->save();
}
$clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first();
if ($clientAddress) {
$clientAddress = ClientsAddress::find($clientAddress['id']);
if ($input['address'] !== '') {
$clientAddress->address = urldecode($input['address']);
} else {
$clientAddress->address = '';
}
$clientAddress->save();
}
if (isset($input['email'])) {
$clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first();
if ($clientEmail) {
$clientEmail = ClientsEmail::find($clientEmail['id']);
if (isset($input['email']) && $input['email'] !== '') {
$clientEmail->email = urldecode($input['email']);
} else {
$clientEmail->email = '';
}
} else {
$clientEmail = new ClientsEmail;
$clientEmail->email = urldecode($input['email']);
}
$clientEmail->client_guid = $client->user_code;
$clientEmail->save();
} else {
$clientEmail = '';
}
$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']);
} else {
$clientBarcode->code_id = '';
}
$clientBarcode->save();
}
if (isset($input['address'])) {
$clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first();
if ($clientAddress) {
$clientAddress = ClientsAddress::find($clientAddress['id']);
if ($input['address'] !== '') {
$clientAddress->address = urldecode($input['address']);
} else {
$clientAddress->address = '';
}
} else {
$clientAddress = new ClientsAddress;
$clientAddress->address = urldecode($input['address']);
}
$clientAddress->client_guid = $client->user_code;
$clientAddress->save();
}
$clientBarcodeStart = 0;
$clientBarcodeEnd = 0;
if (isset($input['barcode'])) {
if ($input['barcode'] !== '') {
$client->barcode_type = 2;
$client->barcode_start = $clientBarcodeStart = urldecode($input['barcode']);
$client->barcode_end = $clientBarcodeEnd = urldecode($input['barcode']);
} else {
$client->barcode_type = 1;
$client->barcode_start = $clientBarcodeStart;
$client->barcode_end = $clientBarcodeEnd;
}
}
if (isset($input['is_special_price']) && $input['is_special_price'] == 'true') {
$specialPrice = 1;
} else {
$specialPrice = 0;
}
if (isset($input['is_employee']) && $input['is_employee'] == 'true') {
$employee = 1;
} else {
$employee = 0;
}
$client->is_special_price = $specialPrice;
$client->is_employee = $employee;
$client->save();
return [
'status' => 'success',
'client' => $client,
'phone' => $clientPhone,
'email' => $clientEmail,
'address' => $clientAddress,
'barcode' => $clientBarcode,
'message' => 'Клиент обновлен',
];
}
return [
'status' => 'success',
'client' => $client,
'phone' => $clientPhone,
'email' => $clientEmail,
'address' => $clientAddress,
'barcode' => $clientBarcodeStart,
'message' => 'Клиент обновлен',
];
}
if ($input['task'] == 'delete') {
$client = Client::find($input['id']);
$clientGroup = ClientsGroup::where('code', $client->group_id)->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::find($clientEmail['id']);
$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::find($clientBarcode['id']);
if ($clientPhone) {
$clientPhone->delete();
}
if ($clientEmail) {
$clientEmail->delete();
}
if ($clientAddress) {
$clientAddress->delete();
}
if ($clientBarcode) {
$clientBarcode->delete();
}
if ($client) {
$client->delete();
}
if ($input['task'] == 'delete') {
$client = Client::find($input['id']);
$clientGroup = ClientsGroup::where('code', $client->group_id)->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::find($clientEmail['id']);
$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::find($clientBarcode['id']);
if ($clientPhone) {
$clientPhone->delete();
}
if ($clientEmail) {
$clientEmail->delete();
}
if ($clientAddress) {
$clientAddress->delete();
}
if ($clientBarcode) {
$clientBarcode->delete();
}
if ($client) {
$client->delete();
}
return [
'status' => 'success',
'message' => 'Клиент удален',
'currentGroup' => $clientGroup['id'],
];
}
} else {
return [
'status' => 'success',
'error_message' => 'Проверьте введенные данные',
];
}
}
return [
'status' => 'success',
'message' => 'Клиент удален',
'currentGroup' => $clientGroup['id'],
];
}
if ($input['task'] == 'lock') {
if (isset($input['id'])) {
$id = $input['id'];
} else if (isset($input['client_guid'])) {
$fClient = Client::where('user_code', $input['client_guid'])->first();
if (!isset($fClient)) {
return [
'status' => 'success',
'error_message' => 'Клиент не найден',
];
}
$id = $fClient['id'];
} else {
return [
'status' => 'success',
'error_message' => 'Проверьте введенные данные',
];
}
$client = Client::find($id);
$clientGroup = ClientsGroup::where('code', $client->group_id)->first();
$client->is_block = 1;
$client->save();
return [
'status' => 'success',
'message' => 'Клиент заблокирован',
'currentGroup' => $clientGroup['id'],
];
}
if ($input['task'] == 'unlock') {
if (isset($input['id'])) {
$id = $input['id'];
} else if (isset($input['client_guid'])) {
$fClient = Client::where('user_code', $input['client_guid'])->first();
if (!isset($fClient)) {
return [
'status' => 'success',
'error_message' => 'Клиент не найден',
];
}
$id = $fClient['id'];
} else {
return [
'status' => 'success',
'error_message' => 'Проверьте введенные данные',
];
}
$client = Client::find($id);
$clientGroup = ClientsGroup::where('code', $client->group_id)->first();
$client->is_block = 0;
$client->save();
return [
'status' => 'success',
'message' => 'Клиент разблокирован',
'currentGroup' => $clientGroup['id'],
];
}
if ($input['task'] == 'search' && isset($input['name'])) {
$client = Client::where('name', 'like', '%' . urldecode($input['name']) . '%')->get();
if (count($client) > 0) {
$message = 'Клиенты найдены!';
} else {
$message = 'Клиенты с именем ' . urldecode($input['name']) . ' не найдены!';
}
return [
'status' => 'success',
'message' => $message,
'clients' => $client
];
}
} else {
return [
'status' => 'success',
'error_message' => 'Проверьте введенные данные',
];
}
}
}