Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] can't save transaction without details
#11

[eluser]maria clara[/eluser]
can anyone show me a code for this??? for reference..

thanks in advance,
kahtrina :question:
#12

[eluser]theprodigy[/eluser]
if you are trying to call the save_detail method in your controller, try calling it instead of your save method
Code:
$data['item'] = $this->Sec_users_db->save($dt,$item)
should probably be changed to:
Code:
$data['item'] = $this->Sec_users_db->save_detail($dt,$item)
#13

[eluser]maria clara[/eluser]
[quote author="theprodigy" date="1265278565"]if you are trying to call the save_detail method in your controller, try calling it instead of your save method
Code:
$data['item'] = $this->Sec_users_db->save($dt,$item)
should probably be changed to:
Code:
$data['item'] = $this->Sec_users_db->save_detail($dt,$item)
[/quote]

yes you're right but my problem is the code in my controller.. the function detailpost() wasn't working at all.. the switch method for creating and etc..should be re-created for it to save the detail list...


thanks for your reply...

regards,
kahtrina
#14

[eluser]Muhamad Perdiyansyah[/eluser]
i
#15

[eluser]maria clara[/eluser]
[quote author="Muhamad Perdiyansyah" date="1265285874"]i[/quote]

i????? what do you mean by that??
#16

[eluser]maria clara[/eluser]
hi to all,

im having a problem with this code... i have to add company code and company name to my db.but this is not working...

Code:
case $crudConfig['create']:
                $c = "";
                $dt['company_code'] = $this->input->post('company_code');
                $sec_exist = $this->Sec_users_db->getDetails($dt);
                
                if ($sec_exist)
                {
                    $c .= 'Company ID already exists.';
                    $data['action'] = 'exist';
                }
                else
                {
                $fields = array(
                        "company_code"
                        ,"company_name"
                        );
                
                foreach ($fields as $field)
                {if (isset($_POST[$field])) $dt[$field] = $this->input->post($field);}

                $item = $this->input->post("item");        
                $data['item'] = $this->Sec_users_db->save($dt,$item);
                }
                break;


can anyone help me...

thanks in advance,
kahtrina
#17

[eluser]theprodigy[/eluser]
show me the output of print_r($_POST), please
#18

[eluser]maria clara[/eluser]
[quote author="theprodigy" date="1265364813"]show me the output of print_r($_POST), please[/quote]

here's the output:

Quote:Array
(
[company_code] => dgs
[company_name] => gsg
[id] => _empty
[oper] => add
)
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined property: Sec_users::$Sec_users_db</p>
<p>Filename: controllers/sec_users.php</p>
<p>Line Number: 538</p>

</div><br />
<b>Fatal error</b>: Call to a member function getDetails() on a non-object in <b>C:\xampp\htdocs\comunion\system\application\modules\sec_users\controllers\sec_users.php</b> on line <b>538</b><br />
#19

[eluser]maria clara[/eluser]
here's my new code for my controller:

