Skip to content

Commit

Permalink
added accounts for getTariff and getTariffs
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew committed Jan 26, 2012
1 parent 0a5e9f8 commit 6315c60
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 38 deletions.
38 changes: 19 additions & 19 deletions examples/accountManager.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
case "getProfile": case "getProfile":
$gen->getProfile($_POST); $gen->getProfile($_POST);
break; break;
case "uploadReadings":
$gen->uploadReadings($_POST);
break;
} }
} }


Expand Down Expand Up @@ -240,6 +243,22 @@
} }
} ?> } ?>


<form action="<?=$_SERVER['PHP_SELF']?>?<?=$_SERVER['QUERY_STRING']?>" method="POST" enctype="multipart/form-data">
<fieldset>
<legend>Upload Reading Data</legend>
<input type="hidden" name="action" value="uploadReadings"/>
<input type="hidden" name="profileId" value="<?=$profile["profileId"]?>"/>
<input type="hidden" name="fileFormat" value="espi"/>
<div class="inputBlock">
<label for="fileData">file</label>
<input type="file" name="fileData" id="fileData"/>
</div>
<div class="inputBlock">
<input type="submit" value="Upload"/>
</div>
</fieldset>
</form>

<? } else { ?> <? } else { ?>
Please connect your appId to Genability's Explorer. Please connect your appId to Genability's Explorer.
<?}?> <?}?>
Expand All @@ -256,24 +275,5 @@
}?> }?>


</div> </div>
<style>
.debugFunction {
display: block;
font-weight: bold;
}
.account {
border-bottom: 1px solid #ccc;
padding-bottom: 10px;
margin-bottom: 25px;
}

.accountProperties {
margin-left: 35px;
}

.inputBlock {

}
</style>
</body> </body>
</html> </html>
25 changes: 23 additions & 2 deletions examples/tariff.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
$TERRITORY_ID = $_POST['territoryId']; $TERRITORY_ID = $_POST['territoryId'];
} }


// if an Account Id is passed through, set it
if ($_POST['accountId']) {
$ACCOUNT_ID = $_POST['accountId'];
}

/** include the Genability PHP Library */ /** include the Genability PHP Library */
require_once('../genability.php'); require_once('../genability.php');


Expand All @@ -30,8 +35,13 @@
'masterTariffId'=> $TARIFF_ID, // Unique Genability ID (primary key) for this tariff 'masterTariffId'=> $TARIFF_ID, // Unique Genability ID (primary key) for this tariff
'populateRates' => true, // Populates the rate details for this Tariff (Boolean). The PHP Library defaults to false if not set 'populateRates' => true, // Populates the rate details for this Tariff (Boolean). The PHP Library defaults to false if not set
'territoryId' => $TERRITORY_ID, // When specified, rate changes returned will be for the specified Territory. (Optional) 'territoryId' => $TERRITORY_ID, // When specified, rate changes returned will be for the specified Territory. (Optional)
'accountId' => $ACCOUNT_ID,
)); ));


// check to see if this account has accounts
$accounts = $gen->getAccounts();
$accounts = json_decode($accounts);

