1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
<?php
/* --------------------------------------------------------------
InvoicesModalsAjaxController.inc.php 2016-10-13
Gambio GmbH
http://www.gambio.de
Copyright (c) 2016 Gambio GmbH
Released under the GNU General Public License (Version 2)
[http://www.gnu.org/licenses/gpl-2.0.html]
--------------------------------------------------------------
*/
/**
* Class InvoicesModalsAjaxController
*
* AJAX controller for the invoices modals.
*
* @category System
* @package AdminHttpViewControllers
* @extends AdminHttpViewController
*/
class InvoicesModalsAjaxController extends AdminHttpViewController
{
/**
* @var InvoiceArchiveReadService
*/
protected $invoiceArchiveReadService;
/**
* @var InvoiceArchiveWriteService
*/
protected $invoiceArchiveWriteService;
/**
* @var OrderReadService
*/
protected $orderReadService;
/**
* Initialize Controller
*
* @throws Exception
*/
public function init()
{
$this->_validatePageToken();
$this->invoiceArchiveReadService = StaticGXCoreLoader::getService('InvoiceArchiveRead');
$this->invoiceArchiveWriteService = StaticGXCoreLoader::getService('InvoiceArchiveWrite');
$this->orderReadService = StaticGXCoreLoader::getService('OrderRead');
}
/**
* Delete Invoices Callback
*
* This method expects a "selectedInvoices" POST value which must contain the IDs of the invoices to be deleted.
*
* @return JsonHttpControllerResponse
*
* @throws InvalidArgumentException
*/
public function actionDeleteInvoice()
{
$invoiceIds = $this->_getPostData('selectedInvoices') ? : [];
$orderFormat = MainFactory::create('GMOrderFormat');
foreach($invoiceIds as $invoiceId)
{
$invoiceListItem = $this->invoiceArchiveReadService->getInvoiceListItemById(new IdType($invoiceId));
$orderFormat->delete_id('invoice', $invoiceListItem->getInvoiceNumber());
$this->invoiceArchiveWriteService->deleteInvoiceById(new IdType($invoiceId));
}
return MainFactory::create('JsonHttpControllerResponse', []);
}
/**
* Download Bulk Invoices PDF.
*
* This method will provide a concatenated file of invoice PDFs. Provide a GET parameter "i" that contain
* the selected invoice IDs.
*
* Notice: The "i" is used instead of "invoiceIds" because the final URL must be as small as possible (some
* browsers do not work with GET URL of 100 invoices).
*
* @see InvoiceActions
*/
public function actionBulkPdfInvoices()
{
$invoiceActions = MainFactory::create('InvoiceActions');
$invoiceIds = $this->_getQueryParameter('i');
$invoiceActions->bulkPdfInvoices($invoiceIds);
}
/**
* Get Email Invoice Information
*
* This method will provide the required email-invoice information to the modal JS controller. The subject
* will have to be parsed in frontend with JavaScript.
*
* Provide a GET "o" parameter with the selected order numbers.
*
* @return JsonHttpControllerResponse
*/
public function actionGetEmailInvoiceInformation()
{
$response = [
'subject' => gm_get_content('GM_PDF_EMAIL_SUBJECT', $_SESSION['languages_id']),
'emails' => []
];
$orderIds = $this->_getQueryParameter('o') ?: [];
foreach($orderIds as $orderId)
{
$orders = $this->orderReadService->filterOrderList(['number' => $orderId]);
$email = $orders->count() ? $orders->getItem(0)->getCustomerEmail() : '';
if($email)
{
$response['emails'][$orderId] = $email;
}
}
return MainFactory::create('JsonHttpControllerResponse', $response);
}
}