Nidheesh N Namboodhiri
Nidheesh N Namboodhiri

Reputation: 199

CodeIgniter Data insert is not working

In Codeigniter project ,when inserting multiple fields only one field value is not inserting in the database.

Controller Code For Billing

function billing()
{

    $arrInsert =array();
    $arrtoolsId =array();
    $this->db_session->unset_userdata('tools_cart');
    $arrtoolsId= $this->input->post('productId');
    foreach ($arrtoolsId as $val) {
    $arrToolrow = array();
    $productExclusivePrice =0;
    $arrToolrow =$this->product_model->getRow_products("gp.productId = '$val'");
    $price  =$arrToolrow['productPrice'];
    $actual_price=$this->input->post('actual_price');
    //$price    =$this->input->post('price');
    /////////////////////////////////////////////////////////////////////
    $qty=1;
        ////////////////////////////////////////////////////
    $variant ='';
    $total  = ($price * trim($qty));
    $engineNo=$arrToolrow['engineNo'];
    $vehicleClass               =$arrToolrow['vehicleClass'];
        $manufacturer               =$arrToolrow['manufacturer'];
        $model                      =$arrToolrow['model'];
        //Note variant
        $variant                    = $arrToolrow['hp'];
        $vin                        = $arrToolrow['vin'];
        $wcoNo                      = $arrToolrow['wcoNo'];
        $horsePower                 =$arrToolrow['horsePower'];
        $fuel                       =$arrToolrow['fuel'];
        $noCylinders            =$arrToolrow['noCylinders'];
        $manufactureDate            =$arrToolrow['manufactureDate'];
        $seatCapacity               =$arrToolrow['seatCapacity'];
        $unladenWeight              =$arrToolrow['unladenWeight'];
        $frontAxle                  =$arrToolrow['frontAxle'];
        $rearAxle                   =$arrToolrow['rearAxle'];
        $otherAxle                  =$arrToolrow['otherAxle'];
        $tandemAxle             =$arrToolrow['tandemAxle'];
        $color                      =$arrToolrow['color'];
        $keyNo                      =$arrToolrow['keyNo'];
        $grossVehicleWeight     =$arrToolrow['grossVehicleWeight'];
        $typeofBody             =$arrToolrow['typeofBody'];

    $productExclusivePrice=$arrToolrow['productExclusivePrice'];
    $productTax =  $arrToolrow['productTax'];
    $saleExclusivePrice = ($productExclusivePrice * trim($qty));
    $saleTax    = ($arrToolrow['productTaxamt'] * trim($qty));
    $saleCess   = ($arrToolrow['productCess'] * trim($qty));
        $arrInsert[]    =array (
                "productId" =>$val,
                "engineNo"=>$engineNo,
                "productPrice"  =>round($price,2),
                "productTax"    =>$productTax,
                "saleQty"   =>$qty,
                "salePrice" =>round($total,2),
                "saleTax"=>round($saleTax,2),
                "saleCess"=>round($saleCess,2),
                "saleExclusiveprice"=>round($saleExclusivePrice,2),
                "added_date" =>date("Y-m-d H:i:s"),
                "vehicleClass"              =>$vehicleClass,
                "manufacturer"              =>$manufacturer,
                "model"                     =>$model,
                "variant"                   =>$variant,
                "vin"                       =>$vin,
                "wcoNo"                     =>$wcoNo,
                "horsePower"                =>$horsePower,
                "fuel"                      =>$fuel,
                "noCylinders"               =>$noCylinders,
                "manufactureDate"           =>$manufactureDate,
                "seatCapacity"              =>$seatCapacity,
                "unladenWeight"             =>$unladenWeight,
                "frontAxle"                 =>$frontAxle,
                "rearAxle"                  =>$rearAxle,
                "otherAxle"                 =>$otherAxle,
                "tandemAxle"                =>$tandemAxle,
                "color"                     =>$color,
                "keyNo"                     =>$keyNo,
                "grossVehicleWeight"        =>$grossVehicleWeight,
                "typeofBody"                =>$typeofBody
                );
    }
    $this->db_session->set_userdata('tools_cart',$arrInsert);
    ///////////////////////////////////////////////////////////////////////////////
    $data['list_product']= $this->db_session->userdata('tools_cart');
    $this->load->view('header_login');
    $this->load->view('catalog/billing',$data);
    $this->load->view('footer_login');
}

Screenshot1

Controller Code for Bill(After clicking bill button of the sale page)

