<?php
/**
 * Marketplace - Component Marketplace 
 * ******************************************************************
 *
 * PHP version 7.0
 *
 * @category   Component
 * @package    Joomla
 * @author     WebKul software private limited <support@webkul.com>
 * @copyright  2010 WebKul software private limited
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @version    GIT:5.2
 * @filesource http://store.webkul.com
 * @link       Technical Support:  webkul.uvdesk.com
 * ******************************************************************
 */
// no direct access
defined('_JEXEC') or die('Restricted access');
if (!class_exists('VmConfig')) {
    include JPATH_ADMINISTRATOR .'/components/com_virtuemart/helpers/config.php';
}
VmConfig::loadConfig();
VmLanguage::loadJLang('com_virtuemart', $site = false);
MarketplaceViewMporders::startAdminArea($this);
$doc=JFactory::getDocument();
$style="
.icon-marketplaceorders {
    background-image: url('components/com_marketplace/assets/images/sprite-icon.png');
    background-repeat: no-repeat;
    background-position: -39px -232px !important;
    vertical-align: middle;
    width: 20px;
    height: 25px;
    margin-right: 5px!important;
}

table tr th {
    vertical-align: middle!important;
}

.js-stools-btn-filter {
    display: none;
}

.print_wk_32 {
    background-image: url('components/com_marketplace/assets/images/icon-print.png');
    background-repeat: no-repeat;
    float: left;
    height: 32px;
    margin: auto;
    text-align: center;
    width: 32px;
    margin-right: 5px;
}

