getorderdetails.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. use WHMCS\Database\Capsule;
  3. if (!defined("WHMCS")) {
  4. exit("This file cannot be accessed directly");
  5. }
  6. $data = $_REQUEST;
  7. if(empty($data['orderid'])) {
  8. $apiresults = array('result' => 'error', 'message' => 'OrderID is required');
  9. return ;
  10. }
  11. $orderid = (int) $data['orderid'];
  12. $setup = array(
  13. 'One Time' => 'msetupfee',
  14. 'Monthly' => 'msetupfee',
  15. 'Quarterly' => 'qsetupfee',
  16. 'Semi-Annually' => 'ssetupfee',
  17. 'Annually' => 'asetupfee',
  18. 'Biennially' => 'bsetupfee',
  19. 'Triennially' => 'tsetupfee',
  20. );
  21. $recurring = array(
  22. 'One Time' => 'monthly',
  23. 'Monthly' => 'monthly',
  24. 'Quarterly' => 'quarterly',
  25. 'Semi-Annually' => 'semiannually',
  26. 'Annually' => 'annually',
  27. 'Biennially' => 'biennially',
  28. 'Triennially' => 'triennially',
  29. );
  30. $billingterm = array(
  31. 'Free Account' => Lang::trans('orderpaymenttermfree'),
  32. 'One Time' => Lang::trans('orderpaymenttermonetime'),
  33. 'Monthly' => Lang::trans('orderpaymenttermmonthly'),
  34. 'Quarterly' => Lang::trans('orderpaymenttermquarterly'),
  35. 'Semi-Annually' => Lang::trans('orderpaymenttermsemiannually'),
  36. 'Annually' => Lang::trans('orderpaymenttermannually'),
  37. 'Biennially' => Lang::trans('orderpaymenttermbiennially'),
  38. 'Triennially' => Lang::trans('orderpaymenttermtriennially'),
  39. );
  40. $order_details = array();
  41. $order = localAPI('GetOrders', array('id' => $orderid));
  42. $order_details['ordernumber'] = $order['orders']['order'][0]['ordernum'];
  43. $order_details['date'] = $order['orders']['order'][0]['date'];
  44. $order_details['invoiceid'] = $order['orders']['order'][0]['invoiceid'];
  45. $order_details['currency'] = $order['orders']['order'][0]['currencyprefix'];
  46. $order_details['amount'] = $order['orders']['order'][0]['amount'];
  47. $currencyId = Capsule::table('tblcurrencies')
  48. ->where('prefix', $order_details['currency'])
  49. ->value('id');
  50. $serviceIds = Capsule::table('tblhosting')
  51. ->where('orderid', $orderid)
  52. ->get('id');
  53. $order_details['products'] = array();
  54. foreach($serviceIds as $serviceId) {
  55. unset($service_details);
  56. $service[$serviceId->id] = localAPI('GetClientsProducts', array('serviceid' => $serviceId->id));
  57. $service_details['id'] = $serviceId->id;
  58. $service_details['name'] = $service[$serviceId->id]['products']['product'][0]['name'];
  59. $service_details['groupname'] = $service[$serviceId->id]['products']['product'][0]['groupname'];
  60. $productBillingcycle = $service[$serviceId->id]['products']['product'][0]['billingcycle'];
  61. // use domain or alternatvie custom fields for naming the service
  62. if($service[$serviceId->id]['products']['product'][0]['domain']) {
  63. $service_details['domain'] = $service[$serviceId->id]['products']['product'][0]['domain'];
  64. } else {
  65. unset($domain);
  66. unset($name);
  67. foreach($service[$serviceId->id]['products']['product'][0]['customfields']['customfield'] as $customfield) {
  68. switch($customfield['name']) {
  69. case 'E-Mail Name':
  70. case 'Login E-Mail':
  71. case 'Nextcloud Benutzername':
  72. case 'Name des VDC':
  73. $name = $customfield['value'];
  74. break;
  75. case 'Mail Domaine':
  76. $domain = $customfield['value'];
  77. break;
  78. }
  79. if ($name && $domain) {
  80. $service_details['altdomain'] = $name . '@' . $domain;
  81. } elseif ($name) {
  82. $service_details['altdomain'] = $name;
  83. } elseif ($domain) {
  84. $service_details['altdomain'] = $domain;
  85. } else {
  86. $service_details['altdomain'] = 'ID:' . $serviceId->id;
  87. }
  88. }
  89. }
  90. // price
  91. if($productBillingcycle != 'Free Account') {
  92. $packageId = Capsule::table('tblhosting')
  93. ->where('id', $serviceId->id)
  94. ->value('packageid');
  95. $prorata = Capsule::table('tblproducts')
  96. ->where('id', $packageId)
  97. ->value('proratabilling');
  98. if($prorata == 1) {
  99. $service_details['prorata'] = $prorata;
  100. }
  101. $product_setup = Capsule::table('tblpricing')
  102. ->where('relid', $packageId)
  103. ->where('type', 'product')
  104. ->where('currency', $currencyId)
  105. ->value($setup[$productBillingcycle]);
  106. $product_recurring = Capsule::table('tblpricing')
  107. ->where('relid', $packageId)
  108. ->where('type', 'product')
  109. ->where('currency', $currencyId)
  110. ->value($recurring[$productBillingcycle]);
  111. if($product_setup > 0) {
  112. $service_details['setup'] = $product_setup;
  113. }
  114. if($product_recurring > 0) {
  115. $service_details['recurring'] = $product_recurring;
  116. }
  117. }
  118. $service_details['billingcycle'] = $billingterm[$productBillingcycle];
  119. // configoptions
  120. $service_details['configoptions'] = array();
  121. foreach($service[$serviceId->id]['products']['product'][0]['configoptions']['configoption'] as $configoption) {
  122. unset($option_details);
  123. if($configoption['value'] != '' && $configoption['value'] != 0) {
  124. $option_details['id'] = $configoption['id'];
  125. $option_details['name'] = $configoption['option'];
  126. $option_details['qty'] = $configoption['value'];
  127. if($productBillingcycle != 'Free Account') {
  128. $configoptionId = Capsule::table('tblhostingconfigoptions')
  129. ->where('configid', $configoption['id'])
  130. ->value('optionid');
  131. $option_setup = Capsule::table('tblpricing')
  132. ->where('type', 'configoptions')
  133. ->where('currency', $currencyId)
  134. ->where('relid', $configoptionId)
  135. ->value($setup[$productBillingcycle]);
  136. $option_recurring = Capsule::table('tblpricing')
  137. ->where('type', 'configoptions')
  138. ->where('currency', $currencyId)
  139. ->where('relid', $configoptionId)
  140. ->value($recurring[$productBillingcycle]);
  141. if($option_setup > 0) {
  142. $option_details['setup'] = $option_setup;
  143. }
  144. if ($option_recurring > 0) {
  145. $option_details['recurring'] = $option_recurring;
  146. }
  147. }
  148. array_push($service_details['configoptions'], $option_details);
  149. }
  150. }
  151. if(empty($service_details['configoptions'])) {
  152. unset($service_details['configoptions']);
  153. }
  154. // addons
  155. $addon[$serviceId->id] = localAPI('GetClientsAddons', array('serviceid' => $serviceId->id));
  156. if($addon[$serviceId->id]['totalresults'] != 0) {
  157. $service_details['addons'] = array();
  158. foreach($addon[$serviceId->id]['addons']['addon'] as $addon) {
  159. unset($service_addon_details);
  160. $addon_details = (array) Capsule::table('tblhostingaddons')->where('id', $addon['id'])->first();
  161. $addonBillingcycle = $addon_details['billingcycle'];
  162. $service_addon_details['id'] = $addon['id'];
  163. $service_addon_details['name'] = $addon['name'];
  164. $service_addon_details['qty'] = $addon_details['qty'];
  165. if($addonBillingcycle != 'Free Account') {
  166. $addon_setup = Capsule::table('tblpricing')
  167. ->where('relid', $addon_details['addonid'])
  168. ->where('type', 'addon')
  169. ->where('currency', $currencyId)
  170. ->value($setup[$addonBillingcycle]);
  171. $addon_recurring = Capsule::table('tblpricing')
  172. ->where('relid', $addon_details['addonid'])
  173. ->where('type', 'addon')
  174. ->where('currency', $currencyId)
  175. ->value($recurring[$addonBillingcycle]);
  176. if($addon_setup > 0) {
  177. $service_addon_details['setup'] = $addon_setup;
  178. }
  179. if($addon_recurring > 0) {
  180. $service_addon_details['recurring'] = $addon_recurring;
  181. }
  182. }
  183. $service_addon_details['billingcycle'] = $billingterm[$addonBillingcycle];
  184. array_push($service_details['addons'], $service_addon_details);
  185. }
  186. }
  187. array_push($order_details['products'], $service_details);
  188. }
  189. $apiresults['orderdetails'] = $order_details;
  190. $responsetype = "xml";