function isHappy($n)
{
    $soFar = array();
    while ($n != 1 && !in_array($n, $soFar)) {
        $soFar[] = $n;
        $n = nextNumber($n);
    }
    return $n == 1;
}
function insertledgerlogheader($lldDate, $lldDescription)
{
    $lldBatchID = nextNumber('sysnumber');
    $ledgerlogID = uniqid('1');
    $sql = "INSERT INTO ledgerlog(ledgerlogID, lldBatchID, lldDate,lldDescription,lldPosted) VALUES ";
    $sql .= "('{$ledgerlogID}','{$lldBatchID}','{$lldDate}','{$lldDescription}',1)";
    RunQuery($sql);
    return $ledgerlogID;
}
Beispiel #3
0
class Person
{
    public $firstName;
    public $lastName;
    function __construct($fname, $lname, $age)
    {
        $this->firstName = $fname;
        $this->lastName = $lname;
        $this->age = $age;
    }
}
$var = new Person("Ivan", "Dimitrov", 28);
$people = [new Person("Ivan", "Dimitrov", 28), new Person("Gosho", "Ivanov", 25), new Person("Petar", "Petrov", 26), new Person("Svetlin", "Nakov", 27)];
usort($people, function ($p1, $p2) {
    return $p1->age - $p2->age;
});
var_dump($var);
var_dump($people);
echo "<hr>";
function nextNumber()
{
    $counter = 0;
    return function () use(&$counter) {
        return ++$counter;
    };
}
$num = nextNumber();
echo $num();
echo $num();
echo $num();
echo "<hr>";
Beispiel #4
0
function mkTTorder($id, $evids, $trans_id)
{
    $tt = getOneTT($id, $false);
    $vendcust = $tt['tab'] == 'C' ? 'customer' : 'vendor';
    //Steuerzone ermitteln (0-3)
    $sql = "SELECT taxzone_id FROM " . $vendcust . " WHERE id = " . $tt["fid"];
    $rs = $_SESSION['db']->getOne($sql);
    $tzid = $rs["taxzone_id"];
    $TAX = getTax($tzid);
    //Artikeldaten holen
    $sql = "SELECT * FROM parts WHERE partnumber = '" . $_SESSION['ttpart'] . "'";
    $part = $_SESSION['db']->getOne($sql);
    $partid = $part["id"];
    $sellprice = $part["sellprice"];
    $unit = $part["unit"];
    //Steuersatz ermitteln
    $tax = $TAX[$part["buchungsgruppen_id"]];
    $curr = getCurr(True);
    //Events holen
    $events = getTTEvents($id, false, $evids, True);
    if (!$events) {
        return ".:nothing to do:.";
    }
    if (!$evids) {
        $evids = 'and t.id in (';
        foreach ($events as $row) {
            $tmp[] = $row['id'];
        }
        $evids .= implode(',', $tmp) . ') ';
    }
    $_SESSION['db']->begin();
    if ($trans_id < 1) {
        //Auftrag erzeugen
        $sonumber = $tt['tab'] == 'C' ? nextNumber("sonumber") : nextNumber("ponumber");
        if (!$sonumber) {
            return ".:error:.";
        }
        $sql = "INSERT INTO oe (notes,transaction_description,ordnumber," . $vendcust . "_id,taxincluded,currency_id) ";
        $sql .= "VALUES ('" . $tt["ttdescription"] . "','" . $tt["ttname"] . "',{$sonumber},'" . $tt["fid"] . "','f',";
        $sql .= "coalesce((SELECT currency_id FROM " . $vendcust . " WHERE id = " . $tt['fid'] . "),{$curr}))";
        $rc = $_SESSION['db']->query($sql, "newOE");
        if (!$rc) {
            $sql = "DELETE FROM oe WHERE ordnumber = '{$sonumber}'";
            $rc = $_SESSION['db']->query($sql, "delOE");
            return ".:error:. 0";
        }
        $sql = "SELECT id FROM oe WHERE  ordnumber = '{$sonumber}'";
        $rs = $_SESSION['db']->getOne($sql);
        $trans_id = $rs["id"];
        if ($trans_id <= 0) {
            $sql = "DELETE FROM oe WHERE ordnumber = '{$sonumber}'";
            $rc = $_SESSION['db']->query($sql, "delOE");
            return ".:error:. 0";
        }
        $netamount = 0;
    } else {
        $sql = "SELECT * from oe WHERE id = " . $trans_id;
        $rc = $_SESSION['db']->getOne($sql, '');
        if (!$rc) {
            return ".:error:. 00";
        }
        $netamount = $rc['netamount'];
    }
    //$sql_i = 'INSERT INTO orderitems (trans_id, parts_id, description, qty, sellprice, unit, ship, discount,serialnumber,reqdate) values (';
    $fields = array('trans_id', 'parts_id', 'description', 'qty', 'sellprice', 'unit', 'ship', 'discount', 'serialnumber', 'reqdate');
    foreach ($events as $row) {
        if ($row["ttstop"] == "") {
            $_SESSION['db']->rollback();
            return ".:close event:.";
        }
        $t1 = strtotime($row["ttstart"]);
        $t2 = strtotime($row["ttstop"]);
        //Minuten
        $diff = floor(($t2 - $t1) / 60);
        //Abrechnungseinheiten
        $time = floor($diff / $_SESSION['tttime']);
        //Ist der Rest über der Tolleranz
        if ($diff - $_SESSION['tttime'] * $time > $_SESSION['ttround']) {
            $time++;
        }
        $price = $time * $sellprice;
        //Orderitemseintrag
        $rqdate = substr($row['ttstop'], 0, 10);
        $values = array($trans_id, $partid, $row["ttevent"], $time, $sellprice, $unit, 0, 0, $diff, $rqdate);
        //$sql = $sql_i."$trans_id,$partid,'".$row["ttevent"]."',$time,$sellprice,'$unit',0,0,'$diff','".substr($row['ttstop'],0,10)."')";
        //$rc = $_SESSION['db']->query($sql);
        $rc = $_SESSION['db']->insert('orderitems', $fields, $values);
        if (!$rc) {
            $_SESSION['db']->rollback();
            return ".:error:. 1";
        }
        $netamount += $price;
        $amount += $price * $tax;
        $parts = getTTparts($row["id"]);
        if ($parts) {
            foreach ($parts as $part) {
                $values = array($trans_id, $part['parts_id'], $part['parts_txt'], $part['qty'], $part['sellprice'], $part['unit'], 0, 0, Null, $rqdate);
                $rc = $_SESSION['db']->insert('orderitems', $fields, $values);
                if (!$rc) {
                    $_SESSION['db']->rollback();
                    return ".:error:. 2";
                }
                $netamount += $part['qty'] * $part['sellprice'];
                $amount += $part['qty'] * $part['sellprice'] * $TAX[$part['buchungsgruppen_id']];
            }
        }
    }
    //OE-Eintrag updaten
    $nun = date('Y-m-d');
    //$amount = $netamount + $mwst;
    $fields = array('transdate', 'amount', 'netamount', 'reqdate', 'notes', 'employee_id');
    $values = array($nun, $amount, $netamount, $nun, $tt["ttdescription"], $_SESSION["loginCRM"]);
    $rc = $_SESSION['db']->update('oe', $fields, $values, 'id = ' . $trans_id);
    if (!$rc) {
        $_SESSION['db']->rollback();
        return ".:error:. 2";
    } else {
        //Events als Abgerechnet markieren.
        $sql = "UPDATE tt_event t set cleared = {$trans_id} where t.ttid = {$id} {$evids}";
        $rc = $_SESSION['db']->query($sql);
        $_SESSION['db']->commit();
        return ".:ok:.";
    }
}