// helper method to display text easier (lowercase and without _s) // helper method to display text easier (lowercase and without _s)
function formatText($input) { function formatText($input) {
return strtolower(str_replace("_", " ", $input)); return strtolower(str_replace("_", " ", $input));
Expand Down Expand Up @@ -59,7 +69,7 @@ function formatText($input) {
<h2>Get Tariff Example</h2> <h2>Get Tariff Example</h2>
<form id="tariffForm" action="<?=$_SERVER['PHP_SELF']?>" method="POST"> <form id="tariffForm" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<div class="inputBlock"> <div class="inputBlock">
<label for="tariff">Master Tariff Id</label> <label for="tariffId">Master Tariff Id</label>
<input type="text" id="tariffId" name="tariff" value="<?=$TARIFF_ID?>"/> <input type="text" id="tariffId" name="tariff" value="<?=$TARIFF_ID?>"/>
<a href="#toggleTariffList">tariff cheat sheet</a> <a href="#toggleTariffList">tariff cheat sheet</a>
</div> </div>
Expand All @@ -81,8 +91,19 @@ function formatText($input) {
</div> </div>
<div class="inputBlock"> <div class="inputBlock">
<label for="territoryId">Territory Id(Optional)</label> <label for="territoryId">Territory Id(Optional)</label>
<input type="text" name="territoryId" value="<?=$TERRITORY_ID?>"/> <input id="territoryId" type="text" name="territoryId" value="<?=$TERRITORY_ID?>"/>
</div>
<?if (sizeof($accounts->results)>0) {?>
<div class="inputBlock">
<label for="accountId">Account Id(Optional)</label>
<select id="accountId" name="accountId">
<option value="">--</option>
<?for ($i=0; $i<sizeof($accounts->results); $i++) {?>
<option value="<?=$accounts->results[$i]->accountId?>"<?if ($_POST['accountId'] == $accounts->results[$i]->accountId) echo ' selected="selected"';?>><?if ($accounts->results[$i]->accountName) echo $accounts->results[$i]->accountName . ' (' . $accounts->results[$i]->accountId . ')'; else echo $accounts->results[$i]->accountId;?></option>
<?}?>
</select>
</div> </div>
<?}?>
<button type="submit">Get Tariff!</button> <button type="submit">Get Tariff!</button>
</form> </form>


Expand Down
38 changes: 27 additions & 11 deletions examples/tariffs.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
'debug' => false, // Debug mode echos API Url & POST data if set to true (Optional) 'debug' => false, // Debug mode echos API Url & POST data if set to true (Optional)
)); ));


// check to see if this account has accounts
$accounts = $gen->getAccounts();
$accounts = json_decode($accounts);

