Skip to main content

store data to make grn and gp

 


<?php
require("connect.php");
session_start();
date_default_timezone_set('Asia/Kolkata');
$date = date("Y-m-d");
$time = date("h:i:sa");
$gp = rand(111, 999) . date("dmy") . date("hi");

if (isset($_GET['del'])) {
    $query = "UPDATE `cart` SET `status`='5' WHERE `id`='$_GET[del]'";
    if (mysqli_query($con, $query)) {
        echo "<script>window.location.href='brief.php?id=1&oid=$_GET[oid]'</script>";
    }
}
// if (isset($_GET['acc'])) {
//    
// }
if (isset($_POST['value'])) {
    $query = "SELECT * FROM `socitems` WHERE `id`='$_POST[prodid]'";
    $res = mysqli_query($con, $query);
    $row = mysqli_fetch_assoc($res);
    $rate0 = $_POST['quan'] * $row['rate'];
    $rate = $rate0 + ($rate0 * $row['gst']) / 100;
    $query0 = "SELECT * FROM `deduction` WHERE `dcscode`='$_POST[bmccode]'";
    $res0 = mysqli_query($con, $query0);
    $row0 = mysqli_fetch_assoc($res0);
    if (mysqli_num_rows($res0) == 0) {
        $query1 = "INSERT INTO `deduction`( `dcscode`, `amount`, `status`) VALUES ('$_POST[bmccode]','$rate','0')";
        mysqli_query($con, $query1);
    } else {
        $total = $rate + $row0['amount'];
        $query2 = "UPDATE `deduction` SET `amount`='$total' WHERE `dcscode`='$_POST[bmccode]'";
        mysqli_query($con, $query2);
    }
    $query1 = "UPDATE `cart` SET `status`='3',`dispatched`='$date',`aquan`='$_POST[quan]',`atotal`='$rate'  WHERE `id`='$_POST[id]'";
    if (mysqli_query($con, $query1)) {
        echo "<script>window.location.href='brief.php?id=2&oid=$_POST[oid]'</script>";
    }
    echo $rate . "<br>";
    echo $total . "<br>";
}

