Subversion Repositories SmartDukaan

Rev

Rev 37613 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
37613 amit 1
package com.smartdukaan.cron.migrations;
2
 
3
import org.apache.logging.log4j.LogManager;
4
import org.apache.logging.log4j.Logger;
5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.stereotype.Component;
7
 
8
import java.util.List;
9
 
10
/**
11
 * Receives stock into the destination warehouse for internal transfer invoices that were billed but never
37614 amit 12
 * GRNed. The receiving itself is InternalGrnReceiver, one invoice at a time.
37613 amit 13
 *
37614 amit 14
 * This driver carries no transaction of its own. It must not, and it must not hold the receiving logic
15
 * either: a transactional method called from within its own bean is a self invocation, which bypasses the
16
 * Spring proxy and runs with no transaction at all.
37613 amit 17
 */
18
@Component
19
public class InternalGrnTask {
20
 
21
    private static final Logger LOGGER = LogManager.getLogger(InternalGrnTask.class);
22
 
23
    @Autowired
37614 amit 24
    private InternalGrnReceiver internalGrnReceiver;
37613 amit 25
 
26
    public void grnInternalInvoices(List<String> invoiceNumbers, String operatorEmail, boolean dryRun) {
27
        LOGGER.info("=== Internal GRN {} : {} invoice(s), operator {} ===",
28
                dryRun ? "DRY RUN (no writes)" : "LIVE RUN", invoiceNumbers.size(), operatorEmail);
29
        int received = 0;
30
        int skipped = 0;
31
        int failed = 0;
32
        for (String invoiceNumber : invoiceNumbers) {
33
            try {
37614 amit 34
                if (internalGrnReceiver.grnInvoice(invoiceNumber.trim(), operatorEmail, dryRun)) {
37613 amit 35
                    received++;
36
                } else {
37
                    skipped++;
38
                }
39
            } catch (Exception e) {
40
                failed++;
41
                LOGGER.error("FAILED  {} - {}", invoiceNumber, e.getMessage(), e);
42
            }
43
        }
44
        LOGGER.info("=== Internal GRN {} complete : {} {}, {} skipped, {} failed ===",
45
                dryRun ? "DRY RUN" : "LIVE RUN", received, dryRun ? "would be received" : "received",
46
                skipped, failed);
47
    }
48
}