<?php
    $id= $_GET["id"];
    $invoiceNumber= $_GET["invoiceNumber"];
    $date= $_GET["date"];
    $customerName= $_GET["customerName"];
    $customerAddress= $_GET["customerAddress"];
    $serviceType= $_GET["serviceType"];
    $payment= $_GET["payment"];
    $hst= $_GET["hst"];
    $subtotal= $_GET["subtotal"];
    $totalTax= $_GET["totalTax"];  

    function convertNumber($num = false)
{
    $num = str_replace(array(',', ''), '' , trim($num));
    if(! $num) {
        return false;
    }
    $num = (int) $num;
    $words = array();
    $list1 = array('', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
        'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'
    );
    $list2 = array('', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety', 'hundred');
    $list3 = array('', 'thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion', 'sextillion', 'septillion',
        'octillion', 'nonillion', 'decillion', 'undecillion', 'duodecillion', 'tredecillion', 'quattuordecillion',
        'quindecillion', 'sexdecillion', 'septendecillion', 'octodecillion', 'novemdecillion', 'vigintillion'
    );
    $num_length = strlen($num);
    $levels = (int) (($num_length + 2) / 3);
    $max_length = $levels * 3;
    $num = substr('00' . $num, -$max_length);
    $num_levels = str_split($num, 3);
    for ($i = 0; $i < count($num_levels); $i++) {
        $levels--;
        $hundreds = (int) ($num_levels[$i] / 100);
        $hundreds = ($hundreds ? ' ' . $list1[$hundreds] . ' hundred' . ( $hundreds == 1 ? '' : '' ) . ' ' : '');
        $tens = (int) ($num_levels[$i] % 100);
        $singles = '';
        if ( $tens < 20 ) {
            $tens = ($tens ? ' and ' . $list1[$tens] . ' ' : '' );
        } elseif ($tens >= 20) {
            $tens = (int)($tens / 10);
            $tens = ' and ' . $list2[$tens] . ' ';
            $singles = (int) ($num_levels[$i] % 10);
            $singles = ' ' . $list1[$singles] . ' ';
        }
        $words[] = $hundreds . $tens . $singles . ( ( $levels && ( int ) ( $num_levels[$i] ) ) ? ' ' . $list3[$levels] . ' ' : '' );
    } //end for loop
    $commas = count($words);
    if ($commas > 1) {
        $commas = $commas - 1;
    }
    $words = implode(' ',  $words);
    $words = preg_replace('/^\s\b(and)/', '', $words );
    $words = trim($words);
    $words = ucfirst($words);
    $words = $words . ".";
    return $words;
}
    
    
    
    $totalPriceInWords = convertNumber($totalPrice);
    $paidInWords = convertNumber($paid);
    $balanceInWords = convertNumber($balance);

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Invoice</title>

    <style>
        @media print {            
            /* Hide header and footer */
            @page {
                margin: 0;
            }

            body::before {
                content: "";
                display: block;
                position: fixed;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                border: 5px solid black;
                z-index: -1;
                margin: 20px;
            }

            .print-logo {
                display: block;
                position: fixed;
                top: 10%;
                left: 50%;
                transform: translate(-50%, -50%);
            }

            /* Hide the print button when printing */
            .print-btn {
                display: none;
            }
        }
        .print-btn {
                display: none;
            }
        .heading {
            position: absolute;
            top: 180px; /* Adjust the value for the desired distance from the top */
            left: 50%;
            transform: translate(-50%, 0);
            text-align: center;
        }
        .left{
            position: absolute;
            top: 290px; /* Adjust the value for the desired distance from the top */
            left: 11%;            
        }
        .center-line1{
            position: absolute;
            top: 550px; /* Adjust the value for the desired distance from the top */
            left: 50%;
            transform: translate(-50%, 0);
            text-align: center;
        }
        .center-line2{
            position: absolute;
            top: 605px; /* Adjust the value for the desired distance from the top */
            left: 50%;
            transform: translate(-50%, 0);
            text-align: center;
        }
        .center-line3{
            position: absolute;
            top: 770px; /* Adjust the value for the desired distance from the top */
            left: 50%;
            transform: translate(-50%, 0);
            text-align: center;
        }
        .center-line4{
            position: absolute;
            top: 870px; /* Adjust the value for the desired distance from the top */
            left: 50%;
            transform: translate(-50%, 0);
            text-align: center;
        }
    </style>
</head>
<body>
    <button class="print-btn" onclick="printPage()">Print</button>
    <div class="print-logo">
        <img src="images/mts.png" alt="Your Logo" width="250px" height="150px">        
    </div>
    <div class="heading">
        <i><h3>Deposit Slip</h3></i>
        <h1 style="margin-top: -10px;">Customer Copy</h1>
        <h1 style="margin-left: -120px;margin-right: -120px; margin-top: -20px;">----------------------------------------------------------</h1>
    </div>
    <input type="text" style="border: 2px solid black; height: 30px;padding: 4px;font-weight: bold;font-size: 17px;width: 110px;margin-top: 320px;margin-left: 550px;" value="Slip#: <?php echo $slipNumber; ?>"/>
    <div class="left">
        <h3>Slip Date: <?php
echo $date;
?></h3>
        <br>
        <label>From:</label>        
        <input type="text" style="margin-top: -20px; margin-left: 40px; width: 300px; border: none; border-bottom: 1px solid black;" value="<?php echo $name; ?>">
        <br>
        <br>
        <label>Against:</label>        
        <input type="text" style="margin-top: -20px; margin-left: 23px; width: 300px; border: none; border-bottom: 1px solid black;" value="<?php echo $against; ?>">
        <br>
        <br>
        <label>Project:</label>        
        <input type="text" style="margin-top: -20px; margin-left: 27px; width: 300px; border: none; border-bottom: 1px solid black;" value="<?php echo $project; ?>">
        <br>
        <br>
        <label>Plot Size:</label>        
        <input type="text" style="margin-top: -20px; margin-left: 16px; width: 300px; border: none; border-bottom: 1px solid black;" value="<?php echo $plotSize; ?>">
        <br>
        <br>
        <label>Payment Type:</label>        
        <input type="text" style="margin-top: -20px; margin-left: 20px; width: 300px; border: none;font-weight: bold;" value="
        <?php if($type=="Cheque") {
            echo $type." ( ".$cheque." ) ";
        }
        else{
            echo $type; 
        }
        
        ?>
        ">
        <br>
        <br>
        <br>
        <label>Total:</label>        
        <input type="text" style="margin-top: -20px; margin-left: 20px; width: 100px; border: none; font-weight: bold; box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2); border-radius: 4px;" value="<?php echo $totalPrice; ?>/-">
        <label style="margin-left: 40px;">Paid:</label>        
        <input type="text" style="margin-top: -20px; margin-left: 20px; width: 100px; border: none; font-weight: bold; box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2); border-radius: 4px;" value="<?php echo $paid; ?>/-">
        <label style="margin-left: 40px;">Balance:</label>        
        <input type="text" style="margin-top: -20px; margin-left: 20px; width: 100px; border: none; font-weight: bold; box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2); border-radius: 4px;" value="<?php echo $balance; ?>/-">
        <br>
        <br>
        <br>
        <br>
        <label>Total In Words:</label>        
        <input type="text" style="margin-top: -20px; margin-left: 60px; width: 450px; border: none;font-style: italic;" value="<?php echo $totalPriceInWords; ?> /-">
        <br>
        <br>
        
        <label>Paid In Words:</label>        
        <input type="text" style="margin-top: 7px; margin-left: 63px; width: 450px; border: none;font-style: italic;" value="<?php echo $paidInWords; ?> /-">
        <br>
        <br>
        <label>Remaining In Words:</label>        
        <input type="text" style="margin-top: 7px; margin-left: 20px; width: 450px; border: none;font-style: italic;" value="<?php echo $balanceInWords; ?> /-">
        <br>
        <br>
        <br>        
        <br>
        <b><label>Customer Addres:</label></b>
        <input type="text" style="margin-top: 7px; margin-left: 30px; width: 450px; border: none;font-weight: bold;" value="<?php echo $customerAddress ?>">
        <br>        
        <b><label>Customer Mobile:</label></b>
        <input type="text" style="margin-top: 7px; margin-left: 30px; width: 450px; border: none;font-weight: bold;" value="<?php echo $customerMobile ?>">
         <br>
        <br>
        <br>       
        <br>     
        <br>         
        <b><label>Note:</label></b>        
        <input type="text" style="margin-top: -20px; margin-left: 20px; width: 530px; border: none; font-weight: bold; box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2); border-radius: 4px;font-style: italic;" value="This is Computerized generated slip no sign and stamp requried">
        <br>       
        <br> 
        <br>
        <b><label>Company Address:</label></b>        
        <input type="text" style="margin-top: -20px; margin-left: 23px; width: 450px; border: none; border-bottom: 1px solid black;font-weight: bold;" value="OFFICE NO.3-4 GROUND FLOOR, MALIK COMPLEX,">
        <br>
        <br>        
        <input type="text" style="margin-top: -20px; margin-left: 155px; width: 450px; border: none; border-bottom: 1px solid black;font-weight: bold;" value="80-WEST, JINNAH AVENUE BLUE AREA ISLAMABAD">
        <br> 
        <br>
        <b><label>Company Mobile:</label></b>        
        <input type="text" style="margin-top: -20px; margin-left: 23px; width: 450px; border: none; border-bottom: 1px solid black;font-weight: bold;" value="03344553696 / 0333333419">



    </div>
    <div class="center-line1">        
        <h1 style="margin-left: -120px;margin-right: -120px; margin-top: -20px;">----------------------------------------------------------</h1>
    </div>

    <div class="center-line2">        
        <h1 style="margin-left: -120px;margin-right: -120px; margin-top: -20px;">----------------------------------------------------------</h1>
    </div>
    <div class="center-line3">        
        <h1 style="margin-left: -120px;margin-right: -120px; margin-top: -20px;">----------------------------------------------------------</h1>
    </div>
    <div class="center-line4">        
        <h1 style="margin-left: -120px;margin-right: -120px; margin-top: -20px;">----------------------------------------------------------</h1>
    </div>

    <script>
        function printPage() {
            window.print();
        }
        window.addEventListener('load', function() {
            printPage();
        });
    </script>
    <script>
    // Disable double click
    document.addEventListener('DOMContentLoaded', function () {
        document.addEventListener('dblclick', function (event) {
            event.preventDefault();
        });
    });

    // Disable right click
    document.addEventListener('contextmenu', function (event) {
        event.preventDefault();
    });

    // Disable right click on mouse down event
    document.addEventListener('mousedown', function (event) {
        if (event.button === 2) { // 2 represents the right mouse button
            event.preventDefault();
        }
    });

    // Disable Ctrl+S key combination
    document.addEventListener('keydown', function (event) {
        if (event.ctrlKey && event.key === 's') { // Check if Ctrl+S is pressed
            event.preventDefault();
            // Add your custom code or display a message indicating the restriction
        }
    });
</script>
</body>
</html>
