<?php

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

class Deletetransactions extends MY_Controller {

    function __construct() {
        parent::__construct();
    }

    function index() {
         $data['categories'] = $this->_getProdCategories();
        $this->load->view('settings/header');
        $this->load->view('settings/deletetransactions_view', $data);
        $this->load->view('settings/footer');
    }
function numeric_wcomma ($str)
{
    return preg_match('/^[0-9,]+$/', $str);
}
//  public function ticketsupdate2() {
//
//        $this->load->library('session');
//        $this->session->set_userdata('idlist',  $this->input->post('idlist'));
//        return 1;
//    }
    public function ticketsupdate() {

         $data['categories'] = $this->_getProdCategories();
        // var_dump($data);
        $this->load->library('form_validation');
        $this->form_validation->set_rules('cutt', 'Cut(%)', 'trim|required|numeric');
//        $this->form_validation->set_rules('notes', 'Receipts', 'trim|required|numeric');
        $this->form_validation->set_rules('lineitems', 'Close Cash', 'trim|required');
//        $plist = unserialize($this->input->post('lineitems'));
         

        if ($this->form_validation->run() == TRUE) {
            $cutt = $this->input->post('cutt');
            $receipts = $this->input->post('notes');
           // var_dump('$receipts');
           // var_dump($receipts);
             $product = $this->input->post('product');
             $productnew = substr_replace($product,"",-1);
             $Categorytotal = $this->input->post('Categorytotal');
             $proinc = $this->input->post('proinc');
             $catinc = $this->input->post('catinc');
             $Categorytotalnew = substr_replace($Categorytotal,"",-1);
             $products=(string)$product;

           //  var_dump($productnew);
              $plist = unserialize($this->input->post('lineitems'));
             //  var_dump($plist);
                $i=0;
            foreach ($plist as $line)
                    {

            $money = $line['ID'];
                }
//            var_dump($receipts);

            $this->load->model('settings/deletetransactions_model');
            $this->deletetransactions_model->ticketsupdate($cutt, $receipts, $money,$productnew,$Categorytotalnew, $proinc, $catinc);
            $fdata = array('msgt' => 'S', 'msg' => 'Tickets Updated successfully.');
            $this->session->set_flashdata($fdata);
           redirect(site_url() . 'settings/deletetransactions');
        } else {

            $this->load->view('settings/header');

            $this->load->view('settings/deletetransactions_view', $data);
            $this->load->view('settings/footer');
        }
    }
    // MATERIALREQUESTS LIST FOR  MANAGE
    public function getclosecash() {
        $datefrom = $this->input->post('datefrom');
        $dateto = $this->input->post('dateto');
        $hostsequence = $this->input->post('hostsequence');
//        $paymenttype = $this->input->post('paymenttype');


        $this->load->model('closecash_model');
        echo $this->closecash_model->getclosecash($datefrom, $dateto, $hostsequence);
    }
    //GET PRODUCT CATEGORIES LIST
    private function _getProdCategories($id = NULL) {
        $this->load->model('inventory/categories_model');
        $catarr = $this->categories_model->getproductcategories();

        $data = '<option value="">Select</option>';

        for ($i = 0; $i < count($catarr); $i++) {
            if ($id != NULL && $id == $catarr[$i]->ID)
                $data .= "<option id=\"option_custom\" selected=\"yes\" value=\"" . $catarr[$i]->ID . "\">" . $catarr[$i]->NAME . "</option>\n";
            else
                $data .= "<option id=\"option_custom\" value=\"" . $catarr[$i]->ID . "\">" . $catarr[$i]->NAME . "</option>\n";
        }
        return $data;
    }


}