
PK 
<?php
ob_start();
//error_reporting(E_ALL ^ E_NOTICE);
@session_start();
ini_set('allow_url_include',1);
date_default_timezone_set("Asia/Kolkata");
set_time_limit(600);
ini_set('max_execution_time',600);
include '../includes/settings/constant.php';
//include '../includes/settings/db.php';
require_once '../includes/settings/PDODB.php';
include '../includes/modules/functions.php';
$function = new FUNCTIONS();
if(empty($_SESSION['adminId_cheesyBites'])){
header("Location: ../index.php");
exit();
}
$ipAddress = $function->getRealIpAddr();
$inventoryData = $function->getInventory($id=NULL,$itemCode=NULL,$itemType=NULL,$isActive=1);
$purchaseData = $function->getPurchase($pId=$_GET['id'],$customer_contactno=NULL,$isActive=1,$orderBy='ASC');
$purchaseItemData = $function->getPurchaseItems($id=NULL,$purchaseId=$_GET['id'],$inventoryId=NULL,$isActive=1,$orderBy=NULL);
if(isset($_POST['btneditPurchase'])){
print_r($_POST); exit;
//echo $current_timestamp;
$editDate = date("Y-m-d H:i:s");
//echo $editDate; exit;
$purchseid= !empty($_POST['purchseid'])?trim($_POST['purchseid']):"";
$customer_contactno= !empty($_POST['customer_contactno'])?trim($_POST['customer_contactno']):"$did";
$invoiceId= !empty($_POST['invoiceId'])?trim($_POST['invoiceId']):"";
$invoiceDate= !empty($_POST['invoiceDate'])?trim($_POST['invoiceDate']):"";
//print_r($customer_contactno); exit;
if (!empty($_POST['istate']) && $_POST['istate']=='DELHI') {
$cgst= !empty($_POST['cgst'])?trim($_POST['cgst']):"";
$sgst= !empty($_POST['sgst'])?trim($_POST['sgst']):"";
$igst= "";
}else{
$igst= !empty($_POST['igst'])?trim($_POST['igst']):"";
$cgst= "";
$sgst= "";
}
$pdodb = PDODB::getInstance();
$sql = "UPDATE `purchase` SET
customer_contactno='$customer_contactno',
invoiceId='$invoiceId',
invoiceDate='$invoiceDate',
cgst='$cgst',
sgst='$sgst',
igst='$igst',
editDate='$editDate'
WHERE pId = '".$purchseid."' ";
//exit;
$result = $pdodb->query($sql);
$sql2 = "UPDATE `purchase_items` SET invoiceDate='$invoiceDate' WHERE purchaseId = '".$purchseid."'";
$result2 = $pdodb->query($sql2);
if (!empty($result)) {
echo "<script>window.location.href='purchase-list.php';</script>";
}
//print_r($purchaseId); exit;
}
//delete item
if(!empty($_GET['itemid']) && ($_GET['action']=='Del')) {
//print_r($_GET); exit;
//$modifyDate = date("Y-m-d H:i:s");
$modifyDate=date("Y-m-d H:i:s");
//echo $modifyDate; exit;
$inventoryid=$_GET['inventoryid'];
$qty=$_GET['qty'];
$itemid=$_GET['itemid'];
$id=$_GET['id'];
$rate=$_GET['rate'];
$value = $rate*$qty;
//print_r($value); exit;
$pdodb = PDODB::getInstance();
$sql = "UPDATE `purchase_items` SET isActive=0, modifyDate='".$modifyDate."' WHERE id = '".$itemid."'";
//exit;
$result = $pdodb->query($sql);
$sql2 = "UPDATE `inventory` SET item_stock_qty = item_stock_qty - '".$qty."', item_value = item_value - '".$value."' WHERE id = '".$inventoryid."'"; //exit;
$result2 = $pdodb->query($sql2);
PDODB::closeInstance();
if(!empty($result)){
header("Location: purchase-edit.php?id=$id");
//echo '<script type="text/javascript">location.href("member-details.php?id=$id");</script>';
}
}
//end delete item
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>INSPINIA | Basic Form</title>
<?php include_once '../layout/style.php'; ?>
<style type="text/css">
.inpt-width {width: 60px;}
.itemCode {width: 60px;}
.hsnCode {width: 60px;}
.unit {width: 60px;}
.gstRate {width: 10px;}
.rateperunit {width: 60%;}
.qty {width: 60px;}
.total {width: 60%;}
.inpt-bgbord { border: none; background: transparent; }
span.select2-container { z-index:10050; }
</style>
</head>
<body>
<div id="wrapper">
<?php $currentPage = 'Purchase-list'; include_once '../layout/side-bar.php'; ?>
<div id="page-wrapper" class="gray-bg">
<?php include_once '../layout/header.php'; ?>
<div class="row wrapper border-bottom white-bg page-heading">
<div class="col-lg-10">
<h2></h2>
<h2>Edit Purchase Form</h2>
</div>
<div class="col-lg-2">
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="row">
<div class="col-lg-12" style="padding:0px;">
<div class="ibox float-e-margins">
<div class="ibox-title">
<?php if (!empty($statusMsg)) { ?>
<div class="alert alert-success" role="alert">
<button type="button" class="close" data-dismiss="alert">x</button>
<?=$statusMsg;?>
</div>
<?php } ?>
</div>
<form method="post" action="" enctype="multipart/form-data" id="formAddPurchase">
<div class="ibox-content">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label>Customer Mobile Number </label>
<input type="text" class="form-control" name="customer_contactno" id="customer_contactno" value="<?=!empty($purchaseData[0]['customer_contactno'])?$purchaseData[0]['customer_contactno']:'';?>" />
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Invoice No</label>
<input type="text" class="form-control" id="invoiceId" value="<?=!empty($purchaseData[0]['invoiceId'])?$purchaseData[0]['invoiceId']:'';?>" id="invoiceId" name="invoiceId" />
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<label>Datetime of Invoice</label>
<input type="text" class="form-control" readonly value="<?=date('d-M-Y h:i:s A', strtotime($purchaseData[0]['invoiceDate']));?>" id="invoiceDate" name="invoiceDate" />
</div>
</div>
</div>
</div>
<div class="ibox-content">
<div class="table-responsive">
<table class='table table-bordered' >
<thead>
<tr>
<th>Item Name</th>
<th>ItemCode</th>
<th>HSN code</th>
<th>Gst %</th>
<th>Rate/Unit</th>
<th>Qty</th>
<th>Total</th>
<th style="text-align: center;">Action</th>
</tr>
</thead>
<tbody id="tbl">
<?php
$total_amt = 0;
foreach ($purchaseItemData as $key => $value) {
$total_amt += (float)$value['total'];
foreach ($inventoryData as $isKey => $isValue) {
if($value['inventoryId']==$isValue['id']){
($itemName = $isValue['itemName']);
($itemCode = $isValue['itemCode']);
($hsnCode = $isValue['hsnCode']);
($gstRate = $isValue['gstRate']);
($inventoryid = $isValue['id']);
}
} ?>
<tr>
<td><?=$itemName;?></td>
<td class="td-itemCode"><?=$itemCode;?></td>
<td><?=$hsnCode;?></td>
<td><?=$gstRate;?></td>
<td><?=$value['rateperunit'];?></td>
<td><?=$value['qty'];?></td>
<td><?=$value['total'];?></td>
<td>
<a href='purchase-item-edit.php?inventoryid=<?=$inventoryid;?>&itemCode=<?=$itemCode;?>&hsnCode=<?=$hsnCode;?>&gstRate=<?=$gstRate;?>&rateperunit=<?=$value['rateperunit'];?>&qty=<?=$value['qty'];?>&total=<?=$value['total'];?>&itemid=<?=$value['id'];?>&pid=<?=$_GET['id'];?>&action=purchaseItemEdit' class='btn btn-primary btn-xs'><i class="fa fa-pencil"></i> Edit</a>
<a href='purchase-edit.php?itemid=<?=$value['id'];?>&inventoryid=<?=$inventoryid;?>&qty=<?=$value['qty'];?>&rate=<?=$value['rateperunit'];?>&id=<?=$_GET['id'];?>&action=Del' onclick='return confirm("Do you really want to delete!")' class='btn btn-danger btn-xs'>Delete</a>
</td>
</tr>
<?php } ?>
</tbody>
<tbody>
<tr>
<td colspan='6'> </td>
<td><b>Total : </b></td>
<td><input type="text" disabled class="form-control" id="total_amt" name="total_amt" value="<?=$total_amt;?>"></td>
<input type="text" class="form-control cgst hidden" id="hcgst" name="hcgst" value="<?=!empty($purchaseData[0]['cgst'])?trim($purchaseData[0]['cgst']):""?>">
</tr>
</tbody>
</table>
</div>
</div>
<div class="ibox-content">
<div class="row">
<div class="col-sm-6">
</div>
<div class="col-sm-4">
<div class="form-group text-right">
<button class="btn btn-primary" name="btneditPurchase" id="btneditPurchase" type="submit">Submit</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include_once '../layout/script.php'; ?>
<script>
$('#partyName').on('change', function() {
var partyaddress = $('select#partyName').find(':selected').data('partyaddress');
//$('#partyName option').find(':selected').attr("data-service");
//console.log(cat_id);
$("#partyAddress").val(partyaddress);
});
$('#partyName').on('change', function() {
var customer_contactno = $('select#partyName').find(':selected').data('customer_contactno');
//$('#partyName option').find(':selected').attr("data-service");
//console.log(cat_id);
$("#customer_contactno").val(customer_contactno);
});
$('#partyName').on('change', function() {
var partygst = $('select#partyName').find(':selected').data('partygst');
//$('#partyName option').find(':selected').attr("data-service");
//console.log(partyGst);
$("#partyGst").val(partygst);
});
$('#partyName').on('change', function() {
var state = $('select#partyName').find(':selected').data('state');
//$('#partyName option').find(':selected').attr("data-service");
//console.log(state);
$("#state").val(state);
});
$('#partyName').on('change', function() {
var state = $('select#partyName').find(':selected').data('state');
//$('#partyName option').find(':selected').attr("data-service");
//console.log(state);
$("#istate").val(state);
});
var aigst = $('.igst').val();
var acgst = $('#cgst').val();
if (aigst != '') {
document.getElementById("delhi").classList.add('hide');
document.getElementById("igst").classList.remove('hide');
var a = $('.igst').val();
var b = $('#total_amt').val();
var c = parseFloat(a) + parseFloat(b);
//Set
$('#grandtotal_amt').val(c);
}
if (acgst != '') {
document.getElementById("delhi").classList.remove('hide');
document.getElementById("igst").classList.add('hide');
//Get
var a = $('#cgst').val();
var b = $('#total_amt').val();
var c = $('#sgst').val();
//var d = a + b + c;
var d = parseFloat(a) + parseFloat(b) +parseFloat(c);
//alert($(this).val(d));
//Set
$('#grandtotal_amt').val(d);
}
$('#partyName').on('change', function() {
var state = $('select#partyName').find(':selected').data('state');
//var state = $('#state').find(':selected').data('state');
if(state=='DELHI'){
//console.log('vinay');
//document.getElementById("delhi").classList.add('show');
document.getElementById("delhi").classList.remove('hide');
document.getElementById("igst").classList.add('hide');
//document.getElementById("igst").classList.remove('show');
$("#grandtotal_amt").val(0);
$("#sgst").keyup(function() {
//Get
var a = $('#cgst').val();
var b = $('#total_amt').val();
var c = $('#sgst').val();
//var d = a + b + c;
var d = parseFloat(a) + parseFloat(b) +parseFloat(c);
//alert($(this).val(d));
//Set
$('#grandtotal_amt').val(d);
});
}else {
document.getElementById("delhi").classList.add('hide');
//document.getElementById("delhi").classList.remove('show');
//document.getElementById("igst").classList.add('show');
document.getElementById("igst").classList.remove('hide');
$("#grandtotal_amt").val(0);
$(".igst").keyup(function() {
//Get
var a = $('.igst').val();
var b = $('#total_amt').val();
var c = parseFloat(a) + parseFloat(b);
//Set
$('#grandtotal_amt').val(c);
});
}
});
$('#partyName').on('change', function() {
var pincode = $('select#partyName').find(':selected').data('pincode');
//$('#partyName option').find(':selected').attr("data-service");
//console.log(pincode);
$("#pincode").val(pincode);
});
$(".select2_demo_3").select2({
placeholder: "Select a name",
allowClear: true
});
var config = {
'.chosen-select' : {},
'.chosen-select-deselect' : {allow_single_deselect:true},
'.chosen-select-no-single' : {disable_search_threshold:10},
'.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
'.chosen-select-width' : {width:"95%"}
}
for (var selector in config) {
$(selector).chosen(config[selector]);
}
</script>
<script type="text/javascript">
$("#formAddPurchase").validate({
rules: {
itemName: {
required: true
},
invoiceId: {
required: true
},
invoiceDate: {
required: true
},
customer_contactno: {
required: true,
minlength: 10,
maxlength: 10,
//number: true
digits: true
}
},
messages: {
itemName: {
required: "Please Enter Itme Name"
},
invoiceId: {
required: "Please Enter Invoice Number"
},
invoiceDate: {
required: "Please Enter Invoice Date"
},
customer_contactno: {
required: "Please enter mobile No",
minlength: "Mobile No Must Contain at least 10 digit",
maxlength: "Mobile No Must Not Exceed 10 digit",
digits: "Please enter only digit"
}
},
submitHandler: function(form) {
form.submit();
}
});
</script>
</body>
</html>


PK 99