Undo a wrong credit memo is not easy. Its defined within your order and the payments of that order.
Magento nests a lot of different things when it comes down to accounting.
Now when you reaalllyy want to do it the SQL command it accurate as far as i can see. I don't see anything you missed.
That was your question right? Just if something is wrong with your SQL command.
You can also do this by code if you want to know how.
Update :
Since i don't know how good you can code or what you need to know i will start with explaning the basics. Magento is devided in a Theme and Modules. Modules you can find in the app/code
folder or the vendor/
folder.
The app/code folder is when you want to create your own module. If you require a module with composer
(ssh command : composer require ....
) it will appear in the vendor folder.
Also all the magento files (magento is build on modules only) you will find in vendor/magento.
Now that you know that we want to create a module. I will not explain that part since this has been explained 1000 times before :
http://devdocs.magento.com/videos/fundamentals/create-a-new-module/
When you made that you want to add something that you can call that will perform an action. Lets say we want to make a page where we want to fill in a number and it deletes the credit memo for us.
We can make pages in modules with controllers. This is done within the app/code/Vendor/Namespace/Controller
folder.
http://devdocs.magento.com/videos/fundamentals/create-a-new-page/
You can follow this link to see how its made exactly. Now within this controller you have an execute function. You can make an input field where you put the credit memo number in and use a form submit to trigger this page (<form action="url.extension/newpage">
) and within this execute you can do a number of things.
I suggest you use a new fille in your controller and put that new file in your Model
folder. Within that fille you can use the Magento\Sales\Model\Order\Creditmemo
(lets give this variable $creditmemo) to adjust the credit memo settings. You will need to use Magento\Sales\Api\CreditmemoRepositoryInterface
to getlist()
with searchcriteria to find your Creditmemo and then use the ->save($creditmemo)
function to save it or ->delete()
to delete it.
The same logics is applied to Orders. I will show you how i do it with orders (and you will need to update this field to).
How to use the getlist()
with search functions you can find in my answer here :
Search by color
Now how i load , adjust and save an order with the repository interface :
Notice how i use the interfaceFactory. This fille does not exist but is generated within your /generated
or /var/generation
folders and allows you to create a separate instance :
<?
namespace Vendor\Namespace\...
use Magento\Sales\Api\Data\OrderInterfaceFactory;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model;
public function __construct(
OrderInterfaceFactory $orderinterface,
OrderRepositoryInterface $orderrepository,
Model\OrderFactory $order,
)
{
$this->_magentoorder = $orderinterface;
$this->_orderrepository = $orderrepository;
$this->_order = $order;
}
public function UpdateOrders(){
$orderrep = $this->_orderrepository;
$order = $this->_order->create();
/**
* @var $order \Magento\Sales\Model\Order;
*
*/
$order
->setOrderCurrencyCode($ex_order['Currency'])
->setCreatedAt(preg_replace('/[^0-9.]+/', '', $ex_order['OrderDate']) / 1000)
->setStoreId(1)
->setBaseCurrencyCode($this->_storeManager->getStore(1)->getCurrentCurrencyCode())
->setStoreCurrencyCode($this->_storeManager->getStore(1)->getCurrentCurrencyCode())
->setIncrementId($ex_order['OrderNumber'])
->setCustomerId($customerid)
->setCustomerFirstname($customerfirstname)
->setCustomerLastname($customerlastname)
->setCustomerEmail($customeremail)
->setBillingAddress($billingaddress)
->setShippingAddress($deliveryaddress)
->setBaseDiscountAmount($ex_order['TotalExclVatDiscount'] * $orderrate)
->setDiscountAmount($ex_order['TotalExclVatDiscount'])
->setTaxAmount($ex_order['TotalInclVat'] - $ex_order['TotalExclVat'])
->setBaseSubtotal($ex_order['TotalExclVat'] * $orderrate)
->setSubtotal($ex_order['TotalExclVat'])
->setBaseGrandTotal($ex_order['TotalInclVat'] * $orderrate)
->setGrandTotal($ex_order['TotalInclVat'])
->setShippingInclTax(0)
->setShippingAmount(0)
->setBaseShippingAmount(0)
->setBaseShippingInclTax(0)
->setPayment($orderpayment);
$orderrep->save($order);
}
Now again this is just an example how to work with those.
You can do $orderep->getlist($searchcriteria);
to get the order you want (same logics for credit memo's)
Now again i'm not sure how good your understanding of magento and php is so this all can be very confusing for you. I'm afraid explaining everything in detail will require me to write even more explenation about this. If you want you can always PM me so i can help you out or make it for you.