<?php

require_once ("jdf.php");
    header("content-type: application/json;");
    header("character_set: utf8;");
	$sitename="http://amatiscomputer.ir/";
	$hostname="localhost";
    $username="amatisco_pakhsh";
	$password="amatis@maryam";
    $database="amatisco_pakhshkhani";

    $suer="09104717855";
    $spass="43104645481991";
    $ptr="gu6j3cle6x";
    $vislim = 17;


    $tbl_factor="FACTURE";
    $tbl_factor_art="FACTART";
    $tbl_admin="tbl_admin";
    $tbl_company="tbl_company";
    $tbl_customer="tbl_customer";
    $tbl_orderdtl="tbl_orderdtl";
    $tbl_orders="tbl_orders";
    $tbl_products="tbl_products";
    $tbl_routdtl="tbl_routdtl";
    $tbl_routs="tbl_routs";
    $tbl_sessions="tbl_sessions";
    $tbl_visitors="tbl_visitors";
    $tbl_visitor_locations="tbl_visitor_locations";
    $tbl_visitor_routs="tbl_visitor_routs";
    $tbl_visits="tbl_visits";
    $tbl_visit_detail="tbl_visit_detail";
    $tbl_category="tbl_category";
    $tbl_category1="tbl_category1";
    $tbl_visitcomment="tbl_visitcomment";
    $tbl_pays="tbl_pays";

    function addNumbers(String $date, int $day,$ttt) {
       
        $y = (int) substr($date,0,4);
        $m = (int) substr($date,5,2);
        $d = (int) substr($date,8,2);
       
        $d += $day;
        if($m<7)
        {
       if($d>31){
       $d = $d-31;
       $m++;
       if($m>12){
           $m=1;
           $y++;
       }
       }
        }
        else{
           if($d>30){
               $d = $d-30;
               $m++;
               }
               if($m>12){
                   $m=1;
                   $y++;
               }
        }
        if($d<10)
        $d = "0" . $d;
        if($m<10)
        $m = "0" . $m;
        $targetdate =$y."/".$m."/".$d;
        if($ttt){
            return $targetdate;
        }
        else{
        if ($targetdate >= jdate('Y/m/d'))
        return true;
        else
        return false;
        }
           }

           function remMounths(String $date, int $day) {
            $y = (int) substr($date,0,4);
            $m = (int) substr($date,5,2);
            $d = (int) substr($date,8,2);
            $m -= $day;
            if($m<1)
            {
            $m=12;
            $y--;
            }
            if($d<10)
            $d = "0" . $d;
            if($m<10)
            $m = "0" . $m;
            $targetdate =$y."/".$m."/".$d;
            
            return $targetdate;
            }

            function getTimer(String $date, string $time) {

                $mydate = jdate('Y/m/d');
                $mytime =jdate('H:i');
                $days=0;
               
                $y = (int) substr($date,0,4);
                $m = (int) substr($date,5,2);
                $d = (int) substr($date,8,2);

                $h = (int) substr($time,0,2);
                $t = (int) substr($time,3,2);

                $myy = (int) substr($mydate,0,4);
                $mym = (int) substr($mydate,5,2);
                $myd = (int) substr($mydate,8,2);

                $myh = (int) substr($mytime,0,2);
                $myt = (int) substr($mytime,3,2);

                $yy = $y-$myy;
                $mm = $m-$mym;
                $dd = $d-$myd;

                $hh = $h-$myh;
                $tt = $t-$myt;

                if($mydate!=$date){
          
                $m1t = 0;

                if ($m < 7)
                    $mt = 0;
                else $mt = 1;
                

                if ($mm < 7)
                    $m1t = 0;
                else $m1t = 1;

                $yy = $y-$myy;
                $mm = $m-$mym;
                $dd = $d-$myd;

                if ($mt == 1 && $m1t == 1)
                    $days = ($yy * 365) + ($mm * 30) + ($dd);
                else if (($mt == 0 && $m1t == 1) || ($mt == 1 && $m1t == 0))
                    $days = ($yy * 365) + ($mm * 31) + ($dd);
                else if ($mt == 0 && $m1t == 0)
                    $days = ($yy * 365) + ($mm * 31) + ($dd);

            }

                if($tt<0)
                    $hh--;

                $tt = (60-$myt)+$t;

                if($tt>=60)
                    $tt=$tt-60;

                $hh += $days * 24;
                $timer = $hh * 60 + $tt;

                return $timer;
                }

?>