307 lines
17 KiB
JavaScript
307 lines
17 KiB
JavaScript
define(["angularAMD"], function (angularAMD) {
|
|
angularAMD.service('material', ['$rootScope', '$filter', 'config', 'MMWService', '$mdDialog', '$timeout', '$calculater',
|
|
function ($rootScope, $filter, config, $MMWService, $mdDialog, $timeout, $calculater) {
|
|
this.init = function (options) {
|
|
(function openDialog() {
|
|
$mdDialog.dialog('module/moduleWIP/program/dialog/material/material.tmp.html',
|
|
function (dialog) {
|
|
dialog.ISCI = options.ISCI;
|
|
//dialog.listMaterialLot = [];
|
|
|
|
function funRefreshUseQty(sub_mtl, item) {
|
|
|
|
if (!(sub_mtl.USEQTY) ||
|
|
typeof sub_mtl.USEQTY !== 'number') {
|
|
sub_mtl.USEQTY = 0;
|
|
}
|
|
|
|
if (parseFloat(sub_mtl.USEQTY) > sub_mtl.QTY) {
|
|
$rootScope.showMessage('[%USEQTY%] > [%MATERIALSTATE%], [%MATERIALLOT%]:' + sub_mtl.MATERIALLOTNO, "0000-203083");
|
|
return;
|
|
}
|
|
|
|
//更新Temp Material 總數量
|
|
var int_useqty = 0;
|
|
item.mtl_lot.forEach(function (ary_tmp) {
|
|
int_useqty = parseFloat(int_useqty) + parseFloat(ary_tmp.USEQTY);
|
|
});
|
|
item.USEQTY = int_useqty;
|
|
}
|
|
|
|
return {
|
|
css_url: 'module/moduleWIP/program/dialog/material/material.css',
|
|
lotno: options.lotno,
|
|
materials_list: options.materials_list,
|
|
beforeShown: function () { },
|
|
confirm: function () {
|
|
|
|
var listMaterialLot = [];
|
|
dialog.materials_list.forEach(material => {
|
|
material.mtl_lot.forEach(mtl => {
|
|
listMaterialLot.push(mtl);
|
|
});
|
|
});
|
|
|
|
//料批需要數入數量
|
|
for (var i = 0; i < listMaterialLot.length; i++) {
|
|
var number = parseFloat(listMaterialLot[i].USEQTY);
|
|
if (isNaN(number)) {
|
|
$rootScope.showAlert($filter('translate')('mrs04.msg.QtyEmpty') + " " +
|
|
$filter('translate')('wp03_e_runcard.material.mtlNo') + ":" + listMaterialLot[i].MATERIALNO + " " +
|
|
$filter('translate')('wp03_e_runcard.material.mtlLot') + ":" + listMaterialLot[i].MATERIALLOTNO);
|
|
return;
|
|
}
|
|
}
|
|
|
|
dialog.hide();
|
|
|
|
//20210714 13871,刪除angular索引物件,避免後端轉型錯誤
|
|
var result = $rootScope.deepCopy(dialog.materials_list);
|
|
result.forEach(item => {
|
|
if (item["$$hashKey"])
|
|
delete item["$$hashKey"];
|
|
|
|
//20211125 13871,小鍵盤回傳值會字串,轉為數值,避免後端應用錯誤
|
|
item.USEQTY = Number(item.USEQTY);
|
|
|
|
if (item.mtl_lot != undefined) {
|
|
item.mtl_lot.forEach(item2 => {
|
|
if (item2["$$hashKey"])
|
|
delete item2["$$hashKey"];
|
|
|
|
//20211125 13871,小鍵盤回傳值會字串,轉為數值,避免後端應用錯誤
|
|
item2.USEQTY = Number(item2.USEQTY);
|
|
});
|
|
}
|
|
});
|
|
|
|
if (options.callback) {
|
|
options.callback({
|
|
listTempMaterial: result,
|
|
listMaterialLot: listMaterialLot
|
|
});
|
|
}
|
|
|
|
},
|
|
background: {
|
|
click: function () {
|
|
dialog.hide();
|
|
if (typeof (feedback) == 'function')
|
|
feedback();
|
|
}
|
|
},
|
|
back: function () {
|
|
dialog.hide();
|
|
if (options.close)
|
|
options.close();
|
|
},
|
|
mtlqty_chk_click: function (event, item, sub_mtl) {
|
|
var target = event.currentTarget;
|
|
angular.element(target).addClass('is-focus');
|
|
$calculater.open(function (num, calcDialog) {
|
|
|
|
if ((+num) > sub_mtl.QTY) {
|
|
$rootScope.showMessage('[%USEQTY%] > [%MATERIALSTATE%], [%MATERIALLOT%]:' + sub_mtl.MATERIALLOTNO, "0000-203083");
|
|
return;
|
|
}
|
|
|
|
angular.element(target).removeClass('is-focus');
|
|
sub_mtl.USEQTY = num;
|
|
|
|
//更新Temp Material 總數量
|
|
funCalculateUseQty(item);
|
|
|
|
calcDialog.hide();
|
|
|
|
},
|
|
function (calcDialog) {
|
|
angular.element(target).removeClass('is-focus');
|
|
calcDialog.hide();
|
|
},
|
|
{
|
|
title: '',
|
|
decimal: true
|
|
});
|
|
|
|
},
|
|
mtlqty_chk_enter: function (event, item, sub_mtl) {
|
|
if (event.keyCode != 13) return;
|
|
funRefreshUseQty(sub_mtl, item);
|
|
|
|
},
|
|
mtlqty_chk_blur: function (event, item, sub_mtl) {
|
|
funRefreshUseQty(sub_mtl, item);
|
|
},
|
|
scanQrcode1: function () {
|
|
$rootScope.OpenScanner({
|
|
after: function (result) {
|
|
if ($rootScope.IsNullOrEmpty(result.text))
|
|
return;
|
|
//20210827 13871修正錯誤變數使用mtl_no -> mtlno
|
|
dialog.mtlno = result.text;
|
|
dialog.scanQrcode2();
|
|
},
|
|
exception: function () {
|
|
//目前裝置無法使用相機
|
|
$rootScope.showAlert($filter('translate')('common.msg.camera_not_support'));
|
|
},
|
|
orientation: "landscape"
|
|
});
|
|
},
|
|
scanQrcode2: function () {
|
|
$rootScope.OpenScanner({
|
|
after: function (result) {
|
|
if ($rootScope.IsNullOrEmpty(result.text))
|
|
return;
|
|
//20210827 13871修正錯誤變數使用mtl_lotno -> mtllotno
|
|
dialog.mtllotno = result.text;
|
|
if (!$rootScope.IsNullOrEmpty(dialog.mtlno))
|
|
dialog.barcodeScan_mtllotno({ keyCode: 13 });
|
|
},
|
|
exception: function () {
|
|
//目前裝置無法使用相機
|
|
$rootScope.showAlert($filter('translate')('common.msg.camera_not_support'));
|
|
},
|
|
orientation: "landscape"
|
|
});
|
|
},
|
|
barcodeScan_mtlno: function (event) {
|
|
if (event == undefined || event.keyCode == 13) {
|
|
if (event && event.currentTarget)
|
|
event.currentTarget.blur();
|
|
|
|
if (event && event.keyCode == 13 && dialog.mtlno == '') {
|
|
$rootScope.showAlert($filter('translate')('mrs04.msg.barcode_empty_mtlno'));
|
|
return;
|
|
}
|
|
$rootScope.focusById('intput_mtllotno');
|
|
}
|
|
},
|
|
barcodeScan_mtllotno: function (event) {
|
|
|
|
if (!event || event.keyCode != 13) {
|
|
return;
|
|
}
|
|
|
|
if (event.currentTarget)
|
|
event.currentTarget.blur();
|
|
|
|
if (dialog.mtllotno == '') {
|
|
$rootScope.showAlert($filter('translate')('mrs04.msg.barcode_empty_mtllotno'));
|
|
return;
|
|
}
|
|
|
|
//20210714 13871,改寫方式AutoFeedingByPutinPlace不在迴圈內執行
|
|
//檢查料批是否已存在
|
|
var bln_feeding = false;
|
|
dialog.materials_list.forEach(function (tmp_obj) {
|
|
if (tmp_obj.mtl_lot != undefined && tmp_obj.mtl_lot != null) {
|
|
|
|
tmp_obj.mtl_lot.forEach(function (tmp_mtl_lot) {
|
|
|
|
//20210714 13871,修正變數名稱錯誤 -> 全大寫
|
|
if (tmp_mtl_lot.SUBSTITUTEMATERIALNO == dialog.mtlno
|
|
&& tmp_mtl_lot.MATERIALLOTNO == dialog.mtllotno) {
|
|
|
|
bln_feeding = true;
|
|
|
|
}
|
|
})
|
|
}
|
|
});
|
|
|
|
//20210714 13871,後端查核移出迴圈
|
|
if (bln_feeding) {
|
|
$rootScope.showAlert($filter('translate')('lc_co_gen.dialog.material.msg.mtlalreadyfeed'));
|
|
return;
|
|
}
|
|
|
|
AutoFeedingByPutinPlace({
|
|
LotNo: dialog.lotno,
|
|
MaterialNo: dialog.mtlno,
|
|
MaterialLotNo: dialog.mtllotno
|
|
//UnitNo: tmp_obj.UNITNO //20210714 13871,後端根本沒有使用此資訊改為傳入空字串
|
|
}, function (options) {
|
|
|
|
var SubstituteMaterial = options.SubstituteMaterial;
|
|
if (SubstituteMaterial.length <= 0) {
|
|
$rootScope.showAlert($filter('translate')('lc_co_gen.dialog.material.msg.mtlunexist'));
|
|
return;
|
|
}
|
|
|
|
var lst_tmp_obj = dialog.materials_list.filter(item => { return item.MATERIALNO == SubstituteMaterial[0].MATERIALNO });
|
|
if (lst_tmp_obj.length > 0) {
|
|
|
|
//CHECKLOTNO開啟, 物料批號不允許輸入N/A
|
|
if (lst_tmp_obj[0].CHECKLOTNO == 1) {
|
|
if (SubstituteMaterial[0].MATERIALLOTNO == "N/A") {
|
|
$rootScope.showAlert(lst_tmp_obj[0].MATERIALNO + $filter('translate')('lc_ci_gen.msg.NACannotBeUsedAsTheMaterialLotNo'));
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (!lst_tmp_obj[0].mtl_lot)
|
|
lst_tmp_obj[0].mtl_lot = [];
|
|
|
|
//填入還缺少的數量
|
|
SubstituteMaterial[0].USEQTY =
|
|
(lst_tmp_obj[0].STDUSEQTY - lst_tmp_obj[0].USEQTY) *
|
|
(SubstituteMaterial[0].SUBSTITUTESTDQTY / lst_tmp_obj[0].STDQTY);
|
|
|
|
//料批數量不足以填補
|
|
if (SubstituteMaterial[0].USEQTY > SubstituteMaterial[0].QTY)
|
|
SubstituteMaterial[0].USEQTY = SubstituteMaterial[0].QTY;
|
|
|
|
lst_tmp_obj[0].mtl_lot.push(SubstituteMaterial[0]);
|
|
|
|
//更新Temp Material 總數量
|
|
funCalculateUseQty(lst_tmp_obj[0]);
|
|
}
|
|
});
|
|
|
|
}
|
|
}
|
|
});
|
|
|
|
//計算各料批用量(要考量替代料用量SUBSTITUTESTDQTY)
|
|
function funCalculateUseQty(TempMaterial) {
|
|
|
|
var UseQty = 0;
|
|
TempMaterial.mtl_lot.forEach(MaterialLot => {
|
|
UseQty += (MaterialLot.USEQTY * (TempMaterial.STDQTY / MaterialLot.SUBSTITUTESTDQTY));
|
|
});
|
|
|
|
TempMaterial.USEQTY = UseQty;
|
|
}
|
|
|
|
|
|
function AutoFeedingByPutinPlace(options, callback) {
|
|
|
|
$MMWService.sendToMESSrv({
|
|
uri: 'kcWIP.clsMDS.AutoFeedingByPutinPlace',
|
|
content: {
|
|
LotNo: options.LotNo,
|
|
MaterialNo: options.MaterialNo,
|
|
MaterialLotNo: options.MaterialLotNo,
|
|
//UnitNo:options.UnitNo //20210714 13871,後端根本沒有使用此資訊改為傳入空字串
|
|
UnitNo: ''
|
|
},
|
|
success: function (data) {
|
|
|
|
if (data.Code == '0') {
|
|
data = JSON.parse(data.ResultJson);
|
|
if (callback) {
|
|
callback(data);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
})();
|
|
}
|
|
}
|
|
]);
|
|
});
|