Subversion Repositories SmartDukaan

Rev

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

Rev 5460 Rev 5504
Line 4... Line 4...
4
import in.shop2020.catalog.dashboard.shared.ItemInventory;
4
import in.shop2020.catalog.dashboard.shared.ItemInventory;
5
import in.shop2020.catalog.dashboard.shared.SourcePricings;
5
import in.shop2020.catalog.dashboard.shared.SourcePricings;
6
import in.shop2020.catalog.dashboard.shared.Utils;
6
import in.shop2020.catalog.dashboard.shared.Utils;
7
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
7
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
8
import in.shop2020.catalog.dashboard.shared.VendorPricings;
8
import in.shop2020.catalog.dashboard.shared.VendorPricings;
-
 
9
import in.shop2020.catalog.dashboard.shared.VoucherItemMapping;
9
 
10
 
10
import java.util.ArrayList;
11
import java.util.ArrayList;
11
import java.util.Date;
12
import java.util.Date;
12
import java.util.HashMap;
13
import java.util.HashMap;
13
import java.util.Iterator;
14
import java.util.Iterator;
Line 77... Line 78...
77
                      TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER = 3,
78
                      TABLE_INDEX_SIMILAR_ITEMS_MODEL_NUMBER = 3,
78
                      TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME = 4,
79
                      TABLE_INDEX_SIMILAR_ITEMS_MODEL_NAME = 4,
79
                      TABLE_INDEX_SIMILAR_ITEMS_CATEGORY = 5,
80
                      TABLE_INDEX_SIMILAR_ITEMS_CATEGORY = 5,
80
                      TABLE_INDEX_SIMILAR_ITEMS_BUTTON = 6;
81
                      TABLE_INDEX_SIMILAR_ITEMS_BUTTON = 6;
81
    
82
    
-
 
83
    private final int TABLE_INDEX_VOUCHERS_TYPE = 0,
-
 
84
                      TABLE_INDEX_VOUCHERS_AMOUNT = 1,
-
 
85
                      TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON = 2,
-
 
86
                      TABLE_INDEX_VOUCHERS_DEL_BUTTON = 3;
-
 
87
    
82
    private final String MANDATORY_MRP = "MRP",
88
    private final String MANDATORY_MRP = "MRP",
83
					  MANDATORY_WEIGHT = "Weight",
89
					  MANDATORY_WEIGHT = "Weight",
84
					  MANDATORY_BEST_DEAL_TEXT = "Best Deal Text",
90
					  MANDATORY_BEST_DEAL_TEXT = "Best Deal Text",
85
					  MANDATORY_BRAND = "Brand",
91
					  MANDATORY_BRAND = "Brand",
86
					  MANDATORY_MODEL_NO = "Model Number",
92
					  MANDATORY_MODEL_NO = "Model Number",
Line 129... Line 135...
129
    @UiField CheckBox defaultForEntity, risky, warehouseStickiness, itemType, hasItemNo, clearance;
135
    @UiField CheckBox defaultForEntity, risky, warehouseStickiness, itemType, hasItemNo, clearance;
130
    @UiField DateBox startDate, expectedArrivalDate, comingSoonStartDate;
136
    @UiField DateBox startDate, expectedArrivalDate, comingSoonStartDate;
131
    @UiField FlexTable headerSimilarItems, tableSimilarItems;
137
    @UiField FlexTable headerSimilarItems, tableSimilarItems;
132
    @UiField ListBox preferredVendor;
138
    @UiField ListBox preferredVendor;
133
    @UiField Button comingSoonButton;
139
    @UiField Button comingSoonButton;
-
 
140
    @UiField FlexTable headerVouchers, tableVouchers;
134
 
141
 
135
    public ItemDetails(Item item){
142
    public ItemDetails(Item item){
136
        this();
143
        this();
137
        setItemDetails(item);
144
        setItemDetails(item);
138
    }
145
    }
Line 142... Line 149...
142
        initAvailabilityHeader();
149
        initAvailabilityHeader();
143
        initVendorKeysHeader();
150
        initVendorKeysHeader();
144
        initVendorPricingHeader();
151
        initVendorPricingHeader();
145
        initSourcePricingHeader();
152
        initSourcePricingHeader();
146
        initSimilarItemList();
153
        initSimilarItemList();
-
 
154
        initVoucherHeader();
147
        preferredVendor.addItem("null");
155
        preferredVendor.addItem("null");
148
        getConfigdataforPriceCompare();
