| Server IP : 172.67.216.113 / Your IP : 104.23.243.32 [ Web Server : Apache System : Linux cpanel01wh.bkk1.cloud.z.com 2.6.32-954.3.5.lve1.4.59.el6.x86_64 #1 SMP Thu Dec 6 05:11:00 EST 2018 x86_64 User : cp648411 ( 1354) PHP Version : 7.2.34 Disable Function : NONE Domains : 0 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home2/cp648411/public_html/ilawasia.onnud20.com/Scripts/pages_v1/ |
Upload File : |
var items = [];
var isItemEdit = false;
var itemEditId = 0;
var documents = [];
var isDocumentEdit = false;
var documentEditId = 0;
var payments = [];
var isPaymentEdit = false;
var paymentEditId = 0;
var sumItems = 0;
var sumPaymentTerms = 0;
var countRelatedSuccess = 0;
$(document).ready(function ($) {
$("#CBO_QUOTATION_TYPE").change(function () {
if ($(this).val() == "1") {
$("#RETAINER_DURATION").hide("slow");
} else {
$("#RETAINER_DURATION").show("slow");
}
});
var quotationType = $("#CBO_QUOTATION_TYPE").val();
if (typeof retainerStart !== 'undefined' || typeof retainerEnd !== 'undefined') {
if (quotationType == '2') {
$("#RETAINER_DURATION").show("slow");
}
if (retainerStart != "") {
var stDate = new Date(retainerStart);
$("#dte_retain_start").datepicker('setDate', stDate);
}
if (retainerEnd != "") {
var nDate = new Date(retainerEnd);
$("#dte_retain_end").datepicker('setDate', nDate);
}
}
if (typeof urlLoadCustomerAuto !== 'undefined') { //'undefined'
}
var customerInput = $("#customer-filter");
//console.log(customerInput.val());
var autocompCustomer = customerInput.autocomplete({
source: function (request, response) {
$.getJSON(urlLoadCustomerAuto, {
Keyword: customerInput.val()
}, response);
},
select: function (event, ui) {
customerInput.val(ui.item.custCode + '-' + ui.item.custName);
$("#hd-customer-id").val(ui.item.custId);
return false;
}
}).change(function (e) {
if (e.target.value == "") { $("#hd-customer-id").val(''); }
});
autocompCustomer.autocomplete("instance")._renderItem = function (ul, item) {
//console.log(item);
return $("<li>").append(item.custCode + '-' + item.custName).appendTo(ul);
};
/*
*/
if (typeof urlLoadQuotationList !== 'undefined') {
loadQuotationList();
}
if (typeof urlLoadCustomer !== 'undefined') {
loadCustomer();
}
if (typeof countryId !== 'undefined' && countryId != "") {
loadCaseType(countryId);
}
if (typeof customerId !== 'undefined') {
loadCustomerDetail(customerId);
loadItems();
loadDocuments();
loadPayments();
loadRelatedList();
}
if ($.isFunction($.fn.validate)) {
$("#quotation-form").validate({
ignore: "",
rules: {
CountryId: {
required: true,
},
CaseTypeId: {
required: true
},
CustomerId: {
required: true
},
QuotationType: {
required: true
},
RetainerStart: {
required: function () {
return $("#CBO_QUOTATION_TYPE").val() == '2';
}
},
RetainerEnd: {
required: function () {
return $("#CBO_QUOTATION_TYPE").val() == '2';
}
},
Condition: {
required: function () {
return $("#CBO_QUOTATION_TYPE").val() == '2';
}
},
LocalQuantity: {
required: function () {
return $("#CBO_QUOTATION_TYPE").val() == '2';
}
},
InterQuantity: {
required: function () {
return $("#CBO_QUOTATION_TYPE").val() == '2';
}
},
CreditTerms: {
required:true
},
Vat: {
required:true
},
ContactPerson: {
required: true
},
Currency: {
required:true
}
},
errorPlacement: function (error, element) {
if (element.parent().hasClass('input-group')) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
})
}
$("#itemModal").on("hide.bs.modal", function () {
$("#item-form").trigger("reset");
});
$("#paymentModal").on("hide.bs.modal", function () {
$("#payment-form").trigger("reset");
});
$("#documentModal").on("hide.bs.modal", function () {
$("#document-form").trigger("reset");
$("#doc_link").hide();
$("#doc_link > a").attr("href", "");
$("#doc_link > a").text("");
$("#doc_approve_link").hide();
$("#doc_approve_link > a").attr("href", "");
$("#doc_approve_link > a").text("");
$(".file-approve").hide();
});
});
function docStatusChange(e) {
if ($(e).val() == '3') {
$(".file-approve").show();
} else {
$(".file-approve").hide();
}
}
function editItem(index) {
isItemEdit = true;
var edit = items[index];
itemEditId = edit.QuotationItemId;
$("#txt_item_desc").val(edit.Description);
$("#txt_item_quantity").val(edit.Quantity);
$("#txt_item_price").val(edit.UnitPrice);
if (edit.IsExcludeVat == 1) {
$("#check_ex_vat").prop('checked', true);
}
$("#itemModal").modal("show");
}
function deleteItem(index) {
if (confirm("Confirm to delete?")) {
var formToken = $('#__AjaxAntiForgeryForm');
var token = $('input[name="__RequestVerificationToken"]', formToken).val();
$.ajax({
url: urlDeleteItem,
data: { Id: items[index].QuotationItemId, __RequestVerificationToken:token},
type: 'POST',
success: function (resp) {
$("#itemModal").modal("hide");
loadItems();
$("#item-submit").prop("disabled", false);
location.reload();
},
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 400) {
alert(jqXHR.responseJSON.Message);
}
$("#item-submit").prop("disabled", false);
}
})
}
}
function loadItems() {
items = [];
var $tb = $("#item-table > tbody");
$tb.html('');
sumItems = 0;
$.get(urlLoadItem, { QuotationId: quotationId }).done(function (resp) {
var vat = parseFloat($("#txt_vat").val());
var total = 0;
var totalExcludeVat = 0;
var res = JSON.parse(resp);
//console.log(res);
if(res.Data.length > 0){
res.Data.forEach((element, index) => {
//console.log(element.Description);
var html = '<tr>' +
'<td>'+(index+1)+'</td>' +
'<td>' + element.Description + '</td>' +
'<td class="text-center">' + element.Quantity + '</td>' +
'<td class="text-right">' + numberWithCommas(element.UnitPrice.toFixed(2)) + '</td>' +
'<td class="text-right">' + numberWithCommas(element.Amount.toFixed(2)) + '</td>' +
'<td class="text-center">' + (element.IsExcludeVat == 1 ? "✓":"-") + '</td>' +
'<td>' +
'<a class="btn btn-info btn-sm" href="javascript:;" onclick="editItem('+index+')"><i class="fas fa-edit"></i>Edit</a> ' +
'<a class="btn btn-danger btn-sm" href="javascript:;" onclick="deleteItem(' + index +')"><i class="fas fa-trash"></i>Delete</a>' +
'</td > ' +
'</tr>';
$(html).appendTo($tb);
items.push(element);
if (element.IsExcludeVat != 1) {
total += (element.Quantity * element.UnitPrice);
} else {
totalExcludeVat += (element.Quantity * element.UnitPrice);
}
})
}else{
var html = '<tr>' +
'<td colspan="7"></td>' +
'</tr>';
}
sumItems = total;
var vatTotal = total * vat / 100;
var netTotal = total + totalExcludeVat + vatTotal;
$("#lbl_vat").text(numberWithCommas(vatTotal.toFixed(2)));
$("#lbl_total").text(numberWithCommas(netTotal.toFixed(2)));
countRelatedSuccess++;
calculateItemsAndPaymentTerms();
})
}
function calculateItemsAndPaymentTerms() {
if (countRelatedSuccess == 2) {
var $e = $(".lbl-related-item");
$e.removeClass('text-danger').removeClass('text-success');
var msg = 'Items total = ' + numberWithCommas(sumItems.toFixed(2)) + ",Payment Terms total = " + numberWithCommas(sumPaymentTerms.toFixed(2));
$e.text(msg);
if (sumItems != sumPaymentTerms) {
$e.addClass('text-danger');
} else {
$e.addClass('text-success');
}
countRelatedSuccess = 1;
}
}
function editDocument(index) {
isDocumentEdit = true;
var edit = documents[index];
documentEditId = edit.QuotationDocumentId;
$("#txt_doc_type").val(edit.DocType);
if (edit.FilePath != null) {
var arrFile = edit.FilePath.split('/');
$("#doc_link").show();
$("#doc_link > a").attr("href", "/Upload/" + edit.FilePath);
$("#doc_link > a").text(arrFile[arrFile.length - 1]);
}
$("#ddl_doc_status").val(edit.Status);
if (edit.ApproveFilePath != null) {
var arrApproveFile = edit.ApproveFilePath.split('/');
$("#doc_approve_link").show();
$("#doc_approve_link > a").attr("href", "/Upload/" + edit.ApproveFilePath);
$("#doc_approve_link > a").text(arrApproveFile[arrApproveFile.length - 1]);
}
if (edit.Status == 3) {
$(".file-approve").show();
}
$("#documentModal").modal("show");
}
function deleteDocument(index) {
if (confirm("Confirm to delete?")) {
var formToken = $('#__AjaxAntiForgeryForm');
var token = $('input[name="__RequestVerificationToken"]', formToken).val();
$.ajax({
url: urlDeleteDocument,
data: { Id: documents[index].QuotationDocumentId, __RequestVerificationToken: token },
type: 'POST',
success: function (resp) {
//console.log(resp);
loadDocuments();
location.reload();
},
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 400) {
alert(jqXHR.responseJSON.Message);
}
}
})
}
}
function getDocumentStatusText(id) {
var obj = ["Pending", "Waiting Paid", "Paid"];
return obj[id - 1];
}
function loadDocuments() {
documents = [];
var $tb = $("#document-table > tbody");
$tb.html('');
$.get(urlLoadDocument, { QuotationId: quotationId }).done(function (resp) {
var res = JSON.parse(resp);
//console.log(res_d);
if(res.Data.length > 0){
res.Data.forEach((element, index) => {
var arrFile = element.FilePath.split('/');
var html = '<tr>' +
'<td>' + (index + 1) + '</td>' +
'<td>' + element.DocType + '</td>' +
'<td><a href="../Upload/' + element.FilePath + '" target="_blank">' + arrFile[arrFile.length - 1] + '</a></td>' +
'<td>' + getDocumentStatusText(element.Status) + '' + (element.Status == 3 ? ' <a href="../Upload/' + element.ApproveFilePath + '" target="_blank"><i class="fas fa-file-pdf"></i></a>' : '') + '</td>' +
'<td>' +
'<a class="btn btn-info btn-sm" href="javascript:;" onclick="editDocument(' + index + ')"><i class="fas fa-edit"></i>Edit</a> ' +
'<a class="btn btn-danger btn-sm" href="javascript:;" onclick="deleteDocument(' + index + ')"><i class="fas fa-trash"></i>Delete</a>' +
'</td > ' +
'</tr>';
$(html).appendTo($tb);
documents.push(element);
})
}else{
var html = '<tr>' +
'<td colspan="7"></td>' +
'</tr>';
}
})
}
function editPayment(index) {
isPaymentEdit = true;
var edit = payments[index];
paymentEditId = edit.QuotationPaymentTermId;
$("#txt_payment_phase").val(edit.Phase);
$("#txt_payment_detail").val(edit.Detail);
$("#txt_payment_amount").val(edit.Amount);
$("#ddl_payment_status").val(edit.Status);
$("#paymentModal").modal("show");
}
function deletePayment(index) {
if (confirm("Confirm to delete?")) {
var formToken = $('#__AjaxAntiForgeryForm');
var token = $('input[name="__RequestVerificationToken"]', formToken).val();
$.ajax({
url: urlDeletePayment,
data: { Id: payments[index].QuotationPaymentTermId, __RequestVerificationToken: token },
type: 'POST',
success: function (resp) {
console.log(resp);
/*
*/
$("#paymentModal").modal("hide");
loadPayments();
$("#payment-submit").prop("disabled", false);
location.reload();
},
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 400) {
alert(jqXHR.responseJSON.Message);
}
$("#payment-submit").prop("disabled", false);
}
})
}
}
function loadPayments() {
payments = [];
var $tb = $("#payment-table > tbody");
$tb.html('');
sumPaymentTerms = 0;
$.get(urlLoadPayment, { QuotationId: quotationId }).done(function (resp) {
var res = JSON.parse(resp);
//console.log(res);
if(res.Data.length >0){
res.Data.forEach((element, index) => {
var html = '<tr>' +
'<td>' + (index + 1) + '</td>' +
'<td>' + element.Phase + '</td>' +
'<td>' + element.Detail + '</td>' +
'<td class="text-right">' + numberWithCommas(element.Amount.toFixed(2)) + '</td>' +
'<td>' + getDocumentStatusText(element.Status) + '</td><td>' ;
for (var i = 0; i < element.invoicelist.length; i++) {
html += '<a href="../Invoice/?InvoiceNo=' +element.invoicelist[i].InvoiceNo+ '"><p>' + element.invoicelist[i].InvoiceNo + '</p></a>';
}
html += '</td><td>' +
(element.IsEdit ? '<a class="btn btn-info btn-sm" href="javascript:;" onclick="editPayment(' + index + ')"><i class="fas fa-edit"></i>Edit</a> ' : '-') +
(element.IsEdit ? '<a class="btn btn-danger btn-sm" href="javascript:;" onclick="deletePayment(' + index + ')"><i class="fas fa-trash"></i>Delete</a>':'') +
'</td > ' +
'</tr>';
$(html).appendTo($tb);
payments.push(element);
sumPaymentTerms += element.Amount;
countRelatedSuccess++;
calculateItemsAndPaymentTerms();
})
}else{
var html = '<tr>' +
'<td colspan="7"></td>' +
'</tr>';
}
})
}
function loadCaseType(val) {
$("#ddl_case_type option[class*='load']").remove();
$.get(urlLoadCaseType, { CountryId: val })
.done(function (resp) {
var res = JSON.parse(resp);
//console.log(resp);
$.each(res, function (key, value) {
$('<option value="' + value.CaseTypeId + '" class="load">' + value.CaseTypeName + '</option>').appendTo("#ddl_case_type");
})
if (typeof caseTypeId !== 'undefined') {
$("#ddl_case_type").val(caseTypeId);
}
});
}
function loadCustomer(search = false) {
var parent = $("#customer_pagination");
var tableTbody = parent.find("table>tbody");
var page = parent.find(".page").val();
var pageSize = parent.find(".page-size").val();
var $loader = parent.find('.table-loader');
if (search == true) page = 1;
var params = {
PageNumber: page,
PageSize: pageSize
};
if ($("#hd-customer-id").val() != "") {
params.CustomerId = $("#hd-customer-id").val();
}
if ($("#txt_search_cus_code").val() != "") {
params.CustomerCode = $("#txt_search_cus_code").val();
}
if ($("#txt_search_cus_name").val() != "") {
params.CustomerName = $("#txt_search_cus_name").val();
}
$loader.show();
$.get(urlLoadCustomer, params)
.done(function (resp) {
var res = JSON.parse(resp);
//console.log(resp);
$(tableTbody).html('');
$.each(res.Data, function (key, value) {
var html = '<tr>' +
' <td > ' + value.custCode + '</td>' +
' <td>' + value.custName + '</td>' +
' <td><button type="button" class="btn btn-info btn-sm" onclick="shopCustomer(\'' + value.custId + '\',\'' + value.custCode + '\',\'' + $.trim(escape(value.address)) + '\',\'' + value.custName + '\',\'' + value.taxId + '\')"><i class="fa fa-edit"></i> Select</button>' +
//' <div><input type="hidden" class="address" value="'+value.address+'" /></div>' +
'</td > ' +
'</tr > ';
$(html).appendTo(tableTbody);
});
parent.find(".page").val(res.PageNumber);
parent.find(".page-size").val(res.PageSize);
parent.find(".numrows").val(res.TotalRecords);
renderPagination('#customer_pagination', 'loadCustomer');
$loader.hide();
});
}
function loadCustomerDetail(id) {
var params = {
id: id,
};
$.get(urlGetCustomerDetail, params)
.done(function (resp) {
var res = JSON.parse(resp);
$("#hd_cus_id").val(res[0].custId);
$("#txt_cus_name").val(res[0].custName);
$("#txt_cus_tax_id").val(res[0].taxId == null ? "" : res.taxId);
$("#txt_cus_code").val(res[0].custCode);
$("#txt_cus_address").val(res[0].address);
$("#txt_cus_billing_address").val(res[0].address);
});
}
function shopCustomer(id, cusCode, address,name,taxId) {
$("#hd_cus_id").val(id);
$("#txt_cus_name").val(name);
$("#txt_cus_tax_id").val(taxId=='null' ? "" : taxId);
$("#txt_cus_code").val(cusCode);
$("#txt_cus_address").val(address);
$("#txt_cus_billing_address").val(address);
$("#customerModal").modal('hide');
}
function loadQuotationList() {
var parent = $("#quotation_pagination");
var tableTbody = parent.find("table>tbody");
var page = parent.find(".page").val();
var pageSize = parent.find(".page-size").val();
var orderBy = parent.find('.orderBy').val();
var orderDirection = parent.find('.orderDirection').val();
var paramsHidden = parent.find(".params").val();
var $loader = parent.find('.table-loader');
var params = {
PageNumber: page,
PageSize: pageSize,
OrderBy: orderBy,
OrderDirection: orderDirection
};
if (paramsHidden != "") {
params = Object.assign({}, params, JSON.parse('{"' + decodeURI(paramsHidden).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}'));
}
//console.log(params);
$loader.show();
$.get(urlLoadQuotationList, params)
.done(function (resp) {
var res = JSON.parse(resp);
//console.log(res);
if (res.Data.length > 0) {
$(tableTbody).html('');
$.each(res.Data, function (key, value) {
var html = '<tr>' +
' <td style="width: 182px;">' + value.QuotationNo + '</td>' +
' <td style="width: 182px;"> ' + value.CustomerCode + '</td>' +
' <td style="width: 250px;">' + value.CustomerName + '</td>' +
' <td style="width: 150px;">' + value.Country + '</td> <td style="width: 150px;"> ' ;
if(value.invoicelist.length> 0){
for (var i = 0; i < value.invoicelist.length; i++) {
html += '<a href="../Invoice/?InvoiceNo=' +value.invoicelist[i].InvoiceNo+ '"><p>' + value.invoicelist[i].InvoiceNo + '</p></a>';
}
}
html += ' </td> <td style="width: 150px;">' + value.StatusText + '</td>' +
' <td style="width: 150px;"><b class="text-primary">' + ((value.Amount==null)? "0": numberWithCommas(value.Amount.toFixed(2))) + '</b>/<b class="text-success">' + ((value.PaidAmount==null)? "0":numberWithCommas(value.PaidAmount.toFixed(2))) + '</b></td>' +
' <td><a href="' + urlEdit + "?Id=" + value.QuotationId + '&Type=Edit" class="btn btn-info btn-sm"><i class="fa fa-search"></i> View</a>' +
((value.IsEdit == 0) ? ' <a href="javascript:;" class="btn btn-danger btn-sm" onclick="deleteQuotation(' + value.QuotationId + ')"><i class="fa fa-trash"></i> Delete</a>' : '') +
'</td > ' +
'</tr > ';
$(html).appendTo(tableTbody);
});
parent.find(".page").val(res.PageNumber);
parent.find(".page-size").val(res.PageSize);
parent.find(".numrows").val(res.TotalRecords);
parent.find(".orderBy").val(res.OrderBy);
parent.find(".orderDirection").val(res.OrderDirection);
var $order = parent.find("th>a.order[data-by=" + res.OrderBy + "]");
if ($order.length > 0) {
parent.find("th>a.order").attr('data-direction', "").attr("class", "").addClass("order sorting");
$order.attr("data-direction", res.OrderDirection == null ? "" : res.OrderDirection);
$order.attr("class", "");
if (resp.OrderDirection != null) {
$order.addClass("order sorting_" + res.OrderDirection.toLowerCase());
} else {
$order.addClass("order sorting");
}
}
renderPagination('#quotation_pagination', 'redirectPaging');
} else {
$(tableTbody).html('<tr><td colspan="7" class="text-center">Not found data</td></tr>');
}
$loader.hide();
});
}
function deleteQuotation(id) {
if (confirm('Confirm to delete ?')) {
var formToken = $('#__AjaxAntiForgeryForm');
var token = $('input[name="__RequestVerificationToken"]', formToken).val();
$.ajax({
url: urlDelete + '?id=' + id,
data: { __RequestVerificationToken: token },
type: 'POST',
success: function (resp) {
//console.log(resp);
loadQuotationList();
},
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 400) {
alert(jqXHR.responseJSON.Message);
}
}
})
}
}
function loadRelatedList() {
var parent = $("#related_pagination");
var tableTbody = parent.find("table>tbody");
var page = parent.find(".page").val();
var pageSize = parent.find(".page-size").val();
var orderBy = parent.find('.orderBy').val();
var orderDirection = parent.find('.orderDirection').val();
var $loader = parent.find('.table-loader');
var params = {
PageNumber: page,
PageSize: pageSize,
OrderBy: orderBy,
OrderDirection: orderDirection,
QuotationId: quotationId
};
$loader.show();
$.get(urlLoadRelatedCase, params)
.done(function (resp) {
var res_ca = JSON.parse(resp);
if (res_ca.Data.length > 0) {
$(tableTbody).html('');
$.each(res_ca.Data, function (key, value) {
var html = '<tr>' +
' <td><a href="' + urlCaseEdit + "?Id=" + value.CaseId + '&Type=Edit" target="_blank">' + value.CaseNumber + '</a></td>' +
' <td>' + value.DueDate + '</td>' +
' <td>' + value.CaseType + '</td>' +
'</tr>';
$(html).appendTo(tableTbody);
});
parent.find(".page").val(res_ca.PageNumber);
parent.find(".page-size").val(res_ca.PageSize);
parent.find(".numrows").val(res_ca.TotalRecords);
parent.find(".orderBy").val(res_ca.OrderBy);
parent.find(".orderDirection").val(res_ca.OrderDirection);
renderPagination('#related_pagination', 'loadRelatedList');
} else {
$(tableTbody).html('<tr><td colspan="3" class="text-center">Not found data</td></tr>');
}
$loader.hide();
});
}