| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?php
- use WHMCS\Database\Capsule;
- if (!defined("WHMCS")) {
- exit("This file cannot be accessed directly");
- }
- $data = $_REQUEST;
- if(empty($data['orderid'])) {
- $apiresults = array('result' => 'error', 'message' => 'OrderID is required');
- return ;
- }
- $orderid = (int) $data['orderid'];
- $setup = array(
- 'One Time' => 'msetupfee',
- 'Monthly' => 'msetupfee',
- 'Quarterly' => 'qsetupfee',
- 'Semi-Annually' => 'ssetupfee',
- 'Annually' => 'asetupfee',
- 'Biennially' => 'bsetupfee',
- 'Triennially' => 'tsetupfee',
- );
- $recurring = array(
- 'One Time' => 'monthly',
- 'Monthly' => 'monthly',
- 'Quarterly' => 'quarterly',
- 'Semi-Annually' => 'semiannually',
- 'Annually' => 'annually',
- 'Biennially' => 'biennially',
- 'Triennially' => 'triennially',
- );
- $billingterm = array(
- 'Free Account' => Lang::trans('orderpaymenttermfree'),
- 'One Time' => Lang::trans('orderpaymenttermonetime'),
- 'Monthly' => Lang::trans('orderpaymenttermmonthly'),
- 'Quarterly' => Lang::trans('orderpaymenttermquarterly'),
- 'Semi-Annually' => Lang::trans('orderpaymenttermsemiannually'),
- 'Annually' => Lang::trans('orderpaymenttermannually'),
- 'Biennially' => Lang::trans('orderpaymenttermbiennially'),
- 'Triennially' => Lang::trans('orderpaymenttermtriennially'),
- );
- $order_details = array();
- $order = localAPI('GetOrders', array('id' => $orderid));
- $order_details['ordernumber'] = $order['orders']['order'][0]['ordernum'];
- $order_details['date'] = $order['orders']['order'][0]['date'];
- $order_details['invoiceid'] = $order['orders']['order'][0]['invoiceid'];
- $order_details['currency'] = $order['orders']['order'][0]['currencyprefix'];
- $order_details['amount'] = $order['orders']['order'][0]['amount'];
- $currencyId = Capsule::table('tblcurrencies')
- ->where('prefix', $order_details['currency'])
- ->value('id');
- $serviceIds = Capsule::table('tblhosting')
- ->where('orderid', $orderid)
- ->get('id');
- $order_details['products'] = array();
- foreach($serviceIds as $serviceId) {
- unset($service_details);
- $service[$serviceId->id] = localAPI('GetClientsProducts', array('serviceid' => $serviceId->id));
- $service_details['id'] = $serviceId->id;
- $service_details['name'] = $service[$serviceId->id]['products']['product'][0]['name'];
- $service_details['groupname'] = $service[$serviceId->id]['products']['product'][0]['groupname'];
- $productBillingcycle = $service[$serviceId->id]['products']['product'][0]['billingcycle'];
- // use domain or alternatvie custom fields for naming the service
- if($service[$serviceId->id]['products']['product'][0]['domain']) {
- $service_details['domain'] = $service[$serviceId->id]['products']['product'][0]['domain'];
- } else {
- unset($domain);
- unset($name);
- foreach($service[$serviceId->id]['products']['product'][0]['customfields']['customfield'] as $customfield) {
- switch($customfield['name']) {
- case 'E-Mail Name':
- case 'Login E-Mail':
- case 'Nextcloud Benutzername':
- case 'Name des VDC':
- $name = $customfield['value'];
- break;
- case 'Mail Domaine':
- $domain = $customfield['value'];
- break;
- }
- if ($name && $domain) {
- $service_details['altdomain'] = $name . '@' . $domain;
- } elseif ($name) {
- $service_details['altdomain'] = $name;
- } elseif ($domain) {
- $service_details['altdomain'] = $domain;
- } else {
- $service_details['altdomain'] = 'ID:' . $serviceId->id;
- }
- }
- }
- // price
- if($productBillingcycle != 'Free Account') {
- $packageId = Capsule::table('tblhosting')
- ->where('id', $serviceId->id)
- ->value('packageid');
- $prorata = Capsule::table('tblproducts')
- ->where('id', $packageId)
- ->value('proratabilling');
- if($prorata == 1) {
- $service_details['prorata'] = $prorata;
- }
- $product_setup = Capsule::table('tblpricing')
- ->where('relid', $packageId)
- ->where('type', 'product')
- ->where('currency', $currencyId)
- ->value($setup[$productBillingcycle]);
- $product_recurring = Capsule::table('tblpricing')
- ->where('relid', $packageId)
- ->where('type', 'product')
- ->where('currency', $currencyId)
- ->value($recurring[$productBillingcycle]);
- if($product_setup > 0) {
- $service_details['setup'] = $product_setup;
- }
- if($product_recurring > 0) {
- $service_details['recurring'] = $product_recurring;
- }
- }
- $service_details['billingcycle'] = $billingterm[$productBillingcycle];
- // configoptions
- $service_details['configoptions'] = array();
- foreach($service[$serviceId->id]['products']['product'][0]['configoptions']['configoption'] as $configoption) {
- unset($option_details);
- if($configoption['value'] != '' && $configoption['value'] != 0) {
- $option_details['id'] = $configoption['id'];
- $option_details['name'] = $configoption['option'];
- $option_details['qty'] = $configoption['value'];
- if($productBillingcycle != 'Free Account') {
- $configoptionId = Capsule::table('tblhostingconfigoptions')
- ->where('configid', $configoption['id'])
- ->value('optionid');
- $option_setup = Capsule::table('tblpricing')
- ->where('type', 'configoptions')
- ->where('currency', $currencyId)
- ->where('relid', $configoptionId)
- ->value($setup[$productBillingcycle]);
- $option_recurring = Capsule::table('tblpricing')
- ->where('type', 'configoptions')
- ->where('currency', $currencyId)
- ->where('relid', $configoptionId)
- ->value($recurring[$productBillingcycle]);
- if($option_setup > 0) {
- $option_details['setup'] = $option_setup;
- }
- if ($option_recurring > 0) {
- $option_details['recurring'] = $option_recurring;
- }
- }
- array_push($service_details['configoptions'], $option_details);
- }
- }
- if(empty($service_details['configoptions'])) {
- unset($service_details['configoptions']);
- }
- // addons
- $addon[$serviceId->id] = localAPI('GetClientsAddons', array('serviceid' => $serviceId->id));
- if($addon[$serviceId->id]['totalresults'] != 0) {
- $service_details['addons'] = array();
- foreach($addon[$serviceId->id]['addons']['addon'] as $addon) {
- unset($service_addon_details);
- $addon_details = (array) Capsule::table('tblhostingaddons')->where('id', $addon['id'])->first();
- $addonBillingcycle = $addon_details['billingcycle'];
- $service_addon_details['id'] = $addon['id'];
- $service_addon_details['name'] = $addon['name'];
- $service_addon_details['qty'] = $addon_details['qty'];
- if($addonBillingcycle != 'Free Account') {
- $addon_setup = Capsule::table('tblpricing')
- ->where('relid', $addon_details['addonid'])
- ->where('type', 'addon')
- ->where('currency', $currencyId)
- ->value($setup[$addonBillingcycle]);
- $addon_recurring = Capsule::table('tblpricing')
- ->where('relid', $addon_details['addonid'])
- ->where('type', 'addon')
- ->where('currency', $currencyId)
- ->value($recurring[$addonBillingcycle]);
- if($addon_setup > 0) {
- $service_addon_details['setup'] = $addon_setup;
- }
- if($addon_recurring > 0) {
- $service_addon_details['recurring'] = $addon_recurring;
- }
- }
- $service_addon_details['billingcycle'] = $billingterm[$addonBillingcycle];
- array_push($service_details['addons'], $service_addon_details);
- }
- }
- array_push($order_details['products'], $service_details);
- }
- $apiresults['orderdetails'] = $order_details;
- $responsetype = "xml";
|