function get_report()
 {
     // Inputs for our report are passed in the following format : Format (type, label, name)
     // Currently supported include:
     // 		date - 	a standard date range element which displays the BR system report ranges and
     //				including a 'custom' option for enterying a start and end date. Start and end
     // 				dates are passed to the post array with the date field name as prepended with
     //				_st for start and _end for end
     // 		input - a standard input field.
     //		category - a category tree field
     // 		member_group - a member group drop down field
     $input[] = array('date', 'Select Date', 'date_range');
     // If there are values in the post array
     // we can use them
     $range_type = $this->date_range == '' ? $this->EE->input->post("date_range", TRUE) : $this->date_range;
     if ($range_type == '') {
         $range_type = 'week';
     }
     if ($range_type == 'custom') {
         $range["start"] = $this->EE->input->post("date_range_st", TRUE);
         $range["end"] = $this->EE->input->post("date_range_end", TRUE);
     } else {
         $range = get_range($range_type);
     }
     $this->EE->load->model('search_model');
     $search = $this->EE->search_model->get_search_results($range["start"], $range["end"]);
     // Header row
     $header = array(lang('br_customer_email'), lang('br_search_phrase'), lang('br_products_found'), lang('br_search_created'));
     // Results array
     $base = 0;
     $tax = 0;
     $total = 0;
     $shipping = 0;
     $discount = 0;
     $result = array();
     if (count($search) == 0) {
         $result = array();
         $graph = '';
     } else {
         $str = '_get_graph_' . $range_type;
         $graph = "";
     }
     foreach ($search as $row) {
         // Is it member or guest ?
         if (isset($row["email"])) {
             $member = '<a href="' . BASE . '&C=myaccount&id=' . $row["member_id"] . '">' . $row["email"] . "</a>";
         } else {
             $member = ' - ';
         }
         // only add orders if they are not canceled
         $result[] = array($member, $row['search_term'], $row['result_count'], $row["created"]);
     }
     $footer = array('', '', '', '');
     $report = array('input' => $input, 'range' => $range, 'graph' => $graph, 'header' => $header, 'results' => $result, 'footer' => $footer);
     return $report;
 }
 function get_report()
 {
     // Inputs for our report are passed in the following format : Format (type, label, name)
     // Currently supported include:
     // 		date - 	a standard date range element which displays the BR system report ranges and
     //				including a 'custom' option for enterying a start and end date. Start and end
     // 				dates are passed to the post array with the date field name as prepended with
     //				_st for start and _end for end
     // 		input - a standard input field.
     //		category - a category tree field
     // 		member_group - a member group drop down field
     $input[] = array('date', 'br_select_date', 'date_range');
     // If there are values in the post array
     // we can use them
     $range_type = $this->date_range == '' ? $this->EE->input->post("date_range", TRUE) : $this->date_range;
     if ($range_type == '') {
         $range_type = 'week';
     }
     if ($range_type == 'custom') {
         $range["start"] = $this->EE->input->post("date_range_st", TRUE);
         $range["end"] = $this->EE->input->post("date_range_end", TRUE);
     } else {
         $range = get_range($range_type);
     }
     $this->EE->load->model('order_model');
     $orders = $this->EE->order_model->get_download_collection($range["start"], $range["end"]);
     // Header row
     $header = array(lang('br_order_id'), lang('br_customer_email'), lang('br_date'), lang('br_download_count'));
     // Results array
     $base = 0;
     $tax = 0;
     $total = 0;
     $shipping = 0;
     $discount = 0;
     $result = array();
     if (count($orders) == 0) {
         $result = array();
         $graph = '';
     } else {
         $str = '_get_graph_' . $range_type;
         $graph = "";
     }
     foreach ($orders as $row) {
         // only add orders if they are not canceled
         if ($row["status_id"] >= 1) {
             $result[] = array($row['order_id'], "<strong>" . $row["email"] . "</strong>", $this->EE->localize->format_date('%m/%d/%Y', $row["created"]), $row['cnt']);
             $orders = $this->EE->order_model->get_order($row["order_id"]);
             foreach ($orders['items'] as $item) {
                 $result[] = array("", $item['quantity'] . " x " . $item['title'], "", "");
             }
         }
     }
     $footer = array('', '', '', '');
     $report = array('input' => $input, 'range' => $range, 'graph' => $graph, 'header' => $header, 'results' => $result, 'footer' => $footer);
     return $report;
 }
 function get_report()
 {
     // Inputs for our report are passed in the following format : Format (type, label, name)
     // Currently supported include:
     // 		date - 	a standard date range element which displays the BR system report ranges and
     //				including a 'custom' option for enterying a start and end date. Start and end
     // 				dates are passed to the post array with the date field name as prepended with
     //				_st for start and _end for end
     // 		input - a standard input field.
     //		category - a category tree field
     // 		member_group - a member group drop down field
     $input[] = array('date', 'Select Date', 'date_range');
     // If there are values in the post array
     // we can use them
     $range_type = $this->date_range == '' ? $this->EE->input->post("date_range", TRUE) : $this->date_range;
     if ($range_type == '') {
         $range_type = 'week';
     }
     if ($range_type == 'custom') {
         $range["start"] = $this->EE->input->post("date_range_st", TRUE);
         $range["end"] = $this->EE->input->post("date_range_end", TRUE);
     } else {
         $range = get_range($range_type);
     }
     $this->EE->load->model('order_model');
     $products = $this->EE->order_model->get_best_products($range["start"], $range["end"]);
     $header = array(lang('br_product_title'), lang('br_qty_sold'), lang('br_total_value'));
     // Results array
     $result = array();
     $ttl = 0;
     $qty = 0;
     if (count($products) == 0) {
         $result = array();
         $graph = '';
     } else {
         $str = '_get_graph_' . $range_type;
         $graph = "";
     }
     $base_url = str_replace('&amp;', '&', BASE) . '&C=addons_modules&M=show_module_cp&module=brilliant_retail';
     foreach ($products as $row) {
         $result[] = array($row['title'], $row['qty'], $this->_currency_round($row['total_sales']));
         $ttl += $row['total_sales'];
         $qty += $row['qty'];
     }
     $footer = array(strtoupper(lang('br_total')), $qty, $this->_currency_round($ttl));
     $report = array('input' => $input, 'range' => $range, 'graph' => $graph, 'header' => $header, 'results' => $result, 'footer' => $footer);
     return $report;
 }
