Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.13 KB | None | 0 0
  1. //
  2. // TransaksiDetailViewController.swift
  3. // Logan Warehouse
  4. //
  5. // Created by Logan on 14/11/19.
  6. // Copyright (c) 2019 Ilham Malik Ibrahim. All rights reserved.
  7. //
  8. /// Modify By: * Ilham Malik Ibrahim
  9. // * ilhammalik19@gmail.com
  10. // * https://github.com/ilhammalik11
  11. //
  12.  
  13. import UIKit
  14. import Alamofire
  15. import Toaster
  16.  
  17. protocol setDone {
  18. func setCallBack()
  19. }
  20.  
  21.  
  22. class PaymentCell: UICollectionViewCell {
  23. @IBOutlet open weak var titleLabel: UILabel!
  24. @IBOutlet open weak var dateLabel: UILabel!
  25. @IBOutlet open weak var nominalLabel: UILabel!
  26. override func layoutSubviews() {
  27. super.layoutSubviews()
  28. }
  29. }
  30.  
  31.  
  32. class TransaksiQuotationCell: UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate {
  33. @IBOutlet open weak var titleLabel: UILabel!
  34. @IBOutlet open weak var subtitleLabel: UILabel!
  35. @IBOutlet open weak var capasitasLabel: UILabel!
  36. @IBOutlet open weak var mulaisewaLabel: UILabel!
  37. @IBOutlet open weak var selesaiLabel: UILabel!
  38. @IBOutlet open weak var kebutuhanLabel: UILabel!
  39. @IBOutlet open weak var storageLabel: UILabel!
  40. @IBOutlet open weak var totalLabel: UILabel!
  41. @IBOutlet open weak var pembayaranLabel: UILabel!
  42. @IBOutlet open weak var pembayaran2Label: UILabel!
  43. @IBOutlet open weak var pembayaran3Label: UILabel!
  44. @IBOutlet open weak var descLabel: UILabel!
  45. @IBOutlet open weak var collectionView: UICollectionView!
  46. let screenSize: CGRect = UIScreen.main.bounds
  47. private let cellReuseIdentifier = "cell"
  48. var data = [TransaksiDetail.Model.Fetch.PaymentSchedule]()
  49. override func layoutSubviews() {
  50. super.layoutSubviews()
  51. self.collectionView.register(UINib(nibName: "Cell_Payment", bundle: nil), forCellWithReuseIdentifier:cellReuseIdentifier)
  52. collectionView.delegate = self
  53. collectionView.dataSource = self
  54. }
  55.  
  56.  
  57. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
  58. {
  59. return self.data.count
  60. }
  61.  
  62. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
  63. {
  64. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellReuseIdentifier, for: indexPath) as! PaymentCell
  65. cell.titleLabel.text = checkNull(sender: data[indexPath.row].remarks)
  66. cell.dateLabel.text = convertStringUNIXDateIndo(data: checkNullInt(sender: data[indexPath.row].date))
  67. cell.nominalLabel.text = "Rp. \(checkNullInt(sender: data[indexPath.row].nominal))"
  68. return cell
  69. }
  70.  
  71. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
  72. {
  73. return CGSize(width: screenSize.width-20, height: 30)
  74. }
  75.  
  76. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets
  77. {
  78. return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  79. }
  80.  
  81. override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize {
  82. let height = collectionView.contentSize.height
  83. return CGSize(width: targetSize.width, height: height)
  84. }
  85.  
  86.  
  87.  
  88. }
  89.  
  90.  
  91. class TransaksiDetailCell: UITableViewCell {
  92. @IBOutlet open weak var avatar: UIImageView!
  93. @IBOutlet open weak var titleLabel: UILabel!
  94. @IBOutlet open weak var subtitleLabel: UILabel!
  95. @IBOutlet open weak var capasitasLabel: UILabel!
  96. @IBOutlet open weak var mulaisewaLabel: UILabel!
  97. @IBOutlet open weak var selesaiLabel: UILabel!
  98. @IBOutlet open weak var kebutuhanLabel: UILabel!
  99. @IBOutlet open weak var storageLabel: UILabel!
  100. @IBOutlet open weak var companyLabel: UILabel!
  101. @IBOutlet open weak var kontakLabel: UILabel!
  102. @IBOutlet open weak var statusLabel: UITextField!
  103. @IBOutlet open weak var dateLabel: UILabel!
  104.  
  105. }
  106.  
  107.  
  108. class FeatureCell: UICollectionViewCell {
  109. @IBOutlet open weak var titleLabel: UILabel!
  110. override func layoutSubviews() {
  111. super.layoutSubviews()
  112. contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 5, left: 0, bottom: 10, right: 0))
  113. contentView.backgroundColor = UIColor.white
  114. contentView.cornerRadiuss = 5
  115. }
  116. }
  117. protocol TransaksiDetailDisplayLogic: class
  118. {
  119. func displayModel(viewModel: TransaksiDetail.Model.ViewModel)
  120. }
  121.  
  122. class TransaksiDetailViewController: UITableViewController, TransaksiDetailDisplayLogic,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,setDone,UITextFieldDelegate
  123. {
  124.  
  125.  
  126. var interactor: TransaksiDetailBusinessLogic?
  127. var router: (NSObjectProtocol & TransaksiDetailRoutingLogic & TransaksiDetailDataPassing)?
  128. @IBOutlet open weak var CollectionView: UICollectionView!
  129. let leftAndRightPaddings: CGFloat = 80.0
  130. let numberOfItemsPerRow: CGFloat = 7.0
  131. let screenSize: CGRect = UIScreen.main.bounds
  132.  
  133. private let cellReuseIdentifier = "cell"
  134. var items = ["Fork Lift", "Palet", "Racking","Security"]
  135. @IBOutlet open weak var avatar: UIImageView!
  136. @IBOutlet open weak var avatar2: UIImageView!
  137. @IBOutlet open weak var titleLabel: UILabel!
  138. @IBOutlet open weak var subtitleLabel: UILabel!
  139. @IBOutlet open weak var capasitasLabel: UILabel!
  140.  
  141. @IBOutlet open weak var mulaisewaLabel: UILabel!
  142. @IBOutlet open weak var selesaiLabel: UILabel!
  143. @IBOutlet open weak var kebutuhanLabel: UILabel!
  144. @IBOutlet open weak var storageLabel: UILabel!
  145. @IBOutlet open weak var companyLabel: UILabel!
  146. @IBOutlet open weak var kontakLabel: UILabel!
  147. @IBOutlet open weak var titleQuotationLabel: UILabel!
  148. @IBOutlet open weak var placeholdeEmpty: UILabel!
  149. @IBOutlet open weak var statusLabel: UITextField!
  150.  
  151. @IBOutlet open weak var subtitle2Label: UILabel!
  152. @IBOutlet open weak var regionLabel: UILabel!
  153. @IBOutlet open weak var capasitas2Label: UILabel!
  154. @IBOutlet open weak var mulaisewa2Label: UILabel!
  155. @IBOutlet open weak var selesai2Label: UILabel!
  156. @IBOutlet open weak var kebutuhan2Label: UILabel!
  157. @IBOutlet open weak var storage2Label: UILabel!
  158. @IBOutlet open weak var company2Label: UILabel!
  159. @IBOutlet open weak var kontak2Label: UILabel!
  160. @IBOutlet open weak var titleQuotation2Label: UILabel!
  161. @IBOutlet open weak var status2Label: UITextField!
  162. @IBOutlet open weak var kontrakUITextfield: UITextField!
  163. @IBOutlet open weak var dateLabel: UILabel!
  164. @IBOutlet open weak var titleStatusLabel: UILabel!
  165. @IBOutlet open weak var titleidLabel: UILabel!
  166. @IBOutlet open weak var titletrxLabel: UILabel!
  167. @IBOutlet open weak var views: UIView!
  168. @IBOutlet open weak var statusTrxLabel: UILabel!
  169. fileprivate var dataFacility = [TransaksiDetail.Model.Fetch.Facility]()
  170. fileprivate var dataQuotation = [TransaksiDetail.Model.Fetch.Quotation]()
  171. var data: TransaksiDetail.Model.Fetch.Data!
  172. var activityIndicator = LoganToast()
  173. var activity = LoganLoading()
  174. // MARK: Setup
  175. var status = 0
  176. var isStatus = 0
  177. var id : String = ""
  178. var code : String = ""
  179. var isDetail : Bool = false
  180. var isHistory : Bool = false
  181. var strAlasan : String = ""
  182. var strDesc : String = ""
  183. var heightBottom : Int = 320
  184. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?){
  185. super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
  186. setup()
  187. }
  188.  
  189. required init?(coder aDecoder: NSCoder)
  190. {
  191. super.init(coder: aDecoder)
  192. setup()
  193. }
  194.  
  195.  
  196. private func setup()
  197. {
  198. let viewController = self
  199. let interactor = TransaksiDetailInteractor()
  200. let presenter = TransaksiDetailPresenter()
  201. let router = TransaksiDetailRouter()
  202. viewController.interactor = interactor
  203. viewController.router = router
  204. interactor.presenter = presenter
  205. presenter.viewController = viewController
  206. router.viewController = viewController
  207. router.dataStore = interactor
  208. }
  209.  
  210. // MARK: Routing
  211.  
  212.  
  213. // MARK: View lifecycle
  214.  
  215. override func viewDidLoad()
  216. {
  217. super.viewDidLoad()
  218. navigationController?.navigationBar.tintColor = UIColor.black
  219. CollectionView.delegate = self
  220. CollectionView.dataSource = self
  221. navigationItem.title = "Transaksi"
  222. titleidLabel.text = "Transaksi ID \(code)"
  223. titletrxLabel.text = "Transaksi ID \(code)"
  224. kontrakUITextfield.delegate = self
  225. tableView.frame = tableView.bounds
  226. // tableView.layoutIfNeeded()
  227. if(UserDefaults.standard.isVendor() == true){
  228. titleQuotationLabel.text = "Kontrak Dikirim"
  229. }
  230.  
  231. tableView.register(UINib(nibName: "Cell_Qoutation", bundle: nil), forCellReuseIdentifier: CellId.Dynamic)
  232. tableView.reloadData()
  233. addLoganLoading()
  234.  
  235. }
  236.  
  237.  
  238. func textFieldDidBeginEditing(_ textField: UITextField) {
  239.  
  240. if kontrakUITextfield.isEditing == true{
  241. view.endEditing(true)
  242. removeView()
  243.  
  244. router?.routeToKontrak(id: "0", status: isStatus)
  245. }
  246.  
  247. }
  248. override func viewDidAppear(_ animated: Bool) {
  249. super.viewDidAppear(true)
  250. doModel()
  251. }
  252.  
  253. func addLoganLoading(){
  254. self.navigationController?.view.addSubview(activityIndicator)
  255. activityIndicator.frame = CGRect(x: 0, y: 60, width: UIScreen.main.bounds.width, height:30)
  256. }
  257.  
  258. func addLoading(){
  259. self.navigationController?.view.addSubview(activity)
  260. activity.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height:UIScreen.main.bounds.height)
  261. }
  262.  
  263.  
  264.  
  265. func addButtonChat(){
  266. let button = UIButton(frame: CGRect(x: UIScreen.main.bounds.width-80, y: UIScreen.main.bounds.height-150, width: 100, height: 100))
  267. button.tag = 2
  268. button.addTarget(self, action: #selector(showChat), for: .touchUpInside)
  269. button.setImage(UIImage(named: "ic_chat"), for: .normal)
  270. self.navigationController?.view.addSubview(button)
  271. }
  272.  
  273. func addViewButton(){
  274. if let customView = Bundle.main.loadNibNamed("ButtomButton", owner: self, options: nil)?.first as? BottomView {
  275. customView.tag = 1
  276. let btn = UserDefaults.standard.isVendor() == true ? "Tolak" : "Batalkan"
  277. let btn2 = UserDefaults.standard.isVendor() == true ? "Buat Kontrak" : "Terima"
  278. customView.btn.setTitle("\(btn)", for: .normal)
  279. customView.btn2.setTitle("\(btn2)", for: .normal)
  280. customView.btn.addTarget(self, action: #selector(actionTolak), for: .touchUpInside)
  281. customView.btn2.addTarget(self, action: #selector(actionKontrak), for: .touchUpInside)
  282. self.navigationController?.view.addSubview(customView)
  283. customView.frame = CGRect(x: 0, y: UIScreen.main.bounds.height-70, width: UIScreen.main.bounds.width, height:50)
  284. }
  285. }
  286.  
  287. // MARK: Do Model
  288. override func viewWillDisappear(_ animated: Bool) {
  289. super.viewWillDisappear(true)
  290. if let viewWithTag = self.navigationController?.view.viewWithTag(1) {
  291. viewWithTag.removeFromSuperview()
  292. }
  293.  
  294. if let viewWithTag = self.navigationController?.view.viewWithTag(2) {
  295. viewWithTag.removeFromSuperview()
  296. }
  297.  
  298. }
  299.  
  300.  
  301. @objc func showChat(){
  302. let destinationVC = ChatsViewController()
  303. destinationVC.id = id
  304. destinationVC.trxCode = code
  305. self.navigationController?.pushViewController(destinationVC, animated: true)
  306. }
  307.  
  308. func removeView(){
  309. if let viewWithTag = self.navigationController?.view.viewWithTag(1) {
  310. viewWithTag.removeFromSuperview()
  311. }
  312.  
  313. if let viewWithTag = self.navigationController?.view.viewWithTag(2) {
  314. viewWithTag.removeFromSuperview()
  315. }
  316. }
  317. //@IBOutlet weak var nameTextField: UITextField!
  318.  
  319. func doModel()
  320. {
  321. let request = TransaksiDetail.Model.Request(id: id)
  322. interactor?.doModel(request: request)
  323. }
  324.  
  325. func displayModel(viewModel: TransaksiDetail.Model.ViewModel)
  326. {
  327. titleLabel.text = checkNull(sender: viewModel.data.warehouseName)
  328. subtitleLabel.text = checkNull(sender: viewModel.data.warehouseName)
  329. capasitasLabel.text = "\(checkNullInt(sender: viewModel.data.warehouseCapacity))"
  330. let startRent = checkNullTypeInt(sender: "\(viewModel.data.startRent)")
  331. let endRent = checkNullTypeInt(sender: "\(viewModel.data.endRent)")
  332. let contract = checkNullTypeInt(sender: "\(viewModel.data.contractedAt)")
  333. let lastBit = checkNullTypeInt(sender: "\(viewModel.data.latestBidAt)")
  334. let reject = checkNullTypeInt(sender: "\(viewModel.data.rejectedAt)")
  335.  
  336. mulaisewaLabel.text = convertStringUNIXDateIndo(data: startRent)
  337. selesaiLabel.text = convertStringUNIXDateIndo(data: endRent)
  338. kebutuhanLabel.text = "\(checkNullInt(sender: viewModel.data.demand))"
  339. storageLabel.text = checkNull(sender: viewModel.data.warehouseStorageType)
  340.  
  341. subtitle2Label.text = checkNull(sender: viewModel.data.warehouseRegionName)
  342. regionLabel.text = checkNull(sender: viewModel.data.warehouseProvinceName)
  343. mulaisewa2Label.text = convertStringUNIXDateIndo(data: startRent)
  344. selesai2Label.text = convertStringUNIXDateIndo(data: endRent)
  345. kebutuhan2Label.text = "\(checkNullInt(sender: viewModel.data.demand)) m2"
  346. storage2Label.text = checkNull(sender: viewModel.data.warehouseStorageType)
  347. capasitas2Label.text = "\(checkNullInt(sender: viewModel.data.warehouseCapacity)) m2"
  348. company2Label.text = checkNull(sender: viewModel.data.warehouseName)
  349. companyLabel.text = checkNull(sender: viewModel.data.user?.companyName)
  350. kontakLabel.text = checkNull(sender: viewModel.data.user?.name)
  351. if checkStatusInt(contract: contract, reject: reject, lastbit: lastBit, end_rent: endRent) == 0{
  352. status = 0
  353. addButtonChat()
  354. }
  355.  
  356.  
  357.  
  358. if checkStatusInt(contract: contract, reject: reject, lastbit: lastBit, end_rent: endRent) == 1 && UserDefaults.standard.isVendor(){
  359. status = 0
  360. addButtonChat()
  361. addViewButton()
  362. }
  363.  
  364. if checkStatusInt(contract: contract, reject: reject, lastbit: lastBit, end_rent: endRent) == 1 && !UserDefaults.standard.isVendor(){
  365. status = 0
  366. addButtonChat()
  367. addViewButton()
  368. }
  369.  
  370.  
  371. if checkStatusInt(contract: contract, reject: reject, lastbit: lastBit, end_rent: endRent) == 2 && !UserDefaults.standard.isVendor(){
  372. status = 0
  373. addButtonChat()
  374. addViewButton()
  375. }
  376.  
  377. if checkStatusInt(contract: contract, reject: reject, lastbit: lastBit, end_rent: endRent) == 2 && UserDefaults.standard.isVendor(){
  378. status = 1
  379. addButtonChat()
  380.  
  381. }
  382.  
  383. if checkStatusInt(contract: contract, reject: reject, lastbit: lastBit, end_rent: endRent) == 3 {
  384. status = 1
  385. if let viewWithTag = self.navigationController?.view.viewWithTag(1) {
  386. viewWithTag.removeFromSuperview()
  387. }
  388. }
  389.  
  390. if checkStatusInt(contract: contract, reject: reject, lastbit: lastBit, end_rent: endRent) == 3 {
  391. views.backgroundColor = UIColor.init(hexString: "C74545")
  392. views.isHidden = false
  393. status = 3
  394. titleStatusLabel.text = "Transaksi Batal"
  395. statusTrxLabel.textColor = UIColor.red
  396. if let viewWithTag = self.navigationController?.view.viewWithTag(1) {
  397. viewWithTag.removeFromSuperview()
  398. }
  399. heightBottom = 250
  400. strAlasan = "Api ya belum ada"
  401. strDesc = "Api ya belum ada"
  402.  
  403. isDetail = true
  404. if let customView = Bundle.main.loadNibNamed("DetailViewTolak", owner: self, options: nil)?.first as? DetailViewTolak {
  405. customView.tag = 1
  406. customView.btnLabel.addTarget(self, action: #selector(bottomsheetTolak), for: .touchUpInside)
  407. self.navigationController?.view.addSubview(customView)
  408. customView.frame = CGRect(x: 0, y: UIScreen.main.bounds.height-100, width: UIScreen.main.bounds.width, height:100)
  409. }
  410. }
  411.  
  412. isStatus = checkStatusInt(contract: contract, reject: reject, lastbit: lastBit, end_rent: endRent)
  413.  
  414. if checkStatusInt(contract: contract, reject: reject, lastbit: lastBit, end_rent: endRent) == 4 {
  415. views.backgroundColor = UIColor.init(hexString: "519576")
  416. views.isHidden = false
  417. status = 4
  418. titleStatusLabel.text = "Transaksi Selesai"
  419. statusTrxLabel.textColor = UIColor.green
  420. if let viewWithTag = self.navigationController?.view.viewWithTag(1) {
  421. viewWithTag.removeFromSuperview()
  422. }
  423.  
  424. }
  425. if(UserDefaults.standard.isVendor() == true){
  426. statusLabel.text = checkStatusVendor(contract: contract, reject: reject, lastbit: lastBit, end_rent: endRent)
  427.  
  428. }else{
  429. statusLabel.text = checkStatus(contract: contract, reject: reject, lastbit: lastBit, end_rent: endRent)
  430. }
  431.  
  432. statusTrxLabel.text = checkStatus(contract: contract, reject: reject, lastbit: lastBit, end_rent: endRent)
  433. avatar.kf.setImage(with: URL(string : "\(checkNull(sender: viewModel.data.warehouseImageURL))"), placeholder:UIImage(named: "ic_placeholder"), options: nil)
  434. avatar2.kf.setImage(with: URL(string : "\(checkNull(sender: viewModel.data.warehouseImageURL))"), placeholder:UIImage(named: "ic_placeholder_gudang"), options: nil)
  435. dataFacility = viewModel.data.facilities!
  436. if dataFacility.count>0 {
  437. placeholdeEmpty.isHidden = true
  438. }
  439. dataQuotation = viewModel.data.quotations!
  440. data = viewModel.data
  441. CollectionView.reloadData()
  442. tableView.reloadData()
  443. }
  444.  
  445. @objc func actionKontrak(_ sender:UIButton){
  446. removeView()
  447. if(UserDefaults.standard.isVendor() == false){
  448. self.activity.startAnimating()
  449. Alamofire.request(apiCancel+"/\(id)/accept", method: .put, encoding: JSONEncoding.default, headers: APIManager.headersJwt()).responseJSON { response in
  450. if response.response?.statusCode == 200 || response.response?.statusCode == 201 {
  451. self.activityIndicator.startAnimating(string: "Transaksi Diprosess")
  452. self.activity.stopAnimating()
  453. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.0) {
  454. self.activityIndicator.stopAnimating()
  455. self.navigationController?.popViewController(animated: true)
  456. }
  457. }
  458.  
  459. if response.response?.statusCode == 400 || response.response?.statusCode == 401 || response.response?.statusCode == 422 || response.response?.statusCode == 500 {
  460. self.activityIndicator.stopAnimating()
  461. self.activity.stopAnimating()
  462. Toast(text: "Terjadi sesuatu server", delay: 0, duration: 1).show()
  463. }
  464. }
  465.  
  466. }else{
  467. router?.routeToKontrak(id:(router?.dataStore!.id)!,status: isStatus)
  468. }
  469.  
  470.  
  471. }
  472.  
  473. @objc func actionTolak(_ sender:UIButton){ bottomsheetTolak() }
  474.  
  475. @objc func bottomsheetTolak(){
  476. let storyboard = UIStoryboard(name: "BottomSheetTolak", bundle: nil)
  477. let destinationVc = storyboard.instantiateViewController(withIdentifier: "BottomSheetTolakViewController") as! BottomSheetTolakViewController
  478. destinationVc.id = (router?.dataStore!.id)!
  479. destinationVc.isDetail = isDetail
  480. destinationVc.strDesc = strDesc
  481. destinationVc.strAlasan = strAlasan
  482. let sheetController = SheetViewController(controller: destinationVc, sizes: [.fixed(CGFloat(heightBottom))])
  483. destinationVc.delegateDone = self
  484. sheetController.extendBackgroundBehindHandle = true
  485. self.present(sheetController, animated: true, completion: { () in
  486.  
  487. })
  488. }
  489. func setCallBack() {
  490. self.activityIndicator.startAnimating(string: "Transaksi DiTolak")
  491. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.0) {
  492. self.activityIndicator.stopAnimating()
  493. self.navigationController?.popViewController(animated: true)
  494. }
  495. }
  496.  
  497.  
  498. @IBAction func actionHistoryPenawaran(_ sender:UIButton){
  499. router?.routeToPenawaran(id: checkNull(sender: router?.dataStore?.id))
  500. }
  501.  
  502. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
  503. {
  504. return self.dataFacility.count
  505. }
  506.  
  507. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
  508. {
  509. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellReuseIdentifier, for: indexPath) as! FeatureCell
  510. cell.titleLabel.text = dataFacility[indexPath.row].name
  511.  
  512. return cell
  513. }
  514.  
  515. // func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  516. // return CGSize(width: self.tableView.frame.width / 5, height: 40)
  517. // }
  518.  
  519. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  520. let label = UILabel(frame: CGRect.zero)
  521. label.text = dataFacility[indexPath.row].name
  522. label.sizeToFit()
  523. return CGSize(width: label.frame.width, height: 32)
  524. }
  525. // dyanmic height
  526. // func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  527. // let label = UILabel(frame: CGRect.zero)
  528. // label.text = textArray[indexPath.item]
  529. // label.sizeToFit()
  530. // return CGSize(width: 120, height: label.frame.height)
  531. // }
  532.  
  533. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
  534. return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  535. }
  536.  
  537. func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize {
  538. let height = CollectionView.contentSize.height
  539. return CGSize(width: targetSize.width, height: height)
  540. }
  541.  
  542.  
  543. private struct Section
  544. {
  545. static let Static = 1
  546. static let Static_two = 2
  547. static let Static_tree = 3
  548. static let Static_four = 4
  549. static let Static_five = 5
  550. static let Static_six = 6
  551. static let Static_seven = 7
  552.  
  553. }
  554.  
  555. private struct CellId
  556. {
  557. static let Dynamic = "cell"
  558.  
  559.  
  560. }
  561.  
  562. func tableView(_ tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool
  563. {
  564. return false
  565. }
  566.  
  567. // ----------
  568.  
  569. func tableView(_ tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool
  570. {
  571. return false
  572. }
  573.  
  574. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
  575. {
  576. if section == Section.Static_tree {
  577. // count of your data source items
  578. return dataQuotation.count == 0 ? 0 : 1
  579. }
  580.  
  581. return super.tableView(tableView, numberOfRowsInSection: section)
  582. }
  583.  
  584. override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  585. if indexPath.section == Section.Static && UserDefaults.standard.isVendor(){
  586. // custom or calculating height for dynamic cell
  587. return 270
  588. }
  589.  
  590. if indexPath.section == 0 && indexPath.row == 0 && !UserDefaults.standard.isVendor(){
  591. // custom or calculating height for dynamic cell
  592. return 270
  593.  
  594. }
  595.  
  596. if indexPath.section == 0 && indexPath.row == 1 && !UserDefaults.standard.isVendor(){
  597. // custom or calculating height for dynamic cell
  598. return 80
  599. }
  600.  
  601.  
  602. if indexPath.section == 0 && indexPath.row == 2 && !UserDefaults.standard.isVendor(){
  603. // custom or calculating height for dynamic cell
  604. return 66
  605. }
  606.  
  607. if indexPath.section == 0 && indexPath.row == 3 && !UserDefaults.standard.isVendor(){
  608. // custom or calculating height for dynamic cell
  609. return 66
  610. }
  611.  
  612.  
  613.  
  614. if indexPath.section == Section.Static_two{
  615. // custom or calculating height for dynamic cell
  616. return 44
  617. }
  618.  
  619.  
  620. if indexPath.section == Section.Static_five && dataQuotation.count == 0 {
  621. // custom or calculating height for dynamic cell
  622. return 150
  623. }
  624.  
  625. if indexPath.section == Section.Static_tree {
  626. // custom or calculating height for dynamic cell
  627. var paymentData = 30*dataQuotation[indexPath.row].paymentSchedules!.count
  628. return CGFloat(320+paymentData)
  629. }
  630.  
  631.  
  632. if indexPath.section == Section.Static_six && status == 1 && UserDefaults.standard.isVendor(){
  633. // custom or calculating height for dynamic cell
  634. return 44
  635. }
  636.  
  637. if indexPath.section == Section.Static_four && isHistory == true && dataQuotation.count != 0 {
  638. // custom or calculating height for dynamic cell
  639. return 60
  640. }
  641.  
  642.  
  643. if UserDefaults.standard.isVendor() && indexPath.section == Section.Static_seven{
  644. // custom or calculating height for dynamic cell
  645. return 200
  646. }
  647.  
  648. return 0
  649. }
  650.  
  651. // ---------
  652. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  653. if indexPath.section == Section.Static_tree
  654. {
  655. var cell = tableView.dequeueReusableCell(withIdentifier: CellId.Dynamic)
  656.  
  657. if cell == nil {
  658. // create dynamic cell from xib or with default style
  659. cell = UITableViewCell(style: .value1, reuseIdentifier: CellId.Dynamic)
  660. }
  661.  
  662. // customize your dynamic cell
  663. if let cell = cell {
  664.  
  665. var cell = tableView.dequeueReusableCell(withIdentifier: CellId.Dynamic) as! TransaksiQuotationCell;
  666. if (cell == nil)
  667. {
  668. //Functionality goes here when it not needed to happen every time.
  669. }
  670.  
  671. //cell.capasitasLabel.text = "\(checkNullInt(sender: data!.warehouseCapacity)) m2"
  672.  
  673. let startRent = checkNullTypeInt(sender: "\(dataQuotation.first?.startRent)")
  674. let endRent = checkNullTypeInt(sender: "\(dataQuotation.first?.endRent)")
  675. cell.mulaisewaLabel.text = convertStringUNIXDateIndo(data: startRent)
  676. cell.selesaiLabel.text = convertStringUNIXDateIndo(data: endRent)
  677. cell.kebutuhanLabel.text = "\(checkNullInt(sender: data.warehouseCapacity))"
  678. cell.storageLabel.text = "Rp. \(checkNullInt(sender: dataQuotation.first?.quotationPrice))"
  679. cell.totalLabel.text = "Rp.\(checkNullInt(sender: dataQuotation.first?.totalQuotationPrice))"
  680. cell.descLabel.text = checkNull(sender: dataQuotation.first?.remarks)
  681. cell.data = dataQuotation[indexPath.row].paymentSchedules!
  682. cell.collectionView.reloadData()
  683. cell.frame = tableView.bounds
  684. cell.layoutIfNeeded()
  685. return cell
  686. }
  687. }
  688.  
  689. return super.tableView(tableView, cellForRowAt: indexPath as IndexPath)
  690. }
  691.  
  692.  
  693. override func viewWillAppear(_ animated: Bool) {
  694. self.tableView.layoutSubviews()
  695. }
  696.  
  697.  
  698. override func tableView(_ tableView: UITableView, indentationLevelForRowAt indexPath: IndexPath) -> Int {
  699. if indexPath.section == Section.Static {
  700. // use only this indentation level for dynamic cell
  701. return super.tableView (tableView, indentationLevelForRowAt: NSIndexPath(row: 0, section: Section.Static) as IndexPath)
  702. }
  703.  
  704. if indexPath.section == Section.Static_two {
  705. // use only this indentation level for dynamic cell
  706. return super.tableView (tableView, indentationLevelForRowAt: NSIndexPath(row: 0, section: Section.Static_two) as IndexPath)
  707. }
  708.  
  709.  
  710. if indexPath.section == Section.Static_tree {
  711. // use only this indentation level for dynamic cell
  712. return super.tableView (tableView, indentationLevelForRowAt: NSIndexPath(row: 0, section: Section.Static_tree) as IndexPath)
  713. }
  714.  
  715. if indexPath.section == Section.Static_four {
  716. // use only this indentation level for dynamic cell
  717. return super.tableView (tableView, indentationLevelForRowAt: NSIndexPath(row: 0, section: Section.Static_four) as IndexPath)
  718. }
  719.  
  720. if indexPath.section == Section.Static_five {
  721. // use only this indentation level for dynamic cell
  722. return super.tableView (tableView, indentationLevelForRowAt: NSIndexPath(row: 0, section: Section.Static_five) as IndexPath)
  723. }
  724.  
  725.  
  726. if indexPath.section == Section.Static_seven {
  727. // use only this indentation level for dynamic cell
  728. return super.tableView (tableView, indentationLevelForRowAt: NSIndexPath(row: 0, section: Section.Static_seven) as IndexPath)
  729. }
  730.  
  731. return super.tableView(tableView, indentationLevelForRowAt: indexPath)
  732. }
  733. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement