$sp_list = $class_sp->retrieveList();
$sp_list['ALL'] = array('name' => 'ALL SP and J&G');
$sp_list['0'] = array('name' => 'Julie & Grace');
if (isset($_POST['me_action'])) {
    if ($_POST['me_action'] == 'GENERATEREPORT') {
        $jng_sp_id = tep_db_prepare_input($_POST['jng_sp_id']);
        $start_date_raw = tep_db_prepare_input($_POST['start_date']);
        $start_date = generateMysqlDateFromGerman($start_date_raw);
        $end_date_raw = tep_db_prepare_input($_POST['end_date']);
        $end_date = generateMysqlDateFromGerman($end_date_raw);
        $brand_id = tep_db_prepare_input($_POST['brand_id']);
        $cost_mkt_fix = tep_db_prepare_input($_POST['cost_mkt_fix']);
        $cost_mkt_var_pct = tep_db_prepare_input($_POST['cost_mkt_var']);
        $cost_oth_fix = tep_db_prepare_input($_POST['cost_oth_fix']);
        $cost_oth_var_pct = tep_db_prepare_input($_POST['cost_oth_var']);
        $summary = ReportCOGS::retrieveSummary($jng_sp_id, $start_date, $end_date, $brand_id);
        //before returns value
        $total_returns = $summary['total_quantity_return'];
        $br_total_qty = $summary['total_quantity_sold'];
        $br_gross_sales = $summary['total_price_before_return'];
        $br_gross_sales_avg = $br_total_qty == 0 ? 0 : $br_gross_sales / $br_total_qty;
        $br_cash_discount = $summary['total_cash_discount_before_return'];
        $br_cash_discount_avg = $br_total_qty == 0 ? 0 : $br_cash_discount / $br_total_qty;
        $br_net_sales = $summary['total_net_sales_before_return'];
        $br_net_sales_avg = $br_total_qty == 0 ? 0 : $br_net_sales / $br_total_qty;
        $br_returns_gross = $summary['total_price_before_return'] - $summary['total_price'];
        $br_returns_gross_avg = $br_returns_gross / $total_returns;
        $br_returns_net = $summary['total_net_sales_before_return'] - $summary['total_net_sales'];
        $br_returns_net_avg = $br_returns_net / $total_returns;
        $return_rate = $br_returns_net / $br_net_sales * 100;
        //after returns value (default data)
 $header['w100 6'] = 'Gross Profit';
 $header['w100 7'] = 'Open Prepayment Orders';
 $header['w100 8'] = 'Open Prepayment Value';
 $table[] = $header;
 $total_sales = 0;
 $total_sold = 0;
 $total_cogs = 0;
 $total_net_sales = 0;
 $total_gross_profit = 0;
 $total_prepayment_count = 0;
 $total_prepayment_value = 0;
 for ($d = 0; $d < $weekly_days; $d++) {
     $date_ts = strtotime($date_start . " -{$d} days");
     $date_display = date('d-M-y', $date_ts);
     $date_filter = date('Y-m-d', $date_ts);
     $daily_data = ReportCOGS::retrieveSummary($jng_sp_id, $date_filter, $date_filter);
     $total_sales += $daily_data['total_price'];
     $total_sold += $daily_data['total_quantity'];
     $total_cogs += $daily_data['total_cogs'];
     $total_net_sales += $daily_data['total_net_sales'];
     $total_gross_profit += $daily_data['total_gross_profit'];
     if (!isset($prepayments[$date_filter])) {
         $prepayment_count = 0;
         $prepayment_value = 0;
     } else {
         $prepayment_count = $prepayments[$date_filter]['count'];
         $prepayment_value = $prepayments[$date_filter]['value'];
     }
     $total_prepayment_count += $prepayment_count;
     $total_prepayment_value += $prepayment_value;
     $avpr = $daily_data['total_quantity'] == 0 ? 0 : $daily_data['total_price'] / $daily_data['total_quantity'];
Example #3
0
//yesterday
$date_start = date('Y-m-d', strtotime('-2 days'));
$date_end = $date_start;
$daily_data = ReportCOGS::retrieveSummary($jng_sp_id, $date_start, $date_end);
$sales_ld = displayCurrency(CURRENCY_DEFAULT, $daily_data['total_price'], false);
$grossprofit_ld = number_format($daily_data['average_gross_profit_percent'] * 100, 1) . ' %';
//last week
$date_start = date('Y-m-d', strtotime('last sunday -6 days'));
$date_end = date('Y-m-d', strtotime('last sunday'));
$daily_data = ReportCOGS::retrieveSummary($jng_sp_id, $date_start, $date_end);
$sales_lw = displayCurrency(CURRENCY_DEFAULT, $daily_data['total_price'], false);
$grossprofit_lw = number_format($daily_data['average_gross_profit_percent'] * 100, 1) . ' %';
//last month
$date_start = date('Y-m-01', strtotime('last month'));
$date_end = date('Y-m-t', strtotime('last month'));
$daily_data = ReportCOGS::retrieveSummary($jng_sp_id, $date_start, $date_end);
$sales_lm = displayCurrency(CURRENCY_DEFAULT, $daily_data['total_price'], false);
$grossprofit_lm = number_format($daily_data['average_gross_profit_percent'] * 100, 1) . ' %';
//bestseller
$q = "SELECT COUNT(products_id) AS total FROM products WHERE active_status=1 AND stars=3";
$r = tep_db_query($q);
$row = tep_db_fetch_array($r);
$total_bestseller = $row['total'];
//Draw content
$wall = new wall('0');
$content .= '<div id="dashboard">' . '<div id="db-block-left" style="position:absolute;">' . '<div id="db-block-sales" style="margin-bottom:40px">' . '<h2>Sales Summary (' . CURRENCY_DEFAULT . ')</h2>' . '<ul class="table-list">' . '<li><span class="label">Yesterday</span><span class="value">' . $sales_ld . '</span></li>' . '<li><span class="label">Last Week</span><span class="value">' . $sales_lw . '</span></li>' . '<li><span class="label">Last Month</span><span class="value">' . $sales_lm . '</span></li>' . '</ul>' . '</div>' . '<div id="db-block-grossprofit" style="margin-bottom:40px">' . '<h2>Gross Profit Margin</h2>' . '<ul class="table-list">' . '<li><span class="label">Yesterday</span><span class="value">' . $grossprofit_ld . '</span></li>' . '<li><span class="label">Last Week</span><span class="value">' . $grossprofit_lw . '</span></li>' . '<li><span class="label">Last Month</span><span class="value">' . $grossprofit_lm . '</span></li>' . '</ul>' . '</div>' . '<div id="db-block-bestseller" style="margin-bottom:40px">' . '<h2>Bestseller Management</h2>' . '<ul class="table-list">' . '<li><span class="value" style="">' . $total_bestseller . '</span><span class="label">Total 3 stars products</span></li>' . '<li><span class="value" title="coming soon!">NA</span><span class="label">Bestseller not on stock</span></li>' . '</ul>' . '</div>' . '</div>' . '<div id="db-block-middle" style="position:absolute;left:320px;margin-bottom:20px;">' . '<h1>News</h1>' . $wall->draw(2, 'width:500px;margin-bottom:20px;', true, 'Share something new...') . '</div>' . '<div id="db-block-right" class="w500" style="position:absolute;left:870px;">' . '<h2>Recent Orders</h2>' . '<div id="recent-bought"></div>' . '</div>' . '</div>';
#dashboard
$javascript = wall::drawWallJSaction() . '
            var recent_bought_firstload = true;
            function compareProduct(xmlResult, txtStatus) {
                if(txtStatus=="success") {