Subversion Repositories SmartDukaan

Rev

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

Rev 14500 Rev 14501
Line 98... Line 98...
98
    curs = getOrdersAfterDate(datetime.now() - timedelta(days=30), 3)
98
    curs = getOrdersAfterDate(datetime.now() - timedelta(days=30), 3)
99
    db = client.Dtr
99
    db = client.Dtr
100
    
100
    
101
    matchedList = []
101
    matchedList = []
102
    workbook = xlwt.Workbook()
102
    workbook = xlwt.Workbook()
103
    worksheet = workbook.add_sheet("Snapdeal")
103
    worksheet = workbook.add_sheet("Snapdeal Reconciled")
-
 
104
    worksheet1 = workbook.add_sheet("Snapdeal Reconciled All")
104
    column = 0
105
    setHeaders(worksheet, worksheet1)
105
    row = 0
106
    row = 0
106
    global i
-
 
107
    i=-1    
107
    anotherrow = 0
108
    worksheet.write(row, inc(), 'Order Id', boldStyle)
-
 
109
    worksheet.write(row, inc(), 'User Id', boldStyle)
-
 
110
    worksheet.write(row, inc(), 'Username', boldStyle)
-
 
111
    worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
-
 
112
    worksheet.write(row, inc(), 'Product Title', boldStyle)
-
 
113
    worksheet.write(row, inc(), 'Price', boldStyle)
-
 
114
    worksheet.write(row, inc(), 'Quantity', boldStyle)
-
 
115
    worksheet.write(row, inc(), 'Status', boldStyle)
-
 
116
    worksheet.write(row, inc(), 'Detailed Status', boldStyle)
-
 
117
    worksheet.write(row, inc(), 'Cashback Status', boldStyle)
-
 
118
    worksheet.write(row, inc(), 'Our CashBack', boldStyle)
-
 
119
    worksheet.write(row, inc(), 'Sale Date', boldStyle)
-
 
120
    worksheet.write(row, inc(), 'SubtagId', boldStyle)
-
 
121
    worksheet.write(row, inc(), 'Ad Id', boldStyle)
-
 
122
    worksheet.write(row, inc(), 'Affiliate PayOut', boldStyle)
-
 
123
    worksheet.write(row, inc(), 'Affiliate Sale Amount', boldStyle)
-
 
124
    worksheet.write(row, inc(), 'Affiliate Sale Date', boldStyle)
-
 
125
    
-
 
126
    for row1 in curs:
108
    for row1 in curs:
127
        orderId = row1[0]
109
        orderId = row1[0]
128
        order = db.merchantOrder.find_one({"orderId":orderId})
110
        order = db.merchantOrder.find_one({"orderId":orderId})
129
        if order is None:
111
        if order is None:
130
            continue
112
            continue
131
        #saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
113
        #saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
132
        aff = list(db.snapdealOrderAffiliateInfo.find({"subTagId":order["subTagId"]}))
114
        aff = list(db.snapdealOrderAffiliateInfo.find({"subTagId":order["subTagId"]}))
133
        matched = False
115
        anotherrow += 1
134
        if len(aff) > 0 and order["subTagId"] not in matchedList: 
116
        if len(aff) > 0 and order["subTagId"] not in matchedList: 
-
 
117
            matchedList.append(order["subTagId"])
-
 
118
            aff[0]['reconciled'] = True
-
 
119
            db.snapdealOrderAffiliateInfo.save(aff[0])
-
 
120
            order['reconciled'] = True
-
 
121
            db.merchantOrder.save(order)
-
 
122
            row += 1
-
 
123
            global i
-
 
124
            i=-1 
-
 
125
            worksheet.write(row, inc(), orderId)
-
 
126
            worksheet1.write(anotherrow, i, orderId)
-
 
127
            worksheet.write(row, inc(), row1[1])
-
 
128
            worksheet1.write(anotherrow, i, row1[1])
-
 
129
            worksheet.write(row, inc(), row1[-1])
-
 
130
            worksheet1.write(anotherrow, i, row1[-1])
-
 
131
            worksheet.write(row, inc(), order['merchantOrderId'])
-
 
132
            worksheet1.write(anotherrow, i, order['merchantOrderId'])
-
 
133
            worksheet.write(row, inc(), order['subTagId'])
-
 
134
            worksheet1.write(anotherrow, i, order['subTagId'])
-
 
135
            worksheet.write(row, inc(), order['placedOn'])
-
 
136
            worksheet1.write(anotherrow, i, order['placedOn'])
-
 
137
            worksheet.write(row, inc(), int(order['paidAmount']))
-
 
