-- 库存单据字段设置-预设红蓝单-领料出库单添加转固字段
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171772308168704) 
INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FFIELDNAME, FFIELD, FENTRYENTITYID, FFULLFIELD, FISINVERSE) 
VALUES (757172464185929728, 841171772308168704, 13, '单据体.已转固数量', 'purchasedqty', 'billentry', 'billentry.purchasedqty', '1');

IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171772308168705) 
INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FFIELDNAME, FFIELD, FENTRYENTITYID, FFULLFIELD, FISINVERSE) 
VALUES (757172464185929728, 841171772308168705, 14, '单据体.未转固数量', 'remainpurqty', 'billentry', 'billentry.remainpurqty', '1');

IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171772308168706) 
INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FFIELDNAME, FFIELD, FENTRYENTITYID, FFULLFIELD, FISINVERSE) 
VALUES (757172464185929728, 841171772308168706, 15, '单据体.已转固金额', 'purchasedamount', 'billentry', 'billentry.purchasedamount', '1');

IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171772308168707) 
INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FFIELDNAME, FFIELD, FENTRYENTITYID, FFULLFIELD, FISINVERSE) 
VALUES (757172464185929728, 841171772308168707, 16, '单据体.未转固金额', 'remainpuramount', 'billentry', 'billentry.remainpuramount', '1');



IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517763) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517763, 4, 'billentry', '物料明细.单价', 'price', 'billentry.price', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517764) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517764, 5, 'billentry', '物料明细.含税单价', 'priceandtax', 'billentry.priceandtax', '1');

-- 库存单据字段设置-预设红蓝单-添加预制采购出库单支持红单
IF NOT EXISTS (SELECT 1 FROM T_IM_BILLFIELDSETTING WHERE fid = 841171415012188160) 
insert into T_IM_BILLFIELDSETTING (FID, FBILL, FSTATUS, FCREATORID, FMODIFIERID, FENABLE, FCREATETIME, FMODIFYTIME)
values (841171415012188160, 'im_purreceivebill', 'C', 1, 1, '1', {ts'2019-11-11  11:11:11'}, {ts'2019-11-11  11:11:11'});
-- 删除错误预制的单价字段
DELETE FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID in (841171415062517763, 841171415062517764); 
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517760) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517760, 1, 'billentry', '物料明细.数量', 'qty', 'billentry.qty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517761) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517761, 2, 'billentry', '物料明细.辅助数量', 'qtyunit2nd', 'billentry.qtyunit2nd', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517762) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517762, 3, 'billentry', '物料明细.数量(基本单位)', 'baseqty', 'billentry.baseqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517765) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517765, 4, 'billentry', '物料明细.金额', 'amount', 'billentry.amount', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517766) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517766, 5, 'billentry', '物料明细.金额(本位币)', 'curamount', 'billentry.curamount', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517767) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517767, 6, 'billentry', '物料明细.税额', 'taxamount', 'billentry.taxamount', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517768) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517768, 7, 'billentry', '物料明细.税额(本位币)', 'curtaxamount', 'billentry.curtaxamount', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517769) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517769, 8, 'billentry', '物料明细.价税合计', 'amountandtax', 'billentry.amountandtax', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517770) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517770, 9, 'billentry', '物料明细.价税合计(本位币)', 'curamountandtax', 'billentry.curamountandtax', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517771) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517771, 10, 'billentry', '物料明细.累计入库数量', 'invqty', 'billentry.invqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517772) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517772, 11, 'billentry', '物料明细.剩余入库数量', 'remaininvqty', 'billentry.remaininvqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517773) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517773, 12, 'billentry', '物料明细.累计入库数量(基本单位)', 'invbaseqty', 'billentry.invbaseqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517774) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517774, 13, 'billentry', '物料明细.剩余入库数量(基本单位)', 'remaininvbaseqty', 'billentry.remaininvbaseqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517775) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517775, 14, 'billentry', '物料明细.累计应付数量', 'joinpriceqty', 'billentry.joinpriceqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517776) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517776, 15, 'billentry', '物料明细.累计应付数量(基本单位)', 'joinpricebaseqty', 'billentry.joinpricebaseqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517777) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517777, 16, 'billentry', '物料明细.剩余应付数量', 'remainjoinpriceqty', 'billentry.remainjoinpriceqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517778) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517778, 17, 'billentry', '物料明细.剩余应付数量(基本单位)', 'remainjoinpricebaseqty', 'billentry.remainjoinpricebaseqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517779) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517779, 18, 'billentry', '物料明细.已核销数量', 'verifyqty', 'billentry.verifyqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517780) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517780, 19, 'billentry', '物料明细.已核销数量(基本单位)', 'verifybaseqty', 'billentry.verifybaseqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517781) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517781, 20, 'billentry', '物料明细.未核销数量', 'unverifyqty', 'billentry.unverifyqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517782) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517782, 21, 'billentry', '物料明细.未核销数量(基本单位)', 'unverifybaseqty', 'billentry.unverifybaseqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517783) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517783, 22, 'billentry', '物料明细.已转固数量', 'purchasedqty', 'billentry.purchasedqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517784) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517784, 23, 'billentry', '物料明细.未转固数量', 'remainpurqty', 'billentry.remainpurqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517785) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517785, 24, 'billentry', '物料明细.已转固价税合计（本位币）', 'purchasedamount', 'billentry.purchasedamount', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517786) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517786, 25, 'billentry', '物料明细.未转固价税合计（本位币）', 'remainpuramount', 'billentry.remainpuramount', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517787) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517787, 26, 'billentry', '物料明细.合格数量(基本单位)', 'qualifiedbaseqty', 'billentry.qualifiedbaseqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517788) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517788, 27, 'billentry', '物料明细.不合格数量', 'unqualifiedqty', 'billentry.unqualifiedqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517789) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517789, 28, 'billentry', '物料明细.不合格数量(基本单位)', 'unqualifiedbaseqty', 'billentry.unqualifiedbaseqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517790) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517790, 29, 'billentry', '物料明细.合格数量(主辅单位)', 'qualifiedunit2nd', 'billentry.qualifiedunit2nd', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517791) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517791, 30, 'billentry', '物料明细.不合格数量(主辅单位)', 'unqualifiedunit2nd', 'billentry.unqualifiedunit2nd', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 841171415062517792) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 841171415062517792, 31, 'billentry', '物料明细.合格数量', 'qualifiedqty', 'billentry.qualifiedqty', '1');
IF NOT EXISTS (SELECT 1 FROM T_IM_FIELDSETTINGENTRY WHERE FENTRYID = 843612934981896192) INSERT INTO T_IM_FIELDSETTINGENTRY (FID, FENTRYID, FSEQ, FENTRYENTITYID, FFIELDNAME, FFIELD, FFULLFIELD, FISINVERSE) VALUES (841171415012188160, 843612934981896192, 32, 'billentry', '物料明细.折扣额', 'discountamount', 'billentry.discountamount', '1');
                                                                                                                                                                                                                                                              