shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

transaction.php (1506B)


      1 <?php
      2 class ModelAccountTransaction extends Model {
      3 	public function getTransactions($data = array()) {
      4 		$sql = "SELECT * FROM `" . DB_PREFIX . "customer_transaction` WHERE customer_id = '" . (int)$this->customer->getId() . "'";
      5 
      6 		$sort_data = array(
      7 			'amount',
      8 			'description',
      9 			'date_added'
     10 		);
     11 
     12 		if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
     13 			$sql .= " ORDER BY " . $data['sort'];
     14 		} else {
     15 			$sql .= " ORDER BY date_added";
     16 		}
     17 
     18 		if (isset($data['order']) && ($data['order'] == 'DESC')) {
     19 			$sql .= " DESC";
     20 		} else {
     21 			$sql .= " ASC";
     22 		}
     23 
     24 		if (isset($data['start']) || isset($data['limit'])) {
     25 			if ($data['start'] < 0) {
     26 				$data['start'] = 0;
     27 			}
     28 
     29 			if ($data['limit'] < 1) {
     30 				$data['limit'] = 20;
     31 			}
     32 
     33 			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
     34 		}
     35 
     36 		$query = $this->db->query($sql);
     37 
     38 		return $query->rows;
     39 	}
     40 
     41 	public function getTotalTransactions() {
     42 		$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "customer_transaction` WHERE customer_id = '" . (int)$this->customer->getId() . "'");
     43 
     44 		return $query->row['total'];
     45 	}
     46 
     47 	public function getTotalAmount() {
     48 		$query = $this->db->query("SELECT SUM(amount) AS total FROM `" . DB_PREFIX . "customer_transaction` WHERE customer_id = '" . (int)$this->customer->getId() . "' GROUP BY customer_id");
     49 
     50 		if ($query->num_rows) {
     51 			return $query->row['total'];
     52 		} else {
     53 			return 0;
     54 		}
     55 	}
     56 }