<?php 
if (empty($total)) { ?>
    <div class="alert alert-danger" role="alert">
        <button class="close" data-dismiss="alert"></button>
        <strong>Danger: </strong>you can not view delivery note! 
        <br>
        This delivery note is not available.
    </div>
<?php die(); } ?>
<link href="<?php echo THEME_PATH; ?>css/style.css" rel="stylesheet" type="text/css"/>
<link href="<?php echo THEME_PATH; ?>css/style-responsive.css" rel="stylesheet">
<!--<link href="<?php echo THEME_PATH; ?>css/print-invoice.html" rel="stylesheet" media="print">-->

<style type="text/css">
    .ValSpan{
        opacity:0;
    }
</style>
<script src="<?php echo VIEWS; ?>files/towords.js"></script>
<script src="<?php echo JS_PATH; ?>scripts.js"></script>
<script>
    // to check if this invoice is for customer or vendor by using URL
    var IsVendor = location.pathname.toString().match(/\/vendor/i) != null;
    // to remove many digits after the period
//    $(function(){$(".ValSpan").each(function(){$(this).html(AddCommas(parseFloat($.trim($(this).text())).toFixed(3))).animate({opacity:1})})})
</script>
<!--body wrapper start-->
<div class="wrapper">
    <div class="panel invoice">
        <div class="panel-body">
            <div class="row">
                <div class="col-xs-3">
                    <div class="invoice-logo">
                        <img src="<?= upload_url;?>org_logo/invoice_logo.jpg" alt=""style="max-width:250px"/>
                    </div>
                </div>
                <div class="col-xs-5">
                    <h1><?php echo CommonLanguage::getMessage($IsVendor ? "purchase_delivery_note" : "invoice_delivery_note");?></h1>
                </div>
                
            </div>
            <br/>
            <br/>
            <br/>
            <div class="row">
                <div class="col-xs-4">

                    <strong><?php print CommonLanguage::getMessage('From');?></strong>
                    <br/><?php print CommonLanguage::getMessage('Name');?>: <?php echo $From_Details[0][$IsVendor ? "Supplier_Name" : "Organization_Name"]; ?>
                    <br/><?php print CommonLanguage::getMessage('address');?>: <?php echo $From_Details[0][$IsVendor ? "Country_Name" : "Country_Name"] .'-'. $From_Details[0][$IsVendor ? "city_name" : "city_name"].'-'. $From_Details[0][$IsVendor ? "Supplier_Address" : "Organization_Street"]?>
                    <br/><?php print CommonLanguage::getMessage('Email');?>: <?php echo $From_Details[0][$IsVendor ? "Supplier_Email" : "Organization_Email"] ?>
                    <br/><?php print CommonLanguage::getMessage('Phone');?>: <?php echo $From_Details[0][$IsVendor ? "Supplier_Phone" : "Organization_Phone"] ?>
                </div>
                <div class="col-xs-4">
                    <strong>
                        <?php print CommonLanguage::getMessage('To');?>
                    </strong>
                    <br/><?php print CommonLanguage::getMessage('Name');?>: <?php echo $To_Details ? $To_Details[0][$IsVendor ? "Organization_Name" : "Customer_Name"] : "Road Customer"; ?>
                    <br/><?php print CommonLanguage::getMessage('address');?>: <?php echo $To_Details ? ($To_Details[0][$IsVendor ? "Country_Name" : "Country_Name"]  .'-'.  $To_Details[0][$IsVendor ? "Name" : "Name"] .'-'. $To_Details[0][$IsVendor ? "Organization_Street" : "Customer_Address"]) : "-- --";?>
                    <br/><?php print CommonLanguage::getMessage('Email');?>: <?php echo $To_Details ? $To_Details[0][$IsVendor ? "Organization_Email" : "Customer_Email"] : "-- --"; ?>
                    <br/><?php print CommonLanguage::getMessage('Phone');?>: <?php echo $To_Details ? $To_Details[0][$IsVendor ? "Organization_Phone" : "Customer_Phone"] : "-- --"; ?>
                </div>
                <div class="col-xs-4 inv-info">
                    <strong><?php print CommonLanguage::getMessage('invoice_info');?></strong>
                    <br/>
                    <div >
<!--                        <span> < ?php echo $IsVendor ? 'Vendor Invoice Number ': '';?> 	</span><span>&nbsp;< ?php echo 	$list[0][$IsVendor ? "Supplier_Invoice_ID" : ""]; ?></span></div>-->
                    <div><span><?php print CommonLanguage::getMessage('Date');?>    </span><span>&nbsp;<?php echo 	$total[0]["Date"]; ?></span></div>
                </div>
            </div>
            <br/>
            <br/>
            <br/>
            <table class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th>#</th>
                        <th><?php print CommonLanguage::getMessage('Code');?></th>
                        <th><?php print CommonLanguage::getMessage('Item');?></th>
                        <th><?php print CommonLanguage::getMessage('Quantity');?></th>
                        
                    </tr>
                </thead>
                <tbody>
                    <?php
for($i=0;$i<count($total);$i++){
                    ?>
                    <tr>
                        <td><?php echo $i+1; ?></td>
                        <td><?php echo $total[$i]["Code"] ; ?></td>
                        <td><?php echo $total[$i]["Product_Name"] ; ?></td>
                        <td class=""><?php echo $total[$i]["Product_Delivery_Quantity"] ; ?> </td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
            <br/>
            <br/>
       
            </div>
            <br/>
            <br/>
            <br/>
            <div class="row no-print">
                <div class="col-md-12">
                    <div class="pull-right">
                        <a class="btn btn-danger" onclick="javascript:window.print();"><i class="fa fa-print"></i> Print</a>
<!--                        <a href="#" data-download-pdf="" data-title="< ?php echo CommonLanguage::getMessage($IsVendor ? "purchase_delivery_note" : "invoice_delivery_note");?> " class="btn btn-primary">Generate PDF</a>-->
                    </div>
                    <!--
<div class="pull-right">
<a href="#" class="btn btn-success">Submit Payment</a>
</div>
-->
                </div>
            </div>
        </div>
    </div>
</div>
<!--body wrapper end-->
<script>
     var ZeroLang = <?php echo json_encode(CommonLanguage::getMessage('zero'));?>,
        SayLang = <?php echo json_encode(CommonLanguage::getMessage('say'));?>;
    $(function(){
        var PrimaryCurrency = <?php echo json_encode(CommonLanguage::getMessage($CurrName)); ?>;
        var TotalVal = ($("#TotalTable").find("span.TotalVal").text());


        var WordedPriceFirstCurrency = ucWords(toWords(TotalVal)) + " " + PrimaryCurrency;
        // Adding Zero if 0.##
        if(TotalVal < 1)WordedPriceFirstCurrency = ZeroLang+" " + WordedPriceFirstCurrency;



        $("#InvoiceBottomPriceInWords > h4").html(SayLang+" " + WordedPriceFirstCurrency);

    })
</script>