if ($_POST) { if ($_POST) {
// make the getTariffs call // make the getTariffs call
$output = $gen->getTariffs(array( $output = $gen->getTariffs(array(
'search' => $_POST['search'], 'search' => $_POST['search'],
'zipCode' => $_POST['zipCode'], 'zipCode' => $_POST['zipCode'],
'tariffTypes' => $_POST['tariffTypes'], 'tariffTypes' => $_POST['tariffTypes'],
'sortOn' => $_POST['sortOn'] 'sortOn' => $_POST['sortOn'],
'accountId' => $_POST['accountId']
)); ));
} }
?> ?>
Expand Down Expand Up @@ -49,20 +54,31 @@
</div> </div>
<div class="inputBlock"> <div class="inputBlock">
<label>Tariff Types</label> <label>Tariff Types</label>
<input type="checkbox" name="tariffTypes[]" value="DEFAULT" id="default"<?if ($_POST) foreach($_POST['tariffTypes'] as $option) { if ($option == 'DEFAULT') echo ' checked'; }?>><label for="default" class="cb">Default</label> <input type="checkbox" name="tariffTypes[]" value="DEFAULT" id="default"<?if ($_POST['tariffTypes']) foreach($_POST['tariffTypes'] as $option) { if ($option == 'DEFAULT') echo ' checked'; }?>><label for="default" class="cb">Default</label>
<input type="checkbox" name="tariffTypes[]" value="ALTERNATIVE" id="alternative"<?if ($_POST) foreach($_POST['tariffTypes'] as $option) { if ($option == 'ALTERNATIVE') echo ' checked'; }?>><label for="alternative" class="cb">Alternative</label> <input type="checkbox" name="tariffTypes[]" value="ALTERNATIVE" id="alternative"<?if ($_POST['tariffTypes']) foreach($_POST['tariffTypes'] as $option) { if ($option == 'ALTERNATIVE') echo ' checked'; }?>><label for="alternative" class="cb">Alternative</label>
<input type="checkbox" name="tariffTypes[]" value="OPTIONAL_EXTRA" id="optional_extra"<?if ($_POST) foreach($_POST['tariffTypes'] as $option) { if ($option == 'OPTIONAL_EXTRA') echo ' checked'; }?>><label for="optional_extra" class="cb">Optional Extra</label> <input type="checkbox" name="tariffTypes[]" value="OPTIONAL_EXTRA" id="optional_extra"<?if ($_POST['tariffTypes']) foreach($_POST['tariffTypes'] as $option) { if ($option == 'OPTIONAL_EXTRA') echo ' checked'; }?>><label for="optional_extra" class="cb">Optional Extra</label>
<input type="checkbox" name="tariffTypes[]" value="RIDER" id="rider"<?if ($_POST) foreach($_POST['tariffTypes'] as $option) { if ($option == 'RIDER') echo ' checked'; }?>><label for="rider" class="cb">Rider</label> <input type="checkbox" name="tariffTypes[]" value="RIDER" id="rider"<?if ($_POST['tariffTypes']) foreach($_POST['tariffTypes'] as $option) { if ($option == 'RIDER') echo ' checked'; }?>><label for="rider" class="cb">Rider</label>
</div> </div>
<div class="inputBlock"> <div class="inputBlock">
<label>Sort On</label> <label>Sort On</label>
<input type="checkbox" name="sortOn[]" value="masterTariffId" id="sort_masterTariffId"<?if ($_POST) foreach($_POST['sortOn'] as $option) { if ($option == 'masterTariffId') echo ' checked'; }?>><label for="sort_masterTariffId" class="cb">Master Tariff Id</label> <input type="checkbox" name="sortOn[]" value="masterTariffId" id="sort_masterTariffId"<?if ($_POST['sortOn']) foreach($_POST['sortOn'] as $option) { if ($option == 'masterTariffId') echo ' checked'; }?>><label for="sort_masterTariffId" class="cb">Master Tariff Id</label>
<input type="checkbox" name="sortOn[]" value="lseId" id="sort_lseId"<?if ($_POST) foreach($_POST['sortOn'] as $option) { if ($option == 'lseId') echo ' checked'; }?>><label for="sort_lseId" class="cb">LSE Id</label> <input type="checkbox" name="sortOn[]" value="lseId" id="sort_lseId"<?if ($_POST['sortOn']) foreach($_POST['sortOn'] as $option) { if ($option == 'lseId') echo ' checked'; }?>><label for="sort_lseId" class="cb">LSE Id</label>
<input type="checkbox" name="sortOn[]" value="lseName" id="sort_lseName"<?if ($_POST) foreach($_POST['sortOn'] as $option) { if ($option == 'lseName') echo ' checked'; }?>><label for="sort_lseName" class="cb">LSE Name</label> <input type="checkbox" name="sortOn[]" value="lseName" id="sort_lseName"<?if ($_POST['sortOn']) foreach($_POST['sortOn'] as $option) { if ($option == 'lseName') echo ' checked'; }?>><label for="sort_lseName" class="cb">LSE Name</label>
<input type="checkbox" name="sortOn[]" value="tariffCode" id="sort_tariffCode"<?if ($_POST) foreach($_POST['sortOn'] as $option) { if ($option == 'tariffCode') echo ' checked'; }?>><label for="sort_tariffCode" class="cb">Tariff Code</label> <input type="checkbox" name="sortOn[]" value="tariffCode" id="sort_tariffCode"<?if ($_POST['sortOn']) foreach($_POST['sortOn'] as $option) { if ($option == 'tariffCode') echo ' checked'; }?>><label for="sort_tariffCode" class="cb">Tariff Code</label>
<input type="checkbox" name="sortOn[]" value="tariffName" id="sort_tariffName"<?if ($_POST) foreach($_POST['sortOn'] as $option) { if ($option == 'tariffName') echo ' checked'; }?>><label for="sort_tariffName" class="cb">Tariff Name</label> <input type="checkbox" name="sortOn[]" value="tariffName" id="sort_tariffName"<?if ($_POST['sortOn']) foreach($_POST['sortOn'] as $option) { if ($option == 'tariffName') echo ' checked'; }?>><label for="sort_tariffName" class="cb">Tariff Name</label>
<input type="checkbox" name="sortOn[]" value="tariffType" id="sort_tariffType"<?if ($_POST) foreach($_POST['sortOn'] as $option) { if ($option == 'tariffType') echo ' checked'; }?>><label for="sort_tariffType" class="cb">Tariff Type</label> <input type="checkbox" name="sortOn[]" value="tariffType" id="sort_tariffType"<?if ($_POST['sortOn']) foreach($_POST['sortOn'] as $option) { if ($option == 'tariffType') echo ' checked'; }?>><label for="sort_tariffType" class="cb">Tariff Type</label>
</div>
<?if (sizeof($accounts->results)>0) {?>
<div class="inputBlock">
<label for="accountId">Account Id(Optional)</label>
<select id="accountId" name="accountId">
<option value="">--</option>
<?for ($i=0; $i<sizeof($accounts->results); $i++) {?>
<option value="<?=$accounts->results[$i]->accountId?>"<?if ($_POST['accountId'] == $accounts->results[$i]->accountId) echo ' selected="selected"';?>><?if ($accounts->results[$i]->accountName) echo $accounts->results[$i]->accountName . ' (' . $accounts->results[$i]->accountId . ')'; else echo $accounts->results[$i]->accountId;?></option>
<?}?>
</select>
</div> </div>
<?}?>
<button type="submit">Get Tariffs!</button> <button type="submit">Get Tariffs!</button>
</form> </form>