.invoicenew_wk_32 {
    background-image: url('components/com_marketplace/assets/images/icon-pdf.png');
    background-repeat: no-repeat;
    float: left;
    height: 25px;
    margin: auto;
    text-align: center;
    width: 25px;
}
";
$doc->addStyleDeclaration($style);
$styleDateCol = 'style="width:5%;min-width:110px"';
?>
<form style="margin:0px" action="<?php echo JRoute::_('index.php?option=com_marketplace&view=mporders'); ?>" method="post" name="adminForm" id="adminForm">
    <?php if (!empty($this->sidebar)) : ?>
    <div id="j-sidebar-container" class="span2">
        <?php echo $this->sidebar; ?>
    </div>
    <div id="j-main-container" class="span10">
        <?php else : ?>
        <div id="j-main-container">
        <?php endif;
        echo JLayoutHelper::render(
            'joomla.searchtools.default', array('view' => $this)
        );
        ?>
            <table class="adminlist table table-striped table-bordered" cellspacing="0" cellpadding="0">
                <thead>
                    <tr bgcolor="#6994C4" style="color:#FFFFFF;vertical-align:top">
                        <th width="8%"><?php echo JText::_('COM_MP_ORDER_LIST_NUMBER');?></th>
                        <th width="26%"><?php echo JText::_('COM_MP_ORDER_PRINT_NAME'); ?></th>
                        <th width="18%"><?php echo JText::_('COM_MP_EMAIL'); ?></th>
                        <th width="18%"><?php echo JText::_('COM_MP_ORDER_PRINT_PAYMENT_LBL'); ?></th>
                        
                        <th class="admin-dates"><?php echo JText::_('COM_MP_ORDER_CDATE'); ?></th>
                        <th class="admin-dates"><?php echo JText::_('COM_MP_ORDER_LIST_MDATE'); ?></th>
                        <th width="10%"><?php echo JText::_('COM_MP_TOTAL'); ?></th>
                        <th><?php echo JText::_('COM_MP_ORDER_LIST_ID')  ?></th>
                        <th style="min-width:70px;width:5%;"><?php echo JText::_('COM_MP_PRINT_VIEW'); ?></th>
                    </tr>
                </thead>
                <?php
                if (count($this->orderslist)) {
                ?>
                
                <tbody>
                    <?php
                    if (count($this->orderslist) > 0) {
                        $i = 0;
                        $k = 0;
                        $keyword = vRequest::getCmd('keyword');
                        foreach ($this->orderslist as $key => $order) {
                            $checked = JHtml::_(
                                'grid.id', $i, $order->virtuemart_order_id
                            );
                    ?>
                    <tr class="row<?php echo $k; ?>">
                        <?php
                        $link
                            = 'index.php?option=com_virtuemart&view=orders&task=edit&virtuemart_order_id='
                            . $order->virtuemart_order_id;
                        ?>
                        <td><?php echo JHtml::_('link', $link, $order->order_number, array('title' => vmText::_('COM_VIRTUEMART_ORDER_EDIT_ORDER_NUMBER') . ' ' . $order->order_number)); ?></td>
                        <td>
                            <?php
                            if ($order->virtuemart_user_id) {
                                $userlink = 'index.php?option=com_virtuemart&view=user&task=edit&virtuemart_user_id[]='. $order->virtuemart_user_id;
                                echo JHtml::_('link', $userlink, $order->order_name, array('title' => vmText::_('COM_VIRTUEMART_ORDER_EDIT_USER') . ' ' .  $order->order_name));
                            } else {
                                echo $order->order_name;
                            }
                            ?>
                        </td>
                        <td>
                            <?php
                            echo $order->order_email;
                            ?>
                        </td>
                        
                        <td><?php echo $order->payment_method; ?></td>
                        
                        <?php
                        $print_url = juri::root() . 'index.php?option=com_virtuemart&view=invoice&layout=invoice&tmpl=component&virtuemart_order_id=' . $order->virtuemart_order_id . '&order_number=' . $order->order_number . '&order_pass='.$order->order_pass;
                        $print_link = "<a href=\"javascript:void window.open('$print_url', 'win2', 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no');\"  >";
                        $print_link .= '<span class="hasTip print_wk_32" title="' . vmText::_('COM_VIRTUEMART_PRINT') . '">&nbsp;</span></a>';
                        $invoice_link = '';
                        
                        $pdfDummi= '&d='.rand(0, 100);
                        if (!$order->invoiceNumber) {
                            $invoice_url = juri::root() . 'index.php?option=com_virtuemart&view=invoice&layout=invoice&format=pdf&tmpl=component&virtuemart_order_id=' . $order->virtuemart_order_id . '&order_number=' . $order->order_number . '&order_pass=' . $order->order_pass . '&create_invoice='.$order->order_create_invoice_pass.$pdfDummi;
                            $invoice_link .= "<a href=\"$invoice_url\"  >".
                                '<span class="hasTip invoicenew_wk_32" title="'.
                                vmText::_('COM_VIRTUEMART_INVOICE_CREATE') .
                                '"></span></a>';
                        } elseif (!shopFunctions::InvoiceNumberReserved($order->invoiceNumber)) {
                            $invoice_url = juri::root() . 'index.php?option=com_virtuemart&view=invoice&layout=invoice&format=pdf&tmpl=component&virtuemart_order_id=' . $order->virtuemart_order_id . '&order_number=' . $order->order_number . '&order_pass=' . $order->order_pass.$pdfDummi;
                            $invoice_link = "<a href=\"$invoice_url\"  >" . '<span class="hasTip invoicenew_wk_32" title="' . vmText::_('COM_VIRTUEMART_INVOICE') . '"></span></a>';
                        }
                        if (!$order->invoiceNumber) {
                            $deliverynote_url = juri::root() . 'index.php?option=com_virtuemart&view=invoice&layout=deliverynote&format=pdf&tmpl=component&virtuemart_order_id=' . $order->virtuemart_order_id . '&order_number=' . $order->order_number . '&order_pass=' . $order->order_pass . '&create_invoice='.$order->order_create_invoice_pass.$pdfDummi;
                            
                        } elseif (!shopFunctions::InvoiceNumberReserved($order->invoiceNumber)) {
                            $deliverynote_url = juri::root() . 'index.php?option=com_virtuemart&view=invoice&layout=deliverynote&format=pdf&tmpl=component&virtuemart_order_id=' . $order->virtuemart_order_id . '&order_number=' . $order->order_number . '&order_pass=' . $order->order_pass.$pdfDummi;
                            
                        }
                        ?>
                            <td><?php echo vmJsApi::date($order->created_on, 'LC2', true); ?></td>
                            <td><?php echo vmJsApi::date($order->modified_on, 'LC2', true); ?></td>
                            <td><?php echo $order->order_total; ?></td>
                            <td><?php echo JHtml::_('link', $link, $order->virtuemart_order_id, array('title' => vmText::_('COM_VIRTUEMART_ORDER_EDIT_ORDER_ID') . ' ' . $order->virtuemart_order_id)); ?></td>
                            <td><?php echo $print_link;echo $invoice_link; ?></td>
                        </tr>
                        <?php
                        $k = 1 - $k;
                        $i++;
                        }
                    }
                } else {
                    echo "<tr ><td colspan='10'><div class='alert alert-info'>
                    <strong>Info!</strong>".JText::_('NO_RECORD_FOUND')."</div></td></tr>";
                }
                ?>
                    </tbody>
                </table>
            </div>
        </div>
        <input type="hidden" name="task" value="" />
        <input type="hidden" name="boxchecked" value="0" />
    </form>
    <?php AdminUIHelper::endAdminArea(); ?>