Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function(){
- $("#sell").click(function(e) {
- var check = $("#isempty").val();
- if(check!='1'){
- alert("Add Products to Cart First");
- }
- });
- $("#add_cart").click(function(e){
- e.preventDefault();
- $("#isempty").val('1');
- var price = $("#unit_price").val();
- var customer = $("#customer_id").val();
- var quantity = $("#total_quantity").val();
- var total = $("#total_price").val();
- var warehouse_id = $("#warehouse_id").val();
- var warehouse = $("#warehouse_id option:selected").text();
- var product_id = $("#item_id").val();
- var product = $("#item_id option:selected").text();
- var category_id = $("#catagory_id").val();
- var category = $("#catagory_id option:selected").text();
- var sub_total = $("#sub_total").val();
- var numsubtotal = parseInt(sub_total) + parseInt(total);
- var cart_item = '';
- cart_item += '<tr id="tablerow">';
- cart_item += '<td>' + warehouse + '<input type="hidden" class="form-control" name="warehouse[]" value="'+warehouse_id+'"></td>';
- cart_item += '<td>' + product + '<input type="hidden" class="form-control" name="item[]" value="'+product_id+'" readonly></td>';
- cart_item += '<td>' + category + '<input type="hidden" class="form-control" name="category[]" value="'+category_id+'" readonly></td>';
- cart_item += '<td>' + quantity + '<input type="hidden" class="form-control" name="quantity[]" value="'+quantity+'" readonly></td>';
- cart_item += '<td>' + price + '<input type="hidden" class="form-control" name="price[]" value="'+price+'" readonly></td>';
- cart_item += '<td>' + total + '<input type="hidden" class="form-control" id="cart_total" name="total[]" value="'+total+'" readonly></td>';
- cart_item += '<td><a href="#" style="margin-left: 20px;" class="remove_field btn btn-rounded btn-inline btn-danger"><span class="glyphicon"></span></a></td>';
- cart_item += '</tr>';
- $(".cart").append(cart_item);
- $('option').prop('selected', function() {
- return this.defaultSelected;
- });
- $('.fields').find('input:text').val('');
- $("#customer_id").val(customer);
- $("#sub_total").val(numsubtotal);
- });
- $(".cart").on("click",".remove_field", function(e){
- e.preventDefault();
- var minustotal = $(this).closest("#tablerow").find("input[id='cart_total']").val();
- var intmintotal = parseInt(minustotal);
- var sub_total = $("#sub_total").val();
- var numsubtotal = parseInt(sub_total) - parseInt(intmintotal);
- $("#sub_total").val(numsubtotal);
- $(this).closest('#tablerow').remove();
- })
- });
Add Comment
Please, Sign In to add comment