0byt3m1n1
Path:
C:
/
wamp64
/
www
/
cpms_new
/
USER
/
[
Home
]
File: pi_edit_project.php
<?php $MAIN_HEADING = "Edit Project"; $SUB_HEADING =""; require_once "pi_edit_project_ctrl.php"; include("include/pi_header.php"); require_once"../lib/config.php"; ?> <span class="msgText"> <?php if (isset($message)) echo $message;?> </span> <div id="msg_edit_project"></div> <form action="pi_edit_project_cntrl.php" method="post" class="form-horizontal form-label-left" name="form_editproject" id="form_editproject" data-parsley-validate> <input type="hidden" name="project_id" id="project_id" value="<?php if (isset($project_id) && $project_id!="") { echo $project_id; } ?>"> <div class="form-group"> <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Project Title</label> <div class="col-md-6 col-sm-6 col-xs-12"> <input type="text" class="form-control col-md-7 col-xs-12" required name="txtproject_title" id="txtproject_title" value="<?php if (isset($project_title) && $project_title!="") { echo $project_title; } ?>" /> <ul class="parsley-errors-list filled" id="parsley-id-5"><li class="parsley-required"><?php if(isset($error['project_title'])) { echo $error['project_title']; }?></li></ul> </div> </div> <div class="form-group"> <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Co. Investigators</label> <div class="col-md-6 col-sm-6 col-xs-12"> <input id="txtinvestigator" type="text" class="tags form-control" name="txtinvestigator" value="" placeholder="add co investigator" /> <div id="suggestions-container" style="position: relative; float: left; width: 250px; margin: 10px;"></div> <ul class="parsley-errors-list filled" id="parsley-id-5"><li class="parsley-required"><?php if(isset($error['investigators'])) { echo $error['investigators']; }?></li></ul> </div> </div> <div class="form-group"> <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Date of Start</label> <div class="col-md-6 col-sm-6 col-xs-12"> <input type="text" readonly required class="form-control col-md-7 col-xs-12 date_show" id="start_date" placeholder="Start Date" name="start_date" aria-describedby="inputSuccess2Status" value="<?php if (isset($start_date) && $start_date != "") { echo $start_date; } ?>"/> <ul class="parsley-errors-list filled" id="parsley-id-5"><li class="parsley-required"><?php if(isset($error['start_date'])) { echo $error['start_date']; }?></li></ul> </div> </div> <div class="form-group"> <label class="control-label col-md-3 col-sm-3 col-xs-12" required for="first-name">Date of Completion</label> <div class="col-md-6 col-sm-6 col-xs-12"> <input type="text" name="end_date" readonly required class="form-control col-md-7 col-xs-12 date_show" id="end_date" placeholder="Date of Completion" aria-describedby="inputSuccess2Status" value="<?php if (isset($end_date) && $end_date != "") { echo $end_date; } ?>" /> <ul class="parsley-errors-list filled" id="parsley-id-5"><li class="parsley-required"><?php if(isset($error['end_date'])) { echo $error['end_date']; }?></li></ul> </div> </div> <div class="form-group"> <label class="control-label col-md-3 col-sm-3 col-xs-12" required for="first-name">Duration</label> <div class="col-md-6 col-sm-6 col-xs-12"> <input type="text" name="txtduration" readonly required class="form-control col-md-7 col-xs-12" id="txtduration" placeholder="Project duration" aria-describedby="inputSuccess2Status" value="<?php if (isset($duration) && $duration != "") { echo $duration; } ?>" /> <ul class="parsley-errors-list filled" id="parsley-id-5"><li class="parsley-required"><?php if(isset($error['duration'])) { echo $error['duration']; }?></li></ul> </div> </div> <div class="form-group"> <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Project Outlay (Rupees) </label> <div class="col-md-6 col-sm-6 col-xs-12"> <input readonly="" type="text" class="form-control col-md-7 col-xs-12" required name="txtproject_overlay" id="txtproject_overlay" value="<?php if (isset($project_outlay) && $project_outlay!="") { echo $project_outlay; } ?>" /> <ul class="parsley-errors-list filled" id="parsley-id-5"><li class="parsley-required"><?php if(isset($error['project_overlay_null'])) { echo $error['project_overlay_null']; }?></li> </ul> </div> </div> <div class="total_outlay_div row " id="total_outlay_div" > <div class="center"> <h4>Total outlay of the project. </h4></div> <table class="table table-bordered table-striped jambo_table" id="total_outlay_table" > <thead><tr> <?php if(isset($outlay_details)){ $counter = 0; foreach ($outlay_details as $installment){ ?> <th class="center"><?php echo ordinal($counter + 1)." Year"; ?></th> <?php $counter++; } ?> <th id="installment_total_head" class="center">Total (Rupees)</th></thead></tr> <tbody> <tr> <?php $amount_total = 0; foreach ($outlay_details as $j => $value1){ $amount_total += $value1['amount']; ?> <td lass="center"> <input type="text" id="total_outlay_input" required="" class="form-control total_outlay_input" name="out_lay[]" readonly value="<?php echo $value1['amount'] ?>" > </td> <?php } ?> <?php } ?> <td class="center"> <?php echo $amount_total ?> </td> </tr> </thead> </table> </div> <div class="form-group"> <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">No.of Budget Head </label> <div class="col-md-6 col-sm-6 col-xs-12"> <input type="text" class="form-control col-md-7 col-xs-12" name="txtbudget_head" id="txtbudget_head" value="<?php if (isset($budget_head) && $budget_head!="") { echo $budget_head; } ?>"/> <ul class="parsley-errors-list filled" id="parsley-id-5"><li class="parsley-required"><?php if(isset($error['budget_head'])) { echo $error['budget_head']; }?></li></ul> </div> <div class="col-md-2 col-sm-2 col-xs-12 pull-right"> <a class="btn btn-xs btn-warning " data-toggle="modal" data-target="#modal-budget-master"><i class="fa fa-plus-circle"></i> Budget Head Master</a> </div> </div> <div class="budget_details_div row " id="budget_details_div" style=""> <div class="center"> <h4>Budget Details </h4></div> <table class="table table-bordered table-striped jambo_table" id="budget_details_table" > <thead> <tr> <th class="center">Budget Head</th> <th class="center">Budget Amount (Rupees)</th> </tr> </thead> <tbody> <?php $budget_amount_total = 0; $budget_head_count = 0; $used_budget_heads = array(); foreach ($budget_head_details as $j => $bd_value){ $budget_amount_total += $bd_value['amount']; $budget_head_count++; array_push( $used_budget_heads , $bd_value['budget_head_id'] ); ?> <tr> <td class="center master_val key" > <?php echo $bd_value["name"] ?> </td> <td class="center master_val value"> <?php echo $bd_value["amount"] ?> </td> </tr> <?php } ?> <tr> <td class="center">Total</td><td class="center"><?php echo $budget_amount_total ?></td> </tr> </tbody> </table> <div id="splitup_master"></div> </div> <div class="form-group"> <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-4"> <button type="submit" class=" validate btn btn-success" onclick="" name="save" id="save" value="SAVE">Submit</button> <button type="button" class=" validate btn btn-danger" onclick="" name="btn_cancel" id="btn_cancel">Cancel</button> </div> </div> <div id="budget_head_master_div" style="display:none"> <select class="form-control col-md-7 col-xs-12 budget-head-common budget-head-select" custattr name="CONTROLL_ID" id="CONTROLL_ID" budget-val="CUSTOM_VAL"> <option value="">Please select </option> <?php if(!empty($budgetMasterArray)) foreach ($budgetMasterArray as $key => $value) {?> <option value="<?php echo $key; ?>" <?php if(in_array( $key , $used_budget_heads)) { echo "disabled"; } ?> ><?php echo $value; ?></option> <?php } ?> </select> </div> <div class="modal fade" id="project-confirmation-modal" tabindex="-1" role="dialog" style="z-index: 9999"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title">Please Confirm</h4> </div> <div class="modal-body"> <div class="" style="padding:10px"> <table class="table table-hover table-bordered"> <!-- <tr> <td>Project Code</td> <td><p id="con_project_code"></p></td> </tr> --> <tr> <td>Project Title</td> <td><p id="con_project_title"></p></td> </tr> <!-- <tr> <td>Principle Investigator</td> <td><p id="con_pricipal_inv"></p></td> </tr> --> <tr> <td>Co. Investigator</td> <td><p id="con_co_investigator"></p></td> </tr> <!-- <tr> <td>Fund Agency</td> <td><p id="con_fund_agency"></p></td> </tr> --> <tr> <td>Start Date</td> <td><p id="con_start_date"></p></td> </tr> <tr> <td>Date of Completion</td> <td><p id="con_end_date"></p></td> </tr> <tr> <td>Project Outlay</td> <td><p id="con_project_outlay"></p></td> </tr> <tr> <td>Duration</td> <td><p id="con_duration"></p></td> </tr> <tr> <td>No.of Budget Head</td> <td><p id="con_budget_head_num"></p></td> </tr> </table> </div> <div style="padding-left: 10px;padding-right:10px;padding-bottom: 10px" class="row"> <div style="" id="con-budget-details" class="col-md-6 col-sm-6 col-xs-6"></div> <div style="" id="con-project-layout" class="col-md-6 col-sm-6 col-xs-6"></div> </div> <div style="padding-left: 10px;padding-right:10px;padding-bottom: 10px" class="row"> <div style="" id="con-project-splitup" class="col-md-6 col-sm-6 col-xs-6"></div> <div style="" id="" class="col-md-6 col-sm-6 col-xs-6"></div> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal" style="margin-bottom:0px;">Close</button> <button type="button" class="validate btn btn-primary" onclick="submitPrjectForm()" style=" margin-top: 0px;">Submit</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal --> <div class="modal fade" id="modal-budget-master" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <form data-parsley-validate="" class="form-horizontal form-label-left" id="add-budget-master"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title" id="myModalLabel">Add Budget Master</h4> </div> <div class="modal-body"> <div class="form-group"> <label class="col-sm-3 control-label">Budget Head Name</label> <div class="col-sm-9"> <input autocomplete="off" type="text" class="form-control" name="name" id="budgetNameMaster" required=""> </div> </div> <div class="form-group"> <label class="col-sm-12 control-label" id="budget-msg" style="display:none"></label> </div> </div> <div class="modal-footer"> <i class="fa fa-refresh fa-spin fa-2x" id="budget-spin" style="display:none"></i> <button id="add-budget-master" onclick="AddBudgetMaster()" type="button" class="btn btn-sm btn-success" >Add</button> </div> </div> </form> </div> </div> </form> <?php include "include/footer.php"; ?> <script type="text/javascript"> window.Parsley.addValidator('csdate', { validateString: function(value) { return validateDate(); }, messages: { en: 'Date of Completion must be greater than start date', } }); function validateDate(){ var strStartDate = $('input[name="start_date"]').attr("date-org"); var strEndDate = $('input[name="end_date"]').attr("date-org"); if(isNotBlank(strStartDate) && isNotBlank(strEndDate)){ var a = moment(strStartDate); var b = moment(strEndDate); return !b.isBefore(a); } return true; } $(function(){ $('#txtinvestigator').tagsInput({ width: 'auto', defaultText : "Co-investigator name" }); var investigators = <?php echo '"'.$investigators .'"' ?>; investigators = investigators.replace(/\s*,\s*/g, ','); investigators = investigators.replace(/^[,\s]+|[,\s]+$/g, ''); var inv_arr = investigators.split(","); $('#txtinvestigator').importTags(inv_arr.join()); /* $('#start_date').daterangepicker({ singleDatePicker: true, showDropdowns: true, maxDate: '01/01/2050', startDate: '01/01/2013' }, function(start, end, label) { }); */ var start_date1 = "<?php echo $start_date ?>"; var end_date1 = "<?php echo $end_date ?>"; var start_date = moment(start_date1, "DD-MMM-YYYY"); var end_date = moment(end_date1, "DD-MMM-YYYY"); $('#end_date').daterangepicker({ singleDatePicker: true, showDropdowns: true, maxDate: moment().add(30, 'year').format('MM/DD/YYYY'), minDate: end_date, startDate: end_date }, function(start, end, label) { end = moment(end.set({hour:0,minute:0,second:0,millisecond:0}).toISOString()); var controll = this.element[0]; $(controll).attr("date-org",moment(start).format("MM/DD/YYYY")); start_date = moment(start_date1, "DD-MMM-YYYY"); var difference = end.diff(end_date, 'years' , true); var intvalue = Math.floor( difference ); if(isFloat(difference)){ intvalue = intvalue + 1; } $txtDuration.val(getDifferenceText(end,start_date)); $('#end_date').val(moment(end).format("DD-MMM-YYYY")); console.log("Duration : "+ intvalue +" - difference "+ difference); // if(end.isSame(end_date,'day')){ // console.log("date is same"); // }else{ // console.log("date is not same"); // } if(intvalue > 0){ makeTotalOutlayOfProject(intvalue); // $txtDuration.attr("intvalue",intvalue); } }); // $txtbudget_head.val(budget_head_count); $("#form_editproject").submit(function(e){ e.preventDefault(); // Keep the form from submitting if ( $(this).parsley().isValid() ) { showProjectConfirmationModel(); } }); $('#form_editproject').parsley().on('form:validate', function(formInstance) { console.log(formInstance); }); }); var $txtDuration = $("input#txtduration"); var $txtbudget_head = $("input#txtbudget_head"); var $totalOutLayDiv = $("div#total_outlay_div"); var $totalOutLayTable = $("table#total_outlay_table"); var $projectOutlayInp = $("input#txtproject_overlay"); var totalOutLayTableRow = ""; var $budgetDetailsDiv = $("div#budget_details_div"); var $budgetDetailsTable = $("table#budget_details_table"); const installment_spitup_count = "<?php echo $counter ?>"; const installment_splitup_amount = "<?php echo $amount_total ?>"; const budget_head_count = "<?php echo $budget_head_count ?>"; const budget_amount_total = "<?php echo $budget_amount_total ?>"; // console.log(budget_head_count); $("body").on("keyup", "input#txtbudget_head" ,function () { var val = $.trim($(this).val()); if(isNaN(val) || val<=0){ $(this).val(""); makeBudgetDetailsTable(0); calculateSum(); return; }else{ makeBudgetDetailsTable(val); } }); function getDifferenceText(a,b){ var years = a.diff(b, 'year'); b.add(years, 'years'); var months = a.diff(b, 'months'); b.add(months, 'months'); var days = a.diff(b, 'days'); var txtYear = (years > 1) ? "years " : "year "; var txtmonth = (months > 1) ? "months " : "month "; var txtDate = (days > 1) ? "days " : "day "; var txtDiff = years + txtYear + months + txtmonth + days + txtDate; return txtDiff; } function makeTotalOutlayOfProject(val){ var head = ""; var tbody = ""; var tbody_content = ""; var controllArray = []; $totalOutLayTable.find('.total_outlay_input').each(function (i) { $('#form_editproject').parsley( 'removeItem', "#"+ $(this).attr('id') ); }); //remove newly inserted rows first $totalOutLayTable.find('.new_ins').closest("th").remove(); $totalOutLayTable.find('.new_ins').closest("td").remove(); var rowCount = $('table#total_outlay_table td').length; rowCount--; // console.log("rowCount -> "+rowCount) ; for (var i=0 ; i < val ; i++) { var controllId = "total_outlay_input_"+i; controllArray.push(controllId); rowCount++; head+= "<th class='center new_ins'>" + ordinal_suffix_of(rowCount) + " Year</th>"; tbody_content+= "<td class='center new_ins'><input type='text' id='"+controllId+"' required class='form-control total_outlay_input new_item' name='out_lay[]'/> </td>"; }; $totalOutLayTable.find('th:last').prev().after(head); $totalOutLayTable.find('td:last').prev().after(tbody_content); console.log(controllArray); for(var i in controllArray){ $('#form_editproject').parsley( 'addItem', "#"+i ); } } function makeBudgetDetailsTable(val){ var budgetHeadMasterSelect = $("#budget_head_master_div").html(); var controllIDs = []; //remove newly added rows $budgetDetailsTable.find('.newly_added').remove(); for (var i=0 ; i < val ; i++) { var tbody_content = ""; var controllIdSelect = "sel_id_"+ (i+1); var controllIdTxt = "budget_head_master_value_"+ (i+1); var tempSel = budgetHeadMasterSelect; tempSel = tempSel.replace(/CONTROLL_ID/g, "sel_id_"+(i+1) ); tempSel = tempSel.replace(/CUSTOM_VAL/g, i+1 ); tempSel = tempSel.replace(/custattr/g, "required" ); controllIDs.push(controllIdSelect); controllIDs.push(controllIdTxt); tbody_content+= "<tr class='newly_added'><td class='center'> "+tempSel+" </td>"; tbody_content+= "<td class='center'><input type='text' id='"+controllIdTxt+"' required class='form-control budget_details_amount budget-head-common' name='budget_details_amount[]'/> </td></tr>"; $budgetDetailsTable.find('tr:last').prev().after(tbody_content); }; for(var i in controllIDs){ $('#form_editproject').parsley( 'addItem', "#"+controllIDs[i]); } // var selectedBudgetHeads = []; // var budgetSelectLogger = {}; } $("body").on("keyup","input.total_outlay_input",function () { var sum = parseInt(installment_splitup_amount); $totalOutLayTable.find("input.new_item").each(function(){ var val = $.trim($(this).val()); if(isNaN(val) || val<0){ val = 0; $(this).val(""); return; }else{ if(val != "" && typeof(val) != "undefined"){ sum+= parseInt(val); } } }); $totalOutLayTable.find("tr:last-child td:last-child").html("<b>"+(sum)+ "</b>"); $projectOutlayInp.val(sum); }); /*====================================================================================*/ var array_code = '<?php echo json_encode($budgetMasterArray); ?>'; array_code = JSON.parse(array_code); var used_budget_heads = '<?php echo json_encode($used_budget_heads); ?>'; used_budget_heads = JSON.parse(used_budget_heads); var AvailablebudgetHeads = []; for(var k in array_code){ if(used_budget_heads.indexOf(k) == -1 ){ AvailablebudgetHeads.push(k); } } var selectedBudgetHeads = []; var budgetSelectLogger = {}; function manageBudgetHeadSelectControlls(select_id,budgetHeadId){ // console.log("select_id : "+ select_id +" , budgetHeadId : "+ budgetHeadId + "---logger : "+budgetSelectLogger[select_id]); if( typeof(budgetSelectLogger[select_id]) != "undefined" && budgetSelectLogger[select_id] != "" ) { //already selected var previousSelectedId = budgetSelectLogger[select_id]; selectedBudgetHeads = remove_array_value(selectedBudgetHeads,previousSelectedId); AvailablebudgetHeads.push(previousSelectedId); budgetSelectLogger[select_id] = budgetHeadId; if(budgetHeadId != ""){ selectedBudgetHeads.push(budgetHeadId); AvailablebudgetHeads = remove_array_value(AvailablebudgetHeads,budgetHeadId); } }else{ selectedBudgetHeads.push(budgetHeadId); budgetSelectLogger[select_id] = budgetHeadId; AvailablebudgetHeads = remove_array_value(AvailablebudgetHeads,budgetHeadId); } // console.log("========================================"); // console.log(AvailablebudgetHeads); // console.log(selectedBudgetHeads); // console.log(budgetSelectLogger); $(".budget-head-select").each(function(){ var controll_id = $(this).attr("id"); if( controll_id != "CONTROLL_ID"){ for(var i in AvailablebudgetHeads){ // console.log("available : "+AvailablebudgetHeads[i]); $(this).children('option[value=' + AvailablebudgetHeads[i] + ']') .attr('disabled', false); } for(var j in selectedBudgetHeads){ if( $(this).val() != selectedBudgetHeads[j] ){ $(this).children('option[value=' + selectedBudgetHeads[j] + ']') .attr('disabled', true); } } } }); } function remove_array_value(array, value) { var index = array.indexOf(value); if (index >= 0) { array.splice(index, 1); } return array; } $('body').on('change', '.budget-head-select', function() { var textVal = $(this).children('option:selected').text(); var budgetHeadId = $(this).val(); var budgetVal = $(this).attr("budget-val"); var select_id = $(this).attr("id"); var className = "splitup_budget_head_"+budgetVal; $("."+className).val(textVal); $("."+className).attr("budget-head-id",budgetHeadId); manageBudgetHeadSelectControlls(select_id,budgetHeadId); }); $("body").on("keyup","input.budget_details_amount",function () { calculateSum(); }); function calculateSum(){ var sum = parseInt(budget_amount_total); $budgetDetailsTable.find("input.budget_details_amount").each(function(){ var val = $.trim($(this).val()); if(isNaN(val) || val<0){ val = 0; $(this).val(""); return; }else{ if(val != "" && typeof(val) != "undefined"){ sum+= parseInt(val); } } }); $budgetDetailsTable.find("tr:last-child td:last-child").html("<b>"+sum+"</b>"); } /*-----------------------------------------------*/ function showProjectConfirmationModel(){ var select_array = []; $(".select2-selection__choice").each(function (i) { var controll = $(this)[0]; select_array.push( $(controll).attr("title") ); }); console.log("select_array : "+ select_array); $("#con_project_code").text($("#txtprojectcode").val()); $("#con_project_title").text($("#txtproject_title").val()); $("#con_pricipal_inv").text($("#cmbpi option:selected").text()); $("#con_co_investigator").text( getCoInvestigators() ); $("#con_fund_type").text( $('#cmbfundtype option:selected').text() ); $("#con_fund_agency").text( $("#txtfund").val() ); $("#con_start_date").text( $("#start_date").val() ); $("#con_end_date").text( $("#end_date").val() ); $("#con_project_outlay").text($("#txtproject_overlay").val()); $("#con_duration").text($("#txtduration").val()); $("#con_budget_head_num").text($("table#budget_details_table tbody tr").length-1); $("#con-budget-details").html( getBudgetDetailsForConfirmation() ); $("#con-project-layout").html( getotalOutLayForConfirmation() ); // $("#con-project-splitup").html( getSlitupForConfirmation() ); $('#project-confirmation-modal').modal('show'); } /*----------------------------------------------*/ function getBudgetDetailsForConfirmation(){ var tempHtml = "<table class='table table-hover table-bordered'><tr><th class='center'>Budget Head</th><th class='center'>Budget Amount(Rupees)</th></tr>" var _total = 0; $("#budget_details_table").find('.master_val').each(function (i) { if( $(this).hasClass("key")){ tempHtml += "<tr><td>" + $(this).html() +"</td>" ; }else if($(this).hasClass("value")){ tempHtml += "<td>" + $(this).html() +"</td></tr>" ; var _val = $(this).html(); _total += parseInt($.trim(_val)); } }); $("#budget_details_table").find('.budget-head-common').each(function (i) { var controll = $(this)[0]; if( $(controll).prop('type') == 'text' ){ var _val = $(this).val(); _total += parseInt($.trim(_val)); tempHtml += "<td>" + $(this).val() +"</td></tr>" ; }else{ tempHtml += "<tr><td>" + $(controll).children('option:selected').text() +"</td>" ; } }); tempHtml +="<tr class='bold'><td>Total</td><td>"+_total+"</td></tr>"; tempHtml +="</table>"; return tempHtml; } function getotalOutLayForConfirmation(){ var tempHtml = "<table class='table table-hover table-bordered'><tr><th class='center'>Year</th><th class='center'>Amount (Rupees)</th></tr>" var num = 1; var total = 0; $totalOutLayTable.find("input").each(function(){ var val = $.trim($(this).val()); tempHtml += "<tr><td>" + num +"</td>" ; tempHtml += "<td>" + val +"</td></tr>" ; num++; total+=parseInt(val); }); tempHtml +="<tr class='bold'><td>Total (Rupees)</td><td>"+total+"</td></tr>"; tempHtml +="</table>"; return tempHtml; } function getCoInvestigators(){ var investArray = []; $(".tag").find("span").each(function(){ investArray.push($(this).text() ); }); return investArray.join(); } /*==========================================================*/ function submitPrjectForm(){ var projectOutLayArray = getTotalOutLay(); var budgetDetails = getBudgetDetails(); var postData = {}; var txtinvestigator = ""; postData.project_id = $("#project_id").val(); postData.project_code = $("#txtprojectcode").val(); postData.project_title = $("#txtproject_title").val(); postData.principle_investigator = $("#cmbpi").val();; postData.cmbfundtype = $("#cmbfundtype").val(); postData.txtfund = $("#txtfund").val(); postData.start_date = moment( $("#start_date").val() ).format("YYYY-MM-DD"); postData.end_date = moment( $("#end_date").attr("date-org")).format("YYYY-MM-DD"); postData.txtproject_overlay = $("#txtproject_overlay").val(); postData.txtduration = $("#txtduration").val(); postData.txtbudget_head = $("#txtbudget_head").val(); postData.f = "edit_project"; postData.projectOutLayArray = projectOutLayArray; postData.budgetDetails = budgetDetails; postData.installment = getProjectInstallments(); postData.txtinvestigator = getCoInvestigators(); console.log(postData); $.ajax({ url: "/CPMS_NEW/USER/pi_ajax.php", data: postData, type: 'post', cache: false, dataType: 'json', success: function (data) { $('#project-confirmation-modal').modal('hide'); $("html, body").animate({scrollTop: "0px"},500); if(data["status"]==true){ showSuccessDiv("msg_edit_project","Updated successfully ",true); setTimeout(function(){ location.href = BASE_URL+"pi_project_list.php" },1000); }else{ showErrorBoxDiv("msg_edit_project",data.error); } }, error:function(err){ } }); } function getTotalOutLay(){ var totalLayoutArray = []; $("#total_outlay_table").find('.total_outlay_input.new_item').each(function (i) { var layoutVal = $(this).val(); console.log("------>"+ layoutVal) if( isNotBlank(layoutVal) ){ totalLayoutArray.push($.trim(layoutVal)); }else{ } }); console.log(totalLayoutArray); return totalLayoutArray; } function getBudgetDetails(){ var keyArray = []; var valueArray = []; var objFinal = {}; $("#budget_details_table").find('.budget-head-common').each(function (i) { // console.log(this); if( $(this).prop('type') == 'text' ){ valueArray.push( $(this).val() ); }else{ keyArray.push( $(this).val() ); } }); //-----------------------------// for(var i = 0; i < keyArray.length ; i++ ){ objFinal[keyArray[i]] = valueArray[i]; // var obj = {}; // obj["budget_id"] = keyArray[i]; // obj["amount"] = valueArray[i]; // objFinal.push(obj); } console.log("====================================") console.log(keyArray) console.log(valueArray) console.log(objFinal) return objFinal; } function getProjectInstallments(){ var keyArray = []; var valueArray = []; var objFinal = []; $(".table-proj-splitup").find('input').each(function (i) { if( $(this).hasClass('installment_budget_details_amount')){ valueArray.push( $(this).val() ); }else{ keyArray.push( $(this).attr("budget-head-id") ); } }); for(var i = 0; i < keyArray.length ; i++ ){ //objFinal[keyArray[i]] = valueArray[i]; var obj = {}; obj["id"]= keyArray[i]; obj["v"]= valueArray[i]; objFinal.push(obj); } console.log(keyArray); console.log(valueArray); console.log(objFinal); return objFinal; } function AddBudgetMaster(){ var bdMsg = $("#budget-msg"); var bdSpin = $("#budget-spin"); var nn = $.trim($("#budgetNameMaster").val()); if(nn==null || nn.length<1){ bdMsg.html("Please enter Budget Head Master").css('color',"red").show(); return; } bdMsg.html("").hide(); bdSpin.show(); $.ajax({ url: BASE_URL+"pi_ajax.php", data: {name : nn,f:"add_budget_master"}, type: 'post', cache: false, dataType: 'json', success: function (data) { bdSpin.hide(); if(data.status==true && data.id >0 ){ bdMsg.html("Successfully added.").css('color',"green").show(); $('table#budget_details_table tbody select').append($('<option>', {value:data.id, text:nn})); $('div#budget_head_master_div select').append($('<option>', {value:data.id, text:nn})); setTimeout(function(){ $("#budgetNameMaster").val("") bdMsg.html("").hide(); AvailablebudgetHeads.push(data.id); $("#modal-budget-master").modal("toggle"); },700); }else{ bdMsg.html("Duplicate Budget Head Name").css('color',"red").show(); } }, error:function(err){ bdMsg.html("Something went wrong, Please try again").css('color',"red").show(); bdSpin.hide(); } }); } </script>