<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Invoice_management extends MY_BackendController
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('Invoice_management_model');  
    }

    public function index()
    {
        $im = $this->Invoice_management_model->one();
        $id = $im['id']??'';
        $toc = $im['toc']??'';
        $action = empty($id)?'insert':'save';
        $this->view('backend/invoice_management/index',['id'=>$id,'toc'=>$toc, 'action'=>$action]);
    }
    
    public function insert(){
        $this->Invoice_management_model->insert(array_merge(['tenant_no'=>$this->session->userdata('tenant_no')],$this->input->post()));
        header('location:/invoice_management');
    }
    
    public function save(){
        $this->Invoice_management_model->save(array_merge(['tenant_no'=>$this->session->userdata('tenant_no')],$this->input->post()),$this->input->post('id'));
        header('location:/invoice_management');
    }
}