Beispiel #1
0
 public function index()
 {
     $data = array();
     $this->load->model('customer');
     $customer = new Customer();
     $customer->load(1);
     $data['customer'] = $customer;
     $this->load->model('fault');
     $fault = new Fault();
     $fault->load(1);
     $data['fault'] = $fault;
     $this->load->view('fault', $data);
 }
 /**
  * Show customer data and sales
  */
 public function onCheckSales()
 {
     try {
         $data = $this->form->getData();
         // get form data
         $this->form->setData($data);
         // keep the form filled
         // load the html template
         $html = new THtmlRenderer('app/resources/customer_status.html');
         // load CSS styles
         parent::include_css('app/resources/styles.css');
         TTransaction::open('samples');
         $customer = new Customer();
         // load customer identified in the form
         $object = $customer->load($data->customer_id);
         if ($object) {
             // create one array with the customer data
             $array_object = $object->toArray();
             $array_object['city_name'] = $object->city_name;
             $array_object['category_name'] = $object->category_name;
             // replace variables from the main section with the object data
             $html->enableSection('main', $array_object);
             $replaces = array();
             $sales = $object->getSales();
             if ($sales) {
                 $total = 0;
                 // iterate the customer sales
                 foreach ($sales as $sale) {
                     // foreach sale item
                     foreach ($sale->getSaleItems() as $item) {
                         // define the multidimensional array with the sale items
                         $replaces[] = array('date' => $sale->date, 'product_id' => $item->product_id, 'product_description' => $item->product->description, 'sale_price' => number_format($item->sale_price, 2), 'amount' => $item->amount, 'discount' => $item->discount, 'total' => number_format($item->total, 2));
                         $total += $item->total;
                     }
                 }
                 $totals['total'] = number_format($total, 2);
                 // replace sale items and totals
                 $html->enableSection('sale-details', $replaces, TRUE);
                 $html->enableSection('sale-totals', $totals);
             }
         } else {
             throw new Exception('Customer not found');
         }
         TTransaction::close();
         parent::add($html);
     } catch (Exception $e) {
         new TMessage('error', $e->getMessage());
     }
 }
Beispiel #3
0
 public function __construct()
 {
     parent::__construct();
     try {
         TTransaction::open('samples');
         // open transaction
         $objeto = new Customer();
         // instantiates customer
         $customer = $objeto->load(31);
         // load customer 31
         if ($customer) {
             $customer->phone = '51 8111-3333';
             // changes phone
             $customer->store();
             // store the object
         }
         new TMessage('info', 'Objeto atualizado');
         TTransaction::close();
         // close the transaction
     } catch (Exception $e) {
         new TMessage('error', $e->getMessage());
     }
 }
 public function __construct()
 {
     parent::__construct();
     try {
         TTransaction::open('samples');
         // abre uma transação
         $objeto = new Customer();
         // instancia o cliente
         $customer = $objeto->load(31);
         // carrega o cliente 31
         if ($customer) {
             $customer->phone = '51 8111-3333';
             // muda o fone
             $customer->store();
             // armazena o objeto
         }
         new TMessage('info', 'Objeto atualizado');
         TTransaction::close();
         // fecha a transação.
     } catch (Exception $e) {
         new TMessage('error', $e->getMessage());
     }
 }
<?php

session_start();
if (isset($_SESSION['CustomerID']) == false) {
    header("Location:index.php");
    exit;
}
require_once "includes/header.php";
require_once "includes/customer.php";
require_once "includes/view.php";
$iCustomerID = 1;
if (isset($_GET["CustomerID"])) {
    $iCustomerID = $_GET["CustomerID"];
}
$oCustomer = new Customer();
$iCustomerID = $_SESSION["CustomerID"];
$oCustomer->load($iCustomerID);
echo View::renderCustomer($oCustomer);
?>
<a href="edit_details.php?CustomerID=<?php 
echo $iCustomerID;
?>
">+Edit Details</a>

<?php 
require_once "includes/footer.php";
?>

try {
    $load_account5 = Customer::load('B2345');
    $user_name = $load_account5->generate_username($load_account5->customer_type_id, 29);
    echo 'Username for ' . get_class($load_account5) . ' with customer ID: B2345' . $user_name;
} catch (Exception $e) {
    echo 'Exception generating username: '******'S5678');
    $user_name2 = $load_account6->generate_username($load_account6->customer_type_id, 29);
    echo 'Username for ' . get_class($load_account6) . ' with customer ID: S5678' . $user_name2;
} catch (Exception $e) {
    echo 'Exception generating username: '******'G1234');
    $user_name3 = $load_account6->generate_username($load_account7->customer_type_id, 29);
    echo 'Username for ' . get_class($load_account7) . ' with customer ID: G1234' . $user_name3;
} catch (Exception $e) {
    echo 'Exception generating username: '******'A9876');
    $user_name4 = $load_account6->generate_username($load_account8->customer_type_id, 29);
    echo 'Username for ' . get_class($load_account8) . ' with customer ID: A9876' . $user_name4;
} catch (Exception $e) {
    echo 'Exception generating username: ' . $e->getMessage();
}
<?php

ob_start();
require_once "includes/header.php";
require_once "includes/form.php";
require_once "includes/customer.php";
session_start();
if (isset($_SESSION['CustomerID']) == false) {
    header("Location:index.php");
    exit;
}
$iCurrentID = $_SESSION['CustomerID'];
$oExistingCustomer = new Customer();
$oExistingCustomer->load($iCurrentID);
$aExistingData = [];
$aExistingData["Name"] = $oExistingCustomer->Name;
$aExistingData["Address"] = $oExistingCustomer->Address;
$aExistingData["Phone"] = $oExistingCustomer->Phone;
$aExistingData["Email"] = $oExistingCustomer->Email;
$oForm = new Form();
$oForm->data = $aExistingData;
if (isset($_POST["submit"]) == true) {
    $oForm->data = $_POST;
    $oForm->checkRequired("Name");
    $oForm->checkRequired("Address");
    $oForm->checkRequired("Phone");
    $oForm->checkRequired("Email");
    if ($oForm->valid == true) {
        $oExistingCustomer->Name = $_POST["Name"];
        $oExistingCustomer->Address = $_POST["Address"];
        $oExistingCustomer->Phone = $_POST["Phone"];