示例#1
0
 public function testGetParameters()
 {
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_GET['captain'] = 'kirk';
     $request = new Http();
     $this->assertEquals('kirk', $request->getParameter('captain'));
 }
示例#2
0
<?php

if (!isset($payment)) {
    $payment = new stdClass();
    $payment->invoice_id = Http::getParameter('invoice_id', 'int');
    $payment->type = '';
    $payment->billed = 0;
    $payment->total = 0;
    $payment->description = 'Enter a description here...';
}
?>
<form method="POST" action="<?php 
echo $action;
?>
" id="payment-edit">
    <div id="messages"></div>
    <fieldset>
        <legend>Payment</legend>
        <input type="hidden" name="Payment[invoice_id]" value="<?php 
echo $payment->invoice_id;
?>
" />
        <label>Date (DDMMYYYY)</label>
        <?php 
$billed = $payment->billed ? Entry::__getStringFromDateTime($payment->billed) : '';
?>
        <input type="text" name="Payment[billed]" value="<?php 
echo $billed;
?>
" />
        <span class="help"></span><br/>
示例#3
0
 /**
  * Creates an invoice and related items
  */
 public function create()
 {
     $post = Http::getParameter('POST');
     if (count($this->validate()) > 0) {
         throw new Exception('Invalid data entered', 400);
     }
     // create invoice
     if ($this->id == 'new') {
         $this->id = null;
     }
     $this->status = 'Drafted';
     $id = parent::create();
     // create entries
     $this->entries = array();
     foreach ($post['Invoice']['Entry'] as $entry) {
         $Entry = new Entry();
         $Entry->__bind($entry);
         $Entry->invoice_id = $id;
         $Entry->billed = Entry::__getDateTimeFromString($Entry->billed);
         if (!array_key_exists('total', $entry)) {
             $Entry->total = round($entry['quantity'] * $entry['amount_per'], 2);
         }
         $Entry->create();
         $this->entries[] = $Entry;
     }
     // create discounts
     $this->discounts = array();
     foreach ($post['Invoice']['Discount'] as $discount) {
         $Discount = new Discount();
         $Discount->__bind($discount);
         $Discount->invoice_id = $id;
         $Discount->create();
         $this->discounts[] = $Discount;
     }
     // update total
     $this->update_total();
     // update cache, see libraries/misc.php
     delete_cache_entry('invoices', $id);
     // return
     return $id;
 }
示例#4
0
 /**
  * Creates a payment
  * @return int 
  */
 public function create()
 {
     $post = Http::getParameter('POST');
     if (count($this->validate()) > 0) {
         throw new Exception('Invalid data entered', 400);
     }
     // should have been handled by AJAX
     // create invoice
     if ($this->id == 'new') {
         $this->id = null;
     }
     $this->billed = Entry::__getDateTimeFromString($this->billed);
     $this->description = trim($this->description);
     $id = parent::create();
     // recalculate invoice total
     $invoice = new Invoice($this->invoice_id);
     $invoice->update_total();
     // update cache, see libraries/misc.php
     delete_cache_entry('payments', $id);
     // send payment receipt
     $this->mail();
     // return
     return $id;
 }