Skip to content

Instantly share code, notes, and snippets.

@sudhakar191
Created April 12, 2024 05:36
Show Gist options
  • Save sudhakar191/03df83cb4434979e89a379d86f6904af to your computer and use it in GitHub Desktop.
Save sudhakar191/03df83cb4434979e89a379d86f6904af to your computer and use it in GitHub Desktop.
<?php
session_start();
// error log
ini_set('display_errors', 0); error_reporting(0);
// set header to utf-8
header ('Content-type: text/html; charset=utf-8');
include '../../../inc/session_proof.php';
include '../../../inc/db_connect.php';
$basisdir = $_SESSION['basisdir'];
include_once("../../config.php");
include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
// Database config file to be passed in phpgrid constructor
$db_conf = array(
"type" => PHPGRID_DBTYPE,
"server" => PHPGRID_DBHOST,
"user" => PHPGRID_DBUSER,
"password" => PHPGRID_DBPASS,
"database" => PHPGRID_DBNAME
);
// first grid (User Activation)
$g = new jqgrid($db_conf);
$grid["caption"] = "Open order Add/Edit"; // caption of grid
$grid["sortname"] = 'vendor_name'; // by default sort grid by this field
$grid["sortorder"] = "asc"; // ASC or DESC
$grid["hiddengrid"] = false;
$grid["autowidth"] = true; // expand grid to screen width
$grid["shrinkToFit"] = false; // dont shrink to fit on screen
$grid["autoresize"] = true; // responsiveresponsive effect
$grid["responsive"] = true; // responsiveresponsive effect
$grid["height"] = "auto"; // required for iphone/safari scroll display (e.g. "400", "auto")
$grid["scroll"] = false;
$grid["rowNum"] = 20; // by default 20
$grid["rowList"] = array(20,50,100,250,500);
$grid["footerrow"] = false; // Show footer row
$grid["userDataOnFooter"] = false; // Fill footer row with userdata (with on_data_display event)
$grid["multiselect"] = true; // allow you to multi-select through checkboxes
$grid["cellEdit"] = false;
$grid["reloadedit"] = true; // auto reload after editing
$grid["multiSort"] = false; // multi-sorting
$grid["tooltip"] = true;
$grid["toolbar"] = "bottom";
$grid["toppager"] = false;
$grid["altRows"] = true;
$grid["view_options"]["rowButton"] = true;
// show reload link with dropdown
$grid["add_options"]["afterShowForm"] = 'function(formid){ add_dropdown_action(formid); }';
//$grid["edit_options"]["afterShowForm"] = 'function(formid){ add_dropdown_action(formid); }';
$g->set_options($grid);
$g->set_actions(array(
"edit"=>true, // allow/disallow edit
"rowactions"=>true, // show/hide row wise edit/del/save option
"add"=>true, // allow/disallow add
"view"=>true,
"clone"=>false, // allow/disallow edit
"delete"=>true, // allow/disallow delete
"bulkedit"=>true, // allow/disallow delete
"showhidecolumns"=>true, // allow/disallow delete
"export_pdf"=>false,
"export_excel"=>false, // show/hide export to excel option
"autofilter" => true, // show/hide autofilter for search
"search" => "advance" // show single/multi field search condition (e.g. simple or advance)
)
);
// you can provide custom SQL query to display data
#$g->select_command = "";
// you can provide custom SQL count query to display data
//$g->select_count = "SELECT count(*) as c FROM invheader i INNER JOIN clients c ON c.client_id = i.client_id";
// this db table will be used for add,edit,delete
$g->select_command = "SELECT * FROM zds_openorder where status !='purchased order'";
$g->table = "zds_openorder";
$col = array();
$col["title"] = "Order id"; // caption of column
$col["name"] = "order_id";
$col["hidden"] = true;
$col["viewable"] = true;
$col["editable"] = false;
$col["isnull"] = false;
$cols[] = $col;
// $col = array();
// $col["title"] = "Order id"; // caption of column
// $col["name"] = "order_id";
// $col["width"] = "100";
// $col["search"] = true;
// $col["hidden"] = false;
// $col["hidedlg"] = false;
// $col["viewable"] = true;
// $col["editable"] = false;
// $col["isnull"] = false;
// $col["resizable"] = true;
// $cols[] = $col;
$col = array();
$col["title"] = "Offer no";
$col["name"] = "offer_name";
$col["align"] = "left";
$col["hidden"] = false;
$col["viewable"] = true;
$col["width"] = "70";
$col["search"] = true;
$col["editable"] = true;
$col["isnull"] = false;
$col["resizable"] = true;
$col["export"] = true;
$col["editrules"] = array("required" => true);
$cols[] = $col;
$col = array();
$col["title"] = "Offer date";
$col["name"] = "offer_date";
$col["align"] = "left";
$col["hidden"] = false;
$col["viewable"] = true;
$col["width"] = "150";
$col["search"] = true;
$col["editable"] = true;
$col["isnull"] = false;
$col["resizable"] = true;
$col["formatter"] = "date";
$col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'Y-m-d');
$col["editrules"] = array("required" => true);
$cols[] = $col;
// $col = array();
// $col["title"] = "Expiry date";
// $col["name"] = "expiry_date";
// $col["align"] = "left";
// $col["hidden"] = false;
// $col["viewable"] = true;
// $col["width"] = "150";
// $col["search"] = true;
// $col["editable"] = true;
// $col["isnull"] = false;
// $col["resizable"] = true;
// $col["formatter"] = "date";
// $col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'Y-m-d');
// $col["editrules"] = array("required" => true);
// $cols[] = $col;
$col = array();
$col["title"] = "Vendor";
$col["name"] = "vendor_name";
$col["align"] = "left";
$col["hidden"] = false;
$col["viewable"] = true;
$col["width"] = "150";
$col["search"] = true;
$col["editable"] = true;
$col["isnull"] = false;
$col["resizable"] = true;
$str = $g->get_dropdown_values("select distinct name as k, name as v from zds_names where type='supplier' ORDER BY k ASC");
$col["editoptions"] = array("value" => ":;".$str);
$col["edittype"] = "select";
$col["export"] = true;
$col["editrules"] = array("required" => true);
$col["stype"] = "select-multiple";
$col["searchoptions"] = array("value" => ":;".$str);
$cols[] = $col;
$col = array();
$col["title"] = "Item no";
$col["name"] = "product_no";
$col["align"] = "left";
$col["hidden"] = false;
$col["viewable"] = true;
$col["width"] = "150";
$col["search"] = true;
$col["editable"] = true;
$col["isnull"] = false;
$col["resizable"] = true;
$str = $g->get_dropdown_values("SELECT stm_artnr AS k, stm_artnr AS v FROM zds_total ORDER BY stm_artnr ASC");
//$col["editoptions"] = array("value" => ":;".$str);
$col["stype"] = "select-multiple";
$col["export"] = true;
//$col["searchoptions"] = array("value" => ":;".$str);
$col["editrules"] = array("required" => true);
$cols[] = $col;
$col = array();
$col["title"] = "Quantity";
$col["name"] = "quantity";
$col["align"] = "left";
$col["hidden"] = false;
$col["viewable"] = true;
$col["width"] = "150";
$col["search"] = true;
$col["editable"] = true;
$col["isnull"] = false;
$col["resizable"] = true;
$col["formatter"] = "number";
$col["export"] = true;
$col["editrules"] = array("required" => true);
$cols[] = $col;
$col = array();
$col["title"] = "Price &nbsp;&euro;";
$col["name"] = "price";
$col["align"] = "left";
$col["hidden"] = false;
$col["viewable"] = true;
$col["width"] = "150";
$col["search"] = true;
$col["editable"] = true;
$col["isnull"] = false;
$col["resizable"] = true;
$col["formatter"] = "number";
$col["formatoptions"] = array("thousandsSeparator" => ",",
"decimalSeparator" => ".",
"decimalPlaces" => 0);$col["export"] = true;
$col["editrules"] = array("required" => true);
$cols[] = $col;
// $col = array();
// $col["title"] = "Product tax";
// $col["name"] = "product_tax";
// $col["align"] = "left";
// $col["hidden"] = false;
// $col["viewable"] = true;
// $col["width"] = "150";
// $col["search"] = true;
// $col["editable"] = true;
// $col["isnull"] = false;
// $col["resizable"] = true;
// $col["formatter"] = "number";
// $col["formatoptions"] = array("thousandsSeparator" => ",",
// "decimalSeparator" => ".",
// "decimalPlaces" => 0);$col["export"] = true;
// $cols[] = $col;
$col = array();
$col["title"] = "Total amount &nbsp;&euro;";
$col["name"] = "total_amount";
$col["align"] = "left";
$col["hidden"] = false;
$col["viewable"] = true;
$col["width"] = "150";
$col["search"] = true;
$col["editable"] = true;
$col["isnull"] = false;
$col["resizable"] = true;
$col["formatter"] = "number";
$col["export"] = true;
$col["editrules"] = array("required" => true);
$cols[] = $col;
$col = array();
$col["title"] = "Status";
$col["name"] = "status";
$col["align"] = "center";
$col["hidden"] = false;
$col["viewable"] = true;
$col["width"] = "150";
$col["search"] = true;
$col["editable"] = true;
$col["isnull"] = false;
$col["resizable"] = true;
$col["editoptions"] = array("value"=>'open order:open order;purchased order:purchased order;blocking:blocking');
$col["edittype"] = "select";
$col["stype"] = "select-multiple";
$col["searchoptions"] = array("value"=>'open order:open order;blocking:blocking');
$col["editrules"] = array("required" => true);
$cols[] = $col;
$col = array();
$col["title"] = "Reason for blocking";
$col["name"] = "reasonfor_blocking";
$col["align"] = "left";
$col["hidden"] = false;
$col["viewable"] = true;
$col["width"] = "150";
$col["search"] = true;
$col["editable"] = true;
$col["isnull"] = false;
$col["resizable"] = true;
$col["edittype"] = "textarea";
$col["editoptions"] = array("rows"=>2, "cols"=>20);
$cols[] = $col;
// pass the cooked columns to grid
$g->set_columns($cols);
$out = $g->render("list1");
include '../../../inc/header.php';
?>
<div class="row">
<div class="col-12">
<?php
echo $out;
?>
</div>
</div>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script>
function add_dropdown_action(formid)
{
var str = '';
str += "<a href='javascript:void(0)' style='outline:none;' onclick='add_append_button();'><span style='padding:0 11px; color: green; display:inline; padding: 0 11px;font-size: 15px; font-weight: bold; margin:0 0 0 5px; top: 2px;right: 4px;' class='ui-icon ui-icon-plus'></span></a>";
jQuery("#product_no").after(str);
}
var x = 1;
function add_append_button() {
x++; // Increase field counter
var newRow = '<tr class="FormData dynamicadd' + x + '">' +
'<td class="CaptionTD">Item no</td>' +
'<td class="DataTD">&nbsp;<input type="text" id="product_no_' + x + '" name="product_no[' + x + ']" class="FormElement ui-widget-content ui-corner-all product_no"></td>' +
'</tr>' +
'<tr class="FormData dynamicadd' + x + '">' +
'<td class="CaptionTD">Quantity</td>' +
'<td class="DataTD">&nbsp;<input type="text" id="quantity_' + x + '" name="quantity[' + x + ']" class="FormElement ui-widget-content ui-corner-all product_no"></td>' +
'</tr>' +
'<tr class="FormData dynamicadd' + x + '">' +
'<td class="CaptionTD">Price &nbsp;€</td>' +
'<td class="DataTD">&nbsp;<input type="text" id="price_' + x + '" name="price[' + x + ']" class="FormElement ui-widget-content ui-corner-all product_no"></td>' +
'</tr>' +
'<tr class="FormData dynamicadd' + x + '">' +
'<td class="CaptionTD">Total amount &nbsp;€</td>' +
'<td class="DataTD">&nbsp;<input type="text" id="total_amount_' + x + '" name="total_amount[' + x + ']" class="FormElement ui-widget-content ui-corner-all product_no"></td>' +
'</tr>' +
'<tr class="FormData dynamicadd' + x + '">' +
'<td></td>' +
'<td><button class="btn btn-danger remove_row" onclick="deleterow(' + x + ')" style="font-size: 10px;padding: 5px;font-weight: bold;">Remove</button></td>' +
'</tr>';
$('#TblGrid_list1 #total_amount').after(newRow); // Append the new row after the #total_amount element
}
function deleterow(ids) {
$('.dynamicadd' + ids).remove(); // Remove the row with the corresponding dynamicadd class
}
$(document).on('input', '.product_no', function(){
//console.log($(this));
var $inputField = $(this); // Store a reference to the input field
$inputField.autocomplete({
source: function(request, response) {
$.ajax({
url: "getprice_amount.php",
dataType: "json",
data: {
term: request.term
},
success: function(data) {
response(data);
}
});
},
minLength: 2,
select: function(event, ui) {
var ean = ui.item.eanval;
var $tr = $inputField.closest('tr'); // Store a reference to the parent row
var productId = $tr.find('[id^="product_no"]').attr('id'); // Get the ID of the product number input field
console.log(productId);
if (productId) {
var splitId = productId.split('_'); // Split the ID string by underscore
var lastPart = splitId[splitId.length - 1]; // Get the last part of the split array
}
$.ajax({
type: "POST",
dataType: "json",
url: "getprice_result.php",
data: { keyword: ean },
success: function(data) {
if(data.error){
alert(data.error);
$tr.find("#quantity_" + lastPart).val("");
$tr.find("#price_" + lastPart).val("");
$tr.find("#total_amount_" + lastPart).val("");
}
else {
$("#quantity_"+lastPart).val(data.quantity);
$("#price_"+lastPart).val(data.prices);
$("#total_amount_" + lastPart).val(data.totamt);
}
}
});
}
});
});
$(document).on('input', '#product_no', function(){
$(this).autocomplete({
source: function(request, response) {
$.ajax({
url: "getprice_amount.php", // URL to your PHP script that handles autocomplete requests
dataType: "json",
data: {
term: request.term // Pass the user input as 'term' parameter
},
success: function(data) {
response(data); // Pass the response data array to the autocomplete widget
}
});
},
minLength: 2, // Minimum number of characters before autocomplete starts
select: function(event, ui) {
var ean = ui.item.eanval; // Access the stm_ean value
$.ajax({
type: "POST",
dataType: "json",
url: "getprice_result.php",
data: { keyword: ean }, // Send the selected EAN as keyword
success: function(data) {
if(data.error){
alert(data.error);
$("#quantity").val("");
$("#price").val("");
$("#total_amount").val("");
}
else {
$("#quantity").val(data.quantity);
$("#price").val(data.prices);
$("#total_amount").val(data.totamt);
}
}
});
}
});
});
</script>
<?php
include '../../../inc/footer.php';
?>
<style type="text/css">
.message-error{
color: red;
text-align: center;
font-weight: bold;
font-size: 20px;
padding-bottom: 15px;
}
.message-success{
color: green;
text-align: center;
font-weight: bold;
font-size: 20px;
padding-bottom: 15px;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment