Manos Chorianopoulos

fix Market History

...@@ -83,6 +83,39 @@ extension AnalysisItemViewCell { ...@@ -83,6 +83,39 @@ extension AnalysisItemViewCell {
83 } 83 }
84 } 84 }
85 85
86 + func configureCell(item: swiftApi.SharingCouponModel, isMarket: Bool) {
87 +
88 + let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
89 + let couponSetData: swiftApi.CouponSetItemModel? = item._sm_couponset_data
90 +
91 + titleLabel.text = ""
92 +
93 + for merchant in merchantList {
94 + if (merchant._uuid == item._merchant_uuid) {
95 + // itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
96 + self.postImageURL = merchant._img_preview
97 + titleLabel.text = merchant._admin_name
98 + break;
99 + }
100 + }
101 +
102 + dateLabel.text = item._date
103 + // titleLabel.text = item._name
104 +// titleLabel.text = couponSetData?.name ?? ""
105 +
106 +// let priceFloat = Float(round(100 * (Float(item._final_price) )) / 100)
107 + let priceFloat = Float(round(100 * (Float(couponSetData?.final_price ?? 0.0) )) / 100)
108 + var priceString = "0"
109 + priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
110 + priceLabel.text = priceString + "€"
111 +
112 + if ("sent" == item._sharing_type) {
113 + subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι προς " + item._receiver_msisdn)
114 + } else if ("received" == item._sharing_type) {
115 + subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι από " + item._sender_msisdn)
116 + }
117 + }
118 +
86 func configureCell(item: swiftApi.CouponItemModel) { 119 func configureCell(item: swiftApi.CouponItemModel) {
87 120
88 // COUPONSET: desc, img_preview, name, terms, merchant_uuid 121 // COUPONSET: desc, img_preview, name, terms, merchant_uuid
...@@ -130,7 +163,7 @@ extension AnalysisItemViewCell { ...@@ -130,7 +163,7 @@ extension AnalysisItemViewCell {
130 // let couponSetData: swiftApi.CouponSetItemModel? = item.couponset_data 163 // let couponSetData: swiftApi.CouponSetItemModel? = item.couponset_data
131 164
132 titleLabel.text = "" 165 titleLabel.text = ""
133 - 166 +
134 for merchant in merchantList { 167 for merchant in merchantList {
135 if (merchant._uuid == item.merchant_uuid) { 168 if (merchant._uuid == item.merchant_uuid) {
136 // itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache()) 169 // itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
......
...@@ -44,6 +44,7 @@ class MarketHistoryViewController: AnalysisChildViewController { ...@@ -44,6 +44,7 @@ class MarketHistoryViewController: AnalysisChildViewController {
44 44
45 showLoading() 45 showLoading()
46 46
47 +// items = swiftApi().getOldUnifiedCouponList()
47 items = swiftApi().getOldUnifiedCouponList() 48 items = swiftApi().getOldUnifiedCouponList()
48 49
49 self.showMore = (self.items.count > 3) 50 self.showMore = (self.items.count > 3)
...@@ -139,7 +140,8 @@ class MarketHistoryViewController: AnalysisChildViewController { ...@@ -139,7 +140,8 @@ class MarketHistoryViewController: AnalysisChildViewController {
139 } 140 }
140 141
141 let cell = tableView.dequeueReusableCell(withIdentifier: "AnalysisItemViewCell", for: indexPath) as! SwiftWarplyFramework.AnalysisItemViewCell 142 let cell = tableView.dequeueReusableCell(withIdentifier: "AnalysisItemViewCell", for: indexPath) as! SwiftWarplyFramework.AnalysisItemViewCell
142 - cell.configureCell(item: items[indexPath.row], isMarket: true) 143 +// cell.configureCell(item: items[indexPath.row], isMarket: true)
144 + cell.configureCell(item: items[indexPath.row])
143 145
144 return cell 146 return cell
145 } 147 }
......
...@@ -133,7 +133,7 @@ class MarketSharingHistoryViewController: AnalysisChildViewController { ...@@ -133,7 +133,7 @@ class MarketSharingHistoryViewController: AnalysisChildViewController {
133 } 133 }
134 134
135 let cell = tableView.dequeueReusableCell(withIdentifier: "AnalysisItemViewCell", for: indexPath) as! SwiftWarplyFramework.AnalysisItemViewCell 135 let cell = tableView.dequeueReusableCell(withIdentifier: "AnalysisItemViewCell", for: indexPath) as! SwiftWarplyFramework.AnalysisItemViewCell
136 - cell.configureCell(item: items[indexPath.row]) 136 + cell.configureCell(item: items[indexPath.row], isMarket: true)
137 137
138 return cell 138 return cell
139 } 139 }
......
...@@ -591,34 +591,64 @@ import SwiftEventBus ...@@ -591,34 +591,64 @@ import SwiftEventBus
591 591
592 func updateMarketBadge() { 592 func updateMarketBadge() {
593 unifiedCouponsDiscount = 0.0 593 unifiedCouponsDiscount = 0.0
594 +// for smCouponSet in swiftApi().getCouponSetsDealsList() {
595 +// for oldCoupon in swiftApi().getAllOldCouponList() {
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 +// }
605 +// }
606 +// }
607 +
608 + for coupon in swiftApi().getOldUnifiedCouponList() {
609 + if let discountFloat = Float(coupon.discount ?? "0.0") {
610 + unifiedCouponsDiscount += discountFloat
611 + }
612 + }
613 +
614 + // TODO: UNCOMMENT if emptyView is needed again
615 +// if (totalCouponValue == 0.0 && loyaltyBadge._couponCount == 0 && dfyCoupons.count == 0 && coupons.count == 0 && unifiedCoupons.count == 0 && unifiedCouponsDiscount == 0.0) {
616 +// emptyView.isHidden = false
617 +// emptyViewHeight.constant = emptyView.intrinsicContentSize.height
618 +// } else {
619 +// emptyView.isHidden = true
620 +// emptyViewHeight.constant = 0
621 +// }
622 + }
623 +
624 + func matchOldSMCoupons() {
625 + var oldUnifiedCouponsArray:Array<swiftApi.CouponItemModel> = []
626 +
594 for smCouponSet in swiftApi().getCouponSetsDealsList() { 627 for smCouponSet in swiftApi().getCouponSetsDealsList() {
595 for oldCoupon in swiftApi().getAllOldCouponList() { 628 for oldCoupon in swiftApi().getAllOldCouponList() {
596 if (smCouponSet.uuid != "" && oldCoupon.couponset_uuid != "" && smCouponSet.uuid == oldCoupon.couponset_uuid) { 629 if (smCouponSet.uuid != "" && oldCoupon.couponset_uuid != "" && smCouponSet.uuid == oldCoupon.couponset_uuid) {
597 630
598 oldCoupon.setCouponSetData(smCouponSet); 631 oldCoupon.setCouponSetData(smCouponSet);
632 + oldUnifiedCouponsArray.append(oldCoupon);
599 633
600 - if let discountFloat = Float(oldCoupon.discount ?? "0.0") {
601 - unifiedCouponsDiscount += discountFloat
602 - }
603 break; 634 break;
604 } 635 }
605 } 636 }
606 } 637 }
607 638
608 -// for coupon in swiftApi().getOldUnifiedCouponList() { 639 + oldUnifiedCouponsArray.sort(by: {
609 -// if let discountFloat = Float(coupon.discount ?? "0.0") { 640 + let date1 = $0.redeemed_date
610 -// unifiedCouponsDiscount += discountFloat 641 + let date2 = $1.redeemed_date
611 -// } 642 +
612 -// } 643 + if ((date1 != nil) && (date2 != nil)) {
644 + return date1!.compare(date2!) == .orderedDescending
645 + } else {
646 + return false
647 + }
648 +
649 + })
650 + swiftApi().setOldUnifiedCouponList(oldUnifiedCouponsArray)
613 651
614 - // TODO: UNCOMMENT if emptyView is needed again
615 -// if (totalCouponValue == 0.0 && loyaltyBadge._couponCount == 0 && dfyCoupons.count == 0 && coupons.count == 0 && unifiedCoupons.count == 0 && unifiedCouponsDiscount == 0.0) {
616 -// emptyView.isHidden = false
617 -// emptyViewHeight.constant = emptyView.intrinsicContentSize.height
618 -// } else {
619 -// emptyView.isHidden = true
620 -// emptyViewHeight.constant = 0
621 -// }
622 } 652 }
623 653
624 // MARK: - API Functions 654 // MARK: - API Functions
...@@ -648,6 +678,7 @@ import SwiftEventBus ...@@ -648,6 +678,7 @@ import SwiftEventBus
648 self.unifiedCoupons = couponsData ?? [] 678 self.unifiedCoupons = couponsData ?? []
649 679
650 DispatchQueue.main.async { 680 DispatchQueue.main.async {
681 + self.matchOldSMCoupons()
651 self.updateMarketBadge() 682 self.updateMarketBadge()
652 self.tableView.reloadData() 683 self.tableView.reloadData()
653 } 684 }
......
...@@ -492,7 +492,21 @@ public class swiftApi { ...@@ -492,7 +492,21 @@ public class swiftApi {
492 self.terms = dictionary["terms"] as? String? ?? "" 492 self.terms = dictionary["terms"] as? String? ?? ""
493 self.merchant_uuid = dictionary["merchant_uuid"] as? String? ?? "" 493 self.merchant_uuid = dictionary["merchant_uuid"] as? String? ?? ""
494 self.discount_type = dictionary["discount_type"] as? String? ?? "" 494 self.discount_type = dictionary["discount_type"] as? String? ?? ""
495 - self.final_price = dictionary["final_price"] as? Float? ?? 0.0 495 +// self.final_price = dictionary["final_price"] as? Float? ?? 0.0
496 +
497 + if let double_final_price = dictionary["final_price"] as? Double {
498 + self.final_price = Float(double_final_price)
499 + }
500 + else if let float_final_price = dictionary["final_price"] as? Float {
501 + self.final_price = float_final_price
502 + }
503 + else if let string_final_price = dictionary["final_price"] as? String {
504 + self.final_price = Float(string_final_price) ?? 0.0
505 + }
506 + else {
507 + self.final_price = 0.0
508 + }
509 +
496 510
497 let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""] 511 let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""]
498 let expirationString = expirationObject?["value"] as? String? ?? "" 512 let expirationString = expirationObject?["value"] as? String? ?? ""
...@@ -5574,6 +5588,7 @@ public class swiftApi { ...@@ -5574,6 +5588,7 @@ public class swiftApi {
5574 private var receiver_msisdn: String? 5588 private var receiver_msisdn: String?
5575 private var sender_msisdn: String? 5589 private var sender_msisdn: String?
5576 private var final_price: Float? 5590 private var final_price: Float?
5591 + private var sm_couponset_data: CouponSetItemModel?
5577 5592
5578 public init() { 5593 public init() {
5579 self.couponset_uuid = "" 5594 self.couponset_uuid = ""
...@@ -5586,6 +5601,7 @@ public class swiftApi { ...@@ -5586,6 +5601,7 @@ public class swiftApi {
5586 self.receiver_msisdn = "" 5601 self.receiver_msisdn = ""
5587 self.sender_msisdn = "" 5602 self.sender_msisdn = ""
5588 self.final_price = 0.0 5603 self.final_price = 0.0
5604 + self.sm_couponset_data = nil
5589 } 5605 }
5590 5606
5591 public init(dictionary: [String: Any]) { 5607 public init(dictionary: [String: Any]) {
...@@ -5594,6 +5610,7 @@ public class swiftApi { ...@@ -5594,6 +5610,7 @@ public class swiftApi {
5594 self.merchant_uuid = dictionary["merchant_uuid"] as? String? ?? "" 5610 self.merchant_uuid = dictionary["merchant_uuid"] as? String? ?? ""
5595 self.sharing_type = dictionary["sharing_type"] as? String? ?? "" 5611 self.sharing_type = dictionary["sharing_type"] as? String? ?? ""
5596 // self.transaction_metadata = dictionary["transaction_metadata"] as? String? ?? "" 5612 // self.transaction_metadata = dictionary["transaction_metadata"] as? String? ?? ""
5613 + self.sm_couponset_data = nil
5597 5614
5598 self.name = "" 5615 self.name = ""
5599 self.final_price = 0.0 5616 self.final_price = 0.0
...@@ -5731,17 +5748,81 @@ public class swiftApi { ...@@ -5731,17 +5748,81 @@ public class swiftApi {
5731 self.final_price = newValue 5748 self.final_price = newValue
5732 } 5749 }
5733 } 5750 }
5751 +
5752 + public var _sm_couponset_data: CouponSetItemModel? {
5753 + get { // getter
5754 + return self.sm_couponset_data ?? nil
5755 + }
5756 + set(newValue) { //setter
5757 + self.sm_couponset_data = newValue
5758 + }
5759 + }
5734 } 5760 }
5735 5761
5736 5762
5737 public func getSharingHistoryAsync(isMarketHistory: Bool, getSharingHistoryCallback: @escaping (_ sharingHistoryData: Array<SharingCouponModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void { 5763 public func getSharingHistoryAsync(isMarketHistory: Bool, getSharingHistoryCallback: @escaping (_ sharingHistoryData: Array<SharingCouponModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
5738 let instanceOfMyApi = MyApi() 5764 let instanceOfMyApi = MyApi()
5739 if (isMarketHistory == true) { 5765 if (isMarketHistory == true) {
5740 - instanceOfMyApi.getMarketSharingHistoryAsync(requestCallback, failureBlock: requestFailureCallback) 5766 + instanceOfMyApi.getMarketSharingHistoryAsync(marketRequestCallback, failureBlock: requestFailureCallback)
5741 } else { 5767 } else {
5742 instanceOfMyApi.getSharingHistoryAsync(requestCallback, failureBlock: requestFailureCallback) 5768 instanceOfMyApi.getSharingHistoryAsync(requestCallback, failureBlock: requestFailureCallback)
5743 } 5769 }
5744 5770
5771 + func marketRequestCallback(_ sharingHistoryData: [AnyHashable: Any]?) -> Void {
5772 + var historyArray:Array<SharingCouponModel> = []
5773 +
5774 + if let responseDataDictionary = sharingHistoryData as? [String: AnyObject] {
5775 +
5776 + if (responseDataDictionary["status"] as? Int == 1) {
5777 +
5778 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
5779 + dynatraceEvent._eventName = "custom_success_sharing_history_loyalty"
5780 + dynatraceEvent._parameters = nil
5781 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
5782 +
5783 + if let responseDataResult = responseDataDictionary["result"] as? [[String : Any]?] {
5784 +
5785 + for item in responseDataResult {
5786 + if let itemDictionary = item {
5787 +
5788 + let couponsetUuid = itemDictionary["couponset_uuid"] as? String? ?? ""
5789 + let couponsetsList = swiftApi().getCouponSetsDealsList()
5790 + for item in couponsetsList {
5791 + if (item.uuid == couponsetUuid) {
5792 + let tempHistoyItem = SharingCouponModel(dictionary: itemDictionary)
5793 + tempHistoyItem._sm_couponset_data = item;
5794 + historyArray.append(tempHistoyItem)
5795 + break;
5796 + }
5797 + }
5798 +
5799 + }
5800 + }
5801 +
5802 + getSharingHistoryCallback(historyArray);
5803 + } else {
5804 + getSharingHistoryCallback(nil)
5805 + }
5806 +
5807 + } else {
5808 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
5809 + dynatraceEvent._eventName = "custom_error_sharing_history_loyalty"
5810 + dynatraceEvent._parameters = nil
5811 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
5812 +
5813 + getSharingHistoryCallback(nil)
5814 + }
5815 +
5816 + } else {
5817 + let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
5818 + dynatraceEvent._eventName = "custom_error_sharing_history_loyalty"
5819 + dynatraceEvent._parameters = nil
5820 + SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
5821 +
5822 + getSharingHistoryCallback(nil)
5823 + }
5824 + }
5825 +
5745 func requestCallback(_ sharingHistoryData: [AnyHashable: Any]?) -> Void { 5826 func requestCallback(_ sharingHistoryData: [AnyHashable: Any]?) -> Void {
5746 var historyArray:Array<SharingCouponModel> = [] 5827 var historyArray:Array<SharingCouponModel> = []
5747 5828
...@@ -7088,13 +7169,13 @@ public class swiftApi { ...@@ -7088,13 +7169,13 @@ public class swiftApi {
7088 } 7169 }
7089 7170
7090 // Old Unified Coupons 7171 // Old Unified Coupons
7091 - let tempUniCoupon = UnifiedCouponModel(dictionary: itemDictionary) 7172 + // let tempUniCoupon = UnifiedCouponModel(dictionary: itemDictionary)
7092 7173
7093 - for item in tempUniCoupon._coupons { 7174 + // for item in tempUniCoupon._coupons {
7094 - if (item.status == 0) { 7175 + // if (item.status == 0) {
7095 - oldUnifiedCouponsArray.append(item) 7176 + // oldUnifiedCouponsArray.append(item)
7096 - } 7177 + // }
7097 - } 7178 + // }
7098 7179
7099 } 7180 }
7100 } 7181 }
...@@ -7109,18 +7190,18 @@ public class swiftApi { ...@@ -7109,18 +7190,18 @@ public class swiftApi {
7109 7190
7110 swiftApi().setUnifiedCouponList(sortedUnifiedCouponsArray) 7191 swiftApi().setUnifiedCouponList(sortedUnifiedCouponsArray)
7111 7192
7112 - oldUnifiedCouponsArray.sort(by: { 7193 + // oldUnifiedCouponsArray.sort(by: {
7113 - let date1 = $0.redeemed_date 7194 + // let date1 = $0.redeemed_date
7114 - let date2 = $1.redeemed_date 7195 + // let date2 = $1.redeemed_date
7115 7196
7116 - if ((date1 != nil) && (date2 != nil)) { 7197 + // if ((date1 != nil) && (date2 != nil)) {
7117 - return date1!.compare(date2!) == .orderedDescending 7198 + // return date1!.compare(date2!) == .orderedDescending
7118 - } else { 7199 + // } else {
7119 - return false 7200 + // return false
7120 - } 7201 + // }
7121 7202
7122 - }) 7203 + // })
7123 - swiftApi().setOldUnifiedCouponList(oldUnifiedCouponsArray) 7204 + // swiftApi().setOldUnifiedCouponList(oldUnifiedCouponsArray)
7124 successCallback(sortedUnifiedCouponsArray) 7205 successCallback(sortedUnifiedCouponsArray)
7125 } 7206 }
7126 } else { 7207 } else {
......