Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function generatePrintableInvoice($challanId)
- {
- $db = $GLOBALS['ISC_CLASS_DB'];
- $template = new TEMPLATE('ISC_LANG');
- $template->frontEnd();
- $template->setTemplateBase(ISC_BASE_PATH . "/templates");
- $template->panelPHPDir = ISC_BASE_PATH . "/includes/display/";
- $template->templateExt = "html";
- $template->setTemplate(getConfig("template"));
- //[anand.6756@gmail.com]
- $GLOBALS['ISC_CLASS_ADMIN_ENGINE']->LoadLangFile('challans');
- $query = "
- 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
- FROM [|PREFIX|]company o
- LEFT JOIN [|PREFIX|]challans c ON o.companyid = c.companyid
- WHERE c.challanid = '".(int)$challanId."'
- ";
- $result = $db->Query($query);
- $row = $db->Fetch($result);
- $template->assign('CompanyName',$row['comname']);
- $template->assign('CompanyAddress',$row['comaddress']);
- $template->assign('CompanyEmail',$row['comemail']);
- $template->assign('CompanyLogo',$row['comlogo']);
- $template->assign('CompanyPhone',$row['comphone']);
- $template->assign('CompanyFax',$row['comfax']);
- //$template->assign('HeaderLogo', fetchHeaderLogo());
- //$template->assign('StoreAddressFormatted', nl2br(getConfig('StoreAddress')));
- $query = "
- SELECT o.*, CONCAT(c.custconfirstname, ' ', c.custconlastname) AS ordcustname, c.custconemail AS ordcustemail, c.custconphone AS ordcustphone
- FROM [|PREFIX|]challans o
- LEFT JOIN [|PREFIX|]customers c ON o.ordcustid = c.customerid
- WHERE o.challanid = '".(int)$challanId."'
- ";
- $result = $db->Query($query);
- $row = $db->Fetch($result);
- if(!$row) {
- return false;
- }
- $template->assign('ChallanId', $row['challanid']);
- $template->assign('ChallanDate', cDate($row['orddate']));
- if($row['ordcustmessage']) {
- $template->assign('Comments', nl2br(isc_html_escape($row['ordcustmessage'])));
- }
- else {
- $template->assign('HideComments', 'display: none');
- }
- $template->assign('InvoiceTitle', sprintf(getLang('InvoiceTitle'), $challanId));
- $template->assign('ItemCost', currencyConvertFormatPrice($row['ordsubtotal'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate'], true ));
- if($row['ordshipcost']) {
- $template->assign('ShippingCost', currencyConvertFormatPrice($row['ordshipcost'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate' ], true));
- }
- else {
- $template->assign('HideShippingCost', 'display: none');
- }
- // Is there a handling fee?
- if ($row['ordhandlingcost'] > 0) {
- $template->assign('HandlingCost', currencyConvertFormatPrice($row['ordhandlingcost'], $row['ordcurrencyid'], $row[ 'ordcurrencyexchangerate'], true));
- }
- else {
- $template->assign('HideHandlingCost', 'display: none');
- }
- // Is there any sales tax?
- if($row['ordtaxtotal'] > 0) {
- if($row['ordtaxname']) {
- $template->assign('SalesTaxName', isc_html_escape($row['ordtaxname']));
- }
- else {
- $template->assign('SalesTaxName', getLang('InvoiceSalesTax'));
- }
- if($row['ordtotalincludestax']) {
- $template->assign('HideSalesTax', 'none');
- $template->assign('SalesTaxName', isc_html_escape($row['ordtaxname']) . ' ' . getLang('IncludedInTotal'));
- }
- else {
- $template->assign('HideSalesTaxIncluded', 'none');
- }
- $template->assign('SalesTax', currencyConvertFormatPrice($row['ordtaxtotal'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate'], true));
- }
- else {
- $template->assign('HideSalesTax', 'none');
- $template->assign('HideSalesTaxIncluded', 'none');
- }
- $template->assign('TotalCost', currencyConvertFormatPrice($row['ordtotalamount'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate'], true));
- // Format the customer details
- if($row['ordcustid'] == 0) {
- $template->assign('HideCustomerDetails', 'display: none');
- }
- $template->assign('CustomerId', $row['ordcustid']);
- $template->assign('CustomerName', isc_html_escape($row['ordcustname']));
- $template->assign('CustomerEmail', $row['ordcustemail']);
- $template->assign('CustomerPhone', $row['ordcustphone']);
- // Format the billing address
- $template->assign('ShipFullName', isc_html_escape($row['ordbillfirstname'].' '.$row['ordbilllastname']));
- if($row['ordbillcompany']) {
- $template->assign('ShipCompany', '<br />'.isc_html_escape($row['ordbillcompany']));
- }
- else {
- $template->assign('ShipCompany', '');
- }
- $addressLine = isc_html_escape($row['ordbillstreet1']);
- if ($row['ordbillstreet2'] != "") {
- $addressLine .= '<br />' . isc_html_escape($row['ordbillstreet2']);
- }
- $template->assign('ShipAddressLines', $addressLine);
- $template->assign('ShipSuburb', isc_html_escape($row['ordbillsuburb']));
- $template->assign('ShipState', isc_html_escape($row['ordbillstate']));
- $template->assign('ShipZip', isc_html_escape($row['ordbillzip']));
- //$template->assign('ShipCountry', isc_html_escape($row['ordbillcountry']));
- $template->assign('BillingAddress', $template->getSnippet('AddressLabel'));
- $query = "
- SELECT ordprodname
- FROM [|PREFIX|]challan_products
- WHERE challanchallanid='".(int)$challanId."'
- ";
- $res3 = $db->query($query);
- $count=0;
- while($prod = $db->fetch($res3))
- {
- $count++;
- }
- $query = "
- SELECT *
- FROM [|PREFIX|]challan_products
- WHERE challanchallanid='".(int)$challanId."'
- ";
- $result = $db->query($query);
- /*$product = $db->fetch($result);
- $count=count($product['ordprodname']);
- echo $count;
- */
- $productsTable = '';
- $wrappingTotal = 0;
- $sno=1;
- while($product = $db->fetch($result)) {
- $template->assign('Serialnumber',$sno);
- $template->assign('ProductName', isc_html_escape($product['ordprodname']));
- if($product['ordprodsku']) {
- $template->assign('ProductSku', isc_html_escape($product['ordprodsku']));
- }
- else {
- $template->assign('ProductSku', getLang('NA'));
- }
- $template->assign('ProductQuantity', $product['ordprodqty']);
- $template->assign('Discount',$product['discountpercentprod']);
- $query = "
- SELECT o.currencystring
- FROM [|PREFIX|]currencies o
- LEFT JOIN [|PREFIX|]challans c ON o.currencyid = c.ordcurrencyid
- WHERE c.challanid = '".(int)$challanId."'
- ";
- $res = $db->Query($query);
- while($currencystring = $db->Fetch($res)) {
- $template->assign('Currency',$currencystring['currencystring']);
- }
- $query="
- SELECT b.brandname
- FROM brands b
- LEFT JOIN [|PREFIX|]products p ON p.prodbrandid=b.brandid
- LEFT JOIN [|PREFIX|]challan_products c ON c.ordprodid=p.productid
- WHERE c.challanchallanid='".(int)$challanId."'
- ";
- $res2=$db->Query($query);
- $brandname=$db->Fetch($res2);
- while($brandname=$db->Fetch($res2)) {
- $template->assign('BrandName',$brandname['brandname']);
- }
- $pOptions = '';
- if($product['ordprodoptions'] != '') {
- $options = @unserialize($product['ordprodoptions']);
- if(!empty($options)) {
- foreach($options as $name => $value) {
- $template->assign('FieldName', isc_html_escape($name));
- $template->assign('FieldValue', isc_html_escape($value));
- $pOptions .= $template->GetSnippet('PrintableInvoiceItemConfigurableField');
- }
- }
- }
- if($pOptions) {
- $template->assign('ProductOptions', $pOptions);
- $template->assign('HideVariationOptions', '');
- }
- else {
- $template->assign('HideVariationOptions', 'display: none');
- }
- $productFields = '';
- if(!empty($fieldsArray[$product['challanprodid']])) {
- $fields = $fieldsArray[$product['challanprodid']];
- foreach($fields as $field) {
- if(empty($field['textcontents']) && empty($field['filename'])) {
- continue;
- }
- $fieldValue = '-';
- $template->assign('FieldName', isc_html_escape($field['fieldname']));
- if($row['fieldtype'] == 'file') {
- $fieldValue = '<a href="'.GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/configured_products/'.urlencode($field['originalfilename']).'">'.isc_html_escape($row['originalfilename']).'</a>';
- }
- else {
- $fieldValue = isc_html_escape($field['textcontents']);
- }
- $template->assign('FieldValue', $fieldValue);
- $productFields .= $template->getSnippet('PrintableInvoiceItemConfigurableField');
- }
- }
- $template->assign('ProductConfigurableFields', $productFields);
- if(!$productFields) {
- $template->assign('HideConfigurableFields', 'display: none');
- }
- else {
- $template->assign('HideConfigurableFields', '');
- }
- $template->assign('ProductCost', $product['ordprodcost']);
- //$template->assign('Discount',$product['discountpercentprod']);
- $template->assign('ProductTotalCost', currencyConvertFormatPrice($product['ordprodcost'] * $product['ordprodqty'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate'], true));
- if($product['ordprodwrapcost'] > 0) {
- $wrappingTotal += $product['ordprodwrapcost'] * $product['ordprodqty'];
- }
- if($product['ordprodwrapname']) {
- $template->assign('FieldName', getLang('GiftWrapping'));
- $template->assign('FieldValue', isc_html_escape($product['ordprodwrapname']));
- $template->assign('ProductGiftWrapping', getSnippet('PrintableInvoiceItemConfigurableField'));
- $template->assign('HideGiftWrapping', '');
- }
- else {
- $template->assign('ProductGiftWrapping', '');
- $template->assign('HideGiftWrapping', 'display: none');
- }
- if($product['ordprodeventdate']) {
- $template->assign('FieldName', isc_html_escape($product['ordprodeventname']));
- $template->assign('FieldValue', isc_date('dS M Y', $product['ordprodeventdate']));
- $template->assign('ProductEventDate', getSnippet('PrintableInvoiceItemConfigurableField'));
- $template->assign('HideEventDate', '');
- }
- else {
- $template->assign('ProductEventDate', '');
- $template->assign('HideEventDate', 'display: none');
- }
- /*if($sno>7)
- {
- //echo "<hr/>";
- //PrintLineBreak
- $template->assign('PrintLineBreak','
- <html>
- <head>
- <body >
- <br style="page-break-after: always;">
- </body>
- </html>
- ');
- }*/
- //<br style="page-break-before:always;">
- ++$sno;
- // echo"<br style="page-break-after:always;">";
- switch($row['companyid'])
- {
- case 1:
- $productsTable .= $template->GetSnippet('PrintableInvoiceItemtechniz');
- break;
- case 2:
- $productsTable .= $template->GetSnippet('PrintableInvoiceItemtechno');
- break;
- case 3:
- $productsTable .= $template->GetSnippet('PrintableInvoiceItemvsp');
- break;
- case 11:
- $productsTable .= $template->GetSnippet('PrintableInvoiceItemabi');
- break;
- case 13:
- $productsTable .= $template->GetSnippet('PrintableInvoiceItemtech');
- break;
- default:
- $productsTable .= $template->GetSnippet('PrintableInvoiceItem');
- }
- }
- $template->assign('ProductsTable', $productsTable);
- /* $query="select c.currencyexchangerate AS cer
- from currencies c";
- $res3=$db->query($query);
- while($currencyexchangerate=$db->fetch($res3))
- {
- $template->assign('CurrencyExchangeRate',$currencyexchangerate['cer']);
- }*/
- if($wrappingTotal > 0) {
- $template->assign('GiftWrappingTotal', currencyConvertFormatPrice($wrappingTotal, $row['ordcurrencyid'], $row['ordcurrencyexchangerate'], true));
- }
- else {
- $template->assign('HideGiftwrappingTotal', 'display: none');
- }
- //echo $row['companyid'];
- switch($row['companyid'])
- {
- case 1:
- $template->setTemplate("challan_printtechniz");//invoice_print
- break;
- case 2:
- $template->setTemplate("challan_printtechno");//invoice_print
- break;
- case 3:
- $template->setTemplate("challan_printvsp");//invoice_print
- break;
- case 11:
- $template->setTemplate("challan_printabi");//invoice_print
- break;
- case 13:
- $template->setTemplate("challan_printtech");//invoice_print
- break;
- default:
- $template->setTemplate("challan_print");//invoice_print
- }
- //$template->setTemplate("challan_printabi");//invoice_print
- return $template->parseTemplate(true);
- }
Add Comment
Please, Sign In to add comment