public static function read_items($quote_id) { $items = QuoteItem::read(['*'], FALSE, ['quote_id = ?', $quote_id]); for ($i = 0; $i < count($items); ++$i) { $part = Part::read_part($items[$i]['part']); unset($part['id']); $items[$i] += $part; if (!is_null($items[$i]['override'])) { $items[$i]['price'] = $items[$i]['override']; } $items[$i]['annual_fee'] = $items[$i]['price'] * $items[$i]['quantity']; } return $items; }
public static function read_key($key) { $quote = self::read(['*'], TRUE, ["`key` = ?", $key]); $quote['items'] = QuoteItem::read_items($quote['id']); $annual_fee = 0; foreach ($quote['items'] as $item) { $annual_fee += $item['annual_fee']; } $quote['first_fee'] = $annual_fee; $quote['annual_fee'] = $annual_fee; if (!is_null($quote['discount'])) { $quote['first_fee'] -= $quote['discount']; } $quote['expiration'] = Util2::future_date(substr($quote['created'], 0, 10), 60); return $quote; }
public function order_custom($params = []) { $parts = Part::get_parts(); $order = Record::allow($params, array_keys($parts)); $key = Quote::get_unique_key([]); $model['`key`'] = $key; $fields = ['company', 'address', 'country', 'billing_name', 'billing_email', 'billing_phone', 'technical_name', 'technical_email', 'discount', 'discount_desc']; $model += Record::allow($params, $fields); $quote = Quote::create($model); $total = 0; foreach ($order as $name => $value) { if ($value) { $model = ['quote_id' => $quote['id'], 'part' => $name, 'override' => null, 'quantity' => $value]; QuoteItem::create($model); } } return Render::json(['key' => $key]); }
<div class="content left"> <table class="data"> <thead> <th>Date</th> <th>Expires</th> <th>Company</th> <th>Contact/Email/Key</th> <th>Items</th> <th>Views</th> </thead> <tbody> <?php $quotes = Quote::read(['*'], FALSE, ['created > CURRENT_DATE - INTERVAL 2 MONTH'], 'created DESC'); foreach ($quotes as $quote) { $expiration = Util2::future_date(substr($quote['created'], 0, 10), 60); $items = QuoteItem::read_items($quote['id']); $views = QuoteView::read_views($quote['id']); $item_details = []; foreach ($items as $item) { $item_details[] = $item['quantity'] . ' ' . $item['part']; } $view_details = []; foreach ($views as $view) { $view_details[] = $view['created'] . ' ' . $view['ip']; } echo '<tr>'; echo '<td>' . htmlspecialchars($quote['created']) . '</td>'; echo '<td>' . htmlspecialchars($expiration) . '</td>'; echo '<td>' . htmlspecialchars($quote['company']) . '</td>'; echo '<td>' . htmlspecialchars($quote['technical_name']) . '<br/>'; echo htmlspecialchars($quote['technical_email']) . '<br/>';