nsu_controller.class.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/nsu_controller_helper.class.php';
  3. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/nsu_log.class.php';
  4. class DBARRAPIInvoice extends DolibarrApi
  5. {
  6. public $nsuControllerHelper = new NsuControllerHelper();
  7. /**
  8. * Invoice/draft
  9. *
  10. * @param array $cart //product ID => darabszám
  11. * @param boolean $invoice // Invoice / Receipt
  12. *
  13. *
  14. * @return array|mixed Data without useless information
  15. *
  16. * @url POST draft
  17. */
  18. public function draft(array $cart, boolean $invoice = false, int $billing_id = null)
  19. {
  20. $array = [];
  21. $log_id = ApiNSULog::getLogId();
  22. ApiNSULog::invoiceLog("{$log_id}: DBARRAPIInvoice->draft");
  23. $dbTransactionID = $this->nsuControllerHelper->generateTransactionID($log_id);
  24. $lines = $this->nsuControllerHelper->getProductLines($product_id);
  25. $apiInvoiceHelper = new ApiInvoiceHelper;
  26. $invoiceObj = $apiInvoiceHelper->createInvoice($invoice, $log_id, $company_invoice);
  27. ApiNSULog::invoiceLog("{$log_id} Invoice created");
  28. $products = [];
  29. foreach ($lines as $line) {
  30. $invoiceObj = $apiInvoiceHelper->addLineToInvoice($invoiceObj, $line, $log_id);
  31. $product = $apiInvoiceHelper->loadProductToResult($line);
  32. if (!empty($product)) {
  33. $products[] = $product;
  34. }
  35. }
  36. $invoiceObj->fetch_lines();
  37. foreach ($products as &$row) {
  38. foreach ($invoiceObj->lines as $line) {
  39. if ($line->product_ref == $row['ref']) {
  40. $row['price'] = $line->multicurrency_total_ttc;
  41. $row['total_tva'] = $line->total_tva;
  42. }
  43. }
  44. }
  45. return $array;
  46. }
  47. /**
  48. * Invoice/createInvoice
  49. *
  50. * @param string $dolibar_transaction_id //Dolibarr transaction id
  51. * @param string $simple_transaction_id //Simple Pay transaction id
  52. * @param array $payment //Payment array
  53. * @param array $invoice //Invoice array
  54. * @param string $log_id //logId
  55. *
  56. *
  57. *
  58. * @return array|mixed Data without useless information
  59. *
  60. * @url POST createInvoice
  61. */
  62. public function createInvoice(string $dolibar_transaction_id, string $simple_transaction_id, array $payment, array $invoice, string $log_id)
  63. {
  64. $array = [];
  65. $apiInvoiceHelper = new ApiInvoiceHelper;
  66. $invoiceObj = []
  67. $invoiceObj = $apiInvoiceHelper->validateInvoice($invoiceObj, $log_id);
  68. /**
  69. * set payment
  70. */
  71. $apiInvoiceHelper->setPayment($invoiceObj, $payment, $log_id);
  72. /**
  73. * save card payment data
  74. */
  75. if (!empty($cardPaymentLog)) {
  76. $invoiceObj = $apiInvoiceHelper->saveCardPaymentLog($invoiceObj, $cardPaymentLog, $log_id);
  77. }
  78. ApiBbusLog::appLog("{$log_id} Invoice created. ID: {$invoiceObj->id} REF: {$invoiceObj->ref} REQ: {$log_id}");
  79. dol_syslog("{$log_id} Invoice created. ID: {$invoiceObj->id} REF: {$invoiceObj->ref} REQ: {$log_id}", LOG_INFO, 0);
  80. //$bbApiLock->delete($user);
  81. ApiBbusLog::appLog("{$log_id}####################################################################");
  82. dol_syslog("{$log_id}####################################################################", LOG_INFO, 0);
  83. $products = [];
  84. return [
  85. 'log_id' => $log_id,
  86. 'invoice' => [
  87. 'id' => $invoiceObj->id,
  88. 'ref' => $invoiceObj->ref,
  89. 'total' => $invoiceObj->multicurrency_total_ttc
  90. ],
  91. 'products' => $products,
  92. ];
  93. return $array;
  94. }
  95. /**
  96. * Invoice/list
  97. *
  98. * @param int $backenduser_id //ID of the backenduser
  99. * @return array|mixed Data without useless information
  100. *
  101. * @url GET list
  102. */
  103. public function list($backenduser_id)
  104. {
  105. $array = [];
  106. $sql = "SELECT * FROM llx_facture as f INNER JOIN llx_facture_extrafields as fe ON fe.fk_facture = f.rowid WHERE fe.backenduser_id = {$backenduser_id}";
  107. $array = $this->nsuControllerHelper->getObject($sql);
  108. return $array;
  109. }
  110. /**
  111. * Invoice/details
  112. *
  113. * @param int $facture_id //Facture rowid
  114. *
  115. *
  116. * @return array|mixed Data without useless information
  117. *
  118. * @url GET details
  119. */
  120. public function deatils(int $facture_id)
  121. {
  122. global $db;
  123. $factureObj = new Facture($db);
  124. $result = $factureObj->fetch($facture_id);
  125. if($db->num_rows($result) > 0){
  126. return $factureObj;
  127. }
  128. return [];
  129. }
  130. /**
  131. * Invoice/resend
  132. *
  133. * @param int $facture_id //Facture rowid
  134. *
  135. *
  136. * @return array|mixed Data without useless information
  137. *
  138. * @url GET resend
  139. */
  140. public function resend(int $facture_id)
  141. {
  142. $array = [];
  143. $note = "";
  144. $this->nsuControllerHelper->emailSender($note, $array);
  145. }
  146. }
  147. class DBARRAPIBilling extends DolibarrApi
  148. {
  149. public $nsuControllerHelper = new NsuControllerHelper();
  150. /**
  151. * billing/create
  152. *
  153. * @param string $name
  154. * @param string $city
  155. * @param int $zip
  156. * @param string $town
  157. * @param int $currency
  158. * @param string $currencyCode
  159. *
  160. * @return array|mixed Data without useless information
  161. *
  162. * @url POST create
  163. */
  164. public function create(string $name, string $city, int $zip, string $town, int $currency, string $currencyCode)
  165. {
  166. $array = [];
  167. global $db, $user;
  168. $ThirdPartyObj = new Societe($db);
  169. $ThirdPartyObj->nom = $name;
  170. $ThirdPartyObj->entity = 1;
  171. $ThirdPartyObj->address = $city;
  172. $ThirdPartyObj->zip = $zip;
  173. $ThirdPartyObj->town = $town;
  174. $ThirdPartyObj->fk_multicurrency = $currency;
  175. $ThirdPartyObj->multicurrency_code = $currencyCode;
  176. $result = $ThirdPartyObj->create($user);
  177. if($result){
  178. return $ThirdPartyObj; # Megnézni, hogy mivel tér vissza és mit kell visszaadni.
  179. }
  180. return $array;
  181. }
  182. /**
  183. * billing/modify
  184. *
  185. * @param int $thirdpartyID
  186. * @param string $name
  187. * @param string $city
  188. * @param int $zip
  189. * @param string $town
  190. * @param int $currency
  191. * @param string $currencyCode
  192. *
  193. * @return array|mixed Data without useless information
  194. *
  195. * @url POST modify
  196. */
  197. public function modify(int $thirdpartyID, string $name, string $city, int $zip, string $town, int $currency, string $currencyCode)
  198. {
  199. $array = [];
  200. global $db, $user;
  201. $ThirdParty = new Societe($db);
  202. $result = $ThirdPartyObj->fetch($thirdpartyID);
  203. $ThirdPartyObj->nom = $name;
  204. $ThirdPartyObj->entity = 1;
  205. $ThirdPartyObj->address = $city;
  206. $ThirdPartyObj->zip = $zip;
  207. $ThirdPartyObj->town = $town;
  208. $ThirdPartyObj->fk_multicurrency = $currency;
  209. $ThirdPartyObj->multicurrency_code = $currencyCode;
  210. $result = $ThirdPartyObj->update($user);
  211. if($result){
  212. return $ThirdPartyObj; # Megnézni, hogy mivel tér vissza és mit kell visszaadni.
  213. }
  214. return $array;
  215. }
  216. /**
  217. * billing/delete
  218. *
  219. * @param int $thirdpartyID
  220. * @param string $name
  221. * @param string $city
  222. * @param int $zip
  223. * @param string $town
  224. * @param int $currency
  225. * @param string $currencyCode
  226. *
  227. * @return array|mixed Data without useless information
  228. *
  229. * @url POST delete
  230. */
  231. public function delete(int $thirdpartyID)
  232. {
  233. global $db, $user;
  234. $ThirdParty = new Societe($db);
  235. $result = $ThirdPartyObj->delete($thirdpartyID);
  236. if($result){
  237. return true; # Megnézni, hogy mivel tér vissza és mit kell visszaadni.
  238. }
  239. return false;
  240. }
  241. }
  242. class DBARRAPIFacilities extends DolibarrApi
  243. {
  244. public $nsuControllerHelper = new NsuControllerHelper();
  245. /**
  246. * ticket/list
  247. *
  248. * @return array|mixed Data without useless information
  249. *
  250. * @url GET list
  251. */
  252. public function list()
  253. {
  254. $array = [];
  255. return $array;
  256. }
  257. /**
  258. * ticket/details
  259. *
  260. * @param int $facility_id //facility ID
  261. *
  262. * @return array|mixed Data without useless information
  263. *
  264. * @url GET details
  265. */
  266. public function details(int $facility_id)
  267. {
  268. $array = [];
  269. return $array;
  270. }
  271. }
  272. class DBARRAPITicket extends DolibarrApi
  273. {
  274. public $nsuControllerHelper = new NsuControllerHelper();
  275. /**
  276. * ticket/details
  277. *
  278. * @param int $ticket_id //ticket rowid
  279. * @param int $backend_user_id //backend_user_id
  280. *
  281. *
  282. * @return array|mixed Data without useless information
  283. *
  284. * @url GET details
  285. */
  286. public function details(int $ticket_id, int $backend_user_id)
  287. {
  288. $array = [];
  289. global $db;
  290. $NSUTIcketObj = new NSUTicket($db);
  291. $result = $NSUTIcketObj->fetch($ticket_id);
  292. if($db->num_rows($result) > 0){
  293. return $NSUTIcketObj;
  294. }
  295. return $array;
  296. }
  297. /**
  298. * ticket/tickets
  299. *
  300. * @param int $backenduser_id //backend_user_id
  301. *
  302. *
  303. * @return array|mixed Data without useless information
  304. *
  305. * @url GET tickets
  306. */
  307. public function tickets(int $backenduser_id)
  308. {
  309. $array = [];
  310. $facturesArray = DBARRAPIInvoice::list($backenduser_id);
  311. if(!empty($facturesArray)){
  312. $tmp_factures_array = [];
  313. foreach($facturesArray as $facture){
  314. $tmp_factures_array[] = $facture['rowid'];
  315. }
  316. $factures = implode(',', $tmp_factures_array);
  317. $sql = "SELECT * FROM llx_nsu_ticket as t WHERE t.fk_facture IN ({$factures})";
  318. $array = $this->nsuControllerHelper->getObject($sql);
  319. }
  320. return $array;
  321. }
  322. }