{block name="content"}


    <div class="row">

        <div class="col-md-3 ib_profile_width">
            {$menu}
        </div>

        <div class="col-md-9">


            <div class="ibox float-e-margins animated fadeIn">
                <div class="ibox-title">
                    <h3>

                    </h3>
                </div>
                <div class="ibox-content">
                    {*
                    {foreach $data as $key => $value}

                        {if is_string($value)}
                            <strong>{ucwords($key)}:</strong> {$value} <br>
                        {/if}


                    {/foreach}
                    *}







            <div class="row">
        <div class="col-lg-12">
         
        </div>
        <div class="col-lg-12"  id="application_ajaxrender">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>Order - {$data->id} </h5>
                    <input type="hidden" name="iid" value="{$data->id}" id="iid">


                    <div class="btn-group  pull-right" role="group" aria-label="...">


                       {if $data->issync eq 1} 

                     <div class="btn-group" role="group">
                          {if ($data->candelivery eq 1) && ($data->deliveryExist eq 0)} 

                             <a onclick="return addDate(this)" href="{$_url}wcsuite/app/sync-order/{$data->id}" class="btn btn-primary  btn-sm"><i class="fa fa-building"></i> Generate Delivery</a>

                             {* <a onclick="return confirm('Do you want to create delivery challan?')" href="{$_url}wcsuite/app/sync-order/{$data->id}" class="btn btn-primary  btn-sm"><i class="fa fa-building"></i> Generate Delivery</a> *}
                                    
                            {elseif ($data->candelivery eq 0) } 
                            <a href="{$_url}contacts/view/{$data->customer_id}/edit/" class="btn btn-primary  btn-sm"><i class="fa fa-building"></i>Location is not found. Please update address</a>

                            {elseif ($data->deliveryExist eq 1) } 
                            <a href="{$_url}crmdelivery/view/{$data->delivery_id}/" class="btn btn-primary  btn-sm"><i class="fa fa-building"></i> View Delivery</a>


                            {/if}

                          {if ($data->invoiceExist eq 0)} 
                            <a onclick="return confirm('Do you want to create invoice?')" href="{$_url}wcsuite/app/sync-invoice/{$data->id}" class="btn btn-warning  btn-sm"><i class="fa fa-building"></i> Generate Invoice</a>
                            {else}
                            <a href="{$_url}invoices/view/{$data->invoice_id}/" class="btn btn-warning  btn-sm"><i class="fa fa-building"></i> View Invoice</a>

                           {/if} 
                        {* <a href="{$_url}wcsuite/app/sync-transaction/{$data->id}"  class="btn btn-green  btn-sm"><i class="fa fa-pencil"></i> Update Payment</a> *}


                          
                        </div>

                       
                       

                        {elseif $data->billing->postcode eq ''}
                             <h3 class="alert alert-warning">No Postcode Found. Please Update </h3>

                        {else}
                            <button id="synchcustomer" data-email="{$data->billing->email|base64_encode}" data-id="{$data->id}" 
                            data-postcode="{$data->billing->postcode}" data-first_name="{$data->billing->first_name}" 
                            data-last_name="{$data->billing->last_name}" data-address_1="{$data->billing->address_1}" 
                            data-address_2="{$data->billing->address_2}" data-city="{$data->billing->city}" 
                            data-state="{$data->billing->state}" data-phone="{$data->billing->phone}" 
                             class="btn btn-primary">Synchronize Customer</button>

                        {/if}

     

                    </div>

                </div>
                <div class="ibox-content">

                    <div class="invoice">
                        <header class="clearfix">
                            <div class="row">
                                <div class="col-sm-6 mt-md">
                                    <h2 class="h2 mt-none mb-sm text-dark text-bold">Order</h2>
                                    <h4 class="h4 m-none text-dark text-bold">#{$data->id}</h4>
                                    {if $data->status eq 'processing'}
                                        <h3 class="alert alert-danger">Webite Status: {$data->status}</h3>
                                    {elseif  $data->status eq 'Paid'}
                                        <h3 class="alert alert-success">Webite Status: {$_L['Paid']}</h3>
                                    {elseif  $data->status eq 'Partially Paid'}
                                        <h3 class="alert alert-info">Webite Status: {$_L['Partially Paid']}</h3>
                                    {else}
                                        <h3 class="alert alert-info">Webite Status: {$data->status}</h3>
                                    {/if}

                                 


                                </div>
                                <div class="col-sm-6 text-right mt-md mb-md">

                                    <div class="ib">
                                        <img src="{$app_url}storage/system/{$config['logo_default']}" alt="Logo" style="margin-bottom: 15px;">
                                    </div>

                                    <address class="ib mr-xlg">
                                        <strong>{$config['CompanyName']}</strong>
                                        <br>
                                        {$config['caddress']}

                                        {if isset($config['vat_number']) && ($config['vat_number'] != '')}

                                            {if $config['tax_system'] == 'India'}

                                                <br>
                                                <strong>GSTIN:</strong> {$config['vat_number']}

                                            {else}

                                                <br>
                                                <strong>{$_L['Vat number']}:</strong> {$config['vat_number']}

                                            {/if}

                                        {/if}


                                    </address>

                                </div>
                            </div>
                        </header>
                        <div class="bill-info">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="bill-to">
                                        <p class="h5 mb-xs text-dark text-semibold"><strong>Address:</strong></p>
                                        <address>


                                            {$data->billing->address_1} <br>
                                            {$data->billing->city} <br>
                                            {$data->billing->state} - {$data->billing->postcode} <br>
                                            {$data->billing->country}

                                            {*getContactFormattedAddress($config,$a)*}

                                            <br>
                                            <strong>{$_L['Phone']}:</strong> {$data->billing->phone}

                                          

                                            <br>
                                            <strong>{$_L['Email']}:</strong> {$data->billing->email}

                                        </address>





                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="bill-data text-right">
                                        <p class="mb-none">
                                            <span class="text-dark">Order Date:</span>
                                            <span class="value">{date( $config['df'], strtotime($data->date_created))}</span>
                                        </p>
                                       
                                        <h2> Order Total: {$data->total} </h2>
                                    
                                    </div>
                                </div>
                            </div>
                        </div>







                        <div class="table-responsive">


                                <table class="table table-bordered invoice-items">
                                    <thead>
                                    <tr class="text-dark">
                                        <th id="cell-id" class="text-semibold">#</th>
                                        <th id="cell-item" class="text-semibold">{$_L['Item']}</th>
                                        <th id="cell-price" class="text-center text-semibold">{$_L['Price']}</th>
                                        <th id="cell-qty" class="text-center text-semibold">{$_L['Qty']}</th>
                                        <th id="cell-total" class="text-center text-semibold">{$_L['Total']}</th>
                                    </tr>
                                    </thead>
                                    <tbody>

                                    {foreach $data->line_items as $item}
                                        <tr>
                                            <td>{$item->id}</td>
                                            <td class="text-semibold text-dark">{$item->name}</td>
                                            <td class="text-center amount">{$item->subtotal}</td>
                                            <td class="text-center">{$item->quantity}</td>
                                            <td class="text-center amount">{$item->total}</td>
                                        </tr>
                                    {/foreach}
                                    </tbody>
                                </table>

                            


                        </div>

                        <div class="invoice-summary">
                            <div class="row">
                                <div class="col-sm-4 col-sm-offset-8">
                                    <table class="table h5 text-dark">
                                        <tbody>
                                        
                                        <tr class="b-top-none">
                                            <td colspan="2">Discount Total</td>
                                            <td class="text-left amount" >{$data->discount_total}</td>
                                        </tr>
                                      

                                      

                                            <tr>
                                                <td colspan="2">{$_L['TAX']}</td>
                                                <td class="text-left amount">{$data->total_tax}</td>
                                            </tr>
                                            
                                          <tr class="h4">
                                                <td colspan="2">{$_L['Grand Total']}</td>
                                                <td class="text-left amount">{$data->total}</td>
                                            </tr>
                                           {* 
                                         {if ($d['credit']) neq '0.00'}
                                            <tr>
                                                <td colspan="2">{$_L['Total']}</td>
                                                <td class="text-left amount" data-a-sign="{$data_a_sign}" data-a-dec="{$data_a_dec}" data-a-sep="{$data_a_sep}" data-p-sign="{$data_p_sign}">{$d['total']}</td>
                                            </tr>
                                            <tr>
                                                <td colspan="2">{$_L['Total Paid']}</td>
                                                <td class="text-left amount" data-a-sign="{$data_a_sign}" data-a-dec="{$data_a_dec}" data-a-sep="{$data_a_sep}" data-p-sign="{$data_p_sign}">{$d['credit']}</td>
                                            </tr>
                                            <tr class="h4">
                                                <td colspan="2">{$_L['Amount Due']}</td>
                                                <td class="text-left amount" data-a-sign="{$data_a_sign}" data-a-dec="{$data_a_dec}" data-a-sep="{$data_a_sep}" data-p-sign="{$data_p_sign}">{$i_due}</td>
                                            </tr>
                                        {else}
                                          
                                        {/if} 
                                        *}
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>

                

                    {if ($data->customer_note) neq ''}
                        <div class="well m-t">
                            {$data->customer_note}
                        </div>
                    {/if}


                   

                </div>


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

 







                </div>
            </div>



        </div>

    </div>
    

        {/block}
{block name="script"}
<script>

