printview.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. require '../../../main.inc.php';
  3. require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
  4. require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
  5. require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php';
  6. require_once DOL_DOCUMENT_ROOT . '/core/lib/invoice.lib.php';
  7. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  8. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/bbticketinvoiceprinting.class.php';
  9. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/bbticketnaplo.class.php';
  10. require_once DOL_DOCUMENT_ROOT . '/core/modules/facture/doc/pdf_crabe_new_printinginvoice.modules.php';
  11. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/bbticketcounter.class.php';
  12. if (isModEnabled('project')) {
  13. require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
  14. }
  15. global $db, $conf;
  16. $statuses = array("OK", "Lejárt", "Érvénytelen");
  17. // Load translation files required by the page
  18. $langs->loadLangs(array('bills', 'companies'));
  19. $id = (GETPOST('id') ? GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
  20. $ref = GETPOST('ref', 'alpha');
  21. $lineid = GETPOST('lineid', 'int');
  22. $socid = GETPOST('socid', 'int');
  23. $action = GETPOST('action', 'aZ09');
  24. $timestamp = GETPOST('timestamp', 'alpha');
  25. $Bbticketcounter = new Bbticketcounter();
  26. //print_r($_REQUEST);
  27. // Kikeresem a facture_id-hoz tartozó jegyeket a llx_bbus_bbticketinvoiceprinting táblából. Osszekotni: user, jegy adatok (bbticket), hol hasznaltak
  28. $res = getBbticketinvoiceprinting($id);
  29. // Security check
  30. if ($user->socid) {
  31. $socid = $user->socid;
  32. }
  33. $object = new Facture($db);
  34. // Load object
  35. if ($id > 0 || !empty($ref)) {
  36. $ret = $object->fetch($id, $ref, '', '', (!empty($conf->global->INVOICE_USE_SITUATION) ? $conf->global->INVOICE_USE_SITUATION : 0));
  37. }
  38. $result = restrictedArea($user, 'facture', $object->id);
  39. /*
  40. * View
  41. */
  42. $title = $langs->trans('InvoiceCustomer') . " - " . $langs->trans('ContactsAddresses');
  43. $helpurl = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
  44. llxHeader('', $title, $helpurl);
  45. $form = new Form($db);
  46. $formcompany = new FormCompany($db);
  47. $contactstatic = new Contact($db);
  48. $userstatic = new User($db);
  49. $PDF_Crabe = new pdf_crabe_new_printinginvoice($db);
  50. function getBbticketinvoiceprinting($id)
  51. {
  52. global $db;
  53. $bbticketinvoiceprinting = new BbTicketInvoicePrinting($db);
  54. $sql = "SELECT product.label, ticket.available_at, ticket.validated_at, ticket.expire_at, ticket.usable_occasions, ticket.usage, tip.date_creation, tip.ticket_id, ticket.bundle_id, ticket.ticket_id as product_id, tip.printing_date, usr.lastname, usr.firstname
  55. FROM " . $db->prefix() . $bbticketinvoiceprinting->table_element . " AS tip
  56. INNER JOIN llx_user as usr ON tip.fk_user_creat = usr.rowid
  57. INNER JOIN llx_bbus_bbticket as ticket ON tip.ticket_id = ticket.rowid
  58. INNER JOIN llx_product AS product ON ticket.ticket_id = product.rowid
  59. WHERE tip.fk_facture = {$id}";
  60. //print $sql;
  61. return $db->query($sql);
  62. }
  63. function getTicketnaploByTicketId($id)
  64. {
  65. global $db;
  66. $bbticketNaplo = new BbTicketNaplo($db);
  67. $sql = "SELECT
  68. loc.location_name,
  69. loc.available_services,
  70. naplo.date_creation AS naplo_date_creation,
  71. naplo.status,
  72. devices.device_name,
  73. devices.device_function,
  74. devices.device_type,
  75. devices.ref
  76. FROM
  77. " . $db->prefix() . $bbticketNaplo->table_element . " as naplo
  78. LEFT JOIN llx_bbus_bbdevices AS devices ON naplo.device_id = devices.rowid AND naplo.device_id IS NOT NULL
  79. LEFT JOIN llx_bbus_bbdevicesservicelocation as ds ON ds.rowid = naplo.bbservicelocation_id
  80. LEFT JOIN llx_bbus_bbservicelocation AS loc ON ds.service_location_id = loc.rowid AND naplo.bbservicelocation_id IS NOT NULL
  81. WHERE
  82. ticket_row_id = {$id} ORDER BY naplo_date_creation DESC";
  83. return $db->query($sql);
  84. }
  85. function getQRcode($facture_id, $ticket_id)
  86. {
  87. global $db;
  88. $sql = "SELECT bbti.printing_date_timestamp AS timestamp FROM llx_bbus_bbticketinvoiceprinting AS bbti
  89. INNER JOIN llx_facture as f ON f.rowid = bbti.fk_facture
  90. WHERE bbti.fk_facture = {$facture_id}
  91. AND bbti.ticket_id = {$ticket_id}";
  92. $result = $db->query($sql);
  93. if (pg_num_rows($result) > 0) {
  94. $data = pg_fetch_assoc($result);
  95. return $data['timestamp'];
  96. }
  97. return '';
  98. }
  99. function createPDFButton($id, $ticket_id)
  100. {
  101. global $langs;
  102. $string = '';
  103. $QRCode = getQRcode($id, $ticket_id);
  104. if ($QRCode != '') {
  105. $string = '<a href="/custom/bbus/views/printview.php?id=' . $id . '&timestamp=' . $QRCode . '" name="timestamp">' . $langs->trans('GenerateInvoice') . '</a>';
  106. }
  107. return $string;
  108. }
  109. if ($timestamp !== '') {
  110. $result = $PDF_Crabe->write_file($object, $timestamp, $langs);
  111. if ($result == 1) {
  112. setEventMessage($langs->trans('InvoiceReady'));
  113. } else {
  114. setEventMessage($langs->trans('InvoiceFailed'), 'error');
  115. }
  116. }
  117. function setColor($status)
  118. {
  119. return $status == 0 ? 'green' : 'red';
  120. }
  121. /* *************************************************************************** */
  122. /* */
  123. /* View and edit mode */
  124. /* */
  125. /* *************************************************************************** */
  126. if ($id > 0 || !empty($ref)) {
  127. if ($object->fetch($id, $ref) > 0) {
  128. $object->fetch_thirdparty();
  129. $head = facture_prepare_head($object);
  130. $totalpaid = $object->getSommePaiement();
  131. print dol_get_fiche_head($head, 'tickets', $langs->trans('InvoiceCustomer'), -1, 'bill');
  132. print '<input type="hidden" id="printedTicketsNumber" name="printedticketsnumber" value="' . $Bbticketcounter->numberOfPrintedTickets . '">';
  133. // Invoice content
  134. $linkback = '<a href="' . DOL_URL_ROOT . '/compta/facture/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  135. $morehtmlref = '<div class="refidno">';
  136. // Ref customer
  137. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  138. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  139. // Thirdparty
  140. $morehtmlref .= '<br>' . $langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1, 'customer');
  141. $morehtmlref .= '</div>';
  142. $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  143. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  144. $content = '';
  145. $content .= '<table class="centpercent noborder listaction">';
  146. $content .= '<tr class="liste_titre">';
  147. $content .= '<th class="wrapcolumntitle liste_titre">' . $langs->trans('TicketId') . '</th>';
  148. $content .= '<th class="wrapcolumntitle liste_titre">' . $langs->trans('TicketLabel') . '</th>';
  149. $content .= '<th class="wrapcolumntitle liste_titre">' . $langs->trans('PrintingDate') . '</th>';
  150. $content .= '<th class="wrapcolumntitle liste_titre">' . $langs->trans('PrintingUser') . '</th>';
  151. $content .= '<th class="wrapcolumntitle liste_titre">' . $langs->trans('validated_at') . '</th>';
  152. $content .= '<th class="wrapcolumntitle liste_titre">' . $langs->trans('expire_at') . '</th>';
  153. $content .= '<th class="wrapcolumntitle liste_titre">' . $langs->trans('available_at') . '</th>';
  154. $content .= '<th class="wrapcolumntitle liste_titre">PDF</th>';
  155. $content .= '<th class="wrapcolumntitle liste_titre"></th>';
  156. $content .= '</tr>';
  157. while ($row = pg_fetch_assoc($res)) {
  158. $ticketNaploResults = getTicketnaploByTicketId($row['ticket_id']);
  159. $PDFButton = createPDFButton($id, $row['ticket_id']);
  160. $content .= '<tr class="oddeven">';
  161. $content .= '<td class="tdoverflowmax100">' . $row['ticket_id'] . '</td>';
  162. $content .= '<td class="tdoverflowmax200">' . $row['label'] . '</td>';
  163. $content .= '<td class="tdoverflowmax100">' . $row['printing_date'] . '</td>';
  164. $content .= '<td class="tdoverflowmax100">' . $row['lastname'] . ' ' . $row['firstname'] . '</td>';
  165. $content .= '<td class="tdoverflowmax100">' . $row['validated_at'] . '</td>';
  166. $content .= '<td class="tdoverflowmax100">' . $row['expire_at'] . '</td>';
  167. $content .= '<td class="tdoverflowmax100">' . $row['available_at'] . '</td>';
  168. $content .= '<td class="tdoverflowmax100">' . $PDFButton . '</td>';
  169. $content .= '<td class="tdoverflowmax10 fa fa-chevron-down padding-left5" id="arrow_' . $row['ticket_id'] . '" onClick="myFunction(' . $row['ticket_id'] . ')" style="cursor:pointer;"></td>';
  170. $content .= '</tr>';
  171. $content .= '<tr id="hidden_' . $row['ticket_id'] . '" style="display:none;"><td colspan="7">';
  172. if (pg_num_rows($ticketNaploResults) == 0) {
  173. $content .= '<div style="width:100%; height:50px; margin-top:20px; text-align: center;">Nincs adat. A jegy még nem volt használva.</div>';
  174. } else {
  175. $content .= '<div style="width:100%; text-align: center; height:40px; margin-top:10px;">JEGYHASZNÁLAT</div>';
  176. $content .= '<table class="centpercent noborder listaction">';
  177. $content .= '<tr class="liste_titre">';
  178. $content .= '<th class="wrapcolumntitle liste_titre">Használat időpontja</th>';
  179. $content .= '<th class="wrapcolumntitle liste_titre">Eszköz</th>';
  180. $content .= '<th class="wrapcolumntitle liste_titre">Helyszín</th>';
  181. $content .= '<th class="wrapcolumntitle liste_titre">Státusz</th>';
  182. $content .= '</tr>';
  183. while ($result = pg_fetch_assoc($ticketNaploResults)) {
  184. $deviceString = !is_null($result['device_name']) ? $result['device_name'] : 'Mobilephone';
  185. $locationString = !is_null($result['location_name']) ? $result['location_name'] . '(' . $result['available_services'] . ')' : 'Validated by mobilephone';
  186. $content .= '<tr class="oddeven">';
  187. $content .= '<td class="tdoverflowmax100">' . $result['naplo_date_creation'] . '</td>';
  188. $content .= '<td class="tdoverflowmax100">' . $deviceString . '</td>';
  189. $content .= '<td class="tdoverflowmax100">' . $locationString . '</td>';
  190. $content .= '<td class="tdoverflowmax100" style="color:' . setColor($result['status']) . ';">' . $statuses[$result['status']] . '</td>';
  191. $content .= '</tr>';
  192. }
  193. $content .= '</table>';
  194. }
  195. $content .= '</td></tr>';
  196. }
  197. $content .= '</table>';
  198. print $content;
  199. print dol_get_fiche_end();
  200. } else {
  201. // Record not found
  202. print "ErrorRecordNotFound";
  203. }
  204. }
  205. // End of page
  206. llxFooter();
  207. $db->close();
  208. ?>
  209. <link rel="stylesheet" type="text/css" href="/custom/bbus/views/bbus.css">
  210. <script src="/custom/bbus/js/bbus.js"></script>;