Guest User

Untitled

a guest
Jul 18th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.71 KB | None | 0 0
  1. function generatePrintableInvoice($challanId)
  2. {
  3. $db = $GLOBALS['ISC_CLASS_DB'];
  4.  
  5. $template = new TEMPLATE('ISC_LANG');
  6. $template->frontEnd();
  7. $template->setTemplateBase(ISC_BASE_PATH . "/templates");
  8. $template->panelPHPDir = ISC_BASE_PATH . "/includes/display/";
  9. $template->templateExt = "html";
  10. $template->setTemplate(getConfig("template"));
  11.  
  12. //[anand.6756@gmail.com]
  13. $GLOBALS['ISC_CLASS_ADMIN_ENGINE']->LoadLangFile('challans');
  14. $query = "
  15. SELECT o.compname AS comname, o.compemail AS comemail, o.compaddress AS comaddress,o.complogo AS comlogo,o.compphone AS comphone,o.compfax AS comfax
  16. FROM [|PREFIX|]company o
  17. LEFT JOIN [|PREFIX|]challans c ON o.companyid = c.companyid
  18. WHERE c.challanid = '".(int)$challanId."'
  19. ";
  20. $result = $db->Query($query);
  21. $row = $db->Fetch($result);
  22. $template->assign('CompanyName',$row['comname']);
  23. $template->assign('CompanyAddress',$row['comaddress']);
  24. $template->assign('CompanyEmail',$row['comemail']);
  25. $template->assign('CompanyLogo',$row['comlogo']);
  26. $template->assign('CompanyPhone',$row['comphone']);
  27. $template->assign('CompanyFax',$row['comfax']);
  28.  
  29.  
  30.  
  31. //$template->assign('HeaderLogo', fetchHeaderLogo());
  32.  
  33. //$template->assign('StoreAddressFormatted', nl2br(getConfig('StoreAddress')));
  34.  
  35. $query = "
  36. SELECT o.*, CONCAT(c.custconfirstname, ' ', c.custconlastname) AS ordcustname, c.custconemail AS ordcustemail, c.custconphone AS ordcustphone
  37. FROM [|PREFIX|]challans o
  38. LEFT JOIN [|PREFIX|]customers c ON o.ordcustid = c.customerid
  39. WHERE o.challanid = '".(int)$challanId."'
  40. ";
  41.  
  42. $result = $db->Query($query);
  43. $row = $db->Fetch($result);
  44.  
  45. if(!$row) {
  46. return false;
  47. }
  48.  
  49. $template->assign('ChallanId', $row['challanid']);
  50. $template->assign('ChallanDate', cDate($row['orddate']));
  51.  
  52. if($row['ordcustmessage']) {
  53. $template->assign('Comments', nl2br(isc_html_escape($row['ordcustmessage'])));
  54. }
  55. else {
  56. $template->assign('HideComments', 'display: none');
  57. }
  58.  
  59. $template->assign('InvoiceTitle', sprintf(getLang('InvoiceTitle'), $challanId));
  60. $template->assign('ItemCost', currencyConvertFormatPrice($row['ordsubtotal'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate'], true ));
  61. if($row['ordshipcost']) {
  62. $template->assign('ShippingCost', currencyConvertFormatPrice($row['ordshipcost'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate' ], true));
  63. }
  64. else {
  65. $template->assign('HideShippingCost', 'display: none');
  66. }
  67. // Is there a handling fee?
  68. if ($row['ordhandlingcost'] > 0) {
  69. $template->assign('HandlingCost', currencyConvertFormatPrice($row['ordhandlingcost'], $row['ordcurrencyid'], $row[ 'ordcurrencyexchangerate'], true));
  70. }
  71. else {
  72. $template->assign('HideHandlingCost', 'display: none');
  73. }
  74.  
  75. // Is there any sales tax?
  76. if($row['ordtaxtotal'] > 0) {
  77. if($row['ordtaxname']) {
  78. $template->assign('SalesTaxName', isc_html_escape($row['ordtaxname']));
  79. }
  80. else {
  81. $template->assign('SalesTaxName', getLang('InvoiceSalesTax'));
  82. }
  83.  
  84. if($row['ordtotalincludestax']) {
  85. $template->assign('HideSalesTax', 'none');
  86. $template->assign('SalesTaxName', isc_html_escape($row['ordtaxname']) . ' ' . getLang('IncludedInTotal'));
  87. }
  88. else {
  89. $template->assign('HideSalesTaxIncluded', 'none');
  90. }
  91. $template->assign('SalesTax', currencyConvertFormatPrice($row['ordtaxtotal'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate'], true));
  92. }
  93. else {
  94. $template->assign('HideSalesTax', 'none');
  95. $template->assign('HideSalesTaxIncluded', 'none');
  96. }
  97.  
  98. $template->assign('TotalCost', currencyConvertFormatPrice($row['ordtotalamount'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate'], true));
  99.  
  100. // Format the customer details
  101. if($row['ordcustid'] == 0) {
  102. $template->assign('HideCustomerDetails', 'display: none');
  103. }
  104. $template->assign('CustomerId', $row['ordcustid']);
  105. $template->assign('CustomerName', isc_html_escape($row['ordcustname']));
  106. $template->assign('CustomerEmail', $row['ordcustemail']);
  107. $template->assign('CustomerPhone', $row['ordcustphone']);
  108.  
  109. // Format the billing address
  110. $template->assign('ShipFullName', isc_html_escape($row['ordbillfirstname'].' '.$row['ordbilllastname']));
  111.  
  112. if($row['ordbillcompany']) {
  113. $template->assign('ShipCompany', '<br />'.isc_html_escape($row['ordbillcompany']));
  114. }
  115. else {
  116. $template->assign('ShipCompany', '');
  117. }
  118.  
  119. $addressLine = isc_html_escape($row['ordbillstreet1']);
  120. if ($row['ordbillstreet2'] != "") {
  121. $addressLine .= '<br />' . isc_html_escape($row['ordbillstreet2']);
  122. }
  123. $template->assign('ShipAddressLines', $addressLine);
  124.  
  125. $template->assign('ShipSuburb', isc_html_escape($row['ordbillsuburb']));
  126. $template->assign('ShipState', isc_html_escape($row['ordbillstate']));
  127. $template->assign('ShipZip', isc_html_escape($row['ordbillzip']));
  128. //$template->assign('ShipCountry', isc_html_escape($row['ordbillcountry']));
  129. $template->assign('BillingAddress', $template->getSnippet('AddressLabel'));
  130.  
  131. $query = "
  132. SELECT ordprodname
  133. FROM [|PREFIX|]challan_products
  134. WHERE challanchallanid='".(int)$challanId."'
  135. ";
  136. $res3 = $db->query($query);
  137. $count=0;
  138. while($prod = $db->fetch($res3))
  139. {
  140. $count++;
  141. }
  142.  
  143.  
  144. $query = "
  145. SELECT *
  146. FROM [|PREFIX|]challan_products
  147. WHERE challanchallanid='".(int)$challanId."'
  148. ";
  149.  
  150. $result = $db->query($query);
  151. /*$product = $db->fetch($result);
  152. $count=count($product['ordprodname']);
  153. echo $count;
  154. */
  155.  
  156.  
  157. $productsTable = '';
  158. $wrappingTotal = 0;
  159. $sno=1;
  160. while($product = $db->fetch($result)) {
  161.  
  162.  
  163.  
  164. $template->assign('Serialnumber',$sno);
  165.  
  166. $template->assign('ProductName', isc_html_escape($product['ordprodname']));
  167.  
  168.  
  169. if($product['ordprodsku']) {
  170. $template->assign('ProductSku', isc_html_escape($product['ordprodsku']));
  171. }
  172. else {
  173. $template->assign('ProductSku', getLang('NA'));
  174. }
  175. $template->assign('ProductQuantity', $product['ordprodqty']);
  176. $template->assign('Discount',$product['discountpercentprod']);
  177.  
  178.  
  179. $query = "
  180. SELECT o.currencystring
  181. FROM [|PREFIX|]currencies o
  182. LEFT JOIN [|PREFIX|]challans c ON o.currencyid = c.ordcurrencyid
  183. WHERE c.challanid = '".(int)$challanId."'
  184. ";
  185. $res = $db->Query($query);
  186.  
  187. while($currencystring = $db->Fetch($res)) {
  188. $template->assign('Currency',$currencystring['currencystring']);
  189. }
  190.  
  191. $query="
  192. SELECT b.brandname
  193. FROM brands b
  194. LEFT JOIN [|PREFIX|]products p ON p.prodbrandid=b.brandid
  195. LEFT JOIN [|PREFIX|]challan_products c ON c.ordprodid=p.productid
  196. WHERE c.challanchallanid='".(int)$challanId."'
  197. ";
  198. $res2=$db->Query($query);
  199. $brandname=$db->Fetch($res2);
  200. while($brandname=$db->Fetch($res2)) {
  201. $template->assign('BrandName',$brandname['brandname']);
  202. }
  203.  
  204. $pOptions = '';
  205. if($product['ordprodoptions'] != '') {
  206. $options = @unserialize($product['ordprodoptions']);
  207. if(!empty($options)) {
  208. foreach($options as $name => $value) {
  209. $template->assign('FieldName', isc_html_escape($name));
  210. $template->assign('FieldValue', isc_html_escape($value));
  211. $pOptions .= $template->GetSnippet('PrintableInvoiceItemConfigurableField');
  212. }
  213. }
  214. }
  215.  
  216. if($pOptions) {
  217. $template->assign('ProductOptions', $pOptions);
  218. $template->assign('HideVariationOptions', '');
  219. }
  220. else {
  221. $template->assign('HideVariationOptions', 'display: none');
  222. }
  223.  
  224. $productFields = '';
  225. if(!empty($fieldsArray[$product['challanprodid']])) {
  226. $fields = $fieldsArray[$product['challanprodid']];
  227. foreach($fields as $field) {
  228. if(empty($field['textcontents']) && empty($field['filename'])) {
  229. continue;
  230. }
  231.  
  232. $fieldValue = '-';
  233. $template->assign('FieldName', isc_html_escape($field['fieldname']));
  234.  
  235. if($row['fieldtype'] == 'file') {
  236. $fieldValue = '<a href="'.GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/configured_products/'.urlencode($field['originalfilename']).'">'.isc_html_escape($row['originalfilename']).'</a>';
  237. }
  238. else {
  239. $fieldValue = isc_html_escape($field['textcontents']);
  240. }
  241.  
  242. $template->assign('FieldValue', $fieldValue);
  243. $productFields .= $template->getSnippet('PrintableInvoiceItemConfigurableField');
  244. }
  245. }
  246. $template->assign('ProductConfigurableFields', $productFields);
  247. if(!$productFields) {
  248. $template->assign('HideConfigurableFields', 'display: none');
  249. }
  250. else {
  251. $template->assign('HideConfigurableFields', '');
  252. }
  253.  
  254. $template->assign('ProductCost', $product['ordprodcost']);
  255.  
  256. //$template->assign('Discount',$product['discountpercentprod']);
  257.  
  258. $template->assign('ProductTotalCost', currencyConvertFormatPrice($product['ordprodcost'] * $product['ordprodqty'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate'], true));
  259.  
  260. if($product['ordprodwrapcost'] > 0) {
  261. $wrappingTotal += $product['ordprodwrapcost'] * $product['ordprodqty'];
  262. }
  263.  
  264. if($product['ordprodwrapname']) {
  265. $template->assign('FieldName', getLang('GiftWrapping'));
  266. $template->assign('FieldValue', isc_html_escape($product['ordprodwrapname']));
  267. $template->assign('ProductGiftWrapping', getSnippet('PrintableInvoiceItemConfigurableField'));
  268. $template->assign('HideGiftWrapping', '');
  269. }
  270. else {
  271. $template->assign('ProductGiftWrapping', '');
  272. $template->assign('HideGiftWrapping', 'display: none');
  273. }
  274.  
  275. if($product['ordprodeventdate']) {
  276. $template->assign('FieldName', isc_html_escape($product['ordprodeventname']));
  277. $template->assign('FieldValue', isc_date('dS M Y', $product['ordprodeventdate']));
  278. $template->assign('ProductEventDate', getSnippet('PrintableInvoiceItemConfigurableField'));
  279. $template->assign('HideEventDate', '');
  280. }
  281. else {
  282. $template->assign('ProductEventDate', '');
  283. $template->assign('HideEventDate', 'display: none');
  284. }
  285. /*if($sno>7)
  286. {
  287. //echo "<hr/>";
  288. //PrintLineBreak
  289. $template->assign('PrintLineBreak','
  290. <html>
  291. <head>
  292. <body >
  293. <br style="page-break-after: always;">
  294. </body>
  295. </html>
  296. ');
  297. }*/
  298.  
  299. //<br style="page-break-before:always;">
  300. ++$sno;
  301.  
  302. // echo"<br style="page-break-after:always;">";
  303. switch($row['companyid'])
  304. {
  305. case 1:
  306. $productsTable .= $template->GetSnippet('PrintableInvoiceItemtechniz');
  307. break;
  308.  
  309. case 2:
  310. $productsTable .= $template->GetSnippet('PrintableInvoiceItemtechno');
  311. break;
  312.  
  313. case 3:
  314. $productsTable .= $template->GetSnippet('PrintableInvoiceItemvsp');
  315. break;
  316.  
  317. case 11:
  318. $productsTable .= $template->GetSnippet('PrintableInvoiceItemabi');
  319. break;
  320.  
  321. case 13:
  322. $productsTable .= $template->GetSnippet('PrintableInvoiceItemtech');
  323. break;
  324.  
  325. default:
  326. $productsTable .= $template->GetSnippet('PrintableInvoiceItem');
  327. }
  328.  
  329. }
  330. $template->assign('ProductsTable', $productsTable);
  331.  
  332.  
  333. /* $query="select c.currencyexchangerate AS cer
  334. from currencies c";
  335. $res3=$db->query($query);
  336. while($currencyexchangerate=$db->fetch($res3))
  337. {
  338.  
  339. $template->assign('CurrencyExchangeRate',$currencyexchangerate['cer']);
  340. }*/
  341. if($wrappingTotal > 0) {
  342. $template->assign('GiftWrappingTotal', currencyConvertFormatPrice($wrappingTotal, $row['ordcurrencyid'], $row['ordcurrencyexchangerate'], true));
  343. }
  344. else {
  345. $template->assign('HideGiftwrappingTotal', 'display: none');
  346. }
  347. //echo $row['companyid'];
  348. switch($row['companyid'])
  349. {
  350. case 1:
  351. $template->setTemplate("challan_printtechniz");//invoice_print
  352. break;
  353.  
  354. case 2:
  355. $template->setTemplate("challan_printtechno");//invoice_print
  356. break;
  357.  
  358. case 3:
  359. $template->setTemplate("challan_printvsp");//invoice_print
  360. break;
  361.  
  362. case 11:
  363. $template->setTemplate("challan_printabi");//invoice_print
  364. break;
  365.  
  366. case 13:
  367. $template->setTemplate("challan_printtech");//invoice_print
  368. break;
  369.  
  370. default:
  371. $template->setTemplate("challan_print");//invoice_print
  372.  
  373. }
  374. //$template->setTemplate("challan_printabi");//invoice_print
  375. return $template->parseTemplate(true);
  376. }
Add Comment
Please, Sign In to add comment