if (isset($_GET['oid'])) {
    $query = "UPDATE `oid` SET `status`='2' WHERE `oid`='$_GET[oid]'";
    if (mysqli_query($con, $query)) {
        echo "<script>window.location.href='index.php'</script>";
    }
}
if (isset($_GET['delgpprod'])) {
    $query1 = "SELECT * FROM `material` WHERE `matcode`='$_GET[pcode]'";
    $res1 = mysqli_query($store, $query1);
    $row1 = mysqli_fetch_assoc($res1);
    $value = $_GET['piss'] + $row1['stock'];
    $query2 = "UPDATE `material` SET `stock`='$value' WHERE `matcode`='$_GET[pcode]'";
    mysqli_query($store, $query2);
    $query = "DELETE FROM `gpprod` WHERE `id`='$_GET[delgpprod]'";
    if (mysqli_query($store, $query)) {
        echo "<script>window.location.href='gp0.php?gp=$_GET[gp]'</script>";
    }
}
if (isset($_GET['gpdel'])) {
    $query = "DELETE FROM `gp` WHERE `gatepass`='$_GET[gpdel]'";
    mysqli_query($store, $query);
    $query0 = "SELECT * FROM `gpprod` WHERE `gpno`='$_GET[gpdel]'";
    $res0 = mysqli_query($store, $query0);
    while ($row0 = mysqli_fetch_assoc($res0)) {
        $query1 = "SELECT * FROM `material` WHERE `matcode`='$row0[prodcode]'";
        $res1 = mysqli_query($store, $query1);
        $row1 = mysqli_fetch_assoc($res1);
        $value = $row0['issued'] + $row1['stock'];
        $query2 = "UPDATE `material` SET `stock`='$value' WHERE `matcode`='$row0[prodcode]'";
        mysqli_query($store, $query2);
        $query3 = "DELETE FROM `gpprod` WHERE `gpno`='$_GET[gpdel]'";
        mysqli_query($store, $query3);
    }
    echo "<script>window.location.href='vgp.php'</script>";
}
if (isset($_GET['trunc'])) {
    $query = "TRUNCATE TABLE $_GET[trunc]";
    if (mysqli_query($store, $query)) {
        $query0 = "INSERT INTO `history`( `name`,`tablename`, `tablerow`, `date`, `time`) VALUES ('$_SESSION[name]','$_GET[trunc]','truncate','$date','$time')";
        if (mysqli_query($store, $query0)) {
            echo "<script>window.location.href='index.php'</script>";
        }
    }
}
if (isset($_POST['updatemat'])) {
    $total = $_POST['rate'] + ($_POST['rate'] * $_POST['gst']) / 100 + ($_POST['rate'] * $_POST['cgst']) / 100 + ($_POST['rate'] * $_POST['sgst']) / 100;
    $query = "UPDATE `material` SET `username`='$_POST[username]',`matcode`='$_POST[matcode]',`matname`='$_POST[matname]',`gst`='$_POST[gst]',`cgst`='$_POST[cgst]',`sgst`='$_POST[sgst]',`hsn`='$_POST[hsn]',`unit`='$_POST[unit]',`rate`='$_POST[rate]',`total`='$total',`stock`='$_POST[stock]' WHERE `id`='$_POST[id]'";
    if (mysqli_query($store, $query)) {
        $query0 = "INSERT INTO `history`( `name`,`tablename`, `tablerow`, `date`, `time`) VALUES ('$_POST[username]','material','$_POST[matcode]','$date','$time')";
        if (mysqli_query($store, $query0)) {
            echo "<script>window.location.href='matstock0.php?matcode=$_POST[matcode]'</script>";
        }
    }
}
if (isset($_POST['addgp'])) {
    $society = $_POST['society'];
    $societycode = strtok($society, '-');
    $trans = strtoupper($_POST['trans']);
    $query1 = "SELECT * FROM `dcscust` WHERE `dcscode`='$societycode'";
    $res1 = mysqli_query($store, $query1);
    $row1 = mysqli_fetch_assoc($res1);
    $query2 = "SELECT * FROM `gp`";
    $res2 = mysqli_query($store, $query2);
    $gpid = mysqli_num_rows($res2) + 1;
    $query = "INSERT INTO `gp`( `username`,`gpid`, `gatepass`, `society`, `societyname`, `date`, `vehicle`, `rep`, `trans`, `address`, `status`) VALUES ('$_SESSION[name]','$gpid','$gp','$societycode','$row1[socname]','$date','$_POST[vehicle]','$_POST[rep]','$trans','$_POST[address]','0')";
    if (mysqli_query($store, $query)) {
        $query0 = "INSERT INTO `history`( `name`,`tablename`, `tablerow`, `date`, `time`) VALUES ('$_SESSION[name]','gate pass','$gp','$date','$time')";
        if (mysqli_query($store, $query0)) {
            echo "<script>window.location.href='gp0.php?gp=$gp'</script>";
        }
    }
}
if (isset($_POST['updategp'])) {
    $society = str_replace("(", "-", $_POST['society']);
    $societycode = strtok($society, '-');
    $vehicle = strtoupper($_POST['vehicle']);
    $trans = strtoupper($_POST['trans']);
    $query1 = "SELECT * FROM `dcscust` WHERE `dcscode`='$societycode'";
    $res1 = mysqli_query($store, $query1);
    $row1 = mysqli_fetch_assoc($res1);
    $query = "UPDATE `gp` SET `username`='$_SESSION[name]',`society`='$societycode',`societyname`='$row1[socname]',`vehicle`='$vehicle',`rep`='$_POST[rep]',`trans`='$trans',`address`='$_POST[address]' WHERE `gatepass`='$_POST[gp]'";
    if (mysqli_query($store, $query)) {
        $query0 = "INSERT INTO `history`( `name`,`tablename`, `tablerow`, `date`, `time`) VALUES ('$_SESSION[name]','gate pass edit','$gp','$date','$time')";
        if (mysqli_query($store, $query0)) {
            echo "<script>window.location.href='gp0.php?gp=$_POST[gp]'</script>";
        }
    }
}
if (isset($_POST['addgpprod'])) {
    $prod = $_POST['prod'];
    $prodcode = strtok($prod, '-');
    $query1 = "SELECT * FROM `material` WHERE `matcode`='$prodcode'";
    $res1 = mysqli_query($store, $query1);
    $row1 = mysqli_fetch_assoc($res1);
    $gst = $row1['gst'] + $row1['cgst'] + $row1['sgst'];
    $rate = $row1['total'] * $_POST['qiss'];
    $stock = $row1['stock'] - $_POST['qiss'];
    $query2 = "UPDATE `material` SET `stock`='$stock' WHERE `matcode`='$prodcode'";
    mysqli_query($store, $query2);
    $query = "INSERT INTO `gpprod`( `username`, `gpno`, `prodcode`, `prodname`, `unit`, `indent`, `issued`, `hsn`, `gst`, `rate`,`value`) VALUES ('$_SESSION[name]','$_POST[gpno]','$prodcode','$row1[matname]','$row1[unit]','$_POST[qind]','$_POST[qiss]','$row1[hsn]','$gst','$row1[total]','$rate')";
    if (mysqli_query($store, $query)) {
        $query0 = "INSERT INTO `history`( `name`,`tablename`, `tablerow`, `date`, `time`) VALUES ('$_SESSION[name]','gate pass prod','$_POST[gpno]','$date','$time')";
        if (mysqli_query($store, $query0)) {
            echo "<script>window.location.href='gp0.php?gp=$_POST[gpno]'</script>";
        }
    }
}

