added pargar

This commit is contained in:
2026-07-05 16:43:34 +03:30
parent 694fddc909
commit 7ac7bbdb90
27 changed files with 1341 additions and 493 deletions
@@ -17,7 +17,10 @@ use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use App\Models\Price;
use App\Http\Controllers\Admin\ProductController;
use App\Http\Controllers\Admin\GiftCardController;
use App\Http\Controllers\Admin\TahesabController;
use App\Services\AccountingLedgerService;
use App\Services\ConfigService;
use App\Services\PargarSyncService;
use App\Services\ProductPriceService;
@@ -342,11 +345,55 @@ class CartController extends Controller
// $product->decrement('inventory', $item->quantity);
}
$this->syncCartOrderAccounting($order, $cart);
return response()->json([
'message' => 'true',
]);
}
/**
* ثبت سبد در دفترکل داخلی + حسابداری بیرونی (مستقل از is_store؛ فقط accounting_provider).
*/
private function syncCartOrderAccounting(Order $order, Cart $cart): void
{
$config = app(ConfigService::class);
try {
app(AccountingLedgerService::class)->recordTrade($order);
} catch (\Throwable $e) {
report($e);
}
$primaryProduct = Product::find($cart->items->first()?->product_id);
$metalId = max(1, (int) ($primaryProduct->metal_id ?? 1));
if ($config->isTahesabAccounting()) {
try {
app(TahesabController::class)->storeTrade([
'customer_id' => $order->customer_id,
'amount' => $order->amount,
'direction' => (int) ($order->direction ?? 1),
'price' => $order->price,
'total_price' => $order->total_price,
'pay_at' => $order->pay_at ?? $order->created_at,
'product' => ['metal_id' => $metalId],
'order' => ['id' => $order->id],
]);
} catch (\Throwable $e) {
report($e);
}
}
if ($config->isPargarAccounting()) {
try {
app(PargarSyncService::class)->recordTrade($order, true);
} catch (\Throwable $e) {
report($e);
}
}
}
/**
* تسویه سبد فروشگاهی — قیمت نقدی هر محصول، بدون فرمول آبشده/گرم.
*/
@@ -476,6 +523,8 @@ class CartController extends Controller
Product::where('id', $item->product_id)->decrement('inventory', $item->quantity);
}
$this->syncCartOrderAccounting($order, $cart);
return response()->json([
'message' => 'true',
]);
@@ -14,6 +14,7 @@ use App\Models\BankAccount;
use App\Models\Price;
use App\Models\Setting;
use App\Http\Controllers\Admin\TahesabController;
use App\Services\ConfigService;
use App\Services\AssetSummaryService;
use App\Services\WalletBalanceService;
use App\Services\ZaarboxPriceService;
@@ -272,7 +273,7 @@ class WalletController extends Controller
$userMobile = $customer->mobile; // User's mobile number
$userName = $customer->name; // User's name
$withdrawAmount = $data['value']; // amount
if($this->Config('send_to_tahesab') == "true") {
if (app(ConfigService::class)->isTahesabAccounting()) {
try {
$result = app(TahesabController::class)->wallet([
"customer_id" => auth('customer')->id(),