1

i've been working on Financial year calendar and it is also generating year correctly but the problem i'm facing is i want to restrict this with date like right now its generating current and next Financial year but i want to give custom date with custom year.

e.g In month field(January) in Date field(01-01-2018) and it generates all 2018 year from January or if i give in Month Field(August) and in Date Field (01-08-2019) so it generates from August 2018

Html Code

`<div class="calenderYear">
        <h3 class="box-title">Calendar Year</h3>
            <div class="table-responsive">
                <table class="table color-bordered-table inverse-bordered-table">
                      <thead>
                            <tr>
                                <th>Period</th>
                                                <th>Title</th>
                                                <th>Start Date</th>
                                                <th>End Date</th>
                                                <th>GL Year</th>
                                                <th>GL Period</th>
                                            </tr>
                                        </thead>
                                        <tbody>                                            
                                            <tr class="remove">
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                                <td><input type="button" class="btn btn-default generate" value="Generate New"  /></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>`

Jquery Code

$(".process").click(function(){
            var month = $(".month").val();
            var start_date = $(".firstDay").val();
            if(start_date=='') {
                swal({
                    title: "Default Finalcial Year Generation",
                    text: "Month and Start Date is required.!",
                    type: "info",
                    showCancelButton: false,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "OK",
                    closeOnConfirm: true
                }, function () {
                    swal("Deleted!", "Your imaginary file has been deleted.", "success");
                });
            }else{
                var offsetValue = 6;
                var month = $(".month").val();
                var theMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
                if(month == 'January'){
                    offsetValue = 0;
                }else if(month == 'February'){
                    offsetValue = 1;
                }else if(month == 'March'){
                    offsetValue = 2;
                }else if(month == 'April'){
                    offsetValue = 3;
                }else if(month == 'May'){
                    offsetValue = 4;
                }else if(month == 'June'){
                    offsetValue = 5;
                }else if(month == 'July'){
                    offsetValue = 6;
                }else if(month == 'August'){
                    offsetValue = 7;
                }else if(month == 'September'){
                    offsetValue = 8;
                }else if(month == 'October'){
                    offsetValue = 9;
                }else if(month == 'November'){
                    offsetValue = 10;
                }else if(month == 'December'){
                    offsetValue = 11;
                }else {
                    swal({
                        title: "Default Finalcial Year Generation",
                        text: "Month and Start Date is required.!",
                        type: "info",
                        showCancelButton: false,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "OK",
                        closeOnConfirm: true
                    }, function () {
                        swal("Deleted!", "Your imaginary file has been deleted.", "success");
                    });
                }
                var offset = offsetValue;
                for (var i = 0; i < 12; i++) {
                    var j = i+1;
                    var date = new Date();
                    var currentMonth = (new Date).getMonth();  // GET current month
                    var currentYear = (new Date).getFullYear();  // GET current year
                    var financialYear = 0;
                    var lastYear = offset-1;
                    var nextYear = offset+1;
                    if (currentMonth <= 5) {   // IF current month is June (5) or earlier use financial year pattern 2014/2015
                        financialYear =  lastYear+"/"+currentYear;
                    } else {   // ELSE current month is after June (5) use financial year pattern 2015/2016
                        financialYear = currentYear+"/"+nextYear;
                    }
                    var monthIndex = i + offset;
                    var firstDay = new Date(date.getFullYear(), monthIndex + 0 % theMonths.length, 1);
                    var firstDay = moment(firstDay).format('DD-MM-YYYY');

                    var lastDay = new Date(date.getFullYear(), monthIndex + 1 % theMonths.length, 0, 23, 59, 59);
                    var lastDay = moment(lastDay).format('DD-MM-YYYY');
                    var months = '<tr><td><input type="text" name="Period[]" class="form-control" value="' + j + '" size="2" /></td>';
                    months+='<td><input type="text" name="month[]" class="form-control month" value="' + theMonths[monthIndex % theMonths.length] + '" /></td>';
                    months+='<td><input type="text" name="firstDay[]" class="form-control firstDay" value="' + firstDay + '" /></td>';
                    months+='<td><input type="text" name="lastDay[]" class="form-control" value="' + lastDay + '" /></td>';
                    months+='<td><input type="text" name="year[]" class="form-control" value="' + currentYear + '" /></td>';
                    months+='<td><input type="text" name="GLPeriod[]" class="form-control" value="' + j + '" size="2" /></td></tr>';
                    $('.generate').attr('disabled',true);
                    $('.calenderYear .table-responsive table tbody').append(months).fadeIn(300);
                }
                $(".hideAfterFilledup").hide();
                $('.calenderYear .table-responsive table tbody').append('<tr><td></td><td></td><td></td><td></td><td><input type="submit" class="btn btn-info process" value="Process"  /></td><td><input type="submit" class="btn btn-info" value="Create New"  /></td></tr>');
            }



        });
Salman Khan Sohoo
  • 97
  • 1
  • 1
  • 13

0 Answers0