if (isset($_POST['addsection'])) {
    $query = "INSERT INTO `section`( `section`, `status`) VALUES ('$_POST[section]','1')";
    if (mysqli_query($store, $query)) {
        echo "<script>window.location.href='addsection.php'</script>";
    }
}
if (isset($_GET['secdel'])) {
    $query = "DELETE FROM `section` WHERE `id`='$_GET[secdel]'";
    if (mysqli_query($store, $query)) {
        echo "<script>window.location.href='addsection.php'</script>";
    }
}

if (isset($_POST['addgrn'])) {
    $query0 = "SELECT * FROM `grn`";
    $res0 = mysqli_query($store, $query0);
    $grn=mysqli_num_rows($res0)+1;
    $query1 = "SELECT * FROM `vendorent` WHERE `vendor`='$_POST[supplier]'";
    $res1 = mysqli_query($store, $query1);
    $row1 = mysqli_fetch_assoc($res1);
    $query = "INSERT INTO `grn`( `username`,`uid`, `dept`, `grnno`, `date`, `challan`, `challandate`, `pono`, `podate`, `supplier`,`suppliername`, `address`, `state`, `statecode`, `gstin`, `status`) VALUES ('$_SESSION[name]','$gp','$_POST[section]','$grn','$_POST[gdate]','$_POST[cno]','$_POST[cdate]','$_POST[pono]','$_POST[podate]','$row1[vendor]','$row1[name]','$row1[city]','$row1[state]','$row1[postal]','$row1[gstin]','0')";
    if (mysqli_query($store, $query)) {
        echo "<script>window.location.href='grn0.php?grn=$gp'</script>";
    }
}
if (isset($_POST['addgrnprod'])) {
    $prod = $_POST['prod'];
    $prodcode = strtok($prod, '-');
    $query1 = "SELECT * FROM `material` WHERE `matcode`='$prodcode'";
    $res1 = mysqli_query($store, $query1);
    $row1 = mysqli_fetch_assoc($res1);
    $gst = $row1['gst'] + $row1['cgst'] + $row1['sgst'];
    $rate = $row1['rate'] * $_POST['qty'];
    $stock = $row1['stock'] + $_POST['qty'];
    $total=($gst*$rate)/100+$rate;
    $query2 = "UPDATE `material` SET `stock`='$stock' WHERE `matcode`='$prodcode'";
    mysqli_query($store, $query2);
    $query = "INSERT INTO `grnprod`(`username`, `uid`, `prodcode`, `prodname`, `hsn`, `unit`, `qty`, `rate`, `amount`, `igst`, `cgst`, `sgst`, `total`, `status`) VALUES ('$_SESSION[name]','$_POST[uid]','$prodcode','$row1[matname]','$row1[hsn]','$row1[unit]','$_POST[qty]','$row1[rate]','$rate','$row1[gst]','$row1[cgst]','$row1[sgst]','$total','0')";
    if (mysqli_query($store, $query)) {
        $query0 = "INSERT INTO `history`( `name`,`tablename`, `tablerow`, `date`, `time`) VALUES ('$_SESSION[name]','GRN prod add','$_POST[uid]','$date','$time')";
        if (mysqli_query($store, $query0)) {
            echo "<script>window.location.href='grn0.php?grn=$_POST[uid]'</script>";
        }
    }
}
if (isset($_GET['delgrnprod'])) {
    $query1 = "SELECT * FROM `material` WHERE `matcode`='$_GET[pcode]'";
    $res1 = mysqli_query($store, $query1);
    $row1 = mysqli_fetch_assoc($res1);
    $value = $row1['stock']-$_GET['piss'];
    $query2 = "UPDATE `material` SET `stock`='$value' WHERE `matcode`='$_GET[pcode]'";
    mysqli_query($store, $query2);
    $query = "DELETE FROM `grnprod` WHERE `id`='$_GET[delgrnprod]'";
    if (mysqli_query($store, $query)) {
        echo "<script>window.location.href='grn0.php?grn=$_GET[gp]'</script>";
    }
}
?>

Comments

Popular posts from this blog

How to add the treeview numbers to get the grand total in tkinter entry box

 in this blog we are going to know about the adding of the integers in the treeview and get the total in the entry box of tkinter so here is the image first so the coding to do such things are here as follow but here is the condition that pls make assured that the state of entry box is disabled.......      for child in my_tree1 . get_children ():         e2l . config ( state = "normal" )         b1 += float ( my_tree1 . item ( child , "values" )[ 3 ])         var2 . set ( b1 )         e2l . config ( state = "disable" )      l2l = Label ( ento , text = "Purnea-2" , width = 8 )      l2l . grid ( row = 0 , column = 1 )     e2l = Entry ( ento , textvariable = var2 , state = "disable" , width = 8 )     e2l . grid ( row = 1 , column = 1 )