<?php
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zyear1 = $_SESSION["zdbyear_" . $dbname];
$zyear = substr($zyear1, -4);
$zroot = $_SESSION["zdir"];
$zdir = substr($zroot, 0, -4);

//$dbyear = "msp_year";
$compcd = $_SESSION["comp_" . $dbname];

//browse($compcd);

$username = $_SESSION["username"];
$cacmst = "accmast";
$cgrpmast = "grpmast";
$cgrphead = "grphead";
$cstate = "state";
$cunit = "unit";
$cunitsub = "unitsub";
$citemunit = "itemunit";
$citempart = "itempart";
$citem = "item";
$citemgrp = "itemgrp";
$citemsubgrp = "itemsubgrp";
$citemsize = "itemsize";
$cbrand = "brand";
$cquality = "quality";
$csize = "size";

//$cnarration = "narration";
//$ctype = "type";
$cstkitem = "transacn";
$ctrans = "transport";

$zdb = $_SESSION["zdbyear_" . $dbname];
//browse($zdb);
mysqli_select_db($conn, $zdb);

function mysql_current_db() {
    $r = mysqli_query($conn, "SELECT DATABASE()") or die(mysqli_error($conn));
    //browse("Current DB->".mysql_result($r,0));
}

if (isset($_POST["save"])) {
    $fryear = $zdir . $compcd . '_' . $_POST["frmyear"];
    $toyear = $zdir . $compcd . '_' . $_POST["toyear"];
    /*     * **********Copying **************** */
    browse($fryear);
    browse($toyear);
//    die();
    mysqli_select_db($conn, $fryear);
    $acqry = mysqli_query($conn, "SELECT * FROM `$cacmst`") or die(mysqli_error($conn));
    $grpmqry = mysqli_query($conn, "SELECT * FROM `$cgrpmast`") or die(mysqli_error($conn));
    $grpheadqry = mysqli_query($conn, "SELECT * FROM `$cgrphead`") or die(mysqli_error($conn));
    $stateqry = mysqli_query($conn, "SELECT * FROM `$cstate` order by code") or die(mysqli_error($conn));
    $itemqry = mysqli_query($conn, "SELECT * FROM `$citem`") or die(mysqli_error($conn));
    $itemgrpqry = mysqli_query($conn, "SELECT * FROM `$citemgrp`") or die(mysqli_error($conn));
    $itempartqry = mysqli_query($conn, "SELECT * FROM `$citempart`") or die(mysqli_error($conn));
    $itemunitqry = mysqli_query($conn, "SELECT * FROM `$citemunit`") or die(mysqli_error($conn));
    $itemsizeqry = mysqli_query($conn, "SELECT * FROM `$citemsize`") or die(mysqli_error($conn));
    $unitqry = mysqli_query($conn, "SELECT * FROM `$cunit`") or die(mysqli_error($conn));
    $unitsubqry = mysqli_query($conn, "SELECT * FROM `$cunitsub`") or die(mysqli_error($conn));
    $sizeqry = mysqli_query($conn, "SELECT * FROM `$csize` group by brand,prodtype,type,size") or die(mysqli_error($conn));
    $qualqry = mysqli_query($conn, "SELECT * FROM `$cquality`") or die(mysqli_error($conn));
    $brandqry = mysqli_query($conn, "SELECT * FROM `$cbrand` group by brand,prodtype,type") or die(mysqli_error($conn));
    $stkitqry = mysqli_query($conn, "SELECT *,SUM(qty) as tqty 
                            FROM `$cstkitem` GROUP BY godown,prodcode") or die(mysqli_error($conn));
//    print table($stkitqry);
//    $opstkqry = mysqli_query($conn, "SELECT *,SUM(opening) as tqty 
//                            FROM `$cstkitem` GROUP BY itemcode") or die(mysqli_error($conn));
//      $getit = mysqli_fetch_object($stkitqry);
//    $balqty = $get["tqty"];

    browse('quality');
    while ($rowqual = mysqli_fetch_array($qualqry)) {
        $qlbrand = $rowqual["brand"];
        $qlprodtype = $rowqual["prodtype"];
        $qltype = $rowqual["type"];
        $qlord = $rowqual["ord"];



        mysqli_select_db($conn, $toyear);
        $chkql = mysqli_query($conn, "SELECT * FROM `$cquality` WHERE `prodtype`='$qlprodtype' and type='$qltype' and brand='$qlbrand'") or die(mysqli_error($conn));
        if (mysqli_num_rows($chkql) > 0) {
            
        } else {
            mysqli_query($conn, "INSERT INTO `$cquality`(`brand`, `prodtype`,`type`, `ord`)
                                          VALUES('$qlbrand', '$qlprodtype', '$qltype', '$qlord')") or die(mysqli_error($conn));
        }
    }
    browse('size');
    while ($rowsize = mysqli_fetch_array($sizeqry)) {
        $szbrand = $rowsize["brand"];
        $szprodtype = $rowsize["prodtype"];
        $sztype = $rowsize["type"];
        $szsize = $rowsize["size"];



        mysqli_select_db($conn, $toyear);
        $chksz = mysqli_query($conn, "SELECT * FROM `$csize` WHERE `prodtype`='$szprodtype' and type='$sztype' and brand='$szbrand' and size = '$szsize'") or die(mysqli_error($conn));
        if (mysqli_num_rows($chksz) > 0) {
            
        } else {
            mysqli_query($conn, "INSERT INTO `$csize`(`brand`, `prodtype`,`type`, `size`)
                                          VALUES('$szbrand', '$szprodtype', '$sztype', '$szsize')") or die(mysqli_error($conn));
        }
    }

    browse('brand');
    while ($rowbrand = mysqli_fetch_array($brandqry)) {
        $bdbrand = $rowbrand["brand"];
        $bdprodtype = $rowbrand["prodtype"];
        $bdtype = $rowbrand["type"];



        mysqli_select_db($conn, $toyear);
        $chkgrhdpmast = mysqli_query($conn, "SELECT * FROM `$cbrand` WHERE `prodtype`='$bdprodtype' and type='$bdtype' and brand='$bdbrand'") or die(mysqli_error($conn));
        if (mysqli_num_rows($chkgrhdpmast) > 0) {
            
        } else {
            mysqli_query($conn, "INSERT INTO `$cbrand`(`brand`, `prodtype`,`type`)
                                          VALUES('$bdbrand', '$bdprodtype', '$bdtype')") or die(mysqli_error($conn));
        }
    }

    browse('grphead');
    while ($rowhead = mysqli_fetch_array($grpheadqry)) {
        $grphdsrno = $rowhead["srno"];
        $grphdname = $rowhead["name"];
        $grphdtype = $rowhead["type"];
        $grphdsubtype = $rowhead["subtype"];
        $grphdcode = $rowhead["code"];


        mysqli_select_db($conn, $toyear);
        $chkgrhdpmast = mysqli_query($conn, "SELECT * FROM `$cgrphead` WHERE `code`='$grphdcode'") or die(mysqli_error($conn));
        if (mysqli_num_rows($chkgrhdpmast) > 0) {
            mysqli_query($conn, "UPDATE `$cgrphead` SET `name`='$grphdname', `type`='$grphdtype', `subtype`='$grphdsubtype'
                                                        WHERE code='$grphdcode'") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "INSERT INTO `$cgrphead`(`srno`, `code`, `name`, `type`, `subtype`)
                                          VALUES('$grphdsrno', '$grphdcode', '$grphdname', '$grphdtype', '$grphdsubtype')") or die(mysqli_error($conn));
        }
    }

    browse('grpmast');
    while ($row2 = mysqli_fetch_array($grpmqry)) {
        $grpcode = $row2["grpcode"];
        $name2 = $row2["name"];
        $type = $row2["type"];
        $subtype = $row2["subtype"];
        $add_info = $row2["add_info"];
        $initial = $row2["initial"];
        $headcode = $row2["headcode"];

        mysqli_select_db($conn, $toyear);
        $chkgrpmast = mysqli_query($conn, "SELECT * FROM `$cgrpmast` WHERE `grpcode`='$grpcode'") or die(mysqli_error($conn));
        if (mysqli_num_rows($chkgrpmast) > 0) {
            mysqli_query($conn, "UPDATE `$cgrpmast` SET `name`='$name2', `type`='$type', `subtype`='$subtype', `add_info`='$add_info', `initial`='$initial',
                                                         headcode='$headcode' WHERE grpcode='$grpcode'") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "Insert into $toyear.$cgrpmast Select * from $fryear.$cgrpmast where grpcode='$grpcode'") or die(mysqli_error($conn));

//            mysqli_query($conn, "INSERT INTO `$cgrpmast`(`grpcode`, `name`, `type`, `subtype`, `add_info`, `initial`, headcode)
//                                                 VALUES('$grpcode', '$name2', '$type', '$subtype', '$add_info', '$initial', '$headcode')") or die(mysqli_error($conn));
        }
    }
//    /*     * **********accmast **************** */
    browse('accmast');
    while ($row = mysqli_fetch_array($acqry)) {
        $accode = $row["accode"];
        $name = mysqli_real_escape_string($conn, $row["name"]);
//        $consname = $row["consname"];
        $add1 = mysqli_real_escape_string($conn, $row["add1"]);
        $add2 = mysqli_real_escape_string($conn, $row["add2"]);
        $add3 = mysqli_real_escape_string($conn, $row["add3"]);
//        $add4 = $row["add4"];
        $grpcode = $row["grpcode"];
        $custtype = $row["custtype"];
        $custcode = $row["custcode"];
        $deptcode = $row["deptcode"];
        $nameprin = $row["nameprin"];
        $type = $row["type"];
        $init = $row["init"];
        $bankinit = $row["bankinit"];
        $tinno = $row["tinno"];
        $city = $row["city"];
        $pin = $row["pin"];
        $country = $row["country"];
        $station = $row["station"];
        $tel = $row["tel"];
        $fax = $row["fax"];
        $mobile = $row["mobile"];
        $mobile2 = $row["mobile2"];
        $email = $row["email"];
        $openbal = $row["openbal"];
        $dc = $row["dc"];
        $owner = $row["owner"];
        $creditlimit = $row["credlimit"];
        $website = $row["website"];
        $contpers = $row["contpers"];
        $vattin = $row["vattin"];
        $csttin = $row["csttin"];
        $pattern = $row["pattern"];
        $closbal = $row["closbal"];
        $closbdc = $row["closbc"];
        $pfund = $row["pfund"];
        $saltype = $row["saltype"];
        $salwise = $row["salwise"];
        $salmon = $row["salmon"];
        $travmon = $row["travmon"];
        $convmon = $row["convmon"];
        $p_tax = $row["p_tax"];
        $leaveflag = $row["leaveflag"];
        $leavecode = $row["leavecode"];
        $esic = $row["esic"];
        $salary = $row["salary"];
        $active = $row["active"];
        $username = $row["username"];
        $pan = $row["pan"];
        $staff = $row["staff"];
        $transporter = $row["transporter"];
        $state = $row["state"];
        $statecode = $row["statecode"];
        $gstno = $row["gstno"];
        $increcode = $row["increcode"];
//        $transport = $row["transport"];
        $lbt = $row["lbt"];
//        $discount = $row["discount"];
//        $commperc = $row["commperc"];
//        $ledgfrom = $row["ledgfrom"];
//        $ledgto = $row["ledgto"];

        if ($dc == "D") {
            $topen = abs($openbal) * -1;
        } else {
            $topen = abs($openbal);
        }
        if ($accode == "51") {
            mysql_current_db();
        }





        /*        if($accode=="51"){
          browse($balamt);
          browse($nopen);
          browse($topen);
          browse($tdc);
          } */

        mysqli_select_db($conn, $toyear);
        $chkac = mysqli_query($conn, "SELECT * FROM `$cacmst` WHERE accode = '$accode'");
        if (mysqli_num_rows($chkac) > 0) {
            mysqli_query($conn, "UPDATE `$cacmst` SET `name`='$name', `add1`='$add1', `add2`='$add2', `add3`='$add3',
                                           `grpcode`='$grpcode', `custtype`='$custtype', `custcode`='$custcode', `deptcode`='$deptcode', 
                                           `nameprin`='$nameprin', `type`='$type', `init`='$init', `bankinit`='$bankinit', `tinno`='$tinno', `city`='$city',  
                                           `pin`='$pin', `country`='$country',  `tel`='$tel', `fax`='$fax', `mobile`='$mobile',
                                           `mobile2`='$mobile2', `email`='$email', openbal='$topen', `dc`='$tdc', `owner`='$owner',credlimit='$creditlimit',
                                           `website`='$website', `contpers`='$contpers', `vattin`='$vattin', `csttin`='$csttin',
                                           `pattern`='$pattern', closbal='$closbal', `closdc`='$closbdc', `pfund`='$pfund',currbal='$currbal',currdc='$currdc',
                                           `saltype`='$saltype', `salwise`='$salwise', salmon='$salmon', travmon='$travmon',
                                            convmon='$convmon', `p_tax`='$p_tax', `leaveflag`='$leaveflag', `leavecode`='$leavecode',
                                           `esic`='$esic', salary='$salary', active='$active', `username`='$username', 
                                           `pan`='$pan', staff='$staff', transporter ='$transporter', `state`='$state', `statecode`='$statecode',`gstno`='$gstno', `increcode`='$increcode',
                                           `lbt`='$lbt' WHERE accode = $accode") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "Insert into $toyear.$cacmst Select * from $fryear.$cacmst where accode='$accode'") or die(mysqli_error($conn));

            mysqli_query($conn, "UPDATE $toyear.$cacmst SET openbal='$topen', `dc`='$tdc',currbal='$currbal',currdc='$currdc',closbal='$closbal',closdc='$closbdc' WHERE accode = '$accode'") or die(mysqli_error($conn));
//            mysqli_query($conn, "INSERT INTO `$cacmst`(`accode`,`name`, `add1`, `add2`, `add3`, `grpcode`, `custtype`, `custcode`, `deptcode`,
//                                               `nameprin`, `type`, `init`, `bankinit`, `tinno`, `city`, `pin`, `country`, `station`, `tel`, `fax`,
//                                                `mobile`, `mobile2`, `email`, openbal, `dc`, `owner`, credlimit, `website`, `contpers`, 
//                                               `vattin`, `csttin`, `pattern`, closbal, `closdc`, `pfund`, `saltype`, `salwise`, salmon, 
//                                                travmon, convmon, `p_tax`, `leaveflag`, `leavecode`, `esic`, salary, active, `username`, `pan`,
//                                                staff, transporter, `lbt`,`state`, `statecode`,`gstno`, `increcode`)
//   
//                                        VALUES('$accode', '$name', '$add1', '$add2', '$add3', '$grpcode', '$custtype', '$custcode', '$deptcode',
//                                               '$nameprin', '$type', '$init', '$bankinit', '$tinno', '$city', '$pin', '$country', '$station', '$tel', '$fax', 
//                                               '$mobile', '$mobile2', '$email', '$topen', '$tdc', '$owner', '$website', '$creditlimit', '$contpers', 
//                                               '$vattin', '$csttin', '$pattern', '$closbal', '$closbdc', '$pfund', '$saltype', '$salwise', '$salmon', 
//                                               '$travmon', '$convmon', '$p_tax', '$leaveflag', '$leavecode', '$esic', '$salary', '$active', '$username', '$pan', 
//                                               '$staff', '$transporter', '$lbt', '$state', '$statecode','$gstno', '$increcode')") or die(mysqli_error($conn));
        }
    }

    browse('state');
    while ($rowstate = mysqli_fetch_array($stateqry)) {
        $stcode = $rowstate["code"];
        $ststcode = $rowstate["stcode"];
        $stname = $rowstate["name"];

        mysqli_select_db($conn, $toyear);
        $chkstate = mysqli_query($conn, "SELECT * FROM `$cstate` WHERE `code`='$stcode'") or die(mysqli_error($conn));
        if (mysqli_num_rows($chkstate) > 0) {
            mysqli_query($conn, "UPDATE `$cstate` SET `name`='$stname', stcode='$ststcode' WHERE code='$stcode'") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "Insert into $toyear.$cstate Select * from $fryear.$cstate where code='$stcode'") or die(mysqli_error($conn));

//            mysqli_query($conn,  "INSERT INTO `$cunit`(`code`, `name`)
//                                     VALUES('$unitcode', '$unitname')") or die(mysqli_error($conn));
        }
    }



    browse('item');
    while ($rowitm = mysqli_fetch_array($itemqry)) {
        $itmcode = $rowitm["code"];
        $prodtype = $rowitm["prodtype"];
        $brand = $rowitm["brand"];
        $size = $rowitm["size"];
        $prodname = $rowitm["prodname"];
        $quality = $rowitm["quality"];
        $unit = $rowitm["unit"];
        $pcsinunit = $rowitm["pcsinunit"];
        $hsncode = $rowitm["hsncode"];
        $gstperc = $rowitm["gstperc"];



        mysqli_select_db($conn, $toyear);
        $chkitem = mysqli_query($conn, "SELECT * FROM `$citem` WHERE `code`='$itmcode'") or die(mysqli_error($conn));
        if (mysqli_num_rows($chkitem) > 0) {
            mysqli_query($conn, "UPDATE $citem SET `prodtype`='$prodtype', `brand`='$brand', `size`='$size',`prodname`='$prodname',
                                                   `quality`='$quality', `unit`='$unit', `pcsinunit`='$pcsinunit',
                                                   `hsncode`='$hsncode', `gst`='$gstperc' WHERE code = '$itmcode' ") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "Insert into $toyear.$citem Select * from $fryear.$citem where code='$itmcode'") or die(mysqli_error($conn));
        }
    }
//    
//
    browse('unit');
    while ($rowunit = mysqli_fetch_array($unitqry)) {
        $unitcode = $rowunit["code"];
        $unitname = $rowunit["name"];

        mysqli_select_db($conn, $toyear);
        $chkunit = mysqli_query($conn, "SELECT * FROM `$cunit` WHERE `code`='$unitcode'") or die(mysqli_error($conn));
        if (mysqli_num_rows($chkunit) > 0) {
            mysqli_query($conn, "UPDATE `$cunit` SET `name`='$unitname' WHERE code='$unitcode'") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "Insert into $toyear.$cunit Select * from $fryear.$cunit where code='$unitcode'") or die(mysqli_error($conn));
        }
    }
    browse('unitsub');

    while ($rowunitsub = mysqli_fetch_array($unitsubqry)) {
        $unitsubmm = $rowunitsub["mm"];
        $unitsubname = $rowunitsub["name"];
        $unitsubvalue = $rowunitsub["value"];

        mysqli_select_db($conn, $toyear);
        $chkunitsub = mysqli_query($conn, "SELECT * FROM `$cunitsub` WHERE `mm`='$unitsubmm'") or die(mysqli_error($conn));
        if (mysqli_num_rows($chkunitsub) > 0) {
            mysqli_query($conn, "UPDATE `$cunitsub` SET `name`='$unitsubname', value='$unitsubvalue' WHERE mm='$unitsubmm'") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "Insert into $toyear.$cunitsub Select * from $fryear.$cunitsub where mm='$unitsubmm'") or die(mysqli_error($conn));
        }
    }
//    
    browse('itemunit');

    while ($rowitunit = mysqli_fetch_array($itemunitqry)) {
        $itunitsrno = $rowitunit["srno"];
        $itunitcode = $rowitunit["code"];
        $itunitunit = $rowitunit["unit"];
        $itunitconvfact = $rowitunit["convfact"];

        mysqli_select_db($conn, $toyear);
        $chktypest1 = mysqli_query($conn, "SELECT * FROM `$citemunit` WHERE `code`='$itunitcode' and srno='$itunitsrno'") or die(mysqli_error($conn));
        if (mysqli_num_rows($chktypest1) > 0) {
            mysqli_query($conn, "UPDATE `$citemunit` SET `unit`='$itunitunit',`convfact`='$itunitconvfact' WHERE code='$itunitcode' and srno='$itunitsrno'") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "Insert into $toyear.$citemunit Select * from $fryear.$citemunit where code='$itunitcode' and srno = '$itunitsrno'") or die(mysqli_error($conn));

//            mysqli_query($conn, "INSERT INTO `$citemunit`(`code`, `name`, `itemgrp`)
//                                     VALUES('$itunitcode', '$itunitname', '$itunititemgrp')") or die(mysqli_error($conn));
        }
    }
    browse('itempart');

    while ($rowitpart = mysqli_fetch_array($itempartqry)) {
        $itpartsrno = $rowitpart["sr"];
        $itpartcode = $rowitpart["code"];
        $itpartname = $rowitpart["name"];
        $itpartdescrip = mysqli_real_escape_string($conn, $rowitpart["descrip"]);

        mysqli_select_db($conn, $toyear);
        $chktypest1 = mysqli_query($conn, "SELECT * FROM `$citempart` WHERE `code`='$itpartcode' and sr='$itpartsrno'") or die(mysqli_error($conn));
        if (mysqli_num_rows($chktypest1) > 0) {
            mysqli_query($conn, "UPDATE `$citempart` SET `name`='$itpartpart',`descrip`='$itpartdescrip' WHERE code='$itpartcode' and sr='$itpartsrno'") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "Insert into $toyear.$citempart Select * from $fryear.$citempart where code='$itpartcode' and sr = '$itpartsrno'") or die(mysqli_error($conn));

//            mysqli_query($conn, "INSERT INTO `$citempart`(`code`, `name`, `itemgrp`)
//                                     VALUES('$itpartcode', '$itpartname', '$itpartitemgrp')") or die(mysqli_error($conn));
        }
    }
    browse('itemgroup');

    while ($rowitgrp = mysqli_fetch_array($itemgrpqry)) {
        $itgrpcode = $rowitgrp["code"];
        $itgrpname = $rowitgrp["name"];
        $itgrphsncode = $rowitgrp["hsncode"];
        $itgrpgstperc = $rowitgrp["gstperc"];

        mysqli_select_db($conn, $toyear);
        $chktypest = mysqli_query($conn, "SELECT * FROM `$citemgrp` WHERE `code`='$itgrpcode'") or die(mysqli_error($conn));
        if (mysqli_num_rows($chktypest) > 0) {
            mysqli_query($conn, "UPDATE `$citemgrp` SET `name`='$itgrpname',`hsncode`='$itgrphsncode',`gstperc`='$itgrpgstperc' WHERE code='$itgrpcode'") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "Insert into $toyear.$citemgrp Select * from $fryear.$citemgrp where code='$itgrpcode'") or die(mysqli_error($conn));
        }
    }
    browse('stock');
    mysqli_query($conn, "Delete from transacn where source = 'OP'");

    $srl = 0;
    while ($stkitm = mysqli_fetch_array($stkitqry)) {
        $srl++;

        $barcode = $stkitm['prodcode'];
        $icode = $stkitm['prodcode'];
        $prodtype = $stkitm['prodtype'];
        $size = $stkitm['size'];
        $brand = $stkitm['brand'];
        $quality = $stkitm['quality'];
        $prodname = $stkitm['prodname'];

        $itemgrp = $stkitm["itemgrp"];
        $item = $stkitm["itemcode"];
        $hsncode = $stkitm["hsncode"];
        $godown = $stkitm["godown"];
//        $size = $stkitm["size"];
        $unit = mysqli_real_escape_string($conn, $stkitm["unit"]);
        $stkitemcode = $stkitm["itemcode"];
        $balqty = $stkitm["tqty"];
        mysqli_select_db($conn, $fryear);
//        $chkopenqty = mysqli_query($conn, "SELECT opening, code FROM `$citem` WHERE `code`='$stkitemcode'") or die(mysqli_error($conn));
//        $fetopenit = mysqli_fetch_array($chkopenqty);
//        $openqty = $fetopenit["opening"];
//
//        $totqty = $openqty + $balqty;
        $group = 'OP' . $item;
        mysqli_select_db($conn, $toyear);
        mysqli_query($conn, "INSERT INTO `transacn`(`source`, `yearno`, `vouchno`, `vouchdt`, `srno`, `prodcode`, `prodtype`, 
                                                           `brand`, `size`, `prodname`, `quality`, `qty`, godown, hsncode,
                                                           `group`)
                                                    VALUES('OP', '$myyear', '$mvouch', '$vouchdt', '$srl', '$barcode', '$prodtype',
                                                           '$brand', '$size', '$prodname', '$quality', '$balqty', '$godown', '$hsncode',
                                                           '$group')") or die(mysqli_error($conn));
//        mysqli_query($conn, "UPDATE `$citem` SET `opening`='$totqty' WHERE code='$stkitemcode'") or die(mysqli_error($conn));
//        mysqli_query($conn, "INSERT INTO `$cstkitem`( `yearno`, `srno`, `source`, `vouchno`, `vouchdt`, `size`, `itemcode`, `itemgrp`, `qty`, `ordno`, `trangrp`, `unit`, `group`, `accode`)
//                                        VALUES( '$toyear',  '$srl', 'OP', '', '0000-00-00', '$size', '$item', '$itemgrp', '$balqty', '1', '', '$unit', '$group', '')") or die(mysqli_error($conn));
    }





    browse("Processing Complete");
    header("refresh: 1;yearend.php");
}
include("includes/linkshead.php");
?>



</head>
<body onLoad="">
    <form action=''  name="yearend" method="POST">
        <div class="panel-body" style="border: 1px solid black;">
            <div class="row">
                <div class="col-lg-12" style=''>
                    <div class="row">
                        <div class="col-lg-2"></div>
                        <div class="col-lg-2 text-right">
                            <label class="control-label">From Year</label>
                        </div>
                        <div class="col-lg-2">
                            <select name="frmyear" class="form-control" >
                                <?php
                                require("includes/dbconnect.php");

                                $fyear = mysqli_query($conn, "SELECT * FROM `compyear` where finyear = '$zyear' group by `finyear` order by `lastdate` DESC") OR die(mysqli_error($conn));
                                while ($rowf = mysqli_fetch_array($fyear)) {
                                    echo "<option value=\"$rowf[finyear]\">$rowf[finyear]</option>";
                                }
                                ?>
                            </select>
                        </div>

                    </div>
                    <br>
                    <div class="row">
                        <div class="col-lg-2"></div>
                        <div class="col-lg-2 text-right">
                            <label class="control-label">To Year</label>
                        </div>
                        <div class="col-lg-2">
                            <select name="toyear" class="form-control" >
                                <?php
//                            require("includes/dbconnect.php");
                                $tyear = mysqli_query($conn, "SELECT * FROM `compyear` WHERE finyear !='$zyear' group by `finyear`  ORDER BY `lastdate`") OR die(mysqli_error($conn));
                                while ($rowt = mysqli_fetch_array($tyear)) {
                                    echo "<option value=\"$rowt[finyear]\">$rowt[finyear]</option>";
                                }
                                ?>
                            </select>
                        </div>

                    </div>
                    <br>
                    <br>
                    <div class="row">
                        <div class="col-lg-4"></div>
                        <div class="col-lg-2">
                            <input type="submit" name="save" value="Proceed" class="btn btn-primary">
                            <!--<input type="button" name="exit" value="Exit" class="btn btn-danger" href="default.php">-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <?php include("includes/linksfoot.php"); ?>
</body>
</html>