コード例 #1
0
function price_profit_rate($data)
{
    $CI =& get_instance();
    $eshop_code = $data['eshop_code'];
    $buyer_shipping_cost = $data['buyer_shipping_cost'];
    $shipping_type = $data['shipping_type'];
    $shipping_country = $data['shipping_country'];
    $total_weight = $data['total_weight'];
    $sale_mode = $data['sale_mode'];
    $eshop_category = $data['eshop_category'];
    $suggest_price = $data['suggest_price'];
    $key = $data['key'];
    $balance_profit = $data['balance_profit'];
    $total_price = $data['total_price'];
    $eshop_list_count = $data['eshop_list_count'];
    $eshop_list_fee_multiply = $data['eshop_list_fee_multiply'];
    $pay_option = $data['pay_option'];
    $pay_discount = $data['pay_discount'];
    $other_cost = $data['other_cost'];
    $max_length = $data['max_length'];
    $max_width = $data['max_width'];
    $total_height = $data['total_height'];
    $currency_code = $CI->fee_price_model->fetch_eshop_currency_code($eshop_code);
    $buyer_shipping_cost_original = $buyer_shipping_cost;
    $buyer_shipping_cost = calc_currency($currency_code, $buyer_shipping_cost);
    $special_types = array('X');
    if (in_array($shipping_type, $special_types)) {
        $shipping_method_oject = $CI->shipping_code_model->fetch_shipping_method($shipping_type);
        $shipping_cost = 0;
        $shipping_type_name = $shipping_method_oject ? $shipping_method_oject->name_cn : '';
    } else {
        $shipping_rule = _fetch_shipping_cost($total_weight, $shipping_type, $shipping_country, $max_length, $max_width, $total_height);
        if (!$shipping_rule) {
            return lang('no_suitable_shipping_type');
        }
        $shipping_cost = $shipping_rule['price'];
        $shipping_type_name = $shipping_rule['type']->type_name;
    }
    $product_cost = $total_price;
    // calculate profit
    $price = $key ? calc_currency($currency_code, $suggest_price) : $product_cost;
    $test_profit = 0;
    $deviation = 1.0E-14;
    $min_profit = $balance_profit - $deviation;
    $max_profit = $balance_profit + $deviation;
    $try_count = 0;
    do {
        $eshop_price = to_foreigh_currency($currency_code, $price);
        $eshop_list_fee = $CI->fee_price_model->fetch_eshop_list_formula($eshop_code, $sale_mode, $eshop_category, $eshop_price);
        if ($eshop_list_fee === NULL) {
            return lang('eshop_list_fee_not_set');
        }
        if ($eshop_code == 'ebay-USA') {
            $price_for_trade = $key ? calc_currency($currency_code, $suggest_price) + $buyer_shipping_cost : $price + $buyer_shipping_cost;
            $price_for_trade = to_foreigh_currency($currency_code, $price_for_trade);
        } else {
            $price_for_trade = $eshop_price;
        }
        $eshop_trade_fee = $CI->fee_price_model->fetch_eshop_trade_formula($eshop_code, $sale_mode, $eshop_category, $price_for_trade);
        if ($eshop_trade_fee === NULL) {
            return lang('eshop_trade_fee_not_set') . $price_for_trade;
        }
        $eshop_list_fee = _eval_fee($eshop_list_fee, $eshop_price) / $eshop_list_count;
        // for auction;
        $eshop_list_fee *= $eshop_list_fee_multiply;
        $eshop_trade_fee = _eval_fee($eshop_trade_fee, $price_for_trade);
        $eshop_trade_fee = $eshop_trade_fee * (1 - $pay_discount);
        $pay_fee = isset($data['paypal_cost']) ? $data['paypal_cost'] : _eval_fee($pay_option, $eshop_price + $buyer_shipping_cost_original);
        $eshop_list_fee_default = calc_currency($currency_code, $eshop_list_fee);
        $eshop_trade_fee_default = calc_currency($currency_code, $eshop_trade_fee);
        $pay_fee_default = calc_currency($currency_code, $pay_fee);
        $total_cost = $product_cost + $pay_fee_default + $eshop_list_fee_default + $eshop_trade_fee_default + $shipping_cost + $other_cost;
        $test_profit = ($price + $buyer_shipping_cost - $total_cost) / ($price + $buyer_shipping_cost - $pay_fee_default);
        if ($key) {
            break;
        }
        if ($test_profit >= $min_profit && $test_profit <= $max_profit) {
            break;
        }
        if ($test_profit < $min_profit) {
            // too low
            $price = $price + $price * (($min_profit + $max_profit) / 2 - $test_profit);
        } else {
            // too hight
            $price = $price - $price * ($test_profit - ($min_profit + $max_profit) / 2);
        }
    } while (1);
    return array('suggest_price' => $price, 'buyer_shipping_cost' => $buyer_shipping_cost, 'list_fee' => $eshop_list_fee_default, 'trade_fee' => $eshop_trade_fee_default, 'pay_fee' => $pay_fee_default, 'shipping_cost' => $shipping_cost, 'shipping_type_name' => $shipping_type_name, 'other_cost' => $other_cost, 'product_cost' => $product_cost, 'total_cost' => $total_cost, 'total_profit' => $price + $buyer_shipping_cost - $total_cost, 'total_profit_rate' => $test_profit, 'currency_code' => $currency_code, 'default_currency_code' => DEFAULT_CURRENCY_CODE, 'total_weight' => $total_weight);
}
コード例 #2
0
 public function merge_order_for_auto_assign($order_id)
 {
     $order = $this->get_order($order_id);
     if (empty($order)) {
         return FALSE;
     }
     $epacket_shipping_code = 'H';
     $status = fetch_status_id('order_status', 'wait_for_confirmation');
     $can_merge_where = array('id !=' => $order_id, 'name' => $order->name, 'country' => $order->country, 'state_province' => $order->state_province, 'town_city' => $order->town_city, 'address_line_1' => $order->address_line_1, 'address_line_2' => $order->address_line_2, 'input_user' => $order->input_user, 'order_status' => $status, 'is_register !=' => $epacket_shipping_code, 'ebay_id' => $order->ebay_id);
     $this->db->select('*');
     $this->db->where($can_merge_where);
     $this->db->from('order_list');
     $query = $this->db->get();
     $to_merge_order = $query->row();
     if (empty($to_merge_order->id)) {
         return FALSE;
     }
     // starting merging
     if ($to_merge_order->currency == $order->currency) {
         $new_gross = $to_merge_order->gross + $order->gross;
         $new_fee = $to_merge_order->fee + $order->fee;
     } else {
         $tmp_rmb = calc_currency($order->currency, $order->gross);
         $new_gross = $to_merge_order->gross + price(to_foreigh_currency($to_merge_order->currency, $tmp_rmb));
         $tmp_rmb = calc_currency($order->currency, $order->fee);
         $new_fee = $to_merge_order->fee + price(to_foreigh_currency($to_merge_order->currency, $tmp_rmb));
     }
     echo "new gross: {$new_gross}\n";
     echo "new fee: {$new_fee}\n";
     echo "to merge gross: {$to_merge_order->gross}\n";
     echo "to merge fee: {$to_merge_order->fee}\n";
     echo "to merge currency: {$to_merge_order->currency}\n";
     echo "order gross: {$order->gross}\n";
     echo "order gross: {$order->fee}\n";
     echo "gross: {$order->currency}\n";
     $new_net = $new_gross - $new_fee;
     $new_title = $to_merge_order->item_title_str . ITEM_TITLE_SEP . $order->item_title_str;
     $new_id = $to_merge_order->item_id_str . ',' . $order->item_id_str;
     $new_sku_str = $to_merge_order->sku_str . ',' . $order->sku_str;
     $new_amount = $to_merge_order->qty_str . ',' . $order->qty_str;
     $sys_remark = $to_merge_order->sys_remark . ', ' . sprintf(lang('merge_log'), get_current_time(), $order->transaction_id);
     $data = array('gross' => $new_gross, 'fee' => $new_fee, 'net' => $new_net, 'item_title_str' => $new_title, 'item_id_str' => $new_id, 'sku_str' => $new_sku_str, 'qty_str' => $new_amount, 'sys_remark' => $sys_remark);
     $this->update('order_list', array('id' => $to_merge_order->id), $data);
     $this->db->insert('order_merged_list', array('transaction_id' => $order->transaction_id));
     $this->delete('order_list', array('id' => $order->id));
     if (!isset($this->CI->order_role_model)) {
         $this->CI->load->model('order_role_model');
     }
     $this->CI->order_role_model->add_order_role($order_id);
     $data = array('import_date' => get_current_time(), 'user_name' => lang('program'), 'descript' => sprintf(lang('merge_log'), get_current_time(), $order->transaction_id), 'user_login' => lang('program'));
     $this->import_log($data);
     echo 'auto merge: to merge id: ', $to_merge_order->id, "\n";
     return TRUE;
 }