156
        getConfigdataforPriceCompare();
149
    }
157
    }
150
 
158
 
151
    public void getConfigdataforPriceCompare(){
159
    public void getConfigdataforPriceCompare(){
Line 246... Line 254...
246
        updateAvailabilityTable(item.getItemInventory());
254
        updateAvailabilityTable(item.getItemInventory());
247
        updateVendorKeysTable(item.getVendorKeysMap());
255
        updateVendorKeysTable(item.getVendorKeysMap());
248
        updateVendorPricingTable(item.getVendorPricesMap());
256
        updateVendorPricingTable(item.getVendorPricesMap());
249
        updateSourcePricingTable(item.getSourcePricesMap());
257
        updateSourcePricingTable(item.getSourcePricesMap());
250
        updateSimilarItemsTable(item.getSimilarItems());
258
        updateSimilarItemsTable(item.getSimilarItems());
-
 
259
        updateVoucherTable(item.getVouchersMap());
251
    }
260
    }
252
 
261
 
253
    /**
262
    /**
254
     * initialise item availability table header.
263
     * initialise item availability table header.
255
     */
264
     */
Line 556... Line 565...
556
            	addSimilarItemDialog.show();
565
            	addSimilarItemDialog.show();
557
            }
566
            }
558
        });
567
        });
559
    }
568
    }
560
 
569
 
-
 
570
    private void initVoucherHeader(){
-
 
571
    	headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_TYPE, ITEM_KEY_WIDTH);
-
 
572
    	headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_AMOUNT, VENDOR_DESC_WIDTH);
-
 
573
    	headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, BUTTON_WIDTH);
-
 
574
    	headerVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_DEL_BUTTON, BUTTON_WIDTH);
-
 
575
    	
-
 
576
    	headerVouchers.setText(0, TABLE_INDEX_VOUCHERS_TYPE, "Voucher Type");
-
 
577
    	headerVouchers.setText(0, TABLE_INDEX_VOUCHERS_AMOUNT, "Voucher Amount");
-
 
578
        headerVouchers.getCellFormatter().setVisible(0, TABLE_INDEX_VOUCHERS_DEL_BUTTON, false);
-
 
579
        Button addButton = new Button("Add");
-
 
580
        headerVouchers.setWidget(0, TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, addButton);
-
 
581
        addButton.addClickHandler(new ClickHandler() {
-
 
582
            @Override
-
 
583
            public void onClick(ClickEvent event) {
-
 
584
            	VoucherItemDialog voucherItemDialog = new VoucherItemDialog();
-
 
585
            	voucherItemDialog.updateButton.setText("Add");
-
 
586
            	voucherItemDialog.setVoucherUpdateListener(new VoucherItemDialog.VoucherUpdateListener() {
-
 
587
                    @Override
-
 
588
                    public boolean onUpdate(final String voucherType, final long voucherAmount) {
-
 
589
                        if(!voucherExists(voucherType)) {
-
 
590
                            Window.alert("Voucher already exists");
-
 
591
                            return false;
-
 
592
                        }
-
 
593
                        
-
 
594
                        catalogService.addVoucher(item.getCatalogItemId(), voucherType, voucherAmount, new AsyncCallback<Boolean>() {
-
 
595
	                        @Override
-
 
596
	                        public void onSuccess(Boolean result) {
-
 
597
	                        	if(result) {
-
 
598
	                                GWT.log("Voucher Added");
-
 
599
	                                VoucherItemMapping newvoucher = new VoucherItemMapping(voucherAmount, voucherType);
-
 
600
	                                Map<String, VoucherItemMapping> newvouchersMap = item.getVouchersMap();
-
 
601
	                                newvouchersMap.put(voucherType, newvoucher);
-
 
602
	                                item.setVouchersMap(newvouchersMap);
-
 
603
	                                updateVoucherTable(item.getVouchersMap());
-
 
604
	                                Window.alert("Voucher Added successfully.");
-
 
605
	                            }
-
 
606
	                            else {
-
 
607
	                                GWT.log("Error Adding Voucher");
-
 
608
	                                Window.alert("Error Adding Voucher");
-
 
609
	                            }
-
 
610
	                        }
-
 
611
	                        @Override
-
 
612
	                        public void onFailure(Throwable caught) {
-
 
613
	                            caught.printStackTrace();
-
 
614
	                            Window.alert("Error deleting voucher");
-
 
615
	                        }
-
 
616
	                    });
-
 
617
                        return true;
-
 
618
                    }
-
 
619
                });
-
 
620
            	voucherItemDialog.show();
-
 
621
            }
-
 
622
        });
