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