OrderOrProformaController.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <?php
  2. namespace Controller;
  3. class OrderOrProformaController
  4. {
  5. public $marketplaceOrders;
  6. public $settingsRepository;
  7. public function __construct($settingsRepository)
  8. {
  9. $this->settingsRepository = $settingsRepository;
  10. }
  11. public function sync()
  12. {
  13. if($this->settingsRepository->getOptionOrderOrProforma() == \Core\App\Factory\SettingsFactory::SELECT_ORDER)
  14. {
  15. $this->syncOrders();
  16. return \Core\App\Factory\SettingsFactory::SELECT_ORDER;
  17. }
  18. if($this->settingsRepository->getOptionOrderOrProforma() == \Core\App\Factory\SettingsFactory::SELECT_PROFORMA)
  19. {
  20. $this->syncProformas();
  21. return \Core\App\Factory\SettingsFactory::SELECT_PROFORMA;
  22. }
  23. if ($this->settingsRepository->getOptionOrderOrProforma() == \Core\App\Factory\SettingsFactory::SELECT_EXPFACTURA) {
  24. $this->syncExpfactura();
  25. return \Core\App\Factory\SettingsFactory::SELECT_EXPFACTURA;
  26. }
  27. if ($this->settingsRepository->getOptionOrderOrProforma() == \Core\App\Factory\SettingsFactory::SELECT_AVIZE) {
  28. $this->syncAvize();
  29. return \Core\App\Factory\SettingsFactory::SELECT_AVIZE;
  30. }
  31. }
  32. public function syncOrders()
  33. {
  34. $facturisCustomerRepository = new \Core\FacturisRepository\CustomerRepository(
  35. $this->settingsRepository->getAuthApiKey(),
  36. $this->settingsRepository->getAuthUsername(),
  37. $this->settingsRepository->getAuthPassword(),
  38. $this->settingsRepository->getAuthFiscalCode()
  39. );
  40. $facturisProductRepository = new \Core\FacturisRepository\ProductRepository(
  41. $this->settingsRepository->getAuthApiKey(),
  42. $this->settingsRepository->getAuthUsername(),
  43. $this->settingsRepository->getAuthPassword(),
  44. $this->settingsRepository->getAuthFiscalCode()
  45. );
  46. $marketplaceOrderRepository = new \MarketplaceRepository\OrderRepository(
  47. $this->settingsRepository->getToken(),
  48. $this->settingsRepository->getShop()
  49. );
  50. $marketplaceProductRepository = new \MarketplaceRepository\ProductRepository(
  51. $this->settingsRepository->getToken(),
  52. $this->settingsRepository->getShop()
  53. );
  54. $facturisOrderRepository = new \Core\FacturisRepository\OrderRepository(
  55. $this->settingsRepository->getAuthApiKey(),
  56. $this->settingsRepository->getAuthUsername(),
  57. $this->settingsRepository->getAuthPassword(),
  58. $this->settingsRepository->getAuthFiscalCode()
  59. );
  60. $service = new \Core\App\Service\OrderService(
  61. $marketplaceOrderRepository,
  62. $marketplaceProductRepository,
  63. $facturisCustomerRepository,
  64. $facturisProductRepository,
  65. $facturisOrderRepository,
  66. $this->settingsRepository
  67. );
  68. $service->sync();
  69. }
  70. public function syncProformas()
  71. {
  72. $facturisCustomerRepository = new \Core\FacturisRepository\CustomerRepository(
  73. $this->settingsRepository->getAuthApiKey(),
  74. $this->settingsRepository->getAuthUsername(),
  75. $this->settingsRepository->getAuthPassword(),
  76. $this->settingsRepository->getAuthFiscalCode()
  77. );
  78. $facturisProductRepository = new \Core\FacturisRepository\ProductRepository(
  79. $this->settingsRepository->getAuthApiKey(),
  80. $this->settingsRepository->getAuthUsername(),
  81. $this->settingsRepository->getAuthPassword(),
  82. $this->settingsRepository->getAuthFiscalCode()
  83. );
  84. $marketplaceProformaRepository = new \MarketplaceRepository\ProformaRepository(
  85. $this->settingsRepository->getToken(),
  86. $this->settingsRepository->getShop()
  87. );
  88. $marketplaceProductRepository = new \MarketplaceRepository\ProductRepository(
  89. $this->settingsRepository->getToken(),
  90. $this->settingsRepository->getShop()
  91. );
  92. $facturisProformaRepository = new \Core\FacturisRepository\ProformaRepository(
  93. $this->settingsRepository->getAuthApiKey(),
  94. $this->settingsRepository->getAuthUsername(),
  95. $this->settingsRepository->getAuthPassword(),
  96. $this->settingsRepository->getAuthFiscalCode()
  97. );
  98. $service = new \Core\App\Service\ProformaService(
  99. $marketplaceProformaRepository,
  100. $marketplaceProductRepository,
  101. $facturisCustomerRepository,
  102. $facturisProductRepository,
  103. $facturisProformaRepository,
  104. $this->settingsRepository
  105. );
  106. $service->sync();
  107. }
  108. public function syncAvize()
  109. {
  110. $facturisCustomerRepository = new \Core\FacturisRepository\CustomerRepository(
  111. $this->settingsRepository->getAuthApiKey(),
  112. $this->settingsRepository->getAuthUsername(),
  113. $this->settingsRepository->getAuthPassword(),
  114. $this->settingsRepository->getAuthFiscalCode()
  115. );
  116. $facturisProductRepository = new \Core\FacturisRepository\ProductRepository(
  117. $this->settingsRepository->getAuthApiKey(),
  118. $this->settingsRepository->getAuthUsername(),
  119. $this->settingsRepository->getAuthPassword(),
  120. $this->settingsRepository->getAuthFiscalCode()
  121. );
  122. $marketplaceAvizeRepository = new \MarketplaceRepository\AvizeRepository(
  123. $this->settingsRepository->getToken(),
  124. $this->settingsRepository->getShop()
  125. );
  126. $marketplaceProductRepository = new \MarketplaceRepository\ProductRepository(
  127. $this->settingsRepository->getToken(),
  128. $this->settingsRepository->getShop()
  129. );
  130. $facturisAvizeRepository = new \Core\FacturisRepository\AvizeRepository(
  131. $this->settingsRepository->getAuthApiKey(),
  132. $this->settingsRepository->getAuthUsername(),
  133. $this->settingsRepository->getAuthPassword(),
  134. $this->settingsRepository->getAuthFiscalCode()
  135. );
  136. $service = new \Core\App\Service\AvizeService(
  137. $marketplaceAvizeRepository,
  138. $marketplaceProductRepository,
  139. $facturisCustomerRepository,
  140. $facturisProductRepository,
  141. $facturisAvizeRepository,
  142. $this->settingsRepository
  143. );
  144. $service->sync();
  145. }
  146. public function syncExpfactura()
  147. {
  148. $facturisCustomerRepository = new \Core\FacturisRepository\CustomerRepository(
  149. $this->settingsRepository->getAuthApiKey(),
  150. $this->settingsRepository->getAuthUsername(),
  151. $this->settingsRepository->getAuthPassword(),
  152. $this->settingsRepository->getAuthFiscalCode()
  153. );
  154. $facturisProductRepository = new \Core\FacturisRepository\ProductRepository(
  155. $this->settingsRepository->getAuthApiKey(),
  156. $this->settingsRepository->getAuthUsername(),
  157. $this->settingsRepository->getAuthPassword(),
  158. $this->settingsRepository->getAuthFiscalCode()
  159. );
  160. $marketplaceExpfacturaRepository = new \MarketplaceRepository\ExpfacturaRepository(
  161. $this->settingsRepository->getToken(),
  162. $this->settingsRepository->getShop()
  163. );
  164. $marketplaceProductRepository = new \MarketplaceRepository\ProductRepository(
  165. $this->settingsRepository->getToken(),
  166. $this->settingsRepository->getShop()
  167. );
  168. $facturisExpfacturaRepository = new \Core\FacturisRepository\ExpfacturaRepository(
  169. $this->settingsRepository->getAuthApiKey(),
  170. $this->settingsRepository->getAuthUsername(),
  171. $this->settingsRepository->getAuthPassword(),
  172. $this->settingsRepository->getAuthFiscalCode()
  173. );
  174. $service = new \Core\App\Service\ExpfacturaService(
  175. $marketplaceExpfacturaRepository,
  176. $marketplaceProductRepository,
  177. $facturisCustomerRepository,
  178. $facturisProductRepository,
  179. $facturisExpfacturaRepository,
  180. $this->settingsRepository
  181. );
  182. $service->sync();
  183. }
  184. public function autoSync()
  185. {
  186. if($this->settingsRepository->getOptionAutoOrderSync() == \Core\App\Factory\SettingsFactory::AUTO_SYNC_ENABLED)
  187. {
  188. $this->sync();
  189. }
  190. }
  191. public function addProforma($orderId)
  192. {
  193. $facturisCustomerRepository = new \Core\FacturisRepository\CustomerRepository(
  194. $this->settingsRepository->getAuthApiKey(),
  195. $this->settingsRepository->getAuthUsername(),
  196. $this->settingsRepository->getAuthPassword(),
  197. $this->settingsRepository->getAuthFiscalCode()
  198. );
  199. $facturisProductRepository = new \Core\FacturisRepository\ProductRepository(
  200. $this->settingsRepository->getAuthApiKey(),
  201. $this->settingsRepository->getAuthUsername(),
  202. $this->settingsRepository->getAuthPassword(),
  203. $this->settingsRepository->getAuthFiscalCode()
  204. );
  205. $marketplaceProformaRepository = new \MarketplaceRepository\ProformaRepository(
  206. $this->settingsRepository->getToken(),
  207. $this->settingsRepository->getShop()
  208. );
  209. $marketplaceProductRepository = new \MarketplaceRepository\ProductRepository(
  210. $this->settingsRepository->getToken(),
  211. $this->settingsRepository->getShop()
  212. );
  213. $facturisProformaRepository = new \Core\FacturisRepository\ProformaRepository(
  214. $this->settingsRepository->getAuthApiKey(),
  215. $this->settingsRepository->getAuthUsername(),
  216. $this->settingsRepository->getAuthPassword(),
  217. $this->settingsRepository->getAuthFiscalCode()
  218. );
  219. $service = new \Core\App\Service\ProformaService(
  220. $marketplaceProformaRepository,
  221. $marketplaceProductRepository,
  222. $facturisCustomerRepository,
  223. $facturisProductRepository,
  224. $facturisProformaRepository,
  225. $this->settingsRepository
  226. );
  227. $result = $service->add($orderId);
  228. return $result;
  229. }
  230. public function addAvize($orderId)
  231. {
  232. $facturisCustomerRepository = new \Core\FacturisRepository\CustomerRepository(
  233. $this->settingsRepository->getAuthApiKey(),
  234. $this->settingsRepository->getAuthUsername(),
  235. $this->settingsRepository->getAuthPassword(),
  236. $this->settingsRepository->getAuthFiscalCode()
  237. );
  238. $facturisProductRepository = new \Core\FacturisRepository\ProductRepository(
  239. $this->settingsRepository->getAuthApiKey(),
  240. $this->settingsRepository->getAuthUsername(),
  241. $this->settingsRepository->getAuthPassword(),
  242. $this->settingsRepository->getAuthFiscalCode()
  243. );
  244. $marketplaceAvizeRepository = new \MarketplaceRepository\AvizeRepository(
  245. $this->settingsRepository->getToken(),
  246. $this->settingsRepository->getShop()
  247. );
  248. $marketplaceProductRepository = new \MarketplaceRepository\ProductRepository(
  249. $this->settingsRepository->getToken(),
  250. $this->settingsRepository->getShop()
  251. );
  252. $facturisAvizeRepository = new \Core\FacturisRepository\AvizeRepository(
  253. $this->settingsRepository->getAuthApiKey(),
  254. $this->settingsRepository->getAuthUsername(),
  255. $this->settingsRepository->getAuthPassword(),
  256. $this->settingsRepository->getAuthFiscalCode()
  257. );
  258. $service = new \Core\App\Service\AvizeService(
  259. $marketplaceAvizeRepository,
  260. $marketplaceProductRepository,
  261. $facturisCustomerRepository,
  262. $facturisProductRepository,
  263. $facturisAvizeRepository,
  264. $this->settingsRepository
  265. );
  266. $result = $service->add($orderId);
  267. return $result;
  268. }
  269. public function addExpfactura($orderId)
  270. {
  271. $facturisCustomerRepository = new \Core\FacturisRepository\CustomerRepository(
  272. $this->settingsRepository->getAuthApiKey(),
  273. $this->settingsRepository->getAuthUsername(),
  274. $this->settingsRepository->getAuthPassword(),
  275. $this->settingsRepository->getAuthFiscalCode()
  276. );
  277. $facturisProductRepository = new \Core\FacturisRepository\ProductRepository(
  278. $this->settingsRepository->getAuthApiKey(),
  279. $this->settingsRepository->getAuthUsername(),
  280. $this->settingsRepository->getAuthPassword(),
  281. $this->settingsRepository->getAuthFiscalCode()
  282. );
  283. $marketplaceExpfacturaRepository = new \MarketplaceRepository\ExpfacturaRepository(
  284. $this->settingsRepository->getToken(),
  285. $this->settingsRepository->getShop()
  286. );
  287. $marketplaceProductRepository = new \MarketplaceRepository\ProductRepository(
  288. $this->settingsRepository->getToken(),
  289. $this->settingsRepository->getShop()
  290. );
  291. $facturisExpfacturaRepository = new \Core\FacturisRepository\ExpfacturaRepository(
  292. $this->settingsRepository->getAuthApiKey(),
  293. $this->settingsRepository->getAuthUsername(),
  294. $this->settingsRepository->getAuthPassword(),
  295. $this->settingsRepository->getAuthFiscalCode()
  296. );
  297. $service = new \Core\App\Service\ExpfacturaService(
  298. $marketplaceExpfacturaRepository,
  299. $marketplaceProductRepository,
  300. $facturisCustomerRepository,
  301. $facturisProductRepository,
  302. $facturisExpfacturaRepository,
  303. $this->settingsRepository
  304. );
  305. $result = $service->add($orderId);
  306. return $result;
  307. }
  308. public function viewProforma($orderId)
  309. {
  310. $marketplaceProformaRepository = new \MarketplaceRepository\ProformaRepository(
  311. $this->settingsRepository->getToken(),
  312. $this->settingsRepository->getShop()
  313. );
  314. $factId = $marketplaceProformaRepository->getFactId($orderId);
  315. $facturisProformaRepository = new \Core\FacturisRepository\ProformaRepository(
  316. $this->settingsRepository->getAuthApiKey(),
  317. $this->settingsRepository->getAuthUsername(),
  318. $this->settingsRepository->getAuthPassword(),
  319. $this->settingsRepository->getAuthFiscalCode()
  320. );
  321. $facturisProformaRepository->view($factId);
  322. }
  323. public function viewAvize($orderId)
  324. {
  325. $marketplaceAvizeRepository = new \MarketplaceRepository\AvizeRepository(
  326. $this->settingsRepository->getToken(),
  327. $this->settingsRepository->getShop()
  328. );
  329. $factId = $marketplaceAvizeRepository->getFactId($orderId);
  330. $facturisAvizeRepository = new \Core\FacturisRepository\AvizeRepository(
  331. $this->settingsRepository->getAuthApiKey(),
  332. $this->settingsRepository->getAuthUsername(),
  333. $this->settingsRepository->getAuthPassword(),
  334. $this->settingsRepository->getAuthFiscalCode()
  335. );
  336. $facturisAvizeRepository->view($factId);
  337. }
  338. public function viewExpfactura($orderId)
  339. {
  340. $marketplaceExpfacturaRepository = new \MarketplaceRepository\ExpfacturaRepository(
  341. $this->settingsRepository->getToken(),
  342. $this->settingsRepository->getShop()
  343. );
  344. $factId = $marketplaceExpfacturaRepository->getFactId($orderId);
  345. $facturisExpfacturaRepository = new \Core\FacturisRepository\ExpfacturaRepository(
  346. $this->settingsRepository->getAuthApiKey(),
  347. $this->settingsRepository->getAuthUsername(),
  348. $this->settingsRepository->getAuthPassword(),
  349. $this->settingsRepository->getAuthFiscalCode()
  350. );
  351. $facturisExpfacturaRepository->view($factId);
  352. }
  353. public function addInvoice($orderId)
  354. {
  355. $facturisCustomerRepository = new \Core\FacturisRepository\CustomerRepository(
  356. $this->settingsRepository->getAuthApiKey(),
  357. $this->settingsRepository->getAuthUsername(),
  358. $this->settingsRepository->getAuthPassword(),
  359. $this->settingsRepository->getAuthFiscalCode()
  360. );
  361. $facturisProductRepository = new \Core\FacturisRepository\ProductRepository(
  362. $this->settingsRepository->getAuthApiKey(),
  363. $this->settingsRepository->getAuthUsername(),
  364. $this->settingsRepository->getAuthPassword(),
  365. $this->settingsRepository->getAuthFiscalCode()
  366. );
  367. $marketplaceInvoiceRepository = new \MarketplaceRepository\InvoiceRepository(
  368. $this->settingsRepository->getToken(),
  369. $this->settingsRepository->getShop()
  370. );
  371. $marketplaceProductRepository = new \MarketplaceRepository\ProductRepository(
  372. $this->settingsRepository->getToken(),
  373. $this->settingsRepository->getShop()
  374. );
  375. $facturisInvoiceRepository = new \Core\FacturisRepository\InvoiceRepository(
  376. $this->settingsRepository->getAuthApiKey(),
  377. $this->settingsRepository->getAuthUsername(),
  378. $this->settingsRepository->getAuthPassword(),
  379. $this->settingsRepository->getAuthFiscalCode()
  380. );
  381. $service = new \Core\App\Service\InvoiceService(
  382. $marketplaceInvoiceRepository,
  383. $marketplaceProductRepository,
  384. $facturisCustomerRepository,
  385. $facturisProductRepository,
  386. $facturisInvoiceRepository,
  387. $this->settingsRepository
  388. );
  389. return $service->add($orderId);
  390. }
  391. public function viewInvoice($orderId)
  392. {
  393. $marketplaceInvoiceRepository = new \MarketplaceRepository\InvoiceRepository(
  394. $this->settingsRepository->getToken(),
  395. $this->settingsRepository->getShop()
  396. );
  397. $factId = $marketplaceInvoiceRepository->getFactId($orderId);
  398. $facturisInvoiceRepository = new \Core\FacturisRepository\InvoiceRepository(
  399. $this->settingsRepository->getAuthApiKey(),
  400. $this->settingsRepository->getAuthUsername(),
  401. $this->settingsRepository->getAuthPassword(),
  402. $this->settingsRepository->getAuthFiscalCode()
  403. );
  404. $facturisInvoiceRepository->view($factId);
  405. }
  406. }