PK

ADDRLIN : /home/questend/public_html/subdomain/cheesybite.questend.com/purchase/
FLL :
Current File : /home/questend/public_html/subdomain/cheesybite.questend.com/purchase/purchase-create-new_25feb.php

<?php
   ob_start();
   error_reporting(E_ALL ^ E_NOTICE);
   @session_start();
   ini_set('allow_url_include',1);    
   date_default_timezone_set("Asia/Kolkata");
   set_time_limit(600);
   ini_set('max_execution_time',600);
   include '../includes/settings/constant.php';
   //include '../includes/settings/db.php';
   require_once '../includes/settings/PDODB.php';
   include '../includes/modules/functions.php';
   
   $function = new FUNCTIONS();
   
   if(empty($_SESSION['adminId_cheesyBites'])){
    header("Location: ../index.php");
    exit();
   }

   
   $ipAddress = $function->getRealIpAddr();  

   $pdodb = PDODB::getInstance();
   $sql = "SELECT * FROM `inventory` WHERE isActive=1 ORDER BY `id` ASC";
   $inventoryData = $pdodb->query($sql);
   //print_r($inventoryData); exit;

   //item select option
   //include "config.php";
    $sql="SELECT * FROM `inventory` WHERE isActive=1 ORDER BY `id` ASC";
    $itemlist="<option value=''> Select </option>";
    $result=$pdodb->query($sql);
    if($result>0){
      foreach ($result as $key => $value) {
        $itemlist.="<option value='{$value["id"]}'>{$value["itemName"]}</option>";
      }      
    }
    //end item select option
   //print_r($ipaddress); exit;
   if(isset($_POST['btnAddPurchase'])){
      //print_r($_POST); exit;
      $purchase =$_POST;
      $paymentMode= !empty($purchase['paymentMode'])?trim($purchase['paymentMode']):"";
      $customer_contactno= !empty($purchase['customer_contactno'])?trim($purchase['customer_contactno']):"";
      $total_amt= !empty($purchase['total_amt'])?trim($purchase['total_amt']):"";
      
      $sql = "INSERT INTO `purchase` SET customer_contactno='".$customer_contactno."', paymentMode='".$paymentMode."', total_amt='".$total_amt."'";

      $result = $pdodb->query($sql);
      $purchaseId = $pdodb->lastInsertId();
      $invoiceId = "INVC/CHEESYBITE/00".$purchaseId;
      //print_r($purchaseId); exit;

      $sqlupt = "UPDATE `purchase`  SET invoiceId='".$invoiceId."' WHERE pId = '".$purchaseId."'";
      $resultupt = $pdodb->query($sqlupt);

      if(!empty($purchaseId)){
        for ($i=0; $i < sizeof($purchase['itemname']); $i++) { 
          
          $inventoryId= $purchase['itemname'][$i]; !empty($purchase['itemname'][$i])?trim($purchase['itemname'][$i]):"";
          $rateperunit= $purchase['rateperunit'][$i]; !empty($purchase['rateperunit'][$i])?trim($purchase['rateperunit'][$i]):"";
          $qty= $purchase['qty'][$i]; !empty($purchase['qty'][$i])?trim($purchase['qty'][$i]):"";
          $total= !empty($purchase['total'][$i])?trim($purchase['total'][$i]):"";
          
          $pdodb = PDODB::getInstance();
          $sql = "INSERT INTO `purchase_items` SET 
            purchaseId='$purchaseId',
            inventoryId='$inventoryId',            
            rateperunit='$rateperunit',
            qty='$qty',
            balStockQty='$qty',
            total='$total'";
          //exit;
          $result = $pdodb->query($sql);

          //echo $result; exit;        
          PDODB::closeInstance();    
          if (!empty($result)) {
            $statusMsg = 'Successfully ADD New Order Entry.';
            header("Location: ../invoice.php?id=$purchaseId");
          }
        }
      }


    }
