Manos Chorianopoulos

fix WalletVC SM discount banner

......@@ -117,7 +117,8 @@ import SwiftEventBus
// TODO: DELETE <===
// TODO: Uncomment when UnifiedCoupons will be shown again
getUnifiedCouponsRequest()
// getUnifiedCouponsRequest()
getCouponsSetsDealsRequest()
setBackButton()
setNavigationTitle("My Rewards")
......@@ -590,12 +591,26 @@ import SwiftEventBus
func updateMarketBadge() {
unifiedCouponsDiscount = 0.0
for coupon in swiftApi().getOldUnifiedCouponList() {
if let discountFloat = Float(coupon.discount ?? "0.0") {
for smCouponSet in swiftApi().getCouponSetsDealsList() {
for oldCoupon in swiftApi().getAllOldCouponList() {
if (smCouponSet.uuid != "" && oldCoupon.couponset_uuid != "" && smCouponSet.uuid == oldCoupon.couponset_uuid) {
oldCoupon.setCouponSetData(smCouponSet);
if let discountFloat = Float(oldCoupon.discount ?? "0.0") {
unifiedCouponsDiscount += discountFloat
}
break;
}
}
}
// for coupon in swiftApi().getOldUnifiedCouponList() {
// if let discountFloat = Float(coupon.discount ?? "0.0") {
// unifiedCouponsDiscount += discountFloat
// }
// }
// TODO: UNCOMMENT if emptyView is needed again
// if (totalCouponValue == 0.0 && loyaltyBadge._couponCount == 0 && dfyCoupons.count == 0 && coupons.count == 0 && unifiedCoupons.count == 0 && unifiedCouponsDiscount == 0.0) {
// emptyView.isHidden = false
......@@ -607,6 +622,21 @@ import SwiftEventBus
}
// MARK: - API Functions
func getCouponsSetsDealsRequest() {
swiftApi().getCouponSetsDealsAsync(getCouponsSetsDealsCallback, failureCallback: {errorCode in
})
}
func getCouponsSetsDealsCallback (_ couponsData: Array<swiftApi.CouponSetItemModel>?) -> Void {
if (couponsData != nil) {
DispatchQueue.main.async {
self.getUnifiedCouponsRequest()
}
} else {
}
}
func getUnifiedCouponsRequest() {
swiftApi().getUnifiedCouponsAsync(getUnifiedCouponsCallback, failureCallback: {errorCode in
self.unifiedCoupons = []
......
......@@ -16,6 +16,7 @@ public struct GlobalVariables {
static var dfyCoupons: Array<swiftApi.ActiveDFYCouponModel> = []
static var couponList: Array<swiftApi.CouponItemModel> = []
static var oldCouponList: Array<swiftApi.CouponItemModel> = []
static var allOldCouponList: Array<swiftApi.CouponItemModel> = []
static var couponSetList: Array<swiftApi.CouponSetItemModel> = []
static var couponsetsDealsList: Array<swiftApi.CouponSetItemModel> = [] // Supermarket couponsets
static var unifiedCouponList: Array<swiftApi.UnifiedCouponModel> = []
......@@ -840,6 +841,24 @@ public class swiftApi {
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
// setAllOldCouponList uncluding Supermarkets ==>
var allOldCouponsArray:Array<CouponItemModel> = []
if let myCouponsDictionary = coupons as? [String : AnyObject] {
let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>)
if let cpns = couponsData as? NSArray {
for coupon in cpns {
var c = coupon as! NSDictionary
let temp = NSMutableDictionary(dictionary: c);
let tempCoupon = CouponItemModel(dictionary: temp as! [String : Any])
allOldCouponsArray.append(tempCoupon)
}
}
}
swiftApi().setAllOldCouponList(allOldCouponsArray)
// <==
// On Coupons request success, make CouponSets request
instanceOfMyApi.getCouponsetsAsync(true, andVisible: true, andUuids: nil, couponSetsCallback, failureBlock: couponSetsFailureCallback)
}
......@@ -4525,6 +4544,37 @@ public class swiftApi {
return GlobalVariables.oldCouponList
}
public func setAllOldCouponList(_ coupons: Array<CouponItemModel>) {
// let filteredCoupons = coupons.filter { CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: $0.discount ?? "")) }
var oldCoupons = coupons.filter({ return $0.status == 0 })
// sort oldCoupons by redeemed date
// let dateFormatter = DateFormatter()
// dateFormatter.dateFormat = "dd/MM/yyyy"
oldCoupons.sort(by: {
// let date1 = dateFormatter.date(from: $0.redeemed ?? "")
// let date2 = dateFormatter.date(from: $1.redeemed ?? "")
let date1 = $0.redeemed_date
let date2 = $1.redeemed_date
if ((date1 != nil) && (date2 != nil)) {
return date1!.compare(date2!) == .orderedDescending
} else {
return false
}
})
GlobalVariables.allOldCouponList = oldCoupons
}
public func getAllOldCouponList() -> Array<CouponItemModel> {
return GlobalVariables.allOldCouponList
}
public func setCouponSetList(_ couponSets: Array<CouponSetItemModel>) {
GlobalVariables.couponSetList = couponSets
......