Example #1
0
 public function dashboard()
 {
     $sucursales = Branch::count();
     $usuarios = User::count();
     $clientes = Client::count();
     $productos = Product::count();
     $informacionCuenta = array('sucursales' => $sucursales, 'usuarios' => $usuarios, 'clientes' => $clientes, 'productos' => $productos);
     // return Response::json($informacionCuenta);
     return View::make('cuentas.dashboard')->with('cuenta', $informacionCuenta);
 }
Example #2
0
 public function validate()
 {
     if ($this->id) {
         $rows = Product::count(array('conditions' => array('category_id = ? AND name = ? AND id <> ?', $this->category_id, $this->name, $this->id)));
     } else {
         $rows = Product::count(array('conditions' => array('category_id = ? AND name = ? ', $this->category_id, $this->name)));
     }
     if ($rows) {
         $this->errors->add('name', "El nombre del producto no es único en esta categoría. Por favor, escribe otro nombre");
     }
 }
    public function listProduct()
    {
        if (!Request::ajax()) {
            return App::abort(404);
        }
        $admin_id = Auth::admin()->get()->id;
        $start = Input::has('start') ? (int) Input::get('start') : 0;
        $length = Input::has('length') ? Input::get('length') : 10;
        $search = Input::has('search') ? Input::get('search') : [];
        $products = Product::with('mainImage')->select(DB::raw('id, name, sku, sell_price, short_description, active,
												(SELECT COUNT(*)
													FROM notifications
										         	WHERE notifications.item_id = products.id
										         		AND notifications.item_type = "Product"
														AND notifications.admin_id = ' . $admin_id . '
														AND notifications.read = 0 ) as new'));
        if (!empty($search)) {
            foreach ($search as $key => $value) {
                if (empty($value)) {
                    continue;
                }
                if ($key == 'active') {
                    if ($value == 'yes') {
                        $value = 1;
                    } else {
                        $value = 0;
                    }
                    $products->where($key, $value);
                } else {
                    if ($key == 'sell_price') {
                        $value = trim($value);
                        if (strpos($value, '-') !== false) {
                            list($from, $to) = explode('-', $value);
                            $products->where($key, '>', (double) $from);
                            $products->where($key, '<', (double) $to);
                        } else {
                            $products->where($key, (double) $value);
                        }
                    } else {
                        if ($key == 'category' && !empty($value)) {
                            if (is_numeric($value)) {
                                $products->whereHas('categories', function ($query) use($value) {
                                    $query->where('categories.id', $value);
                                });
                            } else {
                                if (is_array($value)) {
                                    foreach ($value as $k => $v) {
                                        if (empty($v)) {
                                            unset($value[$k]);
                                        }
                                    }
                                    if (empty($value)) {
                                        continue;
                                    }
                                    $products->whereHas('categories', function ($query) use($value) {
                                        $query->whereIn('categories.id', $value);
                                    });
                                } else {
                                    $products->whereHas('categories', function ($query) use($value) {
                                        $query->where('categories.name', 'like', '%' . $value . '%');
                                    });
                                }
                            }
                        } else {
                            $value = ltrim(rtrim($value));
                            $products->where($key, 'like', '%' . $value . '%');
                        }
                    }
                }
            }
        }
        $order = Input::has('order') ? Input::get('order') : [];
        if (!empty($order)) {
            $columns = Input::has('columns') ? Input::get('columns') : [];
            foreach ($order as $value) {
                $column = $value['column'];
                if (!isset($columns[$column]['name']) || empty($columns[$column]['name'])) {
                    continue;
                }
                $products->orderBy($columns[$column]['name'], $value['dir'] == 'asc' ? 'asc' : 'desc');
            }
        }
        $count = $products->count();
        if ($length > 0) {
            $products = $products->skip($start)->take($length);
        }
        $arrProducts = $products->get();
        $arrReturn = ['draw' => Input::has('draw') ? Input::get('draw') : 1, 'recordsTotal' => Product::count(), 'recordsFiltered' => $count, 'data' => []];
        $arrRemoveNew = [];
        if (!empty($arrProducts)) {
            foreach ($arrProducts as $product) {
                if (isset($product->main_image[0])) {
                    $image = URL . '/' . str_replace('/images/products', '/images/products/thumbs', $product->main_image[0]->path);
                } else {
                    $image = URL . '/assets/images/noimage/110x110.gif';
                }
                $name = $product->name;
                if ($product->new) {
                    $name .= '| <span class="badge badge-danger">new</span>';
                    $arrRemoveNew[] = $product->id;
                }
                if (empty($product->short_description)) {
                    $product->short_description = '(empty)';
                }
                $data = Product::getSmallestPrice($product, true);
                $arrReturn['data'][] = array(++$start, $product->id, $name, $product->sku, "({$data['sizew']}x{$data['sizeh']})|{$data['sell_price']}", $image, $product->short_description, $product->active);
            }
        }
        if (!empty($arrRemoveNew)) {
            Notification::whereIn('item_id', $arrRemoveNew)->where('item_type', 'Product')->where('admin_id', $admin_id)->update(['read' => 1]);
        }
        $response = Response::json($arrReturn);
        $response->header('Content-Type', 'application/json');
        return $response;
    }
Example #4
0
<?php

!defined('IN_PTF') && exit('ILLEGAL EXECUTION');
/**
 * @file    index
 * @author  ryan <*****@*****.**>
 * @created Jun 27, 2012 6:24:01 PM
 */
if ($user_type === 'Admin') {
    redirect('order/all');
}
if ($user_type === 'SuperAdmin') {
    redirect('admin');
}
list($name, $no, $stone_size, $type) = _get('name', 'no', 'stone_size', 'type');
$mode = _get('mode') ?: 'list';
$cur_page = _get('p') ?: 1;
$page_num_map = array('list' => 10, 'image' => 24);
$per_page = $page_num_map[$mode];
$conds = compact('name', 'no', 'stone_size', 'type');
$total = Product::count($conds);
$paging = new Paginate($per_page, $total);
$paging->setCurPage($cur_page);
$products = Product::read(array_merge($conds, array('limit' => $per_page, 'offset' => $paging->offset())));
$chosen_map = SesState::chosenProducts();
$types = Product::types();
$view .= '?master';
$page['scripts'][] = 'widget';
Example #5
0
            $admin->delProduct($ids);
            exit;
            break;
        default:
            throw new Exception("unkown action: {$action}");
            break;
    }
}
$types = Product::types();
switch ($target) {
    case '':
        list($name, $no, $type, $sort1, $sort2) = _get('name', 'no', 'type', 'sort1', 'sort2');
        $sort = $sort1 ? $sort1 . ' ' . $sort2 : '';
        $p = _get('p') ?: 1;
        $per_page = 50;
        $total = Product::count(array('name' => $name, 'no' => $no, 'type' => $type));
        $paging = new Paginate($per_page, $total);
        $paging->setCurPage($p);
        $products = Product::listProduct(array('limit' => $per_page, 'offset' => $paging->offset(), 'name' => $name, 'no' => $no, 'type' => $type, 'sort' => $sort));
        break;
    case 'post':
        $types = Product::types();
        list($name, $no, $type, $material, $weight, $rabbet_start, $rabbet_end, $small_stone, $st_weight, $remark) = _post('name', 'no', 'type', 'material', 'weight', 'rabbet_start', 'rabbet_end', 'small_stone', 'st_weight', 'remark');
        $image1 = _post('image1');
        $image1_400 = _post('image1_400');
        $image1_thumb = _post('image1_thumb');
        $image2 = _post('image2');
        $image2_400 = _post('image2_400');
        $image2_thumb = _post('image2_thumb');
        $image3 = _post('image3');
        $image3_400 = _post('image3_400');
Example #6
0
File: test.php Project: name3/cheng
// for ($i=0; $i < 50; $i++) {
//     $info2 = $info;
//     $info2['name'] = $info['name'] . $i;
//     $admin->postProduct($info2);
// }
// but what if we count?
test(Pdb::fetchRow('*', Product::$table, array('id=?' => $product->id)), $info, array('name' => 'Admin post Product, db', 'compare' => 'in'));
// case 9 Admin del Product
begin_test();
$info = array_merge($info, array('name' => 'product test to del'));
$product_to_del1 = $admin->postProduct($info);
$product_to_del2 = $admin->postProduct($info);
$old_num = Product::count();
$admin->delProduct($product_to_del1);
$admin->delProduct($product_to_del2->id);
$new_num = Product::count();
test($old_num - 2, $new_num, array('name' => 'Admin del Product'));
// case 10 Customer edit Address
begin_test();
$address = $customer->defaultAddress();
$address->edit(array('name' => '小池', 'phone' => '14722320989', 'detail' => '深圳罗湖区田贝'));
test(1, 1, array('name' => 'Customer edit Address'));
// case 11 Customer add a Product to Cart
begin_test();
$old_entry_num = Pdb::count(Order::$table);
$opts = array('material' => 'PT950', 'size' => 12, 'carve_text' => 'I love U');
$order = $customer->addProductToCart($product, $opts);
$entry_num = Pdb::count(Order::$table);
test($old_entry_num + 1, +$entry_num, array('name' => 'Customer add a Product to Cart'));
// case 12 Cart count()
begin_test();
Example #7
0
 private function set_paginate_options($method = NULL, $category_id = NULL)
 {
     $config = array();
     if ($method == 'index') {
         $config["base_url"] = site_url() . "products";
     } else {
         $config["base_url"] = site_url() . "products/product_list/" . $category_id;
     }
     if ($method == 'index') {
         $config["total_rows"] = Product::count();
     } else {
         $config["total_rows"] = Product::count(array('conditions' => 'category_id = ' . $category_id . ''));
     }
     $config["use_page_numbers"] = TRUE;
     $config["per_page"] = 5;
     if ($method == 'index') {
         $config["uri_segment"] = 3;
     } else {
         $config["uri_segment"] = 5;
     }
     $config["first_link"] = "<< " . lang('web_first');
     $config['first_tag_open'] = "<span class='pag'>";
     $config['first_tag_close'] = '</span>';
     $config['last_link'] = lang('web_last') . " >>";
     $config['last_tag_open'] = "<span class='pag'>";
     $config['last_tag_close'] = "</span>";
     $config['next_link'] = FALSE;
     $config['next_tag_open'] = "<span class='pag'>";
     $config['next_tag_close'] = '</span>';
     $config['prev_link'] = FALSE;
     $config['prev_tag_open'] = "<span class='pag'>";
     $config['prev_tag_close'] = '</span>';
     $config['cur_tag_open'] = "<span class='pag pag_active'>";
     $config['cur_tag_close'] = '</span>';
     $config['num_tag_open'] = "<span class='pag'>";
     $config['num_tag_close'] = '</span>';
     $config['full_tag_open'] = "<div class='navigation'>";
     $config['full_tag_close'] = '</div>';
     $choice = $config["total_rows"] / $config["per_page"];
     //$config["num_links"] = round($choice);
     return $config;
 }