<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <script src="https://www.google.com/recaptcha/api.js?render=6Lea-cUUAAAAALqo7u2IKZr5JYp2LdkEuylmuT8e"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Dashboard</title>
    <meta name="description" content="Lawn Mower - Petrol" />
    <meta name="keywords" content="LAWN MOWER petrol" />
    <meta name="robots" content="INDEX,FOLLOW" />
    <link rel="icon" href="https://www.completehire.com.au/media/favicon/default/ch_1.png" type="image/x-icon" />
    <link rel="shortcut icon" href="https://www.completehire.com.au/media/favicon/default/ch_1.png"
        type="image/x-icon" />
    <!--[if lt IE 7]>
<script type="text/javascript">
//<![CDATA[
    var BLANK_URL = 'https://www.completehire.com.au/js/blank.html';
    var BLANK_IMG = 'https://www.completehire.com.au/js/spacer.gif';
//]]>
</script>
<![endif]-->

    <link rel="stylesheet" type="text/css"
        href="https://www.completehire.com.au/media/css/e9411e85deedf5303a337838822a58d8-1-SSL-1586867774.css?6560019944e61" />
    <link rel="stylesheet" type="text/css"
        href="https://www.completehire.com.au/media/css/c2c1964ba379ccf27d2a5b16848e750b-1-SSL-1688620731.css?6560019944e61"
        media="all" />
    <script type="text/javascript" src="https://www.completehire.com.au/js/prototype/prototype.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/lib/jquery/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/lib/jquery/noconflict.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/lib/ccard.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/prototype/validation.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/scriptaculous/builder.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/scriptaculous/effects.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/scriptaculous/dragdrop.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/scriptaculous/controls.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/scriptaculous/slider.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/varien/js.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/varien/form.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/mage/translate.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/mage/cookies.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/varien/product.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/varien/product_options.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/varien/configurable.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/calendar/calendar.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/js/calendar/calendar-setup.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/onewest/default/js/slick.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/onewest/default/js/onewest.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/base/default/js/fake-00003.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/onewest/default/extensions/jquery-validation/jquery.validate.min.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/onewest/default/extensions/jquery-validation/additional-methods.min.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/rwd/default/js/lib/modernizr.custom.min.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/rwd/default/js/lib/selectivizr.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/rwd/default/js/lib/matchMedia.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/rwd/default/js/lib/matchMedia.addListener.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/rwd/default/js/lib/enquire.js"></script>
    <script type="text/javascript" src="https://www.completehire.com.au/skin/frontend/rwd/default/js/app.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/rwd/default/js/lib/jquery.cycle2.min.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/rwd/default/js/lib/jquery.cycle2.swipe.min.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/rwd/default/js/slideshow.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/onewest/default/js/bootstrap.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/rwd/default/js/lib/imagesloaded.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/rwd/default/js/minicart.js"></script>
    <script type="text/javascript"
        src="https://www.completehire.com.au/skin/frontend/rwd/default/js/lib/elevatezoom/jquery.elevateZoom-3.0.8.min.js"></script>
        <script type="text/javascript"
        src="test.js"></script>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Anton" />
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Heebo:300,400,500,700" />
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway:300,400,500,700,600" />
    <link rel="canonical" href="https://www.completehire.com.au/lawn-mower-petrol-3447" />
    <link rel="stylesheet" href="test.css" />
    <!--[if  (lte IE 8) & (!IEMobile)]>
<link rel="stylesheet" type="text/css" href="https://www.completehire.com.au/media/css/77768f43239ba847e1b4ec12a1d795e6-1-SSL-1551839727.css?6560019944e61" media="all" />
<![endif]-->
    <!--[if (gte IE 9) | (IEMobile)]><!-->
    <link rel="stylesheet" type="text/css"
        href="https://www.completehire.com.au/media/css/eed67cf2e1aa2fb3942ef5ada5c54ac6-1-SSL-1688620581.css?6560019944e61"
        media="all" />
    <!--<![endif]-->

    <script type="text/javascript">
        //<![CDATA[
        Mage.Cookies.path = '/';
        Mage.Cookies.domain = '.www.completehire.com.au';
        //]]>


    </script>
    <meta name="viewport" content="initial-scale=1.0, width=device-width" />

    <script type="text/javascript">
        //<![CDATA[
        optionalZipCountries = ["AU"];
        //]]>
    </script>
    <script type="text/javascript">//<![CDATA[
        var Translator = new Translate([]);
        //]]></script>
    <script type="text/javascript" src="https://www.milawig.com/js/validation.js"></script>
