本文整理汇总了PHP中Discount::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Discount::create方法的具体用法?PHP Discount::create怎么用?PHP Discount::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discount
的用法示例。
在下文中一共展示了Discount::create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* 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;
}