function render_edit($clientid) { global $client_framework_render; global $parameters; foreach ($parameters as $parameter) { global ${$parameter}; } $family = get_family_by_id($clientid); $content = ''; $bag_list = ''; $bags = get_all_bags(); foreach ($bags as $bag) { $bag_list .= "<option value='" . $bag['bagid'] . "'" . ($bag['bagid'] == $family['bagid'] ? ' selected' : '') . ">" . $bag['name'] . "</option>"; } $toggle = true; $rows = ''; $client_edit_aid = new Template(); $client_edit_aid->load('client_edit_aid'); $aids = get_all_financial_aids_client($clientid); foreach ($aids as $aid) { $client_edit_aid_render['row'] = $toggle ? '1' : '2'; $client_edit_aid_render['name'] = $aid['name']; $client_edit_aid_render['field'] = clean_url($aid['name']); $client_edit_aid_render['checked'] = $aid['clientid'] > 0 ? ' checked="true"' : ''; $client_edit_aid_render['amount'] = $aid['amount']; $client_edit_aid->set_vars($client_edit_aid_render); $client_edit_aid->parse(); $rows .= $client_edit_aid->final; $toggle = !$toggle; } $client_edit = new Template(); $client_edit->load('client_edit'); $client_edit_render['id'] = $family['clientid']; $client_edit_render['bags'] = $bag_list; $client_edit_render['active'] = $family['active'] == '1' ? 'checked' : ''; $client_edit_render['first_name'] = $family['first_name']; $client_edit_render['last_name'] = $family['last_name']; $client_edit_render['male'] = $family['gender'] == '1' ? ' selected' : ''; $client_edit_render['female'] = $family['gender'] == '0' ? ' selected' : ''; $client_edit_render['address'] = $family['address']; $client_edit_render['telephone'] = $family['telephone']; $client_edit_render['dob'] = $family['dob']; $client_edit_render['fuel'] = $family['fuel_assistance'] ? ' checked' : ''; $client_edit_render['usda'] = $family['usda_assistance'] ? ' checked' : ''; $client_edit_render['delivery'] = $family['delivery'] ? ' checked' : ''; $client_edit_render['dietary'] = $family['dietary'] ? ' checked' : ''; $client_edit_render['second'] = $family['pickup_second'] ? ' checked' : ''; $client_edit_render['fourth'] = $family['pickup_fourth'] ? ' checked' : ''; $client_edit_render['cooking'] = $family['cooking_facilities'] ? ' checked' : ''; $client_edit_render['start'] = $family['start_date']; $client_edit_render['comments'] = $family['comments']; $client_edit_render['aids'] = $rows; $client_edit->set_vars($client_edit_render); $client_edit->parse(); $content .= $client_edit->final; $client_framework_render['content'] = $content; render_all(); }
function render_new_bag() { global $bag_framework_render; global $parameters; foreach ($parameters as $parameter) { global ${$parameter}; } $content = ""; $bag_new = new Template(); $bag_new->load('bag_new'); $bag_new_render['place_holder'] = ''; $bag_new->set_vars($bag_new_render); $bag_new->parse(); $content .= $bag_new->final; $bags = get_all_bags(); $bag_list = "<option name='none' id='none' value='none'>None</option>"; foreach ($bags as $bag) { $bag_list .= "<option name='" . $bag['name'] . "' id='" . $bag['name'] . "' value='" . $bag['bagid'] . "'>" . $bag['name'] . "</option>"; } $bag_framework_render['content'] = $content; $bag_framework_render['bags'] = $bag_list; 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(); }