Esempio n. 4
0
function get_limits($id)
{
    global $bzwrapper, $DAYS;
    $res = array();
    $arange = get_range($id, $DAYS);
    $json = $bzwrapper->get_records_in_timeframe($id, 'Bluetooth%20Count%20match', $arange[1], $arange[0]);
    $avalue = json_decode($json, true);
    $ares = array();
    $xmax = 0;
    $xsum = 0;
    $xcount = 0;
    // ciclo i valori json per ottenere
    // la somma totale dei mezzi($xsum)
    // il massimo nr dei mezzi su quella strada ($xmax)
    // il conteggio dei rilevamenti ($xcount)
    // e carico $ares array per il calcolo della moda
    for ($i = 0; $xcount < count($avalue); $i++) {
        $xcount += 1;
        $a = $avalue[$i];
        $value = $a['value'];
        if (!isset($ares[$value])) {
            $ares[$value] = 0;
        }
        $ares[$value] += 1;
        $xsum += $value;
        if ($value > $xmax) {
            $xmax = $value;
        }
    }
    //calcolo la moda
    $xmode = 0;
    $vmax = 0;
    foreach ($ares as $key => $value) {
        if ($value > $vmax) {
            $vmax = $value;
            $xmode = $key;
        }
    }
    // linea verde fino alla media
    $res['max-low'] = $xsum / $xcount;
    $res['max-medium'] = ($xmode + $xmax) / 2;
    $res['min-high'] = $res['max-medium'] + 1;
    return $res;
}
function write_setting()
{
    extract($_POST);
    db_connect();
    $check1 = getCSetting("BLOCKED_FROM");
    $check2 = getCSetting("BLOCKED_TO");
    if (!isset($check1) or strlen($check1) < 1) {
        $ins_sql = "\n\t\t\tINSERT INTO settings (\n\t\t\t\tconstant, label, value, type, \n\t\t\t\tdatatype, minlen, maxlen, div, readonly\n\t\t\t) VALUES (\n\t\t\t\t'BLOCKED_FROM', 'Blocked Period Date Range From', '{$from_year}-{$from_month}-{$from_day}', 'accounting', \n\t\t\t\t'allstring', '10', '10', '0','f'\n\t\t\t)";
        $run_ins = db_exec($ins_sql) or errDie("Unable to record blocked period information.");
    } else {
        $upd1_sql = "UPDATE settings SET value = '{$from_year}-{$from_month}-{$from_day}' WHERE constant = 'BLOCKED_FROM'";
        $run_upd1 = db_exec($upd1_sql) or errDie("Unable to update blocked period information.");
    }
    if (!isset($check2) or strlen($check2) < 1) {
        $ins_sql = "\n\t\t\tINSERT INTO settings (\n\t\t\t\tconstant, label, value, type, \n\t\t\t\tdatatype, minlen, maxlen, div, readonly\n\t\t\t) VALUES (\n\t\t\t\t'BLOCKED_TO', 'Blocked Period Date Range To', '{$to_year}-{$to_month}-{$to_day}', 'accounting', \n\t\t\t\t'allstring', '10', '10', '0','f'\n\t\t\t)";
        $run_ins = db_exec($ins_sql) or errDie("Unable to record blocked period information.");
    } else {
        $upd2_sql = "UPDATE settings SET value = '{$to_year}-{$to_month}-{$to_day}' WHERE constant = 'BLOCKED_TO'";
        $run_upd2 = db_exec($upd2_sql) or errDie("Unable to update blocked period information.");
    }
    return get_range("<li class='yay'>Setting has been saved.</li><br>");
}
Esempio n. 6
0
function prepare_report()
{
    $cntryarr = load_countries_from_csv("./country.csv");
    $category = load_catnames_from_db();
    global $curr;
    $fname = tempnam("/tmp", "krep");
    //$report_fname=$client_dir."/".$fname.".csv";
    $fw = fopen($fname, "w");
    fputs($fw, "id,launch_time,till_days,pname, parent_category, goal, pledged, state, state_days, creator_name, bakerscount, category_name,  categoryposition, location_name,  location_state, location_country,days_till_deadline,pledged_pct,year,month,goal_dim, till_days_dim, pct_dim, state_days_dim, pledged_rng, goal_rng\n");
    $res = pg_query("select p.id as id,deadline, currency, pname, goal, pledged, \"state\", to_timestamp(launchedat) as launch_time, ((deadline-launchedat)/86400) as till_days,  ((statechangedat-launchedat)/86400) as state_days, cr.cname as creator_name, bakerscount, cat.cname as category_name , cat.parentid as parent_category, categoryposition, l.lname as loc_name, l.cstate as loc_state, l.ccountry as loc_country from project as p, creator as cr, category as cat, location as l where l.id=p.l_id and cr.id=p.creator_id and cat.id=p.cat_id;");
    while ($row2 = @pg_fetch_assoc($res)) {
        if (0 == $row2['launch_time']) {
            continue;
        }
        // skip fake projects
        if (100 < $row2['till_days']) {
            continue;
        }
        // export row
        $line = array();
        $line[] = $row2['id'];
        $line[] = convert_to_cps_date($row2['launch_time']);
        $line[] = $row2['till_days'];
        $line[] = preg_replace('/[^A-Za-z0-9\\ \\-]/', '', $row2['pname']);
        $pcat = (int) $row2['parent_category'];
        if (0 == $pcat) {
            $line[] = $row2['category_name'];
        } else {
            $line[] = $category[$pcat];
        }
        $currency = $row2['currency'];
        //process currency
        $goal = $line[] = convert_to_usd($curr, $currency, $row2['goal']);
        $pledged = $line[] = convert_to_usd($curr, $currency, $row2['pledged']);
        // rest of
        $line[] = $row2['state'];
        $line[] = $row2['state_days'];
        $line[] = preg_replace('/[^A-Za-z0-9\\ \\-]/', '', $row2['creator_name']);
        $line[] = $row2['bakerscount'];
        $line[] = $row2['category_name'];
        $line[] = $row2['categoryposition'];
        $line[] = $row2['loc_name'];
        $line[] = $row2['loc_state'];
        if (!isset($cntryarr[$row2['loc_country']])) {
            $line[] = "unknown country";
        } else {
            $line[] = $cntryarr[$row2['loc_country']];
        }
        $days_left = floor(($row2['deadline'] - time()) / 86400);
        if (0 > $days_left) {
            $days_left = 0;
        }
        $line[] = $days_left;
        if (0 == $goal) {
            $goal = 1.0E-5;
        }
        $line[] = floor($pledged / $goal * 100);
        //$line[]=$row2['loc_country'];
        $launch_date = strtotime($row2['launch_time']);
        $line[] = date("Y", $launch_date);
        $line[] = date("M", $launch_date);
        $line[] = $goal;
        $line[] = $row2['till_days'];
        $line[] = floor($pledged / $goal * 100);
        $line[] = $row2['state_days'];
        $line[] = get_range($pledged);
        $line[] = get_range($goal);
        fputcsv($fw, $line);
    }
    fclose($fw);
    $zip = new ZipArchive();
    $filename = $fname . ".zip";
    if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
        die("cant open <{$filename}>\n");
    }
    $zip->addFile($fname, "data.csv");
    $zip->close();
    @unlink($fname);
    return $filename;
}
 function _get_graph_quarter($type, $orders)
 {
     $range = get_range('quarter');
     for ($i = date("n", strtotime($range["start"])); $i <= date("n", strtotime($range["end"])); $i++) {
         $months[$i] = 0;
     }
     foreach ($orders as $row) {
         if (isset($months[date("n", $row["created"])])) {
             $months[date("n", $row["created"])] += $row["total"];
         }
     }
     $max = 0;
     foreach ($months as $key => $val) {
         $axis_x[] = date('F', strtotime('2010-' . $key . '-01'));
         $vals[] = $val;
         if ($val > $max) {
             $max = $val;
         }
     }
     $ratio = $max == 0 ? 0 : 100 / $max;
     foreach ($vals as $v) {
         $values[] = $v * $ratio;
     }
     $axis_y = $this->_get_y($max);
     return 'http://chart.apis.google.com/chart?cht=p3&chs=700x300&chf=bg,lg,90,b4dcec,0,e6f3f8,0.5&chma=40,125,20,30&chdl=' . join('|', $axis_x) . '&chco=116d88|5db9d4|baecfb&chd=t:' . join(',', $values);
 }
