Welcome Guest, Not a member yet? Register   Sign In
RE:[help!!!] A PHP Error was encountered
#11

[eluser]Ben Edmunds[/eluser]
Yea cause the array is empty.

You need to pass a valid array with data to foreach.
#12

[eluser]maria clara[/eluser]
here's the code in the model:
Code:
function save_detail($id,$rows0,$rows1,$rows2,$rows3,$dt)
    //function save_detail($id,$rows0=array(),$rows1=array(),$rows2,$rows3,$dt)
    {
        $this->db->where('receipt_id', $id);
        $this->db->delete('ccm_receipt_t');        
        
        //print_r($rows0);
        foreach ($rows0 as $row0)
        {
            $rdata = explode('|', $row0);
            
            $data['receipt_id'] = $id;
            $data['si_id'] = $rdata[7];
            $data['inv_date'] = convertViewDate($rdata[2]);
            $data['inv_balance'] = $rdata[3];
            $data['applied'] = $rdata[4];
            $data['ewt'] = $rdata[5];
            $data['evat'] = $rdata[6];
            
            $this->db->insert('ccm_receipt_t', $data);
            
            $this->updateSalesBalance($data);    
        
        }
        
        
        $this->db->where('receipt_id', $id);
        $this->db->delete('ccm_receipt_c');        
        
        //print_r($rows1);    
        foreach ($rows1 as $row1)
        {
            $rdata = explode('|', $row1);
            
            $data1['receipt_id'] = $id;
            $data1['type_id'] = $rdata[6];
            $data1['bank_id'] = $rdata[7];
            $data1['check_no'] = $rdata[3];
            $data1['check_date'] = convertViewDate($rdata[4]);
            $data1['amount'] = $rdata[5];
            
            $this->db->insert('ccm_receipt_c', $data1);
            
            if ($data1['type_id']=='171')
            {
                $this->db->where('tran_id', $data1['receipt_id']);
                $this->db->delete('maint_cheque');
        
                $company = $this->session->userdata('company');
                $cheque['company_id'] = $company['company_id'];
                $cheque['cheque_no'] = $data1['check_no'];
                $cheque['cheque_date'] = $data1['check_date'];
                $cheque['amount'] = $data1['amount'];
                $cheque['client_id'] = $dt['client_id'];
                $cheque['bank_id'] = $data1['bank_id'];
                $cheque['type_id'] = $data1['type_id'];
                $cheque['tran_id'] = $data1['receipt_id'];
                $cheque['trans_type_id'] = '228';
                $cheque['cleared_date'] = $dt['date'];

                $this->db->insert('maint_cheque', $cheque);
            }
        }
        
        
        $this->db->where('receipt_id', $id);
        $this->db->delete('ccm_receipt_o');    
        
        if ($rows2)
        {        
            foreach ($rows2 as $row2)
            {
                $rdata = explode('|', $row2);
                
                $data2['receipt_id'] = $id;
                $data2['type_id'] = $rdata[6];
                $data2['accnt_id'] = $rdata[7];
                $data2['desc'] = $rdata[4];
                $data2['amount'] = $rdata[5];
                
                $this->db->insert('ccm_receipt_o', $data2);
            }
        }
        
        $this->db->where('receipt_id', $id);
        $this->db->delete('ccm_receipt_map');
        
        if ($rows3)
        {        
            foreach ($rows3 as $row3)
            {
                $rdata = explode('|', $row3);
                
                $data3['receipt_id'] = $id;
                $data3['bank_id'] = $rdata[5];
                $data3['check_no'] = $rdata[2];
                $data3['si_id'] = $rdata[6];
                $data3['amount'] = $rdata[4];
                
                $this->db->insert('ccm_receipt_map', $data3);
            }
        }
    }

and it is passing in the controller with this
Code:
foreach ($fields as $field)
                {
                    if (isset($_POST[$field])) $dt[$field] = $this->input->post($field);
                }
                
                $item = $this->input->post("item");        
                $company = $this->session->userdata('company');
                $dt['company_id'] = $company['company_id'];
                //$dt['sales_date'] = convertDate($this->input->post("sales_date"));
                
                $rows = $this->input->post("row0");    
    
                $data['item'] = $this->CCM_receipt_db->save($dt,$item,$rows,'','','');
#13

[eluser]Ben Edmunds[/eluser]
Where are you calling save_detail() from?
#14

[eluser]maria clara[/eluser]
im calling the save_detail() from the controller with this code:

