format('F'); if (isset($usage_billing[$ye]['quarters'][$qu]['months'][$mo])){ $billing_run = $usage_billing[$ye]['quarters'][$qu]['months'][$mo]; } break; case 2: # quarter $period = 'Q'.$qu; if (isset($usage_billing[$ye]['quarters'][$qu]['total'])){ $billing_run = $usage_billing[$ye]['quarters'][$qu]['total']; } break; case 3: # year $period = $ye; if (isset($usage_billing[$ye]['total'])){ $billing_run = $usage_billing[$ye]['total']; } break; } //Variable translation $status = 'contract_status' . $response['status']; $type = 'contract_type'.$response['type']; $contract_billingplan_text = 'contract_billing'.$response['billing_plan'] ?? ''; //calculate enddate from duration $date = date('Y-m-d', strtotime('+'.$response['duration'].' months', strtotime($response['start_date']))); //GetPartnerDetails $partner_data = json_decode($response['accounthierarchy'],true); //SHOW USAGE PERCENTAGE $usage_service_count = ($response['service_count'] > 0) ? $response['service_count']:1; $usage_percentage = ($billing_run != 0) ? round((($billing_run/$usage_service_count)*100),2) : 0; $usage_per_status = ($usage_percentage < 100) ? 'enabled' : 'disabled'; $output[] = array( "#" => $response['rowID'] , "Status" => $$status, "Account" => $partner_data['soldto'], "Type" => $$type, "Billingplan" =>$$contract_billingplan_text, "Start date" =>$response['start_date'], "End date" => $date, "Reference" =>$response['reference'], "Consumed" =>$billing_run, "Contracted" =>$response['service_count'], "Deviation" => $usage_percentage, "Snapshot_date" => $da, "Period" => $period ); } } $total = count( $output ); //SEND TOTALS WHEN REQUESTED if(isset($criterias['totals']) && $criterias['totals'] ==''){ $messages = json_encode($total, JSON_UNESCAPED_UNICODE); } else { //------------------------------------------ //Paging //------------------------------------------ $current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1; $offset = ($current_page - 1) * $page_rows_contracts; $output = array_slice( $output, $offset, $page_rows_contracts ); //------------------------------------------ //JSON_ENCODE //------------------------------------------ $messages = json_encode($output, JSON_UNESCAPED_UNICODE); } //Send results echo $messages; ?>