function render_all_bags($bags) { global $bag_framework_render; global $parameters; foreach ($parameters as $parameter) { global ${$parameter}; } if ($bags == null) { $bag_framework_render['message'] = 'There are no bags to display.'; render_all(); return; } $content = ""; $bag_list = new Template(); $bag_list->load('bag_list'); $bag_list_render['bags'] = ''; $bag_row = new Template(); $bag_row->load('bag_row'); $bag_row_render['id'] = ''; $bag_row_render['name'] = ''; $bag_row_render['class'] = ''; foreach ($bags as $bag) { $bag_row_render['id'] = $bag['bagid']; $bag_row_render['name'] = $bag['name']; $total_weight = "0"; $total_cost = "0"; $food_sources = get_all_bag_food_sources($bag['bagid']); foreach ($food_sources as $food_source) { $total_weight += $food_source['weight']; $total_cost += $food_source['price']; } $bag_row_render['total_weight'] = $total_weight; $bag_row_render['total_cost'] = $total_cost; $bag_contents = get_bag_contents($bag['bagid']); $bag_row_render['num_products'] = '0'; foreach ($bag_contents as $product) { $bag_row_render['num_products'] += $product['quantity']; } //$bag_row_render['num_products'] = count($bag_contents); $bag_clients = get_bag_clients($bag['bagid']); $bag_row_render['num_clients'] = count($bag_clients); $bag_row->set_vars($bag_row_render); $bag_row->parse(); $content .= $bag_row->final; } $bag_list_render['bags'] = $content; $bag_list->set_vars($bag_list_render); $bag_list->parse(); $bag_framework_render['content'] = $bag_list->final; render_all(); }
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(); }