206 lines
6.6 KiB
Java
206 lines
6.6 KiB
Java
package com.tenwa.customer.controller.invoice;
|
|
|
|
import java.util.List;
|
|
|
|
import jbo.app.tenwa.customer.CUSTOMER_INVOICE;
|
|
|
|
import com.amarsoft.are.jbo.BizObject;
|
|
import com.amarsoft.are.jbo.BizObjectManager;
|
|
import com.amarsoft.are.jbo.BizObjectQuery;
|
|
import com.amarsoft.are.jbo.JBOFactory;
|
|
import com.amarsoft.are.jbo.JBOTransaction;
|
|
|
|
public class CustomerInvoiceController {
|
|
|
|
private String id="";
|
|
private String customer_id="";
|
|
private String tax_status="";
|
|
private String tax_no="";
|
|
|
|
public String getTax_no() {
|
|
return tax_no;
|
|
}
|
|
|
|
public void setTax_no(String tax_no) {
|
|
this.tax_no = tax_no;
|
|
}
|
|
|
|
public String getTax_status() {
|
|
return tax_status;
|
|
}
|
|
|
|
public void setTax_status(String tax_status) {
|
|
this.tax_status = tax_status;
|
|
}
|
|
|
|
public String getCustomer_id() {
|
|
return customer_id;
|
|
}
|
|
|
|
public void setCustomer_id(String customer_id) {
|
|
this.customer_id = customer_id;
|
|
}
|
|
|
|
public String getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(String id) {
|
|
this.id = id;
|
|
}
|
|
|
|
/**
|
|
* 生效
|
|
* @param tx
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public String initStatusYes(JBOTransaction tx)throws Exception {
|
|
BizObjectManager bom = JBOFactory.getBizObjectManager(CUSTOMER_INVOICE.CLASS_NAME);
|
|
tx.join(bom);
|
|
//将此开票信息设置为生效状态
|
|
BizObjectQuery boq = bom.createQuery("update O set tax_status = 'valid' where id=:id ");
|
|
boq.setParameter("id",id);
|
|
int i = boq.executeUpdate();
|
|
String s = Integer.toString(i);
|
|
return s;
|
|
}
|
|
|
|
/**
|
|
* 失效
|
|
* @param tx
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public String initStatusNo(JBOTransaction tx)throws Exception {
|
|
BizObjectManager bom = JBOFactory.getBizObjectManager(CUSTOMER_INVOICE.CLASS_NAME);
|
|
tx.join(bom);
|
|
//查询此客户所有有效的开票信息
|
|
List<BizObject> CUSTOMER_INVOICES = bom.createQuery("customer_id=:customer_id and tax_status='valid'").setParameter("customer_id",customer_id).getResultList(false);
|
|
//此客户只有一条有效开票信息时不许做失效操作
|
|
if(CUSTOMER_INVOICES.size() == 1){
|
|
return "no";
|
|
}
|
|
//将此开票信息设为失效,同时设置为非默认开票
|
|
BizObjectQuery boq = bom.createQuery("update O set tax_status = 'invalid',tax_isdefault = 'no' where id=:id");
|
|
boq.setParameter("id",id);
|
|
int i = boq.executeUpdate();
|
|
String s = Integer.toString(i);
|
|
return s;
|
|
}
|
|
|
|
/**
|
|
* 设置为默认开票
|
|
* @param tx
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public String setDefault(JBOTransaction tx)throws Exception {
|
|
BizObjectManager bom = JBOFactory.getBizObjectManager(CUSTOMER_INVOICE.CLASS_NAME);
|
|
tx.join(bom);
|
|
//查询当前开票信息
|
|
BizObject CUSTOMER_INVOICE = bom.createQuery("id=:id").setParameter("id",id).getSingleResult(false);
|
|
//如果当前开票信息状态为无效,不允许设置为默认开票
|
|
if(CUSTOMER_INVOICE.getAttribute("tax_status").toString().equals("invalid")){
|
|
return "no";
|
|
}
|
|
//先把当前客户所有开票信息设置为非默认
|
|
BizObjectQuery boq1 = bom.createQuery("update O set tax_isdefault = 'no' where customer_id=:customer_id").setParameter("customer_id",customer_id);
|
|
boq1.executeUpdate();
|
|
//然后把当前开票信息设置为默认开票
|
|
BizObjectQuery boq2 = bom.createQuery("update O set tax_isdefault = 'yes' where id=:id ");
|
|
boq2.setParameter("id",id);
|
|
int i = boq2.executeUpdate();
|
|
String s = "";
|
|
if(i == 1){
|
|
s = "yes";
|
|
}
|
|
return s;
|
|
}
|
|
|
|
/**
|
|
* 新增时校验纳税人识别号
|
|
* @param tx
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public String checkTax_no(JBOTransaction tx)throws Exception {
|
|
BizObjectManager bom = JBOFactory.getBizObjectManager(CUSTOMER_INVOICE.CLASS_NAME);
|
|
tx.join(bom);
|
|
//查询当前客户有效且纳税人识别号与当前纳税人识别号相同的开票信息
|
|
BizObjectManager manager = JBOFactory.getFactory().getManager(CUSTOMER_INVOICE.CLASS_NAME);
|
|
List<BizObject> CUSTOMER_INVOICE = manager.createQuery("customer_id=:customer_id and tax_status='valid' and tax_no=:tax_no").setParameter("customer_id",customer_id).setParameter("tax_no",tax_no).getResultList(false);
|
|
//如果存在满足以上条件的开票信息,不允许保存
|
|
if(CUSTOMER_INVOICE != null && CUSTOMER_INVOICE.size() >0){
|
|
return "false";
|
|
}else return "true";
|
|
}
|
|
|
|
/**
|
|
* 修改时校验纳税人识别号
|
|
* @param tx
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public String editCheckTax_no(JBOTransaction tx)throws Exception {
|
|
BizObjectManager bom = JBOFactory.getBizObjectManager(CUSTOMER_INVOICE.CLASS_NAME);
|
|
tx.join(bom);
|
|
//查询当前客户此条以外有效且纳税人识别号与当前纳税人识别号相同的开票信息
|
|
BizObjectManager manager = JBOFactory.getFactory().getManager(CUSTOMER_INVOICE.CLASS_NAME);
|
|
List<BizObject> CUSTOMER_INVOICE = manager.createQuery("customer_id=:customer_id and tax_status='valid' and tax_no=:tax_no and id<>:id").setParameter("customer_id",customer_id).setParameter("tax_no",tax_no).setParameter("id",id).getResultList(false);
|
|
//如果存在满足以上条件的开票信息,不允许保存
|
|
if(CUSTOMER_INVOICE != null && CUSTOMER_INVOICE.size() >0){
|
|
return "false";
|
|
}else return "true";
|
|
}
|
|
|
|
/**
|
|
* 新增默认为是时更新之前开票信息的默认状态为否
|
|
* @param tx
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public void updateIsDefault(JBOTransaction tx)throws Exception {
|
|
BizObjectManager bom = JBOFactory.getBizObjectManager(CUSTOMER_INVOICE.CLASS_NAME);
|
|
tx.join(bom);
|
|
//查询当前客户有效且纳税人识别号与当前纳税人识别号相同的开票信息
|
|
BizObjectManager manager = JBOFactory.getFactory().getManager(CUSTOMER_INVOICE.CLASS_NAME);
|
|
BizObjectQuery boq = bom.createQuery("update O set tax_isdefault = 'no' where customer_id=:customer_id and id<>:id").setParameter("customer_id",customer_id).setParameter("id",id);
|
|
boq.executeUpdate();
|
|
}
|
|
|
|
/**
|
|
* 新增时查询当前客户有无开票信息
|
|
* @param tx
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public String selectInvoice(JBOTransaction tx)throws Exception {
|
|
BizObjectManager bom = JBOFactory.getBizObjectManager(CUSTOMER_INVOICE.CLASS_NAME);
|
|
tx.join(bom);
|
|
//查询当前客户有无开票信息
|
|
List<BizObject> CUSTOMER_INVOICES = bom.createQuery("customer_id=:customer_id").setParameter("customer_id",customer_id).getResultList(false);
|
|
if(CUSTOMER_INVOICES != null && CUSTOMER_INVOICES.size() > 0){
|
|
return "true";
|
|
}
|
|
return "false";
|
|
}
|
|
|
|
/**
|
|
* 修改时查询当前客户有无开票信息
|
|
* @param tx
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public String selectEditInvoice(JBOTransaction tx)throws Exception {
|
|
BizObjectManager bom = JBOFactory.getBizObjectManager(CUSTOMER_INVOICE.CLASS_NAME);
|
|
tx.join(bom);
|
|
//查询当前客户有无开票信息
|
|
List<BizObject> CUSTOMER_INVOICES = bom.createQuery("customer_id=:customer_id and id<>:id and tax_isdefault='yes'").setParameter("customer_id",customer_id).setParameter("id",id).getResultList(false);
|
|
if(CUSTOMER_INVOICES != null && CUSTOMER_INVOICES.size() > 0){
|
|
return "true";
|
|
}
|
|
return "false";
|
|
}
|
|
}
|