<?php
include("../public/impOpreation.php");
include("../library/uploadImages.php");
include_once("../public/config.php");
include_once("dailyentryfun.php");
$do = $_GET['do'];
$today = date("Y-m-d H:i:s");
$date = date("Y-m-d");

if (empty($do)) {
  $id = filter_input(INPUT_GET, 'id');
  $claim = R::load('claims', $id);
  $smarty->assign('claim', $claim);

  $smarty->assign('searchinonesave', $_SESSION['searchinonesave']);
  if ($_SESSION['searchinonesave'] == 0) {
      $saveQuery = '';
      if ($_SESSION['saveids'] != 0) {
          $saveQuery .= ' and saveid in (' . $_SESSION['saveids'] . ')';
      }
      $saves =  R::getAll('SELECT  *  FROM `save` WHERE conditions = 0 ' . $saveQuery);
      $smarty->assign("allSave", $saves);
      $smarty->assign("saveid", $_SESSION['saveid']);
  } else {
      $smarty->assign('allSave', $_SESSION['saveid']);
  }

  $bankQuery = '';
  if ($_SESSION['bankids'] != 0) {
      $bankQuery .= ' and bankid in (' . $_SESSION['bankids'] . ')';
  }
  $banks =  R::getAll('SELECT  *  FROM `bank` WHERE conditions = 0 ' . $bankQuery);
  $smarty->assign("banks", $banks);

  $smarty->display("header.html");
  $smarty->display("claimdebtview/add.html");
  $smarty->assign("claim", 1);
  $smarty->display("footer.html");
} elseif ($do == "show") {
  include_once("../public/authentication.php");
  $show = filter_input(INPUT_GET, 'show');
  if ($show == 2) {
    $smarty->assign('show', 2);
  }

  $smarty->assign('date', $date);
  $smarty->display("header.html");
  $smarty->display("claimdebtview/show.html");
  $smarty->assign("claim", 1);
  $smarty->display("footer.html");

} elseif ($do == "edit") {
  include_once("../public/authentication.php");

  $id = filter_input(INPUT_GET, 'id');
  $claimdebt = R::load('claimdebts', $id);
  $smarty->assign("claimdebt", $claimdebt);

  $claim = R::load('claims', $claimdebt->claimid);
  $smarty->assign('claim', $claim);

  $smarty->assign('searchinonesave', $_SESSION['searchinonesave']);
  if ($_SESSION['searchinonesave'] == 0) {
      $saveQuery = '';
      if ($_SESSION['saveids'] != 0) {
          $saveQuery .= ' and saveid in (' . $_SESSION['saveids'] . ')';
      }
      $saves =  R::getAll('SELECT  *  FROM `save` WHERE conditions = 0 ' . $saveQuery);
      $smarty->assign("allSave", $saves);
      $smarty->assign("saveid", $_SESSION['saveid']);
  } else {
      $smarty->assign('allSave', $_SESSION['saveid']);
  }

  $bankQuery = '';
  if ($_SESSION['bankids'] != 0) {
      $bankQuery .= ' and bankid in (' . $_SESSION['bankids'] . ')';
  }
  $banks =  R::getAll('SELECT  *  FROM `bank` WHERE conditions = 0 ' . $bankQuery);
  $smarty->assign("banks", $banks);

  $smarty->display("header.html");
  $smarty->display("claimdebtview/edit.html");
  $smarty->assign("claim", 1);
  $smarty->display("footer.html");
} elseif ($do == "detail") {

  $id = filter_input(INPUT_GET, 'id');
  $claimdebt = R::load('claimdebts', $id);
  $smarty->assign("claimdebt", $claimdebt);

  $claim = R::load('claims', $claimdebt->claimid);
  $smarty->assign('claim', $claim);

  if ($claimdebt->paymethod ==  0) {
     $save =  R::getRow('SELECT  *  FROM `save` WHERE saveid = ? ',[$claimdebt->saveid]);
     $smarty->assign("save", $save);
  }else{
     $bank =  R::getRow('SELECT  *  FROM `bank` WHERE bankid = ? ',[$claimdebt->bankid]);
     $smarty->assign("bank", $bank);
  }

  $smarty->display("header.html");
  $smarty->display("claimdebtview/detail.html");
  $smarty->assign("claim", 1);
  $smarty->display("footer.html");  

} else if ($do == 'savedata') {
  savedata();
} else if ($do == 'showajax') {
  showajax();
} else if ($do == 'removecontroller') {
  removecontroller();
} 


