Merge branch 'master' of https://github.com/bagisto/bagisto into development

This commit is contained in:
rahul shukla 2019-09-20 14:50:07 +05:30
commit 7779688d64
14 changed files with 125 additions and 67 deletions

View File

@ -115,10 +115,16 @@ class RefundController extends Controller
$totals = $this->refundRepository->getOrderItemsRefundSummary($data['refund']['items'], $orderId);
$maxRefundAmount = $totals['grand_total']['price'] - $order->refunds()->sum('base_adjustment_refund') + $order->refunds()->sum('base_adjustment_fee');
$maxRefundAmount = $totals['grand_total']['price'] - $order->refunds()->sum('base_adjustment_refund');
$refundAmount = $totals['grand_total']['price'] - $totals['shipping']['price'] + $data['refund']['shipping'] + $data['refund']['adjustment_refund'] - $data['refund']['adjustment_fee'];
if (! $refundAmount) {
session()->flash('error', trans('admin::app.sales.refunds.invalid-refund-amount-error'));
return redirect()->back();
}
if ($refundAmount > $maxRefundAmount) {
session()->flash('error', trans('admin::app.sales.refunds.refund-limit-error', ['amount' => core()->formatBasePrice($maxRefundAmount)]));

View File

@ -350,7 +350,9 @@ return [
'date' => 'Refund Date',
'customer-name' => 'Customer Name',
'status' => 'Status',
'action' => 'Action'
'action' => 'Action',
'view-title' => 'Refund #:refund_id',
'invalid-refund-amount-error' => 'Refund amount should be non zero.'
]
],
'catalog' => [

View File

@ -414,6 +414,8 @@ return [
'status' => 'Status',
'action' => 'Action',
'view-title' => 'Refund #:refund_id',
'invalid-refund-amount-error' => 'Refund amount should be non zero.'
]
],

View File

@ -377,7 +377,9 @@ return [
'date' => 'Refund Date',
'customer-name' => 'Customer Name',
'status' => 'Status',
'action' => 'Action'
'action' => 'Action',
'view-title' => 'Refund #:refund_id',
'invalid-refund-amount-error' => 'Refund amount should be non zero.'
]
],

View File

@ -358,7 +358,9 @@ return [
'date' => 'Refund Date',
'customer-name' => 'Customer Name',
'status' => 'Status',
'action' => 'Action'
'action' => 'Action',
'view-title' => 'Refund #:refund_id',
'invalid-refund-amount-error' => 'Refund amount should be non zero.'
]
],
'catalog' => [

View File

@ -43,7 +43,7 @@
</span>
<span class="value">
<a href="{{ route('admin.sales.orders.view', $order->id) }}">#{{ $order->id }}</a>
<a href="{{ route('admin.sales.orders.view', $order->id) }}">#{{ $order->increment_id }}</a>
</span>
</div>
@ -303,7 +303,7 @@
<td>-</td>
<td>
<div class="control-group" :class="[errors.has('refund[shipping]') ? 'has-error' : '']" style="width: 100px; margin-bottom: 0;">
<input type="text" v-validate="'required|min_value:0|max_value:{{$order->base_shipping_invoiced - $order->base_shipping_refunded}}'" class="control" id="refund[shipping]" name="refund[shipping]" :value="refund.summary.shipping.price" data-vv-as="&quot;{{ __('admin::app.sales.refunds.refund-shipping') }}&quot;" style="width: 100%; margin: 0"/>
<input type="text" v-validate="'required|min_value:0|max_value:{{$order->base_shipping_invoiced - $order->base_shipping_refunded}}'" class="control" id="refund[shipping]" name="refund[shipping]" v-model="refund.summary.shipping.price" data-vv-as="&quot;{{ __('admin::app.sales.refunds.refund-shipping') }}&quot;" style="width: 100%; margin: 0"/>
<span class="control-error" v-if="errors.has('refund[shipping]')">
@{{ errors.first('refund[shipping]') }}

View File

@ -40,7 +40,7 @@
</span>
<span class="value">
<a href="{{ route('admin.sales.orders.view', $order->id) }}">#{{ $order->id }}</a>
<a href="{{ route('admin.sales.orders.view', $order->id) }}">#{{ $order->increment_id }}</a>
</span>
</div>
@ -213,9 +213,7 @@
<th>{{ __('admin::app.sales.orders.qty') }}</th>
<th>{{ __('admin::app.sales.orders.subtotal') }}</th>
<th>{{ __('admin::app.sales.orders.tax-amount') }}</th>
@if ($refund->base_discount_amount > 0)
<th>{{ __('admin::app.sales.orders.discount-amount') }}</th>
@endif
<th>{{ __('admin::app.sales.orders.discount-amount') }}</th>
<th>{{ __('admin::app.sales.orders.grand-total') }}</th>
</tr>
</thead>
@ -242,14 +240,18 @@
<td>{{ core()->formatBasePrice($item->base_tax_amount) }}</td>
@if ($refund->base_discount_amount > 0)
<td>{{ core()->formatBasePrice($item->base_discount_amount) }}</td>
@endif
<td>{{ core()->formatBasePrice($item->base_discount_amount) }}</td>
<td>{{ core()->formatBasePrice($item->base_total + $item->base_tax_amount - $item->base_discount_amount) }}</td>
</tr>
@endforeach
@if (! $refund->items->count())
<tr>
<td class="empty" colspan="7">{{ __('admin::app.common.no-result-found') }}</td>
<tr>
@endif
</tbody>
</table>
</div>

View File

@ -208,7 +208,7 @@ class Order extends Model implements OrderContract
return true;
}
if ($this->base_grand_total_invoiced - $this->base_grand_total_refunded > 0)
if ($this->base_grand_total_invoiced - $this->base_grand_total_refunded - $this->refunds()->sum('base_adjustment_fee') > 0)
return true;
return false;

