saorderdetail.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. package saorderdetail;
  2. import baseclass.PaoCust;
  3. import baseclass.tools.GetFieldsName;
  4. import baseclass.tools.Math;
  5. import p2.pao.PaoRemote;
  6. import p2.pao.PaoSet;
  7. import p2.pao.PaoSetRemote;
  8. import p2.util.P2AppException;
  9. import p2.util.P2Exception;
  10. import saorder.saorder;
  11. import tinvoiceapply.tinvoiceapply;
  12. import titem.titem;
  13. import java.util.Calendar;
  14. import java.util.Date;
  15. public class saorderdetail extends PaoCust {
  16. public saorderdetail(PaoSet arg0) {
  17. super(arg0);
  18. }
  19. @Override
  20. public void add() throws P2Exception {
  21. super.add();
  22. saorder saorder = (saorder) getOwner();
  23. setValue("fsonum", saorder.getString("fsonum"));
  24. setValue("fagentnum", saorder.getString("fagentnum"));
  25. setValue("ftype", saorder.getString("ftype"), 11L);
  26. setValue("frownum", getThisPaoSet().count() + 1);
  27. setValue("fpromnum", saorder.getString("fpromnum"));
  28. setValue("fparentid", saorder.getUniqueIDValue());
  29. }
  30. @Override
  31. public void delete(long l) throws P2Exception {
  32. super.delete(l);
  33. getOwner().setValue("changedate", getDate(), 11L);
  34. }
  35. @Override
  36. protected void save() throws P2Exception {
  37. super.save();
  38. if (getOwner() instanceof saorder) {
  39. saorder saorder = (saorder) getOwner();
  40. if (!getBoolean("fisration") && getDouble("fqty") == 0 && "新建".equals(saorder.getString("fstatus"))) {
  41. setValue("fqty", 1);
  42. }
  43. if (toBeAdded()) {
  44. if ("定制订单".equals(saorder.getString("ftype"))) {
  45. PaoSetRemote saorder_customizedset = getPaoSet("saorder_customized");
  46. if (saorder_customizedset.isEmpty()) {
  47. PaoSetRemote titem_customizedset = getPaoSet("titem_customized");
  48. int i = 0;
  49. PaoRemote pao = null;
  50. while ((pao = titem_customizedset.getPao(i)) != null) {
  51. PaoRemote saorder_customized = saorder_customizedset.addAtEnd();
  52. saorder_customized.setValue("titem_customizedid", pao.getUniqueIDValue(), 11L);
  53. saorder_customized.setValue("fitemno", pao.getString("fitemno"), 11L);
  54. saorder_customized.setValue("fname", pao.getString("fname"), 11L);
  55. saorder_customized.setValue("fnotes", pao.getString("fnotes"), 11L);
  56. saorder_customized.setValue("ftype", pao.getString("ftype"), 11L);
  57. saorder_customized.setValue("fvalue", pao.getString("fvalue"), 11L);
  58. i++;
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. @Override
  66. public void init() throws P2Exception {
  67. super.init();
  68. try {
  69. if (!toBeAdded()) {
  70. if (getOwner() != null && getOwner() instanceof saorder) {
  71. String fstatus = getOwner().getString("fstatus");
  72. if (!"新建".equals(fstatus)) {
  73. PaoRemote vars = getSysVars();
  74. String fupdateavlqtytime = vars.getString("fupdateavlqtytime");
  75. String app = getOwner().getThisPaoSet().getApp();
  76. String fupdatebaltime = getSysVars().getString("fupdatebaltime");
  77. String fupdatfreeztime = getSysVars().getString("fupdatfreeztime");
  78. if (!"saorder0".equalsIgnoreCase(app)
  79. || !"提交".equals(fstatus)
  80. || "订单提交".equals(fupdateavlqtytime)
  81. || "订单提交".equals(fupdatebaltime) || "订单提交".equals(fupdatfreeztime)) {
  82. //1、不是订单管理应用,非新建状态下只读
  83. //2、非新建或者提交状态下均为只读。
  84. //3、提交的时候进行账户扣款或者冻结的为只读
  85. //4、提交的时候进行可销售量扣减的为只读
  86. setFieldFlag(new GetFieldsName(getName()).getFields(),
  87. READONLY, true);
  88. }
  89. if ("提交".equals(fstatus) && "工具借出单".equals(getOwner().getString("ftype"))) {
  90. setFieldFlag(new String[]{"fprice", "famount", "frateprice", "frateamount"}, READONLY, false);
  91. setFieldFlag(new String[]{"fprice", "famount", "frateprice", "frateamount"}, REQUIRED, true);
  92. }
  93. if ("提交".equals(fstatus)) {
  94. setFieldFlag(new String[]{"fplandate", "fnotes"}, READONLY, false);
  95. }
  96. if ("审核".equals(fstatus) || "关闭".equals(fstatus)) {
  97. double frateprice = getDouble("frateprice");//订单单价
  98. double frateamount = getDouble("frateamount");//订单金额
  99. double freturnqty = getDouble("freturnqty");//订单退货金额
  100. double fwriteoffamount_order = getDouble("fwriteoffamount");//订单已核销金额
  101. setValue("funwriteoffamount", Math.sub(Math.sub(frateamount, Math.mul(freturnqty, frateprice, 2)), fwriteoffamount_order), 11L);
  102. }
  103. } else {
  104. PaoSetRemote titemSet = getPaoSet("titem");
  105. if (!getBoolean("fisration")) {
  106. if (!getOwner().getPaoSet("saorderdetail_view2").isEmpty()) {
  107. setFieldFlag(new String[]{"fqty", "fpackqty", "frationnum"}, READONLY, true);
  108. } else {
  109. setFieldFlag(new String[]{"fqty", "fpackqty"}, READONLY, false);
  110. setFieldFlag("frationnum", READONLY, titemSet.isEmpty() || !titemSet.getPao(0).getBoolean("fisrationmag"));
  111. }
  112. }
  113. if (!titemSet.isEmpty()) {
  114. setFieldFlag("fneeddate", READONLY, !titemSet.getPao(0).getBoolean("fissaleday"));
  115. }
  116. }
  117. if ("欠款发货".equals(getOwner().getString("fborrowtype"))) {
  118. setFieldFlag("fprice", READONLY, true);
  119. setFieldFlag("famount", READONLY, true);
  120. }
  121. }
  122. }
  123. if (getOwner() instanceof saorder) {
  124. if ("打包促销".equals(getOwner().getString("tpromotions.ftype"))) {
  125. setFieldFlag("fqty", READONLY, true);
  126. setFieldFlag("fpackqty", READONLY, true);
  127. }
  128. }
  129. } catch (Exception e) {
  130. e.printStackTrace();
  131. }
  132. }
  133. @Override
  134. public void fieldAction(Object paoField, String fieldname)
  135. throws P2Exception {
  136. super.fieldAction(paoField, fieldname);
  137. if ("FQTY".equals(fieldname)) {
  138. PaoSetRemote titem = getPaoSet("titem");
  139. double fqty = getDouble("fqty");
  140. //非辅材或者配件数量修改时,计算起订量和批量增量
  141. if (!getBoolean("fisration")) {
  142. if ("促销订单".equals(getOwner().getString("ftype"))) {
  143. //促销商品表
  144. PaoSetRemote tpromproducts = getPaoSet("tpromproducts");
  145. if (!tpromproducts.isEmpty()) {
  146. double fsaleminqty = tpromproducts.getPao(0).getDouble("fsaleminqty");
  147. double fsaleaddqty = tpromproducts.getPao(0).getDouble("fsaleaddqty");
  148. fqty = caculateQty(fqty, fsaleminqty, fsaleaddqty);
  149. setValue("fqty", fqty, 11L);
  150. }
  151. } else if ("标准订单".equals(getOwner().getString("ftype"))) {
  152. double fsaleminqty = titem.getPao(0).getDouble("fsaleminqty");
  153. double fsaleaddqty = titem.getPao(0).getDouble("fsaleaddqty");
  154. fqty = caculateQty(fqty, fsaleminqty, fsaleaddqty);
  155. setValue("fqty", fqty, 11L);
  156. }
  157. }
  158. fqty = getDouble("fqty");
  159. setValue("famount", fqty * getDouble("fprice"));
  160. setValue("frateamount", fqty * getDouble("frateprice"));
  161. setValue("fundeliqty", fqty, 11L);
  162. //每包数量
  163. double fpackingqty = titem.getPao(0).getDouble("fpackingqty");
  164. setValue("fpackqty", fqty / fpackingqty, 11L);
  165. } else if ("FPACKQTY".equals(fieldname)) {
  166. PaoSetRemote titem = getPaoSet("titem");
  167. double fpackqty = getDouble("fpackqty");
  168. //每包数量
  169. double fpackingqty = titem.getPao(0).getDouble("fpackingqty");
  170. setValue("fqty", fpackqty * fpackingqty, 2L);
  171. } else if ("FPRICE".equals(fieldname)) {
  172. double fqty = getDouble("fqty");
  173. double fprice = getDouble("fprice");
  174. setValue("frateprice", getDouble("fprice"));
  175. setValue("famount", fqty * fprice);
  176. setValue("frateamount", fqty * fprice);
  177. } else if ("FRATEPRICE".equals(fieldname)) {
  178. double fqty = getDouble("fqty");
  179. double frateprice = getDouble("frateprice");
  180. setValue("frateamount", fqty * frateprice);
  181. } else if ("FRATEAMOUNT".equals(fieldname)) {
  182. double fqty = getDouble("fqty");
  183. double frateamount = getDouble("frateamount");
  184. if (getDouble("fmjamount") != 0 || getDouble("fflamount") != 0) {
  185. setValue("frateprice", frateamount / fqty, 11L);
  186. } else {
  187. setValue("frateprice", getDouble("fprice"), 11L);
  188. }
  189. } else if ("FMJAMOUNT".equals(fieldname)) {
  190. double famount = getDouble("famount");
  191. double fmjamount = getDouble("fmjamount");
  192. double fflamount = getDouble("fflamount");
  193. if (fmjamount == 0 && fflamount == 0) {
  194. setValue("frateamount", famount);
  195. } else {
  196. setValue("frateamount", Math.add(famount, Math.add(-fmjamount, -fflamount)));
  197. }
  198. } else if ("FFLAMOUNT".equals(fieldname)) {
  199. double famount = getDouble("famount");
  200. double fmjamount = getDouble("fmjamount");
  201. double fflamount = getDouble("fflamount");
  202. if (fmjamount == 0 && fflamount == 0) {
  203. setValue("frateamount", famount);
  204. } else {
  205. setValue("frateamount", Math.add(famount, Math.add(-fmjamount, -fflamount)));
  206. }
  207. } else if ("FITEMNO".equals(fieldname)) {
  208. PaoSetRemote titemset = getPaoSet("titem");
  209. if (!titemset.isEmpty()) {
  210. titem titem = (titem) titemset.getPao(0);
  211. if (titem.getBoolean("fissaleday") && "NB".equals(getString("siteid"))) {
  212. setValue("fneeddate", getDate(), 11L);
  213. }
  214. /**
  215. * 牌价
  216. */
  217. double foldprice = titem.getCardPriceByAagentnum(getString("fagentnum"));
  218. /**
  219. * 销售价
  220. */
  221. double fprice = titem.getAgentSalePrice(getString("fagentnum"));
  222. if (getOwner() instanceof saorder && "欠款发货".equals(getOwner().getString("fborrowtype"))) {
  223. setValue("fprice", 0, 2L);
  224. setValue("frateprice", 0, 2L);
  225. } else {
  226. setValue("fprice", fprice);
  227. setValue("frateprice", fprice);
  228. }
  229. setValue("foldprice", foldprice, 11L);
  230. setValue("fitemname", titem.getString("fitemname"), 11L);
  231. setValue("fmodel", titem.getString("fmodel"), 11L);
  232. setValue("funitid", titem.getString("funitid"), 11L);
  233. setValue("fspec", titem.getString("fspec"), 11L);
  234. /*此处待改进,考虑经销商及方案审核状态过滤*/
  235. if (titem.getBoolean("fisrationmag")) {
  236. String ftype = getString("ftype");
  237. StringBuffer sql = new StringBuffer();
  238. sql.append("exists (select frationnum from tration where fordertype1=1 and fstatus='审核'and frationnum=titem_ration.frationnum) ");
  239. sql.append("and (exists (select frationnum from tration where frationnum=titem_ration.frationnum and fagentauthors=1) or exists (select frationnum from tagents_ration where frationnum=titem_ration.frationnum and fagentnum='" + getOwner().getString("fagentnum") + "'))");
  240. PaoSetRemote titem_ration = titem.getPaoSet("titem_ration");
  241. if ("标准订单".equals(ftype)) {
  242. titem_ration.setWhere(sql.toString());
  243. } else if ("特殊订单".equals(ftype)) {
  244. titem_ration.setWhere(sql.toString().replace("fordertype1", "fordertype2"));
  245. } else if ("促销订单".equals(ftype)) {
  246. titem_ration.setWhere(sql.toString().replace("fordertype1", "fordertype3"));
  247. } else if ("定制订单".equals(ftype)) {
  248. titem_ration.setWhere(sql.toString().replace("fordertype1", "fordertype4"));
  249. } else {
  250. titem_ration.setWhere("1=2");
  251. }
  252. titem_ration.reset();
  253. if (!titem_ration.isEmpty()) {
  254. setValue("frationqty", titem_ration.getPao(0).getDouble("frationqty"), 11L);
  255. setValue("frationnum", titem_ration.getPao(0).getString("frationnum"), 11L);
  256. setValue("frationtype", titem_ration.getPao(0).getString("frationtype"), 11L);
  257. setValue("frationminqty", titem_ration.getPao(0).getDouble("frationminqty"), 11L);
  258. setValue("frationismincaculate", titem_ration.getPao(0).getBoolean("frationismincaculate"), 11L);
  259. }
  260. }
  261. } else {
  262. setValue("fprice", 0);
  263. }
  264. }
  265. }
  266. @Override
  267. public void fieldValidate(Object paoField, String fieldname)
  268. throws P2Exception {
  269. super.fieldValidate(paoField, fieldname);
  270. if (!toBeAdded() && "FAMOUNT".equals(fieldname)) {
  271. if (getDouble("fqty") == 0) {
  272. throw new P2AppException("", "数量不能为0");
  273. }
  274. }
  275. if ("FPRICE".equals(fieldname)) {
  276. if (getOwner() instanceof saorder && "工具借出单".equals(getOwner().getString("ftype")) && "款到发货".equals(getOwner().getString("fborrowtype"))) {
  277. if (getDouble(fieldname) <= 0) {
  278. throw new P2AppException("", "款到发货,单价必须大于0");
  279. }
  280. }
  281. if (getDouble(fieldname) < 0) {
  282. throw new P2AppException("", "单价不可小于0");
  283. }
  284. }
  285. if ("FCHANGEQTY".equals(fieldname)) {
  286. double fundeliqty = getDouble("fundeliqty");
  287. double FCHANGEQTY = getDouble(fieldname);
  288. double foldqty = getDouble("fqty");
  289. if (FCHANGEQTY >= foldqty) {
  290. throw new P2AppException("", "修改数量必须小于原订单数量" + foldqty);
  291. }
  292. if (FCHANGEQTY< Math.sub(foldqty, fundeliqty)) {
  293. throw new P2AppException("", "修改数量必须大于等于已发货数量" + Math.sub(foldqty, fundeliqty));
  294. }
  295. if (FCHANGEQTY < 0) {
  296. throw new P2AppException("", "修改数量不可小于0");
  297. }
  298. }
  299. }
  300. @Override
  301. public PaoSetRemote fieldGetlist(Object paoField, PaoSetRemote list,
  302. String fieldname) throws P2Exception {
  303. PaoSetRemote paoset = super.fieldGetlist(paoField, list, fieldname);
  304. //配送方案过滤
  305. if ("frationnum".equalsIgnoreCase(fieldname)) {
  306. if (!getPaoSet("titem").isEmpty() && getPaoSet("titem").getPao(0).getBoolean("fisrationmag")) {
  307. StringBuffer sql = new StringBuffer();
  308. sql.append("exists (select frationnum from tration where fordertype1=1 and fstatus='审核'and frationnum=titem_ration.frationnum) ");
  309. sql.append("and (exists (select frationnum from tration where frationnum=titem_ration.frationnum and fagentauthors=1) or exists (select frationnum from tagents_ration where frationnum=titem_ration.frationnum and fagentnum='" + getOwner().getString("fagentnum") + "'))");
  310. String ftype = getString("ftype");
  311. if ("标准订单".equals(ftype)) {
  312. paoset.setWhere(sql.toString());
  313. } else if ("特殊订单".equals(ftype)) {
  314. paoset.setWhere(sql.toString().replace("fordertype1", "fordertype2"));
  315. } else if ("促销订单".equals(ftype)) {
  316. paoset.setWhere(sql.toString().replace("fordertype1", "fordertype3"));
  317. } else if ("定制订单".equals(ftype)) {
  318. paoset.setWhere(sql.toString().replace("fordertype1", "fordertype4"));
  319. } else {
  320. paoset.setWhere("1=2");
  321. }
  322. } else {
  323. paoset.setWhere("1=2");
  324. }
  325. paoset.reset();
  326. }
  327. return paoset;
  328. }
  329. /**
  330. * 获取产品交期
  331. *
  332. * @return
  333. * @throws P2Exception
  334. */
  335. public Date getItemSaleDay() throws P2Exception {
  336. int fsaleday = getPaoSet("titem")
  337. .getPao(0).getInt("fsaleday");
  338. Calendar calendar = Calendar.getInstance();
  339. calendar.add(Calendar.DATE, fsaleday);
  340. return calendar.getTime();
  341. }
  342. }