<?php
if (empty($Product_Info[0]["Product_ID"])) {
?>
<div class="alert alert-danger" role="alert">
    <button class="close" data-dismiss="alert"></button>
    <strong>Danger: </strong>you can not view or edit this product! 
    <br>
    This product is deleted or disabled.
</div>
<?php
} else {
    if ($permissions->hasPermission('EditProduct')) {
        include("Views/Inventory/EditProduct.php");
    }
?>

<style>
    .profile-pic {
        text-align: center;
        border-radius: 100%;
        -moz-border-radius: 100%;
        -webkit-border-radius: 100%;
        width: 210px;
        height: 210px;
        border: 5px solid #4c0870;
        overflow: hidden;
        margin:0px auto;
        background: #fafafa;
    }
    .profile-pic img {
        width: 188px;
        height: 188px;
        margin-top: 6px;
        border-radius: 100%;
        -moz-border-radius: 100%;
        -webkit-border-radius: 100%;
        overflow: hidden;
        -webkit-transition: all .3s ease-in-out;
        -moz-transition: all .3s ease-in-out;
        transition: all .3s ease-in-out;
    }
    #NewProductUploadPhoto{
        width:25%;
        overflow:hidden;
        position:relative;
    }
    #NewProductUploadPhoto{
        margin-left:128px;
        margin-top:10px;
        background-color:#4c0870 !important;
        color:#fff;
        width:initial;
    }
    #NewProductUploadPhoto > input,#NewProductUploadPhoto > input{
        position:absolute;
        left:0px;
        top:0px;
        width:100%;
        height:100%;
        opacity:0.01;
        cursor:pointer;}
    .b-r {
        border-left-width: 1px;
    }
    .bg-master-lighter {
        border:none;
        background-color:#fff;
        border-top:1px solid #ddd;  
    }
    .table thead tr >th{
        background-color:#4c0870;
        color:#fff;
    }
    .table thead tr th[class*='sorting_'] {
        color: #fff;
    }
