Looking to export invoices from magento and import them into QuickBooks. It doesn't matter which version of QB but please reference Magento 1.9 solutions, if possible.
- Has anyone built a module for this?
- Are there extensions available?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityLooking to export invoices from magento and import them into QuickBooks. It doesn't matter which version of QB but please reference Magento 1.9 solutions, if possible.
I hope it will be useful
Here is /etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Sales\Model\Order\InvoiceRepository">
<plugin name="Company_quickbooks_plugin_sale_order_invoice"
type="Company\QuickBooks\Plugin\Sale\Order\InvoiceRepository"
sortOrder="2"/>
</type>
</config>
And Company\QuickBooks\Plugin\Sale\Order\InvoiceRepository.php
<?php
namespace Company\QuickBooks\Plugin\Sale\Order;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Sales\Api\OrderRepositoryInterface;
use Company\QuickBooks\Helper\Data;
class InvoiceRepository
{
/**
* @var Data
*/
protected $data;
/**
* @var OrderRepositoryInterface
*/
protected $orderRepository;
public function __construct(
Data $data,
OrderRepositoryInterface $orderRepository
)
{
$this->data = $data;
$this->orderRepository = $orderRepository;
}
public function afterSave($subject, $result)
{
$order = $this->orderRepository->get($result->getOrderId());
$idCustomer = $this->data->getIdCustomerQuick($order->getCustomerEmail(),$result->getOrderId());
foreach ($order->getAllVisibleItems() as $item) {
$idItem = $this->data->getIdItem($item->getSku());
$TaxCodeRef=$this->data->getTaxCodeRef($item->getSku());
$items[] = array("DetailType" => "SalesItemLineDetail", "SalesItemLineDetail" => array("TaxCodeRef" => array("value" => $TaxCodeRef), "ItemRef" => array("value" => $idItem), "Qty" => $item->getQtyInvoiced(), "UnitPrice" => $item->getPrice()), "Amount" => $item->getRowTotal());
}
$params = [
"DocNumber" => $result->getIncrementId(),
"CustomerRef" => [
"value" => $idCustomer
],
"Line" => $items,
"CurrencyRef" => [
"value" => $result->getOrderCurrencyCode(),
],
"ShipMethodRef" => [
"name" => $order->getShippingDescription(),
"value" => $order->getShippingDescription()
]
];
$this->data->postInvoice($params);
}
}
Company\QuickBooks\Helper\data.php
<?php
namespace Company\QuickBooks\Helper;
use Company\MagApi\Model\Requester;
use Company\QuickBooks\Model\Config;
use Magento\Framework\App\Helper\AbstractHelper as BaseAbstractHelper;
use Magento\Framework\App\Helper\Context;
use Zend\Http\Response;
use Magento\Framework\HTTP\Client\Curl;
use Magento\Sales\Api\OrderRepositoryInterface;
class Data extends BaseAbstractHelper
{
protected $Curl;
/**
* @var Config
*/
protected $config;
/**
* @var Requester
*/
protected $requester;
/**
* @var OrderRepositoryInterface
*/
protected $orderRepository;
/**
* AbstractHelper constructor.
* @param Context $context
* @param Config $config
* @param Curl $Curl
* @param Requester $requester
*/
public function __construct(
Context $context,
Config $config,
Curl $Curl,
OrderRepositoryInterface $orderRepository,
Requester $requester
) {
$this->config = $config;
$this->requester = $requester;
$this->orderRepository = $orderRepository;
$this->Curl = $Curl;
parent::__construct($context);
}
/**
* @param array $params
* @return Response
*/
public function postInvoice(array $params)
{
$token = $this->config->getToken();
$url = $this->config->getUrl();
$response = $this->requester
->setToken($token)
->post( $url, $params);
return $response;
}
}