added tahesab options 3
This commit is contained in:
@@ -20,6 +20,7 @@ use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
use App\Http\Controllers\Admin\TahesabController;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Models\TransactionsAdmin;
|
||||
use App\Services\BalanceReportService;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\WalletBalanceService;
|
||||
@@ -124,6 +125,8 @@ class WalletController extends Controller
|
||||
'active' => true
|
||||
], $type, true, $deposit, $gold_block);
|
||||
|
||||
$this->recordAccountingTransaction($customer, $Withdraw, (int) $user->id, (float) $data['value'], 0, $data['note'] ?? null);
|
||||
|
||||
if($this->Config('send_to_tahesab') == "true"){
|
||||
try {
|
||||
$data['direction'] = $deposit ? 0 : 1;
|
||||
@@ -192,6 +195,8 @@ class WalletController extends Controller
|
||||
'active' => true
|
||||
], 7, $deposit, false, $gold_block);
|
||||
|
||||
$this->recordAccountingTransaction($customer, $Withdraw, (int) $user->id, 0, (float) $data['value'], $data['note'] ?? null);
|
||||
|
||||
//send to tahesab
|
||||
if($this->Config('send_to_tahesab') == "true"){
|
||||
try {
|
||||
@@ -325,6 +330,15 @@ class WalletController extends Controller
|
||||
'active' => true,
|
||||
], 7, $deposit, false, $goldBlock);
|
||||
|
||||
$this->recordAccountingTransaction(
|
||||
$customer,
|
||||
$Withdraw,
|
||||
(int) $user->id,
|
||||
0,
|
||||
(float) $data['value'],
|
||||
($data['note'] ?? null) ?: ('شارژ ' . $product->title)
|
||||
);
|
||||
|
||||
if ($this->Config('send_to_tahesab') == 'true') {
|
||||
try {
|
||||
$data['direction'] = $deposit ? 1 : 0;
|
||||
@@ -621,4 +635,29 @@ class WalletController extends Controller
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
private function recordAccountingTransaction(
|
||||
Customer $customer,
|
||||
Withdraw $withdraw,
|
||||
int $adminUserId,
|
||||
float $cash = 0,
|
||||
float $gold = 0,
|
||||
?string $note = null
|
||||
): void {
|
||||
$transaction = Transaction::where('withdraw_id', $withdraw->id)->latest('id')->first();
|
||||
|
||||
TransactionsAdmin::create([
|
||||
'customer_id' => $customer->id,
|
||||
'customer_to_id' => $customer->id,
|
||||
'user_id' => $adminUserId,
|
||||
'wallet' => null,
|
||||
'transaction_id' => $transaction?->id,
|
||||
'cash' => $cash,
|
||||
'note' => $note ?? $withdraw->note,
|
||||
'type' => 1,
|
||||
'gold' => $gold,
|
||||
'balance_cash' => 0,
|
||||
'withdraw_id' => $withdraw->id,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ use App\Models\Price;
|
||||
use App\Models\TransactionsAdmin;
|
||||
use App\Models\User;
|
||||
use App\Models\Withdraw;
|
||||
use App\Models\Tahesab;
|
||||
use App\Services\TahesabSyncService;
|
||||
use App\DB\Te\TableEngine;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
@@ -27,6 +29,41 @@ class FinanceController extends Controller
|
||||
->initSearch(['price'])
|
||||
->select(['*'])
|
||||
->export($transactions_admins);
|
||||
|
||||
if (isset($transactions_admins['rows']) && is_array($transactions_admins['rows']) && $this->Config('send_to_tahesab') === 'true') {
|
||||
$withdrawIds = collect($transactions_admins['rows'])
|
||||
->pluck('withdraw_id')
|
||||
->filter()
|
||||
->unique()
|
||||
->values()
|
||||
->all();
|
||||
|
||||
if ($withdrawIds !== []) {
|
||||
$tahesabByWithdraw = Tahesab::query()
|
||||
->whereIn('withdraw_id', $withdrawIds)
|
||||
->orderByDesc('id')
|
||||
->get()
|
||||
->unique('withdraw_id')
|
||||
->keyBy('withdraw_id');
|
||||
|
||||
foreach ($transactions_admins['rows'] as &$row) {
|
||||
$tahesab = $tahesabByWithdraw->get($row['withdraw_id'] ?? null);
|
||||
if (! $tahesab) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row['tahesab_record_id'] = $tahesab->id;
|
||||
$row['tahesab_sync_status'] = $tahesab->sync_status
|
||||
?? (empty($tahesab->tahesab_id) ? TahesabSyncService::STATUS_PENDING : TahesabSyncService::STATUS_SUCCESS);
|
||||
|
||||
if (empty($tahesab->tahesab_id) || $row['tahesab_sync_status'] === TahesabSyncService::STATUS_FAILED) {
|
||||
$row['tahesab_failed_id'] = $tahesab->id;
|
||||
}
|
||||
}
|
||||
unset($row);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($transactions_admins);
|
||||
}
|
||||
public function index()
|
||||
|
||||
Reference in New Issue
Block a user