generate-document.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/php
  2. <?php
  3. require_once dirname(__FILE__) . '/../../common.php';
  4. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  5. $phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME)
  6. ->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
  7. /*
  8. * ALTERNATIVE: Specify username and password in constructor
  9. */
  10. /*
  11. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(
  12. array (
  13. 'username' => Demos_Zend_Service_LiveDocx_Helper::USERNAME,
  14. 'password' => Demos_Zend_Service_LiveDocx_Helper::PASSWORD
  15. )
  16. );
  17. */
  18. $phpLiveDocx->setLocalTemplate('template.doc');
  19. $phpLiveDocx->assign('customer_number', sprintf("#%'10s", rand(0,1000000000)))
  20. ->assign('invoice_number', sprintf("#%'10s", rand(0,1000000000)))
  21. ->assign('account_number', sprintf("#%'10s", rand(0,1000000000)));
  22. $billData = array (
  23. 'phone' => '+22 (0)333 444 555',
  24. 'date' => Zend_Date::now()->toString(Zend_Date::DATE_LONG),
  25. 'name' => 'James Henry Brown',
  26. 'service_phone' => '+22 (0)333 444 559',
  27. 'service_fax' => '+22 (0)333 444 558',
  28. 'month' => sprintf('%s %s', Zend_Date::now()->toString(Zend_Date::MONTH_NAME),
  29. Zend_Date::now()->toString(Zend_Date::YEAR)),
  30. 'monthly_fee' => '15.00',
  31. 'total_net' => '19.60',
  32. 'tax' => '19.00',
  33. 'tax_value' => '3.72',
  34. 'total' => '23.32'
  35. );
  36. $phpLiveDocx->assign($billData);
  37. $billConnections = array(
  38. array(
  39. 'connection_number' => '+11 (0)222 333 441',
  40. 'connection_duration' => '00:01:01',
  41. 'fee' => '1.15'
  42. ),
  43. array(
  44. 'connection_number' => '+11 (0)222 333 442',
  45. 'connection_duration' => '00:01:02',
  46. 'fee' => '1.15'
  47. ),
  48. array(
  49. 'connection_number' => '+11 (0)222 333 443',
  50. 'connection_duration' => '00:01:03',
  51. 'fee' => '1.15'
  52. ),
  53. array(
  54. 'connection_number' => '+11 (0)222 333 444',
  55. 'connection_duration' => '00:01:04',
  56. 'fee' => '1.15'
  57. )
  58. );
  59. $phpLiveDocx->assign('connection', $billConnections);
  60. $documentProperties = array (
  61. 'title' => sprintf('Telephone Invoice (%s)', $billData['name']),
  62. 'author' => 'TIS Telecom',
  63. 'subject' => sprintf('Your telephone invoice for %s', $billData['month']),
  64. 'keywords' => sprintf('Telephone, Payment, Invoice, %s', $billData['month'])
  65. );
  66. $phpLiveDocx->setDocumentProperties($documentProperties);
  67. $phpLiveDocx->createDocument();
  68. $document = $phpLiveDocx->retrieveDocument('pdf');
  69. unset($phpLiveDocx);
  70. file_put_contents('document.pdf', $document);