Ejemplo n.º 1
0
  /**
   * 修改invocie
   *
   * @return
   */
  public String edit() {
    int invoiceId = Tools.String2Integer(Struts2Util.getParameter("invoiceId"));
    List<ApInvoiceLine> apInvoiceLines = null;
    try {
      apInvoice = new ApInvoice();
      apInvoice = (ApInvoice) this.apInvoiceDao.getSession().get(ApInvoice.class, invoiceId);
      apInvoice.setOldStatus(apInvoice.getStatus());
      apInvoiceLines = apInvoiceLineDao.queryInvoiceByInvoiceId(apInvoice.getInvoiceId());
      String symbol = currency_Dao.getCurrencySymbol(apInvoice.getCurrency());
      apInvoice.setSymbol(symbol);
    } catch (Exception e) {
      e.printStackTrace();
    }

    if ((null == apInvoiceLines) || (0 == apInvoiceLines.size())) {
      return "edit_invoice";
    }
    int length = apInvoiceLines.size();

    String[] itemNos = new String[length];
    String[] invoiceLineIds = new String[length];
    String[] invoiceIds = new String[length];
    String[] catalogNo = new String[length];
    String[] names = new String[length];
    String[] qtys = new String[length];
    String[] qtyUoms = new String[length];
    String[] unitPrices = new String[length];
    String[] amounts = new String[length];
    String[] taxs = new String[length];
    String[] sizes = new String[length];
    String[] lineNo = new String[length];
    String[] discounts = new String[length];
    String[] createDate = new String[length];
    String[] createBy = new String[length];
    String[] modifyDate = new String[length];
    String[] modifyBy = new String[length];
    ApInvoiceLine InvoiceLine = null;

    for (int i = 0; i < apInvoiceLines.size(); i++) {
      InvoiceLine = apInvoiceLines.get(i);
      invoiceLineIds[i] = "" + InvoiceLine.getInvoiceLineId();
      invoiceIds[i] = "" + InvoiceLine.getInvoiceId();
      amounts[i] = "" + InvoiceLine.getAmount();
      catalogNo[i] = InvoiceLine.getCatalogNo();
      itemNos[i] = "" + InvoiceLine.getItemNo();
      names[i] = InvoiceLine.getName();
      qtys[i] = "" + InvoiceLine.getQty();
      qtyUoms[i] = "" + InvoiceLine.getQtyUom();
      unitPrices[i] = "" + InvoiceLine.getUnitPrice();
      taxs[i] = "" + InvoiceLine.getTax();
      sizes[i] = "" + InvoiceLine.getSize();
      lineNo[i] = "" + InvoiceLine.getLineNo();
      discounts[i] = "" + InvoiceLine.getDiscount();
      createDate[i] = "" + InvoiceLine.getCreationDate();
      createBy[i] = "" + InvoiceLine.getCreatedBy();
      modifyDate[i] = "" + InvoiceLine.getModifyDate();
      modifyBy[i] = "" + InvoiceLine.getModifiedBy();
    }

    param.put("invoiceLineIds", invoiceLineIds);
    param.put("invoiceIds", invoiceIds);
    param.put("itemNo", itemNos);
    param.put("catalogNo", catalogNo);
    param.put("name", names);
    param.put("qty", qtys);
    param.put("qtyUom", qtyUoms);
    param.put("unitPrice", unitPrices);
    param.put("amount", amounts);
    param.put("tax", taxs);
    param.put("size", sizes);
    param.put("lineNo", lineNo);
    param.put("discount", discounts);
    param.put("creationDate", createDate);
    param.put("createdBy", createBy);
    param.put("modifyDate", modifyDate);
    param.put("modifiedBy", modifyBy);

    Struts2Util.getRequest().setAttribute("paramEL", param);
    return "edit_invoice";
  }
