D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
thread-self
/
root
/
proc
/
self
/
root
/
home
/
shubmkcj
/
urbane.createerp.com
/
Filename :
send-invoice.php
back
Copy
<?php session_start(); require ('config.php'); function getInvoiceData($id, $conn){ $companyName = ""; $companyLogo = ""; $companySign = ""; $companyPhone = ""; $companyEmail = ""; $companyAddress = ""; $companyCity = ""; $companyState = ""; $companyCountry = ""; $companygstin = ""; $companyPin = ""; $accountHolderName = ""; $accountNumber = ""; $bankName = ""; $ifsc = ""; $swift= ""; $color = ""; $currency = ""; $branch = ""; $billingCompanyName = ""; $billingCompanyAddress = ""; $billingCompanyCity = ""; $billingCompanyState = ""; $billingCompanyPhone = ""; $billingCompanyEMail = ""; $billingCompanyPin = ""; $billingCompanyCountry = ""; $billingGSTIN = ""; $shippingCompanyAddress = ""; $shippingCompanyCity = ""; $shippingCompanyState = ""; $shippingCompanyPhone = ""; $shippingCompanyEMail = ""; $shippingCompanyPin = ""; $shippingCompanyCountry = ""; $shippingGSTIN = ""; $invoice = ""; $date = ""; $terms = ""; $dueDate = ""; $itemName = ""; $price = ""; $quantity = ""; $discountValueQty = ""; $tax = ""; $totalAmount = ""; $discountApplied = ""; $discountCategory = ""; $taxValue = ""; $totalDiscount = ""; $totalTax = ""; $subTotal = ""; $amountPaid = ""; $dateCreation = ""; $companyName = ""; $address = ""; $city = ""; $state = ""; $pin = ""; $gstin = ""; $invoice = ""; $date = ""; $dueDate = ""; $itemName = ""; $price = ""; $quantity = ""; $discountValueQty = ""; $tax = ""; $totalAmount = ""; $discountApplied = ""; $discountCategory = ""; $taxValue = ""; $totalDiscount = ""; $totalTax = ""; $subTotal = ""; $amountPaid = ""; $dateCreation = ""; $billingCompanyName = ""; $billingCompanyLogo = ""; $billingCompanyPhone = ""; $billingCompanyEMail = ""; $billingCompanyAddress = ""; $billingCompanyCity = ""; $billingCompanyState = ""; $billingCompanyCountry = ""; $billingGSTIN = ""; $accountHolderName = ""; $accountNumber = ""; $bankName = ""; $ifsc = ""; $swift= ""; $invoice_note = ""; $color = ""; $currency = ""; $branch = ""; $logo = ""; $sign = ""; $country = ""; $gstTax = ""; $gstTax1 = ""; $billingAddress = ""; $shipingAddress = ""; $checkPaidUnpaid = ""; $paidImage = ""; $dueDateAccToPaid = ""; $companyId = ''; $invoice_type = ""; $header = ""; $sqlGetInvoice = "SELECT a.*, b.invoice_note FROM invoice a JOIN company_details b ON a.company_id = b.id WHERE a.id = '$id'"; $result = mysqli_query($conn, $sqlGetInvoice) or die(mysqli_error()); if($result){ if(mysqli_num_rows($result) > 0){ while($rowGetInvoice = mysqli_fetch_assoc($result)){ $companyId = $rowGetInvoice["company_id"]; $invoice_type = $rowGetInvoice["invoice_type"]; $companyName = $rowGetInvoice["company_name"]; $companyLogo = $rowGetInvoice["company_logo"]; $companySign = $rowGetInvoice["signature"]; $companyPhone = $rowGetInvoice["company_phone"]; $companyEmail = $rowGetInvoice["company_email"]; $companyAddress = $rowGetInvoice["company_address"]; $companyCity = $rowGetInvoice["company_city"]; $companyState = $rowGetInvoice["company_state"]; $companyCountry = $rowGetInvoice["company_country"]; $companygstin = $rowGetInvoice["company_gstin"]; $accountHolderName = $rowGetInvoice["company_account_name"]; $accountNumber = $rowGetInvoice["company_account_no"]; $bankName = $rowGetInvoice["company_bank_name"]; $ifsc = $rowGetInvoice["company_ifsc"]; $swift= $rowGetInvoice["company_swift"]; $color = $rowGetInvoice["company_color"]; $currency = $rowGetInvoice["company_currency"]; $branch = $rowGetInvoice["company_branch"]; $invoice_note = $rowGetInvoice["invoice_note"]; $billingCompanyName = $rowGetInvoice["billing_company_name"]; $billingCompanyAddress = $rowGetInvoice["billing_company_address"]; $billingCompanyCity = $rowGetInvoice["billing_company_city"]; $billingCompanyState = $rowGetInvoice["billing_company_state"]; $billingCompanyPhone = $rowGetInvoice["billing_company_phone"]; $billingCompanyEMail = $rowGetInvoice["billing_company_email"]; $billingCompanyPin = $rowGetInvoice["billing_company_pin"]; $billingCompanyCountry = $rowGetInvoice["billing_comapny_country"]; $billingGSTIN = $rowGetInvoice["billing_company_gstin"]; $shippingCompanyAddress = $rowGetInvoice["shipping_company_address"]; $shippingCompanyCity = $rowGetInvoice["shipping_company_city"]; $shippingCompanyState = $rowGetInvoice["shipping_company_state"]; $shippingCompanyPhone = $rowGetInvoice["shipping_comapny_phone"]; $shippingCompanyEMail = $rowGetInvoice["shipping_comapny_email"]; $shippingCompanyPin = $rowGetInvoice["shipping_company_pin"]; $shippingCompanyCountry = $rowGetInvoice["shipping_comapny_country"]; $shippingGSTIN = $rowGetInvoice["shipping_company_gstin"]; $invoice = $rowGetInvoice["invoice"]; $date = $rowGetInvoice["date"]; $terms = $rowGetInvoice["terms"]; $dueDate = $rowGetInvoice["due_date"]; $itemName = $rowGetInvoice["item_name"]; $price = $rowGetInvoice["price"]; $quantity = $rowGetInvoice["quantity"]; $discountValueQty = $rowGetInvoice["discount_value_qty"]; $tax = $rowGetInvoice["tax"]; $totalAmount = $rowGetInvoice["total_amount"]; $discountApplied = $rowGetInvoice["discount_applied"]; $discountCategory = $rowGetInvoice["discount_category"]; $taxValue = $rowGetInvoice["tax_value"]; $totalDiscount = $rowGetInvoice["total_discount"]; $totalTax = $rowGetInvoice["total_tax"]; $subTotal = $rowGetInvoice["sub_total"]; $amountPaid = $rowGetInvoice["amount_paid"]; $dateCreation = $rowGetInvoice["date_creation"]; } if(!empty($companygstin)){ $companygstin = "<span><strong style='font-weight:bold'>GSTIN : </strong>".$companygstin."</span>"; } if($terms == "Paid"){ $paidImage = "<img src='images/paid.png' height='75px' style='margin-left:100px;'>"; } else{ $dueDateAccToPaid = "<tr><th style='text-align:left; width:50%; float:left'><strong style='font-weight:bold'>Due Date</strong></th><th>:</th><td style='text-align:right;width:50%; float:left'>".$dueDate."</td></tr>"; } if($companyLogo != ""){ $logo = "<img src='images/".$companyLogo."' style='max-height:100px;' />"; } if($companySign != ""){ $sign = "<img src='signature/".$companySign."' style='max-height:100px;max-width:150px;' />"; } if($billingCompanyCountry == "India"){ if(!empty($billingGSTIN)){ $gstTax = "<div><strong style='font-weight:bold'>GSTIN : </strong><span>".$billingGSTIN."</span></div>"; } } else{ if(!empty($billingGSTIN)){ $gstTax = " <div><strong style='font-weight:bold'>Tax Number : </strong><span>".$billingGSTIN."</span></div>"; } } if($shippingCompanyCountry == "India"){ if(!empty($shippingGSTIN)){ $gstTax1 = "<div><strong style='font-weight:bold'>GSTIN : </strong><span>".$shippingGSTIN."</span></div>"; } } else{ if(!empty($shippingGSTIN)){ $gstTax1 = " <div><strong style='font-weight:bold'>Tax Number : </strong><span>".$shippingGSTIN."</span></div>"; } } $item = explode(",", $itemName); $price1 = explode(",", $price); $quantity1 = explode(",", $quantity); $discountValueQty1 = explode(",", $discountValueQty); $tax1 = explode(",", $tax); $totalAmount1 = explode(",", $totalAmount); $discountApplied1 = explode(",", $discountApplied); $discountCategory1 = explode(",", $discountCategory); $taxValue1 = explode(",", $taxValue); $count = sizeof($item); $itemList = ""; $taxList = ""; $halfTax = number_format((float)$totalTax/2, 2, '.', ''); if(strtoupper($companyCountry) == strtoupper("India")){ if(strtoupper($billingCompanyState) == strtoupper($companyState)){ $taxList = "<tr><th><strong style='font-weight:bold'>CGST</strong></th><td> : </td> <td style='text-align:right'> ".$halfTax."</td></tr><tr><th><strong style='font-weight:bold'>SGST</strong></th><td> : </td> <td style='text-align:right'> ".$halfTax."</td></tr>"; } else{ $taxList = "<tr><th><strong style='font-weight:bold'>IGST</strong></th><td> : </td> <td style='text-align:right'> ".$totalTax."</td></tr>"; } } else{ $sqlGetTaxName = "SELECT tax_name FROM tax_manager WHERE UPPER(country) = UPPER('$companyCountry') AND source_id = '$companyId'"; $resultGetTaxName = mysqli_query($conn, $sqlGetTaxName); if($resultGetTaxName){ if(mysqli_num_rows($resultGetTaxName) > 0){ while($rowGetTaxName = mysqli_fetch_assoc($resultGetTaxName)){ $taxList = "<tr><th><strong style='font-weight:bold'>".$rowGetTaxName["tax_name"]."</strong></th><td> : </td> <td style='text-align:right'> ".$totalTax."</td></tr>"; } } } } for($i = 0; $i < $count; $i++){ $number = $i+1; $iid = $item[$i]; $iitemName = ""; $item_description = ""; $hsn_sac_code = ""; $sqlGetItemName = "SELECT item_name, hsn_sac_code, item_description FROM inventory_manager WHERE id = '$iid'"; $resultGetItemName = mysqli_query($conn, $sqlGetItemName); if($resultGetItemName){ while($rowGetItemName = mysqli_fetch_assoc($resultGetItemName)){ $iitemName = $rowGetItemName["item_name"]; $hsn_sac_code = $rowGetItemName["hsn_sac_code"]; $item_description = $rowGetItemName["item_description"]; } } $ttax = "-"; if($taxValue1[$i] != ""){ $ttax = $taxValue1[$i]."%"; } $itemList .= "<tr data-iterate='item'> <td style='vertical-align:top'>".$number."</td> <td>".$iitemName."<br><span style='font-size:10px'>".$item_description."</span></td> <td style='vertical-align:top'>".$hsn_sac_code."</td> <td style='vertical-align:top'>".$quantity1[$i]."</td> <td style='vertical-align:top'>".$price1[$i]."</td> <td style='vertical-align:top'>".$discountValueQty1[$i]."</td> <td style='vertical-align:top'>".$ttax."</td> <td style='vertical-align:top'>".$totalAmount1[$i]."</td> </tr>"; } if(empty($color) && $color == "#ffffff"){ $color = "#415472"; } if($invoice_type == "Performa Invoice"){ $header = "PERFORMA"; $invoiceNumber = "Performa Id"; } else{ $header = "INVOICE"; $invoiceNumber = "Invoice Number"; } $html = "<html lang='en'> <body> <div id='container'> <div style='width:100%'> <div class='company-info' style='float:left; width:70%'> <div style='margin-top:10px'>".$companyName."</div> <span>".$companyAddress."</span> <br> <span>".$companyCity.", ".$companyState.", ".$companyCountry."</span> <br> <span><strong style='font-weight:bold'>Phone : </strong>".$companyPhone.", <strong style='font-weight:bold'> Email : </strong>".$companyEmail." </span> <br> ".$companygstin." </div> <div class='logo' style='margin-top:10px;'> ".$logo." </div> </div> <section style='width:100%; margin-top:15px' > <div style='float:left; width:60%'> <span><strong style='font-weight:bold'>Bill To:</strong></span> <div style='text-transform:uppercase; font-weight:bold; font-size:16px'> <span>".$billingCompanyName."</span> </div> <div style='width:99%;'> <div style='width:49%; float:left'> <span><strong style='font-weight:bold'>Billing Address </strong></span> <div><span>".$billingCompanyAddress."</span></div> <div> <span>".$billingCompanyCity.", ".$billingCompanyState.", ".$billingCompanyCountry."</span></div> <div> <span>ZIP - ".$billingCompanyPin." </span></div> <span><strong style='font-weight:bold'>Phone : </strong>".$billingCompanyPhone."</span> ".$gstTax." </div> <div style='width:50%; float:left'> <span><strong style='font-weight:bold'>Shipping Address</strong></span> <div><span>".$shippingCompanyAddress." </span></div> <div> <span>".$shippingCompanyCity.", ".$shippingCompanyState.", ".$shippingCompanyCountry."</span></div> <div> <span>ZIP - ".$shippingCompanyPin." </span></div> <div><strong style='font-weight:bold'>Phone : </strong>".$shippingCompanyPhone."</div> ".$gstTax1." </div> </div> </div> <div id='invoice-title-number'> <div id='title' style='background-color:".$color."; font-weight:bold'>".$header."</div> <table width='100%'> <tr> <th style='text-align:left; width:45%; float:left'> <strong style='font-weight:bold'>".$invoiceNumber."</strong> </th> <th>:</th> <td style='text-align:right;width:54%; float:left'>".$invoice."</td> </tr> <tr> <th style='text-align:left; width:45%; float:left'> <strong style='font-weight:bold'>Date</strong> </th> <th>:</th> <td style='text-align:right;width:54%; float:left'>".$date."</td> </tr> ".$dueDateAccToPaid." </table> ".$paidImage." </div> </section> <div style='width:100%; text-align:right'> <span>* All prices are in </span> <span>".$currency."</span> </div> <section id='items'> <table cellpadding='0' cellspacing='0'> <tr> <th><strong>SL</strong></th> <th><strong>ITEM</strong></th> <th><strong>HSN/SAC</strong></th> <th><strong>QTY</strong></th> <th><strong>PRICE</strong></th> <th><strong>DISCOUNT</strong></th> <th><strong>TAX</strong></th> <th><strong>TOTAL</strong></th> </tr> ".$itemList." </table> </section> <section id='sums' style='width:100%; margin-top:20px'> <div style='float:left; width:60%'> </div> <div style='float:left; width:40%'> <table> <tr> <th><strong style='font-weight:bold'>SUBTOTAL</strong></th> <td> : </td> <td style='text-align:right'>".$subTotal."</td> </tr> ".$taxList." </table> <div style='height:30px; padding: 10px; font-size:20px; text-align:center; color:#ffffff; background-color:".$color."; font-weight:bold'>".$currency." ".$amountPaid."</div> </div> </section> <div class='payment-info' style='margin-top:20px'> <table width='100%'> <tr> <td width='78%'> <div><b>Account Details</b></div> <table> <tr> <th>Bank Name</th> <th> : </th> <td>".$bankName."</td> </tr> <tr> <th>A/C Name</th> <th> : </th> <td>".$accountHolderName."</td> </tr> <tr> <th>A/C Number</th> <th> : </th> <td>".$accountNumber."</td> </tr> <tr> <th>IFSC</th> <th> : </th> <td>".$ifsc."</td> </tr> <tr> <th>Branch</th> <th> : </th> <td>".$branch."</td> </tr> <tr> <th>SWIFT</th> <th> : </th> <td>".$swift."</td> </tr> </table> </td> <td width='20%' style='text-align:right'> <div> <div> ".$sign." </div> <div> Authorised Signatory</div> </div> </td> </tr> </table> </div> <div style='text-align:center; margin-top:10px'>".$invoice_note."</div> </div> </div> </body> </html>"; } } return $html; } function executeQuerySQL($sql, $conn){ $out = ""; $result = mysqli_query($conn, $sql); if($result){ if(mysqli_num_rows($result) > 0){ while($row= mysqli_fetch_array($result)){ $out = $row[0]; } } } return $out; } require ("mpdf/mpdf.php"); $invoiceId = $_POST["invoiceId"]; $emailId = $_POST["emailId"]; $LoginEmail = $_SESSION["login_email"]; $source_id = $_SESSION["source_id"]; $userName = ""; $inNumber = ""; $html1 = getInvoiceData($invoiceId, $conn); $invoiceType = executeQuerySQL("SELECT invoice_type FROM invoice WHERE id = '$invoiceId'", $conn); $inNumber = executeQuerySQL("SELECT invoice FROM invoice WHERE id = '$invoiceId'", $conn); $billingCompanyId = executeQuerySQL("SELECT billing_company_id FROM invoice WHERE id = '$invoiceId'", $conn); $billingCompanyName = executeQuerySQL("SELECT billing_company_name FROM invoice WHERE id = '$invoiceId'", $conn); $billingPersonName = executeQuerySQL("SELECT contact_person_name FROM contact_manager WHERE id = '$billingCompanyId'", $conn); $invoiceDate = executeQuerySQL("SELECT date FROM invoice WHERE id = '$invoiceId'", $conn); $invoiceDueDate = executeQuerySQL("SELECT due_date FROM invoice WHERE id = '$invoiceId'", $conn); $invoiceAmount = executeQuerySQL("SELECT amount_paid FROM invoice WHERE id = '$invoiceId'", $conn); // $billerName = executeQuerySQL("SELECT name FROM login_admin WHERE email = '$LoginEmail'", $conn); $billerCompany = executeQuerySQL("SELECT company_name FROM company_details WHERE id = '$source_id'", $conn); $invoiceDate = date("l, F jS, Y", strtotime($invoiceDate)); $invoiceDueDate = date("l, F jS, Y", strtotime($invoiceDueDate)); $name = str_replace("#", "", $inNumber); $name = $name."_".date("YmdHms").".pdf"; if($invoiceType == "Performa Invoice"){ $invoiceType = "Performa"; } $mpdf=new mPDF('A4'); $mpdf->allow_charset_conversion=true; $stylesheet=file_get_contents('bootstrap.min.css'); $mpdf->WriteHTML($stylesheet, 1); $stylesheet1=file_get_contents('style1212.css'); $mpdf->WriteHTML($stylesheet1, 1); $mpdf->showImageErrors=true; $mpdf->SetDisplayMode('fullpage'); $mpdf->WriteHTML($html1); ob_clean(); ob_end_clean(); $mpdf->Output("output/invoice.pdf", "F"); require 'sendgrid-php/sendgrid-php.php'; $API_KEY = "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"; $email = new \SendGrid\Mail\Mail(); $email->setFrom("$LoginEmail", "$billerName"); $email->setSubject("Invoice"); $email->addTo("$emailId", "$billingPersonName"); $email->addContent("text/plain", "Dear $billingPersonName ($billingCompanyName)! \n \n This is a notification that an $invoiceType has been generated on $invoiceDate \n Your payment method is: Bank Transfer/Cheque/Payment Gateway. \n \n Invoice : $inNumber \n Amount Due: Rs. $invoiceAmount \n Due Date: $invoiceDueDate \n \n\n \n Thanks & Regards, \n $billerCompany"); $email->addContent( "text/html", "<html> <head> <title>Reset Password</title> </head> <body> <div style='width:100%;'> <p style='font-size:18px'>Dear $billingPersonName ($billingCompanyName)!</p> <p>This is a notification that an $invoiceType has been generated on $invoiceDate<br> Your payment method is: Bank Transfer/Cheque/Payment Gateway.</p> <p>$invoiceType : $inNumber<br>Amount Due: Rs. $invoiceAmount<br>Due Date: $invoiceDueDate</p> <br> <br><br> <p>Thanks & Regards,</p> <p>$billerCompany</p> </div> </body> </html>" ); $file_encoded = base64_encode(file_get_contents('output/invoice.pdf')); $email->addAttachment( $file_encoded, "application/pdf", $name, "attachment" ); $sendgrid = new \SendGrid($API_KEY); if($sendgrid->send($email)){ unlink('output/invoice.pdf'); echo '<script>localStorage.setItem("InvoiceSent", "'.$invoiceType.'");</script>'; $conn->query("INSERT INTO invoice_notification SET invoice_id = '$invoiceId', notification_text = '$invoiceType has been sent to $emailId'"); } else{ echo '<script>localStorage.setItem("InvoiceNotSent", "'.$invoiceType.'");</script>'; } echo "<script>location.replace('view_invoice.php?id=$invoiceId');</script>"; ?>