2022年10月20日 星期四

V120201 - Email 通知人員 - – [申請撤銷] –物料申請撤銷時, Email 通知撿料人員 - V30702E

 目的: V120201 - EMail 通知人員

處理說明:




1>V120201.js  - Email 通知

//按鈕 : [物料申請] [申請撤銷]
    var BtnAry = [
        {
            xtype: 'button', text: '物料申請', id: 'ApyBtn',
            listeners: {
                click: function () {
                    ApyBtn_click();
                }
            }
        },
        {
            xtype: 'button', text: '申請撤銷', id: 'CancelBtn',
            listeners: {
                click: function () {
                    console.log(" 1 inside 申請撤銷: " );
                    //若目前物料申請單號已有領料記錄,則不允許執行[申請撤銷]鈕
                    var cur_recs = Ext.getCmp('grid_Single').getSelectionModel().getSelection(); //grid select指向選擇的第一筆        
                    var cur_rec = cur_recs[0];
                    var Tmp_STAT = cur_rec['raw']['STAT'];                    
                    var Tmp_APNO = cur_rec['raw']['APNO'];
                    if (Tmp_STAT == 'Z') {                    
                        Tmp_Str = " 目前物料申請單( " + Tmp_APNO + ") 的單況為 Z: 撤銷 <br>"
                                        + " 無法再次撤銷 !! <br>"
                                        + " 請檢核 ";
                        mywarnalert(Tmp_Str);
                        return;
                    }
                    var Tmp_PN = cur_rec['raw']['PN'];
                    var Tmp_MPKUPP = cur_rec['raw']['MPKUPP'];
                    var Tmp_MPKUPP_ = cur_rec['raw']['MPKUPP_'];
                    var Tmp_Str = "";
                    var Tmp_Sql = " SELECT   nvl(SUM(QTY),0)  as  PQTY "
                        + "  FROM    AMM_COMPQTY "
                        + "   WHERE  EFF='Y'  "
                        + "   AND        APNO=" + AA(Tmp_APNO);
                    console.log("Tmp_Sql: ", Tmp_Sql);
                    var Tmp_PQTY_Str = SqlValue(Tmp_Sql);
                    console.log("0 Tmp_STAT=", Tmp_STAT);
                    console.log("1 Tmp_PQTY_Str=", Tmp_PQTY_Str);                    
                    var Tmp_PQTY = Number(Tmp_PQTY_Str);
                    console.log("2 Tmp_PQTY=", Tmp_PQTY.toString());
                    var Tmp_PQTY = Number(SqlValue(Tmp_Sql));                    
                    console.log("3 Tmp_PQTY= Number(SqlValue(Tmp_Sql))", Tmp_PQTY.toString());
                    if ((Tmp_STAT == 'D') && (Tmp_PQTY > 0)) {
                        Tmp_Str = " 目前物料申請單( " + AA(Tmp_APNO) + "<br>"
                            + " 已有領用記錄<br>"
                            + " 無法撤銷 !! <br>"
                            + " 請先將物料退回 BenchStock ";
                        mywarnalert(Tmp_Str);
                        return;
                    }
                    var win = getMyWindow("申請撤銷", mySub2, mySub2_Btns);
                    Ext.getCmp('sub_APNO').setValue(Tmp_APNO);
                    Ext.getCmp('sub_PN').setValue(Tmp_PN);
                    Ext.getCmp('sub_MPKUPP').setValue(Tmp_MPKUPP);
                    Ext.getCmp('sub_MPKUPP_').setValue(Tmp_MPKUPP_);
                    Ext.getCmp('sub_DELTP').setValue(loginInfo.id);
                    Tmp_Sql = " SELECT  EMPLYNM "
                        + "   FROM    HR_EMPLYM "
                        + " WHERE   EMPLYID=" + AA(loginInfo.id);
                    Tmp_Str = SqlValue(Tmp_Sql);
                    Ext.getCmp('sub_DELTP_').setValue(Tmp_Str);
                    console.log("2  win: ", win);
                    win.width = 600;
                    win.height = 400;
                    win.show();
                }
            }
        },        
        ];
    