138
            worksheet1.write(anotherrow, i, int(order['paidAmount']))
135
            if int(order["paidAmount"]) == aff[0]["saleAmount"]:
139
            if int(order["paidAmount"]) == aff[0]["saleAmount"]:
136
                matchedList.append(order["subTagId"])
140
                worksheet.write(row, inc(), aff[0]['saleDate'])
-
 
141
                worksheet1.write(anotherrow, i, aff[0]['saleDate'])
137
                aff[0]['reconciled'] = True
142
                worksheet.write(row, inc(), aff[0]['saleAmount'])
138
                db.snapdealOrderAffiliateInfo.save(aff[0])
143
                worksheet1.write(anotherrow, i, aff[0]['saleAmount'])
139
                order['reconciled'] = True
144
                worksheet.write(row, inc(), aff[0]['payOut'])
140
                db.merchantOrder.save(order)
145
                worksheet1.write(anotherrow, i, aff[0]['payOut'])
141
                once = True        
146
            k = i
142
                for subOrder in order['subOrders']:
147
            for subOrder in order['subOrders']:
143
                    i=-1 
148
                i = k
144
                    row += 1
149
                worksheet.write(row, inc(), subOrder['productTitle'])
145
                    worksheet.write(row, inc(), orderId)
150
                worksheet1.write(anotherrow, i, subOrder['productTitle'])
146
                    worksheet.write(row, inc(), row1[1])
151
                worksheet.write(row, inc(), subOrder['amountPaid'])
147
                    worksheet.write(row, inc(), row1[-1])
152
                worksheet1.write(anotherrow, i, subOrder['amountPaid'])
148
                    worksheet.write(row, inc(), order['merchantOrderId'])
153
                worksheet.write(row, inc(), subOrder['quantity'])
149
                    worksheet.write(row, inc(), subOrder['productTitle'])
154
                worksheet1.write(anotherrow, i, subOrder['quantity'])
150
                    worksheet.write(row, inc(), subOrder['amountPaid'])
155
                worksheet.write(row, inc(), subOrder['status'])
151
                    worksheet.write(row, inc(), subOrder['quantity'])
156
                worksheet1.write(anotherrow, i, subOrder['status'])
152
                    worksheet.write(row, inc(), subOrder['status'])
157
                worksheet.write(row, inc(), subOrder['cashBackStatus'])
153
                    worksheet.write(row, inc(), subOrder['detailedStatus'])
158
                worksheet1.write(anotherrow, i, subOrder['cashBackStatus'])
154
                    worksheet.write(row, inc(), subOrder['cashBackStatus'])
159
                worksheet.write(row, inc(), subOrder['cashBackAmount'])
155
                    worksheet.write(row, inc(), subOrder['cashBackAmount'])
160
                worksheet1.write(anotherrow, i, subOrder['cashBackAmount'])
-
 
161
        else:
-
 
162
            worksheet1.write(anotherrow, inc(), orderId)
-
 
163
            worksheet1.write(anotherrow, inc(), row1[1])
-
 
164
            worksheet1.write(anotherrow, inc(), row1[-1])
156
                    worksheet.write(row, inc(), subOrder['placedOn'])
165
            worksheet1.write(anotherrow, inc(), order['merchantOrderId'])
157
                    worksheet.write(row, inc(), order['subTagId'])
166
            worksheet1.write(anotherrow, inc(), order['subTagId'])
158
                    worksheet.write(row, inc(), aff[0]['adId'])
167
            worksheet1.write(anotherrow, inc(), order['placedOn'])
-
 
168
            worksheet1.write(anotherrow, inc(), int(order['paidAmount']))
-
 
169
            worksheet1.write(anotherrow, inc(), "")
-
 
170
            worksheet1.write(anotherrow, inc(), "")
-
 
171
            worksheet1.write(anotherrow, inc(), "")
-
 
172
            worksheet1.write(anotherrow, inc(), 'Product Title', boldStyle)
-
 
173
            worksheet1.write(anotherrow, inc(), 'Price', boldStyle)
-
 
174
            worksheet1.write(anotherrow, inc(), 'Amoun Paid', boldStyle)
159
                    worksheet.write(row, inc(), aff[0]['saleDate'])
175
            worksheet1.write(anotherrow, inc(), 'Status', boldStyle)
-
 
176
            worksheet1.write(anotherrow, inc(), 'Cashback Status', boldStyle)
-
 
177
            worksheet1.write(anotherrow, inc(), 'CashBack', boldStyle)
-
 
178
            k = i
-
 
179
            for subOrder in order['subOrders']:
160
                    if once:
180
                i = k