Code:
case $crudConfig['create']:
                $c = "";
                $data['action'] = $this->input->post('action');
                $item = $this->input->post("item");
                $dt['tran_no'] = $this->input->post('tran_no');
                $ccm_exist = $this->CCM_receipt_db->getDetails($dt);
                
                if ($ccm_exist && $item!=$ccm_exist['receipt_id'])
                {
                    $c .= 'Receipt No. already exists.';
                    $data['action'] = 'exist';
                }
                else
                {
                    $fields = array(
                            "tran_no"
                            ,"client_id"
                            ,"remarks"    
                            ,"inv_total"
                            ,"pay_total"
                            ,"others_total"
                            ,"pdc"
                            ,"cash"
                            ,"ewt"
                            ,"evat"
                            );
                    
                foreach ($fields as $field)
                {
                    if (isset($_POST[$field])) $dt[$field] = $this->input->post($field);
                }
                
                $item = $this->input->post("item");        
                $company = $this->session->userdata('company');
                $dt['company_id'] = $company['company_id'];
                //$dt['sales_date'] = convertDate($this->input->post("sales_date"));
                
                $rows = $this->input->post("row0");    
    
                $data['item'] = $this->CCM_receipt_db->save($dt,$item,$rows,'','','');
                
                //if Sales Invoice type is equal to invoice, auto generate DR
                
                
                
                if($dt['company_id']=='34')
                {    
    
                    $fields = array(
                            "client_id"
                            ,"remarks"
                            ,"gross"
                            );
                    
                    foreach ($fields as $field)
                    {
                        if (isset($_POST[$field])) $dtDR[$field] = $this->input->post($field);
                    }
                    $company = $this->session->userdata('company');
                    $dtDR['company_id'] = $company['company_id'];
                    $dtDR['dr_no'] = "DR-".$dt['tran_no'];
                    $dtDR['dr_date'] = $dt['date'];
                    $dtDR['type_id'] = '108'; //AUTO-DR
                    $dtDR['doc_type_id'] = '89'; //DOC 1
                    
                    $this->CCM_receipt_db->save_DR($dtDR,$rows);
            }

tables are joined so there is a save function when im adding data.
#15

[eluser]saidai jagan[/eluser]
:grrr: wer is that save_detail() u called ?
#16

[eluser]maria clara[/eluser]
[quote author="saidai jagan" date="1263298934"]:grrr: wer is that save_detail() u called ?[/quote]

here is the function save_detail()
Code:
function save_detail($id,$rows0,$rows1,$rows2,$rows3,$dt)
    //function save_detail($id,$rows0=array(),$rows1=array(),$rows2,$rows3,$dt)
    {
        $this->db->where('receipt_id', $id);
        $this->db->delete('ccm_receipt_t');        
        
    //print_r($rows0);
        foreach ($rows0 as $row0)
        {
            $rdata = explode('|', $row);
            
            $data['receipt_id'] = $id;
            $data['si_id'] = $rdata[7];
            $data['inv_date'] = convertViewDate($rdata[2]);
            $data['inv_balance'] = $rdata[3];
            $data['applied'] = $rdata[4];
            $data['ewt'] = $rdata[5];
            $data['evat'] = $rdata[6];
            
            $this->db->insert('ccm_receipt_t', $data);
            
            $this->updateSalesBalance($data);    
        
        }
        
        
        $this->db->where('receipt_id', $id);
        $this->db->delete('ccm_receipt_c');        
        
    //print_r($rows1);    
        foreach ($rows1 as $row1)
        {
            $rdata = explode('|', $row1);
            
            $data1['receipt_id'] = $id;
            $data1['type_id'] = $rdata[6];
            $data1['bank_id'] = $rdata[7];
            $data1['check_no'] = $rdata[3];
            $data1['check_date'] = convertViewDate($rdata[4]);
            $data1['amount'] = $rdata[5];
            
            $this->db->insert('ccm_receipt_c', $data1);
            
            if ($data1['type_id']=='171')
            {
                $this->db->where('tran_id', $data1['receipt_id']);
                $this->db->delete('maint_cheque');
        
                $company = $this->session->userdata('company');
                $cheque['company_id'] = $company['company_id'];
                $cheque['cheque_no'] = $data1['check_no'];
                $cheque['cheque_date'] = $data1['check_date'];
                $cheque['amount'] = $data1['amount'];
                $cheque['client_id'] = $dt['client_id'];
                $cheque['bank_id'] = $data1['bank_id'];
                $cheque['type_id'] = $data1['type_id'];
                $cheque['tran_id'] = $data1['receipt_id'];
                $cheque['trans_type_id'] = '228';
                $cheque['cleared_date'] = $dt['date'];

                $this->db->insert('maint_cheque', $cheque);
            }
        }
        
        
        $this->db->where('receipt_id', $id);
        $this->db->delete('ccm_receipt_o');    
        
        if ($rows2)
        {        
            foreach ($rows2 as $row2)
            {
                $rdata = explode('|', $row2);
                
                $data2['receipt_id'] = $id;
                $data2['type_id'] = $rdata[6];
                $data2['accnt_id'] = $rdata[7];
                $data2['desc'] = $rdata[4];
                $data2['amount'] = $rdata[5];
                
                $this->db->insert('ccm_receipt_o', $data2);
            }
        }
        
        $this->db->where('receipt_id', $id);
        $this->db->delete('ccm_receipt_map');
        
        if ($rows3)
        {        
            foreach ($rows3 as $row3)
            {
                $rdata = explode('|', $row3);
                
                $data3['receipt_id'] = $id;
                $data3['bank_id'] = $rdata[5];
                $data3['check_no'] = $rdata[2];
                $data3['si_id'] = $rdata[6];
                $data3['amount'] = $rdata[4];
                
                $this->db->insert('ccm_receipt_map', $data3);
            }
        }
    }
#17

[eluser]saidai jagan[/eluser]
[quote author="maria clara" date="1263295599"]im calling the save_detail() from the controller with this code:

Code:
case $crudConfig['create']:
                $c = "";
                $data['action'] = $this->input->post('action');
                $item = $this->input->post("item");
                $dt['tran_no'] = $this->input->post('tran_no');
                $ccm_exist = $this->CCM_receipt_db->getDetails($dt);
                
                if ($ccm_exist && $item!=$ccm_exist['receipt_id'])
                {
                    $c .= 'Receipt No. already exists.';
                    $data['action'] = 'exist';
                }
                else
                {
                    $fields = array(
                            "tran_no"
                            ,"client_id"
                            ,"remarks"    
                            ,"inv_total"
                            ,"pay_total"
                            ,"others_total"
                            ,"pdc"
                            ,"cash"
                            ,"ewt"
                            ,"evat"
                            );
                    
                foreach ($fields as $field)
                {
                    if (isset($_POST[$field])) $dt[$field] = $this->input->post($field);
                }
                
                $item = $this->input->post("item");        
                $company = $this->session->userdata('company');
                $dt['company_id'] = $company['company_id'];
                //$dt['sales_date'] = convertDate($this->input->post("sales_date"));
                
                $rows = $this->input->post("row0");    
    
                $data['item'] = $this->CCM_receipt_db->save($dt,$item,$rows,'','','');
                
                //if Sales Invoice type is equal to invoice, auto generate DR
                
                
                
                if($dt['company_id']=='34')
                {    
    
                    $fields = array(
                            "client_id"
                            ,"remarks"
                            ,"gross"
                            );
                    
                    foreach ($fields as $field)
                    {
                        if (isset($_POST[$field])) $dtDR[$field] = $this->input->post($field);
                    }
                    $company = $this->session->userdata('company');
                    $dtDR['company_id'] = $company['company_id'];
                    $dtDR['dr_no'] = "DR-".$dt['tran_no'];
                    $dtDR['dr_date'] = $dt['date'];
                    $dtDR['type_id'] = '108'; //AUTO-DR
                    $dtDR['doc_type_id'] = '89'; //DOC 1
                    
                    $this->CCM_receipt_db->save_DR($dtDR,$rows);
            }

tables are joined so there is a save function when im adding data.[/quote]
In the above code pls point out the save_detail() function.
#18

[eluser]maria clara[/eluser]
this script will save the details
Code:
if($dt['company_id']=='34')
                {    
    
                    $fields = array(
                            "client_id"
                            ,"remarks"
                            ,"gross"
                            );
                    
                    foreach ($fields as $field)
                    {
                        if (isset($_POST[$field])) $dtDR[$field] = $this->input->post($field);
                    }
                    $company = $this->session->userdata('company');
                    $dtDR['company_id'] = $company['company_id'];
                    $dtDR['dr_no'] = "DR-".$dt['tran_no'];
                    $dtDR['dr_date'] = $dt['date'];
                    $dtDR['type_id'] = '108'; //AUTO-DR
                    $dtDR['doc_type_id'] = '89'; //DOC 1
                    
                    $this->CCM_receipt_db->save_DR($dtDR,$rows);
            }

and this code will call the function save_details() in the MODEL
Code:
$this->CCM_receipt_db->save_DR($dtDR,$rows);
#19

[eluser]WebsiteDuck[/eluser]
Lets assume that save_details gets called somewhere...

Code:
$rows = $this->input->post("row0");

If this is what you're passing to it, it probably doesn't contain an array that you can do a foreach on.
#20

[eluser]maria clara[/eluser]
but i can't find where to put that.. all of my tables have the same error about the invalid argument for foreach().




Theme © iAndrew 2016 - Forum software by © MyBB