/linxone-beta/protected/modules/lbReport/views/default/pdf_saleReport.php

https://github.com/LinxHQ/linxbooks · PHP · 195 lines · 165 code · 30 blank · 0 comment · 12 complexity · dba8768d7444069061d1c5868496a612 MD5 · raw file

  1. <?php
  2. $thousand =LbGenera::model()->getGeneraSubscription()->lb_thousand_separator;
  3. $decimal= LbGenera::model()->getGeneraSubscription()->lb_decimal_symbol;
  4. $strnum = new LbInvoiceTotal();
  5. $method = LbPayment::model()->method;
  6. $date_from = date('Y-m-d');
  7. $date_to = date('Y-m-d', strtotime("+1 month -1 day"));
  8. $customer_id = false;
  9. if (isset($_REQUEST['search_date_from']) && $_REQUEST['search_date_from'] != "")
  10. $date_from = date('Y-m-d', strtotime($_REQUEST['search_date_from']));
  11. if (isset($_REQUEST['search_date_to']) && $_REQUEST['search_date_to'] != "")
  12. $date_to = date('Y-m-d', strtotime($_REQUEST['search_date_to']));
  13. if(isset($_REQUEST['customer']) && $_REQUEST['customer'] != 0)
  14. $customer_id = $_REQUEST['customer'];
  15. $a = LbInvoice::model()->getInvoiceMonth($customer_id,$date_from,$date_to);
  16. $PDFGst = '<table border="0" style="margin:auto;width:100%;" cellpadding="0" cellspacing="0">'
  17. . '<tr><td>
  18. <table border="0" style="margin:auto;width:100%;" cellpadding="0" cellspacing="0">
  19. <tr><td >
  20. <span style="font-size:20px;font-weight:bold;">Sales Report</span>
  21. </td></tr>
  22. </table>
  23. </td></tr>'
  24. . '<tr><td>
  25. <table border="0" style="margin:auto;width:100%;" cellpadding="0" cellspacing="0">
  26. <tr><td >
  27. <span style="margin:10px;padding:10px">From: '.$date_from.'</span>
  28. <span style="margin:10px;">To: '.$date_to.'</span>
  29. </td></tr>
  30. </table>
  31. </td></tr>'
  32. . '<tr><td>
  33. <table width="100%" class="items table table-bordered">
  34. <thead>
  35. <tr>
  36. <th width="80" class="lb-grid-header">'.Yii::t('lang','Date').'</th>
  37. <th width="100" class="lb-grid-header">'.Yii::t('lang','Number').'</th>
  38. <th width="100" class="lb-grid-header">'.Yii::t('lang','Customer').'</th>
  39. <th width="100" class="lb-grid-header">'.Yii::t('lang','Total').'</th>
  40. <th width="100" class="lb-grid-header">'.Yii::t('lang','Paid').'</th>
  41. <th width="100" class="lb-grid-header">'.Yii::t('lang','Amount').'</th>
  42. <th width="150" class="lb-grid-header">'.Yii::t('lang','Due').'</th>
  43. </tr>
  44. <tr></tr>
  45. </thead>
  46. ';
  47. if($customer_id > 0){
  48. $PDFGst .='<tbody>';
  49. $invoiceValue = 0;
  50. $AllPaid = 0;
  51. $invoiceDue = 0;
  52. foreach ($a as $data)
  53. {
  54. $customer_id = false;
  55. $invoice_information = LbInvoiceTotal::model()->getInvoiceById($data->lb_record_primary_key);
  56. $invoiceTax = LbInvoiceItem::model()->getInvoiceTaxById($data->lb_record_primary_key,"TAX");
  57. $PDFGst .= '<tr>';
  58. $PDFGst .= '<td>'.$data->lb_invoice_date.'</td>';
  59. $PDFGst .= '<td>'.$data->lb_invoice_no.'</td>';
  60. $PDFGst .= '<td>';
  61. if($data->lb_invoice_customer_id)
  62. {
  63. $customer_id = $data->lb_invoice_customer_id;
  64. $PDFGst .= LbCustomer::model()->customerInformation($customer_id)->attributes['lb_customer_name'];
  65. }
  66. $PDFGst .= '</td>';
  67. $invoiceValue = $invoiceValue+$invoice_information->lb_invoice_total_after_taxes;
  68. $PDFGst .= '<td>$'.$invoice_information->lb_invoice_total_after_taxes.'</td>';
  69. $PDFGst .= '<td>';
  70. $totalPaid = LbInvoiceTotal::model()->find('lb_invoice_id='. intval($data->lb_record_primary_key));
  71. $AllPaid = $AllPaid + $totalPaid->lb_invoice_total_paid;
  72. $PDFGst .= $totalPaid->lb_invoice_total_paid;
  73. $PDFGst .= '</td>';
  74. $PDFGst .= '<td>';
  75. $PDFGst .= $totalPaid->lb_invoice_total_paid;
  76. $PDFGst .= '</td>';
  77. $invoiceDue = $invoiceDue+$totalPaid->lb_invoice_total_outstanding;
  78. $PDFGst .= '<td>$'.$totalPaid->lb_invoice_total_outstanding.'</td>';
  79. $PDFGst .= '</tr>';
  80. }
  81. $PDFGst .= '</tbody>';
  82. $PDFGst .='<tfoot><tr>
  83. <td colspan="3"><b>Sub Total</b></td>
  84. <td align="right" style="border-top:1px solid #000">
  85. <b>$'.number_format($invoiceValue,2).'</b>
  86. </td>
  87. <td align="right" style="border-top:1px solid #000">
  88. <b>$'.number_format($AllPaid,2).'</b>
  89. </td>
  90. <td align="right" style="border-top:1px solid #000">
  91. <b>$'.number_format($AllPaid,2).'</b>
  92. </td>
  93. <td align="right" style="border-top:1px solid #000">
  94. <b> $'.number_format($invoiceDue,2).'</b>
  95. </td></tr>
  96. </tfoot>';
  97. }
  98. else
  99. {
  100. $PDFGst .='<tbody>';
  101. $customer_arr=LbCustomer::model()->getCompanies($sort = 'lb_customer_name ASC',
  102. LbCustomer::LB_QUERY_RETURN_TYPE_MODELS_ARRAY);
  103. $invoiceValue = 0;
  104. $AllPaid = 0;
  105. $invoiceDue = 0;
  106. foreach ($customer_arr as $customer)
  107. {
  108. $a = LbInvoice::model()->getInvoiceMonth($customer['lb_record_primary_key'],$date_from,$date_to);
  109. foreach ($a as $data)
  110. {
  111. $customer_id = false;
  112. $invoice_information = LbInvoiceTotal::model()->getInvoiceById($data->lb_record_primary_key);
  113. $invoiceTax = LbInvoiceItem::model()->getInvoiceTaxById($data->lb_record_primary_key,"TAX");
  114. $PDFGst .= '<tr>';
  115. $PDFGst .= '<td>'.$data->lb_invoice_date.'</td>';
  116. $PDFGst .= '<td>'.$data->lb_invoice_no.'</td>';
  117. $PDFGst .= '<td>';
  118. if($data->lb_invoice_customer_id)
  119. {
  120. $customer_id = $data->lb_invoice_customer_id;
  121. $PDFGst .= LbCustomer::model()->customerInformation($customer_id)->attributes['lb_customer_name'];
  122. }
  123. $PDFGst .= '</td>';
  124. $invoiceValue = $invoiceValue+$invoice_information->lb_invoice_total_after_taxes;
  125. $PDFGst .= '<td>$'.$invoice_information->lb_invoice_total_after_taxes.'</td>';
  126. $PDFGst .= '<td>';
  127. $totalPaid = LbInvoiceTotal::model()->find('lb_invoice_id='. intval($data->lb_record_primary_key));
  128. $AllPaid = $AllPaid + $totalPaid->lb_invoice_total_paid;
  129. $PDFGst .= $totalPaid->lb_invoice_total_paid;
  130. $PDFGst .= '</td>';
  131. $PDFGst .= '<td>';
  132. $PDFGst .= $totalPaid->lb_invoice_total_paid;
  133. $PDFGst .= '</td>';
  134. $invoiceDue = $invoiceDue+$totalPaid->lb_invoice_total_outstanding;
  135. $PDFGst .= '<td>$'.$totalPaid->lb_invoice_total_outstanding.'</td>';
  136. $PDFGst .= '</tr>';
  137. }
  138. }
  139. $PDFGst .= '</tbody>';
  140. $PDFGst .='<tfoot><tr>
  141. <td colspan="3"><b>Sub Total</b></td>
  142. <td align="right" style="border-top:1px solid #000">
  143. <b>$'.number_format($invoiceValue,2).'</b>
  144. </td>
  145. <td align="right" style="border-top:1px solid #000">
  146. <b>$'.number_format($AllPaid,2).'</b>
  147. </td>
  148. <td align="right" style="border-top:1px solid #000">
  149. <b>$'.number_format($AllPaid,2).'</b>
  150. </td>
  151. <td align="right" style="border-top:1px solid #000">
  152. <b> $'.number_format($invoiceDue,2).'</b>
  153. </td></tr>
  154. </tfoot>';
  155. }
  156. $PDFGst .='
  157. </table>
  158. </td></tr>'
  159. . '</table>';
  160. echo $PDFGst;
  161. ?>