<?php 
    include "head.php" ;
    
    if(isset($_GET['invoice'])){
        $invoice_id = $_GET['invoice'];
    }
?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js" ></script><body>
	<body>

		<!-- Main Wrapper -->
		<div class="main-wrapper">
		

			<!-- Page Content -->
			<div class="content">
				<div class="container-fluid">

					<div class="row">

						<div class="col-md-7 col-lg-10 col-xl-9 mx-auto">
						    <div class="card card-table">
								<div class="card-body">
    								<?php
        						        $sno = 1;
        								$sql = "SELECT * FROM report_master WHERE id = '$invoice_id' AND status = 1 " ;
        						        $res = $config->query($sql);
        						        $list = $res->fetch_assoc();
        						        $total = number_format($list['price'], 2, '.', '');
        						        $user_id = $list['customer_id'];
        						    ?>
									<!-- Invoice Table -->
									<div class="table-responsive">
										<table class="table table-hover table-center mb-0">
											<thead>
												<tr>
													<th>Invoice No</th>
													<th>Category</th>
													<th>Package</th>
													<th>Type</th>
													<th>Amount</th>
													<th>Validity</th>
													<th>Action</th>
													<th></th>
												</tr>
											</thead>
											<tbody>
												<tr>
													<td>
														#INV<?= date('my') ?><?= substr($list['category'],0,1) ?><?= $list['id'] ?>
													</td>
													<td><?= $list['category'] ?></td>
													<td><?= $list['package'] ?></td>
													<td><?= $list['type'] ?></td>
													<td>Rs.<?= $total ?></td>
													<td><?= $list['validity'] ?> Days</td>
													<!--<td>14 Nov 2019</td>-->
													<td class="text-right">
														<div class="table-action">
															<a class="btn btn-sm bg-primary-light" id="download">
																<i class="fas fa-print"></i> Print
															</a>
														</div>
													</td>
												</tr>
											</tbody>
										</table>
									</div>
									<!-- /Invoice Table -->
									
								</div>
							</div>
							<?php 
								$sql = "SELECT * FROM invoice_management WHERE status = 1 ";
								$res = $config->query($sql);
								$row = $res->fetch_assoc();
							?>
							<div class="invoice-content" id="invoice-view">
								<div class="invoice-item">
									<div class="row">
										<div class="col-md-6">
											<div class="invoice-logo">
												<img src="assets/img/invoice/<?= $row['in_logo'] ?>" class="img-fluid" alt="<?= $logo['logo_name'] ?> Logo">
											</div>
										</div>
										<div class="col-md-6">
											<p class="invoice-details">
												<strong>Invoice Order:</strong> #INV<?= date('my') ?><?= substr($list['category'],0,1) ?><?= $list['id'] ?> <br>
												<strong>Issued:</strong> <?= date('d/m/Y',strtotime($list['payment_date'])) ?> <br>
												<strong>GST No:</strong> <?= $row['gst'] ?>
											</p>
										</div>
									</div>
								</div>
								
								<!-- Invoice Item -->
								<div class="invoice-item">
									<div class="row">
										<!--<div class="col-md-6">-->
										<!--	<div class="invoice-info">-->
										<!--		<strong class="customer-text">Invoice From</strong>-->
										<!--		<p class="invoice-details invoice-details-two">-->
										<!--			Dr. Darren Elder <br>-->
										<!--			806  Twin Willow Lane, Old Forge,<br>-->
										<!--			Newyork, USA <br>-->
										<!--		</p>-->
										<!--	</div>-->
										<!--</div>-->
										<div class="col-md-6">
											<div class="invoice-info">
											    <?php
                    								$v_sql = "SELECT * FROM v_profile WHERE v_id = '$user_id' " ;
                    						        $v_res = $config->query($v_sql);
                    						        $v_list = $v_res->fetch_assoc();
                    						    ?>
												<strong class="customer-text">Invoice To</strong>
												<p class="invoice-details invoice-details-two">
													<strong><?= $v_list['v_name'] ?></strong><br>
													<?= $v_list['address'] ?> <br>
													<?= $v_list['area'] ?>, <?= $v_list['city'] ?><br>
													<?php if(!empty($v_list['gst'])){ ?>
													<strong>GST No </strong><?= $v_list['gst'] ?>
													<?php } ?>
												</p>
											</div>
										</div>
										<div class="col-md-6">
											<div class="invoice-info invoice-info2">
												<strong class="customer-text">Payment Method</strong>
												<p class="invoice-details">
													<?= $row['pay_method'] ?><br>
													<?= $row['pay_detail'] ?><br>
													<?= $row['pay_branch'] ?>
												</p>
											</div>
										</div>
									</div>
								</div>
								<!-- /Invoice Item -->
								
								<!-- Invoice Item -->
								<!--<div class="invoice-item">-->
								<!--	<div class="row">-->
								<!--		<div class="col-md-12">-->
								<!--			<div class="invoice-info">-->
								<!--				<strong class="customer-text">Payment Method</strong>-->
								<!--				<p class="invoice-details invoice-details-two">-->
								<!--					Debit Card <br>-->
								<!--					XXXXXXXXXXXX-2541 <br>-->
								<!--					HDFC Bank<br>-->
								<!--				</p>-->
								<!--			</div>-->
								<!--		</div>-->
								<!--	</div>-->
								<!--</div>-->
								<!-- /Invoice Item -->
								
								<!-- Invoice Item -->
								<div class="invoice-item invoice-table-wrap">
									<div class="row">
										<div class="col-md-12">
											<div class="table-responsive">
												<table class="invoice-table table table-bordered">
													<thead>
														<tr>
															<th>Category</th>
															<th class="text-center">Package</th>
															<th class="text-center">Type</th>
															<th class="text-center">Validity</th>
															<th class="text-center">Service Tax</th>
															<th class="text-right">Total</th>
														</tr>
													</thead>
													<tbody>
														<tr>
															<td><?= $list['category'] ?></td>
															<td class="text-center"><?= $list['package'] ?></td>
															<td class="text-center"><?= $list['type'] ?></td>
															<td class="text-center"><?= $list['validity'] ?> Days</td>
															<td class="text-center"><?= $row['tax'] ?>%</td>
															<td class="text-right">Rs.<?= $total ?></td>
														</tr>
														<!--<tr>-->
														<!--	<td>Video Call Booking</td>-->
														<!--	<td class="text-center">1</td>-->
														<!--	<td class="text-center">$0</td>-->
														<!--	<td class="text-right">$250</td>-->
														<!--	<td class="text-right">$250</td>-->
														<!--	<td class="text-right">$250</td>-->
														<!--</tr>-->
													</tbody>
												</table>
											</div>
										</div>
										<div class="col-md-6 col-xl-8 d-flex align-items-center">
											<div>
											    <h5>Payment in words</h5>
											    <p class="text-muted mb-0">
											    <?php
                                                    $class_obj = new numbertowordconvertsconver();
                                                    $convert_number =array_sum($grand_to);
                                                    echo $class_obj->convert_number($total)." Rupees";
                                                ?>
                                                </p>
											</div>
										</div>
										<div class="col-md-6 col-xl-4 ">
											<div class="table-responsive">
												<table class="invoice-table-two table">
													<tbody>
													<tr>
														<th>Subtotal:</th>
														<td><span>Rs.<?= $total ?></span></td>
													</tr>
													<tr>
														<th style="color: #757575;">Splitup:</th>
														<?php 
														    $tax = $row['tax'];
														    $sub = $total - ($total * ($tax/100));
														    $subtotal = number_format($sub, 2, '.', '');
														?>
														<td><span style="font-weight: 600;color: #111;">Rs.<?= $subtotal ?></span></td>
													</tr>
													<tr>
													    <?php 
														    $cgst = $row['cgst'];
														    $cgst_val = number_format(($total * ($cgst/100)), 2, '.', '');
														?>
														<th style="color: #757575;">CGST - <?= $cgst ?>%</th>
														<td><span style="font-weight: 600;color: #111;">Rs.<?= $cgst_val ?></span></td>
													</tr>
													<tr>
													    <?php 
														    $sgst = $row['sgst'];
														    $sgst_val = number_format(($total * ($sgst/100)), 2, '.', '');
														?>
														<th style="color: #757575;">SGST - <?= $sgst ?>%</th>
														<td><span style="font-weight: 600;color: #111;">Rs.<?= $sgst_val ?></span></td>
													</tr>
													<tr>
														<th style="color: #757575;">Total Amount:</th>
														<td><span style="font-weight: 600;color: #111;">Rs.<?= $total ?></span></td>
													</tr>
													</tbody>
												</table>
											</div>
										</div>
									</div>
								</div>
								<!-- /Invoice Item -->
								
								<!-- Invoice Information -->
								<div class="other-info">
								    <!--<h5>Computer Generated Bill</h5>-->
									<h4>Terms And Condition</h4>
									<ul class="text-muted mb-4"> 
									    <li>This Portal is  accepting payment for only  ad posting .</li>
									    <li>The companies are solely responsible for their business.</li>
									    <li>The Organisation and customers are solely responsible for their sales.</li>
									    <li>Payment Once rendered is Non - Refundable.</li>
									</ul>
								</div>
								<div class="other-info">
									<div class="row">
									    <div class="col-md-10">
    									    <h4>Address</h4>
        									<address class="text-muted mb-0">
        									    <strong><?= $row['company'] ?></strong><br>
        									    <?= $row['in_address'] ?><br>
        									    <?= $row['in_website'] ?> | <?= $row['in_email'] ?> | Customer Care: +91- <?= $row['cc_mobile'] ?>
        									</address>
    									</div>
    									<div class="col-md-2 d-flex justify-content-center">
    									    <img src="assets/img/invoice/<?= $row['qr_code'] ?>" alt="" class="img-fluid" style="width:105px;">
    									</div>
									</div>
								</div>
								<!-- /Invoice Information -->
								
							</div>
						</div>
					</div>

				</div>

			</div>		
			<!-- /Page Content -->

		   
		</div>
		<!-- /Main Wrapper -->
	    <!-- Appointment Details Modal -->
		<div class="modal fade custom-modal" id="buypack">
			<div class="modal-dialog modal-dialog-centered">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title">Scan To Pay</h5>
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
					</div>
					<div class="modal-body">
						<ul class="info-details">
						    
							<li>
								<div class="details-header">
									<div class="row">
										<div class="col-md-12">
										    <?php 
            						            $sql = "SELECT * FROM offline_payment WHERE status = 1 " ;
            							        $res = $config->query($sql);
            							        $row = $res->fetch_assoc();
            							    ?>
										    <img class="qrcode img-fluid" src="assets/img/qrcode/<?= $row['qr_code']; ?>" alt="payment QR-Code">
										</div>
									</div>
								</div>
							</li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<style>
		    .swal-text {
              color: red;
            }
		</style>
		<!-- /Appointment Details Modal -->

		<!-- jQuery -->
		<script src="assets/js/jquery.min.js"></script>
		
		<!-- Bootstrap Core JS -->
		<script src="assets/js/popper.min.js"></script>
		<script src="assets/js/bootstrap.min.js"></script>
		
		<!-- Sticky Sidebar JS -->
        <script src="assets/plugins/theia-sticky-sidebar/ResizeSensor.js"></script>
        <script src="assets/plugins/theia-sticky-sidebar/theia-sticky-sidebar.js"></script>
		
		<!-- Custom JS -->
		<script src="assets/js/script.js"></script>
		
		<script>
            $('.request').on('click', function() {
                let rid = $(this).val();
                let userId = <?php echo $_SESSION['user_id']; ?>;
                let ticket = <?php echo rand(999999,111111); ?>;
                swal({
                    title: "Request to activate package",
                    text: "Enter your transaction id",
                    content: "input",
                    icon: "info",
                    buttons: true,
                    dangerMode: true,
                }).then((value) => {
                    if(value) {
                        $.ajax({
                            type: "POST",
                            url: "order_confirm.php",
                            data: {rid:rid,userId:userId,ticket:ticket,tran_id:value},
                            success: function(data){
                                swal({
                                    title: "Your ticket "+ticket, 
                                    text: "Our team will contact you soon.If you have any emergency contact admin!",
                                    icon: "success",
                                    button: {
                                        className: "agree",
                                    },
                                });
                                $('.agree').on('click', function() {
                                    window.location.href="vendor_dashboard.php";
                                });
                            }
                        });
                  } else {
                    swal("Request Cancelled.",{
                        icon: "error",
                    });
                  }
                });
            });
            
		</script>
		<script>
    		<?php if(isset($_SESSION['check']) && !empty($_SESSION['check'])) { ?>
    		    swal({
                    title: "<?= $_SESSION['check'] ?>", 
                    text: "",
                    icon: "<?= $_SESSION['alert'] ?>",
                    button: {
                        className: "agree",
                    },
                });
            <?php unset($_SESSION['check']) ; } ?>
        </script>
        <script>
            window.onload = function(){
                document.getElementById("download").addEventListener('click',()=>{
                    const viewlist = document.getElementById('invoice-view');
                    let opt = {
                      filename:     'invoice.pdf',
                      image:        { type: 'jpeg', quality: 0.98 },
                      html2canvas:  { scale: 2 },
                      jsPDF:        { unit: 'in', format: 'letter', orientation: 'portrait' }
                    };
                    html2pdf().set(opt).from(viewlist).save();
                })
            }
        </script>
    <?php
    class numbertowordconvertsconver {
        function convert_number($number) 
        {
            if (($number < 0) || ($number > 999999999)) 
            {
                throw new Exception("Number is out of range");
            }
            $giga = floor($number / 1000000);
            // Millions (giga)
            $number -= $giga * 1000000;
            $kilo = floor($number / 1000);
            // Thousands (kilo)
            $number -= $kilo * 1000;
            $hecto = floor($number / 100);
            // Hundreds (hecto)
            $number -= $hecto * 100;
            $deca = floor($number / 10);
            // Tens (deca)
            $n = $number % 10;
            // Ones
            $result = "";
            if ($giga) 
            {
                $result .= $this->convert_number($giga) .  "Million";
            }
            if ($kilo) 
            {
                $result .= (empty($result) ? "" : " ") .$this->convert_number($kilo) . " Thousand";
            }
            if ($hecto) 
            {
                $result .= (empty($result) ? "" : " ") .$this->convert_number($hecto) . " Hundred";
            }
            $ones = array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen", "Nineteen");
            $tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eigthy", "Ninety");
            if ($deca || $n) {
                if (!empty($result)) 
                {
                    $result .= " and ";
                }
                if ($deca < 2) 
                {
                    $result .= $ones[$deca * 10 + $n];
                } else {
                    $result .= $tens[$deca];
                    if ($n) 
                    {
                        $result .= "-" . $ones[$n];
                    }
                }
            }
            if (empty($result)) 
            {
                $result = "zero";
            }
            return $result;
        }
    }
    ?>
	</body>

<!-- doccure/my-patients.html  30 Nov 2019 04:12:09 GMT -->
</html>



