Subversion Repositories SmartDukaan

Rev

Rev 33225 | Rev 33227 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33225 Rev 33226
Line 737... Line 737...
737
        Map<LocalDate, List<StatementDetailModel>> dateInvoiceMap = invoiceDetails.stream().collect(Collectors.groupingBy(x -> x.getOnDate().toLocalDate()));
737
        Map<LocalDate, List<StatementDetailModel>> dateInvoiceMap = invoiceDetails.stream().collect(Collectors.groupingBy(x -> x.getOnDate().toLocalDate()));
738
        //LOGGER.info("dateInvoiceMap - {}", dateInvoiceMap);
738
        //LOGGER.info("dateInvoiceMap - {}", dateInvoiceMap);
739
        Map<LocalDate, List<UserWalletHistory>> dateWalletMap = history.stream().collect(Collectors.groupingBy(x -> x.getTimestamp().toLocalDate()));
739
        Map<LocalDate, List<UserWalletHistory>> dateWalletMap = history.stream().collect(Collectors.groupingBy(x -> x.getTimestamp().toLocalDate()));
740
        XSSFWorkbook workbook = new XSSFWorkbook(is);
740
        XSSFWorkbook workbook = new XSSFWorkbook(is);
741
        CreationHelper creationHelper = workbook.getCreationHelper();
741
        CreationHelper creationHelper = workbook.getCreationHelper();
742
        CellStyle style2 = workbook.createCellStyle();
742
        CellStyle dateStyle = workbook.createCellStyle();
743
        style2.setDataFormat(creationHelper.createDataFormat().getFormat("dd/mm/yyyy"));
743
        dateStyle.setDataFormat(creationHelper.createDataFormat().getFormat("dd/mm/yyyy"));
744
 
744
 
745
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
745
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
746
        Sheet sheet = workbook.getSheetAt(0);
746
        Sheet sheet = workbook.getSheetAt(0);
747
        sheet.getRow(0).getCell(0).setCellValue(customRetailer.getBusinessName());
747
        sheet.getRow(0).getCell(0).setCellValue(customRetailer.getBusinessName());
