FormController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. namespace Controller;
  3. class FormController
  4. {
  5. public function getForm($db, $language)
  6. {
  7. $data = array();
  8. $settingsRepository = new \MarketplaceRepository\SettingsRepository($db);
  9. $settingsService = new \Core\App\Service\SettingsService(
  10. $settingsRepository
  11. );
  12. $data['title'] = $language->get('title');
  13. $data['description'] = $language->get('description');
  14. //tab1
  15. $data['tab_name_1'] = $language->get('tab_name_1');
  16. $data['tab_description_1'] = $language->get('tab_description_1');
  17. $dataTypes = $settingsService->getSyncDataTypes();
  18. $data['dataTypes'] = array(array('id' => '', 'label' => $language->get('data_type')));
  19. if(!empty($dataTypes))
  20. {
  21. foreach($dataTypes as $dataType)
  22. {
  23. $data['dataTypes'][] = array('id' => $dataType, 'label' => $language->get($dataType));
  24. }
  25. }
  26. sort($data['dataTypes']);
  27. $data['sync_btn'] = $language->get('sync_btn');
  28. $data['download_btn'] = $language->get('download_btn');
  29. $data['clear_btn'] = $language->get('clear_btn');
  30. $data['datatype_error'] = $language->get('datatype_error');
  31. $data['authform_error'] = $language->get('authform_error');
  32. $data['sync_please_wait'] = $language->get('sync_please_wait');
  33. $data['download_log_error_1'] = $language->get('download_log_error_1');
  34. $data['download_log_error_2'] = $language->get('download_log_error_2');
  35. $data['select_text'] = $language->get('select_text');
  36. //tab 2
  37. $data['tab_name_2'] = $language->get('tab_name_2');
  38. $data['tab_description_2'] = $language->get('tab_description_2');
  39. $data['auth_apikey'] = $language->get('auth_api_key');
  40. $data['auth_username'] = $language->get('auth_username');
  41. $data['auth_password'] = $language->get('auth_password');
  42. $data['auth_fiscalcode'] = $language->get('auth_fiscal_code');
  43. $data['auth_apikey_error'] = $language->get('auth_apikey_error');
  44. $data['auth_username_error'] = $language->get('auth_username_error');
  45. $data['auth_password_error'] = $language->get('auth_password_error');
  46. $data['auth_fiscalcode_error'] = $language->get('auth_fiscalcode_error');
  47. $data['save_btn'] = $language->get('save_btn');
  48. //tab 3
  49. $data['tab_name_3'] = $language->get('tab_name_3');
  50. $data['tab_name_3_1'] = $language->get('tab_name_3_1');
  51. $data['tab_name_3_2'] = $language->get('tab_name_3_2');
  52. $data['proforma_invoice_options_title'] = $language->get('proforma_invoice_options_title');
  53. $data['add_proforma'] = $language->get('add_proforma');
  54. $data['add_avize'] = $language->get('add_avize');
  55. $data['add_expfactura'] = $language->get('add_expfactura');
  56. $data['with_discount'] = $language->get('with_discount');
  57. $data['with_discount_desc'] = $language->get('with_discount_desc');
  58. $data['add_invoice'] = $language->get('add_invoice');
  59. $data['view_proforma'] = $language->get('view_proforma');
  60. $data['view_invoice'] = $language->get('view_invoice');
  61. $data['view_avize'] = $language->get('view_avize');
  62. $data['view_expfactura'] = $language->get('view_expfactura');
  63. $data['edit_proforma'] = $language->get('edit_proforma');
  64. $data['edit_invoice'] = $language->get('edit_invoice');
  65. $data['edit_avize'] = $language->get('edit_avize');
  66. $data['edit_expfactura'] = $language->get('edit_expfactura');
  67. $data['fosync_proforma_series2_label'] = $language->get('fosync_proforma_series2_label');
  68. $data['fosync_invoice_series_label'] = $language->get('fosync_invoice_series_label');
  69. $data['fosync_avize_series2_label'] = $language->get('fosync_avize_series2_label');
  70. $data['fosync_expfactura_series2_label'] = $language->get('fosync_expfactura_series2_label');
  71. //tab4
  72. $data['tab_name_4'] = $language->get('tab_name_4');
  73. //tab 5
  74. $data['tab_name_5'] = $language->get('tab_name_5');
  75. $data['datepicker'] = $language->get('datepicker');
  76. $data['tab_description_5_1'] = $language->get('tab_description_5_1');
  77. $data['tab_description_5_2'] = $language->get('tab_description_5_2');
  78. $data['confirm_clear_log'] = $language->get('confirm_clear_log');
  79. $syncOrdersAs = $settingsService->getSyncOrdersAs();
  80. $data['syncOrdersAs'] = array();
  81. if(!empty($syncOrdersAs))
  82. {
  83. foreach($syncOrdersAs as $syncOrdersAsElement)
  84. {
  85. $data['syncOrdersAs'][] = array('id' => $syncOrdersAsElement, 'label' => $language->get($syncOrdersAsElement));
  86. }
  87. }
  88. $data['sync_orders_as'] = $language->get('sync_orders_as');
  89. $data['proforma_series'] = $language->get('proforma_series');
  90. $data['avize_series'] = $language->get('avize_series');
  91. $data['expfactura_series'] = $language->get('expfactura_series');
  92. $data['days_ago'] = $language->get('days_ago');
  93. $data['auto_order_sync'] = $language->get('auto_order_sync');
  94. $data['auto_stock_sync'] = $language->get('auto_stock_sync');
  95. $autoSyncOptions = $settingsService->getAutoSyncOptions();
  96. $data['autoSyncOptions'] = array();
  97. if(!empty($autoSyncOptions))
  98. {
  99. foreach($autoSyncOptions as $autoSyncOptionsElement)
  100. {
  101. $data['autoSyncOptions'][] = array('id' => $autoSyncOptionsElement, 'label' => $language->get($autoSyncOptionsElement));
  102. }
  103. }
  104. $data['shopLocations'] = $this->getShopLocations($settingsRepository);
  105. $data['locations'] = $language->get('locations');
  106. $enabledDisabledOptions = $settingsService->getEnabledDisabledOptions();
  107. $data['withDiscountOptions'] = array();
  108. if(!empty($enabledDisabledOptions))
  109. {
  110. foreach($enabledDisabledOptions as $enabledDisabledOption)
  111. {
  112. $data['withDiscountOptions'][] = array('id' => $enabledDisabledOption, 'label' => $language->get($enabledDisabledOption));
  113. }
  114. }
  115. $data['filter_stock'] = $language->get('filter_stock');
  116. $data['filter_pdls'] = $language->get('filter_pdls');
  117. $data['loading_data_please_wait'] = $language->get('loading_data_please_wait');
  118. $data['option_proformaserie_error'] = $language->get('option_proformaserie_error');
  119. $data['option_avizeserie_error'] = $language->get('option_avizeserie_error');
  120. $data['option_expfacturaserie_error'] = $language->get('option_expfacturaserie_error');
  121. $data['option_daysago_error'] = $language->get('option_daysago_error');
  122. $data['version_text'] = $language->get('version_text');
  123. $data['option'] = $settingsService->getOptions();
  124. $data['auth'] = $settingsService->getAuth();
  125. $data['version_number'] = $settingsService->getVersion();
  126. $data['version_link'] = $settingsService->getVersionLink();
  127. $data['check_latest_version'] = $language->get('check_latest_version');
  128. //tutorials
  129. $data['tutorial_title'] = $language->get('tutorial_title');
  130. $data['tutorial_p'] = $language->get('tutorial_p');
  131. $data['tutorial_1'] = $language->get('tutorial_1');
  132. $data['tutorial_2'] = $language->get('tutorial_2');
  133. $data['tutorial_3'] = $language->get('tutorial_3');
  134. $data['tutorial_4'] = $language->get('tutorial_4');
  135. $data['show_tutorial'] = $settingsService->showTutorial();
  136. $data['authform_error'] = $language->get('authform_error');
  137. return $data;
  138. }
  139. public function testAuth($db)
  140. {
  141. $this->settingsRepository = new \MarketplaceRepository\SettingsRepository($db);
  142. $settingsService = new \Core\App\Service\SettingsService(
  143. $this->settingsRepository
  144. );
  145. $remoteStockRepository = new \Core\FacturisRepository\StockRepository(
  146. $_GET['fsync_auth_apikey'],
  147. $_GET['fsync_auth_username'],
  148. $_GET['fsync_auth_password'],
  149. $_GET['fsync_auth_fiscalcode']
  150. );
  151. $settingsService->testAuth($remoteStockRepository);
  152. }
  153. public function getPdlGestiuni($db, $language)
  154. {
  155. $settingsRepository = new \MarketplaceRepository\SettingsRepository($db);
  156. $settingsService = new \Core\App\Service\SettingsService(
  157. $settingsRepository
  158. );
  159. $remoteStockRepository = new \Core\FacturisRepository\StockRepository(
  160. $settingsRepository->getAuthApiKey(),
  161. $settingsRepository->getAuthUsername(),
  162. $settingsRepository->getAuthPassword(),
  163. $settingsRepository->getAuthFiscalCode()
  164. );
  165. $pdl_gestiuni = $settingsService->getPdlGestiuni($remoteStockRepository);
  166. $result = '';
  167. $result .= '<option value=""';
  168. $result .= (isset($_GET['fsync_option_filterstock']) && $_GET['fsync_option_filterstock'] == '') ? ' selected="selected" ' : '';
  169. $result .= ' >' . $language->get('filter_stock_all') . '</option>';
  170. if(!empty($pdl_gestiuni))
  171. {
  172. foreach($pdl_gestiuni as $pdl_gestiune)
  173. {
  174. $result .= '<option value=' . $pdl_gestiune['id'] . ' ';
  175. $result .= (isset($_GET['fsync_option_filterstock']) && $_GET['fsync_option_filterstock'] == $pdl_gestiune['id']) ? ' selected="selected" ' : '';
  176. $result .= ' >' . $pdl_gestiune['name'] . '</option>';
  177. }
  178. }
  179. echo $result;
  180. }
  181. public function checkLatestVersion($db, $language)
  182. {
  183. $settingsRepository = new \MarketplaceRepository\SettingsRepository($db);
  184. $settingsService = new \Core\App\Service\SettingsService(
  185. $settingsRepository
  186. );
  187. $settingsService->checkLatestVersion($language);
  188. }
  189. private function getShopLocations($settingsRepository)
  190. {
  191. $marketplaceStockRepository = new \MarketplaceRepository\StockRepository(
  192. $settingsRepository->getToken(),
  193. $settingsRepository->getShop()
  194. );
  195. return $marketplaceStockRepository->getShopLocations();
  196. }
  197. }