</head>

<body
    class=" catalog-product-view catalog-product-view product-lawn-mower-petrol-3447 categorypath-products-landscaping category-landscaping">
    <div class="wrapper">
        <noscript>
            <div class="global-site-notice noscript">
                <div class="notice-inner">
                    <p>
                        <strong>JavaScript seems to be disabled in your browser.</strong><br />
                        You must have JavaScript enabled in your browser to utilize the functionality of this website.
                    </p>
                </div>
            </div>
        </noscript>

            <header id="header" class="page-header">
                <div id="page-header-container-new-div" class="page-header-container">
                    <div>
                        <a id="header-logo-a" href="/">
                            <img src="https://www.completehire.com.au/skin/frontend/onewest/default/images/page-elements/CH-logo-header.svg"
                                alt="Complete Hire" class="img-responsive" width="295">
                        </a>
                    </div>
                    <div class = "big_dashboard_text">DASHBOARD</div>

                    <div id="newhomepage-nav-outer-div">
                        <!-- Navigation -->
                        <div id="header-nav" class="skip-content newhomepage-nav">

                       </div>

                </div>
            </header>

    <script type="text/javascript" src="https://www.milawig.com/js/validation.js"></script>
</body>

</html>
<?php
    //sleep(3);
    /* Database credentials. Assuming you are running MySQL
    server with default setting (user 'root' with no password) */
    define('DB_SERVER', 'localhost');
    define('DB_USERNAME', 'itiseasy_chire2');
    define('DB_PASSWORD', 'cMr~ezrpG.@)');
    define('DB_NAME', 'itiseasy_chire2');
    require_once "vendor/stripe/stripe-php/init.php";
    $stripe = new \Stripe\StripeClient('sk_test_51OCubSK8ETdQ9853uIY4vlOdAG5p8fvkfmuRu1IlMsUUzlvNGVIecfBKbTGKxF43Z3xzQAEoGkAC9QNxN9kdUpTs00CYRQmCkw');
    /*$stripe->prices->create([
      'currency' => 'usd',
      'unit_amount' => 1000,
      'product' => 'prod_P2qGy9gmFkWXAe',
    ]);*/
    /* Attempt to connect to MySQL database */
    $link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
     
    // Check connection
    if($link === false){
        die("ERROR: Could not connect. " . mysqli_connect_error());
    }
   $sql = 'SELECT * FROM bookings';
   //mysqli_select_db($link,'chire_test1');
   $retval = mysqli_query( $link, $sql );

   
   if(! $retval ) {
      die('Could not get data: ' . mysql_error());
   }

/*    
    $url = $stripe->paymentLinks->create([
      'line_items' => [
        [
          'price' => 'price_1OF7mCK8ETdQ9853KEh4gG21',
          'quantity' => 1,
        ],
      ],
    ]);
    print_r(($url->url));*/
    echo "<h1 class = 'processed_h1'>------------------  New Bookings  ------------------</h1>";
   echo "<div class = 'maximo_div'><ul>";
