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

class Crnjobs extends CI_Controller {

	function __construct()
    {
        parent::__construct();
        error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
        $this->load->model('common_model');
        $this->clientid = 1;
    }
    
	function rmDuplicateBills()
	{
		$arrbillids = array();
		$currdate = date("Y-m-d");
		$sql = "select fld_id, fld_billno from tbl_billing where fld_billno=any(SELECT fld_billno FROM tbl_billing where fld_billdate='" . $currdate . "' group by fld_billno having count(*)>1)";
		$result02 = $this->db->query($sql);
		if($result02->num_rows()>0)
		{
			foreach($result02->result() as $row)
			{
				$arrbillids[$row->fld_billno] = $row->fld_id;
			}
			$billids = implode(",", $arrbillids);
			$billids2compare = explode(",", $billids);
			if(is_array($billids2compare))
			{
				## del bill info
				$this->db->where_in("fld_billingid", $billids2compare);
				$this->db->delete("tbl_billinginfo");
				//echo "<br><br>" . $this->db->last_query();

				#3 del main bills
				$this->db->where_in("fld_id", $billids2compare);
				$this->db->delete("tbl_billing");
				//echo "<br><br>" . $this->db->last_query();
			}
		}
	}
	

}
