<?php require_once('../auth/auth.php'); require_once('../auth/acid_balance.php');

if (isset($_POST['newemployee'])) {
    $em_acname=    $_POST['em_acname'];
    $alias_name= $_POST['alias_name'];
    $ac_number=$_POST['ac_number'];
    $ac_email=$_POST['ac_email'];
    $divisions=$_POST['divisions']; 
    $distr=$_POST['distr'];
    $polic_sta=$_POST['polic_sta'];
    $present_address=$_POST['present_address'];
    $em_nid=$_POST['em_nid'];  //user table
    $outlet_id=$_POST['out_it'];
    $designation_type=$_POST['designation_type'];
    $comm_margin=$_POST['comm_margin'];
    $crlimit=$_POST['crlimit'];
    $salary=$_POST['salary'];
    $brith_date=$_POST['brith_date'];
    $par_address=$_POST['par_address'];
    $g_note=$_POST['g_note'];
    $balance=0;
    $sendsms=$_POST['sendsms'];
    $ac_join_date=$_POST['ac_join_date'];
    $status=1;
    $working_type=$_POST['working_type'];

    $gcatid=$_POST['gcatid'];

mysqli_query($conn,"INSERT INTO `accounts`( `coid`, `bid`, `brid`, `gcatid`, `outlet_id`, `ac_name`, `ac_alise`, `ac_number`, `ac_details`, `ac_email`, `ac_area`, `opdate`, `atime`, `balance`, `userid`, `ac_type`, `active`) VALUES ('$coid','$bid','$brid','$gcatid','$outlet_id','$em_acname','$alias_name','$ac_number','$present_address','$ac_email','0','$ac_join_date','$time','0','$uid',(SELECT g_type FROM ac_sub_g_category WHERE ac_g_catid='$gcatid'),'1')")or die(mysqli_error($conn));
    $account_id = mysqli_insert_id($conn);





if ($account_id >0) {

    mysqli_query($conn,"INSERT INTO `account_info`( `coid`, `bid`, `brid`, `acid`, `nid`,`g_note`) VALUES ('$coid','$bid','$brid','$account_id','$em_nid','$g_note')")or die(mysqli_error($conn));


         mysqli_query($conn,"INSERT INTO `em_employee`(`em_coid`, `em_bid`, `em_brid`, `em_acid`, `em_acname`, `em_dis_id`, `em_phone`, `em_email`, `divisions`, `distr`, `polic_sta`, `em_pres_address`, `em_parma_address`,`em_nid`,`id_card`,`commission`,`crlimit`,`salary`,`g_note`, `working_type`, `em_balance`, `join_date`, `date_of_brith`, `em_status`) VALUES ('$coid','$bid','$brid','$account_id', '$em_acname', '$designation_type','$ac_number','$ac_email','$divisions','$distr','$polic_sta','$present_address','$par_address','$em_nid','$outlet_id','$comm_margin','$crlimit','$salary','$g_note', '$working_type', '0','$ac_join_date', '$brith_date', '$status' )")or die(mysqli_error($conn));
}else{ echo "Employee Table Not Valid ";}

if ($sendsms=='') { echo "SMS Not Sent";}

}

?>
<?php 
if (isset($_POST['update_emfrom'])) {
    $em_id=    $_POST['em_id'];
    $em_acname= $_POST['em_acname'];
    $em_alias= $_POST['em_alias'];
    $em_phone= $_POST['em_phone'];
    $em_email= $_POST['em_email'];
    $em_pres_address= $_POST['em_pres_address'];
    $em_nid= $_POST['em_nid'];
    $id_card= $_POST['id_card'];

if($em_id >0){
        mysqli_query($conn,"UPDATE em_employee SET em_acname='$em_acname',em_alias='$em_alias',em_phone='$em_phone',em_email='$em_email',em_pres_address='$em_pres_address',em_nid='$em_nid',id_card='$id_card' WHERE em_id='$em_id' AND em_coid='$coid' AND em_bid='$bid' AND em_brid='$brid' ");
    }

}
 ?>
