function search() { $viewMode = $this->uri->segment(2, "") == "" ? "ma-tran" : $this->uri->segment(2); $orderBy = $this->uri->segment(3, "") == "" ? "moi-nhat" : $this->uri->segment(3); $page = $this->uri->segment(4, "") == "" ? "trang-1" : $this->uri->segment(4); if ($_SERVER['REQUEST_METHOD'] == "POST") { $searchKey = $this->input->post('searchKey'); $this->session->set_userdata('searchKey', $searchKey); } $searchKey = $this->session->userdata('searchkey'); $limit = $viewMode == "ma-tran" ? 15 : 10; $offset = ($this->getPageNumber($page) - 1) * $limit; $product = new Product(); if (trim($searchKey) != "") { $product->like('name', $searchKey); } $product->where('active', 1); $product->order_by($this->getOrderBy($orderBy), $this->getOrderDirection($orderBy)); $product->get_paged_iterated(); $dis['product'] = $product; $dis['pageUrl'] = "tim-kiem"; $config['base_url'] = site_url($url . "/" . $viewMode . "/" . $orderBy . "/trang-"); $config['total_rows'] = $product->paged->total_rows; $config['per_page'] = $limit; $config['use_page_numbers'] = TRUE; $config['uri_segment'] = 4; $config['num_links'] = 3; $config['full_tag_open'] = '<span class="pagin">'; $config['full_tag_close'] = "</span>"; $config['first_link'] = FALSE; $config['first_tag_open'] = ''; $config['first_tag_close'] = ''; $config['last_link'] = FALSE; $config['last_tag_open'] = ''; $config['last_tag_close'] = ''; $config['next_link'] = '<img src="' . base_url() . 'images/pagination_next.png" />'; $config['next_tag_open'] = ''; $config['next_tag_close'] = ''; $config['prev_link'] = '<img src="' . base_url() . 'images/pagination_pre.png" /'; $config['prev_tag_open'] = ''; $config['prev_tag_close'] = ''; $config['num_tag_open'] = ''; $config['num_tag_close'] = ''; $config['cur_tag_open'] = '<span class="active">'; $config['cur_tag_close'] = '</span>'; $this->pagination->initialize($config); if ($viewMode == 'ma-tran') { $dis['view'] = 'product/product_grid'; } else { $dis['view'] = 'product/product_list'; } $productSaleOff = new product(); $productSaleOff->where('active', 1); $productSaleOff->where('isSale', 1); $productSaleOff->order_by('id', 'desc'); $productSaleOff->get_iterated(15); $dis['productSaleOff'] = $productSaleOff; $dis['base_url'] = base_url(); $this->viewfront($dis); }
public function bufet() { $this->load->helper('operations'); $multiplier = operations_ledcoin_multiplier(); $quantity_addition = new Product_quantity(); $quantity_addition->select_sum('quantity', 'quantity_sum'); $quantity_addition->where('type', Product_quantity::TYPE_ADDITION); $quantity_addition->where_related('product', 'id', '${parent}.id'); $quantity_subtraction = new Product_quantity(); $quantity_subtraction->select_sum('quantity', 'quantity_sum'); $quantity_subtraction->where('type', Product_quantity::TYPE_SUBTRACTION); $quantity_subtraction->where_related('product', 'id', '${parent}.id'); $products = new Product(); $products->order_by('price', 'asc'); $products->select('*'); $products->select_subquery($quantity_addition, 'plus_quantity'); $products->select_subquery($quantity_subtraction, 'minus_quantity'); $products->get_iterated(); $this->parser->parse('web/controllers/ledcoin/bufet.tpl', array('products' => $products, 'title' => 'Bufet', 'multiplier' => $multiplier)); }
function productMultiDialog($productId = 0) { $chooseProduct = new Product($productId); $product = new Product(); $dis['searchKey'] = ""; $dis['searchProductCat'] = ""; $dis['searchProductCatId'] = ""; if ($_SERVER['REQUEST_METHOD'] == "POST") { $searchKey = $this->input->post('searchName'); $searchProductCat = $this->input->post('searchProductCat'); $searchProductCatId = $this->input->post('searchProductCatId'); $product->like("name", $searchKey); if ($searchProductCatId != "") { $product->where_related_productcat('id', $searchProductCatId); } $dis['searchKey'] = $searchKey; $dis['searchProductCat'] = $searchProductCat; $dis['searchProductCatId'] = $searchProductCatId; $dis['isSearch'] = true; } if ($productId != 0 && $chooseProduct->accessory->result_count() > 0) { $product->where_not_in('id', $chooseProduct->accessory); } $product->order_by("name", "asc"); $product->get_iterated(100); $dis['chooseProduct'] = $chooseProduct; $dis['base_url'] = base_url(); $dis['product'] = $product; $this->load->view("admin/layout/dialogContent/productMultiSelectDialogContent", $dis); }
function search($value) { $valueSearch = $this->input->post('valueSearch'); $products = new Product(); $products->order_by('position'); $products->like('name_vietnamese', '%' . $valueSearch . '%'); $products->get_iterated(); $dis['products'] = $products; $this->page_title = lang('search') . " - " . $this->page_title; $this->menu_active = 'home'; $dis['base_url'] = base_url(); $this->sidebar = true; $dis['view'] = 'front/searchpage'; $this->page_title = "Kết quả tìm kiếm"; $this->page_keyword = "Kết quả tìm kiếm"; $this->page_description = "Kết quả tìm kiếm"; $this->viewfront($dis); }
private function _generate_number() { $header = "IT"; $YY = date("y"); $MM = date("m"); $headerWithDate = $header . $YY . $MM; $inv = new Product(null, $this->entity); $inv->order_by('id', 'desc'); $inv->get(); $last_no = ""; if ($inv->result_count() > 0) { $last_no = $inv->sku; } $no = 0; $curr_YY = 0; if (strlen($last_no) > 10) { $no = intval(substr($last_no, strlen($last_no) - 5)); $curr_YY = intval(substr($last_no, strlen($last_no) - 9, 2)); } //Reset invoice number back to 1 for the new year starts if (intval($YY) > $curr_YY) { $no = 1; } else { $no++; } $number = $headerWithDate . str_pad($no, 5, "0", STR_PAD_LEFT); return $number; }
function listNew($offset = 0, $limit = 20) { $products = new Product(); $products->where('isNew', 1); $products->order_by('newPosition', 'asc'); if ($_SERVER['REQUEST_METHOD'] == "POST") { if ($this->input->post('submit') == "Cập nhật") { foreach ($_POST as $key => $value) { if (substr($key, 0, 11) == "newPosition") { if (trim($this->input->post($key)) != "") { $keylist = explode("_", $key); $pId = $keylist[1]; $product = new Product($pId); $product->newPosition = $this->input->post($key); $product->save(); $product->clear(); } } } redirect('admin/products/listNew'); } if ($this->input->post('submit') == "Xóa chọn") { $arr = $this->input->post('checkinput'); $this->firephp->log($arr); foreach ($arr as $row) { $product = new Product($row); $product->isNew = 0; $product->save(); $product->clear(); } redirect('admin/products/listNew'); } } $products->get_paged($offset, $limit, TRUE); setPagination($this->admin . 'products/listNew/', $products->paged->total_rows, $limit, 4); $dis['base_url'] = base_url(); $dis['view'] = 'products/listNew'; $dis['products'] = $products; $dis['menu_active'] = "Sản phẩm Mới"; $dis['title_table'] = "Trang hiện tại:" . $products->paged->current_page . '/' . $products->paged->total_pages; $dis['title'] = "Danh sách sản phẩm mới"; $this->viewadmin($dis); }
public function get_form($type = '', $subtraction_type = '') { $this->load->helper('operations'); $operations_addition = new Operation(); $operations_addition->where('type', Operation::TYPE_ADDITION); $operations_addition->select_sum('amount', 'amount_sum'); $operations_addition->where_related_person('id', '${parent}.id'); $operations_subtraction_direct = new Operation(); $operations_subtraction_direct->where('type', Operation::TYPE_SUBTRACTION); $operations_subtraction_direct->where('subtraction_type', Operation::SUBTRACTION_TYPE_DIRECT); $operations_subtraction_direct->select_sum('amount', 'amount_sum'); $operations_subtraction_direct->where_related_person('id', '${parent}.id'); $operations_subtraction_products = new Operation(); $operations_subtraction_products->where('type', Operation::TYPE_SUBTRACTION); $operations_subtraction_products->where('subtraction_type', Operation::SUBTRACTION_TYPE_PRODUCTS); $operations_subtraction_products->where_related('product_quantity', 'price >', 0); $operations_subtraction_products->group_start(' NOT', 'AND'); $operations_subtraction_products->where_related('product_quantity', 'product_id', NULL); $operations_subtraction_products->group_end(); unset($operations_subtraction_products->db->ar_select[0]); $operations_subtraction_products->select_func('SUM', array('@product_quantities.quantity', '*', '@product_quantities.price', '*', '@product_quantities.multiplier'), 'amount_sum'); $operations_subtraction_products->where_related_person('id', '${parent}.id'); $operations_subtraction_services = new Operation(); $operations_subtraction_services->where('type', Operation::TYPE_SUBTRACTION); $operations_subtraction_services->where('subtraction_type', Operation::SUBTRACTION_TYPE_SERVICES); $operations_subtraction_services->where_related('service_usage', 'price >', 0); $operations_subtraction_services->group_start(' NOT', 'AND'); $operations_subtraction_services->where_related('service_usage', 'service_id', NULL); $operations_subtraction_services->group_end(); unset($operations_subtraction_services->db->ar_select[0]); $operations_subtraction_services->select_func('SUM', array('@service_usages.quantity', '*', '@service_usages.price', '*', '@service_usages.multiplier'), 'amount_sum'); $operations_subtraction_services->where_related_person('id', '${parent}.id'); $persons = new Person(); $persons->order_by('surname', 'asc')->order_by('name', 'asc'); $persons->where('admin', 0); $persons->select('*'); $persons->select_subquery($operations_addition, 'plus_amount'); $persons->select_subquery($operations_subtraction_direct, 'minus_amount_direct'); $persons->select_subquery($operations_subtraction_products, 'minus_amount_products'); $persons->select_subquery($operations_subtraction_services, 'minus_amount_services'); $persons->include_related('group', 'title'); $persons->get_iterated(); $persons_select = array('' => ''); foreach ($persons as $person) { $amount = doubleval($person->plus_amount) - intval($person->minus_amount_direct) - intval($person->minus_amount_products) - intval($person->minus_amount_services); $persons_select[$person->id] = $person->name . ' ' . $person->surname . ' (' . $person->group_title . ' | LEDCOIN: ' . $amount . ' ' . get_inflection_ledcoin($amount) . ')'; } $workplaces = new Workplace(); $workplaces->order_by('title', 'asc'); $workplaces->get_iterated(); $workplaces_select = array('' => ''); foreach ($workplaces as $workplace) { $workplaces_select[$workplace->id] = $workplace->title; } $form = array('fields' => array('type' => array('name' => 'operation[type]', 'type' => 'select', 'id' => 'operation-type', 'label' => 'Typ operácie', 'data' => array('stay-visible' => 'true'), 'values' => array('' => '', Operation::TYPE_ADDITION => 'Pridanie LEDCOIN-u', Operation::TYPE_SUBTRACTION => 'Odobratie LEDCOIN-u'), 'validation' => 'required'), 'subtraction_type' => array('name' => 'operation[subtraction_type]', 'type' => 'select', 'id' => 'operation-subtraction_type', 'label' => 'Spôsob odobratia LEDCOIN-u', 'data' => array('stay-visible' => 'true'), 'values' => array('' => '', Operation::SUBTRACTION_TYPE_DIRECT => 'Priame odobratie LEDCOIN-u', Operation::SUBTRACTION_TYPE_PRODUCTS => 'Nákup v bufete', Operation::SUBTRACTION_TYPE_SERVICES => 'Využitie služieb'), 'validation' => 'required'), 'addition_type' => array('name' => 'operation[addition_type]', 'type' => 'select', 'id' => 'operation-addition_type', 'data' => array('stay-visivle' => 'true'), 'label' => 'Spôsob pridania LEDCOIN-u', 'values' => array('' => '', Operation::ADDITION_TYPE_TRANSFER => 'Prevod z účtu vedúcich', Operation::ADDITION_TYPE_MINING => 'Vydolovanie LEDCOIN-u'), 'validation' => 'required'), 'person' => array('name' => 'operation[person_id]', 'type' => 'select', 'id' => 'operation-person_id', 'label' => 'Účastník', 'data' => array('stay-visible' => 'true'), 'values' => $persons_select, 'validation' => 'required'), 'workplace' => array('name' => 'operation[workplace_id]', 'type' => 'select', 'id' => 'operation-workplace_id', 'data' => array('stay-visible' => 'true'), 'label' => 'Zamestnanie', 'values' => $workplaces_select), 'comment' => array('name' => 'operation[comment]', 'type' => 'text_input', 'id' => 'comment-id', 'label' => 'Komentár', 'data' => array('stay-visible' => 'true'), 'validation' => 'max_length[255]'), 'amount' => array('name' => 'operation[amount]', 'type' => 'slider', 'id' => 'comment-amount', 'label' => 'LEDCOIN', 'data' => array('stay-visible' => 'true'), 'min' => 0, 'max' => 25, 'step' => 0.1, 'default' => 0, 'validation' => array(array('if-field-not-equals' => array('field' => 'operation[amount]', 'value' => 0), 'rules' => 'required|floatpoint|convert_floatpoint|greater_than[0]'))), 'multiplier-fake' => array('name' => 'operation[multiplier-fake]', 'type' => 'text_input', 'disabled' => true, 'id' => 'operation-multiplier-fake', 'default' => operations_ledcoin_multiplier(), 'label' => 'Multiplikátor LEDCOIN-u'), 'multiplier' => array('name' => 'operation[multiplier]', 'type' => 'hidden', 'default' => operations_ledcoin_multiplier())), 'arangement' => array('type', 'person', 'workplace', 'comment')); if ($type == Operation::TYPE_SUBTRACTION) { if ($subtraction_type == Operation::SUBTRACTION_TYPE_DIRECT) { $form['arangement'] = array('type', 'subtraction_type', 'person', 'workplace', 'comment', 'amount'); } elseif ($subtraction_type == Operation::SUBTRACTION_TYPE_SERVICES) { $form['arangement'] = array('type', 'subtraction_type', 'person', 'comment', 'multiplier', 'multiplier-fake'); $services = new Service(); $services->order_by('title', 'asc'); $services->get_iterated(); foreach ($services as $service) { $form['fields']['service_' . $service->id . '_quantity'] = array('name' => 'operation_service[' . $service->id . '][quantity]', 'class' => 'controlls-services', 'id' => 'operation_service-' . $service->id . '-quantity', 'type' => 'slider', 'min' => 0, 'max' => 240, 'label' => $service->title . ' (LEDCOIN)', 'data' => array('service-title' => $service->title), 'default' => 0, 'validation' => array(array('if-field-not-equals' => array('field' => 'operation_service[' . $service->id . '][quantity]', 'value' => 0), 'rules' => 'required|integer|greater_than[0]'))); $form['fields']['service_' . $service->id . '_price'] = array('name' => 'operation_service[' . $service->id . '][price]', 'class' => 'controlls-services', 'id' => 'operation_service-' . $service->id . '-price', 'type' => 'text_input', 'label' => $service->title . ' (cena za minútu)', 'data' => array('service-title' => $service->title), 'default' => $service->price, 'validation' => array(array('if-field-not-equals' => array('field' => 'operation_service[' . $service->id . '][quantity]', 'value' => 0), 'rules' => 'required|floatpoint|convert_floatpoint|greater_than[0]'))); $form['arangement'][] = 'service_' . $service->id . '_quantity'; $form['arangement'][] = 'service_' . $service->id . '_price'; } } elseif ($subtraction_type == Operation::SUBTRACTION_TYPE_PRODUCTS) { $form['arangement'] = array('type', 'subtraction_type', 'person', 'comment', 'multiplier', 'multiplier-fake'); $quantity_addition = new Product_quantity(); $quantity_addition->select_sum('quantity', 'quantity_sum'); $quantity_addition->where('type', Product_quantity::TYPE_ADDITION); $quantity_addition->where_related('product', 'id', '${parent}.id'); $quantity_subtraction = new Product_quantity(); $quantity_subtraction->select_sum('quantity', 'quantity_sum'); $quantity_subtraction->where('type', Product_quantity::TYPE_SUBTRACTION); $quantity_subtraction->where_related('product', 'id', '${parent}.id'); $products = new Product(); $products->order_by('title', 'asc'); $products->select('*'); $products->select_subquery($quantity_addition, 'plus_quantity'); $products->select_subquery($quantity_subtraction, 'minus_quantity'); $products->get_iterated(); $p = 1; foreach ($products as $product) { $form['fields']['product_' . $product->id . '_quantity'] = array('name' => 'operation_product[' . $product->id . '][quantity]', 'class' => 'controlls-products', 'id' => 'operation_product-' . $product->id . '-quantity', 'type' => 'slider', 'min' => 0, 'max' => intval($product->plus_quantity) - intval($product->minus_quantity), 'label' => '<span class="product_title_label"><img src="' . get_product_image_min($product->id) . '" alt="" /><span class="product_title">' . $product->title . ' (počet kusov)</span></span>', 'default' => 0, 'disabled' => intval($product->plus_quantity) - intval($product->minus_quantity) <= 0 ? true : false, 'data' => array('product-title' => $product->title), 'validation' => array(array('if-field-not-equals' => array('field' => 'operation_product[' . $product->id . '][quantity]', 'value' => 0), 'rules' => 'required|integer|greater_than[0]|less_than_equals[' . (intval($product->plus_quantity) - intval($product->minus_quantity)) . ']'))); $form['fields']['product_' . $product->id . '_price'] = array('name' => 'operation_product[' . $product->id . '][price]', 'class' => 'controlls-products', 'id' => 'operation_product-' . $product->id . '-price', 'type' => 'text_input', 'label' => $product->title . ' (cena za kus)', 'default' => $product->price, 'disabled' => intval($product->plus_quantity) - intval($product->minus_quantity) <= 0 ? true : false, 'data' => array('product-title' => $product->title), 'validation' => array(array('if-field-not-equals' => array('field' => 'operation_product[' . $product->id . '][quantity]', 'value' => 0), 'rules' => 'required|floatpoint|convert_floatpoint|greater_than[0]'))); $form['arangement'][] = 'product_' . $product->id . '_quantity'; $form['arangement'][] = 'product_' . $product->id . '_price'; if ($p < $products->result_count()) { $form['fields']['product_' . $product->id . '_divider'] = array('type' => 'divider', 'data' => array('product-title' => $product->title)); $form['arangement'][] = 'product_' . $product->id . '_divider'; } $p++; } } else { $form['arangement'] = array('type', 'subtraction_type', 'person'); } } else { $form['arangement'][] = 'addition_type'; $form['arangement'][] = 'amount'; } if ($type == Operation::TYPE_ADDITION) { $form['fields']['amount']['validation'] = 'required|floatpoint|convert_floatpoint|greater_than[0]'; } elseif ($type == Operation::TYPE_SUBTRACTION) { } else { $form['arangement'] = array('type'); } return $form; }
protected function get_batch_stock_addition_form() { $products = new Product(); $products->order_by('title', 'asc'); $products->get_iterated(); $form_fields = array(); $form_arangement = array(); foreach ($products as $product) { $form_fields['product_' . $product->id] = array('name' => 'product_quantity_addition[' . $product->id . '][quantity]', 'data' => array('product-name' => $product->title), 'id' => 'product_quantity_addition-' . $product->id, 'label' => '<span class="product_title_label"><img src="' . get_product_image_min($product->id) . '" alt="" /><span class="product_title">' . $product->title . '</span></span>', 'placeholder' => 'Nechajte prázdne, ak nie je čo pridať.', 'type' => 'text_input', 'validation' => array(array('if-field-not-equals' => array('field' => 'product_quantity_addition[' . $product->id . '][quantity]', 'value' => ''), 'rules' => 'required|integer|greater_than[0]'), array('if-field-equals' => array('field' => 'product_quantity_addition[' . $product->id . '][quantity]', 'value' => ''), 'rules' => 'callback__ok'))); $form_arangement[] = 'product_' . $product->id; } return array('fields' => $form_fields, 'arangement' => $form_arangement); }