import { default as BaseController } from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { PurchaseDamagedOrder } from "../../entity/inbound/purchase/purchaseDamagedOrder";
|
|
/**
|
* 收货 - 收货计划单
|
*/
|
export default class DamagedOrderController extends BaseController {
|
//#region 残次品转入到预到货单
|
@Post()
|
public async toPurchaseOrder() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
let damagedOrder_Id = body.damagedOrder_Id;
|
|
try {
|
//如果预到货单存在 工单 则跳出
|
let count = await this.dbRead.count(PurchaseDamagedOrder, {
|
damagedOrder_Id: damagedOrder_Id,
|
statusText: "已转预到货单"
|
});
|
if (count > 0) {
|
this.info.msg = "残品已生成预到货订单,不允许重复操作!";
|
this.info.result = false;
|
ctx.body = this.info;
|
return;
|
}
|
let orderCode = await ctx.service.common.getCodeRegular(102); //得到预到货单自动编号
|
//#region 复制数据
|
let sql = `
|
--复制主表数据
|
INSERT INTO Purchase_Order
|
(OrderCode,Storage_Id,StorageName,Provider_Id, ProviderCode, ProviderShortName, TotalQuantity,TotalMoney,
|
User_Id,UserTrueName,Dept_Id,DeptName,
|
StatusText,StatusID,Enable, Remark, CreateID, Creator, CreateDate,Consignor_Id,ConsignorCode,ConsignorName,
|
SourceId,TrackingNumber,OrderType,PlatUser_Id,PlatUserCode,PlatUserName,PlatCorpName,UserProduct_Id,UserProductCode,UserProductAlias)
|
SELECT '${orderCode}', Storage_Id, StorageName,
|
Provider_Id, ProviderCode,ProviderShortName, TotalQuantity,TotalMoney,
|
User_Id,UserTrueName,Dept_Id,DeptName,
|
'新建', 1, 1 AS Enable, Remark, ${userInfo.user_Id} as CreateID, '${userInfo.userTrueName}' as Creator, getdate(),
|
Consignor_Id,ConsignorCode,ConsignorName,damagedOrder_Id as SourceId,DamagedOrderCode as TrackingNumber,'残品预到货',
|
PlatUser_Id,PlatUserCode,PlatUserName,PlatCorpName,UserProduct_Id,UserProductCode,UserProductAlias
|
FROM Purchase_DamagedOrder
|
WHERE damagedOrder_Id=${damagedOrder_Id};`;
|
|
sql += `
|
--获取主表主键ID
|
declare @order_Id int;
|
SELECT @order_Id = IDENT_CURRENT('Purchase_Order');`;
|
|
sql += `
|
--复制明细数据
|
INSERT INTO Purchase_OrderList
|
(Order_Id, Product_Id,ProductCode, ProductName, ProductModel,ProductSpec,RelationCode,
|
Quantity,PurchasePrice,PurchaseMoney,BatchNumber,ProduceDate,SmallUnit,Enable,Remark, CreateID, Creator, CreateDate)
|
SELECT @order_Id AS Order_Id, Product_Id,ProductCode, ProductName, ProductModel,ProductSpec,
|
RelationCode,Quantity,PurchasePrice,
|
PurchaseMoney,BatchOrder,ProductDate,SmallUnit,1 AS Enable,Remark,
|
${userInfo.user_Id} as CreateID, '${userInfo.userTrueName}' as Creator, getdate()
|
FROM Purchase_DamagedOrderList
|
WHERE damagedOrder_Id=${damagedOrder_Id};`;
|
|
sql += "select @order_Id as order_Id";
|
sql = "Begin Tran\r\n" + sql + "\r\n";
|
sql += " If @@Error <> 0 RollBack Tran Else Commit Tran";
|
let resultData = await this.dbWrite.query(sql);
|
//#endregion
|
let newOrder_Id = resultData[0].order_Id;
|
if (newOrder_Id && newOrder_Id > 0) {
|
await this.dbWrite.update(PurchaseDamagedOrder, damagedOrder_Id, {
|
statusID: 3,
|
statusText: "已转预到货单"
|
});
|
|
this.info.msg = "转入到预到货单成功!";
|
this.info.result = true;
|
} else {
|
this.info.msg = "转入到预到货单失败!";
|
this.info.result = false;
|
}
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|