<?
global $db;
ob_start();
?>
<input type="hidden" name="order_id" value="<?= $this -> order['id'];?>">
<div class="details">
  <div class="row">
  <div class="col-xl-8">
    <div class="row">
      <div class="col-md-6">
        <div class="text-big">Numer zamówienia: <b id="order-number"><?= $this -> order[ 'number' ];?></b> <i class="fa fa-copy" onclick="copyToClipboard( 'order-number' ); return false;"></i></div>
        <div>Data zamówienia <b><?= $this -> order[ 'date_order' ];?></b></div>
        <br>
        <div class="text-big">Dane do dostawy:</div>
        <div class="row">
          <div class="col-sm-6">
            <input type="text" class="form-control" name="client_name" value="<?= $this -> order[ 'client_name' ];?>" placeholder="Imię">
          </div>
          <div class="col-sm-6">
            <input type="text" class="form-control" name="client_surname" value="<?= $this -> order[ 'client_surname' ];?>" placeholder="Nazwisko">
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <input type="text" class="form-control" name="client_street" value="<?= $this -> order[ 'client_street' ];?>" placeholder="Ulica">
          </div>
        </div>
        <div class="row">
          <div class="col-sm-6">
            <input type="text" class="form-control" name="client_postal_code" value="<?= $this -> order[ 'client_postal_code' ];?>" placeholder="Kod pocztowy">
          </div>
          <div class="col-sm-6">
            <input type="text" class="form-control" name="client_city" value="<?= $this -> order[ 'client_city' ];?>" placeholder="Miasto">
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <input type="text" class="form-control" name="client_email" value="<?= $this -> order[ 'client_email' ];?>" placeholder="Email">
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <input type="text" class="form-control" name="client_phone" value="<?= $this -> order[ 'client_phone' ];?>" placeholder="Telefon">
          </div>
        </div>
        <? if ( $this -> order['firm_name'] ):?>
          <div class="text-big">Dane do faktury:</div>
          <div class="row">
            <div class="col-12">
              <input type="text" class="form-control" name="firm_name" value="<?= $this -> order[ 'firm_name' ];?>" placeholder="Nazwa firmy">
            </div>
          </div>
          <div class="row">
            <div class="col-12">
              <input type="text" class="form-control" name="firm_street" value="<?= $this -> order[ 'firm_street' ];?>" placeholder="Ulica">
            </div>
          </div>
          <div class="row">
            <div class="col-sm-6">
              <input type="text" class="form-control" name="firm_postal_code" value="<?= $this -> order[ 'firm_postal_code' ];?>" placeholder="Kod pocztowy">
            </div>
            <div class="col-sm-6">
              <input type="text" class="form-control" name="firm_city" value="<?= $this -> order[ 'firm_city' ];?>" placeholder="Miasto">
            </div>
          </div>
          <div class="row">
            <div class="col-12">
              <input type="text" class="form-control" name="firm_nip" value="<?= $this -> order[ 'firm_nip' ];?>" placeholder="NIP">
            </div>
          </div>
        <? endif;?>
      </div>
      <div class="col-md-6">
        <div>Kwota zamówienia <b><?= $this -> order[ 'summary' ];?> zł</b></div>
        <br>
        <div class="row">
          <div class="col-12">
            <select name="transport_id" class="form-control" id="transport_id">
              <option value="0">--- wybierz formę transportu ---</option>
              <? if ( \S::is_array_fix( $this -> transport ) ): foreach ( $this -> transport as $transport_tmp ):?>
                <option value="<?= $transport_tmp['id'];?>" <? if ( $this -> order['transport_id'] == $transport_tmp['id'] ):?>selected="selected"<? endif;?>>
                  <?= $transport_tmp['name'];?> - <?= $transport_tmp['cost'];?> zł
                </option>
              <? endforeach; endif;?>
            </select>
          </div>
        </div>
        <div class="row row-flex">
          <div class="col-12">
            <div class="input-group">
              <input type="text" class="form-control" name="inpost_paczkomat" id="inpost_paczkomat" value="<?= $this -> order[ 'inpost_paczkomat' ];?>" placeholder="Paczkomat">
              <span class="input-group-addon btn btn-danger btn-paczkomat">
                <i class="fa fa-folder"></i>
              </span>
            </div>
          </div>
        </div>

        <div class="row">
          <div class="col-12">
            <select name="payment_method_id" class="form-control" id="payment_method_id">
              <option value="0">--- wybierz formę płatności ---</option>
              <? if ( \S::is_array_fix( $this -> payment_methods ) ): foreach ( $this -> payment_methods as $payment_method ):?>
                <option value="<?= $payment_method['id'];?>" <? if ( $this -> order['payment_method_id'] == $payment_method['id'] ):?>selected="selected"<? endif;?>>
                  <?= $payment_method['name'];?>
                </option>
              <? endforeach; endif;?>
            </select>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="col-xl-4">
    <div class="order-status text-big">
      <?= $this -> order_statuses[ $this -> order[ 'status' ] ];?>
    </div>
    <div class="form-group status_select">
      <select class="form-control" id="order-status">
        <? foreach ( $this -> order_statuses as $key => $val ):?>
        <option value="<?= $key;?>" <? if ( $key==$this -> order[ 'status' ] ):?>selected="selected"
          <? endif;?>><?= $val;?>
        </option>
        <? endforeach;?>
      </select>
    </div>
    <div class="row">
      <div class="col-12 buttons">
        <button class="btn btn-primary order_status_change_email">zmień status i wyślij email</button>
        <button class="btn btn-success order_status_change">zmień status</button>
      </div>
      <div class="col-12 order-history">
        <? if ( \S::is_array_fix( $this -> order['statuses'] ) ): foreach ( $this -> order['statuses'] as $status ):?>
          <div><b><?= date( 'Y-m-d H:i', strtotime( $status['date'] ) );?></b>: <?= $this -> order_statuses[$status['status_id']];?></div>
        <? endforeach; endif;?>
      </div>
    </div>
  </div>
    <div class="col-md-4">
    </div>
    <div class="col-md-4">
    </div>
    <div class="col-md-4">
      <div class="text-big">Wiadomość do zamówienia:</div>
      <div> <b> <?= $this -> order[ 'message' ];?> </b></div>
    </div>
  </div>
  <div class="row">
    <div class="col-12">
      <div class="table-responsive">
      <table class="table">
        <thead>
          <tr>
            <th>Zdjęcie</th>
            <th scope="col">Nazwa</th>
            <th scope="col" class="tab-center">Ilość</th>
            <th scope="col" class="tab-right">Cena / szt:</th>
            <th scope="col" class="tab-right">Cena / szt (po rabacie):</th>
            <th scope="col" class="tab-right">Suma (po rabacie):</th>
          </tr>
        </thead>
        <tbody>
          <? if ( is_array( $this -> order[ 'products' ] ) ): foreach ( $this -> order[ 'products' ] as $product ):?>
          <tr class="order-product-details">
            <td class="product-image">
              <? if ( $product['product_id'] ):?>
                <img src="<?= \shop\Product::getProductImg( (int)$product['product_id'] );?>">
              <? endif;?>
            </td>
            <td>
              <a href="<?= \shop\Product::getProductUrl( (int)$product['product_id'] );?>" target="_blank"><?= $product[ 'name' ];?></a>
              <br />
              <div class="atributes">
                <?= $product[ 'attributes' ];?>
              </div>
              <br />
              <div class="product-message">
                <?= $product[ 'message' ] != '' ? '<strong>Wiadomość:</strong> ' . $product['message'] : '';?>
              </div>
            </td>
            <td class="tab-center"><?= $product[ 'quantity' ];?></td>
            <td class="tab-right"><?= $product[ 'price_brutto' ];?> zł</td>
            <td class="tab-right"><?= $product[ 'price_brutto_promo' ];?> zł</td>
            <td class="tab-right"><?= $product[ 'price_brutto_promo' ] * $product[ 'quantity' ];?> zł</td>
          </tr>
          <? endforeach; endif;?>
        </tbody>
      </table>
    </div>
    </div>
  </div>
  <div class="row">
    <div class="col-12">
      <form>
        <div class="form-group">
          <label for="note">Notatki</label>
          <textarea class="form-control" id="note" rows="10"></textarea>
        </div>
      </form>
    </div>
  </div>
