public function save() { if ($this->validation()) { $json = array(); if (!empty($this->input->post('amount')) && !empty($this->input->post('method')) && !empty($this->input->post('status')) && !empty($this->input->post('depot_id'))) { if (is_numeric($this->input->post('amount'))) { $payment_data = array('created_by' => $this->ion_auth->get_user_id(), 'depot_id' => $this->input->post('depot_id'), 'amount' => $this->input->post('amount'), 'method' => $this->input->post('method'), 'cash_type' => $this->input->post('cash_type'), 'receipt_no' => $this->input->post('receipt_no'), 'cheque_no' => $this->input->post('cheque_no'), 'bank_name' => $this->input->post('bank_name'), 'bank_branch' => $this->input->post('bank_branch'), 'transfer_id' => $this->input->post('transfer_id'), 'date' => convertDMYtoYMD('-', $this->input->post('date')), 'remark' => $this->input->post('remark'), 'status' => $this->input->post('status'), 'date_created' => CURRENT_DATETIME, 'date_modified' => CURRENT_DATETIME); if ($this->input->post('confirm_date') != '' && $this->input->post('confirm_date') != '0000-00-00') { $payment_data['confirm_date'] = convertDMYtoYMD('-', $this->input->post('confirm_date')); } if ($this->ion_auth->is_admin()) { $payment_data['created_at'] = 'admin'; } else { if ($this->ion_auth->is_depot()) { $payment_data['created_at'] = 'depot'; } } if ($this->input->post('status') == 'Pending') { $payment_data['date_pending'] = CURRENT_DATETIME; } else { if ($this->input->post('status') == 'Done') { $payment_data['date_done'] = CURRENT_DATETIME; } } if (!empty($this->input->post('record'))) { $this->query_model->save('depot_payment', $payment_data, $this->input->post('record')); } else { $this->query_model->save('depot_payment', $payment_data); } redirect('payment/view/' . $this->input->post('depot_id')); $json['success'] = 'Added Successfully.'; } else { $json['error'] = 'Please enter a valid amount'; } } else { $json['error'] = 'Please complete all fields'; } $this->output->set_content_type('application/json'); $this->output->set_output(json_encode($json)); } else { $this->data = $_POST; $this->edit($this->input->post('depot_id')); } }
public function preProcessSave() { $field_vardefs = $this->vardefs['fields']; $request_data = $this->request_data; foreach ($request_data as $req_key => $req_val) { if (array_key_exists($req_key, $field_vardefs)) { if (array_key_exists('method', $field_vardefs[$req_key])) { $this->request_data[$req_key] = implode(",", $req_val); } if (array_key_exists('type', $field_vardefs[$req_key])) { if ($field_vardefs[$req_key]['type'] == 'date' || $field_vardefs[$req_key]['type'] == 'datetime') { if (strpos($req_val, '/') !== false) { $this->request_data[$req_key] = convertDMYtoYMD('/', $req_val); } else { $this->request_data[$req_key] = convertDMYtoYMD('-', $req_val); } } } } } $this->preProcessCommon(); }