Welcome Guest, Not a member yet? Register   Sign In
Using foreach in REST API Codeigniter
#1

Hi,
  I'm using rest API (not any library just core PHP). I'm working on invoice creation (Order) through Mobile App, how do i make it work.

Controller Page :

public function save1(){

$insertdata = array(
  'invoice_no' => $this->input->post('pid'),
  'invoice_date' => date('Y-m-d', strtotime($this->input->post('pdate'))),
  'customer_id' => $this->input->post('customer_id'),
  'customer_name' => $this->input->post('customer_name'),
  'customer_address' => $this->input->post('customer_address'),
  'customer_city' => $this->input->post('customer_city'),
  'customer_state' => $this->input->post('customer_state'),
  'customer_pincode' => $this->input->post('customer_pincode'),
  'customer_phone_no' => $this->input->post('customer_phone_no'),
  'customer_type' => $this->input->post('customer_type'),
  'invoice_sub_total' => $this->input->post('subtot'),
  'total_sgst' => $this->input->post('sgst_tot'),
  'total_cgst' => $this->input->post('cgst_tot'),
  'invoice_total' => $this->input->post('total'),
  //'duedate' =>date('Y-m-d', strtotime($this->input->post('duedate'))),
  'customer_shipping_address' => $this->input->post('customer_shipping_address'),
  'customer_shipping_city' => $this->input->post('customer_shipping_city'),
  'customer_shipping_state' => $this->input->post('customer_shipping_state'),
  'customer_shipping_pincode' => $this->input->post('customer_shipping_pincode'),
  'customer_shipping_phone_no' => $this->input->post('customer_shipping_phone_no'),
  'payment_mode' => $this->input->post('mode'),
  'transaction_details' => $this->input->post('transaction_details'),
  'invoice_status' => $this->input->post('invoice_status'));

$this->load->model("Model_invoice");
$this->Model_invoice->insert_data($insertdata);

 

  $tc = $this->input->post('tc');
  for ($x=1; $x<$tc; $x++)
    {
        $purchase_item = array(
          'invoice_no'    => $this->input->post('pid'),
          'invoice_date' => date('Y-m-d', strtotime($this->input->post('pdate'))),
          'product_id'  => $this->input->post('p_id'.$x),
          'seller_id'  => $this->input->post('seller_id'.$x),
          'product_name'    => $this->input->post('pname'.$x),
          'product_price'    => $this->input->post('p_price'.$x),
          'product_quantity'    => $this->input->post('qty'.$x),
          'sub_total'    => $this->input->post('stot'.$x),
          'sgst_tax'    => $this->input->post('sgst'.$x),
          'sgst_amount'    => $this->input->post('sgst_amt'.$x),
          'cgst_tax'    => $this->input->post('cgst'.$x),
          'cgst_amount'    => $this->input->post('cgst_amt'.$x),
          'total_price'    => $this->input->post('tot'.$x),
          //'status'    => $status       
        ); 

        $this->Model_invoice->insert_invoice_details($purchase_item);

        $ppid = $this->input->post('p_id'.$x);
        $qty = $this->input->post('qty'.$x);
        $dat1 = $this->Model_invoice->getpro($ppid);
        foreach ($dat1 as $row)
        {
        $qty1 = $row->quantity - $qty;

        $pro_up=array(
          'quantity'    => $qty1,
        ); 
        $this->Model_invoice->update_product_stock(array('product_id' => $this->input->post('p_id'.$x)), $pro_up);           
        }

    }


    $view1="Bill Saved Successfully";
      echo json_encode($view1);
}



Model Page :

public function insert_data($data)
    {
        $this->db->insert("invoice_info",$data);       
        $id = $this->db->insert_id();         
        // return (isset($id)) ? $id : FALSE;
    }

    // insert_purchase_item renamed to ...
    public function insert_invoice_details($data)
    {
        $this->db->insert("invoice_details",$data);
    }



public function update_product_stock($where, $data) {
      $this->db->update($this->products_info, $data, $where);
      return $this->db->affected_rows();
    }
Reply
#2

i have completed this.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB