This commit is contained in:
linfso 2024-07-26 08:26:10 +08:00
parent c0cff7e465
commit d2464e30a5
3 changed files with 181 additions and 81 deletions

View File

@ -1054,22 +1054,21 @@ public class EmisBaseService {
public void redoGenerateBill(String billCode) throws EmisBizError{
log.error("===>Start 运单出账:"+billCode);
EmisSettleSubBill oldBill=null;
boolean isNewBill=true;
boolean isNewBill=true;
BigDecimal oldTotalFee = BigDecimal.ZERO;
BigDecimal newTotalFee = BigDecimal.ZERO;
// 已确认的不允许出账
List<EmisSettleSubBill> oldSubBillList=getSettleSubBillListByBillCode(billCode);
if(oldSubBillList!=null ) {
if(oldSubBillList.size()>1 ) {
log.error("===>账已拆分不允许出账!");
return;
}
oldBill = oldSubBillList.get(0);
if(!CollectionUtils.isEmpty(oldSubBillList) ) {
isNewBill=false;
if (!"0".equals(oldBill.getBlConfirmCenter())) {
log.error("===>账单财务确认不允许出账!");
return;
for (EmisSettleSubBill oldBill:oldSubBillList) {
if ("1".equals(oldBill.getBlConfirmCenter())) {
log.error("===>账单财务确认不允许出账!");
return;
}
oldTotalFee=oldTotalFee.add(oldBill.getBillFee());
}
}
@ -1078,10 +1077,11 @@ public class EmisBaseService {
// 生成分账单明细,判断是否是新账单
EmisSettleSubBill emisSettleSubBill=new EmisSettleSubBill();
if(oldBill!=null){
// emisSettleSubBill.setId(oldBill.getId());
if(!isNewBill){
// 逻辑删除原账单重出账单
emisSettleSubBillMapper.deleteEmisSettleSubBillByBillCode(billCode);
// 逻辑删除原来的费用明细,重新插入明细
emisSettleSubBillFeeitemMapper.deleteEmisSettleSubBillFeeitemByBillCode(billCode);
}
emisSettleSubBill.setBillCode(dt.getBillCode());
@ -1108,6 +1108,9 @@ public class EmisBaseService {
emisSettleSubBill.setCurrency(dt.getCurrency());
emisSettleSubBill.setBillMonth(DateUtils.parseDateToStr("yyyyMM",dt.getSendDate()));
emisSettleSubBill.setBillFee(dt.getFreight());
emisSettleSubBill.setCustNo(dt.getCustNo());
@ -1126,13 +1129,13 @@ public class EmisBaseService {
emisSettleSubBillMapper.insertEmisSettleSubBill(emisSettleSubBill);
// 新费用
newTotalFee = emisSettleSubBill.getBillFee();
// 如果是一口价,自动生成一条运费明细,其他则根据实际来计算
// 生成费用明细
if(dt.getCalcFeeType().equals("3")) {
}else{
// 逻辑删除原来的费用明细,重新插入明细
emisSettleSubBillFeeitemMapper.deleteEmisSettleSubBillFeeitemByBillCode(billCode);
// 产生新的费用明细
List<EmisWaybillFeeitem> feeitemList = emisWaybillFeeitemMapper.selectFeeitemListByWaybillId(dt.getId());
for(EmisWaybillFeeitem feeitem:feeitemList){
@ -1151,66 +1154,139 @@ public class EmisBaseService {
// 出账标识
emisWaybillMapper.updateHasDoBill(dt);
// 判断网点余额-运单金额 是否足够,如果不够则不允许下单
// 判断是否调整账单费用,对比差异
EmisSiteAccount emisSiteAccount=getSiteAccountBySiteCode(dt.getSendSiteCode());
if(emisSiteAccount!=null){
// 扣减寄件网点账户额度
EmisSiteSettleRecord emisSiteSettleRecord=new EmisSiteSettleRecord();
emisSiteSettleRecord.setAccCode(emisSiteAccount.getAccCode());
emisSiteSettleRecord.setBillCode(dt.getBillCode());
emisSiteSettleRecord.setRecPayType("2"); // 应付
emisSiteSettleRecord.setSettleType("003");// 运输费用
emisSiteSettleRecord.setSettleName("运输费");
emisSiteSettleRecord.setCurMoney(dt.getFreight());
emisSiteSettleRecord.setCurConfirmMoney(dt.getFreight());
emisSiteSettleRecord.setChangeType("2"); // 减少
emisSiteSettleRecord.setCurrency("CNY");
// 计算日期
emisSiteSettleRecord.setChangeDate(new Date());
// 新账单增加费用
if(isNewBill) {
// 扣减寄件网点账户额度
EmisSiteSettleRecord emisSiteSettleRecord = new EmisSiteSettleRecord();
emisSiteSettleRecord.setAccCode(emisSiteAccount.getAccCode());
emisSiteSettleRecord.setBillCode(dt.getBillCode());
emisSiteSettleRecord.setRecPayType("2"); // 应付
emisSiteSettleRecord.setSettleType("006");// 运输费用
emisSiteSettleRecord.setSettleName("运输费");
emisSiteSettleRecord.setCurMoney(dt.getFreight());
emisSiteSettleRecord.setCurConfirmMoney(dt.getFreight());
emisSiteSettleRecord.setChangeType("2"); // 减少
emisSiteSettleRecord.setCurrency("CNY");
emisSiteSettleRecord.setSiteCode(dt.getSendSiteCode());
emisSiteSettleRecord.setSiteName(dt.getSendSiteName());
emisSiteSettleRecord.setDataFrom("job");
emisSiteSettleRecord.setOperataDate(new Date());
emisSiteSettleRecord.setFinanceDate(new Date());
emisSiteSettleRecord.setBlCenter("1");
emisSiteSettleRecord.setCenterCode(dt.getSendCenterCode());
// emisSiteSettleRecord.setCenterManCode(getCurrentUser().getEmpCode());
emisSiteSettleRecord.setBlChargeFee("1");
emisSiteSettleRecord.setCustomerCode(dt.getCustomerCode());
addSiteSettleRecord(emisSiteSettleRecord);
// 计算日期
emisSiteSettleRecord.setChangeDate(new Date());
// 增加财务中心的收入
emisSiteSettleRecord.setSiteCode(dt.getSendSiteCode());
emisSiteSettleRecord.setSiteName(dt.getSendSiteName());
emisSiteSettleRecord.setDataFrom("job");
emisSiteSettleRecord.setOperataDate(new Date());
emisSiteSettleRecord.setFinanceDate(new Date());
emisSiteSettleRecord.setBlCenter("1");
emisSiteSettleRecord.setCenterCode(dt.getSendCenterCode());
// emisSiteSettleRecord.setCenterManCode(getCurrentUser().getEmpCode());
emisSiteSettleRecord.setBlChargeFee("1");
emisSiteSettleRecord.setCustomerCode(dt.getCustomerCode());
addSiteSettleRecord(emisSiteSettleRecord);
// 财务中心
EmisSite centerSite=getSiteByCode(dt.getSendCenterCode());
// 调整财务中心的收入
EmisSiteSettleRecord centerRecord=new EmisSiteSettleRecord();
centerRecord.setAccCode(centerSite.getSiteCode()+"001");
centerRecord.setBillCode(dt.getBillCode());
centerRecord.setRecPayType("1"); // 应收
centerRecord.setSettleType("003");// 运输费用
centerRecord.setSettleName("运输费");
centerRecord.setCurMoney(dt.getFreight());
centerRecord.setCurConfirmMoney(dt.getFreight());
centerRecord.setChangeType("1"); // 增加
centerRecord.setCurrency("CNY");
// 财务中心
EmisSite centerSite = getSiteByCode(dt.getSendCenterCode());
// 计算日期
centerRecord.setChangeDate(new Date());
EmisSiteSettleRecord centerRecord = new EmisSiteSettleRecord();
centerRecord.setAccCode(centerSite.getSiteCode() + "001");
centerRecord.setBillCode(dt.getBillCode());
centerRecord.setRecPayType("1"); // 应收
centerRecord.setSettleType("003");// 运输费用
centerRecord.setSettleName("运输费");
centerRecord.setCurMoney(dt.getFreight());
centerRecord.setCurConfirmMoney(dt.getFreight());
centerRecord.setChangeType("1"); // 增加
centerRecord.setCurrency("CNY");
centerRecord.setSiteCode(centerSite.getSiteCode());
centerRecord.setSiteName(centerSite.getSiteName());
centerRecord.setDataFrom("job");
centerRecord.setOperataDate(new Date());
centerRecord.setFinanceDate(new Date());
centerRecord.setBlCenter("1");
centerRecord.setCenterCode(centerSite.getParentSiteCode());
// emisSiteSettleRecord.setCenterManCode(getCurrentUser().getEmpCode());
centerRecord.setBlChargeFee("1");
centerRecord.setCustomerCode(dt.getCustomerCode());
addSiteSettleRecord(centerRecord);
// 计算日期
centerRecord.setChangeDate(new Date());
centerRecord.setSiteCode(centerSite.getSiteCode());
centerRecord.setSiteName(centerSite.getSiteName());
centerRecord.setDataFrom("job");
centerRecord.setOperataDate(new Date());
centerRecord.setFinanceDate(new Date());
centerRecord.setBlCenter("1");
centerRecord.setCenterCode(centerSite.getParentSiteCode());
// emisSiteSettleRecord.setCenterManCode(getCurrentUser().getEmpCode());
centerRecord.setBlChargeFee("1");
centerRecord.setCustomerCode(dt.getCustomerCode());
addSiteSettleRecord(centerRecord);
}
// 旧账单调整费用
else{
// 判断是增加还是减少
int dif=oldTotalFee.compareTo(newTotalFee);
// 有差异才调整
if(dif!=0) {
BigDecimal difFee=oldTotalFee.subtract(newTotalFee).abs();
// 扣减寄件网点账户额度
EmisSiteSettleRecord emisSiteSettleRecord = new EmisSiteSettleRecord();
emisSiteSettleRecord.setAccCode(emisSiteAccount.getAccCode());
emisSiteSettleRecord.setBillCode(dt.getBillCode());
emisSiteSettleRecord.setRecPayType("2"); // 应付
emisSiteSettleRecord.setSettleType("006");// 运输费用
emisSiteSettleRecord.setSettleName("运输费调整");
emisSiteSettleRecord.setCurMoney(difFee);
emisSiteSettleRecord.setCurConfirmMoney(difFee);
// 2-减少 1-增加
emisSiteSettleRecord.setChangeType(dif>0?"1":"2");
emisSiteSettleRecord.setCurrency("CNY");
// 计算日期
emisSiteSettleRecord.setChangeDate(new Date());
emisSiteSettleRecord.setSiteCode(dt.getSendSiteCode());
emisSiteSettleRecord.setSiteName(dt.getSendSiteName());
emisSiteSettleRecord.setDataFrom("job");
emisSiteSettleRecord.setOperataDate(new Date());
emisSiteSettleRecord.setFinanceDate(new Date());
emisSiteSettleRecord.setBlCenter("1");
emisSiteSettleRecord.setCenterCode(dt.getSendCenterCode());
// emisSiteSettleRecord.setCenterManCode(getCurrentUser().getEmpCode());
emisSiteSettleRecord.setBlChargeFee("1");
emisSiteSettleRecord.setCustomerCode(dt.getCustomerCode());
addSiteSettleRecord(emisSiteSettleRecord);
// 调整财务中心的收入
// 财务中心
EmisSite centerSite = getSiteByCode(dt.getSendCenterCode());
EmisSiteSettleRecord centerRecord = new EmisSiteSettleRecord();
centerRecord.setAccCode(centerSite.getSiteCode() + "001");
centerRecord.setBillCode(dt.getBillCode());
centerRecord.setRecPayType("1"); // 应收
centerRecord.setSettleType("003");// 运输费用
centerRecord.setSettleName("运输费调整");
centerRecord.setCurMoney(difFee);
centerRecord.setCurConfirmMoney(difFee);
centerRecord.setChangeType(dif>0?"1":"2"); // 增加
centerRecord.setCurrency("CNY");
// 计算日期
centerRecord.setChangeDate(new Date());
centerRecord.setSiteCode(centerSite.getSiteCode());
centerRecord.setSiteName(centerSite.getSiteName());
centerRecord.setDataFrom("job");
centerRecord.setOperataDate(new Date());
centerRecord.setFinanceDate(new Date());
centerRecord.setBlCenter("1");
centerRecord.setCenterCode(centerSite.getParentSiteCode());
// emisSiteSettleRecord.setCenterManCode(getCurrentUser().getEmpCode());
centerRecord.setBlChargeFee("1");
centerRecord.setCustomerCode(dt.getCustomerCode());
addSiteSettleRecord(centerRecord);
}
}
}

View File

@ -180,15 +180,16 @@ public class EmisWaybillAjustApplyServiceImpl extends EmisBaseService implements
// 获取账单状态,若账单处于非未确认状态,不允许审核
List<EmisSettleSubBill> emisSettleSubBillList=getSettleSubBillListByBillCode(emisWaybillAjustApply.getBillCode());
if(emisSettleSubBillList!=null && emisSettleSubBillList.size()>1){
throw new EmisBizError(EmisBizErrorType.FAIL,"账单已拆分,请先删除子账单!");
if(emisSettleSubBillList!=null && emisSettleSubBillList.size()>0){
for (EmisSettleSubBill emisSettleSubBill:emisSettleSubBillList) {
if("1".equals(emisSettleSubBill.getBlConfirmCenter())){
throw new EmisBizError(EmisBizErrorType.FAIL,"财务已确认账单,不允许审核,请先取消财务确认!");
}
}
}
EmisSettleSubBill emisSettleSubBill=emisSettleSubBillList.get(0);
if("1".equals(emisSettleSubBill.getBlConfirmCenter())){
throw new EmisBizError(EmisBizErrorType.FAIL,"财务已确认账单,不允许审核,请先取消财务确认!");
}

View File

@ -15,6 +15,7 @@
<result property="recMoney" column="rec_money" />
<result property="recedMoney" column="reced_money" />
<result property="custNo" column="cust_no" />
<result property="custName" column="cust_name" />
<result property="customerCode" column="customer_code" />
<result property="customerName" column="customer_name" />
<result property="siteCode" column="site_code" />
@ -53,7 +54,7 @@
</resultMap>
<sql id="selectEmisSettleBillVo">
select id, settle_bill_no, settle_bill_name, settle_type, settle_start_date, settle_end_date, bill_month, rec_money, reced_money, cust_no, customer_code, customer_name, site_code, site_name, satisfy_money, allowance_money, deduction_money, other_money, satisfy_reason, allowance_reason, deduction_reason, other_reason, open_bill_status, payment_status, charge_status, send_piece_sum, piece_number, fee_weight, uncollected_amount, send_money_sum, refund_amount, refund_money, payee, salesmen, bl_send_oms, bl_confirm_center, confirm_center_date, confirm_center_note, confirm_center_man_code, confirm_center_code, bl_confirm_site, confirm_site_date, confirm_site_man_code, confirm_site_note, confirm_site_code, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site from emis_settle_bill
select id, settle_bill_no, settle_bill_name, settle_type, settle_start_date, settle_end_date, bill_month, rec_money, reced_money, cust_no, cust_name, customer_code, customer_name, site_code, site_name, satisfy_money, allowance_money, deduction_money, other_money, satisfy_reason, allowance_reason, deduction_reason, other_reason, open_bill_status, payment_status, charge_status, send_piece_sum, piece_number, fee_weight, uncollected_amount, send_money_sum, refund_amount, refund_money, payee, salesmen, bl_send_oms, bl_confirm_center, confirm_center_date, confirm_center_note, confirm_center_man_code, confirm_center_code, bl_confirm_site, confirm_site_date, confirm_site_man_code, confirm_site_note, confirm_site_code, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site from emis_settle_bill a
</sql>
<select id="selectEmisSettleBillList" parameterType="EmisSettleBill" resultMap="EmisSettleBillResult">
@ -61,7 +62,7 @@
<where>
del_flag='0'
<if test="id != null "> and id = #{id}</if>
<if test="settleBillNo != null and settleBillNo != ''"> and settle_bill_no like concat('%', #{settleBillNo}, '%')</if>
<if test="settleBillNo != null and settleBillNo != ''"> and FIND_IN_SET(a.`settle_bill_no`,#{settleBillNo})</if>
<if test="settleBillName != null and settleBillName != ''"> and settle_bill_name like concat('%', #{settleBillName}, '%')</if>
<if test="settleType != null and settleType != ''"> and settle_type like concat('%', #{settleType}, '%')</if>
<if test="settleStartDate != null "> and settle_start_date = #{settleStartDate}</if>
@ -70,6 +71,7 @@
<if test="recMoney != null "> and rec_money = #{recMoney}</if>
<if test="recedMoney != null "> and reced_money = #{recedMoney}</if>
<if test="custNo != null and custNo != ''"> and cust_no = #{custNo}</if>
<if test="custName != null and custName != ''"> and cust_name like concat('%', #{custName}, '%')</if>
<if test="customerCode != null and customerCode != ''"> and customer_code = #{customerCode}</if>
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
<if test="siteCode != null and siteCode != ''"> and site_code = #{siteCode}</if>
@ -113,6 +115,24 @@
<if test="updateTime != null "> and update_time = #{updateTime}</if>
<if test="createSite != null and createSite != ''"> and create_site = #{createSite}</if>
<if test="updateSite != null and updateSite != ''"> and update_site = #{updateSite}</if>
<if test="params.billCode != null and params.billCode != ''">
and exists (
select 1 from emis_settle_sub_bill b
where a.settle_bill_no=b.settle_bill_no
and ( FIND_IN_SET(b.`bill_code`,#{params.billCode}) or b.bill_code like concat('%', #{params.billCode}, '%') )
)
</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and ( salesmen=#{params.privEmpName}
or payee=#{params.privEmpName}
)
</if>
</where>
order by create_time desc
</select>
@ -177,16 +197,16 @@
</select>
<select id="selectEmisSettleBillById" parameterType="Long" resultMap="EmisSettleBillResult">
select id, settle_bill_no, settle_bill_name, settle_type, settle_start_date, settle_end_date, bill_month, rec_money, reced_money, cust_no, customer_code, customer_name, site_code, site_name, satisfy_money, allowance_money, deduction_money, other_money, satisfy_reason, allowance_reason, deduction_reason, other_reason, open_bill_status, payment_status, charge_status, send_piece_sum, piece_number, fee_weight, uncollected_amount, send_money_sum, refund_amount, refund_money, payee, salesmen, bl_send_oms, bl_confirm_center, confirm_center_date, confirm_center_note, confirm_center_man_code, confirm_center_code, bl_confirm_site, confirm_site_date, confirm_site_man_code, confirm_site_note, confirm_site_code, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
select id, settle_bill_no, settle_bill_name, settle_type, settle_start_date, settle_end_date, bill_month, rec_money, reced_money, cust_no, cust_name, customer_code, customer_name, site_code, site_name, satisfy_money, allowance_money, deduction_money, other_money, satisfy_reason, allowance_reason, deduction_reason, other_reason, open_bill_status, payment_status, charge_status, send_piece_sum, piece_number, fee_weight, uncollected_amount, send_money_sum, refund_amount, refund_money, payee, salesmen, bl_send_oms, bl_confirm_center, confirm_center_date, confirm_center_note, confirm_center_man_code, confirm_center_code, bl_confirm_site, confirm_site_date, confirm_site_man_code, confirm_site_note, confirm_site_code, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
from emis_settle_bill a
where a.id = #{id}
</select>
<select id="selectSettleBillBySettleBillNo" parameterType="String" resultMap="EmisSettleBillResult">
select id, settle_bill_no, settle_bill_name, settle_type, settle_start_date, settle_end_date, bill_month, rec_money, reced_money, cust_no, customer_code, customer_name, site_code, site_name, satisfy_money, allowance_money, deduction_money, other_money, satisfy_reason, allowance_reason, deduction_reason, other_reason, open_bill_status, payment_status, charge_status, send_piece_sum, piece_number, fee_weight, uncollected_amount, send_money_sum, refund_amount, refund_money, payee, salesmen, bl_send_oms, bl_confirm_center, confirm_center_date, confirm_center_note, confirm_center_man_code, confirm_center_code, bl_confirm_site, confirm_site_date, confirm_site_man_code, confirm_site_note, confirm_site_code, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
select id, settle_bill_no, settle_bill_name, settle_type, settle_start_date, settle_end_date, bill_month, rec_money, reced_money, cust_no, cust_name, customer_code, customer_name, site_code, site_name, satisfy_money, allowance_money, deduction_money, other_money, satisfy_reason, allowance_reason, deduction_reason, other_reason, open_bill_status, payment_status, charge_status, send_piece_sum, piece_number, fee_weight, uncollected_amount, send_money_sum, refund_amount, refund_money, payee, salesmen, bl_send_oms, bl_confirm_center, confirm_center_date, confirm_center_note, confirm_center_man_code, confirm_center_code, bl_confirm_site, confirm_site_date, confirm_site_man_code, confirm_site_note, confirm_site_code, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
from emis_settle_bill a
where a.settle_bill_no = #{settleBillNo}
where a.settle_bill_no = #{settleBillNo} and del_flag='0'
</select>
@ -203,6 +223,7 @@
<if test="recMoney != null">rec_money,</if>
<if test="recedMoney != null">reced_money,</if>
<if test="custNo != null and custNo != ''">cust_no,</if>
<if test="custName != null and custName != ''">cust_name,</if>
<if test="customerCode != null and customerCode != ''">customer_code,</if>
<if test="customerName != null and customerName != ''">customer_name,</if>
<if test="siteCode != null and siteCode != ''">site_code,</if>
@ -258,6 +279,7 @@
<if test="recMoney != null">#{recMoney},</if>
<if test="recedMoney != null">#{recedMoney},</if>
<if test="custNo != null and custNo != ''">#{custNo},</if>
<if test="custName != null and custName != ''">#{custName},</if>
<if test="customerCode != null and customerCode != ''">#{customerCode},</if>
<if test="customerName != null and customerName != ''">#{customerName},</if>
<if test="siteCode != null and siteCode != ''">#{siteCode},</if>
@ -316,6 +338,7 @@
<if test="recMoney != null">rec_money = #{recMoney},</if>
<if test="recedMoney != null">reced_money = #{recedMoney},</if>
<if test="custNo != null and custNo != ''">cust_no = #{custNo},</if>
<if test="custName != null and custName != ''">cust_name = #{custName},</if>
<if test="customerCode != null and customerCode != ''">customer_code = #{customerCode},</if>
<if test="customerName != null and customerName != ''">customer_name = #{customerName},</if>
<if test="siteCode != null and siteCode != ''">site_code = #{siteCode},</if>
@ -364,11 +387,11 @@
</update>
<delete id="deleteEmisSettleBillById" parameterType="Long">
delete from emis_settle_bill where id = #{id}
update emis_settle_bill set del_flag='0' where id = #{id}
</delete>
<delete id="deleteEmisSettleBillByIds" parameterType="String">
delete from emis_settle_bill where id in
update emis_settle_bill set del_flag='0' where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>