Advertisement
caloyiv

footer code

Oct 18th, 2014
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.67 KB | None | 0 0
  1. <?php require_once('../../includes/initialize.php');?>
  2. <?php
  3. /**
  4.  * PHP Grid Component
  5.  *
  6.  * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
  7.  * @version 1.5.2
  8.  * @license: see license.txt included in package
  9.  */
  10. $g = new jqgrid();
  11.  
  12. $opt["rowNum"] = 10; // by default 20
  13. //$opt["sortname"] = 'id'; // by default sort grid by this field
  14. $opt["sortorder"] = "desc"; // ASC or DESC
  15. $opt["caption"] = "Remittance"; // caption of grid
  16. $opt["autowidth"] = false; // expand grid to screen width
  17. $opt["multiselect"] = true; // allow you to multi-select through checkboxes
  18. $opt["footerrow"] = true;
  19. $opt["reloadedit"] = true;
  20.  
  21. $g->set_options($opt);
  22.  
  23. $g->set_actions(array(
  24.                         "add"=>false, // allow/disallow add
  25.                         "edit"=>false, // allow/disallow edit
  26.                         "delete"=>false, // allow/disallow delete
  27.                         "rowactions"=>false, // show/hide row wise edit/del/save option
  28.                         "search" => "advance", // show single/multi field search condition (e.g. simple or advance)
  29.                         "autofilter" => true
  30.                     )
  31.                 );
  32.  
  33. // you can provide custom SQL query to display data
  34. $g->select_command = "SELECT remittance_id,salesman_id, amount, date, (SELECT sum(amount) from remittance) AS table_total FROM remittance";
  35.  
  36. // this db table will be used for add,edit,delete
  37. $g->table = "remittance";
  38.  
  39. $col = array();
  40. $col["title"] = "Id"; // caption of column
  41. $col["name"] = "remittance_id";
  42. $col["width"] = "15";
  43. $col["search"] = false;
  44. $col["editable"] = false;
  45. $cols[] = $col;        
  46.        
  47. $col = array();
  48. $col["title"] = "Salesman";
  49. $col["name"] = "salesman_id";
  50. $col["width"] = "100";
  51. $col["search"] = true;
  52. $col["editable"] = true;
  53. $cols[] = $col;
  54.  
  55. $col = array();
  56. $col["title"] = "Date";
  57. $col["name"] = "date";
  58. $col["width"] = "50";
  59. $col["editable"] = false; // this column is editable
  60. $col["formatter"] = "date"; // format as date
  61. $col["search"] = true;
  62. $cols[] = $col;
  63.  
  64. $col = array();
  65. $col["title"] = "Amount";
  66. $col["name"] = "amount";
  67. $col["width"] = "50";
  68. $col["search"] = true;
  69. $col["editable"] = false; // this column is editable
  70. $col["formatter"] = "currency";
  71. $col["formatoptions"] = array("prefix" => "P",
  72.                                 "suffix" => '',
  73.                                 "thousandsSeparator" => ",",
  74.                                 "decimalSeparator" => ".",
  75.                                 "decimalPlaces" => '2');
  76. $cols[] = $col;
  77.  
  78. // virtual column for running total
  79. $col = array();
  80. $col["title"] = "running_total";
  81. $col["name"] = "running_total";
  82. $col["width"] = "100";
  83. $col["hidden"] = true;
  84. $col[] = $col;
  85.  
  86. // virtual column for grand total
  87. $col = array();
  88. $col["title"] = "table_total";
  89. $col["name"] = "table_total";
  90. $col["width"] = "100";
  91. $col["hidden"] = true;
  92. $col[] = $col;
  93.  
  94. // pass the cooked columns to grid
  95. $g->set_columns($cols);
  96.  
  97. // running total calculation
  98. $e = array();
  99. $e["on_data_display"] = array("pre_render","",true);
  100.  
  101. $e["js_on_select_row"] = "grid_onselect";
  102. $e["js_on_load_complete"] = "grid_onload";
  103.  
  104. $g->set_events($e);
  105.  
  106. function pre_render($data)
  107. {
  108.     $rows = $_GET["jqgrid_page"] * $_GET["rows"];
  109.     $sidx = $_GET['sidx']; // get index row - i.e. user click to sort
  110.     $sord = $_GET['sord']; // get the direction
  111.    
  112.     // same sql as in select_command
  113.     $rs = mysql_fetch_assoc(mysql_query("SELECT SUM(amount) as s FROM (SELECT total FROM remittance ORDER BY $sidx $sord LIMIT $rows) AS tmp"));
  114.     foreach($data["params"] as &$d)
  115.     {
  116.         $d["running_total"] = $rs["s"];
  117.     }
  118. }
  119.  
  120. // generate grid output, with unique grid name as 'list1'
  121. $out = $g->render("list1");
  122.  
  123. ?>
  124.  
  125. <?php include_layout_template('header.php'); ?>
  126. <?php include_layout_template('menu.php'); ?>
  127.  
  128. <!-- start page -->
  129. <div id="page">
  130.   <!-- start content -->
  131.  
  132.  <script>
  133. // e.g. to show footer summary
  134.     function grid_onload()
  135.     {
  136.         var grid = $("#list1");
  137.  
  138.         // sum of displayed result
  139.         sum = grid.jqGrid('getCol', 'Amount', false, 'sum'); // 'sum, 'avg', 'count' (use count-1 as it count footer row).
  140.  
  141.         // sum of running total records
  142.         sum_running = grid.jqGrid('getCol', 'running_total')[0];
  143.  
  144.         // sum of total records
  145.         sum_table = grid.jqGrid('getCol', 'table_total')[0];
  146.  
  147.         // record count
  148.         c = grid.jqGrid('getCol', 'Id', false, 'sum');
  149.  
  150.         grid.jqGrid('footerData','set', {Id: 'Total: ' + sum, Date: 'Sub Total: '+sum_running, Amount: 'Grand Total: '+sum_table});
  151.     };
  152.    
  153.     // e.g. to update footer summary on selection
  154.     function grid_onselect()
  155.     {
  156.  
  157.         var grid = $("#list1");
  158.  
  159.         var t = 0;
  160.         var selr = grid.jqGrid('getGridParam','selarrrow'); // array of id's of the selected rows when multiselect options is true. Empty array if not selection
  161.         for (var x=0;x<selr.length;x++)
  162.         {
  163.             t += parseInt(grid.jqGrid('getCell', selr[x], 'total'));
  164.         }
  165.         grid.jqGrid('footerData','set', {Date: 'Total: '+t});
  166.     };
  167.     </script>
  168.     <h6 class="pagetitle">&nbsp </h6>
  169.     <div id="tabs">
  170. <ul>
  171. <li><a href="#tabs-1">Remittance</a></li>
  172. <li><a href="#tabs-2">Report B</a></li>
  173. <li><a href="#tabs-3">Report C</a></li>
  174. </ul>
  175. <div id="tabs-1">
  176.     <?php echo $out ?>
  177. </div>
  178. <div id="tabs-2">
  179.     <?php //echo $out2?>
  180. </div>
  181. <div id="tabs-3">
  182.     <p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
  183.     <p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
  184.     <?php //echo $out_third?>
  185. </div>
  186. </div>
  187.  
  188.  
  189.  <script>
  190. $(function() {
  191. $( "#tabs" ).tabs();
  192. });
  193. </script>
  194.  
  195.     </div>
  196.  
  197.   <!-- end content -->
  198.  
  199. <?php include_layout_template('footer.php'); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement