Fix tax calculation for order refund
This commit is contained in:
parent
c1ac3d3a20
commit
e42fdc4c15
2 changed files with 18 additions and 7 deletions
|
|
@ -592,8 +592,11 @@ class ToolboxHelper
|
|||
'date' => $date,
|
||||
'documentType' => $documentType,
|
||||
'basket' => $invoiceBasketItems,
|
||||
'totalTtc' => $invoiceBasketItems->sum('subtotal'),
|
||||
'totalTaxes' => $invoiceBasketItems->sum('tax')
|
||||
'totalTtc' => \intval($invoiceBasketItems->sum('subtotal')),
|
||||
'totalTaxes' => \intval($invoiceBasketItems->sum(function (object $basketItem) {
|
||||
return ($basketItem->subtotal / abs($basketItem->subtotal)) *
|
||||
$basketItem->qty * $basketItem->tax;
|
||||
}))
|
||||
],
|
||||
[],
|
||||
[
|
||||
|
|
|
|||
|
|
@ -425,10 +425,17 @@ class Order extends Model
|
|||
*/
|
||||
public function getItemForOrderCancelling(): Collection
|
||||
{
|
||||
$remainingToRefund = \intval($this->transactions()
|
||||
->where('id', '!=', $this->id)->pluck('items')->sum(function ($items) {
|
||||
return \collect($items)->sum('subtotal');
|
||||
}));
|
||||
$itemsToRefund = $this->transactions()->where('id', '!=', $this->id)->pluck('items');
|
||||
$remainingToRefund = \intval($itemsToRefund->sum(function ($items) {
|
||||
return \collect($items)->sum('subtotal');
|
||||
}));
|
||||
$remainingTaxToRefund = \intval($itemsToRefund->sum(function ($items) {
|
||||
return \collect($items)->sum(function ($basketItem) {
|
||||
$basketItem = (object)$basketItem;
|
||||
return ($basketItem->subtotal / abs($basketItem->subtotal)) *
|
||||
$basketItem->qty * $basketItem->tax;
|
||||
});
|
||||
}));
|
||||
|
||||
// * Créer un dummy product pour représenter la transaction.
|
||||
$cartItemOptions = \array_merge(Controller::$cartItemOptionsSkel, [
|
||||
|
|
@ -441,7 +448,7 @@ class Order extends Model
|
|||
'name' => trans('Remboursement complet'),
|
||||
'price' => $remainingToRefund,
|
||||
'weight' => 0,
|
||||
'options' => $cartItemOptions
|
||||
'options' => $cartItemOptions,
|
||||
]);
|
||||
$cartItem->setQuantity(1);
|
||||
|
||||
|
|
@ -450,6 +457,7 @@ class Order extends Model
|
|||
$basketItem->price = $basketItem->price * -1;
|
||||
$basketItem->options->price_ttc = $basketItem->options->price_ttc * -1;
|
||||
$basketItem->subtotal = $basketItem->subtotal * -1;
|
||||
$basketItem->tax = $remainingTaxToRefund * -1;
|
||||
|
||||
return collect()->add($basketItem)->values();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue