Old UniVate Website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TimesharesImport.php 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace App\Imports;
  3. use App\Timeshare;
  4. use Auth;
  5. use Maatwebsite\Excel\Concerns\ToModel;
  6. use Maatwebsite\Excel\Concerns\WithHeadingRow;
  7. use Illuminate\Support\Facades\DB;
  8. class TimesharesImport implements ToModel, WithHeadingRow
  9. {
  10. /**
  11. * @param array $row
  12. *
  13. * @return Timeshare|null
  14. */
  15. public $count = 0;
  16. public function model(array $row)
  17. {
  18. if(Auth::user()->role=='user' && Auth::user()->agency==NULL)//private seller/buyer
  19. {
  20. $user = DB::table('users')
  21. ->where('id','=',Auth::user()->id)
  22. ->first();
  23. ++$this->count;
  24. return new Timeshare([
  25. 'resort' => $row['Resort'],
  26. 'module' => $row['Module'],
  27. 'week' => $row['Week'],
  28. 'bedrooms' => $row['Bedrooms'],
  29. 'season' => $row['Season'],
  30. 'region' => $row['Region'],
  31. 'price' => $row['Price'],
  32. 'sleeps' => $row['Sleeps'],
  33. 'unit' => $row['Unit'],
  34. 'fromDate' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['Arrival']),
  35. 'toDate' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['Departure']),
  36. 'levy' => $row['Levy'],
  37. 'setPrice' => 0,
  38. 'offerPending' => 0,
  39. 'sold' => 0,
  40. 'published' => 0,
  41. 'owner' => $row['Owner'],
  42. 'spacebankOwner' => NULL,
  43. 'other' => NULL,
  44. 'agency' => 'N/A',
  45. 'statusDate' => NULL,
  46. 'listingFee' => NULL,
  47. 'status' => 'For Sale',
  48. 'names'=> $user->name,
  49. 'phone' => $user->phone,
  50. 'mobile' => $user->mobile,
  51. 'email' => $user->email,
  52. 'paid' => 'no',
  53. 'spacebankedyear' => 'no',
  54. 'propertType' => 'Timeshare',
  55. 'agent'=> 'N/A',
  56. 'pre_selected' => 0
  57. ]);
  58. }
  59. elseif(Auth::user()->role=='user' && Auth::user()->agency!=NULL) //Agents who are under an agency
  60. {
  61. $user = DB::table('users')
  62. ->where('id','=',Auth::user()->id)
  63. ->first();
  64. ++$this->count;
  65. return new Timeshare([
  66. 'resort' => $row['resort'],
  67. 'module' => $row['module'],
  68. 'week' => $row['week'],
  69. 'bedrooms' => $row['bedrooms'],
  70. 'season' => $row['season'],
  71. 'region' => $row['region'],
  72. 'price' => $row['price'],
  73. 'sleeps' => $row['sleeps'],
  74. 'unit' => $row['unit'],
  75. 'fromDate' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['arrival']),
  76. 'toDate' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['departure']),
  77. 'levy' => $row['levy'],
  78. 'setPrice' => 0,
  79. 'offerPending' => 0,
  80. 'sold' => 0,
  81. 'published' => 0,
  82. 'owner' => $row['owner'],
  83. 'spacebankOwner' => NULL,
  84. 'other' => NULL,
  85. 'agency' => $user->agency,
  86. 'statusDate' => NULL,
  87. 'listingFee' => NULL,
  88. 'status' => 'For Sale',
  89. 'names'=> $user->name,
  90. 'phone' => $user->phone,
  91. 'mobile' => $user->mobile,
  92. 'email' => $user->email,
  93. 'paid' => 'no',
  94. 'spacebankedyear' => 'no',
  95. 'propertType' => 'Timeshare',
  96. 'agent'=> $user->name,
  97. 'pre_selected' => 0
  98. ]);
  99. }
  100. elseif(Auth::user()->role=='agency admin') //Agency administrator
  101. {
  102. $user = DB::table('users')
  103. ->where('id','=',Auth::user()->id)
  104. ->first();
  105. ++$this->count;
  106. return new Timeshare([
  107. 'resort' => $row['resort'],
  108. 'module' => $row['module'],
  109. 'week' => $row['week'],
  110. 'bedrooms' => $row['bedrooms'],
  111. 'season' => $row['season'],
  112. 'region' => $row['region'],
  113. 'price' => $row['price'],
  114. 'sleeps' => $row['sleeps'],
  115. 'unit' => $row['unit'],
  116. 'fromDate' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['arrival']),
  117. 'toDate' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['departure']),
  118. 'levy' => $row['levy'],
  119. 'setPrice' => 0,
  120. 'offerPending' => 0,
  121. 'sold' => 0,
  122. 'published' => 0,
  123. 'owner' => $row['owner'],
  124. 'spacebankOwner' => NULL,
  125. 'other' => NULL,
  126. 'agency' => $user->agency,
  127. 'statusDate' => NULL,
  128. 'listingFee' => NULL,
  129. 'status' => 'For Sale',
  130. 'names'=> $user->name,
  131. 'phone' => $user->phone,
  132. 'mobile' => $user->mobile,
  133. 'email' => $user->email,
  134. 'paid' => 'no',
  135. 'spacebankedyear' => 'no',
  136. 'propertType' => 'Timeshare',
  137. 'agent'=> $user->name,
  138. 'pre_selected' => 0
  139. ]);
  140. }
  141. elseif(Auth::user()->role=='admin') //admin
  142. {
  143. return new Timeshare([
  144. 'resort' => $row['resort'],
  145. 'module' => $row['module'],
  146. 'week' => $row['week'],
  147. 'bedrooms' => $row['bedrooms'],
  148. 'season' => $row['season'],
  149. 'region' => $row['region'],
  150. 'price' => $row['price'],
  151. 'sleeps' => $row['sleeps'],
  152. 'unit' => $row['unit'],
  153. 'fromDate' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['arrival_date']),
  154. 'toDate' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['departure_date']),
  155. 'levy' => $row['levy'],
  156. 'setPrice' => 0,
  157. 'offerPending' => 0,
  158. 'sold' => 0,
  159. 'published' => 0,
  160. 'owner' => 'UB',
  161. 'spacebankOwner' => NULL,
  162. 'other' => NULL,
  163. 'agency' => NULL,
  164. 'statusDate' => NULL,
  165. 'listingFee' => NULL,
  166. 'status' => 'For Sale',
  167. 'names'=> 'Delia',
  168. 'phone' => '012 700 4567',
  169. 'mobile' => '083 784 5554',
  170. 'email' => 'info@univateproperties.co.za',
  171. 'paid' => 'no',
  172. 'spacebankedyear' => 'no',
  173. 'propertType' => 'Timeshare',
  174. 'agent'=> 'None',
  175. 'pre_selected' => 0
  176. ]);
  177. }
  178. }
  179. }