//按鈕 : [物料申請] [申請撤銷]
var mySub2_Btns = [
{
xtype: 'button', text: '確定', id: 'OkBtn_mySub2',
listeners: {
click: function () {
//mysuccessalert("press ok");
mySub2_OkBtn_click();
}
}
},
{
xtype: 'button', text: '取消', id: 'CancelBtn_mySub2',
listeners: {
click: function () {
//mysuccessalert("press cancel");
var Tmp_win = this.up("window");
if (Tmp_win == undefined) {
Ext.Msg.alert("取消時未取到Window Object");
}
this.up("window").close();
this.up("window").destroy();
}
}
},
];

// [申請撤銷]鈕 - 子畫面欄位
var mySub2 = [
{
bodyStyle: "background-color:transparent;", border: false, layout: "vbox", padding: "5", items: [
{
xtype: "fieldcontainer", fieldLabel: "申請單號", labelWidth: 80, layout: "hbox", items: [
{ id: "sub_APNO", name: "sub_APNO", xtype: "textfield", width: 200, padding: "0 4 0 0", readOnly: true, fieldCls: "readonly", },
]
}, //end of 申請單號
{
xtype: "fieldcontainer", fieldLabel: "申請件號", labelWidth: 80, layout: "hbox", items: [
{ id: "sub_PN", name: "sub_PN", xtype: "textfield", width: 200, padding: "0 4 0 0", readOnly: true, fieldCls: "readonly", },
]
}, // end of 申請件號
{
xtype: "fieldcontainer", fieldLabel: "撿料人員", labelWidth: 80, layout: "hbox", items: [
{ id: "sub_MPKUPP", name: "sub_MPKUPP", xtype: "textfield", width: 100, padding: "0 4 0 0", readOnly: true, fieldCls: "readonly", },
{ id: "sub_MPKUPP_", name: "sub_MPKUPP_", xtype: "textfield", width: 100, padding: "0 4 0 0", readOnly: true, fieldCls: "readonly", },
]
}, // end of 申請件號
{
xtype: "fieldcontainer", fieldLabel: "撤銷人員", labelWidth: 80, layout: "hbox", items: [
{ id: "sub_DELTP", name: "sub_DELTP", xtype: "textfield", width: 100, padding: "0 4 0 0", fieldCls: "required", },
{ id: "sub_DELTP_", name: "sub_DELTP_", xtype: "textfield", width: 100, padding: "0 4 0 0", readOnly: true, fieldCls: "readonly", },
{
id: "btn_sub_DELTP", name: "btn_sub_DELTP", xtype: "button", text: "...",
//員工編號挑選 , TreeView 挑選
handler: function () {
console.log(" btn_sub_DELTP on click");
var treepanel = Ext.create('EmployeeTree', {
id: 'myEmployeeTree',
listeners: {
itemclick: function (view, record, item, index, e) {
if (record.raw.leaf) {
var info = record.raw.text;
var newStr = info.split(":");
Ext.getCmp('sub_DELTP').setValue(newStr[0]);
Ext.getCmp('sub_DELTP_').setValue(newStr[1]);
win_tree.close();
}
}
}
});
var win_tree = getWindow('撤銷人員挑選', treepanel);
win_tree.height = 400;
win_tree.show();
} // end of handler of btn_sub_APER
}, // end of btn_sub_APER
{
id: "btn_sub_DELTP1", name: "btn_sub_DELTP1", xtype: "button", text: "切換人員",
//切換人員 , 欄位清成空白
handler: function () {
Ext.getCmp('sub_DELTP').setValue("");
Ext.getCmp('sub_DELTP_').setValue("");
Ext.getCmp('sub_DELTNOTE').setValue("");
}
},
]
}, // end of 申請人
{
xtype: "fieldcontainer", fieldLabel: "撤銷原因", labelWidth: 80, layout: "hbox", items: [
{
id: "sub_DELTNOTE", name: "sub_DELTNOTE", xtype: "textarea", width: 200, padding: "0 4 0 0", fieldCls: "required",
}
] // end of 撤銷原因.items
}, // end of 撤銷原因
//{ // 多行 Sample
// xtype: 'textareafield',
// grow: true,
// name: 'message',
// fieldLabel: 'Message',
// anchor: '100%'
//},
] // end of layout: "vbox", padding: "5", items: [
} //end of J_formFields_Sub1 , items[{
] //end of J_formFields_Sub1 , items[


