PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/SwissPaymentSlip/SwissPaymentSlip/SwissPaymentSlip.php

https://github.com/ravage84/SwissPaymentSlip
PHP | 1331 lines | 590 code | 129 blank | 612 comment | 55 complexity | 9212f47e1f0bb5775e97a106a1e76316 MD5 | raw file
  1. <?php
  2. /**
  3. * Swiss Payment Slip as PDF
  4. *
  5. * PHP version >= 5.3.0
  6. *
  7. * @licence MIT
  8. * @copyright 2012-2013 Some nice Swiss guys
  9. * @author Manuel Reinhard <manu@sprain.ch>
  10. * @author Peter Siska <pesche@gridonic.ch>
  11. * @author Marc W端rth ravage@bluewin.ch
  12. * @link https://github.com/sprain/class.Einzahlungsschein.php
  13. * @version: 0.5.0
  14. */
  15. namespace SwissPaymentSlip\SwissPaymentSlip;
  16. use InvalidArgumentException;
  17. // TODO include CHF boxed slip image (609, SwissPaymentSlip+)
  18. // TODO include EUR framed slip image (701) --> back side!
  19. // TODO include EUR boxed slip image (701) --> back side!
  20. // TODO implement notForInpaying (XXXX.XX)
  21. // TODO implement cash on delivery (Nachnahme)
  22. // TODO include cash on delivery (Nachnahme) slip image
  23. // TODO create constants for the attribute keys
  24. // TODO create constants for left, right and center text alignment (L, R, C)
  25. // TODO create central cell placement and formatting code (lines as array, attributes)...
  26. // TODO code cleanup
  27. // TODO create Tests, what's possible (getter and setter, setter without getters testable?
  28. // TODO docblocks
  29. // TODO class docblock
  30. // TODO test docs generated
  31. /**
  32. * A general purpose class for swiss payment slips. Data is organized by its sister class SwissPaymentSlipData.
  33. */
  34. class SwissPaymentSlip
  35. {
  36. /**
  37. * The payment slip value object, which contains the payment slip data
  38. *
  39. * @var SwissPaymentSlipData The payment slip value object
  40. */
  41. protected $paymentSlipData = null;
  42. /**
  43. * Starting X position of the slip
  44. *
  45. * @var int Starting X position of the slip in mm
  46. */
  47. protected $slipPosX = 0;
  48. /**
  49. * Starting Y position of the slip
  50. *
  51. * @var int Starting Y position of the slip in mm
  52. */
  53. protected $slipPosY = 191;
  54. /**
  55. * @var int
  56. */
  57. protected $slipHeight = 106; // default height of an orange slip
  58. /**
  59. * @var int
  60. */
  61. protected $slipWidth = 210; // default width of an orange slip
  62. /**
  63. * Background of the slip
  64. *
  65. * Can be either transparent, a color or image
  66. *
  67. * @var null
  68. */
  69. protected $slipBackground = null;
  70. /**
  71. * @var string
  72. */
  73. protected $defaultFontFamily = 'Helvetica';
  74. /**
  75. * @var string
  76. */
  77. protected $defaultFontSize = '10';
  78. /**
  79. * @var string
  80. */
  81. protected $defaultFontColor = '#000';
  82. /**
  83. * @var int
  84. */
  85. protected $defaultLineHeight = 4;
  86. /**
  87. * @var string
  88. */
  89. protected $defaultTextAlign = 'L';
  90. /**
  91. * Determines if the bank details should be displayed
  92. *
  93. * @var bool True if yes, false if no
  94. */
  95. protected $displayBank = true;
  96. /**
  97. * Determines if the recipient details should be displayed
  98. *
  99. * @var bool True if yes, false if no
  100. */
  101. protected $displayRecipient = true;
  102. /**
  103. * Determines if the account should be displayed
  104. *
  105. * @var bool True if yes, false if no
  106. */
  107. protected $displayAccount = true;
  108. /**
  109. * Determines if the amount should be displayed
  110. *
  111. * @var bool True if yes, false if no
  112. */
  113. protected $displayAmount = true;
  114. /**
  115. * Determines if the reference number should be displayed
  116. *
  117. * @var bool True if yes, false if no
  118. */
  119. protected $displayReferenceNr = true;
  120. /**
  121. * Determines if the payer details should be displayed
  122. *
  123. * @var bool True if yes, false if no
  124. */
  125. protected $displayPayer = true;
  126. /**
  127. * Determines if the IBAN should be displayed
  128. *
  129. * @var bool True if yes, false if no
  130. */
  131. protected $displayIban = false;
  132. /**
  133. * Determines if the payment reason should be displayed
  134. *
  135. * @var bool True if yes, false if no
  136. */
  137. protected $displayPaymentReason = false;
  138. /**
  139. * Determines if the code line at the bottom should be displayed
  140. *
  141. * @var bool True if yes, false if no
  142. */
  143. protected $displayCodeLine = true;
  144. /**
  145. * @var array
  146. */
  147. protected $bankLeftAttr = array();
  148. /**
  149. * @var array
  150. */
  151. protected $bankRightAttr = array();
  152. /**
  153. * @var array
  154. */
  155. protected $recipientLeftAttr = array();
  156. /**
  157. * @var array
  158. */
  159. protected $recipientRightAttr = array();
  160. /**
  161. * @var array
  162. */
  163. protected $accountLeftAttr = array();
  164. /**
  165. * @var array
  166. */
  167. protected $accountRightAttr = array();
  168. /**
  169. * @var array
  170. */
  171. protected $amountFrancsLeftAttr = array();
  172. /**
  173. * @var array
  174. */
  175. protected $amountFrancsRightAttr = array();
  176. /**
  177. * @var array
  178. */
  179. protected $amountCentsLeftAttr = array();
  180. /**
  181. * @var array
  182. */
  183. protected $amountCentsRightAttr = array();
  184. /**
  185. * @var array
  186. */
  187. protected $referenceNumberLeftAttr = array();
  188. /**
  189. * @var array
  190. */
  191. protected $referenceNumberRightAttr = array();
  192. /**
  193. * @var array
  194. */
  195. protected $payerLeftAttr = array();
  196. /**
  197. * @var array
  198. */
  199. protected $payerRightAttr = array();
  200. /**
  201. * @var array
  202. */
  203. protected $codeLineAttr = array();
  204. /**
  205. * @param SwissPaymentSlipData $paymentSlipData
  206. * @param integer $slipPosX
  207. * @param integer $slipPosY
  208. *
  209. * @throws \InvalidArgumentException
  210. * @todo Implement width and height as optional parameters
  211. */
  212. public function __construct($paymentSlipData, $slipPosX = null, $slipPosY = null)
  213. {
  214. if (!is_object($paymentSlipData)) {
  215. throw new InvalidArgumentException('PaymentSlipData parameter is not an object!');
  216. }
  217. if (!$paymentSlipData instanceof SwissPaymentSlipData) {
  218. throw new InvalidArgumentException('PaymentSlipData parameter is not an instance of SwissPaymentSlipData!');
  219. }
  220. $this->paymentSlipData = $paymentSlipData;
  221. if (!is_null($slipPosX)) {
  222. $this->setSlipPosX($slipPosX);
  223. }
  224. if (!is_null($slipPosY)) {
  225. $this->setSlipPosY($slipPosY);
  226. }
  227. $this->setDefaults();
  228. }
  229. /**
  230. * Sets the default attributes of the elements according to the type
  231. *
  232. * @todo Eliminate the direct system dependency, make the background image a mandatory constructor parameter
  233. */
  234. protected function setDefaults()
  235. {
  236. if ($this->paymentSlipData->getType() == SwissPaymentSlipData::ORANGE) {
  237. $this->setBankLeftAttr(3, 8, 50, 4);
  238. $this->setBankRightAttr(66, 8, 50, 4);
  239. $this->setRecipientLeftAttr(3, 23, 50, 4);
  240. $this->setRecipientRightAttr(66, 23, 50, 4);
  241. $this->setAccountLeftAttr(27, 43, 30, 4);
  242. $this->setAccountRightAttr(90, 43, 30, 4);
  243. $this->setAmountFrancsLeftAttr(5, 50.5, 35, 4);
  244. $this->setAmountFrancsRightAttr(66, 50.5, 35, 4);
  245. $this->setAmountCentsLeftAttr(50, 50.5, 6, 4);
  246. $this->setAmountCentsRightAttr(111, 50.5, 6, 4);
  247. $this->setReferenceNumberLeftAttr(3, 60, 50, 4, null, null, 8);
  248. $this->setReferenceNumberRightAttr(125, 33.5, 80, 4);
  249. $this->setPayerLeftAttr(3, 65, 50, 4);
  250. $this->setPayerRightAttr(125, 48, 50, 4);
  251. $this->setCodeLineAttr(64, 85, 140, 4, null, 'OCRB10');
  252. // TODO Eliminate system dependency
  253. $this->setSlipBackground(__DIR__.'/Resources/img/ezs_orange.gif');
  254. } elseif ($this->paymentSlipData->getType() == SwissPaymentSlipData::RED) {
  255. $this->setBankLeftAttr(3, 8, 50, 4);
  256. $this->setBankRightAttr(66, 8, 50, 4);
  257. $this->setRecipientLeftAttr(3, 23, 50, 4);
  258. $this->setRecipientRightAttr(66, 23, 50, 4);
  259. $this->setAccountLeftAttr(27, 43, 30, 4);
  260. $this->setAccountRightAttr(90, 43, 30, 4);
  261. $this->setAmountFrancsLeftAttr(5, 50.5, 35, 4);
  262. $this->setAmountFrancsRightAttr(66, 50.5, 35, 4);
  263. $this->setAmountCentsLeftAttr(50, 50.5, 6, 4);
  264. $this->setAmountCentsRightAttr(111, 50.5, 6, 4);
  265. $this->setReferenceNumberLeftAttr(3, 60, 50, 4, null, null, 8);
  266. $this->setReferenceNumberRightAttr(125, 33.5, 80, 4);
  267. $this->setPayerLeftAttr(3, 65, 50, 4);
  268. $this->setPayerRightAttr(125, 48, 50, 4);
  269. $this->setCodeLineAttr(64, 85, 140, 4, null, 'OCRB10');
  270. // TODO Eliminate system dependency
  271. $this->setSlipBackground(__DIR__.'/Resources/img/ezs_red.gif');
  272. }
  273. }
  274. /**
  275. * @return SwissPaymentSlipData
  276. */
  277. public function getPaymentSlipData() {
  278. return $this->paymentSlipData;
  279. }
  280. /**
  281. * Set slip X & Y position
  282. *
  283. * @param $slipPosX
  284. * @param $slipPosY
  285. * @return bool True if successful, else false
  286. */
  287. public function setSlipPosition($slipPosX, $slipPosY)
  288. {
  289. if ($this->setSlipPosX($slipPosX) &&
  290. $this->setSlipPosY($slipPosY)) {
  291. return true;
  292. }
  293. return false;
  294. }
  295. /**
  296. * @param $slipPosX
  297. * @return bool
  298. */
  299. protected function setSlipPosX($slipPosX)
  300. {
  301. if (is_int($slipPosX) || is_float($slipPosX)) {
  302. $this->slipPosX = $slipPosX;
  303. return true;
  304. }
  305. return false;
  306. }
  307. /**
  308. * @param $slipPosY
  309. * @return bool
  310. */
  311. protected function setSlipPosY($slipPosY)
  312. {
  313. if (is_int($slipPosY) || is_float($slipPosY)) {
  314. $this->slipPosY = $slipPosY;
  315. return true;
  316. }
  317. return false;
  318. }
  319. /**
  320. * Set slip height & width
  321. *
  322. * @param $slipWidth
  323. * @param $slipHeight
  324. * @return bool True if successful, else false
  325. */
  326. public function setSlipSize($slipWidth, $slipHeight)
  327. {
  328. if ($this->setSlipHeight($slipHeight) &&
  329. $this->setSlipWidth($slipWidth)) {
  330. return true;
  331. }
  332. return false;
  333. }
  334. /**
  335. * @param $slipWidth
  336. * @return bool
  337. */
  338. protected function setSlipWidth($slipWidth)
  339. {
  340. if (is_int($slipWidth) || is_float($slipWidth)) {
  341. $this->slipWidth = $slipWidth;
  342. return true;
  343. }
  344. return false;
  345. }
  346. /**
  347. * @param $slipHeight
  348. * @return bool
  349. */
  350. protected function setSlipHeight($slipHeight)
  351. {
  352. if (is_int($slipHeight) || is_float($slipHeight)) {
  353. $this->slipHeight = $slipHeight;
  354. return true;
  355. }
  356. return false;
  357. }
  358. /**
  359. * @param string $slipBackground
  360. * @return bool Always true
  361. *
  362. * @todo Implement sanity checks on parameter (filename or color)
  363. */
  364. public function setSlipBackground($slipBackground)
  365. {
  366. $this->slipBackground = $slipBackground;
  367. return true;
  368. }
  369. /**
  370. * @param $attributes
  371. * @param null $posX
  372. * @param null $posY
  373. * @param null $width
  374. * @param null $height
  375. * @param null $background
  376. * @param null $fontFamily
  377. * @param null $fontSize
  378. * @param null $fontColor
  379. * @param null $lineHeight
  380. * @param null $textAlign
  381. * @return bool
  382. */
  383. protected function setAttributes(&$attributes, $posX = null, $posY = null, $width = null, $height = null, $background = null,
  384. $fontFamily = null, $fontSize = null, $fontColor = null,
  385. $lineHeight = null, $textAlign = null) {
  386. if ($posX) {
  387. $attributes['PosX'] = $posX;
  388. } elseif (!isset($attributes['PosX'])) {
  389. $attributes['PosX'] = 0;
  390. }
  391. if ($posY) {
  392. $attributes['PosY'] = $posY;
  393. } elseif (!isset($attributes['PosY'])) {
  394. $attributes['PosY'] = 0;
  395. }
  396. if ($width) {
  397. $attributes['Width'] = $width;
  398. } elseif (!isset($attributes['Width'])) {
  399. $attributes['Width'] = 0;
  400. }
  401. if ($height) {
  402. $attributes['Height'] = $height;
  403. } elseif (!isset($attributes['Height'])) {
  404. $attributes['Height'] = 0;
  405. }
  406. if ($background) {
  407. $attributes['Background'] = $background;
  408. } elseif (!isset($attributes['Background'])) {
  409. $attributes['Background'] = 'transparent';
  410. }
  411. if ($fontFamily) {
  412. $attributes['FontFamily'] = $fontFamily;
  413. } elseif (!isset($attributes['FontFamily'])) {
  414. $attributes['FontFamily'] = $this->defaultFontFamily;
  415. }
  416. if ($fontSize) {
  417. $attributes['FontSize'] = $fontSize;
  418. } elseif (!isset($attributes['FontSize'])) {
  419. $attributes['FontSize'] = $this->defaultFontSize;
  420. }
  421. if ($fontColor) {
  422. $attributes['FontColor'] = $fontColor;
  423. } elseif (!isset($attributes['FontColor'])) {
  424. $attributes['FontColor'] = $this->defaultFontColor;
  425. }
  426. if ($lineHeight) {
  427. $attributes['LineHeight'] = $lineHeight;
  428. } elseif (!isset($attributes['LineHeight'])) {
  429. $attributes['LineHeight'] = $this->defaultLineHeight;
  430. }
  431. if ($textAlign) {
  432. $attributes['TextAlign'] = $textAlign;
  433. } elseif (!isset($attributes['TextAlign'])) {
  434. $attributes['TextAlign'] = $this->defaultTextAlign;
  435. }
  436. return true;
  437. }
  438. /**
  439. * @param null $posX
  440. * @param null $posY
  441. * @param null $width
  442. * @param null $height
  443. * @param null $background
  444. * @param null $fontFamily
  445. * @param null $fontSize
  446. * @param null $fontColor
  447. * @param null $lineHeight
  448. * @param null $textAlign
  449. * @return bool
  450. */
  451. public function setBankLeftAttr($posX = null, $posY = null, $width = null, $height = null,
  452. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  453. $lineHeight = null, $textAlign = null) {
  454. return $this->setAttributes($this->bankLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  455. $fontSize, $fontColor, $lineHeight, $textAlign);
  456. }
  457. /**
  458. * @param null $posX
  459. * @param null $posY
  460. * @param null $width
  461. * @param null $height
  462. * @param null $background
  463. * @param null $fontFamily
  464. * @param null $fontSize
  465. * @param null $fontColor
  466. * @param null $lineHeight
  467. * @param null $textAlign
  468. * @return bool
  469. */
  470. public function setBankRightAttr($posX = null, $posY = null, $width = null, $height = null,
  471. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  472. $lineHeight = null, $textAlign = null) {
  473. return $this->setAttributes($this->bankRightAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  474. $fontSize, $fontColor, $lineHeight, $textAlign);
  475. }
  476. /**
  477. * @param null $posX
  478. * @param null $posY
  479. * @param null $width
  480. * @param null $height
  481. * @param null $background
  482. * @param null $fontFamily
  483. * @param null $fontSize
  484. * @param null $fontColor
  485. * @param null $lineHeight
  486. * @param null $textAlign
  487. * @return bool
  488. */
  489. public function setRecipientLeftAttr($posX = null, $posY = null, $width = null, $height = null,
  490. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  491. $lineHeight = null, $textAlign = null) {
  492. return $this->setAttributes($this->recipientLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  493. $fontSize, $fontColor, $lineHeight, $textAlign);
  494. }
  495. /**
  496. * @param null $posX
  497. * @param null $posY
  498. * @param null $width
  499. * @param null $height
  500. * @param null $background
  501. * @param null $fontFamily
  502. * @param null $fontSize
  503. * @param null $fontColor
  504. * @param null $lineHeight
  505. * @param null $textAlign
  506. * @return bool
  507. */
  508. public function setRecipientRightAttr($posX = null, $posY = null, $width = null, $height = null,
  509. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  510. $lineHeight = null, $textAlign = null) {
  511. return $this->setAttributes($this->recipientRightAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  512. $fontSize, $fontColor, $lineHeight, $textAlign);
  513. }
  514. /**
  515. * @param null $posX
  516. * @param null $posY
  517. * @param null $width
  518. * @param null $height
  519. * @param null $background
  520. * @param null $fontFamily
  521. * @param null $fontSize
  522. * @param null $fontColor
  523. * @param null $lineHeight
  524. * @param null $textAlign
  525. * @return bool
  526. */
  527. public function setAccountLeftAttr($posX = null, $posY = null, $width = null, $height = null,
  528. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  529. $lineHeight = null, $textAlign = null) {
  530. return $this->setAttributes($this->accountLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  531. $fontSize, $fontColor, $lineHeight, $textAlign);
  532. }
  533. /**
  534. * @param null $posX
  535. * @param null $posY
  536. * @param null $width
  537. * @param null $height
  538. * @param null $background
  539. * @param null $fontFamily
  540. * @param null $fontSize
  541. * @param null $fontColor
  542. * @param null $lineHeight
  543. * @param null $textAlign
  544. * @return bool
  545. */
  546. public function setAccountRightAttr($posX = null, $posY = null, $width = null, $height = null,
  547. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  548. $lineHeight = null, $textAlign = null) {
  549. return $this->setAttributes($this->accountRightAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  550. $fontSize, $fontColor, $lineHeight, $textAlign);
  551. }
  552. /**
  553. * @param null $posX
  554. * @param null $posY
  555. * @param null $width
  556. * @param null $height
  557. * @param null $background
  558. * @param null $fontFamily
  559. * @param null $fontSize
  560. * @param null $fontColor
  561. * @param null $lineHeight
  562. * @param null $textAlign
  563. * @return bool
  564. */
  565. public function setAmountFrancsLeftAttr($posX = null, $posY = null, $width = null, $height = null,
  566. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  567. $lineHeight = null, $textAlign = null) {
  568. if (!$textAlign) {
  569. $textAlign = 'R';
  570. }
  571. return $this->setAttributes($this->amountFrancsLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  572. $fontSize, $fontColor, $lineHeight, $textAlign);
  573. }
  574. /**
  575. * @param null $posX
  576. * @param null $posY
  577. * @param null $width
  578. * @param null $height
  579. * @param null $background
  580. * @param null $fontFamily
  581. * @param null $fontSize
  582. * @param null $fontColor
  583. * @param null $lineHeight
  584. * @param null $textAlign
  585. * @return bool
  586. */
  587. public function setAmountFrancsRightAttr($posX = null, $posY = null, $width = null, $height = null,
  588. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  589. $lineHeight = null, $textAlign = null) {
  590. if (!$textAlign) {
  591. $textAlign = 'R';
  592. }
  593. return $this->setAttributes($this->amountFrancsRightAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  594. $fontSize, $fontColor, $lineHeight, $textAlign);
  595. }
  596. /**
  597. * @param null $posX
  598. * @param null $posY
  599. * @param null $width
  600. * @param null $height
  601. * @param null $background
  602. * @param null $fontFamily
  603. * @param null $fontSize
  604. * @param null $fontColor
  605. * @param null $lineHeight
  606. * @param null $textAlign
  607. * @return bool
  608. */
  609. public function setAmountCentsLeftAttr($posX = null, $posY = null, $width = null, $height = null,
  610. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  611. $lineHeight = null, $textAlign = null) {
  612. return $this->setAttributes($this->amountCentsLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  613. $fontSize, $fontColor, $lineHeight, $textAlign);
  614. }
  615. /**
  616. * @param null $posX
  617. * @param null $posY
  618. * @param null $width
  619. * @param null $height
  620. * @param null $background
  621. * @param null $fontFamily
  622. * @param null $fontSize
  623. * @param null $fontColor
  624. * @param null $lineHeight
  625. * @param null $textAlign
  626. * @return bool
  627. */
  628. public function setAmountCentsRightAttr($posX = null, $posY = null, $width = null, $height = null,
  629. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  630. $lineHeight = null, $textAlign = null) {
  631. return $this->setAttributes($this->amountCentsRightAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  632. $fontSize, $fontColor, $lineHeight, $textAlign);
  633. }
  634. /**
  635. * @param null $posX
  636. * @param null $posY
  637. * @param null $width
  638. * @param null $height
  639. * @param null $background
  640. * @param null $fontFamily
  641. * @param null $fontSize
  642. * @param null $fontColor
  643. * @param null $lineHeight
  644. * @param null $textAlign
  645. * @return bool
  646. */
  647. public function setReferenceNumberLeftAttr($posX = null, $posY = null, $width = null, $height = null,
  648. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  649. $lineHeight = null, $textAlign = null) {
  650. return $this->setAttributes($this->referenceNumberLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  651. $fontSize, $fontColor, $lineHeight, $textAlign);
  652. }
  653. /**
  654. * @param null $posX
  655. * @param null $posY
  656. * @param null $width
  657. * @param null $height
  658. * @param null $background
  659. * @param null $fontFamily
  660. * @param null $fontSize
  661. * @param null $fontColor
  662. * @param null $lineHeight
  663. * @param null $textAlign
  664. * @return bool
  665. */
  666. public function setReferenceNumberRightAttr($posX = null, $posY = null, $width = null, $height = null,
  667. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  668. $lineHeight = null, $textAlign = null) {
  669. if (!$textAlign) {
  670. $textAlign = 'R';
  671. }
  672. return $this->setAttributes($this->referenceNumberRightAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  673. $fontSize, $fontColor, $lineHeight, $textAlign);
  674. }
  675. /**
  676. * @param null $posX
  677. * @param null $posY
  678. * @param null $width
  679. * @param null $height
  680. * @param null $background
  681. * @param null $fontFamily
  682. * @param null $fontSize
  683. * @param null $fontColor
  684. * @param null $lineHeight
  685. * @param null $textAlign
  686. * @return bool
  687. */
  688. public function setPayerLeftAttr($posX = null, $posY = null, $width = null, $height = null,
  689. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  690. $lineHeight = null, $textAlign = null) {
  691. return $this->setAttributes($this->payerLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  692. $fontSize, $fontColor, $lineHeight, $textAlign);
  693. }
  694. /**
  695. * @param null $posX
  696. * @param null $posY
  697. * @param null $width
  698. * @param null $height
  699. * @param null $background
  700. * @param null $fontFamily
  701. * @param null $fontSize
  702. * @param null $fontColor
  703. * @param null $lineHeight
  704. * @param null $textAlign
  705. * @return bool
  706. */
  707. public function setPayerRightAttr($posX = null, $posY = null, $width = null, $height = null,
  708. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  709. $lineHeight = null, $textAlign = null) {
  710. return $this->setAttributes($this->payerRightAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  711. $fontSize, $fontColor, $lineHeight, $textAlign);
  712. }
  713. /**
  714. * @param null $posX
  715. * @param null $posY
  716. * @param null $width
  717. * @param null $height
  718. * @param null $background
  719. * @param null $fontFamily
  720. * @param null $fontSize
  721. * @param null $fontColor
  722. * @param null $lineHeight
  723. * @param null $textAlign
  724. * @return bool
  725. */
  726. public function setCodeLineAttr($posX = null, $posY = null, $width = null, $height = null,
  727. $background = null, $fontFamily = null, $fontSize = null, $fontColor = null,
  728. $lineHeight = null, $textAlign = null) {
  729. if (!$textAlign) {
  730. $textAlign = 'R';
  731. }
  732. return $this->setAttributes($this->codeLineAttr, $posX, $posY, $width, $height, $background, $fontFamily,
  733. $fontSize, $fontColor, $lineHeight, $textAlign);
  734. }
  735. /**
  736. * @return array
  737. */
  738. public function getAccountLeftAttr()
  739. {
  740. return $this->accountLeftAttr;
  741. }
  742. /**
  743. * @return array
  744. */
  745. public function getAccountRightAttr()
  746. {
  747. return $this->accountRightAttr;
  748. }
  749. /**
  750. * @return array
  751. */
  752. public function getAmountCentsRightAttr()
  753. {
  754. return $this->amountCentsRightAttr;
  755. }
  756. /**
  757. * @return array
  758. */
  759. public function getAmountCentsLeftAttr()
  760. {
  761. return $this->amountCentsLeftAttr;
  762. }
  763. /**
  764. * @return array
  765. */
  766. public function getAmountFrancsLeftAttr()
  767. {
  768. return $this->amountFrancsLeftAttr;
  769. }
  770. /**
  771. * @return array
  772. */
  773. public function getAmountFrancsRightAttr()
  774. {
  775. return $this->amountFrancsRightAttr;
  776. }
  777. /**
  778. * @return array
  779. */
  780. public function getBankLeftAttr()
  781. {
  782. return $this->bankLeftAttr;
  783. }
  784. /**
  785. * @return array
  786. */
  787. public function getBankRightAttr()
  788. {
  789. return $this->bankRightAttr;
  790. }
  791. /**
  792. * @return array
  793. */
  794. public function getCodeLineAttr()
  795. {
  796. return $this->codeLineAttr;
  797. }
  798. /**
  799. * @return array
  800. */
  801. public function getRecipientRightAttr()
  802. {
  803. return $this->recipientRightAttr;
  804. }
  805. /**
  806. * @return array
  807. */
  808. public function getRecipientLeftAttr()
  809. {
  810. return $this->recipientLeftAttr;
  811. }
  812. /**
  813. * @return array
  814. */
  815. public function getPayerRightAttr()
  816. {
  817. return $this->payerRightAttr;
  818. }
  819. /**
  820. * @return array
  821. */
  822. public function getPayerLeftAttr()
  823. {
  824. return $this->payerLeftAttr;
  825. }
  826. /**
  827. * @return array
  828. */
  829. public function getReferenceNumberLeftAttr()
  830. {
  831. return $this->referenceNumberLeftAttr;
  832. }
  833. /**
  834. * @return array
  835. */
  836. public function getReferenceNumberRightAttr()
  837. {
  838. return $this->referenceNumberRightAttr;
  839. }
  840. /**
  841. * @return null
  842. */
  843. public function getSlipBackground()
  844. {
  845. return $this->slipBackground;
  846. }
  847. /**
  848. * @return int
  849. */
  850. public function getSlipPosX()
  851. {
  852. return $this->slipPosX;
  853. }
  854. /**
  855. * @return int
  856. */
  857. public function getSlipPosY()
  858. {
  859. return $this->slipPosY;
  860. }
  861. /**
  862. * @return int
  863. */
  864. public function getSlipWidth()
  865. {
  866. return $this->slipWidth;
  867. }
  868. /**
  869. * @return int
  870. */
  871. public function getSlipHeight()
  872. {
  873. return $this->slipHeight;
  874. }
  875. /**
  876. * Set whether or not to display the account
  877. *
  878. * @param bool $displayAccount True if yes, false if no
  879. * @return bool True if successful, else false
  880. */
  881. public function setDisplayAccount($displayAccount = true)
  882. {
  883. if (is_bool($displayAccount)) {
  884. $this->displayAccount = $displayAccount;
  885. return true;
  886. }
  887. return false;
  888. }
  889. /**
  890. * Get whether or not to display the account
  891. *
  892. * @return bool True if yes, false if no
  893. */
  894. public function getDisplayAccount()
  895. {
  896. return $this->displayAccount;
  897. }
  898. /**
  899. * Set whether or not to display the amount
  900. *
  901. * @param bool $displayAmount True if yes, false if no
  902. * @return bool True if successful, else false
  903. */
  904. public function setDisplayAmount($displayAmount = true)
  905. {
  906. if (is_bool($displayAmount)) {
  907. $this->displayAmount = $displayAmount;
  908. return true;
  909. }
  910. return false;
  911. }
  912. /**
  913. * Get whether or not to display the amount
  914. *
  915. * @return bool True if yes, false if no
  916. */
  917. public function getDisplayAmount()
  918. {
  919. return $this->displayAmount;
  920. }
  921. /**
  922. * Set whether or not to display the bank
  923. *
  924. * @param bool $displayBank True if yes, false if no
  925. * @return bool True if successful, else false
  926. */
  927. public function setDisplayBank($displayBank = true)
  928. {
  929. if (is_bool($displayBank)) {
  930. $this->displayBank = $displayBank;
  931. return true;
  932. }
  933. return false;
  934. }
  935. /**
  936. * Get whether or not to display the bank
  937. *
  938. * @return bool True if yes, false if no
  939. */
  940. public function getDisplayBank()
  941. {
  942. return $this->displayBank;
  943. }
  944. /**
  945. * Set whether or not to display the payer
  946. *
  947. * @param bool $displayPayer True if yes, false if no
  948. * @return bool True if successful, else false
  949. */
  950. public function setDisplayPayer($displayPayer = true)
  951. {
  952. if (is_bool($displayPayer)) {
  953. $this->displayPayer = $displayPayer;
  954. return true;
  955. }
  956. return false;
  957. }
  958. /**
  959. * Get whether or not to display the payer
  960. *
  961. * @return bool True if yes, false if no
  962. */
  963. public function getDisplayPayer()
  964. {
  965. return $this->displayPayer;
  966. }
  967. /**
  968. * Set whether or not to display the recipient
  969. *
  970. * @param bool $displayRecipient True if yes, false if no
  971. * @return bool True if successful, else false
  972. */
  973. public function setDisplayRecipient($displayRecipient = true)
  974. {
  975. if (is_bool($displayRecipient)) {
  976. $this->displayRecipient = $displayRecipient;
  977. return true;
  978. }
  979. return false;
  980. }
  981. /**
  982. * Get whether or not to display the recipient
  983. *
  984. * @return bool True if yes, false if no
  985. */
  986. public function getDisplayRecipient()
  987. {
  988. return $this->displayRecipient;
  989. }
  990. /**
  991. * Set whether or not to display the reference number
  992. *
  993. * @param bool $displayReferenceNr True if yes, false if no
  994. * @return bool True if successful, else false
  995. */
  996. public function setDisplayReferenceNr($displayReferenceNr = true)
  997. {
  998. if (is_bool($displayReferenceNr)) {
  999. $this->displayReferenceNr = $displayReferenceNr;
  1000. return true;
  1001. }
  1002. return false;
  1003. }
  1004. /**
  1005. * Get whether or not to display the reference number
  1006. *
  1007. * @return bool True if yes, false if no
  1008. */
  1009. public function getDisplayReferenceNr()
  1010. {
  1011. return $this->displayReferenceNr;
  1012. }
  1013. /**
  1014. * Set whether or not to display the IBAN
  1015. *
  1016. * @param bool $displayIban True if yes, false if no
  1017. * @return bool True if successful, else false
  1018. */
  1019. public function setDisplayIban($displayIban = true)
  1020. {
  1021. if (is_bool($displayIban)) {
  1022. $this->displayIban = $displayIban;
  1023. return true;
  1024. }
  1025. return false;
  1026. }
  1027. /**
  1028. * Get whether or not to display the IBAN
  1029. *
  1030. * @return bool True if yes, false if no
  1031. */
  1032. public function getDisplayIban()
  1033. {
  1034. return $this->displayIban;
  1035. }
  1036. /**
  1037. * Set whether or not to display the payment reason lines
  1038. *
  1039. * @param bool $displayPaymentReason True if yes, false if no
  1040. * @return bool True if successful, else false
  1041. */
  1042. public function setDisplayPaymentReason($displayPaymentReason = true)
  1043. {
  1044. if (is_bool($displayPaymentReason)) {
  1045. $this->displayPaymentReason = $displayPaymentReason;
  1046. return true;
  1047. }
  1048. return false;
  1049. }
  1050. /**
  1051. * Get whether or not to display the payment reason lines
  1052. *
  1053. * @return bool True if yes, false if no
  1054. */
  1055. public function getDisplayPaymentReason()
  1056. {
  1057. return $this->displayPaymentReason;
  1058. }
  1059. /**
  1060. * Set whether or not to display the code line at the bottom
  1061. *
  1062. * @param bool $displayCodeLine True if yes, false if no
  1063. * @return bool True if successful, else false
  1064. */
  1065. public function setDisplayCodeLine($displayCodeLine = true)
  1066. {
  1067. if (is_bool($displayCodeLine)) {
  1068. $this->displayCodeLine = $displayCodeLine;
  1069. return true;
  1070. }
  1071. return false;
  1072. }
  1073. /**
  1074. * Get whether or not to display the code line at the bottom
  1075. *
  1076. * @return bool True if yes, false if no
  1077. */
  1078. public function getDisplayCodeLine()
  1079. {
  1080. return $this->displayCodeLine;
  1081. }
  1082. /**
  1083. * @param bool $formatted
  1084. * @param bool $fillZeroes
  1085. * @return array
  1086. */
  1087. public function getAllElements($formatted = true, $fillZeroes = true) {
  1088. $paymentSlipData = $this->paymentSlipData;
  1089. $elements = array();
  1090. // Place left bank lines
  1091. if ($this->getDisplayBank()) {
  1092. $lines = array($paymentSlipData->getBankName(),
  1093. $paymentSlipData->getBankCity());
  1094. $elements['bankLeft'] = array('lines' => $lines,
  1095. 'attributes' => $this->getBankLeftAttr()
  1096. );
  1097. }
  1098. // Place right bank lines
  1099. if ($this->getDisplayBank()) {
  1100. // reuse lines from above
  1101. $elements['bankRight'] = array('lines' => $lines,
  1102. 'attributes' => $this->getBankRightAttr()
  1103. );
  1104. }
  1105. // Place left recipient lines
  1106. if ($this->getDisplayRecipient()) {
  1107. $lines = array($paymentSlipData->getRecipientLine1(),
  1108. $paymentSlipData->getRecipientLine2(), $paymentSlipData->getRecipientLine3(),
  1109. $paymentSlipData->getRecipientLine4());
  1110. $elements['recipientLeft'] = array('lines' => $lines,
  1111. 'attributes' => $this->getRecipientLeftAttr()
  1112. );
  1113. }
  1114. // Place right recipient lines
  1115. if ($this->getDisplayRecipient()) {
  1116. // reuse lines from above
  1117. $elements['recipientRight'] = array('lines' => $lines,
  1118. 'attributes' => $this->getRecipientRightAttr()
  1119. );
  1120. }
  1121. // Place left account number
  1122. if ($this->getDisplayAccount()) {
  1123. $lines = array($paymentSlipData->getAccountNumber());
  1124. $elements['accountLeft'] = array('lines' => $lines,
  1125. 'attributes' => $this->getAccountLeftAttr()
  1126. );
  1127. }
  1128. // Place right account number
  1129. if ($this->getDisplayAccount()) {
  1130. // reuse lines from above
  1131. $elements['accountRight'] = array('lines' => $lines,
  1132. 'attributes' => $this->getAccountRightAttr()
  1133. );
  1134. }
  1135. // Place left amount in francs
  1136. if ($this->getDisplayAmount()) {
  1137. $lines = array($this->paymentSlipData->getAmountFrancs());
  1138. $elements['amountFrancsLeft'] = array('lines' => $lines,
  1139. 'attributes' => $this->getAmountFrancsLeftAttr()
  1140. );
  1141. }
  1142. // Place right amount in francs
  1143. if ($this->getDisplayAmount()) {
  1144. // reuse lines from above
  1145. $elements['amountFrancsRight'] = array('lines' => $lines,
  1146. 'attributes' => $this->getAmountFrancsRightAttr()
  1147. );
  1148. }
  1149. // Place left amount in cents
  1150. if ($this->getDisplayAmount()) {
  1151. $lines = array($this->paymentSlipData->getAmountCents());
  1152. $elements['amountCentsLeft'] = array('lines' => $lines,
  1153. 'attributes' => $this->getAmountCentsLeftAttr()
  1154. );
  1155. }
  1156. // Place right amount in cents
  1157. if ($this->getDisplayAmount()) {
  1158. // reuse lines from above
  1159. $elements['amountCentsRight'] = array('lines' => $lines,
  1160. 'attributes' => $this->getAmountCentsRightAttr()
  1161. );
  1162. }
  1163. // Place left reference number
  1164. if ($this->getDisplayReferenceNr()) {
  1165. $lines = array($this->paymentSlipData->getCompleteReferenceNumber($formatted, $fillZeroes));
  1166. $elements['referenceNumberLeft'] = array('lines' => $lines,
  1167. 'attributes' => $this->getReferenceNumberLeftAttr()
  1168. );
  1169. }
  1170. // Place right reference number
  1171. if ($this->getDisplayReferenceNr()) {
  1172. // reuse lines from above
  1173. $elements['referenceNumberRight'] = array('lines' => $lines,
  1174. 'attributes' => $this->getReferenceNumberRightAttr()
  1175. );
  1176. }
  1177. // Place left payer lines
  1178. if ($this->getDisplayPayer()) {
  1179. $lines = array($paymentSlipData->getPayerLine1(),
  1180. $paymentSlipData->getPayerLine2(), $paymentSlipData->getPayerLine3(),
  1181. $paymentSlipData->getPayerLine4());
  1182. $elements['payerLeft'] = array('lines' => $lines,
  1183. 'attributes' => $this->getPayerLeftAttr()
  1184. );
  1185. }
  1186. // Place right payer lines
  1187. if ($this->getDisplayPayer()) {
  1188. // reuse lines from above
  1189. $elements['payerRight'] = array('lines' => $lines,
  1190. 'attributes' => $this->getPayerRightAttr()
  1191. );
  1192. }
  1193. // Place code line
  1194. if ($this->getDisplayCodeLine()) {
  1195. $lines = array($this->paymentSlipData->getCodeLine($fillZeroes));
  1196. $elements['codeLine'] = array('lines' => $lines,
  1197. 'attributes' => $this->getCodeLineAttr()
  1198. );
  1199. }
  1200. return $elements;
  1201. }
  1202. }