<p></p>
<div class="content-top-1 box box-default">
    <div class="box-body">
        <?= form_open_multipart("/crossindustry/add_partners"); ?>
        <input type="hidden" name="id" id="id">
        <input type="hidden" name="phone" id="phone">
        <input type="hidden" name="cname" id="cname">
        <input type="hidden" name="email" id="email">
        <div class="row">
            <div class="col-md-6">
                Partner Code
                <input class="form-control" required="required" name="dmo_id" id="dmo_id" placeholder="dmo_id" type="text">
                <br>
                Vendor
                <div class="row">
                    <div class="col-md-9">
                        <select class="form-control" required="required" name="vendor" id="vendor">
                            <option value="">Select Vendor</option>
                        </select>
                    </div>
                    <div class="col-md-3">
                        <button type="button" data-target="#usersmodal" data-toggle="modal" class="btn btn-warning btn-sm"><i class="fa fa-plus"> Vendor</i></button>
                    </div>
                </div>
                <br>
                Partner Name
                <input class="form-control" required="required" name="name" id="name" placeholder="Partner name" type="text">
                <br>
                Logo
                <input type="file" required id="logo" name="userfile" placeholder="Upload File **Only Images allowed." class="form-control">
                <br>
                Terms &amp; Conditions
                <textarea name="terms" id="terms" placeholder="" class="form-control"></textarea>
                <br>
                Description
                <textarea name="description" id="description" placeholder="" class="form-control"></textarea>
            </div>
            <div class="col-md-6">
                Categories
                <select class="form-control" required="required" name="categories" id="categories">
                    <option value="">Select Category</option>
                    <option value="AGRICULTURE AND FRESH PRODUCE">Agriculture & Fresh Produce</option>
                    <option value="Automotive">Automotive</option>
                    <option value="Beauty and Wellness">Beauty and Wellness</option>
                    <option value="BUILDING MINING AND CONSTRUCTION">Building Mining & Construction</option>
                    <option value="Entertainment">Entertainment</option>
                    <option value="Electronics">Electronics</option>
                    <option value="FINANCE AND INSURANCE">Finance & Insurance</option>
                    <option value="Furniture and Accessories">Furniture and Accessories</option>
                    <option value="Grocery and Household">Grocery and Household</option>
                    <option value="Health and Fitness">Health and Fitness</option>
                    <option value="Hotel and Restaurants">Hotel and Restaurants</option>
                    <option value="Women fashion">Women Fashion</option>
                    <option value="Mens fashion">Mens Fashion</option>
                    <option value="PLASTICS & RUBBER">Plastic & Rubber</option>
                    <option value="RETAIL">Retail</option>
                    <option value="Travel">Travel</option>
                    <option value="TRAVEL AND HOSPITALITY">Travel & Hospitality</option>
                    <option value="Sports and Outdoors">Sports and Outdoors</option>
                </select>
                <br><br>
                Partner Type
                <select class="form-control" required="required" name="type" id="type">
                    <option value="">Is Redemption Partner</option>
                    <option value="Redemption">Redemption</option>
                    <option value="Discount">Discount</option>
                    <option value="Redemption & Discount">Redemption & Discount</option>
                </select>
                <br><br>

                <div id="discounts">
                    Discount Type
                    <select class="form-control" required="required" name="discounttype" id="discounttype">
                        <option value="">Select Discount Type</option>
                        <option value="fixed">Fixed Amount</option>
                        <option value="percentage">Percentage</option>
                    </select>
                    <br><br>
                    Discount Value
                    <input class="form-control" required="required" name="discount_amount" id="discount_amount" placeholder="Discount Amount" type="number">
                    <br>
                    Generate Discount Code?
                    <select class="form-control" required="required" name="discountcode" id="discountcode">
                        <option value="">Generate Code</option>
                        <option value="1">Yes</option>
                        <option value="0">No</option>
                    </select>
                    <br><br>
                    <input class="form-control" required="required" name="actualcode" id="actualcode" placeholder="Discount Code" type="text">
                    <br>
                </div> 
                How will voucher validation occur?
                <select class="form-control" required="required" name="redemptionoption" id="redemptionoption">
                    <option value="">How will voucher validation occur?</option>
                    <option value="Integration">Integration</option>
                    <option value="Portal">Web Portal</option>
                </select>
                <br><br>
            </div>
        </div>
        <br>
        <button type="submit" class="btn btn-info">Save Partner Details</button>
        </form><br>
    </div>
</div>
<br>

<div id="usersmodal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" id="mclose" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Vendors</h4>
            </div>
            <div class="modal-body">
                <input class="form-control" name="vndor" id="vndor" placeholder="Vendor" type="text">
                <br>
                Contact Person
                <input class="form-control" name="contact_person" id="contact_person" placeholder="Contact Person" type="text">
                <br>
                <input class="form-control" name="contact_person_email" id="contact_person_email" placeholder="example@email.com (Optional)" type="email">
                <br>
                <input class="form-control" name="contact_phone" id="contact_phone" pattern="^(0)([0-9]{9})$" title="Phone number should start with: 0xxxxxxxxx" placeholder="Phone number (0xxxxxxxxx)" autocomplete="off" type="text">

            </div>

            <div class="modal-footer">
                <button type="button" id="addv" class="btn btn-primary ">Add Vendor</button>
            </div>
        </div>
    </div>
</div>
<script language="javascript">
    $(document).ready(function() {
        $("#discounts,#actualcode").fadeOut();
        $('#addv').click(function() {
            if ($('#vndor').val() != "" && $('#contact_person').val() != "" && $('#contact_phone').val() != "") {

                $('#vendor').append("<option value='" + $('#vndor').val() + "'>" + $('#vndor').val() + "</option>");
                $('#vendor').val($('#vndor').val()).change();
                $('#cname').val($('#contact_person').val());
                $('#phone').val($('#contact_phone').val());
                $('#email').val($('#contact_person_email').val());
                $('#mclose').click();

            } else
                alert("Supply the required details.")

        });

        $.ajax({
            url: "/crossindustry/get_vendor",
            type: "get",
            success: function(data) {
                var json = JSON.parse(data);
                if (json.result == "OK") {
                    for (var m = 0; m < json.message.length; m++) {
                        $('#vendor').append("<option value='" + json.message[m].partner + "'>" + json.message[m].partner + "</option>");
                    }
                }
            }
        });

        $('#type').change(function(){
            if(this.value=="Redemption & Discount" || this.value=="Discount"){
                $("#discounts").fadeIn();
                $("#discounts select, #discounts input").attr("required","required");
            } else {
                $("#discounts").fadeOut();
                $("#discounts select, #discounts input").removeAttr("required");
            } 
        });

        $('#discountcode').change(function(){
            if(this.value==1){
                $('#actualcode').removeAttr("required");
                $('#actualcode').fadeOut();
            } else {
                $('#actualcode').attr("required","required");
                $('#actualcode').fadeIn();
            }
        });

    });
</script>