<?php
        session_cache_expire(1440);
        session_start();
        session_name("insys");
        include "../include/config.php";
        include "../include/functions.php";
        include "../class/UctVw.php";

        //$DateStart = date("Y-m-d");
        //$DateStart = "2017-12-31";

	$ssql=" SELECT ftitem_code, ftitem_name, COUNT(ftlocation_code) FROM tlstock_det
                GROUP BY ftitem_code
                HAVING COUNT(ftlocation_code) != 22
                ORDER BY ftitem_code
                LIMIT 300
              ";
        
	$rs1=mysql_query($ssql);
        // pr("sql 1 : {$ssql}");

        $counter_item = 0;
	while($r1=mysql_fetch_assoc($rs1)) {
                $ssql2="SELECT a.ftlocation_code, a.ftwarehouse_code FROM tllocation a
                        WHERE a.ftlocation_code NOT IN (SELECT ftlocation_code FROM tlstock_det WHERE ftitem_code = '{$r1['ftitem_code']}') ";
                $rs2=mysql_query($ssql2);     
                // pr("sql 2 : {$ssql2}");
                
                while($r2=mysql_fetch_assoc($rs2)) {  
                    $ssql3="INSERT INTO tlstock_det(ftBranch_Code,ftWarehouse_Code,ftLocation_Code,ftItem_Code,ftitem_name,
				ftBatch_Code,fnqty_on_hand,fnqty_available,ftCreated_User,fdCreated_Date,ftModified_User,fdModified_Date)
                            SELECT 'PUSAT','{$r2['ftwarehouse_code']}','{$r2['ftlocation_code']}','{$r1['ftitem_code']}','{$r1['ftitem_name']}',
                                    '' AS ftBatch_Code,'0' AS fnqty_on_hand,'0' AS fnqty_available,'admin',now(),'admin',now()
                          
                            ";

                    mysql_query($ssql3);
                    // pr("sql 3 : {$ssql3}");
                }    
                
                $counter_item=$counter_item+1;

	}

        pr("TOTAL ITEM : {$counter_item} . *** SELESAI ***");
        
?>