Manos Chorianopoulos

fix WalletVC SM discount banner

...@@ -117,7 +117,8 @@ import SwiftEventBus ...@@ -117,7 +117,8 @@ import SwiftEventBus
117 // TODO: DELETE <=== 117 // TODO: DELETE <===
118 118
119 // TODO: Uncomment when UnifiedCoupons will be shown again 119 // TODO: Uncomment when UnifiedCoupons will be shown again
120 - getUnifiedCouponsRequest() 120 +// getUnifiedCouponsRequest()
121 + getCouponsSetsDealsRequest()
121 122
122 setBackButton() 123 setBackButton()
123 setNavigationTitle("My Rewards") 124 setNavigationTitle("My Rewards")
...@@ -590,12 +591,26 @@ import SwiftEventBus ...@@ -590,12 +591,26 @@ import SwiftEventBus
590 591
591 func updateMarketBadge() { 592 func updateMarketBadge() {
592 unifiedCouponsDiscount = 0.0 593 unifiedCouponsDiscount = 0.0
593 - for coupon in swiftApi().getOldUnifiedCouponList() { 594 + for smCouponSet in swiftApi().getCouponSetsDealsList() {
594 - if let discountFloat = Float(coupon.discount ?? "0.0") { 595 + for oldCoupon in swiftApi().getAllOldCouponList() {
595 - unifiedCouponsDiscount += discountFloat 596 + if (smCouponSet.uuid != "" && oldCoupon.couponset_uuid != "" && smCouponSet.uuid == oldCoupon.couponset_uuid) {
597 +
598 + oldCoupon.setCouponSetData(smCouponSet);
599 +
600 + if let discountFloat = Float(oldCoupon.discount ?? "0.0") {
601 + unifiedCouponsDiscount += discountFloat
602 + }
603 + break;
604 + }
596 } 605 }
597 } 606 }
598 607
608 +// for coupon in swiftApi().getOldUnifiedCouponList() {
609 +// if let discountFloat = Float(coupon.discount ?? "0.0") {
610 +// unifiedCouponsDiscount += discountFloat
611 +// }
612 +// }
613 +
599 // TODO: UNCOMMENT if emptyView is needed again 614 // TODO: UNCOMMENT if emptyView is needed again
600 // if (totalCouponValue == 0.0 && loyaltyBadge._couponCount == 0 && dfyCoupons.count == 0 && coupons.count == 0 && unifiedCoupons.count == 0 && unifiedCouponsDiscount == 0.0) { 615 // if (totalCouponValue == 0.0 && loyaltyBadge._couponCount == 0 && dfyCoupons.count == 0 && coupons.count == 0 && unifiedCoupons.count == 0 && unifiedCouponsDiscount == 0.0) {
601 // emptyView.isHidden = false 616 // emptyView.isHidden = false
...@@ -607,6 +622,21 @@ import SwiftEventBus ...@@ -607,6 +622,21 @@ import SwiftEventBus
607 } 622 }
608 623
609 // MARK: - API Functions 624 // MARK: - API Functions
625 + func getCouponsSetsDealsRequest() {
626 + swiftApi().getCouponSetsDealsAsync(getCouponsSetsDealsCallback, failureCallback: {errorCode in
627 + })
628 + }
629 +
630 + func getCouponsSetsDealsCallback (_ couponsData: Array<swiftApi.CouponSetItemModel>?) -> Void {
631 + if (couponsData != nil) {
632 +
633 + DispatchQueue.main.async {
634 + self.getUnifiedCouponsRequest()
635 + }
636 + } else {
637 + }
638 + }
639 +
610 func getUnifiedCouponsRequest() { 640 func getUnifiedCouponsRequest() {
611 swiftApi().getUnifiedCouponsAsync(getUnifiedCouponsCallback, failureCallback: {errorCode in 641 swiftApi().getUnifiedCouponsAsync(getUnifiedCouponsCallback, failureCallback: {errorCode in
612 self.unifiedCoupons = [] 642 self.unifiedCoupons = []
......
...@@ -16,6 +16,7 @@ public struct GlobalVariables { ...@@ -16,6 +16,7 @@ public struct GlobalVariables {
16 static var dfyCoupons: Array<swiftApi.ActiveDFYCouponModel> = [] 16 static var dfyCoupons: Array<swiftApi.ActiveDFYCouponModel> = []
17 static var couponList: Array<swiftApi.CouponItemModel> = [] 17 static var couponList: Array<swiftApi.CouponItemModel> = []
18 static var oldCouponList: Array<swiftApi.CouponItemModel> = [] 18 static var oldCouponList: Array<swiftApi.CouponItemModel> = []
19 + static var allOldCouponList: Array<swiftApi.CouponItemModel> = []
19 static var couponSetList: Array<swiftApi.CouponSetItemModel> = [] 20 static var couponSetList: Array<swiftApi.CouponSetItemModel> = []
20 static var couponsetsDealsList: Array<swiftApi.CouponSetItemModel> = [] // Supermarket couponsets 21 static var couponsetsDealsList: Array<swiftApi.CouponSetItemModel> = [] // Supermarket couponsets
21 static var unifiedCouponList: Array<swiftApi.UnifiedCouponModel> = [] 22 static var unifiedCouponList: Array<swiftApi.UnifiedCouponModel> = []
...@@ -839,6 +840,24 @@ public class swiftApi { ...@@ -839,6 +840,24 @@ public class swiftApi {
839 dynatraceEvent._eventName = "custom_success_user_coupons_loyalty" 840 dynatraceEvent._eventName = "custom_success_user_coupons_loyalty"
840 dynatraceEvent._parameters = nil 841 dynatraceEvent._parameters = nil
841 SwiftEventBus.post("dynatrace", sender: dynatraceEvent) 842 SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
843 +
844 + // setAllOldCouponList uncluding Supermarkets ==>
845 + var allOldCouponsArray:Array<CouponItemModel> = []
846 +
847 + if let myCouponsDictionary = coupons as? [String : AnyObject] {
848 + let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>)
849 + if let cpns = couponsData as? NSArray {
850 + for coupon in cpns {
851 + var c = coupon as! NSDictionary
852 + let temp = NSMutableDictionary(dictionary: c);
853 + let tempCoupon = CouponItemModel(dictionary: temp as! [String : Any])
854 + allOldCouponsArray.append(tempCoupon)
855 + }
856 + }
857 + }
858 +
859 + swiftApi().setAllOldCouponList(allOldCouponsArray)
860 + // <==
842 861
843 // On Coupons request success, make CouponSets request 862 // On Coupons request success, make CouponSets request
844 instanceOfMyApi.getCouponsetsAsync(true, andVisible: true, andUuids: nil, couponSetsCallback, failureBlock: couponSetsFailureCallback) 863 instanceOfMyApi.getCouponsetsAsync(true, andVisible: true, andUuids: nil, couponSetsCallback, failureBlock: couponSetsFailureCallback)
...@@ -4525,6 +4544,37 @@ public class swiftApi { ...@@ -4525,6 +4544,37 @@ public class swiftApi {
4525 return GlobalVariables.oldCouponList 4544 return GlobalVariables.oldCouponList
4526 } 4545 }
4527 4546
4547 + public func setAllOldCouponList(_ coupons: Array<CouponItemModel>) {
4548 + // let filteredCoupons = coupons.filter { CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: $0.discount ?? "")) }
4549 + var oldCoupons = coupons.filter({ return $0.status == 0 })
4550 +
4551 + // sort oldCoupons by redeemed date
4552 +// let dateFormatter = DateFormatter()
4553 +// dateFormatter.dateFormat = "dd/MM/yyyy"
4554 +
4555 + oldCoupons.sort(by: {
4556 +// let date1 = dateFormatter.date(from: $0.redeemed ?? "")
4557 +// let date2 = dateFormatter.date(from: $1.redeemed ?? "")
4558 +
4559 + let date1 = $0.redeemed_date
4560 + let date2 = $1.redeemed_date
4561 +
4562 + if ((date1 != nil) && (date2 != nil)) {
4563 + return date1!.compare(date2!) == .orderedDescending
4564 + } else {
4565 + return false
4566 + }
4567 +
4568 + })
4569 +
4570 + GlobalVariables.allOldCouponList = oldCoupons
4571 + }
4572 +
4573 +
4574 + public func getAllOldCouponList() -> Array<CouponItemModel> {
4575 + return GlobalVariables.allOldCouponList
4576 + }
4577 +
4528 4578
4529 public func setCouponSetList(_ couponSets: Array<CouponSetItemModel>) { 4579 public func setCouponSetList(_ couponSets: Array<CouponSetItemModel>) {
4530 GlobalVariables.couponSetList = couponSets 4580 GlobalVariables.couponSetList = couponSets
......