<?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');
}
}else{
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'] != ''){ ///// PROBLEM HERE! Now all have a start date
$or .= ' AND Job.DateCompleted >= \'' . $_POST['start_date'] . '\'';}
if($_POST['end_date'] != ''){ ///// PROBLEM HERE! Now all have an 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'];}} ///// PROBLEM! The $or .= should be separated...
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'){ // Anything
$job_or = ' AND DateReceived IS NULL';
$or .= ' OR ' . $gen_or . $cust_or . $status_or;} //// MAJOR PROBLEM! $or should be split up coz it just ain't working
elseif( $_POST['status'] == '3' && $status_or == '' ){ // Auditing
// do nothing;
}
elseif( $_POST['status'] == '1' ){// Unreceived status
// $return_cols = array('DateReceived', 'DateCompleted', 'Number', 'Customer', 'CustomerReference',
// 'OwnerReference', 'TotalUnits', 'FreightCost', 'Job.Status');
$job_or = ' AND DateReceived IS NULL';
$unreceived_report = 'TRUE';
}
else{
$or = $cust_or . $status_or;
}
}}
$return_sels = array('Job.Owner' => intval($_SESSION['company_id']),
'Job.JobType' => '\'I\'');
$unreceived_job_cols = array('DateReceived', 'DateCompleted', 'Number', 'Customer', 'CustomerReference',
'OwnerReference', 'TotalUnits', 'FreightCost', 'Job.Status');
if(isset($_POST['return_detail_options'])){
if(isset($job_or)){
$unreceived_job_query = new Query($unreceived_job_cols, 'Job', $return_sels, $job_or);
$unreceived_job_array = $unreceived_job_query->array;}
if(! isset($unreceived_report) ){
$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);
$all_stock_arr = $return_query->array;
print_r($return_query->query);
$row_count = $return_query->row_count;
$return_headers = array('Job', 'DateReceived', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'FreightCharge', 'DateCompleted', 'Product');
$return_array = subset_array('Job', $return_headers, $all_stock_arr, 'Product');
if(isset($unreceived_job_array)){
$full_array = array_merge($unreceived_job_array, $return_array);}
else{
$full_array = $return_array;
}
create_title('Customer Returns', 'Number of Items : ' . $row_count);
create_general_table($return_headers, $full_array);
}
else{
$return_headers = array('Number', 'DateReceived', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'FreightCost', 'DateCompleted');
$row_count = $unreceived_job_query->row_count;
create_title('Customer Returns', 'Number of Jobs : ' . $row_count);
create_general_table($return_headers, $unreceived_job_array);
}
}
if(isset($_POST['return_summary_options'])){
$return_cols = array('Number', 'Customer', 'CustomerReference', 'OwnerReference', 'TotalUnits', 'DateReceived', 'DateCompleted');
$return_headers = array('Number', 'Customer', 'CustomerReference', '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