PHP Classes

File: examples/3_example_read_invoices.php

Recommend this page to a friend!
  Classes of Jorge Castro   PHP Document Store One   examples/3_example_read_invoices.php   Download  
File: examples/3_example_read_invoices.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Document Store One
Store and retrieve key-value pairs in flat files
Author: By
Last change: Update of examples/3_example_read_invoices.php
Date: 4 years ago
Size: 1,457 bytes
 

Contents

Class file image Download
<?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>";