748
        sheet.getRow(1).getCell(1).setCellValue(new Date(startLocalDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
748
        sheet.getRow(1).getCell(1).setCellValue(new Date(startLocalDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
Line 753... Line 753...
753
        int row = 4;
753
        int row = 4;
754
        LocalDate startDate = startLocalDateTime.toLocalDate();
754
        LocalDate startDate = startLocalDateTime.toLocalDate();
755
        LocalDate endDate = endLocalDateTime.toLocalDate();
755
        LocalDate endDate = endLocalDateTime.toLocalDate();
756
        LOGGER.info(" startDate - {}", startDate);
756
        LOGGER.info(" startDate - {}", startDate);
757
        LOGGER.info(" endDate - {}", endDate);
757
        LOGGER.info(" endDate - {}", endDate);
-
 
758
        double currentOpening = openingBalance;
758
        for (LocalDate date = startDate; date.isBefore(endDate.plusDays(1)); date = date.plusDays(1)) {
759
        for (LocalDate date = startDate; date.isBefore(endDate.plusDays(1)); date = date.plusDays(1)) {
759
            List<UserWalletHistory> datewiseWalletHistory = dateWalletMap.get(date);
760
            List<UserWalletHistory> datewiseWalletHistory = dateWalletMap.get(date);
760
            LOGGER.info("date - {}, datewiseWalletHistory - {}", date, datewiseWalletHistory);
761
            LOGGER.info("date - {}, datewiseWalletHistory - {}", date, datewiseWalletHistory);
761
            if (datewiseWalletHistory != null) {
762
            if (datewiseWalletHistory != null) {
762
                for (UserWalletHistory walletEntry : datewiseWalletHistory) {
763
                for (UserWalletHistory walletEntry : datewiseWalletHistory) {
763
                    Cell dateCell = sheet.createRow(row).createCell(0);
764
                    Cell dateCell = sheet.createRow(row).createCell(0);
-
 
765
                    //Date
764
                    dateCell.setCellValue(new Date(walletEntry.getTimestamp().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
766
                    dateCell.setCellValue(new Date(walletEntry.getTimestamp().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
765
                    dateCell.setCellStyle(style2);
767
                    dateCell.setCellStyle(dateStyle);
-
 
768
                    //TransactType
766
                    sheet.getRow(row).createCell(1).setCellValue(walletEntry.getReferenceType().toString());
769
                    sheet.getRow(row).createCell(1).setCellValue(walletEntry.getReferenceType().toString());
-
 
770
                    //Reference Id
-
 
771
                    sheet.getRow(row).createCell(5).setCellValue(walletEntry.getReference());
767
                    if (walletEntry.getAmount() > 0) {
772
                    if (walletEntry.getAmount() > 0) {
-
 
773
                        //Debit
768
                        sheet.getRow(row).createCell(2).setCellValue(0);
774
                        sheet.getRow(row).createCell(2).setCellValue(0);
-
 
775
                        //Credit
769
                        sheet.getRow(row).createCell(3).setCellValue(walletEntry.getAmount());
776
                        sheet.getRow(row).createCell(3).setCellValue(walletEntry.getAmount());
770
                        grandTotalCredit += walletEntry.getAmount();
777
                        grandTotalCredit += walletEntry.getAmount();
771
                    } else {
778
                    } else {
772
                        sheet.getRow(row).createCell(2).setCellValue(-walletEntry.getAmount());
779
                        sheet.getRow(row).createCell(2).setCellValue(-walletEntry.getAmount());
773
                        sheet.getRow(row).createCell(3).setCellValue(0);
780
                        sheet.getRow(row).createCell(3).setCellValue(0);
774
                        grandTotalDebit -= walletEntry.getAmount();
781
                        grandTotalDebit -= walletEntry.getAmount();
775
                    }
782
                    }
-
 
783
                    //Running balance
-
 
784
                    currentOpening += walletEntry.getAmount();
-
 
785
                    sheet.getRow(row).createCell(4).setCellValue(currentOpening);
-
 
786
                    //Description
776
                    sheet.getRow(row).createCell(4).setCellValue(walletEntry.getDescription());
787
                    sheet.getRow(row).createCell(4).setCellValue(walletEntry.getDescription());
777
                    sheet.getRow(row).createCell(5).setCellValue(walletEntry.getReference());
-
 
778
                    row++;
788
                    row++;
779
                }
789
                }
780
            }
790
            }
781
            List<StatementDetailModel> statementDetailModels = dateInvoiceMap.get(date);
791
            List<StatementDetailModel> statementDetailModels = dateInvoiceMap.get(date);
782
            LOGGER.info("statementDetailModels - {}", statementDetailModels);
792
            LOGGER.info("statementDetailModels - {}", statementDetailModels);
783
            if (statementDetailModels != null) {
793
            if (statementDetailModels != null) {
784
                for (StatementDetailModel statementDetailModel : statementDetailModels) {
794
                for (StatementDetailModel statementDetailModel : statementDetailModels) {
785
                    Cell dateCell = sheet.createRow(row).createCell(0);
795
                    Cell dateCell = sheet.createRow(row).createCell(0);
786
                    dateCell.setCellValue(statementDetailModel.getOnDate());
796
                    dateCell.setCellValue(statementDetailModel.getOnDate());
787
                    dateCell.setCellStyle(style2);
797
                    dateCell.setCellStyle(dateStyle);
-
 
798
                    //Transact Type
788
                    sheet.getRow(row).createCell(1).setCellValue("BILLING");
799
                    sheet.getRow(row).createCell(1).setCellValue("BILLING");
-
 
800
                    //Transact Reference
-
 
801
                    sheet.getRow(row).createCell(5).setCellValue(statementDetailModel.getInvoiceNumber());
789
                    if (statementDetailModel.getAmount() > 0) {
802
                    if (statementDetailModel.getAmount() > 0) {
790
                        sheet.getRow(row).createCell(2).setCellValue(statementDetailModel.getAmount());
803
                        sheet.getRow(row).createCell(2).setCellValue(statementDetailModel.getAmount());
791
                        sheet.getRow(row).createCell(3).setCellValue(0);
804
                        sheet.getRow(row).createCell(3).setCellValue(0);
792
                        grandTotalDebit += statementDetailModel.getAmount();
805
                        grandTotalDebit += statementDetailModel.getAmount();
793
                    } else {
806
                    } else {
794
                        sheet.getRow(row).createCell(2).setCellValue(0);
807
                        sheet.getRow(row).createCell(2).setCellValue(0);
795
                        sheet.getRow(row).createCell(3).setCellValue(-statementDetailModel.getAmount());
808
                        sheet.getRow(row).createCell(3).setCellValue(-statementDetailModel.getAmount());
796
                        grandTotalCredit += -statementDetailModel.getAmount();
809
                        grandTotalCredit += -statementDetailModel.getAmount();
797
                    }
810
                    }
-
 
811
                    //Running Balance
-
 
812
                    currentOpening += statementDetailModel.getAmount();
-
 
813
 
798
 
814
 
-
 
815
                    //Narration
799
                    sheet.getRow(row).createCell(4).setCellValue(statementDetailModel.getReferenceType());
816
                    sheet.getRow(row).createCell(4).setCellValue(statementDetailModel.getReferenceType());
800
                    sheet.getRow(row).createCell(5).setCellValue(statementDetailModel.getInvoiceNumber());
-
 
801
 
817
 
802
                    row += 1;
818
                    row += 1;
803
                }
819
                }
804
            }
820
            }
805
            if (YearMonth.from(date).atEndOfMonth().equals(date)) {
821
            if (YearMonth.from(date).atEndOfMonth().equals(date)) {
Line 807... Line 823...
807
                if (creditNotes != null) {
823
                if (creditNotes != null) {
808
                    for (CreditNote creditNote : creditNotes) {
824
                    for (CreditNote creditNote : creditNotes) {
809
                        double cnAmount = creditNoteLineRepository.selectAllByCreditNote(creditNote.getId()).stream().collect(Collectors.summingDouble(x -> x.getAmount()));
825
                        double cnAmount = creditNoteLineRepository.selectAllByCreditNote(creditNote.getId()).stream().collect(Collectors.summingDouble(x -> x.getAmount()));
810
                        Cell dateCell = sheet.createRow(row).createCell(0);
826
                        Cell dateCell = sheet.createRow(row).createCell(0);
811
                        dateCell.setCellValue(new Date(date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
827
                        dateCell.setCellValue(new Date(date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
812
                        dateCell.setCellStyle(style2);
828
                        dateCell.setCellStyle(dateStyle);
813
                        sheet.getRow(row).createCell(1).setCellValue("CREDIT NOTE");
829
                        sheet.getRow(row).createCell(1).setCellValue("CREDIT NOTE");
-
 
830
                        sheet.getRow(row).createCell(5).setCellValue(creditNote.getCreditNoteNumber());
814
                        if (cnAmount > 0) {
831
                        if (cnAmount > 0) {
815
                            sheet.getRow(row).createCell(2).setCellValue(0);
832
                            sheet.getRow(row).createCell(2).setCellValue(0);
816
                            sheet.getRow(row).createCell(3).setCellValue(cnAmount);
833
                            sheet.getRow(row).createCell(3).setCellValue(cnAmount);
817
                            grandTotalCredit += cnAmount;
834
                            grandTotalCredit += cnAmount;
818
                        } else {
835
                        } else {
819
                            sheet.getRow(row).createCell(2).setCellValue(-cnAmount);
836
                            sheet.getRow(row).createCell(2).setCellValue(-cnAmount);
820
                            sheet.getRow(row).createCell(3).setCellValue(0);
837
                            sheet.getRow(row).createCell(3).setCellValue(0);
821
                            grandTotalDebit += -cnAmount;
838
                            grandTotalDebit += -cnAmount;
822
                        }
839
                        }
823
 
-
 
-
 
840
                        //Running balance
-
 
841
                        currentOpening += cnAmount;
-
 
842
                        sheet.getRow(row).createCell(4).setCellValue(currentOpening);
-
 
843
                        //Narration
824
                        sheet.getRow(row).createCell(4).setCellValue("Credit Note Issued");
844
                        sheet.getRow(row).createCell(4).setCellValue("Credit Note Issued");
825
                        sheet.getRow(row).createCell(5).setCellValue(creditNote.getCreditNoteNumber());
-
 
826
 
845
 
827
                        row += 1;
846
                        row += 1;
828
                    }
847
                    }
829
                }
848
                }
830
            }
849
            }