MMCT TEAM
Server IP : 217.21.85.138  /  Your IP : 216.73.216.103
Web Server : LiteSpeed
System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64
User : u915722082 ( 915722082)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u915722082/public_html/agro/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u915722082/public_html/agro/create.php
<?php
	session_start();
	require_once '_config.php';
	
	if(!isset($_SESSION["logs"])){
		redirect("index.php");
	} 
 
	#post
	if($_SERVER["REQUEST_METHOD"]=='POST'){
		try{
			$con->autocommit(FALSE);
			 
			$_POST=filter_input_array(INPUT_POST,FILTER_SANITIZE_STRING);
			
			$date = $_POST["invoice_date"];
    
			$invoice_date = DateTime::createFromFormat('d, M Y', $date)->format('Y-m-d');
		   
			$invoice_num=mysqli_real_escape_string($con,$_POST["invoice_num"]);
			$btname=mysqli_real_escape_string($con,$_POST["btname"]);
			$igstin=mysqli_real_escape_string($con,$_POST["igstin"]);
			$usstate=mysqli_real_escape_string($con,$_POST["usstate"]);
			$uspincode=mysqli_real_escape_string($con,$_POST["uspincode"]);
			$usplace=mysqli_real_escape_string($con,$_POST["usplace"]);
			$usaddress=mysqli_real_escape_string($con,$_POST["usaddress"]);
			$fcharge=mysqli_real_escape_string($con,$_POST["fcharge"]);
			$transno=mysqli_real_escape_string($con,$_POST["transno"]); 
			$notes=mysqli_real_escape_string($con,$_POST["notes"]); 
			$net_amt=mysqli_real_escape_string($con,$_POST["net_amt"]); 
			$gstp=mysqli_real_escape_string($con,$_POST["gstp"]); 
			$gst_amt=mysqli_real_escape_string($con,$_POST["gst"]); 
			$round_off=mysqli_real_escape_string($con,$_POST["round_off"]);  
			$sub_total=mysqli_real_escape_string($con,$_POST["sub_total"]);  
			 
			$sql="insert into tbl_sales (invoice_date,invoice_num,btname,igstin,usstate,uspincode,usplace,usaddress,fcharge,transno,notes,net_amt,gstp,round_off,gst_amt,sub_total) VALUES ('{$invoice_date}','{$invoice_num}','{$btname}','{$igstin}','{$usstate}','{$uspincode}','{$usplace}','{$usaddress}','{$fcharge}','{$transno}','{$notes}','{$net_amt}','{$gstp}','{$round_off}','{$gst_amt}','{$sub_total}')";   
			   
			if($con->query($sql)){  
				$id=$con->insert_id;
				
				$sql="insert into tbl_sales_product (sid,name,quantity,uom,price,total) VALUES ";  
				$rows=[];  
				
				for($i=0;$i<count($_POST["name"])-1;$i++){ 
					$sid=$id; 
					$name=mysqli_real_escape_string($con,$_POST["name"][$i]);
					$quantity=mysqli_real_escape_string($con,$_POST["quantity"][$i]);
					$uom=mysqli_real_escape_string($con,$_POST["uom"][$i]);
					$price=mysqli_real_escape_string($con,$_POST["price"][$i]); 
					$total=mysqli_real_escape_string($con,$_POST["total"][$i]); 
					$rows[]="('{$sid}','{$name}','{$quantity}','{$uom}','{$price}','{$total}')"; 
				}  
				$sql.=implode(",",$rows);
				if(!$con->query($sql)){
				  throw new Exception('Invoice Added Failed');   
				}  
			}
			
			  
			$con->commit();  
			flash("msg","Invoice Added Successfully. Print Invoice <a href='invoice_print?id={$id}' style='text-decoration:underline;' target='_blank'>Click</a>");
			
		}catch(Exception $e){ 
			$con->rollback();
			flash("msg",$e->getMessage(),"danger");
		}
	}

    #get invoice no
	$sql="select invoice_num+1 as invoice_num from tbl_sales order by invoice_num desc limit 1";
	$data["invoice_num"]="001";
	$row=single($con,$sql);
	if(!empty($row)){
		$data["invoice_num"]=$row["invoice_num"];
	}

?> 
 