Esempio n. 8
0
function prepare_report($db)
{
    $fulldata_collection = $db->fulldata;
    $investments_collection = $db->investments;
    $investments = load_investments_from_mongo($investments_collection);
    $jsondata_collection = $db->jsondata;
    $fulljson = load_objs_list_from_mongo($jsondata_collection);
    $fname = tempnam("/tmp", "cb-rep");
    $fw = fopen($fname, "w");
    fputs($fw, "investor_name,investment_sum_usd,funding_series,funding_type,recipient,date,year,month, quarter, category, investment_range\n");
    $cursor1 = $fulldata_collection->find();
    foreach ($cursor1 as $doc) {
        $name = $doc['name'];
        $inv = $doc['investments'];
        $markets = $doc['markets'];
        foreach ($inv as $investment) {
            if (!isset($investments[$investment]['s'])) {
                continue;
            }
            $funding_sum = $investments[$investment]['s'];
            $funding_type = $investments[$investment]['t'];
            $funding_date = $investments[$investment]['d'];
            $funding_round = $investments[$investment]['r'];
            $funding_company = $investments[$investment]['c'];
            $line = array();
            $line[0] = $name;
            $line[1] = $funding_sum;
            $line[2] = $funding_round;
            $line[3] = $funding_type;
            $line[4] = $funding_company;
            $line[5] = cps_date_from_utime($funding_date);
            $line[6] = year_from_utime($funding_date);
            $line[7] = month_from_utime($funding_date);
            $line[8] = quarter_from_utime($funding_date);
            $line[9] = null;
            $line[10] = get_range($funding_sum);
            foreach ($markets as $market) {
                $line[9] = $market->name;
                fputcsv($fw, $line);
            }
            // each market
        }
        // each investment
    }
    //each investor
    fclose($fw);
    $zip = new ZipArchive();
    $filename = $fname . "-report.zip";
    if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
        die("cant open <{$filename}>\n");
    }
    $zip->addFile($fname, "data.csv");
    $zip->close();
    @unlink($fname);
    return $filename;
}
Esempio n. 9
0
function get_ranges($range_arr)
{
    $result = [];
    if (is_array($range_arr)) {
        foreach ($range_arr as $range_str) {
            $result[] = get_range($range_str);
        }
    } else {
    }
    return $result;
}