Skip to content

Commit

Permalink
// now can reinject quantities on partial refund
Browse files Browse the repository at this point in the history
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@17758 b9a71923-0436-4b27-9f14-aed3839534dd
  • Loading branch information
rGaillard committed Oct 4, 2012
1 parent 6c98ff9 commit 4863e60
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@
<div style="clear:both; height:15px;">&nbsp;</div>
<div style="float: right; width: 160px; display: none;" class="standard_refund_fields">
{if ($order->hasBeenDelivered() && Configuration::get('PS_ORDER_RETURN'))}
<input type="checkbox" id="reinjectQuantities" name="reinjectQuantities" class="button" />&nbsp;<label for="reinjectQuantities" style="float:none; font-weight:normal;">{l s='Re-stock products'}</label><br />
<input type="checkbox" name="reinjectQuantities" class="button" />&nbsp;<label for="reinjectQuantities" style="float:none; font-weight:normal;">{l s='Re-stock products'}</label><br />
{/if}
{if ((!$order->hasBeenDelivered() && $order->hasBeenPaid()) || ($order->hasBeenDelivered() && Configuration::get('PS_ORDER_RETURN')))}
<input type="checkbox" id="generateCreditSlip" name="generateCreditSlip" class="button" onclick="toggleShippingCost(this)" />&nbsp;<label for="generateCreditSlip" style="float:none; font-weight:normal;">{l s='Generate a credit slip'}</label><br />
Expand All @@ -733,10 +733,9 @@
{/if}
</div>
<div style="float: right; width: 160px; display:none;" class="partial_refund_fields">
<div style="text-align:center; margin-top:5px;">
<input type="checkbox" id="generateDiscountRefund" name="generateDiscountRefund" class="button" onclick="toggleShippingCost(this)" />&nbsp;<label for="generateDiscount" style="float:none; font-weight:normal;">{l s='Generate a voucher'}</label><br />
<input type="submit" name="partialRefund" value="{l s='Partial refund'}" class="button" style="margin-top:8px;" />
</div>
<input type="checkbox" name="reinjectQuantities" class="button" />&nbsp;<label for="reinjectQuantities" style="float:none; font-weight:normal;">{l s='Re-stock products'}</label><br />
<input type="checkbox" id="generateDiscountRefund" name="generateDiscountRefund" class="button" onclick="toggleShippingCost(this)" />&nbsp;<label for="generateDiscount" style="float:none; font-weight:normal;">{l s='Generate a voucher'}</label><br />
<input type="submit" name="partialRefund" value="{l s='Partial refund'}" class="button" style="margin-top:8px;" />
</div>
</fieldset>
</form>
Expand Down
106 changes: 54 additions & 52 deletions controllers/admin/AdminOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ public function postProcess()
else
$order_detail_list[$id_order_detail]['amount'] = (float)str_replace(',', '.', $amount_detail);
$amount += $order_detail_list[$id_order_detail]['amount'];

$order_detail = new OrderDetail((int)$id_order_detail);
if (!$order->hasBeenDelivered() || ($order->hasBeenDelivered() && Tools::isSubmit('reinjectQuantities')) && $order_detail_list[$id_order_detail]['quantity'] > 0)
$this->reinjectQuantity($order_detail, $order_detail_list[$id_order_detail]['quantity']);
}

$shipping_cost_amount = (float)str_replace(',', '.', Tools::getValue('partialRefundShippingCost'));
Expand Down Expand Up @@ -638,58 +642,9 @@ public function postProcess()
$qty_cancel_product = abs($qtyList[$key]);
$order_detail = new OrderDetail((int)($id_order_detail));

// Reinject product
if (!$order->hasBeenDelivered() || ($order->hasBeenDelivered() && Tools::isSubmit('reinjectQuantities')))
{
$reinjectable_quantity = (int)$order_detail->product_quantity - (int)$order_detail->product_quantity_reinjected;
$quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product;

// @since 1.5.0 : Advanced Stock Management
$product_to_inject = new Product($order_detail->product_id, false, $this->context->language->id, $order->id_shop);

$product = new Product($order_detail->product_id);

if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
&& $product->advanced_stock_management
&& $order_detail->id_warehouse != 0)
{

$manager = StockManagerFactory::getManager();

$movements = StockMvt::getNegativeStockMvts(
$order_detail->id_order,
$order_detail->product_id,
$order_detail->product_attribute_id,
$quantity_to_reinject
);

foreach ($movements as $movement)
{
$manager->addProduct(
$order_detail->product_id,
$order_detail->product_attribute_id,
new Warehouse($movement['id_warehouse']),
$movement['physical_quantity'],
null,
$movement['price_te'],
true
);
}
StockAvailable::synchronize($order_detail->product_id);
}
else if ($order_detail->id_warehouse == 0)
{
StockAvailable::updateQuantity(
$order_detail->product_id,
$order_detail->product_attribute_id,
$quantity_to_reinject,
$order->id_shop
);
}
else
$this->errors[] = Tools::displayError('Cannot re-stock product');
}

if (!$order->hasBeenDelivered() || ($order->hasBeenDelivered() && Tools::isSubmit('reinjectQuantities')) && $qty_cancel_product > 0)
$this->reinjectQuantity($order_detail, $qty_cancel_product);

// Delete product
$order_detail = new OrderDetail((int)$id_order_detail);
if (!$order->deleteProduct($order, $order_detail, $qtyCancelProduct))
Expand Down Expand Up @@ -2180,6 +2135,53 @@ protected function getProducts($order)

return $products;
}

protected function reinjectQuantity($order_detail, $qty_cancel_product)
{
// Reinject product
$reinjectable_quantity = (int)$order_detail->product_quantity - (int)$order_detail->product_quantity_reinjected;
$quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product;
// @since 1.5.0 : Advanced Stock Management
$product_to_inject = new Product($order_detail->product_id, false, (int)$this->context->language->id, (int)$order_detail->id_shop);

$product = new Product($order_detail->product_id, false, (int)$this->context->language->id, (int)$order_detail->id_shop);

if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management && $order_detail->id_warehouse != 0)
{
$manager = StockManagerFactory::getManager();
$movements = StockMvt::getNegativeStockMvts(
$order_detail->id_order,
$order_detail->product_id,
$order_detail->product_attribute_id,
$quantity_to_reinject
);

foreach ($movements as $movement)
{
$manager->addProduct(
$order_detail->product_id,
$order_detail->product_attribute_id,
new Warehouse($movement['id_warehouse']),
$movement['physical_quantity'],
null,
$movement['price_te'],
true
);
}
StockAvailable::synchronize($order_detail->product_id);
}
elseif ($order_detail->id_warehouse == 0)
{
StockAvailable::updateQuantity(
$order_detail->product_id,
$order_detail->product_attribute_id,
$quantity_to_reinject,
$order_detail->id_shop
);
}
else
$this->errors[] = Tools::displayError('Cannot re-stock product');
}

protected function applyDiscountOnInvoice($order_invoice, $value_tax_incl, $value_tax_excl)
{
Expand Down

0 comments on commit 4863e60

Please sign in to comment.