-
 
623
    }
-
 
624
 
561
    /**
625
    /**
562
     * Clear and populate item availability table.
626
     * Clear and populate item availability table.
563
     * @param availabilityMap
627
     * @param availabilityMap
564
     */
628
     */
565
    private void updateAvailabilityTable(Map<Long, ItemInventory> itemInventoryMap){
629
    private void updateAvailabilityTable(Map<Long, ItemInventory> itemInventoryMap){
Line 775... Line 839...
775
            });
839
            });
776
            i++;
840
            i++;
777
        }
841
        }
778
    }
842
    }
779
 
843
 
-
 
844
    private void updateVoucherTable(Map<String, VoucherItemMapping> vouchersMap){
-
 
845
    	tableVouchers.removeAllRows();
-
 
846
        
-
 
847
        if(vouchersMap == null || vouchersMap.isEmpty()) {
-
 
848
            return;
-
 
849
        }
-
 
850
        tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_TYPE, ITEM_KEY_WIDTH);
-
 
851
        tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_AMOUNT, VENDOR_DESC_WIDTH);
-
 
852
        tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, BUTTON_WIDTH);
-
 
853
        tableVouchers.getColumnFormatter().setWidth(TABLE_INDEX_VOUCHERS_DEL_BUTTON, BUTTON_WIDTH);
-
 
854
 
-
 
855
        int i=0;
-
 
856
        for(VoucherItemMapping voucher : vouchersMap.values()){
-
 
857
        	tableVouchers.setText(i, TABLE_INDEX_VOUCHERS_TYPE, voucher.getVoucherType());
-
 
858
        	tableVouchers.setText(i, TABLE_INDEX_VOUCHERS_AMOUNT, voucher.getAmount() + "");
-
 
859
        	
-
 
860
            Button editButton = new Button("Edit");
-
 
861
            tableVouchers.setWidget(i, TABLE_INDEX_VOUCHERS_ADD_EDIT_BUTTON, editButton);
-
 
862
            editButton.addClickHandler(new ClickHandler() {
-
 
863
                @Override
-
 
864
                public void onClick(ClickEvent event) {
-
 
865
                    Cell cell = tableVouchers.getCellForEvent(event);
-
 
866
                    final int row = cell.getRowIndex();
-
 
867
                    String voucherAmount = tableVouchers.getText(row, TABLE_INDEX_VOUCHERS_AMOUNT);
-
 
868
                    VoucherItemDialog voucherDialog = new VoucherItemDialog(voucherAmount);
-
 
869
                    voucherDialog.updateButton.setText("Update");
-
 
870
                    voucherDialog.setVoucherUpdateListener(new VoucherItemDialog.VoucherUpdateListener() {
-
 
871
                        @Override
-
 
872
                        public boolean onUpdate(final String voucherType, final long voucherAmount) {
-
 
873
                        	catalogService.addVoucher(item.getCatalogItemId(), voucherType, voucherAmount, new AsyncCallback<Boolean>() {
-
 
874
    	                        @Override
-
 
875
    	                        public void onSuccess(Boolean result) {
-
 
876
    	                        	if(result) {
-
 
877
    	                                GWT.log("Voucher Updated");
-
 
878
    	                                VoucherItemMapping newvoucher = new VoucherItemMapping(voucherAmount, voucherType);
-
 
879
    	                                Map<String, VoucherItemMapping> newvouchersMap = item.getVouchersMap();
-
 
880
    	                                newvouchersMap.remove(voucherType);
-
 
881
    	                                newvouchersMap.put(voucherType, newvoucher);
-
 
882
    	                                item.setVouchersMap(newvouchersMap);
-
 
883
    	                                updateVoucherTable(item.getVouchersMap());
-
 
884
    	                                Window.alert("Voucher Updated successfully.");
-
 
885
    	                            }
-
 
886
    	                            else {
-
 
887
    	                                GWT.log("Error Updating Voucher");
-
 
888
    	                                Window.alert("Error Updating Voucher");
-
 
889
    	                            }
-
 
890
    	                        }
-
 
891
    	                        @Override
-
 
892
    	                        public void onFailure(Throwable caught) {
-
 
893
    	                            caught.printStackTrace();
-
 
894
    	                            Window.alert("Error Updating voucher");
-
 
895
    	                        }
-
 
896
    	                    });
-
 
897
                            return true;
-
 
898
                        }
-
 
899
                    });
-
 
900
                    voucherDialog.show();
-
 
901
                }
-
 
902
            });
-
 
903
            
-
 
904
            Button deleteButton = new Button("Delete");
-
 
905
            tableVouchers.setWidget(i, TABLE_INDEX_VOUCHERS_DEL_BUTTON, deleteButton);
-
 
906
            deleteButton.addClickHandler(new ClickHandler() {
-
 
907
                @Override
-
 
908
                public void onClick(ClickEvent event) {
-
 
909
                    Cell cell = tableVouchers.getCellForEvent(event);
-
 
910
                    final int row = cell.getRowIndex();
-
 
911
                    String voucherType = tableVouchers.getText(row, TABLE_INDEX_VOUCHERS_TYPE);
-
 
912
                    
-
 
913
                    catalogService.deleteVoucher(item.getCatalogItemId(), voucherType, new AsyncCallback<Boolean>() {
-
 
914
                        @Override
-
 
915
                        public void onSuccess(Boolean result) {
-
 
916
                            if(result) {
-
 
917
                                GWT.log("Voucher deleted");
-
 
918
                                String voucherType = tableVouchers.getText(row, TABLE_INDEX_VOUCHERS_TYPE);
-
 
919
                                tableVouchers.removeRow(row);
-
 
920
                                Map<String, VoucherItemMapping> newvouchersMap = item.getVouchersMap();
-
 
921
                                newvouchersMap.remove(voucherType);
-
 
922
                                item.setVouchersMap(newvouchersMap);
-
 
923
                            }
-
 
924
                            else {
-
 
925
                                GWT.log("Error deleting Voucher");
-
 
926
                                Window.alert("Error deleting Voucher");
-
 
927
                            }
-
 
928
                        }
-
 
929
                        @Override
-
 
930
                        public void onFailure(Throwable caught) {
-
 
931
                            caught.printStackTrace();
-
 
932
                            Window.alert("Error deleting Voucher");
-
 
933
                        }
-
 
934
                    });
-
 
935
                }
-
 
936
            });
-
 
937
            i++;
-
 
938
        }
