2026-01-24 14:03:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use App\DB\Te\TableEngine;
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\Order;
|
2026-06-23 21:28:49 +03:30
|
|
|
use App\Services\BalanceReportService;
|
2026-06-23 21:40:33 +03:30
|
|
|
use App\Services\WalletBalanceService;
|
2026-01-24 14:03:11 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
class OrderController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function table(Request $request){
|
2026-06-23 21:28:49 +03:30
|
|
|
$balanceReport = app(BalanceReportService::class);
|
2026-06-23 21:40:33 +03:30
|
|
|
$catalogMetalIds = app(WalletBalanceService::class)->catalogMetalIds();
|
2026-06-23 21:28:49 +03:30
|
|
|
|
|
|
|
|
$records = Order::with([
|
|
|
|
|
'customer',
|
2026-07-21 22:23:09 +03:30
|
|
|
'product' => static function ($q) {
|
|
|
|
|
$q->withTrashed()->select(['id', 'title', 'unit', 'metal_id', 'group_type', 'amount', 'trade_by_quantity', 'direct_price']);
|
|
|
|
|
},
|
|
|
|
|
'transactions.product' => static function ($q) {
|
|
|
|
|
$q->withTrashed()->select(['id', 'title', 'unit', 'metal_id', 'group_type', 'amount', 'trade_by_quantity', 'direct_price']);
|
|
|
|
|
},
|
2026-06-23 21:28:49 +03:30
|
|
|
]);
|
2026-01-24 14:03:11 +00:00
|
|
|
TableEngine::create($records, $request->all())
|
|
|
|
|
->initSearch(['customer.name'])
|
|
|
|
|
->select([
|
|
|
|
|
'*',Order::$SELECT_STS_STR
|
|
|
|
|
])->export($records);
|
2026-06-23 21:28:49 +03:30
|
|
|
|
|
|
|
|
if (isset($records['rows'])) {
|
|
|
|
|
foreach ($records['rows'] as &$row) {
|
2026-06-23 21:40:33 +03:30
|
|
|
$balanceReport->enrichOrderTableRow($row, $catalogMetalIds);
|
2026-06-23 21:28:49 +03:30
|
|
|
}
|
|
|
|
|
unset($row);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-23 21:40:33 +03:30
|
|
|
$records['catalogMetals'] = $balanceReport->catalogMetalsMeta();
|
|
|
|
|
|
2026-01-24 14:03:11 +00:00
|
|
|
return response()->json($records);
|
|
|
|
|
}
|
2026-06-23 21:28:49 +03:30
|
|
|
|
2026-01-24 14:03:11 +00:00
|
|
|
public function singleOrderTable(Request $request){
|
2026-06-23 21:28:49 +03:30
|
|
|
$balanceReport = app(BalanceReportService::class);
|
2026-06-23 21:40:33 +03:30
|
|
|
$catalogMetalIds = app(WalletBalanceService::class)->catalogMetalIds();
|
2026-06-23 21:28:49 +03:30
|
|
|
|
|
|
|
|
$records = Order::with([
|
|
|
|
|
'customer',
|
2026-07-21 22:23:09 +03:30
|
|
|
'product' => static function ($q) {
|
|
|
|
|
$q->withTrashed()->select(['id', 'title', 'unit', 'metal_id', 'group_type', 'amount', 'trade_by_quantity', 'direct_price']);
|
|
|
|
|
},
|
|
|
|
|
'transactions.product' => static function ($q) {
|
|
|
|
|
$q->withTrashed()->select(['id', 'title', 'unit', 'metal_id', 'group_type', 'amount', 'trade_by_quantity', 'direct_price']);
|
|
|
|
|
},
|
2026-06-23 21:28:49 +03:30
|
|
|
])->where('type',2);
|
2026-01-24 14:03:11 +00:00
|
|
|
TableEngine::create($records, $request->all())
|
|
|
|
|
->initSearch(['customer.name'])
|
|
|
|
|
->select([
|
|
|
|
|
'*',Order::$SELECT_STS_STR
|
|
|
|
|
])->export($records);
|
2026-06-23 21:28:49 +03:30
|
|
|
|
|
|
|
|
if (isset($records['rows'])) {
|
|
|
|
|
foreach ($records['rows'] as &$row) {
|
2026-06-23 21:40:33 +03:30
|
|
|
$balanceReport->enrichOrderTableRow($row, $catalogMetalIds);
|
2026-06-23 21:28:49 +03:30
|
|
|
}
|
|
|
|
|
unset($row);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-23 21:40:33 +03:30
|
|
|
$records['catalogMetals'] = $balanceReport->catalogMetalsMeta();
|
|
|
|
|
|
2026-01-24 14:03:11 +00:00
|
|
|
return response()->json($records);
|
|
|
|
|
}
|
|
|
|
|
}
|