<?= $this->extend('rs/template', $data); ?>
<?= $this->section('content'); ?>
<?php
if ($edit)
    echo '<form action="?$id" method="post" accept-charset="utf-8">';
else
     echo '<form action="" method="post" accept-charset="utf-8">';

?>
<style>
 select{width:300px!important;}
 input[type=text]{width:300px!important;}
 input[type=date]{width:300px!important;}

 textarea{width:300px!important;}
</style>
<div class="container-fluid">
  <div class="card shadow mb-4">
	<div class="card-header py-3 text-dark" >
	<h2><?php echo $title ?></h2>
		<table class="table table-sm text-dark font-weight-bold small ml-1">

<?php if ($edit) { ?>
        <tr>
            <td>ID:</td><td> <?php echo $formitem["id"]; ?></td>
        </tr>
<?php } ?>

    <tr>
        <td>
            Nr. comanda</td><td>
            <input size="50" type="text" name="order_num" value="<?php
            if (isset($formitem)) {
                echo $formitem["order_num"];
            }
            ?>"/></td>
    </tr>
    <tr>
        <td>
           Client</td><td>
			
		   <select class="form-select form-select-sm" name ="customer" style="width:300px!important">
           <?php
			
			//var_dump($customers);
			echo '<option value="">-- Selecteaza clientul --</option>';
			foreach($customers as $cust)
			{ 
				if($formitem["customer"]==$cust['code'])
					echo '<option value="'.$cust['code'].'" selected>'.$cust['code'].' ('.$cust['name'].')</option>';
				else
				echo '<option value="'.$cust['code'].'">'.$cust['code'].' ('.$cust['name'].')</option>';
			}
            ?></select></td>
    </tr>
	
	 <tr>
        <td>Data</td><td>
            <input type="text" name="order_date"  class="form-select form-select-sm" aria-label=".form-select-sm example"  value="<?php
            if (isset($formitem)) {
                echo $formitem["order_date"];
            }
            ?>"/></td>
    </tr>
	
	
	 <tr>
        <td>
           Status</td><td>
			
		   <select class="form-select form-select-sm" name ="order_status" style="width:300px!important;">
           <?php
			
			//var_dump($customers);
			$options = array();
		    foreach($statuses as $stat)
			{ 
				if($formitem["order_status"]==$stat['code'])
					echo '<option value="'.$stat['code'].'" selected>'.$stat['code'].'</option>';
				else
					echo '<option value="'.$stat['code'].'" >'.$stat['code'].'</option>';
			}
            ?></select></td>
    </tr>
	
	<tr>
        <td>Colete</td><td>
            <input size="50" type="text" name="no_of_package" value="<?php
            if (isset($formitem)) {
                echo $formitem["no_of_package"];
            }
            ?>"/></td>
    </tr>
	
	<tr>
        <td>Greutate totala</td><td>
            <input size="50" type="text" name="total_weight" value="<?php
            if (isset($formitem)) {
                echo $formitem["total_weight"];
            }
            ?>"/></td>
    </tr>
	
	<tr>
        <td>AWB</td><td>
            <input size="50" type="text" name="awb" value="<?php
            if (isset($formitem)) {
                echo $formitem["awb"];
            }
            ?>"/></td>
    </tr>
	
	<tr>
        <td>AWB URL</td><td>
			
            <?php
            if (isset($formitem) && $formitem["awb_url"] ) {
                echo '<a href ="'.$formitem["awb_url"].'" target="_blank">'.$formitem["awb_url"].'</a>';
            }
            ?></td>
    </tr>
	
	
  <tr>
        <td>Destinatar</td><td>
            <input size="50" type="text" name="receiver" value="<?php
            if (isset($formitem)) {
                echo $formitem["receiver"];
            }
            ?>"/></td>
    </tr>
	
    <tr>
        <td>Localitate</td><td>
            <input size="50" type="text" name="city" value="<?php
            if (isset($formitem)) {
                echo $formitem["city"];
            }
            ?>"/></td>
    </tr>

	 <tr>
        <td>Judet</td><td>
            <input size="50" type="text" name="district" value="<?php
            if (isset($formitem)) {
                echo $formitem["district"];
            }
            ?>"/></td>
    </tr>

	
	 <tr>
        <td>Adresa</td><td>
            <input size="50" type="text" name="address" value="<?php
            if (isset($formitem)) {
                echo $formitem["address"];
            }
            ?>"/></td>
    </tr>
	
	<tr>
        <td>Cod postal</td><td>
            <input size="50" type="text" name="zip" value="<?php
            if (isset($formitem)) {
                echo $formitem["zip"];
            }
            ?>"/></td>
    </tr>
	
	 <tr>
        <td>Tara</td><td>
            <input size="50" type="text" name="country" value="<?php
            if (isset($formitem)) {
                echo $formitem["country"];
            }
            ?>"/></td>
    </tr>
	
	<tr>
        <td>Telefon</td><td>
            <input size="50" type="text" name="phone" value="<?php
            if (isset($formitem)) {
                echo $formitem["phone"];
            }
            ?>"/></td>
    </tr>
	
	<tr>
        <td>Email</td><td>
            <input size="50" type="text" name="email" value="<?php
            if (isset($formitem)) {
                echo $formitem["email"];
            }
            ?>"/></td>
    </tr>
	
	<tr>
        <td>Ramburs</td><td>
            <input size="50" type="text" name="repayment" id="repayment" value="<?php
            if (isset($formitem)) {
                echo $formitem["repayment"];
            }
            ?>"/></td>
    </tr>
	
	
	
	 <tr>
        <td>Data livrare</td><td>
			
			
            <input type="text" name="shiping_date" class="form-control form_datetime" value="<?php
            if (isset($formitem)) {
                echo $formitem["shiping_date"];
            }
            ?>"/></td>
    </tr>
	
	
	
    
    <tr>
        <td>Obs.</td>
        <td>
            <textarea name="obs"><?php
                if (isset($formitem)) {
                    echo $formitem["obs"];
                }
                ?></textarea>
        </td>
    </tr>
    <tr>
        <td></td><td>
            <?php if ($edit) { ?>
                <input type="submit" name="submit" value="Update" class="btn btn-primary btn-sm" />
            <?php } else { ?>
                <input type="submit" name="submit" value="Create" class="btn btn-primary btn-sm" />
<?php } ?>
        </td>
    </tr>

