<?php

require_once(dirname(dirname(__FILE__)) . '/app.php');
need_manager();

$sql = "SELECT count( a.quantity ) AS q, a.item_number, a.origin
        FROM order_item AS a, provider AS c
        WHERE a.state = 'send'
        AND a.provider_id = c.id
        GROUP BY a.item_number
        ORDER BY q DESC
        LIMIT 0 , 20";
$item_sale_rank = DB::GetQueryResult($sql, false);

$sql = "SELECT sum( a.quantity ) AS q, sum( a.origin ) AS o, c.name, c.channel
        FROM order_item AS a, provider AS c
        WHERE a.provider_id = c.id
        AND a.state = 'send'
        GROUP BY c.id
        ORDER BY q DESC
        LIMIT 0 , 30";
$provider_rank = DB::GetQueryResult($sql, false);

$sql = "SELECT sum( a.quantity ) AS q, sum( a.origin ) AS o, b.user_id, c.username,c.realname
        FROM order_item AS a, order_info AS b, user AS c,provider as d
        WHERE a.order_number = b.order_number
        AND b.user_id = c.id
        AND a.state = 'send'
        AND a.provider_id = d.id
        GROUP BY b.user_id
        ORDER BY o DESC
        LIMIT 0 , 20";
$user_rank = DB::GetQueryResult($sql, false);


$sql = "SELECT sum( money ) AS money
        FROM flow
        WHERE direction = 'income'
        UNION ALL
        SELECT sum( money ) AS money
        FROM flow
        WHERE direction = 'expense'
        UNION ALL
        SELECT sum( money ) AS money
        FROM user";
$total = DB::GetQueryResult($sql, false);
    

include template('manage_analysis');?>
