Skip to content

Instantly share code, notes, and snippets.

@ErMandeep
Created March 2, 2019 11:57
Show Gist options
  • Save ErMandeep/012ba594205d4a949e6d03054dc820bc to your computer and use it in GitHub Desktop.
Save ErMandeep/012ba594205d4a949e6d03054dc820bc to your computer and use it in GitHub Desktop.
edit_product.php
<?php
if(isset($_GET['pid'])){
$pid = $_GET['pid'];
}
$id = base64_decode($pid);
echo $id;
//echo $id;
global $wpdb;
$q = "SELECT * FROM wpcl_ball_orderheader
Inner join wpcl_ball_orders_details on wpcl_ball_orders_details.Reference_ID = wpcl_ball_orderheader.Reference_ID
Inner Join VW_Sales_Items_details on VW_Sales_Items_details.saleitemid = wpcl_ball_orders_details.PlantCode
WHERE wpcl_ball_orderheader.ID = '".$id."'";
$fetchdata = $wpdb->get_results($q,ARRAY_A);
echo "<pre>";
print_r($fetchdata);
echo "</pre>";
?>
<style type="text/css">
.main_title {
margin-bottom: 20px;
display: none;
}
a.repeatedaction {
background-color: transparent!important;
color: #333!important;
text-shadow: none!important;
border: 0!important;
box-shadow: none!important;
padding: 6px 11px!important;
line-height: 0!important;
margin: 0!important;
height: 10px!important;
float: right;
}
.tt-menu{height: 250px;
overflow: hidden;
overflow-y: scroll;}
.entry {
display: inline-block;
background-color: #fff;
padding: 15px 2px;
border-radius: 13px;
margin-bottom: 22px;
}
.form-group.col5 {
width: 100px;
font-size: 12px;
float: left;
/*margin-top: 21px;*/
margin-right: 10px;
}
#products-sync-gexcel-sheet-html{
margin-top: 44px;
margin-bottom: 47px;
}
#products-sync-gexcel-sheet-html .repeated-col .form-group.col5 input{
font-size: 12px;
}
.form_description{ margin-bottom: 44px;}
.cal p {
margin-top: 25px;
/*margin-top: 36px;*/
font-size: 23px;
color: #005432;
font-weight: 800;
}
.modal-body textarea , .modal-body input{ border: 1px solid #ccc;}
.repeated-col{display: inline-block;}
.cal {
background-image: url(http://vanwingerdensales.vanwingerden.com/wp-content/uploads/2018/12/kisspng-computer-icons-calendar-5b58f7595be9e2.1455376715325571453765-1.png);
height: 104px;
width: 150px;
background-position: center center;
background-size: 52%;
background-repeat: no-repeat;
text-align: center;
display: table-cell;
/* align-items: center; */
vertical-align: middle;
}
.modal {
text-align: center;
padding: 0!important;
}
.modal:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -4px;
}
.modal-dialog {
display: inline-block;
text-align: left;
vertical-align: middle;
}
.modal-body textarea{
width: 100%;
min-height: 116px;
}
.saveshipping , .refernce_code { background-color: #5cb85c!important; }
.modal-body input[type="text"]{
width: 100%;
}
#addorderform a{color: #333}
.top-margin-15{
margin-top: 15px;
}
select.form-control , input[type='text'] {
border: 1px solid black !important;
border-radius: 2px !important;
}
#map{
height: 300px;
margin-bottom: 20px;
}
.hidebar{display: none;}
.contctdetails a , .contctdetails p{display: inline-block;}
.entry:nth-child(5n+1) {
background: #fce5cd;
}
.entry:nth-child(5n+2) {
background: #d9ead3;
}
.entry:nth-child(5n+3) {
background: #fff2cc;
}
.entry:nth-child(5n+4) {
background: #c9daf8;
}
.entry:nth-child(5n+5) {
background: #ead1dc;
}
.total_eaches , .price_per_unit , .total_price{
font-size: 17px;
text-align: left;
margin-top: 10px;
}
#products-sync-gexcel-sheet-html .repeated-col .form-group.col5 input {
font-size: 17px;
}
.product_form_outer > .container {
background-color: #ffffff !important;
padding-left: 0;
padding-right: 0;
}
</style>
<div class="overlay"><div class="overlay-content"><img src="/wp-content/plugins/ERP-wholesale-app/assets/images/75.gif" alt="Loading..."/></div></div>
<div class="row">
<div class="col-sm-12 text-center">
<div class="form_description">
<h2 style = "text-align:center">Edit Purchase Order</h2>
<p></p>
</div>
</div>
<form id="addorderform" name = "addorderform" class="appnitro" method="post" action="">
<div class="">
<div class="col-sm-8">
<div class="row">
<div class="col-sm-6">
<div class="form-group col-sm-12">
<label for="customerselect">Company</label>
<input type="hidden" class="form-control customerId" placeholder="Customer Reference" name="customerId"/>
<input type="text" name="" value="<?php echo $fetchdata[0]['companyIdnumber']; ?>" class="form-control" readonly>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label>PO#</label>
<input type="text" class="form-control" id="customerpo" value="<?php echo $fetchdata[0]['CustomerPONumber']; ?>" placeholder="PO#" name="customerpo" readonly/>
</div>
</div>
</div>
<!-- col-6 ends here secondbox_para-->
<div class="col-sm-6 ">
<div class="form-row">
<div class="form-group col-md-12">
<label>Store Location</label>
<div style="float: right;">
PO# | #<?php echo $fetchdata[0][CustomerPONumber]; ?>
</div>
<div style="float: right;" class="contctdetails">
<a href="#" class="contact_name"></a> <span class="hidebar"> | </span> <p class="contact_num"> </p>
</div>
<!-- <input type="text" disabled = "disabled" class="form-control" id="customerpo" placeholder="Customer PO#" name="customerpo"/> -->
<?php
global $wpdb;
$customerCountry = $wpdb->get_results("SELECT * FROM `VW_Store_Locations` ORDER BY id ASC ",ARRAY_A);
$newlocation = $fetchdata[0]['storeIdnumber'];
$store_location = $wpdb->get_results("SELECT * FROM `VW_Store_Locations` where store_id = '$newlocation'", ARRAY_A);
$final_location = $store_location[0]['ship_to_description'];
?>
<input type="text" required="required" placeholder = "Select Store Location" class="form-control" id="store_location" name="store_location" value="<?php echo $final_location; ?>">
<!-- <option value = "0">Select Location</option>
<?php foreach($customerCountry as $country) { if($country['ship_to_description']){ ?>
<option value = "<?php echo $country['store_id'] ?>" <?php echo ($country['ship_to_description'] == $final_location) ? 'selected' : ''; ?> ><?php echo $country['ship_to_description'] ?></option>
<?php } } ?> -->
<!-- </select> -->
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label>Customer PO#</label>
<div style="float: right;">
<a href="#" class="shipping_action" >Add Shipping</a> | <a href="#" class="reference">Reference</a>
</div>
<input type="text" class="form-control" id="customereference" value="<?php echo $fetchdata[0][CustomerReference]; ?> " name="customereference"/>
<!--
<?php
global $wpdb;
$customerCountry = $wpdb->get_results("SELECT * FROM `VW_Store_Locations` ORDER BY id ASC ",ARRAY_A);
?>
<select required="required" placeholder = "Select Description" class="form-control" id="store_location" name="store_location">
<option value = "0">Select Description</option>
<?php foreach($customerCountry as $country) { if($country['ship_to_description']){ ?>
<option value = "<?php echo $country['store_id'] ?>"><?php echo $country['ship_to_description'] ?></option>
<?php } } ?>
</select> -->
</div>
</div>
</div>
</div>
<?php
global $wpdb;
$Reference_ID = $fetchdata[0]['Reference_ID'];
$loop_products = $wpdb->get_results("SELECT * FROM `wpcl_ball_orders_details` WHERE Reference_ID= '$Reference_ID' ",ARRAY_A);
foreach ($loop_products as $key ) {
$product_id = $key['id'];
$PlantCodeDescription = $key['PlantCodeDescription'];
$traysize = $key['traysize'];
$eaches = $key['eaches'];
$Reference_ID = $key['Reference_ID'];
$price = $key['price'];
$unit_type = $key['unit_type'];
$totalUnits = $key['totalUnits'];
$eachesPerUnits = $key['eachesPerUnits'];
$pricepereaches = $key['pricepereaches'];
$totalprice = $key['totalprice'];
$notes = $key['notes'];
?>
<!-- first row finishes -->
<div class="repeated-col" id="myRepeatingFields">
<div class="entry ">
<div class="form-row">
<div class="form-group col-md-6">
<div class=" col-md-12">
<?php
global $wpdb;
$products_collection = [];
$customerCountry = $wpdb->get_results("SELECT * FROM `VW_Sales_Items` ORDER BY id ASC ",ARRAY_A);
foreach($customerCountry as $country) {
$products_collection[] = array('desc'=> addslashes(htmlspecialchars_decode($country['description'])) , 'itemcode' =>$country['item_code']) ;
}
?>
<input type="text" class="typeahead form-control" placeholder="Select Product" name="" value="<?php echo $PlantCodeDescription; ?>">
<input type="hidden" value="" class="product_id" >
<input type="hidden" value="" class="product_desc" >
<!-- <select required="required" placeholder = "Select Product" class="form-control product_id" id="company_name" name="product">
<option value = "0">Select Product</option>
<?php foreach($customerCountry as $country) { if($country['description']){ ?>
<option value = "<?php echo $country['item_code'] ?>"><?php echo $country['description'] ?></option>
<?php } } ?>
</select> -->
<br/>
</div>
</div>
<!-- <a href="#" class="contact_edit" >Contact</a> -->
<div class=" col-md-6">
<div class='col-sm-5'>
<?php global $wpdb; $itemsize = $wpdb->get_results("SELECT * FROM `VW_Sales_Items_Size`",ARRAY_A); ?>
<select class="form-control size_select">
<?php
// $size = $fetchdata[0]['traysize'];
$data = $wpdb->get_results("SELECT * FROM `VW_Sales_Items_Size` where unique_id = '$traysize'", ARRAY_A);
$edit_size = $data[0]['desc'];
?>
<option value="0">Size</option>
<?php foreach($itemsize as $value) { if($edit_size){ ?>
<option value = "<?php echo $traysize; ?>" <?php echo ($value['desc'] == $edit_size) ? 'selected' : ''; ?> ><?php echo $value['desc'] ?></option>
<?php } } ?>
</select>
</div>
<div class='col-sm-7'>
<select class="form-control unit_type">
<?php global $wpdb; $item_type = $wpdb->get_results("SELECT * FROM `VW_Sales_Items`",ARRAY_A); ?>
<?php
// $type = $fetchdata[0]['unit_type'];
?>
<option>Select Unit </option>
<option value="flat" <?php echo ('flat' == $unit_type) ? 'selected' : ''; ?>>Flat</option>
<option value="single" <?php echo ('single' == $unit_type) ? 'selected' : ''; ?>>Single</option>
<option value="case" <?php echo ('case' == $unit_type) ? 'selected' : ''; ?>>Case</option>
<option value="rack" <?php echo ('rack' == $unit_type) ? 'selected' : ''; ?>>Rack</option>
</select>
</div>
<!-- <div class=" rightleft_right">
<div class="checkbox col-sm-6">
<input type="radio" class="rack_case" name="rack" checked>
<label for="scales">Rack</label>
</div>
<div class="checkbox col-sm-6" style=" margin-top: 5px;">
<input type="radio" class="rack_case" name="rack">
<label for="horns">Case</label>
</div>
</div> -->
<input type="hidden" name="rack_case_value" value="Rack">
</div>
</div>
<div class="form-group col-sm-12">
<div>
<div class="">
<div class="form-group col5">
<label>Total Units</label>
<?php $total = $fetchdata[0]['totalUnits']; ?>
<input type="text" required="required" maxlength="4" class="form-control total_units" placeholder="Total" name="total_units" value="<?php echo $totalUnits; ?> " />
</div>
<!--
<div class="form-group col5">
<label>Eaches</label>
<input type="text" required="required" class="form-control" id="eaches" placeholder="Eaches" name="eaches"/>
</div>
-->
<div class="form-group col5">
<label>Eaches per Unit</label>
<input type="text" required="required" maxlength="4" class="form-control eaches_per_unit" id="eaches" placeholder="Per Unit" name="eaches_per_unit" value="<?php echo $eachesPerUnits; ?> " />
</div>
<!-- <div class="form-group col5">
<label>Per Flate</label>
<input type="text" class="form-control" id="per_flats" placeholder="Per Flate" name="per_flat"/>
</div> -->
<div class="form-group col5">
<label>Total Eaches</label>
<p class="total_eaches" name="total_eaches" ><?php echo $totaleaches; ?></p>
<!-- <input type="text" class="form-control total_eaches" placeholder="Total Eaches" name="total_eaches" readonly="readonly" /> -->
</div>
<!-- <div class="form-group col5">
<label> # Flats </label>
<input type="text" class="form-control" id="flats" placeholder="Flats" name="flats"/>
</div> -->
<div class="form-group col5">
<label> Price Per each </label>
<input type="text" class="form-control price_per_each" value="<?php echo $pricepereaches; ?>" maxlength="4" placeholder="Price" name="price_per_each" />
<p class="Forecasted"> </p>
</div>
<!-- <div class="form-group col5">
<label> Price </label>
<input type="text" class="form-control" id="price" placeholder="Price" name="price"/>
</div> -->
<div class="form-group col5">
<label> Price Per Unit </label>
<?php $priceperunits = $fetchdata[0]['priceperunits']; ?>
<p class="price_per_unit" name="price_per_unit"> <?php echo $eachesPerUnits; ?> </p>
<!-- <input type="text" id="price" class="form-control price_per_unit" placeholder="Price" name="price_per_unit" readonly="readonly"/> -->
</div>
<div class="form-group col5">
<label> Total Price </label>
<p class="total_price" name='total_price'><?php echo $totalprice ?></p>
<!-- <input type="text" class="form-control total_price" placeholder="Total Price" name="total_price" readonly="readonly"/> -->
</div>
<?php
$b = str_replace( '+', ' ', $notes );
?>
<input type="text" class="form-control" id="headercomments" value="<?php echo $b; ?>" placeholder="Notes" name="headercomments"/>
<div class="top-margin-15">
<input type="checkbox" name="update_price" ><span class="update_price_text"> Update Price & Eaches Per Unit</span>
<select class="fpap_price" >
<option value="forecast">Forecasted</option>
<option value="availability">Availability</option>
</select>
</div>
<!-- row -->
</div>
</div>
</div>
<a href="#" class="repeatedaction btn btn-success btn-add">ADD ADDITIONAL SALES ITEM</a>
</div>
</div>
<?php } ?>
<input type="submit" name = "addpurchaseordersubmit" id = "addpurchaseordersubmit" class="btn btn-success" value ="Save"></input>
</div>
<div class="col-sm-4">
<div id="map"></div>
<div class="form-row">
<div class="form-group col-sm-7 ">
<label> Next Available Ship Day: </label>
<select class="form-control" id="shipday">
<option value="0">Ship Day</option>
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
<option value="Sunday">Sunday</option>
</select>
<!-- <input type="text" required="required" class="form-control" id="shipday" placeholder="Ship Day" name="shipday"/> -->
<label>Ship Date</label>
<input type="text" required="required" class="form-control" id="shipweek" placeholder="Ship Week" name="shipweek"/>
</div>
<div class="form-group col-sm-5 text-center">
<label>Ship Week:</label>
<div class="cal">
<p class="cal_val" name="shipweek_number">0</p>
</div>
</div>
<div class="form-group col-sm-12 text-center">
<select required="required" placeholder = "Select Product" class="form-control" id="shipmethod" name="shipmethod">
<option value = "0">Select Shipping Method</option>
<!-- <option value = "Customer Pick U">Customer Pick Up</option>
<option value="WCFTRK">WCFTRK</option>
<option value="MNLAND">MNLAND</option> -->
<option value="Grower Truck">Grower Truck</option>
<option value="Customer Pickup">Customer Pickup</option>
<option value=GSO">GSO</option>
<option value="FedEx">FedEx</option>
<option value="USPS">USPS</option>
<option value="Mainland Floral">Mainland Floral</option>
</select>
</div>
</div>
<input type="hidden" name="shipping_instructions" value="" class="shipping_instructions">
<input type="hidden" name="reference_code" value="" class="reference_codes">
</div>
</form>
</div>
</div>
<div id="myModal" class="modal shippinginstructions fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h3>Add Shipping Instruction Here</h3>
<textarea name="" placeholder="Add Shipping Instruction Here"></textarea>
<a href="#" class="saveshipping btn btn-default" >Save</a>
<p></p>
</div>
</div>
</div>
</div>
<div id="myModal" class="modal reference_code fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h3>Add Reference Here</h3>
<input type="text" name="reference_code" value="">
<a href="#" class="refernce_code btn btn-default" >Save</a>
<p></p>
</div>
</div>
</div>
</div>
<form id="edit_contact_store_info" method="POST">
<div id="myModal" class="modal company_contact fade" role="dialog"></div>
</form>
<div id="myModal" class="modal contact_edit_modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<form class="contact_edit_form" method="POST">
<div>
<p><b>Contact Name: </b><input type="text" name="last_name" value=""></p>
<p><b>Email: </b><input type="email" name="email" value=""></p>
<p><b>Phone: </b> <input type="text" name="phone" value =""> </p>
<p><b>Fax: </b> <input type="text" name="fax" value=""></p>
<input type="hidden" name="value" value=''>
<a href="#" class="contact_edit_submit btn btn-success" >Save</a>
</div>
</form>
<p></p>
</div>
</div>
</div>
</div>
</div>
<?php $populate = json_encode($products_collection) ?>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.bundle.min.js"></script>
<script type="text/javascript">
$ = jQuery;
$('#store_location').attr('disabled', 'disabled');
$('#company_name').change(function(){
if($('#company_name').val() != '0' ){
$('#store_location').removeAttr('disabled');
}
else{
$('#store_location').attr('disabled', 'disabled');
}
});
$('#store_location').change(function(){
if($('#store_location').val() != 'Select Store' ){
$('.entry').removeClass('disabled');
}
else{
$('.entry').addClass('disabled');
}
});
//var states = JSON.parse('<?php echo $populate ?>');
// var substringMatcher = function(strs) {
// return function findMatches(q, cb) {
// var matches, substringRegex;
// // an array that will be populated with substring matches
// matches = [];
// // regex used to determine if a string contains the substring `q`
// substrRegex = new RegExp(q, 'i');
// // iterate through the pool of strings and for any string that
// // contains the substring `q`, add it to the `matches` array
// $.each(strs, function(i, str) {
// if (substrRegex.test(str.desc)) {
// matches.push(str);
// }
// });
// cb(matches);
// };
// };
var substringMatcher = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'https://wholesale.vanwingerden.com/sales/po/add-purchase-order/?auto=typehead&query=%QUERY',
wildcard: '%QUERY',
transform: function(str) {
// Map the remote source JSON array to a JavaScript object array
return $.map(str, function(strs) {
return {
desc: strs.desc,
itemcode: strs.itemcode
};
});
}
}
});
jQuery(".contact_edit").click(function(){
jQuery(".contact_edit_modal").modal();
});
jQuery(".shipping_action").click(function(){
jQuery(".shippinginstructions").modal();
});
jQuery(".saveshipping").click(function(){
jQuery(this).parents(".modal-body").find('textarea');
$value = jQuery(this).parents(".modal-body").find('textarea').val();
jQuery(".shipping_instructions").val($value);
jQuery(".shippinginstructions").modal('hide');
});
jQuery(".refernce_code").click(function(){
jQuery(this).parents(".modal-body").find('input');
$value = jQuery(this).parents(".modal-body").find('input').val();
jQuery(".reference_codes").val($value);
jQuery(".reference_code").modal('hide');
});
// jQuery('.shippinginstructions').on('hidden.bs.modal', function () {
// jQuery(this).find("textarea");
// console.log(jQuery(this).find("textarea"));
// })
jQuery(".reference").click(function(){
jQuery(".reference_code").modal();
});
Date.prototype.getWeek = function() {
var onejan = new Date(this.getFullYear(),0,1);
var today = new Date(this.getFullYear(),this.getMonth(),this.getDate());
var dayOfYear = ((today - onejan +1)/86400000);
return Math.ceil(dayOfYear/7)
};
function initAutocomplete(value = '8210 Portal Way, Blaine, WA 98230') {
initialize();
function initialize() {
function explode(){
jQuery( "#shipweek" ).datepicker({
showWeek: true,
firstDay: 1,
dateFormat: 'dd-mm-yy',
onSelect: function(selected,evnt) {
console.log(selected ,'jhh');
var date = jQuery(this).datepicker('getDate');
var dayOfWeek = date.getUTCDay();
var formattedDate = jQuery.datepicker.formatDate("m-d-yy", date);
var wkno = jQuery.datepicker.iso8601Week(new Date(formattedDate) );
seldate = date.toDateString();
seldate = seldate.split(' ');
var weekday=new Array();
weekday['Mon']="Monday";
weekday['Tue']="Tuesday";
weekday['Wed']="Wednesday";
weekday['Thu']="Thursday";
weekday['Fri']="Friday";
weekday['Sat']="Saturday";
weekday['Sun']="Sunday";
var dayOfWeek = weekday[seldate[0]];
console.log(formattedDate , dayOfWeek , 'local[today.getDay()]');
jQuery("#shipday").val(dayOfWeek);
var newdate = wkno + ' ' + formattedDate;
console.log(wkno,'date' , formattedDate ,selected);
jQuery("#shipweek").val(newdate);
jQuery('.cal .cal_val').text(wkno);
jQuery('.cal .cal_val').val(wkno);
jQuery("#shipweekhidden").val(wkno + ' ' + formattedDate );
}
});
}
setTimeout(explode, 1000);
geolocation(48.941309, -122.674384);
// contact popup click event
jQuery('.contact_name').click(function(e){
e.preventDefault();
jQuery(".company_contact ").modal()
});
jQuery( "#store_location" ).change(function(){
$val = jQuery(this).val();
jQuery('.overlay').css('display','block');
jQuery('.company_contact').html(' ');
jQuery.ajax({
url : '/wp-admin/admin-ajax.php',
type : 'post',
data : {
action : 'get_contact_store_info',
label_name : $val
},
success : function( response ) {
gotresponse = JSON.parse(response);
jQuery('.overlay').css('display','none');
jQuery(".contact_name").text("Contact Name");
jQuery('.company_contact').html(gotresponse.html);
jQuery('.hidebar').css('display','inline-block');
jQuery('.contact_num').html(gotresponse.phone);
}
});
$lat = jQuery('#store_location option[value='+ $val+'] ').attr('data-attr-lat');
$long = jQuery('#store_location option[value='+ $val+'] ').data('attr-long');
console.log("dfgdfgdfgfdg", $lat , $long ,'sdf');
geolocation($lat , $long );
});
function geolocation($lat,$long){
console.log("df", $lat , $long );
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng($lat , $long);
var mapOptions = {
zoom: 15,
center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
var geo = new google.maps.Geocoder;
geo.geocode( {
latLng : latlng,
},
function(results, status){
if (status == google.maps.GeocoderStatus.OK) {
var myLatLng = results[0].geometry.location;
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
console.log("Geocode was not successful for the following reason:" + status);
}
});
}
}
}
jQuery(function($)
{
$(document).on('click', '.btn-add', function(e)
{
e.preventDefault();
// console.log( jQuery("") );
// $div.append()
var controlForm = $('#myRepeatingFields:first'),
currentEntry = $(this).parents('.entry:first'),
newEntry = $(currentEntry.clone()).appendTo(controlForm);
$count = 1;
jQuery(".entry").each(function(){
jQuery(this).find('.rack_case').attr('name', $count );
$count++;
});
// $div = '';Math.random();
//$html = '<div class="cases_added"><h4> Cases Added: </h4><div class=""> GL Code: <p>'+currentEntry.find(".glcode_case").val()+' Size Code: <span class="case_gl_code">'+currentEntry.find(".size_case").val()+'</span> | GL Size <span class="case_size">'+currentEntry.find(".case_quantity").val()+'</span></p></div></div>';
// $div = jQuery('.cases_added').append($html);
newEntry.find('.Forecasted').html('');
newEntry.find('.total_eaches').html('');
newEntry.find('.price_per_unit').html('');
newEntry.find('.total_price').html('');
// newEntry.find('.typeahead').on('added',function(){
// newEntry.find(".twitter-typeahead:nth-child(1)").html(' ');
newEntry.find('.typeahead').typeahead({
hint: true,
scroll:true,
minLength: 1
},
{
name: 'states',
limit: 30,
display: 'desc',
source: substringMatcher ,
templates: {
suggestion: function(data) {
return '<div data-attr="'+ data.itemcode +'">' + data.desc + '</div>';
}
}
}).on('typeahead:selected', function(event, selection) {
jQuery(newEntry[0]).find(".product_id").val(selection.itemcode);
jQuery(newEntry[0]).find(".product_desc").val(selection.desc);
jQuery('.overlay').css('display','block');
jQuery.ajax({
url : '/wp-admin/admin-ajax.php',
type : 'post',
data : {
action : 'get_size_price',
label_name : selection.desc,
itemcode : selection.itemcode,
},
success : function( response ) {
jQuery('.overlay').css('display','none');
$data = JSON.parse(response) ;
//console.log( jQuery(newEntry[0]).find("#shipmethod") , "sdfddf" );
// console.log($data[0].size , "heryt" );
jQuery(newEntry[0]).find(".size_select").val($data[0].size);
jQuery(newEntry[0]).find("#price").val($data[0].cost);
jQuery(newEntry[0]).find(".Forecasted").html( "<b>Fp:</b>"+$data[0].forecast +" <b>Ap:</b> "+$data[0].availability)
//jQuery(newEntry[0]).find(".Forecasted").text($data[0].forecast)
}
});
});
console.log(newEntry.find('.typeahead'));
newEntry.find('input').val('');
newEntry.find(".tt-hint").typeahead('destroy');
controlForm.find('.entry:not(:last) .btn-add')
.removeClass('btn-add').addClass('btn-remove')
.removeClass('btn-success').addClass('btn-danger')
.html('REMOVE');
}).on('click', '.btn-remove', function(e)
{
e.preventDefault();
$(this).parents('.entry:first').remove();
return false;
});
});
//check all functionality
$('#select-all-check').change(function(){
var apply_for = $(this).val();
//uncheck "select all", if one of the listed checkbox item is unchecked
if(false == $(this).prop("checked")){ //if this item is unchecked
$("."+apply_for).prop('checked', false); //change "select all" checked status to false
}else{
$("."+apply_for).prop('checked', true);
}
});
setTimeout(function(){
$('.typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1,
},
{
name: 'states',
display: 'desc',
limit: 30,
source:substringMatcher,
templates: {
suggestion: function(data) {
console.log("me her" ,data);
return '<div data-attr="'+ data.itemcode +'">' + data.desc + '</div>';
}
}
}).on('typeahead:selected', function(event, selection) {
$this = jQuery(this);
$this.parents('.entry').find(".product_id").val(selection.itemcode);
$this.parents('.entry').find(".product_desc").val(selection.desc);
jQuery('.overlay').css('display','block');
jQuery.ajax({
url : '/wp-admin/admin-ajax.php',
type : 'post',
data : {
action : 'get_size_price',
label_name : selection.desc,
itemcode : selection.itemcode,
},
success : function( response ) {
jQuery('.overlay').css('display','none');
$data = JSON.parse(response) ;
//console.log($data[0].cost, $data , jQuery(this) , 'htygj');
$this.parents('.entry').find(".size_select").val($data[0].size);
$this.parents('.entry').find("#price").val($data[0].cost);
$this.parents('.entry').find(".Forecasted").html( "<b>Fp:</b>"+$data[0].forecast +" <b>Ap:</b> "+$data[0].availability)
}
});
});
}, 5000);
jQuery(document).on( 'focusout' , '.eaches_per_unit' , function() {
eaches = jQuery(this).val() ;
total_units = jQuery(this).parents('.entry').find(".total_units").val();
//jQuery(this).parents('.entry').find(".total_eaches").val(total_units*eaches);
jQuery(this).parents('.entry').find(".total_eaches").text(total_units*eaches);
total_units = jQuery(this).parents('.entry').find(".total_units").val();
price_per_unit = jQuery(this).parents('.entry').find(".price_per_unit").text();
//jQuery(this).parents('.entry').find(".total_price").val(total_units*price_per_unit);
jQuery(this).parents('.entry').find(".total_price").text(total_units*price_per_unit);
});
jQuery(document).on( 'focusout' , '.total_units' , function() {
eaches = jQuery(this).parents('.entry').find(".eaches_per_unit").val() ;
total_units = jQuery(this).parents('.entry').find(".total_units").val();
// jQuery(this).parents('.entry').find(".total_eaches").val(total_units*eaches);
jQuery(this).parents('.entry').find(".total_eaches").text(total_units*eaches);
price_per_unit = jQuery(this).parents('.entry').find(".price_per_unit").text();
jQuery(this).parents('.entry').find(".total_price").text(total_units*price_per_unit);
// jQuery(this).parents('.entry').find(".total_price").val(total_units*price_per_unit);
});
jQuery(document).on( 'focusout', '.price_per_each' , function() {
eaches = jQuery(this).val() ;
eaches_per_unit = jQuery(this).parents('.entry').find(".eaches_per_unit").val();
//jQuery(this).parents('.entry').find(".price_per_unit").val(eaches_per_unit*eaches);
jQuery(this).parents('.entry').find(".price_per_unit").text(eaches_per_unit*eaches);
total_units = jQuery(this).parents('.entry').find(".total_units").val();
price_per_unit = jQuery(this).parents('.entry').find(".price_per_unit").text();
//jQuery(this).parents('.entry').find(".total_price").val(total_units*price_per_unit);
jQuery(this).parents('.entry').find(".total_price").text(total_units*price_per_unit);
});
$(document).on('click', '#edit_contact_store_info_submit', function(e){
console.log('heyuy');
jQuery('.overlay').css('display','block');
var form = jQuery('#edit_contact_store_info');
var storeid = jQuery('#store_location').val();
$.ajax({
type: "POST",
url: '/wp-admin/admin-ajax.php',
data: {
action : 'edit_contact_store_info',
data : form.serialize(),
store_id : storeid,
},
success: function(data)
{
jQuery('.overlay').css('display','none');
// $('.edit_message').text('Information Updated');
// $(".edit_message").delay(3200).fadeOut(300);
$('.modal.company_contact').modal('toggle');
$('.contact_num').text($('#edit_contact_store_info input[name="phone"]').val());
$('.customerId').val(data);
},
error: function (error)
{
$('.edit_message').text('Error while updating information');
}
});
e.preventDefault();
});
$(document).on('click', '.contact_edit_submit', function(e){
var form = jQuery('.contact_edit_form');
var storeid = jQuery('#store_location').val();
var company_id = jQuery('#company_name').val();
$.ajax({
type: "POST",
url: '/wp-admin/admin-ajax.php',
data: {
action : 'edit_contact_store_info_repeat',
data : form.serialize(),
store_id : storeid,
company_id: company_id,
},
success: function(data)
{
console.log(data);
if(data[0].id){
$(".contact_edit_form input[name=value]").val(data[0]['id']) ;
$('.contact_edit_submit').text('Update');
}
},
});
})
</script>
<script type="text/javascript" src="https://twitter.github.io/typeahead.js/js/handlebars.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCvpVpr64JO4z3XY-sMoe2nX4wsKRxI-Zw&libraries=places&callback=initAutocomplete"
></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment