PHP code example of ourenergy / eiep

1. Go to this page and download the library: Download ourenergy/eiep library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ourenergy / eiep example snippets


use Eiep\Eiep3\Report;
use Eiep\Eiep3\DetailRecord;

$report = new Report();

$report->streamFromFile("eiep3.csv", function(DetailRecord $record)  {
    echo $record->getActiveEnergy() . PHP_EOL;
});
    

use Eiep\Eiep3\Report;
use Eiep\Eiep3\DetailRecord;

$report = new Report();

$handle = fopen("eiep3.csv", "r");

$report->readFromStream($handle, function(DetailRecord $record)  {
    echo $record->getActiveEnergy() . PHP_EOL;
});
    

use Eiep\Eiep3\Report;
use Eiep\Eiep3\DetailRecord;

// Create the report
$report = new Report();
$report
    ->setReportDate(new \DateTime("2019-01-01 00:00:00"))
    ->setUtilityType(Report::UTILITY_TYPE_ELECTRICITY)
    ->setFileStatus(Report::FILE_STATUS_REPLACEMENT)
    ->setNumRecords(1);

// Create records
$record = new DetailRecord();

$record
    ->setIcpIdentifier("1234567890")
    ->setStreamIdentifier("ABCDEFG")
    ->setReadingType(DetailRecord::READING_TYPE_FINAL)
    ->setDate(new \DateTime("2019-01-01 00:00:00"))
    ->setTradingPeriod(48)
    ->setActiveEnergy(1)
    ->setReactiveEnergy(2)
    ->setApparentEnergy(3)
    ->setFlowDirection(DetailRecord::FLOW_DIRECTION_EXTRACT);
    
// Write everything to a file
$records = [
    $record
];

$report->writeRecords("eiep3.csv", $records);


use Eiep\Eiep3\Report;
use Eiep\Eiep3\DetailRecord;

// ... prepare your report and records as above ...

// Create a writer
$writer = $report->createWriter("eiep3.csv");

// Write one record
$writer->insertOne($record->toArray());

// Write multiple records
$rows = array_map(function (DetailRecord $record) {
    return $record->toArray();
}, $records);

$writer->insertAll($rows);