SyncController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace Controller;
  3. class SyncController
  4. {
  5. public $language;
  6. const TIME_LIMIT = 18000;
  7. public function __construct($db, $language, $shop = '')
  8. {
  9. set_time_limit( self::TIME_LIMIT );
  10. $this->language = $language;
  11. $this->settingsRepository = new \MarketplaceRepository\SettingsRepository($db, $shop);
  12. }
  13. public function sync()
  14. {
  15. if(isset($_POST['fsync_datatype']))
  16. {
  17. switch($_POST['fsync_datatype'])
  18. {
  19. case 'product': $result = $this->syncProduct();break;
  20. case 'order': $result = $this->syncOrderOrProforma();break;
  21. case 'stock': $result = $this->syncStock();break;
  22. default: $result = '';break;
  23. }
  24. }
  25. else
  26. {
  27. $result = '';
  28. }
  29. return $result;
  30. }
  31. public function syncProduct()
  32. {
  33. $controller = new \Controller\ProductController(
  34. $this->settingsRepository
  35. );
  36. $controller->sync();
  37. return $this->language->get('success_sync_prod');
  38. }
  39. public function syncOrderOrProforma()
  40. {
  41. $controller = new \Controller\OrderOrProformaController(
  42. $this->settingsRepository
  43. );
  44. $response = $controller->sync();
  45. if($response == \Core\App\Factory\SettingsFactory::SELECT_ORDER)
  46. {
  47. return $this->language->get('success_sync_order');
  48. }
  49. if($response == \Core\App\Factory\SettingsFactory::SELECT_PROFORMA)
  50. {
  51. return $this->language->get('success_sync_proforma');
  52. }
  53. if ($response == \Core\App\Factory\SettingsFactory::SELECT_EXPFACTURA) {
  54. return $this->language->get('success_sync_expfactura');
  55. }
  56. if ($response == \Core\App\Factory\SettingsFactory::SELECT_AVIZE) {
  57. return $this->language->get('success_sync_avize');
  58. }
  59. }
  60. public function syncStock()
  61. {
  62. $controller = new \Controller\StockController(
  63. $this->settingsRepository
  64. );
  65. $controller->sync();
  66. return $this->language->get('success_sync_stock');
  67. }
  68. public function autoSync()
  69. {
  70. $orderController = new \Controller\OrderOrProformaController(
  71. $this->settingsRepository
  72. );
  73. $stockController = new \Controller\StockController(
  74. $this->settingsRepository
  75. );
  76. $orderController->autoSync();
  77. $stockController->autoSync();
  78. }
  79. public function addProforma($orderId)
  80. {
  81. $controller = new \Controller\OrderOrProformaController(
  82. $this->settingsRepository
  83. );
  84. $result = $controller->addProforma($orderId);
  85. if (isset($result['serie_fact']) && isset($result['numar_fact'])) {
  86. return $this->language->get(
  87. 'success_add_proforma_a',
  88. array($result['serie_fact'], $result['numar_fact'], $orderId)
  89. );
  90. } else {
  91. return $this->language->get('success_add_proforma_b', array($orderId));
  92. }
  93. }
  94. public function viewProforma($orderId)
  95. {
  96. $controller = new \Controller\OrderOrProformaController(
  97. $this->settingsRepository
  98. );
  99. $controller->viewProforma($orderId);
  100. }
  101. public function addInvoice($orderId)
  102. {
  103. $controller = new \Controller\OrderOrProformaController(
  104. $this->settingsRepository
  105. );
  106. $result = $controller->addInvoice($orderId);
  107. if (isset($result['serie_fact']) && isset($result['numar_fact'])) {
  108. return $this->language->get(
  109. 'success_add_invoice_a',
  110. array($result['serie_fact'], $result['numar_fact'], $orderId)
  111. );
  112. } else {
  113. return $this->language->get('success_add_invoice_b', array($orderId));
  114. }
  115. }
  116. public function viewInvoice($orderId)
  117. {
  118. $controller = new \Controller\OrderOrProformaController(
  119. $this->settingsRepository
  120. );
  121. $controller->viewInvoice($orderId);
  122. }
  123. }