コード例 #3
0
{$item_title_str}<br/>
{$item_sku_html}
{$shipping_type} {$phone} <br/>
{$product_name}

</div>
PRODUCT;
    $row[] = $product_info;
    $config = array('name' => 'note_' . $order->id, 'id' => 'note_' . $order->id, 'value' => !empty($order->descript) ? $order->descript : $order->note, 'rows' => '4', 'cols' => '20');
    $note = form_textarea($config);
    $transaction_id = lang('transaction_id');
    $ebay_shippingamt = lang('ebay_shippingamt');
    $receipt_way = lang('receipt_way');
    $is_deficit = '';
    if ($order->profit_rate < 0) {
        $net_rmb = price(calc_currency($order->currency, $order->net));
        $deficit = $net_rmb - $order->product_cost_all - $order->shipping_cost - $order->trade_fee - $order->listing_fee;
        $deficit_div = "deficit_{$order->id}";
        $deficit_text = <<<DEFICIT_TEXT
profit rate: {$order->profit_rate} <br/>
net: {$net_rmb} <br/>
product cost: {$order->product_cost_all} <br/>
shipping cost: {$order->shipping_cost} <br/>
final value fee: {$order->trade_fee} <br/>
listing fee: {$order->listing_fee} <br/>
deficit: {$deficit}
DEFICIT_TEXT;
        $is_deficit = "<span style='padding:5px;'>" . "<a href='#' title='click to see detail' onclick=\"\$('{$deficit_div}').toggle();return false;\">" . fetch_icon('deficit.gif') . "</a>" . "<div id='{$deficit_div}' style='display: none;border: 2px solid #F27B04;background-color: #F0FFF0;'>{$deficit_text}</div>" . "</span>";
    }
    $is_splited = '';
    if ($order->is_splited) {
コード例 #4
0
ファイル: auto.php プロジェクト: ohjack/mallerp_standard
 protected function _calculate_profit_rate($order_data)
 {
     $shipping_code = $order_data['shipping_code'];
     $item_ids = explode(',', $order_data['item_id_str']);
     $product_cost = $order_data['price'];
     $transaction_ids = $order_data['transaction_ids'];
     $currency = $order_data['currency'];
     $gross = price(calc_currency($currency, $order_data['gross']), 2);
     $net = price(calc_currency($currency, $order_data['net']), 2);
     $shipping_weight = $order_data['shipping_weight'];
     $country = $order_data['country'];
     $trade_fee = 0;
     $phone = '';
     $item_ids = array_unique($item_ids);
     $i = 0;
     $listing_fee = 0;
     // Todo: chinese auction
     foreach ($item_ids as $item_id) {
         if (is_array($transaction_ids)) {
             $transaction_id = $transaction_ids[$i];
         } else {
             $transaction_id = $transaction_ids;
         }
         $ebay_order = $this->sale_model->fetch_ebay_order($item_id, $transaction_id);
         // it's not correct for merged or splited orders.
         if (!empty($ebay_order)) {
             $currency = $ebay_order->currency;
             $trade_fee += price(calc_currency($currency, $ebay_order->final_value_fee), 2);
             $phone = '';
             if ($ebay_order->transaction_id == 0) {
                 $listing = $this->ebay_order_model->fetch_listing_fee($item_id);
                 if (isset($listing->listing_fee)) {
                     $listing_fee += price(calc_currency($listing->listing_fee_currency, $listing->listing_fee));
                 }
             }
             if ($phone == 'Invalid Request') {
                 $phone = '';
             }
         }
         $i++;
     }
     $country_cn = get_country_name_cn($country);
     $max_length = 0;
     $max_width = 0;
     $total_height = 0;
     $shipping_rule = _fetch_shipping_cost($shipping_weight, $shipping_code, $country_cn, $max_length, $max_width, $total_height);
     $shipping_cost = isset($shipping_rule['price']) ? $shipping_rule['price'] : 0;
     $profit = price(to_foreigh_currency('USD', $net - $product_cost - $shipping_cost - $trade_fee - $listing_fee));
     $profit_rate = price($profit / $gross, 4);
     if ($profit_rate == 0) {
         $profit_rate = 0.001;
     }
     return array('profit' => $profit, 'profit_rate' => $profit_rate, 'trade_fee' => $trade_fee, 'listing_fee' => $listing_fee, 'product_cost' => $product_cost, 'shipping_cost' => $shipping_cost, 'phone' => $phone);
 }
コード例 #5
0
    $shipping_cost_str .= $code . ": " . price($cost) . " (" . lang('order_count') . ": {$shipping_count_by_code[$code]})<br/>";
    $total_shipping_cost += $cost;
}
$ebay_cost_str = '';
$total_ebay_cost = 0;
$total_ebay_cost_usd = 0;
foreach ($ebay_by_currency as $corrency => $cost) {
    $rmb = price(calc_currency('USD', $cost));
    $total_ebay_cost_usd += price($cost);
    $total_ebay_cost += $rmb;
}
$ebay_cost_str .= "USD: " . $total_ebay_cost_usd . ' -> ' . DEFAULT_CURRENCY_CODE . ': ' . $total_ebay_cost . "<br/>";
$revenue_str = '';
$total_revenue = 0;
foreach ($revenue_by_currency as $corrency => $cost) {
    $rmb = price(calc_currency($corrency, $cost));
    $revenue_str .= $corrency . ": " . price($cost) . ' -> ' . DEFAULT_CURRENCY_CODE . ': ' . $rmb . "<br/>";
    $total_revenue += $rmb;
}
$total_profit = price($total_revenue - $total_shipping_cost - $product_total_cost - $total_ebay_cost);
$data[] = array(lang('total_order_count') . ': ' . $order_count . '<br/><br/>' . $country_str, DEFAULT_CURRENCY_CODE . ': ' . price($product_total_cost), lang('total_cost') . "(" . DEFAULT_CURRENCY_CODE . '): ' . price($total_shipping_cost) . '<br/><br/>' . $shipping_cost_str, lang('total_cost') . "(" . DEFAULT_CURRENCY_CODE . '): ' . price($total_ebay_cost) . '<br/><br/>' . $ebay_cost_str, lang('total_revenue') . "(" . DEFAULT_CURRENCY_CODE . '): ' . price($total_revenue) . '<br/><br/>' . $revenue_str, lang('total_profit') . "(" . DEFAULT_CURRENCY_CODE . '): ' . $total_profit);
echo block_header(lang('order_cost_statistics'));
echo '<br/>';
echo form_open(current_url());
echo lang('from') . ' ' . block_time_picker('begin_time', $begin_time) . '&nbsp;&nbsp;';
echo lang('to') . ' ' . block_time_picker('end_time', $end_time) . '&nbsp;&nbsp;';
//echo form_dropdown('input_user', $input_users, $current_input_user);
$auction_sites = array('' => lang('all'), 'ebay_site' => lang('ebay_site'), 'aliexpress' => lang('aliexpress'), 'b2c' => lang('b2c'), 'not_online' => lang('not_online'));
echo form_dropdown('auction_site', $auction_sites, '');
$config = array('name' => 'submit', 'value' => lang('submit'), 'type' => 'submit');
echo block_button($config);
コード例 #6
0
    $ship_info = <<<SHIP
        {$lang_confirm_date} : {$order->ship_confirm_date} <br/>
        {$lang_weight} : {$order->ship_weight} <br/>
        {$lang_confirm_user} : {$order->ship_confirm_user} <br/>
        {$lang_ship_remark} : {$order->ship_remark} <br/> | {$order->descript} <br/>
        {$lang_receive_date} : {$order->order_receive_date} <br/>
        {$lang_sys_remark}:</br>


