first commit
This commit is contained in:
@@ -0,0 +1,478 @@
|
||||
<?php
|
||||
class ModelSaleOrder extends Model {
|
||||
public function getOrder($order_id) {
|
||||
$order_query = $this->db->query("SELECT *, (SELECT CONCAT(c.firstname, ' ', c.lastname) FROM " . DB_PREFIX . "customer c WHERE c.customer_id = o.customer_id) AS customer, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') . "') AS order_status FROM `" . DB_PREFIX . "order` o WHERE o.order_id = '" . (int)$order_id . "'");
|
||||
|
||||
if ($order_query->num_rows) {
|
||||
$country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$order_query->row['payment_country_id'] . "'");
|
||||
|
||||
if ($country_query->num_rows) {
|
||||
$payment_iso_code_2 = $country_query->row['iso_code_2'];
|
||||
$payment_iso_code_3 = $country_query->row['iso_code_3'];
|
||||
} else {
|
||||
$payment_iso_code_2 = '';
|
||||
$payment_iso_code_3 = '';
|
||||
}
|
||||
|
||||
$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['payment_zone_id'] . "'");
|
||||
|
||||
if ($zone_query->num_rows) {
|
||||
$payment_zone_code = $zone_query->row['code'];
|
||||
} else {
|
||||
$payment_zone_code = '';
|
||||
}
|
||||
|
||||
$country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$order_query->row['shipping_country_id'] . "'");
|
||||
|
||||
if ($country_query->num_rows) {
|
||||
$shipping_iso_code_2 = $country_query->row['iso_code_2'];
|
||||
$shipping_iso_code_3 = $country_query->row['iso_code_3'];
|
||||
} else {
|
||||
$shipping_iso_code_2 = '';
|
||||
$shipping_iso_code_3 = '';
|
||||
}
|
||||
|
||||
$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['shipping_zone_id'] . "'");
|
||||
|
||||
if ($zone_query->num_rows) {
|
||||
$shipping_zone_code = $zone_query->row['code'];
|
||||
} else {
|
||||
$shipping_zone_code = '';
|
||||
}
|
||||
|
||||
$reward = 0;
|
||||
|
||||
$order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
|
||||
|
||||
foreach ($order_product_query->rows as $product) {
|
||||
$reward += $product['reward'];
|
||||
}
|
||||
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$affiliate_info = $this->model_customer_customer->getCustomer($order_query->row['affiliate_id']);
|
||||
|
||||
if ($affiliate_info) {
|
||||
$affiliate_firstname = $affiliate_info['firstname'];
|
||||
$affiliate_lastname = $affiliate_info['lastname'];
|
||||
} else {
|
||||
$affiliate_firstname = '';
|
||||
$affiliate_lastname = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($order_query->row['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
return array(
|
||||
'order_id' => $order_query->row['order_id'],
|
||||
'invoice_no' => $order_query->row['invoice_no'],
|
||||
'invoice_prefix' => $order_query->row['invoice_prefix'],
|
||||
'store_id' => $order_query->row['store_id'],
|
||||
'store_name' => $order_query->row['store_name'],
|
||||
'store_url' => $order_query->row['store_url'],
|
||||
'customer_id' => $order_query->row['customer_id'],
|
||||
'customer' => $order_query->row['customer'],
|
||||
'customer_group_id' => $order_query->row['customer_group_id'],
|
||||
'firstname' => $order_query->row['firstname'],
|
||||
'lastname' => $order_query->row['lastname'],
|
||||
'email' => $order_query->row['email'],
|
||||
'telephone' => $order_query->row['telephone'],
|
||||
'custom_field' => json_decode($order_query->row['custom_field'], true),
|
||||
'payment_firstname' => $order_query->row['payment_firstname'],
|
||||
'payment_lastname' => $order_query->row['payment_lastname'],
|
||||
'payment_company' => $order_query->row['payment_company'],
|
||||
'payment_address_1' => $order_query->row['payment_address_1'],
|
||||
'payment_address_2' => $order_query->row['payment_address_2'],
|
||||
'payment_postcode' => $order_query->row['payment_postcode'],
|
||||
'payment_city' => $order_query->row['payment_city'],
|
||||
'payment_zone_id' => $order_query->row['payment_zone_id'],
|
||||
'payment_zone' => $order_query->row['payment_zone'],
|
||||
'payment_zone_code' => $payment_zone_code,
|
||||
'payment_country_id' => $order_query->row['payment_country_id'],
|
||||
'payment_country' => $order_query->row['payment_country'],
|
||||
'payment_iso_code_2' => $payment_iso_code_2,
|
||||
'payment_iso_code_3' => $payment_iso_code_3,
|
||||
'payment_address_format' => $order_query->row['payment_address_format'],
|
||||
'payment_custom_field' => json_decode($order_query->row['payment_custom_field'], true),
|
||||
'payment_method' => $order_query->row['payment_method'],
|
||||
'payment_code' => $order_query->row['payment_code'],
|
||||
'shipping_firstname' => $order_query->row['shipping_firstname'],
|
||||
'shipping_lastname' => $order_query->row['shipping_lastname'],
|
||||
'shipping_company' => $order_query->row['shipping_company'],
|
||||
'shipping_address_1' => $order_query->row['shipping_address_1'],
|
||||
'shipping_address_2' => $order_query->row['shipping_address_2'],
|
||||
'shipping_postcode' => $order_query->row['shipping_postcode'],
|
||||
'shipping_city' => $order_query->row['shipping_city'],
|
||||
'shipping_zone_id' => $order_query->row['shipping_zone_id'],
|
||||
'shipping_zone' => $order_query->row['shipping_zone'],
|
||||
'shipping_zone_code' => $shipping_zone_code,
|
||||
'shipping_country_id' => $order_query->row['shipping_country_id'],
|
||||
'shipping_country' => $order_query->row['shipping_country'],
|
||||
'shipping_iso_code_2' => $shipping_iso_code_2,
|
||||
'shipping_iso_code_3' => $shipping_iso_code_3,
|
||||
'shipping_address_format' => $order_query->row['shipping_address_format'],
|
||||
'shipping_custom_field' => json_decode($order_query->row['shipping_custom_field'], true),
|
||||
'shipping_method' => $order_query->row['shipping_method'],
|
||||
'shipping_code' => $order_query->row['shipping_code'],
|
||||
'comment' => $order_query->row['comment'],
|
||||
'total' => $order_query->row['total'],
|
||||
'reward' => $reward,
|
||||
'order_status_id' => $order_query->row['order_status_id'],
|
||||
'order_status' => $order_query->row['order_status'],
|
||||
'affiliate_id' => $order_query->row['affiliate_id'],
|
||||
'affiliate_firstname' => $affiliate_firstname,
|
||||
'affiliate_lastname' => $affiliate_lastname,
|
||||
'commission' => $order_query->row['commission'],
|
||||
'language_id' => $order_query->row['language_id'],
|
||||
'language_code' => $language_code,
|
||||
'currency_id' => $order_query->row['currency_id'],
|
||||
'currency_code' => $order_query->row['currency_code'],
|
||||
'currency_value' => $order_query->row['currency_value'],
|
||||
'ip' => $order_query->row['ip'],
|
||||
'forwarded_ip' => $order_query->row['forwarded_ip'],
|
||||
'user_agent' => $order_query->row['user_agent'],
|
||||
'accept_language' => $order_query->row['accept_language'],
|
||||
'date_added' => $order_query->row['date_added'],
|
||||
'date_modified' => $order_query->row['date_modified']
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public function getOrders($data = array()) {
|
||||
$sql = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') . "') AS order_status, o.shipping_code, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `" . DB_PREFIX . "order` o";
|
||||
|
||||
if (!empty($data['filter_order_status'])) {
|
||||
$implode = array();
|
||||
|
||||
$order_statuses = explode(',', $data['filter_order_status']);
|
||||
|
||||
foreach ($order_statuses as $order_status_id) {
|
||||
$implode[] = "o.order_status_id = '" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
} elseif (isset($data['filter_order_status_id']) && $data['filter_order_status_id'] !== '') {
|
||||
$sql .= " WHERE o.order_status_id = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " WHERE o.order_status_id > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$sql .= " AND o.order_id = '" . (int)$data['filter_order_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$sql .= " AND CONCAT(o.firstname, ' ', o.lastname) LIKE '%" . $this->db->escape($data['filter_customer']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_added'])) {
|
||||
$sql .= " AND DATE(o.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_modified'])) {
|
||||
$sql .= " AND DATE(o.date_modified) = DATE('" . $this->db->escape($data['filter_date_modified']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_total'])) {
|
||||
$sql .= " AND o.total = '" . (float)$data['filter_total'] . "'";
|
||||
}
|
||||
|
||||
$sort_data = array(
|
||||
'o.order_id',
|
||||
'customer',
|
||||
'order_status',
|
||||
'o.date_added',
|
||||
'o.date_modified',
|
||||
'o.total'
|
||||
);
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY o.order_id";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getOrderProducts($order_id) {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getOrderOptions($order_id, $order_product_id) {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$order_product_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getOrderVouchers($order_id) {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_voucher WHERE order_id = '" . (int)$order_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getOrderVoucherByVoucherId($voucher_id) {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_voucher` WHERE voucher_id = '" . (int)$voucher_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getOrderTotals($order_id) {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "' ORDER BY sort_order");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getTotalOrders($data = array()) {
|
||||
$sql = "SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order`";
|
||||
|
||||
if (!empty($data['filter_order_status'])) {
|
||||
$implode = array();
|
||||
|
||||
$order_statuses = explode(',', $data['filter_order_status']);
|
||||
|
||||
foreach ($order_statuses as $order_status_id) {
|
||||
$implode[] = "order_status_id = '" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
} elseif (isset($data['filter_order_status_id']) && $data['filter_order_status_id'] !== '') {
|
||||
$sql .= " WHERE order_status_id = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " WHERE order_status_id > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$sql .= " AND order_id = '" . (int)$data['filter_order_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$sql .= " AND CONCAT(firstname, ' ', lastname) LIKE '%" . $this->db->escape($data['filter_customer']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_added'])) {
|
||||
$sql .= " AND DATE(date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_modified'])) {
|
||||
$sql .= " AND DATE(date_modified) = DATE('" . $this->db->escape($data['filter_date_modified']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_total'])) {
|
||||
$sql .= " AND total = '" . (float)$data['filter_total'] . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalOrdersByStoreId($store_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE store_id = '" . (int)$store_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalOrdersByOrderStatusId($order_status_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id = '" . (int)$order_status_id . "' AND order_status_id > '0'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalOrdersByProcessingStatus() {
|
||||
$implode = array();
|
||||
|
||||
$order_statuses = $this->config->get('config_processing_status');
|
||||
|
||||
foreach ($order_statuses as $order_status_id) {
|
||||
$implode[] = "order_status_id = '" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE " . implode(" OR ", $implode));
|
||||
|
||||
return $query->row['total'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTotalOrdersByCompleteStatus() {
|
||||
$implode = array();
|
||||
|
||||
$order_statuses = $this->config->get('config_complete_status');
|
||||
|
||||
foreach ($order_statuses as $order_status_id) {
|
||||
$implode[] = "order_status_id = '" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE " . implode(" OR ", $implode) . "");
|
||||
|
||||
return $query->row['total'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTotalOrdersByLanguageId($language_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE language_id = '" . (int)$language_id . "' AND order_status_id > '0'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalOrdersByCurrencyId($currency_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE currency_id = '" . (int)$currency_id . "' AND order_status_id > '0'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalSales($data = array()) {
|
||||
$sql = "SELECT SUM(total) AS total FROM `" . DB_PREFIX . "order`";
|
||||
|
||||
if (!empty($data['filter_order_status'])) {
|
||||
$implode = array();
|
||||
|
||||
$order_statuses = explode(',', $data['filter_order_status']);
|
||||
|
||||
foreach ($order_statuses as $order_status_id) {
|
||||
$implode[] = "order_status_id = '" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
} elseif (isset($data['filter_order_status_id']) && $data['filter_order_status_id'] !== '') {
|
||||
$sql .= " WHERE order_status_id = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " WHERE order_status_id > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$sql .= " AND order_id = '" . (int)$data['filter_order_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$sql .= " AND CONCAT(firstname, ' ', lastname) LIKE '%" . $this->db->escape($data['filter_customer']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_added'])) {
|
||||
$sql .= " AND DATE(date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_modified'])) {
|
||||
$sql .= " AND DATE(date_modified) = DATE('" . $this->db->escape($data['filter_date_modified']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_total'])) {
|
||||
$sql .= " AND total = '" . (float)$data['filter_total'] . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function createInvoiceNo($order_id) {
|
||||
$order_info = $this->getOrder($order_id);
|
||||
|
||||
if ($order_info && !$order_info['invoice_no']) {
|
||||
$query = $this->db->query("SELECT MAX(invoice_no) AS invoice_no FROM `" . DB_PREFIX . "order` WHERE invoice_prefix = '" . $this->db->escape($order_info['invoice_prefix']) . "'");
|
||||
|
||||
if ($query->row['invoice_no']) {
|
||||
$invoice_no = $query->row['invoice_no'] + 1;
|
||||
} else {
|
||||
$invoice_no = 1;
|
||||
}
|
||||
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "order` SET invoice_no = '" . (int)$invoice_no . "', invoice_prefix = '" . $this->db->escape($order_info['invoice_prefix']) . "' WHERE order_id = '" . (int)$order_id . "'");
|
||||
|
||||
return $order_info['invoice_prefix'] . $invoice_no;
|
||||
}
|
||||
}
|
||||
|
||||
public function getOrderHistories($order_id, $start = 0, $limit = 10) {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT oh.date_added, os.name AS status, oh.comment, oh.notify FROM " . DB_PREFIX . "order_history oh LEFT JOIN " . DB_PREFIX . "order_status os ON oh.order_status_id = os.order_status_id WHERE oh.order_id = '" . (int)$order_id . "' AND os.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY oh.date_added DESC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getTotalOrderHistories($order_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "order_history WHERE order_id = '" . (int)$order_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalOrderHistoriesByOrderStatusId($order_status_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "order_history WHERE order_status_id = '" . (int)$order_status_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getEmailsByProductsOrdered($products, $start, $end) {
|
||||
$implode = array();
|
||||
|
||||
foreach ($products as $product_id) {
|
||||
$implode[] = "op.product_id = '" . (int)$product_id . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT DISTINCT email FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_product op ON (o.order_id = op.order_id) WHERE (" . implode(" OR ", $implode) . ") AND o.order_status_id <> '0' LIMIT " . (int)$start . "," . (int)$end);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getTotalEmailsByProductsOrdered($products) {
|
||||
$implode = array();
|
||||
|
||||
foreach ($products as $product_id) {
|
||||
$implode[] = "op.product_id = '" . (int)$product_id . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT COUNT(DISTINCT email) AS total FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_product op ON (o.order_id = op.order_id) WHERE (" . implode(" OR ", $implode) . ") AND o.order_status_id <> '0'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
class ModelSaleRecurring extends Model {
|
||||
public function getRecurrings($data) {
|
||||
$sql = "SELECT `or`.order_recurring_id, `or`.order_id, `or`.reference, `or`.`status`, `or`.`date_added`, CONCAT(`o`.firstname, ' ', `o`.lastname) AS customer FROM `" . DB_PREFIX . "order_recurring` `or` LEFT JOIN `" . DB_PREFIX . "order` `o` ON (`or`.order_id = `o`.order_id)";
|
||||
|
||||
$implode = array();
|
||||
|
||||
if (!empty($data['filter_order_recurring_id'])) {
|
||||
$implode[] = "or.order_recurring_id = " . (int)$data['filter_order_recurring_id'];
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$implode[] = "or.order_id = " . (int)$data['filter_order_id'];
|
||||
}
|
||||
|
||||
if (!empty($data['filter_reference'])) {
|
||||
$implode[] = "or.reference LIKE '" . $this->db->escape($data['filter_reference']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] = "CONCAT(o.firstname, ' ', o.lastname) LIKE '" . $this->db->escape($data['filter_customer']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_status'])) {
|
||||
$implode[] = "or.status = " . (int)$data['filter_status'];
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_added'])) {
|
||||
$implode[] = "DATE(or.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = array(
|
||||
'or.order_recurring_id',
|
||||
'or.order_id',
|
||||
'or.reference',
|
||||
'customer',
|
||||
'or.status',
|
||||
'or.date_added'
|
||||
);
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY or.order_recurring_id";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getRecurring($order_recurring_id) {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_recurring WHERE order_recurring_id = " . (int)$order_recurring_id);
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getRecurringTransactions($order_recurring_id) {
|
||||
$transactions = array();
|
||||
|
||||
$query = $this->db->query("SELECT amount, type, date_added FROM " . DB_PREFIX . "order_recurring_transaction WHERE order_recurring_id = " . (int)$order_recurring_id . " ORDER BY date_added DESC");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
switch ($result['type']) {
|
||||
case 0:
|
||||
$type = $this->language->get('text_transaction_date_added');
|
||||
break;
|
||||
case 1:
|
||||
$type = $this->language->get('text_transaction_payment');
|
||||
break;
|
||||
case 2:
|
||||
$type = $this->language->get('text_transaction_outstanding_payment');
|
||||
break;
|
||||
case 3:
|
||||
$type = $this->language->get('text_transaction_skipped');
|
||||
break;
|
||||
case 4:
|
||||
$type = $this->language->get('text_transaction_failed');
|
||||
break;
|
||||
case 5:
|
||||
$type = $this->language->get('text_transaction_cancelled');
|
||||
break;
|
||||
case 6:
|
||||
$type = $this->language->get('text_transaction_suspended');
|
||||
break;
|
||||
case 7:
|
||||
$type = $this->language->get('text_transaction_suspended_failed');
|
||||
break;
|
||||
case 8:
|
||||
$type = $this->language->get('text_transaction_outstanding_failed');
|
||||
break;
|
||||
case 9:
|
||||
$type = $this->language->get('text_transaction_expired');
|
||||
break;
|
||||
default:
|
||||
$type = '';
|
||||
break;
|
||||
}
|
||||
|
||||
$transactions[] = array(
|
||||
'date_added' => $result['date_added'],
|
||||
'amount' => $result['amount'],
|
||||
'type' => $type
|
||||
);
|
||||
}
|
||||
|
||||
return $transactions;
|
||||
}
|
||||
|
||||
private function getStatus($status) {
|
||||
switch ($status) {
|
||||
case 1:
|
||||
$result = $this->language->get('text_status_inactive');
|
||||
break;
|
||||
case 2:
|
||||
$result = $this->language->get('text_status_active');
|
||||
break;
|
||||
case 3:
|
||||
$result = $this->language->get('text_status_suspended');
|
||||
break;
|
||||
case 4:
|
||||
$result = $this->language->get('text_status_cancelled');
|
||||
break;
|
||||
case 5:
|
||||
$result = $this->language->get('text_status_expired');
|
||||
break;
|
||||
case 6:
|
||||
$result = $this->language->get('text_status_pending');
|
||||
break;
|
||||
default:
|
||||
$result = '';
|
||||
break;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getTotalRecurrings($data) {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order_recurring` `or` LEFT JOIN `" . DB_PREFIX . "order` o ON (`or`.order_id = `o`.order_id)";
|
||||
|
||||
$implode = array();
|
||||
|
||||
if (!empty($data['filter_order_recurring_id'])) {
|
||||
$implode[] .= "or.order_recurring_id = " . (int)$data['filter_order_recurring_id'];
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$implode[] .= "or.order_id = " . (int)$data['filter_order_id'];
|
||||
}
|
||||
|
||||
if (!empty($data['filter_payment_reference'])) {
|
||||
$implode[] .= " or.reference LIKE '" . $this->db->escape($data['filter_reference']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] .= "CONCAT(o.firstname, ' ', o.lastname) LIKE '" . $this->db->escape($data['filter_customer']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_status'])) {
|
||||
$implode[] .= "or.status = " . (int)$data['filter_status'];
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_added'])) {
|
||||
$implode[] .= "DATE(or.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
class ModelSaleReturn extends Model {
|
||||
public function addReturn($data) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return` SET order_id = '" . (int)$data['order_id'] . "', product_id = '" . (int)$data['product_id'] . "', customer_id = '" . (int)$data['customer_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', product = '" . $this->db->escape($data['product']) . "', model = '" . $this->db->escape($data['model']) . "', quantity = '" . (int)$data['quantity'] . "', opened = '" . (int)$data['opened'] . "', return_reason_id = '" . (int)$data['return_reason_id'] . "', return_action_id = '" . (int)$data['return_action_id'] . "', return_status_id = '" . (int)$data['return_status_id'] . "', comment = '" . $this->db->escape($data['comment']) . "', date_ordered = '" . $this->db->escape($data['date_ordered']) . "', date_added = NOW(), date_modified = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
public function editReturn($return_id, $data) {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "return` SET order_id = '" . (int)$data['order_id'] . "', product_id = '" . (int)$data['product_id'] . "', customer_id = '" . (int)$data['customer_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', product = '" . $this->db->escape($data['product']) . "', model = '" . $this->db->escape($data['model']) . "', quantity = '" . (int)$data['quantity'] . "', opened = '" . (int)$data['opened'] . "', return_reason_id = '" . (int)$data['return_reason_id'] . "', return_action_id = '" . (int)$data['return_action_id'] . "', comment = '" . $this->db->escape($data['comment']) . "', date_ordered = '" . $this->db->escape($data['date_ordered']) . "', date_modified = NOW() WHERE return_id = '" . (int)$return_id . "'");
|
||||
}
|
||||
|
||||
public function deleteReturn($return_id) {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return` WHERE `return_id` = '" . (int)$return_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_history` WHERE `return_id` = '" . (int)$return_id . "'");
|
||||
}
|
||||
|
||||
public function getReturn($return_id) {
|
||||
$query = $this->db->query("SELECT DISTINCT *, (SELECT CONCAT(c.firstname, ' ', c.lastname) FROM " . DB_PREFIX . "customer c WHERE c.customer_id = r.customer_id) AS customer, (SELECT rs.name FROM " . DB_PREFIX . "return_status rs WHERE rs.return_status_id = r.return_status_id AND rs.language_id = '" . (int)$this->config->get('config_language_id') . "') AS return_status FROM `" . DB_PREFIX . "return` r WHERE r.return_id = '" . (int)$return_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getReturns($data = array()) {
|
||||
$sql = "SELECT *, CONCAT(r.firstname, ' ', r.lastname) AS customer, (SELECT rs.name FROM " . DB_PREFIX . "return_status rs WHERE rs.return_status_id = r.return_status_id AND rs.language_id = '" . (int)$this->config->get('config_language_id') . "') AS return_status FROM `" . DB_PREFIX . "return` r";
|
||||
|
||||
$implode = array();
|
||||
|
||||
if (!empty($data['filter_return_id'])) {
|
||||
$implode[] = "r.return_id = '" . (int)$data['filter_return_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$implode[] = "r.order_id = '" . (int)$data['filter_order_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] = "CONCAT(r.firstname, ' ', r.lastname) LIKE '" . $this->db->escape($data['filter_customer']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_product'])) {
|
||||
$implode[] = "r.product = '" . $this->db->escape($data['filter_product']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_model'])) {
|
||||
$implode[] = "r.model = '" . $this->db->escape($data['filter_model']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_return_status_id'])) {
|
||||
$implode[] = "r.return_status_id = '" . (int)$data['filter_return_status_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_added'])) {
|
||||
$implode[] = "DATE(r.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_modified'])) {
|
||||
$implode[] = "DATE(r.date_modified) = DATE('" . $this->db->escape($data['filter_date_modified']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = array(
|
||||
'r.return_id',
|
||||
'r.order_id',
|
||||
'customer',
|
||||
'r.product',
|
||||
'r.model',
|
||||
'status',
|
||||
'r.date_added',
|
||||
'r.date_modified'
|
||||
);
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY r.return_id";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getTotalReturns($data = array()) {
|
||||
$sql = "SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "return`r";
|
||||
|
||||
$implode = array();
|
||||
|
||||
if (!empty($data['filter_return_id'])) {
|
||||
$implode[] = "r.return_id = '" . (int)$data['filter_return_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] = "CONCAT(r.firstname, ' ', r.lastname) LIKE '" . $this->db->escape($data['filter_customer']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$implode[] = "r.order_id = '" . $this->db->escape($data['filter_order_id']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_product'])) {
|
||||
$implode[] = "r.product = '" . $this->db->escape($data['filter_product']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_model'])) {
|
||||
$implode[] = "r.model = '" . $this->db->escape($data['filter_model']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_return_status_id'])) {
|
||||
$implode[] = "r.return_status_id = '" . (int)$data['filter_return_status_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_added'])) {
|
||||
$implode[] = "DATE(r.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_modified'])) {
|
||||
$implode[] = "DATE(r.date_modified) = DATE('" . $this->db->escape($data['filter_date_modified']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalReturnsByReturnStatusId($return_status_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "return` WHERE return_status_id = '" . (int)$return_status_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalReturnsByReturnReasonId($return_reason_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "return` WHERE return_reason_id = '" . (int)$return_reason_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalReturnsByReturnActionId($return_action_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "return` WHERE return_action_id = '" . (int)$return_action_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function addReturnHistory($return_id, $return_status_id, $comment, $notify) {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "return` SET `return_status_id` = '" . (int)$return_status_id . "', date_modified = NOW() WHERE return_id = '" . (int)$return_id . "'");
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_history` SET `return_id` = '" . (int)$return_id . "', return_status_id = '" . (int)$return_status_id . "', notify = '" . (int)$notify . "', comment = '" . $this->db->escape(strip_tags($comment)) . "', date_added = NOW()");
|
||||
}
|
||||
|
||||
public function getReturnHistories($return_id, $start = 0, $limit = 10) {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT rh.date_added, rs.name AS status, rh.comment, rh.notify FROM " . DB_PREFIX . "return_history rh LEFT JOIN " . DB_PREFIX . "return_status rs ON rh.return_status_id = rs.return_status_id WHERE rh.return_id = '" . (int)$return_id . "' AND rs.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY rh.date_added DESC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getTotalReturnHistories($return_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "return_history WHERE return_id = '" . (int)$return_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalReturnHistoriesByReturnStatusId($return_status_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "return_history WHERE return_status_id = '" . (int)$return_status_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
class ModelSaleVoucher extends Model {
|
||||
public function addVoucher($data) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "voucher SET code = '" . $this->db->escape($data['code']) . "', from_name = '" . $this->db->escape($data['from_name']) . "', from_email = '" . $this->db->escape($data['from_email']) . "', to_name = '" . $this->db->escape($data['to_name']) . "', to_email = '" . $this->db->escape($data['to_email']) . "', voucher_theme_id = '" . (int)$data['voucher_theme_id'] . "', message = '" . $this->db->escape($data['message']) . "', amount = '" . (float)$data['amount'] . "', status = '" . (int)$data['status'] . "', date_added = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
public function editVoucher($voucher_id, $data) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "voucher SET code = '" . $this->db->escape($data['code']) . "', from_name = '" . $this->db->escape($data['from_name']) . "', from_email = '" . $this->db->escape($data['from_email']) . "', to_name = '" . $this->db->escape($data['to_name']) . "', to_email = '" . $this->db->escape($data['to_email']) . "', voucher_theme_id = '" . (int)$data['voucher_theme_id'] . "', message = '" . $this->db->escape($data['message']) . "', amount = '" . (float)$data['amount'] . "', status = '" . (int)$data['status'] . "' WHERE voucher_id = '" . (int)$voucher_id . "'");
|
||||
}
|
||||
|
||||
public function deleteVoucher($voucher_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "voucher WHERE voucher_id = '" . (int)$voucher_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "voucher_history WHERE voucher_id = '" . (int)$voucher_id . "'");
|
||||
}
|
||||
|
||||
public function getVoucher($voucher_id) {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "voucher WHERE voucher_id = '" . (int)$voucher_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getVoucherByCode($code) {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "voucher WHERE code = '" . $this->db->escape($code) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getVouchers($data = array()) {
|
||||
$sql = "SELECT v.voucher_id, v.order_id, v.code, v.from_name, v.from_email, v.to_name, v.to_email, (SELECT vtd.name FROM " . DB_PREFIX . "voucher_theme_description vtd WHERE vtd.voucher_theme_id = v.voucher_theme_id AND vtd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS theme, v.amount, v.status, v.date_added FROM " . DB_PREFIX . "voucher v";
|
||||
|
||||
$sort_data = array(
|
||||
'v.code',
|
||||
'v.from_name',
|
||||
'v.to_name',
|
||||
'theme',
|
||||
'v.amount',
|
||||
'v.status',
|
||||
'v.date_added'
|
||||
);
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY v.date_added";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getTotalVouchers() {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "voucher");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalVouchersByVoucherThemeId($voucher_theme_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "voucher WHERE voucher_theme_id = '" . (int)$voucher_theme_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getVoucherHistories($voucher_id, $start = 0, $limit = 10) {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT vh.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, vh.amount, vh.date_added FROM " . DB_PREFIX . "voucher_history vh LEFT JOIN `" . DB_PREFIX . "order` o ON (vh.order_id = o.order_id) WHERE vh.voucher_id = '" . (int)$voucher_id . "' ORDER BY vh.date_added ASC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getTotalVoucherHistories($voucher_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "voucher_history WHERE voucher_id = '" . (int)$voucher_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
class ModelSaleVoucherTheme extends Model {
|
||||
public function addVoucherTheme($data) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "voucher_theme SET image = '" . $this->db->escape($data['image']) . "'");
|
||||
|
||||
$voucher_theme_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['voucher_theme_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "voucher_theme_description SET voucher_theme_id = '" . (int)$voucher_theme_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('voucher_theme');
|
||||
|
||||
return $voucher_theme_id;
|
||||
}
|
||||
|
||||
public function editVoucherTheme($voucher_theme_id, $data) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "voucher_theme SET image = '" . $this->db->escape($data['image']) . "' WHERE voucher_theme_id = '" . (int)$voucher_theme_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "voucher_theme_description WHERE voucher_theme_id = '" . (int)$voucher_theme_id . "'");
|
||||
|
||||
foreach ($data['voucher_theme_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "voucher_theme_description SET voucher_theme_id = '" . (int)$voucher_theme_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('voucher_theme');
|
||||
}
|
||||
|
||||
public function deleteVoucherTheme($voucher_theme_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "voucher_theme WHERE voucher_theme_id = '" . (int)$voucher_theme_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "voucher_theme_description WHERE voucher_theme_id = '" . (int)$voucher_theme_id . "'");
|
||||
|
||||
$this->cache->delete('voucher_theme');
|
||||
}
|
||||
|
||||
public function getVoucherTheme($voucher_theme_id) {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "voucher_theme vt LEFT JOIN " . DB_PREFIX . "voucher_theme_description vtd ON (vt.voucher_theme_id = vtd.voucher_theme_id) WHERE vt.voucher_theme_id = '" . (int)$voucher_theme_id . "' AND vtd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getVoucherThemes($data = array()) {
|
||||
if ($data) {
|
||||
$sql = "SELECT * FROM " . DB_PREFIX . "voucher_theme vt LEFT JOIN " . DB_PREFIX . "voucher_theme_description vtd ON (vt.voucher_theme_id = vtd.voucher_theme_id) WHERE vtd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY vtd.name";
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
} else {
|
||||
$voucher_theme_data = $this->cache->get('voucher_theme.' . (int)$this->config->get('config_language_id'));
|
||||
|
||||
if (!$voucher_theme_data) {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "voucher_theme vt LEFT JOIN " . DB_PREFIX . "voucher_theme_description vtd ON (vt.voucher_theme_id = vtd.voucher_theme_id) WHERE vtd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY vtd.name");
|
||||
|
||||
$voucher_theme_data = $query->rows;
|
||||
|
||||
$this->cache->set('voucher_theme.' . (int)$this->config->get('config_language_id'), $voucher_theme_data);
|
||||
}
|
||||
|
||||
return $voucher_theme_data;
|
||||
}
|
||||
}
|
||||
|
||||
public function getVoucherThemeDescriptions($voucher_theme_id) {
|
||||
$voucher_theme_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "voucher_theme_description WHERE voucher_theme_id = '" . (int)$voucher_theme_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$voucher_theme_data[$result['language_id']] = array('name' => $result['name']);
|
||||
}
|
||||
|
||||
return $voucher_theme_data;
|
||||
}
|
||||
|
||||
public function getTotalVoucherThemes() {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "voucher_theme");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user