Updated Store Method

This commit is contained in:
sanjeev 2022-07-11 17:27:18 +05:30
parent 6bc6131c2a
commit fde35a15ca
19 changed files with 77 additions and 49 deletions

View File

@ -80,58 +80,68 @@ class TransactionController extends Controller
$invoice = $this->invoiceRepository->where('increment_id', $request->invoice_id)->first();
if ($invoice) {
if ($invoice->state == 'paid') {
session()->flash('info', trans('admin::app.sales.transactions.response.already-paid'));
if (! $invoice) {
session()->flash('error', trans('admin::app.sales.transactions.response.invoice-missing'));
return redirect(route('admin.sales.transactions.index'));
}
if ($request->amount > $invoice->base_grand_total) {
session()->flash('info', trans('admin::app.sales.transactions.response.transaction-amount-exceeds'));
return redirect(route('admin.sales.transactions.create'));
} else {
$order = $this->orderRepository->find($invoice->order_id);
$randomId = random_bytes(20);
$this->orderTransactionRepository->create([
'transaction_id' => bin2hex($randomId),
'type' => $request->payment_method,
'payment_method' => $request->payment_method,
'invoice_id' => $invoice->id,
'order_id' => $invoice->order_id,
'amount' => $request->amount,
'status' => 'paid',
'data' => json_encode([
'paidAmount' => $request->amount,
]),
]);
$transactionTotal = $this->orderTransactionRepository->where('invoice_id', $invoice->id)->sum('amount');
if ($transactionTotal >= $invoice->base_grand_total) {
$shipments = $this->shipmentRepository->where('order_id', $invoice->order_id)->first();
if (isset($shipments)) {
$this->orderRepository->updateOrderStatus($order, 'completed');
} else {
$this->orderRepository->updateOrderStatus($order, 'processing');
}
$this->invoiceRepository->updateState($invoice, 'paid');
}
session()->flash('success', trans('admin::app.sales.transactions.response.transaction-saved'));
return redirect(route('admin.sales.transactions.index'));
}
return redirect()->back();
}
session()->flash('error', trans('admin::app.sales.transactions.response.invoice-missing'));
$transactionAmtBefore = $this->orderTransactionRepository->where('invoice_id', $invoice->id)->sum('amount');
$transactionAmtfinal = $request->amount + $transactionAmtBefore;
return redirect()->back();
if ($invoice->state == 'paid') {
session()->flash('info', trans('admin::app.sales.transactions.response.already-paid'));
return redirect(route('admin.sales.transactions.index'));
}
if ($transactionAmtfinal > $invoice->base_grand_total) {
session()->flash('info', trans('admin::app.sales.transactions.response.transaction-amount-exceeds'));
return redirect(route('admin.sales.transactions.create'));
}
if ($request->amount <= 0) {
session()->flash('info', trans('admin::app.sales.transactions.response.transaction-amount-zero'));
return redirect(route('admin.sales.transactions.create'));
}
$order = $this->orderRepository->find($invoice->order_id);
$randomId = random_bytes(20);
$this->orderTransactionRepository->create([
'transaction_id' => bin2hex($randomId),
'type' => $request->payment_method,
'payment_method' => $request->payment_method,
'invoice_id' => $invoice->id,
'order_id' => $invoice->order_id,
'amount' => $request->amount,
'status' => 'paid',
'data' => json_encode([
'paidAmount' => $request->amount,
]),
]);
$transactionTotal = $this->orderTransactionRepository->where('invoice_id', $invoice->id)->sum('amount');
if ($transactionTotal >= $invoice->base_grand_total) {
$shipments = $this->shipmentRepository->where('order_id', $invoice->order_id)->first();
if (isset($shipments)) {
$this->orderRepository->updateOrderStatus($order, 'completed');
} else {
$this->orderRepository->updateOrderStatus($order, 'processing');
}
$this->invoiceRepository->updateState($invoice, 'paid');
}
session()->flash('success', trans('admin::app.sales.transactions.response.transaction-saved'));
return redirect(route('admin.sales.transactions.index'));
}
/**

View File

@ -523,6 +523,7 @@ return [
'transaction-saved' => 'تم حفظ الصفقة',
'already-paid' => 'تم دفع هذه الفاتورة بالفعل',
'transaction-amount-exceeds' => 'المبلغ المحدد لهذه المعاملة أكبر من المبلغ الإجمالي للفاتورة.',
'transaction-amount-zero' => 'يمكن أن يكون مبلغ الصفقة صفرًا أو أقل',
],
],
],

View File

@ -526,6 +526,7 @@ return [
'transaction-saved' => 'The transaction has been saved',
'already-paid' => 'This invoice has already been paid',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],

View File

@ -516,6 +516,7 @@ return [
'transaction-saved' => 'Die Transaktion wurde gespeichert',
'already-paid' => 'Diese Rechnung wurde bereits bezahlt',
'transaction-amount-exceeds' => 'Der angegebene Betrag dieser Transaktion übersteigt den Gesamtbetrag der Rechnung.',
'transaction-amount-zero' => 'Der Transaktionsbetrag kann Null oder weniger betragen',
],
],
],

View File

@ -526,6 +526,7 @@ return [
'transaction-saved' => 'The transaction has been saved',
'already-paid' => 'This invoice has already been paid',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],

View File

@ -524,6 +524,7 @@ return [
'transaction-saved' => 'The transaction has been saved',
'already-paid' => 'This invoice has already been paid',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],

View File

@ -521,6 +521,7 @@ return [
'transaction-saved' => 'The transaction has been saved',
'already-paid' => 'This invoice has already been paid',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],

View File

@ -524,7 +524,8 @@ return [
'invoice-missing' => 'Ce numéro de facture n\'existe pas',
'transaction-saved' => 'La transaction a été enregistrée',
'already-paid' => 'Cette facture a déjà été payée',
'transaction-amount-exceeds' => 'Le montant de cette transaction dépasse le montant total de la facture.',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less.',
],
],
],

View File

@ -526,6 +526,7 @@ return [
'transaction-saved' => 'The transaction has been saved',
'already-paid' => 'This invoice has already been paid',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],

View File

@ -523,6 +523,7 @@ return [
'transaction-saved' => 'लेन-देन सहेजा गया है',
'already-paid' => 'इस चालान का भुगतान पहले ही किया जा चुका है',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],

View File

@ -521,6 +521,7 @@ return [
'transaction-saved' => 'The transaction has been saved',
'already-paid' => 'This invoice has already been paid',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],

View File

@ -526,6 +526,7 @@ return [
'transaction-saved' => 'The transaction has been saved',
'already-paid' => 'This invoice has already been paid',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],

View File

@ -517,6 +517,7 @@ return [
'transaction-saved' => 'De transactie is geregistreerd',
'already-paid' => 'Dit factuur is al voldaan',
'transaction-amount-exceeds' => 'Het opgegeven bedrag van deze transactie overschrijdt het totaalbedrag van de factuur.',
'transaction-amount-zero' => 'Transactiebedrag kan nul of minder zijn',
],
],
],

View File

@ -517,6 +517,7 @@ return [
'transaction-saved' => 'The transaction has been saved',
'already-paid' => 'This invoice has already been paid',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],

View File

@ -516,6 +516,7 @@ return [
'transaction-saved' => 'The transaction has been saved',
'already-paid' => 'This invoice has already been paid',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],

View File

@ -526,6 +526,7 @@ return [
'transaction-saved' => 'The transaction has been saved',
'already-paid' => 'This invoice has already been paid',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],

View File

@ -526,6 +526,7 @@ return [
'transaction-saved' => 'The transaction has been saved',
'already-paid' => 'This invoice has already been paid',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],

View File

@ -517,6 +517,7 @@ return [
'transaction-saved' => 'İşlem kaydedildi',
'already-paid' => 'Bu fatura zaten ödendi',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],

View File

@ -517,6 +517,7 @@ return [
'transaction-saved' => '交易已保存',
'already-paid' => '此发票已支付',
'transaction-amount-exceeds' => 'The specified amount of this transaction exceeds the total amount of the invoice.',
'transaction-amount-zero' => 'Transaction amount can be zero or less',
],
],
],