73 lines
3.2 KiB
JavaScript
73 lines
3.2 KiB
JavaScript
'use strict';
|
|
|
|
const MainService = require('../main');
|
|
|
|
class stockoutServer extends MainService {
|
|
|
|
async create(data) {
|
|
const { app } = this;
|
|
|
|
let totalOrderLines = data.request.deliveryOrder.totalOrderLines || 0;
|
|
|
|
let orderLine = data.request.orderLines.orderLine;
|
|
if (orderLine.orderLineNo) {
|
|
orderLine = [ orderLine ];
|
|
}
|
|
const isSingle = totalOrderLines ? 0 : 1;
|
|
totalOrderLines = totalOrderLines || orderLine.length;
|
|
const errors = [];
|
|
const items = [];
|
|
for (let i = 0; i < orderLine.length; i++) {
|
|
const wms_stock = await app.model.StockStore.findByPk(orderLine[i].itemId);
|
|
if (!wms_stock) {
|
|
errors.push(`SKU${orderLine[i].itemId}商品《${orderLine[i].itemName}》编码《${orderLine[i].itemCode}》\n未同步推送到仓库`);
|
|
continue;
|
|
}
|
|
if (!wms_stock.stock_id) {
|
|
errors.push(`SKU${orderLine[i].itemId}商品《${orderLine[i].itemName}》编码《${orderLine[i].itemCode}》wms无对应关系\n请联系仓库关联创建商品`);
|
|
continue;
|
|
}
|
|
wms_stock.inventory_type = orderLine[i].inventoryType;
|
|
wms_stock.order_line_no = orderLine[i].orderLineNo;
|
|
wms_stock.count = orderLine[i].planQty;
|
|
wms_stock.item_id = orderLine[i].itemId;
|
|
items.push(wms_stock);
|
|
}
|
|
console.log('出库单参数:', data.request.deliveryOrder, this.appKey, this.storeId, this.warehouseId, totalOrderLines, 'QM', this.customerId, this.warehouseCode);
|
|
console.log('出库单明细:', items);
|
|
if (errors.length > 0) {
|
|
return this.fail('创建入库单失败,失败原因:\n' + errors.join('\n'));
|
|
}
|
|
/* const order = await this.ctx.service.systems.deliveryOrder.tryCreatedeliveryOrder(data.request.deliveryOrder,this.appKey, this.storeId, this.warehouseId,totalOrderLines,"QM",this.customerId,this.warehouseCode);
|
|
console.log("入库单参数",order);
|
|
if(!order.success){
|
|
return this.fail("创建入库单失败,失败原因:\n"+order.error);
|
|
}
|
|
const orderId = order.deliveryOrderId;
|
|
for (var i = 0; i < items.length; i++) {
|
|
const item = items[i];
|
|
let res = await this.ctx.service.systems.deliveryOrder.addItems(item,orderId);
|
|
console.log("“添加商品返回信息",res);
|
|
if(!res.success){
|
|
errors.push(`SKU${item.itemId}商品《${item.itemName}》编码《${item.itemCode}》入库失败,错误信息:${res.error}`);
|
|
}
|
|
}
|
|
if(errors.length>0){
|
|
await app.model.deliveryOrder.delete(orderId);//失败删除;
|
|
return this.fail("创建入库单失败,失败原因:\n"+errors.join("\n"));
|
|
}
|
|
const lineCount = await this.ctx.service.systems.deliveryOrder.getLineCount(orderId);//获取接收行数
|
|
if(lineCount==totalOrderLines){//所有行数接收完成
|
|
await this.ctx.service.systems.deliveryOrder.received(orderId,this.warehouseId,this.storeId);//接收完成
|
|
return this.success("入库单接收完毕",{deliveryOrderId:orderId});
|
|
}*/
|
|
return this.success('入库单接收中');
|
|
}
|
|
async query(data) {
|
|
console.log(data);
|
|
return this.fail('接口未完善');
|
|
}
|
|
|
|
}
|
|
module.exports = stockoutServer;
|