コード例 #1
0
function allocate_entries($_POST)
{
    extract($_POST);
    if (isset($alloc) and is_array($alloc) and (isset($entries) and is_array($entries))) {
        #all set
    } else {
        return show_allocate_entries($_POST, "<li class='err'>Please Select At Least 1 Receipt And Payment.</li>");
    }
    #update the allocation
    pglib_transaction("BEGIN") or errDie("Unable to start transaction.");
    db_connect();
    #remove each of the selected entries ...
    foreach ($entries as $each) {
        $upd_sql = "UPDATE stmnt SET allocation = '' WHERE id = '{$each}'";
        $run_upd = db_exec($upd_sql) or errDie("Unable to update customer statement information.");
    }
    #check if we should remove the receipt itself
    foreach ($alloc as $each) {
        $check_sql = "SELECT * FROM stmnt WHERE allocation = '{$each}'";
        $run_check = db_exec($check_sql) or errDie("Unable to check customer information.");
        if (pg_numrows($run_check) < 1) {
            #this receipt has no invoices ... remove it from allocation listing ...
            $upd_sql2 = "UPDATE stmnt SET allocation = '' WHERE id = '{$each}'";
            $run_upd2 = db_exec($upd_sql2) or errDie("Unable to update customer allocation information.");
        }
    }
    pglib_transaction("COMMIT") or errDie("Unable to complete transaction.");
    return show_allocate_entries($_POST, "<li class='err'>Allocation Complete.</li>");
}
コード例 #2
0
function reallocate($_POST)
{
    extract($_POST);
    db_connect();
    $get_entries = "SELECT * FROM stmnt WHERE id = '{$remid}' LIMIT 1";
    $run_entries = db_exec($get_entries) or errDie("Unable to get customer information.");
    if (pg_numrows($run_entries) < 1) {
        return "Invalid Use Of Module.";
    }
    $rarr = pg_fetch_array($run_entries);
    $linkedarr = explode("|", $rarr['allocation_linked']);
    $empty1 = array_shift($linkedarr);
    $amountsarr = explode("|", $rarr['allocation_amounts']);
    $empty2 = array_shift($amountsarr);
    $get_entries = "SELECT * FROM stmnt WHERE id = '{$fromid}' LIMIT 1";
    $run_entries = db_exec($get_entries) or errDie("Unable to get customer information.");
    if (pg_numrows($run_entries) < 1) {
        return "Invalid Use Of Module.";
    }
    $farr = pg_fetch_array($run_entries);
    $flinkedarr = explode("|", $farr['allocation_linked']);
    $empty1 = array_shift($flinkedarr);
    $famountsarr = explode("|", $farr['allocation_amounts']);
    $empty2 = array_shift($famountsarr);
    $newrembalance = 0;
    $newremlinked = "";
    $newremamounts = "";
    foreach ($linkedarr as $key => $each) {
        if ($each != $fromid) {
            $newremlinked .= "|{$each}";
            if (strlen($amountsarr[$key]) > 0) {
                $newremamounts .= "|{$amountsarr[$key]}";
            }
        } else {
            $newrembalance += $amountsarr[$key];
        }
    }
    $newfrombalance = 0;
    $newfromlinked = "";
    $newfromamounts = "";
    foreach ($flinkedarr as $key => $each) {
        if ($each != $remid) {
            $newfromlinked .= "|{$each}";
            if (strlen($famountsarr[$key]) > 0) {
                $newfromamounts .= "|{$famountsarr[$key]}";
            }
        } else {
            $newfrombalance += $famountsarr[$key];
        }
    }
    $upd_sql1 = "\n\t\tUPDATE stmnt \n\t\tSET allocation_linked = '{$newremlinked}', allocation_amounts = '{$newremamounts}', \n\t\t\tallocation_balance = allocation_balance + '{$newrembalance}' \n\t\tWHERE id = '{$remid}'";
    $run_upd1 = db_exec($upd_sql1) or errDie("Unable to update entry information.");
    $upd_sql2 = "\n\t\tUPDATE stmnt \n\t\tSET allocation_linked = '{$newfromlinked}', allocation_amounts = '{$newfromamounts}', \n\t\t\tallocation_balance = allocation_balance + '{$newfrombalance}' \n\t\tWHERE id = '{$fromid}'";
    $run_upd2 = db_exec($upd_sql2) or errDie("Unable to update entry information.");
    $sendarray = array("from_day" => $from_day, "from_month" => $from_month, "from_year" => $from_year, "to_day" => $to_day, "to_month" => $to_month, "to_year" => $to_year, "customer" => $customer);
    return show_allocate_entries($sendarray);
}
コード例 #3
0
function reallocate($_GET)
{
    $allocate = $_GET["reallocate"];
    $from_date = $_GET["from_date"];
    $to_date = $_GET["to_date"];
    $from_date_arr = explode("-", $from_date);
    $to_date_arr = explode("-", $to_date);
    $array = array();
    $array["from_year"] = $from_date_arr[0];
    $array["from_month"] = $from_date_arr[1];
    $array["from_day"] = $from_date_arr[2];
    $array["to_year"] = $to_date_arr[0];
    $array["to_month"] = $to_date_arr[1];
    $array["to_day"] = $to_date_arr[2];
    db_connect();
    $get_entries = "SELECT id, cusnum FROM stmnt WHERE allocation = '{$allocate}'";
    $run_entries = db_exec($get_entries) or errDie("Unable to get allocation information.");
    if (pg_numrows($run_entries) > 0) {
        $allocation = array();
        $allocation[] = $allocate;
        while ($aarr = pg_fetch_array($run_entries)) {
            $array["customer"] = $aarr["cusnum"];
            $allocation[] = $aarr['id'];
        }
        $array["allocation"] = $allocation;
    }
    $get_switch = "SELECT amount FROM stmnt WHERE id = '{$allocate}' LIMIT 1";
    $run_switch = db_exec($get_switch) or errDie("Unable to get allocation method information.");
    if (pg_numrows($run_switch) > 0) {
        $amt_tmp = pg_fetch_result($run_switch, 0, 0);
        $amt_tmp += 0;
        if ($amt_tmp <= 0) {
            $array["switch"] = "reverse";
        } else {
            $array["switch"] = "normal";
        }
    } else {
        $array["switch"] = "normal";
    }
    $upd_sql = "UPDATE stmnt SET allocation = '' WHERE id = '{$allocate}'";
    $run_upd = db_exec($upd_sql) or errDie("Unable to update customer statement information.");
    $upd_sql2 = "UPDATE stmnt SET allocation = '' WHERE allocation = '{$allocate}'";
    $run_upd2 = db_exec($upd_sql2) or errDie("Unable to update customer allocation information.");
    return show_allocate_entries($array);
}