function addDate(element)
{
    const today = new Date()
    const tomorrow = new Date(today)
    tomorrow.setDate(tomorrow.getDate() + 1)

    
        month = '' + (tomorrow.getMonth() + 1),
        day = '' + tomorrow.getDate(),
        year = tomorrow.getFullYear();

    if (month.length < 2) 
        month = '0' + month;
    if (day.length < 2) 
        day = '0' + day;

    formatedDate = [year, month, day].join('-');

    var date = prompt("Please enter the order delivery date (yyyy-mm-dd)", formatedDate);

    $(element).attr('href', function() {
        if (date!=null)
            this.href= this.href + '/'+date;
         
        
    });
    if (date!=null)
        return true;
    else 
        return false;
}



$("#synchcustomer").click(function(e){
    
                       var r = confirm("Do you want to synchronize customer?");
  if (r == true) {

       var _url = $("#_url").val();
                var id = $(this).attr("data-id");
                var email = $(this).attr("data-email");
                var account = $(this).attr("data-email");

                var postcode = $(this).attr("data-postcode");
                var first_name = $(this).attr("data-first_name");
                var last_name = $(this).attr("data-last_name");
                var address_1 = $(this).attr("data-address_1");
                var city = $(this).attr("data-city");
                var state = $(this).attr("data-state");
                var phone = $(this).attr("data-phone");
                
                 //var customerid = $(this).attr("data-customerid");
                
                 $.post(_url + 'crmcontroller/crm-sync-customer/', { 'email': email, 'id':id, 'account':account, 'postcode':postcode, 'first_name':first_name, 'last_name':last_name, 'address_1':address_1, 'city':city, 'state':state, 'phone': phone})
                  .done(function (data) {
                    // alert(data);
                       if(data=="1"){
                                location.reload();                            
                        }
                        else {
                            location.reload();   
                            alert(data);
                        }
                    });
                
    
  } else {
    
  }

            // e.preventDefault();
                //$('#ibox_form').block({ message:block_msg });
               
});
/*$("#but_delivery").click(function (e){
    
});*/
</script>

{/block}