<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<div class="modal-dialog modal-lg">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-2x">&times;</i>
            </button>
            <h4 class="modal-title" id="myModalLabel"><?php echo lang('add_customer'); ?></h4>
        </div>
        <?php $attrib = array('data-toggle' => 'validator', 'role' => 'form', 'id' => 'add-customer-form');
        echo admin_form_open_multipart("customers/add", $attrib); ?>
        <div class="modal-body">
            <p><?= lang('enter_info'); ?></p>

            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                    <label class="control-label" for="customer_group"><?php echo $this->lang->line("customer_group"); ?></label>
                        <?php
                        foreach ($customer_groups as $customer_group) {
                            $cgs[$customer_group->id] = $customer_group->name;
                        }
                        echo form_dropdown('customer_group', $cgs, $Settings->customer_group, 'class="form-control select" id="customer_group" style="width:100%;" required="required"');
                        ?>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <label class="control-label" for="price_group"><?php echo $this->lang->line("price_group"); ?></label>
                        <?php
                        $pgs[''] = lang('select').' '.lang('price_group');
                        foreach ($price_groups as $price_group) {
                            $pgs[$price_group->id] = $price_group->name;
                        }
                        echo form_dropdown('price_group', $pgs, $Settings->price_group, 'class="form-control select" id="price_group" style="width:100%;"');
                        ?>
                    </div>
                </div>
            </div>
	    <div class="row">
                <div class="col-md-12">
					<ul id="tabCustomerAdd" class="nav nav-tabs">
					  <li><a href="#custinfo">Customer Info</a></li>
					  <li><a href="#custadd">GST & Address</a></li>
					  <li><a href="#custfld">Custom Fields</a></li>
					</ul>
					<div class="tab-content">
						<div id="custinfo" class="tab-pane fade in">
							<div class="row">
								<div class="col-md-6">
									<div class="form-group person">
										<?= lang("name", "name"); ?> <a id="aCopyName" href="javascript:void(0);"><i class="fa fa-copy"></i></a>
										<?php echo form_input('name', '', 'class="form-control tip" id="name" data-bv-notempty="true"'); ?>
									</div>
									<div class="form-group">
										<?= lang("phone", "phone"); ?> <a id="aCopyPhone" href="javascript:void(0);"><i class="fa fa-copy"></i></a>
										<input type="tel" name="phone" class="form-control" required="required" id="phone"/>
									</div>
								</div>
								<div class="col-md-6">
									<div class="form-group">
										<?= lang("email_address", "email_address"); ?> <a id="aCopyEmail" href="javascript:void(0);"><i class="fa fa-copy"></i></a>
										<input type="email" name="email" class="form-control" required="required" id="email_address"/>
									</div>
									<div class="form-group company">
										<?= lang("company", "company"); ?>
										<?php echo form_input('company', '', 'class="form-control tip" id="company"'); ?>
									</div>
									<!--<div class="form-group company">
										<?= lang("contact_person", "contact_person"); ?>
										<?php echo form_input('contact_person', '', 'class="form-control" id="contact_person" data-bv-notempty="true"'); ?>
									</div>-->
								</div>
							</div>
						</div>
						<div id="custadd" class="tab-pane fade in">
							<div class="row">
								<div class="col-md-6">
									<div class="form-group">
										<?= lang("vat_no", "vat_no"); ?>
										<?php echo form_input('vat_no', '', 'class="form-control" id="vat_no"'); ?>
									</div>
									<div class="form-group">
										<?= lang("gst_no", "gst_no"); ?>
										<?php echo form_input('gst_no', '', 'class="form-control" id="gst_no"'); ?>
									</div>
									<div class="form-group">
										<?= lang("address", "address"); ?>
										<?php echo form_input('address', '', 'class="form-control" id="address" '); ?>
									</div>
								</div>
								<div class="col-md-6">
									<div class="form-group">
										<?= lang("city", "city"); ?>
										<?php echo form_input('city', 'Surat', 'class="form-control" id="city" '); ?>
									</div>
									<div class="form-group">
										<?= lang("state", "state"); ?>
										<?php
										if ($Settings->indian_gst) {
											$states = $this->gst->getIndianStates(true);
											echo form_dropdown('state', $states, 'GJ', 'class="form-control select" id="state" required="required"');
										} else {
											echo form_input('state', '', 'class="form-control" id="state"');
										}
										?>
									</div>
									<div class="form-group">
										<?= lang("postal_code", "postal_code"); ?>
										<?php echo form_input('postal_code', '', 'class="form-control" id="postal_code"'); ?>
									</div>
									<div class="form-group">
										<?= lang("country", "country"); ?>
										<?php echo form_input('country', '', 'class="form-control" id="country"'); ?>
									</div>
								</div>
							</div>
						</div>
						<div id="custfld" class="tab-pane fade in">
							<div class="row">
								<div class="col-md-6">
									<div class="form-group">
										<?= lang("ccf1", "cf1"); ?>
										<?php echo form_input('cf1', '', 'class="form-control" id="cf1"'); ?>
									</div>
									<div class="form-group">
										<?= lang("ccf2", "cf2"); ?>
										<?php echo form_input('cf2', '', 'class="form-control" id="cf2"'); ?>
									</div>
									<div class="form-group">
										<?= lang("ccf3", "cf3"); ?>
										<?php echo form_input('cf3', '', 'class="form-control" id="cf3"'); ?>
									</div>
								</div>
								<div class="col-md-6">
									<div class="form-group">
										<?= lang("ccf4", "cf4"); ?>
										<?php echo form_input('cf4', '', 'class="form-control" id="cf4"'); ?>
									</div>
									<div class="form-group">
										<?= lang("ccf5", "cf5"); ?>
										<?php echo form_input('cf5', '', 'class="form-control" id="cf5"'); ?>
									</div>
									<div class="form-group">
										<?= lang("ccf6", "cf6"); ?>
										<?php echo form_input('cf6', '', 'class="form-control" id="cf6"'); ?>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
        </div>
        <div class="modal-footer">
            <?php echo form_submit('add_customer', lang('add_customer'), 'class="btn btn-primary"'); ?>
        </div>
    </div>
    <?php echo form_close(); ?>
