Esempio n. 1
0
 function do_manage($is_show = "")
 {
     global $ttH;
     $err = "";
     //update
     if (isset($ttH->input['do_action'])) {
         $up_id = isset($ttH->input["selected_id"]) ? $ttH->input["selected_id"] : array();
         switch ($ttH->input["do_action"]) {
             case "do_edit":
                 $arr_show_order = isset($ttH->post["show_order"]) ? $ttH->post["show_order"] : array();
                 $arr_is_focus = isset($ttH->post["is_focus"]) ? $ttH->post["is_focus"] : array();
                 $mess = $ttH->lang['global']['edit_success'] . " ID: <strong>";
                 $str_mess = "";
                 for ($i = 0; $i < count($up_id); $i++) {
                     $dup = array();
                     $dup['show_order'] = $arr_show_order[$up_id[$i]];
                     $dup['is_focus'] = isset($arr_is_focus[$up_id[$i]]) ? $arr_is_focus[$up_id[$i]] : 0;
                     $ok = $ttH->db->do_update("product", $dup, "item_id=" . $up_id[$i]);
                     if ($ok) {
                         $str_mess .= $str_mess ? ", " : "";
                         $str_mess .= $up_id[$i];
                     } else {
                         $mess .= $ttH->lang["global"]['edit_false'] . " ID: <strong>" . $up_id[$i] . "</strong>";
                     }
                 }
                 $mess .= $str_mess . "</strong>";
                 $err = $ttH->html->html_alert($mess, "success");
                 break;
             case "do_duplicate":
                 if (isset($ttH->input['id'])) {
                     $list_duplicate = $ttH->input['id'];
                 } elseif (isset($ttH->post['selected_id']) && is_array($ttH->post['selected_id'])) {
                     $list_duplicate = @implode(',', $ttH->post['selected_id']);
                 }
                 $err = $this->do_duplicate($list_duplicate);
                 break;
             case "do_restore":
                 $up_id = isset($ttH->input["id"]) ? array($ttH->input["id"]) : $up_id;
                 $mess = $ttH->lang['global']['restore_success'] . " ID: <strong>";
                 $str_mess = "";
                 for ($i = 0; $i < count($up_id); $i++) {
                     $dup = array();
                     $dup['is_show'] = 1;
                     $ok = $ttH->db->do_update("product", $dup, "item_id=" . $up_id[$i]);
                     if ($ok) {
                         $str_mess .= $str_mess ? ", " : "";
                         $str_mess .= $up_id[$i];
                     } else {
                         $mess .= $ttH->lang["global"]['restore_false'] . " ID: <strong>" . $up_id[$i] . "</strong>";
                     }
                 }
                 $mess .= $str_mess . "</strong>";
                 $err = $ttH->html->html_alert($mess, "success");
                 break;
             case "do_trash":
                 $up_id = isset($ttH->input["id"]) ? array($ttH->input["id"]) : $up_id;
                 $mess = $ttH->lang['global']['trash_success'] . " ID: <strong>";
                 $str_mess = "";
                 for ($i = 0; $i < count($up_id); $i++) {
                     $dup = array();
                     $dup['is_show'] = 0;
                     $ok = $ttH->db->do_update("product", $dup, "item_id=" . $up_id[$i]);
                     if ($ok) {
                         $str_mess .= $str_mess ? ", " : "";
                         $str_mess .= $up_id[$i];
                     } else {
                         $mess .= $ttH->lang["global"]['trash_false'] . " ID: <strong>" . $up_id[$i] . "</strong>";
                     }
                 }
                 $mess .= $str_mess . "</strong>";
                 $err = $ttH->html->html_alert($mess, "success");
                 break;
             case "do_del":
                 if (isset($ttH->input['id'])) {
                     $list_del = $ttH->input['id'];
                 } elseif (isset($ttH->post['selected_id']) && is_array($ttH->post['selected_id'])) {
                     $list_del = @implode(',', $ttH->post['selected_id']);
                 }
                 $err = $this->do_del($list_del);
                 break;
         }
     }
     $p = isset($ttH->input["p"]) ? $ttH->input["p"] : 1;
     $search_date_begin = isset($ttH->input["search_date_begin"]) ? $ttH->input["search_date_begin"] : "";
     $search_date_end = isset($ttH->input["search_date_end"]) ? $ttH->input["search_date_end"] : "";
     $search_product_id = isset($ttH->input["search_product_id"]) ? $ttH->input["search_product_id"] : 0;
     $search_title = isset($ttH->input["search_title"]) ? $ttH->input["search_title"] : "";
     $where = " and is_level=0 ";
     $ext = "";
     $is_search = 0;
     if ($is_show == "trash") {
         $where .= " and is_show=0 ";
     } else {
         $where .= " and is_show=2 ";
     }
     if ($search_date_begin || $search_date_end) {
         $tmp1 = @explode("/", $search_date_begin);
         $time_begin = @mktime(0, 0, 0, $tmp1[1], $tmp1[0], $tmp1[2]);
         $tmp2 = @explode("/", $search_date_end);
         $time_end = @mktime(23, 59, 59, $tmp2[1], $tmp2[0], $tmp2[2]);
         $where .= " AND (a.date_create BETWEEN {$time_begin} AND {$time_end} ) ";
         $ext .= "&date_begin=" . $search_date_begin . "&date_end=" . $search_date_end;
         $is_search = 1;
     }
     if (!empty($search_product_id)) {
         $where .= " and type='product' and type_id='" . $search_product_id . "' ";
         $ext .= "&search_product_id=" . $search_product_id;
         $is_search = 1;
     }
     if (!empty($search_title)) {
         $where .= " and (a.receipt_id='{$search_title}' or receipt_code like '%{$search_title}%') ";
         $ext .= "&search_title=" . $search_title;
         $is_search = 1;
     }
     $num_total = 0;
     $res_num = $ttH->db->query("select a.item_id \n\t\t\t\t\t\tfrom repository_receipt a, repository_receipt_detail al \n\t\t\t\t\t\twhere a.receipt_id=al.receipt_id \n\t\t\t\t\t\t" . $where . "  ");
     $num_total = $ttH->db->num_rows($res_num);
     $n = $ttH->conf["n_list"] ? $ttH->conf["n_list"] : 30;
     $num_products = ceil($num_total / $n);
     if ($p > $num_products) {
         $p = $num_products;
     }
     if ($p < 1) {
         $p = 1;
     }
     $start = ($p - 1) * $n;
     $link_action = $ttH->admin->get_link_admin($this->modules_call, $this->action, $this->sub);
     //Sort
     $arr_title = array("item_id" => array("title" => $ttH->lang["global"]["id"], "link" => $link_action . "&p=" . $p . $ext . "&sort=item_id-desc", "class" => ""), "item_code" => array("title" => $ttH->lang["global"]["series"], "link" => $link_action . "&p=" . $p . $ext . "&sort=item_code-desc", "class" => ""), "show_order" => array("title" => $ttH->lang["global"]["show_order"], "link" => $link_action . "&p=" . $p . $ext . "&sort=show_order-desc", "class" => ""), "picture" => array("title" => $ttH->lang["global"]["picture"], "link" => $link_action . "&p=" . $p . $ext . "&sort=picture-desc", "class" => ""), "title" => array("title" => 'Tên sản phẩm', "link" => $link_action . "&p=" . $p . $ext . "&sort=title-desc", "class" => ""), "price" => array("title" => 'Giá nhập', "link" => $link_action . "&p=" . $p . $ext . "&sort=price-desc", "class" => ""), "quantity" => array("title" => $ttH->lang['global']['quantity'], "link" => $link_action . "&p=" . $p . $ext . "&sort=quantity-desc", "class" => ""), "date_create" => array("title" => $ttH->lang["global"]["date_create"], "link" => $link_action . "&p=" . $p . $ext . "&sort=date_create-desc", "class" => ""));
     $sort = isset($ttH->input["sort"]) ? $ttH->input["sort"] : "";
     if ($sort) {
         $arr_allow_sort = array(1 => "asc", 2 => "desc");
         $tmp = explode("-", $sort);
         if (array_key_exists($tmp[0], $arr_title) && in_array($tmp[1], $arr_allow_sort)) {
             $order_tmp = $tmp[0] == "item_id" ? "a.item_id" : $tmp[0];
             $order_tmp = $tmp[0] == "import_stock" ? "(in_stock+out_stock)" : $tmp[0];
             $where .= " order by " . $order_tmp . " " . $tmp[1];
             $arr_title[$tmp[0]]["class"] = $tmp[1];
             $arr_title[$tmp[0]]["link"] = $link_action . "&p=" . $p . $ext . "&sort=" . $tmp[0] . "-" . $arr_allow_sort[3 - array_search($tmp[1], $arr_allow_sort)];
         } else {
             $sort = "";
         }
     }
     if ($sort == "") {
         $where .= " order by a.date_create DESC";
     }
     //End sort
     //Title row
     foreach ($arr_title as $k => $v) {
         $class = $v["class"] ? " class='" . $v["class"] . "'" : "";
         $data["f_" . $k] = '<a href="' . $v["link"] . '" ' . $class . '>' . $v["title"] . '</a>';
     }
     //End title row
     $sql = "select * \n\t\t\t\t\t\tfrom repository_receipt a, repository_receipt_detail al \n\t\t\t\t\t\twhere a.receipt_id=al.receipt_id \n\t\t\t\t\t\t" . $where . " \n\t\t\t\t\t\tlimit {$start},{$n}";
     //die($sql);
     $nav = $ttH->admin->admin_paginate($link_action, $num_total, $n, $ext, $p);
     $result = $ttH->db->query($sql);
     $i = 0;
     $html_row = "";
     if ($num = $ttH->db->num_rows($result)) {
         while ($row = $ttH->db->fetch_row($result)) {
             $i++;
             $row['stt'] = $start + $i;
             $html_row .= $this->manage_row($row, $is_show);
         }
     } else {
         $ttH->temp_act->assign('row', array("mess" => $ttH->lang["global"]["no_have_data"]));
         $ttH->temp_act->parse("manage.row_empty");
     }
     $data['html_row'] = $html_row;
     $data['nav'] = $nav;
     $data['err'] = $err;
     $data['link_action_search'] = $link_action;
     $data['link_action'] = $link_action . "&p=" . $p . $ext;
     $data['search_date_begin'] = $search_date_begin;
     $data['search_date_end'] = $search_date_end;
     $data['search_title'] = $search_title;
     $data["list_product_search"] = list_product("search_product_id", $search_product_id, " class=\"form-control\"", array("title" => $ttH->lang['global']['select_title']));
     $data['form_search_class'] = $is_search == 1 ? ' expand' : '';
     $ttH->temp_act->assign('data', $data);
     $ttH->temp_act->parse("manage");
     return $ttH->temp_act->text("manage");
 }