// [申請撤銷].[確認]鈕  - 處理
function mySub2_OkBtn_click() {
//判斷 AMM_COMQ.STAT='D'(已領料)        
console.log("  1 inside  mySub2_OkBtn_click ");
var Tmp_Str = "";
var Tmp_Sql = " ";
var cur_recs = Ext.getCmp('grid_Single').getSelectionModel().getSelection(); //grid select指向選擇的第一筆                
var cur_rec = cur_recs[0];
var Tmp_APNO = Ext.getCmp('sub_APNO').getValue();
var np = {};
np['sub_APNO'] = Ext.getCmp('sub_APNO').getValue();
np['sub_PN'] = Ext.getCmp('sub_PN').getValue();
np['sub_MPKUPP'] = Ext.getCmp('sub_MPKUPP').getValue();
np['sub_DELTP'] = Ext.getCmp('sub_DELTP').getValue();
np['sub_DELTNOTE'] = Ext.getCmp('sub_DELTNOTE').getValue();
np['sub_STAT'] = cur_rec['raw']['STAT'];

console.log(" 2 UPDATE  AMM_COMQ, AMM_COMPQTY ");
//1>更新 AMM_COMQ.STAT='Z' 及撤銷人員 & 撤銷原因
Tmp_Sql = "  UPDATE  AMM_COMQ  "
+ "   SET   STAT=" + AA('Z') + ","
+ "     DELTP=" + AA(np['sub_DELTP']) + ","
+ "  DELTNOTE=" + AA(np['sub_DELTNOTE'])
+ "    WHERE  APNO=" + AA(np['sub_APNO']);
SqlExec(Tmp_Sql);
//2>更新 AMM_COMPQTY.EFF='N' 及撤銷人員 & 撤銷原因
Tmp_Sql = "  UPDATE  AMM_COMPQTY  "
+ "   SET   EFF=" + AA('N')
+ "    WHERE  APNO=" + AA(np['sub_APNO']);
SqlExec(Tmp_Sql);
console.log(" 3 Email sendmail2 np['sub_MPKUPP']:", np['sub_MPKUPP']);

//3> Email 通知檢料人員 , 若撿料人員空白,則不 Email 
if (checkisnull(np['sub_MPKUPP'])) {
Tmp_Str = "申請單單號(" + Ext.getCmp('sub_APNO').getValue() +") 已撤銷成功 !! <br> "
          +"因本申請單的撿料人員空白, 無法Email 通知撿料人員!! <br>"
          + "請檢核 !!";
mywarnalert(Tmp_Str);
console.log("3.1 Ext.getCmp(btn_Show)= :", Ext.getCmp("btn_Show"));
Ext.getCmp("btn_Show").fireHandler();
console.log("3.2 after Ext.getCmp(btn_Show).fireHandler()", Ext.getCmp("btn_Show"));
Ext.getCmp("OkBtn_mySub2").up("window").close();
Ext.getCmp("OkBtn_mySub2").up("window").destroy();
return;
}

console.log(" 3.5   Ext.Ajax.request sendmail2 np ", np);
Ext.Ajax.request({
method: 'POST',
params: np,
async: false, //將非同步功能關閉
url: '../../api/V120201API/sendmail2',
success: function (response, opts) {
console.log("4 sendmail2 success!!");
var obj = Ext.decode(response.responseText);
console.log("obj:", obj);
if (obj["failure"]) {
console.log("obj.failure=true, obj[Rtn_Msg] : ", obj["Rtn_Msg"] );
var Tmp_Str = obj["Rtn_Msg"];
mywarnalert(Tmp_Str);
return;
};
console.log("5 show 撤銷成功訊息");
Tmp_Str = " 物料申請單(" + Tmp_APNO + ") 撤銷成功 !!<BR> "
+ "  並已Email 通知撿料人員 ";
mysuccessalert(Tmp_Str);
//重新顯示畫面
console.log("6 Ext.getCmp(btn_Show)= :", Ext.getCmp("btn_Show"));
Ext.getCmp("btn_Show").fireHandler();
console.log("7 after Ext.getCmp(btn_Show).fireHandler()", Ext.getCmp("btn_Show"));
Ext.getCmp("OkBtn_mySub2").up("window").close();
Ext.getCmp("OkBtn_mySub2").up("window").destroy();
},
failure: function (response, opts) {
console.log("6 failure !!");
Tmp_Str = " 物料申請單(" + Tmp_APNO + ") 撤銷失敗<BR> "
+ "  Email 失敗 ";
mywarnalert(Tmp_Str + response.status);
}
});  // end of  Ext.Ajax.Request  for Email

}


