What's new

RE: HELP... Ajax auto populate dropdown box and show percentage value..

J P

Journeyman
Joined
Jun 1, 2023
Posts
32
Reaction
0
Points
21
PHP:
                            if(isset($id)):
                            $order_items_qry = $conn->query("SELECT o.*,i.name, i.size FROM `order_items` o inner join item_list i on o.item_id = i.id where o.`po_id` = '$id' ");
                            echo $conn->error;
                            while($row = $order_items_qry->fetch_assoc()):
                            ?>
                            <tr class="po-item" data-id="">
                                <td class="align-middle p-1 text-center">
                                    <button class="btn btn-sm btn-danger py-0" type="button" onclick="rem_item($(this))"><i class="fa fa-times"></i></button>
                                </td>
                                <td class="align-middle p-0 text-center">
                                    <input type="number" class="text-center w-100 border-0" step="any" name="qty[]" value="<?php echo $row['quantity'] ?>"/>
                                </td>
                                <td class="align-middle p-1">
                                    <input type="text" class="text-center w-100 border-0" name="unit[]" value="<?php echo $row['unit'] ?>"/>
                                </td>
                                <td class="align-middle p-1">
                                    <input type="text" class="text-center w-100 border-0" name="specs[]" value="<?php echo $row['specs'] ?>"/>
                                </td>
                                <td class="align-middle p-1">
                                    <input type="hidden" name="item_id[]" value="<?php echo $row['item_id'] ?>">
                                    <input type="text" class="text-center w-100 border-0 item_id" value="<?php echo $row['name'] ?>" required/></td>
                                <td class="align-middle text-center p-1 item-size"><?php echo $row['size'] ?></td>

                                <td class="align-middle p-1">
                                    <input type="number" step="any" class="text-center w-100 border-0" name="unit_price[]"  value="<?php echo ($row['unit_price']) ?>"/></td>
                                <td class="align-middle p-1 text-left total-price"><?php echo number_format($row['quantity'] * $row['unit_price']) ?></td>
                            </tr>
                            <?php endwhile;endif; ?>
                        </tbody>
                        <tfoot>
                                    

                            <tr class="bg-lightblue">
                                <tr>
                                    <th class="p-1 text-right" colspan="6"><span><button class="btn btn btn-sm btn-flat btn-primary py-0 mx-1" type="button" id="add_row">Add Row</button></span> PO Amount</th>
                                    <th class="p-1 text-right" colspan="">$</th>
                                    <th class="p-1 text-left" id="sub_total">0</th>
                                </tr>
                            
                                <tr>
                                    <th class="p-1 text-right" colspan="6">Advance Payment (%)
                                    <th class="p-1 text-right" colspan="">$</th>
                                
                                    //* This the text to be filled by the percentage from supplier_list
                                    <input type="number" step="any" name="discount_percentage" class="border-light text-right" value="<?php echo isset($discount_percentage) ? $discount_percentage : 0 ?>">
                                    
                                </th>
                                
                                    <th class="p-1"><input type="text" class="w-100 border-0 text-left" readonly value="<?php echo isset($discount_amount) ? $discount_amount : 0 ?>" name="discount_amount"></th>
                                </tr>
                                <tr>
                                    <th class="p-1 text-right" colspan="6">Total:</th>
                                    <th class="p-1 text-right" colspan="">$</th>
                                    <th class="p-1 text-left" id="total">0</th>
                                </tr>
                            </tr>
Picture1.JPG
picture2.JPG
 

Attachments

This code appears to be a PHP script that generates a table with input fields for displaying and editing order items. Here is a breakdown of what the code does:

  • The script starts with an if(isset($id)) condition, which suggests that it is checking if the $id variable is set before executing the code inside.
  • Inside the condition, a SQL query is executed to retrieve order items from the database. The query joins the order_items table with the item_list table using the item_id column as the join condition.
  • The retrieved order items are then looped through using a while loop, and each item is displayed in a table row (<tr>). The values from the database are used to pre-fill the input fields in each row.
  • The table row also includes a delete button (<button>) that calls a JavaScript function named rem_item when clicked. It passes $(this) as an argument to the function, which refers to the clicked button element.
  • The remaining table cells (<td>) contain input fields for quantity, unit, specs, item ID, item size, unit price, and total price. Their values are also pre-filled with the respective values from the database.
  • After the while loop, the script includes the table footer (<tfoot>) section.
  • Inside the table footer, there are several <tr> rows for displaying additional information. The first row includes a button for adding a new row (Add Row) and a cell for displaying the total PO amount ($) based on the calculations done in the JavaScript.
  • The second row includes a cell for displaying the label Advance Payment (%), a cell for displaying the label $, and an input field (<input>) for entering a discount percentage. The value of this input field is fetched from the $discount_percentage variable and is set as the default value.
  • The third row includes a cell for displaying the label Total:, a cell for displaying the label $, and a cell for displaying the total amount after applying the discount. The value of this cell is fetched from the $discount_amount variable and is set as the default value.

Please note that there are some commented out lines in the code, which means those lines are not being executed and might be there for reference purposes.
 

Similar threads

Back
Top