'use strict';
var sProgramId = getProgramId(),
sQueryPrgId = getQueryPrgId(),
sAction = getUrlParam('Action') || 'Add',
sDataId = getUrlParam('ExportBillNO'),
sFlag = getUrlParam('Flag'),
sGoTab = getUrlParam('GoTab'),
sBillNOGO = getUrlParam('BillNO'),
sCheckId = sDataId,
sOrganizers = [],
sSelectedOrganizers = [],
MaxOrganizerCount = $(".Organizer").length + 1,//organizer count
fnPageInit = function () {
var FeeItemCurrency = "TE,TG".indexOf(parent.UserInfo.OrgID) > -1 ? 'NTD' : 'RMB';
var oGrid = null,
oForm = $('#form_main'),
oValidator = null,
sServiceCode = '',
sDeptCode = '',
sCustomersOptionsHtml = '',
sCustomersNotAuditOptionsHtml = '',
sCurrencyOptionsHtml = '',
sAccountingCurrencyOptionsHtml = '',
sTransportOptionsHtml = '',
oAddItem = {},
oCurSupplierData = {},
oPrintMenu = {},
oCurData = {},
saGridData = [],
saCustomers = [],
saBatchArr = [],
saPort = [],
saCurrency = [],
saFeeClass = [],
saAccountingCurrency = [],
nowResponsiblePerson = '',
/**
* 獲取資料
* @return {Object} ajax物件
*/
fnGet = function () {
if (sDataId) {
return g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
{
Guid: sDataId
},
function (res) {
if (res.RESULT) {
var oRes = res.DATA.rel;
$('#VoidReason').text(oRes.VoidReason);
if (oRes.Organizer.indexOf("]") === -1)
oRes.Organizer = '["' + oRes.Organizer + '"]';
sOrganizers = $.parseJSON(oRes.Organizer);
if (oRes.IsVoid === 'Y') {
$('.voidreason').show();
$('#Toolbar_Void').attr({ 'id': 'Toolbar_OpenVoid', 'data-i18n': 'common.Toolbar_OpenVoid' });
}
else {
$('.voidreason').hide();
$('#Toolbar_OpenVoid').attr({ 'id': 'Toolbar_Void', 'data-i18n': 'common.Toolbar_Void' });
}
transLang($('#Toolbar'));
}
});
}
else {
oCurData.Quote = { guid: guid(), KeyName: 'Quote', AuditVal: '0', FeeItems: [] };
oCurData.EstimatedCost = { guid: guid(), KeyName: 'EstimatedCost', AuditVal: '0', FeeItems: [] };
oCurData.ActualCost = { guid: guid(), KeyName: 'ActualCost', AuditVal: '0', FeeItems: [] };
oCurData.Bills = [];
oCurData.ReturnBills = [];
$('#AgentContactor').html(createOptions([]));
fnSetPermissions();
return $.Deferred().resolve().promise();
}
},
/**
* 新增或修改完之后重新查询资料
*/
fnReSet = function () {
fnGet().done(function (res) {
var oRes = res.DATA.rel;
$('#VoidReason').text(oRes.VoidReason);
if (oRes.VoidReason) { $('.voidreason').show(); } else { $('.voidreason').hide(); }
getPageVal(); //緩存頁面值,用於清除
});
},
/**
* 獲取貨物狀態
* @param {Object} data 當前流程對象
* @return {String} 當前流程名稱
*/
fnGetFlowStatus = function (data) {
var sFlowStatus = '';
if (data.ReturnType !== '') {
sFlowStatus = '退運';
}
else if (data.ClearanceData.ServiceBooth.Checked) {
sFlowStatus = '送達攤位';
}
else if (data.ClearanceData.WaitingApproach.Checked) {
sFlowStatus = '等待進場';
}
else if (data.ClearanceData.CargoRelease.Checked) {
sFlowStatus = '貨物放行';
}
else if (data.ClearanceData.GoodsArrival.Checked) {
sFlowStatus = '貨物抵港';
}
else if (data.ExportData.ExportRelease.Checked) {
sFlowStatus = '出口放行';
}
else if (data.ExportData.CustomsDeclaration.Checked) {
sFlowStatus = '報關作業';
}
else if (data.ExportData.Intowarehouse.Checked) {
sFlowStatus = '貨物進倉';
}
else if (data.ExportData.ReceiveFile.Checked) {
sFlowStatus = '已收文件';
}
return sFlowStatus;
},
/**
* 新增資料
* @param {String} flag 新增或儲存後新增
* @return {Object} ajax物件
*/
fnAdd = function (flag) {
var data = getFormSerialize(oForm),
fnGetAdd = function () {
data.Exhibitors = JSON.stringify(saGridData);
data.Organizer = JSON.stringify(sOrganizers);
CallAjax(ComFn.W_Com, ComFn.GetAdd, {
Params: { exportexhibition: data }
}, function (res) {
if (res.d > 0) {
bRequestStorage = false;
if (flag === 'add') {
showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Upd&ExportBillNO=' + sDataId); // ╠message.Save_Success⇒新增成功╣
}
else {
showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Add'); // ╠message.Save_Success⇒新增成功╣
}
}
else {
showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
}
}, function () {
showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
});
};
data = packParams(data);
data.OrgID = parent.OrgID;
data.IsVoid = 'N';
data.DepartmentID = sDeptCode;
data.Flow_Status = oCurData.Flow_Status || '';
data.Quote = oCurData.Quote || {};
data.Quote.AuditVal = oCurData.Quote.AuditVal || '0';
data.Quote.FeeItems = oCurData.Quote.FeeItems || [];
data.EstimatedCost = oCurData.EstimatedCost || {};
data.EstimatedCost.AuditVal = oCurData.EstimatedCost.AuditVal || '0';
data.EstimatedCost.FeeItems = oCurData.EstimatedCost.FeeItems || [];
data.ActualCost = oCurData.ActualCost || {};
data.ActualCost.AuditVal = oCurData.ActualCost.AuditVal || '0';
data.ActualCost.FeeItems = oCurData.ActualCost.FeeItems || [];
data.Bills = oCurData.Bills || [];
data.ReturnBills = oCurData.ReturnBills || [];
data.Quote = JSON.stringify(data.Quote);
data.EstimatedCost = JSON.stringify(data.EstimatedCost);
data.ActualCost = JSON.stringify(data.ActualCost);
data.Bills = JSON.stringify(data.Bills);
data.ReturnBills = JSON.stringify(data.ReturnBills);
if (data.AgentContactor) {
data.AgentContactorName = $('#AgentContactor option:selected').text();
}
else {
data.AgentContactorName = '';
}
if (data.ExhibitionNO) {
data.ExportBillName = $('#ExhibitionNO option:selected').text();
}
else {
data.ExhibitionName = '';
}
if (!data.DocumentDeadline) delete data.DocumentDeadline;
if (!data.ClosingDate) delete data.ClosingDate;
if (!data.ETC) delete data.ETC;
if (!data.ETD) delete data.ETD;
if (!data.ETA) delete data.ETA;
if (!data.ReminderAgentExecutionDate) delete data.ReminderAgentExecutionDate;
if (!data.PreExhibitionDate) delete data.PreExhibitionDate;
if (!data.ExitDate) delete data.ExitDate;
if (!data.ExhibitionDateStart) delete data.ExhibitionDateStart;
if (!data.ExhibitionDateEnd) delete data.ExhibitionDateEnd;
data.ExportBillNO = sDataId = guid();
return g_api.ConnectLite(Service.com, ComFn.GetSerial, {
Type: 'C' + parent.UserInfo.OrgID + 'E',
Flag: 'MinYear',
Len: 3,
Str: sServiceCode,
AddType: sServiceCode,
PlusType: ''
}, function (res) {
if (res.RESULT) {
data.RefNumber = res.DATA.rel;
var bRelease = true,
sSuppliers = '',
saPost = [];
$.each(saGridData, function (idx, item) {
item.RefSupplierNo = data.RefNumber + rndnum(3);
if (!item.VoidContent) {
if (bRelease && !item.VoidContent && (item.ExportData && !item.ExportData.ExportRelease.Checked) || !item.ExportData) {
bRelease = false;
}
}
sSuppliers += item.SupplierName + '|';
});
data.Suppliers = sSuppliers;
data.Release = saGridData.length > 0 ? (bRelease ? 'Y' : 'N') : 'N';
fnGetAdd();
}
else {
showMsg(i18next.t("message.Save_Failed") + '
' + res.MSG, 'error');// ╠message.Save_Failed⇒新增失敗╣
}
}, function () {
showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
});
},
/**
* 修改資料
*/
fnUpd = function () {
var data = getFormSerialize(oForm),
bRelease = true,
sSuppliers = '';
data = packParams(data, 'upd');
data.Organizer = JSON.stringify(sOrganizers);
$.each(saGridData, function (idx, item) {
if (!item.VoidContent) {
if (bRelease && (item.ExportData && !item.ExportData.ExportRelease.Checked) || !item.ExportData) {
bRelease = false;
}
}
sSuppliers += item.SupplierName + '|';
});
data.Suppliers = sSuppliers;
data.Release = saGridData.length > 0 ? (bRelease ? 'Y' : 'N') : 'N';
data.IsVoid = oCurData.IsVoid;
data.Flow_Status = oCurData.Flow_Status || '';
data.Quote = oCurData.Quote || {};
data.Quote.AuditVal = oCurData.Quote.AuditVal || '0';
data.Quote.FeeItems = oCurData.Quote.FeeItems || [];
data.EstimatedCost = oCurData.EstimatedCost || {};
data.EstimatedCost.AuditVal = oCurData.EstimatedCost.AuditVal || '0';
data.EstimatedCost.FeeItems = oCurData.EstimatedCost.FeeItems || [];
data.ActualCost = oCurData.ActualCost || {};
data.ActualCost.AuditVal = oCurData.ActualCost.AuditVal || '0';
data.ActualCost.FeeItems = oCurData.ActualCost.FeeItems || [];
data.Bills = oCurData.Bills || [];
data.ReturnBills = oCurData.ReturnBills || [];
data.Quote = JSON.stringify(data.Quote);
data.EstimatedCost = JSON.stringify(data.EstimatedCost);
data.ActualCost = JSON.stringify(data.ActualCost);
data.Bills = JSON.stringify(data.Bills);
data.ReturnBills = JSON.stringify(data.ReturnBills);
data.Exhibitors = JSON.stringify(saGridData);
if (data.AgentContactor) {
data.AgentContactorName = $('#AgentContactor option:selected').text();
}
else {
data.AgentContactorName = '';
}
if (data.ExhibitionNO) {
data.ExportBillName = $('#ExhibitionNO option:selected').text();
}
else {
data.ExhibitionName = '';
}
delete data.ExportBillNO;
if (!data.DocumentDeadline) delete data.DocumentDeadline;
if (!data.ClosingDate) delete data.ClosingDate;
if (!data.ETC) delete data.ETC;
if (!data.ETD) delete data.ETD;
if (!data.ETA) delete data.ETA;
if (!data.ReminderAgentExecutionDate) delete data.ReminderAgentExecutionDate;
if (!data.PreExhibitionDate) delete data.PreExhibitionDate;
if (!data.ExitDate) delete data.ExitDate;
if (!data.ExhibitionDateStart) delete data.ExhibitionDateStart;
if (!data.ExhibitionDateEnd) delete data.ExhibitionDateEnd;
CallAjax(ComFn.W_Com, ComFn.GetUpd, {
Params: {
exportexhibition: {
values: data,
keys: { ExportBillNO: sDataId }
}
}
}, function (res) {
if (res.d > 0) {
bRequestStorage = false;
showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
if (window.bLeavePage) {
setTimeout(function () {
pageLeave();
}, 1000);
}
fnUpdateBillInfo(sProgramId, sDataId);
oCurData.ResponsiblePerson = data.ResponsiblePerson;
}
else {
showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
nowResponsiblePerson = oCurData.ResponsiblePerson;
}
}, function () {
showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
nowResponsiblePerson = oCurData.ResponsiblePerson;
});
},
/**
* 資料刪除
*/
fnDel = function () {
CallAjax(ComFn.W_Com, ComFn.GetDel, {
Params: {
exportexhibition: {
ExportBillNO: sDataId
}
}
}, function (res) {
if (res.d > 0) {
showMsgAndGo(i18next.t("message.Delete_Success"), sQueryPrgId); // ╠message.Delete_Success⇒刪除成功╣
}
else {
showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
}
}, function () {
showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
});
},
/**
* 資料作廢
*/
fnVoid = function () {
layer.open({
type: 1,
title: i18next.t('common.Toolbar_Void'),// ╠common.Toolbar_Void⇒作廢╣
shade: 0.75,
maxmin: true, //开启最大化最小化按钮
area: ['500px', '250px'],
content: '
\
\
',
btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
success: function (layero, index) {
},
yes: function (index, layero) {
var data = {
IsVoid: 'Y',
VoidReason: $('#VoidContent').val()
};
if (!$('#VoidContent').val()) {
showMsg(i18next.t("message.VoidReason_Required")); // ╠message.VoidReason_Required⇒請填寫作廢原因╣
return false;
}
CallAjax(ComFn.W_Com, ComFn.GetUpd, {
Params: {
exportexhibition: {
values: data,
keys: { ExportBillNO: sDataId }
}
}
}, function (res) {
if (res.d > 0) {
oCurData.IsVoid = 'Y';
showMsg(i18next.t("message.Void_Success"), 'success'); // ╠message.Void_Success⇒作廢成功╣
fnReSet();
}
else {
showMsg(i18next.t('message.Void_Failed'), 'error'); // ╠message.Void_Failed⇒作廢失敗╣
}
});
layer.close(index);
}
});
},
/**
* 資料啟用
*/
fnOpenVoid = function () {
var data = {
IsVoid: 'N',
VoidReason: ''
};
CallAjax(ComFn.W_Com, ComFn.GetUpd, {
Params: {
exportexhibition: {
values: data,
keys: { ExportBillNO: sDataId }
}
}
}, function (res) {
if (res.d > 0) {
oCurData.IsVoid = 'N';
showMsg(i18next.t("message.OpenVoid_Success"), 'success'); // ╠message.OpenVoid_Success⇒啟用成功╣
fnReSet();
}
else {
showMsg(i18next.t("message.OpenVoid_Failed"), 'error'); // ╠message.OpenVoid_Failed⇒啟用失敗╣
}
}, function () {
showMsg(i18next.t("message.OpenVoid_Failed"), 'error'); // ╠message.OpenVoid_Failed⇒啟用失敗╣
});
},
/**
* 打開要匯出的pop選擇匯出類別
*/
fnOpenPopToExcel = function () {
layer.open({
type: 1,
title: i18next.t('common.DownLoadDocuments'),// ╠common.DownLoadDocuments⇒下載文檔╣
area: ['200px', '160px'],//寬度
shade: 0.75,//遮罩
shadeClose: true,
btn: [i18next.t('common.Cancel')],// ╠common.Cancel⇒取消╣
content: '\
\
',// ╠common.BusinessTrackingSchedule⇒請立即安排付款╣
success: function (layero, idx) {
$('.pop-box :button').click(function () {
var sToExcelType = this.id;
fnExcel({
pageIndex: 1,
pageSize: 100000,
ToExcelType: sToExcelType
}, idx);
});
transLang(layero);
}
});
},
/**
* 匯入資料
*/
fnImport = function () {
var oConfig = {
Get: fnGetPopData_ImportData,
SearchFields: [
{ id: "Pop_RefNumber", type: 'text', i18nkey: 'ExhibitionExport_Upd.RefNumber' },
{ id: "Pop_ExportBillName", type: 'text', i18nkey: 'ExhibitionExport_Upd.ExportBillName' },
{ id: "Pop_ExportBillEName", type: 'text', i18nkey: 'ExhibitionExport_Upd.ExportBillEName' },
{ id: "Pop_Agent", type: 'text', i18nkey: 'ExhibitionExport_Upd.Agent' }
],
Fields: [
{ name: "RowIndex", title: 'common.RowNumber', sorting: false, align: 'center', width: 50 },
{ name: "RefNumber", title: 'ExhibitionExport_Upd.RefNumber', width: 100 },
{ name: "ExportBillName", title: 'ExhibitionExport_Upd.ExportBillName', width: 200 },
{ name: "ExportBillEName", title: 'ExhibitionExport_Upd.ExportBillEName', width: 200 },
{ name: "AgentName", title: 'ExhibitionExport_Upd.Agent', width: 200 }
],
Callback: function (item) {
var oData = {};
oData.ResponsiblePerson = item.ResponsiblePerson;
oData.ExhibitionNO = item.ExhibitionNO;
oData.ExportBillName = item.ExportBillName;
oData.ExportBillEName = item.ExportBillEName;
oData.ExhibitionDateStart = item.ExhibitionDateStart;
oData.ExhibitionDateEnd = item.ExhibitionDateEnd;
oData.Organizer = item.Organizer;
oData.Agent = item.Agent;
oData.AgentContactor = item.AgentContactor;
oData.AgentTelephone = item.AgentTelephone;
oData.AgentEamil = item.AgentEamil;
setFormVal(oForm, oData);
if (oData.Agent) {
var oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === oData.Agent; }).First(),
saContactors = JSON.parse(oCur.Contactors || '[]');
$('#AgentContactor').html(createOptions(saContactors, 'guid', 'FullName')).val(oData.AgentContactor);
}
else {
$('#AgentContactor').html(createOptions([]));
}
$('#ExhibitionDateStart').val(newDate(oData.ExhibitionDateStart, 'date', true));
$('#ExhibitionDateEnd').val(newDate(oData.ExhibitionDateEnd, 'date', true));
}
};
oPenPops(oConfig);
},
/**
* 獲取展覽名稱資料
* @param {Object} args 查詢參數
* @return {Object} ajax
*/
fnGetPopData_ImportData = function (args) {
args = args || {};
args.sortField = args.sortField || 'RefNumber';
args.sortOrder = args.sortOrder || 'desc';
args.pageIndex = args.pageIndex || 1;
args.pageSize = args.pageSize || 10;
args.RefNumber = $('#Pop_RefNumber').val();
args.ExportBillName = $('#Pop_ExportBillName').val();
args.ExportBillEName = $('#Pop_ExportBillEName').val();
args.Agent = $('#Pop_Agent').val();
return g_api.ConnectLite(sQueryPrgId, 'GetExcel', args);
},
/**
* 流程修改發送郵件
* @param {String} itemname 第幾個流程
* @param {Function} callback 回調函數
* @return {Boolean} 是否停止
*/
fnSendEmail = function (itemname, callback) {
if (parent.SysSet.IsOpenMail !== 'Y') {
layer.alert(i18next.t('message.NotOpenMail'), { icon: 0 }, function () {// ╠message.NotOpenMail⇒系統沒有開放郵件發送功能,請聯絡管理員!╣
callback();
});
return false;
}
CallAjax(ComFn.W_Com, ComFn.SendMail, {
Params: {
FromOrgID: parent.OrgID,
FromUserID: parent.UserID,
EmailTo: [{
ToUserID: $('#ResponsiblePerson').val(),
Type: 'to'
}],
MailTempId: 'FlowChange',
MailData: {
RefNumber: $('#RefNumber').val(),
ExhibitionType: '出口',
DataDources: '出口管理',
ChangeItem: itemname,
SupplierName: oCurSupplierData.SupplierName,
ModifyUser: parent.UserInfo.MemberName,
ModifyDate: newDate(null, 'date')
}
}
}, function (res) {
if (res.d === '1') {
callback();
showMsg(i18next.t("message.SendEmail_Success"), 'success'); // ╠message.SendEmail_Success⇒郵件寄送成功╣
}
else {
showMsg(i18next.t("message.SendEmail_Failed"), 'error'); // ╠message.SendEmail_Failed⇒郵件寄送失敗╣
}
}, function () {
showMsg(i18next.t("message.SendEmail_Failed"), 'error'); // ╠message.SendEmail_Failed⇒郵件寄送失敗╣
});
},
/**
* 發送Tracking number給客戶格式
* @param {Object} data 單筆廠商資料
* @return {Boolean} 是否停止
*/
fnSendTrackingNumberEmail = function (data) {
var sMsg = '';
if (parent.SysSet.IsOpenMail !== 'Y') {
showMsg(i18next.t("message.NotOpenMail"));// ╠message.NotOpenMail⇒系統沒有開放郵件發送功能,請聯絡管理員!╣
return false;
}
if (!data.Email) {
sMsg += i18next.t("ExhibitionExport_Upd.SupplierEamil_required") + '
'; // ╠ExhibitionImport_Upd.SupplierEamil_required⇒請輸入付款人╣
}
if (!$('#ShipmentPort').val()) {
sMsg += i18next.t("common.ShipmentPort_required") + '
'; // ╠common.ShipmentPort_required⇒請輸入起運地╣
}
if (!$('#Destination').val()) {
sMsg += i18next.t("common.DestinationPort_required") + '
'; // ╠common.DestinationPort_required⇒請輸入目的地╣
}
if (!(data.ExportData !== undefined && data.ExportData.Intowarehouse !== undefined ? data.ExportData.Intowarehouse.Number : '')) {
sMsg += i18next.t("message.Number_required") + '
'; // ╠message.Number_required⇒請輸入件數╣
}
if (!(data.ExportData !== undefined && data.ExportData.Intowarehouse !== undefined ? data.ExportData.Intowarehouse.Unit : '')) {
sMsg += i18next.t("message.Unit_required"); // ╠message.Unit_required⇒ 請輸入(件數)單位╣
}
if (sMsg) {
showMsg(sMsg);
return false;
}
var toSendMail = function (flag) {
CallAjax(ComFn.W_Com, ComFn.SendMail, {
Params: {
FromOrgID: parent.OrgID,
FromUserName: parent.SysSet.FromName || '系統郵件',
EmailTo: [{
ToUserName: data.SupplierName,
ToEmail: data.Email,
Type: 'to'
}],
MailTempId: 'TrackingNumberNotice',
MailData: {
RefNumber: data.RefSupplierNo,
BillLadNOType: 'none',
ExhibitionName: oCurData.Exhibitioname_TW || '',
ExhibitionEName: oCurData.Exhibitioname_EN || '',
Shipment: $('#ShipmentPortCode').val(),
Destination: $('#DestinationCode').val(),
Number: data.ExportData !== undefined && data.ExportData.Intowarehouse !== undefined ? (data.ExportData.Intowarehouse.Number + ' ' + data.ExportData.Intowarehouse.Unit) : ''
}
}
}, function (res) {
if (res.d === '1') {
showMsg(i18next.t("message.SendEmail_Success"), 'success'); // ╠message.SendEmail_Success⇒郵件寄送成功╣
if (flag) {
var sIsSendMail = oCurData.IsSendMail + ',' + data.guid;
CallAjax(ComFn.W_Com, ComFn.GetUpd, {
Params: {
exportexhibition: {
values: { IsSendMail: sIsSendMail },
keys: { ExportBillNO: sDataId }
}
}
}, function (res1) {
if (res1.d > 0) {
oCurData.IsSendMail = sIsSendMail;
$('.' + data.guid).removeClass('a-url').addClass('a-mailurl');
}
});
}
}
else {
showMsg(i18next.t("message.SendEmail_Failed"), 'error'); // ╠message.SendEmail_Failed⇒郵件寄送失敗╣
}
}, function () {
showMsg(i18next.t("message.SendEmail_Failed"), 'error'); // ╠message.SendEmail_Failed⇒郵件寄送失敗╣
});
};
if (isEmail(data.Email)) {
if ((oCurData.IsSendMail || '').indexOf(data.guid) === -1) {
toSendMail(true);
}
else {
// ╠message.IsSendTrackingNumberEmail⇒已寄送过,是否再次寄送?╣ ╠common.Tips⇒提示╣
layer.confirm(i18next.t('message.IsSendTrackingNumberEmail'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
toSendMail(false);
layer.close(index);
});
}
}
else {
showMsg(i18next.t("message.IncorrectEmail"), 'error'); // ╠message.IncorrectEmail⇒郵箱格式不正確╣
}
},
/**
* 批次發送Tracking number給客戶格式
*/
fnBatchMail = function () {
var toSendMail = function (data, name) {
return CallAjax(ComFn.W_Com, ComFn.SendMail, {
Params: {
FromOrgID: parent.OrgID,
FromUserName: parent.SysSet.FromName || '系統郵件',
EmailTo: [{
ToUserName: data.SupplierName,
ToEmail: data.Email,
Type: 'to'
}],
MailTempId: 'TrackingNumberNotice',
MailData: {
RefNumber: data.RefSupplierNo,
BillLadNOType: 'none',
ExhibitionName: oCurData.Exhibitioname_TW || '',
ExhibitionEName: oCurData.Exhibitioname_EN || '',
Shipment: $('#ShipmentPortCode').val(),
Destination: $('#DestinationCode').val(),
Number: data.ExportData !== undefined && data.ExportData.Intowarehouse !== undefined ? (data.ExportData.Intowarehouse.Number + ' ' + data.ExportData.Intowarehouse.Unit) : ''
}
}
}, function (res) {
if (res.d === '1') {
$('.' + data.guid).removeClass('a-url').addClass('a-mailurl');
showMsg(name + i18next.t("message.SendEmail_Success"), 'success'); // ╠message.SendEmail_Success⇒郵件寄送成功╣
}
else {
showMsg(name + i18next.t("message.SendEmail_Failed"), 'error'); // ╠message.SendEmail_Failed⇒郵件寄送失敗╣
}
}, function () {
showMsg(name + i18next.t("message.SendEmail_Failed"), 'error'); // ╠message.SendEmail_Failed⇒郵件寄送失敗╣
});
},
fnGetData = function () {
var d = $.Deferred(),
saList = [],
iIndex = 1,
sName = $('#Pop_SupplierName').val(),
sEName = $('#Pop_SupplierEName').val();
$.each(saGridData, function (idx, item) {
if ((((item.SupplierName || '').indexOf(sName) > -1 || sName === '')
&& ((item.SupplierEName || '').indexOf(sEName) > -1 || sEName === ''))) {
saList.push({
RowIndex: iIndex,
guid: item.guid,
SupplierID: item.SupplierID,
CustomerNO: item.CustomerNO,
UniCode: item.UniCode,
Email: item.Email,
RefSupplierNo: item.RefSupplierNo,
ExportData: item.ExportData,
SupplierName: item.SupplierName || '',
SupplierEName: item.SupplierEName || ''
});
iIndex++;
}
});
d.resolve({
data: saList,
itemsCount: saList.length
});
return d.promise();
},
oConfig = {
Id: 'PopIsBatch',
Title: i18next.t('common.SelectBatchList'),// ╠common.SelectBatchList⇒請選擇要批次操作的資料╣
PageSize: 10000,
Get: fnGetData,
SearchFields: [
{ id: "Pop_SupplierName", type: 'text', i18nkey: 'common.SupplierCName' },
{ id: "Pop_SupplierEName", type: 'text', i18nkey: 'common.SupplierEName' }
],
Fields: [
{ name: "RowIndex", title: 'common.RowNumber', sorting: false, align: 'center', width: 50 },// ╠common.RowNumber⇒項次╣
{ name: "CustomerNO", title: 'Customers_Upd.CustomerNO', width: 80 },
{ name: "SupplierName", title: 'common.SupplierCName', width: 150 },
{ name: "SupplierEName", title: 'common.SupplierEName', width: 150 }
],
Callback: function (items) {
var sMsg = '',
bEmail = true,
oPost = [],
sIsSendMail = '';
$.each(items, function (idx, item) {
if (!item.Email || !isEmail(item.Email)) {
sMsg = item.SupplierName === '' ? item.SupplierEName : item.SupplierName;
bEmail = false;
return false;
}
});
if (!bEmail) {
showMsg(sMsg + i18next.t("message.IncorrectEmail"), 'error'); // ╠message.IncorrectEmail⇒郵箱格式不正確╣
return false;
}
$.each(items, function (idx, item) {
var sSupplierName = item.SupplierName === '' ? item.SupplierEName : item.SupplierName;
if ((oCurData.IsSendMail || '').indexOf(item.guid) === -1) {
sIsSendMail += item.guid + ',';
oPost.push(toSendMail(item, sSupplierName));
}
else {
toSendMail(item, sSupplierName);
}
});
$.whenArray(oPost).done(function () {
sIsSendMail = oCurData.IsSendMail + ',' + sIsSendMail;
CallAjax(ComFn.W_Com, ComFn.GetUpd, {
Params: {
exportexhibition: {
values: { IsSendMail: sIsSendMail },
keys: { ExportBillNO: sDataId }
}
}
}, function (res) {
if (res.d > 0) {
oCurData.IsSendMail = sIsSendMail;
}
});
});
}
};
oPenPopm(oConfig);
},
/**
* 批次匯入廠商列表
*/
fnBatchImport = function () {
var fnGetData = function () {
var sId = $('#Pop_ExhibitionName').val(),
d = $.Deferred();
if (!sId) {
return;
}
g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
{
Guid: sId
},
function (res) {
if (res.RESULT) {
var oRes = res.DATA.rel;
if (oRes.ExportBillNO) {
var saExhibitors = $.parseJSON(oRes.Exhibitors),
saNewExhibitors = [];
$.each(saExhibitors, function (idx, supplier) {
var oNewExhibitor = {},
sRefSupplierNo = $('#RefNumber').val() + rndnum(3);
oNewExhibitor.RowIndex = idx + 1;
oNewExhibitor.guid = guid();
oNewExhibitor.SupplierID = supplier.SupplierID;
oNewExhibitor.CustomerNO = supplier.CustomerNO || '';
oNewExhibitor.UniCode = supplier.UniCode;
oNewExhibitor.SupplierName = supplier.SupplierName;
oNewExhibitor.SupplierEName = supplier.SupplierEName || '';
oNewExhibitor.RefSupplierNo = sRefSupplierNo;
oNewExhibitor.Contactor = supplier.Contactor || '';
oNewExhibitor.Telephone = supplier.Telephone || '';
oNewExhibitor.Email = supplier.Email || '';
oNewExhibitor.ContactorName = supplier.ContactorName || '';
oNewExhibitor.CreateUser = parent.UserID;
oNewExhibitor.CreateDate = new Date().formate("yyyy/MM/dd HH:mm:ss");
saNewExhibitors.push(oNewExhibitor);
});
d.resolve({
data: saNewExhibitors,
itemsCount: saNewExhibitors.length
});
}
}
});
return d.promise();
},
oConfig = {
Id: 'PopIsBatch',
Title: i18next.t('ExhibitionExport_Upd.SupplierBatchList'),// ╠ExhibitionExport_Upd.SupplierBatchList⇒批次匯入廠商╣
Width: '1000px',
PageSize: 10000,
Get: fnGetData,
SearchFields: [
{ id: "Pop_ExhibitionName", type: 'select', i18nkey: 'ExhibitionExport_Upd.ExportBillName' }
],
Fields: [
{ name: "RowIndex", title: 'common.RowNumber', sorting: false, align: 'center', width: 50 },
{ name: "SupplierName", title: 'common.SupplierName', width: 200 },
{ name: "SupplierEName", title: 'common.SupplierEName', width: 200 },
{ name: "ContactorName", title: 'common.Contactor', width: 100 },
{ name: "Telephone", title: 'common.Telephone', width: 100 },
{ name: "Email", title: 'common.Email', width: 150 }
],
Callback: function (items) {
saGridData = clone(items);
oGrid.loadData();
}
};
CallAjax(ComFn.W_Com, ComFn.GetList, {
Type: '', Params: {
exportexhibition: {
IsVoid: 'N',
OrgID: parent.OrgID
}
}
}, function (res) {
var saList = $.parseJSON(res.d);
oConfig.SearchFields[0].html = createOptions(saList, 'ExportBillNO', 'ExportBillName');
oConfig.ContentPlush = '';
oConfig.PopSuccessCallback = function (layero) {
setTimeout(function () {
$('#Pop_ExhibitionName').select2({ width: '240px' });
}, 100);
};
oPenPopm(oConfig);
});
},
/**
* 設定完成按鈕
* @param {Object} flow 父層dom對象
* @param {Boolean} bcomplete 是否完成
*/
setSuccessBtn = function (flow, bcomplete) {
var iCheckBox = flow.find(':input[type=checkbox]').length,
iChecked = flow.find(':input[type=checkbox]').not("input:checked").length;
if (iChecked === 0 && (iCheckBox !== iChecked || !bcomplete)) {
flow.find(':input.complete').removeAttr('disabled');
}
else {
flow.find(':input.complete').attr('disabled', true);
}
},
/**
* 設定完成按鈕
* @param {Object}that 父層dom對象
*/
setTime = function (checkbox) {
let sDate = newDate(null, true);
let divFormGroup = checkbox.parentNode.parentNode;
let FormGroupDate = divFormGroup.querySelector('.date-picker');
if (checkbox.checked) {
switch (checkbox.id) {
case 'ExportData_InTransit1_Checked':
//運輸中
let DesPortCode = document.querySelector('#DestinationCode'); //目的地
let InTransitETA = divFormGroup.querySelector('#ExportData_InTransit1_ETA'); //運送中-ETA
InTransitETA.value = DesPortCode.value;
break;
}
FormGroupDate.value = sDate;
}
else {
FormGroupDate.value = '';
switch (checkbox.id) {
case 'ExportData_InTransit1_Checked':
//運輸中
let InTransitETA = document.querySelector('#ExportData_InTransit1_ETA'); //運送中-ETA
let IntransitDate = divFormGroup.querySelector('#ExportData_InTransit1_ETADate'); //運輸中-日期
InTransitETA.value = '';
IntransitDate.value = '';
break;
}
}
},
/**
* 設定流程頁簽
* @param {Object}form 表單
* @param {Object} oData 資料json
*/
setFlowBox = function (form, oData) {
if (oData.ExportData) {
if (oData.ExportData.complete) {
form.find('#ExportData').find('[name]').attr('disabled', true);
form.find('#ExportData').find(':input.complete').attr('disabled', true);
}
else {
setSuccessBtn(form.find('#ExportData'), false);
}
if (oData.ReturnType === 'H') {
form.find('#ReImport').show();
form.find('.addreturns').attr('disabled', true);
}
else if (oData.ReturnType === 'T') {
form.find('#TranserThird').show();
form.find('.addreturns').attr('disabled', true);
}
else if (oData.ReturnType === 'P') {
form.find('#PartThirdAndReImport').show();
form.find('.addreturns').attr('disabled', true);
}
form.find('#ExportData').find(':input.undo').removeAttr('disabled').click(function () {
var fnCallBack = function () {
//form.find('#ExportData').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
form.find('#ExportData').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
form.find('#ExportData').find(':input.undo').attr('disabled', true);
form.find('#ExportData').find(':input[type=hidden]').val('');
};
// ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
fnSendEmail(i18next.t("ExhibitionExport_Upd.ExportData"), fnCallBack);
layer.close(index);
}, function () {
fnCallBack();
});
});
} else {
setSuccessBtn(form.find('#ExportData'));
}
if (oData.ReImport) {
if (oData.ReImport.complete) {
form.find('#ReImport').find('[name]').attr('disabled', true);
form.find('#ReImport').find(':input.complete').attr('disabled', true);
}
else {
setSuccessBtn(form.find('#ReImport'), false);
}
form.find('#ReImport').find(':input.undo').removeAttr('disabled').click(function () {
var fnCallBack = function () {
//form.find('#ReImport').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
form.find('#ReImport').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
form.find('#ReImport').find(':input.undo').attr('disabled', true);
form.find('#ReImport').find(':input[type=hidden]').val('');
};
// ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
fnSendEmail(i18next.t("ExhibitionExport_Upd.ReImport"), fnCallBack);
layer.close(index);
}, function () {
fnCallBack();
});
});
} else {
setSuccessBtn(form.find('#ReImport'));
}
if (oData.TranserThird) {
if (oData.TranserThird.complete) {
form.find('#TranserThird').find('[name]').attr('disabled', true);
form.find('#TranserThird').find(':input.complete').attr('disabled', true);
}
else {
setSuccessBtn(form.find('#TranserThird'), false);
}
if (oData.LastReturnType === 'F') {
form.find('#TransferFour').show();
form.find('#TranserThird').find('.addnextreturn').attr('disabled', true);
}
else if (oData.LastReturnType === 'H') {
form.find('#ReImportFour').show();
form.find('.addnextreturn').attr('disabled', true);
}
form.find('#TranserThird').find(':input.undo').removeAttr('disabled').click(function () {
var fnCallBack = function () {
//form.find('#TranserThird').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
form.find('#TranserThird').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
form.find('#TranserThird').find(':input.undo').attr('disabled', true);
form.find('#TranserThird').find(':input[type=hidden]').val('');
};
// ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
fnSendEmail(i18next.t("ExhibitionExport_Upd.TranserThird"), fnCallBack);
layer.close(index);
}, function () {
fnCallBack();
});
});
if (oData.TransferFour) {
if (oData.TransferFour.complete) {
form.find('#TransferFour').find('[name]').attr('disabled', true);
form.find('#TransferFour').find(':input.complete').attr('disabled', true);
}
else {
setSuccessBtn(form.find('#TransferFour'), false);
}
if (oData.ReturnType_4 === 'F') {
form.find('#TransferFive').show();
form.find('#TransferFour').find('.addnextreturn').attr('disabled', true);
}
else if (oData.ReturnType_4 === 'H') {
form.find('#ReImportFive').show();
form.find('#TransferFour').find('.addnextreturn').attr('disabled', true);
}
form.find('#TransferFour').find(':input.undo').removeAttr('disabled').click(function () {
var fnCallBack = function () {
//form.find('#TransferFour').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
form.find('#TransferFour').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
form.find('#TransferFour').find(':input.undo').attr('disabled', true);
form.find('#TransferFour').find(':input[type=hidden]').val('');
};
// ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
fnSendEmail(i18next.t("ExhibitionExport_Upd.TransferFourPlace"), fnCallBack);
layer.close(index);
}, function () {
fnCallBack();
});
});
} else {
setSuccessBtn(form.find('#TransferFour'));
}
if (oData.ReImportFour) {
if (oData.ReImportFour.complete) {
form.find('#ReImportFour').find('[name]').attr('disabled', true);
form.find('#ReImportFour').find(':input.complete').attr('disabled', true);
}
else {
setSuccessBtn(form.find('#ReImportFour'), false);
}
form.find('#ReImportFour').find(':input.undo').removeAttr('disabled').click(function () {
var fnCallBack = function () {
//form.find('#ReImportFour').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
form.find('#ReImportFour').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
form.find('#ReImportFour').find(':input.undo').attr('disabled', true);
form.find('#ReImportFour').find(':input[type=hidden]').val('');
};
// ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
fnSendEmail(i18next.t("ExhibitionExport_Upd.ReImport"), fnCallBack);
layer.close(index);
}, function () {
fnCallBack();
});
});
} else {
setSuccessBtn(form.find('#ReImportFour'));
}
if (oData.TransferFive) {
if (oData.TransferFive.complete) {
form.find('#TransferFive').find('[name]').attr('disabled', true);
form.find('#TransferFive').find(':input.complete').attr('disabled', true);
}
else {
setSuccessBtn(form.find('#TransferFive'), false);
}
if (oData.ReturnType_5 === 'F') {
form.find('#TransferSix').show();
form.find('#TransferFive').find('.addnextreturn').attr('disabled', true);
}
else if (oData.ReturnType_5 === 'H') {
form.find('#ReImportSix').show();
form.find('#TransferFive').find('.addnextreturn').attr('disabled', true);
}
form.find('#TransferFive').find(':input.undo').removeAttr('disabled').click(function () {
var fnCallBack = function () {
form.find('#TransferFive').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
form.find('#TransferFive').find(':input.undo').attr('disabled', true);
form.find('#TransferFive').find(':input[type=hidden]').val('');
};
// ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
fnSendEmail(i18next.t("ExhibitionExport_Upd.TransferFivePlace"), fnCallBack);
layer.close(index);
}, function () {
fnCallBack();
});
});
} else {
setSuccessBtn(form.find('#TransferFive'));
}
if (oData.ReImportFive) {
if (oData.ReImportFive.complete) {
form.find('#ReImportFive').find('[name]').attr('disabled', true);
form.find('#ReImportFive').find(':input.complete').attr('disabled', true);
}
else {
setSuccessBtn(form.find('#ReImportFive'), false);
}
form.find('#ReImportFive').find(':input.undo').removeAttr('disabled').click(function () {
var fnCallBack = function () {
form.find('#ReImportFive').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
form.find('#ReImportFive').find(':input.undo').attr('disabled', true);
form.find('#ReImportFive').find(':input[type=hidden]').val('');
};
// ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
fnSendEmail(i18next.t("ExhibitionExport_Upd.ReImport"), fnCallBack);
layer.close(index);
}, function () {
fnCallBack();
});
});
} else {
setSuccessBtn(form.find('#ReImportFive'));
}
if (oData.TransferSix) {
if (oData.TransferSix.complete) {
form.find('#TransferSix').find('[name]').attr('disabled', true);
form.find('#TransferSix').find(':input.complete').attr('disabled', true);
}
else {
setSuccessBtn(form.find('#TransferSix'), false);
}
form.find('#TransferSix').find(':input.undo').removeAttr('disabled').click(function () {
var fnCallBack = function () {
form.find('#TransferSix').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
form.find('#TransferSix').find(':input.undo').attr('disabled', true);
form.find('#TransferSix').find(':input[type=hidden]').val('');
};
// ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
fnSendEmail(i18next.t("ExhibitionExport_Upd.TransferSixPlace"), fnCallBack);
layer.close(index);
}, function () {
fnCallBack();
});
});
} else {
setSuccessBtn(form.find('#TransferSix'));
}
if (oData.ReImportSix) {
if (oData.ReImportSix.complete) {
form.find('#ReImportSix').find('[name]').attr('disabled', true);
form.find('#ReImportSix').find(':input.complete').attr('disabled', true);
}
else {
setSuccessBtn(form.find('#ReImportSix'), false);
}
form.find('#ReImportSix').find(':input.undo').removeAttr('disabled').click(function () {
var fnCallBack = function () {
form.find('#ReImportSix').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
form.find('#ReImportSix').find(':input.undo').attr('disabled', true);
form.find('#ReImportSix').find(':input[type=hidden]').val('');
};
// ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
fnSendEmail(i18next.t("ExhibitionExport_Upd.ReImport"), fnCallBack);
layer.close(index);
}, function () {
fnCallBack();
});
});
} else {
setSuccessBtn(form.find('#ReImportSix'));
}
} else {
setSuccessBtn(form.find('#TranserThird'));
}
if (oData.PartThird) {
if (oData.PartThird.complete) {
form.find('#PartThird').find('[name]').attr('disabled', true);
form.find('#PartThird').find(':input.complete').attr('disabled', true);
}
else {
setSuccessBtn(form.find('#PartThird'), false);
}
form.find('#PartThird').find(':input.undo').removeAttr('disabled').click(function () {
var fnCallBack = function () {
//form.find('#PartThird').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
form.find('#PartThird').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
form.find('#PartThird').find(':input.undo').attr('disabled', true);
form.find('#PartThird').find(':input[type=hidden]').val('');
};
// ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
fnSendEmail(i18next.t("ExhibitionExport_Upd.ReturnedHomeAndThirdPlace"), fnCallBack);// ╠ExhibitionExport_Upd.ReturnedHomeAndThirdPlace⇒部份轉運其他地區;部份退運回台╣
layer.close(index);
}, function () {
fnCallBack();
});
});
} else {
setSuccessBtn(form.find('#PartThird'));
}
if (oData.PartReImport) {
if (oData.PartReImport.complete) {
form.find('#PartReImport').find('[name]').attr('disabled', true);
form.find('#PartReImport').find(':input.complete').attr('disabled', true);
}
else {
setSuccessBtn(form.find('#PartReImport'), false);
}
form.find('#PartReImport').find(':input.undo').removeAttr('disabled').click(function () {
var fnCallBack = function () {
//form.find('#PartReImport').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
form.find('#PartReImport').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
form.find('#PartReImport').find(':input.undo').attr('disabled', true);
form.find('#PartReImport').find(':input[type=hidden]').val('');
};
// ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
fnSendEmail(i18next.t("ExhibitionExport_Upd.ReturnedHomeAndThirdPlace"), fnCallBack);// ╠ExhibitionExport_Upd.ReturnedHomeAndThirdPlace⇒部份轉運其他地區;部份退運回台╣
layer.close(index);
}, function () {
fnCallBack();
});
});
} else {
setSuccessBtn(form.find('#PartReImport'));
}
form.find('.complete').click(function () {
var oBtn = this,
sId = $(oBtn).parents('.flow').attr('id'),
data = getFormSerialize(form);
data[sId].complete = 'Y';
form.find('#' + sId + '_complete').val('Y');
form.find(oBtn).attr('disabled', true);
form.find('#' + sId).find('[name]').attr('disabled', true);
if ($(oBtn).parents('.flow').next('.flow').length > 0) {
$(oBtn).parents('.flow').find('.addreturns,.addnextreturn').removeAttr('disabled');
}
});
form.find('.addreturns').click(function () {
layer.open({
type: 1,
title: i18next.t('common.ReturnType'),// ╠common.ReturnType⇒請選擇運送類型╣
area: ['500px', '120px'],//寬度
shade: 0.75,//遮罩
shadeClose: true,// ╠ExhibitionExport_Upd.ReturnedHome⇒退運回國╣ ╠ExhibitionExport_Upd.TransferThirdPlace⇒出貨至第三地╣ ╠ExhibitionExport_Upd.ReturnedHomeAndThirdPlace⇒部分運至第三地部分退運回國╣
content: '\
\
\
\
',
success: function (layero, idx) {
layero.find('#btn_ReturnedHome').click(function () {
form.find('#ReImport').show();
form.find('#TranserThird,#PartThirdAndReImport,#TransferFour,#ReImportFour').hide();
form.find('.addreturns').attr('disabled', true);
form.find('#ReturnType').val('H');
layer.close(idx);
});
layero.find('#btn_TransferThirdPlace').click(function () {
form.find('#TranserThird').show();
form.find('#ReImport,#PartThirdAndReImport,#TransferFour,#ReImportFour').hide();
form.find('.addreturns').attr('disabled', true);
form.find('#ReturnType').val('T');
layer.close(idx);
});
layero.find('#btn_ReturnedHomeAndThirdPlace').click(function () {
form.find('#PartThirdAndReImport').show();
form.find('#ReImport,#TranserThird,#TransferFour,#ReImportFour').hide();
form.find('.addreturns').attr('disabled', true);
form.find('#ReturnType').val('P');
layer.close(idx);
});
transLang(layero);
}
});
});
form.find('.addnextreturn').click(function () {
var iIndex = $(this).attr('data-index');
layer.open({
type: 1,
title: i18next.t('common.AddReimport'),// ╠common.AddReimport⇒增加退運╣
area: ['300px', '120px'],//寬度
shade: 0.75,//遮罩
shadeClose: true,// ╠common.ReturnedHome⇒退運回國╣ ╠common.TransferFourPlace⇒出貨至第四地╣ ╠common.TransferFivePlace⇒出貨至第五地╣ ╠common.TransferSixPlace⇒出貨至第六地╣
content: '\
\
\
',
success: function (layero, idx) {
layero.find('#btn_ReturnedHome').click(function () {
switch (iIndex) {
case '3':
form.find('#TransferFour').hide();
form.find('#ReImportFour').show();
form.find('#TranserThird').find('.addnextreturn').attr('disabled', true);
form.find('#LastReturnType').val('H');
break;
case '4':
form.find('#TransferFive').hide();
form.find('#ReImportFive').show();
form.find('#TransferFour').find('.addnextreturn').attr('disabled', true);
form.find('#ReturnType_4').val('H');
break;
case '5':
form.find('#TransferSix').hide();
form.find('#ReImportSix').show();
form.find('#TransferFive').find('.addnextreturn').attr('disabled', true);
form.find('#ReturnType_5').val('H');
break;
}
layer.close(idx);
});
layero.find('#btn_Transfer').click(function () {
switch (iIndex) {
case '3':
form.find('#TransferFour').show();
form.find('#ReImportFour').hide();
form.find('#TranserThird').find('.addnextreturn').attr('disabled', true);
form.find('#LastReturnType').val('F');
break;
case '4':
form.find('#TransferFive').show();
form.find('#ReImportFive').hide();
form.find('#TransferFour').find('.addnextreturn').attr('disabled', true);
form.find('#ReturnType_4').val('F');
break;
case '5':
form.find('#TransferSix').show();
form.find('#ReImportSix').hide();
form.find('#TransferFive').find('.addnextreturn').attr('disabled', true);
form.find('#ReturnType_5').val('F');
break;
}
layer.close(idx);
});
transLang(layero);
}
});
});
form.find(':input[type=checkbox]').not('#IsBatch').on('click', function (e) {
setTime(this);
setSuccessBtn($(this).parents('.flow'));
});
form.find(':input,select').on('change', function () {
bRequestStorage = true;
});
form.find('.ui-icon-close').on('click', function (e) {
var sFlowId = $(this).parents('.flow')[0].id;
switch (sFlowId) {
case 'ExportData':
$(this).parents('.form-group').remove();
break;
case 'PartThird':
form.find('#PartThirdAndReImport').hide();
form.find('.addreturns').removeAttr('disabled');
form.find('#ReturnType').val('');
break;
case 'TranserThird':
form.find('#TranserThird,#ReImportFour,#TransferFour,#ReImportFive,#TransferFive,#ReImportSix,#TransferSix').hide();
form.find('.addreturns').removeAttr('disabled');
form.find('#ReturnType').val('');
form.find('#LastReturnType').val('');
form.find('#ReturnType_4').val('');
form.find('#ReturnType_5').val('');
break;
case 'ReImport':
form.find('#ReImport').hide();
form.find('.addreturns').removeAttr('disabled');
form.find('#ReturnType').val('');
break;
case 'TransferFour':
form.find('#TransferFour,#ReImportFive,#TransferFive,#ReImportSix,#TransferSix').hide();
form.find('#TranserThird').find('.addnextreturn').removeAttr('disabled');
form.find('#LastReturnType').val('');
form.find('#ReturnType_4').val('');
form.find('#ReturnType_5').val('');
break;
case 'ReImportFour':
form.find('#ReImportFour').hide();
form.find('#TranserThird').find('.addnextreturn').removeAttr('disabled');
form.find('#LastReturnType').val('');
break;
case 'TransferFive':
form.find('#TransferFive,#ReImportSix,#TransferSix').hide();
form.find('#TransferFour').find('.addnextreturn').removeAttr('disabled');
form.find('#ReturnType_4').val('');
form.find('#ReturnType_5').val('');
break;
case 'ReImportFive':
form.find('#ReImportFive').hide();
form.find('#TransferFour').find('.addnextreturn').removeAttr('disabled');
form.find('#ReturnType_4').val('');
break;
case 'TransferSix':
form.find('#TransferSix').hide();
form.find('#TransferFive').find('.addnextreturn').removeAttr('disabled');
form.find('#ReturnType_5').val('');
break;
case 'ReImportSix':
form.find('#ReImportSix').hide();
form.find('#TransferFive').find('.addnextreturn').removeAttr('disabled');
form.find('#ReturnType_5').val('');
break;
}
});
},
/**
* 取得帳單log資料
* @return {Object}
*/
fnGetBillLogData = function (Bill) {
var LogData = {};
LogData.OrgID = parent.OrgID;
LogData.BillNO = Bill.BillNO;
LogData.ExhibitioName = oCurData.Exhibitioname_TW; //ExhibitioName
LogData.PayerName = '';
if (Bill.Payer) {
var PayerData = Enumerable.From(saCustomers).Where(function (e) { return e.id === Bill.Payer; }).First();
LogData.PayerName = PayerData.text;
}
LogData.ResponsiblePersonName = oCurData.ResponsiblePerson;
LogData.Currency = Bill.Currency;
LogData.ExchangeRate = Bill.ExchangeRate;
LogData.Advance = Bill.Advance;
LogData.AmountSum = Bill.AmountSum;
LogData.TaxSum = Bill.TaxSum;
LogData.AmountTaxSum = Bill.AmountTaxSum;
LogData.TotalReceivable = Bill.TotalReceivable;
LogData.OpmBillCreateUserName = oCurData.CreateUser;
LogData.ModifyUser = parent.UserID;
return LogData;
},
/**
* 設定客戶下拉選單
* @return {Object} ajax物件
*/
fnSetCustomersDrop = function () {
return g_api.ConnectLite(Service.sys, 'GetCustomerlist', {}, function (res) {
if (res.RESULT) {
saCustomers = res.DATA.rel;
var saContactors = []
if (saCustomers.length > 0) {
sCustomersOptionsHtml = createOptions(saCustomers, 'id', 'text');
$('#Agent').html(sCustomersOptionsHtml).on('change', function () {
var sAgent = this.value;
if (sAgent) {
var oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === sAgent; }).First();
saContactors = JSON.parse(oCur.Contactors || '[]');
$('#AgentContactor').html(createOptions(saContactors, 'guid', 'FullName')).off('change').on('change', function () {
var sContactor = this.value;
if (sContactor) {
var oContactor = Enumerable.From(saContactors).Where(function (e) { return e.guid === sContactor; }).First();
$('#AgentEamil').val(oContactor.Email);
$('#AgentTelephone').val(oContactor.TEL1);
}
else {
$('#AgentEamil').val('');
$('#AgentTelephone').val('');
}
bRequestStorage = true;
});
}
else {
$('#AgentContactor').html(createOptions([]));
}
});
$('#Organizer1,#Organizer2,#Organizer3,#Organizer4').html(sCustomersOptionsHtml);
var saNotAuditCurs = Enumerable.From(saCustomers).Where(function (e) { return e.IsAudit === 'Y'; }).ToArray();
sCustomersNotAuditOptionsHtml = createOptions(saNotAuditCurs, 'id', 'text');
}
select2Init();
$("#Organizer1,#Organizer2,#Organizer3,#Organizer4").select2();
$.each($("#Organizer1,#Organizer2,#Organizer3,#Organizer4"), function (idx, item) {
//組團單位-動態產生
let OrganizerIdex = idx + 1;
$("#Organizer" + OrganizerIdex).on('select2:select', function (e) {
var data = e.params.data;
sSelectedOrganizers[OrganizerIdex] = { id: data.id, text: data.text, title: data.title };
$('[data-id="BillOrganizer"]').html(createOptions(sSelectedOrganizers.filter(e => e != null), 'id', 'text'));
//加入到儲存資料內
sOrganizers = [];
$.each(sSelectedOrganizers, function (idx, e) {
if (e && e.id.length === 36)
sOrganizers.push(e.id);
})
});
})
//後端對應也要改
sSelectedOrganizers[MaxOrganizerCount] = { id: "SelfCome", text: "自來", title: "自來" };
}
});
},
/**
* 批次操作獲取廠商資料
* @return {Object} promise物件
*/
fnGetPop_CusSupplier = function () {
var saList = [],
iIndex = 1,
sSupplierName = $('#Pop_SupplierName').val(),
sSupplierEName = $('#Pop_SupplierEName').val(),
fnCheck = function (itemMatch) {
var bMatch = true;
if (!((itemMatch.LastReturnType || '') === (oCurSupplierData.LastReturnType || '') && (itemMatch.ReturnType || '') === (oCurSupplierData.ReturnType || ''))) {
bMatch = false;
}
return bMatch;
},
d = $.Deferred();
$.each(saGridData, function (idx, item) {
if ((((item.SupplierName || '').indexOf(sSupplierName) > -1 || sSupplierName === '')
&& ((item.SupplierEName || '').indexOf(sSupplierEName) > -1 || sSupplierEName === '') && fnCheck(item))) {
saList.push({
RowIndex: iIndex,
guid: item.guid,
SupplierID: item.SupplierID,
CustomerNO: item.CustomerNO,
UniCode: item.UniCode,
SupplierName: item.SupplierName || '',
SupplierEName: item.SupplierEName || ''
});
iIndex++;
}
});
d.resolve({
data: saList,
itemsCount: saList.length
});
return d.promise();
},
/*
* 取得當年度幣值設定
*/
fnGetCurrencyThisYear = function (BillCreateTime) {
return fnGetCurrencyByYear({
Year: BillCreateTime, CallBack: function (data) {
saAccountingCurrency = data;
sAccountingCurrencyOptionsHtml = createOptions(saAccountingCurrency, 'ArgumentID', 'ArgumentValue', false, 'Correlation');
}
});
},
/**------------------------帳單部分---------------------------Start*/
/**
* 審核通過後禁用頁面欄位
* @param {Object}dom 當前區塊
* @param {Object}data 當前資料
*/
fnSetDisabled = function (dom, data) {
if (data) {
if (data.BillNO) {
switch (data.AuditVal) {
case '0':// ╠common.NotAudit⇒未提交審核╣
dom.find('.status-font').text(i18next.t("common.NotAudit")).css('color', 'red');
break;
case '1':// ╠common.InAudit⇒提交審核中╣
dom.find('.status-font').text(i18next.t("common.InAudit")).css('color', 'blue');
break;
case '2':// ╠common.Audited⇒已審核╣
dom.find('.status-font').text(i18next.t("common.Audited")).css('color', 'green');
break;
case '3':// ╠common.NotPass⇒不通過╣
dom.find('.status-font').text(i18next.t("common.NotPass")).css('color', 'red');
break;
case '4':// ╠common.NotPass⇒已銷帳╣
dom.find('.status-font').text(i18next.t("common.HasBeenRealized")).css('color', 'red');
break;
case '5':// ╠common.HasBeenPost⇒已過帳╣
dom.find('.status-font').text(i18next.t("common.HasBeenPost")).css('color', 'green');
break;
case '6':// ╠common.HasVoid⇒已作廢╣
dom.find('.status-font').text(i18next.t("common.HasVoid")).css('color', '#b2b1b1');
break;
case '7':// ╠common.HasReEdit⇒抽單中╣
dom.find('.status-font').text(i18next.t("common.HasReEdit")).css('color', 'blue');
break;
}
}
dom.find('.bill-status-box').show();
dom.find('.notpass-reason-box').hide();
let DraftRecipt = false;
switch (data.AuditVal) {
case '0':// ╠common.NotAudit⇒未提交審核╣
dom.find('.bill-status').text(i18next.t("common.NotAudit")).css('color', 'red');
dom.find('.billpost,.cancelpost,.writeoff,.canceloff,.reedit,.cancelreedit').hide();
dom.find('.submittoaudit,.synquote,.alreadyaudit').show();
dom.find('.alreadyaudit,.cancelaudi,.cancelpost,.writeoff').attr('disabled', 'disabled');
if (parent.UserInfo.MemberID === oCurData.ResponsiblePerson || parent.UserInfo.MemberID === oCurData.CreateUser) {
if (data.FeeItems.length > 0) {
dom.find('.submittoaudit').removeAttr('disabled');
dom.parent().next().find('.synquote').removeAttr('disabled');
}
else {
dom.find('.submittoaudit').prop('disabled', true);
dom.parent().next().find('.synquote').prop('disabled', true);
}
}
else {
if (data.KeyName === 'Bill') {
dom.find(':input,textarea,.alreadyaudit,.cancelaudi,.cancelpost,.writeoff').attr('disabled', 'disabled');
dom.find('.icon-p').addClass('disabled');
}
}
if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
dom.find('.prepay,.mprepay,.billvoid').removeAttr('disabled');
}
else {
dom.find('.billvoid').hide();
}
if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
dom.find('.billdelete').removeAttr('disabled');
}
else {
dom.find('.billdelete').hide();
}
dom.find('.bills-print').removeAttr('disabled');//新增列印草稿
DraftRecipt = true;
break;
case '1':// ╠common.InAudit⇒提交審核中╣
dom.find('.bill-status').text(i18next.t("common.InAudit")).css('color', 'blue');
dom.find('.billpost,.cancelpost,.writeoff,.canceloff,.cancelaudi').hide();
dom.find('.submittoaudit,.synquote,.alreadyaudit,.reedit,.cancelreedit').show();
dom.find(':input,textarea,.plusfeeitem,.importfeeitem,.copyfeeitem,.plusfeeitemstar,select,.submittoaudit,.synquote,.billpost,.cancelaudi,.cancelpost,.writeoff').attr('disabled', 'disabled');
dom.find('.icon-p').addClass('disabled');
if (parent.UserInfo.MemberID === oCurData.ResponsiblePerson || parent.UserInfo.MemberID === oCurData.CreateUser) {
dom.find('.reedit').removeAttr('disabled');
}
if (parent.UserInfo.UsersDown.indexOf(oCurData.ResponsiblePerson) > -1 || parent.UserInfo.UsersBranch.indexOf(oCurData.ResponsiblePerson) > -1 || parent.SysSet.BillAuditor.indexOf(parent.UserInfo.MemberID) > -1) {
dom.find('.alreadyaudit').removeAttr('disabled');
}
if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
dom.find('.reedit,.cancelreedit').hide();
dom.find('.prepay,.mprepay,.billvoid').removeAttr('disabled');
}
else {
dom.find('.billvoid').hide();
}
if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
dom.find('.billdelete').removeAttr('disabled');
}
else {
dom.find('.billdelete').hide();
}
dom.find('.bills-print').removeAttr('disabled');//新增列印草稿
break;
case '2':// ╠common.Audited⇒已審核╣
dom.find('.bill-status').text(i18next.t("common.Audited")).css('color', 'green');
dom.find('.submittoaudit,.synquote,.alreadyaudit,.writeoff,.canceloff,.reedit,.cancelreedit').hide();
dom.find('.billpost,.cancelpost,.cancelaudi,.writeoff').show();
dom.find(':input,textarea,.plusfeeitem,.importfeeitem,.copyfeeitem,.plusfeeitemstar,select,.submittoaudit,.synquote,.billpost,.alreadyaudit,.cancelpost,.writeoff,[data-id="Payer"]').attr('disabled', 'disabled');
dom.find('.icon-p').addClass('disabled');
dom.find('.bills-print').removeAttr('disabled');
if (parent.UserInfo.MemberID === oCurData.ResponsiblePerson || parent.UserInfo.MemberID === oCurData.CreateUser) {
dom.find('.billpost,.receiptnumberbtn,.checkauditdate').removeAttr('disabled');
}
if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
dom.find('.prepay,.mprepay,.cancelaudi,.billvoid,.writeoff').removeAttr('disabled');
}
else {
dom.find('.billvoid').hide();
}
if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
dom.find('.billdelete').removeAttr('disabled');
dom.find('.billpost,.cancelpost').hide();
}
else {
dom.find('.billdelete').hide();
}
break;
case '3':// ╠common.NotPass⇒不通過╣
dom.find('.notpass-reason-text').text(data.NotPassReason || '');
dom.find('.bill-status').text(i18next.t("common.NotPass")).css('color', 'red');
dom.find('.billpost,.cancelpost,.writeoff,.canceloff,.reedit,.cancelreedit').hide();
dom.find('.submittoaudit,.synquote,.alreadyaudit,.notpass-reason-box').show();
if (parent.UserInfo.MemberID === oCurData.ResponsiblePerson || parent.UserInfo.MemberID === oCurData.CreateUser) {
if (data.FeeItems.length > 0) {
dom.find('.submittoaudit').removeAttr('disabled');
dom.parent().next().find('.synquote').removeAttr('disabled');
}
else {
dom.find('.submittoaudit').prop('disabled', true);
dom.parent().next().find('.synquote').prop('disabled', true);
}
}
else {
dom.find(':input,textarea,.alreadyaudit,.cancelaudi,.cancelpost,.writeoff').attr('disabled', 'disabled');
dom.find('.icon-p').addClass('disabled');
}
if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
dom.find('.prepay,.mprepay,.billvoid').removeAttr('disabled');
}
else {
dom.find('.billvoid').hide();
}
if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
dom.find('.billdelete').removeAttr('disabled');
}
else {
dom.find('.billdelete').hide();
}
break;
case '4':// ╠common.NotPass⇒已銷帳╣
dom.find('.bill-status').text(i18next.t("common.HasBeenRealized")).css('color', 'red');
dom.find('.submittoaudit,.synquote,.alreadyaudit,.cancelaudi,.billpost,.cancelpost,.writeoff,.reedit,.cancelreedit').hide();
dom.find('.canceloff').show();
dom.find(':input,textarea,.plusfeeitem,.importfeeitem,.copyfeeitem,.plusfeeitemstar,select,.alreadyaudit,.cancelaudi,.cancelpost,.writeoff,.submittoaudit,.synquote,.billpost').attr('disabled', 'disabled');
dom.find('.icon-p').addClass('disabled');
dom.find('.bills-print').removeAttr('disabled');
if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
dom.find('.canceloff,.billvoid').removeAttr('disabled');
}
else {
dom.find('.billvoid').hide();
}
if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
dom.find('.billdelete').removeAttr('disabled');
}
else {
dom.find('.billdelete').hide();
}
break;
case '5':// ╠common.HasBeenPost⇒已過帳╣
dom.find('.bill-status').text(i18next.t("common.HasBeenPost")).css('color', 'green');
dom.find('.billpost,.submittoaudit,.synquote,.alreadyaudit,.cancelaudi,.reedit,.cancelreedit').hide();
dom.find('.cancelpost,.writeoff,.canceloff').show();
dom.find(':input,textarea,.plusfeeitem,.importfeeitem,.copyfeeitem,.plusfeeitemstar,select,.alreadyaudit,.cancelaudi,.cancelpost,.writeoff,.bills-print,.submittoaudit,.synquote,.billpost').attr('disabled', 'disabled');
dom.find('.icon-p').addClass('disabled');
dom.find('.bills-print').removeAttr('disabled');
if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
dom.find('.cancelpost,.writeoff,.billvoid').removeAttr('disabled');
}
else {
dom.find('.billvoid').hide();
}
if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
dom.find('.billdelete').removeAttr('disabled');
}
else {
dom.find('.billdelete').hide();
}
break;
case '6':// ╠common.HasVoid⇒已作廢╣
dom.find('.notpass-reason-text').text(data.VoidReason || '');
dom.find('.bill-status').text(i18next.t("common.HasVoid")).css('color', '#b2b1b1');
dom.find('button').not('.plusfeeitem').hide();
dom.find('.notpass-reason-box').show();
dom.find(':input,textarea').attr('disabled', 'disabled');
dom.find('.icon-p').addClass('disabled');
if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
dom.find('.billvoid').removeAttr('disabled');
}
break;
case '7':// ╠common.HasReEdit⇒抽單中╣
dom.find(':input,textarea').removeAttr('disabled');
dom.find('.icon-p').removeClass('disabled');
dom.find('.bill-status').text(i18next.t("common.HasReEdit")).css('color', 'blue');
dom.find('.submittoaudit,.synquote,.alreadyaudit').show();
dom.find('.billpost,.cancelpost,.writeoff,.canceloff').hide();
dom.find('.alreadyaudit,.cancelaudi,.cancelpost,.writeoff,.bills-print,.submittoaudit,.synquote,.reedit').attr('disabled', 'disabled');
if (parent.UserInfo.MemberID === oCurData.ResponsiblePerson || parent.UserInfo.MemberID === oCurData.CreateUser) {//如果有資料且是null或者N
dom.find('.cancelreedit').removeAttr('disabled');
}
else {
if (data.KeyName === 'Bill') {
dom.find(':input,textarea,.alreadyaudit,.cancelaudi,.cancelpost,.writeoff').attr('disabled', 'disabled');
dom.find('.icon-p').addClass('disabled');
}
}
if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
dom.find('.prepay,.mprepay,.billvoid').removeAttr('disabled');
}
else {
dom.find('.billvoid').hide();
}
if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
dom.find('.billdelete').removeAttr('disabled');
}
else {
dom.find('.billdelete').hide();
}
break;
}
if (DraftRecipt) {
dom.find("[data-action='Print_Receipt']").hide();
dom.find("[data-action='Download_Receipt']").hide();
}
else {
dom.find("[data-action='Print_Receipt']").show();
dom.find("[data-action='Download_Receipt']").show();
}
if (parent.UserInfo.roles.indexOf('Business') > -1) {
dom.find('[data-id="ExchangeRate"]').attr('disabled', 'disabled');
}
fnOpenAccountingArea(dom.find('.OnlyForAccounting'), parent.UserInfo.roles);
fnOpenAccountingArea(dom.find('.BillOrganizers'), parent.UserInfo.roles);
}
},
/**
* 綁定費用項目
* @param {HTMLELment} dom 當前標籤
* @param {HTMLELment} parentdata 父層標籤
* @param {Object} data 當前資料
* @param {String} flag 綁定狀態
*/
fnBindFeeItem = function (dom, parentdata, data, flag) {
$.each(data.FeeItems, function (idx, item) {
item.OrderBy = idx + 1;
item.FinancialUnitPrice = parseFloat((item.FinancialUnitPrice || '0').toString().replaceAll(',', ''));
item.FinancialAmount = parseFloat((item.FinancialAmount || '0').toString().replaceAll(',', ''));
item.FinancialTWAmount = parseFloat((item.FinancialTWAmount || '0').toString().replaceAll(',', ''));
item.FinancialTax = parseFloat((item.FinancialTax || '0').toString().replaceAll(',', ''));
});
data.FeeItems = Enumerable.From(data.FeeItems).OrderBy("x=>x.OrderBy").ToArray();
var sFeeItemsHtml = '',
iSubtotal = 0, // 未稅總計
iSubtotal_Tax = 0,// 未稅總計-有稅率
iSubtotal_NoTax = 0,// 未稅總計-沒稅率
iTaxtotal = 0,// (純)稅金總計
iTaxSubtotal = 0, //總金額(未稅+稅)
oFinancial = dom.parents('.financial'),
sDomId = dom.attr('data-id'),
bForn = (data.Currency === undefined || data.Currency === 'NTD'),
iOldBoxTotal = parseFloat((oFinancial.find('.boxtotal').val() || '0').replaceAll(',', '')),
oTab = dom.parents('.tab-pane');
$.each(data.FeeItems, function (idx, item) {
sFeeItemsHtml += ''
+ '' + (idx + 1) + ' | '
+ '' + item.FinancialCode + ' | '
+ '' + (!item.FinancialCostStatement ? item.Memo : item.FinancialCostStatement + (!item.Memo ? '' : '(' + item.Memo + ')')) + ' | '
+ '' + item.FinancialCurrency + ' | '
+ '' + fMoney(item.FinancialUnitPrice, 2) + ' | '
+ '' + item.FinancialNumber + ' | '
+ '' + item.FinancialUnit + ' | '
+ '' + fMoney(item.FinancialAmount, 2) + ' | '
+ '' + item.FinancialExchangeRate + ' | '
+ '' + fMoney(item.FinancialTWAmount, 2) + ' | '
+ '' + item.FinancialTaxRate + ' | '
+ '' + fMoney(item.FinancialTax, 2) + ' | '
+ (data.KeyName === 'ActualCost' ? ' | ' : '')
+ (!flag ? ''
+ ' '
+ ' '
+ ((data.FeeItems.length !== idx + 1) ? ' ' : ' ')
+ ((idx !== 0) ? ' ' : ' ')
+ ' | ' : '') +
+'
';
if (item.FinancialTaxRate.toString().replace('%', '') !== '0') {
iSubtotal_Tax += parseFloat(item.FinancialTWAmount);
}
else {
iSubtotal_NoTax += parseFloat(item.FinancialTWAmount);
}
});
//計算總計(total)依序:1.參數的幣值 2.抓到財務的Currency設定 3.再來設定台幣。
var CurrencyType = (data.Currency || oFinancial.find('[data-id="Currency"]').val()) || FeeItemCurrency;
dom.html(sFeeItemsHtml);
iSubtotal_Tax = fnRound(iSubtotal_Tax, data.Currency);
iSubtotal_NoTax = fnRound(iSubtotal_NoTax, data.Currency);
iSubtotal = fnRound(iSubtotal_Tax + iSubtotal_NoTax, CurrencyType);
var iTaxRate = parent.SysSet.TaxRate.toPoint();
iTaxtotal = fnRound(iSubtotal_Tax * (iTaxRate === 0 ? 0.05 : iTaxRate), CurrencyType);
iTaxSubtotal = iSubtotal + iTaxtotal;
oFinancial.find('.subtotal').val(fMoney(iSubtotal, 2, CurrencyType));
oFinancial.find('.taxtotal').val(fMoney(iTaxtotal, 2, CurrencyType));
oFinancial.find('.boxtotal').val(fMoney(iTaxSubtotal, 2, CurrencyType));
data.AmountSum = iSubtotal;
data.TaxSum = iTaxtotal;
data.AmountTaxSum = iTaxSubtotal;
switch (data.KeyName) {
case 'ActualCost':
if (oTab[0].id === 'tab4') {
$('#tab4 .topshowsum').show();
$('#tab4 .actualsum').val(fMoney(iSubtotal, 2, data.Currency));
if (parentdata.ActualCost.AmountTaxSum > parentdata.EstimatedCost.AmountTaxSum) {
$('#tab4 #warnning_tips').show();
}
else {
$('#tab4 #warnning_tips').hide();
}
}
else if (oTab[0].id === 'tab6') {
oFinancial.find('.actualsum').val(fMoney(iSubtotal, 2, data.Currency));
var iAcount = 0;
$.each(parentdata.Bills, function (idx, _bill) {
if (_bill.AuditVal !== '6') {
iAcount += _bill.AmountSum;
}
});
oFinancial.find('.amountsum').val(fMoney(iAcount, 2, data.Currency));
if (parentdata.ActualCost.AmountTaxSum > parentdata.EstimatedCost.AmountTaxSum) {
oFinancial.parent().prev().find('.warnningtips').show();
}
else {
oFinancial.parent().prev().find('.warnningtips').hide();
}
}
break;
case 'EstimatedCost':
if (oTab[0].id === 'tab3') {
$('#tab3 .estimatedcostsum').val(fMoney(iSubtotal, 2, data.Currency));
}
else if (oTab[0].id === 'tab5') {
//增加退運報價/預估成本-預估成本累加
let Return_Estimatedcostsum = $('#tab5 .return_estimatedcostsum').val();
let Current_Return_Estimatedcostsum = parseFloat((Return_Estimatedcostsum || '0').toString().replaceAll(',', ''));
$('#tab5 .return_estimatedcostsum').val(fMoney(Current_Return_Estimatedcostsum + iSubtotal, 2, data.Currency));
}
break;
case 'Bill':
var iAdvance = parseFloat(oFinancial.find('.prepay').val().replaceAll(',', '')),
iExchangeRate = data.ExchangeRate || 1;
data.TotalReceivable = iTaxSubtotal - iAdvance;
oFinancial.find('.subtotal').val(fMoney(iSubtotal, 2, data.Currency));
oFinancial.find('.taxtotal').val(fMoney(iTaxtotal, 2, data.Currency));
oFinancial.find('.boxtotal').val(fMoney(iTaxSubtotal, 2, data.Currency));
oFinancial.find('.paytotal').val(fMoney(iTaxSubtotal - iAdvance, 2, data.Currency));
// 匯率
let TabTipExchangeRate = (bForn ? 1 : iExchangeRate);
// 純稅金(本幣別)
let TabTipTaxtotal = fnRound(iTaxtotal * TabTipExchangeRate, FeeItemCurrency);
// 未稅總額(本幣別)
let TabTipUntaxtotal = fnRound(iSubtotal * TabTipExchangeRate, FeeItemCurrency);
iOldBoxTotal = iOldBoxTotal * (bForn ? 1 : iExchangeRate);
//加總 = 上個帳單加總 + 此次帳單的未稅金額
if (oTab[0].id === 'tab3') {
if (data.AuditVal !== '6') {
let LastRowActualsum = parseFloat($('#tab3 .amountsum').val().replaceAll(',', '')) - iOldBoxTotal;
$('#tab3 .amountsum').val(fMoney(LastRowActualsum + TabTipUntaxtotal, 2, FeeItemCurrency));
$('#tab4 .amountsum').val($('#tab3 .amountsum').val());
}
}
else if (oTab[0].id === 'tab5') {
// 每筆退運帳單的預估成本
oFinancial.find('.topshowsum').show();
oFinancial.find('.estimatedcostsum').val(fMoney(parentdata.EstimatedCost.AmountSum, 2, data.Currency));
if (data.AuditVal !== '6') {
//退運帳單加總
let LastRowActualsum = parseFloat(oFinancial.find('.amountsum').val().replaceAll(',', '')) - iOldBoxTotal;
oFinancial.find('.amountsum').val(fMoney(LastRowActualsum + TabTipUntaxtotal, 2, FeeItemCurrency));
$('.bill-box-' + data.BillNO).find('.amountsum').val(oFinancial.find('.amountsum').val());
//增加退運報價/預估成本-帳單金額累加(有先後順序,無法對調)
let LastRow_Return_Amountsum = parseFloat($('#tab5 .return_amountsum').val().replaceAll(',', ''));
$('#tab5 .return_amountsum').val(fMoney(LastRow_Return_Amountsum + TabTipUntaxtotal, 2, FeeItemCurrency));
}
}
break;
}
/*計算$$*/
if (oTab[0].id === 'tab3') {
if (data.KeyName === 'Bill')
fnCalcuBillsFee(oFinancial, '.BillForeignCurrency', '.BillMainCurrency', data.Currency, data.ExchangeRate);
else
fnCalcuQuotationFee(oFinancial.find('.QuotationForeignCurrency'), oFinancial.find('.QuotationMainCurrency'),
parentdata.Quote.QuotationOrBillingCurrency, parentdata.Quote.AccountingExchangeRate);
}
else if (oTab[0].id === 'tab5') {
if (data.KeyName === 'Bill')
fnCalcuBillsFee(oFinancial, '.ReturnBillForeignCurrency', '.ReturnBillMainCurrency',
data.Currency, data.ExchangeRate);
else {
fnCalcuQuotationFee(oFinancial.find('.ReturnQuotationForeignCurrency'), oFinancial.find('.ReturnQuotationMainCurrency'),
parentdata.ReturnQuotationOrBillingCurrency, parentdata.ReturnAccountingExchangeRate);
}
}
dom.parents('.financial').find('.plusfeeitem').prop('disabled', false);
fnSetDisabled(oFinancial, data);
oFinancial.find('.input-value').on('change', function () {
var that = this,
sId = $(that).attr('data-id');
data[sId] = $(that).val();
bRequestStorage = true;
});
if (data.KeyName === 'ActualCost') {
var saBillPayers = function () {
var saRetn = [];
$.each(parentdata.Bills, function (idx, bill) {
if (!bill.VoidReason) {
var sPayer = '',
oCur = {};
if (bill.Payer) {
oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === bill.Payer; }).First();
}
saRetn.push({
id: bill.BillNO,
text: oCur.text,
val: bill.BillNO + '-' + (oCur.text || '') + '-' + bill.BillCreateDate
});
}
});
return saRetn;
}();
dom.find('.billpayer').each(function () {
var sGuid = $(this).attr('data-value'),
sBillNO = $(this).attr('data-billno'),
Selector = 'oBillPayers-' + sGuid;
$(this).append($('