Expand Down
17 changes: 11 additions & 6 deletions genability.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ function getTariff($params) {
} else { } else {
$url .= "&populateProperties=true"; $url .= "&populateProperties=true";
} }
if ($params['accountId']) {
$url .= "&accountId=" . $params['accountId'];
}


if ($this->config['debug']) { echo $url; } if ($this->config['debug']) { echo '<strong class="debugFunction">' . __FUNCTION__ . '</strong>' . $url; }


$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_URL,$url);
Expand Down Expand Up @@ -119,7 +122,7 @@ function getTariffs($params) {
} }
} }


if ($this->config['debug']) { echo $url; } if ($this->config['debug']) { echo '<strong class="debugFunction">' . __FUNCTION__ . '</strong>' . $url; }


$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_URL,$url);
Expand Down Expand Up @@ -158,7 +161,7 @@ function getPrice($params) {
$url .= "&demand=" . $params['demand']; $url .= "&demand=" . $params['demand'];
} }


if ($this->config['debug']) { echo $url; } if ($this->config['debug']) { echo '<strong class="debugFunction">' . __FUNCTION__ . '</strong>' . $url; }


$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_URL,$url);
Expand Down Expand Up @@ -187,7 +190,7 @@ function getCalculateInputs($params) {
$url .= "&" . rawurlencode($k) . "=" . rawurlencode($v); $url .= "&" . rawurlencode($k) . "=" . rawurlencode($v);
} }


if ($this->config['debug']) { echo $url; } if ($this->config['debug']) { echo '<strong class="debugFunction">' . __FUNCTION__ . '</strong>' . $url; }


$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_URL,$url);
Expand All @@ -212,7 +215,7 @@ function getCalculateInputs($params) {
function getCalculation($params) { function getCalculation($params) {
$url = $this->GENABILITY_API_URL_BETA . "calculate/" . $params['masterTariffId']; $url = $this->GENABILITY_API_URL_BETA . "calculate/" . $params['masterTariffId'];


if ($this->config['debug']) { echo $url; } if ($this->config['debug']) { echo '<strong class="debugFunction">' . __FUNCTION__ . '</strong>' . $url; }


$data['appId'] = $this->APP_ID; $data['appId'] = $this->APP_ID;
$data['appKey'] = $this->APP_KEY; $data['appKey'] = $this->APP_KEY;
Expand Down Expand Up @@ -253,7 +256,7 @@ function getCalculation($params) {
function getPropertyKey($params) { function getPropertyKey($params) {
$url = $this->GENABILITY_API_URL . "properties/" . $params['keyName'] . $this->API_PARAMS; $url = $this->GENABILITY_API_URL . "properties/" . $params['keyName'] . $this->API_PARAMS;


if ($this->config['debug']) { echo $url; } if ($this->config['debug']) { echo '<strong class="debugFunction">' . __FUNCTION__ . '</strong>' . $url; }


$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_URL,$url);
Expand Down Expand Up @@ -530,5 +533,7 @@ function getProfile($params) {
return $result; return $result;
} }




} }
?> ?>
23 changes: 23 additions & 0 deletions static/genability_php_library.css
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ label {
width: 250px; width: 250px;
} }


label.cb {
float: none;
margin-left: 4px;
}

#tariffForm input[type="checkbox"] {
width: auto;
}

button { button {
position: relative; position: relative;
left: 300px; left: 300px;
Expand Down Expand Up @@ -270,3 +279,17 @@ button {
clear: both; clear: both;
margin: 20px 0 0 240px; margin: 20px 0 0 240px;
} }

.debugFunction {
display: block;
font-weight: bold;
}
.account {
border-bottom: 1px solid #ccc;
padding-bottom: 10px;
margin-bottom: 25px;
}

.accountProperties {
margin-left: 35px;
}

0 comments on commit 6315c60

Please sign in to comment.