Advertisement
xah

Report.php

xah
Oct 5th, 2020
1,200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.27 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.  
  23. if( isset($_POST['return_type']) ){
  24.   echo "<section id='three' class='wrapper'><div class='inner'>";
  25.  
  26.   if( $_POST['return_type'] == 'return_detail' ){
  27.  
  28.     $status_arr = array('Any', 'Unreceived', 'Auditing', 'Completed');
  29.  
  30.     $arr_func = array(array('create_date_picker', 'table'),
  31.                       array('create_dropdown', $customer_arr, 'customer', 'Customer', 'table'),
  32.                       array('create_dropdown', $status_arr, 'status', 'Status', 'table'),
  33.                       array('create_text_input', 'Job #', 'job_no', 'table')
  34.                       );
  35.  
  36.     create_table_form( $arr_func, '', 'small_form', 'return_detail_options' );
  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.   echo "</div></section>";
  53.  
  54. }else{
  55.   echo "<section id='three' class='wrapper'><div class='inner'>";
  56.  
  57.   if( isset($_POST['return_detail_options']) || isset($_POST['return_summary_options']) || isset($_POST['return_condition_options'])){
  58.     $or = '';
  59.  
  60.     if(isset($_POST['start_date']) || isset($_POST['end_date']) || isset($_POST['customer']) || isset($_POST['job_no'])){
  61.       $gen_or = 'Job.Owner = ' . intval($_SESSION['company_id']) .
  62.             ' AND Job.JobType = \'I\'';
  63.  
  64.       if($_POST['customer'] != '0'){
  65.         $or .= ' AND Customer.Name = \'' . $customer_arr[$_POST['customer']] . '\'';}
  66.       if($_POST['start_date'] != ''){
  67.       $or .= ' AND Job.DateCompleted >= \'' . $_POST['start_date'] . '\'';}
  68.       if($_POST['end_date'] != ''){
  69.       $or .= ' AND Job.DateCompleted <= \'' . $_POST['end_date'] . '\'';}
  70.       if(isset($_POST['job_no'])){
  71.         if($_POST['job_no'] != ''){
  72.           $or .= ' AND Job.Number = ' . $_POST['job_no'];}}
  73.       if(isset($_POST['status'])){
  74.         $gen_or .= ' AND StockItem.Owner = '. intval($_SESSION['company_id']);
  75.         $cust_or = '';
  76.         $status_or = '';
  77.  
  78.         if($_POST['customer'] != '0'){
  79.           $cust_or = ' AND Customer.Name = \'' .  $customer_arr[$_POST['customer']] . '\'';
  80.         }
  81.  
  82.         if($_POST['status'] == '1'){
  83.           $status_or = ' AND Job.DateReceived IS NULL';}
  84.         elseif($_POST['status'] == '2' || $_POST['status'] == '0'){
  85.           $status_or = ' AND Job.DateCompleted IS NULL';
  86.         }
  87.  
  88.         if($_POST['status'] == '0'){
  89.           $or .= ' OR ' . $gen_or . $cust_or . $status_or;}
  90.         elseif( $_POST['status'] == '3' && $status_or == '' ){
  91.           // notjing;
  92.         }
  93.         elseif( $_POST['status'] == '1' ){
  94.           $return_cols = array('DateReceived', 'DateCompleted', 'Number', 'Customer', 'CustomerReference',
  95.                         'OwnerReference', 'FreightCost', 'Job.Status');
  96.           $or = ' AND DateReceived IS NULL';
  97.         }
  98.         else{
  99.           $or = $cust_or . $status_or;
  100.         }
  101.         }}
  102.  
  103.         $return_sels = array('Job.Owner' => intval($_SESSION['company_id']),
  104.                       'Job.JobType' => '\'I\'');
  105.  
  106.         // print_r($return_query->query);
  107.  
  108.         if(isset($_POST['return_detail_options'])){
  109.           if(! isset($return_cols)){
  110.             $return_sels['StockItem.Owner'] = intval($_SESSION['company_id']);
  111.             $return_cols = array('DateReceived', 'DateCompleted', 'Job', 'Customer', 'TotalUnits', 'CustomerReference',
  112.                         'OwnerReference', 'FreightCharge', 'Job.Status', 'Product');
  113.             $return_query = new Query($return_cols, 'StockItem', $return_sels, $or);}
  114.           else{
  115.             $return_query = new Query($return_cols, 'Job', $return_sels, $or);
  116.             $unreceived_status = '';
  117.           }
  118.  
  119.           $all_stock_arr = $return_query->array;
  120.           create_title('Customer Returns', 'Number of Jobs : ' . $return_query->row_count);
  121.  
  122.           if(! isset($unreceived_status) ){
  123.               $return_headers = array('Job', 'DateReceived', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'FreightCharge', 'DateCompleted', 'Product');
  124.               $return_array = subset_array('Job', $return_headers, $all_stock_arr, 'Product');
  125.               create_general_table($return_headers, $return_array);}
  126.           else{
  127.               $return_headers = array('Number', 'DateReceived', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'FreightCost', 'DateCompleted');
  128.               create_general_table($return_headers, $all_stock_arr);
  129.               }}
  130.         if(isset($_POST['return_summary_options'])){
  131.           $return_cols = array('Number', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'DateReceived', 'DateCompleted');
  132.  
  133.           $return_headers = array('Number', 'Customer', 'CurstomerReference', 'OwnerReference', 'TotalUnits', 'DateReceived', 'DateCompleted');
  134.           $return_query = new Query($return_cols, 'Job', $return_sels, $or . ' OR ' . $gen_or . ' AND DateCompleted IS NULL');
  135.           $job_arr = $return_query->array;
  136.           create_general_table($return_headers, $job_arr);
  137.         }
  138.  
  139.   }
  140.   echo "</div></section>";
  141. }
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement