Files
admin-php-module/commands/GETClients.php
miroman-afk fb46c8e739 v.2.27
Fixed reports
2023-05-02 15:21:54 +03:00

86 lines
2.9 KiB
PHP

<?php
namespace App\Commands;
use App\Component\Models\Client;
use App\Component\Models\ClientsGroup;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
class GETClients extends HRCCommand implements HRCCommandInterface
{
protected $signature = 'getclients';
public function command($input, $output = null)
{
if (ClientsGroup::where('code', '0')->count() == 0) {
$group = new ClientsGroup([
'code' => '0',
'name' => 'Без группы',
]);
$group->save();
}
$countPerPage = 25;
$offset = ($input['page'] - 1) * $countPerPage;
if ($input['group_id'] == 0) {
$group = ClientsGroup::where('code', '=', $input['group_id'])->first();
} else {
$group = ClientsGroup::where('id', '=', $input['group_id'])->first();
}
$clients = Client::where('group_id', '=', $group['code'])->skip($offset)->take($countPerPage)->get();
$total = Client::where('group_id', '=', $group['code'])->count();
if ($total == NULL) {
return [
'status' => 'success',
'clients' => array(),
'total' => 0,
'size' => $countPerPage,
'pages' => 1,
'currentGroup' => $group['id'],
];
} else {
foreach ($clients as $client) {
$phone = Client::getPhone($client['user_code']);
$email = Client::getEmail($client['user_code']);
$address = Client::getAddress($client['user_code']);
$barcode = Client::getBarcode($client['user_code']);
if ($client['is_special_price'] == 0) {
$special_price = false;
} else {
$special_price = true;
}
if ($client['is_employee'] == 0) {
$employee = false;
} else {
$employee = true;
}
if ($client['is_block'] == 0) {
$is_block = false;
} else {
$is_block = true;
}
$out[] = array(
'id' => $client['id'],
'name' => $client['name'],
'phone' => $phone,
'email' => $email,
'address' => $address,
'barcode' => $barcode,
'special_price' => $special_price,
'employee' => $employee,
'is_block' => $is_block,
);
}
return [
'status' => 'success',
'clients' => $out,
'total' => $total,
'size' => $countPerPage,
'pages' => ceil($total / $countPerPage),
'currentGroup' => $group['id'],
];
}
}
}