|
@@ -8,6 +8,7 @@ use App\Models\Order;
|
|
|
use App\Models\OrderStatus;
|
|
use App\Models\OrderStatus;
|
|
|
use App\Models\Product;
|
|
use App\Models\Product;
|
|
|
use App\Models\ProductSKU;
|
|
use App\Models\ProductSKU;
|
|
|
|
|
+use App\Models\User;
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
@@ -22,29 +23,73 @@ class ReportController extends Controller
|
|
|
|
|
|
|
|
public function index()
|
|
public function index()
|
|
|
{
|
|
{
|
|
|
- $doneStatuses = [5, 7, 8, 9, 10];
|
|
|
|
|
|
|
+ $mountStatuses = [5, 7, 8, 9, 10];
|
|
|
|
|
+ $doneStatuses = [9, 10];
|
|
|
$objectTypes = ObjectType::query()->get()->pluck('name', 'id')->toArray();
|
|
$objectTypes = ObjectType::query()->get()->pluck('name', 'id')->toArray();
|
|
|
$this->data['objectTypes'] = $objectTypes;
|
|
$this->data['objectTypes'] = $objectTypes;
|
|
|
- $this->data['totalOrders'] = Order::all()->count();
|
|
|
|
|
- $this->data['doneOrders'] = Order::query()->whereIn('order_status_id', [9, 10])->count();
|
|
|
|
|
|
|
+ $user_ids = Order::query()->distinct()->get('user_id')->pluck('user_id')->toArray();
|
|
|
|
|
+ $managers = User::query()->whereIn('id', $user_ids)->get()->pluck('name', 'id')->toArray();
|
|
|
|
|
+ $this->data['managers'] = $managers;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
+ // всего заказов, выполнено заказов
|
|
|
|
|
+ $this->data['totalOrders'] = Order::all()->count();
|
|
|
|
|
+ $this->data['doneOrders'] = Order::query()->whereIn('order_status_id', $doneStatuses)->count();
|
|
|
|
|
+ $this->data['mountOrders'] = Order::query()->whereIn('order_status_id', $mountStatuses)->count();
|
|
|
|
|
|
|
|
|
|
+ // всего маф / завершено маф / установлено маф
|
|
|
$this->data['totalMafs'] = ProductSKU::all()->count();
|
|
$this->data['totalMafs'] = ProductSKU::all()->count();
|
|
|
$this->data['doneMafs'] = ProductSKU::query()->
|
|
$this->data['doneMafs'] = ProductSKU::query()->
|
|
|
- whereHas('order', function ($query) {
|
|
|
|
|
- $query->whereIn('order_status_id', [9, 10]);
|
|
|
|
|
|
|
+ whereHas('order', function ($query) use ($doneStatuses) {
|
|
|
|
|
+ $query->whereIn('order_status_id', $doneStatuses);
|
|
|
})->count();
|
|
})->count();
|
|
|
|
|
+ $this->data['mountMafs'] = ProductSKU::query()->
|
|
|
|
|
+ whereHas('order', function ($query) use ($mountStatuses){
|
|
|
|
|
+ $query->whereIn('order_status_id', $mountStatuses);
|
|
|
|
|
+ })->count();
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // общая сумма
|
|
|
$this->data['totalSum'] = Price::format(
|
|
$this->data['totalSum'] = Price::format(
|
|
|
ProductSKU::query()->
|
|
ProductSKU::query()->
|
|
|
- whereHas('order', function ($query) use ($doneStatuses) {
|
|
|
|
|
- $query->whereIn('order_status_id', $doneStatuses);
|
|
|
|
|
|
|
+ whereHas('order', function ($query) use ($mountStatuses) {
|
|
|
|
|
+ $query->whereIn('order_status_id', $mountStatuses);
|
|
|
})
|
|
})
|
|
|
->withSum('product', 'total_price')
|
|
->withSum('product', 'total_price')
|
|
|
->get()
|
|
->get()
|
|
|
->sum('product_sum_total_price')
|
|
->sum('product_sum_total_price')
|
|
|
);
|
|
);
|
|
|
|
|
+
|
|
|
|
|
+ // done by managers
|
|
|
|
|
+ foreach ($managers as $userId => $userName) {
|
|
|
|
|
+ $this->data['totalOrderManager'] = Order::where('user_id', $userId)->count();
|
|
|
|
|
+ $this->data['totalMafsManager'][$userId] = ProductSKU::query()->
|
|
|
|
|
+ whereHas('order', function ($query) use ($userId) {
|
|
|
|
|
+ $query->where('user_id', '=', $userId);
|
|
|
|
|
+ })->count();
|
|
|
|
|
+
|
|
|
|
|
+ $this->data['doneOrdersManager'][$userId] = Order::query()
|
|
|
|
|
+ ->where('user_id', '=', $userId)
|
|
|
|
|
+ ->whereIn('order_status_id', $doneStatuses)
|
|
|
|
|
+ ->count();
|
|
|
|
|
+ $this->data['doneMafsManager'][$userId] = ProductSKU::query()->
|
|
|
|
|
+ whereHas('order', function ($query) use ($userId, $doneStatuses) {
|
|
|
|
|
+ $query->where('user_id', '=', $userId)
|
|
|
|
|
+ ->whereIn('order_status_id', $doneStatuses);
|
|
|
|
|
+ })->count();
|
|
|
|
|
+
|
|
|
|
|
+ $this->data['notDoneOrdersManager'][$userId] = Order::query()
|
|
|
|
|
+ ->where('user_id', '=', $userId)
|
|
|
|
|
+ ->whereNotIn('order_status_id', $doneStatuses)
|
|
|
|
|
+ ->count();
|
|
|
|
|
+ $this->data['notDoneMafsManager'][$userId] = ProductSKU::query()->
|
|
|
|
|
+ whereHas('order', function ($query) use ($userId, $doneStatuses) {
|
|
|
|
|
+ $query->where('user_id', '=', $userId)
|
|
|
|
|
+ ->whereNotIn('order_status_id', $doneStatuses);
|
|
|
|
|
+ })->count();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // total mount by types
|
|
|
foreach ($objectTypes as $objectTypeId => $objectType) {
|
|
foreach ($objectTypes as $objectTypeId => $objectType) {
|
|
|
// total by types
|
|
// total by types
|
|
|
$this->data['totalOrdersType'][$objectTypeId] = Order::where('object_type_id', '=', $objectTypeId)->count();
|
|
$this->data['totalOrdersType'][$objectTypeId] = Order::where('object_type_id', '=', $objectTypeId)->count();
|
|
@@ -55,25 +100,25 @@ class ReportController extends Controller
|
|
|
|
|
|
|
|
// со статусами: в монтаже, готова к сдаче, не сдана замечания, сдана замечания, сдана - зеленый цвет
|
|
// со статусами: в монтаже, готова к сдаче, не сдана замечания, сдана замечания, сдана - зеленый цвет
|
|
|
|
|
|
|
|
- $this->data['doneOrdersType'][$objectTypeId] = Order::query()
|
|
|
|
|
|
|
+ $this->data['mountOrdersType'][$objectTypeId] = Order::query()
|
|
|
->where('object_type_id', '=', $objectTypeId)
|
|
->where('object_type_id', '=', $objectTypeId)
|
|
|
- ->whereIn('order_status_id', $doneStatuses)
|
|
|
|
|
|
|
+ ->whereIn('order_status_id', $mountStatuses)
|
|
|
->count();
|
|
->count();
|
|
|
- $this->data['doneMafsType'][$objectTypeId] = ProductSKU::query()->
|
|
|
|
|
- whereHas('order', function ($query) use ($objectTypeId, $doneStatuses) {
|
|
|
|
|
|
|
+ $this->data['mountMafsType'][$objectTypeId] = ProductSKU::query()->
|
|
|
|
|
+ whereHas('order', function ($query) use ($objectTypeId, $mountStatuses) {
|
|
|
$query->where('object_type_id', '=', $objectTypeId)
|
|
$query->where('object_type_id', '=', $objectTypeId)
|
|
|
- ->whereIn('order_status_id', $doneStatuses);
|
|
|
|
|
|
|
+ ->whereIn('order_status_id', $mountStatuses);
|
|
|
})->count();
|
|
})->count();
|
|
|
|
|
|
|
|
// остальные - не готовы
|
|
// остальные - не готовы
|
|
|
- $this->data['notDoneOrdersType'][$objectTypeId] = Order::query()
|
|
|
|
|
|
|
+ $this->data['notMountOrdersType'][$objectTypeId] = Order::query()
|
|
|
->where('object_type_id', '=', $objectTypeId)
|
|
->where('object_type_id', '=', $objectTypeId)
|
|
|
- ->whereNotIn('order_status_id', $doneStatuses)
|
|
|
|
|
|
|
+ ->whereNotIn('order_status_id', $mountStatuses)
|
|
|
->count();
|
|
->count();
|
|
|
- $this->data['notDoneMafsType'][$objectTypeId] = ProductSKU::query()->
|
|
|
|
|
- whereHas('order', function ($query) use ($objectTypeId, $doneStatuses) {
|
|
|
|
|
|
|
+ $this->data['notMountMafsType'][$objectTypeId] = ProductSKU::query()->
|
|
|
|
|
+ whereHas('order', function ($query) use ($objectTypeId, $mountStatuses) {
|
|
|
$query->where('object_type_id', '=', $objectTypeId)
|
|
$query->where('object_type_id', '=', $objectTypeId)
|
|
|
- ->whereNotIn('order_status_id', $doneStatuses);
|
|
|
|
|
|
|
+ ->whereNotIn('order_status_id', $mountStatuses);
|
|
|
})->count();
|
|
})->count();
|
|
|
|
|
|
|
|
|
|
|