Пример #1
0
$g->table = "cat";
$col = array();
$col["title"] = "Table";
// caption of column
$col["name"] = "TABLE_NAME";
$col["search"] = true;
$col["editable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Type";
$col["name"] = "TABLE_TYPE";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select";
// render as select
$str = $g->get_dropdown_values("select distinct TABLE_TYPE as k, TABLE_TYPE as v from cat");
$col["editoptions"] = array("value" => $str);
$cols[] = $col;
$g->set_columns($cols);
// render grid
$out = $g->render("list1");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
	<link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>	
	<link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>	
	
	<script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
	<script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
	<script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>	
Пример #2
0
 public function index()
 {
     //check login
     if ($this->session->userdata('user_name')) {
         $i_rule = $this->session->userdata('user_cizacl_role_id');
         $g = new jqgrid();
         #ID
         $col = array();
         $col['title'] = "ID";
         $col['name'] = "customer_id";
         $col['hidden'] = true;
         $col['isnull'] = true;
         $cols[] = $col;
         #Factory
         $col = array();
         $col["title"] = $this->lang->line("factory_name");
         $col["name"] = "factory_id";
         $col["dbname"] = "cus.factory_id";
         // this is required as we need to search in name field, not id
         $col["width"] = "100";
         $col["align"] = "left";
         $col["search"] = true;
         $col["editable"] = true;
         $col["edittype"] = "select";
         // render as select
         # fetch data from database, with alias k for key, v for value
         $str = $g->get_dropdown_values("select distinct factory_id as k, factory_name as v from transport_factory");
         $col["editoptions"] = array("value" => ":;" . $str);
         $col["formatter"] = "select";
         // display label, not value
         $col["editrules"] = array("required" => true);
         $cols[] = $col;
         #Customer_Type
         $col = array();
         $col["title"] = $this->lang->line('customer_type');
         $col["name"] = "customer_type_id";
         $col["dbname"] = "cus_type.customer_type_title";
         // this is required as we need to search in name field, not id
         $col["fixed"] = true;
         //$col["width"] = "65";
         $col["align"] = "left";
         $col["search"] = true;
         $col["editable"] = true;
         $col["edittype"] = "select";
         // render as select
         # fetch data from database, with alias k for key, v for value
         //$str = $g->get_dropdown_values("select distinct client_id as k, name as v from clients");
         $str = $g->get_dropdown_values("SELECT DISTINCT customer_type_id AS k, customer_type_title AS v FROM `transport_customer_type` WHERE customer_type_status ='2'");
         #$str = $this->dropdrown->get_customer_type();
         $col["editoptions"] = array("value" => $str);
         $col["formatter"] = "select";
         // display label, not value
         $cols[] = $col;
         #Customer name
         $col = array();
         $col['title'] = $this->lang->line('customer_agancy');
         $col['name'] = "customers_name";
         $col["editrules"] = array("required" => true);
         $col["search"] = true;
         $col['editable'] = true;
         $cols[] = $col;
         $col = array();
         $col['title'] = $this->lang->line('car_number');
         $col['name'] = "car_id";
         $col['dbname'] = "cus.car_id";
         $col["width"] = "100";
         $col["align"] = "left";
         $col["search"] = true;
         $col["editable"] = true;
         $col["edittype"] = "select";
         // render as select
         # fetch data from database, with alias k for key, v for value
         $str = $g->get_dropdown_values("SELECT DISTINCT car_id AS k,car_number AS v FROM transport_cars;");
         $col["editoptions"] = array("value" => ":;" . $str);
         $col["formatter"] = "select";
         // display label, not value
         $cols[] = $col;
         #remark
         $col = array();
         $col['title'] = $this->lang->line('car_license');
         $col['name'] = "car_license";
         $col['editable'] = true;
         $col['edittype'] = "textarea";
         $col['editoptions'] = array("rows" => "2", "cols" => "20");
         $cols[] = $col;
         #Address
         $col = array();
         $col['title'] = $this->lang->line('Address1');
         $col['name'] = "address1";
         $col['editable'] = true;
         $col["search"] = false;
         $col['edittype'] = "textarea";
         $col['editoptions'] = array("rows" => "2", "cols" => "20");
         $cols[] = $col;
         #Contact Person
         $col = array();
         $col['title'] = $this->lang->line('contact_person');
         $col['name'] = "contact_person";
         $col['editable'] = true;
         $cols[] = $col;
         # Tel
         /*
         $col = array();
         $col['title'] = $this->lang->line('tel');
         $col['name'] = "mobile_number";
         $col['editable'] = true;
         $col["editrules"] = array("number" => true);
         $cols[] = $col;
         */
         #remark
         $col = array();
         $col['title'] = $this->lang->line('note');
         $col['name'] = "remark";
         $col['editable'] = true;
         $col['edittype'] = "textarea";
         $col["viewable"] = false;
         $col['editoptions'] = array("rows" => "2", "cols" => "20");
         $cols[] = $col;
         $e["on_insert"] = array("add_client", null, true);
         #$e["on_delete"] = array("del_client", null, true);
         $g->set_events($e);
         $g->select_command = "SELECT\n\tcustomer_id,\n\tcus.customer_type_id,\n\tcus_type.customer_type_title,\n\tcus.factory_id,\n\tcustomers_name,\n\tcus.car_id,\n\tcus.car_license,\n\taddress1,\n\tcontact_person,\n\tmobile_number,\n\tremark\nFROM\n\ttransport_customers AS cus\nLEFT JOIN transport_factory AS fac ON (\n\tcus.factory_id = fac.factory_id\n)\nLEFT JOIN transport_customer_type AS cus_type ON (\n\tcus.customer_type_id = cus_type.customer_type_id\n)\nLEFT JOIN transport_cars AS car ON (cus.car_id=car.car_id)\nWHERE\n\tcus. STATUS = 1\nAND cus_type.customer_type_status != 1";
         function add_client(&$data)
         {
             $check_sql = "SELECT count(*) as c from transport_customers where LOWER(`customers_name`) = '" . strtolower($data["params"]["customers_name"]) . "'";
             $rs = mysql_fetch_assoc(mysql_query($check_sql));
             if ($rs["c"] > 0) {
                 phpgrid_error("ข้อมูลลูกค้าซ้ำ");
             }
         }
         // end of sub function
         function del_client(&$data)
         {
             $check_sql = "UPDATE `transport_customers` SET `status`='0' WHERE (`customer_id`='{$data["id"]}')";
             mysql_query($check_sql);
         }
         //Use Table
         $g->table = "transport_customers";
         // pass the cooked columns to grid
         $g->set_columns($cols);
         $opt["sortname"] = 'customer_id';
         $opt["sortorder"] = "desc";
         $opt["rowList"] = array(10, 20, 30);
         $opt["caption"] = $this->lang->line('customer');
         $opt["autowidth"] = true;
         $opt["multiselect"] = false;
         $opt["autowidth"] = true;
         $opt["view_options"]['width'] = '520';
         $opt["add_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         $opt["edit_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         $opt["edit_options"]["beforeSubmit"] = "function(post,form){ return validate_form_once(post,form); }";
         $g->set_options($opt);
         $g->set_actions(array("add" => $this->cizacl->check_isAllowed($i_rule, 'customer', 'add_customer'), "edit" => $this->cizacl->check_isAllowed($i_rule, 'customer', 'edit_customer'), "delete" => $this->cizacl->check_isAllowed($i_rule, 'customer', 'del_customer'), "export" => false, "autofilter" => true, "search" => "advance"));
         // set database table for CRUD operations
         // render grid and get html/js output
         $out_index = $g->render("list1");
         $h2_title = $this->lang->line('customeroils');
         //display
         $this->_example_output((object) array('output' => '', 'out' => $out_index, 'h2_title' => $h2_title, 'js_files' => array(), 'css_files' => array()));
     } else {
         //If no session, redirect to login page
         redirect('login', 'refresh');
     }
 }
Пример #3
0
$col["name"] = "id";
$col["width"] = "10";
$cols[] = $col;
$col = array();
$col["title"] = "Client";
$col["name"] = "client_id";
$col["dbname"] = "clients.name";
// this is required as we need to search in name field, not id
$col["width"] = "100";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select";
// render as select
# fetch data from database, with alias k for key, v for value
$str = $g->get_dropdown_values("select distinct client_id as k, name as v from clients");
$col["editoptions"] = array("value" => $str);
$cols[] = $col;
$col = array();
$col["title"] = "Date";
$col["name"] = "invdate";
$col["width"] = "50";
$col["editable"] = true;
// this column is editable
$col["editoptions"] = array("size" => 20);
// with default display of textbox with size 20
$col["editrules"] = array("required" => true);
// and is required
$col["formatter"] = "date";
// format as date
$col["search"] = false;
Пример #4
0
 public function index()
 {
     if ($this->session->userdata('user_name')) {
         $g = new jqgrid();
         $g->select_command = "SELECT id,fac.factory_code as factory_id ,dis.distance_code as distance_id,cubic.cubic_value as cubic_id,pr.price, start_date,end_date FROM pricelist as pr \nLEFT JOIN transport_factory as fac ON(pr.factory_id=fac.factory_id)\nLEFT JOIN transport_cubiccode as cubic ON(pr.cubic_id = cubic.cubic_id)\nLEFT JOIN distancecode as dis ON(pr.distance_id=dis.distance_id)";
         $g->table = "pricelist";
         $col = array();
         $col["title"] = "id";
         $col["name"] = "id";
         //$col["dbname"] = "pr.pricelist_id";
         $col["width"] = "10";
         $col["hidden"] = true;
         $col["editable"] = false;
         $cols[] = $col;
         $col = array();
         $col["title"] = $this->lang->line('factory_code');
         // caption of column
         $col["name"] = "factory_id";
         $col["dbname"] = "pr.factory_id";
         $col["width"] = "10";
         $col["align"] = "left";
         $col["search"] = true;
         $col["editable"] = true;
         $col["editrules"] = array("required" => true);
         $col["edittype"] = "select";
         // render as select
         # fetch data from database, with alias k for key, v for value
         $str = $g->get_dropdown_values("SELECT DISTINCT factory_id AS k,factory_code AS v FROM transport_factory");
         $col["editoptions"] = array("value" => ":;" . $str);
         // multi-select in search filter
         $col["stype"] = "select-multiple";
         $col["searchoptions"]["value"] = $str;
         $cols[] = $col;
         $col = array();
         $col["title"] = $this->lang->line('distance_code');
         // caption of column
         $col["name"] = "distance_id";
         $col["dbname"] = "pr.distance_id";
         $col["width"] = "10";
         $col["align"] = "left";
         $col["search"] = true;
         $col["editable"] = true;
         $col["editrules"] = array("required" => true);
         $col["edittype"] = "select";
         // render as select
         # fetch data from database, with alias k for key, v for value
         $str = $g->get_dropdown_values("SELECT DISTINCT distance_id AS k,distance_code AS v FROM distancecode WHERE distance_status=1");
         $col["editoptions"] = array("value" => ":;" . $str);
         // multi-select in search filter
         $col["stype"] = "select-multiple";
         $col["searchoptions"]["value"] = $str;
         $cols[] = $col;
         $col = array();
         $col["title"] = $this->lang->line('cubic_value');
         // caption of column
         $col["name"] = "cubic_id";
         $col["dbname"] = "pr.cubic_id";
         $col["width"] = "10";
         $col["align"] = "left";
         $col["search"] = true;
         $col["editable"] = true;
         $col["editrules"] = array("required" => true);
         $col["edittype"] = "select";
         // render as select
         # fetch data from database, with alias k for key, v for value
         $str = $g->get_dropdown_values("SELECT DISTINCT cubic_id AS k,cubic_value AS v FROM transport_cubiccode WHERE cubic_status=1");
         $col["editoptions"] = array("value" => ":;" . $str);
         // multi-select in search filter
         $col["stype"] = "select-multiple";
         $col["searchoptions"]["value"] = $str;
         $cols[] = $col;
         $col = array();
         $col["title"] = $this->lang->line('price');
         // caption of column
         $col["name"] = "price";
         $col["editable"] = true;
         $col["width"] = "10";
         $col["editrules"] = array("required" => true);
         $cols[] = $col;
         $col = array();
         $col["title"] = $this->lang->line('start_date');
         // caption of column
         $col["name"] = "start_date";
         $col["formatter"] = "date";
         // format as date
         $col["formatoptions"] = array("srcformat" => 'Y-m-d', "newformat" => 'd/m/Y');
         // http://docs.jquery.com/UI/Datepicker/formatDate
         $col["width"] = "10";
         $col["editrules"] = array("required" => true);
         $col["editable"] = true;
         $cols[] = $col;
         $col = array();
         $col["title"] = $this->lang->line('end_date');
         // caption of column
         $col["name"] = "end_date";
         $col["formatter"] = "date";
         // format as date
         $col["formatoptions"] = array("srcformat" => 'Y-m-d', "newformat" => 'd/m/Y');
         // http://docs.jquery.com/UI/Datepicker/formatDate
         $col["width"] = "10";
         $col["editrules"] = array("required" => true);
         $col["editable"] = true;
         $cols[] = $col;
         $g->set_columns($cols);
         $g->set_actions(array("add" => true, "edit" => true, "delete" => true, "clone" => true, "rowactions" => true, "search" => "advance", "showhidecolumns" => false));
         // $grid["url"] = ""; // your paramterized URL -- defaults to REQUEST_URI
         $grid["rowNum"] = 50;
         // by default 20
         $grid["sortname"] = 'id';
         // by default sort grid by this field
         $grid["sortorder"] = "desc";
         // ASC or DESC
         $grid["caption"] = $this->lang->line('pricelist');
         // caption of grid
         $grid["autowidth"] = true;
         // expand grid to screen width
         $grid["multiselect"] = true;
         // allow you to multi-select through checkboxes
         $grid["form"]["position"] = "center";
         $grid["altRows"] = true;
         $grid["altclass"] = "myAltRowClass";
         $grid["add_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         $grid["edit_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         $g->set_options($grid);
         $e["on_update"] = array("update_price", null, true);
         $e["on_insert"] = array("add_price", null, true);
         $g->set_events($e);
         function add_price(&$data)
         {
             $factory_id = $data["params"]["factory_id"];
             $distance_id = $data["params"]["distance_id"];
             $cubic_id = $data["params"]["cubic_id"];
             $start_date = $data["params"]["start_date"];
             $end_date = $data["params"]["end_date"];
             $check_sql = "SELECT COUNT(*) AS c\nFROM\n\tpricelist\nWHERE\n\tfactory_id = '{$factory_id}'\nAND distance_id = '{$distance_id}'\nAND cubic_id = '{$cubic_id}'\nAND ( (start_date='0000-00-00' || start_date <= DATE_FORMAT('{$start_date}','%Y-%m-%d')) \nAND (end_date='0000-00-00' || end_date >= DATE_FORMAT('{$start_date}','%Y-%m-%d'))) \nAND ( (start_date='0000-00-00' || start_date <= DATE_FORMAT('{$end_date} ','%Y-%m-%d')) \nAND (end_date='0000-00-00' || end_date >= DATE_FORMAT('{$end_date}','%Y-%m-%d')))";
             $rs = mysql_fetch_assoc(mysql_query($check_sql));
             if ($rs["c"] > 0) {
                 phpgrid_error("ข้อมูลราคาซ้ำ ไม่สามารถบันทึกได้");
             }
         }
         // end of sub function
         function update_price(&$data)
         {
             //print_r($data);
             $obj =& get_instance();
             $obj->load->model("price_model", "price");
             $obj->load->library('conv_date');
             $price_id = $data["params"]["id"];
             //$startdate = date('Y-m-d',strtotime($data['params']['start_date']));
             $startdate = $data['params']['start_date'];
             $enddate = $data['params']['start_date'];
             $c_stdate = $obj->price->check_before_update_price($price_id);
             //$c_endate = $obj->price->check_before_update_price($price_id,$en);
             $st_date = $c_stdate['start_date'];
             $en_date = $c_stdate['end_date'];
             //$ed_date = $c_endate;
             $m_date = $obj->conv_date->compareDate($startdate, $st_date);
             $e_date = $obj->conv_date->compareDate($enddate, $st_date);
             //$m_date ="E";
             if ($m_date !== "E" && $e_date !== "E") {
                 $check_sql = "SELECT COUNT(*) as c\n\nFROM\n\tpricelist\nWHERE\n\tfactory_id = '{$data["params"]["factory_id"]}'\nAND cubic_id = '{$data["params"]["cubic_id"]}'\nAND distance_id = '{$data["params"]["distance_id"]}'\nAND ( (start_date='0000-00-00' || start_date <= DATE_FORMAT('{$data["params"]["start_date"]}','%Y-%m-%d')) \nAND (end_date='0000-00-00' || end_date >= DATE_FORMAT('{$data["params"]["start_date"]}','%Y-%m-%d'))) \nOR\n( (start_date='0000-00-00' || start_date <= DATE_FORMAT('{$data["params"]["end_date"]}','%Y-%m-%d')) \nAND (end_date='0000-00-00' || end_date >= DATE_FORMAT('{$data["params"]["end_date"]}','%Y-%m-%d'))) LIMIT 1";
                 $rs = mysql_fetch_assoc(mysql_query($check_sql));
                 if ($rs["c"] > 0) {
                     phpgrid_error("ข้อมูลราคาซ้ำ ไม่สามารถบันทึกได้");
                 }
             }
         }
         // End of  function update_price
         //Display
         $pricetable = $g->render("list1");
         $h2_title = "Price Setting";
         $this->_example_output((object) array('output' => '', 'out' => $out, 'dispyPrice' => $dispyPrice, 'h2_title' => $h2_title, 'list_row' => $num_row, 'pricelist' => $pricelist, 'pricetable' => $pricetable));
     } else {
         //If no session, redirect to login page
         redirect('login', 'refresh');
     }
 }
Пример #5
0
 public function index()
 {
     if ($this->session->userdata('user_name')) {
         $i_rule = $this->session->userdata('user_cizacl_role_id');
         $this->load->model('income_model', 'dropdrown');
         $this->load->model('dropdown_model', 'cus_drop');
         $g = new jqgrid();
         $col = array();
         $col["title"] = "Id";
         // caption of column
         $col["name"] = "id";
         $col["width"] = "10";
         $col["fixed"] = true;
         $col["search"] = false;
         $col["editable"] = false;
         $col["export"] = false;
         $col["hidden"] = true;
         $cols[] = $col;
         $col = array();
         $col['title'] = "cubic value";
         $col['name'] = "cubic_id";
         $col['dbname'] = "orders.cubic_id";
         $col["editable"] = true;
         $col["formatter"] = "select";
         $col["editable"] = true;
         $col["edittype"] = "select";
         $str = $g->get_dropdown_values("SELECT DISTINCT cubic_id AS k, cubic_value AS v FROM transport_cubiccode WHERE cubic_status=1");
         //$col["editoptions"] = array("value"=>":;".$str);
         $col["editoptions"] = array("value" => $str);
         $col["formatter"] = "select";
         // display label, not value
         $cols[] = $col;
         /**Option Form */
         $opt["sortname"] = 'id';
         $opt["sortorder"] = "desc";
         $opt["caption"] = $this->lang->line('Order_Transportation');
         $opt['rowNum'] = 10;
         $opt['rowList'] = array(10, 20, 30);
         $opt['height'] = "300";
         $opt["autowidth"] = true;
         $opt["multiselect"] = false;
         $opt["scroll"] = true;
         $opt["add_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         $opt["edit_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         $opt["add_options"]["afterShowForm"] = 'function(formid) { jQuery("#dp_number").focus(); }';
         $opt["altRows"] = true;
         $opt["altclass"] = "myAltRowClass";
         $g->set_options($opt);
         $g->set_actions(array("add" => $this->cizacl->check_isAllowed($i_rule, 'truckorder', 'add'), "edit" => $this->cizacl->check_isAllowed($i_rule, 'truckorder', 'edit'), "delete" => $this->cizacl->check_isAllowed($i_rule, 'truckorder', 'delete'), "rowactions" => true, "export" => true, "autofilter" => true, "search" => "advance"));
         $g->select_command = "SELECT\n\tid,\n\tdp_number,\n\torders.customer_id,\n    cus.customers_name AS cid,\n    orders.factory_id,\n\tfac.factory_code,\n\treal_distance,\n\torders.distance_id,\n\tdis.distance_code,\n\torders.cubic_id,\n    cubic.cubic_value,\n    orders.price AS price,\n\torders.use_oil,\n    orders.car_id,\n\tcar.car_number,\n\torders.driver_id,\n\tdri.driver_name,\n    order_date,\n    orders.delivery_datetime,\n    orders.remark\n\nFROM\n\t`orders` AS orders\nLEFT JOIN transport_factory AS fac ON (\n\torders.factory_id = fac.factory_id\n)\nLEFT JOIN transport_customers AS cus ON (\n\torders.customer_id = cus.customer_id\n)\nLEFT JOIN transport_cubiccode AS cubic ON (\n\torders.cubic_id = cubic.cubic_id\n)\nLEFT JOIN distancecode AS dis ON (\n\torders.distance_id = dis.distance_id\n)\nLEFT JOIN transport_cars AS car ON (\norders.car_id = car.car_id\n)\nLEFT JOIN driver AS dri ON (\n\torders.driver_id = dri.driver_id\n)";
         // this db table will be used for add,edit,delete
         $g->table = "orders";
         $e["on_after_insert"] = array("after_insert", null, true);
         $e["on_update"] = array("do_update", null, true);
         /*      
         $e["on_insert"] = array(
             "add_order",
             null,
             true);
         */
         $e["on_data_display"] = array("filter_display", null, true);
         $g->set_events($e);
         function add_order(&$data)
         {
             //print_r($data);
             $obj =& get_instance();
             $obj->load->model("price_model", "pricelist");
             //$id = intval($_REQUEST["id"]);
             $factory_id = $data["params"]["factory_id"];
             $distance_id = $data["params"]["distance_id"];
             $cubid_id = $data["params"]["cubic_id"];
             $order_date = $data["params"]["order_date"];
             #get price
             $order_price = $obj->pricelist->get_order_Price($factory_id, $cubid_id, $distance_id, $order_date);
             if ($order_price == null) {
                 $str = ob_get_clean();
                 $str = "ไม่มีการกำหนดราคาค่าขนส่ง";
                 phpgrid_error($str);
             }
             /*check DP NUmber*/
             $check_sql = "SELECT count(*) as c from orders where LOWER(`dp_number`) = '" . strtolower($data["params"]["dp_number"]) . "'";
             $rs = mysql_fetch_assoc(mysql_query($check_sql));
             if ($rs["c"] > 0) {
                 phpgrid_error("หมายเลข DP Number ซ้ำ");
             }
             /*End Check DP Number*/
             //$str = "UPDATE orders SET price ='{$data["parmas"]["price"]}' WHERE id = '{$data["id"]}'";
             //mysql_query($str);
         }
         function do_update(&$data)
         {
             //print_r($data);
             $obj =& get_instance();
             $obj->load->model("price_model", "pricelist");
             $id = intval($_REQUEST["id"]);
             $factory_id = $data["params"]["factory_id"];
             $distance_id = $data["params"]["distance_id"];
             $cubid_id = $data["params"]["cubic_id"];
             $order_date = $data["params"]["order_date"];
             #get price
             $order_price = $obj->pricelist->get_order_Price($factory_id, $cubid_id, $distance_id, $order_date);
             if ($order_price == null) {
                 $str = ob_get_clean();
                 $str = "ไม่มีการกำหนดราคาค่าขนส่ง";
                 phpgrid_error($str);
             } else {
                 $data["params"]["price"] = $order_price;
                 $str = "UPDATE orders SET price ='{$data["parmas"]["price"]}' WHERE id = '{$data["id"]}'";
                 mysql_query($str);
             }
             //$str = "UPDATE orders SET price ='{$data["parmas"]["price"]}' WHERE id = '{$data["id"]}'";
             //mysql_query($str);
         }
         function after_insert(&$data)
         {
             //print_r($data);
             $obj =& get_instance();
             $obj->load->model("price_model", "pricelist");
             $id = $data["id"];
             $factory_id = $data["params"]["factory_id"];
             $distance_id = $data["params"]["distance_id"];
             $cubid_id = $data["params"]["cubic_id"];
             $order_date = $data["params"]["order_date"];
             #get price
             $order_price = $obj->pricelist->get_order_Price($factory_id, $cubid_id, $distance_id, $order_date);
             $str = "UPDATE orders SET price ='{$order_price}' \n                    WHERE id = {$data["id"]}";
             mysql_query($str);
         }
         function filter_display($data)
         {
             foreach ($data["params"] as &$d) {
                 foreach ($d as $k => $v) {
                     $d[$k] = strtoupper($d[$k]);
                 }
             }
         }
         // pass the cooked columns to grid
         $g->set_columns($cols);
         // generate grid output, with unique grid name as 'list1'
         $out = $g->render("list1");
         $iprice = $this->price->get_order_Price(2, 2, 2);
         //display
         $this->_example_output((object) array('output' => "", 'out' => $out, 'iprice' => $iprice, 'js_files' => array(), 'css_files' => array()));
         //$this->_example_output();
     } else {
         redirect('login', 'refresh');
     }
     //end if
 }
Пример #6
0
 public function index()
 {
     //check login
     if ($this->session->userdata('user_name')) {
         $g = new jqgrid();
         $opt["caption"] = "รายการรับ - จ่าย น้ำมัน";
         // following params will enable subgrid -- by default first column (PK) of parent is passed as param 'id'
         $opt["detail_grid_id"] = "list2,list3";
         $opt["subgridparams"] = "factory_id";
         $opt["height"] = "90";
         $opt['autowidth'] = true;
         $g->set_options($opt);
         $col = array();
         $col['title'] = "id";
         $col['name'] = "factory_id";
         $col['hidden'] = true;
         // $col['dbname'] = "fac.factory_id";
         $cols[] = $col;
         #factory Name
         $col = array();
         $col['title'] = $this->lang->line('factory_name');
         $col['name'] = "factory_name";
         //$col['dbnaem'] = "fac.factory_name";
         $col["search"] = false;
         $cols[] = $col;
         #factory Code
         $col = array();
         $col['title'] = $this->lang->line('factory_code');
         $col['name'] = "factory_code";
         $col['dbnaem'] = "fac.factory_code";
         $col["search"] = false;
         $cols[] = $col;
         #Recived Oil
         $col = array();
         $col['title'] = $this->lang->line('sum_recived_oil');
         $col['name'] = "receive_oil";
         $col["search"] = false;
         $col["formatter"] = "number";
         $col["formatoptions"] = array("thousandsSeparator" => ",", "decimalSeparator" => ".", "decimalPlaces" => 2);
         $cols[] = $col;
         #Sell Oil
         $col = array();
         $col['title'] = $this->lang->line('sum_sell_oil');
         $col['name'] = "sell_oil";
         $col["search"] = false;
         $col["formatter"] = "number";
         $col["formatoptions"] = array("thousandsSeparator" => ",", "decimalSeparator" => ".", "decimalPlaces" => 2);
         $cols[] = $col;
         #Total Amount
         $col = array();
         $col['title'] = $this->lang->line("oil_total_amount");
         $col['name'] = "total_amount";
         $col["search"] = false;
         $col["formatter"] = "number";
         $col["formatoptions"] = array("thousandsSeparator" => ",", "decimalSeparator" => ".", "decimalPlaces" => 2);
         $cols[] = $col;
         // Command 1
         $g->select_command = "SELECT\n     factory_id,\n     factory_code,\n     factory_name,\n     SUM(receive_oil) AS receive_oil,\n     SUM(sell_oil) AS sell_oil,\n     oil_type,\n     SUM(receive_oil - sell_oil) AS total_amount,\n\t\t factory_status\nFROM\n     (\n          SELECT\n               t1.factory_id,\n               t1.factory_code,\n               t1.factory_name,\n\t\t\t\t\t\t\t t1.factory_status,\n               t2.receive_oil,\n               t2.sell_oil,\n               t2.oil_type\n          FROM\n               transport_factory AS t1\n          LEFT JOIN oilstock AS t2 ON t1.factory_id = t2.factory_id\n          UNION\n               SELECT\n                    t1.factory_id,\n                    t1.factory_code,\n                    t1.factory_name,\n\t\t\t\t\t\t\t\t\t\tt1.factory_status,\n                    t2.receive_oil,\n                    t2.sell_oil,\n                    t2.oil_type\n               FROM\n                    transport_factory AS t1\n               RIGHT JOIN oilstock AS t2 ON t1.factory_id = t2.factory_id\n     ) oilstock\nGROUP BY\n     factory_id\nHAVING factory_status =1";
         $g->table = "transport_factory";
         $g->set_columns($cols);
         $g->set_actions(array("add" => false, "edit" => false, "delete" => false, "rowactions" => false, "autofilter" => false));
         // render grid and get html/js output
         $out_master = $g->render("list1");
         /*
         if (!empty($_REQUEST["factory_id"]))
         {
         $_SESSION["factory_id"] = intval($_REQUEST["factory_id"]);
         }
         
         if (isset($_SESSION['factory_id']))
         {
         $fac_id = $_SESSION["factory_id"];
         } else
         {
         $fac_id = "0";
         }
         */
         $fac_id = intval($_GET["factory_id"]);
         #Detail Oil Recive **รับน้ำมัน
         $g2 = new jqgrid();
         /*Option*/
         $opt2["caption"] = $this->lang->line("recived_oil_list");
         $opt2["sortname"] = 'stock_id';
         $opt2["sortorder"] = "desc";
         $opt2["height"] = "250";
         $opt2['rowNum'] = 10;
         $opt2['rowList'] = array(10, 20, 30);
         $opt2["width"] = "979";
         //$opt2["autowidth"] = true;
         //$opt3['hidegrid'] = true;
         $opt2["form"]["position"] = "center";
         $opt2["add_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         $opt2["edit_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         /*
         $opt2["add_options"]["beforeInitData"] = "function(formid){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); if (!selr) { alert('จำเป็นต้องเลือกโรงงาน'); return false; } }";
         $opt2["add_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); return true;}";
         $opt2["edit_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); return true;}";
         $opt2["delete_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); return true;}";
         $opt2["add_options"]["afterShowForm"] =
         'function(formid) { jQuery("#ref_number").focus(); }';
         */
         // Check if master record is selected before detail addition
         $opt2["add_options"]["beforeInitData"] = "function(formid){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); if (!selr) { alert('คุณยังไม่ได้เลือกโรงงาน'); return false; } }";
         // reload master after detail update
         $opt2["onAfterSave"] = "function(){ jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); }";
         $g2->set_options($opt2);
         #id
         $col2 = array();
         $col2['title'] = "id";
         $col2['name'] = 'stock_id';
         $col2['hidden'] = true;
         $col2['editable'] = true;
         $cols2[] = $col2;
         #stick date
         $col2 = array();
         $col2['title'] = $this->lang->line('date');
         $col2['name'] = 'stock_date';
         $col2['editable'] = true;
         $col2["editrules"] = array("required" => true);
         // and is required
         //$col2["editoptions"] = array("size" => 20, "defaultValue" => date("d-m-Y H:i")); // with default display of textbox with size 20
         $col2["searchoptions"]["sopt"] = array("cn");
         // contains search for easy searching
         # to make it date time
         $col2["formatter"] = "datetime";
         # opts array can have these options: http://trentrichardson.com/examples/timepicker/#tp-options
         $col2["formatoptions"] = array("srcformat" => 'Y-m-d H:i:s', "newformat" => 'Y-m-d H:i', "opts" => array("timeFormat" => "HH:mm"));
         $col2["show"] = array("list" => true, "add" => true, "edit" => true, "view" => true);
         $cols2[] = $col2;
         #Ref No.
         $col2 = array();
         $col2['title'] = $this->lang->line('reference_number');
         $col2['name'] = 'ref_number';
         $col2['editable'] = true;
         $cols2[] = $col2;
         $col2 = array();
         $col2['title'] = $this->lang->line('customer_type');
         $col2['name'] = "customer_type_id";
         $col2['dbname'] = "oil.customer_type_id";
         $col2["editable"] = true;
         $col2["edittype"] = "select";
         $col2["editrules"] = array("required" => true);
         $str = $g2->get_dropdown_values("SELECT DISTINCT customer_type_id AS k,customer_type_title AS v FROM transport_customer_type WHERE customer_type_status = '2'");
         $col2["editoptions"] = array("value" => ":;" . $str);
         $col2["editoptions"] = array("value" => $str, "onchange" => array("sql" => "SELECT DISTINCT customer_id AS k , customer_name AS v FROM transport_oilcustomers WHERE customer_type_id ='{customer_type_id}' ", "update_field" => "customer_id"));
         $col2["formatter"] = "select";
         // display label, not value
         $col2["stype"] = "select";
         // enable dropdown search
         $col2["searchoptions"] = array("value" => ":;" . $str);
         $cols2[] = $col2;
         # Customer Name
         $col2 = array();
         $col2['title'] = $this->lang->line('customer_br');
         $col2['name'] = "customer_id";
         $col2['dbname'] = "oil.customer_id";
         $col2["editable"] = true;
         $col2["edittype"] = "select";
         $col2["editrules"] = array("required" => true);
         $str = $g2->get_dropdown_values("SELECT DISTINCT customer_id AS k , customer_name AS v FROM transport_oilcustomers ");
         $col2["editoptions"] = array("value" => ":;" . $str);
         $col2["editoptions"] = array("value" => $str, "onchange" => array("sql" => "SELECT DISTINCT car_id AS k,car_number AS v FROM `transport_oilcars` WHERE customer_id ='{customer_id}' AND `status`=1", "update_field" => "car_id"));
         $col2["editoptions"]["onload"]["sql"] = "SELECT DISTINCT customer_id AS k , customer_name AS v FROM transport_oilcustomers WHERE customer_type_id ='{customer_type_id}' AND `status` =1";
         $col2["formatter"] = "select";
         // display label, not value
         $col2["stype"] = "select";
         // enable dropdown search
         $col2["searchoptions"] = array("value" => ":;" . $str);
         $cols2[] = $col2;
         #Car Number
         $col2 = array();
         $col2['title'] = $this->lang->line('car_number');
         $col2['name'] = "car_id";
         $col2['dbname'] = "car.car_id";
         $col2["editable"] = true;
         $col2["edittype"] = "select";
         $col2["editrules"] = array("required" => true);
         $str = $g2->get_dropdown_values("SELECT DISTINCT car_id AS k, car_number AS v FROM transport_oilcars WHERE  `status` =1");
         $col2["editoptions"] = array("value" => ":;" . $str);
         // initially load 'note' of that
         $col2["editoptions"]["onload"]["sql"] = "SELECT DISTINCT car_id AS k, car_number AS v FROM transport_oilcars WHERE customer_id = '{customer_id}' AND `status` =1";
         $col2["formatter"] = "select";
         // display label, not value
         $col2["stype"] = "select";
         // enable dropdown search
         $col2["searchoptions"] = array("value" => ":;" . $str);
         $cols2[] = $col2;
         #stock_details
         $col2 = array();
         $col2['title'] = $this->lang->line('stock_details');
         $col2['name'] = 'stock_details';
         $col2['editable'] = true;
         $col2["edittype"] = "textarea";
         $col2["editoptions"] = array("rows" => 2, "cols" => 20);
         $col2["formatter"] = "autocomplete";
         // autocomplete
         $col2["formatoptions"] = array("sql" => "SELECT DISTINCT stock_details as k, stock_details as v FROM oilstock", "search_on" => "stock_details", "update_field" => "stock_details");
         $cols2[] = $col2;
         #oil_value
         $col2 = array();
         $col2['title'] = $this->lang->line('recived_oil');
         $col2['name'] = 'receive_oil';
         $col2['editable'] = true;
         $col2['search'] = false;
         $col2["editrules"] = array("required" => true, "number" => true);
         $col2["editoptions"] = array("onblur" => "update_reciveValue()", "defaultValue" => '0');
         $col2['formatter'] = "number";
         $col2["formatoptions"] = array("thousandsSeparator" => ",", "decimalSeparator" => ".", "decimalPlaces" => '2');
         $cols2[] = $col2;
         #oil_value
         $col2 = array();
         $col2['title'] = $this->lang->line('list_per_price');
         $col2['name'] = 'receive_price';
         $col2['align'] = "right";
         $col2['editable'] = true;
         #$col2['formatter'] = "number";
         $col2['search'] = false;
         $col2["editrules"] = array("required" => true, "number" => true);
         $col2["editoptions"] = array("onblur" => "update_reciveValue()", "defaultValue" => '0');
         $col2['formatter'] = "currency";
         $col2["formatoptions"] = array("prefix" => "", "suffix" => '', "thousandsSeparator" => ",", "decimalSeparator" => ".", "decimalPlaces" => '2');
         $cols2[] = $col2;
         #total_mount
         $col2 = array();
         $col2['title'] = $this->lang->line('total_amount');
         $col2['name'] = 'receive_amount';
         $col2['align'] = "right";
         $col2['editable'] = true;
         $col2["editrules"] = array("required" => true);
         # $col2['editoptions'] = array("readonly" => "readonly");
         $col2['search'] = false;
         $col2['formatter'] = "currency";
         $col2["formatoptions"] = array("prefix" => "", "suffix" => '', "thousandsSeparator" => ",", "decimalSeparator" => ".", "decimalPlaces" => 2);
         $cols2[] = $col2;
         // $id = intval($_GET["rowid"]);
         /*
                     $g2->select_command = "SELECT
                     stock_id,
                     stock_date,
                     ref_number,
                     oil.customer_type_id,
                     cus_type.customer_type_title,
                     oil.customer_id,
                     cus.customers_name,
                     oil.car_id,
                     car.car_number,	
                     stock_details,
                     
                     receive_oil,
                     receive_price,
                     receive_amount
                     FROM
                     oilstock AS oil
                     LEFT JOIN transport_cars AS car ON (oil.car_id = car.car_id)
                     LEFT JOIN transport_customers AS cus ON (
                     oil.customer_id = cus.customer_id
                     )
                     LEFT JOIN transport_customer_type AS cus_type ON (
                     cus.customer_type_id = cus_type.customer_type_id
                     )
                     WHERE
                     oil.factory_id = '$fac_id'
                     AND oil_type = 1";
         */
         $g2->select_command = "SELECT\n\tstock_id,\n\tstock_date,\n\tref_number,\n\toil.customer_type_id,\n\tcus_type.customer_type_title,\n\toil.customer_id,\n\tcus.customer_name,\n\toil.car_id,\n\tcar.car_number,\t\n    stock_details,\n\t\n\treceive_oil,\n\treceive_price,\n\treceive_amount\nFROM\n\toilstock AS oil\nLEFT JOIN transport_cars AS car ON (oil.car_id = car.car_id)\nLEFT JOIN transport_oilcustomers AS cus ON (\n\toil.customer_id = cus.customer_id\n)\nLEFT JOIN transport_customer_type AS cus_type ON (\n\tcus.customer_type_id = cus_type.customer_type_id\n)\nWHERE\n\toil.factory_id = '{$fac_id}'\nAND oil_type = 1";
         #select table
         $g2->table = "oilstock";
         #$g2->table = "oil_receive";
         $e["on_insert"] = array("add_client", null, true);
         $g2->set_events($e);
         function add_client(&$data)
         {
             $id = intval($_GET["rowid"]);
             $data["params"]["factory_id"] = $id;
             $data["params"]["oil_type"] = 1;
         }
         $g2->set_actions(array("add" => true, "edit" => true, "delete" => true, "view" => false, "rowactions" => false, "autofilter" => true, "search" => "advance", "inlineadd" => false, "showhidecolumns" => false));
         $g2->set_columns($cols2);
         #display Grid2
         $out_list2 = $g2->render("list2");
         /*Grid3 รายการจ่ายน้ำมัน*/
         $g3 = new jqgrid();
         /*Option*/
         $opt3["caption"] = $this->lang->line('sell_oil_list');
         $opt3["sortname"] = 'stock_id';
         $opt3["sortorder"] = "desc";
         $opt3["height"] = "250";
         $opt3['rowNum'] = 10;
         $opt3['rowList'] = array(10, 20, 30);
         $opt3["width"] = "979";
         //$opt3["autowidth"] = true;
         //$opt3['hidegrid'] = true;
         $opt3["form"]["position"] = "center";
         $opt3["add_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         $opt3["edit_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         /*
         $opt3["add_options"]["beforeInitData"] = "function(formid){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); if (!selr) { alert('จำเป็นต้องเลือกโรงงาน'); return false; } }";
         $opt3["add_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); return true;}";
         $opt3["edit_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); return true;}";
         $opt3["delete_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); return true;}";
         $opt3["add_options"]["afterShowForm"] =
         'function(formid) { jQuery("#ref_number").focus(); }';
         */
         // Check if master record is selected before detail addition
         $opt3["add_options"]["beforeInitData"] = "function(formid){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); if (!selr) { alert('คุณยังไม่ได้เลือกโรงงาน'); return false; } }";
         // reload master after detail update
         $opt3["onAfterSave"] = "function(){ jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); }";
         $g3->set_options($opt3);
         #id
         $col3 = array();
         $col3['title'] = "id";
         $col3['name'] = 'stock_id';
         $col3['hidden'] = true;
         $col3['editable'] = true;
         $cols3[] = $col3;
         #stick date
         $col3 = array();
         $col3['title'] = $this->lang->line('date');
         $col3['name'] = 'stock_date';
         $col3['editable'] = true;
         $col3["editrules"] = array("required" => true);
         // and is required
         //$col2["editoptions"] = array("size" => 20, "defaultValue" => date("d-m-Y H:i")); // with default display of textbox with size 20
         $col3["searchoptions"]["sopt"] = array("cn");
         // contains search for easy searching
         # to make it date time
         $col3["formatter"] = "datetime";
         # opts array can have these options: http://trentrichardson.com/examples/timepicker/#tp-options
         $col3["formatoptions"] = array("srcformat" => 'Y-m-d H:i:s', "newformat" => 'Y-m-d H:i', "opts" => array("timeFormat" => "HH:mm"));
         $col3["show"] = array("list" => true, "add" => true, "edit" => true, "view" => true);
         $cols3[] = $col3;
         #Ref No.
         $col3 = array();
         $col3['title'] = $this->lang->line('reference_number');
         $col3['name'] = 'ref_number';
         $col3['editable'] = true;
         $cols3[] = $col3;
         $col3 = array();
         $col3['title'] = $this->lang->line('customer_type');
         $col3['name'] = "customer_type_id";
         $col3['dbname'] = "oil.customer_type_id";
         $col3["editable"] = true;
         $col3["edittype"] = "select";
         $col3["editrules"] = array("required" => true);
         $str = $g3->get_dropdown_values("SELECT DISTINCT customer_type_id AS k,customer_type_title AS v FROM transport_customer_type WHERE customer_type_status = '2'");
         $col3["editoptions"] = array("value" => ":;" . $str);
         $col3["editoptions"] = array("value" => $str, "onchange" => array("sql" => "SELECT DISTINCT customer_id AS k , customer_name AS v FROM transport_oilcustomers WHERE customer_type_id ='{customer_type_id}' ", "update_field" => "customer_id"));
         $col3["formatter"] = "select";
         // display label, not value
         $col3["stype"] = "select";
         // enable dropdown search
         $col3["searchoptions"] = array("value" => ":;" . $str);
         $cols3[] = $col3;
         # Customer Name
         $col3 = array();
         $col3['title'] = $this->lang->line('customer_br');
         $col3['name'] = "customer_id";
         $col3['dbname'] = "oil.customer_id";
         $col3["editable"] = true;
         $col3["edittype"] = "select";
         $col3["editrules"] = array("required" => true);
         $str = $g3->get_dropdown_values("SELECT DISTINCT customer_id AS k , customer_name AS v FROM transport_oilcustomers ");
         $col3["editoptions"] = array("value" => ":;" . $str);
         $col3["editoptions"] = array("value" => $str, "onchange" => array("sql" => "SELECT DISTINCT car_id AS k,car_number AS v FROM `transport_oilcars` WHERE customer_id ='{customer_id}' AND `status`=1", "update_field" => "car_id"));
         $col3["editoptions"]["onload"]["sql"] = "SELECT DISTINCT customer_id AS k , customer_name AS v FROM transport_oilcustomers WHERE customer_type_id ='{customer_type_id}' AND `status` =1";
         $col3["formatter"] = "select";
         // display label, not value
         $col3["stype"] = "select";
         // enable dropdown search
         $col3["searchoptions"] = array("value" => ":;" . $str);
         $cols3[] = $col3;
         #Car Number
         $col3 = array();
         $col3['title'] = $this->lang->line('car_number');
         $col3['name'] = "car_id";
         $col3['dbname'] = "car.car_id";
         $col3["editable"] = true;
         $col3["edittype"] = "select";
         $col3["editrules"] = array("required" => true);
         $str = $g3->get_dropdown_values("SELECT DISTINCT car_id AS k, car_number AS v FROM transport_oilcars WHERE  `status` =1");
         $col3["editoptions"] = array("value" => ":;" . $str);
         // initially load 'note' of that
         $col3["editoptions"]["onload"]["sql"] = "SELECT DISTINCT car_id AS k, car_number AS v FROM transport_oilcars WHERE customer_id = '{customer_id}' AND `status` =1";
         $col3["formatter"] = "select";
         // display label, not value
         $col3["stype"] = "select";
         // enable dropdown search
         $col3["searchoptions"] = array("value" => ":;" . $str);
         $cols3[] = $col3;
         #stock_details
         $col3 = array();
         $col3['title'] = $this->lang->line('stock_details');
         $col3['name'] = 'stock_details';
         $col3['editable'] = true;
         $col3["edittype"] = "textarea";
         $col3["editoptions"] = array("rows" => 2, "cols" => 20);
         $col3["formatter"] = "autocomplete";
         // autocomplete
         $col3["formatoptions"] = array("sql" => "SELECT DISTINCT stock_details as k, stock_details as v FROM oilstock", "search_on" => "stock_details", "update_field" => "stock_details");
         $cols3[] = $col3;
         #oil_value
         $col3 = array();
         $col3['title'] = $this->lang->line('sell_oil');
         $col3['name'] = 'sell_oil';
         $col3['search'] = false;
         $col3['editable'] = true;
         $col3["editrules"] = array("required" => true, "number" => true);
         $col3["editoptions"] = array("onblur" => "update_oilvalue()", "defaultValue" => '0');
         $col3['formatter'] = "number";
         $col3["formatoptions"] = array("thousandsSeparator" => ",", "decimalSeparator" => ".", "decimalPlaces" => '2');
         $cols3[] = $col3;
         #oil_price
         $col3 = array();
         $col3['title'] = $this->lang->line('list_per_price');
         $col3['name'] = 'sell_price';
         $col3['align'] = "right";
         $col3['editable'] = true;
         $col3['search'] = false;
         $col3["editrules"] = array("required" => true, "number" => true);
         $col3["editoptions"] = array("onblur" => "update_oilvalue()", "defaultValue" => '0');
         $col3['formatter'] = "currency";
         $col3["formatoptions"] = array("thousandsSeparator" => ",", "decimalSeparator" => ".", "decimalPlaces" => '2');
         $cols3[] = $col3;
         #total_mount
         $col3 = array();
         $col3['title'] = $this->lang->line('total_amount');
         $col3['name'] = 'sell_amount';
         $col3['align'] = "right";
         $col3['editable'] = true;
         $col3['search'] = false;
         $col3["editrules"] = array("required" => true);
         #$col3['editoptions'] = array("readonly" => "readonly");
         $col3['formatter'] = "currency";
         $col3["formatoptions"] = array("thousandsSeparator" => ",", "decimalSeparator" => ".", "decimalPlaces" => '2');
         $cols3[] = $col3;
         //$fac_id = intval($_REQUEST["rowid"]);
         /*
         $g3->select_command = "SELECT
         stock_id,
         stock_date,
         ref_number,
         oil.customer_type_id,
         cus_type.customer_type_title,
         oil.customer_id,
         cus.customers_name,
         oil.car_id,
         car.car_number,
         stock_details,
         sell_oil,
         sell_price,
         sell_amount
         FROM
         oilstock AS oil
         LEFT JOIN transport_cars AS car ON (oil.car_id = car.car_id)
         LEFT JOIN transport_customers AS cus ON (
         oil.customer_id = cus.customer_id
         )
         LEFT JOIN transport_customer_type AS cus_type ON (
         cus.customer_type_id = cus_type.customer_type_id
         )
         WHERE
         oil.factory_id = '$fac_id'
         AND oil_type = 2";
         */
         $g3->select_command = "SELECT\n\tstock_id,\n\tstock_date,\n\tref_number,\n\toil.customer_type_id,\n\tcus_type.customer_type_title,\n\toil.customer_id,\n\tcus.customer_name,\n\toil.car_id,\n\tcar.car_number,\n\tstock_details,\n\tsell_oil,\n\tsell_price,\n\tsell_amount\nFROM\n\toilstock AS oil\nLEFT JOIN transport_cars AS car ON (oil.car_id = car.car_id)\nLEFT JOIN transport_oilcustomers AS cus ON (\n\toil.customer_id = cus.customer_id\n)\nLEFT JOIN transport_customer_type AS cus_type ON (\n\tcus.customer_type_id = cus_type.customer_type_id\n)\nWHERE\n\toil.factory_id = '{$fac_id}'\nAND oil_type = 2";
         $g3->table = "oilstock";
         $e["on_insert"] = array("add_oiltype", null, true);
         $g3->set_events($e);
         function add_oiltype(&$data)
         {
             $id = intval($_GET["rowid"]);
             $data["params"]["factory_id"] = $id;
             $data["params"]["oil_type"] = 2;
         }
         $g3->set_columns($cols3);
         $g3->set_actions(array("add" => true, "edit" => true, "delete" => true, "view" => false, "rowactions" => true, "autofilter" => true, "search" => "advance", "inlineadd" => false, "showhidecolumns" => false));
         #display Grid2
         $out_list3 = $g3->render("list3");
         //display
         $this->_example_output((object) array('output' => '', 'out_master' => $out_master, 'out_list2' => $out_list2, 'out_list3' => $out_list3));
         //$this->load->view('oil/oil-view');
     } else {
         //If no session, redirect to login page
         redirect('login', 'refresh');
     }
 }
Пример #7
0
 $col["align"] = "center";
 $cols[] = $col;
 //Client
 $col = array();
 $col["title"] = "Client";
 $col["name"] = "IDClient";
 $col["dbname"] = "t_details.IDClient";
 // this is required as we need to search in name field, not id
 $col["width"] = "100";
 $col["align"] = "left";
 $col["search"] = true;
 $col["editable"] = true;
 $col["edittype"] = "select";
 // render as select
 # fetch data from database, with alias k for key, v for value
 $str = $d_grid->get_dropdown_values("SELECT DISTINCT ID AS k, Nom AS v FROM t_clients ORDER BY Nom");
 $col["editoptions"] = array("value" => $str, "required" => true);
 $col["formatter"] = "select";
 // display label, not value
 $col["stype"] = "select";
 // enable dropdown search
 $col["searchoptions"] = array("value" => ":;" . $str);
 $col["align"] = "center";
 $cols[] = $col;
 //test nom ne marche pas
 /*
   $col = array();
 	$col["title"] = "nom";
 	$col["name"] = "nom";
   $col["dbname"] = "SELECT Nom FROM t_clients WHERE t_details.IDClient = t_clients.ID";
   $col["hidden"] = true;
Пример #8
0
 public function index()
 {
     if ($this->session->userdata('user_name')) {
         $i_rule = $this->session->userdata('user_cizacl_role_id');
         $this->load->model('income_model', 'dropdrown');
         $this->load->model('dropdown_model', 'cus_drop');
         date_default_timezone_set('Asia/Bangkok');
         $g = new jqgrid();
         $col = array();
         $col["title"] = "Id";
         // caption of column
         $col["name"] = "id";
         $col["width"] = "10";
         $col["fixed"] = true;
         $col["search"] = false;
         $col["editable"] = false;
         $col["export"] = false;
         $col["hidden"] = true;
         $cols[] = $col;
         #Date
         $col = array();
         $col["title"] = $this->lang->line('date');
         $col["name"] = "order_date";
         $col["fixed"] = true;
         $col["width"] = "150";
         $col["editable"] = true;
         // this column is editable
         $col["editoptions"] = array("size" => 20, "defaultValue" => date("d-m-Y H:i:s"));
         // with default display of textbox with size 20
         $col["editrules"] = array("required" => true);
         // and is required
         $col["formatter"] = "datetime";
         // format as date
         $col["formatoptions"] = array("srcformat" => 'Y-m-d H:i:s', "newformat" => 'd-m-Y H:i:s', "opts" => array("changeYear" => false, "timeFormat" => "hh:mm tt"));
         $col["search"] = true;
         $cols[] = $col;
         #DP Number
         $col = array();
         $col["title"] = $this->lang->line('dp_number');
         // caption of column
         $col["name"] = "dp_number";
         $col["fixed"] = true;
         $col["width"] = "100";
         $col["search"] = true;
         $col["editrules"] = array("required" => true);
         $col['editoptions'] = array("defaultValue" => "", "min" => "1", "max" => "10", "maxlength" => "10");
         $col["editable"] = true;
         $cols[] = $col;
         #Customer
         $col = array();
         $col["title"] = "customer_id";
         $col["name"] = "customer_id";
         $col["width"] = "10";
         $col["editable"] = true;
         $col["export"] = false;
         $col["hidden"] = true;
         $cols[] = $col;
         #Customer name
         $col = array();
         $col["title"] = $this->lang->line('customer');
         $col["name"] = "cid";
         $col["dbname"] = "cus.customers_name";
         // this is required as we need to search in name field, not id
         $col["fixed"] = true;
         $col["width"] = "200";
         $col["align"] = "left";
         $col["editrules"] = array("required" => true);
         $col["search"] = true;
         $col["editable"] = true;
         $col["formatter"] = "autocomplete";
         // autocomplete
         $col["formatoptions"] = array("sql" => "SELECT * FROM (SELECT customer_id as k, customers_name  as v FROM transport_customers where customer_type_id=1 GROUP BY customers_name) o", "search_on" => "v", "update_field" => "customer_id");
         $cols[] = $col;
         #factory
         $col = array();
         $col["title"] = $this->lang->line('factory');
         $col["name"] = "factory_id";
         $col["dbname"] = "fac.factory_code";
         // this is required as we need to search in name field, not id
         $col["fixed"] = true;
         $col["width"] = "100";
         $col["align"] = "left";
         $col["search"] = true;
         $col["editable"] = true;
         $col["editrules"] = array("required" => true);
         $col["edittype"] = "select";
         // render as select
         # fetch data from database, with alias k for key, v for value
         //$str = $g->get_dropdown_values("select distinct client_id as k, name as v from clients");
         $str = $this->dropdrown->get_factory_dropdown();
         $col["editoptions"] = array("value" => $str);
         $col["editoptions"]["dataInit"] = "function(){ setTimeout(function(){ \$('select[name=factory_id]').select2({width:'80%', dropdownCssClass: 'ui-widget ui-jqdialog'}); },200); }";
         $col["formatter"] = "select";
         // display label, not value
         $cols[] = $col;
         #Real Distance
         $col = array();
         $col['title'] = $this->lang->line('real_distance');
         $col['name'] = "real_distance";
         $col["fixed"] = true;
         $col['align'] = "center";
         $col['width'] = "65";
         $col["search"] = false;
         $col["editrules"] = array("required" => true, "number" => true);
         $col["editable"] = true;
         // this column is editable
         // $col["editoptions"] = array("defaultValue" => 1);
         $col["editoptions"] = array("defaultValue" => 1, "onchange" => array("sql" => "SELECT DISTINCT distance_id AS k,distance_code AS v FROM distancecode\nWHERE range_min <= '{real_distance}'\tAND range_max >='{real_distance}' ", "update_field" => "distance_id"));
         $cols[] = $col;
         #dis Distance_code
         $col = array();
         $col['title'] = $this->lang->line('distance_code');
         $col['name'] = "distance_id";
         $col['dbname'] = "dis.distance_code";
         $col["fixed"] = true;
         $col['width'] = "80";
         $col["search"] = false;
         $col['align'] = "center";
         $col["editable"] = true;
         $col["editrules"] = array("required" => true);
         $col["edittype"] = "select";
         // render as select
         $str = $this->cus_drop->get_distancecode_dropdown();
         $col["editoptions"] = array("value" => $str);
         #$col["formatter"] = "select"; // display label, not value
         // initially load 'note' of that client_id
         $col["editoptions"]["onload"]["sql"] = "SELECT DISTINCT distance_id AS k,distance_code AS v FROM distancecode\nWHERE range_min <= '{real_distance}'\tAND range_max >='{real_distance}' ";
         $col["formatter"] = "select";
         // display label, not value
         $col["stype"] = "select";
         // enable dropdown search
         $col["searchoptions"] = array("value" => ":;" . $str);
         $cols[] = $col;
         /*Cubic*/
         $col = array();
         $col['title'] = $this->lang->line('cubic_value');
         $col["name"] = "cubic_id";
         $col["dbname"] = "orders.cubic_id";
         // this is required as we need to search in name field, not id
         $col['width'] = "80";
         $col["fixed"] = true;
         $col["align"] = "center";
         $col["search"] = false;
         $col["editable"] = true;
         $col["edittype"] = "select";
         // render as select
         # fetch data from database, with alias k for key, v for value
         $str = $g->get_dropdown_values("select distinct cubic_id as k, cubic_value as v from transport_cubiccode where cubic_status=1");
         //$str = $this->cus_drop->get_cubiccode_dropdown();
         $col["editoptions"] = array("value" => ":;" . $str);
         $col["editoptions"]["dataInit"] = "function(){ setTimeout(function(){ \$('select[name=cubic_id]').select2({width:'80%', dropdownCssClass: 'ui-widget ui-jqdialog'}); },200); }";
         $cols[] = $col;
         #price
         $col = array();
         $col['title'] = $this->lang->line('price');
         $col['name'] = "price";
         $col['align'] = "right";
         $col["fixed"] = true;
         $col['width'] = "80";
         //$col["editrules"] = array("number" => true);
         $col['editoptions'] = array("defaultValue" => "0", "readonly" => true);
         #$col['hidden'] = true;
         $col["show"] = array("list" => true, "add" => false, "edit" => false, "view" => true);
         $col['editable'] = true;
         $col['search'] = false;
         $cols[] = $col;
         /*End Cubic*/
         #car
         $col = array();
         $col["title"] = $this->lang->line('car_number');
         $col['name'] = "car_id";
         $col['dbname'] = "car.car_number";
         $col["fixed"] = true;
         $col['align'] = "center";
         $col['width'] = "85";
         $col['search'] = true;
         $col['editable'] = true;
         $col["editrules"] = array("required" => true);
         $col['edittype'] = "select";
         $str = $this->cus_drop->get_car_dropdown();
         $col["editoptions"] = array("value" => $str, "onchange" => array("sql" => "SELECT DISTINCT driver_id as k, driver_name as v  FROM driver WHERE car_id = '{car_id}'", "update_field" => "driver_id"));
         $col['formatter'] = "select";
         //$col["stype"] = "select"; // enable dropdown search
         //$col["searchoptions"] = array("car_id" => ":;".$str);
         $cols[] = $col;
         #Driver
         $col = array();
         $col["title"] = $this->lang->line('driver');
         $col['name'] = "driver_id";
         $col['dbname'] = "dri.driver_name";
         $col["fixed"] = true;
         $col['width'] = "150";
         $col['search'] = true;
         $col['editable'] = true;
         $col['edittype'] = "select";
         $col["editrules"] = array("required" => true);
         $str = $this->cus_drop->get_drivers_dropdown();
         $col['editoptions'] = array("value" => $str);
         $col['formatter'] = "select";
         $col["searchoptions"] = array("car_id" => ":;" . $str);
         $cols[] = $col;
         #OilUse
         $col = array();
         $col['title'] = $this->lang->line('use_oil');
         $col['name'] = "use_oil";
         $col['dbname'] = "orders.use_oil";
         $col["fixed"] = true;
         $col['align'] = "center";
         $col['width'] = "70";
         $col["editoptions"] = array("number" => true, "defaultValue" => '0');
         $col['editrules'] = array("number" => true);
         $col['formater'] = "number";
         $col['editable'] = true;
         $cols[] = $col;
         #Remark
         $col = array();
         $col['title'] = $this->lang->line('remark');
         $col['name'] = "remark";
         $col['dbname'] = "orders.remark";
         $col["fixed"] = true;
         $col['width'] = "120";
         $col["edittype"] = "textarea";
         $col["editoptions"] = array("rows" => 2, "cols" => 20);
         $col['editable'] = true;
         $cols[] = $col;
         /*Grid Option*/
         $opt["sortname"] = 'id';
         $opt["sortorder"] = "desc";
         $opt["caption"] = $this->lang->line('Order_Transportation');
         $opt['rowNum'] = 10;
         $opt['rowList'] = array(10, 20, 30);
         $opt['height'] = "360";
         $opt["autowidth"] = true;
         $opt["multiselect"] = true;
         $opt["scroll"] = true;
         $opt["add_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         $opt["edit_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         $opt["add_options"]["afterShowForm"] = 'function(formid) { jQuery("#dp_number").focus();}';
         $opt["edit_options"]["afterShowForm"] = 'function(formid) { jQuery("#dp_number").focus();}';
         $opt["altRows"] = true;
         $opt["altclass"] = "myAltRowClass";
         $opt["form"]["position"] = "center";
         // or "all"
         $g->set_options($opt);
         $g->set_actions(array("add" => $this->cizacl->check_isAllowed($i_rule, 'truckorder', 'add'), "edit" => $this->cizacl->check_isAllowed($i_rule, 'truckorder', 'edit'), "delete" => $this->cizacl->check_isAllowed($i_rule, 'truckorder', 'delete'), "rowactions" => false, "export" => true, "autofilter" => true, "search" => "advance"));
         $g->select_command = "SELECT\n\tid,\n\tdp_number,\n\torders.customer_id,\n    cus.customers_name AS cid,\n    orders.factory_id,\n\tfac.factory_code,\n\treal_distance,\n\torders.distance_id,\n\tdis.distance_code,\t\n    cubic.cubic_value as cubic_id,\n    orders.price AS price,\n\torders.use_oil,\n    orders.car_id,\n\tcar.car_number,\n\torders.driver_id,\n\tdri.driver_name,\n    order_date,\n    orders.delivery_datetime,\n    orders.remark\n\nFROM\n\t`orders` AS orders\nLEFT JOIN transport_factory AS fac ON (\n\torders.factory_id = fac.factory_id\n)\nLEFT JOIN transport_customers AS cus ON (\n\torders.customer_id = cus.customer_id\n)\nLEFT JOIN transport_cubiccode AS cubic ON (\n\torders.cubic_id = cubic.cubic_id\n)\nLEFT JOIN distancecode AS dis ON (\n\torders.distance_id = dis.distance_id\n)\nLEFT JOIN transport_cars AS car ON (\norders.car_id = car.car_id\n)\nLEFT JOIN driver AS dri ON (\n\torders.driver_id = dri.driver_id\n)";
         // this db table will be used for add,edit,delete
         $g->table = "orders";
         $e["on_insert"] = array("add_order", null, true);
         $e["on_after_insert"] = array("after_insert", null, true);
         $e["on_update"] = array("do_update", null, true);
         $e["on_data_display"] = array("filter_display", null, true);
         $g->set_events($e);
         function add_order(&$data)
         {
             //print_r($data);
             $obj =& get_instance();
             $obj->load->model("price_model", "pricelist");
             //$id = intval($_REQUEST["id"]);
             $factory_id = $data["params"]["factory_id"];
             $distance_id = $data["params"]["distance_id"];
             $cubid_id = $data["params"]["cubic_id"];
             $order_date = $data["params"]["order_date"];
             #get price
             $order_price = $obj->pricelist->get_order_Price($factory_id, $cubid_id, $distance_id, $order_date);
             if ($order_price == null) {
                 $str = ob_get_clean();
                 $str = "ยังไม่มีการกำหนดราคาค่าขนส่ง";
                 phpgrid_error($str);
             }
             /*check DP NUmber*/
             $check_sql = "SELECT count(*) as c from orders where LOWER(`dp_number`) = '" . strtolower($data["params"]["dp_number"]) . "'";
             $rs = mysql_fetch_assoc(mysql_query($check_sql));
             if ($rs["c"] > 0) {
                 phpgrid_error("หมายเลข DP Number ซ้ำ");
             }
             /*End Check DP Number*/
             //$str = "UPDATE orders SET price ='{$data["parmas"]["price"]}' WHERE id = '{$data["id"]}'";
             //mysql_query($str);
         }
         function do_update(&$data)
         {
             //print_r($data);
             $obj =& get_instance();
             $obj->load->model("price_model", "pricelist");
             $id = intval($_REQUEST["id"]);
             $factory_id = $data["params"]["factory_id"];
             $distance_id = $data["params"]["distance_id"];
             $cubid_id = $data["params"]["cubic_id"];
             $order_date = $data["params"]["order_date"];
             #get price
             $order_price = $obj->pricelist->get_order_Price($factory_id, $cubid_id, $distance_id, $order_date);
             if ($order_price == null) {
                 $str = ob_get_clean();
                 $str = "ยังไม่มีการกำหนดราคาค่าขนส่ง";
                 phpgrid_error($str);
             } else {
                 $data["params"]["price"] = $order_price;
                 $str = "UPDATE orders SET price ='{$data["parmas"]["price"]}' WHERE id = '{$data["id"]}'";
                 mysql_query($str);
             }
             //$str = "UPDATE orders SET price ='{$data["parmas"]["price"]}' WHERE id = '{$data["id"]}'";
             //mysql_query($str);
         }
         function after_insert(&$data)
         {
             //print_r($data);
             $obj =& get_instance();
             $obj->load->model("price_model", "pricelist");
             $id = $data["id"];
             $factory_id = $data["params"]["factory_id"];
             $distance_id = $data["params"]["distance_id"];
             $cubid_id = $data["params"]["cubic_id"];
             $order_date = $data["params"]["order_date"];
             #get price
             $order_price = $obj->pricelist->get_order_Price($factory_id, $cubid_id, $distance_id, $order_date);
             $str = "UPDATE orders SET price ='{$order_price}' \n                    WHERE id = {$data["id"]}";
             mysql_query($str);
         }
         function filter_display(&$data)
         {
             foreach ($data["params"] as &$d) {
                 foreach ($d as $k => $v) {
                     $d[$k] = strtoupper($d[$k]);
                 }
             }
         }
         // pass the cooked columns to grid
         $g->set_columns($cols);
         // generate grid output, with unique grid name as 'list1'
         $out = $g->render("list1");
         $iprice = $this->price->get_order_Price(2, 2, 2);
         $h2_title = $this->lang->line('order_car_truck');
         //display
         $this->_example_output((object) array('output' => "", 'out' => $out, 'h2_title' => $h2_title, 'iprice' => $iprice, 'js_files' => array(), 'css_files' => array()));
         //$this->_example_output();
     } else {
         redirect('login', 'refresh');
     }
     //end if
 }
Пример #9
0
// Client
$col = array();
$col["title"] = "Client";
$col["name"] = "IDClient";
$col["dbname"] = "t_clients.Nom";
// this is required as we need to search in name field, not id
$col["width"] = "100";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select";
// render as select
$col["export"] = true;
# fetch data from database, with alias k for key, v for value
# on change, update other dropdown
$str = $detail_grid->get_dropdown_values("SELECT DISTINCT ID AS k, Nom AS v FROM t_clients ORDER BY Nom");
$col["editoptions"] = array("value" => $str);
$col["formatter"] = "select";
// display label, not value
$col["stype"] = "select";
// enable dropdown search
$col["searchoptions"] = array("value" => ":;" . $str);
$cols[] = $col;
//Poids achat
$col = array();
$col["title"] = "Poids achat";
$col["name"] = "PoidsAchat";
$col["width"] = "100";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select";
Пример #10
0
 public function index()
 {
     //check login
     if ($this->session->userdata('user_name')) {
         $i_rule = $this->session->userdata('user_cizacl_role_id');
         $g = new jqgrid();
         #ID
         $col = array();
         $col['title'] = "ID";
         $col['name'] = "customer_id";
         $col['hidden'] = true;
         $col['isnull'] = true;
         $cols[] = $col;
         #Factory
         $col = array();
         $col["title"] = $this->lang->line("factory_name");
         $col["name"] = "factory_id";
         $col["dbname"] = "fac.factory_id";
         // this is required as we need to search in name field, not id
         $col["width"] = "100";
         $col["align"] = "left";
         $col["search"] = true;
         $col["editable"] = true;
         $col["edittype"] = "select";
         // render as select
         # fetch data from database, with alias k for key, v for value
         $str = $g->get_dropdown_values("select distinct factory_id as k, factory_name as v from transport_factory  where factory_status =1");
         $col["editoptions"] = array("value" => ":;" . $str);
         $col["formatter"] = "select";
         // display label, not value
         $col["editrules"] = array("required" => true);
         $col["editoptions"] = array("value" => $str);
         $col["formatter"] = "select";
         // display label, not value
         $col["stype"] = "select";
         // enable dropdown search
         $col["searchoptions"] = array("value" => ":;" . $str);
         $cols[] = $col;
         #Customer_Type
         $col = array();
         $col["title"] = $this->lang->line('customer_type');
         $col["name"] = "customer_type_id";
         $col["dbname"] = "cus_type.customer_type_title";
         // this is required as we need to search in name field, not id
         $col["fixed"] = true;
         //$col["width"] = "65";
         $col["align"] = "left";
         $col["search"] = true;
         $col["editable"] = true;
         $col["edittype"] = "select";
         // render as select
         # fetch data from database, with alias k for key, v for value
         //$str = $g->get_dropdown_values("select distinct client_id as k, name as v from clients");
         $str = $g->get_dropdown_values("SELECT DISTINCT customer_type_id AS k, customer_type_title AS v FROM `transport_customer_type` WHERE customer_type_status ='2'");
         #$str = $this->dropdrown->get_customer_type();
         $col["editoptions"] = array("value" => $str);
         $col["formatter"] = "select";
         // display label, not value
         $cols[] = $col;
         #Customer name
         $col = array();
         $col['title'] = $this->lang->line('customer_agancy');
         $col['name'] = "customer_name";
         $col["editrules"] = array("required" => true);
         $col["search"] = true;
         $col['editable'] = true;
         $cols[] = $col;
         #remark
         $col = array();
         $col['title'] = $this->lang->line('note');
         $col['name'] = "remark";
         $col['editable'] = true;
         $col['edittype'] = "textarea";
         $col["viewable"] = false;
         $col['editoptions'] = array("rows" => "2", "cols" => "20");
         $cols[] = $col;
         // $cols[] = $col;
         $e["on_insert"] = array("add_client", null, true);
         $e["on_delete"] = array("delete_client", null, true);
         #$e["on_delete"] = array("del_client", null, true);
         $g->set_events($e);
         $g->select_command = "SELECT\n\tcustomer_id,\n\tcustomer_name,\n\to_c.factory_id,\n\to_c.customer_type_id,\n\tcustomer_type_title,\n    o_c.remark as remark\nFROM\n\ttransport_oilcustomers AS o_c\nLEFT JOIN transport_factory AS fac ON (\n\to_c.factory_id = fac.factory_id\n)\nLEFT JOIN transport_customer_type AS cus_type ON (\n\to_c.customer_type_id = cus_type.customer_type_id\n)\nWHERE\n\to_c.`status` = 1";
         function add_client(&$data)
         {
             $check_sql = "SELECT count(*) as c from transport_oilcustomers where factory_id =" . $data["params"]["factory_id"] . " AND LOWER(`customer_name`) = '" . strtolower($data["params"]["customer_name"]) . "'";
             $rs = mysql_fetch_assoc(mysql_query($check_sql));
             if ($rs["c"] > 0) {
                 phpgrid_error("ข้อมูลลูกค้าซ้ำ");
             }
         }
         // end of sub function
         function delete_client(&$data)
         {
             ob_start();
             print_r($data);
             $str = ob_get_clean();
             $str = "UPDATE `transport_oilcustomers` SET `status`='0' WHERE (`customer_id`='{$data["id"]}')";
             mysql_query($str);
         }
         //Use Table
         $g->table = "transport_oilcustomers";
         // pass the cooked columns to grid
         $g->set_columns($cols);
         $opt["sortname"] = 'customer_name';
         $opt["sortorder"] = "asc";
         $opt["detail_grid_id"] = "list2";
         $opt["multiselect"] = false;
         $opt["subgridparams"] = "customer_id";
         $opt["rowList"] = array(10, 20, 30);
         $opt["caption"] = $this->lang->line('customer');
         $opt["autowidth"] = true;
         $opt["multiselect"] = false;
         $opt["autowidth"] = true;
         $opt["view_options"]['width'] = '520';
         $opt["add_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         $opt["edit_options"] = array("recreateForm" => true, "closeAfterEdit" => true, 'width' => '420');
         $opt["edit_options"]["beforeSubmit"] = "function(post,form){ return validate_form_once(post,form); }";
         $g->set_options($opt);
         $g->set_actions(array("add" => $this->cizacl->check_isAllowed($i_rule, 'customer', 'add_customer'), "edit" => $this->cizacl->check_isAllowed($i_rule, 'customer', 'edit_customer'), "delete" => $this->cizacl->check_isAllowed($i_rule, 'customer', 'del_customer'), "export" => false, "autofilter" => true, "search" => "advance"));
         // set database table for CRUD operations
         // render grid and get html/js output
         $out_index = $g->render("list1");
         // detail grid
         $grid = new jqgrid();
         $id = intval($_GET["rowid"]);
         $opt2 = array();
         $opt2["sortname"] = 'car_id';
         // by default sort grid by this field
         $opt2["sortorder"] = "desc";
         // ASC or DESC
         $opt2["height"] = "";
         // autofit height of subgrid
         $opt2["width"] = "640";
         $opt2["caption"] = $this->lang->line('car_details');
         // caption of grid
         $opt2["multiselect"] = true;
         // allow you to multi-select through checkboxes
         $opt2["rowList"] = array(10, 20, 30);
         // Check if master record is selected before detail addition
         $opt2["add_options"]["beforeInitData"] = "function(formid){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); if (!selr) { alert('กรุณาเลือกหน่วยงานของรถ'); return false; } }";
         $grid->set_options($opt2);
         $grid->set_actions(array("add" => true, "edit" => true, "delete" => true, "rowactions" => true, "export" => false, "autofilter" => true, "search" => "advance"));
         #ID
         $col2 = array();
         $col2['title'] = "ID";
         $col2['name'] = "car_id";
         $col2['hidden'] = true;
         $col2['isnull'] = true;
         $cols2[] = $col2;
         $col2 = array();
         $col2['title'] = $this->lang->line('car_number');
         $col2['name'] = "car_number";
         $col2['editable'] = true;
         $col2["formatter"] = "autocomplete";
         // autocomplete
         $col2["formatoptions"] = array("sql" => "SELECT car_number AS k,car_number AS v FROM `transport_cars` WHERE `status`=1", "search_on" => "car_number", "update_field" => "car_number");
         $cols2[] = $col2;
         $col2 = array();
         $col2['title'] = $this->lang->line('car_license');
         $col2['name'] = "car_license";
         $col2['editable'] = true;
         $cols2[] = $col2;
         $col2 = array();
         $col2['name'] = "customer_id";
         $col2['title'] = "customer_id";
         $col2['editable'] = true;
         $col2['hidden'] = true;
         $cols2[] = $col2;
         $grid->select_command = "SELECT car_id,car_number,car_license,customer_id FROM transport_oilcars WHERE customer_id ={$id}";
         $grid->table = "transport_oilcars";
         $grid->set_columns($cols2);
         $e["on_insert"] = array("oilcars", null, true);
         $e["on_after_insert"] = array("after_insert", null, true);
         // return last inserted id for further working
         $grid->set_events($e);
         function oilcars(&$data)
         {
             $id = intval($_GET["rowid"]);
             $data["params"]["customer_id"] = $id;
             $check_sql = "SELECT count(*) as c from transport_oilcars WHERE customer_id = {$id} and LOWER(`car_number`) = '" . strtolower($data["params"]["car_number"]) . "'";
             $rs = mysql_fetch_assoc(mysql_query($check_sql));
             if ($rs["c"] > 0) {
                 phpgrid_error("หมายเลขรถซ้ำ");
             }
         }
         function after_insert($data)
         {
             /*
             These comments are just to show the input $data format 
             Array 
             ( 
             [client_id] => 99 
             [params] => Array 
             ( 
             [client_id] =>  
             [name] => Test 
             [gender] => male 
             [company] => Comp Test 
             ) 
             
             )     
             */
             /*
             ob_start(); 
             print_r($data); 
             $str = ob_get_clean(); 
             phpgrid_error($str); 
             */
             $car_number = $data['params']['car_number'];
         }
         $out_detail = $grid->render("list2");
         $h2_title = $this->lang->line('customeroils');
         //display
         $this->_example_output((object) array('output' => '', 'out' => $out_index, 'out_detail' => $out_detail, 'h2_title' => $h2_title, 'js_files' => array(), 'css_files' => array()));
     } else {
         //If no session, redirect to login page
         redirect('login', 'refresh');
     }
 }
Пример #11
-1
$col["name"] = "NoVente";
$col["width"] = "10";
$cols[] = $col;
$col = array();
$col["title"] = "Client";
$col["name"] = "IDClient";
$col["dbname"] = "t_details.IDClient";
// this is required as we need to search in name field, not id
$col["width"] = "100";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select";
// render as select
# fetch data from database, with alias k for key, v for value
$str = $g->get_dropdown_values("select distinct ID as k, Nom as v from t_clients");
$col["editoptions"] = array("value" => ":;" . $str);
$col["formatter"] = "select";
// display label, not value
$cols[] = $col;
$col = array();
$col["title"] = "Poids Achat";
$col["name"] = "PoidsAchat";
$col["width"] = "50";
$col["editable"] = true;
// this column is editable
$col["editoptions"] = array("size" => 20);
// with default display of textbox with size 20
$col["editrules"] = array("required" => true);
// and is required
$col["search"] = false;