Ejemplo n.º 2
0
  /** 保存修改invoiceLine后的发票 */
  public String saveEdit() {
    ActionContext ctx = ActionContext.getContext();
    try {

      ApInvoice oldApInvoice = apInvoiceDao.getById(apInvoice.getInvoiceId());
      apInvoice.setModifiedBy(SessionUtil.getUserId());
      apInvoice.setModifyDate(new Date());
      // 如果原来状态既非  new  也非  inprocess 则不能 修改内容,只能修改状态
      if ((!Constant.STATUS_INPROCESS.equals(oldApInvoice.getStatus()))
          && (!Constant.STATUS_NEW.equals(oldApInvoice.getStatus()))) {
        String status = oldApInvoice.getStatus(); // 以手动更改为Invalid 手动改为Void	

        if (Constant.STATUS_VOID.equals(status) || Constant.STATUS_INVALID.equals(status)) {
          oldApInvoice.setStatus(apInvoice.getStatus());
          status = apInvoice.getStatus();
          if (Constant.STATUS_INPROCESS.equals(status) || Constant.STATUS_NEW.equals(status)) {
            apInvoiceDao.getSession().clear();
            apInvoiceService.edit(oldApInvoice);
          }
        }

        ctx.getSession().remove("apInvoice");
        ctx.getSession().remove("param");
        return input();
      }
      //

      boolean flag = this.apInvoiceDao.isAllocation(apInvoice.getInvoiceId()); // 没对过账,对过账的不能修改
      boolean changeStatus = false;

      String status = apInvoice.getStatus(); // 手动更改为Invalid 手动改为Void		
      if (Constant.STATUS_VOID.equals(status)
          || Constant.STATUS_INVALID.equals(status) && (!flag)) {
        oldApInvoice.setStatus(status);
        changeStatus = true;

        if (Constant.STATUS_INPROCESS.equals(oldApInvoice.getStatus())) {
          this.changeOderItem(oldApInvoice);
          apInvoiceDao.getSession().clear();
          apInvoiceService.edit(oldApInvoice);
          ctx.getSession().remove("apInvoice");
          ctx.getSession().remove("param");
          return input();
        }
      }

      if ((!oldApInvoice.getCurrency().equals(apInvoice.getCurrency()))
          && (!flag)
          && (!changeStatus)) // 没对过账 Currency更改 没手动更改为Invalid 、Void
      {
        if (Constant.STATUS_INPROCESS.equals(oldApInvoice.getStatus())) // 原本就是inprocess
        {
          apInvoiceService.copyNewInvoice(apInvoice);
          apInvoice.setCurrency(oldApInvoice.getCurrency());
          apInvoice.setStatus(Constant.STATUS_VOID);
          apInvoiceDao.getSession().clear();
          apInvoiceService.edit(apInvoice);
          ctx.getSession().remove("apInvoice");
          ctx.getSession().remove("param");
          return input();
        }
        // 原来状态是new的不需要
      }

      apInvoiceDao.getSession().clear();
      apInvoiceService.edit(apInvoice);

      if (!Constant.STATUS_NEW.equals(oldApInvoice.getStatus())) {
        ctx.getSession().remove("apInvoice");
        ctx.getSession().remove("param");
        return input();
      }

      int InvoiceId = apInvoice.getInvoiceId();
      if (0 != param.size()) {
        String[] invoiceLineIds =
            param.get("invoiceLineIds") == null ? null : (String[]) param.get("invoiceLineIds");
        String[] invoiceIds =
            param.get("invoiceIds") == null ? null : (String[]) param.get("invoiceIds");
        String[] itemNos = param.get("itemNo") == null ? null : (String[]) param.get("itemNo");
        String[] catalogNo =
            param.get("catalogNo") == null ? null : (String[]) param.get("catalogNo");
        String[] names = param.get("name") == null ? null : (String[]) param.get("name");
        String[] qtys = param.get("qty") == null ? null : (String[]) param.get("qty");
        String[] qtyUoms = param.get("qtyUom") == null ? null : (String[]) param.get("qtyUom");
        String[] unitPrices =
            param.get("unitPrice") == null ? null : (String[]) param.get("unitPrice");
        String[] amounts = param.get("amount") == null ? null : (String[]) param.get("amount");
        String[] taxs = param.get("tax") == null ? null : (String[]) param.get("tax");
        String[] sizes = param.get("size") == null ? null : (String[]) param.get("size");
        String[] lineNo = param.get("lineNo") == null ? null : (String[]) param.get("lineNo");
        String[] discounts =
            param.get("discount") == null ? null : (String[]) param.get("discount");
        String[] creation_dates =
            param.get("creationDate") == null ? null : (String[]) param.get("creationDate");
        String[] created_by =
            param.get("createdBy") == null ? null : (String[]) param.get("createdBy");
        String[] modify_dates =
            param.get("modifyDate") == null ? null : (String[]) param.get("modifyDate");
        String[] modified_by =
            param.get("modifiedBy") == null ? null : (String[]) param.get("modifiedBy");

        /** 对从invoice 状态从new 变为 inprocess的 invoice line的审核 对invoice line 进行check 开始 */
        if (Constant.STATUS_INPROCESS.equals(apInvoice.getStatus()) && (null != itemNos)) {
          for (int i = 0; i < itemNos.length; i++) {
            int itemNo = 0;
            int quantity = 0;
            double size = 0;

            itemNo = Tools.String2Integer(itemNos[i]);
            quantity = Tools.String2Integer(qtys[i]);
            size = Tools.String2Float(sizes[i]);
            //
            //		   						OrderItemOverSizeDTO = this.apInvoiceService.checkOderItem(
            // apInvoice.getInvoiceId(),
            //		   					           apInvoice.getOrderNo(),itemNo,quantity, size,false );
            //
            //		   						if(null!=OrderItemOverSizeDTO)
            //		   						{
            //		   							apInvoiceService.edit(oldApInvoice);// 将 主表的数据 退回 原值
            //		   							return "edit_invoice";
            //		   						}
          } // for 循环结束
        }
        /** 对invoice line 进行check 结束 */

        ////////////// 在状态为New时。InvoiceLine 执行删除////////////////
        //		  				if(Constant.STATUS_NEW.equals(apInvoice.getStatus()))
        //		  				{
        String InvoiceLineIds = "0";
        String invoiceId = "" + InvoiceId;
        for (int i = 0; i < invoiceLineIds.length; i++) {
          InvoiceLineIds = InvoiceLineIds + "," + invoiceLineIds[i];
        }
        try {
          apInvoiceLineDao.DeleteBatch(invoiceId, InvoiceLineIds);
        } catch (Exception e) {
          e.printStackTrace();
        }

        //		  				}

        ////////////////////////////////

        ApInvoiceLine insertLine = null;
        for (int i = 0; i < itemNos.length; i++) {
          insertLine =
              apInvoiceLineDao.queryInvoiceLine(Tools.String2Integer(invoiceLineIds[i]).intValue());

          if (null == insertLine) {
            insertLine = new ApInvoiceLine();
          } else {
            insertLine.setInvoiceLineId(Tools.String2Integer(invoiceLineIds[i]));
          }
          insertLine.setAmount(Tools.String2Float(amounts[i]));
          insertLine.setCatalogNo(catalogNo[i]);

          insertLine.setDiscount(Tools.String2Float(discounts[i]));
          ;
          insertLine.setInvoiceId(InvoiceId);
          insertLine.setItemNo(Tools.String2Integer(itemNos[i]));
          int linno = Tools.String2Integer(lineNo[i]);
          //		  					insertLine.setLineNo(linno);
          insertLine.setLineNo(i + 1);

          insertLine.setModifiedBy(SessionUtil.getUserId());
          insertLine.setModifyDate(new Date());

          insertLine.setCreatedBy(Tools.String2Integer(created_by[i]));
          insertLine.setCreationDate(Tools.getFormatDate(creation_dates[i]));

          insertLine.setName(names[i]);
          insertLine.setOrderNo(apInvoice.getOrderNo());
          insertLine.setQty(Tools.String2Integer(qtys[i]));
          insertLine.setQtyUom(qtyUoms[i]);
          insertLine.setSize(Tools.String2Float(sizes[i]));
          insertLine.setSizeUom("");
          insertLine.setTax(Tools.String2Float(taxs[i]));
          insertLine.setUnitPrice(Tools.String2Float(unitPrices[i]));
          insertLine.setStatus(apInvoice.getStatus());

          apInvoiceLineDao.save(insertLine);
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

    ctx.getSession().remove("apInvoice");
    ctx.getSession().remove("param");

    return input();
  }
Ejemplo n.º 3
0
  /**
   * 添加invoice,跳转到页面
   *
   * @return
   * @throws Exception
   */
  public String save() throws Exception {
    try {
      apInvoice.setCreatedBy(SessionUtil.getUserId());
      apInvoice.setCreationDate(new Date());
      apInvoice.setModifiedBy(SessionUtil.getUserId());
      apInvoice.setModifyDate(new Date());
      apInvoice.setPrintedFlag("N");
      int companyId = this.apInvoiceDao.getCompanyId(apInvoice.getOrderNo());
      apInvoice.setCompanyId(companyId); // 测试
      int InvoiceId = apInvoiceService.add(apInvoice);
      if (0 != param.size()) {
        String[] itemNos = param.get("itemNo") == null ? null : (String[]) param.get("itemNo");
        String[] catalogNo =
            param.get("catalogNo") == null ? null : (String[]) param.get("catalogNo");
        String[] names = param.get("name") == null ? null : (String[]) param.get("name");
        String[] qtys = param.get("qty") == null ? null : (String[]) param.get("qty");
        String[] qtyUoms = param.get("qtyUom") == null ? null : (String[]) param.get("qtyUom");
        String[] unitPrices =
            param.get("unitPrice") == null ? null : (String[]) param.get("unitPrice");
        String[] amounts = param.get("amount") == null ? null : (String[]) param.get("amount");
        String[] taxs = param.get("tax") == null ? null : (String[]) param.get("tax");
        String[] sizes = param.get("size") == null ? null : (String[]) param.get("size");
        String[] lineNo = param.get("lineNo") == null ? null : (String[]) param.get("lineNo");
        String[] discounts =
            param.get("discount") == null ? null : (String[]) param.get("discount");
        ApInvoiceLine insertLine = null;
        for (int i = 0; i < itemNos.length; i++) {
          insertLine = new ApInvoiceLine();
          insertLine.setAmount(Tools.String2Float(amounts[i]));
          insertLine.setCatalogNo(catalogNo[i]);
          insertLine.setCreatedBy(SessionUtil.getUserId());
          insertLine.setCreationDate(new Date());
          insertLine.setDiscount(Tools.String2Float(discounts[i]));
          insertLine.setInvoiceId(InvoiceId);
          insertLine.setItemNo(Tools.String2Integer(itemNos[i]));
          int linno = Tools.String2Integer(lineNo[i]);
          //					insertLine.setLineNo(linno);
          insertLine.setLineNo(i + 1);
          insertLine.setModifiedBy(SessionUtil.getUserId());
          insertLine.setModifyDate(new Date());
          insertLine.setName(names[i]);
          insertLine.setOrderNo(apInvoice.getOrderNo());
          insertLine.setQty(Tools.String2Integer(qtys[i]));
          insertLine.setQtyUom(qtyUoms[i]);
          insertLine.setSize(Tools.String2Float(sizes[i]));
          insertLine.setSizeUom("");
          insertLine.setTax(Tools.String2Float(taxs[i]));
          insertLine.setUnitPrice(Tools.String2Float(unitPrices[i]));
          insertLine.setStatus(Constant.STATUS_NEW);
          apInvoiceLineDao.save(insertLine);
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

    ActionContext ctx = ActionContext.getContext();
    ctx.getSession().remove("apInvoice");
    ctx.getSession().remove("param");

    return input();
  }