2>*.cs  - sendmail
//物料撤銷. Email 
        [HttpPost]
        public HttpResponseMessage sendmail2()
        {
            var c = System.Web.HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            MailMessage ChkMail = new MailMessage();
            TLSWS.TLSWebServiceSoapClient WS = new TLSWS.TLSWebServiceSoapClient();

            //正本收件人:  AMM_MALLIST  , TP='A'
            string Tmp_EmailStr="";
            string Tmp_RtnMsg = "";
            string Tmp_Sql = "  SELECT  A.MPKUPP,B.NOTES_MAIL  "
                                       + "  FROM    AMM_COMQ A,HR_EMPLYM B  "
                                       + "  WHERE  A.MPKUPP = B.EMPLYID  "                                       
                                       + "  AND       A.APNO="+myfunc.AA(nvc["sub_APNO"]);
            OracleCommand cmd = new OracleCommand();
            cmd.CommandText = Tmp_Sql;
            DataSet ds = getDataTable(cmd);
            for (int i = 0; i < ds.Tables["T1"].Rows.Count; i++)
            {
                ChkMail.To.Add(ds.Tables["T1"].Rows[i]["notes_mail"].ToString());
            };           

            string subject = "BenchStock 件號(" + nvc["sub_PN"] + ") 物料申請單撤銷通知";
            string content = "申請單號(" + nvc["sub_APNO"] + ") 申請件號(" + nvc["sub_PN"] + ")的物料申請單已撤銷<br>"
                                      + "若已完成撿料請將物料歸儲 !! <br> "
                                      +" 撤銷人員: " + nvc["sub_DELTP"]+"<br>"
                                      + " 撤銷日期: " + myfunc.cnow() + "<br>"
                                       + "通知原因: " + nvc["sub_DELTNOTE"];
            string mail_from = "tlsapp@ms.aidc.com.tw";

    ChkMail.From = new MailAddress(mail_from, "TLS", System.Text.Encoding.UTF8);//發送者 

            if (ChkMail.To.Count > 0)
            {
                sendMail(subject, content, ChkMail);
                Tmp_EmailStr = "Email 成功 !!  ";
                Tmp_RtnMsg = "{success: true, failure: false, Rtn_Msg: " + myfunc.AA(Tmp_EmailStr) + " }";
            }
            else
            {
                Tmp_EmailStr = "寄件人空白, 無法 Email.. ";
                Tmp_RtnMsg = "{success: false, failure: true, Rtn_Msg: " + myfunc.AA(Tmp_EmailStr) + " }";
            }
            var response = Request.CreateResponse(HttpStatusCode.OK, "success");
            response.StatusCode = HttpStatusCode.OK;            
            response.Content = new StringContent(Tmp_RtnMsg);    // 回應內容
            return response;
        }  // end of  sendmail2()

沒有留言:

張貼留言