Make a new module like invoice(rename invoices to materials)


#1

When we click on new but does not any action occurred:
modal_create_material.php

<script type="text/javascript">
    $(function () {
        // Display the create material modal
        $('#create-material').modal('show');

        $('#create-material').on('shown', function () {
            $("#client_name").focus();
        });

        $().ready(function () {
            $("[name='client_name']").select2();
        });

        // Creates the material
        $('#material_create_confirm').click(function () {
            // Posts the data to validate and create the material;
            // will create the new client if necessar
            $.post("<?php echo site_url('material/ajax/create'); ?>", {
                    client_name: $('#client_name').val(),
                    material_date_created: $('#material_date_created').val(),
                    material_group_id: $('#material_group_id').val(),
                    material_time_created: '<?php echo date('H:i:s') ?>',
                    material_password: $('#material_password').val(),
                    user_id: '<?php echo $this->session->userdata('user_id'); ?>',
                    payment_method: $('#payment_method_id').val()
                },
                function (data) {
                    <?php echo(IP_DEBUG ? 'console.log(data);' : ''); ?>
                    var response = JSON.parse(data);
                    if (response.success == '1') {
                        // The validation was successful and material was created
                        window.location = "<?php echo site_url('material/view'); ?>/" + response.material_id;
                    }
                    else {
                        // The validation was not successful
                        $('.control-group').removeClass('has-error');
                        for (var key in response.validation_errors) {
                            $('#' + key).parent().parent().addClass('has-error');
                        }
                    }
                });
        });
    });

</script>

<div id="create-material" class="modal col-xs-12 col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2"
     role="dialog" aria-labelledby="modal_create_material" aria-hidden="true">
    <form class="modal-content">
        <div class="modal-header">
            <a data-dismiss="modal" class="close"><i class="fa fa-close"></i></a>

            <h3><?php echo trans('create_material'); ?></h3>
        </div>
        <div class="modal-body">

            <input class="hidden" id="payment_method_id"
                   value="<?php echo $this->mdl_settings->setting('material_default_payment_method'); ?>">

            <div class="form-group">
                <label for="client_name"><?php echo trans('client'); ?></label>
                <select name="client_name" id="client_name" class="form-control" autofocus="autofocus">
                    <?php
                    foreach ($clients as $client) {
                        echo "<option value=\"" . htmlspecialchars($client->client_name) . "\" ";
                        if ($client_name == $client->client_name) echo 'selected';
                        echo ">" . htmlspecialchars($client->client_name) . "</option>";
                    }
                    ?>
                </select>
            </div>

            <div class="form-group has-feedback">
                <label><?php echo trans('material_date'); ?></label>

                <div class="input-group">
                    <input name="material_date_created" id="material_date_created"
                           class="form-control datepicker"
                           value="<?php echo date(date_format_setting()); ?>">
                <span class="input-group-addon">
                    <i class="fa fa-calendar fa-fw"></i>
                </span>
                </div>
            </div>

            <div class="form-group">
                <label for="material_password"><?php echo trans('material_password'); ?></label>
                <input type="text" name="material_password" id="material_password" class="form-control"
                       value="<?php if ($this->mdl_settings->setting('material_pre_password') == '') {
                           echo '';
                       } else {
                           echo $this->mdl_settings->setting('material_pre_password');
                       } ?>" style="margin: 0 auto;" autocomplete="off">
            </div>

            <div class="form-group">
                <label><?php echo trans('material_group'); ?></label>

                <div class="controls">
                    <select name="material_group_id" id="material_group_id" class="form-control">
                        <option value=""></option>
                        <?php foreach ($material_groups as $material_group) { ?>
                            <option value="<?php echo $material_group->material_group_id; ?>"
                                    <?php if ($this->mdl_settings->setting('default_material_group') == $material_group->material_group_id) { ?>selected="selected"<?php } ?>><?php echo $material_group->material_group_name; ?></option>
                        <?php } ?>
                    </select>
                </div>
            </div>

        </div>

        <div class="modal-footer">
            <div class="btn-group">
                <button class="btn btn-danger" type="button" data-dismiss="modal">
                    <i class="fa fa-times"></i> <?php echo trans('cancel'); ?>
                </button>
                <button class="btn btn-success ajax-loader" id="material_create_confirm" type="button">
                    <i class="fa fa-check"></i> <?php echo trans('submit'); ?>
                </button>
            </div>
        </div>

    </form>

</div>