<!DOCTYPE html>
<html lang="en"> 
	<?php include "_header.php"; ?>
	<!--begin::Body-->
	<body id="kt_app_body" data-kt-app-header-fixed="true" data-kt-app-header-fixed-mobile="true" data-kt-app-sidebar-enabled="true" data-kt-app-sidebar-fixed="true" data-kt-app-sidebar-hoverable="true" data-kt-app-sidebar-push-toolbar="true" data-kt-app-sidebar-push-footer="true" data-kt-app-toolbar-enabled="true" data-kt-app-aside-enabled="true" data-kt-app-aside-fixed="true" data-kt-app-aside-push-toolbar="true" data-kt-app-aside-push-footer="true" class="app-default">
		<!--begin::Theme mode setup on page load-->
		<script>
			var defaultThemeMode = "light"; var themeMode; if ( document.documentElement ) { if ( document.documentElement.hasAttribute("data-bs-theme-mode")) { themeMode = document.documentElement.getAttribute("data-bs-theme-mode"); } else { if ( localStorage.getItem("data-bs-theme") !== null ) { themeMode = localStorage.getItem("data-bs-theme"); } else { themeMode = defaultThemeMode; } } if (themeMode === "system") { themeMode = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; } document.documentElement.setAttribute("data-bs-theme", themeMode); }
		</script>
		<!--end::Theme mode setup on page load-->
		<!--begin::App-->
		<div class="d-flex flex-column flex-root app-root" id="kt_app_root">
			<!--begin::Page-->
			<div class="app-page flex-column flex-column-fluid" id="kt_app_page">
				<!--begin::Header-->
				<?php include "_navbar.php"; ?> 
				<!--end::Header-->
				<!--begin::Wrapper-->
				<div class="app-wrapper flex-column flex-row-fluid" id="kt_app_wrapper">
					<!--begin::Sidebar--> 
					<?php include "_sidebar.php"; ?>
					<!--end::Sidebar-->
					<!--begin::Main-->
					<div class="app-main flex-column flex-row-fluid" id="kt_app_main">
						<!--begin::Content wrapper-->
						<div class="d-flex flex-column flex-column-fluid">
							<!--begin::Toolbar-->
							<div id="kt_app_toolbar" class="app-toolbar pt-6 pb-2">
								<!--begin::Toolbar container-->
								<div id="kt_app_toolbar_container" class="app-container container-fluid d-flex align-items-stretch">
									<!--begin::Toolbar wrapper-->
									<div class="app-toolbar-wrapper d-flex flex-stack flex-wrap gap-4 w-100">
										<!--begin::Page title-->
										<div class="page-title d-flex flex-column justify-content-center gap-1 me-3">
											<!--begin::Title-->
											<h1 class="page-heading d-flex flex-column justify-content-center text-gray-900 fw-bold fs-3 m-0">Create</h1>
											<!--end::Title-->
											<!--begin::Breadcrumb-->
											<ul class="breadcrumb breadcrumb-separatorless fw-semibold fs-7 my-0">
												<!--begin::Item-->
												<li class="breadcrumb-item text-muted">
													<a href="create.php" class="text-muted text-hover-primary">Home</a>
												</li> 
												<!--end::Item-->
												<!--begin::Item-->
												<li class="breadcrumb-item">
													<span class="bullet bg-gray-500 w-5px h-2px"></span>
												</li>
												<!--end::Item-->
												<!--begin::Item--> 
												<li class="breadcrumb-item text-muted">Create Invoice</li>
												<!--end::Item-->
											</ul>
											<!--end::Breadcrumb-->
										</div>
										<!--end::Page title-->
										<!--begin::Actions-->
										<!--<div class="d-flex align-items-center gap-2 gap-lg-3">
											<a href="#" class="btn btn-flex btn-outline btn-color-gray-700 btn-active-color-primary bg-body h-40px fs-7 fw-bold" data-bs-toggle="modal" data-bs-target="#kt_modal_view_users">Add Member</a>
											<a href="#" class="btn btn-flex btn-primary h-40px fs-7 fw-bold" data-bs-toggle="modal" data-bs-target="#kt_modal_create_campaign">New Campaign</a>
										</div>--> 
										<!--end::Actions-->
									</div>
									<!--end::Toolbar wrapper-->
								</div>
								<!--end::Toolbar container-->
							</div>
							<!--end::Toolbar-->
							<!--begin::Content-->
							<div id="kt_app_content" class="app-content flex-column-fluid">
								<!--begin::Content container-->
								<div id="kt_app_content_container" class="app-container container-fluid">
									<!--begin::Layout-->
									<div class="d-flex flex-column flex-lg-row">
										<!--begin::Content-->
										<div class="flex-lg-row-fluid mb-10 mb-lg-0 me-lg-7 me-xl-10">
											<!--begin::Card-->
											<div class="card">
												<!--begin::Card body-->
												<div class="card-body p-12">
													<!--begin::Form-->
													
													<?php flash("msg"); ?>
													
													<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" id="kt_invoice_form" enctype="multipart/form-data" > 
														<input type='hidden' name='action' id='action' value='Insert'>
														<!--begin::Wrapper-->
														<div class="d-flex flex-column align-items-start flex-xxl-row">
															<!--begin::Input group-->
															<div class="d-flex align-items-center flex-equal fw-row me-4 order-2" data-bs-toggle="tooltip" data-bs-trigger="hover" title="Specify invoice date">
																<!--begin::Date-->
																<div class="fs-6 fw-bold text-gray-700 text-nowrap">Date:</div>
																<!--end::Date-->
																<!--begin::Input-->
																<div class="position-relative d-flex align-items-center w-150px"> 
																	<!--begin::Datepicker--> 	   
																	<input class="form-control form-control-transparent fw-bold pe-5" placeholder="Select date" name="invoice_date" />    
																	<!--end::Datepicker--> 
																	<!--begin::Icon-->
																	<!--<i class="ki-outline ki-down fs-4 position-absolute ms-4 end-0"></i>
																	end::Icon-->
																</div>
																<!--end::Input-->
															</div>
															<!--end::Input group-->
															<!--begin::Input group-->
															<div class="d-flex flex-center flex-equal fw-row text-nowrap order-1 order-xxl-2 me-4" data-bs-toggle="tooltip" data-bs-trigger="hover" title="Enter invoice number">
																<span class="fs-2x fw-bold text-gray-800">Invoice #</span>
																<input type="text" class="form-control form-control-transparent fw-bold text-muted fs-3" required name="invoice_num" value='<?php echo sprintf('%03d',$data["invoice_num"]); ?>' placeholder="Invoice number" />
															</div>
															<!--end::Input group-->
															<!--begin::Input group-->
															<div class="d-flex align-items-center justify-content-end flex-equal order-3 fw-row" data-bs-toggle="tooltip" data-bs-trigger="hover" title="Specify invoice due date">
																<!--begin::Date-->
																<div class="fs-6 fw-bold text-gray-700 text-nowrap">Document Type:</div>
																<!--end::Date-->
																<!--begin::Input-->
																<select name="doctype" aria-label="Select a Timezone" data-control="select2" data-placeholder="Select currency" class="form-select form-select-solid" id="currency-select">
																	<option data-kt-flag="flags/united-states.svg" value="taxinvoice">Tax Invoice</option>
																	<option data-kt-flag="flags/united-states.svg" value="bill">Bill of Supply</option>
																</select>
																<!--end::Input-->
															</div>

															<div class="d-flex align-items-center justify-content-end flex-equal order-3 fw-row" data-bs-toggle="tooltip" data-bs-trigger="hover" title="Specify invoice due date">
																<!--begin::Date-->
																<div class="fs-6 fw-bold text-gray-700 text-nowrap">Due Date:</div>
																<!--end::Date-->
																<!--begin::Input-->
																<div class="position-relative d-flex align-items-center w-150px">
																	<!--begin::Datepicker-->
																	<input class="form-control form-control-transparent fw-bold pe-5" placeholder="Select date" name="invoice_due_date"  /> 
																	<!--end::Datepicker-->
																	<!--begin::Icon-->
																	<i class="ki-outline ki-down fs-4 position-absolute end-0 ms-4"></i>
																	<!--end::Icon-->
																</div>
																<!--end::Input-->
															</div>
															<!--end::Input group-->
														</div>
														<!--end::Top-->
														<!--begin::Separator-->
														<div class="separator separator-dashed my-10"></div>
														<!--end::Separator-->
														<!--begin::Wrapper-->
														<div class="mb-0">
															<!--begin::Row-->
															<div class="row gx-10 mb-5">

															
																<!--begin::Col-->
																<!--<div class="col-lg-6">
																	<label class="form-label fs-6 fw-bold text-gray-700 mb-3">Bill From</label>
																	begin::Input group
																	<div class="mb-5">
																		<input type="hidden" class="form-control form-control-solid" readonly name="aid" placeholder="Name" value="<?php echo $data['admin'][1]['AID']; ?>" />
																		<input type="text" class="form-control form-control-solid" readonly name="bfname" placeholder="Name" value="<?php echo $data['admin'][1]['ANAME']; ?>" />
																	</div>
																	<!--end::Input group-->
																	<!--begin::Input group-->
																	<!-- <div class="mb-5">
																		<input type="text" class="form-control form-control-solid" readonly name="bfemail" placeholder="Email" value="<?php echo $data['admin'][1]['AEMAIL']; ?>" />
																	</div> -->
																	<!--end::Input group-->
																	<!--begin::Input group
																	<div class="mb-5">
																	<input type="text" class="form-control form-control-solid" readonly name="gstin" value="<?php echo $data['admin'][1]['GSTIN']; ?>" placeholder="State" />
																	</div>
																	<div class="mb-5">
																				<input type="text" class="form-control form-control-solid" readonly name="state" value="<?php echo $data['admin'][1]['STATE']; ?>" placeholder="State" />
																			</div>
																	<!--end::Input group
																</div>-->
																<div class="col-lg-6">
																		<label class="form-label fs-6 fw-bold text-gray-700 mb-3">Bill To</label>
																	<!--begin::Input group-->
																	<div class="mb-5">
																		<input type="text" class="form-control form-control-solid" name="btname" placeholder="Name" required />
																	</div>
																	<div class="mb-5">
																	<input type="text" class="form-control form-control-solid" name="igstin" placeholder="GSTIN" required />
																	</div>
																	<!--end::Input group-->
																	
																	<div class="mb-5">
																		<input type="text" class="form-control form-control-solid" name="usstate" placeholder="State" required />
																	</div> 
																	<!--<label class="form-label fs-6 fw-bold text-gray-700 mb-3">Dispatch From</label>
																			<div class="mb-5">
																				<input type="text" class="form-control form-control-solid" readonly name="pincode" value="<?php echo $data['admin'][1]['PINCODE']; ?>" placeholder="Pincode" />
																			</div>-->
																		 
																	<!--begin::Input group
																	<div class="mb-5">
																		<input type="text" class="form-control form-control-solid" name="place" readonly value="<?php echo $data['admin'][1]['PLACE']; ?>" placeholder="Place" />
																	</div>-->
																	<!--end::Input group-->
																	<!--begin::Input group-->
																	<!--<div class="mb-5">
																	<textarea id="address" name="address" class="form-control form-control-solid" readonly rows="3"  placeholder="Who is this invoice from?"><?php echo $data['admin'][1]['ADDRESS']; ?></textarea>
																	</div>-->
																	<!--end::Input group-->
																</div>
																<!--end::Col-->
																<!--begin::Col-->
																<div class="col-lg-6">
																	<label class="form-label fs-6 fw-bold text-gray-700 mb-3"></label>
																	 
																		<div class="mb-5">
																			<input type="text" class="form-control form-control-solid" name="uspincode" placeholder="Pincode" required />
																		</div>
																		 
																	<div class="mb-5">
																		<input type="text" class="form-control form-control-solid" name="usplace" placeholder="Place" required />
																	</div>
																	
																	<div class="mb-5">
																		<textarea name="usaddress" class="form-control form-control-solid" rows="3" placeholder="Address" required ></textarea>
																	</div>
																</div>
																<div class="col-lg-6">
																	
																</div>
																<!--end::Col-->
															</div>  
															<!--end::Row-->
															<!--begin::Table wrapper-->
															
															<?php 
																$rows=resultSet($con,"select pid,pname,uom from tbl_products order by pname"); 
																$options="<option value=''>Select Product</option>";
																foreach($rows as $row){
																	$options.="<option value='{$row["pid"]}' uom='{$row["uom"]}'>{$row["pname"]}</option>";
																}
															?> 
                                                            <?php
                                                                $rw=resultSet($con,"select * from tbl_product_sizes s inner join tbl_products p on s.pid=p.pid");
                                                                $size="<option value=''>Select Sizes</option>";
																foreach($rw as $r){
																	$size.="<option value='{$r["id"]}' size='{$r["size"]}'>{$r["size"]}</option>";
																}
                                                            ?>
															
															<div class="table-responsive mb-10">
															<label class="form-label fs-6 fw-bold text-gray-700 mb-3">Item Details</label>
																<!--begin::Table-->
																<table class="table g-5 gs-0 mb-0 fw-bold text-gray-700" data-kt-element="items">
																	<!--begin::Table head-->
																	<thead>
																		<tr class="border-bottom fs-7 fw-bold text-gray-700 text-uppercase">
																			<th class="min-w-300px w-475px">Product</th> 
																			<th class="min-w-300px w-475px">Sizes</th> 
																			<th class="min-w-100px w-100px">QTY</th>
																			<th class="min-w-100px w-100px">UOM</th>
																			<th class="min-w-150px w-150px">Price</th>
																			<th class="min-w-100px w-150px text-end">Total</th>
																			<th class="min-w-75px w-75px text-end">Action</th>
																		</tr>
																	</thead>
																	<!--end::Table head-->
																	<!--begin::Table body-->
																	<tbody>
																		<tr class="border-bottom border-bottom-dashed" data-kt-element="item">
																			<td class="pe4">
																				<select name='name[]' id='pid' data-control="select2"  data-placeholder="Select Product" class="form-select form-select-solid pid"> 
																					<?php echo $options;?> 
																				</select>															
																				<!--<input type="text" class="form-control form-control-solid mb-2" name="name[]" placeholder="Item name" required /> -->
																			</td> 
                                                                            <td class="pe4">
                                                                                <select name='size[]' id='size' data-control="select2"  data-placeholder="Select Sizes" class="form-select form-select-solid"> 
																					<?php echo $opt;?> 
																				</select>	
                                                                            </td>
																			<td class="ps-0">
																				<input class="form-control form-control-solid quantity" type="number" min="1" name="quantity[]" placeholder="1" value="1" data-kt-element="quantity" required />
																			</td>
																			<td class="ps-0">
																				<input type="text" class="form-control form-control-solid mb-2 w-100px uom " name="uom[]" placeholder="UOM" required /> 
																			</td> 
																			<td>
																				<input type="text" class="form-control form-control-solid text-end price" name="price[]" placeholder="0.00" data-kt-element="price" required />
																			</td> 
																			<td> 
																				<input type="text" class="total form-control form-control-solid text-end" name='total[]' placeholder="0.00"  data-kt-element="total" /> 
																				<!--<span data-kt-element="total" name='total[]' class='total'>0.00</span>-->
																				   
																			</td>  
																			<td class="pt-5 text-end">  
																				<button type="button" class="btn btn-sm btn-icon btn-active-color-primary" data-kt-element="remove-item">
																					<i class="ki-outline ki-trash fs-3"></i>
																				</button> 
																			</td>
																		</tr>
																	</tbody>
																	<!--end::Table body-->
																	<!--begin::Table foot-->
																	<tfoot>
																		<tr class="border-top border-top-dashed align-top fs-6 fw-bold text-gray-700">
																			<th class="text-primary">
																				<button class="btn btn-link py-1 add_item" data-kt-element="add-item">Add item</button>
																			</th>
																			<th colspan="2" class="border-bottom border-bottom-dashed ps-0">
																				<div class="d-flex flex-column align-items-start">
																					<div class="fs-5">Subtotal</div>
																				</div>
																			</th>
																			<th colspan="2" class="border-bottom border-bottom-dashed text-end">
																				<input type='text' data-kt-element="sub-total" class="form-control form-control-solid text-end sub-total" name='sub_total' id='sub-total'>
																				<!--<span data-kt-element="sub-total" id='sub-total'>0.00</span>--> 
																			</th>
																		</tr>
																		<tr class="border-top border-top-dashed align-top fs-6 fw-bold text-gray-700">
																			<th></th>
																			<th colspan="2" class="border-bottom border-bottom-dashed ps-0">
																				<div class="d-flex flex-column align-items-start">
																					<div class="fs-5">GST %</div>
																					
																				</div>
																			</th>  
																			<input type='hidden' class='text-right amount' value='<?php echo GST; ?>' style='width:80px;' id='gstp' name='gstp' >
																			<th colspan="2" class="border-bottom border-bottom-dashed text-end">
																			<input type='text' class="form-control form-control-solid text-end" id='gst' name='gst' data-kt-element="gst"> 
																		</tr>
																		<tr class="border-top border-top-dashed align-top fs-6 fw-bold text-gray-700">
																			<th></th>
																			<th colspan="3" class="border-bottom border-bottom-dashed ps-0">
																				<div class="d-flex flex-column align-items-start">
																					<div class="fs-5">Round Off</div>
																					
																				</div>
																			</th> 
																			<th><input type='text' class="form-control form-control-solid text-end" id='round_off' name='round_off' data-kt-element="round_off"></th>
																		</tr>
																		<tr class="align-top fw-bold text-gray-700">
																			<th></th>
																			<th colspan="3" class="border-bottom border-bottom-dashed ps-0">
																				<div class="d-flex flex-column align-items-start">
																					<div class="fs-5">Total</div> 
																				</div>
																			</th> 
																			<th class="border-bottom border-bottom-dashed text-end">
																				<input type='text' class="form-control form-control-solid text-end" id='net_amt' name='net_amt' data-kt-element="grand-total"> 
																			</th>
																		</tr> 
																	</tfoot>
																	<!--end::Table foot-->
																</table>
															</div>
															<!--end::Table-->
															<!--begin::Item template-->
															  
															<table class="table d-none" data-kt-element="item-template">
																<tr class="border-bottom border-bottom-dashed" data-kt-element="item">
																	<td class="pe4">
																		<select name='name[]' data-control="select2"  data-placeholder="Select Product" class="form-select form-select-solid pid select"> 
																			<?php echo $options;?> 
																		</select> 
																				
																		<!--<input type="text" class="form-control form-control-solid mb-2" name="name[]" placeholder="Item name" /> -->
																	</td>
                                                                     <td class="pe4">
																		<select name='size[]' id='size' data-control="select2"  data-placeholder="Select Sizes" class="form-select form-select-solid"> 
																			<?php echo $opt;?> 
																		</select>	
																	</td> 
																	<td class="ps-0">
																		<input class="form-control form-control-solid quantity" type="number" min="1" name="quantity[]" placeholder="1" value="1" data-kt-element="quantity" /> 
																	</td>
																	<td class="ps-0">
																		<input type="text" class="form-control form-control-solid mb-2 w-100px " name="uom[]" placeholder="UOM" /> 
																	</td> 
																	<td>
																		<input type="text" class="form-control form-control-solid text-end price" name="price[]" placeholder="0.00" data-kt-element="price" />
																	</td>
																	<td> 
																		<input type="text" class="total form-control form-control-solid text-end" name='total[]' placeholder="0.00"  data-kt-element="total" />  
																		<!--<span data-kt-element="total" name='total[]' class='total'><input type="text"  name='total[]' data-kt-element="total" /></span>-->    
																	</td>   
																	<td class="pt-5 text-end"> 
																		<button type="button" class="btn btn-sm btn-icon btn-active-color-primary" data-kt-element="remove-item">
																			<i class="ki-outline ki-trash fs-3"></i>
																		</button>
																	</td>
																</tr>
															</table>
															
															<table class="table d-none" data-kt-element="empty-template">
																<tr data-kt-element="empty">
																	<th colspan="5" class="text-muted text-center py-10">No items</th>
																</tr>
															</table>
															<!--end::Item template-->
															<!--begin::Notes-->
															<div class="mb-0">
																<label class="form-label fs-6 fw-bold text-gray-700">Notes</label>
																<textarea name="notes" class="form-control form-control-solid" rows="3" placeholder="Thanks for your business"></textarea>
															</div> 
															
															<input type="submit" name='submit' value='Submit' class="btn btn-primary w-100 mt-5">
															
														</div>
												</div>
												<!--end::Card body-->
											</div>
											<!--end::Card-->
										</div>
										<!--begin::Sidebar-->
										<div class="flex-lg-auto min-w-lg-300px">
											<!--begin::Card-->
											<div class="card" data-kt-sticky="true" data-kt-sticky-name="invoice" data-kt-sticky-offset="{default: false, lg: '200px'}" data-kt-sticky-width="{lg: '250px', lg: '300px'}" data-kt-sticky-left="auto" data-kt-sticky-top="150px" data-kt-sticky-animation="false" data-kt-sticky-zindex="95">
												<!--begin::Card body-->
												<div class="card-body p-10">
													<!--begin::Input group-->
													<div class="mb-10">
														<label class="form-label fw-bold fs-6 text-gray-700">Freight Charge</label>
														<input type="text" class="form-control form-control-solid" name="fcharge" />
														
														<label class="form-label fw-bold fs-6 text-gray-700 pt-2">Transport No</label>
														<input type="text" class="form-control form-control-solid" name="transno" />  
													</div>
													<!--end::Input group-->
													<!--begin::Separator-->
													<div class="separator separator-dashed mb-8"></div>
													<!--end::Separator-->
													<!--begin::Actions--> 
													<div class="mb-0">
														<!--begin::Row-->
														<div class="row mb-5">
															<!--begin::Col-->
															<div class="col">
																<a href="#" class="btn btn-light btn-active-light-primary w-100">Preview</a>
															</div>
															<!--end::Col-->
															<!--begin::Col-->
															<div class="col">
																<a href="#" class="btn btn-light btn-active-light-primary w-100">Download</a>
															</div>
															<!--end::Col-->
														</div>
														<!--end::Row-->
														<button type="submit" href="#" class="btn btn-primary w-100" id="kt_invoice_submit_button">
														<i class="ki-outline ki-triangle fs-3"></i>Send Invoice</button>
													</div>
													<!--end::Actions-->
												</div>
												<!--end::Card body-->
											</div>
											<!--end::Card-->
											</div>
										</form>
										
										<!--end::Sidebar-->
									</div>
									<!--end::Layout-->
								</div>
								<!--end::Content container-->
							</div>
							<!--end::Content-->
						</div>
						<!--end::Content wrapper-->
						<!--begin::Footer-->
							<?php include "_footer.php"; ?>
						<!--end::Footer-->
					</div>
					<!--end:::Main-->
					<!--begin::aside-->
					<div id="kt_app_aside" class="app-aside flex-column" data-kt-drawer="true" data-kt-drawer-name="app-aside" data-kt-drawer-activate="{default: true, lg: false}" data-kt-drawer-overlay="true" data-kt-drawer-width="auto" data-kt-drawer-direction="end" data-kt-drawer-toggle="#kt_app_aside_mobile_toggle">
						<!--begin::Wrapper-->
						<div id="kt_app_aside_wrapper" class="d-flex flex-column align-items-center hover-scroll-y mt-lg-n3 py-5 py-lg-0 gap-4" data-kt-scroll="true" data-kt-scroll-activate="{default: false, lg: true}" data-kt-scroll-height="auto" data-kt-scroll-dependencies="#kt_app_header" data-kt-scroll-wrappers="#kt_app_aside_wrapper" data-kt-scroll-offset="5px">
							<a href="apps/calendar.php" class="btn btn-icon btn-color-primary bg-hover-body h-45px w-45px flex-shrink-0" data-bs-toggle="tooltip" title="Calendar" data-bs-custom-class="tooltip-inverse">
								<i class="ki-outline ki-calendar fs-2x"></i>
							</a>
							<a href="account/overview.php" class="btn btn-icon btn-color-warning bg-hover-body h-45px w-45px flex-shrink-0" data-bs-toggle="tooltip" title="Profile" data-bs-custom-class="tooltip-inverse">
								<i class="ki-outline ki-address-book fs-2x"></i>
							</a>
							<a href="apps/ecommerce/catalog/products.php" class="btn btn-icon btn-color-success bg-hover-body h-45px w-45px flex-shrink-0" data-bs-toggle="tooltip" title="Messages" data-bs-custom-class="tooltip-inverse">
								<i class="ki-outline ki-tablet-ok fs-2x"></i>
							</a>
							<a href="apps/inbox/listing.php" class="btn btn-icon btn-color-dark bg-hover-body h-45px w-45px flex-shrink-0" data-bs-toggle="tooltip" title="Products" data-bs-custom-class="tooltip-inverse">
								<i class="ki-outline ki-calendar-add fs-2x"></i>
							</a>
						</div>
						<!--end::Wrapper-->
					</div>
					<!--end::aside-->
				</div>
				<!--end::Wrapper-->
			</div>
			<!--end::Page-->
		</div>
		<!--end::App--> 
		<!--begin::Scrolltop-->
		<div id="kt_scrolltop" class="scrolltop" data-kt-scrolltop="true">
			<i class="ki-outline ki-arrow-up"></i>
		</div>
		<!--end::Scrolltop-->
		 