</table>
</form>

		<h5>Produse</h5>
		<table class="table table-sm table-striped text-dark small">
		 <tr>
			 <th>ID</th>
			 <th>Cod</th>
			 <th>Denumire</th>
			  <th>Barcode</th>
			 <th>Cantitate</th>
			 <th>Locatie</th>
			 <th>Actiune</th>
			 
		 </tr>
		 
			 <?php if(isset($products)){ ?>
		<?php foreach ($products as $items): ?>
			<tr>
				<td><?php echo $items['id']; ?></td>
				<td><?php echo $items['code']; ?></td>
				<td><?php echo $items['description']; ?></td>  
				<td><?php echo $items['barcode']; ?></td>
				<td><?php echo $items['qtty']; ?></td>
				<td><?php echo $items['position'].($items['shelf']>0?'R'.$items['shelf']:'') ?></td> 		
				
				<td><a href="<?php echo site_url('orders/addproduct/'.$items['id'].'/'.$formitem["id"].'/'.$formitem["customer"]);?>" class="btn btn-outline-success btn-sm"><i class="fas fa-fw fa-edit"></i></a>
				&nbsp;&nbsp;&nbsp;
				<a href="<?php echo site_url('orders/askremoveproduct/'.$items['id'].'/'.$formitem["id"]);?>"class="btn btn-outline-danger btn-sm"><i class="fas fa-fw fa-trash"</a></td>
				</tr>
		<?php endforeach; ?>
			<?php }else{ ?>
				<tr>
					<td colspan="8">
				No items</td>
				</tr>
				<?php } ?>
				
		</table>
		
		<?php if ($edit) { ?>
<a class="btn btn-primary btn-sm" href="<?php echo site_url('orders/addproduct/-1/'.$formitem["id"].'/'.$formitem["customer"]);?>"><i class="fa fa-plus-square-o" aria-hidden="true"></i> Adauga produs</a>
<?php } ?>

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


<script type="text/javascript">
    $(".form_datetime").datepicker({dateFormat: 'yy-mm-dd'});
</script> 
<?= $this->endsection(); ?>