/*    echo "<li class = 'title_bar'>
            <label> Name </label>
            <label> Mobile</label>
            <label> Email</label>
            <label>Location</label>
            <label> Hire Dates</label>
            <label> Process</label>
            </li>";*/
            
            
   while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) {
        $this_row = $row['request_id'];
        //echo $row['accepted'];
        $last_processed = "";
        //echo isset($_GET[$this_row]),"<br>";
        if (isset($_GET[$this_row])){
            //echo "djskdjakdjasd";
            $last_processed = $this_row;
            /*echo $_GET[$this_row];*/
            if ($_GET[$this_row] != "false"){
                //update user id and product price
            	global $stripe;
            	
            	$c_id = $row['customer_id'];
            	if ($c_id == NULL) {
            	   $test_customer = $stripe->customers->create([ 
                    //'description' => 'My First Test Customer (created for API docs at https://www.stripe.com/docs/api)',
                    'email' => $row['email'],
                    'name' => $row['full_name'],
                    'phone' => $row['mobile'],
                   ]);
                   $sql_update_customer = "UPDATE bookings SET customer_id = '$test_customer->id' WHERE request_id = $this_row;";
            	} else {
            	    $test_customer = $stripe->customers->retrieve(
            	        $c_id,
            	        []
            	   );
            	}
        	    
        	   // $test_customer = $stripe->customers->create([ 
            //         //'description' => 'My First Test Customer (created for API docs at https://www.stripe.com/docs/api)',
            //         'email' => $row['email'],
            //         'name' => $row['full_name'],
            //     ]);
                $p_id = $row['product_id'];
                $test_product = $stripe->products->retrieve(
                    $p_id,
                    []
                );
    /*            echo $test_product->name;*/
                //print_r($test_product);
                
                $test_price = $stripe->prices->search([
                  'query' => "product: '$p_id'",
                ]);
                $price_id = $test_price['data'][0]->id;
             /*   print_r($test_price['data'][0]->id);*/
                //find the date differences
                $start_hire = strtotime($row['start_hire']);
                $end_hire = strtotime($row['end_hire']);
                $hire_length_in_days = ($end_hire-$start_hire)/86400;
                //echo "Days: $hire_length_in_days";
                
                $sql_update_accept = "UPDATE bookings SET status = 1 WHERE request_id = $this_row;";
                // $sql_update_customer = "UPDATE bookings SET customer_id = '$test_customer->id' WHERE request_id = $this_row;";
                
                
                //$sql_update_price = "UPDATE bookings SET product_id = '$price_id' WHERE request_id = $this_row;";
                /*
                    UPDATE bookings SET customer_id = 'potato' WHERE request_id = 9;
                    UPDATE bookings SET price_id = price_1OEkZuK8ETdQ98530ZjRZs58 WHERE request_id = $this_row;*/
                $something = mysqli_query( $link, $sql_update_accept );
                $something = mysqli_query( $link, $sql_update_customer );
                //$something = mysqli_query( $link, $sql_update_price );
               if(! $something ) {
                    die('Could not get data: ' . mysql_error());
                }
                //echo "potato";
                $shipping_rate = "";
                
                // no idea how to make these actually work
                // $stripe->shippingRates->all(['data' => ['active' => true]])
                // $stripe->shippingRates->all(['active' => true])
                foreach ($stripe->shippingRates->all() as $s_rate){
                    //$shipping_rate = $s_rate->amount;
                   //echo $s_rate->display_name;
                    if($s_rate->id == $_GET['s_rates']){
                        //echo $shipping_rate;
                        $shipping_rate = $s_rate->id;
                        //echo "anuthing";   
                    }
                    
                }
                $invoice = $stripe->invoices->create(
                    [
/*                    'lines'->'data' => 'price',*/
                    'customer' => $test_customer->id,
                    'currency' => "aud",
                    'shipping_cost' => ['shipping_rate' => "$shipping_rate"],
                    //'price' => "price_1OEkZuK8ETdQ98530ZjRZs58",
                    'collection_method'=>"send_invoice",
                    'days_until_due'=>5,
                ]);
                // $discount_rate = 5;
                // if($hire_length_in_days>=7){
                    $discount_rate = $_GET['discounts'];
                    /*echo "5% discount applied";*/
                    if ($discount_rate != 0) {
                        $test_discount = $stripe->coupons->create([
                          'percent_off' => $discount_rate,
                          'duration' => 'once',
                        ]);
                        $invoiceItem = $stripe->invoiceItems->create([
                          'customer' => $test_customer->id,
                          'invoice' => $invoice->id,
                          'price' => $price_id,
                          'quantity' => $hire_length_in_days,
                          'discounts' => [['coupon'=>"$test_discount->id"]]
                        ]);
                    }
                    else{
                        /*echo "no discount applied";*/
                      $invoiceItem = $stripe->invoiceItems->create([
                      'customer' => $test_customer->id,
                      'invoice' => $invoice->id,
                      'price' => $price_id,
                      'quantity' => $hire_length_in_days,
                      //'discounts' => [['coupon'=>"$test_discount->id"]]
                    ]);
                    }
                // }
                // else{
                //     /*echo "no discount applied";*/
                //   $invoiceItem = $stripe->invoiceItems->create([
                //   'customer' => $test_customer->id,
                //   'invoice' => $invoice->id,
                //   'price' => $price_id,
                //   'quantity' => $hire_length_in_days,
                //   //'discounts' => [['coupon'=>"$test_discount->id"]]
                // ]);
                // }

                $invoice->sendInvoice();
                //echo $invoice->lines->data[id];
/*                $newPrice = $stripe->prices->retrieve(
                    'price_1OCvMnK8ETdQ9853gUvi3T89',
                    []
                );
                $newInvoice = $stripe->invoices->allLines(
                    $invoice->id,
                    []
                );*/
                //echo $newInvoice;
                //echo $newPrice;
            }
            
            //$something = mysqli_query( $link, $sql_update_accept );

            //echo $this_row;
            $sql_update_accept = "UPDATE bookings SET processed = 1 WHERE request_id = $this_row";
            $something = mysqli_query( $link, $sql_update_accept );
               if(! $something ) {
                    die('Could not get data: ' . mysql_error());
                }
                //buttonAccept();
                

        }
        /*<label> {$row['full_name']}</label>*/
       if($row['processed']==0 && $last_processed!=$this_row){
            $p_id = $row['product_id'];
            $test_product = $stripe->products->retrieve(
                $p_id,
                []
            );
                $test_price = $stripe->prices->search([
                  'query' => "product: '$p_id'"
                ]);
                $price_id = $test_price['data'][0]->id;
            $current_price = $test_price['data'][0]->unit_amount;
            
            $start_hire = strtotime($row['start_hire']);
            $end_hire = strtotime($row['end_hire']);
            
            $hire_length_in_days = ($end_hire-$start_hire)/86400;
            
            // if ($hire_length_in_days>=7) {
            //     // $value = ($current_price/100)*$hire_length_in_days;
            //     $minus_val = (($current_price/100)*$hire_length_in_days)*($weekly_discount_percent/100);
            //     $norm_val = ($current_price/100)*$hire_length_in_days;
            //     $value = $norm_val - $minus_val;
            // } else {
                $value = ($current_price/100)*$hire_length_in_days;
            // }
            
            //print_r($stripe->shippingRates->all(['limit' => 3]));
            /*$shipping_rate = "";
            foreach( $stripe->shippingRates->all(['limit' => 3]) as $s_rate){
                $shipping_rate = $s_rate->amount;
               
                if($s_rate->display_name == "CustomTest"){
                    
                }
                echo $shipping_rate;
            }
            print_r($stripe->shippingRates->update(
                $shipping_rate,
                ['metadata' => [
                    'order_id'=>6573
                    ]
                ]
            ));
            */

            
/*            print_r($test_product->images);
            print_r($test_product->images[0]);*/
            $img_url = $test_product->images[0];

           echo "<li><div class = 'top-div'><span>{$row['full_name']}</span><span>$test_product->name</span><div class = 'arrow'><span class = 'l-span'></span><span class = 'r-span'></span></div></div><div class = 'bottom-div'>
            <table>
            <tr>
                <td>
                
            <div><label>Name:</label> {$row['full_name']}</div>
            <div><label>Mobile:</label> {$row['mobile']}</div>
            <div><label>Email:</label> {$row['email']}</div>
           <div> <label>Location:</label> {$row['location_of_hire']}</div>
             <div><label>Dates:</label> {$row['start_hire']} to  {$row['end_hire']}</div>
             <div> <label>Notes:</label> {$row['notes']}</div>

             <div>
              <form method = 'get' name = 'form' action = '?$this_row=true'>
              <input type = 'hidden' name = '$this_row' value = 'true'>
              <label for='t_cost'>Total Cost:</label>

              <!-- <input type='text' value = '$value' id='t_cost' name='t_cost'> -->
              <span>$value</span>
              
              <br>
              <label for='s_rates'>Shipping:</label>
            <select name='s_rates' id='s_rates'>
                
            ";
            
            foreach($stripe->shippingRates->all() as $s_rate){
                echo"<option value='$s_rate->id'>$s_rate->display_name</option>";
            }
            echo "
            </select>
            <br>
            
            <label for='discounts'>Discount (%):</label>
            <select name='discounts' id='discounts' value='1'>
            ";
            
            $discount_array = array(0, 5, 10, 15, 20);
            
            foreach($discount_array as $d){
                echo"<option value='$d'>$d</option>";
            }
            echo "
            </select>
            
            
            <br>
            <input class = 'random_class' type='submit' value = 'Accept'>
            </form>
            <a href = '?$this_row=false'> <button>Decline</button></a>
            
            </td>


            </div></tr>
            <tr>

            </tr>
            </table></li>";
            /*            <td class = 'button-column' >
            <div>

            </div>
            
            
            </td>*/
            /*href='?$this_row=true*/
            /*?$this_row=false*/
          //echo $_GET['s_rates'];
            /*            <td class = 'p_image'>
                <img src = $img_url/>
                </td>*/
            
       }
      
   }
   
   echo "</ul><h1 class = 'processed_h1'>------------------  Processed  ------------------</h1><ul><table>
    <tr>
        <th><b>Name</b></th>
        <th><b>Number</b></th>
        <th><b>Email</b></th>
        <th><b>Address</b></th>
        <th><b>Status</b></th>
    </tr>";
   $retval = mysqli_query( $link, $sql );
   while($new_row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) {
       //echo "this works";
       if($new_row['processed']==1){
           echo "<tr>";
           
           if($new_row['status']==1){
               echo "<td><label>{$new_row['full_name']}</td></label>
               <td><label>{$new_row['mobile']}</td></label>
               <td><label>{$new_row['email']}</td></label>
                <td><label>{$new_row['location_of_hire']}</td></label>
               <td><span style = 'color:green'>Accepted</span></td></tr>";
           }else{
               echo "<td><label>{$new_row['full_name']}</td></label>
               <td><label>{$new_row['mobile']}</td></label>
               <td><label>{$new_row['email']}</td></label>
                <td><label>{$new_row['location_of_hire']}</td></label>
                <td><span style = 'color:red'>Rejected</span></td></tr>";
           }
           //echo "</div>";
           
       }
   }
   echo "</ul></table></div>";
  
   /*
   if(array_key_exists($row['request_id'], $_POST)) { 
        buttonAccept(); 
    } 
*/
   /*echo "Fetched data successfully\n";*/
   
   
    echo "<h1 class = 'processed_h1'>------------------  Paid Invoices ------------------</h1>";
    
    echo "<div class = 'maximo_div'><ul><table>
    <tr>
        <th><b>Customer Name</b></th>
        <th><b>Customer Email</b></th>
        <th><b>Invoice ID</b></th>
        <th><b>Customer ID</b></th>
        <th><b>Amount Due</b></th>
        <th><b>Amount Paid</b></th>
        <th><b>Amount Remaining</b></th>
        <th><b>Status</b></th>
    </tr>";
    foreach ($stripe->invoices->all(['status' => 'paid']) as $i){
        echo "<tr>";
        // echo $i->status;
        echo "
        <td>{$i['customer_name']}</td>
        <td>{$i['customer_email']}</td>
        <td>{$i['id']}</td>
        <td>{$i['customer']}</td>
        <td>{$i['amount_due']}</td>
        <td>{$i['amount_paid']}</td>
        <td>{$i['amount_remaining']}</td>
        <td style='color: green'>{$i['status']}</td>
        ";
        echo"</tr>";
    }
    echo "</table></ul></div>";
    
    
    
    echo "<h1 class = 'processed_h1'>------------------  Open Invoices ------------------</h1>";
    
    echo "<div class = 'maximo_div'><ul><table>
    <tr>
        <th><b>Customer Name</b></th>
        <th><b>Customer Email</b></th>
        <th><b>Invoice ID</b></th>
        <th><b>Customer ID</b></th>
        <th><b>Amount Due</b></th>
        <th><b>Amount Paid</b></th>
        <th><b>Amount Remaining</b></th>
        <th><b>Status</b></th>
    </tr>";
    // $count = 0;
    foreach ($stripe->invoices->all(['limit' => 200, 'status' => 'open']) as $i){
        // $count++;
        echo "<tr>";
        // echo $i->status;
        echo "
        <td>{$i['customer_name']}</td>
        <td>{$i['customer_email']}</td>
        <td>{$i['id']}</td>
        <td>{$i['customer']}</td>
        <td>{$i['amount_due']}</td>
        <td>{$i['amount_paid']}</td>
        <td>{$i['amount_remaining']}</td>
        <td style='color: blue'>{$i['status']}</td>
        ";
        echo"</tr>";
    }
    echo "</table></ul></div>";
    // echo $count + '(should be at least 130) | currently being limited to 100 by stripe';
    
   $sql_credit_forms = 'SELECT * FROM credit_forms';
   //mysqli_select_db($link,'chire_test1');
   $retval2 = mysqli_query( $link, $sql_credit_forms );
   
   if(! $retval2 ) {
      die('Could not get data: ' . mysql_error());
   }
   
   echo "<h1 class = 'processed_h1'>------------------  Credit Forms ------------------</h1>";
   
   echo "<div class = 'maximo_div'><ul><table>
       <tr>
        <th><b>Business Structure</b></th>
        <th><b>Years in Business</b></th>
        <th><b>Business Name</b></th>
        <th><b>Trading Name</b></th>
        <th><b>A.C.N</b></th>
        <th><b>A.B.N</b></th>
        <th><b>Business Address</b></th>
        <th><b>Postal Address</b></th>
        <th><b>Telephone</b></th>
        <th><b>Mobile</b></th>
        <th><b>Email</b></th>
    </tr>";
   
   while($row2 = mysqli_fetch_array($retval2, MYSQLI_ASSOC)) {
        echo "<tr>";
        $bstructure = array("Public Co.", "Sole Trader", "Pty Ltd Co.", "Partnership");
        echo "
        <td>{$bstructure[$row2['b_structure']-1]}</td>
        <td>{$row2['b_years']}</td>
        <td>{$row2['b_name']}</td>
        <td>{$row2['t_name']}</td>
        <td>{$row2['c_acn_name']}</td>
        <td>{$row2['c_abn_name']}</td>
        <td>{$row2['b_address']}</td>
        <td>{$row2['p_address']}</td>
        <td>{$row2['t_phone']}</td>
        <td>{$row2['m_phone']}</td>
        <td>{$row2['email']}</td>
        ";
        echo"</tr>";
   }
    echo "</table></ul></div>";
    
    
    echo "<h1 class = 'processed_h1'>------------------  Customers ------------------</h1>";
    
    echo "<div class = 'maximo_div'><ul><table>
    <tr>
        <th><b>Customer Name</b></th>
        <th><b>ID</b></th>
        <th><b>Invoice Prefix</b></th>
        <th><b>Email</b></th>
        <th><b>Phone</b></th>
    </tr>";
    foreach ($stripe->customers->all(['limit' => 10]) as $c){
        echo "<tr>
        <td>{$c['name']}</td>
        <td>{$c['id']}</td>
        <td>{$c['invoice_prefix']}</td>
        <td>{$c['email']}</td>
        <td>{$c['phone']}</td>
        ";
        echo"</tr>";
    }
    echo "</table></ul></div>";
    
    
    
    echo "<h1 class = 'processed_h1'>------------------  Customers (test) ------------------</h1>";
    

    
    // echo "<div class = 'maximo_div'><ul>";
    
    // foreach ($stripe->customers->all(['limit' => 10]) as $c){
    
    // echo "<li>
    // <div class = 'top-div'>
    // <span>{'name 1'}</span>
    // <span>{'name 2}</span>
    //     <div class = 'arrow'>
    //         <span class = 'l-span'></span>
    //         <span class = 'r-span'></span>
    //     </div>
    // </div>
    
    
    // <div class = 'bottom-div'>
    
    // <table>
    // <tr>
    //     <th><b>Customer Name</b></th>
    //     <th><b>ID</b></th>
    //     <th><b>Invoice Prefix</b></th>
    //     <th><b>Email</b></th>
    //     <th><b>Phone</b></th>
    // </tr>";
    // // foreach ($stripe->customers->all(['limit' => 10]) as $c){
    //     echo "<tr>
    //     <td>{$c['name']}</td>
    //     <td>{$c['id']}</td>
    //     <td>{$c['invoice_prefix']}</td>
    //     <td>{$c['email']}</td>
    //     <td>{$c['phone']}</td>
    //     </tr></div>";
    // }
    // echo "</table></ul></div>";
    
    echo "<div class = 'maximo_div'>
    <ul>
    <table style='color: #023b82'>
        <tr>
            <th style='width: 20vw'>Name</th>
            <th style='width: 20vw'>Customer ID</th>
            <th style='width: 20vw'>Invoice Prefix</th>
            <th style='width: 20vw'>Email</th>
            <th style='width: 20vw'>Phone</th>
        </tr>
    </table>";
    
    foreach ($stripe->customers->all(['limit' => 10]) as $c){
    
    echo "<li>
    
    <div class = 'top-div'>
        <table style='color: white;'>
            <tr>
                <td style='width: 20vw'>{$c['name']}</td>
                <td style='width: 20vw'>{$c['id']}</td>
                <td style='width: 20vw'>{$c['invoice_prefix']}</td>
                <td style='width: 20vw'>{$c['email']}</td>
                <td style='width: 20vw'>{$c['phone']}</td>
                <td>&#8889;</td>
            </tr>
        </table>
    </div>
    
    <div class = 'bottom-div'>";
    
    // foreach ($stripe->invoices->search(['limit' => 10]) as $c) {
        
    // }
    echo "
    <table>
    <tr>
        <th><b>Customer Name</b></th>
        <th><b>Customer Email</b></th>
        <th><b>Invoice ID</b></th>
        <th><b>Customer ID</b></th>
        <th><b>Amount Due</b></th>
        <th><b>Amount Paid</b></th>
        <th><b>Amount Remaining</b></th>
        <th><b>Status</b></th>
    </tr>";
    
    foreach ($stripe->invoices->all(['customer' => $c['id']]) as $i) {
        if ($i['status'] == 'open') {
            $test = 'blue';
        } else if ($i['status'] == 'paid') {
            $test = 'green';
        }
        
        echo "
        <tr>
        <td>{$i['customer_name']}</td>
        <td>{$i['customer_email']}</td>
        <td>{$i['id']}</td>
        <td>{$i['customer']}</td>
        <td>{$i['amount_due']}</td>
        <td>{$i['amount_paid']}</td>
        <td>{$i['amount_remaining']}</td>
        <td style='color: {$test}'>{$i['status']}</td>
        </tr>";
    }
    
    echo "</table></div>
    
    </li>";
    }
    echo "</ul></div>";
    
    
   
   mysqli_close($link);
   echo "<script type='text/javascript'
        src='test.js'></script>";
?>
