<?php
defined('BASEPATH') OR exit('No direct script access allowed');

	class Rapaportmdl extends CI_model
    {
        public function get_diamond_data($api_data)
        {
            $subsql= '';
            $record= [];
            if(!empty($api_data) && 
                !empty($api_data['rp_diamond_type']) && 
                !empty($api_data['rp_clarity']) && 
                !empty($api_data['rp_color']) && 
                !empty($api_data['rp_range_from']) && 
                !empty($api_data['rp_range_to'])
            )
            {
                if($api_data['rp_diamond_type'] == 1)
                {
                    $subsql .= " AND dm.dm_sh ='ROUND'";
                }
                else
                {
                    $subsql .= " AND dm.dm_sh !='ROUND'";
                }
                $subsql .= " AND dm.dm_cla ='".$api_data['rp_clarity']."'";
                $subsql .= " AND dm.dm_col ='".$api_data['rp_color']."'";
                $subsql .= " AND dm.dm_wt BETWEEN ".$api_data['rp_range_from']." AND ".$api_data['rp_range_to'];

                $query ="
                        SELECT dm.dm_id, dm.dm_lab, dm.dm_wt, dm.dm_rap, dm.dm_disc
                        FROM diamond_master dm
                        WHERE dm.dm_status != 3
                        $subsql;
                    ";
                $record = $this->db->query($query)->result_array();    
            }
            
            return $record;
        }
	}
?>