<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;
    }
    .inv-info{
        font-size: 15px;
        font-weight: bold;
    }
    .border-div{
        border: 2px solid #000;
        border-style: dotted;
        padding: 10px;
        border-right:0;
        border-left:0;
        border-top:0;
    }

    .border-tr{
        border: 2px solid #000;
        border-style: dotted;
        padding: 12px;
        border-bottom:0;
        border-left:0;
        border-top:0;
    }
    .border-td{
        border: 2px solid #000;
        border-style: dotted;
        padding: 10px;
        border-bottom:0;
        border-top:0;
    }
    .border-table{
        border: 2px solid #000;
        border-style: dotted;
        border-right:0;
        border-left:0;
        margin-top:15px;
    }
    .table tbody tr td{
        /*line-height:12px;*/
    }
    .table thead tr th{
        background: #ddd;
    }

    h5{
        font-size:17px !important;
    }
    .phone-l{
        margin-left:1px !important;
    }
    .font-type-1{
        font-size:medium !important;
    }
    .font-type{
        font-size:large !important;
    }
    h5{
        line-height: 15px !important;
    }
    h4{
        line-height: 18px !important;
    }
    @media print {
        .table thead tr th{
            background: #ddd;
        }

        h5{
            font-size:14px !important;
        }
        img{
            max-width: 50% !important;
        }

        .table tbody tr td{
            /*line-height:20px;*/
            font-size:1em !important;
        }
        .phone-l{
            margin-left:1px !important;
        }.font-type-1{
            font-size:medium !important;
        }
        .font-type{
            font-size:large !important;
        }
        .mytitle{
            font-size:2.5em !important;
        }


        .footer{
            bottom:-90px;
            position:fixed;
        }	
    }

</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>

<?php
$total_amount = $total[0][$IsVendor ? "Purchase_Net_Total" : "Invoice_Net_Total"];
$curr = $total[0][$IsVendor ? 'Currency_ID' : 'Invoice_Currency'];
include("num_to_ar.php");
$ar_number = new convert_ar(floatval($total_amount), ( $curr == 144 ? "male" : "female"));
if ($curr == 144)
    $name_total = $ar_number->convert_number("دولار أميركي", "سنت") . ' فقط لا غير';
else
    $name_total = $ar_number->convert_number() . ' ليرة لبنانية فقط لا غير';
