<?php
@set_time_limit(60*60); // 1 hour.
use eftec\DocumentStoreOne\DocumentStoreOne;
/**
* It reads 20 invoices generated by example_store_invoices.php
* @author Jorge Castro Castillo jcastro@eftec.cl
* @license LGPLv3
*/
include "../lib/DocumentStoreOne.php";
include "modelinvoices/Models.php";
$t1=microtime(true);
try {
$flatcon = new DocumentStoreOne(dirname(__FILE__) . "/base", 'invoices');
} catch (Exception $e) {
die("Unable to create document store");
}
$numItems=0;
$totalInvoice=0;
$listInvoices=$flatcon->select();
$igbinary=function_exists('igbinary_serialize');
foreach($listInvoices as $i) {
if ($i!='genseq_seq') { // we skip the sequence
echo "<pre>";
if ($igbinary) {
$inv = igbinary_unserialize($flatcon->get($i));
} else {
$invTmp = json_decode($flatcon->get($i)); // $invTmp is stdclass
$inv = new Invoice();
DocumentStoreOne::fixCast($inv, $invTmp); // $inv is a Invoice class. However, $inv->details is a stdClass[]
}
var_dump($inv);
foreach ($inv->details as $det) {
$numItems += $det->amount;
$totalInvoice += $det->amount * $det->unitPrice;
}
echo "</pre>";
}
}
$t2=microtime(true);
echo "<hr>Total invoices ".count($listInvoices)."<br>Num Items all invoices : $numItems<br>Total Invoices \$$totalInvoice<br>";
echo "microseconds :".($t2-$t1)." seconds.<br>";
|