<script type="text/javascript">
/*$(document).ready(function(){
	$("#frm-user").submit(function(e){
            if(!validate_user()){
                e.preventDefault();
            }
	});
        
	
});*/
</script>
<div class="breadcrumb">
    <h1>Create Order</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Order</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>
<div class="row">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-body">
                <div class="card-title mb-3">Add New Order</div>
                <p><b>Patient Details :</b> <?php echo w::d($dependantDetails->dependant_fname)." ".w::d($dependantDetails->dependant_lname)." | ".w::d($dependantDetails->dependant_phone)." | ".w::d($dependantDetails->dependant_email_address) ?></p>
                <p><b>Reward Details :</b> <?php echo $redeemedDetail->rewardName." | <b>Face Value :</b> ".$redeemedDetail->faceValue." | <b>Quntity :</b> ".$redeemedDetail->quantity ?></p>
                <p></p>
                <form action="" id='frm-city' method="post" enctype="multipart/form-data">
                  <input type="hidden" id="hdnId" name="hdnId" value="<?php echo $_REQUEST['redeemed_id'] ?>">
                    <div class="row">
                        <div class="col-md-6 form-group mb-3">
                            <label for="template_id">Email Templates <span class="asterisk">*</span></label>
                            <select class="form-control" id="template_id" name="template_id">
                            <option value="">Select Templates</option>
                              <?php
                                    foreach ($allETemplates as $ckey => $t) 
                                      { 
                                        ?>
                                          <option value="<?php echo $t['etid']; ?>"><?php echo $t['name']; ?></option>
                                <?php }
                              ?>
                            </select>
                            <div class="invalid-tooltip" id="msg_template_id"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="account_id">Account <span class="asterisk">*</span></label>
                            <select class="form-control" id="account_id" name="account_id">
                            <option value="">Select Account</option>
                              <?php
                                    foreach ($allAccounts as $akey => $a) 
                                      { 
                                        ?>
                                          <option value="<?php echo $a['accountIdentifier']; ?>"><?php echo $a['displayName']." - ".$a['currentBalance']." ".$a['currencyCode']; ?></option>
                                <?php }
                              ?>
                            </select>
                            <div class="invalid-tooltip" id="msg_account_id"></div>
                        </div>
                        <div class="col-md-12">
                            <input type="submit" class="btn btn-primary" id="submit" name="submit" value="Submit">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
  $( "form" ).on( "submit", function(e) {
      e.preventDefault();

      var account_id = $("#account_id").val();
      var template_id = $("#template_id").val();
      var hdnId = $("#hdnId").val();
      if($("#account_id").val()==''){
          $("#account_id").addClass('error');
          $("#account_id").focus();
          $("#msg_account_id").html('Please select account').show();
          return false;
      }else if($("#template_id").val()==''){
          $("#template_id").addClass('error');
          $("#template_id").focus();
          $("#msg_template_id").html('Please select email templates').show();
          return false;
      }else{
          $.ajax({
              url: "sendorder.php",
              data: { act:"send_order",
                    account_id:account_id,template_id:template_id,hdnId:hdnId },
              method: 'POST',
              success: function(msg){
                  res =JSON.parse(msg);
                  if(res.error){
                    alert(res.msg);
                  }else{
                     window.location='tango_orderlist.php'; 
                  }
              }
          });
      }
});
</script>