Code:
function detailpost()
    {
    
    print_r($_POST);
        
        $crudColumns =  array(
            'id'=>'company_id'
            ,'company_code'=>'company_code'
            ,'company_name'=>'company_name'
        );
        $crudTableName = 'erp_maint_company';
        $postConfig['id'] = 'company_id';

        $postConfig['search'] = '_search';             /* search */
        $postConfig['searchField'] = 'searchField'; /* searchField */
        $postConfig['searchOper'] = 'searchOper';     /* searchOper */
        $postConfig['searchStr'] = 'searchString';     /* searchString */
        $postConfig['action'] = 'oper';             /* action variable */
        $postConfig['sortColumn'] = 'sidx';         /* sort column */
        $postConfig['sortOrder'] = 'sord';             /* sort order */
        $postConfig['page'] = 'page';                 /* current requested page */
        $postConfig['limit'] = 'rows';                /* restrict number of rows to return */
        $crudConfig['row'] = 'cell';                 /* row data identifier */
        $crudConfig['read'] = 'oper';                 /* action READ keyword *//* set to be the same as action keyword for default */
        $crudConfig['create'] = 'add';                /* action CREATE keyword */
        $crudConfig['update'] = 'edit';                /* action UPDATE keyword */
        $crudConfig['delete'] = 'del';                /* action DELETE keyword */
        $crudConfig['totalPages'] = 'total';        /* total pages */
        $crudConfig['totalRecords'] = 'records';    /* total records */
        $crudConfig['responseSuccess'] = 'success';    /* total records */
        $crudConfig['responseFailure'] = 'fail';    /* total records */
        /* end of jqgrid specific settings */
        //$o=null;

        function fnSearchCondition($searchOperation, $searchString){
            switch($searchOperation){
                case 'eq': $searchCondition = '= "'.$searchString.'"'; break;
                case 'ne': $searchCondition = '!= "'.$searchString.'"'; break;
                case 'bw': $searchCondition = 'LIKE "'.$searchString.'%"'; break;
                case 'ew': $searchCondition = 'LIKE "%'.$searchString.'"'; break;
                case 'cn': $searchCondition = 'LIKE "%'.$searchString.'%"'; break;
                case 'lt': $searchCondition = '< "'.$searchString.'"'; break;
                case 'gt': $searchCondition = '> "'.$searchString.'"'; break;
                case 'le': $searchCondition = '<= "'.$searchString.'"'; break;
                case 'ge': $searchCondition = '>= "'.$searchString.'"'; break;
                
            }
            return $searchCondition;
        }
        function fnCleanInputVar($string){
            return $string;
        }

        foreach ($postConfig as $key => $value){
            if(isset($_REQUEST[$value])){
                $postConfig[$key] = fnCleanInputVar($_REQUEST[$value]);
            }
        }
        foreach ($crudColumns as $key => $value){
            if(isset($_REQUEST[$key])){
                $crudColumnValues[$key] = '"'.fnCleanInputVar($_REQUEST[$key]).'"';
            }
        }

        switch($postConfig['action']){
            case $crudConfig['create']:
                $c = "";
                $data['company_code'] = $this->input->post('company_code');
                $sec_exist = $this->Sec_users_db->getDetails($data);
                
                if ($sec_exist)
                {
                    $c .= 'Company ID already exists.';
                    $data['action'] = 'exist';
                }
                else
                {
                $fields = array(
                        "company_code"
                        ,"company_name"
                        );
                
                foreach ($fields as $field)
                {if (isset($_POST[$field])) $dt[$field] = $this->input->post($field);}

                $item = $this->input->post("item");        
                $data['item'] = $this->Sec_users_db->save($dt,$item);
                }
                break;
                
            case $crudConfig['update']:
                $sql = 'update '.$crudTableName.' set ';
                foreach($crudColumns as $key => $value){ $updateArray[$key] = $value.'='.$crudColumnValues[$key]; };
                $sql .= implode(',',$updateArray);
                $sql .= ' where company_id = '.$crudColumnValues['id'];
                mysql_query( $sql );
                break;
                
            case $crudConfig['delete']:
                $this->db->where('company_id', $this->input->post('id'));
                $this->db->delete($crudTableName);
                    
                break;
            }
        
        if (isset($data)) echo json_encode($data);

    }

and my model:

Code:
function getDetails($data)//Joined query for maint_department & sec_role
    {        
        #$data['sec_users.is_deleted'] = '0';

        $this->db->join('maint_department erp_c','sec_users.dept_id=c.dept_id','left');        
        $this->db->join('sec_role erp_d','sec_users.role_id=d.role_id','left');
    
        $this->db->select("sec_users.*,        
                            c.dept_code, c.dept_desc,                            
                            d.role_code, d.role_desc
                            ");    
        $this->db->where($data);                            
        return $this->db->get('sec_users')->row_array();
    }
#20

[eluser]maria clara[/eluser]
continuation of model:

Code:
function save_detail($id,$rows) //Query for saving the company details
    {
        $this->db->where('user_id', $id);
        $this->db->delete('sec_companyaccess');
        
        foreach ($rows as $row)
        {
            $rdata = explode('|', $row);
            
            $data['user_id'] = $id;
            $data['company_id'] = $rdata[3];            
            
            $this->db->insert('sec_companyaccess', $data);
        }
    }
    
    
    
    function save($data,$item,$details) //Save user query
    {

        if ($item=='')    //Add new user
            {
            $this->db->trans_start();
            $data['password'] = md5($this->input->post('password'));    
            $data['status'] = 1;            
            $this->db->insert('sec_users', $data);
            $item = $this->db->insert_id();
            $this->save_detail($item,$details);
            $this->db->trans_complete();                    
            }
        else            //Update/Modify user
            {
            $this->db->trans_start();
            $this->db->where('user_id', $item);
            $this->db->update('sec_users', $data);
            $this->save_detail($item,$details);        
            $this->db->trans_complete();
            }
            
        return $item;    
    }




Theme © iAndrew 2016 - Forum software by © MyBB