<?php
include "../../config/koneksi.php";



	$cek = mysql_query("
								select if((`jualcstaxdetail`.`qty` < 0),'Retur JualTax','KeluarTax') AS `jenis`,jualcstax.ucode,'Tax' as tax ,`jualcstax`.`billno` AS `billno`,`jualcstax`.`billdate` AS `billdate`
								,`jualcstax`.`cust` AS `cust`,(select `customer`.`nama` from `customer` where (`customer`.`id` = `jualcstax`.`cust`)) AS `custname`,`jualcstax`.`dateadded` AS `dateadded`
								,`jualcstaxdetail`.`produk` AS `produk`,(`jualcstaxdetail`.`qty` * -(1)) AS qty,`jualcstaxdetail`.`harga` AS `harga`
								from (`jualcstax` join `jualcstaxdetail` on(((`jualcstaxdetail`.`billno` = `jualcstax`.`billno`) and      
								(jualcstax.billdate >= '2022-07-01' and jualcstax.billdate < '2023-01-01') and 
								(convert(`jualcstaxdetail`.`ucode` using utf8) = convert(`jualcstax`.`ucode` using utf8)) 
								and (`jualcstax`.`status` <> 'D'))))
								");
	$i = 0;
	while ($r=mysql_fetch_array($cek)){	
			$i = $i + 1;
			// if ($i == 8220){
				// echo"$r[jenis], $r[billno],$r[billdate],$r[cust],$r[custname],$r[produk], $r[qty], $r[harga]";
			// }
			$custname = str_replace("'","",$r['custname']);
			mysql_query("INSERT INTO qqtmpproduk(jenis,billno,billdate,cust,custname,dateadded,produk,qty,harga,status,ucode,tax) VALUES('$r[jenis]','$r[billno]','$r[billdate]','$r[cust]','$custname','$r[dateadded]','$r[produk]','$r[qty]','$r[harga]','$i','$r[ucode]','$r[tax]')");


	}
	


	header('location:updatestokD2023a.php');

?>