<?php
if (isset($_POST["action"])) {
    
	$output = '';
	require('../config/dbcon.php');
	if ($_POST["action"] == "Add") {
	    
		$query = "Select srno from control_mst where description='PARTY'";
		$rs = mysqli_query($connect, $query) or die("Cannot execute query: $query\n");
		while ($row = mysqli_fetch_assoc($rs)) {
			$srno = $row['srno'];
			$srnoupd = $srno+1;
    		$party_name = mysqli_escape_string($connect, $_POST["party_name"]);
    		$party_address_one = mysqli_escape_string($connect, $_POST["party_address_one"]);
    		$party_address_two = mysqli_escape_string($connect, $_POST["party_address_two"]);
    		$party_place = mysqli_escape_string($connect, $_POST["party_place"]);
    		$party_contact_person = mysqli_escape_string($connect, $_POST["party_contact_person"]);
    		$party_phone_number = mysqli_escape_string($connect, $_POST["party_phone_number"]);
    		$party_mobile_number = mysqli_escape_string($connect, $_POST["party_mobile_number"]);
    		$party_gst_number = mysqli_escape_string($connect, $_POST["party_gst_number"]);
    		$party_pan_number = mysqli_escape_string($connect, $_POST["party_pan_number"]);
    		$party_aadhar_number = mysqli_escape_string($connect, $_POST["party_aadhar_number"]);
    		$party_payment_terms = mysqli_escape_string($connect, $_POST["party_payment_terms"]);
    		$party_goods = mysqli_escape_string($connect, $_POST["party_goods"]);
    		$party_remarks = mysqli_escape_string($connect, $_POST["party_remarks"]);
    		
    		$query = "insert into party_mst(id, party_name,party_address_one,party_address_two,party_place,party_contact_person,party_phone_number,party_mobile_number,party_gst_number,party_pan_number,party_aadhar_number,party_payment_terms,party_goods,party_remarks) Values ('" . $srno . "','" . $party_name . "','" . $party_address_one . "','" . $party_address_two . "','" . $party_place . "','" . $party_contact_person . "','" . $party_phone_number . "','" . $party_mobile_number . "','" . $party_gst_number . "','" . $party_pan_number . "','" . $party_aadhar_number . "','" . $party_payment_terms . "','" . $party_goods . "','" . $party_remarks . "')";
    		if (mysqli_query($connect, $query)) {
    			$update = "update control_mst set srno = '" . $srnoupd . "' where description='PARTY'";
    			mysqli_query($connect, $update) or die(mysqli_error());
    		}
		}
	}
	if ($_POST["action"] == "Update") {
	    
		$id = mysqli_escape_string($connect, $_POST["id"]);
		$party_name = mysqli_escape_string($connect, $_POST["party_name"]);
		$party_address_one = mysqli_escape_string($connect, $_POST["party_address_one"]);
		$party_address_two = mysqli_escape_string($connect, $_POST["party_address_two"]);
		$party_place = mysqli_escape_string($connect, $_POST["party_place"]);
		$party_contact_person = mysqli_escape_string($connect, $_POST["party_contact_person"]);
		$party_phone_number = mysqli_escape_string($connect, $_POST["party_phone_number"]);
		$party_mobile_number = mysqli_escape_string($connect, $_POST["party_mobile_number"]);
		$party_gst_number = mysqli_escape_string($connect, $_POST["party_gst_number"]);
		$party_pan_number = mysqli_escape_string($connect, $_POST["party_pan_number"]);
		$party_aadhar_number = mysqli_escape_string($connect, $_POST["party_aadhar_number"]);
		$party_payment_terms = mysqli_escape_string($connect, $_POST["party_payment_terms"]);
		$party_goods = mysqli_escape_string($connect, $_POST["party_goods"]);
		$party_remarks = mysqli_escape_string($connect, $_POST["party_remarks"]);
		
		$update = "update party_mst set party_name = '" . $party_name . "',party_address_one = '" . $party_address_one . "',party_address_two = '" . $party_address_two . "',party_place = '" . $party_place . "',party_contact_person = '" . $party_contact_person . "',party_phone_number = '" . $party_phone_number . "',party_mobile_number = '" . $party_mobile_number . "',party_gst_number = '" . $party_gst_number . "',party_pan_number = '" . $party_pan_number . "',party_aadhar_number = '" . $party_aadhar_number . "',party_payment_terms = '" . $party_payment_terms . "',party_goods = '" . $party_goods . "',party_remarks = '" . $party_remarks . "' where id = '" . $id . "'";
		if (mysqli_query($connect, $update)) {
		    
		}
		
	}
	if ($_POST["action"] == "Delete") {
		$delete = "Delete from party_mst where id = '" . $_POST["id"] . "'";
		if (mysqli_query($connect, $delete)) {
		    
		}
	}
	
}