Ben Lin
2024-07-16 5a4d79d9765dfca8812638b57d5f5fe21f7a06ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
import { buildUUID } from '../../../utils/uuid';
import { ApiAction, ApiActionPage } from '../../model/baseModel';
import {
  TransferPageListGetResultModel,
  TransferDetailPageListGetResultModel,
  TransferDetailSNPageListGetResultModel,
  TransferPageParams,
  TransferdtlPageParams,
  TransferdtlsnPageParams,
  TransferDetailListItem
} from '../model/warehoueseModel';
import { genAction, Api, genActionPage } from '../system';
import { useUserStore } from '/@/store/modules/user';
import { formatToDateTime } from '/@/utils/dateUtil';
import { defHttp } from '/@/utils/http/axios';
import { isNullOrEmpty } from '/@/utils/is';
 
/*
 * 获取调拨单分页列表
 */
export const getTransferListByPage = async (params: TransferPageParams) => {
  let order = ''
  if (params.order != undefined) {
    order = params.order == 'descend' ? (params.field + ' desc') : params.field
  }
  let sqlcmd = '1=1';
  if (params?.BILLCODE != undefined && params?.BILLCODE != '') {
    sqlcmd += " And BILLCODE like '%" + params?.BILLCODE + "%'";
  }
  if (params?.BILLDATE != undefined && params?.BILLDATE != '') {
    sqlcmd += " And BILLDATE > '" + params?.BILLDATE[0] + "'";
  }
  if (!isNullOrEmpty(params?.BILLDATE)) {
    sqlcmd += " And BILLDATE < '" + params?.BILLDATE[1] + "'";
  }
  // if (!isNullOrEmpty(params?.STATUS)) {
  //   sqlcmd += " And STATUS = '" + params?.STATUS + "'";
  // }
  if (!isNullOrEmpty(params?.STATUS)) {
    sqlcmd += " And STATUS = '" + params?.STATUS + "'";
  }
  // if (params?.BILLDATE != undefined && params?.BILLDATE != '') {
  //   sqlcmd += "And BILLDATE like '%" + params?.BILLDATE + "%'";
  // }
  let option = {
    UserId:useUserStore().getUserInfo.userId as string,
    ByOrg:true,
    OrgCode:useUserStore().getUserInfo.orgCode as string
  }
  if(!isNullOrEmpty(params.page)){
    const usParams = genAction('BIZ_WMS_TRANSFER', {
      QueryAble_T: '',
      where: sqlcmd,
      order: isNullOrEmpty(order)?'UPDATE_TIME desc':'UPDATE_TIME, '+order,
      page: {
        pageAble_T: 'string',
        draw: 1,
        pageIndex: params.page,
        pageSize: params.pageSize,
      },
      option
    },option);
    return getTransferListByPageAsync(usParams);
  }else{
    const usParams = genAction('BIZ_WMS_TRANSFER', {
      QueryAble_T: '',
      where: sqlcmd,
      option
    },option);
    return getTransferListByPageAsync(usParams);
  }
  // const rParams = genActionPage('BIZ_WMS_TRANSFER', sqlcmd, params.page, params.pageSize, option);
  // return getTransferListByPageAsync(rParams);
};
async function getTransferListByPageAsync(params: any) {
  const data = await defHttp.post(
    { url: Api.QueryUrl, params },
    {
      isTransformResponse: false,
    },
  );
  let model = {}
  if(isNullOrEmpty(data.Data.page)){
     model = {
      items: data.Data.Items,
    };
  }else{
      model = {
      items: data.Data.page.data,
      total: data.Data.page.totals,
    };
  }
  
  return model;
}
//单据详情
export const getTransferDetailListByPage = async (params: TransferdtlPageParams) => {
  let order = ''
  if (params.order != undefined) {
    order = params.order == 'descend' ? (params.field + ' desc') : params.field
  }
  let sqlcmd = '1=1';
  if (params?.BILLCODE != undefined && params?.BILLCODE != '') {
    sqlcmd += " And BILLCODE like '%" + params?.BILLCODE + "%'";
  }
  if (params?.ITEM_CODE != undefined && params?.ITEM_CODE != '') {
    sqlcmd += " And ITEM_CODE like '%" + params?.ITEM_CODE + "%'";
  }
  // if (params?.OUTWAREHOUSECODE != undefined && params?.OUTWAREHOUSECODE != '') {
  //   sqlcmd += " And OUTWAREHOUSECODE = '" + params?.OUTWAREHOUSECODE + "'";
  // }
  // if (params?.INWAREHOUSECODE != undefined && params?.INWAREHOUSECODE != '') {
  //   sqlcmd += " And INWAREHOUSECODE = '" + params?.INWAREHOUSECODE + "'";
  // }
  // if (!isNullOrEmpty(params?.LINESTATUS)) {
  //   sqlcmd += " And LINESTATUS = '" + params?.LINESTATUS + "'";
  // }
  var option ={
    UserId:useUserStore().getUserInfo.userId as string,
    ByOrg:true,
    OrgCode:useUserStore().getUserInfo.orgCode as string
  }
  // const rParams = genActionPage('BIZ_WMS_TRANSFER_DTL', sqlcmd, params.page, params.pageSize,option);
 
  if(!isNullOrEmpty(params.page)){
    const usParams = genAction('V_BIZ_WMS_TRANSFER_DTL', {
      QueryAble_T: '',
      where: sqlcmd,
      order: 'BILLLINE*1'+order,
      page: {
        pageAble_T: 'string',
        draw: 1,
        pageIndex: params.page,
        pageSize: params.pageSize,
      },
      option
    },option);
    return getTransferDetailListByPageAsync(usParams);
  }else{
    const usParams = genAction('V_BIZ_WMS_TRANSFER_DTL', {
      QueryAble_T: '',
      where: sqlcmd,
      option
    },option);
    return getTransferDetailListByPageAsync(usParams);
  }
};
async function getTransferDetailListByPageAsync(params: any) {
  const data = await defHttp.post(
    { url: Api.QueryUrl, params },
    {
      isTransformResponse: false,
    },
  );
  let model = {}
  if(isNullOrEmpty(data.Data.page)){
     model = {
      items: data.Data.Items,
    };
  }else{
      model = {
      items: data.Data.page.data,
      total: data.Data.page.totals,
    };
  }
  
  return model;
}
// async function getTransferDetailListByPageAsync(params: ApiActionPage) {
//   const data = await defHttp.post<ApiActionPage>(
//     { url: Api.EntityPageList, params },
//     {
//       isTransformResponse: false,
//     },
//   );
//   const model: TransferDetailPageListGetResultModel = {
//     items: data.Data.data,
//     total: data.Data.totals,
//   };
//   return model;
// }
//条码详情
export const getTransferDetailSNListByPage = async (params: TransferdtlsnPageParams) => {
  let order = ''
  if (params.order != undefined) {
    order = params.order == 'descend' ? (params.field + ' desc') : params.field
  }
  let sqlcmd = '1=1';
  if (params?.ITEM_CODE != undefined && params?.ITEM_CODE != '') {
    sqlcmd += " And ITEM_CODE like '%" + params?.ITEM_CODE + "%'";
  }
  if (params?.BILLCODE != undefined && params?.BILLCODE != '') {
    sqlcmd += " And BILLCODE  like '%" + params?.BILLCODE + "%'";
  }
  if (params?.SN != undefined && params?.SN != '') {
    sqlcmd += " And SN like '%" + params?.SN + "%'";
  }
  if (!isNullOrEmpty(params?.LINESTATUS)) {
    sqlcmd += " And LINESTATUS = '" + params?.LINESTATUS + "'";
  }
  // if (params?.BILLDATE != undefined && params?.BILLDATE != '') {
  //   sqlcmd += "And BILLDATE like '%" + params?.BILLDATE + "%'";
  // }
  var option ={
    UserId:useUserStore().getUserInfo.userId as string,
    ByOrg:true,
    OrgCode:useUserStore().getUserInfo.orgCode as string
  }
  if(!isNullOrEmpty(params.page)){
    const usParams = genAction('BIZ_WMS_TRANSFER_SN', {
      QueryAble_T: '',
      where: sqlcmd,
      order: order,
      page: {
        pageAble_T: 'string',
        draw: 1,
        pageIndex: params.page,
        pageSize: params.pageSize,
      },
      option
    },option);
    return getTransferDetailSNListByPageAsync(usParams);
  }else{
    const usParams = genAction('BIZ_WMS_TRANSFER_SN', {
      QueryAble_T: '',
      where: sqlcmd,
      option
    },option);
    return getTransferDetailSNListByPageAsync(usParams);
  }
  // const rParams = genActionPage('BIZ_WMS_TRANSFER_SN', sqlcmd, params.page, params.pageSize,option);
  // return getTransferDetailSNListByPageAsync(rParams);
};
async function getTransferDetailSNListByPageAsync(params: any) {
  const data = await defHttp.post(
    { url: Api.QueryUrl, params },
    {
      isTransformResponse: false,
    },
  );
  let model = {}
  if(isNullOrEmpty(data.Data.page)){
     model = {
      items: data.Data.Items,
    };
  }else{
      model = {
      items: data.Data.page.data,
      total: data.Data.page.totals,
    };
  }
  
  return model;
}
//保存
export const AddTransfer = async (params: any) => {
  let data;
  {
    params.ID = buildUUID(); //生成GUID
    params.CREATE_USER = useUserStore().getUserInfo.userId;
    params.UPDATE_USER = useUserStore().getUserInfo.userId;
    params.AUTH_ORG = useUserStore().getUserInfo.orgCode;
    params.UPDATE_TIME=formatToDateTime(new Date());
    const Transfer = {
      ID: params.ID,
      //SEQ_NO: params.SEQ_NO,
      CREATE_USER: params.CREATE_USER,
      UPDATE_USER: params.UPDATE_USER,
      UPDATE_TIME: params.UPDATE_TIME,
      BILLDATE:params.UPDATE_TIME,
      AUTH_ORG: params.AUTH_ORG,
      BILLCODE:params.BILLCODE,
      INWAREHOUSECODE:params.INWAREHOUSECODE,
      OUTWAREHOUSECODE:params.OUTWAREHOUSECODE,
      STATUS:params.STATUS,
      REMARK:params.REMARK,
      ERP_BILL_CODE:'不过帐'
    };
    data = await defHttp.post(
      { url: Api.AddEntity, params: genAction('BIZ_WMS_TRANSFER', Transfer) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  }
  return data;
}
export const AddTransferDtl = async (paramsDtl: any,params:any) => {
  let TransferDtls=[];
  let data;
  {
    paramsDtl.forEach(element => {
      const TransferDtl :TransferDetailListItem = {
        ID: element.ID,
        //SEQ_NO: params.SEQ_NO,
        CREATE_USER: element.CREATE_USER,
        UPDATE_USER: element.UPDATE_USER,
        UPDATE_TIME: formatToDateTime(new Date()),
        AUTH_ORG: element.AUTH_ORG,
        OUTWAREHOUSECODE:params.OUTWAREHOUSECODE,
        INWAREHOUSECODE:params.INWAREHOUSECODE,
        BILLCODE:params.BILLCODE,
        ITEM_CODE:element.ITEM_CODE,
        //ITEM_NAME:element.ITEM_NAME,
        BILLLINE:element.BILLLINE,
        // INQTY:params.INQTY,
        // OUTQTY:params.OUTQTY,
        PRQTY:element.PRQTY,
        UNITCODE:element.UNITCODE,
        ERP_BILL_CODE:'不过帐'
      };
      TransferDtls.push(TransferDtl)
    });
    
    data = await defHttp.post(
      { url: Api.AddListEntity, params: genAction('BIZ_WMS_TRANSFER_DTL', TransferDtls) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  }
  return data;
}
//生成调拨单单据
export const CreateBillCode = async () => {
  const data = await defHttp.get<any>(
    { url: Api.GetCreateTFBillCode },
    {
      isTransformResponse: false,
    },
  );
  return data.Data
}
//下拉列表
// STATUSs 单据状态
export const optionsListApi = async (params: Recordable) => {
  const usParams = genAction('BIZ_WMS_TRANSFER+STATUSs', '');
  var data = await defHttp.post(
    { url: Api.urlQueryEnum, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
      // apiUrl: globSetting.taskApiUrl
    },
  );
  return data;
};
// export const optionTypeListApi = async (params: Recordable) => {
//   const usParams = genAction('BIZ_WMS_TRANSFER+BIZTYPEs', '');
//   return await defHttp.post(
//     { url: Api.urlQueryEnum, params: usParams },
//     {
//       errorMessageMode: 'none',
//       isTransformResponse: false,
//       // apiUrl: globSetting.taskApiUrl
//     },
//   );
// };