uo_inware_other.sru 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. $PBExportHeader$uo_inware_other.sru
  2. forward
  3. global type uo_inware_other from uo_inware
  4. end type
  5. end forward
  6. global type uo_inware_other from uo_inware
  7. end type
  8. global uo_inware_other uo_inware_other
  9. forward prototypes
  10. public function integer acceptmx (s_inwaremx s_mx, ref string arg_msg)
  11. public function integer save (boolean arg_ifcommit, ref string arg_msg)
  12. end prototypes
  13. public function integer acceptmx (s_inwaremx s_mx, ref string arg_msg);Long rslt = 1,cnt = 0,ls_i
  14. Decimal ld_planprice,ld_cost,ld_cost_notax,ld_dftsptprice
  15. Decimal ld_noauditqty,ld_bootqty
  16. String ls_relcode,ls_unit,ls_saletaskcode
  17. Int li_iflimitprice
  18. Dec ld_round = 100
  19. uo_spt_price uo_sptprice
  20. uo_sptprice = Create uo_spt_price
  21. IF it_newbegin = False And it_updatebegin = False THEN
  22. rslt = 0
  23. arg_msg = "非编辑状态不可以使用,操作取消"
  24. GOTO ext
  25. END IF
  26. //清除空值
  27. IF IsNull(s_mx.printid) THEN s_mx.printid = 0
  28. IF IsNull(s_mx.mtrlid) THEN s_mx.mtrlid = 0
  29. IF IsNull(s_mx.mtrlcode) THEN s_mx.mtrlcode = ''
  30. IF IsNull(s_mx.plancode) THEN s_mx.plancode = ''
  31. IF IsNull(s_mx.status) THEN s_mx.status = ''
  32. IF IsNull(s_mx.uqty) THEN s_mx.uqty = 0
  33. IF IsNull(s_mx.addqty) THEN s_mx.addqty = 0
  34. IF IsNull(s_mx.packqty) THEN s_mx.packqty = 0
  35. IF IsNull(s_mx.uprice) THEN s_mx.uprice = 0
  36. IF IsNull(s_mx.rebate) THEN s_mx.rebate = 0
  37. IF IsNull(s_mx.mxdscrp) THEN s_mx.mxdscrp = ''
  38. IF IsNull(s_mx.mxdscrp2) THEN s_mx.mxdscrp2 = ''
  39. IF IsNull(s_mx.mxdscrp3) THEN s_mx.mxdscrp3 = ''
  40. IF IsNull(s_mx.mxdscrp4) THEN s_mx.mxdscrp4 = ''
  41. IF IsNull(s_mx.jgprice) THEN s_mx.jgprice = 0
  42. IF IsNull(s_mx.ifrel) THEN s_mx.ifrel = 0
  43. IF IsNull(s_mx.relid) THEN s_mx.relid = 0
  44. IF IsNull(s_mx.relprintid) THEN s_mx.relprintid = 0
  45. IF IsNull(s_mx.mxdscrp) THEN s_mx.woodcode = ''
  46. IF IsNull(s_mx.pcode) THEN s_mx.pcode = ''
  47. IF IsNull(s_mx.sptid) THEN s_mx.sptid = 0
  48. IF IsNull(s_mx.mtrlcuscode) THEN s_mx.mtrlcuscode = ''
  49. IF IsNull(s_mx.unit) THEN s_mx.unit = ''
  50. IF IsNull(s_mx.rate) THEN s_mx.rate = 1
  51. IF s_mx.rate = 0 THEN s_mx.rate = 1
  52. IF IsNull(s_mx.formula) THEN s_mx.formula = ''
  53. IF IsNull(s_mx.waredscrp) THEN s_mx.waredscrp = ''
  54. IF mrate = 0 THEN mrate = 1
  55. IF IsNull(s_mx.tax) THEN s_mx.tax = 0
  56. IF IsNull(s_mx.buyqty) THEN s_mx.buyqty = 0
  57. IF IsNull(s_mx.uprice_notax) THEN s_mx.uprice_notax = 0
  58. IF s_mx.uprice_notax = 0 THEN
  59. s_mx.uprice_notax = s_mx.uprice / (1 + s_mx.tax)
  60. END IF
  61. s_mx.uqty = Round(s_mx.uqty,5)
  62. s_mx.addqty = Round(s_mx.addqty,5)
  63. IF sys_option_outware_if_buyqty = 1 And billtype = 1 THEN //采购 , 采购数与进仓数分离
  64. ELSE //不分离
  65. s_mx.buyqty = s_mx.uqty
  66. END IF
  67. IF s_mx.mtrlid = 0 Or (s_mx.buyqty = 0 And s_mx.uqty = 0 And s_mx.addqty = 0) THEN
  68. rslt = 1
  69. GOTO ext
  70. END IF
  71. IF acceptmx_chk(s_mx, arg_msg) = 0 THEN
  72. rslt = 0
  73. GOTO ext
  74. END IF
  75. //检查物料id
  76. SELECT unit,planprice,iflimitprice
  77. INTO :ls_unit,:ld_planprice,:li_iflimitprice
  78. FROM u_mtrldef
  79. Where u_mtrldef.mtrlid = :s_mx.mtrlid Using commit_transaction ;
  80. IF commit_transaction.SQLCode <> 0 THEN
  81. rslt = 0
  82. arg_msg = "第" + String(s_mx.printid) + "行,查询物料资料信息失败,编码:"+s_mx.mtrlcode
  83. GOTO ext
  84. END IF
  85. //确实有=1的情况
  86. //IF ls_unit <> s_mx.unit And s_mx.rate = 1 THEN
  87. // arg_msg = "第" + String(s_mx.printid) + "行,库存单位与采购单位不同,但转换率为1,请检查!"
  88. // rslt = 0
  89. // GOTO ext
  90. //END IF
  91. IF ls_unit = s_mx.unit And s_mx.rate <> 1 THEN
  92. arg_msg = "第" + String(s_mx.printid) + "行,库存单位与采购单位相同,但转换率不为1,请检查!"
  93. rslt = 0
  94. GOTO ext
  95. END IF
  96. //查询采购限价并检查进仓价
  97. IF billtype = 1 Or billtype = 4 THEN
  98. IF li_iflimitprice = 1 THEN
  99. IF uo_sptprice.uf_check_price_save(thflag,sptid,s_mx.mtrlid,s_mx.mtrlcode,s_mx.unit,s_mx.status,s_mx.woodcode,s_mx.pcode,s_mx.uprice * s_mx.rebate,arg_msg) = 0 THEN
  100. arg_msg = "第" + String(s_mx.printid) + "行," + arg_msg
  101. rslt = 0
  102. GOTO ext
  103. END IF
  104. END IF
  105. END IF
  106. Int li_if_cus_mtrlware, li_if_plancode, li_inwaretype
  107. IF sys_option_hide_ware = 0 THEN
  108. SELECT balctype , if_plancode, inwaretype
  109. INTO :li_if_cus_mtrlware, :li_if_plancode, :li_inwaretype
  110. FROM u_storage
  111. Where storageid = :storageid;
  112. IF sqlca.SQLCode <> 0 THEN
  113. arg_msg = "第" + String(s_mx.printid) + "行,查询仓库是否使用客户库存失败"
  114. rslt = 0
  115. GOTO ext
  116. END IF
  117. END IF
  118. //关于客户库存处理,sptid
  119. Long ll_cusid
  120. Int li_bhflag
  121. IF dxflag = 0 THEN
  122. IF li_if_cus_mtrlware = 1 THEN
  123. IF billtype = 3 THEN
  124. //特殊情况 20140104
  125. //生产进仓单,按订单进仓的产品,如果订单的客户为 备货客户, 进仓时不按客户库存;
  126. IF s_mx.ifrel > 0 THEN
  127. IF s_mx.relid = 0 THEN
  128. arg_msg = "第" + String(s_mx.printid) + '行,请先择相应的销售订单'
  129. rslt = 0
  130. GOTO ext
  131. END IF
  132. SELECT top 1 cusid INTO :ll_cusid
  133. FROM u_saletaskmx,u_saletask
  134. WHERE u_saletaskmx.scid = u_saletask.scid
  135. AND u_saletaskmx.taskid = u_saletask.taskid
  136. AND u_saletaskmx.scid = :scid
  137. AND u_saletaskmx.taskid = :s_mx.relid
  138. AND u_saletaskmx.printid = :s_mx.relprintid
  139. AND u_saletaskmx.mtrlid = :s_mx.mtrlid
  140. Using commit_transaction;
  141. IF commit_transaction.SQLCode <> 0 THEN
  142. arg_msg = "第" + String(s_mx.printid) + '行,查询销售订单客户资料失败,'+commit_transaction.SQLErrText
  143. rslt = 0
  144. GOTO ext
  145. END IF
  146. // s_mx.mtrlid 以后有可能是 下级的生产物料!!!!
  147. IF IsNull(ll_cusid) THEN ll_cusid = 0
  148. IF ll_cusid > 0 THEN
  149. SELECT bhflag INTO :li_bhflag FROM u_cust WHERE cusid = :ll_cusid
  150. Using commit_transaction;
  151. IF commit_transaction.SQLCode <> 0 THEN
  152. arg_msg = "第" + String(s_mx.printid) + '行,查询销售订单客户资料失败,'+commit_transaction.SQLErrText
  153. rslt = 0
  154. GOTO ext
  155. END IF
  156. ELSE
  157. li_bhflag = 0
  158. END IF
  159. IF IsNull(li_bhflag) THEN li_bhflag = 0
  160. IF li_bhflag = 1 THEN
  161. s_mx.sptid = 0
  162. ELSE
  163. s_mx.sptid = s_mx.sptid
  164. END IF
  165. END IF
  166. ELSE
  167. s_mx.sptid = s_mx.sptid
  168. END IF
  169. ELSE
  170. s_mx.sptid = 0
  171. END IF
  172. ELSE
  173. IF li_if_cus_mtrlware <> 1 THEN
  174. arg_msg = "仓库没有使用客户库存,不能建立代销单据"
  175. rslt = 0
  176. GOTO ext
  177. END IF
  178. s_mx.sptid = sptid
  179. END IF
  180. CHOOSE CASE billtype
  181. CASE 1 //采购
  182. IF s_mx.ifrel > 0 THEN
  183. IF s_mx.relid = 0 THEN
  184. arg_msg = "第" + String(s_mx.printid) + "行,请先择相应的订单!"
  185. rslt = 0
  186. GOTO ext
  187. END IF
  188. SELECT taskcode ,uqty - consignedqty,
  189. CASE when u_buytask.billtype = 1 THEN u_buytaskmx.relcode ELSE '' END
  190. INTO :ls_relcode,:ld_bootqty,:ls_saletaskcode
  191. FROM u_buytaskmx,u_buytask
  192. WHERE u_buytaskmx.taskid = u_buytask.taskid
  193. AND u_buytaskmx.scid = u_buytask.scid
  194. AND u_buytaskmx.scid = :scid
  195. AND u_buytaskmx.taskid = :s_mx.relid
  196. AND u_buytaskmx.printid = :s_mx.relprintid
  197. Using commit_transaction;
  198. IF commit_transaction.SQLCode <> 0 THEN
  199. arg_msg = "第" + String(s_mx.printid) + "行,查询采购订单是否有订购:"+s_mx.mtrlcode+'失败!'+commit_transaction.SQLErrText
  200. rslt = 0
  201. GOTO ext
  202. END IF
  203. //查相关销售订单已开单数
  204. ld_noauditqty = 0
  205. SELECT sum(uqty) INTO :ld_noauditqty
  206. FROM u_inwaremx
  207. WHERE scid = :scid
  208. AND relid = :s_mx.relid
  209. AND relprintid = :s_mx.relprintid
  210. And inwareid <> :inwareid;
  211. IF sqlca.SQLCode <> 0 THEN
  212. arg_msg = "第" + String(s_mx.printid) + "行,查询"+s_mx.mtrlcode+'相关订单单据已开单数失败!'
  213. rslt = 0
  214. GOTO ext
  215. END IF
  216. IF IsNull(ld_noauditqty) THEN ld_noauditqty = 0
  217. ELSE
  218. s_mx.relid = 0
  219. s_mx.relprintid = 0
  220. END IF
  221. CASE 3 //生产
  222. IF s_mx.ifrel > 0 THEN
  223. IF s_mx.relid = 0 THEN
  224. arg_msg = "第" + String(s_mx.printid) + '行,请先择相应的销售订单'
  225. rslt = 0
  226. GOTO ext
  227. END IF
  228. SELECT top 1 taskcode INTO :ls_relcode
  229. FROM u_saletaskmx,u_saletask
  230. WHERE u_saletaskmx.scid = u_saletask.scid
  231. AND u_saletaskmx.taskid = u_saletask.taskid
  232. AND u_saletaskmx.scid = :scid
  233. AND u_saletaskmx.taskid = :s_mx.relid
  234. AND u_saletaskmx.printid = :s_mx.relprintid
  235. AND u_saletaskmx.mtrlid = :s_mx.mtrlid
  236. Using commit_transaction;
  237. IF commit_transaction.SQLCode <> 0 THEN
  238. arg_msg = "第" + String(s_mx.printid) + '行,查询销售订单是否有排产:'+s_mx.mtrlcode+'失败,'+commit_transaction.SQLErrText
  239. rslt = 0
  240. GOTO ext
  241. END IF
  242. ELSE
  243. s_mx.relid = 0
  244. s_mx.relprintid = 0
  245. END IF
  246. CASE 4 //外协
  247. IF s_mx.ifrel > 0 THEN
  248. IF s_mx.relid = 0 THEN
  249. arg_msg = "第" + String(s_mx.printid) + '行,请先择相应的外协订单'
  250. rslt = 0
  251. GOTO ext
  252. END IF
  253. SELECT u_order_wfjg.taskcode,
  254. CASE when u_order_wfjg.billtype = 1 THEN u_order_wfjgmx.relcode ELSE '' END
  255. INTO :ls_relcode,:ls_saletaskcode
  256. FROM u_order_wfjgmx,u_order_wfjg
  257. WHERE u_order_wfjgmx.scid = u_order_wfjg.scid
  258. AND u_order_wfjgmx.wfjgid = u_order_wfjg.wfjgid
  259. AND u_order_wfjgmx.wfjgid = :s_mx.relid
  260. AND u_order_wfjgmx.printid = :s_mx.relprintid
  261. AND u_order_wfjgmx.mtrlid = :s_mx.mtrlid
  262. AND u_order_wfjgmx.status = :s_mx.status
  263. AND u_order_wfjgmx.woodcode = :s_mx.woodcode
  264. AND u_order_wfjgmx.pcode = :s_mx.pcode
  265. Using commit_transaction;
  266. IF commit_transaction.SQLCode <> 0 THEN
  267. arg_msg = "第" + String(s_mx.printid) + '行,查询外协订单是否有加工:'+s_mx.mtrlcode+'失败,'+commit_transaction.SQLErrText
  268. rslt = 0
  269. GOTO ext
  270. END IF
  271. END IF
  272. END CHOOSE
  273. //处理plancode
  274. storage_plancode_flag = 0
  275. IF li_if_plancode = 0 THEN //不使用
  276. s_mx.plancode = ''
  277. ELSE
  278. IF thflag <> 1 THEN //退货不处理
  279. IF li_inwaretype = 1 THEN //无(不变)
  280. //inwaremx[it_mxbt].plancode = s_mx.plancode
  281. ELSEIF li_inwaretype = 2 THEN //价格
  282. s_mx.plancode = String(Round(s_mx.uprice * s_mx.rebate,5))
  283. ELSEIF li_inwaretype = 3 THEN //订单
  284. IF ls_relcode <> '' And billtype = 3 THEN
  285. s_mx.plancode = ls_relcode
  286. ELSEIF ls_saletaskcode <> '' And (billtype = 1 Or billtype = 4 ) THEN
  287. s_mx.plancode = ls_saletaskcode
  288. ELSE
  289. s_mx.plancode = s_mx.plancode //(不变)
  290. END IF
  291. ELSEIF li_inwaretype = 5 THEN //进仓单号
  292. storage_plancode_flag = 1 //仓库中是否设置了使用 “进仓单号” 作为批号
  293. ELSEIF li_inwaretype = 6 THEN //数值
  294. s_mx.plancode = String(s_mx.uqty,'#,##0.####')
  295. ELSEIF li_inwaretype = 7 THEN //日期时间顺序
  296. IF s_mx.plancode = '' THEN
  297. s_mx.plancode = String(Today(), 'yymmddhhmm') + '-' + String(s_mx.printid)
  298. END IF
  299. END IF
  300. END IF //退货不处理
  301. END IF
  302. //处理 sptmtrlname
  303. String ls_sptmtrlname
  304. IF billtype = 1 THEN
  305. IF uo_sptprice.uf_getmtrlname(sptid,s_mx.mtrlid,ls_sptmtrlname,arg_msg) = 0 THEN
  306. rslt = 0
  307. GOTO ext
  308. END IF
  309. ELSE
  310. ls_sptmtrlname = ""
  311. END IF
  312. //处理价格===============================
  313. //取默认报价
  314. IF billtype = 1 THEN
  315. f_get_defsptprice(sptid,s_mx.mtrlid,s_mx.unit,s_mx.status,s_mx.pcode,s_mx.woodcode,ld_dftsptprice)
  316. ELSE
  317. ld_dftsptprice = 0
  318. END IF
  319. //不是自动的单价
  320. IF sysautobuild = False THEN
  321. IF s_mx.uprice * s_mx.rebate < 0 THEN //检查进仓价
  322. rslt = 0
  323. arg_msg = "第" + String(s_mx.printid) + '行,' + String(s_mx.mtrlcode)+" 单价错误"
  324. GOTO ext
  325. END IF
  326. END IF
  327. IF s_mx.tax < 0 THEN
  328. rslt = 0
  329. arg_msg = "税率不能为负数"
  330. GOTO ext
  331. END IF
  332. //检查成本价调整单
  333. Long ll_mtrlwareid
  334. IF sys_option_hide_ware = 0 THEN
  335. SELECT mtrlwareid
  336. INTO :ll_mtrlwareid
  337. FROM u_mtrlware
  338. WHERE ( mtrlid = :s_mx.mtrlid ) AND
  339. ( plancode = :s_mx.plancode ) AND
  340. ( storageid = :storageid ) AND
  341. ( scid = :scid ) AND
  342. ( status = :s_mx.status ) AND
  343. ( sptid = :s_mx.sptid) AND
  344. ( dxflag = :dxflag) AND
  345. ( woodcode = :s_mx.woodcode) AND
  346. ( pcode = :s_mx.pcode) Using commit_transaction;
  347. IF commit_transaction.SQLCode = -1 THEN
  348. arg_msg = "第" + String(s_mx.printid) + "行,查询库存信息失败!"
  349. rslt = 0
  350. GOTO ext
  351. END IF
  352. IF IsNull(ll_mtrlwareid) THEN ll_mtrlwareid = 0
  353. IF ll_mtrlwareid > 0 THEN
  354. IF Not (billtype = 8 And sptname = '成本价调整单审核自动生成') THEN
  355. cnt = 0
  356. SELECT count(*)
  357. INTO :cnt
  358. FROM u_updatecost,u_updatecostmx
  359. WHERE u_updatecost.wareid = u_updatecostmx.wareid AND
  360. u_updatecost.flag = 0 AND
  361. u_updatecostmx.mtrlwareid = :ll_mtrlwareid AND
  362. u_updatecost.scid = :scid Using commit_transaction;
  363. IF commit_transaction.SQLCode <> 0 THEN
  364. rslt = 0
  365. arg_msg = "第" + String(s_mx.printid) + "行,查询成本价调整单操作失败"
  366. GOTO ext
  367. END IF
  368. IF cnt > 0 THEN
  369. rslt = 0
  370. arg_msg = "第" + String(s_mx.printid) + "行," + s_mx.mtrlcode + "已开成本价调整单,请先审核"
  371. GOTO ext
  372. END IF
  373. END IF
  374. //出仓的, 查询成本价
  375. ELSE
  376. END IF
  377. END IF
  378. //s_mx.price = Round(s_mx.enprice * mrate * s_mx.rebate,10) //进仓实价, 本位币,库存单位
  379. s_mx.qty = Round(s_mx.uqty * s_mx.rate, sys_option_unit_dec) //库存单位,进仓数量
  380. //写入内容
  381. it_mxbt++
  382. inwaremx[it_mxbt].mtrlwareid = ll_mtrlwareid
  383. inwaremx[it_mxbt].printid = s_mx.printid
  384. inwaremx[it_mxbt].mtrlid = s_mx.mtrlid
  385. inwaremx[it_mxbt].mtrlcode = s_mx.mtrlcode
  386. inwaremx[it_mxbt].unit = s_mx.unit
  387. inwaremx[it_mxbt].rate = s_mx.rate
  388. inwaremx[it_mxbt].noauditqty = ld_noauditqty
  389. inwaremx[it_mxbt].bootqty = ld_bootqty
  390. inwaremx[it_mxbt].addqty = s_mx.addqty
  391. inwaremx[it_mxbt].uqty = s_mx.uqty
  392. inwaremx[it_mxbt].qty = s_mx.qty
  393. inwaremx[it_mxbt].buyqty = s_mx.buyqty
  394. inwaremx[it_mxbt].packqty = s_mx.packqty
  395. inwaremx[it_mxbt].uprice = s_mx.uprice //进仓价, 原币, 进仓单位
  396. IF s_mx.buyqty <> 0 THEN
  397. inwaremx[it_mxbt].fprice = Round((s_mx.uprice * s_mx.buyqty) /(Round(s_mx.buyqty * s_mx.rate,sys_option_unit_dec)) * mrate ,10) //进仓价, 本位币, 库存单位
  398. ELSE
  399. inwaremx[it_mxbt].fprice = Round(s_mx.uprice * s_mx.rate * mrate,10)
  400. END IF
  401. inwaremx[it_mxbt].price = Round(inwaremx[it_mxbt].fprice * s_mx.rebate,10) //进仓实价, 本位币,库存单位
  402. inwaremx[it_mxbt].rebate = s_mx.rebate
  403. inwaremx[it_mxbt].tax = s_mx.tax
  404. IF billtype = 1 THEN
  405. ld_round = 10.0 ^ (2 - sys_option_inware_buy_amt_round)
  406. IF sys_option_inware_buy_amt_round = 5 THEN ld_round = 1000
  407. END IF
  408. inwaremx[it_mxbt].uamt = Round(s_mx.buyqty * s_mx.uprice * s_mx.rebate * ld_round, 0) / ld_round //原币,实价含税金额
  409. inwaremx[it_mxbt].uamt_tax = Round((s_mx.buyqty * s_mx.uprice * s_mx.rebate) * s_mx.tax / (1 + s_mx.tax) * ld_round, 0) / ld_round //原币, 税金
  410. inwaremx[it_mxbt].bsamt = Round(s_mx.buyqty * s_mx.uprice * s_mx.rebate * mrate * ld_round, 0) / ld_round //本位币, 实价含税金额
  411. inwaremx[it_mxbt].bsamt_tax = Round((s_mx.buyqty * s_mx.uprice * s_mx.rebate * mrate) * s_mx.tax / (1 + s_mx.tax) * ld_round, 0) / ld_round //本位币, 税金
  412. inwaremx[it_mxbt].planprice = ld_planprice
  413. inwaremx[it_mxbt].jgprice = s_mx.jgprice
  414. inwaremx[it_mxbt].mxdscrp = s_mx.mxdscrp
  415. inwaremx[it_mxbt].mxdscrp2 = s_mx.mxdscrp2
  416. inwaremx[it_mxbt].mxdscrp3 = s_mx.mxdscrp3
  417. inwaremx[it_mxbt].mxdscrp4 = s_mx.mxdscrp4
  418. inwaremx[it_mxbt].dxflag = dxflag
  419. inwaremx[it_mxbt].relid = s_mx.relid
  420. inwaremx[it_mxbt].relprintid = s_mx.relprintid
  421. inwaremx[it_mxbt].ifrel = s_mx.ifrel
  422. inwaremx[it_mxbt].status = s_mx.status
  423. inwaremx[it_mxbt].woodcode = s_mx.woodcode
  424. inwaremx[it_mxbt].pcode = s_mx.pcode
  425. inwaremx[it_mxbt].relcode = ls_relcode
  426. inwaremx[it_mxbt].mtrlcuscode = s_mx.mtrlcuscode
  427. inwaremx[it_mxbt].dftsptprice = ld_dftsptprice
  428. inwaremx[it_mxbt].formula = s_mx.formula
  429. inwaremx[it_mxbt].waredscrp = s_mx.waredscrp
  430. inwaremx[it_mxbt].inworkdate = s_mx.inworkdate
  431. inwaremx[it_mxbt].plancode = s_mx.plancode
  432. inwaremx[it_mxbt].sptid = s_mx.sptid
  433. inwaremx[it_mxbt].sptmtrlname = ls_sptmtrlname //供应商别名
  434. inwaremx[it_mxbt].uprice_notax = s_mx.uprice_notax //不含税单价
  435. //IF sys_option_buyth_wareamt = 0 THEN
  436. //
  437. If (billtype = 1 And thflag = 1 And sys_option_buyth_wareamt = 0 ) &
  438. Or (s_mx.uqty < 0 And billtype <> 3 And billtype <> 1) THEN //采购退货单 或者 非采购/生产进仓
  439. SELECT cost,cost_notax
  440. INTO :ld_cost,:ld_cost_notax
  441. FROM u_mtrlware
  442. WHERE scid = :scid
  443. AND mtrlid = :s_mx.mtrlid
  444. AND storageid = :storageid
  445. AND status = :s_mx.status
  446. AND plancode = :s_mx.plancode
  447. AND woodcode = :s_mx.woodcode
  448. AND pcode = :s_mx.pcode
  449. AND dxflag = :dxflag
  450. And sptid = :s_mx.sptid;
  451. IF sqlca.SQLCode <> 0 Or IsNull(ld_cost) THEN ld_cost = 0
  452. inwaremx[it_mxbt].cost = ld_cost
  453. inwaremx[it_mxbt].cost_notax = ld_cost_notax
  454. ELSE
  455. inwaremx[it_mxbt].cost = inwaremx[it_mxbt].fprice * s_mx.rebate
  456. inwaremx[it_mxbt].cost_notax = inwaremx[it_mxbt].fprice * s_mx.rebate
  457. END IF
  458. inwaremx[it_mxbt].costamt = Round(inwaremx[it_mxbt].cost * inwaremx[it_mxbt].qty, 2) //成本金额,库存单位
  459. ext:
  460. Destroy uo_sptprice
  461. IF rslt = 0 THEN
  462. p_clearmx()
  463. arg_msg = billname + ',' + arg_msg
  464. END IF
  465. Return(rslt)
  466. end function
  467. public function integer save (boolean arg_ifcommit, ref string arg_msg);Integer rslt = 1,cnt = 0,i
  468. DateTime server_dt
  469. Long ls_newid
  470. String ls_sccode
  471. IF IsNull(relid) THEN relid = 0
  472. IF IsNull(storageid) THEN storageid = 0
  473. IF IsNull(inrep) THEN inrep = ''
  474. IF IsNull(dscrp) THEN dscrp = ''
  475. IF IsNull(part) THEN part = ''
  476. IF IsNull(sptid) THEN sptid = 0
  477. IF IsNull(sptname) THEN sptname = ''
  478. IF IsNull(dxflag) THEN dxflag = 0
  479. IF IsNull(thflag) THEN thflag = 0
  480. IF IsNull(relint_1) THEN relint_1 = 0
  481. IF IsNull(relint_2) THEN relint_2 = 0
  482. IF IsNull(relint_3) THEN relint_3 = 0
  483. IF IsNull(relint_4) THEN relint_4 = 0
  484. IF IsNull(relint_5) THEN relint_5 = 0
  485. IF IsNull(relstr_1) THEN relstr_1 = ''
  486. IF IsNull(relstr_2) THEN relstr_2 = ''
  487. IF IsNull(relstr_3) THEN relstr_3 = ''
  488. IF IsNull(mrate) THEN mrate = 0
  489. IF mrate = 0 THEN mrate = 1
  490. IF it_newbegin = False And it_updatebegin = False THEN
  491. rslt = 0
  492. arg_msg = "非编辑状态不可以提交"
  493. GOTO ext
  494. END IF
  495. SELECT Top 1 getdate() Into :server_dt From u_user Using commit_transaction ;
  496. //取得系统时间,借用操作员表
  497. IF commit_transaction.SQLCode <> 0 THEN
  498. rslt = 0
  499. arg_msg = "查询操作失败,日期 "
  500. GOTO ext
  501. END IF
  502. IF save_chk(arg_msg) = 0 THEN
  503. rslt = 0
  504. GOTO ext
  505. END IF
  506. //查找进仓原因,记录staticid
  507. select staticid into :staticid
  508. from u_static
  509. where reason = :sptname
  510. and inoutflag = 1;
  511. IF SQLCA.SQLCODE <>0 THEN
  512. staticid = 0
  513. END IF
  514. IF ISNULL(staticid) THEN staticid = 0
  515. ////////////////////////////////////////////// //开始区分:新建/更新 处理
  516. IF inwareid = 0 THEN //新建
  517. ls_newid = f_sys_scidentity(scid,"u_inware","inwareid",arg_msg,if_getid_ture,commit_transaction)
  518. IF ls_newid <= 0 THEN
  519. rslt = 0
  520. GOTO ext
  521. END IF
  522. //取分部代号
  523. IF f_get_sccode(scid,commit_transaction,ls_sccode,arg_msg) = 0 THEN
  524. rslt = 0
  525. GOTO ext
  526. END IF
  527. //取得新单据编号
  528. CHOOSE CASE billtype
  529. CASE 1,2
  530. IF thflag = 0 THEN
  531. inwarecode = getid(scid,ls_sccode + 'CG',Date(server_dt),if_getid_ture,commit_transaction)
  532. ELSE
  533. inwarecode = getid(scid,ls_sccode + 'CT',Date(server_dt),if_getid_ture,commit_transaction)
  534. END IF
  535. CASE 3
  536. inwarecode = getid(scid,ls_sccode + 'CP',Date(server_dt),if_getid_ture,commit_transaction)
  537. CASE 4
  538. IF thflag = 0 THEN
  539. inwarecode = getid(scid,ls_sccode + 'WN',Date(server_dt),if_getid_ture,commit_transaction)
  540. ELSE
  541. inwarecode = getid(scid,ls_sccode + 'WH',Date(server_dt),if_getid_ture,commit_transaction)
  542. END IF
  543. CASE 8
  544. inwarecode = getid(scid,ls_sccode + 'JC',Date(server_dt),if_getid_ture,commit_transaction)
  545. CASE 9
  546. inwarecode = getid(scid,ls_sccode + 'PY',Date(server_dt),if_getid_ture,commit_transaction)
  547. CASE 12
  548. inwarecode = getid(scid,ls_sccode + 'IC',Date(server_dt),if_getid_ture,commit_transaction)
  549. CASE 15
  550. inwarecode = getid(scid,ls_sccode + 'DC',Date(server_dt),if_getid_ture,commit_transaction)
  551. CASE 20
  552. IF thflag = 0 THEN
  553. inwarecode = getid(scid,ls_sccode + 'RI',Date(server_dt),if_getid_ture,commit_transaction)
  554. ELSE
  555. inwarecode = getid(scid,ls_sccode + 'RT',Date(server_dt),if_getid_ture,commit_transaction)
  556. END IF
  557. CASE 22
  558. inwarecode = getid(scid,ls_sccode + 'TI',Date(server_dt),if_getid_ture,commit_transaction)
  559. END CHOOSE
  560. IF inwarecode = "err" THEN
  561. inwarecode = ''
  562. rslt = 0
  563. arg_msg = "无法获取进仓单编号"+"~n"
  564. GOTO ext
  565. END IF
  566. INSERT INTO u_inware (
  567. scid,
  568. inwareid,
  569. inwarecode,
  570. billtype,
  571. relid,
  572. storageid,
  573. indate,
  574. inrep,
  575. part,
  576. dscrp,
  577. sptid,
  578. sptname,
  579. thflag,
  580. dxflag,
  581. otheramt,
  582. opdate,
  583. opemp,
  584. relint_1,
  585. relint_2,
  586. relint_3,
  587. relstr_1,
  588. relstr_2,
  589. relstr_3,
  590. mrate,
  591. relint_4,
  592. relint_5,
  593. staticid)
  594. VALUES (
  595. :scid,
  596. :ls_newid,
  597. :inwarecode,
  598. :billtype,
  599. :relid,
  600. :storageid,
  601. :indate,
  602. :inrep,
  603. :part,
  604. :dscrp,
  605. :sptid,
  606. :sptname,
  607. :thflag,
  608. :dxflag,
  609. :otheramt,
  610. :server_dt,
  611. :publ_operator,
  612. :relint_1,
  613. :relint_2,
  614. :relint_3,
  615. :relstr_1,
  616. :relstr_2,
  617. :relstr_3,
  618. :mrate,
  619. :relint_4,
  620. :relint_5,
  621. :staticid) Using commit_transaction ;
  622. IF commit_transaction.SQLCode <> 0 THEN
  623. rslt = 0
  624. IF Pos(Lower(commit_transaction.SQLErrText),'PK_u_inware') > 0 THEN
  625. arg_msg = '插入单据资料失败,关键字ID重复'
  626. ELSEIF Pos(Lower(commit_transaction.SQLErrText),'IX_u_inware') > 0 THEN
  627. arg_msg = '插入单据资料失败,单据编号重复'
  628. ELSE
  629. arg_msg = '插入单据资料失败,'+commit_transaction.SQLErrText
  630. END IF
  631. //arg_msg = "插入操作失败"+"~n"+commit_transaction.SQLErrText
  632. GOTO ext
  633. END IF
  634. //读取新inwareid
  635. inwareid = ls_newid
  636. ELSE //////////////////////////////////////////////// //更新
  637. UPDATE u_inware
  638. SET billtype = :billtype,
  639. relid = :relid,
  640. storageid = :storageid,
  641. indate = :indate,
  642. inrep = :inrep,
  643. part = :part,
  644. dscrp = :dscrp,
  645. sptid = :sptid,
  646. sptname = :sptname,
  647. thflag = :thflag,
  648. dxflag = :dxflag,
  649. otheramt = :otheramt,
  650. moddate = :server_dt,
  651. modemp = :publ_operator,
  652. relint_1 = :relint_1,
  653. relint_2 = :relint_2,
  654. relint_3 = :relint_3,
  655. relstr_1 = :relstr_1,
  656. relstr_2 = :relstr_2,
  657. relstr_3 = :relstr_3,
  658. mrate = :mrate,
  659. relint_4 = :relint_4,
  660. relint_5 = :relint_5,
  661. staticid = :staticid
  662. WHERE u_inware.inwareid = :inwareid
  663. AND u_inware.scid = :scid
  664. Using commit_transaction;
  665. IF commit_transaction.SQLCode <> 0 Or commit_transaction.SQLNRows <= 0 THEN
  666. rslt = 0
  667. IF Pos(Lower(commit_transaction.SQLErrText),'PK_u_inware') > 0 THEN
  668. arg_msg = '更新单据资料失败,关键字ID重复'
  669. ELSEIF Pos(Lower(commit_transaction.SQLErrText),'IX_u_inware') > 0 THEN
  670. arg_msg = '更新单据资料失败,单据编号重复'
  671. ELSE
  672. arg_msg = '更新单据资料失败,'+commit_transaction.SQLErrText
  673. END IF
  674. arg_msg = "更新单据操作失败"+"~n"+commit_transaction.SQLErrText
  675. GOTO ext
  676. END IF
  677. IF billtype > 1 Or billtype = 1 And flag = 0 THEN
  678. //删除原有明细
  679. DELETE FROM u_inwaremx
  680. WHERE u_inwaremx.inwareid = :inwareid
  681. And u_inwaremx.scid = :scid Using commit_transaction;
  682. IF commit_transaction.SQLCode <> 0 THEN
  683. rslt = 0
  684. arg_msg = "删除旧有单据明细操作失败"+"~n"
  685. GOTO ext
  686. END IF
  687. ELSE
  688. END IF
  689. END IF
  690. IF billtype > 1 Or billtype = 1 And flag = 0 THEN
  691. FOR i = 1 To it_mxbt
  692. IF storage_plancode_flag = 1 THEN //仓库中是否设置了使用 “进仓单号” 作为批号
  693. inwaremx[i].plancode = inwarecode
  694. END IF
  695. INSERT INTO u_inwaremx
  696. (scid,
  697. inwareid,
  698. printid,
  699. mtrlid,
  700. plancode,
  701. status,
  702. qty,
  703. addqty,
  704. packqty,
  705. fprice,
  706. rebate,
  707. price,
  708. planprice,
  709. mxdscrp,
  710. mxdscrp2,
  711. mxdscrp3,
  712. mxdscrp4,
  713. jgprice,
  714. relid,
  715. relprintid,
  716. ifrel,
  717. woodcode,
  718. relcode,
  719. pcode,
  720. sptid_cusid,
  721. cost,
  722. cost_notax,
  723. sptmtrlname,
  724. unit,
  725. rate,
  726. uprice,
  727. uqty,
  728. bootqty,
  729. noauditqty,
  730. mtrlcuscode,
  731. dftsptprice,
  732. formula,
  733. waredscrp,
  734. inworkdate,
  735. tax,
  736. buyqty,
  737. uamt,
  738. uamt_tax,
  739. bsamt,
  740. bsamt_tax,
  741. costamt,
  742. uprice_notax)
  743. VALUES (
  744. :scid,
  745. :inwareid,
  746. :inwaremx[i].printid,
  747. :inwaremx[i].mtrlid,
  748. :inwaremx[i].plancode,
  749. :inwaremx[i].status,
  750. :inwaremx[i].qty,
  751. :inwaremx[i].addqty,
  752. :inwaremx[i].packqty,
  753. :inwaremx[i].fprice,
  754. :inwaremx[i].rebate,
  755. :inwaremx[i].price,
  756. :inwaremx[i].planprice,
  757. :inwaremx[i].mxdscrp,
  758. :inwaremx[i].mxdscrp2,
  759. :inwaremx[i].mxdscrp3,
  760. :inwaremx[i].mxdscrp4,
  761. :inwaremx[i].jgprice,
  762. :inwaremx[i].relid,
  763. :inwaremx[i].relprintid,
  764. :inwaremx[i].ifrel,
  765. :inwaremx[i].woodcode,
  766. :inwaremx[i].relcode,
  767. :inwaremx[i].pcode,
  768. :inwaremx[i].sptid,
  769. :inwaremx[i].cost,
  770. :inwaremx[i].cost_notax,
  771. :inwaremx[i].sptmtrlname,
  772. :inwaremx[i].unit,
  773. :inwaremx[i].rate,
  774. :inwaremx[i].uprice,
  775. :inwaremx[i].uqty,
  776. :inwaremx[i].bootqty,
  777. :inwaremx[i].noauditqty,
  778. :inwaremx[i].mtrlcuscode,
  779. :inwaremx[i].dftsptprice,
  780. :inwaremx[i].formula,
  781. :inwaremx[i].waredscrp,
  782. :inwaremx[i].inworkdate,
  783. :inwaremx[i].tax,
  784. :inwaremx[i].buyqty,
  785. :inwaremx[i].uamt,
  786. :inwaremx[i].uamt_tax,
  787. :inwaremx[i].bsamt,
  788. :inwaremx[i].bsamt_tax,
  789. :inwaremx[i].costamt,
  790. :inwaremx[i].uprice_notax) Using commit_transaction;
  791. IF commit_transaction.SQLCode <> 0 THEN
  792. IF it_newbegin THEN inwareid = 0
  793. rslt = 0
  794. IF Pos(Lower(commit_transaction.SQLErrText),'PK_u_inwaremx') > 0 THEN
  795. arg_msg = '插入单据明细内容失败,关键字ID重复'
  796. ELSEIF Pos(Lower(commit_transaction.SQLErrText),'IX_u_inwaremx') > 0 THEN
  797. arg_msg = '插入单据明细内容失败,三个属性字段重复'
  798. ELSE
  799. arg_msg = '插入单据明细内容失败,'+commit_transaction.SQLErrText
  800. END IF
  801. GOTO ext
  802. END IF
  803. NEXT
  804. ELSE
  805. FOR i = 1 To it_mxbt
  806. UPDATE u_inWAREmx
  807. SET uprice = :inWAREmx[i].uprice,
  808. mxdscrp = :inwaremx[I].mxdscrp,
  809. mxdscrp2 = :inwaremx[I].mxdscrp2,
  810. mxdscrp3 = :inwaremx[I].mxdscrp3,
  811. mxdscrp4 = :inwaremx[I].mxdscrp4,
  812. fprice = :inwaremx[I].fprice,
  813. rebate = :inwaremx[I].rebate,
  814. price = :inwaremx[I].price,
  815. tax = :inwaremx[i].tax,
  816. uamt = :inwaremx[i].uamt,
  817. uamt_tax = :inwaremx[i].uamt_tax,
  818. bsamt = :inwaremx[i].bsamt,
  819. bsamt_tax = :inwaremx[i].bsamt_tax,
  820. uprice_notax =:inwaremx[i].uprice_notax
  821. WHERE ( scid = :scid AND
  822. inWAREid = :inwareid AND
  823. printid = :inwaremx[i].printid);
  824. IF commit_transaction.SQLCode <> 0 THEN
  825. rslt = 0
  826. arg_msg = "更新明细价格、备注操作失败"+"~n"
  827. GOTO ext
  828. END IF
  829. NEXT
  830. END IF
  831. IF save_end(arg_msg) = 0 THEN
  832. rslt = 0
  833. GOTO ext
  834. END IF
  835. it_newbegin = False
  836. it_updatebegin = False
  837. ext:
  838. IF rslt = 0 THEN
  839. ROLLBACK Using commit_transaction;
  840. p_clearmx()
  841. arg_msg = billname + ',' + arg_msg
  842. ELSEIF rslt = 1 And arg_ifcommit THEN
  843. COMMIT Using commit_transaction;
  844. END IF
  845. RETURN rslt
  846. end function
  847. on uo_inware_other.create
  848. call super::create
  849. end on
  850. on uo_inware_other.destroy
  851. call super::destroy
  852. end on