Advertisement
Guest User

Untitled

a guest
Sep 4th, 2018
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 38.57 KB | None | 0 0
  1. <?php
  2. include_once ('dbconn.php');
  3. //$store_id =   intval($_SESSION["store_id"]);
  4. $is_new     =   intval($_SESSION["is_new"]);
  5. $name       =   $_SESSION["user_full_name"];
  6. $group_id   =   $_SESSION["customer_id"];
  7. if ( $_SESSION['auth_type'] == 'SYS-ADMIN')
  8.     $query          =   "select DISTINCT sm.* from store_master sm INNER JOIN view_stocktake_master vsm ON vsm.store_id = sm.id order by vsm.stock_date desc";
  9. //print_r($_SESSION);
  10. else
  11.     $query          =   "select * from store_master where customer_id = '$group_id' order by store_name desc";
  12. //echo $query;
  13. $retval         =   f_select_query($query, $datarows);
  14. $store_id = 0;
  15. if ($retval == -1 )
  16. {
  17.     $connected = false;
  18.  
  19. }
  20.  
  21.  
  22. if ($is_new == 1)
  23. {
  24.  
  25. }
  26. $rowcount =  count($datarows);
  27. //echo $query;
  28. //print_r ($datarows);
  29. ?>
  30. <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  31. <div id="this_form_id" class="container-fluid box-grid " >
  32.     <div class="row">
  33.  
  34.     <div class="col-sm-2 col-xs-12">
  35.     <div class="homepage_blocks">
  36.     <div class="container-fluid content_container" >
  37.     <div class="row">
  38.     <div class="title clearfix">
  39.         <span class="text-primary">List of Stores </span><br>
  40.     </div>
  41.  
  42.     <?
  43.     //echo $group_id;
  44. for ($counter = 0; $counter< $rowcount; $counter++)
  45. {
  46.     $store_id1 = $datarows[$counter]->id;
  47.     $query1             =   "select * from view_stocktake_master where store_id = $store_id1  order by stock_date desc limit 1";
  48.     //echo $query1;
  49.     $retval         =   f_select_query($query1, $datarows1);
  50.  
  51.     $query2             =   "select id from view_stocktake_master where store_id = $store_id1 order by stock_date desc limit 1";
  52.  
  53.     $retval         =   f_read_column('id', $query2, $stocktake_id);
  54.  
  55.     $query3         =   "select sum((quantity * unit_of_measure) + quantity_units) as total_quantity,  sum((quantity * full_cost) + (quantity_units * unit_cost)) as total_cost from stocktake_details where stocktake_id = $stocktake_id and location_id in (select id from stocktake_locations where is_completed = 1 and stocktake_id = $stocktake_id)";
  56.  
  57.     $retval     =   f_select_query($query3, $datarows3);
  58.  
  59. //print_r ($datarows3);
  60. //print_r ($datarows1);
  61. if ($datarows3[0]->total_cost == 0)
  62. { ?>
  63.     <div class="col-lg-12 col-md-1 col-sm-1 col-xs-1 stat-container" id ="stores">
  64.             <div class="dashboard-stat red-stat " >
  65.                 <div class="visual" id="<? echo $datarows[$counter]->id; ?>">
  66.  
  67.                 </div>
  68.                 <div class="details " id="<? echo $datarows[$counter]->id; ?>">
  69.                     <div style="text-align: center; margin-top: 7px; font-size: 10px;" class="more" id="<? echo $datarows[$counter]->id; ?>">
  70.                          <? echo $datarows[$counter]->store_name; ?>
  71.                     </div>
  72.                     <div style="text-align: center; margin-top: 7px; font-size: 12px;" class="desc" id="<? echo $datarows[$counter]->id; ?>">
  73.                     Date:   <? echo $datarows1[0]->stock_date_str; ?></br> Cost: €<? echo number_format($datarows3[0]->total_cost,2); ?>
  74.                     </div>
  75.                 </div>
  76.  
  77.             </div>
  78.         </div> <?
  79. }
  80. else
  81. {
  82. ?>
  83.     <div class="col-lg-12 col-md-1 col-sm-1 col-xs-1 stat-container" id ="stores">
  84.             <div class="dashboard-stat blue-stat " >
  85.                 <div class="visual" id="<? echo $datarows[$counter]->id; ?>">
  86.  
  87.                 </div>
  88.                 <div class="details " id="<? echo $datarows[$counter]->id; ?>">
  89.                     <div style="text-align: center; margin-top: 7px; font-size: 10px;" class="more" id="<? echo $datarows[$counter]->id; ?>">
  90.                          <? echo $datarows[$counter]->store_name; ?>
  91.                     </div>
  92.                     <div style="text-align: center; margin-top: 7px; font-size: 12px;" class="desc" id="<? echo $datarows[$counter]->id; ?>">
  93.                     Date:   <? echo $datarows1[0]->stock_date_str; ?></br> Cost: €<? echo number_format($datarows3[0]->total_cost,2); ?>
  94.                     </div>
  95.                 </div>
  96.  
  97.             </div>
  98.         </div>
  99.  
  100.             <?php
  101. }
  102. }
  103.             ?>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. <div class="col-sm-10 col-xs-12" id="tableDiv">
  109.  
  110.             <div class="homepage_blocks" id="leaderBoard">
  111.             <div class="container-fluid content_container" >
  112.             <div class="row">
  113.             <div class="title clearfix">
  114.                 <span class="text-primary">Leader Board </span><br>
  115.             </div>
  116.             </div>
  117.             </div>
  118.             <table style=' height:10px; margin: 0 auto; width: 1150px;' id="tbl_leader_board" class="table table-fixed table-striped table-bordered datalist"  cellspacing="0">
  119.             <thead>
  120.  
  121.                         <tr >
  122.                             <th style='width:8%;'> Date </th>
  123.                              <th style='width:15%;'> Store Name  </th>
  124.                              <th style='width:8%;'> City </th>
  125.                              <th style='width:10%;'> Opening Stock </th>
  126.                              <th style='width:6%;'> Wastage </th>
  127.                              <th style='width:6%;'> Purchases </th>
  128.                             <th style='width:6%;'> Sales </th>
  129.                             <th style='width:10%;'> Closing Stock </th>
  130.                             <th style='width:7%;'> GP (%) </th>
  131.                             <th style='width:11%;'> Previous GP (%) </th>
  132.                          </tr>
  133.  
  134.                 </thead>
  135.  
  136.                 <tbody>
  137.                 <?
  138.                     for ($counter = 0; $counter< $rowcount; $counter++)
  139.                     {
  140.                         $store_id1 = $datarows[$counter]->id;
  141.                         $store_name = $datarows[$counter]->store_name;
  142.                         $store_city = $datarows[$counter]->location_city;
  143.  
  144.                         $query      =   "select id AS stocktake_id, stock_date_str as stock_date FROM view_stocktake_master WHERE store_id = '$store_id1' ORDER BY stocktake_id DESC LIMIT 1";
  145.                         //echo $query;
  146.                         $retval         =   f_read_column('stocktake_id', $query, $stocktake_id);
  147.                         $retval         =   f_read_column('stock_date', $query, $stock_date);
  148.  
  149.                         $query_total_cost = "select sum(`stocktake_details`.`quantity_units` * `stocktake_details`.`unit_cost`) AS `total_cost`
  150.                              from `stocktake_details` INNER JOIN stocktake_locations on stocktake_details.location_id = stocktake_locations.id where `stocktake_details`.`stocktake_id` = '$stocktake_id'
  151.                              AND stocktake_locations.stocktake_id = '$stocktake_id' and stocktake_locations.is_completed != 0 group by stocktake_locations.stocktake_id";
  152.                         $retval         =   f_read_column('total_cost', $query_total_cost, $closing_stock);
  153.  
  154.                         if ($closing_stock == "0.00")
  155.                         {
  156.                             $query      =   "select id AS stocktake_id, stock_date_str as stock_date FROM view_stocktake_master WHERE store_id = '$store_id1' AND stock_date < DATE(NOW()) ORDER BY stocktake_id DESC LIMIT 1";
  157.                             $retval         =   f_read_column('stocktake_id', $query, $stocktake_id);
  158.                             $retval         =   f_read_column('stock_date', $query, $stock_date);
  159.  
  160.                             $query_total_cost = "select sum(`stocktake_details`.`quantity_units` * `stocktake_details`.`unit_cost`) AS `total_cost`
  161.                                  from `stocktake_details` INNER JOIN stocktake_locations on stocktake_details.location_id = stocktake_locations.id where `stocktake_details`.`stocktake_id` = '$stocktake_id'
  162.                                  AND stocktake_locations.stocktake_id = '$stocktake_id' and stocktake_locations.is_completed != 0 group by stocktake_locations.stocktake_id";
  163.                             $retval         =   f_read_column('total_cost', $query_total_cost, $closing_stock);
  164.  
  165.                              $query_total_purchases = "select sum(`store_purchases`.`cost_value`) AS `total_purchases` from `store_purchases` where `store_purchases`.`stocktake_id` = '$stocktake_id' ;";
  166.                              $retval        =   f_read_column('total_purchases', $query_total_purchases, $purchases);
  167.  
  168.                              $query_total_wastage = "select sum(`store_wastage`.`wastage_amount`) AS `total_wastage` from `store_wastage` where `store_wastage`.`stocktake_id` = '$stocktake_id'; ";
  169.                              $retval        =   f_read_column('total_wastage', $query_total_wastage, $wastage);
  170.  
  171.                              $query_total_sales = "select sum(`store_sales`.`sale_at_cost`) AS `total_sales` from `store_sales` where `store_sales`.`stocktake_id` = '$stocktake_id'; ";
  172.                              $retval        =   f_read_column('total_sales', $query_total_sales,$sales);
  173.  
  174.                              $query_total_labour = "select sum(`labour_costs`.`cost`) AS `total_labour` from `labour_costs` where `labour_costs`.`stocktake_id` = '$stocktake_id'; ";
  175.                              $retval        =   f_read_column('total_labour', $query_total_labour,$labour);
  176.  
  177.                              $query             =   "select id from view_stocktake_master where store_id = $store_id1 AND id < '$stocktake_id' order by stock_date desc limit 1";
  178.                              $retval        =   f_read_column('id', $query, $stocktake_id_prev);
  179.  
  180.                              $query_total_opening = "select sum(`stocktake_details`.`quantity_units` * `stocktake_details`.`unit_cost`) AS `total_cost`
  181.                                                  from `stocktake_details` INNER JOIN stocktake_locations on stocktake_details.location_id = stocktake_locations.id where `stocktake_details`.`stocktake_id` = '$stocktake_id_prev'
  182.                                                  AND stocktake_locations.stocktake_id = '$stocktake_id_prev' and stocktake_locations.is_completed != 0 group by stocktake_locations.stocktake_id LIMIT 1";
  183.                              $retval        =   f_read_column('total_cost', $query_total_opening, $opening_stock);
  184.                         }
  185.                         else {
  186.  
  187.                              $query_total_purchases = "select sum(`store_purchases`.`cost_value`) AS `total_purchases` from `store_purchases` where `store_purchases`.`stocktake_id` = '$stocktake_id' ;";
  188.                              $retval        =   f_read_column('total_purchases', $query_total_purchases, $purchases);
  189.  
  190.                              $query_total_wastage = "select sum(`store_wastage`.`wastage_amount`) AS `total_wastage` from `store_wastage` where `store_wastage`.`stocktake_id` = '$stocktake_id'; ";
  191.                              $retval        =   f_read_column('total_wastage', $query_total_wastage, $wastage);
  192.  
  193.                              $query_total_sales = "select sum(`store_sales`.`sale_at_cost`) AS `total_sales` from `store_sales` where `store_sales`.`stocktake_id` = '$stocktake_id'; ";
  194.                              $retval        =   f_read_column('total_sales', $query_total_sales,$sales);
  195.  
  196.                              $query_total_labour = "select sum(`labour_costs`.`cost`) AS `total_labour` from `labour_costs` where `labour_costs`.`stocktake_id` = '$stocktake_id'; ";
  197.                              $retval        =   f_read_column('total_labour', $query_total_labour,$labour);
  198.  
  199.                              $query             =   "select id from view_stocktake_master where store_id = $store_id1 AND id < '$stocktake_id' order by stock_date desc limit 1";
  200.                              $retval        =   f_read_column('id', $query, $stocktake_id_prev);
  201.  
  202.                              $query_total_opening = "select sum(`stocktake_details`.`quantity_units` * `stocktake_details`.`unit_cost`) AS `total_cost`
  203.                                                  from `stocktake_details` INNER JOIN stocktake_locations on stocktake_details.location_id = stocktake_locations.id where `stocktake_details`.`stocktake_id` = '$stocktake_id_prev'
  204.                                                  AND stocktake_locations.stocktake_id = '$stocktake_id_prev' and stocktake_locations.is_completed != 0 group by stocktake_locations.stocktake_id LIMIT 1";
  205.                              $retval        =   f_read_column('total_cost', $query_total_opening, $opening_stock);
  206.                         }
  207.  
  208.                          if ($sales == '')
  209.                              $sales = 0;
  210.                          if ($purchases == '')
  211.                              $purchases = 0;
  212.                          if ($wastage == '')
  213.                              $wastage = 0;
  214.                          if ($labour == '')
  215.                              $labour = 0;
  216.  
  217.                          if ($opening_stock == '')
  218.                          {
  219.                              $opening_stock = 0;
  220.                          }
  221.  
  222.                         $query          =   "select include_labour FROM store_master where id = $store_id1 ;";
  223.                         $retval         =   f_read_column('include_labour', $query, $include_labour);
  224.  
  225.                         $query          =   "select include_wastage FROM store_master where id = $store_id1 ;";
  226.                         $retval         =   f_read_column('include_wastage', $query, $include_waste);
  227.  
  228.                         if ($include_waste == 1 && $include_labour == 0)
  229.                             $consumption_cost = $opening_stock + $purchases + $wastage  - $closing_stock;
  230.                         else if ($include_waste == 0 && $include_labour == 1)
  231.                             $consumption_cost = $opening_stock + $purchases  + $labour - $closing_stock;
  232.                         else if ($include_waste == 0 && $include_labour == 0)
  233.                             $consumption_cost = $opening_stock + $purchases - $closing_stock;
  234.                         else
  235.                             $consumption_cost = $opening_stock + $purchases + $wastage + $labour - $closing_stock;
  236.  
  237.                           $gp = $sales - $consumption_cost;
  238.  
  239.                          if($gp == 0)
  240.                             $gp_per = 0;
  241.                          else
  242.                              $gp_per = ($gp/$sales) * 100;
  243.  
  244.                           if ($gp_per < 0 || $gp_per == INF)
  245.                              $gp_per = 0;
  246.  
  247.                           if ($wastage == NULL)
  248.                              $wastage = 0;
  249.  
  250.                           if ($purchases == NULL)
  251.                              $purchases = 0;
  252.  
  253.                          if ($sales == NULL)
  254.                              $sales = 0;
  255.  
  256.                          $gp_per_displ = number_format($gp_per,2);
  257.  
  258.                         echo "<tr> ";
  259.                         echo "<td class='details-control' style='text-align:center'>$stock_date</td>";
  260.                         echo "<td style='text-align:center'>$store_name</td>";
  261.                         echo "<td style='text-align:center'>$store_city</td>";
  262.                         echo "<td style='text-align:center'>$global_currency_sign ".number_format($opening_stock,2)."</td>";
  263.                         echo "<td style='text-align:center'>$global_currency_sign ".number_format($wastage,2)."</td>";
  264.                         echo "<td style='text-align:center'>$global_currency_sign ".number_format($purchases,2)."</td>";
  265.                         echo "<td style='text-align:center'>$global_currency_sign ".number_format($sales,2)."</td>";
  266.                         echo "<td style='text-align:center'>$global_currency_sign ".number_format($closing_stock,2)."</td>";
  267.  
  268.                         $query_total_cost = "select sum(`stocktake_details`.`quantity_units` * `stocktake_details`.`unit_cost`) AS `total_cost`
  269.                              from `stocktake_details` INNER JOIN stocktake_locations on stocktake_details.location_id = stocktake_locations.id where `stocktake_details`.`stocktake_id` = '$stocktake_id_prev'
  270.                              AND stocktake_locations.stocktake_id = '$stocktake_id_prev' and stocktake_locations.is_completed != 0 group by stocktake_locations.stocktake_id";
  271.                             $retval         =   f_read_column('total_cost', $query_total_cost, $closing_stock);
  272.  
  273.                             $query_total_purchases = "select sum(`store_purchases`.`cost_value`) AS `total_purchases` from `store_purchases` where `store_purchases`.`stocktake_id` = '$stocktake_id_prev' ;";
  274.                              $retval        =   f_read_column('total_purchases', $query_total_purchases, $purchases);
  275.  
  276.                              $query_total_wastage = "select sum(`store_wastage`.`wastage_amount`) AS `total_wastage` from `store_wastage` where `store_wastage`.`stocktake_id` = '$stocktake_id_prev'; ";
  277.                              $retval        =   f_read_column('total_wastage', $query_total_wastage, $wastage);
  278.  
  279.                              $query_total_sales = "select sum(`store_sales`.`sale_at_cost`) AS `total_sales` from `store_sales` where `store_sales`.`stocktake_id` = '$stocktake_id_prev'; ";
  280.                              $retval        =   f_read_column('total_sales', $query_total_sales,$sales);
  281.  
  282.                              $query_total_labour = "select sum(`labour_costs`.`cost`) AS `total_labour` from `labour_costs` where `labour_costs`.`stocktake_id` = '$stocktake_id_prev'; ";
  283.                              $retval        =   f_read_column('total_labour', $query_total_labour,$labour);
  284.  
  285.                              $query             =   "select id from view_stocktake_master where store_id = $store_id1 AND id < '$stocktake_id_prev' order by stock_date desc limit 1";
  286.                              $retval        =   f_read_column('id', $query, $stocktake_id_prev_prev);
  287.  
  288.                              $query_total_opening = "select sum(`stocktake_details`.`quantity_units` * `stocktake_details`.`unit_cost`) AS `total_cost`
  289.                                                  from `stocktake_details` INNER JOIN stocktake_locations on stocktake_details.location_id = stocktake_locations.id where `stocktake_details`.`stocktake_id` = '$stocktake_id_prev_prev'
  290.                                                  AND stocktake_locations.stocktake_id = '$stocktake_id_prev_prev' and stocktake_locations.is_completed != 0 group by stocktake_locations.stocktake_id LIMIT 1";
  291.                              $retval        =   f_read_column('total_cost', $query_total_opening, $opening_stock);
  292.                               if ($sales == '')
  293.                              $sales = 0;
  294.                          if ($purchases == '')
  295.                              $purchases = 0;
  296.                          if ($wastage == '')
  297.                              $wastage = 0;
  298.                          if ($labour == '')
  299.                              $labour = 0;
  300.  
  301.                          if ($opening_stock == '')
  302.                          {
  303.                              $opening_stock = 0;
  304.                          }
  305.  
  306.                         $query          =   "select include_labour FROM store_master where id = $store_id1 ;";
  307.                         $retval         =   f_read_column('include_labour', $query, $include_labour);
  308.  
  309.                         $query          =   "select include_wastage FROM store_master where id = $store_id1 ;";
  310.                         $retval         =   f_read_column('include_wastage', $query, $include_waste);
  311.  
  312.                         if ($include_waste == 1 && $include_labour == 0)
  313.                             $consumption_cost = $opening_stock + $purchases + $wastage  - $closing_stock;
  314.                         else if ($include_waste == 0 && $include_labour == 1)
  315.                             $consumption_cost = $opening_stock + $purchases  + $labour - $closing_stock;
  316.                         else if ($include_waste == 0 && $include_labour == 0)
  317.                             $consumption_cost = $opening_stock + $purchases - $closing_stock;
  318.                         else
  319.                             $consumption_cost = $opening_stock + $purchases + $wastage + $labour - $closing_stock;
  320.  
  321.                           $gp = $sales - $consumption_cost;
  322.  
  323.                          if($gp == 0)
  324.                             $gp_per = 0;
  325.                          else
  326.                              $gp_per = ($gp/$sales) * 100;
  327.  
  328.                           if ($gp_per < 0 || $gp_per == INF)
  329.                              $gp_per = 0;
  330.  
  331.                           if ($wastage == NULL)
  332.                              $wastage = 0;
  333.  
  334.                           if ($purchases == NULL)
  335.                              $purchases = 0;
  336.  
  337.                          if ($sales == NULL)
  338.                              $sales = 0;
  339.  
  340.                          $gp_per_displ_prev = number_format($gp_per,2);
  341.                         if ($gp_per_displ > $gp_per_displ_prev)
  342.                             echo "<td style='text-align:center'>".$gp_per_displ."% <i class='fa fa-arrow-up fa-md' style='color:green'></i></td>";
  343.                         else
  344.                             echo "<td style='text-align:center'>".$gp_per_displ."% <i class='fa fa-arrow-down fa-md' style='color:red'></i></td>";
  345.                          echo "<td style='text-align:center'>".$gp_per_displ_prev."%</td>";
  346.                         echo "</tr> ";
  347.                    
  348.                         $query1         =   "select id AS stocktake_id, stock_date_str as stock_date FROM view_stocktake_master WHERE store_id = '$store_id1' AND id < $stocktake_id ORDER BY stocktake_id DESC LIMIT 3";
  349.                         $retval         =   f_select_query($query1, $datarows1);
  350.                        
  351.                         $rowCountNew = count($datarows1);
  352.                        
  353.                         for ($counter1 = 0; $counter1< $rowCountNew; $counter1++)
  354.                         {
  355.                             $stocktake_id = $datarows1[$counter1]->stocktake_id;
  356.                             $stock_date = $datarows1[$counter1]->stock_date;
  357.                             //echo $stocktake_id . '<br/>';
  358.                             $query_total_cost = "select sum(`stocktake_details`.`quantity_units` * `stocktake_details`.`unit_cost`) AS `total_cost`
  359.                                  from `stocktake_details` INNER JOIN stocktake_locations on stocktake_details.location_id = stocktake_locations.id where `stocktake_details`.`stocktake_id` = '$stocktake_id'
  360.                                  AND stocktake_locations.stocktake_id = '$stocktake_id' and stocktake_locations.is_completed != 0 group by stocktake_locations.stocktake_id";
  361.                             $retval         =   f_read_column('total_cost', $query_total_cost, $closing_stock);
  362.  
  363.                             if ($closing_stock == "0.00")
  364.                             {
  365.                                 $query      =   "select id AS stocktake_id, stock_date_str as stock_date FROM view_stocktake_master WHERE store_id = '$store_id1' AND stock_date < DATE(NOW()) ORDER BY stocktake_id DESC LIMIT 1";
  366.                                 $retval         =   f_read_column('stocktake_id', $query, $stocktake_id);
  367.                                 $retval         =   f_read_column('stock_date', $query, $stock_date);
  368.  
  369.                                 $query_total_cost = "select sum(`stocktake_details`.`quantity_units` * `stocktake_details`.`unit_cost`) AS `total_cost`
  370.                                      from `stocktake_details` INNER JOIN stocktake_locations on stocktake_details.location_id = stocktake_locations.id where `stocktake_details`.`stocktake_id` = '$stocktake_id'
  371.                                      AND stocktake_locations.stocktake_id = '$stocktake_id' and stocktake_locations.is_completed != 0 group by stocktake_locations.stocktake_id";
  372.                                 $retval         =   f_read_column('total_cost', $query_total_cost, $closing_stock);
  373.  
  374.                                  $query_total_purchases = "select sum(`store_purchases`.`cost_value`) AS `total_purchases` from `store_purchases` where `store_purchases`.`stocktake_id` = '$stocktake_id' ;";
  375.                                  $retval        =   f_read_column('total_purchases', $query_total_purchases, $purchases);
  376.  
  377.                                  $query_total_wastage = "select sum(`store_wastage`.`wastage_amount`) AS `total_wastage` from `store_wastage` where `store_wastage`.`stocktake_id` = '$stocktake_id'; ";
  378.                                  $retval        =   f_read_column('total_wastage', $query_total_wastage, $wastage);
  379.  
  380.                                  $query_total_sales = "select sum(`store_sales`.`sale_at_cost`) AS `total_sales` from `store_sales` where `store_sales`.`stocktake_id` = '$stocktake_id'; ";
  381.                                  $retval        =   f_read_column('total_sales', $query_total_sales,$sales);
  382.  
  383.                                  $query_total_labour = "select sum(`labour_costs`.`cost`) AS `total_labour` from `labour_costs` where `labour_costs`.`stocktake_id` = '$stocktake_id'; ";
  384.                                  $retval        =   f_read_column('total_labour', $query_total_labour,$labour);
  385.  
  386.                                  $query             =   "select id from view_stocktake_master where store_id = $store_id1 AND id < '$stocktake_id' order by stock_date desc limit 1";
  387.                                  $retval        =   f_read_column('id', $query, $stocktake_id_prev);
  388.  
  389.                                  $query_total_opening = "select sum(`stocktake_details`.`quantity_units` * `stocktake_details`.`unit_cost`) AS `total_cost`
  390.                                                      from `stocktake_details` INNER JOIN stocktake_locations on stocktake_details.location_id = stocktake_locations.id where `stocktake_details`.`stocktake_id` = '$stocktake_id_prev'
  391.                                                      AND stocktake_locations.stocktake_id = '$stocktake_id_prev' and stocktake_locations.is_completed != 0 group by stocktake_locations.stocktake_id LIMIT 1";
  392.                                  $retval        =   f_read_column('total_cost', $query_total_opening, $opening_stock);
  393.                             }
  394.                             else {
  395.  
  396.                                  $query_total_purchases = "select sum(`store_purchases`.`cost_value`) AS `total_purchases` from `store_purchases` where `store_purchases`.`stocktake_id` = '$stocktake_id' ;";
  397.                                  $retval        =   f_read_column('total_purchases', $query_total_purchases, $purchases);
  398.  
  399.                                  $query_total_wastage = "select sum(`store_wastage`.`wastage_amount`) AS `total_wastage` from `store_wastage` where `store_wastage`.`stocktake_id` = '$stocktake_id'; ";
  400.                                  $retval        =   f_read_column('total_wastage', $query_total_wastage, $wastage);
  401.  
  402.                                  $query_total_sales = "select sum(`store_sales`.`sale_at_cost`) AS `total_sales` from `store_sales` where `store_sales`.`stocktake_id` = '$stocktake_id'; ";
  403.                                  $retval        =   f_read_column('total_sales', $query_total_sales,$sales);
  404.  
  405.                                  $query_total_labour = "select sum(`labour_costs`.`cost`) AS `total_labour` from `labour_costs` where `labour_costs`.`stocktake_id` = '$stocktake_id'; ";
  406.                                  $retval        =   f_read_column('total_labour', $query_total_labour,$labour);
  407.  
  408.                                  $query             =   "select id from view_stocktake_master where store_id = $store_id1 AND id < '$stocktake_id' order by stock_date desc limit 1";
  409.                                  $retval        =   f_read_column('id', $query, $stocktake_id_prev);
  410.  
  411.                                  $query_total_opening = "select sum(`stocktake_details`.`quantity_units` * `stocktake_details`.`unit_cost`) AS `total_cost`
  412.                                                      from `stocktake_details` INNER JOIN stocktake_locations on stocktake_details.location_id = stocktake_locations.id where `stocktake_details`.`stocktake_id` = '$stocktake_id_prev'
  413.                                                      AND stocktake_locations.stocktake_id = '$stocktake_id_prev' and stocktake_locations.is_completed != 0 group by stocktake_locations.stocktake_id LIMIT 1";
  414.                                  $retval        =   f_read_column('total_cost', $query_total_opening, $opening_stock);
  415.                             }
  416.  
  417.                              if ($sales == '')
  418.                                  $sales = 0;
  419.                              if ($purchases == '')
  420.                                  $purchases = 0;
  421.                              if ($wastage == '')
  422.                                  $wastage = 0;
  423.                              if ($labour == '')
  424.                                  $labour = 0;
  425.  
  426.                              if ($opening_stock == '')
  427.                              {
  428.                                  $opening_stock = 0;
  429.                              }
  430.  
  431.                             $query          =   "select include_labour FROM store_master where id = $store_id1 ;";
  432.                             $retval         =   f_read_column('include_labour', $query, $include_labour);
  433.  
  434.                             $query          =   "select include_wastage FROM store_master where id = $store_id1 ;";
  435.                             $retval         =   f_read_column('include_wastage', $query, $include_waste);
  436.  
  437.                             if ($include_waste == 1 && $include_labour == 0)
  438.                                 $consumption_cost = $opening_stock + $purchases + $wastage  - $closing_stock;
  439.                             else if ($include_waste == 0 && $include_labour == 1)
  440.                                 $consumption_cost = $opening_stock + $purchases  + $labour - $closing_stock;
  441.                             else if ($include_waste == 0 && $include_labour == 0)
  442.                                 $consumption_cost = $opening_stock + $purchases - $closing_stock;
  443.                             else
  444.                                 $consumption_cost = $opening_stock + $purchases + $wastage + $labour - $closing_stock;
  445.  
  446.                               $gp = $sales - $consumption_cost;
  447.  
  448.                              if($gp == 0)
  449.                                 $gp_per = 0;
  450.                              else
  451.                                  $gp_per = ($gp/$sales) * 100;
  452.  
  453.                               if ($gp_per < 0 || $gp_per == INF)
  454.                                  $gp_per = 0;
  455.  
  456.                               if ($wastage == NULL)
  457.                                  $wastage = 0;
  458.  
  459.                               if ($purchases == NULL)
  460.                                  $purchases = 0;
  461.  
  462.                              if ($sales == NULL)
  463.                                  $sales = 0;
  464.  
  465.                              $gp_per_displ = number_format($gp_per,2);
  466.                        
  467.                             echo "<tr style='display:none;'> ";
  468.                             echo "<td style='text-align:center'>$stock_date</td>";
  469.                             echo "<td style='text-align:center'>$store_name</td>";
  470.                             echo "<td style='text-align:center'>$store_city</td>";
  471.                             echo "<td style='text-align:center'>$global_currency_sign ".number_format($opening_stock,2)."</td>";
  472.                             echo "<td style='text-align:center'>$global_currency_sign ".number_format($wastage,2)."</td>";
  473.                             echo "<td style='text-align:center'>$global_currency_sign ".number_format($purchases,2)."</td>";
  474.                             echo "<td style='text-align:center'>$global_currency_sign ".number_format($sales,2)."</td>";
  475.                             echo "<td style='text-align:center'>$global_currency_sign ".number_format($closing_stock,2)."</td>";
  476.  
  477.                             $query_total_cost = "select sum(`stocktake_details`.`quantity_units` * `stocktake_details`.`unit_cost`) AS `total_cost`
  478.                                  from `stocktake_details` INNER JOIN stocktake_locations on stocktake_details.location_id = stocktake_locations.id where `stocktake_details`.`stocktake_id` = '$stocktake_id_prev'
  479.                                  AND stocktake_locations.stocktake_id = '$stocktake_id_prev' and stocktake_locations.is_completed != 0 group by stocktake_locations.stocktake_id";
  480.                                 $retval         =   f_read_column('total_cost', $query_total_cost, $closing_stock);
  481.  
  482.                                 $query_total_purchases = "select sum(`store_purchases`.`cost_value`) AS `total_purchases` from `store_purchases` where `store_purchases`.`stocktake_id` = '$stocktake_id_prev' ;";
  483.                                  $retval        =   f_read_column('total_purchases', $query_total_purchases, $purchases);
  484.  
  485.                                  $query_total_wastage = "select sum(`store_wastage`.`wastage_amount`) AS `total_wastage` from `store_wastage` where `store_wastage`.`stocktake_id` = '$stocktake_id_prev'; ";
  486.                                  $retval        =   f_read_column('total_wastage', $query_total_wastage, $wastage);
  487.  
  488.                                  $query_total_sales = "select sum(`store_sales`.`sale_at_cost`) AS `total_sales` from `store_sales` where `store_sales`.`stocktake_id` = '$stocktake_id_prev'; ";
  489.                                  $retval        =   f_read_column('total_sales', $query_total_sales,$sales);
  490.  
  491.                                  $query_total_labour = "select sum(`labour_costs`.`cost`) AS `total_labour` from `labour_costs` where `labour_costs`.`stocktake_id` = '$stocktake_id_prev'; ";
  492.                                  $retval        =   f_read_column('total_labour', $query_total_labour,$labour);
  493.  
  494.                                  $query             =   "select id from view_stocktake_master where store_id = $store_id1 AND id < '$stocktake_id_prev' order by stock_date desc limit 1";
  495.                                  $retval        =   f_read_column('id', $query, $stocktake_id_prev_prev);
  496.  
  497.                                  $query_total_opening = "select sum(`stocktake_details`.`quantity_units` * `stocktake_details`.`unit_cost`) AS `total_cost`
  498.                                                      from `stocktake_details` INNER JOIN stocktake_locations on stocktake_details.location_id = stocktake_locations.id where `stocktake_details`.`stocktake_id` = '$stocktake_id_prev_prev'
  499.                                                      AND stocktake_locations.stocktake_id = '$stocktake_id_prev_prev' and stocktake_locations.is_completed != 0 group by stocktake_locations.stocktake_id LIMIT 1";
  500.                                  $retval        =   f_read_column('total_cost', $query_total_opening, $opening_stock);
  501.                                   if ($sales == '')
  502.                                  $sales = 0;
  503.                              if ($purchases == '')
  504.                                  $purchases = 0;
  505.                              if ($wastage == '')
  506.                                  $wastage = 0;
  507.                              if ($labour == '')
  508.                                  $labour = 0;
  509.  
  510.                              if ($opening_stock == '')
  511.                              {
  512.                                  $opening_stock = 0;
  513.                              }
  514.  
  515.                             $query          =   "select include_labour FROM store_master where id = $store_id1 ;";
  516.                             $retval         =   f_read_column('include_labour', $query, $include_labour);
  517.  
  518.                             $query          =   "select include_wastage FROM store_master where id = $store_id1 ;";
  519.                             $retval         =   f_read_column('include_wastage', $query, $include_waste);
  520.  
  521.                             if ($include_waste == 1 && $include_labour == 0)
  522.                                 $consumption_cost = $opening_stock + $purchases + $wastage  - $closing_stock;
  523.                             else if ($include_waste == 0 && $include_labour == 1)
  524.                                 $consumption_cost = $opening_stock + $purchases  + $labour - $closing_stock;
  525.                             else if ($include_waste == 0 && $include_labour == 0)
  526.                                 $consumption_cost = $opening_stock + $purchases - $closing_stock;
  527.                             else
  528.                                 $consumption_cost = $opening_stock + $purchases + $wastage + $labour - $closing_stock;
  529.  
  530.                               $gp = $sales - $consumption_cost;
  531.  
  532.                              if($gp == 0)
  533.                                 $gp_per = 0;
  534.                              else
  535.                                  $gp_per = ($gp/$sales) * 100;
  536.  
  537.                               if ($gp_per < 0 || $gp_per == INF)
  538.                                  $gp_per = 0;
  539.  
  540.                               if ($wastage == NULL)
  541.                                  $wastage = 0;
  542.  
  543.                               if ($purchases == NULL)
  544.                                  $purchases = 0;
  545.  
  546.                              if ($sales == NULL)
  547.                                  $sales = 0;
  548.  
  549.                              $gp_per_displ_prev = number_format($gp_per,2);
  550.                             if ($gp_per_displ > $gp_per_displ_prev)
  551.                                 echo "<td style='text-align:center'>".$gp_per_displ."% <i class='fa fa-arrow-up fa-md' style='color:green'></i></td>";
  552.                             else
  553.                                 echo "<td style='text-align:center'>".$gp_per_displ."% <i class='fa fa-arrow-down fa-md' style='color:red'></i></td>";
  554.                              echo "<td style='text-align:center'>".$gp_per_displ_prev."%</td>";
  555.                             echo "</tr> ";
  556.                        
  557.                         }
  558.                     }
  559.                 ?>
  560.                 </tbody>
  561.  
  562.                 </table>
  563.             </div>
  564.  
  565. </div>
  566. <div class="col-sm-5 col-xs-12" id="currentDiv" style="display: none;">
  567.             <div class="homepage_blocks " id="current">
  568.                 <?php include_once('home_stocktake_locations_list_group.php'); ?>
  569.             </div>
  570.         </div>
  571. <div class="col-sm-5 col-xs-12" id="previousDiv" style="display: none;">
  572.             <div class="homepage_blocks" id="graph"> </div>
  573.             <div class="homepage_blocks" id="previous">
  574.             </div>
  575.         </div>
  576. </div>
  577. </div>
  578. <script type="text/javascript" >
  579. $(document).ready(function() {
  580. table = $('#tbl_leader_board').DataTable( {
  581.    stateSave: true,
  582.    "bFilter" : true,
  583.     "responsive" : true,
  584.     "aLengthMenu": [[ 50, 75, -1], [ 50, 75, "All"]],
  585.     "iDisplayLength": 50,
  586.     "order": [[ 8, "desc" ]]
  587. });
  588. $('#tbl_leader_board tbody').on('click', 'td.details-control', function () {
  589.         var tr = $(this).closest('tr');
  590.         tr.css('display','block');
  591. });
  592. });
  593. $(document.body).on('click', '.details', function(event)
  594.     {
  595.     //  $(this) = your current element that clicked.
  596.     // additional code
  597.     $("#tableDiv").hide();
  598.     $("#currentDiv").css('display','block');
  599.     $("#previousDiv").css('display','block');
  600.     var id = event.target.id;
  601.     //alert(id);
  602.     //alert($(this));
  603.         _formurl    =   "home_stocktake_locations_list_group.php";
  604.         _formdata   =   {'store_id' : id};
  605.         _formurl2   =   "home_stocktake_list.php";
  606.         _formurl3   =   "home_sales_graph.php";
  607.         $.ajax({
  608.  
  609.          type: "GET",
  610.           url: _formurl,
  611.           data: _formdata,
  612.          success: function(xhrResponse)
  613.          {
  614.             $('#current').html(xhrResponse);
  615.             var rowCount = $('#locations').length;
  616.             row_count = parseInt(rowCount) ;
  617.           },
  618.           error: function(XMLHttpRequest, textStatus, errorThrown)
  619.           {
  620.             $('#alert_msg').html(errorThrown);
  621.             $('#alert_msg').fadeIn( "slow");
  622.  
  623.           }
  624.     });
  625.     $.ajax({
  626.  
  627.          type: "GET",
  628.           url: _formurl3,
  629.           data: _formdata,
  630.          success: function(xhrResponse)
  631.          {
  632.             $('#graph').html(xhrResponse);
  633.             var rowCount = $('#sales_graph').length;
  634.             row_count = parseInt(rowCount) ;
  635.           },
  636.           error: function(XMLHttpRequest, textStatus, errorThrown)
  637.           {
  638.             $('#alert_msg').html(errorThrown);
  639.             $('#alert_msg').fadeIn( "slow");
  640.  
  641.           }
  642.     });
  643.     $.ajax({
  644.  
  645.          type: "GET",
  646.           url: _formurl2,
  647.           data: _formdata,
  648.          success: function(xhrResponse)
  649.          {
  650.             $('#previous').html(xhrResponse);
  651.             var rowCount = $('#dd_home_stocktake').length;
  652.             row_count = parseInt(rowCount) ;
  653.           },
  654.           error: function(XMLHttpRequest, textStatus, errorThrown)
  655.           {
  656.             $('#alert_msg').html(errorThrown);
  657.             $('#alert_msg').fadeIn( "slow");
  658.  
  659.           }
  660.     });
  661.  
  662. });
  663. $(document.body).on('click', '.visual', function(event)
  664.     {
  665.         $("#tableDiv").hide();
  666.     $("#currentDiv").css('display','block');
  667.     $("#previousDiv").css('display','block');
  668.     //  $(this) = your current element that clicked.
  669.     // additional code
  670.     var id = event.target.id;
  671.     //alert(id);
  672.     //alert($(this));
  673.             _formurl    =   "home_stocktake_locations_list_group.php";
  674.         _formdata   =   {'store_id' : id};
  675.         _formurl2   =   "home_stocktake_list.php";
  676.         _formurl3   =   "home_sales_graph.php";
  677.         $.ajax({
  678.  
  679.          type: "GET",
  680.           url: _formurl,
  681.           data: _formdata,
  682.          success: function(xhrResponse)
  683.          {
  684.             $('#current').html(xhrResponse);
  685.             var rowCount = $('#locations').length;
  686.             row_count = parseInt(rowCount) ;
  687.           },
  688.           error: function(XMLHttpRequest, textStatus, errorThrown)
  689.           {
  690.             $('#alert_msg').html(errorThrown);
  691.             $('#alert_msg').fadeIn( "slow");
  692.  
  693.           }
  694.     });
  695.     $.ajax({
  696.  
  697.          type: "GET",
  698.           url: _formurl3,
  699.           data: _formdata,
  700.          success: function(xhrResponse)
  701.          {
  702.             $('#graph').html(xhrResponse);
  703.             var rowCount = $('#sales_graph').length;
  704.             row_count = parseInt(rowCount) ;
  705.           },
  706.           error: function(XMLHttpRequest, textStatus, errorThrown)
  707.           {
  708.             $('#alert_msg').html(errorThrown);
  709.             $('#alert_msg').fadeIn( "slow");
  710.  
  711.           }
  712.     });
  713.     $.ajax({
  714.  
  715.          type: "GET",
  716.           url: _formurl2,
  717.           data: _formdata,
  718.          success: function(xhrResponse)
  719.          {
  720.             $('#previous').html(xhrResponse);
  721.             var rowCount = $('#dd_home_stocktake').length;
  722.             row_count = parseInt(rowCount) ;
  723.           },
  724.           error: function(XMLHttpRequest, textStatus, errorThrown)
  725.           {
  726.             $('#alert_msg').html(errorThrown);
  727.             $('#alert_msg').fadeIn( "slow");
  728.  
  729.           }
  730.     });
  731.  
  732. });
  733. $(document.body).on('click', '.desc', function(event)
  734.     {
  735.         $("#tableDiv").hide();
  736.     $("#currentDiv").css('display','block');
  737.     $("#previousDiv").css('display','block');
  738.     //  $(this) = your current element that clicked.
  739.     // additional code
  740.     var id = event.target.id;
  741.     //alert(id);
  742.     //alert($(this));
  743.             _formurl    =   "home_stocktake_locations_list_group.php";
  744.         _formdata   =   {'store_id' : id};
  745.         _formurl2   =   "home_stocktake_list.php";
  746.         _formurl3   =   "home_sales_graph.php";
  747.         $.ajax({
  748.  
  749.          type: "GET",
  750.           url: _formurl,
  751.           data: _formdata,
  752.          success: function(xhrResponse)
  753.          {
  754.             $('#current').html(xhrResponse);
  755.             var rowCount = $('#locations').length;
  756.             row_count = parseInt(rowCount) ;
  757.           },
  758.           error: function(XMLHttpRequest, textStatus, errorThrown)
  759.           {
  760.             $('#alert_msg').html(errorThrown);
  761.             $('#alert_msg').fadeIn( "slow");
  762.  
  763.           }
  764.     });
  765.     $.ajax({
  766.  
  767.          type: "GET",
  768.           url: _formurl3,
  769.           data: _formdata,
  770.          success: function(xhrResponse)
  771.          {
  772.             $('#graph').html(xhrResponse);
  773.             var rowCount = $('#sales_graph').length;
  774.             row_count = parseInt(rowCount) ;
  775.           },
  776.           error: function(XMLHttpRequest, textStatus, errorThrown)
  777.           {
  778.             $('#alert_msg').html(errorThrown);
  779.             $('#alert_msg').fadeIn( "slow");
  780.  
  781.           }
  782.     });
  783.     $.ajax({
  784.  
  785.          type: "GET",
  786.           url: _formurl2,
  787.           data: _formdata,
  788.          success: function(xhrResponse)
  789.          {
  790.             $('#previous').html(xhrResponse);
  791.             var rowCount = $('#dd_home_stocktake').length;
  792.             row_count = parseInt(rowCount) ;
  793.           },
  794.           error: function(XMLHttpRequest, textStatus, errorThrown)
  795.           {
  796.             $('#alert_msg').html(errorThrown);
  797.             $('#alert_msg').fadeIn( "slow");
  798.  
  799.           }
  800.     });
  801.  
  802. });
  803. $(document.body).on('click', '.more', function(event)
  804.     {
  805.         $("#tableDiv").hide();
  806.     $("#currentDiv").css('display','block');
  807.     $("#previousDiv").css('display','block');
  808.     //  $(this) = your current element that clicked.
  809.     // additional code
  810.     var id = event.target.id;
  811.     //alert(id);
  812.     //alert($(this));
  813.             _formurl    =   "home_stocktake_locations_list_group.php";
  814.             _formurl2   =   "home_stocktake_list.php";
  815.             _formurl3   =   "home_sales_graph.php";
  816.         _formdata   =   {'store_id' : id};
  817.         $.ajax({
  818.  
  819.          type: "GET",
  820.           url: _formurl,
  821.           data: _formdata,
  822.          success: function(xhrResponse)
  823.          {
  824.             $('#current').html(xhrResponse);
  825.             var rowCount = $('#locations').length;
  826.             row_count = parseInt(rowCount) ;
  827.           },
  828.           error: function(XMLHttpRequest, textStatus, errorThrown)
  829.           {
  830.             $('#alert_msg').html(errorThrown);
  831.             $('#alert_msg').fadeIn( "slow");
  832.  
  833.           }
  834.     });
  835.     $.ajax({
  836.  
  837.          type: "GET",
  838.           url: _formurl3,
  839.           data: _formdata,
  840.          success: function(xhrResponse)
  841.          {
  842.             $('#graph').html(xhrResponse);
  843.             var rowCount = $('#sales_graph').length;
  844.             row_count = parseInt(rowCount) ;
  845.           },
  846.           error: function(XMLHttpRequest, textStatus, errorThrown)
  847.           {
  848.             $('#alert_msg').html(errorThrown);
  849.             $('#alert_msg').fadeIn( "slow");
  850.  
  851.           }
  852.     });
  853.     $.ajax({
  854.  
  855.          type: "GET",
  856.           url: _formurl2,
  857.           data: _formdata,
  858.          success: function(xhrResponse)
  859.          {
  860.             $('#previous').html(xhrResponse);
  861.             var rowCount = $('#dd_home_stocktake').length;
  862.             row_count = parseInt(rowCount) ;
  863.           },
  864.           error: function(XMLHttpRequest, textStatus, errorThrown)
  865.           {
  866.             $('#alert_msg').html(errorThrown);
  867.             $('#alert_msg').fadeIn( "slow");
  868.  
  869.           }
  870.     });
  871.  
  872. });
  873.  
  874. $(document.body).on('click', '.desc', function(event)
  875.     {
  876.         $("#tableDiv").hide();
  877.     $("#currentDiv").css('display','block');
  878.     $("#previousDiv").css('display','block');
  879.     //  $(this) = your current element that clicked.
  880.     // additional code
  881.     var id = event.target.id;
  882.     //alert(id);
  883.     //alert($(this));
  884.             _formurl    =   "home_stocktake_locations_list_group.php";
  885.             _formurl2   =   "home_stocktake_list.php";
  886.             _formurl3   =   "home_sales_graph.php";
  887.         _formdata   =   {'store_id' : id};
  888.         $.ajax({
  889.  
  890.          type: "GET",
  891.           url: _formurl,
  892.           data: _formdata,
  893.          success: function(xhrResponse)
  894.          {
  895.             $('#current').html(xhrResponse);
  896.             var rowCount = $('#locations').length;
  897.             row_count = parseInt(rowCount) ;
  898.           },
  899.           error: function(XMLHttpRequest, textStatus, errorThrown)
  900.           {
  901.             $('#alert_msg').html(errorThrown);
  902.             $('#alert_msg').fadeIn( "slow");
  903.  
  904.           }
  905.     });
  906.     $.ajax({
  907.  
  908.          type: "GET",
  909.           url: _formurl3,
  910.           data: _formdata,
  911.          success: function(xhrResponse)
  912.          {
  913.             $('#graph').html(xhrResponse);
  914.             var rowCount = $('#sales_graph').length;
  915.             row_count = parseInt(rowCount) ;
  916.           },
  917.           error: function(XMLHttpRequest, textStatus, errorThrown)
  918.           {
  919.             $('#alert_msg').html(errorThrown);
  920.             $('#alert_msg').fadeIn( "slow");
  921.  
  922.           }
  923.     });
  924.     $.ajax({
  925.  
  926.          type: "GET",
  927.           url: _formurl2,
  928.           data: _formdata,
  929.          success: function(xhrResponse)
  930.          {
  931.             $('#previous').html(xhrResponse);
  932.             var rowCount = $('#dd_home_stocktake').length;
  933.             row_count = parseInt(rowCount) ;
  934.           },
  935.           error: function(XMLHttpRequest, textStatus, errorThrown)
  936.           {
  937.             $('#alert_msg').html(errorThrown);
  938.             $('#alert_msg').fadeIn( "slow");
  939.  
  940.           }
  941.     });
  942.  
  943. });
  944. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement