<?php
/*
 * Copyright (C) 2018 josh.north@point808.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace App\LobbySIO\Database;
use App\LobbySIO\Config\Registry;

/**
 * Perform visit actions (approve/void/end/new)
 *
 * @author josh.north
 */

class VisitActions {

    public function endVisit ($visitid, $outtime) {
        $query = "
            UPDATE " . Registry::DB_PRFX . "visits
            SET " . Registry::DB_PRFX . "visits.outtime = \"$outtime\"
            WHERE " . Registry::DB_PRFX . "visits.id = \"$visitid\"
        ";
        $database = new \App\LobbySIO\Database\Connect();
        $count = $database->runQuery($query);
        return $count;
    }

    public function voidVisit ($visitid, $approved, $notes) {
        $query = "
            UPDATE " . Registry::DB_PRFX . "visits
            SET
            " . Registry::DB_PRFX . "visits.approved = \"$approved\",
            " . Registry::DB_PRFX . "visits.notes = \"$notes\"
            WHERE " . Registry::DB_PRFX . "visits.id = \"$visitid\"
        ";
        $database = new \App\LobbySIO\Database\Connect();
        $count = $database->runQuery($query);
        return $count;
    }
    
    public function approveVisit ($approvevisit, $id_type, $id_reference, $citizen, $badge, $initials, $approved) {
        $query = "
            UPDATE " . Registry::DB_PRFX . "visits
            SET
            " . Registry::DB_PRFX . "visits.initials = \"$initials\",
            " . Registry::DB_PRFX . "visits.approved = \"$approved\",
            " . Registry::DB_PRFX . "visits.id_type = \"$id_type\",
            " . Registry::DB_PRFX . "visits.id_reference = \"$id_reference\",
            " . Registry::DB_PRFX . "visits.badge = \"$badge\",
            " . Registry::DB_PRFX . "visits.citizen = \"$citizen\"
            WHERE " . Registry::DB_PRFX . "visits.id = \"$approvevisit\"
        ";
        $database = new \App\LobbySIO\Database\Connect();
        $count = $database->runQuery($query);
        return $count;
    }

    public function newVisit ($firstname, $lastname, $company, $reason, $intime, $signature, $siteid, $approved, $escort_signature, $escort, $carnum, $ssanum, $isvendor) {
        $query = "
            INSERT INTO " . Registry::DB_PRFX . "visits (" . Registry::DB_PRFX . "visits.firstname, " . Registry::DB_PRFX . "visits.lastname,
            " . Registry::DB_PRFX . "visits.company, " . Registry::DB_PRFX . "visits.reason, " . Registry::DB_PRFX . "visits.intime,
            " . Registry::DB_PRFX . "visits.signature, " . Registry::DB_PRFX . "visits.site_id, " . Registry::DB_PRFX . "visits.approved,
            " . Registry::DB_PRFX . "visits.escort_signature, " . Registry::DB_PRFX . "visits.escort, " . Registry::DB_PRFX . "visits.carnum, " . Registry::DB_PRFX . "visits.ssanum, " . Registry::DB_PRFX . "visits.isvendor)
            VALUES (\"$firstname\", \"$lastname\", \"$company\", \"$reason\", \"$intime\", \"$signature\", \"$siteid\",
            \"$approved\", \"$escort_signature\", \"$escort\", \"$carnum\", \"$ssanum\", \"$isvendor\")
        ";
        $database = new \App\LobbySIO\Database\Connect();
        $lastVisitId = $database->runQueryWithId($query);
        return $lastVisitId;
    }


    public function setInfoVendorVisitNew ($db_vendorinfo_visitid, $db_vendorinfo_contact1, $db_vendorinfo_contact2, $db_vendorinfo_workstart, $db_vendorinfo_workend, $db_vendorinfo_customerimpacted) {
      $query = "
        INSERT INTO " . Registry::DB_PRFX . "vendorinfo (
          " . Registry::DB_PRFX . "vendorinfo.visitid,
          " . Registry::DB_PRFX . "vendorinfo.contact1,
          " . Registry::DB_PRFX . "vendorinfo.contact2,
          " . Registry::DB_PRFX . "vendorinfo.workstart,
          " . Registry::DB_PRFX . "vendorinfo.workend,
          " . Registry::DB_PRFX . "vendorinfo.customerimpacted)
        VALUES (
          \"$db_vendorinfo_visitid\",
          \"$db_vendorinfo_contact1\",
          \"$db_vendorinfo_contact2\",
          \"$db_vendorinfo_workstart\",
          \"$db_vendorinfo_workend\",
          \"$db_vendorinfo_customerimpacted\")
        ";
      $database = new \App\LobbySIO\Database\Connect();
      $db_vendorinfo_lastid = $database->runQueryWithId($query);
      return $db_vendorinfo_lastid;
    }


    
    
    
    
    
    
    
    
    
    
    
    public function setInfoVendorVisitInitial ($id, $db_vendorinfo_checklistrequired, $db_vendorinfo_routinework, $db_vendorinfo_nonroutinework, $db_vendorinfo_coi, $db_vendorinfo_worksummary, $db_vendorinfo_equipmentsummary) {
        $query = "
            UPDATE " . Registry::DB_PRFX . "vendorinfo
            SET
            " . Registry::DB_PRFX . "vendorinfo.checklistrequired = \"$db_vendorinfo_checklistrequired\",
            " . Registry::DB_PRFX . "vendorinfo.routinework = \"$db_vendorinfo_routinework\",
            " . Registry::DB_PRFX . "vendorinfo.nonroutinework = \"$db_vendorinfo_nonroutinework\",
            " . Registry::DB_PRFX . "vendorinfo.coi = \"$db_vendorinfo_coi\",
            " . Registry::DB_PRFX . "vendorinfo.worksummary = \"$db_vendorinfo_worksummary\",
            " . Registry::DB_PRFX . "vendorinfo.equipmentsummary = \"$db_vendorinfo_equipmentsummary\"
            WHERE " . Registry::DB_PRFX . "vendorinfo.id = \"$id\"
        ";
        $database = new \App\LobbySIO\Database\Connect();
        $count = $database->runQuery($query);
        //return $count;
    }
    
    public function setInfoVendorVisitFinal ($id, $db_vendorinfo_checklistcompleted, $db_vendorinfo_workcompleted, $db_vendorinfo_sitecleanup, $db_vendorinfo_approverid, $db_vendorinfo_doccompleted) {
        $query = "
            UPDATE " . Registry::DB_PRFX . "vendorinfo
            SET
            " . Registry::DB_PRFX . "vendorinfo.checklistcompleted = \"$db_vendorinfo_checklistcompleted\",
            " . Registry::DB_PRFX . "vendorinfo.workcompleted = \"$db_vendorinfo_workcompleted\",
            " . Registry::DB_PRFX . "vendorinfo.sitecleanup = \"$db_vendorinfo_sitecleanup\",
            " . Registry::DB_PRFX . "vendorinfo.approverid = \"$db_vendorinfo_approverid\",
            " . Registry::DB_PRFX . "vendorinfo.doccompleted = \"$db_vendorinfo_doccompleted\"
            WHERE " . Registry::DB_PRFX . "vendorinfo.id = \"$id\"
        ";
        $database = new \App\LobbySIO\Database\Connect();
        $count = $database->runQuery($query);
        //return $count;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    }
