<?php

// CRUD 
   @$getId = base64_decode($_GET['id']);  
    if(@$getId){ 
        $query = mysql_query("SELECT * FROM requests WHERE id = + $getId");
        $result = mysql_fetch_array($query);
        
        $custid = $result['customer'];
        $querycc = mysql_query("SELECT * FROM customers WHERE id = '$custid'");
        $customer = mysql_fetch_array($querycc);
        
        $ird = $result['id'];
		$q = mysql_query("SELECT SUM(amount * qtd) as amount FROM requests_tbl WHERE request = '$ird'");
 		$r = mysql_fetch_array($q);
	    $total = number_format($r["amount"],2,'.','');
		
		
    }
   ?>


<!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            Invoice
            <small>#<?php echo $result['p_order']; ?></small>
          </h1>
          
        </section>

        <!-- Main content -->
        <section class="invoice">
          <!-- title row -->
          <div class="row">
            <div class="col-xs-12">
              <h2 class="page-header">
                <i class="fa fa-globe"></i> <?php echo $config['company']; ?>
                <small class="pull-right">Date: <?php if($lang['DATE_FORMAT'] == 'PT') { ?><?php echo data_br($result['date']); ?><?php } ?><?php if($lang['DATE_FORMAT'] == 'EN') { ?><?php echo data_en($result['date']); ?><?php } ?> <?php echo $result['hour']; ?></small>
              </h2>
            </div><!-- /.col -->
          </div>
          <!-- info row -->
          <div class="row invoice-info">
            <div class="col-sm-4 invoice-col">
              From
              <address>
                <strong><?php echo $config['company']; ?></strong><br>
                Email: <?php echo $config['email']; ?>
              </address>
            </div><!-- /.col -->
            <div class="col-sm-4 invoice-col">
              To
              <address>
                <strong><?php echo $customer['name']; ?></strong><br>
                <?php echo $customer['address']; ?> <?php echo $customer['number']; ?>, <?php echo $customer['neighborhood']; ?><br>
                <?php echo $customer['city']; ?> <?php echo $customer['state']; ?> - <?php echo $customer['zipcode']; ?><br>
                Tax ID: <?php echo $customer['cpf_cnpj']; ?><br>
                Email: <?php echo $customer['email']; ?>
              </address>
            </div><!-- /.col -->
            <div class="col-sm-4 invoice-col">
              <b>Invoice #<?php echo $result['p_order']; ?></b><br>
              <br>
              <b>Date:</b> <?php if($lang['DATE_FORMAT'] == 'PT') { ?><?php echo data_br($result['date']); ?><?php } ?><?php if($lang['DATE_FORMAT'] == 'EN') { ?><?php echo data_en($result['date']); ?><?php } ?> <?php echo $result['hour']; ?><br>
              <b>Payment:</b> <?php echo $result['payment']; ?><br>
              <b>Status:</b>
         <?php if (@$result['status'] == 'A') { echo $lang['ORDER_STATUS_A']; } ?>
         <?php if (@$result['status'] == 'S') { echo $lang['ORDER_STATUS_S']; } ?>
         <?php if (@$result['status'] == 'N') { echo $lang['ORDER_STATUS_N']; } ?>
           
           
            </div><!-- /.col -->
          </div><!-- /.row -->

          <!-- Table row -->
          <div class="row">
            <div class="col-xs-12 table-responsive">
             <table class="table table-striped table-hover">
                    <thead>
                      <tr>
                        <th><?php echo $lang['PRODUCT']; ?></th>
                        <th><?php echo $lang['DOMAIN']; ?></th>
                        <th><?php echo $lang['QTD']; ?></th>
                        <th><?php echo $lang['AMOUNT']; ?></th>
                        <th><?php echo $lang['ORDER_TOTAL']; ?></th>
                      </tr>
                    </thead>
                    <tbody>
					<?php
					$ird = $result['id'];
 		  			$queryRF = mysql_query("SELECT p.*, c.product AS product FROM requests_tbl AS p INNER JOIN products AS c ON p.product = c.id WHERE p.request = '$ird' ORDER BY p.id DESC");
 		  			while($qres = mysql_fetch_array($queryRF)){
					?>
		            <tr>
		            <td><?php echo $qres['product']; ?></td>
					<td><?php echo $qres['domain']; ?></td>
					<td><?php echo $qres['qtd']; ?></td>
					<td><?php echo number_format($qres['amount'],2,'.',''); ?></td>
					<td><?php echo number_format($qres['amount'] * $qres['qtd'],2,'.',''); ?></td>
				    </tr>
					<?php } ?>
					
                    </tbody>
                    
                  </table>
            </div><!-- /.col -->
          </div><!-- /.row -->

          <div class="row">
            <!-- accepted payments column -->
            <div class="col-xs-6">
              <p class="lead">Payment Methods:</p>
              <img src="assets/dist/img/credit/visa.png" alt="Visa">
              <img src="assets/dist/img/credit/mastercard.png" alt="Mastercard">
              <img src="assets/dist/img/credit/american-express.png" alt="American Express">
              <img src="assets/dist/img/credit/paypal2.png" alt="Paypal">
              <!-- <p class="text-muted well well-sm no-shadow" style="margin-top: 10px;">
               
                </p> -->
            </div><!-- /.col -->
            <div class="col-xs-6">
              <p class="lead"><?php echo $lang['AMOUNT']; ?></p>
              <div class="table-responsive">
                <table class="table">
                  <tr>
                    <th style="width:50%">Subtotal:</th>
                    <td><?php echo $total; ?></td>
                  </tr>
                  <tr>
                    <th>Tax (0%)</th>
                    <td>0.00</td>
                  </tr>
                  
                  <tr>
                    <th>Total:</th>
                    <td><?php echo $total; ?></td>
                  </tr>
                </table>
              </div>
            </div><!-- /.col -->
          </div><!-- /.row -->

          <!-- this row will not appear when printing -->
          <div class="row no-print">
            <div class="col-xs-12">
              <a href="invoice-print.php?id=<?php echo base64_encode($result['id']); ?>" target="_blank" class="btn btn-default"><i class="fa fa-print"></i> Print</a>
             
            </div>
          </div>
        </section><!-- /.content -->
        <div class="clearfix"></div>
      </div><!-- /.content-wrapper -->
