Subversion Repositories SmartDukaan

Rev

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

Rev 14530 Rev 14570
Line 165... Line 165...
165
                worksheet1.write(anotherrow, i, subOrder['cashBackStatus'])
165
                worksheet1.write(anotherrow, i, subOrder['cashBackStatus'])
166
                worksheet.write(row, inc(), subOrder['cashBackAmount'])
166
                worksheet.write(row, inc(), subOrder['cashBackAmount'])
167
                worksheet1.write(anotherrow, i, subOrder['cashBackAmount'])
167
                worksheet1.write(anotherrow, i, subOrder['cashBackAmount'])
168
 
168
 
169
        else:
169
        else:
170
            row2 +=1
-
 
171
            i=-1
170
            i=-1
172
            worksheet1.write(anotherrow, inc(), orderId)
171
            worksheet1.write(anotherrow, inc(), orderId)
173
            worksheet2.write(row2, i, orderId)
-
 
174
            worksheet1.write(anotherrow, inc(), row1[1])
172
            worksheet1.write(anotherrow, inc(), row1[1])
175
            worksheet2.write(row2, i, row1[1])
-
 
176
            worksheet1.write(anotherrow, inc(), row1[-1])
173
            worksheet1.write(anotherrow, inc(), row1[-1])
177
            worksheet2.write(row2, i, row1[-1])
-
 
178
            worksheet1.write(anotherrow, inc(), order['merchantOrderId'])
174
            worksheet1.write(anotherrow, inc(), order['merchantOrderId'])
179
            worksheet2.write(row2, i, order['merchantOrderId'])
-
 
180
            worksheet1.write(anotherrow, inc(), order['subTagId'])
175
            worksheet1.write(anotherrow, inc(), order['subTagId'])
181
            worksheet2.write(row2, i, order['subTagId'])
-
 
182
            worksheet1.write(anotherrow, inc(), order['placedOn'])
176
            worksheet1.write(anotherrow, inc(), order['placedOn'])
183
            worksheet2.write(row2, i, order['placedOn'])
-
 
184
            worksheet1.write(anotherrow, inc(), int(order['paidAmount']))
177
            worksheet1.write(anotherrow, inc(), int(order['paidAmount']))
185
            worksheet2.write(row2, i, int(order['paidAmount']))
-
 
186
            timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
178
            timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
187
            notReconciled[orderId] = (anotherrow, i, int(order['paidAmount']), timestamp1, order["subTagId"]) 
179
            notReconciled[orderId] = (anotherrow, i, int(order['paidAmount']), timestamp1, order["subTagId"]) 
188
            inc()
180
            inc()
189
            inc()
181
            inc()
190
            inc()
182
            inc()
191
            k = i
183
            k = i
192
            anotherrow -= 1
184
            anotherrow -= 1
193
            row2 -= 1
-
 
194
            for subOrder in order['subOrders']:
185
            for subOrder in order['subOrders']:
195
                anotherrow += 1
186
                anotherrow += 1
196
                row2 += 1
-
 
197
                i = k
187
                i = k
198
                worksheet1.write(anotherrow, inc(), subOrder['productTitle'])
188
                worksheet1.write(anotherrow, inc(), subOrder['productTitle'])
199
                worksheet2.write(row2, i-3, subOrder['productTitle'])
-
 
200
                worksheet1.write(anotherrow, inc(), subOrder['amountPaid'])
189
                worksheet1.write(anotherrow, inc(), subOrder['amountPaid'])
201
                worksheet2.write(row2, i-3, subOrder['amountPaid'])
-
 
202
                worksheet1.write(anotherrow, inc(), subOrder['quantity'])
190
                worksheet1.write(anotherrow, inc(), subOrder['quantity'])
203
                worksheet2.write(row2, i-3, subOrder['quantity'])
-
 
204
                worksheet1.write(anotherrow, inc(), subOrder['status'])
191
                worksheet1.write(anotherrow, inc(), subOrder['status'])
205
                worksheet2.write(row2, i-3, subOrder['status'])
-
 
206
                worksheet1.write(anotherrow, inc(), subOrder['cashBackStatus'])
192
                worksheet1.write(anotherrow, inc(), subOrder['cashBackStatus'])
207
                worksheet2.write(row2, i-3, subOrder['cashBackStatus'])
-
 
208
                worksheet1.write(anotherrow, inc(), subOrder['cashBackAmount'])
193
                worksheet1.write(anotherrow, inc(), subOrder['cashBackAmount'])
209
                worksheet2.write(row2, i-3, subOrder['cashBackAmount'])
-
 
-
 
194
 
210
                
195
                
211
    last30Days =  date.today() - timedelta(days=30)
196
    last30Days =  date.today() - timedelta(days=30)
212
    int(time.mktime(last30Days.timetuple()))
197
    int(time.mktime(last30Days.timetuple()))
213
    row = 0
198
    row = 0
