Advertisement
xah

Report vRubbish 0.0.1

xah
Oct 5th, 2020 (edited)
1,515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.83 KB | None | 0 0
  1. <?php
  2.  
  3.  error_reporting(E_ALL);
  4.  ini_set('display_errors', '1');
  5.  
  6. require_once( dirname(__FILE__) . DIRECTORY_SEPARATOR . '/../blocks/functions.php');
  7.  
  8. if (! file_exists('blocks/header.php') ){
  9.   include( dirname(__FILE__) . DIRECTORY_SEPARATOR . '/../blocks/header.php');}
  10.  
  11. function return_type(){ // Creates a fancy looking form.
  12.     $return_form = array(  'return_detail' => 'Detailed',
  13.                           'return_summary'  => 'Summary',
  14.                           'return_condition' => 'Condition' );
  15.  
  16.     create_dropdown_query($return_form, 'return_type', 'decommissioning/return.php');}
  17.  
  18.     $customer_query = new Query(array('Name'), 'Customer', array('Owner' =>  intval($_SESSION['company_id'])), 'ORDER BY Name');
  19.     $customer_arr = array_map('end', $customer_query->array);
  20.     $customer_arr[0] = 'All';
  21.  
  22. if( isset($_POST['return_type']) ){
  23.   echo "<section id='three' class='wrapper'><div class='inner'>";
  24.  
  25.   if( $_POST['return_type'] == 'return_detail' ){
  26.  
  27.     $status_arr = array('Any', 'Unreceived', 'Auditing', 'Completed');
  28.  
  29.     $arr_func = array(array('create_date_picker', 'table'),
  30.                       array('create_dropdown', $customer_arr, 'customer', 'Customer', 'table'),
  31.                       array('create_dropdown', $status_arr, 'status', 'Status', 'table'),
  32.                       array('create_text_input', 'Job #', 'job_no', 'table')
  33.                       );
  34.  
  35.     create_table_form( $arr_func, '', 'small_form', 'return_detail_options' );
  36.  
  37.   }
  38.  
  39.   if( $_POST['return_type'] == 'return_summary' ){
  40.     $arr_func = array(array('create_date_picker', 'table'),
  41.                       array('create_dropdown', $customer_arr, 'customer', 'Customer', 'table'));
  42.  
  43.     create_table_form( $arr_func, '', 'small_form', 'return_summary_options' );
  44.   }
  45.   if( $_POST['return_type'] == 'return_condition' ){
  46.     $arr_func = array(array('create_date_picker', 'table'),
  47.                       array('create_dropdown', $customer_arr, 'customer', 'Customer', 'table'));
  48.  
  49.     create_table_form( $arr_func, '', 'small_form', 'return_condition_options');
  50.   }
  51. }
  52. else{
  53.   if( isset($_POST['return_detail_options']) || isset($_POST['return_summary_options']) || isset($_POST['return_condition_options'])){
  54.     echo "<section id='three' class='wrapper'><div class='inner'>";
  55.  
  56.     if(isset($_POST['start_date']) || isset($_POST['end_date']) || isset($_POST['customer']) || isset($_POST['job_no'])){
  57.       $main = 'Job.Owner = ' . intval($_SESSION['company_id']) .
  58.             ' AND Job.JobType = \'I\'';
  59.  
  60.       $return_sels = array('Job.Owner' => intval($_SESSION['company_id']),
  61.                             'Job.JobType' => '\'I\'');
  62.  
  63.       $customer = '';
  64.       $start_date = '';
  65.       $end_date = '';
  66.       $job_no = '';
  67.  
  68.       if($_POST['customer'] != '0'){
  69.         $customer = ' AND Customer.Name = \'' . $customer_arr[$_POST['customer']] . '\'';
  70.         $return_sels['Customer.Name'] = '\'' . $customer_arr[$_POST['customer']] . '\'';}
  71.  
  72.       if(! isset($_POST['status']) || isset($_POST['status']) && $_POST['status'] != '1'){
  73.         $start_date = ' AND Job.DateCompleted >= \'' . $_POST['start_date'] . '\'';
  74.         $end_date = ' AND Job.DateCompleted <= \'' . $_POST['end_date'] . '\'';
  75.         $return_sels['Job.DateCompleted'] = array($_POST['start_date'],  $_POST['end_date']);}
  76.  
  77.       if(isset($_POST['job_no'])){
  78.         if($_POST['job_no'] != ''){
  79.           $job_no = ' AND Job.Number = ' . $_POST['job_no'];
  80.           $return_sels['Job.Number'] = $_POST['job_no'];
  81.         }}
  82.  
  83.       $stock_item = ' AND StockItem.Owner = '. intval($_SESSION['company_id']);
  84.  
  85.       if(isset($_POST['return_detail_options'])){
  86.         if($_POST['status'] == '1'){ // Unreceived status
  87.  
  88.           $status = ' AND Job.DateReceived IS NULL';
  89.           // $final_str = ' OR ' . $main . $customer . $job_no . $status;
  90.           $final_str = $status;
  91.  
  92.           $unreceived_report = 'TRUE';
  93.         }
  94.         elseif($_POST['status'] == '2'){ // Auditing
  95.           $status = ' AND Job.DateCompleted IS NULL AND Job.DateReceived IS NOT NULL';
  96.           $final_str = ' OR ' . $main . $customer . $job_no . $status;
  97.  
  98.         }
  99.         elseif($_POST['status'] == '0'){ // All
  100.           $status = array(' AND Job.DateCompleted IS NULL', ' AND Job.DateReceived IS NULL');
  101.           $final_str = ' OR ' . $main . $customer . $job_no . $status[0] . ' OR ' . $main . $customer . $job_no . $status[1];
  102.           $unreceived_report = 'TRUE';
  103.         }
  104.         else{
  105.           $final_str = '';
  106.         }
  107.  
  108.         if(isset($unreceived_report)){
  109.           $unreceived_job_cols = array('Number', 'DateReceived', 'Customer', 'CustomerReference',
  110.                                'OwnerReference', 'TotalUnits', 'DateCompleted', 'FreightCost');
  111.           $unreceived_job_query = new Query($unreceived_job_cols, 'Job', $return_sels, $final_str);
  112.           $unreceived_job_array = $unreceived_job_query->array;
  113.         }
  114.  
  115.         if($_POST['status'] != '1'){
  116.           $return_sels['StockItem.Owner'] = intval($_SESSION['company_id']);
  117.  
  118.           $return_cols = array('DateReceived', 'DateCompleted', 'Job', 'Customer', 'TotalUnits', 'CustomerReference',
  119.                          'OwnerReference', 'FreightCharge', 'Job.Status', 'Product');
  120.  
  121.           $return_query = new Query($return_cols, 'StockItem', $return_sels, $final_str);
  122.  
  123.           $all_stock_arr = $return_query->array;
  124.           $row_count = $return_query->row_count;
  125.  
  126.           $return_headers = array('Job', 'DateReceived', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'FreightCharge', 'DateCompleted', 'Product');
  127.           $return_array = subset_array('Job', $return_headers, $all_stock_arr, 'Product');
  128.  
  129.           if(isset($unreceived_job_array)){
  130.             $full_array = array_merge($unreceived_job_array, $return_array);}
  131.           else{
  132.             $full_array = $return_array;}
  133.  
  134.             create_title('Customer Returns', 'Number of Items : ' . $row_count);
  135.             create_general_table($return_headers, $full_array);}
  136.         else{
  137.           create_title('Customer Returns', 'Number of Jobs : ' . $unreceived_job_query->row_count);
  138.           create_general_table($unreceived_job_cols, $unreceived_job_array);
  139.         }
  140.       }
  141.       elseif(isset($_POST['return_summary_options'])){
  142.         $return_headers = array('Number', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'DateReceived', 'DateCompleted');
  143.  
  144.         $status = array(' AND Job.DateCompleted IS NULL', ' AND Job.DateReceived IS NULL');
  145.         $return_sum_final_str = ' OR ' . $main . $customer . $job_no . $status[0] . ' OR ' . $main . $customer . $job_no . $status[1];
  146.         $return_sum_query = new Query($return_headers, 'Job', $return_sels, $return_sum_final_str);
  147.         $return_sum_arr = $return_sum_query->array;
  148.  
  149.         create_title('Customer Returns', 'Number of Jobs : ' . $return_sum_query->row_count);
  150.         create_general_table($return_headers, $return_sum_arr);
  151.       }
  152.       elseif(isset($_POST['return_condition_options'])){
  153.         $start_date = ' AND Job.DateCompleted >= \'' . $_POST['start_date'] . '\'';
  154.         $end_date = ' AND Job.DateCompleted <= \'' . $_POST['end_date'] . '\'';
  155.         $return_sels['Job.DateCompleted'] = array($_POST['start_date'],  $_POST['end_date']);
  156.  
  157.         $return_sels['StockItem.Owner'] = intval($_SESSION['company_id']);
  158.  
  159.         $return_condition_cols = array('Product', 'Customer', 'Condition', 'Job', 'ItemCode');
  160.  
  161.         $return_condition_query = new Query($return_condition_cols, 'StockItem', $return_sels);
  162.  
  163.         $all_stock_arr = $return_condition_query->array;
  164.         $row_count = $return_condition_query->row_count;
  165.  
  166.         create_title('Customer Returns', 'Item Count : ' . $row_count);
  167.         create_contingency_table('Condition', 'Product', $all_stock_arr);
  168.  
  169.       }
  170.     }
  171.   }
  172.   echo "</div></section>";
  173. }
  174.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement