Subversion Repositories SmartDukaan

Rev

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

Rev 34563 Rev 34710
Line 34... Line 34...
34
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
34
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
35
import com.spice.profitmandi.dao.enumuration.catalog.StockTransactionType;
35
import com.spice.profitmandi.dao.enumuration.catalog.StockTransactionType;
36
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
36
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
37
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
37
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
38
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
38
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
-
 
39
import com.spice.profitmandi.dao.enumuration.transaction.LoanReferenceType;
39
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
40
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
40
import com.spice.profitmandi.dao.model.*;
41
import com.spice.profitmandi.dao.model.*;
41
import com.spice.profitmandi.dao.repository.GenericRepository;
42
import com.spice.profitmandi.dao.repository.GenericRepository;
42
import com.spice.profitmandi.dao.repository.catalog.*;
43
import com.spice.profitmandi.dao.repository.catalog.*;
43
import com.spice.profitmandi.dao.repository.cs.CsService;
44
import com.spice.profitmandi.dao.repository.cs.CsService;
Line 110... Line 111...
110
import org.springframework.transaction.annotation.Transactional;
111
import org.springframework.transaction.annotation.Transactional;
111
 
112
 
112
import java.io.File;
113
import java.io.File;
113
import java.io.FileInputStream;
114
import java.io.FileInputStream;
114
import java.io.IOException;
115
import java.io.IOException;
-
 
116
import java.math.BigDecimal;
115
import java.time.*;
117
import java.time.*;
116
import java.time.temporal.ChronoUnit;
118
import java.time.temporal.ChronoUnit;
117
import java.util.*;
119
import java.util.*;
118
import java.util.concurrent.TimeUnit;
120
import java.util.concurrent.TimeUnit;
119
import java.util.stream.Collectors;
121
import java.util.stream.Collectors;
Line 1162... Line 1164...
1162
    CartService cartService;
1164
    CartService cartService;
1163
 
1165
 
1164
    @Autowired
1166
    @Autowired
1165
    private CommonPaymentService commonPaymentService;
1167
    private CommonPaymentService commonPaymentService;
1166
 
1168
 
1167
    public void getSweet() throws Exception {
-
 
1168
        List<Integer> fofoIds = Arrays.asList(175139179, 175139178, 175138987, 175138174, 175138843, 175139094, 175135227, 175138908, 175138814, 175139015, 175135707, 175138886, 175139211, 175139130, 159690067, 175139161, 175138842, 175138867, 175139218, 175127215, 175139238, 175139267, 175138541, 175139248, 175138989, 175139232, 175139257, 175138840, 175138829, 175138836, 175139242, 175139217, 175139246, 175139222, 175139256, 175139261, 175139154, 175139266, 175138906, 175138820, 175138951, 175139255, 175139172, 175139264, 175138863, 175139029, 175138934, 175139258, 175139270, 175138408, 175139180, 175139230, 175135923, 175139237, 175139227, 175139191, 175139268, 175139203, 166900459, 175138982, 175139236, 175139205, 175139241, 175138875, 175139184, 175138948, 175139176, 175139189, 175139019, 175139233, 175139204, 175138868, 175139138, 175139262, 175139207, 175138871, 175139188, 175138929, 175139199, 167996137, 175139102, 175139259, 175139260, 175138827, 175139082, 175139158, 175139229, 175139149, 175139073, 175139215, 175139249, 175139223, 175139235, 175139006, 175139107, 175138970, 175139123, 175139114, 175139074, 175139135, 175138883, 175139187, 175139247, 175138856, 175138983, 175138832, 175139190, 175139231, 175139079, 157327507, 175138864, 175139129, 175139214, 175138876, 175139212, 175139146, 175139150, 175139069, 175139025, 175139202, 175139224, 175139243, 175138958, 175139045, 175139108, 175139195, 175139164, 175139181, 175139013, 175138844, 175139226, 175138816, 175139219, 175139088, 175138897, 175139081, 175139197, 175138931);
-
 
1169
        for (int fofoId : fofoIds) {
-
 
1170
            User user = userRepository.selectById(fofoId);
-
 
1171
            UserCart uc = new UserCart();
-
 
1172
            uc.setUserId(fofoId);
-
 
1173
            uc.setCartId(user.getActiveCartId());
-
 
1174
            List<CartItem> cartItems = new ArrayList<>();
-
 
1175
            CartItem cartItem = new CartItem();
-
 
1176
            cartItem.setItemId(33855);
-
 
1177
            cartItem.setSellingPrice(0.1d);
-
 
1178
            cartItem.setQuantity(1);
-
 
1179
            cartItems.add(cartItem);
-
 
1180
            cartService.addItemsToCart(uc.getCartId(), cartItems);
-
 
1181
            int transactionId = transactionService.createTransaction(uc, 0.1, 0);
-
 
1182
            commonPaymentService.payThroughWallet(transactionId);
-
 
1183
            // Once paid let proceed to process the order further.
-
 
1184
 
1169
 
-
 
1170
    @Autowired
-
 
1171
    LoanRepository loanRepository;
-
 
1172
 
-
 
1173
    @Autowired
-
 
1174
    LoanStatementRepository loanStatementRepository;
-
 
1175
 
-
 
1176
 
-
 
1177
    //Reverse CD of a specified Loan
-
 
1178
    public void reverseCD() throws ProfitMandiBusinessException {
-
 
1179
        Loan loan = loanRepository.selectByLoanId(45975);
-
 
1180
        List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
-
 
1181
        loanStatements.stream().filter(x->x.getLoanReferenceType().equals(LoanReferenceType.PRINCIPAL) && x.getAmount().compareTo(BigDecimal.ZERO) > 0).forEach(x->loanStatementRepository.delete(x));
-
 
1182
        loan.setSettledOn(null);
-
 
1183
        loan.setPendingAmount(loan.getIntialAmount());
-
 
1184
        String invoiceNumber = loan.getInvoiceNumber();
-
 
1185
        Purchase purchase = purchaseRepository.selectByPurchaseReference(invoiceNumber);
-
 
1186
        List<Integer> iis = inventoryItemRepository.selectByPurchaseId(purchase.getId()).stream().map(x->x.getId()).collect(Collectors.toList());
-
 
1187
        for (Integer ii : iis) {
-
 
1188
            List<SchemeInOut> sios = schemeInOutRepository.selectAllByType(SchemeType.CASH_DISCOUNT, ii);
-
 
1189
            if(sios.size() > 0) {
-
 
1190
                schemeInOutRepository.delete(sios.get(0));
-
 
1191
            }
-
 
1192
            List<SchemeInOut> sios1 = schemeInOutRepository.selectAllByType(SchemeType.CASH_DISCOUNT1, ii);
-
 
1193
            if(sios1.size() > 0) {
1185
            transactionService.processTransaction(transactionId,0);
1194
                schemeInOutRepository.delete(sios1.get(0));
-
 
1195
            }
-
 
1196
 
1186
        }
1197
        }
-
 
1198
        List<UserWalletHistory> uwhs = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(purchase.getId(), WalletReferenceType.SCHEME_IN);
-
 
1199
        for (UserWalletHistory uwh : uwhs) {
-
 
1200
            genericRepository.delete(uwh);
-
 
1201
        }
-
 
1202
 
1187
    }
1203
    }
