src/Eccube/Entity/TaxRule.php line 28

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of EC-CUBE
  4. *
  5. * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6. *
  7. * http://www.ec-cube.co.jp/
  8. *
  9. * For the full copyright and license information, please view the LICENSE
  10. * file that was distributed with this source code.
  11. */
  12. namespace Eccube\Entity;
  13. use Doctrine\ORM\Mapping as ORM;
  14. if (!class_exists('\Eccube\Entity\TaxRule')) {
  15. /**
  16. * TaxRule
  17. *
  18. * @ORM\Table(name="dtb_tax_rule")
  19. * @ORM\InheritanceType("SINGLE_TABLE")
  20. * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
  21. * @ORM\HasLifecycleCallbacks()
  22. * @ORM\Entity(repositoryClass="Eccube\Repository\TaxRuleRepository")
  23. */
  24. class TaxRule extends \Eccube\Entity\AbstractEntity
  25. {
  26. /**
  27. * @var integer
  28. */
  29. public const DEFAULT_TAX_RULE_ID = 1;
  30. /**
  31. * @var integer
  32. */
  33. private $sort_no;
  34. /**
  35. * is default
  36. *
  37. * @return bool
  38. */
  39. public function isDefaultTaxRule()
  40. {
  41. return self::DEFAULT_TAX_RULE_ID === $this->getId();
  42. }
  43. /**
  44. * Set sortNo
  45. *
  46. * @param integer $sortNo
  47. *
  48. * @return TaxRule
  49. */
  50. public function setSortNo($sortNo)
  51. {
  52. $this->sort_no = $sortNo;
  53. return $this;
  54. }
  55. /**
  56. * Get sortNo
  57. *
  58. * @return integer
  59. */
  60. public function getSortNo()
  61. {
  62. return $this->sort_no;
  63. }
  64. /**
  65. * @var int
  66. *
  67. * @ORM\Column(name="id", type="integer", options={"unsigned":true})
  68. * @ORM\Id
  69. * @ORM\GeneratedValue(strategy="IDENTITY")
  70. */
  71. private $id;
  72. /**
  73. * @var string
  74. *
  75. * @ORM\Column(name="tax_rate", type="decimal", precision=10, scale=0, options={"unsigned":true,"default":0})
  76. */
  77. private $tax_rate = 0;
  78. /**
  79. * @var string
  80. *
  81. * @ORM\Column(name="tax_adjust", type="decimal", precision=10, scale=0, options={"unsigned":true,"default":0})
  82. */
  83. private $tax_adjust = 0;
  84. /**
  85. * @var \DateTime
  86. *
  87. * @ORM\Column(name="apply_date", type="datetimetz")
  88. */
  89. private $apply_date;
  90. /**
  91. * @var \DateTime
  92. *
  93. * @ORM\Column(name="create_date", type="datetimetz")
  94. */
  95. private $create_date;
  96. /**
  97. * @var \DateTime
  98. *
  99. * @ORM\Column(name="update_date", type="datetimetz")
  100. */
  101. private $update_date;
  102. /**
  103. * @var \Eccube\Entity\ProductClass
  104. *
  105. * @ORM\OneToOne(targetEntity="Eccube\Entity\ProductClass", inversedBy="TaxRule")
  106. * @ORM\JoinColumns({
  107. * @ORM\JoinColumn(name="product_class_id", referencedColumnName="id")
  108. * })
  109. */
  110. private $ProductClass;
  111. /**
  112. * @var \Eccube\Entity\Member
  113. *
  114. * @ORM\ManyToOne(targetEntity="Eccube\Entity\Member")
  115. * @ORM\JoinColumns({
  116. * @ORM\JoinColumn(name="creator_id", referencedColumnName="id")
  117. * })
  118. */
  119. private $Creator;
  120. /**
  121. * @var \Eccube\Entity\Master\Country
  122. *
  123. * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Country")
  124. * @ORM\JoinColumns({
  125. * @ORM\JoinColumn(name="country_id", referencedColumnName="id")
  126. * })
  127. */
  128. private $Country;
  129. /**
  130. * @var \Eccube\Entity\Master\Pref
  131. *
  132. * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Pref")
  133. * @ORM\JoinColumns({
  134. * @ORM\JoinColumn(name="pref_id", referencedColumnName="id")
  135. * })
  136. */
  137. private $Pref;
  138. /**
  139. * @var \Eccube\Entity\Product
  140. *
  141. * @ORM\ManyToOne(targetEntity="Eccube\Entity\Product")
  142. * @ORM\JoinColumns({
  143. * @ORM\JoinColumn(name="product_id", referencedColumnName="id")
  144. * })
  145. */
  146. private $Product;
  147. /**
  148. * @var \Eccube\Entity\Master\RoundingType
  149. *
  150. * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\RoundingType")
  151. * @ORM\JoinColumns({
  152. * @ORM\JoinColumn(name="rounding_type_id", referencedColumnName="id")
  153. * })
  154. */
  155. private $RoundingType;
  156. /**
  157. * Get id.
  158. *
  159. * @return int
  160. */
  161. public function getId()
  162. {
  163. return $this->id;
  164. }
  165. /**
  166. * Set taxRate.
  167. *
  168. * @param string $taxRate
  169. *
  170. * @return TaxRule
  171. */
  172. public function setTaxRate($taxRate)
  173. {
  174. $this->tax_rate = $taxRate;
  175. return $this;
  176. }
  177. /**
  178. * Get taxRate.
  179. *
  180. * @return string
  181. */
  182. public function getTaxRate()
  183. {
  184. return $this->tax_rate;
  185. }
  186. /**
  187. * Set taxAdjust.
  188. *
  189. * @param string $taxAdjust
  190. *
  191. * @return TaxRule
  192. */
  193. public function setTaxAdjust($taxAdjust)
  194. {
  195. $this->tax_adjust = $taxAdjust;
  196. return $this;
  197. }
  198. /**
  199. * Get taxAdjust.
  200. *
  201. * @return string
  202. */
  203. public function getTaxAdjust()
  204. {
  205. return $this->tax_adjust;
  206. }
  207. /**
  208. * Set applyDate.
  209. *
  210. * @param \DateTime $applyDate
  211. *
  212. * @return TaxRule
  213. */
  214. public function setApplyDate($applyDate)
  215. {
  216. $this->apply_date = $applyDate;
  217. return $this;
  218. }
  219. /**
  220. * Get applyDate.
  221. *
  222. * @return \DateTime
  223. */
  224. public function getApplyDate()
  225. {
  226. return $this->apply_date;
  227. }
  228. /**
  229. * Set createDate.
  230. *
  231. * @param \DateTime $createDate
  232. *
  233. * @return TaxRule
  234. */
  235. public function setCreateDate($createDate)
  236. {
  237. $this->create_date = $createDate;
  238. return $this;
  239. }
  240. /**
  241. * Get createDate.
  242. *
  243. * @return \DateTime
  244. */
  245. public function getCreateDate()
  246. {
  247. return $this->create_date;
  248. }
  249. /**
  250. * Set updateDate.
  251. *
  252. * @param \DateTime $updateDate
  253. *
  254. * @return TaxRule
  255. */
  256. public function setUpdateDate($updateDate)
  257. {
  258. $this->update_date = $updateDate;
  259. return $this;
  260. }
  261. /**
  262. * Get updateDate.
  263. *
  264. * @return \DateTime
  265. */
  266. public function getUpdateDate()
  267. {
  268. return $this->update_date;
  269. }
  270. /**
  271. * Set productClass.
  272. *
  273. * @param \Eccube\Entity\ProductClass|null $productClass
  274. *
  275. * @return TaxRule
  276. */
  277. public function setProductClass(ProductClass $productClass = null)
  278. {
  279. $this->ProductClass = $productClass;
  280. return $this;
  281. }
  282. /**
  283. * Get productClass.
  284. *
  285. * @return \Eccube\Entity\ProductClass|null
  286. */
  287. public function getProductClass()
  288. {
  289. return $this->ProductClass;
  290. }
  291. /**
  292. * Set creator.
  293. *
  294. * @param \Eccube\Entity\Member|null $creator
  295. *
  296. * @return TaxRule
  297. */
  298. public function setCreator(Member $creator = null)
  299. {
  300. $this->Creator = $creator;
  301. return $this;
  302. }
  303. /**
  304. * Get creator.
  305. *
  306. * @return \Eccube\Entity\Member|null
  307. */
  308. public function getCreator()
  309. {
  310. return $this->Creator;
  311. }
  312. /**
  313. * Set country.
  314. *
  315. * @param \Eccube\Entity\Master\Country|null $country
  316. *
  317. * @return TaxRule
  318. */
  319. public function setCountry(Master\Country $country = null)
  320. {
  321. $this->Country = $country;
  322. return $this;
  323. }
  324. /**
  325. * Get country.
  326. *
  327. * @return \Eccube\Entity\Master\Country|null
  328. */
  329. public function getCountry()
  330. {
  331. return $this->Country;
  332. }
  333. /**
  334. * Set pref.
  335. *
  336. * @param \Eccube\Entity\Master\Pref|null $pref
  337. *
  338. * @return TaxRule
  339. */
  340. public function setPref(Master\Pref $pref = null)
  341. {
  342. $this->Pref = $pref;
  343. return $this;
  344. }
  345. /**
  346. * Get pref.
  347. *
  348. * @return \Eccube\Entity\Master\Pref|null
  349. */
  350. public function getPref()
  351. {
  352. return $this->Pref;
  353. }
  354. /**
  355. * Set product.
  356. *
  357. * @param \Eccube\Entity\Product|null $product
  358. *
  359. * @return TaxRule
  360. */
  361. public function setProduct(Product $product = null)
  362. {
  363. $this->Product = $product;
  364. return $this;
  365. }
  366. /**
  367. * Get product.
  368. *
  369. * @return \Eccube\Entity\Product|null
  370. */
  371. public function getProduct()
  372. {
  373. return $this->Product;
  374. }
  375. /**
  376. * Set roundingType.
  377. *
  378. * @return TaxRule
  379. */
  380. public function setRoundingType(Master\RoundingType $RoundingType = null)
  381. {
  382. $this->RoundingType = $RoundingType;
  383. return $this;
  384. }
  385. /**
  386. * Get roundingType.
  387. *
  388. * @return \Eccube\Entity\Master\RoundingType|null
  389. */
  390. public function getRoundingType()
  391. {
  392. return $this->RoundingType;
  393. }
  394. /**
  395. * 自分自身と Target を比較し, ソートのための数値を返す.
  396. *
  397. * 以下の順で比較し、
  398. *
  399. * 同一であれば 0
  400. * 自分の方が大きければ正の整数
  401. * 小さければ負の整数を返す.
  402. *
  403. * 1. 商品別税率が有効
  404. * 2. apply_date
  405. * 3. sort_no
  406. *
  407. * このメソッドは usort() 関数などで使用する.
  408. *
  409. * @param TaxRule $Target 比較対象の TaxRule
  410. *
  411. * @return integer
  412. */
  413. public function compareTo(TaxRule $Target)
  414. {
  415. if ($this->isProductTaxRule() && !$Target->isProductTaxRule()) {
  416. return -1;
  417. } elseif (!$this->isProductTaxRule() && $Target->isProductTaxRule()) {
  418. return 1;
  419. } else {
  420. if ($this->getApplyDate()->format('YmdHis') == $Target->getApplyDate()->format('YmdHis')) {
  421. if ($this->getSortNo() == $Target->getSortNo()) {
  422. return 0;
  423. }
  424. if ($this->getSortNo() > $Target->getSortNo()) {
  425. return -1;
  426. } else {
  427. return 1;
  428. }
  429. } else {
  430. if ($this->getApplyDate()->format('YmdHis') > $Target->getApplyDate()->format('YmdHis')) {
  431. return -1;
  432. } else {
  433. return 1;
  434. }
  435. }
  436. }
  437. }
  438. /**
  439. * 商品別税率設定が適用されているかどうか.
  440. *
  441. * @return bool 商品別税率が適用されている場合 true
  442. */
  443. public function isProductTaxRule()
  444. {
  445. return $this->getProductClass() !== null || $this->getProduct() !== null;
  446. }
  447. }
  448. }