PHP File Manager
Editing File: agreements.php
<form action="" method="post"> <div class="row"> <div class="col-lg-6 col-md-8"> <table class="table table-striped table-bordered" id="agreed-products"> <thead> <tr> <th>Product</th> <th width="90">Default</th> <th width="120">Price</th> <th width="90">Diff</th> <th width="60">Actions</th> </tr> </thead> <tbody> <?php foreach(((!empty($fixed_prices)) ? $fixed_prices : array(-1)) as $product_info): ?> <tr class="agreed-row"> <td> <?php echo $this->products->productsComboxBox('agreed_product[]', ($product_info === -1) ? '' : $product_info->product_id, 'class="form-control product-dropdown"'); ?> </td> <td align="center" valign="middle" class="default-price"><?php echo display_money(($product_info === -1) ? 0 : $product_info->default_price); ?></td> <td><input type="number" name="agreed_price[]" class="form-control agreed-input text-right" value="<?php echo ($product_info === -1) ? '' : $product_info->price; ?>" data-default-price="<?php echo (isset($product_info->default_price)) ? $product_info->default_price : 0; ?>" step="0.01" min="0" placeholder="0.00" /></td> <td align="center" valign="middle" class="price-difference"><?php echo display_money(($product_info === -1) ? 0 : $product_info->price_difference); ?></td> <td align="center" valign="middle"> <a href="javascript:void(0);" class="remove-agreement"><img src="/assets/images/icons/delete.png" alt="Delete" /></a> </td> </tr> <?php endforeach; ?> <tr> <td colspan="5"> <a href="javascript:void(0);" class="btn btn-xs btn-primary" id="add-another-agreement">Add another</a> </td> </tr> </tbody> </table> <button type="submit" class="btn btn-sm btn-success" name="save_agreements" value="1">Save</a> </div> </div> </form> <script type="text/javascript"> $(function() { var agreedPricesTable = $('#agreed-products'); $('#add-another-agreement').click(function() { var lastRow = $('.agreed-row', agreedPricesTable).last(), clonedRow = lastRow.clone(); clonedRow.find('input, select').val(''); clonedRow.find('.default-price, .price-difference').html('£0.00'); clonedRow.insertAfter(lastRow); }); agreedPricesTable.on('click', '.remove-agreement', function() { if(confirm('Are you sure you want to remove this agreement?')) { var currentRow = $(this).closest('tr'); if(currentRow.siblings('.agreed-row').length === 0) { $('input, select', currentRow).val(''); } else { currentRow.remove(); } } }); agreedPricesTable.on('change', '.product-dropdown', function() { var self = $(this), currentRow = self.closest('tr'), productId = +self.val(); $.post('/products', { get_product: productId }, function(response) { if(response.success) { $('.default-price', currentRow).html('£' + response.product.cost); $('.agreed-input', currentRow).data('default-price', response.product.cost).val(response.product.cost).trigger('change'); } }, 'json'); }); agreedPricesTable.on('input change', '.agreed-input', function() { var self = $(this), currentRow = self.closest('tr'), defaultPrice = +self.data('default-price'), newPrice = +self.val(); if($.isNumeric(defaultPrice) && $.isNumeric(newPrice)) { $('.price-difference', currentRow).html('£' + (newPrice - defaultPrice).toFixed(2)); } }); }) </script>
Cancel