-
 
181
                worksheet.write(anotherrow, inc(), subOrder['productTitle'])
-
 
182
                worksheet.write(anotherrow, inc(), subOrder['amountPaid'])
-
 
183
                worksheet.write(anotherrow, inc(), subOrder['quantity'])
161
                        worksheet.write(row, inc(), aff[0]['payOut'])
184
                worksheet.write(anotherrow, inc(), subOrder['status'])
-
 
185
                worksheet.write(anotherrow, inc(), subOrder['cashBackStatus'])
162
                        worksheet.write(row, inc(), aff[0]['saleAmount'])
186
                worksheet.write(anotherrow, inc(), subOrder['cashBackAmount'])
-
 
187
        
163
                        once = False
188
            
164
        workbook.save(XLS_FILENAME)
189
        workbook.save(XLS_FILENAME)
165
            
190
            
166
def sendmail(email, message, title):
191
def sendmail(email, message, title):
167
    if email == "":
192
    if email == "":
168
        return
193
        return
Line 189... Line 214...
189
    email.append('amit.gupta@shop2020.in')
214
    email.append('amit.gupta@shop2020.in')
190
    MAILTO = email 
215
    MAILTO = email 
191
    mailServer.login(SENDER, PASSWORD)
216
    mailServer.login(SENDER, PASSWORD)
192
    mailServer.sendmail(PASSWORD, MAILTO, msg.as_string())
217
    mailServer.sendmail(PASSWORD, MAILTO, msg.as_string())
193
 
218
 
-
 
219
def setHeaders(worksheet, worksheet1):
-
 
220
    row = 0
-
 
221
    global i
-
 
222
    i=-1    
-
 
223
    worksheet.write(row, inc(), 'Order Id', boldStyle)
-
 
224
    worksheet.write(row, inc(), 'User Id', boldStyle)
-
 
225
    worksheet.write(row, inc(), 'Username', boldStyle)
-
 
226
    worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
-
 
227
    worksheet.write(row, inc(), 'SubtagId', boldStyle)
-
 
228
    worksheet.write(row, inc(), 'Sale Date', boldStyle)
-
 
229
    worksheet.write(row, inc(), 'Sale Amount', boldStyle)
-
 
230
    worksheet.write(row, inc(), 'Aff Sale Date', boldStyle)
-
 
231
    worksheet.write(row, inc(), 'Aff Sale Amt', boldStyle)
-
 
232
    worksheet.write(row, inc(), 'Aff PayOut', boldStyle)
-
 
233
    worksheet.write(row, inc(), 'Product Title', boldStyle)
-
 
234
    worksheet.write(row, inc(), 'Price', boldStyle)
-
 
235
    worksheet.write(row, inc(), 'Quantity', boldStyle)
-
 
236
    worksheet.write(row, inc(), 'Status', boldStyle)
-
 
237
    worksheet.write(row, inc(), 'Cashback Status', boldStyle)
-
 
238
    worksheet.write(row, inc(), 'CashBack', boldStyle)
-
 
239
 
-
 
240
    worksheet1.write(row, inc(), 'Order Id', boldStyle)
-
 
241
    worksheet1.write(row, inc(), 'User Id', boldStyle)
-
 
242
    worksheet1.write(row, inc(), 'Username', boldStyle)
-
 
243
    worksheet1.write(row, inc(), 'Merchant Order Id', boldStyle)
-
 
244
    worksheet1.write(row, inc(), 'SubtagId', boldStyle)
-
 
245
    worksheet1.write(row, inc(), 'Sale Date', boldStyle)
-
 
246
    worksheet1.write(row, inc(), 'Sale Amount', boldStyle)
-
 
247
    worksheet1.write(row, inc(), 'Aff Sale Date', boldStyle)
-
 
248
    worksheet1.write(row, inc(), 'Aff Sale Amt', boldStyle)
-
 
249
    worksheet1.write(row, inc(), 'Aff PayOut', boldStyle)
-
 
250
    worksheet1.write(row, inc(), 'Product Title', boldStyle)
-
 
251
    worksheet1.write(row, inc(), 'Price', boldStyle)
-
 
252
    worksheet1.write(row, inc(), 'Quantity', boldStyle)
-
 
253
    worksheet1.write(row, inc(), 'Status', boldStyle)
-
 
254
    worksheet1.write(row, inc(), 'Cashback Status', boldStyle)
-
 
255
    worksheet1.write(row, inc(), 'CashBack', boldStyle) 
194
    
256
    
195
    
257
    
196
def inc():
258
def inc():
197
    global i
259
    global i
198
    i+=1
260
    i+=1