function bill()
{

    if($this->db_session->userdata('tools_cart')) {
    $data['list_product']= $this->db_session->userdata('tools_cart');                                                                               
    }else{
        redirect('catalog/sale');
    }       
    $salePrice = $this->input->post('price'); 
    $actual_price=$this->input->post('actual_price');

    ////////////////////////////////////////////////////////////CHANGE HERE
    $saleExclusiveprice = ($salePrice * 100) / 114.5;
    ///////////////////////////////////////////////////////////THIS CAN CHANGE EVERY YEAR            

    //$saleTax = $saleExclusiveprice *(14.5/100);

    //checking tax value with the current date...........
      $arrtax    = $this->tax_model->getTaxList(); 
        foreach($arrtax as $taxvalue) :       
          $currdate =$this->input->post('sale_date') ;       
          if(($taxvalue['fromdate']<=$currdate)&&($currdate<=$taxvalue['todate'])) 
          {
            // print_r($taxvalue['tax']); 
            $saleTax = $saleExclusiveprice *($taxvalue['tax']/100);
            $data['list_product'][0]['taxvalue'] = $taxvalue['tax'];                            
          }           
        endforeach;

    //$saleCess = $saleTax*(1/100);  //ORIGINALLY USED IN 2011
    $saleCess = 0;
    $data['list_product'][0]['salePrice'] = $salePrice;   
    $data['list_product'][0]['saleExclusiveprice'] = round($saleExclusiveprice,2);
    $data['list_product'][0]['saleTax'] = round($saleTax,2);
    $data['list_product'][0]['saleCess'] = round($saleCess,2);      
    $data['list_product'][0]['actual_price']=$this->input->post('actual_price');


        $scheme_id =serialize($arrtoolsId);
        $arrInsert  =array (
                "productId" =>$value['productId'],
                "saleCode"  =>$saleCode,
                "saleQty"   =>$value['saleQty'],
                "salePrice" => $value['salePrice'],
                "saleTax"   => $value['saleTax'],
                "saleCess"  => $value['saleCess'],
                "taxable_price" =>$taxable_price,
                "nontaxable_price" =>$nontaxable_price,
                "saleExclusiveprice"    => $value['saleExclusiveprice'],
                "saleCustomer"=>$saleCustomer,
                "saleUserId"=>$this->input->post('saleUserId'),
                "added_date" =>$date,
                "payType"=>$pay_type,
                "bank_id"=>$bank_id,
                "consultant_id"=>$consultant_id,
                "scheme_id"=>$scheme_id,
                "schemes_amount" => $total,
                "actual_price"  =>$actual_price

                );
        $saleId=0;
            if($this->product_model->insert_sale_entry($arrInsert)){
                    $saleId = $this->db->insert_id() ;
                    $arrStatus  =array (
                            "productSaleStatus" =>1
                                );
                $this->product_model->update_entry($arrStatus,$productId);
            }
    }
        $query  = $this->db->get_where('gm_users',array('userId'=>(int)$this->input->post('saleUserId')));
        if($query->num_rows >0) {
        $arrUser    =$query->row_array();
        }else{
            $arrUser    =array();     
        }   


    /*******************************************************************************/
    $this->db_session->unset_userdata('tools_cart');
    $data['arrtoolsId']     = $arrtoolsId;
    $data['saleCustomer']   =$saleCustomer;
    $data['saleCode']   =$saleCode;
    $data['saleId'] =$saleId;
    $data['saleDate']   =$date;
    $data['userinfo']   =$arrUser;
    $data['bank']       = $bank;
    $data['scheme']     = $schemeName;
    $data['wcoNo']      =$wcoNo;
    $data['actual_price'] =$actual_price;
    $this->load->view('header_login');
    $this->load->view('catalog/bill',$data);
    $this->load->view('footer_login');   
}

I have tried many ways, but its not working.I have hands on experience in Dot net mvc,but its my starting project in codeigniter.I want to know how the data flow works here and how to solve this?Is there any logical mistake i have done?

Model Code

 function insert_sale_entry($data)
{
   if($this->db->insert('gm_sale', $data)){
     return true;
   }
  return false;
}

The error field or the value field which is not inserting

$actual_price=$this->input->post('actual_price');

Upvotes: 0

Views: 450

Answers (1)

Kunal Kinalekar
Kunal Kinalekar

Reputation: 36

Which field is not stored ? can you be more specific. The code appears to store one record at a time and there is only one value which is called from the post variable is what i believe is the problem. Will be able to help you if you can define what is not storing

Upvotes: 1

Related Questions