-
 
939
    }
-
 
940
 
780
    /**
941
    /**
781
     * called on the click event of update item button in ItemActions
942
     * called on the click event of update item button in ItemActions
782
     */
943
     */
783
    void updateItem() {
944
    void updateItem() {
784
        if(item == null) {
945
        if(item == null) {
Line 1057... Line 1218...
1057
        newItem.setRetireDate(item.getRetireDate());
1218
        newItem.setRetireDate(item.getRetireDate());
1058
        newItem.setUpdatedOn(item.getUpdatedOn());
1219
        newItem.setUpdatedOn(item.getUpdatedOn());
1059
        newItem.setItemStatus(item.getItemStatus());
1220
        newItem.setItemStatus(item.getItemStatus());
1060
        newItem.setItemInventory(item.getItemInventory());
1221
        newItem.setItemInventory(item.getItemInventory());
1061
        newItem.setSimilarItems(item.getSimilarItems());
1222
        newItem.setSimilarItems(item.getSimilarItems());
-
 
1223
        newItem.setVouchersMap(item.getVouchersMap());
1062
        
1224
        
1063
        return true;
1225
        return true;
1064
    }
1226
    }
1065
 
1227
 
1066
    /**
1228
    /**
Line 1344... Line 1506...
1344
    
1506
    
1345
    public Item getItem() {
1507
    public Item getItem() {
1346
        return item;
1508
        return item;
1347
    }
1509
    }
1348
    
1510
    
-
 
1511
    private boolean voucherExists(String voucherType) {
-
 
1512
        for(int i = 0; i < tableVouchers.getRowCount(); i++) {
-
 
1513
            if(voucherType.equals(tableVouchers.getText(i, TABLE_INDEX_VOUCHERS_TYPE))) {
-
 
1514
                return false;
-
 
1515
            }
-
 
1516
        }
-
 
1517
        return true;
-
 
1518
    }
-
 
1519
    
1349
    /**
1520
    /**
1350
     * This method is used while adding vendor prices to ensure that there is only one row in the table for a vendor.
1521
     * This method is used while adding vendor prices to ensure that there is only one row in the table for a vendor.
1351
     * @param vendorId
1522
     * @param vendorId
1352
     * @return true if parameter vendor Id is already added to vendor prices table.
1523
     * @return true if parameter vendor Id is already added to vendor prices table.
1353
     *      <br>else false
1524
     *      <br>else false