printview.php.bak 12 KB

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