Обновление отчета по персоналу
This commit is contained in:
miroman-afk
2022-06-14 12:22:42 +03:00
parent ebd1180d89
commit 7fdcbcc9e8
8 changed files with 403 additions and 76 deletions

View File

@@ -3,6 +3,9 @@
namespace App\Commands;
use App\Component\Models\ExchangeActions;
use App\Component\Models\ExchangeDeleted;
use App\Component\Models\ExchangeOrders;
use App\Component\Models\ExchangeShifts;
use App\Component\Models\Staff;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
@@ -81,9 +84,8 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface {
}
$reportType = $input['type'];
$shiftNumber = $input['shift_id'];
//merge, slice, move
if (isset($reportType) && isset($shiftNumber)) {
if (isset($reportType)) {
//merge
if ($reportType == 'merge') {
$merged_order_items = [];
@@ -208,6 +210,276 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface {
'data' => $moved_order_data,
];
}
if ($reportType == 'staff') {
if (isset($input['shift_id'])) {
$staff = $staff_data = [];
$countOpened = $countClosed = $sumOpened = $sumClosed = $inputCount = $inputSum = $outputCount = $outputSum = $annulCount = $annulSum = $returnCount = $returnSum = $deletedCount = $deletedSum = 0;
$openedOrders = ExchangeOrders::select('who_open')
->where('shift_id', $input['shift_id'])
->where('who_open', '>', 0)
->groupBy('who_open')
->get();
$closedOrders = ExchangeOrders::select('who_close')
->where('shift_id', $input['shift_id'])
->where('who_close', '>', 0)
->groupBy('who_close')
->get();
foreach ($openedOrders as $key => $openedOrder) {
array_push($staff, $openedOrder['who_open']);
}
foreach ($closedOrders as $key => $closedOrder) {
array_push($staff, $closedOrder['who_close']);
}
$staff = array_unique($staff);
foreach ($staff as $key => $value) {
$staffId = $value + 0;
$name = staffName($staffId);
$code = $staffId;
$countOpened = ExchangeOrders::where('who_open', $staffId)
->where('shift_id', $input['shift_id'])
->where('is_deleted', 0)
->where('is_returned', 0)
->where('order_sum', '>', 0)
->count();
$countClosed = ExchangeOrders::where('who_close', $staffId)
->where('shift_id', $input['shift_id'])
->where('is_deleted', 0)
->where('is_returned', 0)
->where('order_sum', '>', 0)
->count();
$sumOpened = ExchangeOrders::where('who_open', $staffId)
->where('shift_id', $input['shift_id'])
->where('is_deleted', 0)
->where('is_returned', 0)
->where('order_sum', '>', 0)
->sum('order_sum');
$sumClosed = ExchangeOrders::where('who_close', $staffId)
->where('shift_id', $input['shift_id'])
->where('is_deleted', 0)
->where('is_returned', 0)
->where('order_sum', '>', 0)
->sum('order_sum');
$inputCount = ExchangeActions::where('who', $staffId)
->where('shift_id', $input['shift_id'])
->where('action_type', 49)
->count();
$inputSum = ExchangeActions::where('who', $staffId)
->where('shift_id', $input['shift_id'])
->where('action_type', 49)
->sum('value');
$outputCount = ExchangeActions::where('who', $staffId)
->where('shift_id', $input['shift_id'])
->where('action_type', 50)
->count();
$outputSum = ExchangeActions::where('who', $staffId)
->where('shift_id', $input['shift_id'])
->where('action_type', 50)
->sum('value');
$annulCount = ExchangeActions::where('who', $staffId)
->where('shift_id', $input['shift_id'])
->where('action_type', 43)
->count();
$annulOrders = ExchangeActions::where('who', $staffId)
->where('shift_id', $input['shift_id'])
->where('action_type', 43)
->get();
foreach ($annulOrders as $key => $annulOrder) {
$annulOrderSum = ExchangeOrders::where('code', $annulOrder['order_code'])
->where('shift_id', $input['shift_id'])
->first();
$annulSum = $annulSum + $annulOrderSum['order_sum'];
}
$returnCount = ExchangeActions::where('who', $staffId)
->where('shift_id', $input['shift_id'])
->where('action_type', 19)
->count();
$returnOrders = ExchangeActions::where('who', $staffId)
->where('shift_id', $input['shift_id'])
->where('action_type', 19)
->get();
foreach ($returnOrders as $key => $returnOrder) {
$returnOrderSum = ExchangeOrders::where('code', $returnOrder['order_code'])
->where('shift_id', $input['shift_id'])
->first();
$returnSum = $returnSum + abs($returnOrderSum['order_sum']);
}
$deletedCount = ExchangeActions::where('who', $staffId)
->where('shift_id', $input['shift_id'])
->where('action_type', 8)
->where('reason', '>', 0)
->count();
$deletedOrders = ExchangeActions::where('who', $staffId)
->where('shift_id', $input['shift_id'])
->where('action_type', 8)
->where('reason', '>', 0)
->get();
foreach ($deletedOrders as $key => $deletedOrder) {
$deletedOrdersSum = ExchangeDeleted::where('order_code', $deletedOrder['order_code'])
->where('shift_id', $input['shift_id'])
->sum('sale_price');
$deletedSum = $deletedSum + $deletedOrdersSum;
}
$staff_data[] = array(
'name' => $name,
'code' => $code + 0,
'opened_count' => $countOpened + 0,
'closed_count' => $countClosed,
'opened_sum' => $sumOpened + 0,
'closed_sum' => $sumClosed + 0,
'input_count' => $inputCount,
'output_count' => $outputCount,
'input_sum' => $inputSum,
'output_sum' => $outputSum,
'annul_count' => $annulCount,
'annul_sum' => $annulSum,
'return_count' => $returnCount,
'return_sum' => round($returnSum, 2),
'deleted_count' => $deletedCount,
'deleted_sum' => $deletedSum);
}
return [
'status' => 'success',
'staffs' => $staff_data,
];
}
if (isset($input['start_date']) && isset($input['end_date'])) {
$staff = $staff_data = $shifts = [];
$countOpened = $countClosed = $sumOpened = $sumClosed = $inputCount = $inputSum = $outputCount = $outputSum = $annulCount = $annulSum = $returnCount = $returnSum = $deletedCount = $deletedSum = 0;
$end_date = date('Y-m-d H:i:s', strtotime($input['end_date']));
$start_date = date('Y-m-d H:i:s', strtotime($input['start_date']));
$shiftIds = ExchangeShifts::where('opened', '>', $start_date)
->where('opened', '<', $end_date)
->get();
foreach ($shiftIds as $key => $shiftId) {
array_push($shifts, $shiftId['id']);
}
$openedOrders = ExchangeOrders::select('who_open')
->whereIn('shift_id', $shifts)
->where('who_open', '>', 0)
->groupBy('who_open')
->get();
$closedOrders = ExchangeOrders::select('who_close')
->whereIn('shift_id', $shifts)
->where('who_close', '>', 0)
->groupBy('who_close')
->get();
foreach ($openedOrders as $key => $openedOrder) {
array_push($staff, $openedOrder['who_open']);
}
foreach ($closedOrders as $key => $closedOrder) {
array_push($staff, $closedOrder['who_close']);
}
$staff = array_unique($staff);
foreach ($staff as $key => $value) {
$staffId = $value + 0;
$name = staffName($staffId);
$code = $staffId;
$countOpened = ExchangeOrders::where('who_open', $staffId)
->whereIn('shift_id', $shifts)
->where('is_deleted', 0)
->where('is_returned', 0)
->where('order_sum', '>', 0)
->count();
$countClosed = ExchangeOrders::where('who_close', $staffId)
->whereIn('shift_id', $shifts)
->where('is_deleted', 0)
->where('is_returned', 0)
->where('order_sum', '>', 0)
->count();
$sumOpened = ExchangeOrders::where('who_open', $staffId)
->whereIn('shift_id', $shifts)
->where('is_deleted', 0)
->where('is_returned', 0)
->where('order_sum', '>', 0)
->sum('order_sum');
$sumClosed = ExchangeOrders::where('who_close', $staffId)
->whereIn('shift_id', $shifts)
->where('is_deleted', 0)
->where('is_returned', 0)
->where('order_sum', '>', 0)
->sum('order_sum');
$inputCount = ExchangeActions::where('who', $staffId)
->whereIn('shift_id', $shifts)
->where('action_type', 49)
->count();
$inputSum = ExchangeActions::where('who', $staffId)
->whereIn('shift_id', $shifts)
->where('action_type', 49)
->sum('value');
$outputCount = ExchangeActions::where('who', $staffId)
->whereIn('shift_id', $shifts)
->where('action_type', 50)
->count();
$outputSum = ExchangeActions::where('who', $staffId)
->whereIn('shift_id', $shifts)
->where('action_type', 50)
->sum('value');
$annulCount = ExchangeActions::where('who', $staffId)
->whereIn('shift_id', $shifts)
->where('action_type', 43)
->count();
$annulOrders = ExchangeActions::where('who', $staffId)
->whereIn('shift_id', $shifts)
->where('action_type', 43)
->get();
foreach ($annulOrders as $key => $annulOrder) {
$annulSum = $annulSum + ExchangeOrders::where('code', $annulOrder['order_code'])
->whereIn('shift_id', $shifts)
->sum('order_sum');
}
$returnCount = ExchangeActions::where('who', $staffId)
->whereIn('shift_id', $shifts)
->where('action_type', 19)
->count();
$returnOrders = ExchangeActions::where('who', $staffId)
->whereIn('shift_id', $shifts)
->where('action_type', 19)
->get();
foreach ($returnOrders as $key => $returnOrder) {
$returnSum = $returnSum + abs(ExchangeOrders::where('code', $returnOrder['order_code'])
->whereIn('shift_id', $shifts)
->sum('order_sum'));
}
$deletedCount = ExchangeActions::where('who', $staffId)
->whereIn('shift_id', $shifts)
->where('action_type', 8)
->where('reason', '>', 0)
->count();
$deletedOrders = ExchangeActions::where('who', $staffId)
->whereIn('shift_id', $shifts)
->where('action_type', 8)
->where('reason', '>', 0)
->get();
foreach ($deletedOrders as $key => $deletedOrder) {
$deletedSum = $deletedSum + ExchangeDeleted::where('order_code', $deletedOrder['order_code'])
->whereIn('shift_id', $shifts)
->sum('sale_price');
}
$staff_data[] = array(
'name' => $name,
'code' => $code + 0,
'opened_count' => $countOpened + 0,
'closed_count' => $countClosed,
'opened_sum' => $sumOpened + 0,
'closed_sum' => $sumClosed + 0,
'input_count' => $inputCount,
'output_count' => $outputCount,
'input_sum' => $inputSum,
'output_sum' => $outputSum,
'annul_count' => $annulCount,
'annul_sum' => $annulSum,
'return_count' => $returnCount,
'return_sum' => round($returnSum, 2),
'deleted_count' => $deletedCount,
'deleted_sum' => $deletedSum);
}
return [
'status' => 'success',
'staffs' => $staff_data,
];
}
}
} else {
return [
'status' => 'success',

View File

@@ -0,0 +1,96 @@
<?php
namespace App\Commands;
use App\Component\Models\Dishes;
use App\Component\Models\ShiftOnlineItems;
use App\Component\Models\ShiftOnlineOrders;
use App\Component\Models\Staff;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
class GETOnlineStaff extends HRCCommand implements HRCCommandInterface {
protected $signature = 'getonlinestaff';
public function command($input, $output = null) {
function staffName($data) {
$staff_name = Staff::where('code', $data)->where('is_history', 0)->first();
if ($staff_name) {
$staff_name = $staff_name['name'];
} else {
$staff_name = Staff::where('code', $data)->where('is_history', 1)->first();
if ($staff_name) {
$staff_name = $staff_name['name'];
} else {
$staff_name = 'Связанный персонал не найден';
}
}
return $staff_name;
}
if ($input['method'] == 'dashboard') {
$staff_data = [];
$staffs = ShiftOnlineOrders::select('who_open')
->where('is_deleted', 0)
->where('is_returned', 0)
->where('order_sum', '>', 0)
->groupBy('who_open')
->get();
foreach ($staffs as $key => $staff) {
$count = ShiftOnlineOrders::where('who_open', $staff['who_open'])
->where('is_deleted', 0)
->where('is_returned', 0)
->where('order_sum', '>', 0)
->count();
$name = staffName($staff['who_open']);
$code = $staff['who_open'];
$sum = ShiftOnlineOrders::where('who_open', $staff['who_open'])
->where('is_deleted', 0)
->where('is_returned', 0)
->where('order_sum', '>', 0)
->sum('order_sum');
$staff_data[] = array('name' => $name, 'code' => $code + 0, 'orders_count' => $count + 0, 'orders_sum' => $sum + 0);
}
return [
'status' => 'success',
'staff' => $staff_data,
];
}
if ($input['method'] == 'items') {
if (isset($input['order'])) {
$orderId = $input['order'] + 0;
$items = [];
$order = ShiftOnlineOrders::where('code', $orderId)->first();
$who_open = staffName($order['who_open']);
$who_close = staffName($order['who_close']);
$onlineItems = ShiftOnlineItems::where('order_code', $order['code'])->where('modificator_code', 0)->get();
foreach ($onlineItems as $key => $item) {
$realPrice = $item['real_price'] * $item['count'] * $item['cof'];
$salePrice = $item['sale_price'] * $item['count'];
if ($realPrice > 0) {
$discount = $salePrice / $realPrice;
$discount = (1 - $discount) * 100;
} else {
$discount = 0;
}
$dish = Dishes::where('code', $item['dish_code'])->where('is_history', 0)->first();
$items[] = array('name' => $dish['name'], 'discount' => round($discount, 0), 'count' => $item['count'], 'sale_price' => $salePrice, 'sum' => round($realPrice, 2));
}
} else {
return [
'status' => 'success',
'message' => 'Проверьте введенные данные',
];
}
return [
'status' => 'success',
'who_open' => $who_open,
'who_close' => $who_close,
'title' => 'Подробнее о заказе №' . $order['code'],
'total' => $order['order_sum'],
'items' => $items,
];
}
}
}

View File

@@ -323,7 +323,7 @@
$scope.total = data.total;
});
smartRequest.get('dashboard/online/staff', function (data) {
smartRequest.get('v1/onlinestaff?method=dashboard', function (data) {
$scope.personals = data.staff;
});
@@ -503,7 +503,7 @@
$scope.total = data.total;
});
smartRequest.get('dashboard/online/staff', function (data) {
smartRequest.get('v1/onlinestaff?method=dashboard', function (data) {
$scope.personals = data.staff;
});
@@ -730,6 +730,14 @@
});
};
$scope.getItemsStaff = function (order) {
$('#get-more-staff').modal('toggle');
smartRequest.get('v1/onlinestaff?method=items&order=' + order.number, function (data) {
$scope.order = data;
$('#items-staff').modal('toggle');
});
};
$scope.getItemsDiscount = function (order) {
$('#get-more-discount').modal('toggle');
smartRequest.get('v1/discountitems?order=' + order.number, function (data) {

View File

@@ -89,7 +89,7 @@
};
$scope.reportStaff = function() {
smartRequest.get('report/staff?start_date=' + encodeURIComponent($scope.start_date) + '&end_date=' + encodeURIComponent($scope.end_date), function(data) {
smartRequest.get('v1/datareport?type=staff&start_date=' + encodeURIComponent($scope.start_date) + '&end_date=' + encodeURIComponent($scope.end_date), function(data) {
$scope.staffs = data.staffs;
$('#report-staff').modal();
}, function(data) {

View File

@@ -150,7 +150,7 @@
};
$scope.reportStaff = function (shift) {
smartRequest.get('report/staff?shift_id=' + shift.id, function (data) {
smartRequest.get('v1/datareport?type=staff&shift_id=' + shift.id, function (data) {
$scope.staffs = data.staffs;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;

View File

@@ -19,7 +19,7 @@
</thead>
<tbody>
<tr ng-repeat="order in staff.orders" ng-click="getItems('staff', order)">
<tr ng-repeat="order in staff.orders" ng-click="getItemsStaff(order)">
<td>{{order.number}}</td>
<td>{{order.opened}}</td>
<td>{{ getClosedDate(order.closed) }}</td>

View File

@@ -10,40 +10,26 @@
<span class="text-muted">{{start_date}} - {{end_date}}</span>
</div>
<div class="modal-body p-lg">
<div class="col-md-6" ng-repeat="staff in staffs">
<div class="table-responsive">
<table class="table table-border">
<thead>
<th>{{ staff.name }}</th>
</thead>
<tbody>
<tr ng-if="staff.input_count > 0">
<td>{{staff.input_count}} внесений в кассу на сумму {{staff.input_sum | curr}} BYN</td>
</tr>
<tr ng-if="staff.output_count > 0">
<td>{{staff.output_count}} выдач из кассы на сумму {{staff.output_sum | curr}} BYN</td>
</tr>
<tr ng-if="staff.payment_count > 0">
<td>{{staff.payment_count}} платежных документов на сумму {{staff.payment_sum | curr}} BYN</td>
</tr>
<tr ng-if="staff.opened_count > 0">
<td>Открыто {{staff.opened_count}} документов на сумму {{staff.opened_sum | curr}} BYN</td>
</tr>
<tr ng-if="staff.input_presale_count > 0">
<td>Внесено {{staff.input_presale_count}} авансов на сумму {{staff.input_presale_sum | curr} BYN</td>
</tr>
<tr ng-if="staff.output_presale_count > 0">
<td>Выдано {{staff.output_presale_count}} авансов на сумму {{staff.output_presale_sum | curr}} BYN</td>
</tr>
<tr ng-if="staff.correct_count > 0">
<td>Внесено {{staff.correct_count}} корекций на сумму {{staff.correct_sum | curr}} BYN</td>
</tr>
<tr ng-if="staff.return_count > 0">
<td>{{staff.return_count}} возвратов на сумму {{staff.return_sum | curr}} BYN</td>
</tr>
</tbody>
</table>
</div>
<div class="table-responsive" ng-repeat="staff in staffs">
<table class="table table-border">
<thead>
<th>
{{ staff.name }}
</th>
</thead>
<tbody>
<td>
<p ng-if="staff.input_count > 0">{{staff.input_count}} внесений в кассу на сумму {{staff.input_sum | curr}} BYN</p>
<p ng-if="staff.output_count > 0">{{staff.output_count}} выплат из кассы на сумму {{staff.output_sum | curr}} BYN</p>
<p ng-if="staff.opened_count > 0">Открыто {{staff.opened_count}} заказов на сумму {{staff.opened_sum | curr}} BYN</p>
<p ng-if="staff.closed_count > 0">Закрыто {{staff.closed_count}} заказов на сумму {{staff.closed_sum | curr}} BYN</p>
<p ng-if="staff.return_count > 0">{{staff.return_count}} возвратов на сумму {{staff.return_sum | curr}} BYN</p>
<p ng-if="staff.annul_count > 0">{{staff.annul_count}} аннулирований на сумму {{staff.annul_sum | curr}} BYN</p>
<p ng-if="staff.deleted_count > 0">{{staff.deleted_count}} удалений на сумму {{staff.deleted_sum | curr}} BYN</p>
</td>
</tbody>
</table>
</hr>
</div>
</div>
</div>

View File

@@ -1,35 +0,0 @@
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h5 class="modal-title">Отчет по удалениям</h5>
</div>
<div class="modal-body p-lg">
<div class="table-responsive" ng-if="report_delete.length > 0">
<table class="table table-bordered m-a-" ng-repeat="report in report_delete">
<thead>
<th>Заказ #{{ report.order_code }}</th>
</thead>
<tbody>
<tr ng-repeat="item in report.items">
<td>
<h6>{{ item.dish_name }} <small>(<strong>{{ item.count }}</strong> на сумму <strong>{{ item.sum }} BYN</strong>)</small></h6>
<p>
Удалил: <strong>{{ item.who }}</strong><br/>
Подтвердил: <strong>{{ item.approved }}</strong><br/>
Причина: <strong>{{ item.reason }}</strong>
</p>
</td>
</tr>
</tbody>
</table>
</div>
<div ng-if="report_delete.length == 0">
<p>Удаления отсутствуют</p>
</div>
</div>
</div>
</div>