function toasterall(headingtext, Bodyttext, Typealert) {
$.toast({
heading: headingtext,
text: Bodyttext,
position: 'top-right',
loaderBg: '#ff6849',
icon: Typealert,
hideAfter: 3000,
stack: 6
});
}
var mybesturl = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname.split("/")[1] + "/";
if (mybesturl.indexOf("https://localhost:5001/") != -1) {
// console.log(str2 + " found");
mybesturl = window.location.protocol + "//" + window.location.host + "/" ;
}
function LoadddlSetup(id, Meassage, VType) {
$(id).empty();
$.ajax({
url: mybesturl +"Setup/LoadGetbyShow?VType=" + VType,
data: {},
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
error: function (xhr, textStatus, errorThrown) {
toasterall('Error', " An error occurred. Get " + Meassage + " ", 'error');
//if (xhr.status === 401) {
// window.location.href = myPathLogin;
//}
},
success: function (result) {
// console.log(result.Reslst);
if (result != null) {
if (result.MessageType === true) {
var data=result.Reslst;
var optionhtml1 = '<option value="">' + "Select " + Meassage + "" + '</option>';
$(id).append(optionhtml1);
$.each(data, function (i) {
var optionhtml = '<option value="' +
data[i].VID + '">' + data[i].VName + '</option>';
$(id).append(optionhtml);
});
} else {
toasterall('Error', result.Message, 'error');
}
}
}
});
}
function LoadddlSetupSelected(id, Meassage, VType, SelectedVal) {
$(id).empty();
$.ajax({
url: mybesturl + "Setup/LoadGetbyShow?VType=" + VType,
data: {},
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
error: function (xhr, textStatus, errorThrown) {
toasterall('Error', " An error occurred. Get " + Meassage + " ", 'error');
//if (xhr.status === 401) {
// window.location.href = myPathLogin;
//}
},
success: function (result) {
//console.log(result.Reslst);
if (result != null) {
if (result.MessageType === true) {
var data = result.Reslst;
var optionhtml1 = '<option value="">' + "Select " + Meassage + "" + '</option>';
$(id).append(optionhtml1);
$.each(data, function (i) {
var optionhtml = '<option value="' +
data[i].VID + '">' + data[i].VName + '</option>';
$(id).append(optionhtml);
});
$(id).val(SelectedVal);
} else {
toasterall('Error', result.Message, 'error');
}
}
}
});
}
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header text-uppercase">
<div class="divtitle">
Add Admin Expense Voucher
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-12">
<form id="frmAddAdminExpenseVoucher">
<div class="form-group row">
<label class="col-sm-2 col-form-label">Code</label>
<div class="col-sm-4">
<input type="text" class="form-control form-control-sm rounded-0 dn" id="txtVID" name="VID">
<input type="text" class="form-control form-control-sm rounded-0" id="txtVCode" name="VCode" readonly>
</div>
<label class="col-sm-2 col-form-label">Date</label>
<div class="col-sm-4">
<input type="text" class="form-control form-control-sm rounded-0 CustomDate" id="txtVdate" name="Vdate" maxlength="10" data-date-format="DD/MM/YYYY">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">Expense Type</label>
<div class="col-sm-4">
<select class="form-control form-control-sm rounded-0 select2" id="ddlExpenseTypeID" name="ExpenseTypeID">
<option value="">Select Expense Type </option>
</select>
</div>
<label class="col-sm-2 col-form-label">Note</label>
<div class="col-sm-4">
<input type="text" class="form-control form-control-sm rounded-0 " id="txtNote" name="Note">
</div>
</div>
<div class="form-group row">
<div class="col-sm-12">
@*<button type="reset" class="btn btn-sm btn-danger waves-effect waves-light pull-right dn"><i class="fa fa-times"></i> CANCEL</button>*@
<button id="btnsave" type="submit" class="btn btn-sm btn-success waves-effect waves-light pull-right "><i class="fa fa-check-square-o"></i> SAVE</button>
</div>
</div>
</form>
<div class="card">
<div class="card-header text-uppercase">Employee List</div>
<div class="card-body">
<div class="row">
<div class="col-md-12">
<table class="table table-bordered" id="tbl_AdminExp">
<thead>
<tr>
<th>
Sr #
</th>
<th>
Employee Code
</th>
<th>
Employee Name
</th>
<th>
Amount
</th>
</tr>
</thead>
<tbody id="tbl_tbody_AdminExp">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div><!--End Row-->
<script>
$(document).ready(function () {
var urlloc = GetqueryStr("VID");
if (urlloc) {
LoadGetRight("Accounts", "AdminExpenseVoucherList", "Update");
$(".divtitle").html("Edit Admin Expense Voucher");
EditLoadAdminExp(urlloc);
}
else {
LoadGetRight("Accounts", "AdminExpenseVoucherList", "Insert");
LoadVCode("#txtVCode", "AdminExpenseHeader", "Application Code Error");
LoadddlSetup("#ddlExpenseTypeID", "Expense Type", "ExpenseTypes-list");
EditLoadAdminExp(0);
$(".divtitle").html(" Add Admin Expense Voucher");
}
SaveAdminExp();
});
function addAdminExphtml(SRno,VID, AdminExpenseHeaderID, EmployeeID, EmployeeCode, EmployeeName, Amount) {
var myhtml = ' <tr><td ><small class="text-muted">' + SRno + '</small></td><td ><small class="text-muted CL_VID dn">' + VID + '</small><small class="text-muted CL_AdminExpenseHeaderID dn">' + AdminExpenseHeaderID + '</small><small class="text-muted CL_EmployeeID dn">' + EmployeeID + '</small><small class="text-muted">' + EmployeeCode + '</small></td>' +
' <td ><small class="text-muted">' + EmployeeName + '</small></td>' +
' <td ><input type="number" class="form-control form-control-sm rounded-0 CL_Amount " id="txtAmount" name="Amount" value="' + Amount +'"></td>' +
' </tr>';
$("#tbl_tbody_AdminExp").append(myhtml);
}
</script>
<script>
function EditLoadAdminExp(VID) {
$.ajax({
contentType: 'application/json; charset=utf-8',
dataType: 'JSON',
url: mybesturl + 'Accounts/LoadAddminExpByID?VID=' + VID,
type: 'post',
data: {},
success: function (result) {
if (result != null) {
if (result.MessageType == true) {
var lstbyid = result.Reslst;
console.log(result);
if (VID > 0) {
$('#txtVID').val(lstbyid.VID);
$('#txtVCode').val(lstbyid.VCode);
$('#txtVdate').val(lstbyid.VdateStr );
LoadddlSetupSelected("#ddlExpenseTypeID", "Expense Type", "ExpenseTypes-list", lstbyid.ExpenseTypeID);
$('#txtNote').val(lstbyid.Note);
}
if (result.Dlist.length > 0) {
$("#tbl_tbody_AdminExp").html("");
var mcount = 1;
$.each(result.Dlist, function (index, obj) {
addAdminExphtml(mcount,obj.VID, obj.AdminExpenseHeaderID, obj.EmployeeID, obj.EmployeeCode, obj.EmployeeName, obj.Amount);
mcount += mcount;
});
}
else {
$("#tbl_tbody_AdminExp").html("");
}
} else {
// console.log(result);
if (result.MessageCode === "02") {
toasterall('Error', result.Message, 'error');
}
else {
// console.log(result);
if (result.MessageCode === "03") {
toasterall('Error', result.Message, 'error');
}
else {
toasterall('Error', result.Message, 'error');
}
}
}
}
},
failure: function (result) {
toasterall('Error', result, 'error');
},
error: function (xhr, textStatus, errorThrown) {
if (xhr.status === 401) {
window.location.href = myPathLogin;
}
}
});
}
function SaveAdminExp() {
var validator = $("#frmAddAdminExpenseVoucher").validate({
rules: {
VCode: "required",
Vdate: "required",
ExpenseTypeID: "required",
Note: "required"
},
messages: {
VCode: "required",
Vdate: "required",
ExpenseTypeID: "required",
Note: "required"
},
submitHandler: function () {
var $TAdminExpItem = $('#tbl_AdminExp > tbody > tr');
var LAdminExpItem = [];
var chkDet = 0;
$.each($TAdminExpItem, function (index, value) {
var amtde = $(value).find(".CL_Amount").val() == "" ? 0 : $(value).find(".CL_Amount").val();
if (amtde > 0) {
chkDet += 1;
}
var BAdminExpItem = new Object();
BAdminExpItem["VID"] = $(value).find(".CL_VID").text();
BAdminExpItem["AdminExpenseHeaderID"] = $(value).find(".CL_AdminExpenseHeaderID").text();
BAdminExpItem["EmployeeID"] = $(value).find(".CL_EmployeeID").text();
BAdminExpItem["Amount"] = $(value).find(".CL_Amount").val() == "" ? 0 : $(value).find(".CL_Amount").val();
LAdminExpItem.push(BAdminExpItem);
});
var para = {
VID: $('#txtVID').val() == "" ? 0 : $('#txtVID').val(),
VCODE: $('#txtVCode').val(),
Vdate: $('#txtVdate').val(),
ExpenseTypeID: $('#ddlExpenseTypeID').val() == "" ? 0 : $('#ddlExpenseTypeID').val(),
Note: $('#txtNote').val(),
AdminExpenseDetail: LAdminExpItem
};
if (chkDet == 0) {
toasterall('Error', 'Please Add Amount atleast 1 Employee', 'error');
return false;
}
$('#btnsave').prop('disabled', true);
try {
$.ajax({
type: 'POST',
url: mybesturl + 'Accounts/AddAdminExpenseVoucher',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(para),
success: function (result) {
if (result != null) {
if (result.MessageType == true) {
toasterall('Error', result.Message, 'success');
RedirectPageURL('Accounts/AdminExpenseVoucherList');
} else {
if (result.MessageCode === "03") {
toasterall('Error', result.Message, 'error');
}
else {
toasterall('Error', result.Message, 'error');
}
}
}
},
failure: function (result) {
toasterall('Error', result, 'error');
},
error: function (xhr, textStatus, errorThrown) {
toasterall('Error', errorThrown, 'error');
if (xhr.status === 500) {
RedirectPageURL('Login');
}
}
});
} catch (err) {
toasterall('Error', err.message, 'error');
}
finally {
$('#btnsave').removeAttr("disabled");
}
}
});
}
</script>
No comments :
Post a Comment