| Line 112... |
Line 112... |
| 112 |
* manifested.
|
112 |
* manifested.
|
| 113 |
* @param cod
|
113 |
* @param cod
|
| 114 |
* Whether cod orders have to be marked as manifested
|
114 |
* Whether cod orders have to be marked as manifested
|
| 115 |
* @return True if everything goes fine, false otherwise.
|
115 |
* @return True if everything goes fine, false otherwise.
|
| 116 |
*/
|
116 |
*/
|
| 117 |
public static boolean markOrdersAsManifested(long warehouseId, String providerId, boolean cod){
|
117 |
public static List<Long> getBilledOrders(long warehouseId, String providerId, boolean cod){
|
| - |
|
118 |
List<Long> orders = new ArrayList<Long>();
|
| 118 |
try {
|
119 |
try {
|
| 119 |
long provider_id = Long.parseLong(providerId);
|
120 |
long provider_id = Long.parseLong(providerId);
|
| 120 |
TransactionClient client = new TransactionClient();
|
121 |
TransactionClient client = new TransactionClient();
|
| 121 |
Client c = client.getClient();
|
122 |
Client c = client.getClient();
|
| - |
|
123 |
|
| 122 |
if(generateCourierDetailsFile(warehouseId, provider_id, cod)){
|
124 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
| - |
|
125 |
statuses.add(OrderStatus.BILLED);
|
| - |
|
126 |
List<in.shop2020.model.v1.order.Order> torders = c.getOrdersInBatch(statuses, 0, 0, warehouseId);
|
| - |
|
127 |
for(in.shop2020.model.v1.order.Order torder: torders){
|
| 123 |
return c.markOrdersAsShippedFromWarehouse(warehouseId, provider_id, cod);
|
128 |
if(torder.getLogistics_provider_id() == provider_id && torder.isCod() == cod){
|
| 124 |
}else{
|
129 |
orders.add(torder.getId());
|
| 125 |
return false;
|
130 |
}
|
| 126 |
}
|
131 |
}
|
| 127 |
|
132 |
|
| 128 |
}catch(Exception e){
|
133 |
}catch(Exception e){
|
| 129 |
e.printStackTrace();
|
134 |
e.printStackTrace();
|
| 130 |
return false;
|
- |
|
| 131 |
}
|
135 |
}
|
| - |
|
136 |
return orders;
|
| 132 |
}
|
137 |
}
|
| 133 |
|
138 |
|
| 134 |
private static boolean generateCourierDetailsFile(long warehouseId, long providerId, boolean isCod){
|
139 |
public static boolean generateCourierDetailsFile(List<Long> orderIds, long providerId, long warehouseId, boolean isCod){
|
| 135 |
Calendar date = new GregorianCalendar();
|
140 |
Calendar date = new GregorianCalendar();
|
| 136 |
int year = date.get(Calendar.YEAR);
|
141 |
int year = date.get(Calendar.YEAR);
|
| 137 |
int month = date.get(Calendar.MONTH) +1;
|
142 |
int month = date.get(Calendar.MONTH) +1;
|
| 138 |
int day = date.get(Calendar.DAY_OF_MONTH);
|
143 |
int day = date.get(Calendar.DAY_OF_MONTH);
|
| 139 |
|
144 |
|
| 140 |
String fileNameSuffix = "-" + warehouseId + "-"+ providerId + "-" + year + "-" + month + "-" + day;
|
145 |
String fileNameSuffix = "-" + warehouseId + "-"+ providerId + "-" + year + "-" + month + "-" + day;
|
| 141 |
String mergedFileNameSuffix = "-" + 0 + "-"+ providerId + "-" + year + "-" + month + "-" + day;
|
- |
|
| 142 |
if(isCod){
|
146 |
if(isCod){
|
| 143 |
fileNameSuffix = "cod" + fileNameSuffix ;
|
147 |
fileNameSuffix = "cod" + fileNameSuffix ;
|
| 144 |
mergedFileNameSuffix = "cod" + mergedFileNameSuffix;
|
- |
|
| 145 |
}
|
148 |
}
|
| 146 |
else{
|
149 |
else{
|
| 147 |
fileNameSuffix = "prepaid" + fileNameSuffix;
|
150 |
fileNameSuffix = "prepaid" + fileNameSuffix;
|
| 148 |
mergedFileNameSuffix = "prepaid" + mergedFileNameSuffix;
|
- |
|
| 149 |
}
|
151 |
}
|
| 150 |
|
152 |
|
| 151 |
try {
|
153 |
try {
|
| 152 |
String fileName = courierDetailsPath + "/courier-details-" + fileNameSuffix + ".xls";
|
154 |
String fileName = courierDetailsPath + "/courier-details-" + fileNameSuffix + "-temp.xls";
|
| 153 |
File file = new File(fileName);
|
- |
|
| 154 |
if(file.exists()){
|
- |
|
| 155 |
return false;
|
- |
|
| 156 |
}
|
- |
|
| 157 |
FileOutputStream f = new FileOutputStream(fileName);
|
155 |
FileOutputStream f = new FileOutputStream(fileName);
|
| 158 |
CourierDetailsGenerator courierDetailsGenerator = new CourierDetailsGenerator();
|
156 |
CourierDetailsGenerator courierDetailsGenerator = new CourierDetailsGenerator();
|
| 159 |
ByteArrayOutputStream baosXLS = courierDetailsGenerator.generateCourierDetails(warehouseId, providerId, isCod);
|
157 |
ByteArrayOutputStream baosXLS = courierDetailsGenerator.generateCourierDetails(orderIds, warehouseId, providerId, isCod);
|
| 160 |
baosXLS.writeTo(f);
|
158 |
baosXLS.writeTo(f);
|
| 161 |
f.close();
|
159 |
f.close();
|
| 162 |
} catch (FileNotFoundException e) {
|
160 |
} catch (FileNotFoundException e) {
|
| 163 |
logger.error("Unable to create the courier details file", e);
|
161 |
logger.error("Unable to create the courier details file", e);
|
| 164 |
} catch (IOException e) {
|
162 |
} catch (IOException e) {
|
| 165 |
logger.error("Unable to create the courier details file", e);
|
163 |
logger.error("Unable to create the courier details file", e);
|
| 166 |
}
|
164 |
}
|
| 167 |
|
165 |
|
| 168 |
// FIXME This is not a useful way. We need to fix it asap. This is done just to give ease to courier company.
|
- |
|
| 169 |
CourierDetailsReportMerger merger = new CourierDetailsReportMerger();
|
166 |
CourierDetailsReportMerger merger = new CourierDetailsReportMerger();
|
| 170 |
try {
|
167 |
try {
|
| 171 |
FileOutputStream f = new FileOutputStream(courierDetailsPath + "/courier-details-" + mergedFileNameSuffix + ".xls");
|
- |
|
| 172 |
Map<Long, String> warehouseIdFileNames = new HashMap<Long, String>();
|
168 |
Map<Long, String> warehouseIdFileNames = new HashMap<Long, String>();
|
| 173 |
|
- |
|
| 174 |
String p1;
|
169 |
String fName;
|
| - |
|
170 |
fName = courierDetailsPath + "/courier-details-" + fileNameSuffix + "-temp.xls";
|
| 175 |
if(isCod){
|
171 |
if((new File(fName)).exists()){
|
| 176 |
p1 = "cod";
|
172 |
warehouseIdFileNames.put(0L, fName);
|
| 177 |
}
|
173 |
}
|
| - |
|
174 |
fName = courierDetailsPath + "/courier-details-" + fileNameSuffix + ".xls";
|
| 178 |
else{
|
175 |
if((new File(fName)).exists()){
|
| 179 |
p1 = "prepaid";
|
176 |
warehouseIdFileNames.put(1L, fName);
|
| 180 |
}
|
177 |
}
|
| 181 |
String fName;
|
- |
|
| 182 |
fName = courierDetailsPath + "/courier-details-" + p1 + "-" + 1 + "-"+ providerId + "-" + year + "-" + month + "-" + day + ".xls";
|
- |
|
| 183 |
warehouseIdFileNames.put(1L, fName);
|
- |
|
| 184 |
fName = courierDetailsPath + "/courier-details-" + p1 + "-" + 2 + "-"+ providerId + "-" + year + "-" + month + "-" + day + ".xls";
|
- |
|
| 185 |
warehouseIdFileNames.put(2L, fName);
|
- |
|
| 186 |
fName = courierDetailsPath + "/courier-details-" + p1 + "-" + 5 + "-"+ providerId + "-" + year + "-" + month + "-" + day + ".xls";
|
178 |
ByteArrayOutputStream binXLS = merger.mergeCourierDetailsReports(warehouseIdFileNames);
|
| 187 |
warehouseIdFileNames.put(5L, fName);
|
- |
|
| 188 |
ByteArrayOutputStream binXLS = merger.mergeCourierDetailsReports(warehouseIdFileNames, 1, true);
|
179 |
FileOutputStream f = new FileOutputStream(courierDetailsPath + "/courier-details-" + fileNameSuffix + ".xls");
|
| 189 |
binXLS.writeTo(f);
|
180 |
binXLS.writeTo(f);
|
| 190 |
f.close();
|
181 |
f.close();
|
| - |
|
182 |
File tempFile = new File(courierDetailsPath + "/courier-details-" + fileNameSuffix + "-temp.xls");
|
| - |
|
183 |
if(tempFile.exists()){
|
| - |
|
184 |
tempFile.delete();
|
| - |
|
185 |
}
|
| 191 |
} catch (FileNotFoundException e) {
|
186 |
} catch (FileNotFoundException e) {
|
| 192 |
logger.error("Error while creating the Courier Details report", e);
|
187 |
logger.error("Error while creating the Courier Details report", e);
|
| 193 |
} catch (IOException e) {
|
188 |
} catch (IOException e) {
|
| 194 |
logger.error("IO error while writing the Courier Details report", e);
|
189 |
logger.error("IO error while writing the Courier Details report", e);
|
| 195 |
}
|
190 |
}
|