<script>
	$(document).ready(function(){
	
		$("body").on("keyup",".quantity",function(){
			var qty=Number($(this).closest("tr").find(".quantity").val());
			var price=Number($(this).closest("tr").find(".price").val());
			$(this).closest("tr").find(".total").val(price*qty);  
			grand_total(); 
		});
		
		$("body").on("keyup",".price",function(){
			var qty=Number($(this).closest("tr").find(".quantity").val());
			var price=Number($(this).closest("tr").find(".price").val());
			$(this).closest("tr").find(".total").val(price*qty);  
			grand_total();  
		});
		
		$("body").on("change",".pid",function(e){
			var uom=$(this).find("option:selected").attr("uom");
			$(this).closest("tr").find(".uom").val(uom); 
		});
				
        
        
		/*function getTotal(){
			var sum=0;
			$(".total").each(function(){
				sum=sum+Number($(this).val());
			})
			$("#tot").val(sum);
		}; */
		
		
		function round2(num){
			return Math.round(num*100)/100;
		}
		
		$("body").on("keyup","#gstp",function(){
			grand_total();
		});
		
		//grand_total
		function grand_total(){
			var gstp=Number($("#gstp").val().trim());
			
			var total=0;
			$(".total").each(function(){
				total+=Number($(this).val().trim());
			});
			total=round2(total);
			$("#sub-total").val(total);	
			 
			var gst=round2((total*gstp)/100);
			
			$("#gst").val(gst); 
			
			var net_amt=total+gst; 
			var round_off=Math.round(net_amt)-net_amt;
			
			$("#round_off").val(round2(round_off));
			
			$("#net_amt").val(Math.round(net_amt));
			
		}
		
    // Attach click event handler to the submit button
    $('#kt_invoice_submit_button').click(function(e) {
        // Prevent the default button behavior
        e.preventDefault();
        
        // Check if any fields are empty
        var isFormValid = true;
        $('#kt_invoice_form input, #kt_invoice_form textarea').each(function() {
            if ($(this).val() === '') {
                isFormValid = false;
                return false; // Exit the loop early if an empty field is found
            }
        });

        // If any field is empty, show error message and exit
        // if (!isFormValid) {
        //     Swal.fire({
        //         title: 'Error!',
        //         text: 'Please fill in all fields before submitting the form',
        //         icon: 'error'
        //     });
        //     return;
        // }
        
        // Trigger Swal (SweetAlert2) confirmation
        Swal.fire({
            title: 'Are you sure?',
            text: 'You are about to submit the form',
            icon: 'warning',
            showCancelButton: true,
            confirmButtonText: 'Yes, submit it!',
            cancelButtonText: 'No, cancel!',
            reverseButtons: true
        }).then((result) => {
            if (result.isConfirmed) {
                // If user confirms, serialize form data and send AJAX request
                var formData = $('#kt_invoice_form').serialize();
                // Get the selected currency value
                var selectedCurrency = $('#currency-select').val();
                // Append the currency value to the serialized form data
                formData += '&currency=' + selectedCurrency;
                $.ajax({
                    type: 'POST',
                    url: 'ajax_invoice.php', // Update the URL with your server endpoint
                    data: formData,
                    success: function(response) {
                        // Handle success response from server
                        Swal.fire({
                            title: 'Success!',
                            text: 'Form submitted successfully',
                            icon: 'success'
                        });
                        console.log(response); // Log response from server
                        // Optionally, you can perform further actions here
						$('#kt_invoice_form')[0].reset();
                    },
                    error: function(xhr, status, error) {
                        // Handle errors
                        Swal.fire({
                            title: 'Error!',
                            text: 'Failed to submit form. Please try again later.',
                            icon: 'error'
                        });
                        console.error('Error:', error);
                        // Optionally, you can handle errors and display messages to the user
                    }
                });
            }
        });
    });
});
</script>
</body> 
</html>

MMCT - 2023