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

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

i'm creating a function for saving the details. but when i click the save button..it shows me "can't save transaction without details"..

here's my code for the function detailpost() in my controller:

Code:
//-----------------------------------------------------------------------

    function detailpost()
    {

        $crudColumns =  array(
            'id'=>'company_access_id'
            ,'company_id'=>'company_id'
            ,'company_code'=>'company_code'
            ,'company_name'=>'company_name'
        );
        $crudTableName = 'erp_sec_companyaccess';
        $postConfig['id'] = 'company_access_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 = "";
                $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;
            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);
    }
//-----------------------------------------------------------------------

i attached also the image before and after i submit the details.

glad to see replies..
thanks in advance,

kahtrina
#2

[eluser]theprodigy[/eluser]
can I see the save method in your model, please.
#3

[eluser]maria clara[/eluser]
here's my save functions in my 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;    
    }
#4

[eluser]theprodigy[/eluser]
In your controller, you are passing in 2 parameters ($dt and $item):
Quote:$data['item'] = $this->Sec_users_db->save($dt,$item);
But your model function expects 3 parameters ($data, $item, $details):
Quote: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;
}
#5

[eluser]maria clara[/eluser]
ahh i see.. maybe that's why can't save without details.. but that is for the listview..my master jqgrid. i have to reconstruct the detailpost function i made for it to be able to save the details in the detail jqgrd list.. but it don't work..
#6

[eluser]maria clara[/eluser]
i need to make up a function for the detail list to save the data...




can anyone help me???

thanks in advance,
kahtrina
#7

[eluser]theprodigy[/eluser]
I'm not sure exactly how to help you.
You posted some code, I tried to help with that code, but then you told me that the code I helped you with wasn't the code that you need help with.

Can you give me a little more detail as to where in your code I should be looking?
#8

[eluser]maria clara[/eluser]
[quote author="theprodigy" date="1265269971"]I'm not sure exactly how to help you.
You posted some code, I tried to help with that code, but then you told me that the code I helped you with wasn't the code that you need help with.

Can you give me a little more detail as to where in your code I should be looking?[/quote]

im sorry for that, the MODEL was right.. like what you've help me.. what i mean is that i have to re-create a code for add,edit and delete in my detaillist of my jqgrid as i shown in the images i attached..

i need to re-create this code for adding, editing, and deleting:

Code:
switch($postConfig['action']){
            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;
            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;
            }

because this script was for the master grid.. what i need is a code for the detail list..

thanks in advance,
kahtrina
#9

[eluser]theprodigy[/eluser]
and the detail list is the 3-column grid at the bottom of the images, right?

I've never used this script, so I'll need a little background on it and what you've tried (so we don't waste time trying again):

Are you editing in place (like an Excel spreadsheet)?
Does it use ajax to post to the server?
Do you need more info then just those 3 columns?
What road block are you running into when trying to edit the current code (other then "can't save without details")?
What have you tried so far?
#10

[eluser]maria clara[/eluser]
[quote author="theprodigy" date="1265271137"]and the detail list is the 3-column grid at the bottom of the images, right?

I've never used this script, so I'll need a little background on it and what you've tried (so we don't waste time trying again):

Are you editing in place (like an Excel spreadsheet)?
Does it use ajax to post to the server?
Do you need more info then just those 3 columns?
What road block are you running into when trying to edit the current code (other then "can't save without details")?
What have you tried so far?[/quote]

yeah you're right that's the detail list at the bottom as you can see there are buttons for add,edit and delete. im trying to add, it works but when i refresh the page the data i added gets lost..in short, it isn't posting.. as i know there is an ajax. i just needed the company_code and the company_name to be posted in the grid. i have used the code i have posted but its not working.. i have tried to change the codes but no luck with it...in this part i have 3 tables joined, the company table, where i am supposed to put the company_code and the company_name in the grid.. and the user table, where the form fields should be save.. and the company access table where the company_id and the role_id of the user was save..




Theme © iAndrew 2016 - Forum software by © MyBB