<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

/**
 * Description of yk_order_model
 *
 * @author Igor Ratsun
 */
class yk_order_model extends CI_Model
{

    public function get_order_amount($order_number = '')
    {
        $q = $this->db->
                        select('p.price as amount')->
                        join('product p', 'p.id_product=po.id_product', 'left')->
                        where('po.id_product_order', (int) $order_number)->
                        get('product_order po')->row_array();

        if (empty($q['amount'])) {
            return 0;
        }

        $this->load->library('ciext/configurator');
        $conf = new configurator();
        $conf->set_resource('product');
        $data = $conf->get_config();

        return !empty($data['rate_rub_kzt']) ? floatval(round($q['amount'] / $data['rate_rub_kzt'], 2)) : 0;
    }

    public function update_order($order_sum_amount = '')
    {
        $this->db->where('id_product_order', (int) $order_sum_amount)->update('product_order', array(
            'payed_by' => '3',
        ));
    }

}