214
    for offer in db.snapdealOrderAffiliateInfo.find({"reconciled":{"$exists":False}, 
199
    for offer in db.snapdealOrderAffiliateInfo.find({"reconciled":{"$exists":False}, 
Line 220... Line 205...
220
        for order in orders:
205
        for order in orders:
221
            if notReconciled.has_key(order[0]):
206
            if notReconciled.has_key(order[0]):
222
                (roww, column, paidAmount, timestamp1, oSubTagId) = notReconciled[order[0]]
207
                (roww, column, paidAmount, timestamp1, oSubTagId) = notReconciled[order[0]]
223
                if paidAmount==int(offer.get("saleAmount")) and timestamp1 <= saleTime and timestamp1 + 120 >= saleTime:
208
                if paidAmount==int(offer.get("saleAmount")) and timestamp1 <= saleTime and timestamp1 + 120 >= saleTime:
224
                    i = column
209
                    i = column
225
                    worksheet1.write(roww, inc(), subTagId)        
210
                    worksheet1.write(roww, inc(), offer.get("saleDate"))        
226
                    worksheet1.write(roww, inc(), offer.get("saleAmount"))        
211
                    worksheet1.write(roww, inc(), offer.get("saleAmount"))        
227
                    worksheet1.write(roww, inc(), offer.get("payOut"))
212
                    worksheet1.write(roww, inc(), offer.get("payOut"))
-
 
213
                    worksheet1.write(roww, 16, offer.get("payOut"))
228
                    del notReconciled[order[0]]
214
                    del notReconciled[order[0]]
229
                    print "found match for user", order[1]
215
                    print "found match for user", order[1]
-
 
216
                    db.snapdealOrderAffiliateInfo.update({"adId":offer.get("adId")}, {"$set":{"reconciled":True}}, multi=True)
-
 
217
                    db.merchantOrder.update({"orderId":order[0]}, {"$set":{"reconciled":True}}, multi=True)
-
 
218
                    break
-
 
219
 
-
 
220
    unreconciledOrders = notReconciled.keys()
-
 
221
    row2=0
-
 
222
    for row1 in curs:
-
 
223
        if row1[0] in unreconciledOrders:
-
 
224
            for order in db.merchantOrder.find({"orderId":row1[0]}):
-
 
225
                row2 += 1
230
                else:
226
                i=-1
-
 
227
                worksheet2.write(row2, inc(), order["orderId"])
-
 
228
                worksheet2.write(row2, inc(), row1[1])
-
 
229
                worksheet2.write(row2, inc(), row1[-1])
-
 
230
                worksheet2.write(row2, inc(), order['merchantOrderId'])
-
 
231
                worksheet2.write(row2, inc(), order['subTagId'])
-
 
232
                worksheet2.write(row2, inc(), order['placedOn'])
-
 
233
                worksheet2.write(row2, inc(), int(order['paidAmount']))
231
                    row += 1
234
                row2 -=1
-
 
235
                k=i
-
 
236
                for subOrder in order['subOrders']:
232
                    i=-1
237
                    i = k
-
 
238
                    row2 += 1
-
 
239
                    worksheet2.write(row2, inc(), subOrder['productTitle'])
-
 
240
                    worksheet2.write(row2, inc(), subOrder['amountPaid'])
-
 
241
                    worksheet2.write(row2, inc(), subOrder['quantity'])
-
 
242
                    worksheet2.write(row2, inc(), subOrder['status'])
-
 
243
                    worksheet2.write(row2, inc(), subOrder['cashBackStatus'])
-
 
244
                    worksheet2.write(row2, inc(), subOrder['cashBackAmount'])
-
 
245
    
-
 
246
    
-
 
247
    for offer in db.snapdealOrderAffiliateInfo.find({"reconciled":{"$exists":False}, 
-
 
248
                                                     "saleTime":{"$gt":int(time.mktime(last30Days.timetuple())),
-
 
249
                                                                 "$lt":int(time.mktime(date.today().timetuple()))}} ):
-
 
250
        row += 1
-
 
251
        i=-1
233
                    affNotReconciledSheet.write(row, inc(), offer.get("adId")) 
252
        affNotReconciledSheet.write(row, inc(), offer.get("adId")) 
234
                    affNotReconciledSheet.write(row, inc(), offer.get("subTagId")) 
253
        affNotReconciledSheet.write(row, inc(), offer.get("subTagId")) 
235
                    affNotReconciledSheet.write(row, inc(), offer.get("saleDate")) 
254
        affNotReconciledSheet.write(row, inc(), offer.get("saleDate")) 
236
                    affNotReconciledSheet.write(row, inc(), offer.get("saleAmount")) 
255
        affNotReconciledSheet.write(row, inc(), offer.get("saleAmount")) 
237
                    affNotReconciledSheet.write(row, inc(), offer.get("payOut")) 
256
        affNotReconciledSheet.write(row, inc(), offer.get("payOut")) 
238
                    affNotReconciledSheet.write(row, inc(), offer.get("conversionStatus"))
257
        affNotReconciledSheet.write(row, inc(), offer.get("conversionStatus"))
239
 
258
 
240
        
-
 
241
         
-
 
242
        workbook.save(XLS_FILENAME)
259
        workbook.save(XLS_FILENAME)
243
            
260
            
244
def sendmail(email, message, title):
261
def sendmail(email, message, title):
245
    if email == "":
262
    if email == "":
246
        return
263
        return
Line 345... Line 362...
345
    return i
362
    return i
346
    
363
    
347
def main():
364
def main():
348
    generateSnapDealReco()
365
    generateSnapDealReco()
349
    #generateFlipkartReco()
366
    #generateFlipkartReco()
350
    sendmail(["amit.gupta@shop2020.in"], "", "DTR Affiliate Reco")
367
    #sendmail(["amit.gupta@shop2020.in"], "", "DTR Affiliate Reco")
351
 
368
 
352
if __name__ == '__main__':
369
if __name__ == '__main__':
353
    main()
370
    main()
354
    
371
    
355
372