<?php

use app\libraries\CommonHelper;
use app\libraries\DateHelper;
use app\libraries\Tenants;
use app\libraries\Userstamp;


if (!defined("BASEPATH")) exit("No direct script access allowed");

class Receipt_management_model extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    public function get()
    {
        return $this->db->from("mas_receipt_management")
            ->select("id,toc")
            ->get()
            ->row_array();
    }

    public function insert($params){
        Userstamp::$timestamp = true;
        if (isset($params['created_by'])) {
            $params['created_at'] = $params['create_time'];
            unset($params['id']);
            unset($params['create_time']);
            $this->db->insert("mas_receipt_management", $params);
        } else {
            Userstamp::$timestamp = true;
            $this->db->insert('mas_receipt_management', Userstamp::create($params));
        }

        $params['id'] = $this->db->insert_id();
        return $params;
    }

    public function update($toc, $id)
    {
        $this->db->set("toc", $toc)
            ->where('id', $id)
            ->from("mas_receipt_management")
            ->update();
    }

    public function one(){
        return $this->getAll("default","receipt_management",[],[]);
     }
}
