I have two tables that are related, one of them depends on the information of the 1st table (payments depend on contracts). I just have to take a form to save the information.
This is how I have the registry function in the Controller:
public function registro_contrato()
{
$id_client = $this->Clientes_model->lastID_Cliente();
$clienteid = ($id_client[0]->id_cliente);
$id_dom_instalacion = $this->Clientes_model->lastID_Domicilio();
//Omicion de datos para facil lectura....
$tres_pago = $this->input->post("tres_pago");
//Datos a guardar en la otra tabla
$costo_instalacion = $this->input->post("costo_instalacion");
$monto_anticipo = $this->input->post("monto_anticipo");
$forma_de_pago = $this->input->post("forma_de_pago");
$restante = $this->input->post("restante");
$tres_pagos = $this->input->post("tres_pagos");
if ($this->form_validation->run()) {
$data = array(
'fecha_de_contrato' => $fecha_de_contrato,
//Omicion de datos para facil lectura....
'tres_pago' => $tres_pago,
//Datos a guardar en la otra tabla
'costo_instalacion' => $costo_instalacion,
'monto_anticipo' => $monto_anticipo,
'forma_de_pago' => $forma_de_pago,
'restante' => $restante,
'tres_pagos' => $tres_pagos,
);
if ($this->Clientes_model->save_contrato($data)) {
redirect(base_url() . "clientes/clientes_controller");
} else {
$this->session->set_flashdata("error", "No se pudo guardar la informacion");
redirect(base_url() . "clientes/clientes_controller/agregar_contrato");
}
} else {
$this->agregar_contrato();
}
}
The function in the Model:
public function save_contrato($data)
{
return $this->db->insert("contratos", $data);
}
Currently it works perfect for the saved in the "Contracts" table but I have no idea how to implement the saving of the last 5 registers (and the id as the primary key) in the "Payments" table. I would appreciate a help with it ... Thanks in advance.