SHIP;
    $order->saler_id = "";
    $row[] = $ship_info;
    if ($order->cost_user && $order->profit_rate != 0 && (!$start_profit_rate || $start_profit_rate <= $order->profit_rate) && (!$end_profit_rate || $end_profit_rate >= $order->profit_rate)) {
        $net_rmb = price(calc_currency($order->currency, $order->net));
        $trade_fee = price(calc_currency('USD', $order->trade_fee));
        $listing_fee = price(calc_currency('USD', $order->listing_fee));
        if (empty($order->trade_fee)) {
            $profit_str = "<div style='color: blue'>";
            $profit_str .= $order->profit_rate;
            if (!empty($order->gross)) {
                $trade_fee = $net_rmb * 0.12;
            }
        } else {
            $profit_str = $order->profit_rate;
        }
        $profit_str .= '<br/>' . lang('total_revenue') . ': ' . $rmb;
        $profit_str .= '<br/>' . lang('shipping_cost') . ': ' . $order->shipping_cost;
        $profit_str .= '<br/>' . lang('product_cost') . ': ' . $order->product_cost_all;
        $profit_str .= '<br/>' . lang('trade_fee') . ': ' . $trade_fee;
        $profit_str .= '<br/>' . lang('list_fee') . ': ' . $listing_fee;
        $profit_str .= '<br/>' . lang('total_profit') . ': ' . price($net_rmb - $order->cost - $trade_fee - $listing_fee);
コード例 #7
0
/**
 * calculate_order_profit_rate 
 *
 * Warning: should not be used before trade fee is calculated. 
 * 
 * @param intger $order_id 
 * @access public
 * @return array
 */
function calculate_order_profit_rate($order_id, $after_cost = TRUE)
{
    $CI =& get_instance();
    if (!isset($CI->order_model)) {
        $CI->load->model('order_model');
    }
    if (!isset($CI->sale_model)) {
        $CI->load->model('sale_model');
    }
    $order = $CI->order_model->fetch_order($order_id);
    if (empty($order)) {
        return;
    }
    if ($after_cost && empty($order->cost_user)) {
        return;
    }
    $usd_currency = 'USD';
    $currency = $order->currency;
    $gross = calc_currency($currency, $order->gross);
    $net = calc_currency($currency, $order->net);
    $cost = $order->cost;
    if ($cost == 0) {
        $raw_cost = order_raw_cost($order_id);
        var_dump($raw_cost);
        $cost = $raw_cost['product_cost'] + $raw_cost['shipping_cost'];
    }
    $trade_fee = calc_currency($usd_currency, $order->trade_fee);
    $listing_fee = calc_currency($usd_currency, $order->listing_fee);
    if (empty($gross)) {
        if ($order->net <= 0.01) {
            $profit_rate = 0;
        } else {
            $profit_rate = price(($net - $cost) / $net, 4);
        }
    } else {
        if (empty($trade_fee)) {
            $rate = 0.12;
            $trade_fee = $gross * $rate;
        }
        $profit_rate = price(($net - $cost - $trade_fee - $listing_fee) / $gross, 4);
    }
    echo "formula: ({$net} - {$cost} - {$trade_fee} - {$listing_fee}) / {$gross} \n";
    echo $profit_rate, "\n";
    $CI->sale_model->update_order_profit_rate($order->id, $profit_rate);
    $result = array('profit_rate' => $profit_rate, 'profit' => price($net - $cost - $trade_fee - $listing_fee));
    return $result;
}
コード例 #8
0
ファイル: paypal.php プロジェクト: ohjack/mallerp_standard
 private function _merge_order($to_merged_id, $transaction_details)
 {
     $order_obj = $this->paypal_model->get_order_info_for_merge($to_merged_id);
     if (!$order_obj) {
         return $this->_waiting_comfirmed_order($transaction_details);
     }
     $gross = $order_obj->gross;
     $fee = $order_obj->fee;
     $shippingamt = $order_obj->shippingamt;
     $currency = $order_obj->currency;
     $item_title = $order_obj->item_title_str;
     $item_id = $order_obj->item_id_str;
     $sm_products_code = $order_obj->sku_str;
     $amount = $order_obj->qty_str;
     $item_no = $order_obj->item_no;
     $is_register = $order_obj->is_register;
     $item_info = array('item_titles' => array_merge(explode(ITEM_TITLE_SEP, $item_title), $this->item_info['item_titles']), 'item_ids' => array_merge(explode(',', $item_id), $this->item_info['item_ids']), 'item_codes' => array_merge(explode(',', $sm_products_code), $this->item_info['item_codes']), 'item_qties' => array_merge(explode(',', $amount), $this->item_info['item_qties']));
     $item_info = $this->_merge_duplicated_order($item_info);
     if ($currency == $transaction_details['CURRENCYCODE']) {
         $new_gross = $gross + $transaction_details['AMT'];
         $new_fee = $fee + $transaction_details['FEEAMT'];
         $new_shippingamt = $shippingamt + $transaction_details['SHIPPINGAMT'];
     } else {
         $tmp_rmb = calc_currency($transaction_details['CURRENCYCODE'], $transaction_details['AMT']);
         $new_gross = $gross + price(to_foreigh_currency($currency, $tmp_rmb));
         $tmp_rmb = calc_currency($transaction_details['CURRENCYCODE'], $transaction_details['FEEAMT']);
         $new_fee = $fee + price(to_foreigh_currency($currency, $tmp_rmb));
         $tmp_rmb = calc_currency($transaction_details['CURRENCYCODE'], $transaction_details['SHIPPINGAMT']);
         $new_shippingamt = $shippingamt + price(to_foreigh_currency($currency, $tmp_rmb));
     }
     echo "{$new_gross}, {$new_fee}, {$new_shippingamt}\n";
     echo "currency: {$currency}\n";
     echo "transaction_details: {$transaction_details['CURRENCYCODE']}\n";
     echo "gross: {$gross}, {$transaction_details['AMT']}\n";
     echo "fee: {$fee}, {$transaction_details['FEEAMT']}\n";
     echo "shippingamt: {$shippingamt}, {$transaction_details['SHIPPINGAMT']}\n";
     $paypal_transaction_id = array($transaction_details['TRANSACTIONID'], $order_obj->transaction_id);
     $new_net = $new_gross - $new_fee;
     $new_title = implode(ITEM_TITLE_SEP, $item_info['item_titles']);
     $new_id = implode(',', $item_info['item_ids']);
     $new_sm_products_code = implode(',', $item_info['item_codes']);
     $new_amount = implode(',', $item_info['item_qties']);
     $new_gross_usd = $this->order_model->to_usd($currency, $new_gross);
     $item_info['gross_usd'] = $new_gross_usd;
     $item_info['gross'] = $new_gross;
     $new_is_register = get_register($item_info, $this->user, $currency, $paypal_transaction_id);
     $new_item_no = change_item_register($item_no, $is_register, $new_is_register);
     $order_status = $this->order_statuses['wait_for_confirmation'];
     $data = array('transaction_id' => $transaction_details['TRANSACTIONID'], 'gross' => $new_gross, 'fee' => $new_fee, 'net' => $new_net, 'shippingamt' => $new_shippingamt, 'item_title_str' => $new_title, 'item_id_str' => $new_id, 'sku_str' => $new_sm_products_code, 'qty_str' => $new_amount, 'is_register' => $new_is_register, 'item_no' => $new_item_no, 'order_status' => $order_status);
     $sys_remark = $this->_create_sys_remark('merged_order', $transaction_details['TRANSACTIONID']);
     $this->paypal_model->merge_order($to_merged_id, $data, $sys_remark);
     $this->report['merged_order']++;
 }