<?php 
include 'session.php';
require_once('common/getname_functions.php');
extract($_REQUEST);
$act=$action;

switch($act)
{
	
	case 'update_invoice_payment_details':
		
		if(!empty($disp_sup_id) && !empty($txt_given_amount)){
			
			//supplier payments main table save [t_suppliers_payments] - START	
			if($rbtn_payment_mode == "1"){
				//cash
				$paid_on_dt = date("Y-m-d", strtotime($txt_paid_on)); 
				
				$sup_payment_ins_qry = " insert into t_suppliers_payments(sup_id, company_id, payment_type_id, paid_on, amount_recv,  remarks, financial_id, IsActive, UserId, createddate) values('".$disp_sup_id."', '".$disp_company_id."', '".$rbtn_payment_mode."', '".$paid_on_dt."', '".$txt_given_amount."', '".$txt_remarks."', '".$_SESSION["Financial_id"]."', '1', '".$_SESSION["UserId"]."', NOW()) ";				
			}
			else if($rbtn_payment_mode == "2"){
				//cheque
				$cheque_issue_dt = date("Y-m-d", strtotime($txt_cheque_issued_on)); 
				$cheque_cleared_dt = date("Y-m-d", strtotime($txt_cleared_date)); 
				
				$sup_payment_ins_qry = " insert into t_suppliers_payments(sup_id, company_id, payment_type_id, amount_recv, bank_id, acc_no, cheque_issue_date, cheque_no, cleared_date, cheque_interest, cheque_amount, remarks, financial_id, IsActive, UserId, createddate) values('".$disp_sup_id."', '".$disp_company_id."', '".$rbtn_payment_mode."', '".$txt_given_amount."', '".$sel_bank."', '".$txt_acc_no."', '".$cheque_issue_dt."', '".$txt_cheque_no."', '".$cheque_cleared_dt."', '".$txt_cheque_interest."', '".$txt_cheque_amount."', '".$txt_remarks."', '".$_SESSION["Financial_id"]."', '1', '".$_SESSION["UserId"]."', NOW()) ";
			}
			else if($rbtn_payment_mode == "3"){
				//netbanking
				$transfer_dt = date("Y-m-d", strtotime($txt_cheque_issued_on)); 
				
				$sup_payment_ins_qry = " insert into t_suppliers_payments(sup_id, company_id, payment_type_id, amount_recv, bank_id, acc_no, cheque_issue_date, cheque_interest, cheque_amount, remarks, financial_id, IsActive, UserId, createddate) values('".$disp_sup_id."', '".$disp_company_id."', '".$rbtn_payment_mode."', '".$txt_given_amount."', '".$sel_bank."', '".$txt_acc_no."', '".$transfer_dt."', '".$txt_cheque_interest."', '".$txt_cheque_amount."', '".$txt_remarks."', '".$_SESSION["Financial_id"]."', '1', '".$_SESSION["UserId"]."', NOW()) ";
			}
						
			$sup_payment_insert = $db->insert($sup_payment_ins_qry);
			$payment_id_insert=$db->insert_id;									
			//supplier payments main table save [t_suppliers_payments] - END	
			
			if(!empty($payment_id_insert)){
				
				echo json_encode(array("rslt"=>"1")); //success
			}
			else{
				echo json_encode(array("rslt"=>"-1", "errmsg"=>"Payment Details Insert Faild")); //payment insert failed
			}			
		}
		else{
			echo json_encode(array("rslt"=>"-1", "errmsg"=>"Supplier ID Missing")); //no data
		}
	break;
	
}


?>