ICSReceiptAPIService.java
23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
package com.huaheng.pc.u8.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.company.domain.CompanyU8;
import com.huaheng.pc.config.company.service.CompanyU8Service;
import com.huaheng.pc.u8.domain.ICSReceiptDetail;
import com.huaheng.pc.u8.domain.ICSReceiptHeader;
import com.huaheng.pc.u8.domain.ICSReceiptModel;
import com.huaheng.api.general.domain.ReceiptDomain;
import com.huaheng.api.general.service.ReceiptApiService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.company.service.CompanyService;
import com.huaheng.pc.config.documentWarning.service.IDocumentWarningService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.warehouse.domain.Warehouse;
import com.huaheng.pc.config.warehouse.domain.WarehouseU8;
import com.huaheng.pc.config.warehouse.service.WarehouseService;
import com.huaheng.pc.config.warehouse.service.WarehouseU8Service;
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* u8-wms入库下发或回传接口服务层
* @author huaheng
* @date 2019-1-4
*
*/
@Service
public class ICSReceiptAPIService {
@Resource
private WarehouseU8Service warehouseU8Service;
@Resource
private WarehouseService warehouseService;
@Resource
private CompanyService companyService;
@Resource
private IDocumentWarningService documentWarningService;
@Resource
private ICSReceiptHeaderService icsReceiptHeaderService;
@Resource
private ICSReceiptDetailService icsReceiptDetailService;
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ReceiptContainerHeaderService receiptContainerHeaderService;
@Resource
private ReceiptContainerDetailService receiptContainerDetailService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private MaterialService materialService;
@Resource
private ReceiptApiService receiptApiService;
@Resource
private CompanyU8Service companyU8Service;
@Resource
private AddressService addressService;
//入库单下发
//采购入库
@Transactional
public AjaxResult procureReceipt(@RequestBody ICSReceiptModel icsReceiptModel) {
ICSReceiptHeader icsReceiptHeader=icsReceiptModel.getIcsReceiptHeader();
List<ICSReceiptDetail> icsReceiptDetails=icsReceiptModel.getIcsReceiptDetails();
if(StringUtils.isEmpty(icsReceiptHeader.getIsNew())){
return AjaxResult.error("isNew为空");
}
String type=icsReceiptHeader.getType();
String warehouseCode = null;
if (type.equals("TI")) {
warehouseCode = icsReceiptHeader.getIWHCode();
} else {
warehouseCode = icsReceiptHeader.getCWHCode();
}
//通过u8的货主和仓库匹配wms的仓库
LambdaQueryWrapper<WarehouseU8> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(WarehouseU8::getUCompanyCode,icsReceiptHeader.getCompanyCode())
.eq(StringUtils.isNotNull(warehouseCode),WarehouseU8::getWarehouseCode,warehouseCode);
List<WarehouseU8> list = warehouseU8Service.list(queryWrapper);
if (list.size()==0) {
return AjaxResult.error("系统没有此仓库");
}
WarehouseU8 warehouseU8 = list.get(0);
companyService.checkwarehouseCompany(warehouseU8.getCompanyCode());
//根据icsReceiptHeader生成receiptHeader
Date date = null;
try{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if(type.equals("PCI") ) {
date = sdf.parse(icsReceiptHeader.getDPODate());
}else {
date = sdf.parse(icsReceiptHeader.getDDate());
}
}catch (ParseException e){
if(icsReceiptHeader.getCCode()!= null) {
documentWarningService.ErpSendWarning(icsReceiptHeader.getCCode(), "时间转换异常");
}else {
documentWarningService.ErpSendWarning(icsReceiptHeader.getCTVCode(), "时间转换异常");
}
throw new ServiceException("时间转换异常");
}
ReceiptHeader receiptHeader=new ReceiptHeader();
String maker = icsReceiptHeader.getCMaker();
receiptHeader.setReceiptType(type);
receiptHeader.setId(null);
receiptHeader.setLastUpdatedBy(maker);
receiptHeader.setCreatedBy(maker);
receiptHeader.setLastUpdated(date);
receiptHeader.setCreated(date);
receiptHeader.setReceiptNote(icsReceiptHeader.getCMemo());
receiptHeader.setSupplierCode(icsReceiptHeader.getCVenCode());
receiptHeader.setWarehouseCode(warehouseU8.getWarehouseCode());
receiptHeader.setCompanyCode(warehouseU8.getCompanyCode());
if (type.equals("TI")) {
receiptHeader.setReferCode(icsReceiptHeader.getCTVCode());
} else if(type.equals("PCI")){
receiptHeader.setReferCode(icsReceiptHeader.getCPOID());
}else {
receiptHeader.setReferCode(icsReceiptHeader.getCCode());
}
if (StringUtils.isEmpty(receiptHeader.getReferCode())) {
documentWarningService.ErpSendWarning("", "没有单号");
throw new ServiceException("没有单号");
}
checkReceiptBill(icsReceiptHeader,receiptHeader.getReferCode());
//将主表插入到新的接收主表里去
boolean save = icsReceiptHeaderService.save(icsReceiptHeader);
if (!save) {
documentWarningService.ErpSendWarning(receiptHeader.getReferCode(), "入库主单传输失败!");
throw new ServiceException("入库主单传输失败!");
}
//将子表插入到新的接收子表里去
for (ICSReceiptDetail item : icsReceiptDetails) {
if (icsReceiptHeader.getType().equals("TI")) {
item.setCCode(icsReceiptHeader.getCTVCode());
} else {
item.setCCode(icsReceiptHeader.getCCode());
}
boolean result1 = icsReceiptDetailService.save(item);
if (!result1) {
documentWarningService.ErpSendWarning(receiptHeader.getReferCode(), "入库子单传输失败!");
throw new ServiceException("入库子单传输失败!");
}
}
//根据icsShipmentDetail生成shipmentAetail
List<ReceiptDetail> receiptDetails = new ArrayList<ReceiptDetail>();
for (ICSReceiptDetail item : icsReceiptDetails) {
//查找物料
LambdaQueryWrapper<Material> queryWrapper1 = Wrappers.lambdaQuery();
queryWrapper1.eq(Material::getCode,item.getCInvCode())
.eq(Material::getWarehouseCode,warehouseU8.getWarehouseCode());
Material material = materialService.getOne(queryWrapper1);
if (material == null) {
documentWarningService.ErpSendWarning(receiptHeader.getReferCode(), "该物料不存在:" + item.getCInvCode());
throw new ServiceException("该物料不存在:" + item.getCInvCode());
}
ReceiptDetail receiptDetail = new ReceiptDetail();
receiptDetail.setId(null);
receiptDetail.setAutoId(item.getAutoID());
if (icsReceiptHeader.getType().equals("TI")) {
receiptDetail.setAutoId(item.getITrIds());
}
receiptDetail.setReferCode(receiptHeader.getReferCode());
if(StringUtils.isNotEmpty(item.getCDefine22())) {
Boolean flag = StringUtils.isChineseChar(item.getCDefine22());
if (item.getCDefine22().length() == 19 && flag == false) {
receiptDetail.setMoCode(item.getCDefine22());
} else {
receiptDetail.setBatch(item.getCDefine22());
}
} receiptDetail.setLot(item.getCDefine23());
receiptDetail.setWarehouseCode(warehouseU8.getWarehouseCode());
receiptDetail.setMaterialCode(item.getCInvCode());
receiptDetail.setZoneCode(material.getZoneCode());
receiptDetail.setCreated(date);
receiptDetail.setMaterialUnit(item.getCComUnitName());
receiptDetail.setCreatedBy(maker);
receiptDetail.setLastUpdated(date);
receiptDetail.setLastUpdatedBy(maker);
if (!item.getCompanyCode().equals(icsReceiptHeader.getCompanyCode())) {
documentWarningService.ErpSendWarning(receiptHeader.getReferCode(), "子单货主与主单不对应");
throw new ServiceException("子单货主与主单不对应");
}
receiptDetail.setCompanyCode(warehouseU8.getCompanyCode());
receiptDetail.setProjectNo(item.getCItemName());
receiptDetail.setQty(item.getIQuantity().abs());
// receiptDetail.setQtyCompleted(item.getiQuantity());
receiptDetail.setInventorySts(QuantityConstant.GOOD);
if (item.getIrowno() != null && StringUtils.isNotEmpty(item.getIrowno().toString())) {
receiptDetail.setReferLineNum(item.getIrowno().toString());
}
receiptDetails.add(receiptDetail);
}
//调用公共API
ReceiptDomain receiptDomain = new ReceiptDomain();
receiptDomain.setReceiptHeader(receiptHeader);
receiptDomain.setReceiptDetails(receiptDetails);
AjaxResult ajaxResult = receiptApiService.receipt(receiptDomain);
if(ajaxResult.getCode()==200&&icsReceiptHeader.getIsNew().equals("1")){
return AjaxResult.success("入库单下发成功");
}else if (ajaxResult.getCode()==200&&icsReceiptHeader.getIsNew().equals("0")) {
return AjaxResult.success("入库单更新成功");
}else {
return ajaxResult;
}
}
/**
* 采购到货 or 退货入库
* 采购到货单 | 销售退货入库单
* @param icsReceiptModel
* @return
* @throws ParseException
*/
@Transactional
public AjaxResult procureArrive(ICSReceiptModel icsReceiptModel){
ICSReceiptHeader icsReceiptHeader = icsReceiptModel.getIcsReceiptHeader();
List<ICSReceiptDetail> icsReceiptDetails = icsReceiptModel.getIcsReceiptDetails();
String currentWarehouseCode = "CS0001";
// String currentWarehouseCode = icsReceiptHeader.getCWarehouseCode();
// Warehouse warehouse = warehouseService.getOne(new LambdaQueryWrapper<Warehouse>()
// .eq(Warehouse::getCode, currentWarehouseCode));
// if(warehouse==null){
// return AjaxResult.error("本系统中没有编号:【"+currentWarehouseCode+"】的仓库。");
// }
if (!icsReceiptHeader.getType().equals("SRI") && !icsReceiptHeader.getType().equals("PI")) {
return AjaxResult.error("入库类型不匹配");
}
if(StringUtils.isEmpty(icsReceiptHeader.getIsNew())){
return AjaxResult.error("isNew为空");
}
Date date = null;
try{
date = DateUtils.parseDate(icsReceiptHeader.getDPODate(), DateUtils.YYYY_MM_DD_HH_MM_SS);
}catch (ParseException e){
if(icsReceiptHeader.getCCode()!= null) {
documentWarningService.ErpSendWarning(icsReceiptHeader.getCCode(), "时间转换异常");
}else {
documentWarningService.ErpSendWarning(icsReceiptHeader.getCDLCode(), "时间转换异常");
}
return AjaxResult.error("时间:【"+icsReceiptHeader.getDPODate()+"】不能被转换,时间转换异常。");
}
String referCode=null;
if("SRI".equals(icsReceiptHeader.getType())){
referCode=icsReceiptHeader.getCDLCode();
}else {
referCode=icsReceiptHeader.getCCode();
}
if(StringUtils.isEmpty(referCode)){
if("SRI".equals(icsReceiptHeader.getType())){
documentWarningService.ErpSendWarning("", "销售退货入库单没有单号");
}else {
documentWarningService.ErpSendWarning("", "采购到货单下发没有单号");
}
return AjaxResult.error("没有单号");
}
CompanyU8 companyU8 = companyU8Service.getOne(new LambdaQueryWrapper<CompanyU8>()
.eq(CompanyU8::getUCompanyCode, icsReceiptHeader.getCompanyCode()));
if(companyU8 == null){
return AjaxResult.error("单据货主不存在"+icsReceiptHeader.getCompanyCode());
}
checkReceiptBill(icsReceiptHeader,referCode);
//判断仓库是否存在单据的物料编码
for (ICSReceiptDetail icsReceiptDetail : icsReceiptDetails) {
WarehouseU8 warehouseU8 = warehouseU8Service.getOne(new LambdaQueryWrapper<WarehouseU8>()
.eq(WarehouseU8::getUCompanyCode, icsReceiptDetail.getCompanyCode())
.eq(WarehouseU8::getUWarehouseCode, icsReceiptDetail.getCWHCode()));
if(warehouseU8==null){
return AjaxResult.error("系统没有此仓库:【"+icsReceiptDetail.getCompanyCode()+","+icsReceiptDetail.getCWHCode()+"】。");
}
}
String maker=icsReceiptHeader.getCMaker();
//调用mms更改采购状态
String url = addressService.selectAddress("mms");
CompanyU8 companyU81 = companyU8Service.getCompanyByU8CodeWarehouseCode(icsReceiptHeader.getCompanyCode(),currentWarehouseCode);
ReceiptHeader receiptHeader = new ReceiptHeader();
receiptHeader.setReceiptType(icsReceiptHeader.getType());
receiptHeader.setId(null);
receiptHeader.setLastUpdatedBy(maker);
receiptHeader.setCreatedBy(maker);
receiptHeader.setLastUpdated(date);
receiptHeader.setCreated(date);
receiptHeader.setReferCode(referCode);
receiptHeader.setSupplierCode(icsReceiptHeader.getCVenCode());
receiptHeader.setWarehouseCode(companyU81.getWarehouseCode());
receiptHeader.setCompanyCode(companyU81.getCompanyCode());
List<ReceiptDetail> receiptDetails = new ArrayList<>();
for (ICSReceiptDetail icsReceiptDetail : icsReceiptDetails) {
ReceiptDetail receiptDetail = new ReceiptDetail();
receiptDetail.setReceiptId(null);
receiptDetail.setId(null);
receiptDetail.setLot(icsReceiptDetail.getCDefine23());
receiptDetail.setReferCode(referCode);
receiptDetail.setReferId(icsReceiptDetail.getAutoID());
if(StringUtils.isNotEmpty(icsReceiptDetail.getCDefine22())) {
Boolean flag = StringUtils.isChineseChar(icsReceiptDetail.getCDefine22());
if (icsReceiptDetail.getCDefine22().length() == 19 && flag == false) {
receiptDetail.setMoCode(icsReceiptDetail.getCDefine22());
} else {
receiptDetail.setBatch(icsReceiptDetail.getCDefine22());
}
}
receiptDetail.setWarehouseCode(currentWarehouseCode);
receiptDetail.setMaterialCode(icsReceiptDetail.getCInvCode());
receiptDetail.setCreated(date);
receiptDetail.setMaterialUnit(icsReceiptDetail.getCComUnitName());
receiptDetail.setCreatedBy(maker);
receiptDetail.setLastUpdated(date);
receiptDetail.setLastUpdatedBy(maker);
if(icsReceiptHeader.getType().equals("SRI")){
receiptDetail.setCPoCode(icsReceiptDetail.getCSOCode());
}else {
receiptDetail.setCPoCode(icsReceiptDetail.getPOCode());
}
receiptDetail.setCompanyCode(companyU81.getCompanyCode());
receiptDetail.setProjectNo(icsReceiptDetail.getCItemName());
receiptDetail.setQty(icsReceiptDetail.getIQuantity().abs());
// receiptDetail.setQtyCompleted(item.getiQuantity());
receiptDetail.setInventorySts("good");
receiptDetails.add(receiptDetail);
try{
JSONObject json=new JSONObject();
json.put("code",referCode);
json.put("materialCode",icsReceiptDetail.getCInvCode().trim());
json.put("workNo",icsReceiptDetail.getMoCode().trim());
json.put("status","1");
String JsonParam = JSON.toJSONString(json);
System.out.println(JsonParam);
String result2 = HttpUtils.bodypost(url, JsonParam,currentWarehouseCode);
System.out.println(result2);
}catch(Exception e) {
e.printStackTrace();
}
}
//调用公共API
ReceiptDomain receiptModel = new ReceiptDomain();
receiptModel.setReceiptHeader(receiptHeader);
receiptModel.setReceiptDetails(receiptDetails);
AjaxResult ajaxResult = receiptApiService.receipt(receiptModel);
if(ajaxResult.getCode()==200&&icsReceiptHeader.getIsNew().equals("1")){
return AjaxResult.success("入库单下发成功");
}else if (ajaxResult.getCode()==200&&icsReceiptHeader.getIsNew().equals("0")) {
return AjaxResult.success("入库单更新成功");
}else {
return ajaxResult;
}
}
/**
* 判断入库单是否可以更新
* @param icsReceiptHeader U8入库单
* @param code U8单号
*/
private void checkReceiptBill(ICSReceiptHeader icsReceiptHeader,String code){
LambdaQueryWrapper<ICSReceiptHeader> queryWrapper4 = Wrappers.lambdaQuery();
if(icsReceiptHeader.getType().equals("TI")){
queryWrapper4.eq(ICSReceiptHeader::getCTVCode,icsReceiptHeader.getCTVCode());
}else if(icsReceiptHeader.getType().equals("SRI")){
queryWrapper4.eq(ICSReceiptHeader::getCTVCode,icsReceiptHeader.getCDLCode());
}else if(icsReceiptHeader.getType().equals("PCI")){
queryWrapper4.eq(ICSReceiptHeader::getCTVCode,icsReceiptHeader.getCPOID());
}else {
queryWrapper4.eq(ICSReceiptHeader::getCTVCode,icsReceiptHeader.getCCode());
}
ICSReceiptHeader icsr = icsReceiptHeaderService.getOne(queryWrapper4);
LambdaQueryWrapper<ReceiptHeader> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(ReceiptHeader::getReferCode,code);
ReceiptHeader receiptHeader = receiptHeaderService.getOne(queryWrapper);
if (receiptHeader != null||icsr!=null) {
if(icsReceiptHeader.getIsNew().equals("1")){
throw new ServiceException("单号重复,已跳过");
} else if(icsReceiptHeader.getIsNew().equals("0")){
if(receiptHeader!=null){
LambdaQueryWrapper<TaskDetail> queryWrapper3 = Wrappers.lambdaQuery();
queryWrapper3.eq(TaskDetail::getBillCode,receiptHeader.getCode());
List<TaskDetail> taskDetailList = taskDetailService.list(queryWrapper3);
if(taskDetailList!=null&&taskDetailList.size()>0){
taskDetailList.forEach(taskDetail -> {
Integer status = taskDetail.getStatus();
if(status<120){
throw new ServiceException("更新失敗,此入库单存在未完成的任务");
}
});
}
LambdaQueryWrapper<ReceiptContainerDetail> queryWrapper1 = Wrappers.lambdaQuery();
queryWrapper1.eq(ReceiptContainerDetail::getReceiptCode,receiptHeader.getCode());
List<ReceiptContainerDetail> receiptContainerDetails = receiptContainerDetailService.list(queryWrapper1);
if(receiptContainerDetails!=null&&receiptContainerDetails.size()>0){
ReceiptContainerDetail receiptContainerDetail = receiptContainerDetails.get(0);
LambdaQueryWrapper<ReceiptContainerHeader> queryWrapper2 = Wrappers.lambdaQuery();
queryWrapper2.eq(ReceiptContainerHeader::getId,receiptContainerDetail.getReceiptContainerId());
ReceiptContainerHeader receiptContainerHeader = receiptContainerHeaderService.getOne(queryWrapper2);
if(receiptContainerHeader!=null){
if(receiptContainerHeader.getStatus()<20){
throw new ServiceException("更新失敗,此入库单存在未完成的组盘");
}
}
}
receiptHeaderService.removeById(receiptHeader.getId());
LambdaQueryWrapper<ReceiptDetail> queryWrapper2 = Wrappers.lambdaQuery();
queryWrapper2.eq(ReceiptDetail::getReferCode,code);
receiptDetailService.remove(queryWrapper2);
}
icsReceiptHeaderService.removeById(icsr.getID());
boolean remove = icsReceiptDetailService.remove(new LambdaQueryWrapper<ICSReceiptDetail>()
.eq(ICSReceiptDetail::getCCode, code));
}
else {
throw new ServiceException("isNew值无法识别");
}
}
}
public Boolean isSameMonth(Date date){
Calendar cal1 = Calendar.getInstance();
cal1.setTime(date);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(new Date());
boolean isSameYear = cal1.get(Calendar.YEAR) == cal2
.get(Calendar.YEAR);
boolean isSameMonth = isSameYear
&& cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH);
boolean isSameDate = isSameMonth
&& cal1.get(Calendar.DAY_OF_MONTH) == cal2
.get(Calendar.DAY_OF_MONTH);
return isSameDate;
}
}