Manos Chorianopoulos

fix Market History

......@@ -83,6 +83,39 @@ extension AnalysisItemViewCell {
}
}
func configureCell(item: swiftApi.SharingCouponModel, isMarket: Bool) {
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
let couponSetData: swiftApi.CouponSetItemModel? = item._sm_couponset_data
titleLabel.text = ""
for merchant in merchantList {
if (merchant._uuid == item._merchant_uuid) {
// itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
self.postImageURL = merchant._img_preview
titleLabel.text = merchant._admin_name
break;
}
}
dateLabel.text = item._date
// titleLabel.text = item._name
// titleLabel.text = couponSetData?.name ?? ""
// let priceFloat = Float(round(100 * (Float(item._final_price) )) / 100)
let priceFloat = Float(round(100 * (Float(couponSetData?.final_price ?? 0.0) )) / 100)
var priceString = "0"
priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
priceLabel.text = priceString + "€"
if ("sent" == item._sharing_type) {
subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι προς " + item._receiver_msisdn)
} else if ("received" == item._sharing_type) {
subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι από " + item._sender_msisdn)
}
}
func configureCell(item: swiftApi.CouponItemModel) {
// COUPONSET: desc, img_preview, name, terms, merchant_uuid
......
......@@ -44,6 +44,7 @@ class MarketHistoryViewController: AnalysisChildViewController {
showLoading()
// items = swiftApi().getOldUnifiedCouponList()
items = swiftApi().getOldUnifiedCouponList()
self.showMore = (self.items.count > 3)
......@@ -139,7 +140,8 @@ class MarketHistoryViewController: AnalysisChildViewController {
}
let cell = tableView.dequeueReusableCell(withIdentifier: "AnalysisItemViewCell", for: indexPath) as! SwiftWarplyFramework.AnalysisItemViewCell
cell.configureCell(item: items[indexPath.row], isMarket: true)
// cell.configureCell(item: items[indexPath.row], isMarket: true)
cell.configureCell(item: items[indexPath.row])
return cell
}
......
......@@ -133,7 +133,7 @@ class MarketSharingHistoryViewController: AnalysisChildViewController {
}
let cell = tableView.dequeueReusableCell(withIdentifier: "AnalysisItemViewCell", for: indexPath) as! SwiftWarplyFramework.AnalysisItemViewCell
cell.configureCell(item: items[indexPath.row])
cell.configureCell(item: items[indexPath.row], isMarket: true)
return cell
}
......
......@@ -591,25 +591,25 @@ import SwiftEventBus
func updateMarketBadge() {
unifiedCouponsDiscount = 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);
// 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;
// }
// }
// }
if let discountFloat = Float(oldCoupon.discount ?? "0.0") {
for coupon in swiftApi().getOldUnifiedCouponList() {
if let discountFloat = Float(coupon.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) {
......@@ -621,6 +621,36 @@ import SwiftEventBus
// }
}
func matchOldSMCoupons() {
var oldUnifiedCouponsArray:Array<swiftApi.CouponItemModel> = []
for smCouponSet in swiftApi().getCouponSetsDealsList() {
for oldCoupon in swiftApi().getAllOldCouponList() {
if (smCouponSet.uuid != "" && oldCoupon.couponset_uuid != "" && smCouponSet.uuid == oldCoupon.couponset_uuid) {
oldCoupon.setCouponSetData(smCouponSet);
oldUnifiedCouponsArray.append(oldCoupon);
break;
}
}
}
oldUnifiedCouponsArray.sort(by: {
let date1 = $0.redeemed_date
let date2 = $1.redeemed_date
if ((date1 != nil) && (date2 != nil)) {
return date1!.compare(date2!) == .orderedDescending
} else {
return false
}
})
swiftApi().setOldUnifiedCouponList(oldUnifiedCouponsArray)
}
// MARK: - API Functions
func getCouponsSetsDealsRequest() {
swiftApi().getCouponSetsDealsAsync(getCouponsSetsDealsCallback, failureCallback: {errorCode in
......@@ -648,6 +678,7 @@ import SwiftEventBus
self.unifiedCoupons = couponsData ?? []
DispatchQueue.main.async {
self.matchOldSMCoupons()
self.updateMarketBadge()
self.tableView.reloadData()
}
......
......@@ -492,7 +492,21 @@ public class swiftApi {
self.terms = dictionary["terms"] as? String? ?? ""
self.merchant_uuid = dictionary["merchant_uuid"] as? String? ?? ""
self.discount_type = dictionary["discount_type"] as? String? ?? ""
self.final_price = dictionary["final_price"] as? Float? ?? 0.0
// self.final_price = dictionary["final_price"] as? Float? ?? 0.0
if let double_final_price = dictionary["final_price"] as? Double {
self.final_price = Float(double_final_price)
}
else if let float_final_price = dictionary["final_price"] as? Float {
self.final_price = float_final_price
}
else if let string_final_price = dictionary["final_price"] as? String {
self.final_price = Float(string_final_price) ?? 0.0
}
else {
self.final_price = 0.0
}
let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""]
let expirationString = expirationObject?["value"] as? String? ?? ""
......@@ -5574,6 +5588,7 @@ public class swiftApi {
private var receiver_msisdn: String?
private var sender_msisdn: String?
private var final_price: Float?
private var sm_couponset_data: CouponSetItemModel?
public init() {
self.couponset_uuid = ""
......@@ -5586,6 +5601,7 @@ public class swiftApi {
self.receiver_msisdn = ""
self.sender_msisdn = ""
self.final_price = 0.0
self.sm_couponset_data = nil
}
public init(dictionary: [String: Any]) {
......@@ -5594,6 +5610,7 @@ public class swiftApi {
self.merchant_uuid = dictionary["merchant_uuid"] as? String? ?? ""
self.sharing_type = dictionary["sharing_type"] as? String? ?? ""
// self.transaction_metadata = dictionary["transaction_metadata"] as? String? ?? ""
self.sm_couponset_data = nil
self.name = ""
self.final_price = 0.0
......@@ -5731,17 +5748,81 @@ public class swiftApi {
self.final_price = newValue
}
}
public var _sm_couponset_data: CouponSetItemModel? {
get { // getter
return self.sm_couponset_data ?? nil
}
set(newValue) { //setter
self.sm_couponset_data = newValue
}
}
}
public func getSharingHistoryAsync(isMarketHistory: Bool, getSharingHistoryCallback: @escaping (_ sharingHistoryData: Array<SharingCouponModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
let instanceOfMyApi = MyApi()
if (isMarketHistory == true) {
instanceOfMyApi.getMarketSharingHistoryAsync(requestCallback, failureBlock: requestFailureCallback)
instanceOfMyApi.getMarketSharingHistoryAsync(marketRequestCallback, failureBlock: requestFailureCallback)
} else {
instanceOfMyApi.getSharingHistoryAsync(requestCallback, failureBlock: requestFailureCallback)
}
func marketRequestCallback(_ sharingHistoryData: [AnyHashable: Any]?) -> Void {
var historyArray:Array<SharingCouponModel> = []
if let responseDataDictionary = sharingHistoryData as? [String: AnyObject] {
if (responseDataDictionary["status"] as? Int == 1) {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_success_sharing_history_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
if let responseDataResult = responseDataDictionary["result"] as? [[String : Any]?] {
for item in responseDataResult {
if let itemDictionary = item {
let couponsetUuid = itemDictionary["couponset_uuid"] as? String? ?? ""
let couponsetsList = swiftApi().getCouponSetsDealsList()
for item in couponsetsList {
if (item.uuid == couponsetUuid) {
let tempHistoyItem = SharingCouponModel(dictionary: itemDictionary)
tempHistoyItem._sm_couponset_data = item;
historyArray.append(tempHistoyItem)
break;
}
}
}
}
getSharingHistoryCallback(historyArray);
} else {
getSharingHistoryCallback(nil)
}
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_sharing_history_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
getSharingHistoryCallback(nil)
}
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_sharing_history_loyalty"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
getSharingHistoryCallback(nil)
}
}
func requestCallback(_ sharingHistoryData: [AnyHashable: Any]?) -> Void {
var historyArray:Array<SharingCouponModel> = []
......@@ -7088,13 +7169,13 @@ public class swiftApi {
}
// Old Unified Coupons
let tempUniCoupon = UnifiedCouponModel(dictionary: itemDictionary)
// let tempUniCoupon = UnifiedCouponModel(dictionary: itemDictionary)
for item in tempUniCoupon._coupons {
if (item.status == 0) {
oldUnifiedCouponsArray.append(item)
}
}
// for item in tempUniCoupon._coupons {
// if (item.status == 0) {
// oldUnifiedCouponsArray.append(item)
// }
// }
}
}
......@@ -7109,18 +7190,18 @@ public class swiftApi {
swiftApi().setUnifiedCouponList(sortedUnifiedCouponsArray)
oldUnifiedCouponsArray.sort(by: {
let date1 = $0.redeemed_date
let date2 = $1.redeemed_date
// oldUnifiedCouponsArray.sort(by: {
// let date1 = $0.redeemed_date
// let date2 = $1.redeemed_date
if ((date1 != nil) && (date2 != nil)) {
return date1!.compare(date2!) == .orderedDescending
} else {
return false
}
// if ((date1 != nil) && (date2 != nil)) {
// return date1!.compare(date2!) == .orderedDescending
// } else {
// return false
// }
})
swiftApi().setOldUnifiedCouponList(oldUnifiedCouponsArray)
// })
// swiftApi().setOldUnifiedCouponList(oldUnifiedCouponsArray)
successCallback(sortedUnifiedCouponsArray)
}
} else {
......