예제 #1
0
        case 'edit':
            // Make sure productid set to edit
            if (isset($aid_command)) {
                // Get aidid to edit
                $aidid = $aid_command;
                // Check if updating financial aid
                if (isset($_POST) && isset($_POST['name'])) {
                    $new_name = $_POST['name'];
                    $usda_qualifier = $_POST['usda_qualifier'];
                    edit_aid($aidid, $new_name, $usda_qualifier);
                    //echo "Update food source to '".$new_name."'";
                    redirect($g["abs_url"] . '/aid/list/');
                }
                // Show the updated food source
                render_edit_aid($aidid);
            } else {
                redirect($g["abs_url"] . '/error/invalid-page');
            }
            break;
        case 'delete':
            if (isset($aid_command)) {
                delete_aid($aid_command);
                redirect($g["abs_url"] . '/aid/list/');
            }
            break;
        default:
            $client_framework_render['message'] = 'An error occurred.';
            render_all_foodsources(get_all_food_sources());
    }
    return;
}
예제 #2
0
 case 'new':
     render_new_bag();
     break;
 case 'save':
     $bagid = create_bag(post('name'), post('bag'));
     redirect($g["abs_url"] . '/bag/edit/' . $bagid);
     break;
 case 'edit':
     // Make sure bagid set to edit
     if (isset($bag_command)) {
         // Get bagid to edit
         $bagid = $bag_command;
         // Check if updating product
         if (isset($_POST) && isset($_POST['bag_name'])) {
             edit_bag($bag_command, post('bag_name'));
             $food_sources = get_all_food_sources();
             foreach ($food_sources as $food_source) {
                 $field = clean_url($food_source['name']);
                 $weight = post('foodsource-' . $field . '-weight');
                 $price = post('foodsource-' . $field . '-price');
                 edit_bag_food_source($bag_command, $food_source['sourceid'], $weight, $price);
             }
             //echo "Renamed bag to '".post('name')."'";
         }
         // Show the updated bag
         render_edit_bag($bag_command);
     } else {
         redirect($g["abs_url"] . '/error/invalid-page');
     }
     break;
 case 'delete':
예제 #3
0
function render_food_source_report()
{
    global $reporting_framework_render;
    global $parameters;
    foreach ($parameters as $parameter) {
        global ${$parameter};
    }
    $content = "";
    // Get transactions of last month
    $start_date = date('Y-m-d', mktime(0, 0, 0, date('m') - 1, date('d'), date('Y')));
    $end_date = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')));
    $report = array();
    $food_sources = get_all_food_sources();
    // List of products and quantity needed for the month
    $bags = get_all_bags();
    $total_weight = '0';
    $total_weight_last_month = '0';
    foreach ($bags as $bag) {
        $num_clients = count(get_bag_clients($bag['bagid']));
        $num_clients_last_month = count(get_bag_transactions($bag['bagid'], $start_date, $end_date));
        $bag_sources = get_all_bag_food_sources($bag['bagid']);
        foreach ($bag_sources as $bag_source) {
            if (!isset($report[$bag_source['name']])) {
                $report[$bag_source['name']] = array('weight' => $bag_source['weight'] * $num_clients, 'percent' => '0', 'weight_last_month' => $bag_source['weight'] * $num_clients_last_month, 'percent_last_month' => '0');
            } else {
                $report[$bag_source['name']]['weight'] += $bag_source['weight'] * $num_clients;
                $report[$bag_source['name']]['weight_last_month'] += $bag_source['weight'] * $num_clients_last_month;
            }
            $total_weight += $bag_source['weight'] * $num_clients;
            $total_weight_last_month += $bag_source['weight'] * $num_clients_last_month;
        }
    }
    // Add Total Row
    $report['Total'] = array('weight' => $total_weight, 'percent' => '0', 'weight_last_month' => $total_weight_last_month, 'percent_last_month' => '0');
    // Calculate percentages
    foreach ($report as $fsname => $fs) {
        $report[$fsname]['percent'] = number_format($fs['weight'] / $total_weight * 100, 1);
        if ($total_weight_last_month != 0) {
            $report[$fsname]['percent_last_month'] = number_format($fs['weight_last_month'] / $total_weight_last_month * 100, 1);
        }
    }
    $reporting_list = new Template();
    $reporting_list->load('report_foodsource_list');
    $reporting_list_render['food_sources'] = '';
    $report_row = new Template();
    $report_row->load('report_foodsource_row');
    $report_row_render['name'] = '';
    $report_row_render['weight'] = '';
    $report_row_render['percent'] = '';
    $report_row_render['weight_last_month'] = '';
    $report_row_render['percent_last_month'] = '';
    if ($report != null) {
        foreach ($report as $name => $report_fs) {
            $report_row_render['name'] = $name;
            $report_row_render['weight'] = $report_fs['weight'];
            $report_row_render['percent'] = $report_fs['percent'];
            $report_row_render['weight_last_month'] = $report_fs['weight_last_month'];
            $report_row_render['percent_last_month'] = $report_fs['percent_last_month'];
            $report_row->set_vars($report_row_render);
            $report_row->parse();
            $content .= $report_row->final;
        }
    }
    $reporting_list_render['food_sources'] = $content;
    $reporting_list->set_vars($reporting_list_render);
    $reporting_list->parse();
    $reporting_framework_render['content'] = $reporting_list->final;
    render_all();
}