added table of co-woeker requests and new features
This commit is contained in:
@@ -6,8 +6,10 @@ use App\DB\Te\TableEngine;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use App\Services\BalanceReportService;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\WalletBalanceService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
@@ -72,4 +74,75 @@ class OrderController extends Controller
|
||||
|
||||
return response()->json($records);
|
||||
}
|
||||
|
||||
/**
|
||||
* سفارشهایی که نزد همکار (Montzar) ثبت شدهاند — فقط وقتی منبع قیمت montzar است.
|
||||
*/
|
||||
public function colleagueTable(Request $request)
|
||||
{
|
||||
$config = app(ConfigService::class);
|
||||
if (!$config->usesMontzarPricing()) {
|
||||
return response()->json([
|
||||
'message' => 'این لیست فقط وقتی منبع قیمت montzar است در دسترس است.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$hasProvider = Schema::hasColumn('orders', 'provider_id');
|
||||
$hasMontzarPrice = Schema::hasColumn('orders', 'total_price_montzar');
|
||||
|
||||
if (!$hasProvider && !$hasMontzarPrice) {
|
||||
return response()->json([
|
||||
'rows' => [],
|
||||
'total' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
$records = Order::with([
|
||||
'customer:id,name,mobile',
|
||||
'product' => static function ($q) {
|
||||
$q->withTrashed()->select(['id', 'title', 'unit']);
|
||||
},
|
||||
])->where(function ($q) use ($hasProvider, $hasMontzarPrice) {
|
||||
if ($hasProvider) {
|
||||
$q->whereNotNull('provider_id');
|
||||
}
|
||||
if ($hasMontzarPrice) {
|
||||
if ($hasProvider) {
|
||||
$q->orWhereNotNull('total_price_montzar');
|
||||
} else {
|
||||
$q->whereNotNull('total_price_montzar');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(['customer.name', 'customer.mobile'])
|
||||
->select([
|
||||
'*', Order::$SELECT_STS_STR
|
||||
])->export($records);
|
||||
|
||||
if (isset($records['rows'])) {
|
||||
foreach ($records['rows'] as &$row) {
|
||||
$amount = (float) ($row['amount'] ?? 0);
|
||||
$serviceCharge = (float) ($row['service_charge'] ?? 0);
|
||||
$feeAsset = (string) ($row['fee_asset'] ?? 'rial');
|
||||
$montzarUnit = $hasMontzarPrice ? (float) ($row['total_price_montzar'] ?? 0) : 0.0;
|
||||
|
||||
// وقتی کارمزد از طلا کم شده، مقدار اولیهٔ مشتری = مقدار نزد همکار + کارمزد
|
||||
$customerAmount = $feeAsset === 'gold'
|
||||
? round($amount + $serviceCharge, 3)
|
||||
: round($amount, 3);
|
||||
|
||||
$row['customer_amount'] = $customerAmount;
|
||||
$row['colleague_amount'] = round($amount, 3);
|
||||
$row['colleague_unit_price'] = (int) round($montzarUnit);
|
||||
$row['colleague_total_price'] = (int) round($amount * $montzarUnit);
|
||||
$row['direction_label'] = Order::$DIRECTION[(int) ($row['direction'] ?? 0)]
|
||||
?? (string) ($row['direction'] ?? '');
|
||||
}
|
||||
unset($row);
|
||||
}
|
||||
|
||||
return response()->json($records);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user