| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- debugger
- let lotserial = this.formData['workordmaster-lotserial'] || "";
- let factory_id = this.formData['configurationitem-domain'];
- let QtyOrded = this.formData['workordmaster-qtyorded'];
- const workord = this.formData['workordmaster-workord'] || "";
- const bomformula = this.formData['workordmaster-bomformula'] || "";
- const itemnum = this.formData['workordmaster-itemnum'] || "";
- let user = this.formData['field_1705385673713'] || "";
- let msg = "";
- if (lotserial === "") {
- msg += "、生产批次号";
- }
- var orddate = this.formData['workordmaster-orddate'] || "";
- var duedate = this.formData['workordmaster-duedate'] || "";
- if (orddate === "") {
- msg += "、开工日期";
- }
- //var rev = this.formData['workordmaster-rev'] || "";
- //var drawing = this.formData['workordmaster-drawing'] || "";
- //if (drawing != "" && rev == "") {
- // msg3 = "此工单未记录版本";
- //}
- let msg4 = "";
- var sql4 = `select count(*) as count from WorkOrdMaster where Status='r' and isactive=1 and workord='${workord}'`;
- let res4 = utils.getSelectvalue2("dopflow", sql4, sysConfig['SERVER_APIADDRESS']);
- if (res4.data > 0) {
- msg4 = "此工单已下达";
- }
- sql4 = `select count(*) as count from WorkOrdRouting where ProcessOut=1 and (ProcessOutSupp='' or ProcessOutSupp is null) and isactive=1 and workord='${workord}'`;
- res4 = utils.getSelectvalue2("dopflow", sql4, sysConfig['SERVER_APIADDRESS']);
- if (res4.data > 0) {
- msg4 = "请在工单工序明细中维护委外供应商";
- }
- let msg3 = "";
- if (bomformula == "") {
- var sql3 = `select count(*) as count from ItemMaster where itemnum='${itemnum}' and (PMBOM='' or PMBOM is null)`;
- let res3 = utils.getSelectvalue2("dopflow", sql3, sysConfig['SERVER_APIADDRESS']);
- if (res3.data > 0) {
- msg3 = "物料未维护量产bom";
- }
- }
- let msg2 = "";
- var sql = `select count(*) as count from WorkOrdDetail where workord='${workord}' and isactive=1`;
- let res2 = utils.getSelectvalue2("dopflow", sql, sysConfig['SERVER_APIADDRESS']);
- if (res2.data <= 0) {
- msg2 = ",工单未找到物料";
- } else if (workord.indexOf("M6") < 0) {
- sql = `select count(*) as count from WorkOrdDetail where workord='${workord}' and isactive=1 and itemnum='${itemnum}'`;
- res2 = utils.getSelectvalue2("dopflow", sql, sysConfig['SERVER_APIADDRESS']);
- if (res2.data > 0) {
- msg2 = ",工单子物料不能与主物料一致";
- }
- }
- sql = `select count(*) as count from WorkOrdRouting where workord='${workord}' and isactive=1`;
- let res3 = utils.getSelectvalue2("dopflow", sql, sysConfig['SERVER_APIADDRESS']);
- if (res3.data <= 0) {
- msg2 += ",工单未找到工序";
- }
- else {
- sql = `select count(*) as count from WorkOrdRouting where workord='${workord}' and QtyOrded!=${QtyOrded}`;
- let res4 = utils.getSelectvalue2("dopflow", sql, sysConfig['SERVER_APIADDRESS']);
- if (res4.data > 0) {
- msg2 += ",工单工序需求数错误";
- } else {
- sql = `select count(*) as count from WorkOrdRouting where workord='${workord}' and ((Labor=0 and ProcessOut=0) or ChargeCode='' or WorkCtr='' or ufld3='' or QtyOrded=0 )`;
- let res4 = utils.getSelectvalue2("dopflow", sql, sysConfig['SERVER_APIADDRESS']);
- if (res4.data > 0) {
- msg2 += ",工单工序维护错误";
- }
- else {
- sql = `select count(*) as count from WorkOrdRouting where workord='${workord}' and ProcessOut=1 and op=(select min(op) from WorkOrdRouting where workord='${workord}')`;
- let res4 = utils.getSelectvalue2("dopflow", sql, sysConfig['SERVER_APIADDRESS']);
- if (res4.data > 0) {
- msg2 += ",工单工序不可首序委外";
- }
- }
- }
- }
- if (msg === "" && msg2 == "" && msg3 == "" && msg4 == "") {
- let selectedDate = new Date(orddate);
- let today = new Date();
- var year = today.getFullYear();
- var month = (today.getMonth() + 1).toString().padStart(2, '0'); // 月份从0开始,所以要加1
- var day = today.getDate().toString().padStart(2, '0');
- var currentDate = year + '-' + month + '-' + day;
- if (selectedDate <= today) {
- utils.msg("工单开工日期需调整至今日之后。", false);
- }
- else {
- let insertSql = ``;
- let insertSql1 = ``;
- let diffDay = this.formData['field_1705374190767'] || 0;
- if (diffDay != 0) {
- insertSql = `,OrdDate=DATEADD(D, ${diffDay}, OrdDate),DueDate=iif(DATEADD(D, ${diffDay}, DueDate)>DATEADD(D, ${diffDay}, OrdDate),DATEADD(D, ${diffDay}, DueDate),DATEADD(D, ${diffDay + 2}, OrdDate))`;
- insertSql1 = `,InStockDate=DATEADD(D, ${diffDay}, InStockDate),PlanStartDate=DATEADD(D, ${diffDay}, PlanStartDate),week='WK' + cast([dbo].fn_GetWeekNumber(DATEADD(D, ${diffDay}, PlanStartDate),1)
- as nvarchar(10)) `;
- }
- else if (duedate <= orddate) {
- insertSql = `,DueDate=DATEADD(D, ${diffDay + 2}, OrdDate)`;
- insertSql1 = `,InStockDate=DATEADD(D, ${diffDay + 2}, InStockDate)`;
- }
- let sql = `UPDATE WorkOrdMaster SET Eff='${currentDate}', LotSerial='${lotserial}'${insertSql} WHERE Domain='${factory_id}' AND WorkOrd='${workord}';UPDATE ReplenishmentWeekPlan SET ProductionBatch='${lotserial}'${insertSql1} WHERE ProductionOrder='${workord}';UPDATE WorkOrdRouting SET QtyOrded=${QtyOrded} WHERE WorkOrd='${workord}';`;
- utils.execdb("dopflow", sql).then((res) => {
- if (res.success) {
- utils.msg("更新成功,即将下达工单,请稍后。", true);
- programrun_programcomponentref.value.dialogShow = false;//关闭编辑窗口
- programrun_programcomponentref.value.loadData(false);//重新加载列表数据
- sql = `SELECT COUNT(*) rst FROM b_examine_result WHERE morder_no='${workord}'`;
- let res1 = utils.getSelectvalue2("dopflow", sql, sysConfig['SERVER_APIADDRESS']);
- if (res1.data > 0) {
- $.ajax({
- url: "https://dop.rapids.genesismedtech.com:9998/api/business/resource-examine/ProduceWorkOrdKittingCheck?workord=" + workord + "&domain=" + factory_id + "&userAccount=" + user,
- dataType: "text",
- type: "get",
- success: function (result) {
- if (result == "ok") {
- utils.msg("工单下达完成。", true);
- }
- else {
- utils.msg("工单下达失败:" + result, false);
- }
- },
- error: function (err) {
- console.log(err);
- utils.msg("工单下达失败,请联系管理员。", false);
- }
- });
- }
- else {
- utils.msg("请先对当前工单进行在库检。", false);
- }
- }
- else {
- utils.msg("更新失败,请联系管理员。", false);
- }
- });
- }
- }
- else {
- if (msg4 != "") {
- utils.msg(`${msg4}`, false);
- }
- else if (msg2 != "") {
- utils.msg(`${msg2.substring(1)},无法下达,请在对应明细列表手动维护`, false);
- }
- else if (msg3 != "") {
- utils.msg(`${msg3},无法下达`, false);
- }
- else {
- utils.msg(`${msg.substring(1)}不能为空`, false);
- }
- }
|