ficashbill.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. package ficashbill;
  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 taccbal.taccbal;
  12. import java.util.Calendar;
  13. import java.util.Date;
  14. /**
  15. * 收支凭证表主类
  16. */
  17. public class ficashbill extends PaoCust {
  18. /**
  19. * 构造函数
  20. *
  21. * @param arg0
  22. */
  23. public ficashbill(PaoSet arg0) {
  24. super(arg0);
  25. }
  26. /**
  27. * 初始化类
  28. *
  29. * @throws P2Exception
  30. */
  31. @Override
  32. public void init() throws P2Exception {
  33. super.init();
  34. if (!toBeAdded()) {
  35. /*
  36. * 非新建状态下或者该数据是其他单据生成的或者待审标记是true的情况下,将数据设为只读。
  37. */
  38. if (!"新建".equals(getString("fstatus")) || (getInt("FSOURCEID") > 0 && !getString("fsourceobject").equalsIgnoreCase(getName())) || getBoolean("FWILLCHECK")) {
  39. setFieldFlag(new GetFieldsName(getName()).getFields(), READONLY, true);
  40. if ("提交".equals(getString("fstatus"))) {
  41. setFieldFlag("fconfirmamount", READONLY, false);
  42. }
  43. }
  44. /*
  45. * 非新建状态下,将待审标记设为可编辑
  46. */
  47. if ("新建".equals(getString("fstatus"))) {
  48. setFieldFlag("FWILLCHECK", READONLY, false);
  49. }
  50. }
  51. if (getDouble("famount") > 0) {
  52. PaoSetRemote set = getPaoSet(Calendar.getInstance().getTimeInMillis() + getName(), getName(), "fstatus='审核' and ftype='" + getString("ftype") + "' and fsourceid='" + getUniqueIDValue() + "' and fsourceobject='" + getName() + "'");
  53. setValue("FUNWRITEOFFAMOUNT", getDouble("FAMOUNT") + set.sum("famount") - getDouble("FWRITEOFFAMOUNT"), 11l);
  54. }
  55. }
  56. @Override
  57. public void add() throws P2Exception {
  58. super.add();
  59. //获取当前应用名称
  60. String appname = getThisPaoSet().getApp();
  61. //设置单号编号
  62. if (appname != null) {
  63. setValue("fbillnum", getBillNum(appname));
  64. }
  65. if ("RECBILL".equals(appname)) {
  66. //如果是工厂方新建收入凭证
  67. setValue("ftype", "收入");
  68. } else if ("RECBILL2".equals(appname)) {
  69. //如果是经销商新建收入凭证,则获取该账号的归属经销商
  70. String fagentnum = getAgentnumByHrid(getUserName());
  71. setValue("fagentnum", fagentnum);
  72. //默认账户设为01
  73. setValue("faccclsnum", "01", 11L);
  74. setValue("ftype", "收入");
  75. //CREATEFLAG表示制单方,true表示工厂方,false表示客户方。默认值为true
  76. setValue("createflag", false);
  77. } else if ("RECBILL3".equals(appname)) {
  78. //返利金
  79. setValue("faccclsnum", "02", 11L);
  80. setValue("ftype", "收入");
  81. setValue("ftypemx", "返利金", 11L);
  82. } else if ("PAYBILL".equals(appname)) {
  83. //支出凭证
  84. setValue("ftype", "支出");
  85. } else if ("PAYBILL2".equals(appname)) {
  86. //支出凭证
  87. setValue("faccclsnum", "02", 11L);
  88. setValue("ftype", "支出");
  89. setValue("ftypemx", "返利金", 11L);
  90. }
  91. }
  92. @Override
  93. public void canDelete() throws P2Exception {
  94. super.canDelete();
  95. if (!"新建".equals(getString("fstatus"))) {
  96. throw new P2AppException("", "非新建状态不可删除");
  97. }
  98. if (getInt("fsourceid") > 0 && !("sendrepair".equalsIgnoreCase(getString("fsourceobject")) || (getName().equalsIgnoreCase(getString("fsourceobject"))))) {
  99. throw new P2AppException("", "该单为系统自动生成,不可删除");
  100. }
  101. if (getBoolean("fwillcheck")) {
  102. throw new P2AppException("", "待审单据不可删除,如需删除,请清除待审标记");
  103. }
  104. if (!getPaoSet("ficashbill_saorderdetail").isEmpty()) {
  105. throw new P2AppException("", "存在工具借出单表体,请先予以删除!");
  106. }
  107. }
  108. public void submitValidate(boolean issubmit) throws P2Exception {
  109. if (issubmit && !"新建".equals(getString("fstatus"))) {
  110. throw new P2AppException("", "非新建状态不可提交");
  111. }
  112. if (issubmit && getBoolean("createflag")) {
  113. throw new P2AppException("", "非经销商制单不可提交");
  114. }
  115. if (issubmit && !"RECBILL2".equalsIgnoreCase(getThisPaoSet().getApp())) {
  116. throw new P2AppException("", "非打款凭证不可提交");
  117. }
  118. if (issubmit && getDouble("famount") == 0) {
  119. throw new P2AppException("", "金额为0,不可提交");
  120. }
  121. if (!issubmit && !"提交".equals(getString("fstatus"))) {
  122. throw new P2AppException("", "非提交状态不可退回");
  123. }
  124. }
  125. @Override
  126. public void submit(boolean issubmit) throws P2Exception {
  127. setValue("fstatus", issubmit ? "提交" : "新建", 11L);
  128. setValue("submitby", issubmit ? getUserName() : "", 11L);
  129. setValue("submitdate", issubmit ? getDateTime() : null, 11L);
  130. }
  131. @Override
  132. public void checkvalidate(boolean ischeck) throws P2Exception {
  133. super.checkvalidate(ischeck);
  134. boolean createflag = getBoolean("createflag");
  135. if (createflag && !"新建".equals(getString("fstatus"))) {
  136. throw new P2AppException("", "非新建状态不可审核");
  137. }
  138. if (!createflag && !"提交".equals(getString("fstatus"))) {
  139. throw new P2AppException("", "非提交状态不可审核");
  140. }
  141. if (getBoolean("fwillcheck")) {
  142. throw new P2AppException("", "请将待审标记清除,并确认经销商及金额后再审核");
  143. }
  144. if (getDouble("famount") == 0) {
  145. throw new P2AppException("", "金额为0,不可审核");
  146. }
  147. if ("工具押金".equals(getString("ftypemxdetail")) && "收入".equals(getString("ftype"))) {
  148. PaoSetRemote ficashbill_saorderdetailSet = getPaoSet("ficashbill_saorderdetail");
  149. if (ficashbill_saorderdetailSet.isEmpty()) {
  150. throw new P2AppException("", "请选择工具借出单");
  151. }
  152. if (getDouble("famount") > 0) {
  153. //押金收取
  154. int i = 0;
  155. PaoRemote detailpao = null;
  156. while ((detailpao = ficashbill_saorderdetailSet.getPao(i)) != null) {
  157. if (detailpao.getPaoSet("saorderdetail").isEmpty()) {
  158. throw new P2AppException("", "订单行不存在!");
  159. }
  160. PaoRemote saorderdetailPao = detailpao.getPaoSet("saorderdetail").getPao(0);
  161. if (saorderdetailPao.getDouble("fprice") > 0) {
  162. throw new P2AppException("", "工具借出单" + saorderdetailPao.getString("fsonum") + "已收取押金,不可重复收取");
  163. } else if (!"审核,关闭".contains(saorderdetailPao.getPaoSet("saorder").getPao(0).getString("fstatus"))) {
  164. throw new P2AppException("", "工具借出单" + saorderdetailPao.getString("fsonum") + "已退回,不可收取");
  165. }
  166. i++;
  167. }
  168. } else {
  169. //押金退还
  170. int i = 0;
  171. PaoRemote detailpao = null;
  172. while ((detailpao = ficashbill_saorderdetailSet.getPao(i)) != null) {
  173. if (detailpao.getPaoSet("saorderdetail").isEmpty()) {
  174. throw new P2AppException("", "订单行不存在!");
  175. }
  176. PaoRemote saorderdetailPao = detailpao.getPaoSet("saorderdetail").getPao(0);
  177. if (saorderdetailPao.getDouble("fprice") == 0) {
  178. throw new P2AppException("", "工具借出单" + saorderdetailPao.getString("fsonum") + "还未收取押金,不可退回");
  179. }
  180. i++;
  181. }
  182. }
  183. }
  184. double famount = getDouble("famount");
  185. // 支出凭证
  186. if (!ischeck && famount > 0) {
  187. PaoSetRemote taccbal_viewSet = getPaoSet("taccbal_view");
  188. // 账户可用余额
  189. double fcanuseamount = taccbal_viewSet.isEmpty() ? 0 : taccbal_viewSet.getPao(0).getDouble("fcanuseamount");
  190. if (fcanuseamount < famount) {
  191. throw new P2AppException("", "单据金额大于账户可用余额" + fcanuseamount);
  192. }
  193. if ("支出".equals(getString("ftype")) && "返利金".equals(getString("ftypemx"))) {
  194. PaoSetRemote ficashbill_flSet = getPaoSet("ficashbill_fl");
  195. if (ficashbill_flSet.isEmpty()) {
  196. throw new P2AppException("", "返利代金券" + getString("fbillnum_fl") + "不存在!");
  197. }
  198. if (ficashbill_flSet.getPao(0).getDouble("fbalance") < famount) {
  199. throw new P2AppException("", "返利代金券" + getString("fbillnum_fl") + "余额不足!");
  200. }
  201. Date date = ficashbill_flSet.getPao(0).getDate("fenddate");
  202. if (date.before(getDate())) {
  203. throw new P2AppException("", "返利金代金券已过有效期");
  204. }
  205. }
  206. }
  207. if (getName().equalsIgnoreCase(getString("fsourceobject"))) {
  208. if (famount >= 0) {
  209. throw new P2AppException("", "对冲凭证必须为负数");
  210. }
  211. //原凭证
  212. PaoSetRemote cashbillset = getPaoSet(Calendar.getInstance().getTimeInMillis() + getName(), getName(), "ficashbillid=" + getLong("fsourceid"));
  213. if (cashbillset.isEmpty()) {
  214. throw new P2AppException("", "原凭证不存在");
  215. }
  216. PaoRemote cashbill = cashbillset.getPao(0);
  217. double funwriteoffamount = cashbill.getDouble("funwriteoffamount");//原凭证未核销金额
  218. if (-famount > funwriteoffamount) {
  219. throw new P2AppException("", "对冲金额绝对值必须小于原凭证未核销金额");
  220. }
  221. }
  222. }
  223. /**
  224. * 收支凭证审核
  225. *
  226. * @param isincom 是否收入,true表示为收入凭证审核,false表示为支出凭证审核
  227. * @throws P2Exception
  228. */
  229. @Override
  230. public void check(boolean isincom) throws P2Exception {
  231. deleteAssignment();
  232. super.check(isincom);
  233. // 单据金额
  234. double famount = isincom ? getDouble("famount") : -getDouble("famount");
  235. double fbillamount = famount;
  236. String faccclsnum = getString("faccclsnum");
  237. String fagentnum = getString("fagentnum");
  238. if (getSysVars().getBoolean("fisrebate") && getPaoSet("taccclass").getPao(0).getBoolean("fisrebate")) {
  239. /**
  240. * 如果当前账户需要进行返利计算
  241. */
  242. if ("收入".equals(getString("ftype"))) {
  243. /**
  244. * 收入凭证审核生成返利收入凭证
  245. */
  246. PaoSetRemote taccclass_rebateSet = getPaoSet("#taccclass_rebate", "taccclass_rebate", "frebatetime='收入凭证审核' and faccclsnum='" + faccclsnum + "'");
  247. int i = 0;
  248. while (taccclass_rebateSet.getPao(i) != null) {
  249. //返利账户
  250. String frebateaccclsnum = taccclass_rebateSet.getPao(i).getString("frebateaccclsnum");
  251. //返利比例
  252. double frebaterate = taccclass_rebateSet.getPao(i).getDouble("frebaterate");
  253. //返利金额
  254. double rebateamount = Math.mul(fbillamount, frebaterate);
  255. //如果返利账户和当前账户一致,则直接将返返利金额计算到单据金额中,同时生成一张额外到收入凭证
  256. if (frebateaccclsnum.equals(faccclsnum)) {
  257. //返利金额
  258. famount = Math.add(famount, rebateamount);
  259. } else {
  260. PaoSetRemote taccbalset = getPaoSet("$taccbal" + frebateaccclsnum, "taccbal", "faccclsnum='" + frebateaccclsnum + "' and fagentnum='" + fagentnum + "'");
  261. taccbal accpao = null;
  262. if (taccbalset.isEmpty()) {
  263. accpao = (taccbal) taccbalset.addAtEnd();
  264. accpao.setfields(fagentnum, frebateaccclsnum);
  265. } else {
  266. accpao = (taccbal) taccbalset.getPao(0);
  267. }
  268. accpao.setValue("fbalance", Math.add(accpao.getDouble("fbalance"), rebateamount));
  269. }
  270. ficashbill ficashbill = (ficashbill) getThisPaoSet().addAtEnd();
  271. ficashbill.setValues("RECBILL", fagentnum, getString("ftype"), frebateaccclsnum, getDate("fdate"),
  272. rebateamount, "收入凭证" + getString("fbillnum") + "审核时生成;" + fbillamount + "*" + frebaterate + "=" + rebateamount, getName(), getUniqueIDValue(), "审核", getDateTime(), getUserName(),
  273. getDateTime());
  274. ficashbill.setValue("ftypemx", "政策");
  275. ficashbill.setValue("ftypemxdetail", "支持");
  276. i++;
  277. }
  278. } else if ("支出".equals(getString("ftype")) && !getPaoSet("saorder").isEmpty()) {
  279. /**
  280. * 订单生成审核生成返利收入凭证
  281. */
  282. PaoSetRemote taccclass_rebateSet = getPaoSet("#taccclass_rebate", "taccclass_rebate", "frebatetime='订单扣款' and faccclsnum='" + faccclsnum + "'");
  283. int i = 0;
  284. while (taccclass_rebateSet.getPao(i) != null) {
  285. //返利账户
  286. String frebateaccclsnum = taccclass_rebateSet.getPao(i).getString("frebateaccclsnum");
  287. //返利比例
  288. double frebaterate = taccclass_rebateSet.getPao(i).getDouble("frebaterate");
  289. //返利金额
  290. double rebateamount = Math.mul(-fbillamount, frebaterate);
  291. //如果返利账户和当前账户一致,则直接将返返利金额计算到单据金额中,同时生成一张额外到收入凭证
  292. if (frebateaccclsnum.equals(faccclsnum)) {
  293. //返利金额
  294. famount = Math.add(famount, rebateamount);
  295. } else {
  296. PaoSetRemote taccbalset = getPaoSet("$taccbal" + frebateaccclsnum, "taccbal", "faccclsnum='" + frebateaccclsnum + "' and fagentnum='" + fagentnum + "'");
  297. taccbal accpao = null;
  298. if (taccbalset.isEmpty()) {
  299. accpao = (taccbal) taccbalset.addAtEnd();
  300. accpao.setfields(fagentnum, frebateaccclsnum);
  301. } else {
  302. accpao = (taccbal) taccbalset.getPao(0);
  303. }
  304. accpao.setValue("fbalance", Math.add(accpao.getDouble("fbalance"), rebateamount));
  305. }
  306. ficashbill ficashbill = (ficashbill) getThisPaoSet().addAtEnd();
  307. ficashbill.setValues("RECBILL", fagentnum, "收入", frebateaccclsnum, getDate("fdate"),
  308. rebateamount, getString("fnotes") + ";" + -fbillamount + "*" + frebaterate + "=" + rebateamount, getString("fsourceobject"), getLong("fsourceid"), "审核", getDateTime(), getUserName(),
  309. getDateTime());
  310. ficashbill.setValue("ftypemx", "政策");
  311. ficashbill.setValue("ftypemxdetail", "支持");
  312. i++;
  313. }
  314. }
  315. }
  316. PaoSetRemote taccbalset = getPaoSet("taccbal");
  317. taccbal taccbal = null;
  318. if (taccbalset.isEmpty()) {
  319. taccbal = (taccbal) taccbalset.addAtEnd();
  320. taccbal.setfields(fagentnum, faccclsnum);
  321. } else {
  322. taccbal = (taccbal) taccbalset.getPao(0);
  323. }
  324. taccbal.setValue("fbalance", Math.add(taccbal.getDouble("fbalance"), famount));
  325. PaoSetRemote ficashbill_flSet = getPaoSet("ficashbill_fl");
  326. if (!ficashbill_flSet.isEmpty()) {
  327. ficashbill_flSet.getPao(0).setValue("fbalance", Math.add(ficashbill_flSet.getPao(0).getDouble("fbalance"), famount), 2L);
  328. }
  329. if ((isincom && "收入".equals(getString("ftype"))) || (!isincom && "支出".equals(getString("ftype")))) {
  330. if(famount > 0){
  331. sendEmail(getMailBySalesGroup(getString("fagentnum"),getString("siteid")), "收入凭证", "经销商编号:"+getString("FAGENTNUM")+",客户名称:"+getString("FAGENTSHORTNAME")+",客户有新的收入,收入金额:"+famount);
  332. }
  333. setValue("ftaccbalbalance", taccbal.getDouble("fbalance"), 11L);
  334. setValue("fstatus", "审核", 11L);
  335. setValue("checkby", getUserName(), 11L);
  336. setValue("checkdate", getDateTime(), 11L);
  337. updateSaorder();
  338. } else if ((isincom && "支出".equals(getString("ftype"))) || (!isincom && "收入".equals(getString("ftype")))) {
  339. setValue("fstatus", "新建", 11L);
  340. setValue("checkby", "", 11L);
  341. setValue("checkdate", "", 11L);
  342. }
  343. }
  344. /**
  345. * 收支凭证审核
  346. *
  347. * @param isincom 是否收入,true表示为收入凭证审核,false表示为支出凭证审核
  348. * @throws P2Exception
  349. */
  350. public void check(boolean isincom, PaoRemote taccbal) throws P2Exception {
  351. super.check(isincom);
  352. // 单据金额
  353. double famount = isincom ? getDouble("famount") : -getDouble("famount");
  354. taccbal.setValue("fbalance", Math.add(taccbal.getDouble("fbalance"), famount));
  355. if ((isincom && "收入".equals(getString("ftype"))) || (!isincom && "支出".equals(getString("ftype")))) {
  356. setValue("ftaccbalbalance", taccbal.getDouble("fbalance"), 11L);
  357. setValue("fstatus", "审核", 11L);
  358. setValue("checkby", getUserName(), 11L);
  359. setValue("checkdate", getDateTime(), 11L);
  360. updateSaorder();
  361. } else if ((isincom && "支出".equals(getString("ftype"))) || (!isincom && "收入".equals(getString("ftype")))) {
  362. setValue("fstatus", "新建", 11L);
  363. setValue("checkby", "", 11L);
  364. setValue("checkdate", "", 11L);
  365. }
  366. }
  367. /**
  368. * 作废验证
  369. *
  370. * @throws P2Exception
  371. */
  372. public void cancellationvalidate() throws P2Exception {
  373. if (!"审核".equals(getString("fstatus"))) {
  374. throw new P2AppException("", "非审核状态下不可作废");
  375. }
  376. if (getLong("fsourceid") > 0) {
  377. throw new P2AppException("", "该单由其他单据生成,不可作废");
  378. }
  379. /* if (getPaoSet("TPERIOD").getPao(0).getBoolean("fisclose")) {
  380. throw new
  381. P2AppException("", "当前会计期间已关闭,不可进行此操作");
  382. }*/
  383. }
  384. /**
  385. * 作废
  386. *
  387. * @throws P2Exception
  388. */
  389. public void cancellation() throws P2Exception {
  390. // 单据金额
  391. double famount = "收入".equals(getString("ftype")) ? getDouble("famount") : -getDouble("famount");
  392. String fagentnum = getString("fagentnum");
  393. PaoSetRemote taccbalset = getPaoSet("taccbal");
  394. taccbal taccbal = null;
  395. if (taccbalset.isEmpty()) {
  396. taccbal = (taccbal) taccbalset.addAtEnd();
  397. taccbal.setfields(fagentnum, getString("faccclsnum"));
  398. } else {
  399. taccbal = (taccbal) taccbalset.getPao(0);
  400. }
  401. taccbal.setValue("fbalance", Math.sub(taccbal.getDouble("fbalance"), famount));
  402. setValue("fstatus", "作废", 11L);
  403. if ("收入".equals(getString("ftype"))) {
  404. PaoSetRemote cashbillSet = getPaoSet("$ficashbill", "ficashbill", "fstatus='审核'and fsourceobject='ficashbill' and fsourceid='" + getUniqueIDValue() + "'");
  405. int i = 0;
  406. PaoRemote cashpao = null;
  407. while ((cashpao = cashbillSet.getPao(i)) != null) {
  408. String frebateaccclsnum = cashpao.getString("faccclsnum");
  409. double rebateamount = cashpao.getDouble("famount");
  410. if (frebateaccclsnum.equals(getString("faccclsnum"))) {
  411. taccbal.setValue("fbalance", Math.sub(taccbal.getDouble("fbalance"), rebateamount));
  412. } else {
  413. PaoSetRemote rebateaccbalset = getPaoSet("$taccbal" + frebateaccclsnum, "taccbal", "faccclsnum='" + frebateaccclsnum + "' and fagentnum='" + fagentnum + "'");
  414. taccbal accpao = null;
  415. if (rebateaccbalset.isEmpty()) {
  416. accpao = (taccbal) rebateaccbalset.addAtEnd();
  417. accpao.setfields(fagentnum, frebateaccclsnum);
  418. } else {
  419. accpao = (taccbal) rebateaccbalset.getPao(0);
  420. }
  421. accpao.setValue("fbalance", Math.sub(accpao.getDouble("fbalance"), rebateamount));
  422. }
  423. cashpao.setValue("fstatus", "作废", 11L);
  424. i++;
  425. }
  426. }
  427. }
  428. public void setValues(String appname, String fagentnum, String ftype, String faccclsnum, Date fdate, double famount,
  429. String fnotes, String sourceobject, long sourceid, String fstatus, Date createdate,
  430. String checkby, Date checkdate) throws P2Exception {
  431. setValue("fbillnum", getBillNum(appname));
  432. setValue("ftype", ftype);
  433. setValue("fagentnum", fagentnum, 11L);
  434. setValue("faccclsnum", faccclsnum, 11L);
  435. setValue("fdate", fdate);
  436. setValue("famount", famount);
  437. setValue("fnotes", fnotes);
  438. setValue("fsourceobject", sourceobject);
  439. setValue("fsourceid", sourceid);
  440. setValue("fstatus", fstatus);
  441. setValue("createdate", createdate);
  442. setValue("checkby", checkby);
  443. setValue("checkdate", checkdate);
  444. }
  445. @Override
  446. public void fieldAction(Object paoField, String fieldname) throws P2Exception {
  447. super.fieldAction(paoField, fieldname);
  448. if ("FAMOUNT".equals(fieldname)) {
  449. if ("返利金".equals(getString("ftypemx"))) {
  450. setValue("fbalance", getDouble(fieldname));
  451. }
  452. }
  453. }
  454. @Override
  455. public void fieldValidate(Object paoField, String fieldname) throws P2Exception {
  456. super.fieldValidate(paoField, fieldname);
  457. if ("FAMOUNT".equals(fieldname)) {
  458. if ("返利金".equals(getString("ftypemx"))) {
  459. if (getDouble(fieldname) < 0) {
  460. throw new P2AppException("", "金额不可小于0");
  461. }
  462. }
  463. // if (getDouble(fieldname) == 0) {
  464. // throw new P2AppException("", "金额不可等于0");
  465. // }
  466. if (getName().equalsIgnoreCase(getString("fsourceobject"))) {
  467. if (getDouble(fieldname) >= 0) {
  468. throw new P2AppException("", "对冲凭证必须为负数");
  469. }
  470. //原凭证
  471. PaoSetRemote cashbillset = getPaoSet(Calendar.getInstance().getTimeInMillis() + getName(), getName(), "ficashbillid=" + getLong("fsourceid"));
  472. if (cashbillset.isEmpty()) {
  473. throw new P2AppException("", "原凭证不存在");
  474. }
  475. PaoRemote cashbill = cashbillset.getPao(0);
  476. double funwriteoffamount = cashbill.getDouble("famount");//原凭证未核销金额
  477. if (-getDouble(fieldname) > funwriteoffamount) {
  478. throw new P2AppException("", "对冲金额绝对值必须小于原凭证未核销金额");
  479. }
  480. }
  481. }
  482. }
  483. /**
  484. * 押金单添加订单
  485. *
  486. * @param saorderSet
  487. */
  488. public void addsaorders(PaoSetRemote saorderSet) throws P2Exception {
  489. PaoSetRemote ficashbill_saorderdetail = getPaoSet("ficashbill_saorderdetail");
  490. int i = 0;
  491. PaoRemote saorder = null;
  492. while ((saorder = saorderSet.getPao(i)) != null) {
  493. if (saorder.isSelected()) {
  494. PaoSetRemote saorderdetailSet = saorder.getPaoSet("saorderdetail");
  495. int n = 0;
  496. while (saorderdetailSet.getPao(n) != null) {
  497. PaoRemote newpao = ficashbill_saorderdetail.addAtEnd();
  498. newpao.setValue("ficashbillid", getUniqueIDValue());
  499. newpao.setValue("saorderid", saorder.getUniqueIDValue());
  500. newpao.setValue("saorderdetailid", saorderdetailSet.getPao(n).getUniqueIDValue());
  501. newpao.setValue("fqty", saorderdetailSet.getPao(n).getDouble("fqty"));
  502. n++;
  503. }
  504. }
  505. i++;
  506. }
  507. }
  508. /**
  509. * 押金凭证更新工具借出单
  510. */
  511. public void updateSaorder() throws P2Exception {
  512. if ("工具押金".equals(getString("ftypemxdetail")) && "收入".equals(getString("ftype")) && getDouble("famount") > 0 && !(getOwner() instanceof saorder)) {
  513. PaoSetRemote ficashbill_saorderdetail = getPaoSet("ficashbill_saorderdetail");
  514. int i = 0;
  515. PaoRemote saorderdetail = null;
  516. while ((saorderdetail = ficashbill_saorderdetail.getPao(i)) != null) {
  517. PaoSetRemote orderdetailset = saorderdetail.getPaoSet("saorderdetail");
  518. if (!orderdetailset.isEmpty()) {
  519. orderdetailset.getPao(0).setValue("fprice", saorderdetail.getDouble("fprice"), 2L);
  520. }
  521. i++;
  522. }
  523. }
  524. }
  525. public void writeoffValidate() throws P2Exception {
  526. if (!"审核".equals(getString("fstatus"))) {
  527. throw new P2AppException("", "非审核状态不可进行核销操作");
  528. }
  529. if (!"收入".equals(getString("ftype"))) {
  530. throw new P2AppException("", "非收入凭证不可进行核销操作");
  531. }
  532. if (getDouble("funwriteoffamount") == 0) {
  533. throw new P2AppException("", "未核销金额为0!");
  534. }
  535. }
  536. public long writeoff() throws P2Exception {
  537. PaoSetRemote twriteoffbillSet = getPaoSet("twriteoffbill");
  538. twriteoffbillSet.setApp("WRITEOFF");
  539. PaoRemote pao = twriteoffbillSet.addAtEnd();
  540. pao.setValue("fdate", getDate());
  541. pao.setValue("fagentnum", getString("fagentnum"));
  542. pao.setValue("ficashbillnum", getString("fbillnum"));
  543. return pao.getUniqueIDValue();
  544. }
  545. public long createredcashbill() throws P2Exception {
  546. if (!"审核".equalsIgnoreCase(getString("fstatus"))) {
  547. throw new P2AppException("", "非审核状态下不可进行对冲操作");
  548. }
  549. double famount = getDouble("famount");//凭证未核销金额
  550. if (famount <= 0) {
  551. throw new P2AppException("", "该凭证无法进行对冲操作");
  552. }
  553. double funwriteoffamount = getDouble("funwriteoffamount");//凭证未核销金额
  554. if (funwriteoffamount <= 0) {
  555. throw new P2AppException("", "当前凭证已无法进行对冲操作");
  556. }
  557. PaoSetRemote ficashbillSet = getPaoSet("$$ficashbill", "ficashbill");
  558. ficashbillSet.setApp(getThisPaoSet().getApp().toUpperCase());
  559. PaoRemote pao = ficashbillSet.addAtEnd();
  560. pao.setValue("fsourceid", getUniqueIDValue());
  561. pao.setValue("fsourceobject", "FICASHBILL");
  562. pao.setValue("fagentnum", getString("fagentnum"));
  563. pao.setValue("faccclsnum", getString("faccclsnum"));
  564. pao.setValue("ftypemx", getString("ftypemx"), 11L);
  565. pao.setValue("ftypemxdetail", getString("ftypemxdetail"), 11L);
  566. pao.setValue("fnotes", "凭证对冲", 11L);
  567. pao.setValue("fdate", getDate("fdate"));
  568. pao.setValue("famount", -funwriteoffamount);
  569. return pao.getUniqueIDValue();
  570. }
  571. }