Current File : /home/inlingua/www/crm.vprotectindia.com/cron/payment_due_test.php |
<?php error_reporting(E_ALL);
ini_set('display_errors', '1');
// Database connection
//$conn = new mysqli("localhost", "root", "", "vprotect");
$conn = new mysqli("localhost", "inlingua_vprotect_user", "zDqxZh3sn65?vyjN", "inlingua_vprotect");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
require 'vendor/autoload.php'; // Make sure PhpSpreadsheet is installed via Composer
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$auth_token='VW8wsCIXRpmjMBusG42@^(87$8563zMHLQ2';
// Set header to XML
//header("Content-Type: text/xml");
// Root element
/* echo "<?xml version='1.0' encoding='UTF-8'?>";
echo "<DATA_DS>";*/
$_REQUEST['token'];
if('VW8wsCIXRpmjMBusG42@^(87$8563zMHLQ2' ==$auth_token){
$newdate=$_REQUEST['paymentdate'];
// Run query
$sql = "SELECT * FROM `customer_payments` where (trans_remarks='SUCCESS' or trans_remarks='Success-NA-0') and `payment_status`='1' and date(`updated_at`)= '$newdate'";
$result = $conn->query($sql);
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// Set header row
$headers = [
'Sl No', 'Date of Credit/Value date', 'Total net amount credited in Bank',
'Customer Name', 'UTR Number', 'Invoice Date', 'Invoice Number',
'Invoice Amount', 'TDS', 'Other Deductions', 'Bank Charges', 'Net Amount'
];
$sheet->fromArray($headers, NULL, 'A1');
$sheet->getColumnDimension('A')->setWidth(8); // Sl No
$sheet->getColumnDimension('B')->setWidth(20); // Date
$sheet->getColumnDimension('C')->setWidth(20); // Total net amount
$sheet->getColumnDimension('D')->setWidth(25); // Customer Name
$sheet->getColumnDimension('E')->setWidth(40); // UTR Number
$sheet->getColumnDimension('F')->setWidth(15); // Invoice Date
$sheet->getColumnDimension('G')->setWidth(40); // Invoice Number
$sheet->getColumnDimension('H')->setWidth(40); // Invoice Amount
$sheet->getColumnDimension('I')->setWidth(10); // TDS
$sheet->getColumnDimension('J')->setWidth(20); // Other Deductions
$sheet->getColumnDimension('K')->setWidth(20); // Bank Charges
$sheet->getColumnDimension('L')->setWidth(20); // Net Amount
$rowNum = 2;
if ($result->num_rows > 0) {
$z=0;
while($row = $result->fetch_assoc()) {
$invid=explode('@',$row['orderid']);
for($i=0; $i<count($invid); $i++) {
$id=$invid[$i];
if($id>0){
$sql2 = "SELECT * FROM `outstanding_reports` where `id`= '$id'";
$res = $conn->query($sql2);
$row1 = $res->fetch_assoc();
if($row['tds']>0){
$amount=$row['amount'];
$mainamount=$amount/1.18 ;
$percent=2;
$tds=($percent / 100) * $mainamount;
$totalamount =number_format((float)$tds, 2, '.', '');
} else {
$totalamount=$row['tds'];
}
$sr=$z+1;
$updated_at = date("Y-m-d", strtotime($row['updated_at']));
$sheet->fromArray([
$sr,
$updated_at,
$row['amount'],
$row1['party_name'],
//$row['tran_number'],
$row1['INVOICE_DATE'],
$row1['invoice_number'],
$row1['invoice_amount'],
$totalamount,
'0',
'0',
$row1['bal_func_amt']
], NULL, 'A'.$rowNum);
$sheet->setCellValueExplicit('E' . $rowNum, $row['tran_number'], \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
//$sheet->getStyle('E')->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
$rowNum++;
$z++;
}
}
}
}
// 3. Auto-size columns
$tmpFile = '/payment_report_' . date('Ymd_His') . '.xlsx';
// Save file
$writer = new Xlsx($spreadsheet);
// Save to a writable path
$filename = __DIR__ . $tmpFile;
$writer->save($filename);
//echo "Excel file created: $filename";
$results = $conn->query($sql);
if ($results->num_rows > 0) {
$message= '<table border="1">
<th>Sl No</th>
<th>Date of Credit/Value date</th>
<th>Total net amount credited in Bank</th>
<th>Customer Name</th>
<th>UTR Number</th>
<th>Invoice Date</th>
<th>Invoice Number</th>
<th>Invoice Amount</th>
<th>TDS</th>
<th>Other Deductions</th>
<th>Bank Charges</th>
<th>Net Amount</th>';
// Output data
$j=0;
while($rows = $results->fetch_assoc()) {
$invid=explode('@',$rows['orderid']);
//print_r($invid);
//echo count($invid);
for($i=0; $i<count($invid); $i++)
{
$id=$invid[$i];
if($id>0){
$sql = "SELECT * FROM `outstanding_reports` where `id`= '$id'";
$res = $conn->query($sql);
$rows1 = $res->fetch_assoc();
$message.= "<tr>";
if($rows['tds']>0){
$amount=$rows['amount'];
$mainamount=$amount/1.18 ;
$percent=2;
$tds=($percent / 100) * $mainamount;
//echo '<br>';
//echo $tetect_tds=$mainamount-$tds;
//echo '<br>';
//alert(tds);
//echo $total=$amount-$tds;
$totalamount =number_format((float)$tds, 2, '.', ''); //total.toFixed(2);
}else {
$totalamount=$rows['tds'];
}
$sr=$j+1;
$updated_at = date("Y-m-d", strtotime($rows['updated_at']));
$message.= "<td>".$sr."</td>"
. "<td>".$updated_at."</td>"
. "<td>".$rows['amount']."</td>"
. "<td>".$rows1['party_name']."</td>"
. "<td>".$rows['tran_number']."</td>"
. "<td>".$rows1['INVOICE_DATE']."</td>"
. "<td>".$rows1['invoice_number']."</td>"
. "<td>".$rows1['invoice_amount']."</td>"
. "<td>".$totalamount."</td>"
. "<td>".'0'."</td>"
. "<td>".'0'."</td>"
. "<td>".$rows1['bal_func_amt']."</td>"
. '</tr>';
}
}
$j++;
}
$message.= '</table>';
} else {
echo "<tr><td col='12'>No records found</td></tr>";
echo '</table>';
}
}
else
{
echo "<tr><td col='12'>No records found</td></tr>";
echo '</table>';
}
//echo '<br>';echo $message;
include("class.phpmailer.php");
$tomail_array=array();
//array_push($tomail_array,"rohit1.kumar@sisindia.com");
array_push($tomail_array,"a.ansari@infocityhosting.in");
$subject="Payment Update";
$fromEmail= "B2Creceipt@vprotectindia.com";
$fromName="Admin ".'vprotectindia';
//$tomail_array=array($email);
$domain = "sisindia.com";
$smtpHost = "mail.$domain";
//$smtpHost ="smtp.inlinguanewdelhi.in;smtp1.inlinguanewdelhi.in;smtp2.inlinguanewdelhi.in;smtp02.inlinguanewdelhi.in";
$smtpUser = "B2Creceipt@vprotectindia.com";
$smtpPassword = "rbmfLpd@1";
$mail = new PHPMailer();
$mail_type="S";
if( $mail_type=="S")
{
$mail->IsMail(); // set mailer to use SMTP
}
if( $mail_type=="N")
{
$mail->IsMail();
}
if($mail_type=="S")
{
$mail->Host = $smtpHost; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = $smtpUser; // SMTP username
$mail->Password = $smtpPassword; // SMTP password
//$mail->SetLanguage( 'en', 'phpmailer/language/' );
//$mail->Port = 26; //465 //587
$mail->Port =587;
//$mail->Priority = 1;
}
$mail->From = $fromEmail;
$mail->FromName = $fromName;
foreach ($tomail_array as $toAddress)
{
if($toAddress !=''){
$mail->AddAddress(trim($toAddress),"");
}
}
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$filePath =$filename;
if (file_exists($filePath)) {
if (!function_exists('set_magic_quotes_runtime')) {
function set_magic_quotes_runtime($new_setting) {
// no-op (does nothing, safe to ignore in modern PHP)
return false;
}
}
$mail->addAttachment($filePath);
} else {
echo "File not found!";
}
if($mail->Send())
{
echo "Message be sent on mailid: <font color='red'>'".$toAddress."'";
unlink($filePath);
//echo "File deleted after processing.<br>";
$html = $message; // email body
$dom = new DOMDocument();
libxml_use_internal_errors(true); // suppress HTML errors
$dom->loadHTML($html);
$rows = $dom->getElementsByTagName('tr');
$data = [];
foreach ($rows as $row) {
$cols = $row->getElementsByTagName('td');
$rowData = [];
foreach ($cols as $col) {
$rowData[] = trim($col->nodeValue);
}
if (!empty($rowData)) {
$data[] = $rowData;
}
}
for($i=0; $i<count($data); $i++){
$phone='';
$created_date=date("Y-m-d h:i:s");
$whatsapp = "INSERT INTO `whatsapp_msgs` (`id`, `title`, `mobile_no`, `send_id`, `amount`, `invoice_number`, `created_date`,`send_way`) VALUES (NULL, '".$data[$i]['3']."', '".$phone."', 'mail-send', '".$data[$i]['2']."', '".$data[$i]['6']."', '".$created_date."','hit-email')";
$res_whatsapp = $conn->query($whatsapp);
}
//echo "Mailer Error: " . $mail->ErrorInfo;
//exit;
}else{
echo "Message send on given mailid:Done !!!";
exit;
}
//echo '<pre>'; print_r($tomail_array);
$conn->close();
?>