function savedata()
{
  $today = date("Y-m-d H:i:s");
  $date = date('Y-m-d');
  $userid = $_SESSION['userid'];
  $claimid = filter_input(INPUT_POST, 'claimid');
  $paymethod = filter_input(INPUT_POST, 'paymethod');
  $saveid = filter_input(INPUT_POST, 'saveid');
  $bankid = filter_input(INPUT_POST, 'bankid');
  $bankaccountid = filter_input(INPUT_POST, 'bankaccountid');
  $claim_value = filter_input(INPUT_POST, 'claim_value');
  $transaction_number = filter_input(INPUT_POST, 'transaction_number');
  $direct_debit = filter_input(INPUT_POST, 'direct_debit');
  $tax_rate = filter_input(INPUT_POST, 'tax_rate');
  $direct_tax = filter_input(INPUT_POST, 'direct_tax');
  $claim_debtcomment = filter_input(INPUT_POST, 'claim_debtcomment');
  $claimdebtid = filter_input(INPUT_POST, 'claimdebtid');
  if ($claimdebtid) {
    removecontroller($claimdebtid);
  }

  // if (!$claimdebts) {
    $claimdebts = R::dispense('claimdebts');
    $claimdebts->del = 0;
    $claimdebts->addtoday = $today;
    $claimdebts->adduserid = $userid;
    $claimdebts->deltoday = '';
    $claimdebts->deluserid = '';
  // } else {
  //   $claimdebts = R::load('claimdebts', $claimdebtid);
  //   $claimdebts->del = 1;
  //   $claimdebts->updatetoday = $today;
  //   $claimdebts->updateuserid = $userid;
  // }

  if ($paymethod == 0) {
    $saveidorbankid = $saveid;
  }else{
      $saveidorbankid = $bankid;
  }

  $claimdebts->claimid  = $claimid;
  $claimdebts->paymethod = $paymethod;
  $claimdebts->saveid = $saveid;
  $claimdebts->bankid = $bankid;
  $claimdebts->saveidorbankid = $saveidorbankid;
  $claimdebts->bankaccountid = $bankaccountid;
  $claimdebts->claim_value = $claim_value;
  $claimdebts->transaction_number = $transaction_number;
  $claimdebts->direct_debit = $direct_debit;
  $claimdebts->tax_rate = $tax_rate;
  $claimdebts->direct_tax = $direct_tax;
  $claimdebts->claim_debtcomment = $claim_debtcomment;
  $claimdebts->full_total = $claim_value - $direct_debit -  $direct_tax;

  try {
      $claimdebtid = R::store($claimdebts);

      $allsellbilldiscount =  $direct_debit / $claim_value;
      $allsellbilltax =  $direct_tax / $claim_value;


       if ($paymethod == 0) {
           $paytype = 'save';
          }else{
            $paytype = 'bank';
          }



      $claimsellbills = R::findAll('claimsellbills','claimid = ? and claimsellbills.del < 2 ',[$claimid]);
      // $arrayclaimsellbills = [];

      foreach ($claimsellbills as $claimsellbill) {
          $sellbilldiscount = $allsellbilldiscount * $claimsellbill->claimsellbillfinalbill;
          $sellbilltax = $allsellbilltax * $claimsellbill->claimsellbillfinalbill;

          $sellbilltaxdiscount = $sellbilldiscount + $sellbilltax;
        
          $arrayclaimsellbill = array(
            'bill_id' => $claimsellbill->claimsellbillid,
            'payed' => $claimsellbill->claimsellbillfinalbill - $sellbilldiscount - $sellbilltax,
            'paytype_txt' => 'دفع المطلبه رقم   ' . $claimid . ' للفاتوره رقم  ' . $claimsellbill->claimsellbillid,
            'paytype' => $paytype,
            'saveId' => $saveid,
            'bankAccountId' => $bankaccountid
          );
       

          $data_arr = array(
            'erpDB' => $_SESSION['dbname'],
            'curlpost'=>1,
            'userId' => $_SESSION['userid'],
            'id_pay' =>  json_encode([$arrayclaimsellbill]),
          );

           CURL_Request($data_arr, 'sellbillAjaxController.php?do=makeSellBillPayment',  0,  1, '', 'POST');
      
          $client = R::getRow('SELECT client.* FROM client join sellbill on sellbill.sellbillclientid = client.clientid
            WHERE sellbillid = ? ',[$claimsellbill->claimsellbillid]);
          $data_arr = array(
            'itr'=> 3,
            'branchid_entry'=> 0,
            'dDateTime'=> date("Y-m-d"),
            'user_id' => $_SESSION['userid'],
            'entryComment'=> 'دفع المطلبه رقم   ' . $claimid . ' للفاتوره رقم  ' . $claimsellbill->claimsellbillid,
            'E_parent1'=> 398,
            'comment1'=> '',
            'valueFrom1'=> $sellbilldiscount,
            'E_parent2'=> 77,
            'comment2'=> '',
            'valueFrom2'=> $sellbilltax,
            'E_parent3'=> $client['treeId'],
            'comment3'=> '',
            'valueTo3'=> $sellbilltaxdiscount,
            'totalValueFrom_hidden' => $sellbilltaxdiscount,
            'totalValueTo_hidden' => $sellbilltaxdiscount,
          );
          $dailyEntry = CURL_Request($data_arr, 'dailyentryajax.php?do=add',  0,  1, '', 'POST') ;
          $dailyEntry = explode(',', $dailyEntry);


          $claimsellbill->sellbilldiscount = $sellbilldiscount;
          $claimsellbill->sellbilltax = $sellbilltax;
          $claimsellbill->sellbilltaxdiscount = $sellbilltaxdiscount;
          $claimsellbill->dailyentryid = $dailyEntry[1];
          R::store($claimsellbill);


      }


      $claimreturnsellbills = R::findAll('claimreturnsellbills','claimid = ? and claimreturnsellbills.del < 2 ',[$claimid]);
      foreach ($claimreturnsellbills as $claimreturnsellbill) {
          $returnsellbilldiscount = $allsellbilldiscount * abs($claimreturnsellbill->claimreturnsellbillfinalbill);
          $returnsellbilltax = $allsellbilltax * abs($claimreturnsellbill->claimreturnsellbillfinalbill);

          $returnsellbilltaxdiscount = $returnsellbilldiscount + $returnsellbilltax;

          $returnarrayclaimsellbill = array(
            'bill_id' => $claimreturnsellbill->claimreturnsellbillid,
            'payed' =>  abs($claimreturnsellbill->claimreturnsellbillfinalbill) - $returnsellbilldiscount - $returnsellbilltax,
            'paytype_txt' => 'دفع المطلبه رقم   '.$claimid.' للفاتوره رقم  ' . $claimreturnsellbill->claimreturnsellbillid,
            'paytype' => $paytype,
            'saveId' => $saveid,
            'bankAccountId' => $bankaccountid
          );
          // array_push($arrayclaimsellbills, $arrayclaimsellbill);
          $data_arr = array(
            'erpDB' => $_SESSION['dbname'],
            'curlpost'=>1,
            'userId' => $_SESSION['userid'],
            'id_pay' => json_encode([$returnarrayclaimsellbill]),
          );
          CURL_Request($data_arr, 'sellbillAjaxController.php?do=makeReturnSellBillPayment',  0,  1, '', 'POST');
          $client = R::getRow('SELECT client.* FROM client join returnsellbill on returnsellbill.returnsellbillclientid = client.clientid WHERE returnsellbillid   = ? ',[$claimreturnsellbill->claimreturnsellbillid]);
          $data_arr = array(
            'itr'=> 3,
            'branchid_entry'=> 0,
            'dDateTime'=> date("Y-m-d"),
            'user_id' => $_SESSION['userid'],
            'entryComment'=> 'دفع المطلبه رقم   ' .$claimid.' للفاتوره رقم  '. $claimreturnsellbill->claimreturnsellbillid,
            'E_parent1'=> 398,
            'comment1'=> '',
            'valueFrom1'=> $returnsellbilldiscount,
            'E_parent2'=> 77,
            'comment2'=> '',
            'valueFrom2'=> $returnsellbilltax,
            'E_parent3'=> $client['treeId'],
            'comment3'=> '',
            'valueTo3'=> $returnsellbilltaxdiscount,
            'totalValueFrom_hidden' => $returnsellbilltaxdiscount,
            'totalValueTo_hidden' => $returnsellbilltaxdiscount,
          );
          $dailyEntry = CURL_Request($data_arr, 'dailyentryajax.php?do=add',  0,  1, '', 'POST') ;
          $dailyEntry = explode(',', $dailyEntry);

          $claimreturnsellbill->returnsellbilldiscount = $returnsellbilldiscount;
          $claimreturnsellbill->returnsellbilltax = $returnsellbilltax;
          $claimreturnsellbill->returnsellbilltaxdiscount = $returnsellbilltaxdiscount;
          $claimreturnsellbill->dailyentryid = $dailyEntry[1];
          R::store($claimreturnsellbill);

      }

      R::exec("UPDATE `claims` SET `debttrue`= 1 WHERE id = $claimid");

      echo json_encode(array('status' => 1,'id' => $claimdebtid));
  } catch (Exception $e) {
      echo json_encode(array('status' => 0,'id' => 0));
  }
}
function showajax()
{
  $columns = array('claimdebts.id', 'claimdebts.id', 'claimdebts.claimid', 'paymethod', 'saveidorbankid', 'claimdebts.claim_value', 'transaction_number','direct_debit','direct_tax','full_total', 'addtoday', 'adduserid', 'claimdebts.id', 'claimdebts.id');
  $start_date = $_POST['start_date'];
  $end_date   = $_POST['end_date'];
  $del        = $_POST['del'];
  $data1      = $_POST['data1'];
  $data2      = $_POST['data2'];
  $data3      = $_POST['data3'];

  $searchQuery = " ";
  $joinQuery = " ";
  if ($data1 != '') {
    $searchQuery .=  " and claimdebts.claimid = " . $data1 . " ";
    $joinQuery .=  "   ";
  }
  if ($del == '') {
    $searchQuery .= " and claimdebts.del < 2 ";
  }

  if ($data3 != '') {
    $searchQuery .= " and claimdebts.branchid = " . $data3 . " ";
  }

  if ($start_date != '') {
    $searchQuery .= 'and  DATE(claimdebts.addtoday)  >= "' . $start_date . '"';
  }
  if ($end_date != '') {
    $searchQuery .= 'and DATE(claimdebts.addtoday) <= "' . $end_date . '" ';
  }

  // if ($_SESSION['charityids'] && !$data1)
  //   $searchQuery .= ' and claims.id in(' . $_SESSION['charityids'] . ')';


  if (isset($_POST['search']['value']) && $_POST['search']['value'] != "") {
    $searchQuery .= 'and ( claimdebts.id LIKE " % ' . $_POST["search"]["value"] . ' %" 
        OR claimdebts.transaction_number LIKE "%' . $_POST["search"]["value"] . '%"
        )';
  }

  if (isset($_POST["order"])) {
    $searchQuery .= 'ORDER BY ' . $columns[$_POST['order']['0']['column']] . ' ' . $_POST['order']['0']['dir'] . '  ';
  } else {
    $searchQuery .= "ORDER BY  claimdebts.id DESC ";
  }

  $totals = R::count('claimdebts', 'LEFT JOIN user ON claimdebts.adduserid = user.userid 
    LEFT JOIN save ON claimdebts.saveid = save.saveid  
    LEFT JOIN bank ON claimdebts.bankid = bank.bankid 
         '.  $joinQuery .' WHERE 1 ' . $searchQuery . ' ');

  if (isset($_POST['start']) && $_POST['length'] != '-1') {
    $searchQuery .= "LIMIT " . intval($_POST['start']) . ", " .
      intval($_POST['length']);
  }
 

  $rResult = R::getAll(' SELECT claimdebts.*, employeename, savename,  bankname FROM `claimdebts` 
    LEFT JOIN user ON claimdebts.adduserid = user.userid 
    LEFT JOIN save ON claimdebts.saveid = save.saveid  
    LEFT JOIN bank ON claimdebts.bankid = bank.bankid 
          '.  $joinQuery .' WHERE 1 ' . $searchQuery . ' ');
  $apps = count($rResult);

  $output = array(
    "draw" => intval($_POST["draw"]),
    "recordsTotal" => intval($apps),
    "recordsFiltered" => $totals,
    "data" => array()
  );

  foreach ($rResult as $row) {

    $date = date('Y-m-d');
    $sub_array = array();
    $sub_array[] = $row["id"];
    $sub_array[] = $row["claimid"];
    if ($row["paymethod"] == 0) {
    $sub_array[] = 'خزنة';
    $sub_array[] = $row["savename"];
    }else{
    $sub_array[] = 'بنك';
    $sub_array[] = $row["bankname"];
    }
   
    $sub_array[] = $row["claim_value"];
    $sub_array[] = $row["transaction_number"];
    $sub_array[] = $row["direct_debit"];
    $sub_array[] = $row["direct_tax"];
    $sub_array[] = $row["full_total"];
    $sub_array[] = $row["addtoday"];
    $sub_array[] = $row["employeename"];
    if ($row["del"] > 1) {
      $sub_array[] = '<a href="claimdebtController.php?do=detail&id='. $row["id"] .'" type="button" class="btn btn-default btn-lm ">تفاصيل</a>';
      $sub_array[] = '';
      $sub_array[] = 'محذوف ';
    }else{
      $sub_array[] = '<a href="claimdebtController.php?do=detail&id='. $row["id"] .'" type="button" class="btn btn-default btn-lm ">تفاصيل</a>';
      $sub_array[] = '<a href="claimdebtController.php?do=edit&id=' . $row["id"] . '" type="button" class="btn btn-default btn-lg editicon"></a>';
      $sub_array[] = '<a href="javascript:;" data-id="' . $row["id"] . '" data-controll="claimdebtController" type="button" class="btn btn-default btn-lg deleteicon removecontroller"  ></a>';
    } 

    $output['data'][] = $sub_array;
  }

  echo json_encode($output, JSON_UNESCAPED_SLASHES);
}


function removecontroller($fid = 0)
{


  $today = date("Y-m-d H:i:s");
  $date = date('Y-m-d');
  $userid = $_SESSION['userid'];
   $id = filter_input(INPUT_POST, 'id');
  if ($fid > 0) {
    $id = $fid;
  }
 
  $tables = R::load('claimdebts', $id);
  $tables->del = 2;
  $tables->deltoday = $today;
  $tables->deluserid = $userid;
  try {
    R::store($tables);

   $claimid = $tables->claimid;
    $claim = R::load('claims', $claimid);
    $claim->debttrue = 0;
    R::store($claim);

    if ($claim->paymethod == 0) {
      $paytype = 'save';
    }else{
      $paytype = 'bank';
    }


  


    $claimsellbills = R::findAll('claimsellbills','claimid = ? and claimsellbills.del < 2 ',[$claimid]);
    foreach($claimsellbills as $claimsellbill){
          $clientdebtchange = R::getCell('SELECT clientdebtchangeid FROM clientdebtchange WHERE `billid` = ? and tablename = ?',[$claimsellbill->claimsellbillid, 'clientPayedDeptSellBillsController.php']);
          $data_arr = array(
            'clientdebtchangeId' => $clientdebtchange,
            'curlpost' => 1,
            'comment' => '',
            'paytype'=>$paytype,
            'userId' => $_SESSION['userid'],
          );
          CURL_Request($data_arr, 'sellbillAjaxController.php?do=delMakeSellBillPayment',  0,  1, '', 'POST');
          reverseEntryWithItsID($claimsellbill->dailyentryid);

          // $client = R::getRow('SELECT client.* FROM client join sellbill on sellbill.sellbillclientid = client.clientid
          //   WHERE sellbillid = ? ',[$claimsellbill->claimsellbillid]);
          // $data_arr = array(
          //   'itr'=> 3,
          //   'branchid_entry'=> 0,
          //   'dDateTime'=> date("Y-m-d"),
          //   'user_id' => $_SESSION['userid'],
          //   'entryComment'=> ' حذف دفع المطلبه رقم    ' . $claimid . ' للفاتوره رقم  ' . $claimsellbill->claimsellbillid,
          //   'E_parent1'=> $client['treeId'],
          //   'comment1'=> '',
          //   'valueFrom1'=> $claimsellbill->sellbilltaxdiscount,
          //   'E_parent2'=> 398,
          //   'comment2'=> '',
          //   'valueTo2'=> $claimsellbill->sellbilldiscount,
          //   'E_parent3'=> 77,
          //   'comment3'=> '',
          //   'valueTo3'=> $claimsellbill->sellbilltax,
          //   'totalValueFrom_hidden' => $claimsellbill->sellbilltaxdiscount,
          //   'totalValueTo_hidden' => $claimsellbill->sellbilltaxdiscount,
          // );

          // CURL_Request($data_arr, 'dailyentryajax.php?do=add',  0,  1, '', 'POST') ;




    }


    $claimreturnsellbills = R::findAll('claimreturnsellbills','claimid = ? and claimreturnsellbills.del < 2 ',[$today->claimid]);
    foreach($claimreturnsellbills as $claimreturnsellbill){
          $clientdebtchange = R::getCell('SELECT clientdebtchangeid FROM clientdebtchange WHERE `billid` = ? and tablename = ?',[$claimreturnsellbill->claimreturnsellbillid, 'clientPayedDeptReturnSellBillsController.php']);
          $data_arr = array(
            'clientdebtchangeId' => $clientdebtchange,
            'curlpost' => 1,
            'comment' => '',
            'paytype'=>$paytype,
            'userId' => $_SESSION['userid'],
          );
          CURL_Request($data_arr, 'sellbillAjaxController.php?do=delmakeReturnSellBillPayment',  0,  1, '', 'POST');
          reverseEntryWithItsID($claimreturnsellbill->dailyentryid);

          // $client = R::getRow('SELECT client.* FROM client join returnsellbill on returnsellbill.returnsellbillclientid = client.clientid WHERE returnsellbillid   = ? ',[$claimreturnsellbill->claimreturnsellbillid]);
          // $data_arr = array(
          //   'itr'=> 3,
          //   'branchid_entry'=> 0,
          //   'dDateTime'=> date("Y-m-d"),
          //   'user_id' => $_SESSION['userid'],
          //   'entryComment'=> ' حذف دفع المطلبه رقم    ' . $claimid . ' للفاتوره رقم  ' . $claimsellbill->claimsellbillid,
          //   'E_parent1'=> $client['treeId'],
          //   'comment1'=> '',
          //   'valueFrom1'=> $claimreturnsellbill->returnsellbilltaxdiscount,
          //   'E_parent2'=> 398,
          //   'comment2'=> '',
          //   'valueTo2'=> $claimreturnsellbill->returnsellbilldiscount,
          //   'E_parent3'=> 77,
          //   'comment3'=> '',
          //   'valueTo3'=> $claimreturnsellbill->returnsellbilltax,
          //   'totalValueFrom_hidden' => $claimreturnsellbill->returnsellbilltaxdiscount,
          //   'totalValueTo_hidden' => $claimreturnsellbill->returnsellbilltaxdiscount,
          // );
          // CURL_Request($data_arr, 'dailyentryajax.php?do=add',  0,  1, '', 'POST') ;

    }
    // R::exec("UPDATE `claimstypeclients` SET `del`= 2 , `deluserid`= $userid , `deltoday`= '$today' WHERE claimid = $id");
    // R::exec("UPDATE `claimsclientbills` SET `del`= 2 , `deluserid`= $userid , `deltoday`= '$today' WHERE claimid = $id");
    // R::exec("UPDATE `claimsellbills` SET `del`= 2 WHERE claimid = $id");
    // R::exec("UPDATE `claimreturnsellbills` SET `del`= 2 WHERE claimid = $id");

    echo 1;
  } catch (Exception $e) {
    echo 0;
  }
}





//           $id_pay = array();
//           $arrayclaimsellbill = array();
//             $arrayclaimsellbill['bill_id'] = $claimsellbill->claimsellbillid;
//             $arrayclaimsellbill['payed'] = $claimsellbill->claimsellbillfinalbill - $sellbilldiscount - $sellbilltax;
//             $arrayclaimsellbill['paytype_txt'] = 'دفع المطلبه رقم   ' . $claimid . ' للفاتوره رقم  ' . $claimsellbill->claimsellbillid;
//             $arrayclaimsellbill['paytype'] = $paymethod;
//             $arrayclaimsellbill['saveId'] = $saveid;
//             $arrayclaimsellbill['bankAccountId'] = $bankaccountid;
//           // );
//  array_push($id_pay, $arrayclaimsellbill);

//           $data_arr = array(
//             'erpDB' => $_SESSION['dbname'] ,
//             'curlpost'=>1,
//             'userId' => $_SESSION['userid'],
//             'id_pay' =>  json_encode([$arrayclaimsellbill]),
//           );

// // $post = [
// //                         'erpDB' => $_SESSION['dbname'] ,
// //                         'id_pay' => json_encode($id_pay),
// //                         'userId' =>  $_SESSION['userid'],
// //                         'userId_Add' => $_SESSION['userid'],
// //                     ];
//                         // $url = 'http://' . $_SERVER['HTTP_HOST'] . explode('controllers', $_SERVER['REQUEST_URI'])[0] . 'controllers/sellbillAjaxController.php?do=makeSellBillPayment';
//                         // $ch = curl_init($url);
//                         // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//                         // curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

//                         // // execute!
//                         // $response = curl_exec($ch);



//           $ddres = CURL_Request($data_arr, 'sellbillAjaxController.php?do=makeSellBillPayment',  0,  2, '', 'POST');
//           print_r($response);
//           exit();