InvoiceService.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * 2007-2021 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Academic Free License (AFL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/afl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@prestashop.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <contact@prestashop.com>
  22. * @copyright 2007-2021 PrestaShop SA
  23. * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
  24. * International Registered Trademark & Property of PrestaShop SA
  25. */
  26. namespace Core\App\Service;
  27. class InvoiceService
  28. {
  29. protected $marketplaceInvoiceRepository;
  30. protected $marketplaceProductRepository;
  31. protected $facturisInvoiceRepository;
  32. protected $facturisCustomerRepository;
  33. protected $facturisProductRepository;
  34. protected $settingsRepository;
  35. public function __construct(
  36. \Core\App\Repository\Marketplace\InvoiceInterface $marketplaceInvoiceRepository,
  37. \Core\App\Repository\Marketplace\ProductInterface $marketplaceProductRepository,
  38. \Core\App\Repository\Facturis\CustomerInterface $facturisCustomerRepository,
  39. \Core\App\Repository\Facturis\ProductInterface $facturisProductRepository,
  40. \Core\App\Repository\Facturis\InvoiceInterface $facturisInvoiceRepository,
  41. \Core\App\Repository\Marketplace\SettingsInterface $settingsRepository
  42. ) {
  43. $this->marketplaceInvoiceRepository = $marketplaceInvoiceRepository;
  44. $this->marketplaceProductRepository = $marketplaceProductRepository;
  45. $this->facturisInvoiceRepository = $facturisInvoiceRepository;
  46. $this->facturisCustomerRepository = $facturisCustomerRepository;
  47. $this->facturisProductRepository = $facturisProductRepository;
  48. $this->settingsRepository = $settingsRepository;
  49. }
  50. public function add($orderId)
  51. {
  52. $facturisCustomers = $this->facturisCustomerRepository->getAll();
  53. $facturisProducts = $this->facturisProductRepository->getAll();
  54. $this->marketplaceInvoiceRepository->setRemoteCustomers($facturisCustomers);
  55. $this->marketplaceInvoiceRepository->setRemoteProducts($facturisProducts);
  56. /*if(!empty($series))
  57. {
  58. $this->marketplaceInvoiceRepository->setInvoiceSerie($series);
  59. }
  60. else
  61. {
  62. $this->marketplaceInvoiceRepository->setInvoiceSerie($this->settingsRepository->getOptionProformaSerie());
  63. }*/
  64. $this->marketplaceInvoiceRepository->setInvoiceSerie($this->settingsRepository->getOptionInvoiceSerie());
  65. $withOutDiscount = true;
  66. $marketplaceProducts = $this->marketplaceProductRepository->getAll($withOutDiscount);
  67. $this->marketplaceInvoiceRepository->setLocalProducts((array) $marketplaceProducts);
  68. $this->marketplaceInvoiceRepository->setWithDiscount($this->settingsRepository->getOptionWithDiscount());
  69. $marketplaceInvoice = $this->marketplaceInvoiceRepository->getByOrderId($orderId);
  70. if (!empty($marketplaceInvoice)) {
  71. $result = $this->facturisInvoiceRepository->add($marketplaceInvoice);
  72. // $this->marketplaceInvoiceRepository->addInvoice($marketplaceInvoice, $result);
  73. return $result;
  74. }
  75. }
  76. }