src/Domain/Whater/Model/WhaterOrganization.php line 29

Open in your IDE?
  1. <?php
  2. namespace Whater\Domain\Whater\Model;
  3. use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;
  4. use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Ramsey\Uuid\Uuid;
  8. use Spatie\OpeningHours\OpeningHours;
  9. use Whater\Domain\Common\Exception\InvalidUUIDException;
  10. use Whater\Domain\Product\Model\Product;
  11. use Whater\Domain\User\Exception\IllegalPermissionObjectException;
  12. use Whater\Domain\User\Exception\InvalidPermissionException;
  13. use Whater\Domain\User\Model\OrganizationLicense;
  14. use Whater\Domain\User\Model\UserPermission;
  15. use Whater\Domain\Whater\Exception\InvalidStripeStatusException;
  16. use Whater\Domain\Zones\Model\Country;
  17. use Whater\Domain\Zones\Model\CountryArea;
  18. use Whater\Domain\Zones\Model\Town;
  19. use Whater\Domain\Zones\Model\TownLocation;
  20. use Whater\Domain\Zones\Model\Ubication;
  21. /**
  22. * Class WhaterOrganization
  23. *
  24. * @package Whater\Domain\Whater\Model
  25. */
  26. class WhaterOrganization implements ContainsRecordedEvents
  27. {
  28. use EventRecorderCapabilities;
  29. const MAN_ACT_REGIONAL_GOVERMENT = "regional_goberment";
  30. const MAN_ACT_LOCAL_GOVERMENT = "local_goberment";
  31. const MAN_ACT_COMUNITY = "comunity";
  32. const MAN_ACT_CONSORTIUM = "consortium";
  33. const MAN_ACT_MIX_MANAGEMENT = "mix_management";
  34. const MAN_ACT_NPO = "npo";
  35. const MAN_ACT_PROVIDER = "provider";
  36. const MAN_ACT_INDUSTRY = "industry";
  37. const MAN_ACT_OTHER = "other";
  38. const REGION_SCOPE_INTERNATIONAL = "international";
  39. const REGION_SCOPE_NATIONAL = "national";
  40. const REGION_SCOPE_REGIONAL = "regional";
  41. const REGION_SCOPE_LOCAL = "local";
  42. const SPECIALIZATION_IN_WATER_VERY_HIGH = "very_high";
  43. const SPECIALIZATION_IN_WATER_HIGH = "high";
  44. const SPECIALIZATION_IN_WATER_MEDIUM = "medium";
  45. const SPECIALIZATION_IN_WATER_LOW = "low";
  46. const NUM_CUSTOMER_LESS_100 = "less_100";
  47. const NUM_CUSTOMER_LESS_500 = "less_500";
  48. const NUM_CUSTOMER_LESS_1000 = "less_1000";
  49. const NUM_CUSTOMER_LESS_5000 = "less_5000";
  50. const NUM_CUSTOMER_LESS_10000 = "less_10000";
  51. const NUM_CUSTOMER_LESS_100000 = "less_100000";
  52. const NUM_CUSTOMER_LESS_1000000 = "less_1000000";
  53. const NUM_CUSTOMER_MORE_1000000 = "more_1000000";
  54. const NUM_DELEGATIONS_LESS_5 = "less_5";
  55. const NUM_DELEGATIONS_LESS_25 = "less_25";
  56. const NUM_DELEGATIONS_LESS_100 = "less_100";
  57. const NUM_DELEGATIONS_LESS_500 = "less_500";
  58. const NUM_DELEGATIONS_MORE_500 = "more_500";
  59. const STRIPE_CONNECT_STATUS_PENDING = "SC_PENDING";
  60. const STRIPE_CONNECT_STATUS_CONNECTED = "SC_CONNECTED";
  61. const STRIPE_CONNECT_STATUS_DISCONNECTED = "SC_DISCONNECTED";
  62. /**
  63. * @var string
  64. */
  65. private $uuid;
  66. /**
  67. * @var string
  68. */
  69. private $slug;
  70. /**
  71. * @var string
  72. */
  73. private $name;
  74. /**
  75. * @var string
  76. */
  77. private $description;
  78. /**
  79. * @var string
  80. */
  81. private $details;
  82. /**
  83. * @var string
  84. */
  85. private $urlWeb;
  86. /**
  87. * @var Collection
  88. */
  89. private $organizationUsers;
  90. /**
  91. * @var Collection
  92. */
  93. private $referralUsers;
  94. /**
  95. * @var \DateTime
  96. */
  97. private $createdAt;
  98. /**
  99. * @var \DateTime
  100. */
  101. private $updatedAt;
  102. /**
  103. * @var string
  104. */
  105. private $publicName;
  106. /**
  107. * @var string
  108. */
  109. private $contactPerson;
  110. /**
  111. * @var string
  112. */
  113. private $contactEmail;
  114. /**
  115. * @var string
  116. */
  117. private $contactPhone;
  118. /**
  119. * @var string
  120. */
  121. private $fiscalName;
  122. /**
  123. * @var string
  124. */
  125. private $fiscalAddress;
  126. /**
  127. * @var string
  128. */
  129. private $marketplacePostalCode;
  130. /**
  131. * @var string
  132. */
  133. private $marketplaceAddress;
  134. /**
  135. * @var string
  136. */
  137. private $marketplaceCountry;
  138. /**
  139. * @var string
  140. */
  141. private $professionalActivity;
  142. /**
  143. * @var string
  144. */
  145. private $regionScope;
  146. /**
  147. * @var string
  148. */
  149. private $specializationInWater;
  150. /**
  151. * @var string
  152. */
  153. private $numberOfDelegations;
  154. /**
  155. * @var string
  156. */
  157. private $numberOfCustomers;
  158. /**
  159. * @var string
  160. */
  161. private $facebook = null;
  162. /**
  163. * @var string
  164. */
  165. private $instagram = null;
  166. /**
  167. * @var string
  168. */
  169. private $linkedin = null;
  170. /**
  171. * @var bool
  172. */
  173. private $isPublicOrganization = null;
  174. /**
  175. * @var bool
  176. */
  177. private $isManufracturer = null;
  178. /**
  179. * @var string
  180. */
  181. private $organizationType = null;
  182. /**
  183. * @var array
  184. */
  185. private $openingHours = null;
  186. /**
  187. * @var Country
  188. */
  189. private $country;
  190. /**
  191. * @var Collection
  192. */
  193. private $organizationLicenses;
  194. /**
  195. * @var Collection
  196. */
  197. private $products;
  198. /**
  199. * @var Collection
  200. */
  201. private $whaterOrganizationCodes;
  202. /**
  203. * @var string
  204. */
  205. private $urlAnalyticals;
  206. /**
  207. * @var Collection
  208. */
  209. private $distributionNetworksGovernment;
  210. /**
  211. * @var Collection
  212. */
  213. private $distributionNetworksOperator;
  214. /**
  215. * @var Collection
  216. */
  217. private $distributionNetworksCorporative;
  218. /**
  219. * @var Collection
  220. */
  221. private $distributionNetworksUbication;
  222. /**
  223. * @var Collection
  224. */
  225. private $whaterPointsCorporative;
  226. /**
  227. * @var Collection
  228. */
  229. private $whaterPointsUbication;
  230. /**
  231. * @var Collection
  232. */
  233. private $analyticals;
  234. /**
  235. * @var Collection
  236. */
  237. private $buyerWalletOperations;
  238. /**
  239. * @var Collection
  240. */
  241. private $sellerWalletOperations;
  242. /**
  243. * @var float
  244. */
  245. private $currentBalance;
  246. /**
  247. * @var Collection
  248. */
  249. private $walletLiquidationRequests;
  250. /**
  251. * @var string
  252. */
  253. private $bankAccountOwnerName;
  254. /**
  255. * @var string
  256. */
  257. private $bankAccountIbanNumber;
  258. /**
  259. * @var string
  260. */
  261. private $bankAccountBicSwiftNumber;
  262. /**
  263. * @var string
  264. */
  265. private $stripeExpressAccountId;
  266. /**
  267. * @var string
  268. */
  269. private $stripeExpressAccountStatus;
  270. /**
  271. * @var string
  272. */
  273. private $referralCode;
  274. /**
  275. * @var Collection
  276. */
  277. private $ubications;
  278. /**
  279. * @var Collection
  280. */
  281. private $towns;
  282. /**
  283. * @var Collection
  284. */
  285. private $townLocations;
  286. /**
  287. * @var Collection
  288. */
  289. private $whatercoinsCoupons;
  290. /**
  291. * @param string $whaterOrganizationId
  292. * @param string $name
  293. * @param string $details
  294. * @param string $slug
  295. * @param string $urlWeb
  296. */
  297. public function __construct(
  298. string $whaterOrganizationId = null,
  299. string $name,
  300. Country $country,
  301. string $details = null,
  302. string $slug = null,
  303. string $urlWeb = null
  304. ) {
  305. try {
  306. $this->uuid = Uuid::fromString($whaterOrganizationId ?: Uuid::uuid4())->toString();
  307. } catch (\InvalidArgumentException $e) {
  308. throw new InvalidUUIDException();
  309. }
  310. $this->name = $name;
  311. $this->publicName = $name;
  312. $this->country = $country;
  313. $this->slug = $slug;
  314. $this->details = $details;
  315. $this->whaterOrganizationCodes = new ArrayCollection();
  316. $this->organizationUsers = new ArrayCollection();
  317. $this->referralUsers = new ArrayCollection();
  318. $this->organizationLicenses = new ArrayCollection();
  319. $this->referralCode = Uuid::uuid4()->toString();
  320. $this->distributionNetworksGovernment = new ArrayCollection();
  321. $this->distributionNetworksOperator = new ArrayCollection();
  322. $this->distributionNetworksCorporative = new ArrayCollection();
  323. $this->distributionNetworksUbication = new ArrayCollection();
  324. $this->whaterPointsCorporative = new ArrayCollection();
  325. $this->whaterPointsUbication = new ArrayCollection();
  326. $this->whatercoinsCoupons = new ArrayCollection();
  327. $this->analyticals = new ArrayCollection();
  328. $this->products = new ArrayCollection();
  329. $this->buyerWalletOperations = new ArrayCollection();
  330. $this->sellerWalletOperations = new ArrayCollection();
  331. $this->ubications = new ArrayCollection();
  332. $this->towns = new ArrayCollection();
  333. $this->townLocations = new ArrayCollection();
  334. $this->walletLiquidationRequests = new ArrayCollection();
  335. $this->currentBalance = 0;
  336. $this->urlWeb = $urlWeb;
  337. $this->isPublicOrganization = false;
  338. $this->isManufracturer = false;
  339. $this->stripeExpressAccountStatus = WhaterOrganization::STRIPE_CONNECT_STATUS_PENDING;
  340. $this->createdAt = new \DateTime();
  341. $this->updatedAt = new \DateTime();
  342. }
  343. public function updateOrganization(
  344. string $name,
  345. string $details = null,
  346. string $urlWeb = null,
  347. string $slug = null,
  348. string $publicName = null,
  349. string $contactPerson = null,
  350. string $contactEmail = null,
  351. string $contactPhone = null,
  352. bool $isPublicOrganization = null,
  353. bool $isManufracturer = null,
  354. string $fiscalName = null,
  355. string $fiscalAddress = null,
  356. string $professionalActivity = null,
  357. string $regionScope = null,
  358. string $specializationInWater = null,
  359. string $numberOfDelegations = null,
  360. string $numberOfCustomers = null,
  361. string $facebook = null,
  362. string $instagram = null,
  363. string $linkedin = null
  364. ) {
  365. $this->name = $name;
  366. $this->slug = $slug;
  367. $this->details = $details;
  368. $this->urlWeb = $urlWeb;
  369. $this->publicName = $publicName;
  370. $this->contactPerson = $contactPerson;
  371. $this->contactEmail = $contactEmail;
  372. $this->contactPhone = $contactPhone;
  373. $this->isPublicOrganization = $isPublicOrganization;
  374. $this->isManufracturer = $isManufracturer;
  375. $this->fiscalName = $fiscalName;
  376. $this->fiscalAddress = $fiscalAddress;
  377. $this->professionalActivity = $professionalActivity;
  378. $this->regionScope = $regionScope;
  379. $this->specializationInWater = $specializationInWater;
  380. $this->numberOfDelegations = $numberOfDelegations;
  381. $this->numberOfCustomers = $numberOfCustomers;
  382. $this->facebook = $facebook;
  383. $this->instagram = $instagram;
  384. $this->linkedin = $linkedin;
  385. $this->updatedAt = new \DateTime();
  386. return $this;
  387. }
  388. public function updateBankAccount(
  389. string $bankAccountOwnerName = null,
  390. string $bankAccountIbanNumber = null,
  391. string $bankAccountBicSwiftNumber = null
  392. ) {
  393. $this->bankAccountOwnerName = $bankAccountOwnerName;
  394. $this->bankAccountIbanNumber = $bankAccountIbanNumber;
  395. $this->bankAccountBicSwiftNumber = $bankAccountBicSwiftNumber;
  396. }
  397. public function updateMarketplaceAddress(
  398. string $marketplaceCountry = null,
  399. string $marketplacePostalCode = null,
  400. string $marketplaceAddress = null
  401. ) {
  402. $this->marketplaceCountry = $marketplaceCountry;
  403. $this->marketplacePostalCode = $marketplacePostalCode;
  404. $this->marketplaceAddress = $marketplaceAddress;
  405. }
  406. public function updateStripeExpressAccount(
  407. string $stripeExpressAccountId = null,
  408. string $stripeExpressAccountStatus = null
  409. ) {
  410. if ($stripeExpressAccountStatus != null) {
  411. $this->stripeExpressAccountId = $stripeExpressAccountId;
  412. switch ($stripeExpressAccountStatus) {
  413. case WhaterOrganization::STRIPE_CONNECT_STATUS_CONNECTED:
  414. case WhaterOrganization::STRIPE_CONNECT_STATUS_PENDING:
  415. case WhaterOrganization::STRIPE_CONNECT_STATUS_DISCONNECTED:
  416. $this->stripeExpressAccountStatus = $stripeExpressAccountStatus;
  417. break;
  418. default:
  419. throw new InvalidStripeStatusException();
  420. }
  421. } else {
  422. $this->stripeExpressAccountId = null;
  423. $this->stripeExpressAccountStatus = null;
  424. }
  425. }
  426. private function updateOpeningHours(OpeningHours $openingHours)
  427. {
  428. $this->openingHours = $openingHours->asStructuredData();
  429. }
  430. private function openingHours(): OpeningHours
  431. {
  432. return OpeningHours::create($this->openingHours);
  433. }
  434. public function activeLicenses()
  435. {
  436. $activeLicences = [];
  437. foreach ($this->organizationLicenses() as $organizationLicense) {
  438. if ($organizationLicense->isActive()) {
  439. array_push($activeLicences, $organizationLicense);
  440. }
  441. }
  442. return $activeLicences;
  443. }
  444. public function hasActiveLicense(string $licenseScope, string $licenseType = null)
  445. {
  446. foreach ($this->activeLicenses() as $activeLicense) {
  447. if ($activeLicense->licenseScope() == $licenseScope) {
  448. if ($licenseType == null) {
  449. return true;
  450. } else {
  451. if ($activeLicense->licenseType() == $licenseType) {
  452. return true;
  453. }
  454. }
  455. }
  456. }
  457. return false;
  458. }
  459. public function checkPermission(string $permissionCode, $object = null)
  460. {
  461. switch ($permissionCode) {
  462. case UserPermission::PERMISSION_CREATE_PRODUCT:
  463. if ($object != null) {
  464. throw new IllegalPermissionObjectException();
  465. }
  466. if ($this->hasActiveLicense(OrganizationLicense::LICENSE_SCOPE_SELLERS)) {
  467. return true;
  468. }
  469. break;
  470. case UserPermission::PERMISSION_EDIT_PRODUCT:
  471. if ($object == null || !($object instanceof Product)) {
  472. throw new IllegalPermissionObjectException();
  473. }
  474. if ($this->hasActiveLicense(OrganizationLicense::LICENSE_SCOPE_SELLERS)) {
  475. return true;
  476. }
  477. break;
  478. case UserPermission::PERMISSION_EDIT_WHATER_POINT:
  479. if ($object == null || !($object instanceof WhaterPoint)) {
  480. throw new IllegalPermissionObjectException();
  481. }
  482. /** @var WhaterPoint $whaterpoint */
  483. $whaterpoint = $object;
  484. if (
  485. $whaterpoint->responsableOrganizationUbication() != null &&
  486. $whaterpoint->responsableOrganizationUbication()->equals($this)
  487. ) {
  488. return true;
  489. }
  490. if ($whaterpoint->distributionNetwork() != null) {
  491. $distributionNetwork = $whaterpoint->distributionNetwork();
  492. if (
  493. ($distributionNetwork->responsableOrganizationUbication() != null && $distributionNetwork->responsableOrganizationUbication()->equals($this)) ||
  494. ($distributionNetwork->responsableOrganizationOperator() != null && $distributionNetwork->responsableOrganizationOperator()->equals($this)) ||
  495. ($distributionNetwork->responsableOrganizationCorporative() != null && $distributionNetwork->responsableOrganizationCorporative()->equals($this)) ||
  496. ($distributionNetwork->responsableOrganizationGovernment() != null && $distributionNetwork->responsableOrganizationGovernment()->equals($this))
  497. ) {
  498. return true;
  499. }
  500. }
  501. break;
  502. case UserPermission::PERMISSION_CREATE_ANALYTICAL:
  503. throw new \Exception($permissionCode . 'need code implementation!');
  504. break;
  505. case UserPermission::PERMISSION_EDIT_ANALYTICAL:
  506. throw new \Exception($permissionCode . 'need code implementation!');
  507. break;
  508. case UserPermission::PERMISSION_EDIT_WHATER_ORGANIZATION:
  509. throw new \Exception($permissionCode . 'need code implementation!');
  510. break;
  511. case UserPermission::PERMISSION_CREATE_DISTRIBUTION_NETWORK:
  512. throw new \Exception($permissionCode . 'need code implementation!');
  513. break;
  514. case UserPermission::PERMISSION_EDIT_DISTRIBUTION_NETWORK:
  515. if ($object == null || !($object instanceof DistributionNetwork)) {
  516. throw new IllegalPermissionObjectException();
  517. }
  518. /** @var DistributionNetwork $distributionNetwork */
  519. $distributionNetwork = $object;
  520. // check ownership
  521. if (
  522. ($distributionNetwork->responsableOrganizationUbication() != null && $distributionNetwork->responsableOrganizationUbication()->equals($this)) ||
  523. ($distributionNetwork->responsableOrganizationOperator() != null && $distributionNetwork->responsableOrganizationOperator()->equals($this)) ||
  524. ($distributionNetwork->responsableOrganizationCorporative() != null && $distributionNetwork->responsableOrganizationCorporative()->equals($this)) ||
  525. ($distributionNetwork->responsableOrganizationGovernment() != null && $distributionNetwork->responsableOrganizationGovernment()->equals($this))
  526. ) {
  527. return true;
  528. }
  529. break;
  530. case UserPermission::PERMISSION_CREATE_WHATER_DEVICE:
  531. throw new \Exception($permissionCode . 'need code implementation!');
  532. break;
  533. case UserPermission::PERMISSION_EDIT_WHATER_DEVICE:
  534. throw new \Exception($permissionCode . 'need code implementation!');
  535. break;
  536. case UserPermission::PERMISSION_EDIT_COUNTRY:
  537. throw new \Exception($permissionCode . 'need code implementation!');
  538. break;
  539. case UserPermission::PERMISSION_CREATE_COUNTRY_AREA:
  540. throw new \Exception($permissionCode . 'need code implementation!');
  541. break;
  542. case UserPermission::PERMISSION_EDIT_COUNTRY_AREA:
  543. if ($object == null || !($object instanceof CountryArea)) {
  544. throw new IllegalPermissionObjectException();
  545. }
  546. /** @var CountryArea $countryArea */
  547. $countryArea = $object;
  548. // check ownership (TODO)
  549. // if ($countryArea->whaterOrganization() == null || !$countryArea->whaterOrganization()->equals($this)) {
  550. // return false;
  551. // }
  552. break;
  553. case UserPermission::PERMISSION_CREATE_TOWN:
  554. throw new \Exception($permissionCode . 'need code implementation!');
  555. break;
  556. case UserPermission::PERMISSION_EDIT_TOWN:
  557. if ($object == null || !($object instanceof Town)) {
  558. throw new IllegalPermissionObjectException();
  559. }
  560. /** @var Town $town */
  561. $town = $object;
  562. // check ownership
  563. if ($town->whaterOrganization() != null && $town->whaterOrganization()->equals($this)) {
  564. return true;
  565. }
  566. // check license
  567. foreach ($this->activeLicenses() as $activeLicense) {
  568. if ($activeLicense->licenseScope() == OrganizationLicense::LICENSE_SCOPE_COUNTRIES_COUNTRY_AREAS_AGRUPATIONS) {
  569. foreach ($activeLicense->countries() as $country) {
  570. if ($town->country() != null && $town->country()->equals($country)) {
  571. return true;
  572. }
  573. }
  574. foreach ($activeLicense->countryAreas() as $countryArea) {
  575. if ($town->countryArea() != null && $town->countryArea()->equals($countryArea)) {
  576. return true;
  577. }
  578. }
  579. foreach ($activeLicense->agrupations() as $agrupation) {
  580. foreach ($agrupation->town() as $agrupationTown) {
  581. if ($town->equals($agrupationTown)) {
  582. return true;
  583. }
  584. }
  585. }
  586. } else if ($activeLicense->licenseScope() == OrganizationLicense::LICENSE_SCOPE_TOWNS) {
  587. foreach ($activeLicense->towns() as $licenseTown) {
  588. if ($town->equals($licenseTown)) {
  589. return true;
  590. }
  591. }
  592. } else if ($activeLicense->licenseScope() == OrganizationLicense::LICENSE_SCOPE_PROFESSIONALS) {
  593. foreach ($activeLicense->towns() as $licenseTown) {
  594. if ($town->equals($licenseTown)) {
  595. return true;
  596. }
  597. }
  598. }
  599. }
  600. break;
  601. case UserPermission::PERMISSION_CREATE_UBICATION:
  602. throw new \Exception($permissionCode . 'need code implementation!');
  603. break;
  604. case UserPermission::PERMISSION_EDIT_UBICATION:
  605. if ($object == null || !($object instanceof Ubication)) {
  606. throw new IllegalPermissionObjectException();
  607. }
  608. /** @var Ubication $ubication */
  609. $ubication = $object;
  610. // check ownership
  611. if ($ubication->whaterOrganization() != null && $ubication->whaterOrganization()->equals($this)) {
  612. return true;
  613. }
  614. // check license
  615. foreach ($this->activeLicenses() as $activeLicense) {
  616. if ($activeLicense->licenseScope() == OrganizationLicense::LICENSE_SCOPE_COUNTRIES_COUNTRY_AREAS_AGRUPATIONS) {
  617. foreach ($activeLicense->countries() as $country) {
  618. if ($ubication->town()->country() != null && $ubication->town()->country()->equals($country)) {
  619. return true;
  620. }
  621. }
  622. foreach ($activeLicense->countryAreas() as $countryArea) {
  623. if ($ubication->town()->countryArea() != null && $ubication->town()->countryArea()->equals($countryArea)) {
  624. return true;
  625. }
  626. }
  627. foreach ($activeLicense->agrupations() as $agrupation) {
  628. foreach ($agrupation->town() as $agrupationTown) {
  629. if ($ubication->town()->equals($agrupationTown)) {
  630. return true;
  631. }
  632. }
  633. }
  634. } else if ($activeLicense->licenseScope() == OrganizationLicense::LICENSE_SCOPE_TOWNS) {
  635. foreach ($activeLicense->towns() as $licenseTown) {
  636. if ($ubication->town()->equals($licenseTown)) {
  637. return true;
  638. }
  639. }
  640. } else if ($activeLicense->licenseScope() == OrganizationLicense::LICENSE_SCOPE_PROFESSIONALS) {
  641. foreach ($activeLicense->towns() as $licenseTown) {
  642. if ($ubication->town()->equals($licenseTown)) {
  643. return true;
  644. }
  645. }
  646. }
  647. }
  648. break;
  649. case UserPermission::PERMISSION_CREATE_TOWN_LOCATION:
  650. throw new \Exception($permissionCode . 'need code implementation!');
  651. break;
  652. case UserPermission::PERMISSION_EDIT_TOWN_LOCATION:
  653. if ($object == null || !($object instanceof TownLocation)) {
  654. throw new IllegalPermissionObjectException();
  655. }
  656. /** @var TownLocation $townLocation */
  657. $townLocation = $object;
  658. if ($townLocation->whaterOrganization() != null && $townLocation->whaterOrganization()->equals($this)) {
  659. return true;
  660. }
  661. break;
  662. case UserPermission::PERMISSION_CREATE_DISTRICT:
  663. throw new \Exception($permissionCode . 'need code implementation!');
  664. break;
  665. case UserPermission::PERMISSION_EDIT_DISTRICT:
  666. throw new \Exception($permissionCode . 'need code implementation!');
  667. break;
  668. case UserPermission::PERMISSION_CREATE_ESTABLISHMENT:
  669. throw new \Exception($permissionCode . 'need code implementation!');
  670. break;
  671. case UserPermission::PERMISSION_EDIT_ESTABLISHMENT:
  672. throw new \Exception($permissionCode . 'need code implementation!');
  673. break;
  674. default:
  675. throw new InvalidPermissionException();
  676. }
  677. return false;
  678. }
  679. /**
  680. * @return string
  681. */
  682. public function id(): string
  683. {
  684. return $this->uuid;
  685. }
  686. /**
  687. * @return string
  688. */
  689. public function name(): string
  690. {
  691. return $this->name;
  692. }
  693. /**
  694. * @return Country
  695. */
  696. public function country(): Country
  697. {
  698. return $this->country;
  699. }
  700. /**
  701. * @return string
  702. */
  703. public function slug(): string
  704. {
  705. return $this->slug;
  706. }
  707. /**
  708. * @return string
  709. */
  710. public function urlWeb(): ?string
  711. {
  712. return $this->urlWeb;
  713. }
  714. /**
  715. * @return bool
  716. */
  717. public function isPublicOrganization(): bool
  718. {
  719. return $this->isPublicOrganization;
  720. }
  721. /**
  722. * @return bool
  723. */
  724. public function isManufracturer(): bool
  725. {
  726. return $this->isManufracturer;
  727. }
  728. /**
  729. * @return Collection
  730. */
  731. public function organizationUsers(): Collection
  732. {
  733. return $this->organizationUsers;
  734. }
  735. /**
  736. * @return Collection
  737. */
  738. public function referralUsers(): Collection
  739. {
  740. return $this->referralUsers;
  741. }
  742. /**
  743. * @return Collection
  744. */
  745. public function organizationLicenses(): Collection
  746. {
  747. return $this->organizationLicenses;
  748. }
  749. /**
  750. * @return Collection
  751. */
  752. public function distributionNetworksGovernment(): Collection
  753. {
  754. return $this->distributionNetworksGovernment;
  755. }
  756. /**
  757. * @return Collection
  758. */
  759. public function distributionNetworksOperator(): Collection
  760. {
  761. return $this->distributionNetworksOperator;
  762. }
  763. /**
  764. * @return Collection
  765. */
  766. public function distributionNetworksCorporative(): Collection
  767. {
  768. return $this->distributionNetworksCorporative;
  769. }
  770. /**
  771. * @return Collection
  772. */
  773. public function distributionNetworksUbication(): Collection
  774. {
  775. return $this->distributionNetworksUbication;
  776. }
  777. /**
  778. * @return Collection
  779. */
  780. public function whaterPointsCorporative(): Collection
  781. {
  782. return $this->whaterPointsCorporative;
  783. }
  784. /**
  785. * @return Collection
  786. */
  787. public function whaterPointsUbication(): Collection
  788. {
  789. return $this->whaterPointsUbication;
  790. }
  791. /**
  792. * @return Collection
  793. */
  794. public function whatercoinsCoupons(): Collection
  795. {
  796. return $this->whatercoinsCoupons;
  797. }
  798. /**
  799. * @return Collection
  800. */
  801. public function analyticals(): Collection
  802. {
  803. return $this->analyticals;
  804. }
  805. /**
  806. * @return Collection
  807. */
  808. public function products(): Collection
  809. {
  810. return $this->products;
  811. }
  812. /**
  813. * Saldo disponible (ingresos por ventas - comisiones por ventas - pagos a cc )
  814. * @return float
  815. */
  816. public function currentBalance(): float
  817. {
  818. return $this->currentBalance;
  819. }
  820. /**
  821. * @return float
  822. * @return bool
  823. */
  824. public function updateWallet()
  825. {
  826. $balance = 0;
  827. foreach ($this->sellerWalletOperations() as $sellerWalletOperation) {
  828. if ($sellerWalletOperation->checkWalletOperationChecksum()) {
  829. $balance = $balance + $sellerWalletOperation->sellerWhaterOrganizationCoins();
  830. }
  831. }
  832. foreach ($this->buyerWalletOperations() as $buyerWalletOperation) {
  833. if ($buyerWalletOperation->checkWalletOperationChecksum()) {
  834. $balance = $balance + $buyerWalletOperation->buyerWhaterOrganizationCoins();
  835. }
  836. }
  837. $this->currentBalance = $balance;
  838. }
  839. /**
  840. * @return string
  841. */
  842. public function details(): ?string
  843. {
  844. return $this->details;
  845. }
  846. /**
  847. * @return string
  848. */
  849. public function publicName()
  850. {
  851. return $this->publicName;
  852. }
  853. /**
  854. * @return string
  855. */
  856. public function contactPerson()
  857. {
  858. return $this->contactPerson;
  859. }
  860. /**
  861. * @return string
  862. */
  863. public function contactEmail()
  864. {
  865. return $this->contactEmail;
  866. }
  867. /**
  868. * @return string
  869. */
  870. public function facebook()
  871. {
  872. return $this->facebook;
  873. }
  874. /**
  875. * @return string
  876. */
  877. public function instagram()
  878. {
  879. return $this->instagram;
  880. }
  881. /**
  882. * @return string
  883. */
  884. public function linkedin()
  885. {
  886. return $this->linkedin;
  887. }
  888. /**
  889. * @return string
  890. */
  891. public function contactPhone()
  892. {
  893. return $this->contactPhone;
  894. }
  895. /**
  896. * @return string
  897. */
  898. public function marketplaceCountry()
  899. {
  900. return $this->marketplaceCountry;
  901. }
  902. /**
  903. * @return string
  904. */
  905. public function marketplacePostalCode()
  906. {
  907. return $this->marketplacePostalCode;
  908. }
  909. /**
  910. * @return string
  911. */
  912. public function marketplaceAddress()
  913. {
  914. return $this->marketplaceAddress;
  915. }
  916. /**
  917. * @return string
  918. */
  919. public function fiscalName()
  920. {
  921. return $this->fiscalName;
  922. }
  923. /**
  924. * @return string
  925. */
  926. public function fiscalAddress()
  927. {
  928. return $this->fiscalAddress;
  929. }
  930. /**
  931. * @return string
  932. */
  933. public function professionalActivity()
  934. {
  935. return $this->professionalActivity;
  936. }
  937. /**
  938. * @return string
  939. */
  940. public function specializationInWater()
  941. {
  942. return $this->specializationInWater;
  943. }
  944. /**
  945. * @return string
  946. */
  947. public function regionScope()
  948. {
  949. return $this->regionScope;
  950. }
  951. /**
  952. * @return string
  953. */
  954. public function numberOfDelegations()
  955. {
  956. return $this->numberOfDelegations;
  957. }
  958. /**
  959. * @return string
  960. */
  961. public function numberOfCustomers()
  962. {
  963. return $this->numberOfCustomers;
  964. }
  965. /**
  966. * @return string
  967. */
  968. public function bankAccountOwnerName()
  969. {
  970. return $this->bankAccountOwnerName;
  971. }
  972. /**
  973. * @return string
  974. */
  975. public function bankAccountIbanNumber()
  976. {
  977. return $this->bankAccountIbanNumber;
  978. }
  979. /**
  980. * @return string
  981. */
  982. public function bankAccountBicSwiftNumber()
  983. {
  984. return $this->bankAccountBicSwiftNumber;
  985. }
  986. /**
  987. * @return string
  988. */
  989. public function stripeExpressAccountId()
  990. {
  991. return $this->stripeExpressAccountId;
  992. }
  993. /**
  994. * @return string
  995. */
  996. public function stripeExpressAccountStatus()
  997. {
  998. return $this->stripeExpressAccountStatus;
  999. }
  1000. /**
  1001. * @return string
  1002. */
  1003. public function referralCode(): ?string
  1004. {
  1005. return $this->referralCode;
  1006. }
  1007. /**
  1008. * @return \DateTime
  1009. */
  1010. public function createdAt(): \DateTime
  1011. {
  1012. return $this->createdAt;
  1013. }
  1014. /**
  1015. * @return \DateTime
  1016. */
  1017. public function updatedAt(): \DateTime
  1018. {
  1019. return $this->updatedAt;
  1020. }
  1021. /**
  1022. * @return Collection
  1023. */
  1024. public function whaterOrganizationCodes(): Collection
  1025. {
  1026. return $this->whaterOrganizationCodes;
  1027. }
  1028. public function hasOrganizationCode(string $code, string $externalSystem)
  1029. {
  1030. foreach ($this->whaterOrganizationCodes() as $whaterOrganizationCode) {
  1031. if (
  1032. $whaterOrganizationCode->externalSystem() == $externalSystem &&
  1033. $whaterOrganizationCode->code() == $code
  1034. ) {
  1035. return true;
  1036. }
  1037. }
  1038. return false;
  1039. }
  1040. public function hasOrganizationCodeForExternalSystem(string $externalSystem)
  1041. {
  1042. foreach ($this->whaterOrganizationCodes() as $whaterOrganizationCode) {
  1043. if (
  1044. $whaterOrganizationCode->externalSystem() == $externalSystem
  1045. ) {
  1046. return true;
  1047. }
  1048. }
  1049. return false;
  1050. }
  1051. /**
  1052. * @return bool
  1053. */
  1054. public function isMarketable(): bool
  1055. {
  1056. if ($this->stripeExpressAccountStatus() != WhaterOrganization::STRIPE_CONNECT_STATUS_CONNECTED) {
  1057. return false;
  1058. }
  1059. if (!$this->hasActiveLicense(OrganizationLicense::LICENSE_SCOPE_SELLERS)) {
  1060. return false;
  1061. }
  1062. return true;
  1063. }
  1064. /**
  1065. * @return Collection
  1066. */
  1067. public function buyerWalletOperations(): Collection
  1068. {
  1069. return $this->buyerWalletOperations;
  1070. }
  1071. /**
  1072. * @return Collection
  1073. */
  1074. public function sellerWalletOperations(): Collection
  1075. {
  1076. return $this->sellerWalletOperations;
  1077. }
  1078. /**
  1079. * @return Collection
  1080. */
  1081. public function walletLiquidationRequests(): Collection
  1082. {
  1083. return $this->walletLiquidationRequests;
  1084. }
  1085. /**
  1086. * @return bool
  1087. */
  1088. public function equals(WhaterOrganization $whaterOrganization)
  1089. {
  1090. return $this->id() === $whaterOrganization->id();
  1091. }
  1092. public function __tostring()
  1093. {
  1094. return $this->publicName;
  1095. }
  1096. /**
  1097. * @return Collection
  1098. */
  1099. public function ubications(): Collection
  1100. {
  1101. return $this->ubications;
  1102. }
  1103. /**
  1104. * @return Collection
  1105. */
  1106. public function towns(): Collection
  1107. {
  1108. return $this->towns;
  1109. }
  1110. /**
  1111. * @return Collection
  1112. */
  1113. public function townLocations(): Collection
  1114. {
  1115. return $this->townLocations;
  1116. }
  1117. }