xah icon

Report.php

xah | PRO | 10/05/20 09:25:24 PM UTC | 0 ⭐ | 1450 👁️ | Never ⏰ | []
PHP |

6.27 KB

|

None

|

0 👍

/

0 👎

<?php
 
error_reporting(E_ALL);
ini_set('display_errors', '1');
 
require_once( dirname(__FILE__) . DIRECTORY_SEPARATOR . '/../blocks/functions.php');
 
if (! file_exists('blocks/header.php') ){
  include( dirname(__FILE__) . DIRECTORY_SEPARATOR . '/../blocks/header.php');}
 
function return_type(){ // Creates a fancy looking form.
    $return_form = array(  'return_detail' => 'Detailed',
                          'return_summary'  => 'Summary',
                          'return_condition' => 'Condition' );
 
    create_dropdown_query($return_form, 'return_type', 'decommissioning/return.php');}
 
    $customer_query = new Query(array('Name'), 'Customer', array('Owner' =>  intval($_SESSION['company_id'])), 'ORDER BY Name');
    $customer_arr = array_map('end', $customer_query->array);
    $customer_arr[0] = 'All';
 
 
if( isset($_POST['return_type']) ){
  echo "<section id='three' class='wrapper'><div class='inner'>";
 
  if( $_POST['return_type'] == 'return_detail' ){
 
    $status_arr = array('Any', 'Unreceived', 'Auditing', 'Completed');
 
    $arr_func = array(array('create_date_picker', 'table'),
                      array('create_dropdown', $customer_arr, 'customer', 'Customer', 'table'),
                      array('create_dropdown', $status_arr, 'status', 'Status', 'table'),
                      array('create_text_input', 'Job #', 'job_no', 'table')
                      );
 
    create_table_form( $arr_func, '', 'small_form', 'return_detail_options' );
 
  }
  if( $_POST['return_type'] == 'return_summary' ){
    $arr_func = array(array('create_date_picker', 'table'),
                      array('create_dropdown', $customer_arr, 'customer', 'Customer', 'table'));
 
    create_table_form( $arr_func, '', 'small_form', 'return_summary_options' );
  }
  if( $_POST['return_type'] == 'return_condition' ){
    $arr_func = array(array('create_date_picker', 'table'),
                      array('create_dropdown', $customer_arr, 'customer', 'Customer', 'table'));
 
    create_table_form( $arr_func, '', 'small_form', 'return_condition_options');
  }
 
  echo "</div></section>";
 
}else{
  echo "<section id='three' class='wrapper'><div class='inner'>";
 
  if( isset($_POST['return_detail_options']) || isset($_POST['return_summary_options']) || isset($_POST['return_condition_options'])){
    $or = '';
 
    if(isset($_POST['start_date']) || isset($_POST['end_date']) || isset($_POST['customer']) || isset($_POST['job_no'])){
      $gen_or = 'Job.Owner = ' . intval($_SESSION['company_id']) .
            ' AND Job.JobType = \'I\'';
 
      if($_POST['customer'] != '0'){
        $or .= ' AND Customer.Name = \'' . $customer_arr[$_POST['customer']] . '\'';}
      if($_POST['start_date'] != ''){
      $or .= ' AND Job.DateCompleted >= \'' . $_POST['start_date'] . '\'';}
      if($_POST['end_date'] != ''){
      $or .= ' AND Job.DateCompleted <= \'' . $_POST['end_date'] . '\'';}
      if(isset($_POST['job_no'])){
        if($_POST['job_no'] != ''){
          $or .= ' AND Job.Number = ' . $_POST['job_no'];}}
      if(isset($_POST['status'])){
        $gen_or .= ' AND StockItem.Owner = '. intval($_SESSION['company_id']);
        $cust_or = '';
        $status_or = '';
 
        if($_POST['customer'] != '0'){
          $cust_or = ' AND Customer.Name = \'' .  $customer_arr[$_POST['customer']] . '\'';
        }
 
        if($_POST['status'] == '1'){
          $status_or = ' AND Job.DateReceived IS NULL';}
        elseif($_POST['status'] == '2' || $_POST['status'] == '0'){
          $status_or = ' AND Job.DateCompleted IS NULL';
        }
 
        if($_POST['status'] == '0'){
          $or .= ' OR ' . $gen_or . $cust_or . $status_or;}
        elseif( $_POST['status'] == '3' && $status_or == '' ){
          // notjing;
        }
        elseif( $_POST['status'] == '1' ){
          $return_cols = array('DateReceived', 'DateCompleted', 'Number', 'Customer', 'CustomerReference',
                        'OwnerReference', 'FreightCost', 'Job.Status');
          $or = ' AND DateReceived IS NULL';
        }
        else{
          $or = $cust_or . $status_or;
        }
        }}
 
        $return_sels = array('Job.Owner' => intval($_SESSION['company_id']),
                      'Job.JobType' => '\'I\'');
 
        // print_r($return_query->query);
 
        if(isset($_POST['return_detail_options'])){
          if(! isset($return_cols)){
            $return_sels['StockItem.Owner'] = intval($_SESSION['company_id']);
            $return_cols = array('DateReceived', 'DateCompleted', 'Job', 'Customer', 'TotalUnits', 'CustomerReference',
                        'OwnerReference', 'FreightCharge', 'Job.Status', 'Product');
            $return_query = new Query($return_cols, 'StockItem', $return_sels, $or);}
          else{
            $return_query = new Query($return_cols, 'Job', $return_sels, $or);
            $unreceived_status = '';
          }
 
          $all_stock_arr = $return_query->array;
          create_title('Customer Returns', 'Number of Jobs : ' . $return_query->row_count);
 
          if(! isset($unreceived_status) ){
              $return_headers = array('Job', 'DateReceived', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'FreightCharge', 'DateCompleted', 'Product');
              $return_array = subset_array('Job', $return_headers, $all_stock_arr, 'Product');
              create_general_table($return_headers, $return_array);}
          else{
              $return_headers = array('Number', 'DateReceived', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'FreightCost', 'DateCompleted');
              create_general_table($return_headers, $all_stock_arr);
              }}
        if(isset($_POST['return_summary_options'])){
          $return_cols = array('Number', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'DateReceived', 'DateCompleted');
 
          $return_headers = array('Number', 'Customer', 'CurstomerReference', 'OwnerReference', 'TotalUnits', 'DateReceived', 'DateCompleted');
          $return_query = new Query($return_cols, 'Job', $return_sels, $or . ' OR ' . $gen_or . ' AND DateCompleted IS NULL');
          $job_arr = $return_query->array;
          create_general_table($return_headers, $job_arr);
        }
 
  }
  echo "</div></section>";
}
 

Comments