?>
<!--body wrapper start-->
<div class="wrapper">
    <div class="panel invoice">
        <div class="panel-body">

            <div class="row hidden">
                <div class="col-xs-4  m-b-10">
                    <h4 ><?php echo $org_details[0]["Organization_Legal_Name"] ?></h4>
                    <h4 class="phone-l"><?php echo $org_details[0]["Organization_Phone"] ?></h4>

                    <h5> <?php echo $org_details[0]["Name"] . '-' . $org_details[0]['Organization_Province'] ?></h5>
                    <h4 class="phone-l"><?php echo CommonLanguage::getMessage('reg_nb') ?>&nbsp;<?php echo $org_details[0]["Organization_Commercial_Registry"] ?></h4>
                    <h4 class="phone-l"><?php echo CommonLanguage::getMessage('Email') ?>:&nbsp;<?php echo $org_details[0]["Organization_Email"] ?></h4>
                    <h4 class="phone-l"><?php echo CommonLanguage::getMessage('Depot') ?>:&nbsp;<?php echo $total[0]['Depot_Name'] ?></h4>
                </div>
                <div class="col-xs-4 text-center">
                    <img src="<?= upload_url;?>org_logo/invoice_logo.jpg" alt="" style="max-width:150px"/>

                </div>
                <div class="col-xs-4  m-b-10">
                    <h4 class="text-right"><?php echo $org_details[0]["Organization_Name"] ?></h4>
                    <h4 class="text-right"><?php echo $org_details[0]["Organization_Phone"] ?></h4>
                    <h5 class="text-right"><?php echo CommonLanguage::getMessage($org_details[0]["Name"], 'ar') . ' - ' . $org_details[0]["Organization_Street"] ?></h5>
                    <h4 class="text-right"> <?php echo CommonLanguage::getMessage('reg_nb', 'ar') ?>&nbsp;<?php echo $org_details[0]["Organization_Commercial_Registry"] ?></h4>
                </div>
            </div>
            <div class="col-xs-8 col-md-8 pull-right">
                <div class="row">
                    <div class="col-xs-5">
                        <h1 class="text-center mytitle"><?php echo $IsVendor ? CommonLanguage::getMessage('purchase_invoice') : CommonLanguage::getMessage('sales_invoice') ?></h1>
                    </div>
                    <div class="col-xs-7 print_delv">
                        <div class="total-purchase">
                            <?php echo CommonLanguage::getMessage('total') ?>
                        </div>
                        <div class="amount">
                            <strong><span class='CurrencyIndicator'><?php echo $total[0]['Currency_Symbol']; ?></span>&nbsp;<span class=""><?php echo Forms::DecimalNumber($total[0][$IsVendor ? "Purchase_Net_Total" : "Invoice_Net_Total"]); ?></span></strong>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12 col-md-12 border-div">
                <div class="row">
                    <div class="col-xs-6 font-type ">
                        <?php print CommonLanguage::getMessage('Name'); ?>: <?php echo $From_Details[0][$IsVendor ? "Supplier_Name" : "Customer_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" : "Customer_Address"] ?>
                        <br/><?php print CommonLanguage::getMessage('Phone'); ?>: <?php echo $From_Details[0][$IsVendor ? "Supplier_Mobile" : "Customer_Mobile"] . "  " . $From_Details[0][$IsVendor ? "Supplier_Phone" : "Customer_Phone"] ?>
                        <?php if (!$IsVendor) { ?>  <br/><?php print CommonLanguage::getMessage('account_code'); ?>: <?php echo $From_Details[0]["Account_Code"] ?><?php } ?>



                    </div>

                    <div class="col-xs-6 font-type">
                        <div> <?php echo CommonLanguage::getMessage($IsVendor ? 'purchase_voucher' : 'invoice'); ?> #&nbsp;<?php echo ($IsVendor ? '' : $total[0]['invoice_prefix']) . $total[0][$IsVendor ? "Purchase_ID" : "Invoice_ID"]; ?></div>
                        <div <?php echo $IsVendor ? "" : "style='display:none;'"; ?>>
                            <?php echo $IsVendor ? CommonLanguage::getMessage('supplier_invoice_nb') : ''; ?> 	:&nbsp;<?php echo $total[0][$IsVendor ? "Supplier_Invoice_ID" : ""]; ?></div>
                        <div><?php print CommonLanguage::getMessage('Date'); ?> :&nbsp;<?php echo $total[0][$IsVendor ? "Purchase_Date" : "Invoice_Date"]; ?></div>
                        <div><?php print CommonLanguage::getMessage('due_date'); ?>:&nbsp;<?php echo $total[0][$IsVendor ? "Purchase_Due_Date" : "Invoice_Due_Date"]; ?></div>
                        <div class="print_delv"><?php print CommonLanguage::getMessage('Currency'); ?> :&nbsp;<?php echo $total[0][$IsVendor ? "Currency_Name" : "Currency_Name"]; ?></div>
                        <?php if (!$IsVendor) { ?><div><?php print CommonLanguage::getMessage('Depot'); ?> :&nbsp;<?php echo explode("-", $total[0]['Depot_Name'])[0]; ?></div>
                            <div class=" hidden"> <?php print CommonLanguage::getMessage('salesman'); ?> :&nbsp;<?php echo $total[0]["Employee_Name"]; ?></div><?php } ?>
                    </div>

                </div>


                <table class="table  border-table">
                    <thead>
                        <tr class="border-div">
                            <th class="border-td text-center">No.</th>
                            <th  class="border-tr text-center"><?php print CommonLanguage::getMessage('Code'); ?></th>
                            <th class="border-tr text-center"><?php print CommonLanguage::getMessage('Item'); ?></th>
                            <th class="border-tr text-center"><?php print CommonLanguage::getMessage('qty'); ?></th>

                                <!--<th class="border-tr text-center" ><?php print CommonLanguage::getMessage('Description'); ?></th>-->
                            <th class="border-tr print_delv text-center"><?php print CommonLanguage::getMessage('price'); ?></th>
                            <th class="border-tr print_delv text-center" ><?php print CommonLanguage::getMessage('disc'); ?></th>
                            <th class="border-tr print_delv text-center"><?php print CommonLanguage::getMessage('total'); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $total_qty = 0.0;
                        for ($i = 0; $i < count($list) - 2; $i++) {
                            $total_qty += $list[$i]["Item_Quantity_Current"];
                            ?>
                            <tr>
                                <td class=" border-td text-center"><?php echo $i + 1; ?></td>
                                <td  class="border-tr text-center"><?php echo $list[$i]["Code"]; ?></td>

                                <td class="border-tr text-center"><?php echo $list[$i]["Name"]; ?></td>
                                <td class="border-tr text-center"><?php echo $list[$i]["Item_Quantity_Current"]; ?> </td>

                                                        <!--<td class="border-tr text-center " ><?php echo $list[$i]["product_description"]; ?></td>-->
                                <td class="border-tr print_delv text-center"><span class='CurrencyIndicator'></span>&nbsp;<span class=""><?php echo Forms::DecimalNumber($list[$i][$IsVendor ? "Item_Price" : "Product_Net_Price"]); ?></span></td>
                                <td class="border-tr print_delv text-center"><span class='CurrencyIndicator'></span>&nbsp;<span class=""><?php echo Forms::DecimalNumber($list[$i][$IsVendor ? "Item_Discount" : "Product_Discount"]); ?>&nbsp%</span></td>
                                <td class="border-tr print_delv text-center"><span class='CurrencyIndicator'></span>&nbsp;<span class=""><?php echo Forms::DecimalNumber($list[$i][$IsVendor ? "Product_Total_Price" : "Product_Total_Price"] + $list[$i][$IsVendor ? "Item_VAT" : "Product_VAT"]); ?></span> </td>
                            </tr>
                        <?php } ?>
                    </tbody>
                </table>

                <div class="row">
                    <?php if (!$IsVendor) { ?>
                        <div class="col-xs-4 font-type hidden">
                            <div class="col-xs-6 "><span><?php echo CommonLanguage::getMessage('previous_balance') ?></span>:</div><?php echo (is_numeric($total[0]['previous_balance']) ? CommonFunctions::public_round_number($total[0]['previous_balance']) : $total[0]['previous_balance']); ?><br/>
                            <div class="col-xs-6 "><span><?php echo CommonLanguage::getMessage('current_balance') ?></span>:</div><?php echo (is_numeric($total[0]['current_balance']) ? CommonFunctions::public_round_number($total[0]['current_balance']) : $total[0]['current_balance']); ?>

                        </div>
                    <?php } ?>
                    <div class="col-xs-3 ">


                    </div>
                    <div class="col-xs-4 font-type  pull-right print_delv">
                        <div class="col-xs-6"><span><?php echo CommonLanguage::getMessage('subtotal') ?></span>:&nbsp;</div><?php echo Forms::DecimalNumber($total[0][$IsVendor ? "Purchase_Sub_Total" : "Invoice_Sub_Total"]); ?><br/>

                        <div class="col-xs-6"><span><?php echo CommonLanguage::getMessage('Quantity') ?></span>:&nbsp;</div><?php echo Forms::DecimalNumber($total_qty); ?><br/>
                        <div class="col-xs-6"><span><?php echo CommonLanguage::getMessage('vat') . '(' . smc_session()['vat_percent'] . '%)' ?></span>:&nbsp;</div><?php echo Forms::DecimalNumber($total[0][$IsVendor ? "Purchase_VAT" : "Invoice_VAT"]); ?><br/>
                        <div class="col-xs-6 "><span><?php echo CommonLanguage::getMessage('disc') ?></span>:&nbsp;</div><?php echo Forms::DecimalNumber($total[0][$IsVendor ? "Purchase_Discount" : "Invoice_Discount"]); ?><br/>
                        <div class="col-xs-6 "><span><?php echo CommonLanguage::getMessage('total_paid') ?></span>:&nbsp;</div><?php echo Forms::DecimalNumber($total[0][$IsVendor ? "Purchase_Paid_Amount" : "Invoice_Paid_Amount"]); ?><br/>
                        <div class="col-xs-6 "><span><strong><?php echo CommonLanguage::getMessage('grand_total') ?></span>:</strong>&nbsp;</div><strong><?php echo Forms::DecimalNumber($total[0][$IsVendor ? "Purchase_Net_Total" : "Invoice_Net_Total"]); ?></strong>
                    </div>

                </div>


            </div>
            <br>
            <br>
            <div class="col-xs-12 text-right ">
                <h3><?php echo $name_total ?></h3>
            </div>
            <br>
            <br>
            <div class="col-xs-12 hidden">
                <div class="row">
                    <div class="col-xs-4">
                        <h4><strong><?php echo CommonLanguage::getMessage('receiver') ?>:</strong></h4>  &nbsp;
                    </div>
                    <div class="col-xs-4 pull-right">
                        <h4><strong><?php echo CommonLanguage::getMessage('signature') ?> :</strong></h4> &nbsp; 
                    </div>
                </div>
            </div>

            <div class="col-xs-12">

                <div class="row">
                    <div class="footer" style="direction:rtl;bottom:90px;position:fixed;font-size:large; text-align: center;">



                    </div>
                </div>
            </div>

            <div class="row no-print">
                <div class="col-md-12">
                    <div class="pull-right">
                        <a id="invoice_print_btn" class="btn btn-danger" onclick="javascript:$('.print_delv').removeClass('no-print');javascript:window.print();"><i class="fa fa-print"></i> <?php print CommonLanguage::getMessage('print'); ?></a>
                        <a id="delivery_print_btn" class="btn btn-success-darker" onclick="javascript:$('.print_delv').addClass('no-print');window.print();"><i class="fa fa-print"></i> <?php print CommonLanguage::getMessage('print_delv'); ?></a>
                        <!--                        <a href="#" data-download-pdf='' data-title='< ?php echo CommonLanguage::getMessage($IsVendor ? "purchase_invoice" : "sales_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>

