<?php

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/

$app = new Illuminate\Foundation\Application(
    $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);

/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/

$app->singleton(
    Illuminate\Contracts\Http\Kernel::class,
    App\Http\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/
    function IND_money_format($number){        
      $decimal = (string)($number - floor($number));
      $money = floor($number);
      $length = strlen($money);
      $delimiter = '';
      $money = strrev($money);

      for($i=0;$i<$length;$i++){
          if(( $i==3 || ($i>3 && ($i-1)%2==0) )&& $i!=$length){
              $delimiter .=',';
          }
          $delimiter .=$money[$i];
      }

      $result = strrev($delimiter);
      $decimal = preg_replace("/0\./i", ".", $decimal);
      $decimal = substr($decimal, 0, 3);

      if( $decimal != '0'){
          $result = $result.$decimal;
      }

      return $result;
  }

  function getIndianCurrency(float $number)
  {
      $decimal = round($number - ($no = floor($number)), 2) * 100;
      $hundred = null;
      $digits_length = strlen($no);
      $i = 0;
      $str = array();
      $words = array(0 => '', 1 => 'one', 2 => 'two',
          3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six',
          7 => 'seven', 8 => 'eight', 9 => 'nine',
          10 => 'ten', 11 => 'eleven', 12 => 'twelve',
          13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen',
          16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen',
          19 => 'nineteen', 20 => 'twenty', 30 => 'thirty',
          40 => 'forty', 50 => 'fifty', 60 => 'sixty',
          70 => 'seventy', 80 => 'eighty', 90 => 'ninety');
      $digits = array('', 'hundred','thousand','lakh', 'crore');
      while( $i < $digits_length ) {
          $divider = ($i == 2) ? 10 : 100;
          $number = floor($no % $divider);
          $no = floor($no / $divider);
          $i += $divider == 10 ? 1 : 2;
          if ($number) {
              $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
              $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
              $str [] = ($number < 21) ? $words[$number].' '. $digits[$counter]. $plural.' '.$hundred:$words[floor($number / 10) * 10].' '.$words[$number % 10]. ' '.$digits[$counter].$plural.' '.$hundred;
          } else $str[] = null;
      }
      $Rupees = implode('', array_reverse($str));
      $paise = ($decimal) ? "." . ($words[$decimal / 10] . " " . $words[$decimal % 10]) . ' Paise' : '';
      return ($Rupees ? $Rupees . 'Rupees ' : '') . $paise;
  }

 function getPaymentStatus($status){
  $paymentStatus = "Pending";
  if($status == 0){
    $paymentStatus = "Pending";
  }elseif($status == 1){
    $paymentStatus = "Approved";
  }elseif($status == 2){
    $paymentStatus = "Cancelled";
  }elseif($status == 3){
    $paymentStatus = "Revoked";
  }
  return $paymentStatus;
 }

 function getPaymentStatusClass($status){
  $paymentStatusClass = "info";
  if($status == 0){
    $paymentStatusClass = "info";
  }elseif($status == 1){
    $paymentStatusClass = "success";
  }elseif($status == 2){
    $paymentStatusClass = "danger";
  }elseif($status == 3){
    $paymentStatusClass = "danger";
  }
  return $paymentStatusClass;
 }

return $app;