1188
 
1204
 
1189
    private class SioTuple {
1205
    private class SioTuple {
1190
        int inventoryId;
1206
        int inventoryId;
1191
        SchemeType schemeType;
1207
        SchemeType schemeType;
Line 1969... Line 1985...
1969
            for (Map.Entry<YearMonth, Double> yearMonthAmountEntry : fofoMonthAmountEntry.getValue().entrySet()) {
1985
            for (Map.Entry<YearMonth, Double> yearMonthAmountEntry : fofoMonthAmountEntry.getValue().entrySet()) {
1970
                YearMonth yearMonth = yearMonthAmountEntry.getKey();
1986
                YearMonth yearMonth = yearMonthAmountEntry.getKey();
1971
                double walletAmount = yearMonthAmountEntry.getValue();
1987
                double walletAmount = yearMonthAmountEntry.getValue();
1972
                double cnAmount = 0;
1988
                double cnAmount = 0;
1973
                List<Integer> creditNoteIds = creditNoteRepository.selectAll(fofoId, yearMonth).stream().map(cn -> cn.getId()).collect(Collectors.toList());
1989
                List<Integer> creditNoteIds = creditNoteRepository.selectAll(fofoId, yearMonth).stream().map(cn -> cn.getId()).collect(Collectors.toList());
1974
                if(creditNoteIds.size() > 0) {
1990
                if (creditNoteIds.size() > 0) {
1975
                    cnAmount = creditNoteLineRepository.selectAllByCreditNoteIds(creditNoteIds).stream().collect(Collectors.summingDouble(CreditNoteLine::getAmount));
1991
                    cnAmount = creditNoteLineRepository.selectAllByCreditNoteIds(creditNoteIds).stream().collect(Collectors.summingDouble(CreditNoteLine::getAmount));
1976
                }
1992
                }
1977
                if(cnAmount != walletAmount) {
1993
                if (cnAmount != walletAmount) {
1978
                    System.out.println(fofoId + "\t" + yearMonth + "\t" + walletAmount + "\t" + cnAmount);
1994
                    System.out.println(fofoId + "\t" + yearMonth + "\t" + walletAmount + "\t" + cnAmount);
1979
                }
1995
                }
1980
 
1996
 
1981
 
1997
 
1982
            }
1998
            }