<?php
        session_cache_expire(1440);
        session_start();
        session_name("insys");
        include "include/config.php";
        include "include/functions.php";
        include "class/UctVw.php";
        $ssql="SELECT distinct a.ftitem_code,left(a.ftitem_code,16) as ftitem_code1,right(a.ftitem_code,4) as ftitem_code2
                    FROM 	txpurchase_order_det a
                    WHERE not exists(SELECT b.fnid FROM tlstock_hdr_bahan_baku b WHERE a.ftitem_code=b.ftitem_code)

                     ";

        $rs=mysql_query($ssql);
        $ssql1=array();
         mysql_query("BEGIN");
        while($r=mysql_fetch_assoc($rs)) {

             $ssql="INSERT INTO tlstock_hdr_bahan_baku
                            (
                                ftitem_code, ftitem_name, ftprint_name, ftitem_size, ftsupplier_code,
                                ftitem_code_supplier, ftitem_name_supplier, ftuom_code, ftstock_category_code, ftstock_group_code,
                                ftstock_group_code1, ftstock_group_code2, ftstock_group_code3, ftstock_group_code4, ftstock_group_code5,
                                ffweight, ftweight_code, ftdescription, ffreorder_level, ffmaximum_order,
                                fnstatus, fdcreated_date,fdmodified_date,ftcreated_user, ftmodified_user
                            )
                           SELECT '{$r['ftitem_code']}' as  ftitem_code, ftitem_name, ftprint_name, ftitem_size, '{$r['ftitem_code2']}' as  ftsupplier_code,
                                ftitem_code_supplier, ftitem_name_supplier, ftuom_code, ftstock_category_code, ftstock_group_code,
                                ftstock_group_code1, ftstock_group_code2, ftstock_group_code3, ftstock_group_code4, ftstock_group_code5,
                                ffweight, ftweight_code, ftdescription, ffreorder_level, ffmaximum_order,
                                fnstatus, fdcreated_date,fdmodified_date,ftcreated_user, ftmodified_user
                        FROM tlstock_hdr_bahan_baku
                        WHERE ftitem_code like '{$r['ftitem_code1']}%'
                        limit 1";

            $ssql1[]=$ssql;
            mysql_query($ssql);
        }
          mysql_query("COMMIT");
          pr($ssql1);