Skip to content
Browse files

added accounts for getTariff and getTariffs

  • Loading branch information...
1 parent 0a5e9f8 commit 6315c606247ab640736f83c68d5547570fec0226 @mfong mfong committed Jan 25, 2012
Showing with 103 additions and 38 deletions.
  1. +19 −19 examples/accountManager.php
  2. +23 −2 examples/tariff.php
  3. +27 −11 examples/tariffs.php
  4. +11 −6 genability.php
  5. +23 −0 static/genability_php_library.css
View
38 examples/accountManager.php
@@ -28,6 +28,9 @@
case "getProfile":
$gen->getProfile($_POST);
break;
+ case "uploadReadings":
+ $gen->uploadReadings($_POST);
+ break;
}
}
@@ -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 { ?>
Please connect your appId to Genability's Explorer.
<?}?>
@@ -256,24 +275,5 @@
}?>
</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>
</html>
View
25 examples/tariff.php
@@ -15,6 +15,11 @@
$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 */
require_once('../genability.php');
@@ -30,8 +35,13 @@
'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
'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)
function formatText($input) {
return strtolower(str_replace("_", " ", $input));
@@ -59,7 +69,7 @@ function formatText($input) {
<h2>Get Tariff Example</h2>
<form id="tariffForm" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<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?>"/>
<a href="#toggleTariffList">tariff cheat sheet</a>
</div>
@@ -81,8 +91,19 @@ function formatText($input) {
</div>
<div class="inputBlock">
<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>
+<?}?>
<button type="submit">Get Tariff!</button>
</form>
View
38 examples/tariffs.php
@@ -9,13 +9,18 @@
'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) {
// make the getTariffs call
$output = $gen->getTariffs(array(
'search' => $_POST['search'],
'zipCode' => $_POST['zipCode'],
'tariffTypes' => $_POST['tariffTypes'],
- 'sortOn' => $_POST['sortOn']
+ 'sortOn' => $_POST['sortOn'],
+ 'accountId' => $_POST['accountId']
));
}
?>
@@ -49,20 +54,31 @@
</div>
<div class="inputBlock">
<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="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="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="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="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['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['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['tariffTypes']) foreach($_POST['tariffTypes'] as $option) { if ($option == 'RIDER') echo ' checked'; }?>><label for="rider" class="cb">Rider</label>
</div>
<div class="inputBlock">
<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="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="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="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="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="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="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['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['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['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['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['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>
+<?}?>
<button type="submit">Get Tariffs!</button>
</form>
View
17 genability.php
@@ -78,8 +78,11 @@ function getTariff($params) {
} else {
$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();
curl_setopt($ch, CURLOPT_URL,$url);
@@ -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();
curl_setopt($ch, CURLOPT_URL,$url);
@@ -158,7 +161,7 @@ function getPrice($params) {
$url .= "&demand=" . $params['demand'];
}
- if ($this->config['debug']) { echo $url; }
+ if ($this->config['debug']) { echo '<strong class="debugFunction">' . __FUNCTION__ . '</strong>' . $url; }
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
@@ -187,7 +190,7 @@ function getCalculateInputs($params) {
$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();
curl_setopt($ch, CURLOPT_URL,$url);
@@ -212,7 +215,7 @@ function getCalculateInputs($params) {
function getCalculation($params) {
$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['appKey'] = $this->APP_KEY;
@@ -253,7 +256,7 @@ function getCalculation($params) {
function getPropertyKey($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();
curl_setopt($ch, CURLOPT_URL,$url);
@@ -530,5 +533,7 @@ function getProfile($params) {
return $result;
}
+
+
}
?>
View
23 static/genability_php_library.css
@@ -72,6 +72,15 @@ label {
width: 250px;
}
+label.cb {
+ float: none;
+ margin-left: 4px;
+}
+
+#tariffForm input[type="checkbox"] {
+ width: auto;
+}
+
button {
position: relative;
left: 300px;
@@ -270,3 +279,17 @@ button {
clear: both;
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.
Something went wrong with that request. Please try again.