generate-document.php 2.3 KB

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