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


	$cek = mysql_query("select if((`jualcsdetail`.`qty` < 0),'Retur Jual','Keluar') AS `jenis`,jualcs.ucode,'Non' as tax ,`jualcs`.`billno` AS `billno`,`jualcs`.`billdate` AS `billdate`
								,`jualcs`.`cust` AS `cust`,(select `customer`.`nama` from `customer` where (`customer`.`id` = `jualcs`.`cust`)) AS `custname`,`jualcs`.`dateadded` AS `dateadded`,`jualcsdetail`.`produk` AS `produk`
								,(`jualcsdetail`.`qty` * -(1)) AS qty,`jualcsdetail`.`harga` AS `harga` 
								from (`jualcs` join `jualcsdetail` on(((`jualcsdetail`.`billno` = `jualcs`.`billno`) 
								and (jualcs.billdate >='2022-06-01' and jualcs.billdate < '2023-01-01')
								and (convert(`jualcsdetail`.`ucode` using utf8) = convert(`jualcs`.`ucode` using utf8))
								and (`jualcs`.`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:updatestokB2023.php');

?>