<?php
ini_set('display_errors', 0);
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

session_start();
ob_start();

require_once('configuration/server_connect.php');
require_once('configuration/all_function.php');

$order_no = $_REQUEST['order_no'];
$unit_price = $_REQUEST['unit_price'];
$total_unit = $_REQUEST['total_unit'];
$total_amt = $_REQUEST['total_amt'];
$discount = $_REQUEST['discount'];
$discount_amt = $_REQUEST['discount_amt'];
 $amt_after_discount = $_REQUEST['amt_after_discount'];
 $remarks = $_REQUEST['remarks'];
 $jv_no = $_REQUEST['jv_no'];
 
 $flag = $_REQUEST['flag'];

if($total_unit==0){
$sql_del = 'delete from sales_invoice where id="'.$order_no.'" ';
mysqli_query($conn,$sql_del);
}

$sql_del_sjv = 'delete from secondary_journal where jv_no="'.$jv_no.'" and tr_from="Sales"';
mysqli_query($conn,$sql_del_sjv);

$sql_del_jv = 'delete from journal where jv_no="'.$jv_no.'" and tr_from="Sales"';
mysqli_query($conn,$sql_del_jv);


$entry_by=$_SESSION['user']['id'];
$entry_at=date('Y-m-d H:i:s');


//if($total_unit>0) {}
 $up_sql = 'update sales_invoice  set unit_price="'.$unit_price.'", total_unit="'.$total_unit.'", total_amt="'.$total_amt.'", discount="'.$discount.'", 
  discount_amt="'.$discount_amt.'",  amt_after_discount="'.$amt_after_discount.'", remarks="'.$remarks.'",
 edit_by="'.$entry_by.'", edit_at="'.$entry_at.'"  where id='.$order_no;
mysqli_query($conn,$up_sql);





echo 'Success!';
?>