View File

@ -98,9 +98,7 @@ class InvoiceRepository extends Repository
'base_currency_code' => $order->base_currency_code,
'channel_currency_code' => $order->channel_currency_code,
'order_currency_code' => $order->order_currency_code,
'order_address_id' => $order->billing_address->id,
"discount_amount" => $order->discount_amount,
"base_discount_amount" => $order->base_discount_amount,
'order_address_id' => $order->billing_address->id
]);
foreach ($data['invoice']['items'] as $itemId => $qty) {
@ -174,49 +172,40 @@ class InvoiceRepository extends Repository
return $invoice;
}
/**
* @param mixed $invoice
* @return mixed
*/
public function collectTotals($invoice)
{
$subTotal = $baseSubTotal = 0;
$taxAmount = $baseTaxAmount = 0;
$discountAmount = $baseDiscountAmount = 0;
$invoice->sub_total = $invoice->base_sub_total = 0;
$invoice->tax_amount = $invoice->base_tax_amount = 0;
$invoice->discount_amount = $invoice->base_discount_amount = 0;
foreach ($invoice->items as $invoiceItem) {
$subTotal += $invoiceItem->total;
$baseSubTotal += $invoiceItem->base_total;
$invoice->sub_total += $invoiceItem->total;
$invoice->base_sub_total += $invoiceItem->base_total;
$taxAmount += $invoiceItem->tax_amount;
$baseTaxAmount += $invoiceItem->base_tax_amount;
$invoice->tax_amount += $invoiceItem->tax_amount;
$invoice->base_tax_amount += $invoiceItem->base_tax_amount;
$discountAmount += $invoiceItem->discount_amount;
$baseDiscountAmount += $invoiceItem->base_discount_amount;
$invoice->discount_amount += $invoiceItem->discount_amount;
$invoice->base_discount_amount += $invoiceItem->base_discount_amount;
}
$shippingAmount = $invoice->order->shipping_amount;
$baseShippingAmount = $invoice->order->base_shipping_amount;
$invoice->shipping_amount = $invoice->order->shipping_amount;
$invoice->base_shipping_amount = $invoice->order->base_shipping_amount;
if ($invoice->order->shipping_amount) {
foreach ($invoice->order->invoices as $prevInvoice) {
if ((float) $prevInvoice->shipping_amount)
$shippingAmount = $baseShippingAmount = 0;
$invoice->shipping_amount = $invoice->base_shipping_amount = 0;
}
}
$invoice->sub_total = $subTotal;
$invoice->base_sub_total = $baseSubTotal;
$invoice->shipping_amount = $shippingAmount;
$invoice->base_shipping_amount = $baseShippingAmount;
$invoice->tax_amount = $taxAmount;
$invoice->base_tax_amount = $baseTaxAmount;
$invoice->grand_total = $subTotal + $taxAmount + $shippingAmount - $discountAmount;
$invoice->base_grand_total = $baseSubTotal + $baseTaxAmount + $baseShippingAmount - $baseDiscountAmount;
$invoice->grand_total = $invoice->sub_total + $invoice->tax_amount + $invoice->shipping_amount - $invoice->discount_amount;
$invoice->base_grand_total = $invoice->base_sub_total + $invoice->base_tax_amount + $invoice->base_shipping_amount - $invoice->base_discount_amount;
$invoice->save();

View File

@ -135,7 +135,7 @@ class OrderItemRepository extends Repository
/**
* Returns qty to product inventory after order cancelation
*
* @param mixed $orderItem
* @param OrderItem $orderItem
* @return void
*/
public function returnQtyToProductInventory($orderItem)
@ -150,9 +150,8 @@ class OrderItemRepository extends Repository
if (! $orderedInventory)
return ;
if (($qty = $orderedInventory->qty - $orderItem->qty_to_cancel) < 0) {
if (($qty = $orderedInventory->qty - $quantity) < 0)
$qty = 0;
}
$orderedInventory->update([
'qty' => $qty

View File

@ -265,9 +265,11 @@ class OrderRepository extends Repository
*/
public function collectTotals($order)
{
//Order invoice total
$order->sub_total_invoiced = $order->base_sub_total_invoiced = 0;
$order->shipping_invoiced = $order->base_shipping_invoiced = 0;
$order->tax_amount_invoiced = $order->base_tax_amount_invoiced = 0;
$order->discount_invoiced = $order->base_discount_invoiced = 0;
foreach ($order->invoices as $invoice) {
$order->sub_total_invoiced += $invoice->sub_total;
@ -286,7 +288,7 @@ class OrderRepository extends Repository
$order->grand_total_invoiced = $order->sub_total_invoiced + $order->shipping_invoiced + $order->tax_amount_invoiced - $order->discount_invoiced;
$order->base_grand_total_invoiced = $order->base_sub_total_invoiced + $order->base_shipping_invoiced + $order->base_tax_amount_invoiced - $order->base_discount_invoiced;
//Order refund total
$order->sub_total_refunded = $order->base_sub_total_refunded = 0;
$order->shipping_refunded = $order->base_shipping_refunded = 0;
$order->tax_amount_refunded = $order->base_tax_amount_refunded = 0;

View File

@ -25,4 +25,41 @@ class RefundItemRepository extends Repository
{
return RefundItem::class;
}
/**
* Returns qty to product inventory after order refund
*
* @param RefundItem $refundItem
* @param integer $quantity
* @return void
*/
public function returnQtyToProductInventory($refundItem, $quantity)
{
return;
if (! $product = $refundItem->product)
return;
if ($qtyShipped = $refundItem->order_item->qty_shipped) {
} else {
}
$orderedInventory = $product->ordered_inventories()
->where('channel_id', $refundItem->order->channel->id)
->first();
if ($orderedInventory) {
} else {
}
if (($qty = $orderedInventory->qty - $quantity) < 0)
$qty = 0;
$orderedInventory->update([
'qty' => $qty
]);
}
}

View File

@ -151,6 +151,10 @@ class RefundRepository extends Repository
'product_type' => $childOrderItem->product_type,
'additional' => $childOrderItem->additional
]);
$this->refundItemRepository->returnQtyToProductInventory($childOrderItem, $qty);
} else {
$this->refundItemRepository->returnQtyToProductInventory($orderItem, $qty);
}
$this->orderItemRepository->collectTotals($orderItem);
@ -180,29 +184,23 @@ class RefundRepository extends Repository
*/
public function collectTotals($refund)
{
$subTotal = $baseSubTotal = 0;
$taxAmount = $baseTaxAmount = 0;
$discountAmount = $baseDiscountAmount = 0;
$refund->sub_total = $refund->base_sub_total = 0;
$refund->tax_amount = $refund->base_tax_amount = 0;
$refund->discount_amount = $refund->base_discount_amount = 0;
foreach ($refund->items as $refundItem) {
$subTotal += $refundItem->total;
$baseSubTotal += $refundItem->base_total;
$refund->sub_total += $refundItem->total;
$refund->base_sub_total += $refundItem->base_total;
$taxAmount += $refundItem->tax_amount;
$baseTaxAmount += $refundItem->base_tax_amount;
$refund->tax_amount += $refundItem->tax_amount;
$refund->base_tax_amount += $refundItem->base_tax_amount;
$discountAmount += $refundItem->discount_amount;
$baseDiscountAmount += $refundItem->base_discount_amount;
$refund->discount_amount += $refundItem->discount_amount;
$refund->base_discount_amount += $refundItem->base_discount_amount;
}
$refund->sub_total = $subTotal;
$refund->base_sub_total = $baseSubTotal;
$refund->tax_amount = $taxAmount;
$refund->base_tax_amount = $baseTaxAmount;
$refund->grand_total = $subTotal + $taxAmount + $refund->shipping_amount + $refund->adjustment_refund - $refund->adjustment_fee - $discountAmount;
$refund->base_grand_total = $baseSubTotal + $baseTaxAmount + $refund->base_shipping_amount + $refund->base_adjustment_refund - $refund->adjustment_fee - $baseDiscountAmount;
$refund->grand_total = $refund->sub_total + $refund->tax_amount + $refund->shipping_amount + $refund->adjustment_refund - $refund->adjustment_fee - $refund->discount_amount;
$refund->base_grand_total = $refund->base_sub_total + $refund->base_tax_amount + $refund->base_shipping_amount + $refund->base_adjustment_refund - $refund->adjustment_fee - $refund->base_discount_amount;
$refund->save();

View File

@ -68,6 +68,7 @@
<td data-value="{{ __('shop::app.customer.account.order.view.SKU') }}">
{{ $item->type == 'configurable' ? $item->child->sku : $item->sku }}
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}">
{{ $item->name }} <br>
@if (isset($item['additional']['attributes']))
@ -76,7 +77,11 @@
@endforeach
@endif
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.price') }}">{{ core()->formatPrice($item->price, $order->order_currency_code) }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.price') }}">
{{ core()->formatPrice($item->price, $order->order_currency_code) }}
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.item-status') }}">
<span class="qty-row">
{{ __('shop::app.customer.account.order.view.item-ordered', ['qty_ordered' => $item->qty_ordered]) }}
@ -98,10 +103,22 @@
{{ $item->qty_canceled ? __('shop::app.customer.account.order.view.item-canceled', ['qty_canceled' => $item->qty_canceled]) : '' }}
</span>
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.subtotal') }}">{{ core()->formatPrice($item->total, $order->order_currency_code) }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.tax-percent') }}">{{ number_format($item->tax_percent, 2) }}%</td>
<td data-value="{{ __('shop::app.customer.account.order.view.tax-amount') }}">{{ core()->formatPrice($item->tax_amount, $order->order_currency_code) }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.grand-total') }}">{{ core()->formatPrice($item->total + $item->tax_amount, $order->order_currency_code) }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.subtotal') }}">
{{ core()->formatPrice($item->total, $order->order_currency_code) }}
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.tax-percent') }}">
{{ number_format($item->tax_percent, 2) }}%
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.tax-amount') }}">
{{ core()->formatPrice($item->tax_amount, $order->order_currency_code) }}
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.grand-total') }}">
{{ core()->formatPrice($item->total + $item->tax_amount - $item->discount_amount, $order->order_currency_code) }}
</td>
</tr>
@endforeach
</tbody>