605 lines
21 KiB
JavaScript
605 lines
21 KiB
JavaScript
var projectTable;
|
|
var projectRowID;
|
|
var projectPos;
|
|
|
|
var quotationTable;
|
|
var quotationRowID;
|
|
var quotationPos;
|
|
|
|
$(document).ready(function () {
|
|
deptList();
|
|
companyList();
|
|
loadyearmonth();
|
|
loadQuotationTable();
|
|
|
|
var actualDate = new Date(); // convert to actual date
|
|
var prevDate = new Date(actualDate.getFullYear(), actualDate.getMonth() - 13, actualDate.getDate());
|
|
|
|
var startTxt = prevDate.getFullYear().toString() + "/" + padding(prevDate.getMonth() + 1, 2);
|
|
var endTxt = actualDate.getFullYear().toString() + "/" + padding(actualDate.getMonth() + 1, 2);
|
|
|
|
const fpStart = flatpickr("#dateStart", {
|
|
"locale": "zh_tw",
|
|
"plugins": [
|
|
new monthSelectPlugin({
|
|
shorthand: true, //defaults to false
|
|
dateFormat: "Y/m", //defaults to "F Y"
|
|
altFormat: "Y M", //defaults to "F Y"
|
|
theme: "light" // defaults to "light"
|
|
})
|
|
]
|
|
});
|
|
|
|
const fpEnd = flatpickr("#dateEnd", {
|
|
"locale": "zh_tw",
|
|
"plugins": [
|
|
new monthSelectPlugin({
|
|
shorthand: true, //defaults to false
|
|
dateFormat: "Y/m", //defaults to "F Y"
|
|
altFormat: "Y M", //defaults to "F Y"
|
|
theme: "light" // defaults to "light"
|
|
})
|
|
]
|
|
});
|
|
|
|
fpStart.setDate(new Date(startTxt + '/1'))
|
|
fpEnd.setDate(new Date(endTxt + '/1'))
|
|
|
|
$('#projectSaveBtn').on('click', function () {
|
|
var company_uid = $('#company_select').val();
|
|
var project_name = $('#project_name').val();
|
|
var project_ps = $('#project_ps').val();
|
|
var project_uid = $('#project_uid').val();
|
|
var method = $('#project_method').val();
|
|
var dept_uid = $('#dept_select').val();
|
|
|
|
var msg = '';
|
|
|
|
if (company_uid == "") {
|
|
msg += '請選擇客戶公司!\n';
|
|
}
|
|
|
|
if (project_name == '') {
|
|
msg += '請輸入專案名稱!\n';
|
|
}
|
|
|
|
if (msg != '') {
|
|
alert(msg);
|
|
return;
|
|
}
|
|
|
|
var formData = {
|
|
method: method,
|
|
project_uid: project_uid,
|
|
project_name: project_name,
|
|
company_uid: company_uid,
|
|
project_ps: project_ps,
|
|
dept_uid: dept_uid
|
|
}
|
|
|
|
$.ajax({
|
|
url: "/Api/addEditDelGetProject",
|
|
type: "post",
|
|
data: formData,
|
|
success: function (data, textStatus, jqXHR) {
|
|
if (data.ret == "yes") {
|
|
var obj = data.projectViews[0];
|
|
|
|
if (method == "add") {
|
|
projectTable.fnAddData(obj);
|
|
}
|
|
|
|
if (method == "edit") {
|
|
projectTable.fnUpdate(obj, projectRowPos);
|
|
}
|
|
|
|
|
|
|
|
$('#clientProjectModal').modal('toggle');
|
|
} else {
|
|
alert(data.message);
|
|
|
|
if (data.err_code == "99999") {
|
|
location.href = "/Root/Login";
|
|
}
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
alert('網路或伺服器發生錯誤,請稍後重試!');
|
|
}
|
|
});
|
|
});
|
|
|
|
$('#dept_select').on('change', function () {
|
|
$('#dt-responsive').DataTable().ajax.reload();
|
|
});
|
|
$('#projectNewBtn').on('click', function () {
|
|
$('#project_method').val('add');
|
|
$('#clientProjectModal').modal("toggle");
|
|
});
|
|
|
|
function loadyearmonth() {
|
|
var actualDate = new Date(); // convert to actual date
|
|
|
|
var nowYear = actualDate.getFullYear();
|
|
|
|
for (tmpY = nowYear; tmpY >= 2019; tmpY--) {
|
|
$("#project_year").append($("<option></option>").attr("value", tmpY).text(tmpY + " 年度"));
|
|
}
|
|
|
|
for (tmpM = 1; tmpM <= 12; tmpM++) {
|
|
$("#project_month").append($("<option></option>").attr("value", tmpM).text(tmpM + " 月"));
|
|
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
function buttonClick(obj) {
|
|
var type = obj.getAttribute('data-method');
|
|
var uid = obj.getAttribute('data-uid');
|
|
var dept_uid = $('#dept_select').val();
|
|
|
|
projectRowID = $('#' + uid);
|
|
|
|
projectRowPos = projectTable.fnGetPosition($('#' + uid)[0]);
|
|
|
|
if (type == "preview") {
|
|
var data = $('#dt-responsive').DataTable().row(projectRowPos).data();
|
|
var project_name = data.project_name;
|
|
var company_name = data.company_name;
|
|
|
|
var project_info_div = '專案名稱: ' + project_name + ", 客戶公司:" + company_name;
|
|
|
|
var formData = {
|
|
project_uid: uid,
|
|
dept_uid: dept_uid
|
|
}
|
|
|
|
$.ajax({
|
|
url: "/Api/quotationList",
|
|
type: "post",
|
|
data: formData,
|
|
success: function (data, textStatus, jqXHR) {
|
|
if (data.ret == "yes") {
|
|
|
|
var obj = data.quotationViews;
|
|
|
|
$('#dt-responsive-quotation').dataTable().fnClearTable();
|
|
if (obj.length > 0) {
|
|
|
|
$('#dt-responsive-quotation').dataTable().fnAddData(obj);
|
|
}
|
|
|
|
$('#project_info_div').text(project_info_div);
|
|
$('#clientQuotationListModal').modal('toggle');
|
|
|
|
} else {
|
|
alert(data.message);
|
|
|
|
if (data.err_code == "99999") {
|
|
location.href = "/Root/Login";
|
|
}
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
alert('網路或伺服器發生錯誤,請稍後重試!');
|
|
}
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
if (type == "edit") {
|
|
var formData = {
|
|
method: 'get',
|
|
project_uid: uid,
|
|
dept_uid: dept_uid
|
|
}
|
|
|
|
$.ajax({
|
|
url: "/Api/addEditDelGetProject",
|
|
type: "post",
|
|
data: formData,
|
|
success: function (data, textStatus, jqXHR) {
|
|
if (data.ret == "yes") {
|
|
var obj = data.projectViews[0];
|
|
|
|
$("#project_method").val('edit');
|
|
$("#project_uid").val(obj.project_uid);
|
|
$("#project_name").val(obj.project_name).trigger('change');
|
|
$("#company_select").val(obj.company_uid);
|
|
$("#project_ps").val(obj.project_ps).trigger('change');
|
|
|
|
$('#clientProjectModal').modal('toggle');
|
|
} else {
|
|
alert(data.message);
|
|
|
|
if (data.err_code == "99999") {
|
|
location.href = "/Root/Login";
|
|
}
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
alert('網路或伺服器發生錯誤,請稍後重試!');
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
|
|
if (type == "del") {
|
|
if (confirm('確定刪除此筆專案資料? 所有此專案的報價單項目也會一併刪除~')) {
|
|
if (confirm('再次確認是否刪除所有此專案與報價單項目?')) {
|
|
var formData = {
|
|
method: 'del',
|
|
project_uid: uid,
|
|
dept_uid: dept_uid
|
|
}
|
|
|
|
$.ajax({
|
|
url: "/Api/addEditDelGetProject",
|
|
type: "del",
|
|
data: formData,
|
|
success: function (data, textStatus, jqXHR) {
|
|
if (data.ret == "yes") {
|
|
var row = projectTable.api().row(projectRowID).remove().draw(false);
|
|
alert('刪除成功');
|
|
|
|
} else {
|
|
alert(data.message);
|
|
|
|
if (data.err_code == "99999") {
|
|
location.href = "/Root/Login";
|
|
}
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
alert('網路或伺服器發生錯誤,請稍後重試!');
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
function loadQuotationTable() {
|
|
var dataTables = {
|
|
init: function init() {
|
|
|
|
this.bindUIActions();
|
|
},
|
|
bindUIActions: function bindUIActions() {
|
|
|
|
// event handlers
|
|
this.table = this.handleDataTables();
|
|
|
|
// add buttons
|
|
//this.table.buttons().container().appendTo('#dt-buttons').unwrap();
|
|
},
|
|
handleDataTables: function handleDataTables() {
|
|
//$('#myTable').append("<tfoot><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></tfoot>");
|
|
return $('#dt-responsive-quotation').DataTable({
|
|
dom: '<\'text-muted\'Bif>\n <\'table-responsive\'trl>\n <\'mt-4\'p>',
|
|
lengthChange: true,
|
|
lengthMenu: [[25, 50, 100, -1], [25, 50, 100, "All"]],
|
|
pageLength: 50,
|
|
buttons: [
|
|
//{
|
|
// text: '休假設定',
|
|
// action: function (e, dt, node, config) {
|
|
// vacationBtnFun();
|
|
|
|
// }
|
|
//},
|
|
//'excelHtml5'
|
|
],
|
|
language: {
|
|
paginate: {
|
|
previous: '<i class="fa fa-lg fa-angle-left"></i>',
|
|
next: '<i class="fa fa-lg fa-angle-right"></i>'
|
|
},
|
|
buttons: {
|
|
copyTitle: 'Data copied',
|
|
copyKeys: 'Use your keyboard or menu to select the copy command'
|
|
}
|
|
},
|
|
autoWidth: false,
|
|
rowId: 'quotation_uid',
|
|
deferRender: true,
|
|
initComplete: function () {
|
|
quotationTable = $('#dt-responsive-quotation').dataTable();
|
|
$('#dt-responsive-quotation').on('click', 'a', function () {
|
|
buttonQuotationClick(this);
|
|
});
|
|
|
|
$('#dt-responsive-quotation').on('click', 'button', function () {
|
|
buttonQuotationClick(this);
|
|
});
|
|
|
|
|
|
},
|
|
order: [[0, 'desc']],
|
|
info: true,
|
|
search: "搜尋:",
|
|
searching: true,
|
|
columns: [
|
|
{ data: 'quotation_name', className: 'align-top text-left', orderable: true, searchable: true },
|
|
{ data: 'quotation_date', className: 'align-top text-left', orderable: false, searchable: true },
|
|
{ data: 'contactPerson_name', className: 'align-top text-left', orderable: false, searchable: true },
|
|
{ data: 'quotation_uid', className: 'align-top text-center', orderable: false, searchable: false }
|
|
],
|
|
columnDefs: [
|
|
{
|
|
targets: 0,
|
|
className: 'align-middle text-left',
|
|
orderable: false,
|
|
searchable: true,
|
|
render: function render(data, type, row, meta) {
|
|
|
|
|
|
return '<a href="javascript: void(0);" data-uid="' + row.quotation_uid + '" data-version="' + row.quotation_version + '" data-method="preview" >' + row.quotation_name + '</a>';
|
|
|
|
}
|
|
},
|
|
{
|
|
targets: 3,
|
|
orderable: false,
|
|
searchable: false,
|
|
render: function render(data, type, row, meta) {
|
|
var ret = '';
|
|
|
|
ret += '<button type="button" data-uid="' + row.quotation_uid + '" data-version="' + row.quotation_version + '" data-method="edit" class="btn btn-sm btn-icon btn-secondary" ><i class="fa fa-pencil-alt"></i> <span class="sr-only">Edit</span></button>';
|
|
ret += '<button type="button" data-uid="' + row.quotation_uid + '" data-version="' + row.quotation_version + '" data-method="del" class="btn btn-sm btn-icon btn-secondary"><i class="far fa-trash-alt"></i> <span class="sr-only">Remove</span></button>';
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
],
|
|
responsive: {
|
|
details: {
|
|
display: $.fn.dataTable.Responsive.display.childRowImmediate,
|
|
type: ''
|
|
}
|
|
}
|
|
});
|
|
},
|
|
handleSearchRecords: function handleSearchRecords() {
|
|
var self = this;
|
|
|
|
$('#table-search, #filterBy').on('keyup change focus', function (e) {
|
|
var filterBy = $('#filterBy').val();
|
|
var hasFilter = filterBy !== '';
|
|
var value = $('#table-search').val();
|
|
|
|
self.table.search('').columns().search('').draw();
|
|
|
|
if (hasFilter) {
|
|
self.table.columns(filterBy).search(value).draw();
|
|
} else {
|
|
self.table.search(value).draw();
|
|
}
|
|
|
|
});
|
|
}
|
|
}
|
|
|
|
dataTables.init();
|
|
}
|
|
function loadDataTable() {
|
|
var dataTables = {
|
|
init: function init() {
|
|
|
|
this.bindUIActions();
|
|
},
|
|
bindUIActions: function bindUIActions() {
|
|
|
|
// event handlers
|
|
this.table = this.handleDataTables();
|
|
|
|
// add buttons
|
|
//this.table.buttons().container().appendTo('#dt-buttons').unwrap();
|
|
},
|
|
handleDataTables: function handleDataTables() {
|
|
//$('#myTable').append("<tfoot><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></tfoot>");
|
|
return $('#dt-responsive').DataTable({
|
|
dom: '<\'text-muted\'Bif>\n <\'table-responsive\'trl>\n <\'mt-4\'p>',
|
|
lengthChange: true,
|
|
lengthMenu: [[25, 50, 100, -1], [25, 50, 100, "All"]],
|
|
pageLength: 50,
|
|
buttons: [
|
|
//{
|
|
// text: '休假設定',
|
|
// action: function (e, dt, node, config) {
|
|
// vacationBtnFun();
|
|
|
|
// }
|
|
//},
|
|
//'excelHtml5'
|
|
],
|
|
language: {
|
|
paginate: {
|
|
previous: '<i class="fa fa-lg fa-angle-left"></i>',
|
|
next: '<i class="fa fa-lg fa-angle-right"></i>'
|
|
},
|
|
buttons: {
|
|
copyTitle: 'Data copied',
|
|
copyKeys: 'Use your keyboard or menu to select the copy command'
|
|
}
|
|
},
|
|
autoWidth: false,
|
|
ajax: {
|
|
url: '/Api/projectViewList',
|
|
type: 'POST',
|
|
data: function (d) {
|
|
Object.assign(d, {
|
|
dept_uid: $('#dept_select').val(),
|
|
start_txt: $('#dateStart').val(),
|
|
end_txt: $('#dateEnd').val()
|
|
});
|
|
|
|
return d;
|
|
},
|
|
dataSrc: 'projectViews'
|
|
},
|
|
rowId: 'project_uid',
|
|
deferRender: true,
|
|
initComplete: function () {
|
|
projectTable = $('#dt-responsive').dataTable();
|
|
$('#dt-responsive').on('click', 'a', function () {
|
|
buttonClick(this);
|
|
});
|
|
|
|
$('#dt-responsive').on('click', 'button', function () {
|
|
buttonClick(this);
|
|
});
|
|
|
|
|
|
},
|
|
order: [[0, 'desc']],
|
|
info: true,
|
|
search: "搜尋:",
|
|
searching: true,
|
|
columns: [
|
|
{ data: 'project_datetime', className: 'align-top text-left', orderable: true, searchable: true },
|
|
{ data: 'project_name', className: 'align-top text-left', orderable: false, searchable: true },
|
|
{ data: 'company_name', className: 'align-top text-left', orderable: false, searchable: true },
|
|
{ data: 'project_ps', className: 'align-top text-left', orderable: false, searchable: false },
|
|
{ data: 'project_uid', className: 'align-top text-center', orderable: false, searchable: false }
|
|
],
|
|
columnDefs: [
|
|
{
|
|
targets: 1,
|
|
className: 'align-middle text-left',
|
|
orderable: false,
|
|
searchable: true,
|
|
render: function render(data, type, row, meta) {
|
|
|
|
|
|
return '<a href="javascript: void(0);" data-uid="' + row.project_uid + '" data-method="preview" >' + row.project_name + '</a>';
|
|
|
|
}
|
|
},
|
|
{
|
|
targets: 4,
|
|
orderable: false,
|
|
searchable: false,
|
|
render: function render(data, type, row, meta) {
|
|
var ret = '';
|
|
|
|
ret += '<button type="button" data-uid="' + row.project_uid + '" data-method="edit" class="btn btn-sm btn-icon btn-secondary" ><i class="fa fa-pencil-alt"></i> <span class="sr-only">Edit</span></button>';
|
|
ret += '<button type="button" data-uid="' + row.project_uid + '" data-method="del" class="btn btn-sm btn-icon btn-secondary"><i class="far fa-trash-alt"></i> <span class="sr-only">Remove</span></button>';
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
],
|
|
responsive: {
|
|
details: {
|
|
display: $.fn.dataTable.Responsive.display.childRowImmediate,
|
|
type: ''
|
|
}
|
|
}
|
|
});
|
|
},
|
|
handleSearchRecords: function handleSearchRecords() {
|
|
var self = this;
|
|
|
|
$('#table-search, #filterBy').on('keyup change focus', function (e) {
|
|
var filterBy = $('#filterBy').val();
|
|
var hasFilter = filterBy !== '';
|
|
var value = $('#table-search').val();
|
|
|
|
self.table.search('').columns().search('').draw();
|
|
|
|
if (hasFilter) {
|
|
self.table.columns(filterBy).search(value).draw();
|
|
} else {
|
|
self.table.search(value).draw();
|
|
}
|
|
|
|
});
|
|
}
|
|
}
|
|
|
|
dataTables.init();
|
|
}
|
|
|
|
function companyList() {
|
|
$.ajax({
|
|
url: "/Api/companyList",
|
|
type: "post",
|
|
data: null,
|
|
success: function (data, textStatus, jqXHR) {
|
|
if (data.ret == "yes") {
|
|
var obj = data.companys;
|
|
var items = "";
|
|
|
|
$("#company_select").append($("<option>", {
|
|
value: '',
|
|
text: '請選擇客戶公司'
|
|
}));
|
|
$.each(obj, function (i, item) {
|
|
|
|
|
|
$("#company_select").append($("<option>", {
|
|
value: item.company_uid,
|
|
text: item.company_name
|
|
}));
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
alert(data.message);
|
|
|
|
if (data.err_code == "99999") {
|
|
location.href = "/Root/Login";
|
|
}
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
alert('網路或伺服器發生錯誤,請稍後重試!');
|
|
}
|
|
});
|
|
}
|
|
function deptList() {
|
|
$.ajax({
|
|
url: "/Api/deptList",
|
|
type: "post",
|
|
data: null,
|
|
success: function (data, textStatus, jqXHR) {
|
|
if (data.ret == "yes") {
|
|
var obj = data.depts;
|
|
var items = "";
|
|
$.each(obj, function (i, item) {
|
|
|
|
|
|
$("#dept_select").append($("<option>", {
|
|
value: item.dept_uid,
|
|
text: item.dept_name
|
|
}));
|
|
|
|
|
|
});
|
|
loadDataTable();
|
|
|
|
} else {
|
|
alert(data.message);
|
|
|
|
if (data.err_code == "99999") {
|
|
location.href = "/Root/Login";
|
|
}
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
alert('網路或伺服器發生錯誤,請稍後重試!');
|
|
}
|
|
});
|
|
}
|