<?php
// require_once('basic-function.php');
class investment_plan extends basicFunction 
{
    use table_names;

    public function create($name)
    {
        $vals = [$name];
        $if_empty = $this->if_empty($vals);
        if (!$if_empty) {
            return $this->errorMsgs(1);
        }
        
        $name_exist = $this->selectWhereDlt($this->investment_plan_tb,'name',$name);
        if(count($name_exist) > 0){
            return $this->errorMsgs(16);
        }

        $unique_id = $this->rand_id();
        $date_created = $this->todayDate();
        $query = "INSERT INTO $this->investment_plan_tb VALUES (null,
        '".mysqli_real_escape_string($this->connectDb(),$unique_id)."',
        '".mysqli_real_escape_string($this->connectDb(),$name)."',
        '".mysqli_real_escape_string($this->connectDb(),0)."',
        '".mysqli_real_escape_string($this->connectDb(),$date_created)."',
        '".mysqli_real_escape_string($this->connectDb(),$date_created)."') ";
        mysqli_close($this->connectDb());
        if($this->sqlQuery($query)){
            return $this->successMsg('Investment Plan');
        }else{
            return $this->errorMsgs(14);
        }
    }
    public function edit($id,$name)
    {
        $vals = [$id];
        $if_empty = $this->if_empty($vals);
        if (!$if_empty) {
            return $this->errorMsgs(15);
        }
        $vals = [$name];
        $if_empty = $this->if_empty($vals);
        if (!$if_empty) {
            return $this->errorMsgs(1);
        }
        $name_exist = $this->selectWhereDlt($this->investment_plan_tb,'name',$name);
        if(count($name_exist) > 0){
            return $this->errorMsgs(16);
        }

        $fields = ['name'];
        $values = [$name];
        $update_coin = $this->update_where( $this->investment_plan_tb,$fields,$values,'unique_id',$id);
        if($update_coin['error'] == 1){
            return $update_coin;
        }
        return $this->successMsg2('Investment Edit');
    }
    public function delete($id)
    {
        $vals = [$id];
        $if_empty = $this->if_empty($vals);
        if (!$if_empty) {
            return $this->errorMsgs(15);
        }
        $fields = ['is_deleted'];
        $values = ['1'];
        $investment_update = $this->update_tbs( $this->investment_plan_tb,$fields,$values,$id);
        if($investment_update['error'] == 1){
            return $investment_update;
        }
        return $this->dltSuccessMsg();
    }
    
}
$investment_plan = new investment_plan();