</style>
<div class="wrapper">
    <div class="panel invoice">
        <div class="panel-body">
            <?php echo Forms::ModalLoader('ViewProductLoader'); ?>
            <input type="hidden" value="<?php echo!empty($_GET['modal']) ? 1 : 0; ?>" id="is_modal_shown"/>
            <div class="row">
                <?php if ($permissions->hasPermission('EditProduct') && smc_session()['default_setting']['sync_type'] != 2) { ?>
                <a href="#" class="mainPageLinks" data-toggle="modal" data-target="#EditProduct" ><button type='button' class='btn btn-primary pull-right' ><i class='fa fa-pencil'></i> <?php print CommonLanguage::getMessage('Edit'); ?></button></a>
                <?php } if ($permissions->hasPermission('ReportProduct')) { ?>
                <a href="<?php echo SITE_LINK; ?>Inventory/ReportProduct/<?php echo $Product_ID; ?>" class="mainPageLinks" data-toggle="#" data-target="#" ><button type='button' class='btn btn-primary ' ><i class='pg-charts'></i> <?php print CommonLanguage::getMessage('report'); ?></button></a>
                <?php } ?>
                <h1><?php print CommonLanguage::getMessage('product_info'); ?></h1>
                <div class="col-md-4 profile-col  ">
                    <div class="profile-pic">
                        <div class="profile-border" >
                            <img id="ProductloadImagePreview" src="<?php echo $filename1; ?>" data-src="<?php echo $filename1; ?>" alt="" >
                        </div>
                    </div>
                    <?php if(file_exists(dirBase.'uploads/products_photos/' . $Product_ID. '.jpg')){?>
                    <span class="fa fa-trash red-star delete_product_image" data-view="1" data-content="<?php echo $Product_ID; ?>" style="cursor:pointer;"></span>
                    <?php }?>
                </div>
                <div class="col-md-8 b-r b-dashed " id="ProductDetails">
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php print CommonLanguage::getMessage('Code'); ?></label>
                            <div class="col-sm-4 Product_Code"><?php echo $Product_Info[0]["Product_Code"]; ?> </div>
                            <label class="col-sm-2 control-label"><?php print CommonLanguage::getMessage('Name'); ?></label>
                            <div class="col-sm-4 Product_Name">
                                <?php echo $Product_Info[0]["Product_Name"]; ?>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php print CommonLanguage::getMessage('Category'); ?></label>
                            <div class="col-sm-4 Category_ID ">
                                <?php echo $Product_Info[0]["Cat_Name"]; ?>
                            </div>
                            <label class="col-sm-2 control-label"><?php print CommonLanguage::getMessage('Quantity'); ?></label>
                            <div class="col-sm-4 Product_Quantity">
                                <?php echo $Product_Info[0]["Product_Quantity"]; ?>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php print CommonLanguage::getMessage('Taxable'); ?></label>
                            <div class="col-sm-4 Product_VAT">
                                <?php echo $Product_Info[0]["Product_VAT"] ? "Taxtable" : "Not Taxtable"; ?>
                            </div>
                            <label class="col-sm-2 control-label"><?php print CommonLanguage::getMessage('Reorder_Point'); ?></label>
                            <div class="col-sm-4 Product_Reorder_Point">
                                <?php echo $Product_Info[0]["Product_Reorder_Point"]; ?>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">PLU</label>
                            <div class="col-sm-4 Product_PLU">
                                <?php echo $Product_Info[0]["Product_PLU"]; ?>
                            </div>
                            <label class="col-sm-2 control-label"><?php print CommonLanguage::getMessage('on_scale'); ?></label>
                            <div class="col-sm-4 on_scale">
                                <?php echo CommonLanguage::getMessage($Product_Info[0]["on_scale"] ? 'yes' : 'no'); ?>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo CommonLanguage::getMessage('max_discount') ?></label>
                            <div class="col-sm-4 Product_Limit_Discount">
                                <?php echo $Product_Info[0]['Product_Limit_Discount'] . ' %'; ?>
                            </div>
                            <label class="col-sm-2 control-label"><?php echo CommonLanguage::getMessage('brand_name') ?></label>
                            <div class="col-sm-4 brand_name">
                                <?php echo $Product_Info[0]['brand_name']; ?>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label <?php echo smc_session()['default_setting']['activate_card_tax'] == 0 ? 'hidden' : ''; ?>"><?php print CommonLanguage::getMessage('is_card'); ?></label>
                            <div class="col-sm-4 is_card <?php echo smc_session()['default_setting']['activate_card_tax'] == 0 ? 'hidden' : ''; ?>">
                                <?php echo CommonLanguage::getMessage($Product_Info[0]["is_tax"] ? 'yes' : 'no'); ?>
                            </div>
                            <label class="col-sm-2 control-label <?php echo smc_session()['default_setting']['activate_expiry_date'] == 0 ? 'hidden' : ''; ?>"><?php print CommonLanguage::getMessage('expiry') . ' ?'; ?></label>
                            <div class="col-sm-4 is_expiry <?php echo smc_session()['default_setting']['activate_expiry_date'] == 0 ? 'hidden' : ''; ?>">
                                <?php echo CommonLanguage::getMessage($Product_Info[0]["is_expiry"] ? 'yes' : 'no'); ?>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">

                            <label class="col-sm-2 control-label "><?php print CommonLanguage::getMessage('force_change_price') . ' ?'; ?></label>
                            <div class="col-sm-4 force_change_price ">
                                <?php echo CommonLanguage::getMessage($Product_Info[0]["force_change_price"] ? 'yes' : 'no'); ?>
                            </div>
                            <?php if (smc_session()['default_setting']['activate_product_duration_reservation']) { ?>
                            <label class="col-sm-2 control-label "><?php print CommonLanguage::getMessage('duration_reservation') . ' ?'; ?></label>
                            <div class="col-sm-4 duration_reservation ">
                                <?php echo CommonLanguage::getMessage($Product_Info[0]["duration_reservation"] ? 'yes' : 'no'); ?>
                            </div>
                            <?php } ?>
                        </div>
                    </div>
                    <?php foreach ($class_price as $class) { ?>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $class['Class_Name'] . ' ' . CommonLanguage::getMessage('Price'); ?></label>
                            <div class="col-sm-4 price" data-class="<?php echo $class['Class_ID']; ?>">
                                <span class="PriceSpan"><?php echo $class['Product_Price'] ?></span> <?php echo $class['Currency_Symbol'] ?>
                            </div>
                        </div>
                    </div>
                    <?php
                                                           } $i = 1;
    foreach ($uom_conversion as $uom_barcode) {
        ;
                    ?>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo CommonLanguage::getMessage('UOM') . ' ' . $i; ?></label>
                            <div class="col-sm-4 uom" data-uom="<?php echo $uom_barcode['uom_conversion_id'] ?>">
                                <span class="from_uom">
                                    <strong><?php echo CommonLanguage::getMessage('From'); ?></strong> 
                                    <?php echo $uom_barcode['from_name']; ?>
                                </span> 
                                <span class="to_uom">
                                    <strong><?php echo CommonLanguage::getMessage('To'); ?></strong> 
                                    <?php echo $uom_barcode['to_name'] ?>
                                </span> 
                                <span class="conversion_uom"><?php echo $uom_barcode['conversion_amount'] ?></span> 
                                <span class="Barcode">
                                    <strong><?php echo CommonLanguage::getMessage('barcode'); ?></strong>
                                    <?php echo $uom_barcode['Bar_Code'] ?>
                                </span> 
                            </div>
                        </div>
                    </div>
                    <?php
                        $i++;
    }
                    ?>
                    <br>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo CommonLanguage::getMessage('additional_barcodes') ?></label>
                            <div class="col-sm-4 additional_barcodes">
                                <?php echo $Product_Info[0]["additional_barcodes"]; ?>
                            </div>
                            <label class="col-sm-2 control-label"><?php echo CommonLanguage::getMessage('Type') ?></label>
                            <div class="col-sm-4 product_type">
                                <?php echo CommonLanguage::getMessage($Product_Info[0]["product_type"] == 0 ? 'sales_purchase' : ($Product_Info[0]["product_type"] == 1 ? 'sales' : 'purchase')); ?>
                            </div>
                        </div>
                    </div>
                    <br>
                </div>
            </div>
            <br>
            <?php
    if (empty($ProductLocation)) {
        echo ("<div style='background-color:#4c0870;text-align: center;;color:#fff'>" . CommonLanguage::getMessage('not_assigned_to_depot') . "</div><br>");
    } else {
            ?>
            <table class="table table-bordered table-hover demo-table-search" id="DepotContent">
                <thead>
                    <tr>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('Depot'); ?></th>
                        <th class="text-center"><?php print CommonLanguage::getMessage('Quantity'); ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
        for ($x = 0; $x < count($ProductLocation); $x++) {
            $CurItem = $ProductLocation[$x];
                    ?>
                    <tr>
                        <td class="text-center"><?php echo $CurItem['Depot_Name'] ?></td>
                        <td class="text-center"><?php echo $CurItem['Product_Depot_Quantity'] ?></td>
                    </tr>
                    <?php } ?>             
                </tbody>
            </table>
            <?php } ?>
        </div>
    </div>
</div>
<script>
    $(function () {
        if ($('#is_modal_shown').val() == 1)
            $('#EditProduct').modal('show');
        $('.delete_product_image').on('click',function(){
            var parent =  $(this),
                data={directory_name:'products_photos',image_name:parent.attr('data-content')+'.jpg'};
            deleteSpecificImage(data,parent.attr('data-view') == 1 ? '#ViewProductLoader' : '#UpdateProductIsBusy',function(response){
                if(response[1] == "success"){
                    $('#ProductloadImagePreview,#UpdateProductUploadImagePreview').attr('src','<?php echo SITE_LINK; ?>img/profiles/product.png').attr('data-src','<?php echo SITE_LINK; ?>img/profiles/product.png');
                    $('.delete_product_image').remove();
                }
            });
        });
    })
</script>
<?php } ?>