<?php // echo "<pre>";die(print_r($ReturnItem))?>
<!--<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">-->
<style type="text/css">
    .ValSpan{
        opacity:0;
    }
      .table thead tr >th{
        background-color:#4c0870;
        color:#fff;
    }
    #ReturnItem  tr >th{
     background-color:#000;
        color:#fff;
    
    
    }
</style>
<script src="<?php echo VIEWS; ?>files/towords.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 text-center">
                    <h1><?php print CommonLanguage::getMessage('return_invoice');?></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 ? "Name" : "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[0][$IsVendor ? "Organization_Name" : "Customer_Name"]; ?>
                    <br/><?php print CommonLanguage::getMessage('address');?>: <?php echo $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[0][$IsVendor ? "Organization_Email" : "Customer_Email"]; ?>
                    <br/><?php print CommonLanguage::getMessage('Phone');?>: <?php echo $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/><span> <?php print CommonLanguage::getMessage('invoice_number');?> 	</span><span>&nbsp;<?php echo 	isset($ReturnItem['Main']["Invoice_Purchase_ID"]) ? $ReturnItem['Main']["Invoice_Purchase_ID"] : '-- --'; ?></span>
                    <br/><span> <?php print CommonLanguage::getMessage('Date');?>    </span><span>&nbsp;<?php echo 	$ReturnItem['Main']["Date"]; ?></span>
                    <!--<br/><span> <?php // print CommonLanguage::getMessage('return_date');?>        </span><span>&nbsp;<?php // echo 	$ReturnItem['General']["Return_Invoice_Date"]; ?></span>-->	
                </div>
            </div>
            <br/>

            <h5><?php print CommonLanguage::getMessage('return_item');?></h5>
            <table class="table table-striped table-hover " id="ReturnItem">
                <thead>
                    <tr>
                        <th>#</th>
                        <th><?php print CommonLanguage::getMessage('Code');?></th>
                        <th class=""><?php print CommonLanguage::getMessage('Item');?></th>
                        <th class=""><?php print CommonLanguage::getMessage('Quantity');?></th>
                        <th class=""><?php print CommonLanguage::getMessage('unit_cost');?></th>
                        <th><?php print CommonLanguage::getMessage('total');?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
for($i=0;$i<count($ReturnItem['Details']);$i++){
                    ?>        
                    <tr>
                        <td><?php echo $i+1; ?></td>
                        <td><?php echo $ReturnItem['Details'][$i]["Code"] ; ?></td>
                        <td><?php echo $ReturnItem['Details'][$i]["Name"] ; ?></td>
                        <td class=""><?php echo $ReturnItem['Details'][$i]["Product_Quantity"] ; ?> </td>
                        <td class=""><span class='CurrencyIndicator'><?php echo $ReturnItem['Main']['Currency_Symbol']; ?></span>&nbsp;<span class=""><?php echo $ReturnItem['Details'][$i]["Product_Net_Price"] ; ?></span></td>
                        <!--<td class=""><span class='CurrencyIndicator'><?php echo $ReturnItem['Main']['Currency_Symbol'] ?></span>&nbsp;<span class=""><?php echo $ReturnItem['Details'][$i]["Product_Discount"] ; ?></span></td>-->
                        <td><span class='CurrencyIndicator'><?php echo $ReturnItem['Main']['Currency_Symbol']; ?></span>&nbsp;<span class=""><?php echo Forms::DecimalNumber($ReturnItem['Details'][$i][ "Product_Total_Price"]) ; ?></span> </td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
            <br/>
            <br/>
            <div class="row">
                <div class="col-xs-8" id="InvoiceBottomPriceInWords">
                    <h4></h4>

                </div>
                <div class="col-xs-4">
                    <table class="table table-hover" id="TotalTable">
                        <tbody>
                            <tr>
                                <td><?php print CommonLanguage::getMessage('subtotal');?></td>
                                <td class='v-align-middle text-center'><span class='CurrencyIndicator'><?php echo $ReturnItem['Main']['Currency_Symbol']; ?></span>&nbsp;<span><?php echo Forms::DecimalNumber($ReturnItem['Main']["Net_Total"]);?></span></td>
                            </tr><!--
-->                            <tr>
                                <td><?php print CommonLanguage::getMessage('vat');?></td>
                                <td class='v-align-middle text-center'><span class='CurrencyIndicator'><?php echo $ReturnItem['Main']['Currency_Symbol']; ?></span>&nbsp;<span class=""><?php echo $ReturnItem['Main'][ "Invoice_VAT"];?></span></td>
                            </tr><!--
-->                            <tr>
                                <td><?php print CommonLanguage::getMessage('discount');?></td>
                                <td class='v-align-middle text-center'><span class='CurrencyIndicator'><?php echo $ReturnItem['Main']['Currency_Symbol']; ?></span>&nbsp;<span class=""><?php echo $ReturnItem['Main']["Discount"] ;?></span></td>
                            </tr>
                            <tr>
                                <td>
                                    <strong><?php print CommonLanguage::getMessage('total_return');?></strong>
                                </td>
                                <td class='v-align-middle text-center'><strong><span class='CurrencyIndicator'><?php echo $ReturnItem['Main']['Currency_Symbol']; ?></span>&nbsp;<span class=" TotalVal" data-val="<?php echo $ReturnItem['Main']["net"];?>"><?php echo Forms::DecimalNumber( $ReturnItem['Main']["net"] );?></span></strong></td>
                            </tr>
                        </tbody>
                    </table>
                    
                </div>
            </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> <?php print CommonLanguage::getMessage('print');?></a>
<!--                        <a href="#" data-download-pdf="" data-title='< ?php print CommonLanguage::getMessage('return_invoice');?>' class="btn btn-primary"><?php print CommonLanguage::getMessage('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 = parseFloat($("#TotalTable").find("span.TotalVal").attr("data-val"));
//    
//        alert(TotalVal)
        var WordedPriceFirstCurrency = ucWords(toWords(parseFloat(TotalVal.toFixed(3)))) + " " + PrimaryCurrency;
        // Adding Zero if 0.##
        if(TotalVal < 1)WordedPriceFirstCurrency = ZeroLang+" " + WordedPriceFirstCurrency;



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

    })
</script>