<div id="print">
    <div class="pull-right">AV-A</div>
    <div style="text-align: center; font-family: sans-serif; font-size: initial;">
        <?php if($returned_sale_details->sale_type == 'Credit Sale'){ ?>
            <b>FIXED SALE RETURN -  22K</b>
        <?php }else if($returned_sale_details->sale_type == 'Gold Sale'){ ?>
            <b>UNFIXED SALE RETURN -  22K</b>
        <?php } ?> 
    </div>
    
    <br><br>
    
    <div class="row">
        <div class="col-md-offset-2 col-md-8">
            <table class="table" style="font-size: initial; border: none;">
                <tr>
                    <td>
                        Customer Name
                    </td>
                    <td>
                        <?php echo $returned_sale_details->customer_name; ?>
                    </td>
                    <td>
                        Invoice No.
                    </td>
                    <td>
                        <?php echo $returned_sale_details->invoice_num; ?>
                    </td>
                </tr>
                <tr>
                    <td>
                        Contact No.
                    </td>
                    <td>
                        <?php echo $returned_sale_details->contact_number; ?>
                    </td>
                    <td>
                        Date
                    </td>
                    <td>
                        <?php echo $returned_sale_details->date; ?>
                    </td>
                </tr>
                <tr>
                    <td>
                        Gold Price CMB
                    </td>
                    <td>
                        <?php if($returned_sale_details->sale_type == 'Credit Sale'){ 
                            echo 'Rs. '.number_format($returned_sale_details->k_rate,2,'.',',');
                        }else if($returned_sale_details->sale_type == 'Gold Sale'){ 
                            echo '-';
                        } ?> 
                    </td>
                    <td></td>
                    <td></td>
                </tr>
            </table>
        </div>
    </div>
    <?php if($returned_sale_items){ ?>
    <div class="row">
        <div class="col-md-offset-2 col-md-8">
            <?php if($returned_sale_details->sale_type == 'Credit Sale'){ ?>
                <table class="table table-striped table-bordered table-hover" id="">
                    <thead>
                        <tr>
                            <th style="text-align: center"><strong>Item Name</strong></th>
                            <th style="text-align: center"><strong>Gross Weight</strong></th>
                            <th style="text-align: center"><strong>%</strong></th>
                            <th style="text-align: center"><strong>Selling Rate</strong></th>
                            <th style="text-align: center"><strong>Value</strong></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $total_grams = 0;
                        $total_amount = 0;

                        foreach($returned_sale_items as $returned_sale_item) { ?>                                                        
                        <tr>
                            <td><?php echo $returned_sale_item['item_name']; ?></td>
                            <td>
                                <div class="pull-right">
                                    <?php $total_grams += $returned_sale_item['sales_grams']; echo number_format($returned_sale_item['sales_grams'],3,'.',','). ' g'; ?>
                                </div>
                            </td>
                            <td style="text-align: center"><?php echo $returned_sale_item['selling_percentage'].' %'; ?></td>
                            <td>
                                <div class="pull-right">
                                    <?php 
                                        $selling_rate = $returned_sale_details->k_rate*($returned_sale_item['selling_percentage'])/100;
                                        echo 'Rs. '.number_format($selling_rate,2,'.',','); 
                                    ?>
                                </div>
                            </td>
                            <td>
                                <div class="pull-right">
                                    <?php $total_amount += $returned_sale_item['amount']; echo 'Rs. '.number_format($returned_sale_item['amount'],2,'.',','); ?>
                                </div>
                            </td>
                        </tr> 
                        <?php }?> 
                        <tr>
                            <th>Total Amount</th>
                            <th>
                                <div class="pull-right">
                                    <?php echo number_format($total_grams,3,'.',','). ' g'; ?>
                                </div>
                            </th>
                            <th></th>
                            <th></th>
                            <th>
                                <div class="pull-right">
                                    <?php echo 'Rs. '.number_format($total_amount,2,'.',','); ?>
                                </div>
                            </th>
                        </tr>
                    </tbody>
                </table>                                            
            <?php }else if($returned_sale_details->sale_type == 'Gold Sale'){ ?>
                <table class="table table-striped table-bordered table-hover" id="">
                    <thead>
                        <tr>
                            <th style="text-align: center"><strong>Item Name</strong></th>
                            <th style="text-align: center"><strong>Gross Weight</strong></th>
                            <th style="text-align: center"><strong>%</strong></th>
                            <th style="text-align: center"><strong>Value</strong></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $total_grams = 0;
                        $total_amount = 0;

                        foreach ($returned_sale_items as $returned_sale_item) { ?>                                                        
                        <tr>
                            <td><?php echo $returned_sale_item['item_name']; ?></td>
                            <td>
                                <div class="pull-right">
                                    <?php $total_grams += $returned_sale_item['sales_grams']; echo number_format($returned_sale_item['sales_grams'],3,'.',','). ' g'; ?>
                                </div>
                            </td>
                            <td style="text-align: center"><?php echo $returned_sale_item['selling_percentage'].' %'; ?></td>
                            <td>
                                <div class="pull-right">
                                    <?php $total_amount += $returned_sale_item['amount']; echo number_format($returned_sale_item['amount'],3,'.',','). ' g'; ?>
                                </div>
                            </td>
                        </tr>
                        <?php }?> 
                        <tr>
                            <th>Total Amount</th>
                            <th>
                                <div class="pull-right">
                                    <?php echo number_format($total_grams,3,'.',','). ' g'; ?>
                                </div>
                            </th>
                            <th></th>
                            <th>
                                <div class="pull-right">
                                    <?php echo number_format($total_amount,3,'.',','). ' g'; ?>
                                </div>
                            </th>
                        </tr>
                    </tbody>
                </table>
            <?php } ?>
        </div>
    </div>
    <?php } ?>
    <br><br><br>
    <div class="row">
        <div class="col-md-offset-2 col-md-8">
            <div class="col-md-offset-1 col-md-4 pull-left">
                <div style="text-align: center">........................................</div>
                <div style="text-align: center">Salesmen</div>
            </div>
            <div class="col-md-offset-1 col-md-4 pull-right">
                <div style="text-align: center">........................................</div>
                <div style="text-align: center">Customer Signature</div>
            </div>
        </div>
    </div>
</div>



<div class="portlet-title" style="text-align: center;">
    <div class="actions">
        <button type="button" onclick="printDiv('print')" class="btn blue">
            <i class="fa fa-print"></i>
            <span class="hidden-480">
            Print</span>
        </button>

        <a onclick="history.go(-1);" class="btn default yellow-stripe">
            <i class="fa fa-reply"></i>
            <span class="hidden-480">
            Cancel</span>
        </a>
    </div>
</div>

<!-------------------------print----------------------------------------->
<script type="text/javascript" charset="utf-8">   
    function printDiv(print) {
        var printContents = document.getElementById(print).innerHTML;
        var originalContents = document.body.innerHTML;

        document.body.innerHTML = printContents;

        window.print();

        document.body.innerHTML = originalContents;
    }

</script>