</div>

<script type="text/javascript">
    $(document).ready(function (e) {
		// Added by Keval : 18.10.15
		e("#tabCustomerAdd a:first").tab("show");
		e("#tabCustomerAdd a").click(function(t) {
			t.preventDefault();
			e(this).tab("show");
		});
		// End by Keval : 18.10.15
        $('#add-customer-form').bootstrapValidator({
            feedbackIcons: {
                valid: 'fa fa-check',
                invalid: 'fa fa-times',
                validating: 'fa fa-refresh'
            }, excluded: [':disabled']
        });
        $('select.select').select2({minimumResultsForSearch: 7});
        fields = $('.modal-content').find('.form-control');
        $.each(fields, function () {
            var id = $(this).attr('id');
            var iname = $(this).attr('name');
            var iid = '#' + id;
            if (!!$(this).attr('data-bv-notempty') || !!$(this).attr('required')) {
                $("label[for='" + id + "']").append(' *');
                $(document).on('change', iid, function () {
                    $('form[data-toggle="validator"]').bootstrapValidator('revalidateField', iname);
                });
            }
        });
		// Added by Keval : 18.10.25
		$("#name").keyup(function() {
			$("#company").val($("#name").val()).change();
		});
		$('#aCopyName').on('click', function(){
			$('#name').val('Dummy Customer');
			$('#company').val('Dummy Customer');
		});
		$('#aCopyPhone').on('click', function(){
			$('#phone').val('0123456789');
		});
		$('#aCopyEmail').on('click', function(){
			var randomNumber = Math.floor(Math.random() * 10000000000);
			$('#email_address').val(randomNumber + '@customer.com');
		});
		// End by Keval : 18.10.25
	});
</script>