Esempio n. 2
0
 function get_list_type()
 {
     global $ttH;
     $output = "";
     switch ($this->type) {
         case "group":
             $link = $ttH->admin->get_link_admin($this->modules, $this->action, $this->sub);
             $ext = "onchange=\"go_link('" . $link . "&type=" . $this->type . "&type_id='+this.value)\"";
             if ($this->sub == 'edit') {
                 $ext = '';
             }
             $output = list_group("type_id", $this->type_id, " class=\"form-control\" " . $ext, array("title" => $ttH->lang['global']['select_title']));
             break;
         case "item":
             $link = $ttH->admin->get_link_admin($this->modules, $this->action, $this->sub);
             $ext = "onchange=\"go_link('" . $link . "&type=" . $this->type . "&type_id='+this.value)\"";
             if ($this->sub == 'edit') {
                 $ext = '';
             }
             $output = list_product("type_id", $this->type_id, " class=\"form-control\" " . $ext, array("title" => $ttH->lang['global']['select_title']));
             break;
     }
     return $output;
 }
Esempio n. 3
0
 function do_add()
 {
     global $ttH;
     $ttH->func->include_js($ttH->dir_temp . 'js/' . $this->modules . '/' . $this->modules . '.js');
     $arr_color = $ttH->load_data->data_table('product_color', 'color_id', 'color_id,color,title', "\tlang='" . $ttH->conf['lang_cur'] . "' order by show_order desc, date_create desc");
     $arr_size = $ttH->load_data->data_table('product_size', 'size_id', 'size_id,title', "\tlang='" . $ttH->conf['lang_cur'] . "' order by show_order desc, date_create desc");
     $data = array();
     $err = "";
     if (isset($ttH->post['do_submit'])) {
         /*print_arr($ttH->post);
         		die();*/
         $receipt_code = isset($ttH->post["receipt_code"]) ? $ttH->post["receipt_code"] : '';
         if (empty($err) && empty($receipt_code)) {
             $err = $ttH->html->html_alert('Mã số chưa nhập', "error");
         }
         if (empty($err)) {
             $sql = "select receipt_code from repository_receipt where receipt_code='" . $receipt_code . "'";
             $result = $ttH->db->query($sql);
             if ($check = $ttH->db->fetch_row($result)) {
                 $err = $ttH->html->html_alert('Mã số đã tồn tại', "error");
             }
         }
         $price = isset($ttH->post["price"]) ? $ttH->post["price"] : array();
         $import = isset($ttH->post["import"]) ? $ttH->post["import"] : array();
         $import_sub = isset($ttH->post["import_sub"]) ? $ttH->post["import_sub"] : array();
         if (empty($err) && count($import) <= 0) {
             $err = $ttH->html->html_alert('Chưa chọn sản phẩm nhập', "error");
         }
         $has_import = 0;
         foreach ($import as $k => $v) {
             if ($v > 0) {
                 $has_import = 1;
             }
         }
         foreach ($import_sub as $k => $v) {
             if ($v <= 0) {
                 unset($import_sub[$k]);
             }
         }
         if (empty($err) && ($has_import === 0 && count($import_sub) <= 0)) {
             $err = $ttH->html->html_alert('Chưa nhập số lượng hàng', "error");
         }
         /*print_arr($ttH->post);
         		print_arr($price);
         		print_arr($import);
         		print_arr($import_sub);
         		die();*/
         if (empty($err)) {
             $col = array();
             $col["receipt_code"] = $receipt_code;
             $col["receipt_type"] = $this->receipt_type;
             $col["repository_id"] = $ttH->post['repository_id'];
             $col["show_order"] = 0;
             $col["is_show"] = 0;
             $col["admin_id"] = $ttH->data['admin']["id"];
             $col["date_create"] = time();
             $col["date_update"] = time();
             $ok = $ttH->db->do_insert("repository_receipt", $col);
             if ($ok) {
                 $receipt_id = $ttH->db->insertid();
                 $arr_type_in_stock = array();
                 foreach ($import_sub as $k => $v) {
                     $arr_tmp = explode('_', $k);
                     $col_l = array();
                     $col_l["receipt_id"] = $receipt_id;
                     $col_l["is_level"] = 1;
                     $col_l["type"] = 'product';
                     $col_l["type_id"] = str_replace('p', '', $arr_tmp[0]);
                     $col_l["color_id"] = str_replace('c', '', $arr_tmp[1]);
                     $col_l["size_id"] = str_replace('s', '', $arr_tmp[2]);
                     $col_l["quantity"] = $v;
                     $col_l["date_create"] = time();
                     $col_l["date_update"] = time();
                     $arr_type_in_stock[$col_l["type_id"]] = isset($arr_type_in_stock[$col_l["type_id"]]) ? $arr_type_in_stock[$col_l["type_id"]] + $col_l["quantity"] : $col_l["quantity"];
                     $where = "and type='" . $col_l["type"] . "'\r\r\n\t\t\t\t\t\t\t\t\t\t\tand type_id='" . $col_l["type_id"] . "'\r\r\n\t\t\t\t\t\t\t\t\t\t\tand color_id='" . $col_l["color_id"] . "'\r\r\n\t\t\t\t\t\t\t\t\t\t\tand size_id='" . $col_l["size_id"] . "' ";
                     // if not has repository_receipt_detail, Insert repository_receipt_detail
                     $ttH->db->query("update repository_receipt_detail \r\r\n\t\t\t\t\t\t\t\t\t\t\tset quantity=(quantity+" . $col_l["quantity"] . "), \r\r\n\t\t\t\t\t\t\t\t\t\t\t\tdate_update=" . $col_l["date_update"] . "  \r\r\n\t\t\t\t\t\t\t\t\t\t\twhere receipt_id='" . $col_l["receipt_id"] . "'\r\r\n\t\t\t\t\t\t\t\t\t\t\t" . $where);
                     if (!$ttH->db->affected()) {
                         $ttH->db->do_insert("repository_receipt_detail", $col_l);
                     }
                     // End
                 }
                 foreach ($import as $k => $v) {
                     if (isset($arr_type_in_stock[$k]) && $arr_type_in_stock[$k] > 0) {
                         $v = $arr_type_in_stock[$k];
                     }
                     if ($v > 0) {
                         $col_l = array();
                         $col_l["receipt_id"] = $receipt_id;
                         $col_l["is_level"] = 0;
                         $col_l["type"] = 'product';
                         $col_l["type_id"] = $k;
                         $col_l["color_id"] = 0;
                         $col_l["size_id"] = 0;
                         $col_l["price"] = isset($price[$k]) ? $price[$k] : 0;
                         $col_l["quantity"] = $v;
                         $col_l["date_create"] = time();
                         $col_l["date_update"] = time();
                         $ttH->db->do_insert("repository_receipt_detail", $col_l);
                     }
                 }
                 $data = array();
                 $err = $ttH->html->html_alert($ttH->lang["global"]["add_success"], "success");
             } else {
                 $data = $ttH->post;
                 $err = $ttH->html->html_alert($ttH->lang["global"]["add_false"], "error");
             }
         } else {
             $data = $ttH->post;
         }
     }
     $data["err"] = $err;
     $arr_isset = array('repository_id', 'list_product');
     foreach ($arr_isset as $tmp) {
         $data[$tmp] = isset($data[$tmp]) ? $data[$tmp] : '';
     }
     $data['date_create'] = isset($data['date_create']) ? $data['date_create'] : date('d/m/Y');
     $data['date_create_hour'] = isset($data['date_create_hour']) ? $data['date_create_hour'] : date('H');
     $data['date_create_minute'] = isset($data['date_create_minute']) ? $data['date_create_minute'] : date('i');
     $data['receipt_code'] = isset($data['receipt_code']) ? $data['receipt_code'] : receipt_code_next();
     $data["link_action"] = $ttH->admin->get_link_admin($this->modules_call, $this->action, $this->sub);
     $data["list_product"] = list_product("list_product", $data["list_product"], " class=\"form-control\" id=\"list_product\"", array('title' => $ttH->lang['global']['select_title']));
     $data["list_repository"] = list_repository("repository_id", $data["repository_id"], " class=\"form-control\"", array('title' => $ttH->lang['global']['select_title']));
     $data["list_hour"] = $ttH->admin->list_number("date_create_hour", 0, 23, $data["date_create_hour"]);
     $data["list_minute"] = $ttH->admin->list_number("date_create_minute", 0, 59, $data["date_create_minute"]);
     foreach ($arr_color as $row_color) {
         foreach ($arr_size as $row_size) {
             $row_sub['sub_id'] = 'c' . $row_color['color_id'] . '_s' . $row_size['size_id'];
             $row_sub['color'] = $row_color;
             $row_sub['size'] = $row_size;
             $row_sub['in_stock'] = 0;
             $row_sub['out_stock'] = 0;
             $row_sub['import'] = 0;
             $ttH->temp_act->assign('row', $row_sub);
             $ttH->temp_act->parse("add.row_sub_item");
         }
     }
     $ttH->temp_act->assign('data', $data);
     $ttH->temp_act->parse("add");
     return $ttH->temp_act->text("add");
 }
Esempio n. 4
0
        break;
    case 'del_currency':
        del_currency();
        list_currencies();
        break;
    case 'options':
        options();
        break;
    case 'urls':
        urls();
        break;
    case 'automation':
        automation();
        break;
    default:
        list_product();
}
function list_product()
{
    global $tpl, $mysql, $lang, $twig;
    $tpath = locatePluginTemplates(array('config/main', 'config/list_product'), 'eshop', 1);
    $tVars = array();
    $res = mysql_query("SELECT * FROM " . prefix . "_eshop_categories ORDER BY position, id");
    $cats = getCats($res);
    // Load admin page based cookies
    $admCookie = admcookie_get();
    $fName = $_REQUEST['fname'];
    $fStatus = $_REQUEST['fstatus'];
    $fCategory = $_REQUEST['fcategory'];
    $news_per_page = isset($_REQUEST['rpp']) ? intval($_REQUEST['rpp']) : intval($admCookie['eshop']['pp']);
    // - Set default value for `Records Per Page` parameter