I am busy working with function and I have a function that will fetch data according to my script and then i want the info retrieved from fetchBillScript() to be added to a new table (insert ignore)
I want my script to run on the backround(schedule task)
here is my function.php
<?php
function fetchBillScript(){
require(CONNECTIONS.'connection.php');
$sql = "SELECT * FROM (
SELECT
Customer_Information.Branch AS Branch,
Bill_Information.Bill_Date AS Bill_Date,
Rate_Information.BillNUmber AS BillNumber,
Bill_Information.Customer_Reference AS Customer_Reference,
Bill_Information.To_Ops_Branch AS To_Ops_Branch,
DeliverySheet_Information.Route AS Route,
Rate_Information.Account_Number AS Account_Number,
Customer_Information.Customer_Name AS Customer_Name,
Bill_Information.Service_Type AS Service_Type,
Bill_Information.Scan_Back_Reason_Code AS Scan_Back_Reason_Code,
POD_Information.POD_Date AS POD_Date
FROM
Rate_Information
INNER JOIN Bill_Information ON
Bill_Information.BillNumber = Rate_Information.BillNumber AND
YEAR(Bill_Information.Bill_Date) = YEAR(CURDATE()) AND
MONTH(Bill_Information.Bill_Date) >= (MONTH(CURDATE()) - 1)
INNER JOIN Customer_Information ON
Rate_Information.Account_Number = Customer_Information.Account_Number
LEFT JOIN POD_Information ON
POD_Information.BillNumber = Rate_Information.BillNumber
LEFT JOIN Delivery_Bills ON
Delivery_Bills.BillNumber = Bill_Information.BillNumber
LEFT JOIN DeliverySheet_Information ON
DeliverySheet_Information.Delivery_Number = Delivery_Bills.Delivery_Number AND
Delivery_Bills.BillNumber IS NOT NULL) AS Data LIMIT 1";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
$lines2[] = $rows;
}
return $lines2;
}
function insertBillScript(){
while($row=mysql_fetch_array($result)){
$branch = $row['Branch'];
$billdate = $row['Bill_Date'];
$billnumber = $row['BillNumber']
$cus_ref= $row['Customer_Reference'];
$to_ops_branch= $row['To_Ops_Branch'];
$route= $row['Route'];
//$email= $row['EMAIL'];
$acc_num= $row['Account_Number'];
$cus_name= $row['Customer_Name'];
$service_type= $row['Service_Type'];
$scan_back_reason_code= $row['Scan_Back_Reason_Code'];
$pod_date = $row['POD_Date'];
$date_in_rec = $row['Date_Invoice_Received'];
if ($branch == null) {
$sql = "INSERT IGNORE INTO Internal_Docs_bill_outsanding
(Branch, BillDate, BillNumber, Customer_Reference, To_Ops_Branch, Route, Account_Number, Customer_Name, Service_Type, Scan_Back_Reason_Code, POD_Date, Date_Invoice_Returned) VALUES (
'".$branch."', '".$billdate."', '".$billnumber."', '".$cus_ref."', '".$to_ops_branch."', '".$route."', '".$acc_num."', '".$cus_name."', '".$service_type."', ' '".$scan_back_reason_code."'', '".$pod_date."', '".$data[12]."')";
$result=mysql_query($sql);
}
}
}
?>