</div>
<?
$out = ob_get_clean();

$grid = new \gridEdit;
$grid -> id = 'order-details';
$grid -> gdb_opt = $gdb;
$grid -> include_plugins = true;
$grid -> title = 'Szczegóły zamówienia: ' . $this -> order[ 'number' ];
$grid -> buttons = [
    [
      'label' => 'Zapisz zamówienie',
      'icon'  => 'fa-save',
      'class' => 'btn btn-success btn-sm mr5 ml5',
      'id' => 'order-save'
    ],
    [
        'label' => 'Wstecz',
        'url'   => '/admin/shop_order/order_details/order_id=' . $this -> order['id'],
        'icon'  => 'fa-reply',
        'class' => 'btn btn-dark btn-sm mr5'
    ]
];
$grid -> default_buttons = false;
$grid -> external_code = $out;
echo $grid -> draw();
?>
<div class="inpost-map-container">
  <a href="#" onclick="$( '.inpost-map-container' ).hide(); return false;" class="inpost-hide"><?= \S::lang( 'zamknij' );?></a>
  <div id="inpost-map"></div>
</div>
<link class="footer" rel="stylesheet" type="text/css" href="https://geowidget.easypack24.net/css/easypack.css">
<script class="footer" type="text/javascript" src="https://geowidget.easypack24.net/js/sdk-for-javascript.js"></script>
<script type="text/javascript">
  $( function()
  {
    $( 'body' ).on( 'change', '#transport_id', function()
    {
      if ( $( this ).val() != '2' )
        $( '#inpost_paczkomat' ).closest( '.row' ).hide();
      else
        $( '#inpost_paczkomat' ).closest( '.row' ).show();
    });

    $( 'body' ).on( 'click', '.btn-paczkomat', function()
    {
      window.easyPackAsyncInit = function () {
        easyPack.init({
          mapType: 'osm',
          searchType: 'osm',
        });

        var map = easyPack.mapWidget( 'inpost-map', function(point)
        {
          $( '#inpost_paczkomat' ).val( point.name + ' | ' + point.address.line1 + ', ' + point.address.line2 );
          $( '.inpost-map-container' ).hide();
        });
      };
      $( '.inpost-map-container' ).show();
    });

    $( 'body' ).on( 'click', '#order-save', function(e)
    {
      e.preventDefault();
      $( '#fg-order-details' ).attr( 'method', 'POST' ).attr( 'action', '/admin/shop_order/order_save/' ).submit();
    });
  });
</script>