Subversion Repositories SmartDukaan

Rev

Rev 2832 | Blame | Last modification | View Log | RSS feed

package in.shop2020.hotspot.dashbaord.server;

import in.shop2020.hotspot.dashbaord.shared.actions.PoType;
import in.shop2020.hotspot.dashbaord.shared.actions.PurchaseOrder;
import in.shop2020.thrift.clients.WarehouseClient;
import in.shop2020.utils.GmailUtils;
import in.shop2020.warehouse.POStatus;
import in.shop2020.warehouse.Supplier;
import in.shop2020.warehouse.WarehouseService.Client;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WareHouseUtils {
    
    private static Logger logger = LoggerFactory.getLogger(WareHouseUtils.class);
    
    public static List<PurchaseOrder> getPurchaseOrders(PoType type, long warehouseId){
        List<POStatus> statuses = getStatuses(type);
        for(POStatus status : statuses){
            
        }
        return null;
    }
    
    private static List<POStatus> getStatuses(PoType type){
        List<POStatus> statuses = new ArrayList<POStatus>();
        switch(type){
        case ALL:
            statuses.add(POStatus.INIT);
            statuses.add(POStatus.READY);
            statuses.add(POStatus.PARTIALLY_FULFILLED);
            statuses.add(POStatus.PRECLOSED);
            statuses.add(POStatus.CLOSED);
            break;
        case NEW:
            statuses.add(POStatus.READY);
            break;
        case OPEN:
            statuses.add(POStatus.PARTIALLY_FULFILLED);
            statuses.add(POStatus.READY);
            break;
        case CLOSED:
            statuses.add(POStatus.PRECLOSED);
            statuses.add(POStatus.CLOSED);
            break;
        }
        
        return statuses;
    }
    
    public static void sendPurchaseOrder(long purchaseOrderId){
        try {
            WarehouseClient warehouseServiceClient = new WarehouseClient();
            Client client = warehouseServiceClient.getClient();
            in.shop2020.warehouse.PurchaseOrder purchaseOrder = client.getPurchaseOrder(purchaseOrderId);
            Supplier supplier = client.getSupplier(purchaseOrder.getSupplierId());
            
            String filename = PoSheetGenerator.generatePdfSheet(purchaseOrder, supplier);
            String[] sendTo = { supplier.getContactEmail(), supplier.getHeadEmail() };
            String emailSubjectTxt = "Purchase Order No. " + purchaseOrder.getPoNumber();
            String emailMsgTxt = "Dear Sir/Madam\n\nCould you please fulfill the attached Purchase Order?\n\nThanks and Regards\nAnand Sinha";
            String emailFromAddress = "cnc.center@shop2020.in";
            String password = "5h0p2o2o";
            GmailUtils mailer = new GmailUtils();
            mailer.sendSSLMessage(sendTo, emailSubjectTxt, emailMsgTxt, emailFromAddress, password, filename);
        } catch (Exception e) {
            logger.error("Unable to send purchase order", e);
        }
    }
}