?>
<!DOCTYPE html>
<html>
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>INSPINIA | Basic Form</title>
      <?php include_once '../layout/style.php'; ?>
      <style type="text/css">
        /*.inpt-width {width: 60px;}*/
        .itemCode {width: 60px;}
        .hsnCode {width: 100px;}
        .unit {width: 60px;}
        .gstRate {width: 25px;}
        /*.rateperunit {width: 60%;}*/
        .qty {width: 60px;}
        /*.total {width: 60%;}*/
        .inpt-bgbord { border: none; background: transparent; }
      </style>
   </head>
   <body>
      <div id="wrapper">
         <?php $currentPage = 'Purchase-create'; include_once '../layout/side-bar.php'; ?>
         <div id="page-wrapper" class="gray-bg">
            <?php include_once '../layout/header.php'; ?>
            <div class="row wrapper border-bottom white-bg page-heading">
               <div class="col-lg-10">
                  <h2></h2>
                  <h2>New Order Form</h2>                  
               </div>
               <div class="col-lg-2">
               </div>
            </div>           
            <div class="row">
               <div class="col-lg-12">
                  <div class="ibox float-e-margins">                     
                    <div class="row">
                        <div class="col-lg-12" style="padding:0px;">
                            <div class="ibox float-e-margins">
                                <div class="ibox-title">
                                  <?php if (!empty($statusMsg)) { ?>
                                    <div class="alert alert-success" role="alert">
                                      <button type="button" class="close" data-dismiss="alert">x</button>
                                      <?=$statusMsg;?>
                                    </div>
                                  <?php } ?>
                                </div>
                              <form method="post" action="" enctype="multipart/form-data" id="formAddPurchase">
                                <div class="ibox-content">
                                  <div class="row">
                                    <div class="col-sm-4">
                                      <div class="form-group">
                                          <label>Customer Mobile Number</label>
                                          <input class="form-control" type="text" name="customer_contactno" id="customer_contactno">
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                      <div class="form-group">
                                          <label>Paymeny Mode</label>
                                          <select class="form-control" name="paymentMode" id="paymentMode">
                                            <option value="">---Select---</option>
                                            <option value="Cash">Cash</option>
                                            <option value="Online">Online</option>
                                          </select>
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                      <div class="form-group text-center">
                                        <button class="btn-lg btn-primary" name="btnAddPurchase" id="btnAddPurchase" type="submit">Submit</button>
                                      </div>
                                    </div>
                                  </div>                                                                    
                                </div>
                                <div class="ibox-content">
                                  <div class="table-responsive">
                                    <table class='table table-bordered'>
                                      <thead>
                                        <tr> 
                                          <th>Item Name</th>
                                          <th>ItemCode</th>
                                          <th>HSN code</th>                                          
                                          <th>Gst %</th>
                                          <th>Qty</th>
                                          <th>Rate/Amount</th>                                         
                                          <th>Total</th>                                          
                                          <th>Action</th>
                                        </tr>
                                      </thead>
                                      <tbody id="itemTable">
                                        <tr>
                                          <td><select id='itemname' name='itemname[]' class='itemname form-control select2_demo_3' required><?php echo $itemlist; ?></select></td>
                                          <td>
                                            <input id="itemCode[]" name="itemCode[]" class="itemCode form-control" type="text" readonly="readonly">
                                          </td>
                                          <td>
                                            <input id="hsnCode[]" name="hsnCode[]" class="hsnCode form-control" type="text" readonly="readonly">
                                          </td>
                                          <td>
                                            <input id="gstRate[]" name="gstRate[]" class="gstRate form-control" type="text" readonly="readonly">
                                          </td>
                                          <td>
                                            <input id="qty[]" name="qty[]" class="qty form-control" type="text" required="required">
                                          </td>
                                          <td>
                                            <input id="rateperunit[]" name="rateperunit[]" class="rateperunit form-control" type="text" readonly="readonly">
                                          </td>
                                          <td><input id="total[]" name="total[]" class="total form-control" type="text" readonly="readonly"></td>
                                        </tr>
                                      </tbody>
                                      <tfoot>
                                        <tr>
                                          <td colspan='5'>&nbsp;</td> 
                                          <td><b>Grand Total : </b></td>
                                          <td><input type="text" class="form-control" id="total_amt" name="total_amt" readonly></td>
                                          <td>&nbsp;</td>
                                        </tr>
                                      </tfoot>                                      
                                    </table>
                                    <input type="button" class="btn btn-success" value="Add Item" onclick="addField();">
                                  </div>                                                                     
                                </div>                                
                              </form>
                            </div>
                        </div>
                    </div>                    
                  </div>
               </div>
            </div>
         </div>         
      </div>
      <?php include_once '../layout/script.php'; ?>

      <script>
        $(document).ready(function () {
          // Handle item selection change to update fields via AJAX
          $("body").on("change", ".itemname", function () {
            var id = $(this).val();
            var row = $(this).closest("tr");

            $.ajax({
              url: "get_item.php", // Replace with your actual URL
              type: "POST",
              data: { id: id },
              success: function (data) {
                var item = JSON.parse(data);
                row.find(".itemCode").val(item[0]); // Update Item Code
                row.find(".gstRate").val(item[1]); // Update GST Rate
                row.find(".hsnCode").val(item[2]); // Update HSN Code
                row.find(".rateperunit").val(item[3]); // Update Rate per Unit
                calculateRowTotal(row); // Calculate total for the row
                calculateGrandTotal(); // Recalculate grand total after row update
              },
            });
          });

          // Handle changes in quantity or rate per unit to calculate the total
          $("body").on("input", ".qty, .rateperunit", function () {
            var row = $(this).closest("tr");
            calculateRowTotal(row);
            calculateGrandTotal(); // Recalculate grand total after row update
          });

          // Handle add row
          $("body").on("click", ".add-item", function () {
            addField();
            calculateGrandTotal(); // Recalculate grand total after adding a row
          });

          // Handle delete row
          $("body").on("click", ".delete-row", function () {
            deleteRow(this);
            calculateGrandTotal(); // Recalculate grand total after deleting a row
          });
        });

        // Function to calculate the total for a single row
        function calculateRowTotal(row) {
          var qty = parseFloat(row.find(".qty").val()) || 0; // Get quantity, default to 0
          var rate = parseFloat(row.find(".rateperunit").val()) || 0; // Get rate per unit, default to 0
          var total = qty * rate; // Calculate total
          row.find(".total").val(total.toFixed(2)); // Update total field with two decimal places
        }

        // Function to calculate the grand total
        function calculateGrandTotal() {
          var grandTotal = 0;

          // Loop through each row and sum the total values
          $("#itemTable tr").each(function () {
            var rowTotal = parseFloat($(this).find(".total").val()) || 0;
            grandTotal += rowTotal;
          });

          // Update the grand total field
          $("#total_amt").val(grandTotal.toFixed(2)); // Format to 2 decimal places
        }

        function addField() {
          const itemList = `<?php echo $itemlist; ?>`; // PHP $itemlist injected here
          const table = document.getElementById("itemTable");
          const currentIndex = table.rows.length; // Use currentIndex for unique IDs
          const currentRow = table.insertRow(-1);

          // Create select dropdown for item name
          const itemnameBox = document.createElement("select");
          itemnameBox.setAttribute("name", "itemname[]");
          itemnameBox.setAttribute("class", "itemname form-control select2_demo_3");
          itemnameBox.innerHTML = itemList; // Populate dropdown with PHP options

          // Create input fields for other columns
          const itemCodeBox = createInput(`itemCode[]${currentIndex}`, "itemCode form-control", "text", true);
          const hsnCodeBox = createInput(`hsnCode[]${currentIndex}`, "hsnCode form-control", "text", true);
          const gstRateBox = createInput(`gstRate[]${currentIndex}`, "gstRate form-control", "text", true);
          const qtyBox = createInput(`qty[]${currentIndex}`, "qty form-control", "text", false, true); // Set as required
          const rateperunitBox = createInput(`rateperunit[]${currentIndex}`, "rateperunit form-control", "text", true); // Set as readonly
          const totalBox = createInput(`total[]${currentIndex}`, "total form-control", "text", true); // Set as readonly

          // Create delete button
          const deleteRowBox = document.createElement("button");
          deleteRowBox.setAttribute("type", "button");
          deleteRowBox.setAttribute("onclick", "deleteRow(this);");
          deleteRowBox.setAttribute("class", "btn btn-danger delete-row");
          deleteRowBox.innerText = "Delete Row";

          // Append all elements to the row
          appendCell(currentRow, itemnameBox);
          appendCell(currentRow, itemCodeBox);
          appendCell(currentRow, hsnCodeBox);
          appendCell(currentRow, gstRateBox);
          appendCell(currentRow, qtyBox);
          appendCell(currentRow, rateperunitBox);
          appendCell(currentRow, totalBox);
          appendCell(currentRow, deleteRowBox);

          // Reinitialize select2 for the new select dropdown
          $(itemnameBox).select2({
            placeholder: "Select an Option",
            allowClear: true
          });
        }

        // Utility function to create input elements
        function createInput(name, className, type, readonly = false, required = false) {
          const input = document.createElement("input");
          input.setAttribute("name", name);
          input.setAttribute("class", className);
          input.setAttribute("type", type);
          if (readonly) input.setAttribute("readonly", "readonly");
          if (required) input.setAttribute("required", "required");
          return input;
        }

        // Utility function to append a cell to a row
        function appendCell(row, element) {
          const cell = row.insertCell(-1);
          cell.appendChild(element);
        }

        // Delete row function
        function deleteRow(button) {
          const row = button.closest("tr");
          row.remove();
        }

        // Initialize select2 on document ready
        $(document).ready(function () {
          $(".select2_demo_3").select2({
            placeholder: "Select an Option",
            allowClear: true
          });
        });
      </script>
      <script type="text/javascript">
        $("#formAddPurchase").validate({
          rules: {
              itemName: {
                  required: true
              },                         
              invoiceId: {
                  required: true
              },  
              invoiceDate: {
                  required: true
              },
              /*customer_contactno: {
                  required: true,
                  minlength: 10,
                  maxlength: 10,
                  //number: true
                  digits: true
              },*/
              paymentMode: {
                required: true
              }
          },
          messages: {
              itemName: {
                  required: "Please Enter Itme Name"
              },
              invoiceId: {
                  required: "Please Enter Invoice Number"
              },
              invoiceDate: {
                  required: "Please Enter Invoice Date"
              },
              /*customer_contactno: {
                  required: "Please enter mobile No",
                  minlength: "Mobile No Must Contain at least 10 digit",
                  maxlength: "Mobile No Must Not Exceed 10 digit",
                  digits: "Please enter only digit"
              },*/
              paymentMode: {
                required: "Please select Payment Mode"
              }
          },
          submitHandler: function(form) {
              form.submit();             
          }   
        });
      </script>
      
   </body>
</html>


PK 99
E-SHOP || DASHBOARD
404

Page Not Found

It looks like you found a glitch in the matrix...

← Back to Home