<?php 
include "../config.php";
ini_set('memory_limit', '1024M'); // or you could use 1G
//$ticket = $_POST['tkt'];
// "select salescode, ticket, chakka, vehicleno, customer, delivery, product, price, priceori, date, time, processtype, emptyweight, loadweight, unitvalue, netweight, netqty, netqtyori, cft, customertype, totalamount, remark, blockdate, editby, edittime, editdate, status, supplier, financialyear, tablename,(select customerdetails.name from customerdetails where customerdetails.code = second_transaction.customer && status!='deleted')as cusname,(select productdetail.productname from productdetail where productdetail.productcode=second_transaction.product) as productname from second_transaction where status!='deleted' && status !='cancel'  
// union
// select salescode, ticket, chakka, vehicleno, customer, delivery, product, price, priceori, date, time, processtype, emptyweight, loadweight, unitvalue, netweight, netqty, netqtyori, cft, customertype, totalamount, remark, blockdate, editby, edittime, editdate, status, supplier, financialyear, tablename,(select customerdetails.name from customerdetails where customerdetails.code = second_transaction_est.customer && status!='deleted')as cusname,(select productdetail.productname from productdetail where productdetail.productcode=second_transaction_est.product) as productname from second_transaction_est where status!='deleted' && status !='cancel'   
// union
// select salescode, ticket, chakka, vehicleno, customer, delivery, product, price, priceori, date, time, processtype, emptyweight, loadweight, unitvalue, netweight, netqty, netqtyori, cft, customertype, totalamount, remark, blockdate, editby, edittime, editdate, status, supplier, financialyear, tablename,(select customerdetails.name from customerdetails where customerdetails.code = purchasedetails.customer && status!='deleted' )as cusname,(select productdetail.productname from productdetail where productdetail.productcode=purchasedetails.product) as productname from purchasedetails where status!='deleted' && status !='cancel' order by concat(date,time) desc
//  "
$tkt = [];
$proshow=mysqli_query($connect,"select salescode, ticket, chakka, vehicleno, customer, delivery, product, price, priceori, date, time, processtype, emptyweight, loadweight, unitvalue, netweight, netqty, netqtyori, cft, customertype, totalamount, remark, blockdate, editby, edittime, editdate, status, supplier, financialyear, tablename,einvoice_generated,einvoice_id from second_transaction where status!='deleted' && status !='cancel'  
union
select salescode, ticket, chakka, vehicleno, customer, delivery, product, price, priceori, date, time, processtype, emptyweight, loadweight, unitvalue, netweight, netqty, netqtyori, cft, customertype, totalamount, remark, blockdate, editby, edittime, editdate, status, supplier, financialyear, tablename,(0) as einvoice_generated,(0) as einvoice_id from second_transaction_est where status!='deleted' && status !='cancel'   
union
select salescode, ticket, chakka, vehicleno, customer, delivery, product, price, priceori, date, time, processtype, emptyweight, loadweight, unitvalue, netweight, netqty, netqtyori, cft, customertype, totalamount, remark, blockdate, editby, edittime, editdate, status, supplier, financialyear, tablename,(0) as einvoice_generated,(0) as einvoice_id from purchasedetails where status!='deleted' && status !='cancel' order by concat(date,time) desc limit 2000");
while($proshowshow = mysqli_fetch_array($proshow))
{
   $customer_code = $proshowshow['customer'];
   $customer_data = mysqli_query($connect,"select name from customerdetails where code = '$customer_code' and status!='deleted'");
   $customer_name = mysqli_fetch_assoc($customer_data)['name'];
   $customer_data_gst = mysqli_query($connect,"select gst from customerdetails where code = '$customer_code' and status!='deleted'");
   //echo "select gst from customerdetails where code = '$customer_code'";
   $gstin = mysqli_fetch_assoc($customer_data_gst)['gst'];
   $product_code = $proshowshow['product'];
   $product_data = mysqli_query($connect,"select productname from productdetail where productcode = '$product_code'");
   $product_name = mysqli_fetch_assoc($product_data)['productname'];
   $tkt[]=(object)['salescode'=>$proshowshow['salescode'],'ticket'=>$proshowshow['ticket'],'chakka'=>$proshowshow['chakka'],'vehicleno'=>$proshowshow['vehicleno'],'delivery'=>$proshowshow['delivery'],'customer'=>$proshowshow['customer'],'product'=>$proshowshow['product'],'price'=>$proshowshow['price'],'priceori'=>$proshowshow['priceori'],'date'=>$proshowshow['date'],'time'=>$proshowshow['time'],'processtype'=>$proshowshow['processtype'],'emptyweight'=>$proshowshow['emptyweight'],'loadweight'=>$proshowshow['loadweight'],'unitvalue'=>$proshowshow['unitvalue'],'netweight'=>$proshowshow['netweight'],'netqty'=>$proshowshow['netqty'],'netqtyori'=>$proshowshow['netqtyori'],'cft'=>$proshowshow['cft'],'customertype'=>$proshowshow['customertype'],'totalamount'=>$proshowshow['totalamount'],'remark'=>$proshowshow['remark'],'blockdate'=>$proshowshow['blockdate'],'editby'=>$proshowshow['editby'],'edittime'=>$proshowshow['edittime'],'editdate'=>$proshowshow['editdate'],'status'=>$proshowshow['status'],'supplier'=>$proshowshow['supplier'],'financialyear'=>$proshowshow['financialyear'],'tablename'=>$proshowshow['tablename'],'cusname'=>$customer_name,'productname'=>$product_name,'einvoicegenerated'=>$proshowshow['einvoice_generated'],'einvoiceid'=>$proshowshow['einvoice_id'],'gstin'=>$gstin];
}
echo json_encode($tkt);
?>