| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- package saorderdetail;
- import baseclass.PaoCust;
- import baseclass.tools.GetFieldsName;
- import baseclass.tools.Math;
- import p2.pao.PaoRemote;
- import p2.pao.PaoSet;
- import p2.pao.PaoSetRemote;
- import p2.util.P2AppException;
- import p2.util.P2Exception;
- import saorder.saorder;
- import tinvoiceapply.tinvoiceapply;
- import titem.titem;
- import java.util.Calendar;
- import java.util.Date;
- public class saorderdetail extends PaoCust {
- public saorderdetail(PaoSet arg0) {
- super(arg0);
- }
- @Override
- public void add() throws P2Exception {
- super.add();
- saorder saorder = (saorder) getOwner();
- setValue("fsonum", saorder.getString("fsonum"));
- setValue("fagentnum", saorder.getString("fagentnum"));
- setValue("ftype", saorder.getString("ftype"), 11L);
- setValue("frownum", getThisPaoSet().count() + 1);
- setValue("fpromnum", saorder.getString("fpromnum"));
- setValue("fparentid", saorder.getUniqueIDValue());
- }
- @Override
- public void delete(long l) throws P2Exception {
- super.delete(l);
- getOwner().setValue("changedate", getDate(), 11L);
- }
- @Override
- protected void save() throws P2Exception {
- super.save();
- if (getOwner() instanceof saorder) {
- saorder saorder = (saorder) getOwner();
- if (!getBoolean("fisration") && getDouble("fqty") == 0 && "新建".equals(saorder.getString("fstatus"))) {
- setValue("fqty", 1);
- }
- if (toBeAdded()) {
- if ("定制订单".equals(saorder.getString("ftype"))) {
- PaoSetRemote saorder_customizedset = getPaoSet("saorder_customized");
- if (saorder_customizedset.isEmpty()) {
- PaoSetRemote titem_customizedset = getPaoSet("titem_customized");
- int i = 0;
- PaoRemote pao = null;
- while ((pao = titem_customizedset.getPao(i)) != null) {
- PaoRemote saorder_customized = saorder_customizedset.addAtEnd();
- saorder_customized.setValue("titem_customizedid", pao.getUniqueIDValue(), 11L);
- saorder_customized.setValue("fitemno", pao.getString("fitemno"), 11L);
- saorder_customized.setValue("fname", pao.getString("fname"), 11L);
- saorder_customized.setValue("fnotes", pao.getString("fnotes"), 11L);
- saorder_customized.setValue("ftype", pao.getString("ftype"), 11L);
- saorder_customized.setValue("fvalue", pao.getString("fvalue"), 11L);
- i++;
- }
- }
- }
- }
- }
- }
- @Override
- public void init() throws P2Exception {
- super.init();
- try {
- if (!toBeAdded()) {
- if (getOwner() != null && getOwner() instanceof saorder) {
- String fstatus = getOwner().getString("fstatus");
- if (!"新建".equals(fstatus)) {
- PaoRemote vars = getSysVars();
- String fupdateavlqtytime = vars.getString("fupdateavlqtytime");
- String app = getOwner().getThisPaoSet().getApp();
- String fupdatebaltime = getSysVars().getString("fupdatebaltime");
- String fupdatfreeztime = getSysVars().getString("fupdatfreeztime");
- if (!"saorder0".equalsIgnoreCase(app)
- || !"提交".equals(fstatus)
- || "订单提交".equals(fupdateavlqtytime)
- || "订单提交".equals(fupdatebaltime) || "订单提交".equals(fupdatfreeztime)) {
- //1、不是订单管理应用,非新建状态下只读
- //2、非新建或者提交状态下均为只读。
- //3、提交的时候进行账户扣款或者冻结的为只读
- //4、提交的时候进行可销售量扣减的为只读
- setFieldFlag(new GetFieldsName(getName()).getFields(),
- READONLY, true);
- }
- if ("提交".equals(fstatus) && "工具借出单".equals(getOwner().getString("ftype"))) {
- setFieldFlag(new String[]{"fprice", "famount", "frateprice", "frateamount"}, READONLY, false);
- setFieldFlag(new String[]{"fprice", "famount", "frateprice", "frateamount"}, REQUIRED, true);
- }
- if ("提交".equals(fstatus)) {
- setFieldFlag(new String[]{"fplandate", "fnotes"}, READONLY, false);
- }
- if ("审核".equals(fstatus) || "关闭".equals(fstatus)) {
- double frateprice = getDouble("frateprice");//订单单价
- double frateamount = getDouble("frateamount");//订单金额
- double freturnqty = getDouble("freturnqty");//订单退货金额
- double fwriteoffamount_order = getDouble("fwriteoffamount");//订单已核销金额
- setValue("funwriteoffamount", Math.sub(Math.sub(frateamount, Math.mul(freturnqty, frateprice, 2)), fwriteoffamount_order), 11L);
- }
- } else {
- PaoSetRemote titemSet = getPaoSet("titem");
- if (!getBoolean("fisration")) {
- if (!getOwner().getPaoSet("saorderdetail_view2").isEmpty()) {
- setFieldFlag(new String[]{"fqty", "fpackqty", "frationnum"}, READONLY, true);
- } else {
- setFieldFlag(new String[]{"fqty", "fpackqty"}, READONLY, false);
- setFieldFlag("frationnum", READONLY, titemSet.isEmpty() || !titemSet.getPao(0).getBoolean("fisrationmag"));
- }
- }
- if (!titemSet.isEmpty()) {
- setFieldFlag("fneeddate", READONLY, !titemSet.getPao(0).getBoolean("fissaleday"));
- }
- }
- if ("欠款发货".equals(getOwner().getString("fborrowtype"))) {
- setFieldFlag("fprice", READONLY, true);
- setFieldFlag("famount", READONLY, true);
- }
- }
- }
- if (getOwner() instanceof saorder) {
- if ("打包促销".equals(getOwner().getString("tpromotions.ftype"))) {
- setFieldFlag("fqty", READONLY, true);
- setFieldFlag("fpackqty", READONLY, true);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- public void fieldAction(Object paoField, String fieldname)
- throws P2Exception {
- super.fieldAction(paoField, fieldname);
- if ("FQTY".equals(fieldname)) {
- PaoSetRemote titem = getPaoSet("titem");
- double fqty = getDouble("fqty");
- //非辅材或者配件数量修改时,计算起订量和批量增量
- if (!getBoolean("fisration")) {
- if ("促销订单".equals(getOwner().getString("ftype"))) {
- //促销商品表
- PaoSetRemote tpromproducts = getPaoSet("tpromproducts");
- if (!tpromproducts.isEmpty()) {
- double fsaleminqty = tpromproducts.getPao(0).getDouble("fsaleminqty");
- double fsaleaddqty = tpromproducts.getPao(0).getDouble("fsaleaddqty");
- fqty = caculateQty(fqty, fsaleminqty, fsaleaddqty);
- setValue("fqty", fqty, 11L);
- }
- } else if ("标准订单".equals(getOwner().getString("ftype"))) {
- double fsaleminqty = titem.getPao(0).getDouble("fsaleminqty");
- double fsaleaddqty = titem.getPao(0).getDouble("fsaleaddqty");
- fqty = caculateQty(fqty, fsaleminqty, fsaleaddqty);
- setValue("fqty", fqty, 11L);
- }
- }
- fqty = getDouble("fqty");
- setValue("famount", fqty * getDouble("fprice"));
- setValue("frateamount", fqty * getDouble("frateprice"));
- setValue("fundeliqty", fqty, 11L);
- //每包数量
- double fpackingqty = titem.getPao(0).getDouble("fpackingqty");
- setValue("fpackqty", fqty / fpackingqty, 11L);
- } else if ("FPACKQTY".equals(fieldname)) {
- PaoSetRemote titem = getPaoSet("titem");
- double fpackqty = getDouble("fpackqty");
- //每包数量
- double fpackingqty = titem.getPao(0).getDouble("fpackingqty");
- setValue("fqty", fpackqty * fpackingqty, 2L);
- } else if ("FPRICE".equals(fieldname)) {
- double fqty = getDouble("fqty");
- double fprice = getDouble("fprice");
- setValue("frateprice", getDouble("fprice"));
- setValue("famount", fqty * fprice);
- setValue("frateamount", fqty * fprice);
- } else if ("FRATEPRICE".equals(fieldname)) {
- double fqty = getDouble("fqty");
- double frateprice = getDouble("frateprice");
- setValue("frateamount", fqty * frateprice);
- } else if ("FRATEAMOUNT".equals(fieldname)) {
- double fqty = getDouble("fqty");
- double frateamount = getDouble("frateamount");
- if (getDouble("fmjamount") != 0 || getDouble("fflamount") != 0) {
- setValue("frateprice", frateamount / fqty, 11L);
- } else {
- setValue("frateprice", getDouble("fprice"), 11L);
- }
- } else if ("FMJAMOUNT".equals(fieldname)) {
- double famount = getDouble("famount");
- double fmjamount = getDouble("fmjamount");
- double fflamount = getDouble("fflamount");
- if (fmjamount == 0 && fflamount == 0) {
- setValue("frateamount", famount);
- } else {
- setValue("frateamount", Math.add(famount, Math.add(-fmjamount, -fflamount)));
- }
- } else if ("FFLAMOUNT".equals(fieldname)) {
- double famount = getDouble("famount");
- double fmjamount = getDouble("fmjamount");
- double fflamount = getDouble("fflamount");
- if (fmjamount == 0 && fflamount == 0) {
- setValue("frateamount", famount);
- } else {
- setValue("frateamount", Math.add(famount, Math.add(-fmjamount, -fflamount)));
- }
- } else if ("FITEMNO".equals(fieldname)) {
- PaoSetRemote titemset = getPaoSet("titem");
- if (!titemset.isEmpty()) {
- titem titem = (titem) titemset.getPao(0);
- if (titem.getBoolean("fissaleday") && "NB".equals(getString("siteid"))) {
- setValue("fneeddate", getDate(), 11L);
- }
- /**
- * 牌价
- */
- double foldprice = titem.getCardPriceByAagentnum(getString("fagentnum"));
- /**
- * 销售价
- */
- double fprice = titem.getAgentSalePrice(getString("fagentnum"));
- if (getOwner() instanceof saorder && "欠款发货".equals(getOwner().getString("fborrowtype"))) {
- setValue("fprice", 0, 2L);
- setValue("frateprice", 0, 2L);
- } else {
- setValue("fprice", fprice);
- setValue("frateprice", fprice);
- }
- setValue("foldprice", foldprice, 11L);
- setValue("fitemname", titem.getString("fitemname"), 11L);
- setValue("fmodel", titem.getString("fmodel"), 11L);
- setValue("funitid", titem.getString("funitid"), 11L);
- setValue("fspec", titem.getString("fspec"), 11L);
- /*此处待改进,考虑经销商及方案审核状态过滤*/
- if (titem.getBoolean("fisrationmag")) {
- String ftype = getString("ftype");
- StringBuffer sql = new StringBuffer();
- sql.append("exists (select frationnum from tration where fordertype1=1 and fstatus='审核'and frationnum=titem_ration.frationnum) ");
- 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") + "'))");
- PaoSetRemote titem_ration = titem.getPaoSet("titem_ration");
- if ("标准订单".equals(ftype)) {
- titem_ration.setWhere(sql.toString());
- } else if ("特殊订单".equals(ftype)) {
- titem_ration.setWhere(sql.toString().replace("fordertype1", "fordertype2"));
- } else if ("促销订单".equals(ftype)) {
- titem_ration.setWhere(sql.toString().replace("fordertype1", "fordertype3"));
- } else if ("定制订单".equals(ftype)) {
- titem_ration.setWhere(sql.toString().replace("fordertype1", "fordertype4"));
- } else {
- titem_ration.setWhere("1=2");
- }
- titem_ration.reset();
- if (!titem_ration.isEmpty()) {
- setValue("frationqty", titem_ration.getPao(0).getDouble("frationqty"), 11L);
- setValue("frationnum", titem_ration.getPao(0).getString("frationnum"), 11L);
- setValue("frationtype", titem_ration.getPao(0).getString("frationtype"), 11L);
- setValue("frationminqty", titem_ration.getPao(0).getDouble("frationminqty"), 11L);
- setValue("frationismincaculate", titem_ration.getPao(0).getBoolean("frationismincaculate"), 11L);
- }
- }
- } else {
- setValue("fprice", 0);
- }
- }
- }
- @Override
- public void fieldValidate(Object paoField, String fieldname)
- throws P2Exception {
- super.fieldValidate(paoField, fieldname);
- if (!toBeAdded() && "FAMOUNT".equals(fieldname)) {
- if (getDouble("fqty") == 0) {
- throw new P2AppException("", "数量不能为0");
- }
- }
- if ("FPRICE".equals(fieldname)) {
- if (getOwner() instanceof saorder && "工具借出单".equals(getOwner().getString("ftype")) && "款到发货".equals(getOwner().getString("fborrowtype"))) {
- if (getDouble(fieldname) <= 0) {
- throw new P2AppException("", "款到发货,单价必须大于0");
- }
- }
- if (getDouble(fieldname) < 0) {
- throw new P2AppException("", "单价不可小于0");
- }
- }
- if ("FCHANGEQTY".equals(fieldname)) {
- double fundeliqty = getDouble("fundeliqty");
- double FCHANGEQTY = getDouble(fieldname);
- double foldqty = getDouble("fqty");
- if (FCHANGEQTY >= foldqty) {
- throw new P2AppException("", "修改数量必须小于原订单数量" + foldqty);
- }
- if (FCHANGEQTY< Math.sub(foldqty, fundeliqty)) {
- throw new P2AppException("", "修改数量必须大于等于已发货数量" + Math.sub(foldqty, fundeliqty));
- }
- if (FCHANGEQTY < 0) {
- throw new P2AppException("", "修改数量不可小于0");
- }
- }
- }
- @Override
- public PaoSetRemote fieldGetlist(Object paoField, PaoSetRemote list,
- String fieldname) throws P2Exception {
- PaoSetRemote paoset = super.fieldGetlist(paoField, list, fieldname);
- //配送方案过滤
- if ("frationnum".equalsIgnoreCase(fieldname)) {
- if (!getPaoSet("titem").isEmpty() && getPaoSet("titem").getPao(0).getBoolean("fisrationmag")) {
- StringBuffer sql = new StringBuffer();
- sql.append("exists (select frationnum from tration where fordertype1=1 and fstatus='审核'and frationnum=titem_ration.frationnum) ");
- 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") + "'))");
- String ftype = getString("ftype");
- if ("标准订单".equals(ftype)) {
- paoset.setWhere(sql.toString());
- } else if ("特殊订单".equals(ftype)) {
- paoset.setWhere(sql.toString().replace("fordertype1", "fordertype2"));
- } else if ("促销订单".equals(ftype)) {
- paoset.setWhere(sql.toString().replace("fordertype1", "fordertype3"));
- } else if ("定制订单".equals(ftype)) {
- paoset.setWhere(sql.toString().replace("fordertype1", "fordertype4"));
- } else {
- paoset.setWhere("1=2");
- }
- } else {
- paoset.setWhere("1=2");
- }
- paoset.reset();
- }
- return paoset;
- }
- /**
- * 获取产品交期
- *
- * @return
- * @throws P2Exception
- */
- public Date getItemSaleDay() throws P2Exception {
- int fsaleday = getPaoSet("titem")
- .getPao(0).getInt("fsaleday");
- Calendar calendar = Calendar.getInstance();
- calendar.add(Calendar.DATE, fsaleday);
- return calendar.getTime();
- }
- }
|