<?php
include_once '../includes/config.php';
include_once '../includes/database.php';
include_once '../includes/check_session.php';
include_once '../includes/auth.php';

$auth = array('manager');
$authRes = checkAuth($auth, $user);
if(!$authRes)
{
    header('Location: ' . DOMAIN . '/auth/login.php');
    exit;
}

include_once '../includes/check_paid.php';

class Add extends database
{
   
    public function insertData($userID, $companyID)
        {
            return $this->insert('tb_order', ['cl_status' => 'New', 'cl_user_id' => $userID, 'cl_company_id' => $companyID]);
        }
    
}

$obj = new Add();
if(isset($_POST['submit']))
{
    $orderID = $obj->insertData($user['cl_id'], $user['cl_user_id']);
    if($orderID)
    {
        header('Location: ' . DOMAIN . '/orders/edit.php?id=' . $orderID);
    }
}





 include '../header.php';
 ?>
<div class="content-wrapper">
            <!-- Content -->

            <div class="container-xxl flex-grow-1 container-p-y">
              <h4 class="fw-bold py-3 mb-4">Add Order</h4>
                

              <!-- Basic Layout -->
              <div class="row">
				
                   
                    <div class="col-sm-12">
                    	<div class="order-contact">
                        	<div class="row edit-user-box">
                                <div class="col-sm-12">
                                    <div class="row">
									
                                        <form class="col-sm-6" method="POST">
                                            <button type="submit" name="submit" class="btn btn-success ">Create a New Order</button>
                                        </form>
                                    </div>
                            	</div>
                        	</div>                            
                        </div>
                    </div>
                </div>
                
                
            </div>
        </div>

<script>
    $(document).ready(function(){
        $('.btn-remove').click(function(){
            var parent = $(this).parents('tr').first();
            var conf = confirm("Are you sure you want to delete this item?");
            if(conf)
            {
                var href = $(this).attr('data-href');
                $.post(href, function(res){
                    alert("Deletion Successful");
                    $(parent).remove();
                },'json').fail(function(xhr){
                   alert(xhr.responseJSON);
                },'json');
            }
        });
    });
	
    </script>

    <script>
    $(document).ready(function(){
        $('.menu-item').removeClass('active');
        $('#item-menu').addClass('active');
    }); 
</script>
<?php include '../footer.php';?>