PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/customer/A2B_invoice_view.php

https://github.com/hellbound/a2billing-mod
PHP | 301 lines | 259 code | 12 blank | 30 comment | 5 complexity | 0ccc26b7784091cf0eeb2ba81dff3662 MD5 | raw file
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * This file is part of A2Billing (http://www.a2billing.net/)
  5. *
  6. * A2Billing, Commercial Open Source Telecom Billing platform,
  7. * powered by Star2billing S.L. <http://www.star2billing.com/>
  8. *
  9. * @copyright Copyright (C) 2004-2009 - Star2billing S.L.
  10. * @author Belaid Arezqui <areski@gmail.com>
  11. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html
  12. * @package A2Billing
  13. *
  14. * Software License Agreement (GNU Affero General Public License)
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License as
  18. * published by the Free Software Foundation, either version 3 of the
  19. * License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. *
  29. *
  30. **/
  31. include ("./lib/customer.defines.php");
  32. include ("./lib/customer.module.access.php");
  33. include ("./lib/customer.smarty.php");
  34. include ("./lib/support/classes/invoice.php");
  35. include ("./lib/support/classes/invoiceItem.php");
  36. if (! has_rights (ACX_INVOICES)) {
  37. Header ("HTTP/1.0 401 Unauthorized");
  38. Header ("Location: PP_error.php?c=accessdenied");
  39. die();
  40. }
  41. getpost_ifset(array('id'));
  42. if (empty($id)) {
  43. Header ("Location: A2B_entity_invoice.php?atmenu=payment&section=13");
  44. }
  45. $invoice = new invoice($id);
  46. if($invoice->getCard() != $_SESSION["card_id"]) {
  47. Header ("HTTP/1.0 401 Unauthorized");
  48. Header ("Location: PP_error.php?c=accessdenied");
  49. die();
  50. }
  51. $items = $invoice->loadItems();
  52. //load customer
  53. $DBHandle = DbConnect();
  54. $card_table = new Table('cc_card','*');
  55. $card_clause = "id = ".$_SESSION["card_id"];
  56. $card_result = $card_table -> Get_list($DBHandle, $card_clause, 0);
  57. $card = $card_result[0];
  58. if (empty($card)) {
  59. echo "Customer doesn't exist or is not correctly defined for this invoice !";
  60. die();
  61. }
  62. $smarty->display('main.tpl');
  63. //Load invoice conf
  64. $invoice_conf_table = new Table('cc_invoice_conf','value');
  65. $conf_clause = "key_val = 'company_name'";
  66. $result = $invoice_conf_table -> Get_list($DBHandle, $conf_clause, 0);
  67. $company_name = $result[0][0];
  68. $conf_clause = "key_val = 'address'";
  69. $result = $invoice_conf_table -> Get_list($DBHandle, $conf_clause, 0);
  70. $address = $result[0][0];
  71. $conf_clause = "key_val = 'zipcode'";
  72. $result = $invoice_conf_table -> Get_list($DBHandle, $conf_clause, 0);
  73. $zipcode = $result[0][0];
  74. $conf_clause = "key_val = 'city'";
  75. $result = $invoice_conf_table -> Get_list($DBHandle, $conf_clause, 0);
  76. $city = $result[0][0];
  77. $conf_clause = "key_val = 'country'";
  78. $result = $invoice_conf_table -> Get_list($DBHandle, $conf_clause, 0);
  79. $country = $result[0][0];
  80. $conf_clause = "key_val = 'web'";
  81. $result = $invoice_conf_table -> Get_list($DBHandle, $conf_clause, 0);
  82. $web = $result[0][0];
  83. $conf_clause = "key_val = 'phone'";
  84. $result = $invoice_conf_table -> Get_list($DBHandle, $conf_clause, 0);
  85. $phone = $result[0][0];
  86. $conf_clause = "key_val = 'fax'";
  87. $result = $invoice_conf_table -> Get_list($DBHandle, $conf_clause, 0);
  88. $fax = $result[0][0];
  89. $conf_clause = "key_val = 'email'";
  90. $result = $invoice_conf_table -> Get_list($DBHandle, $conf_clause, 0);
  91. $email = $result[0][0];
  92. $conf_clause = "key_val = 'vat'";
  93. $result = $invoice_conf_table -> Get_list($DBHandle, $conf_clause, 0);
  94. $vat_invoice = $result[0][0];
  95. $conf_clause = "key_val = 'display_account'";
  96. $result = $invoice_conf_table -> Get_list($DBHandle, $conf_clause, 0);
  97. $display_account = $result[0][0];
  98. //country convert
  99. $table_country= new Table('cc_country','countryname');
  100. $country_clause = "countrycode = '".$card['country']."'";
  101. $result = $table_country -> Get_list($DBHandle, $country_clause, 0);
  102. $card_country = $result[0][0];
  103. //Currencies check
  104. $curr = $card['currency'];
  105. $currencies_list = get_currencies();
  106. if (!isset($currencies_list[strtoupper($curr)][2]) || !is_numeric($currencies_list[strtoupper($curr)][2])) {$mycur = 1;$display_curr=strtoupper(BASE_CURRENCY);}
  107. else {$mycur = $currencies_list[strtoupper($curr)][2];$display_curr=strtoupper($curr);}
  108. function amount_convert($amount){
  109. global $mycur;
  110. return $amount/$mycur;
  111. }
  112. if(!$popup_select){
  113. ?>
  114. <a href="javascript:;" onClick="MM_openBrWindow('<?php echo $PHP_SELF ?>?popup_select=1&id=<?php echo $id ?>','','scrollbars=yes,resizable=yes,width=700,height=500')" > <img src="./templates/default/images/printer.png" title="Print" alt="Print" border="0"></a>
  115. &nbsp;&nbsp;
  116. <?php
  117. } else {
  118. ?>
  119. <P ALIGN="right"> <a href="javascript:window.print()"> <img src="./templates/default/images/printer.png" title="Print" alt="Print" border="0"> <?php echo gettext("Print"); ?></a> &nbsp; &nbsp;</P>
  120. <?php
  121. }
  122. ?>
  123. <div class="invoice-wrapper">
  124. <table class="invoice-table">
  125. <thead>
  126. <tr class="one">
  127. <td class="one">
  128. <h1><?php echo gettext("INVOICE"); ?></h1>
  129. <div class="client-wrapper">
  130. <div class="company-name break"><?php echo $card['company_name'] ?></div>
  131. <div class="fullname"><?php echo $card['lastname']." ".$card['firstname'] ?></div>
  132. <div class="address"><span class="street"><?php echo $card['address'] ?></span> </div>
  133. <div class="zipcode-city"><span class="zipcode"><?php echo $card['zipcode'] ?></span> <span class="city"><?php echo $card['city'] ?></span></div>
  134. <div class="country break"><?php echo $card_country ?></div>
  135. <?php if(!empty($card['VAT_RN'])){ ?>
  136. <div class="vat-number"><?php echo gettext("VAT nr.")." : ".$card['VAT_RN']; ?></div>
  137. <?php } ?>
  138. </div>
  139. </td>
  140. <td class="two">
  141. </td>
  142. <td class="three">
  143. <div class="supplier-wrapper">
  144. <div class="company-name"><?php echo $company_name ?></div>
  145. <div class="address"><span class="street"><?php echo $address ?></span> </div>
  146. <div class="zipcode-city"><span class="zipcode"><?php echo $zipcode ?></span> <span class="city"><?php echo $city ?></span></div>
  147. <div class="country break"><?php echo $country ?></div>
  148. <div class="phone"><?php echo gettext("tel").": ".$phone ?></div>
  149. <div class="fax"><?php echo gettext("fax").": ".$fax ?> </div>
  150. <div class="email"><?php echo gettext("mail").": ".$email ?></div>
  151. <div class="web"><?php echo $web ?></div>
  152. <div class="vat-number"><?php echo gettext("VAT nr.")." : ".$vat_invoice; ?></div>
  153. </div>
  154. </td>
  155. </tr>
  156. <tr class="two">
  157. <td colspan="3" class="invoice-details">
  158. <br/>
  159. <table class="invoice-details">
  160. <tbody><tr>
  161. <td class="one">
  162. <strong><?php echo gettext("Date"); ?></strong>
  163. <div><?php echo $invoice->getDate() ?></div>
  164. </td>
  165. <td class="two">
  166. <strong><?php echo gettext("Invoice number"); ?></strong>
  167. <div><?php echo $invoice->getReference() ?></div>
  168. </td>
  169. <?php if($display_account==1){ ?>
  170. <td class="three">
  171. <strong><?php echo gettext("Client Account Number"); ?></strong>
  172. <div><?php echo $card['username'] ?></div>
  173. </td>
  174. <?php } ?>
  175. </tr>
  176. </tbody></table>
  177. </td>
  178. </tr>
  179. </thead>
  180. <tbody>
  181. <tr>
  182. <td colspan="3" class="items">
  183. <table class="items">
  184. <tbody>
  185. <tr class="one">
  186. <th style="text-align:left;"><?php echo gettext("Date"); ?></th>
  187. <th class="description"><?php echo gettext("Description"); ?></th>
  188. <th><?php echo gettext("Cost excl. VAT"); ?></th>
  189. <th><?php echo gettext("VAT"); ?></th>
  190. <th><?php echo gettext("Cost incl. VAT"); ?></th>
  191. </tr>
  192. <?php
  193. $i=0;
  194. foreach ($items as $item){ ?>
  195. <tr style="vertical-align:top;" class="<?php if($i%2==0) echo "odd"; else echo "even";?>" >
  196. <td style="text-align:left;">
  197. <?php echo $item->getDate(); ?>
  198. </td>
  199. <td class="description">
  200. <?php echo $item->getDescription(); ?>
  201. </td>
  202. <td align="right">
  203. <?php echo number_format(round(amount_convert($item->getPrice()),2),2); ?>
  204. </td>
  205. <td align="right">
  206. <?php echo number_format(round($item->getVAT(),2),2)."%"; ?>
  207. </td>
  208. <td align="right">
  209. <?php echo number_format(round(amount_convert($item->getPrice())*(1+($item->getVAT()/100)),2),2); ?>
  210. </td>
  211. </tr>
  212. <?php $i++;} ?>
  213. </tbody></table>
  214. </td>
  215. </tr>
  216. <?php
  217. $price_without_vat = 0;
  218. $price_with_vat = 0;
  219. $vat_array = array();
  220. foreach ($items as $item){
  221. $price_without_vat = $price_without_vat + $item->getPrice();
  222. $price_with_vat = $price_with_vat + ($item->getPrice()*(1+($item->getVAT()/100)));
  223. if(array_key_exists("".$item->getVAT(),$vat_array)){
  224. $vat_array[$item->getVAT()] = $vat_array[$item->getVAT()] + $item->getPrice()*($item->getVAT()/100) ;
  225. }else{
  226. $vat_array[$item->getVAT()] = $item->getPrice()*($item->getVAT()/100) ;
  227. }
  228. }
  229. ?>
  230. <tr>
  231. <td colspan="3">
  232. <table class="total">
  233. <tbody><tr class="extotal">
  234. <td class="one"></td>
  235. <td class="two"><?php echo gettext("Subtotal excl. VAT:"); ?></td>
  236. <td class="three"><?php echo number_format(round(amount_convert($price_without_vat)*100)/100,2)." $display_curr"; ?></td>
  237. </tr>
  238. <?php foreach ($vat_array as $key => $val) { ?>
  239. <tr class="vat">
  240. <td class="one"></td>
  241. <td class="two"><?php echo gettext("VAT")."$key%:"; ?></td>
  242. <td class="three"><?php echo number_format(round(amount_convert($val),2),2)." $display_curr"; ?></td>
  243. </tr>
  244. <?php } ?>
  245. <tr class="inctotal">
  246. <td class="one"></td>
  247. <td class="two"><?php echo gettext("Total incl. VAT:") ?></td>
  248. <td class="three"><div class="inctotal"><div class="inctotal inner"><?php echo number_format(round(amount_convert($price_with_vat)*100)/100,2)." $display_curr"; ?></div></div></td>
  249. </tr>
  250. </tbody></table>
  251. </td>
  252. </tr>
  253. <tr>
  254. <td colspan="3" class="additional-information">
  255. <div class="invoice-description">
  256. <?php echo $invoice->getDescription() ?>
  257. </div></td>
  258. </tr>
  259. </tbody>
  260. <tfoot>
  261. <tr>
  262. <td colspan="3" class="footer">
  263. <?php echo $company_name." | ".$address.", ".$zipcode." ".$city." ".$country." | VAT nr.".$vat_invoice; ?>
  264. </td>
  265. </tr>
  266. </tfoot>
  267. </table></div>