"; print_r($invoice); exit(); $customer = $this->admin_model->get_customer_info($invoice->customer, 'customers'); $customer_record = $this->admin_model->get_customer_advanced_record($invoice->customer); if (!empty($this->input->post('is_autoload_amount'))) { $auto_load = $this->input->post('is_autoload_amount'); } else { $auto_load = 0; } $amount_data=array( 'is_autoload_amount' => $auto_load ); $amount_data = $this->security->xss_clean($amount_data); $this->admin_model->edit_option($amount_data, $this->business->id, 'business'); $business = $this->admin_model->get_by_id($this->business->id, 'business'); if (!empty($customer_record) && $customer_record->customer_id == $invoice->customer) { if ($business->is_autoload_amount == 1) { $amount = $this->input->post('amount'); $amount = $customer_record->amount+$amount; }else{ $amount = $this->input->post('amount'); } } else { $amount = $this->input->post('amount'); } if ($invoice->parent_id == 0) { $invoice_id = $invoice->id; } else { $invoice_id = $invoice->parent_id; } if ($this->input->post('payment_method')) { $payment_method = $this->input->post('payment_method'); } else { $payment_method = '0'; } $data=array( 'payment_date' => $this->input->post('payment_date'), 'amount' => $amount, 'convert_amount' => $this->convert_payment($amount, $customer->currency_code), 'customer_id' => $invoice->customer, 'invoice_id' => $invoice_id, 'business_id' => $this->business->uid, 'payment_method' => $payment_method, 'note' => $this->input->post('note'), 'type' => 'income' ); $data = $this->security->xss_clean($data); $id = $this->admin_model->insert($data, 'payment_records'); $total_payment = get_total_invoice_payments($invoice->id, $invoice->parent_id); if($amount == $invoice->grand_total){ $status = 2; if ($business->is_autoload_amount == 1) { $adv_data=array( 'amount' => abs($invoice->grand_total - $amount) ); if (!empty($customer_record) && $customer_record->customer_id == $invoice->customer) { $this->admin_model->edit_option($adv_data, $customer_record->id, 'payment_advance'); } } }else if ($amount > $invoice->grand_total) { $status = 2; if ($business->is_autoload_amount == 1) { $adv_data=array( 'amount' => abs($invoice->grand_total - $amount), 'customer_id' => $invoice->customer, 'business_id' => $this->business->uid, 'created_at' => my_date_now() ); if (empty($customer_record)) { $this->admin_model->insert($adv_data, 'payment_advance'); }else{ $this->admin_model->edit_option($adv_data, $customer_record->id, 'payment_advance'); } } }else if ($amount < $invoice->grand_total) { if ($total_payment == $invoice->grand_total) { $status = 2; } else { $status = 1; } if ($business->is_autoload_amount == 1) { $adv_data=array( 'amount' => abs($invoice->grand_total - $amount) ); if (!empty($customer_record) && $customer_record->customer_id == $invoice->customer) { $this->admin_model->edit_option($adv_data, $customer_record->id, 'payment_advance'); } } } if (empty($this->input->post('due_date'))) { $due_date = date('Y-m-d'); }else{ $due_date = $this->input->post('due_date'); } if ($invoice->recurring == 1 && $status == 2) { $is_completed = 1; } else { $is_completed = 0; } $invoice_data=array( 'status' => $status, 'payment_due' => $due_date, 'is_completed' => 0 ); $this->admin_model->edit_option($invoice_data, $invoice->id, 'invoice'); echo json_encode(array('st' => 1)); } } public function approve_invoice($id) { $invoice = $this->admin_model->get_by_md5_id($id, 'invoice'); $data = array( 'status' => 1 ); $data = $this->security->xss_clean($data); $this->admin_model->edit_option($data, $invoice->id, 'invoice'); echo json_encode(array('st' => 1)); } public function delete($id) { $this->admin_model->delete($id,'invoice'); $this->admin_model->delete_invoice_payments($id,'payment_records'); echo json_encode(array('st' => 1)); } public function delete_payment_record($id) { $this->admin_model->delete($id,'payment_records'); echo json_encode(array('st' => 1)); } }