Advertisement
Guest User

TaxesController

a guest
Jan 22nd, 2020
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.89 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use App\ChildrenPresent;
  6. use App\DatiLeave;
  7. use App\Razpiska;
  8. use App\WorkingDays;
  9. use Illuminate\Support\Facades\Auth;
  10. use Session;
  11.  
  12. class TaxesController extends Controller
  13. {
  14.  
  15.     protected static $doc_no = 9;
  16.     //static protected $secret='4IUCF';
  17.     protected static $secret = 'LLUE';
  18.     //  static protected $MIN='07';
  19.     protected static $MIN = '8773';
  20.     protected static $iban = 'BG85BGUS913900';
  21.     protected static $bic = 'BGUSBGSF';
  22.     protected static $merchant = 'Община Плевен';
  23.     protected static $pstatement = 4002;
  24.  
  25.     public function taxes()
  26.     {
  27.  
  28.         $records = '';
  29.         $searchdate = date('Ym');
  30.  
  31.         $m = 1;
  32.         $num = 0;
  33.         $str = '';
  34.  
  35.         $ccc = ChildrenPresent::
  36.             where('CHILDREN_ID', Auth::user()->CHILDREN_ID)
  37.             ->where(function ($query) {
  38.                 $query->WhereNull('PAYMENT_STATUS')
  39.                     ->orWhere('PAYMENT_STATUS', 0);
  40.  
  41.             })
  42.             ->whereNotNull('IZCHISLENA_TAX')
  43.             ->where('IZCHISLENA_TAX', '!=', '0.00')
  44.             ->where('YYYYMM', '<', $searchdate)
  45.             ->get();
  46.  
  47.         $count = count($ccc);
  48.  
  49.         $query = ChildrenPresent::
  50.             select('CHILDREN_PRESENT.*', 'NOM_GARDEN.*', 'DATI_LEAVE.*')
  51.             ->join("NOM_GARDEN", "NOM_GARDEN.GARDEN_ID", "=", "CHILDREN_PRESENT.GARDEN_ID")
  52.             ->join('DATI_LEAVE', 'DATI_LEAVE.CHILDREN_ID', '=', 'CHILDREN_PRESENT.CHILDREN_ID')
  53.             ->where('CHILDREN_PRESENT.YYYYMM', '<', $searchdate)
  54.             ->where('CHILDREN_PRESENT.CHILDREN_ID', Auth::user()->CHILDREN_ID)
  55.             ->orderBy('CHILDREN_PRESENT.YYYYMM', 'desc')
  56.             ->orderBy('DATI_LEAVE.DATE_BEG', 'desc')
  57.             ->get();
  58.  
  59.         $d = array('1' => 'Яну', '2' => 'Фев', '3' => 'Март', '4' => 'Апр', '5' => 'Май', '6' => 'Юни', '7' => 'Юли', '8' => 'Авг', '9' => 'Сеп', '10' => 'Окт', '11' => 'Ное', '12' => 'Дек');
  60.         $taxes = $query;
  61.         if (count($taxes) == 0) {
  62.             $records = '';
  63.         } else {
  64.             foreach ($query as $q) {
  65.  
  66.                 $num++;
  67. //print_r($q);
  68.  
  69.                 $get_work_days = WorkingDays::
  70.                     where('YYYY', date("Y", strtotime($q->YYYYMM . "01")))
  71.                     ->where('MM', date("m", strtotime($q->YYYYMM . "01")))
  72.                     ->where('GARDEN_ID', $q->GARDEN_ID)
  73.                     ->first();
  74.  
  75.                 $work_days = str_split($get_work_days->DAY_STATUS);
  76.  
  77.                 $presence_days = str_split($q->DAY_STATUS);
  78.  
  79.                 $c = array_count_values($presence_days);
  80.  
  81.                 $leaving = DatiLeave::
  82.                     where('CHILDREN_ID', Auth::user()->CHILDREN_ID)
  83.                     ->where('GARDEN_ID', $q->GARDEN_ID)
  84.                     ->get();
  85.  
  86.                 foreach ($leaving as $leave) {
  87.                     $l = $leave;
  88.                     //$str=$str.count($leave);
  89.                 }
  90.                 $end = 1;
  91.  
  92.                 foreach ($work_days as $k => $v) {
  93.                     if ($v == 1 && $presence_days[$k] == 0 && strtotime($q->YYYYMM . $k) >= strtotime($l->DATE_BEG) && ((strtotime($q->YYYYMM . $k) < strtotime($l->DATE_END)) || $l->DATE_END == '' || $l->DATE_END == 'NULL')) {
  94.  
  95.                         $end = 0;
  96.  
  97.                     }
  98.                 }
  99.                 if ((count(array_filter($presence_days)) != 1 && count(array_filter($presence_days)) != 0) && ($q->IZCHISLENA_TAX != '0.00' || $q->IZCHISLENA_TAX != 'NULL' || $q->IZCHISLENA_TAX != '')) {
  100.                     $records[$num]['garden'] = $q->NAME;
  101.                     $records[$num]['month'] = date("m.Y", strtotime($q->YYYYMM . "01"));
  102.                     //$str=$str. "<tr><td>".$q->NAME."</td><td>".date("m.Y", strtotime($q->YYYYMM."01"))."</td>";
  103.                     $leave = $q->BR_DNI_BOL + $q->BR_DNI_KAR + $q->BR_DNI_DOM + $q->BR_SL_OTS + $q->BR_OTPUSK + $q->BR_DNI_NEIZ;
  104.                     $records[$num]['presence'] = $q->BR_DNI_PRI;
  105.                     //$str=$str.  "<td>".$q->BR_DNI_PRI."</td>";
  106.                     $payment = '';
  107.                     if (is_null($q->PAYMENT_DATE)) {
  108. //                    && ($q->PAYMENT_DATE=="" || $q->PAYMENT_DATE=="NULL")){
  109.  
  110.                         $payment = '';
  111.                     } else //if($q->PAYMENT_DATE!='NULL' && $q->PAYMENT_DATE!='')
  112.                     {
  113.                         //print_r($q);
  114.                         $payment_way = Razpiska::where('RAZPISKA_ID', $q->RAZPISKA_ID)->first();
  115.                         /* foreach($get_payment_way as $payment_way){
  116.                         if($payment_way->PAYMENT_WAY==3)
  117.                         $payment=date("d.m.Yг. H:i:s", strtotime($q->PAYMENT_DATE));
  118.                         else
  119.                         $payment=date("d.m.Yг.", strtotime($q->PAYMENT_DATE));
  120.                         }
  121.                          * */
  122.  
  123.                         if (isset($payment_way->PAYMENT_WAY) && $payment_way->PAYMENT_WAY == 3) {
  124.                             $payment = date("d.m.Yг. H:i:s", strtotime($q->PAYMENT_DATE));
  125.                         } else {
  126.                             $payment = date("d.m.Yг.", strtotime($q->PAYMENT_DATE));
  127.                         }
  128.  
  129.                         //   $payment='off';
  130.                     }
  131.                     $records[$num]['leaving'] = $leave . $str;
  132.                     $records[$num]['izchislena_tax'] = number_format($q->IZCHISLENA_TAX, 2);
  133.                     $records[$num]['nachislena_tax'] = $q->NACH_TAX;
  134.                     $records[$num]['payment_date'] = $payment;
  135.  
  136.                     if ($q->IZCHISLENA_TAX != 'NULL' && $q->IZCHISLENA_TAX != '') {
  137.                         if ($end == 0) {
  138.  
  139.                             if (count(array_filter($presence_days)) == 1) {
  140.  
  141.                                 $records[$num]['payment'] = "<span class=text-danger>Приключило посещение</span>";
  142.                             } else if ($q->NACH_TAX == 'NULL' || $q->NACH_TAX == '') {
  143.  
  144.                                 $records[$num]['payment'] = "<span class=text-danger>Несвършил месец</span>";
  145.                                 $count--;
  146.                             } else //$str=$str.  "<td><span class=text-succes>Платена</span></td></tr>";
  147.                             {
  148.                                 $records[$num]['payment'] = "<span class=text-info><i class=\"material-icons\">done</i> Платена</span>";
  149.                             }
  150.  
  151.                         } else {
  152.                             $c = array_count_values($presence_days);
  153.                             if (count(array_filter($presence_days)) == 1) {
  154.                                 $records[$num]['payment'] = "<span class=text-info>Приключило посещение</span>";
  155.                             } else if ((($q->PAYMENT_STATUS == 0 || $q->PAYMENT_STATUS == 'NULL') && $q->NACH_TAX == '0.00') || ($q->NACH_TAX == '0.00' && $q->IZCHISLENA_TAX == '0.00')) {
  156.                                 $records[$num]['payment'] = "<span class=text-info>Платена</span>";
  157.                             } else if ($q->PAYMENT_STATUS == 0 || $q->PAYMENT_STATUS == 'NULL') {
  158.                                 if ($q->IZCHISLENA_TAX != '0.00') {
  159.                                     if ($m == $count) {
  160.                                         $records[$num]['payment'] = "<span class=text-succes></span>";
  161.  
  162.                                         $content = file_get_contents(Session::get('link') . "EPAY_ZAYVKA?CHILDREN_PRESENT_ID=" . $q->CHILDREN_PRESENT_ID);
  163.  
  164.                                         preg_match('#<p id="names">(.*)</p>#', $content, $match);
  165.                                         $string = str_replace(";", "&", $match[1]);
  166.                                         parse_str($string);
  167.  
  168.                                         if ($ERROR == '') {
  169.  
  170.                                             $records[$num]['payment'] = '<form action="checkout" method=post id=epay  >
  171.    <input type="hidden" name="_token" value="' . csrf_token() . '" id="_token"/>
  172.    <input type=hidden name=TAX value="' . $IZCHISLENA_TAX . '">
  173.    <input type=hidden name=MIN value="' . $q->MIN . '">
  174.    <input type=hidden name=INVOICE value="' . $INVOICE . '">
  175.    <input type=hidden name=LIHVA value="' . $LIHVA . '">
  176.    <input type=hidden name=month value="' . date("m.Y", strtotime($q->YYYYMM . "01")) . '">
  177.  
  178.    <input class=" btn btn-primary epay-button " type=submit name=BUTTON:EPAYNOW  value="ePay.bg">
  179.    </form>';
  180.  
  181.                                         } else {
  182.                                             $records[$num]['payment'] = "<span class=text-danger>" . iconv('windows-1251', 'utf-8', $ERROR) . "</span>";
  183.                                         }
  184.  
  185.                                     } else {
  186.                                         $records[$num]['payment'] = "<span class=text-succes></span>";
  187.                                         $m++;
  188.                                     }
  189.  
  190.                                 } else {
  191.  
  192.                                     $records[$num]['payment'] = "<span class=text-warning>Таксата е нула.</span>";
  193.                                 }
  194.  
  195.                             } else {
  196.                                 $records[$num]['payment'] = "<i class=\"material-icons\">done</i> <span class=text-success>Платена</span>";
  197.                             }
  198.  
  199.                         }
  200.                     } else if (($q->PAYMENT_STATUS == 0 || $q->PAYMENT_STATUS == 'NULL') && $q->IZCHISLENA_TAX == 'NULL') {
  201.                         $records[$num]['payment'] = "<span class=text-danger>Неизчислена такса</span>";
  202.                     }
  203.  
  204.                 } else {
  205.                     $count--;
  206.                 }
  207.  
  208.             }
  209.         }
  210.  
  211.         return view('views.taxes')->with('records', $records);
  212.     }
  213.  
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement