function new_bag_transaction_date($clientid, $date) { $client = get_family_by_id($clientid); $s = q("insert into transaction values('', '" . clean_query($clientid) . "', '" . clean_query($client['delivery']) . "', '" . clean_query($date) . "');"); if (a() == 0) { return false; } $id = i(); $sources = get_all_bag_food_sources($client['bagid']); foreach ($sources as $source) { $s = q("insert into transaction_to_food_source values('" . $id . "', '" . $source['sourceid'] . "', '" . $source['weight'] . "', '" . $source['price'] . "');"); } if (a() == 0) { $s = q("delete from transaction where transaction.transactionid = '" . clean_query($id) . "' limit 1;"); return false; } return true; }
function render_edit_bag($bagid) { global $bag_framework_render; global $parameters; foreach ($parameters as $parameter) { global ${$parameter}; } $content = ""; $toggle = true; $rows = ''; $bag_edit_food_source = new Template(); $bag_edit_food_source->load('bag_edit_food_source'); $food_sources = get_all_bag_food_sources($bagid); foreach ($food_sources as $food_source) { $bag_edit_food_source_render['row'] = $toggle ? '1' : '2'; $bag_edit_food_source_render['name'] = $food_source['name']; $bag_edit_food_source_render['field'] = clean_url($food_source['name']); $bag_edit_food_source_render['checked'] = $food_source['bagid'] > 0 ? ' checked="true"' : ''; $bag_edit_food_source_render['weight'] = $food_source['weight']; $bag_edit_food_source_render['price'] = $food_source['price']; $bag_edit_food_source->set_vars($bag_edit_food_source_render); $bag_edit_food_source->parse(); $rows .= $bag_edit_food_source->final; $toggle = !$toggle; } $bag = get_bag_by_id($bagid); // Render Edit Bag $bag_edit = new Template(); $bag_edit->load('bag_edit'); $bag_edit_render['id'] = $bag['bagid']; $bag_edit_render['name'] = $bag['name']; $bag_edit_render['foodsources'] = $rows; $bag_edit->set_vars($bag_edit_render); $bag_edit->parse(); $content .= $bag_edit->final; // Render Bag Contents render_bag_products($bagid); $content .= $bag_framework_render['content']; // Render All $bag_framework_render['content'] = $content; render_all(); }
function render_dropoffs() { global $client_framework_render; global $parameters; foreach ($parameters as $parameter) { global ${$parameter}; } $toggle = true; $rows = ''; $content = ''; $client_drop_food_source = new Template(); $client_drop_food_source->load('client_drop_food_source'); $food_sources = get_all_bag_food_sources(0); foreach ($food_sources as $food_source) { $client_drop_food_source_render['row'] = $toggle ? '1' : '2'; $client_drop_food_source_render['name'] = $food_source['name']; $client_drop_food_source_render['field'] = clean_url($food_source['name']); $client_drop_food_source_render['checked'] = $food_source['bagid'] > 0 ? ' checked="true"' : ''; $client_drop_food_source_render['weight'] = $food_source['weight']; $client_drop_food_source_render['price'] = $food_source['price']; $client_drop_food_source->set_vars($client_drop_food_source_render); $client_drop_food_source->parse(); $rows .= $client_drop_food_source->final; $toggle = !$toggle; } $client_drop = new Template(); $client_drop->load('client_drop'); $client_drop_render['foodsources'] = $rows; $client_drop->set_vars($client_drop_render); $client_drop->parse(); $content .= $client_drop->final; $client_framework_render['content'] = $content; 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(); }