コード例 #1
0
ファイル: ctrlIndex.php プロジェクト: toppestkek/Test
 function index()
 {
     if (!empty($_POST)) {
         $check = new Check();
         if (!empty($_FILES["img"]["name"])) {
             $target_dir = "uploads/";
             $target_file = $target_dir . basename($_FILES["img"]["name"]);
             $filename = $check->checkInput($_FILES['img']['name']);
             $filesize = filesize($target_file);
             move_uploaded_file($_FILES["img"]["tmp_name"], $target_file);
         } else {
             $filename = '';
             $filesize = '';
         }
         //Получаем данные методом пост
         $name = $check->checkInput($_POST['name']);
         $surname = $check->checkInput($_POST['surname']);
         $email = $check->checkInput($_POST['email']);
         $login = $check->checkInput($_POST['login']);
         $pass = $check->checkInput($_POST['pass']);
         $confirmpass = $check->checkInput($_POST['confirmpass']);
         $age = $check->checkInput($_POST['age']);
         //Создаем массив для валидации данных
         $validateArr = array('name' => $name, 'surname' => $surname, 'email' => $email, 'login' => $login, 'password' => $pass, 'confirmpass' => $confirmpass, 'age' => $age, 'filename' => $filename, 'filesize' => $filesize);
         $pdo = new Db();
         //класс с конфигурацией базы данных
         $db = $pdo->get();
         $validate = new Validate($db);
         $errors = $validate->getErrors($validateArr);
         //Выявляем ошибки через валидатор
         if (empty($errors)) {
             try {
                 //Сохраняем пользователя посредством паттерна Data Mapper
                 $user = new User();
                 $user->name = $name;
                 $user->surname = $surname;
                 $user->email = $email;
                 $user->login = $login;
                 $user->password = md5($pass);
                 $user->age = $age;
                 $user->filename = $filename;
                 $mapper = new Mapper($db);
                 $mapper->save($user);
                 $this->user = $mapper->select($user);
                 $this->out('profile.php');
             } catch (Exception $e) {
                 echo "Ошибка загрузки данных <br>" . $e->getMessage();
             }
         } else {
             foreach ($errors as $error) {
                 $this->error = $error . "<br>";
             }
             $this->out('register.php');
         }
     } else {
         $this->out('register.php');
     }
 }
コード例 #2
0
ファイル: login.php プロジェクト: Wicloz/UniversityWebsite
function createPage($smarty)
{
    if (Users::loggedIn()) {
        Redirect::to('?page=profile');
    }
    if (Input::exists()) {
        if (Input::get('action') === 'register') {
            $validation = new Validate();
            $validation->check($_POST, array_merge(Config::get('validation/register_info'), Config::get('validation/set_password')));
            if ($validation->passed()) {
                try {
                    Users::create(array('student_id' => Input::get('sid'), 'password' => Hash::hashPassword(Input::get('password')), 'permission_group' => 1, 'name' => Input::get('name'), 'email' => Input::get('email'), 'umail' => Input::get('sid') . '@umail.leidenuniv.nl', 'phone' => Phone::formatNumber(Input::get('phone')), 'joined' => DateFormat::sql()));
                    Users::login(Input::get('sid'), Input::get('password'));
                    Notifications::addSuccess('You have been succesfully registered!');
                    Redirect::to('?page=profile');
                } catch (Exception $e) {
                    Notifications::addError($e->getMessage());
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'login') {
            $validation = new Validate();
            $validation->check($_POST, Config::get('validation/login'));
            if ($validation->passed()) {
                $login = Users::login(Input::get('sid'), Input::get('password'), Input::getAsBool('remember'));
                if ($login) {
                    Notifications::addSuccess('You have been logged in!');
                    Redirect::to('?page=profile');
                } else {
                    Notifications::addValidationFail('Invalid student number or password.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
    }
    $smarty->assign('remember', Input::getAsBool('remember'));
    $smarty->assign('name', Input::get('name'));
    $smarty->assign('sid', Input::get('sid'));
    $smarty->assign('email', Input::get('email'));
    $smarty->assign('phone', Input::get('phone'));
    return $smarty;
}
コード例 #3
0
function checknum()
{
    extract($_REQUEST);
    require_lib("validate");
    $v = new Validate();
    $v->isOk($topacc, "num", 4, 4, "Invalid Main Part.");
    $v->isOk($accnum, "num", 3, 3, "Invalid Sub Part.");
    /* is account number valid */
    if ($v->isError()) {
        $e = $v->getErrors();
        if (count($e) == 2) {
            $err = "Invalid account number.";
        } else {
            $err = $e[0]["msg"];
        }
    } else {
        /* does account number exist */
        $qry = new dbSelect("accounts", "core", grp(m("cols", "accname"), m("where", "topacc='{$topacc}' AND accnum='{$accnum}'"), m("limit", "1")));
        $qry->run();
        if (!isset($rslt)) {
            $rslt = array();
        }
        if ($qry->num_rows($rslt) > 0) {
            $accname = $qry->fetch_result();
            $err = "Account number in use: {$accname}.";
        } else {
            if ($accnum != "000") {
                $qry->setOpt(grp(m("where", "topacc='{$topacc}'")));
                $qry->run();
                if ($qry->num_rows() <= 0) {
                    $err = "Main Account doesn't exist.";
                }
            }
        }
    }
    if (!isset($err)) {
        $err = "<strong>Account number valid.</strong>";
    } else {
        $err = "<li class='err'>{$err}</li>";
    }
    return $err;
}
コード例 #4
0
ファイル: profile.php プロジェクト: Wicloz/UniversityWebsite
function createPage($smarty)
{
    if (!Users::loggedIn()) {
        Redirect::to('?page=login');
    }
    if (Input::exists()) {
        if (Input::get('action') === 'logout') {
            if (Users::loggedIn()) {
                Users::logout();
                Notifications::addSuccess('You have been logged out!');
                Redirect::to('?page=login');
            }
        }
        if (Input::get('action') === 'update_info') {
            $validation = new Validate();
            $validation->check($_POST, Config::get('validation/user_info'));
            if ($validation->passed()) {
                $data = array('name' => Input::get('name'), 'student_id' => Input::get('sid'), 'email' => Input::get('email'), 'phone' => Phone::formatNumber(Input::get('phone')));
                if (Users::currentUser()->update($data)) {
                    Notifications::addSuccess('User information updated!');
                } else {
                    Notifications::addError('Could not update user information.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'update_pass') {
            $validation = new Validate();
            $validation->check($_POST, array_merge(Config::get('validation/set_password'), array('password_current' => array('name' => 'Current Password', 'required' => true, 'max' => 72))));
            if ($validation->passed()) {
                if (Hash::checkPassword(Input::get('password_current'), Users::currentData()->password)) {
                    if (Users::currentUser()->update(array('password' => Hash::hashPassword(Input::get('password'))))) {
                        Notifications::addSuccess('Password changed!');
                    } else {
                        Notifications::addError('Could not change password.');
                    }
                } else {
                    Notifications::addValidationFail('Invalid current password.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'update_googleAuth') {
            $validation = new Validate();
            $validation->check($_POST, array('authcode' => array('name' => 'Authorisation Code', 'required' => true)));
            if ($validation->passed()) {
                if (Calendar::setCredentials(Input::get('authcode'))) {
                    Notifications::addSuccess('Google Calendar API authorized!');
                } else {
                    Notifications::addValidationFail('Could not authorize Google Calendar API.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'update_calendarAssignmentsId') {
            $validation = new Validate();
            $validation->check($_POST, array('calid-ass' => array('name' => 'Assignments Calendar ID', 'required' => false), 'calid-ex' => array('name' => 'Exams Calendar ID', 'required' => false)));
            if ($validation->passed()) {
                $data = array('calendar_assignments' => Input::get('calid-ass'), 'calendar_exams' => Input::get('calid-ex'));
                if (Users::currentUser()->update($data)) {
                    Notifications::addSuccess('Calendar ID\'s updated!');
                } else {
                    Notifications::addValidationFail('Could not update calendar ID\'s.');
                }
            } else {
                Notifications::addValidationFail($validation->getErrors());
            }
        }
        if (Input::get('action') === 'delete_googleAuth') {
            Calendar::deleteCredentials();
        }
        if (Input::get('action') === 'update_calendarAssignments' && Users::isEditor()) {
            $assignments = DB::instance()->get(Users::safeSid() . "_assignments")->results();
            foreach ($assignments as $assignment) {
                Calendar::updateAssignment($assignment->id);
            }
        }
        if (Input::get('action') === 'create_database') {
            if (!UserTables::hasTables()) {
                UserTables::createTables();
                if (Users::isGuest()) {
                    Users::currentUser()->update(array('permission_group' => '2'));
                }
            }
        }
    }
    if (!Calendar::isReady()) {
        $smarty->assign('authUrl', Calendar::getAuthUrl());
    }
    $smarty->assign('authCode', Input::get('authcode'));
    $smarty->assign('calid_ass', Users::currentData()->calendar_assignments);
    $smarty->assign('calid_ex', Users::currentData()->calendar_exams);
    $smarty->assign('name', Users::currentData()->name);
    $smarty->assign('sid', Users::currentData()->student_id);
    $smarty->assign('email', Users::currentData()->email);
    $smarty->assign('phone', Users::currentData()->phone);
    return $smarty;
}
コード例 #5
0
function confirm($_POST)
{
    # Get vars
    extract($_POST);
    if (isset($all)) {
        return details($_POST);
    }
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($budname, "string", 1, 255, "Invalid Budget Name.");
    $v->isOk($budfor, "string", 1, 20, "Invalid Budget for option.");
    $v->isOk($budtype, "string", 1, 20, "Invalid Budget type.");
    $v->isOk($fromprd, "string", 1, 20, "Invalid Budget period.");
    $v->isOk($toprd, "string", 1, 20, "Invalid Budget period.");
    if ($budfor == 'acc') {
        if (isset($accids)) {
            foreach ($accids as $akey => $accid) {
                $v->isOk($accid, "num", 1, 50, "Invalid Account number.");
                foreach ($amts[$accid] as $skey => $amtr) {
                    $v->isOk($amts[$accid][$skey], "float", 1, 20, "Invalid Budget amount.");
                }
            }
        } else {
            $v->isOk("#", "num", 0, 0, "Error : please select at least one account.");
        }
    } elseif ($budfor == 'cost') {
        if (isset($ccids)) {
            foreach ($ccids as $akey => $ccid) {
                $v->isOk($ccid, "num", 1, 50, "Invalid Cost Center.");
                foreach ($amts[$ccid] as $skey => $amtr) {
                    $v->isOk($amts[$ccid][$skey], "float", 1, 20, "Invalid Budget amount.");
                }
            }
        } else {
            $v->isOk("#", "num", 0, 0, "Error : please select at least one cost center.");
        }
    }
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class=err>{$e['msg']}</li>";
        }
        return details($_POST, $confirm);
    }
    $ce = new Validate();
    if (isset($ccids)) {
        foreach ($ccids as $akey => $ccid) {
            $tot = array_sum($amts[$ccid]);
            $yr_tot = budgetTotalFromYear($ccid, "cost");
            if (strlen($yr_tot) > 0 && $tot != $yr_tot) {
                $ccRs = get("cubit", "*", "costcenters", "ccid", $ccid);
                $cc = pg_fetch_array($ccRs);
                $cc_name = "{$cc['centercode']} - {$cc['centername']}";
                $ce->addError("", "Yearly budget amount of " . CUR . "{$yr_tot} doesn't\n\t\t\t\t\tmatch proposed total amount of " . CUR . "{$tot} for Cost Center: {$cc_name}.");
            }
        }
    } else {
        if (isset($accids)) {
            foreach ($accids as $akey => $accid) {
                $tot = array_sum($amts[$accid]);
                $yr_tot = budgetTotalFromYear($accid, "acc");
                if (strlen($yr_tot) > 0 && $tot != $yr_tot) {
                    $accRs = get("core", "*", "accounts", "accid", $accid);
                    $acc = pg_fetch_array($accRs);
                    $acc_name = "{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}";
                    $ce->addError("", "Yearly budget amount of " . CUR . "{$yr_tot} doesn't\n\t\t\t\t\tmatch proposed total amount of " . CUR . "{$tot} for Account: {$acc_name}.");
                }
            }
        }
    }
    $mismatches = "";
    if ($ce->isError()) {
        $mm = $ce->getErrors();
        foreach ($mm as $e) {
            $mismatches .= "<li class=err>" . $e["msg"] . "</li>";
        }
    }
    global $BUDFOR, $TYPES, $PERIODS;
    $vbudfor = $BUDFOR[$budfor];
    $vbudtype = $TYPES[$budtype];
    $vfromprd = $PERIODS[$fromprd];
    $vtoprd = $PERIODS[$toprd];
    /* Toggle Options */
    $list = "";
    # budget for
    if ($budfor == 'cost') {
        $head = "<tr><th>Cost Centers</th>";
        foreach ($ccids as $ckey => $ccid) {
            $ccRs = get("cubit", "*", "costcenters", "ccid", $ccid);
            $cc = pg_fetch_array($ccRs);
            $list .= "<tr class='bg-odd'><td><input type=hidden name='ccids[{$cc['ccid']}]' value='{$cc['ccid']}'>{$cc['centercode']} - {$cc['centername']}</td>";
            foreach ($amts[$ccid] as $sprd => $amtr) {
                $amtr = sprint($amtr);
                $list .= "<td align=right><input type=hidden name=amts[{$cc['ccid']}][{$sprd}] value='{$amtr}'>" . CUR . " {$amtr}</td>";
            }
            $list .= "</tr>";
        }
    } elseif ($budfor == 'acc') {
        $head = "<tr><th>Accounts</th>";
        foreach ($accids as $akey => $accid) {
            $accRs = get("core", "*", "accounts", "accid", $accid);
            $acc = pg_fetch_array($accRs);
            $list .= "<tr class='bg-odd'><td><input type=hidden name='accids[{$acc['accid']}]' value='{$acc['accid']}'>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>";
            foreach ($amts[$accid] as $sprd => $amtr) {
                $amtr = sprint($amtr);
                $list .= "<td align=right><input type=hidden name=amts[{$acc['accid']}][{$sprd}] value='{$amtr}'>" . CUR . " {$amtr}</td>";
            }
            $list .= "</tr>";
        }
    }
    # Budget headings
    if ($fromprd < $toprd) {
        for ($i = $fromprd; $i <= $toprd; $i++) {
            $head .= "<th>{$PERIODS[$i]}</th>";
        }
    } elseif ($fromprd > $toprd) {
        for ($i = $fromprd; $i <= 12; $i++) {
            $head .= "<th>{$PERIODS[$i]}</th>";
        }
        for ($i = 1; $i <= $toprd; $i++) {
            $head .= "<th>{$PERIODS[$i]}</th>";
        }
    } else {
        $head .= "<th>{$PERIODS[$toprd]}</th>";
    }
    $head .= "</tr>";
    // $totamt = sprint(array_sum($amts));
    // $list .= "<tr class='bg-even'><td><b>Total Budget Amount</b></td><td align=right><b>".CUR." $totamt</b></td></tr>";
    /* End Toggle Options */
    // Create hidden values
    $hidden = "";
    foreach ($_POST as $name => $value) {
        $hidden .= "<input type='hidden' name='{$name}' value='{$value}'>";
    }
    $confirm = "<center>\n\t<h3> Confirm New Monthly Budget </h3>\n\t<form action='" . SELF . "' method=post name=form>\n\t{$hidden}\n\t<input type=hidden name=key value=write>\n\t<input type=hidden name=budname value='{$budname}'>\n\t<input type=hidden name=budfor value='{$budfor}'>\n\t<input type=hidden name=budtype value='{$budtype}'>\n\t<input type=hidden name=fromprd value='{$fromprd}'>\n\t<input type=hidden name=toprd value='{$toprd}'>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' align=center>\n\t\t<tr>\n\t\t\t<th colspan=2>Details</th>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td>Budget Name</td>\n\t\t\t<td>{$budname}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td><br></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th colspan=2>Options</th>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td>Budget For</td>\n\t\t\t<td>{$vbudfor}</td>\n\t\t</tr>\n\t\t<tr class='bg-even'>\n\t\t\t<td>Budget Type</td>\n\t\t\t<td>{$vbudtype}</td>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td>Budget Period</td>\n\t\t\t<td>{$vfromprd} to {$vtoprd}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td><br></td>\n\t\t</tr>\n\t</table>\n\n\t{$mismatches}\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' align=center>\n\t{$head}\n\t{$list}\n\t</table>\n\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' align=center>\n\t\t<tr>\n\t\t\t<td><br></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td><input type='submit' name='key' value='&laquo Correction'></td>\n\t\t\t<td align=right><input type=submit value='Continue &raquo'></td>\n\t\t</tr>\n\t</table>\n\t</form>\n\t<p>\n\t<table border=0 cellpadding='2' cellspacing='1' width=15%>\n\t\t<tr>\n\t\t\t<th>Quick Links</th>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td align=center><a href='budget-view.php'>View Budgets</td>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td align=center><a href='../main.php'>Main Menu</td>\n\t\t</tr>\n\t</table>";
    return $confirm;
}
コード例 #6
0
            $salt = Hash::salt(32);
            $email_code = md5(Input::get('username') . microtime());
            try {
                $user->create(['username' => Input::get('username'), 'password' => Hash::make(Input::get('password'), $salt), 'salt' => $salt, 'fullname' => strip_excess(Input::get('name')), 'email' => $email, 'profile_pic' => $profilePicDest]);
                /*
                 * TODO: Email Activation Up and Running. V(1.0)
                 * $mail = new Email;
                 * $mail->sendGmailActivation(BASE_URL . 'activate/' . $email_code );
                 * */
                Session::flash('success', 'You registered successfully!');
                Redirect::to(BASE_URL);
            } catch (Exception $e) {
                die($e->getMessage());
            }
        } else {
            foreach ($validate->getErrors() as $error) {
                echo $error . '<br>';
            }
        }
    }
}
?>
<form action="" method="post" enctype="multipart/form-data">
    <div class="field">
        <label for="username">Username</label>
        <input type="text" name="username" id="username" value="<?php 
echo escape(Input::get('username'));
?>
" autocomplete="off">
    </div>
    <div class="field">
コード例 #7
0
function templatePdf($_POST)
{
    extract($_POST);
    global $set_mainFont;
    $pdf =& new Cezpdf();
    $pdf->selectFont($set_mainFont);
    // Validate
    require_lib("validate");
    $v = new Validate();
    foreach ($invids as $invid) {
        $v->isOk($invid, "num", 1, 20, "Invalid invoice number.");
    }
    // Any errors?
    if ($v->isError()) {
        $err = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $err .= "<li class=error>{$e['msg']}</li>";
        }
        $OUTPUT = $confirm;
        require "template.php";
    }
    $ai = 0;
    foreach ($invids as $invid) {
        if ($ai) {
            $pdf->ezNewPage();
        }
        ++$ai;
        // Invoice info
        db_conn("cubit");
        $sql = "SELECT * FROM nons_invoices WHERE invid='{$invid}' AND DIV='" . USER_DIV . "'";
        $invRslt = db_exec($sql) or errDie("Unable to retrieve invoice info.");
        if (pg_num_rows($invRslt) == 0) {
            return "<li class=err>Not found</li>";
        }
        $inv = pg_fetch_array($invRslt);
        // Only needs to be blank, we're manually adding text
        $heading = array(array(""));
        // Company info ----------------------------------------------------------
        db_conn("cubit");
        $sql = "SELECT * FROM compinfo WHERE div='" . USER_DIV . "'";
        $ciRslt = db_exec($sql) or errDie("Unable to retrieve company info from Cubit.");
        $comp = pg_fetch_array($ciRslt);
        $bnkData = qryBankAcct(cust_bank_id($inv["cusid"]));
        $compinfo = array();
        $compinfo[] = array($comp["addr1"], "{$comp['paddr1']}");
        $compinfo[] = array($comp["addr2"], "{$comp['paddr2']}");
        $compinfo[] = array($comp["addr3"], "{$comp['paddr3']}");
        $compinfo[] = array($comp["addr4"], "{$comp['postcode']}");
        $compinfo[] = array("<b>REG: </b>{$comp['regnum']}", "<b>{$bnkData['bankname']}</b>");
        $compinfo[] = array("<b>VAT REG: </b>{$comp['vatnum']}", "<b>Branch: </b>{$bnkData['branchname']}");
        $compinfo[] = array("<b>Tel:</b> {$comp['tel']}", "<b>Branch Code: </b>{$bnkData['branchcode']}");
        $compinfo[] = array("<b>Fax:</b> {$comp['fax']}", "<b>Acc Num: </b>{$bnkData['accnum']}");
        // Date ------------------------------------------------------------------
        $date = array(array("<b>Date</b>"), array($inv['odate']));
        // Document info ---------------------------------------------------------
        db_conn('cubit');
        $Sl = "SELECT * FROM settings WHERE constant='SALES'";
        $Ri = db_exec($Sl) or errDie("Unable to get settings.");
        $data = pg_fetch_array($Ri);
        if ($data['value'] == "Yes") {
            $sp = "<b>Sales Person: </b>{$inv['salespn']}";
        } else {
            $sp = "";
        }
        $docinfo = array(array("<b>Invoice No:</b> {$inv['invnum']}"), array("<b>Proforma Inv No:</b> {$inv['docref']}"), array("{$sp}"));
        // Customer info ---------------------------------------------------------
        if ($inv["cusid"] != 0) {
            db_conn("cubit");
            $sql = "SELECT * FROM customers WHERE cusnum='{$inv['cusid']}'";
            $cusRslt = db_exec($sql) or errDie("Unable to retrieve customer information from Cubit.");
            $cusData = pg_fetch_array($cusRslt);
        } else {
            $cusData["surname"] = $inv["cusname"];
            $cusData["addr1"] = $inv["cusaddr"];
            $cusData["paddr1"] = "";
            $cusData["accno"] = "";
        }
        $cusinfo = array(array("<b>{$cusData['surname']}</b>"));
        $cusaddr = explode("\n", $cusData['paddr1']);
        foreach ($cusaddr as $v) {
            $cusinfo[] = array(pdf_lstr($v, 40));
        }
        $cusinfo[] = array("<b>Account no: </b>{$cusData['accno']}");
        $cusdaddr = array(array("<b>Physical Address:</b>"));
        $cusaddr = explode("\n", $cusData['addr1']);
        foreach ($cusaddr as $v) {
            $cusdaddr[] = array(pdf_lstr($v, 40));
        }
        // Registration numbers --------------------------------------------------
        $regnos = array(array("<b>VAT No:</b>", "<b>Order No:</b>"), array("{$inv['cusvatno']}", "{$inv['cordno']}"));
        // Items display ---------------------------------------------------------
        $items = array();
        db_conn("cubit");
        $sql = "SELECT * FROM nons_inv_items WHERE invid='{$invid}' AND DIV='" . USER_DIV . "'";
        $stkdRslt = db_exec($sql);
        while ($stkd = pg_fetch_array($stkdRslt)) {
            // Check Tax Excempt
            db_conn("cubit");
            $sql = "SELECT zero FROM vatcodes WHERE id='{$stkd['vatex']}'";
            $zRslt = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit.");
            $vatex = pg_fetch_result($zRslt, 0);
            if ($vatex == "Yes") {
                $ex = "#";
            } else {
                $ex = "";
            }
            $items[] = array("Description" => pdf_lstr($ex . $stkd['description'], 65), "Qty" => $stkd['qty'], "Unit Price" => CUR . $stkd['unitcost'], "Amount" => CUR . $stkd['amt']);
        }
        // Comment ---------------------------------------------------------------
        db_conn("cubit");
        $sql = "SELECT value FROM settings WHERE constant='DEFAULT_COMMENTS'";
        $commentRslt = db_exec($sql) or errDie("Unable to retrieve the default comment from Cubit.");
        $default_comment = pg_fetch_result($commentRslt, 0);
        $comment = array(array("<i>VAT Exempt Indicator: #</i>"), array(base64_decode($default_comment)));
        // Box to sign in --------------------------------------------------------
        $sign = array(array("<i>Thank you for your support</i>"), array(''), array("<b>Received in good order by:</b> ____________________"), array(''), array("                                      <b>Date:</b> ____________________"));
        // Totals ----------------------------------------------------------------
        $totals = array(array("1" => "<b>Subtotal:</b> ", "2" => CUR . "{$inv['subtot']}"), array("1" => "<b>VAT @ " . TAX_VAT . "%:</b> ", "2" => CUR . "{$inv['vat']}"), array("1" => "<b>Total Incl VAT:</b> ", "2" => CUR . "{$inv['total']}"));
        $totCols = array("1" => array("width" => 90), "2" => array("justification" => "right"));
        $ic = 0;
        while (++$ic * 20 < count($items)) {
        }
        // Draw the pages, determine by the amount of items how many pages
        // if items > 20 start a new page
        $items_print = array();
        for ($i = 0; $i < $ic; $i++) {
            if ($i) {
                $pdf->ezNewPage();
            }
            // Page number -------------------------------------------------------
            $pagenr = array(array("<b>Page number</b>"), array($i + 1));
            // Heading
            $heading_pos = drawTable(&$pdf, $heading, 0, 0, 520, 5);
            drawText(&$pdf, "<b>{$comp['compname']}</b>", 18, 0, $heading_pos['y'] / 2 + 6);
            drawText(&$pdf, "<b>Tax Invoice</b>", 18, $heading_pos['x'] - 120, $heading_pos['y'] / 2 + 9);
            $compinfo_pos = drawTable(&$pdf, $compinfo, 0, $heading_pos['y'], 320, 8);
            $date_pos = drawTable(&$pdf, $date, $compinfo_pos['x'], $heading_pos['y'], 100, 4);
            $pagenr_pos = drawTable(&$pdf, $pagenr, $date_pos['x'], $heading_pos['y'], 100, 4);
            $docinfo_pos = drawTable(&$pdf, $docinfo, $compinfo_pos['x'], $date_pos['y'], 200, 4);
            $cusinfo_pos = drawTable(&$pdf, $cusinfo, 0, $compinfo_pos['y'], 320, 10);
            $cusdaddr_pos = drawTable(&$pdf, $cusdaddr, $cusinfo_pos['x'], $compinfo_pos['y'], 200, 10);
            $regnos_pos = drawTable(&$pdf, $regnos, 0, $cusinfo_pos['y'], 520, 2);
            $items_start = $i * 20;
            if ($items_start >= count($items) - 20) {
                $items_end = count($items) - 1;
            } else {
                $items_end = ($i + 1) * 20;
            }
            $items_print = array();
            for ($j = $items_start; $j <= $items_end; $j++) {
                $items_print[$j] = $items[$j];
            }
            // Adjust the column widths
            $cols = array("Description" => array("width" => 310), "Qty" => array("width" => 50), "Unit Price" => array("width" => 80, "justification" => "right"), "Amount" => array("width" => 80, "justification" => "right"));
            $items_pos = drawTable(&$pdf, $items_print, 0, $regnos_pos['y'] + 2, 520, 20, $cols, 1);
            $comment_pos = drawTable(&$pdf, $comment, 0, $items_pos['y'], 520, 2);
            $sign_pos = drawTable(&$pdf, $sign, 0, $comment_pos['y'], 320, 5);
            $totals_pos = drawTable(&$pdf, $totals, $sign_pos['x'], $comment_pos['y'], 200, 5, $totCols);
        }
    }
    $pdf->ezStream();
}
コード例 #8
0
function genpdf($quoid)
{
    global $_GET;
    extract($_GET);
    global $set_mainFont;
    $showvat = TRUE;
    $pdf =& new Cezpdf();
    $pdf->selectFont($set_mainFont);
    // Validate
    require_lib("validate");
    $v = new Validate();
    $v->isOk($quoid, "num", 1, 20, "Invalid quote number.");
    // Any errors?
    if ($v->isError()) {
        $err = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $err .= "<li class='err'>{$e['msg']}</li>";
        }
        $OUTPUT = $confirm;
        require "../template.php";
    }
    // Invoice info
    db_conn("cubit");
    $sql = "SELECT * FROM quotes WHERE quoid='{$quoid}' AND DIV='" . USER_DIV . "'";
    $invRslt = db_exec($sql) or errDie("Unable to retrieve quote info.");
    if (pg_num_rows($invRslt) < 1) {
        return "<li class='err'>Not found</li>";
    }
    $inv = pg_fetch_array($invRslt);
    db_conn("cubit");
    $sql = "SELECT symbol FROM currency WHERE fcid='{$inv['fcid']}'";
    $curRslt = db_exec($sql) or errDie("Unable to retrieve currency from Cubit.");
    $curr = pg_fetch_result($curRslt, 0);
    if (!$curr) {
        $curr = CUR;
    }
    // Check if stock was selected
    db_conn("cubit");
    $sql = "SELECT stkid FROM quote_items WHERE quoid='{$quoid}' AND DIV='" . USER_DIV . "'";
    $cRslt = db_exec($sql) or errDie("Unable to retrieve quote info.");
    if (pg_num_rows($cRslt) < 1) {
        $error = "<li class='err'>Quote number <b>{$quoid}</b> has no items</li>";
        $OUTPUT = $error;
    }
    // Only needs to be blank, we're manually adding text
    $heading = array(array(""));
    // Company info ----------------------------------------------------------
    db_conn("cubit");
    $sql = "SELECT * FROM compinfo WHERE div='" . USER_DIV . "'";
    $ciRslt = db_exec($sql) or errDie("Unable to retrieve company info from Cubit.");
    $comp = pg_fetch_array($ciRslt);
    // Banking information ---------------------------------------------------
    $bnkData = qryBankAcct(getdSetting("BANK_DET"));
    $compinfo = array();
    $compinfo[] = array($comp["addr1"], $comp["paddr1"]);
    $compinfo[] = array(pdf_lstr($comp["addr2"], 35), pdf_lstr($comp["paddr2"], 35));
    $compinfo[] = array(pdf_lstr($comp["addr3"], 35), pdf_lstr($comp["paddr3"], 35));
    $compinfo[] = array(pdf_lstr($comp["addr4"], 35), "{$comp['postcode']}");
    $compinfo[] = array("<b>REG: </b>{$comp['regnum']}", "<b>{$bnkData['bankname']}</b>");
    $compinfo[] = array("<b>VAT REG: </b>{$comp['vatnum']}", "<b>Branch: </b>{$bnkData['branchname']}");
    $compinfo[] = array("<b>Tel:</b> {$comp['tel']}", "<b>Branch Code: </b>{$bnkData['branchcode']}");
    $compinfo[] = array("<b>Fax:</b> {$comp['fax']}", "<b>Acc Num: </b>{$bnkData['accnum']}");
    // Date ------------------------------------------------------------------
    $date = array(array("<b>Date</b>"), array($inv['odate']));
    // Document info ---------------------------------------------------------
    db_conn('cubit');
    $Sl = "SELECT * FROM settings WHERE constant='SALES'";
    $Ri = db_exec($Sl) or errDie("Unable to get settings.");
    $data = pg_fetch_array($Ri);
    db_conn('cubit');
    $Sl = "SELECT * FROM settings WHERE constant='SALES'";
    $Ri = db_exec($Sl) or errDie("Unable to get settings.");
    $data = pg_fetch_array($Ri);
    if ($data['value'] == "Yes") {
        $sp = "<b>Sales Person: </b>{$inv['salespn']}";
    } else {
        $sp = "";
    }
    $docinfo = array(array("<b>Quote No:</b> {$inv['quoid']}"), array("<b>Proforma Inv No:</b> {$inv['docref']}"), array("<b>Sales Order No:</b> {$inv['ordno']}"), array("{$sp}"));
    if (isset($salespn)) {
        $docinfo[] = array("<b>Sales Person:</b> {$salespn}");
    }
    // Retrieve the customer information -------------------------------------
    db_conn("cubit");
    $sql = "SELECT * FROM customers WHERE cusnum='{$inv['cusnum']}'";
    $cusRslt = db_exec($sql) or errDie("Unable to retrieve customer information from Cubit.");
    $cusData = pg_fetch_array($cusRslt);
    // Customer info ---------------------------------------------------------
    $invoice_to = array(array(""));
    $cusinfo = array(array("<b>{$inv['surname']}</b>"));
    $cusaddr = explode("\n", $cusData['addr1']);
    foreach ($cusaddr as $v) {
        $cusinfo[] = array(pdf_lstr($v, 40));
    }
    $cusinfo[] = array("<b>Account no: </b>{$cusData['accno']}");
    $cuspaddr = array(array("<b>Postal Address</b>"));
    $paddr = explode("\n", $cusData["paddr1"]);
    foreach ($paddr as $addr) {
        $cuspaddr[] = array($addr);
    }
    $cusdaddr = array(array("<b>Delivery Address:</b>"));
    if ($inv['branch'] == 0) {
        $branchname = "Head Office";
        $cusaddr = explode("\n", $cusData['addr1']);
    } else {
        $get_addr = "SELECT * FROM customer_branches WHERE id = '{$inv['branch']}' LIMIT 1";
        $run_addr = db_exec($get_addr);
        if (pg_numrows($run_addr) < 1) {
            $cusaddr = array();
            $branchname = "Head Office";
        } else {
            $barr = pg_fetch_array($run_addr);
            $cusaddr = explode("\n", $barr['branch_descrip']);
            $branchname = $barr['branch_name'];
        }
    }
    $cusdaddr[] = array(pdf_lstr("Branch : {$branchname}", 30));
    $del_addr = explode("\n", $inv["del_addr"]);
    foreach ($del_addr as $addr) {
        $cusdaddr[] = array(pdf_lstr($addr, 30));
    }
    // Registration numbers --------------------------------------------------
    $regnos = array(array("<b>VAT No:</b>", "<b>Order No:</b>"), array("{$inv['cusvatno']}", "{$inv['cordno']}"));
    // Items display ---------------------------------------------------------
    $items = array();
    db_conn("cubit");
    $sql = "SELECT * FROM quote_items WHERE quoid='{$quoid}' AND DIV='" . USER_DIV . "'";
    $stkdRslt = db_exec($sql);
    while ($stkd = pg_fetch_array($stkdRslt)) {
        // Get warehouse
        db_conn("exten");
        $sql = "SELECT * FROM warehouses WHERE whid='{$stkd['whid']}' AND DIV='" . USER_DIV . "'";
        $whRslt = db_exec($sql);
        $wh = pg_fetch_array($whRslt);
        // Get stock in this warehouse
        db_conn("cubit");
        $sql = "SELECT * FROM stock WHERE stkid='{$stkd['stkid']}' AND DIV='" . USER_DIV . "'";
        $stkRslt = db_exec($sql);
        $stk = pg_fetch_array($stkRslt);
        $sp = "";
        // Check Tax Excempt
        db_conn("cubit");
        $sql = "SELECT zero FROM vatcodes WHERE id='{$stkd['vatcode']}'";
        $zRslt = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit.");
        $vatex = pg_fetch_result($zRslt, 0);
        if ($vatex == "Yes") {
            $ex = "#";
        } else {
            $ex = "";
        }
        $sql = "SELECT * FROM vatcodes WHERE id='{$stkd['vatcode']}'";
        $runsql = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit.");
        if (pg_numrows($runsql) < 1) {
            return "Invalid VAT code entered";
        }
        $vd = pg_fetch_array($runsql);
        if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") {
            $showvat = FALSE;
        }
        // keep track of discounts
        //$disc += $stkd['disc'];
        if ($stkd["account"] > 0) {
            $description = $stkd["description"];
        } else {
            $description = $stk["stkdes"];
        }
        // Remove any new lines from the description
        $ar_desc = explode("\n", $description);
        $description = implode(" ", $ar_desc);
        $items[] = array("Code" => makewidth($pdf, 75, 12, $stk['stkcod']), "Description" => makewidth($pdf, 175, 12, $ex . $description), "Qty" => $stkd['qty'], "Unit Price" => $curr . $stkd['unitcost'], "Unit Discount" => $curr . $stkd['disc'], "Amount" => $curr . $stkd['amt']);
    }
    $inv["comm"] = fixparag(&$pdf, 3, 520, 11, $inv["comm"]);
    /*$inv["comm"] = preg_replace("/[\n]/", " ", $inv["comm"]);
    
    	$lines = array();
    	$txtleft = $inv["comm"];
    	$done = false;
    	while (count($lines) < 3 && !$done) {
    		$mc = maxwidth(&$pdf, 520, 11, $txtleft);
    
    		// run until end of a word.
    		while ($txtleft[$mc - 1] != ' ' && $mc < strlen($txtleft)) ++$mc;
    
    		if ($mc == strlen($txtleft)) {
    			$done = true;
    		}
    
    		$lines[] = substr($txtleft, 0, $mc);
    		$txtleft = substr($txtleft, $mc);
    	}
    
    	if (strlen($txtleft) > 0) {
    		$lines[2] .= "...";
    	}
    
    	$inv["comm"] = preg_replace("/  /", " ", implode("\n", $lines));*/
    // Comment ---------------------------------------------------------------
    $comment = array(array("<i>VAT Exempt Indicator : #</i>"), array($inv["comm"]));
    // Box for signature -----------------------------------------------------
    $sign = array(array("<b>Terms:</b> {$inv['terms']} days"), array(''), array("<b>Received in good order by:</b> ____________________"), array(''), array("                                      <b>Date:</b> ____________________"));
    // Totals ----------------------------------------------------------------
    if (!isset($showvat)) {
        $showvat = TRUE;
    }
    if ($showvat == TRUE) {
        $vat14 = AT14;
    } else {
        $vat14 = "";
    }
    $totals = array(array("1" => "<b>Subtotal:</b> ", "2" => $curr . "{$inv['subtot']}"), array("1" => "<b>Trade Discount:</b> ", "2" => $curr . "{$inv['discount']}"), array("1" => "<b>Delivery Charge:</b> ", "2" => $curr . "{$inv['delivery']}"), array("1" => "<b>VAT {$vat14}:</b> ", "2" => $curr . "{$inv['vat']}"), array("1" => "<b>Total Incl VAT:</b> ", "2" => $curr . "{$inv['total']}"));
    $totCols = array("1" => array("width" => 90), "2" => array("justification" => "right"));
    $ic = 0;
    while (++$ic * 22 < count($items)) {
    }
    // Draw the pages, determine by the amount of items how many pages
    // if items > 20 start a new page
    $items_print = array();
    for ($i = 0; $i < $ic; $i++) {
        if ($i) {
            $pdf->ezNewPage();
        }
        // Page number -------------------------------------------------------
        $pagenr = array(array("<b>Page number</b>"), array($i + 1));
        // Heading
        $heading_pos = drawTable(&$pdf, $heading, 0, 0, 520, 5);
        drawText(&$pdf, "<b>{$comp['compname']}</b>", 18, 0, $heading_pos['y'] / 2 + 6);
        drawText(&$pdf, "<b>Quote</b>", 20, $heading_pos['x'] - 120, $heading_pos['y'] / 2 + 9);
        // Should we display reprint on the invoice
        if ($type == "invreprint") {
            drawText(&$pdf, "<b>Reprint</b>", 12, $heading_pos['x'] - 70, $heading_pos['y'] / 2 + 22);
        }
        $compinfo_pos = drawTable(&$pdf, $compinfo, 0, $heading_pos['y'], 320, 8);
        $date_pos = drawTable(&$pdf, $date, $compinfo_pos['x'], $heading_pos['y'], 100, 3);
        $pagenr_pos = drawTable(&$pdf, $pagenr, $date_pos['x'], $heading_pos['y'], 100, 3);
        $docinfo_pos = drawTable(&$pdf, $docinfo, $compinfo_pos['x'], $date_pos['y'], 200, 5);
        $invoice_to_pos = drawTable(&$pdf, $invoice_to, 0, $compinfo_pos['y'], 520, 2);
        drawText(&$pdf, "<b>Quote To:</b>", 12, 520 / 2 - 45, $invoice_to_pos['y'] - 7);
        $cusinfo_pos = drawTable(&$pdf, $cusinfo, 0, $invoice_to_pos['y'], 173, 8);
        $cuspaddr_pos = drawTable(&$pdf, $cuspaddr, $cusinfo_pos['x'], $invoice_to_pos['y'], 173, 8);
        $cusdaddr_pos = drawTable(&$pdf, $cusdaddr, $cuspaddr_pos['x'], $invoice_to_pos['y'], 174, 8);
        $regnos_pos = drawTable(&$pdf, $regnos, 0, $cusinfo_pos['y'], 520, 2);
        $items_start = $i * 22;
        if ($i) {
            $items_start++;
        }
        if ($items_start >= count($items) - 22) {
            $items_end = count($items) - 1;
        } else {
            $items_end = ($i + 1) * 22;
        }
        $items_print = array();
        for ($j = $items_start; $j <= $items_end; $j++) {
            $items_print[$j] = $items[$j];
        }
        $cols = array("Code" => array("width" => 80), "Description" => array("width" => 180), "Qty" => array("width" => 33), "Unit Price" => array("width" => 80, "justification" => "right"), "Unit Discount" => array("width" => 67, "justification" => "right"), "Amount" => array("width" => 80, "justification" => "right"));
        $items_pos = drawTable(&$pdf, $items_print, 0, $regnos_pos['y'] + 2, 520, 22, $cols, 1);
        $comment_pos = drawTable(&$pdf, $comment, 0, $items_pos['y'], 520, 2);
        $sign_pos = drawTable(&$pdf, $sign, 0, $comment_pos['y'], 320, 5);
        $totals_pos = drawTable(&$pdf, $totals, $sign_pos['x'], $comment_pos['y'], 200, 5, $totCols);
    }
    return $pdf->output();
}
コード例 #9
0
function confirm($_POST)
{
    # Get vars
    foreach ($_POST as $key => $value) {
        ${$key} = $value;
    }
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($budid, "num", 1, 20, "Invalid Budget id.");
    $v->isOk($budname, "string", 1, 255, "Invalid Budget Name.");
    $v->isOk($budtype, "string", 1, 20, "Invalid Budget type.");
    if ($budfor == 'acc') {
        if (isset($accids)) {
            foreach ($accids as $akey => $accid) {
                $v->isOk($accid, "num", 1, 50, "Invalid Account number.");
                foreach ($amts[$accid] as $skey => $amtr) {
                    $v->isOk($amts[$accid][$skey], "float", 1, 20, "Invalid Budget amount.");
                }
            }
        } else {
            $v->isOk("#", "num", 0, 0, "Error : please select at least one account.");
        }
    } elseif ($budfor == 'cost') {
        if (isset($ccids)) {
            foreach ($ccids as $akey => $ccid) {
                $v->isOk($ccid, "num", 1, 50, "Invalid Cost Center.");
                foreach ($amts[$ccid] as $skey => $amtr) {
                    $v->isOk($amts[$ccid][$skey], "float", 1, 20, "Invalid Budget amount.");
                }
            }
        } else {
            $v->isOk("#", "num", 0, 0, "Error : please select at least one cost center.");
        }
    }
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class=err>" . $e["msg"];
        }
        return details($_POST, $confirm);
    }
    $ce = new Validate();
    if (isset($accids)) {
        foreach ($accids as $akey => $accid) {
            $tot = $amts[$accid][BUDGET_YEARS_INDEX];
            $mon_tot = budgetTotalFromMonth($accid, "acc");
            if (strlen($mon_tot) > 0 && $tot != $mon_tot) {
                $accRs = get("core", "*", "accounts", "accid", $accid);
                $acc = pg_fetch_array($accRs);
                $acc_name = "{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}";
                $ce->addError("", "Monthly annual budget total of " . CUR . "{$mon_tot} doesn't\n\t\t\t\t\tmatch proposed total amount of " . CUR . "{$tot} for Account: {$accid} {$acc_name}.");
            }
        }
    } else {
        if (isset($ccids)) {
            foreach ($ccids as $akey => $ccid) {
                $tot = $amts[$ccid][BUDGET_YEARS_INDEX];
                $mon_tot = budgetTotalFromMonth($ccid, "acc");
                if (strlen($mon_tot) > 0 && $tot != $mon_tot) {
                    $ccRs = get("cubit", "*", "costcenters", "ccid", $ccid);
                    $cc = pg_fetch_array($ccRs);
                    $cc_name = "{$cc['centercode']} - {$cc['centername']}";
                    $ce->addError("", "Monthly annual budget total of " . CUR . "{$mon_tot} doesn't\n\t\t\t\t\tmatch proposed total amount of " . CUR . "{$tot} for Cost Center: {$cc_name}.");
                }
            }
        }
    }
    $mismatches = "";
    if ($ce->isError()) {
        $mm = $ce->getErrors();
        foreach ($mm as $e) {
            $mismatches .= "<li class=err>" . $e["msg"] . "</li>";
        }
    }
    # Query server
    db_connect();
    $sql = "SELECT * FROM budgets WHERE budid = '{$budid}'";
    $budRslt = db_exec($sql) or errDie("Unable to retrieve Budgets from database.");
    if (pg_numrows($budRslt) < 1) {
        return "<li class=err> - Invalid Budget.";
    }
    $bud = pg_fetch_array($budRslt);
    global $BUDFOR, $PERIODS, $TYPES, $YEARS;
    $vbudfor = $BUDFOR[$bud['budfor']];
    $vbudtype = $TYPES[$budtype];
    $vfromyr = $YEARS[$bud['fromprd']];
    $vtoyr = $YEARS[$bud['toprd']];
    /* Toggle Options */
    $list = "";
    # budget for
    if ($bud['budfor'] == 'cost') {
        $head = "<tr><th>Cost Centers</th>";
        foreach ($ccids as $ckey => $ccid) {
            $ccRs = get("cubit", "*", "costcenters", "ccid", $ccid);
            $cc = pg_fetch_array($ccRs);
            $list .= "<tr class='bg-odd'><td><input type=hidden name=ccids[] value='{$cc['ccid']}'>{$cc['centercode']} - {$cc['centername']}</td>";
            foreach ($amts[$ccid] as $sprd => $amtr) {
                $amtr = sprint($amtr);
                $list .= "<td align=right><input type=hidden name=amts[{$cc['ccid']}][{$sprd}] value='{$amtr}'>" . CUR . " {$amtr}</td>";
            }
            $list .= "</tr>";
        }
    } elseif ($bud['budfor'] == 'acc') {
        $head = "<tr><th>Accounts</th>";
        foreach ($accids as $akey => $accid) {
            $accRs = get("core", "*", "accounts", "accid", $accid);
            $acc = pg_fetch_array($accRs);
            $list .= "<tr class='bg-odd'><td><input type=hidden name=accids[] value='{$acc['accid']}'>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>";
            foreach ($amts[$accid] as $sprd => $amtr) {
                $amtr = sprint($amtr);
                $list .= "<td align=right><input type=hidden name=amts[{$acc['accid']}][{$sprd}] value='{$amtr}'>" . CUR . " {$amtr}</td>";
            }
            $list .= "</tr>";
        }
    }
    # Budget headings
    if ($bud['fromprd'] < $bud['toprd']) {
        for ($i = $bud['fromprd']; $i <= $bud['toprd']; $i++) {
            $head .= "<th>{$YEARS[$i]}</th>";
        }
    } elseif ($bud['fromprd'] > $bud['toprd']) {
        for ($i = $bud['fromprd']; $i < 10; $i++) {
            $head .= "<th>{$YEARS[$i]}</th>";
        }
        for ($i = 0; $i <= $bud['toprd']; $i++) {
            $head .= "<th>{$YEARS[$i]}</th>";
        }
    } else {
        $i = $bud['toprd'];
        $head .= "<th>{$YEARS[$i]}</th>";
    }
    $head .= "</tr>";
    // $totamt = sprint(array_sum($amts));
    // $list .= "<tr class='bg-even'><td><b>Total Budget Amount</b></td><td align=right><b>".CUR." $totamt</b></td></tr>";
    /* End Toggle Options */
    $confirm = "<center>\n\t<h3> Confirm New Yearly Budget </h3>\n\t<form action='" . SELF . "' method=post name=form>\n\t<input type=hidden name=key value=write>\n\t<input type=hidden name=budid value='{$budid}'>\n\t<input type=hidden name=budname value='{$budname}'>\n\t<input type=hidden name=budtype value='{$budtype}'>\n\t<input type=hidden name=budfor value='{$bud['budfor']}'>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' align=center>\n\t<tr><th colspan=2>Details</th></tr>\n\t<tr class='bg-odd'><td>Budget Name</td><td>{$budname}</td></tr>\n\t<tr><td><br></td></tr>\n\t<tr><th colspan=2>Options</th></tr>\n\t<tr class='bg-odd'><td>Budget For</td><td>{$vbudfor}</td>\n\t<tr class='bg-even'><td>Budget Type</td><td>{$vbudtype}</td>\n\t<tr class='bg-odd'><td>Budget Year</td><td>{$vfromyr} to {$vtoyr}</td>\n\t<tr><td><br></td></tr>\n\t</table>\n\t{$mismatches}\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' align=center>\n\t{$head}\n\t{$list}\n\t</table>\n\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' align=center>\n\t<tr><td><br></td></tr>\n\t<tr><td><input type=button value='&laquo Back' onClick='javascript:history.back()'></td><td align=right><input type=submit value='Continue &raquo'></td></tr>\n\t</table></form>\n\t<p>\n\t<table border=0 cellpadding='2' cellspacing='1' width=15%>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<tr class='bg-odd'><td align=center><a href='budget-view.php'>View Budgets</td></tr>\n\t\t<tr class='bg-odd'><td align=center><a href='../main.php'>Main Menu</td></tr>\n\t</table>";
    return $confirm;
}
コード例 #10
0
ファイル: add.php プロジェクト: toppestkek/GuestBook
$app->get('/add', function () use($app) {
    $main = '';
    $add = 'active';
    return $app['twig']->render('add.twig', array('main' => $main, 'add' => $add));
});
$app->post('/add', function () use($app) {
    if (isset($_POST)) {
        $check = new Check();
        $name = $check->checkInput($_POST['name']);
        $comment = $check->checkInput($_POST['comment']);
        $pdo = new Db();
        $db = $pdo->get();
        $validate = new Validate($db);
        $data = array('name' => $name, 'comment' => $comment);
        $errors = $validate->getErrors($data);
        if (!empty($errors)) {
            $main = '';
            $add = 'active';
            return $app['twig']->render('add.twig', array('main' => $main, 'add' => $add, 'errors' => $errors, 'name' => $name, 'comment' => $comment));
        } else {
            $mapper = new Mapper($db);
            $ip_address = $_SERVER['REMOTE_ADDR'];
            $comments = new Comments();
            $comments->name = $name;
            $comments->comment = $comment;
            $comments->ip_address = $ip_address;
            $mapper->save($comments);
            return $app->redirect('/GuestBook/');
        }
    }
コード例 #11
0
function gennonspdf($invid)
{
    global $set_mainFont;
    $showvat = TRUE;
    $pdf =& new Cezpdf();
    $pdf->selectFont($set_mainFont);
    // Validate
    require_lib("validate");
    $v = new Validate();
    $v->isOk($invid, "num", 1, 20, "Invalid invoice number.");
    // Any errors?
    if ($v->isError()) {
        $err = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $err .= "<li class='err'>{$e['msg']}</li>";
        }
        $OUTPUT = $confirm;
        require "../template.php";
    }
    // Invoice info
    db_conn("cubit");
    $sql = "SELECT * FROM nons_invoices WHERE invid='{$invid}' AND DIV='" . USER_DIV . "'";
    $invRslt = db_exec($sql) or errDie("Unable to retrieve invoice info.");
    //die ($sql);
    if (pg_num_rows($invRslt) == 0) {
        return "<li class='err'>Not found</li>";
    }
    $inv = pg_fetch_array($invRslt);
    db_conn("cubit");
    $sql = "SELECT symbol FROM currency WHERE fcid='{$inv['fcid']}'";
    $curRslt = db_exec($sql) or errDie("Unable to retrieve currency from Cubit.");
    $curr = pg_fetch_result($curRslt, 0);
    if (!$curr) {
        $curr = CUR;
    }
    // Only needs to be blank, we're manually adding text
    $heading = array(array(""));
    // Company info ----------------------------------------------------------
    db_conn("cubit");
    $sql = "SELECT * FROM compinfo WHERE div='" . USER_DIV . "'";
    $ciRslt = db_exec($sql) or errDie("Unable to retrieve company info from Cubit.");
    $comp = pg_fetch_array($ciRslt);
    //	$bnkData = qryBankAcct(getdSetting("BANK_DET"));
    $bnkData = qryBankAcct($inv['bankid']);
    $compinfo = array();
    $compinfo[] = array(pdf_lstr($comp["addr1"], 35), pdf_lstr($comp["paddr1"], 35));
    $compinfo[] = array(pdf_lstr($comp["addr2"], 35), pdf_lstr($comp["paddr2"], 35));
    $compinfo[] = array(pdf_lstr($comp["addr3"], 35), pdf_lstr($comp["paddr3"], 35));
    $compinfo[] = array(pdf_lstr($comp["addr4"], 35), "{$comp['postcode']}");
    $compinfo[] = array("<b>REG: </b>{$comp['regnum']}", "<b>{$bnkData['bankname']}</b>");
    $compinfo[] = array("<b>VAT REG: </b>{$comp['vatnum']}", "<b>Branch: </b>{$bnkData['branchname']}");
    $compinfo[] = array("<b>Tel:</b> {$comp['tel']}", "<b>Branch Code: </b>{$bnkData['branchcode']}");
    $compinfo[] = array("<b>Fax:</b> {$comp['fax']}", "<b>Acc Num: </b>{$bnkData['accnum']}");
    // Date ------------------------------------------------------------------
    $date = array(array("<b>Date</b>"), array($inv['odate']));
    // Document info ---------------------------------------------------------
    db_conn('cubit');
    $Sl = "SELECT * FROM settings WHERE constant='SALES'";
    $Ri = db_exec($Sl) or errDie("Unable to get settings.");
    $data = pg_fetch_array($Ri);
    if ($data['value'] == "Yes") {
        $sp = "<b>Sales Person: </b>{$inv['salespn']}";
    } else {
        $sp = "";
    }
    // Customer info ---------------------------------------------------------
    if ($inv["cusid"] != 0) {
        db_conn("cubit");
        $sql = "SELECT * FROM customers WHERE cusnum='{$inv['cusid']}'";
        $cusRslt = db_exec($sql) or errDie("Unable to retrieve customer information from Cubit.");
        $cusData = pg_fetch_array($cusRslt);
    } else {
        $cusData["surname"] = $inv["cusname"];
        $cusData["addr1"] = $inv["cusaddr"];
        $cusData["paddr1"] = $inv["cusaddr"];
        $cusData["del_addr1"] = "";
        $cusData["accno"] = "";
    }
    $docinfo = array(array("<b>Invoice No:</b> {$inv['invnum']}"), array("<b>Proforma Inv No:</b> {$inv['docref']}"), array("<b>Account no: </b>{$cusData['accno']}"), array("{$sp}"));
    $invoice_to = array(array(""));
    $cusinfo = array(array("<b>{$cusData['surname']}</b>"));
    $cusaddr = explode("\n", $cusData['addr1']);
    foreach ($cusaddr as $v) {
        $cusinfo[] = array(pdf_lstr($v, 40));
    }
    //	$cusinfo[] = array("<b>Account no: </b>$cusData[accno]");
    $cuspaddr = array(array("<b>Postal Address</b>"));
    $paddr = explode("\n", $cusData["paddr1"]);
    foreach ($paddr as $addr) {
        $cuspaddr[] = array("{$addr}");
    }
    $cusdaddr = array(array("<b>Delivery Address:</b>"));
    $cusaddr = explode("\n", $cusData['del_addr1']);
    foreach ($cusaddr as $v) {
        $cusdaddr[] = array(pdf_lstr($v, 40));
    }
    // Registration numbers --------------------------------------------------
    $regnos = array(array("<b>VAT No:</b>", "<b>Order No:</b>"), array("{$inv['cusvatno']}", "{$inv['cordno']}"));
    // Items display ---------------------------------------------------------
    $items = array();
    db_conn("cubit");
    $sql = "SELECT * FROM nons_inv_items WHERE invid='{$invid}' AND DIV='" . USER_DIV . "'";
    $stkdRslt = db_exec($sql);
    while ($stkd = pg_fetch_array($stkdRslt)) {
        // Check Tax Excempt
        db_conn("cubit");
        $sql = "SELECT zero FROM vatcodes WHERE id='{$stkd['vatex']}'";
        $zRslt = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit.");
        $vatex = pg_fetch_result($zRslt, 0);
        if ($vatex == "Yes") {
            $ex = "#";
        } else {
            $ex = "";
        }
        $sql = "SELECT * FROM vatcodes WHERE id='{$stkd['vatex']}'";
        $runsql = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit.");
        if (pg_numrows($runsql) < 1) {
            return "Invalid VAT code entered";
        }
        $vd = pg_fetch_array($runsql);
        if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") {
            $showvat = FALSE;
        }
        $items[] = array("Description" => makewidth($pdf, 305, 12, $ex . strip_tags($stkd["description"])), "Qty" => $stkd['qty'], "Unit Price" => $curr . $stkd['unitcost'], "Amount" => $curr . $stkd['amt']);
    }
    // Comment ---------------------------------------------------------------
    $comment = array(array("<i>VAT Exempt Indicator: #</i>"), array($inv["remarks"]));
    // Box to sign in --------------------------------------------------------
    $sign = array(array("<b>Terms:</b> {$inv['terms']}"), array(''), array("<b>Received in good order by:</b> ____________________"), array(''), array("                                      <b>Date:</b> ____________________"));
    // Totals ----------------------------------------------------------------
    if (!isset($showvat)) {
        $showvat = TRUE;
    }
    if ($showvat == TRUE) {
        $vat14 = AT14;
    } else {
        $vat14 = "";
    }
    $totals = array(array("1" => "<b>Subtotal:</b> ", "2" => $curr . "{$inv['subtot']}"), array("1" => "<b>VAT {$vat14}:</b> ", "2" => $curr . "{$inv['vat']}"), array("1" => "<b>Total Incl VAT:</b> ", "2" => $curr . "{$inv['total']}"));
    $totCols = array("1" => array("width" => 90), "2" => array("justification" => "right"));
    $ic = 0;
    while (++$ic * 20 < count($items)) {
    }
    // Draw the pages, determine by the amount of items how many pages
    // if items > 20 start a new page
    $items_print = array();
    for ($i = 0; $i < $ic; $i++) {
        if ($i) {
            $pdf->ezNewPage();
        }
        // Page number -------------------------------------------------------
        $pagenr = array(array("<b>Page number</b>"), array($i + 1));
        // Heading
        $heading_pos = drawTable(&$pdf, $heading, 0, 0, 520, 5);
        drawText(&$pdf, "<b>{$comp['compname']}</b>", 18, 18, $heading_pos['y'] / 2 + 6);
        drawText(&$pdf, "<b>Tax Invoice</b>", 18, $heading_pos['x'] - 120, $heading_pos['y'] / 2 + 9);
        // Should we display reprint on the invoice
        if (isset($type) and $type == "nonsreprint") {
            drawText(&$pdf, "<b>Reprint</b>", 12, $heading_pos['x'] - 70, $heading_pos['y'] / 2 + 22);
        }
        $compinfo_pos = drawTable(&$pdf, $compinfo, 0, $heading_pos['y'], 320, 8);
        $date_pos = drawTable(&$pdf, $date, $compinfo_pos['x'], $heading_pos['y'], 100, 4);
        $pagenr_pos = drawTable(&$pdf, $pagenr, $date_pos['x'], $heading_pos['y'], 100, 4);
        $docinfo_pos = drawTable(&$pdf, $docinfo, $compinfo_pos['x'], $date_pos['y'], 200, 4);
        $invoice_to_pos = drawTable(&$pdf, $invoice_to, 0, $compinfo_pos['y'], 520, 2);
        drawText(&$pdf, "<b>Tax Invoice to:</b>", 12, 520 / 2 - 45, $invoice_to_pos['y'] - 7);
        $cusinfo_pos = drawTable(&$pdf, $cusinfo, 0, $invoice_to_pos['y'], 173, 8);
        $cuspaddr_pos = drawTable(&$pdf, $cuspaddr, $cusinfo_pos['x'], $invoice_to_pos['y'], 173, 8);
        $cusdaddr_pos = drawTable(&$pdf, $cusdaddr, $cuspaddr_pos['x'], $invoice_to_pos['y'], 174, 8);
        $regnos_pos = drawTable(&$pdf, $regnos, 0, $cusinfo_pos['y'], 520, 2);
        $items_start = $i * 20;
        if ($i) {
            $items_start++;
        }
        if ($items_start >= count($items) - 20) {
            $items_end = count($items) - 1;
        } else {
            $items_end = ($i + 1) * 20;
        }
        $items_print = array();
        for ($j = $items_start; $j <= $items_end; $j++) {
            $items_print[$j] = $items[$j];
        }
        // Adjust the column widths
        $cols = array("Description" => array("width" => 310), "Qty" => array("width" => 50), "Unit Price" => array("width" => 80, "justification" => "right"), "Amount" => array("width" => 80, "justification" => "right"));
        $items_pos = drawTable(&$pdf, $items_print, 0, $regnos_pos['y'] + 2, 520, 22, $cols, 1);
        $comment_pos = drawTable(&$pdf, $comment, 0, $items_pos['y'], 520, 2);
        $sign_pos = drawTable(&$pdf, $sign, 0, $comment_pos['y'], 320, 5);
        $totals_pos = drawTable(&$pdf, $totals, $sign_pos['x'], $comment_pos['y'], 200, 5, $totCols);
    }
    return $pdf->output();
}
コード例 #12
0
 public function testValidate()
 {
     $this->assertSame(false, $this->validate->validate([], 'webmaster.recipe'));
     $this->assertInstanceOf("Illuminate\\Support\\MessageBag", $this->validate->getErrors());
     $this->assertSame(true, $this->validate->validate(['words' => 'testing'], 'search'));
 }
コード例 #13
0
function posInvoices($pdf)
{
    extract($_GET);
    global $set_mainFont;
    $showvat = TRUE;
    $pdf->selectFont($set_mainFont);
    // Validate
    require_lib("validate");
    $v = new Validate();
    $v->isOk($cusnum, "num", 1, 20, "Invalid customer number.");
    // Any errors?
    if ($v->isError()) {
        $err = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $err .= "<li class=error>{$e['msg']}</li>";
        }
        $OUTPUT = $err;
        require "../template.php";
    }
    // Invoice info
    db_conn(PRD_DB);
    $sql = "SELECT * FROM pinvoices WHERE cusnum='{$cusnum}' AND done='y' AND balance>0 AND DIV='" . USER_DIV . "'";
    $invRslt = db_exec($sql) or errDie("Unable to retrieve invoice info.");
    if (pg_num_rows($invRslt) < 1) {
        return $pdf;
    }
    $num_rows = pg_num_rows($invRslt);
    $curr_row = 1;
    while ($inv = pg_fetch_array($invRslt)) {
        $curr_row++;
        // Check if stock was selected
        db_conn(PRD_DB);
        $sql = "SELECT stkid FROM pinv_items WHERE invid='{$inv['invid']}' AND DIV='" . USER_DIV . "'";
        $cRslt = db_exec($sql) or errDie("Unable to retrieve invoice info.");
        if (pg_num_rows($cRslt) < 1) {
            $error = "<li class=err>Invoice number <b>{$inv['invid']}</b> has no items</li>";
            $OUTPUT = $error;
        }
        // Only needs to be blank, we're manually adding text
        $heading = array(array(""));
        // Company info ----------------------------------------------------------
        db_conn("cubit");
        $sql = "SELECT * FROM compinfo WHERE div='" . USER_DIV . "'";
        $ciRslt = db_exec($sql) or errDie("Unable to retrieve company info from Cubit.");
        $comp = pg_fetch_array($ciRslt);
        // Banking information ---------------------------------------------------
        $sql = "SELECT value FROM set WHERE label='BANK_DET' AND div='" . USER_DIV . "'";
        $srslt = db_exec($sql) or errDie("Unable to retrieve banking information from Cubit.");
        $bankid = pg_fetch_result($srslt, 0);
        // Select the default bank account if no accounts were found.
        if (pg_num_rows($srslt) == 0) {
            $bankid = 2;
        }
        db_conn("cubit");
        $sql = "SELECT * FROM bankacct WHERE bankid='{$bankid}' AND div='" . USER_DIV . "'";
        $bnkRslt = db_exec($sql) or errDie("Unable to retrieve the banking information from Cubit.");
        $bnkData = pg_fetch_array($bnkRslt);
        $compinfo = array();
        $compinfo[] = array($comp["addr1"], $comp["paddr1"]);
        $compinfo[] = array(pdf_lstr($comp["addr2"], 35), pdf_lstr($comp["paddr2"], 35));
        $compinfo[] = array(pdf_lstr($comp["addr3"], 35), pdf_lstr($comp["paddr3"], 35));
        $compinfo[] = array(pdf_lstr($comp["addr4"], 35), "{$comp['postcode']}");
        $compinfo[] = array("<b>REG: </b>{$comp['regnum']}", "<b>{$bnkData['bankname']}</b>");
        $compinfo[] = array("<b>VAT REG: </b>{$comp['vatnum']}", "<b>Branch: </b>{$bnkData['branchname']}");
        $compinfo[] = array("<b>Tel:</b> {$comp['tel']}", "<b>Branch Code: </b>{$bnkData['branchcode']}");
        $compinfo[] = array("<b>Fax:</b> {$comp['fax']}", "<b>Acc Num: </b>{$bnkData['accnum']}");
        // Date ------------------------------------------------------------------
        $date = array(array("<b>Date</b>"), array($inv['odate']));
        // Document info ---------------------------------------------------------
        db_conn('cubit');
        $Sl = "SELECT * FROM settings WHERE constant='SALES'";
        $Ri = db_exec($Sl) or errDie("Unable to get settings.");
        $data = pg_fetch_array($Ri);
        $docinfo = array(array("<b>Invoice No:</b> {$inv['invnum']}"), array("<b>Sales Order No:</b> {$inv['ordno']}"));
        if (isset($salespn)) {
            $docinfo[] = array("<b>Sales Person:</b> {$salespn}");
        }
        // Retrieve the customer information -------------------------------------
        db_conn("cubit");
        $sql = "SELECT * FROM customers WHERE cusnum='{$inv['cusnum']}'";
        $cusRslt = db_exec($sql) or errDie("Unable to retrieve customer information from Cubit.");
        $cusData = pg_fetch_array($cusRslt);
        // Customer info ---------------------------------------------------------
        $invoice_to = array(array(""));
        $cusinfo = array(array("<b>{$inv['surname']}</b>"));
        $cusaddr = explode("\n", $cusData['addr1']);
        foreach ($cusaddr as $v) {
            $cusinfo[] = array(pdf_lstr($v, 40));
        }
        $cusinfo[] = array("<b>Account no: </b>{$cusData['accno']}");
        $cuspaddr = array(array("<b>Postal Address</b>"));
        $paddr = explode("\n", $cusData["paddr1"]);
        foreach ($paddr as $addr) {
            $cuspaddr[] = array($addr);
        }
        $cusdaddr = array(array("<b>Delivery Address:</b>"));
        $branchname = "Head Office";
        $cusaddr = explode("\n", $cusData['addr1']);
        $cusdaddr[] = array(pdf_lstr("Branch : {$branchname}", 30));
        $del_addr = explode("\n", $cusData["del_addr1"]);
        foreach ($del_addr as $addr) {
            $cusdaddr[] = array(pdf_lstr($addr, 30));
        }
        // Registration numbers --------------------------------------------------
        $regnos = array(array("<b>VAT No:</b>", "<b>Order No:</b>"), array("{$inv['cusvatno']}", "{$inv['cordno']}"));
        // Items display ---------------------------------------------------------
        $items = array();
        db_conn(PRD_DB);
        $sql = "SELECT * FROM pinv_items WHERE invid='{$inv['invid']}' AND DIV='" . USER_DIV . "'";
        $stkdRslt = db_exec($sql);
        while ($stkd = pg_fetch_array($stkdRslt)) {
            // Get warehouse
            db_conn("exten");
            $sql = "SELECT * FROM warehouses WHERE whid='{$stkd['whid']}' AND DIV='" . USER_DIV . "'";
            $whRslt = db_exec($sql);
            $wh = pg_fetch_array($whRslt);
            // Get stock in this warehouse
            db_conn("cubit");
            $sql = "SELECT * FROM stock WHERE stkid='{$stkd['stkid']}' AND DIV='" . USER_DIV . "'";
            $stkRslt = db_exec($sql);
            $stk = pg_fetch_array($stkRslt);
            $sp = "";
            // Check Tax Excempt
            db_conn("cubit");
            $sql = "SELECT zero FROM vatcodes WHERE id='{$stkd['vatcode']}'";
            $zRslt = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit.");
            $vatex = pg_fetch_result($zRslt, 0);
            if ($vatex == "Yes") {
                $ex = "#";
            } else {
                $ex = "";
            }
            $sql = "SELECT * FROM vatcodes WHERE id='{$stkd['vatcode']}'";
            $runsql = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit.");
            if (pg_numrows($runsql) < 1) {
                return "Invalid VAT code entered";
            }
            $vd = pg_fetch_array($runsql);
            if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") {
                $showvat = FALSE;
            }
            // keep track of discounts
            //$disc += $stkd['disc'];
            if ($stkd["account"] > 0) {
                $description = $stkd["description"];
            } else {
                $description = $stk["stkdes"];
            }
            // Remove any new lines from the description
            $ar_desc = explode("\n", $description);
            $description = implode(" ", $ar_desc);
            $items[] = array("Code" => makewidth($pdf, 75, 12, $stk['stkcod']), "Description" => makewidth($pdf, 175, 12, $ex . $description), "Qty" => $stkd['qty'], "Unit Price" => CUR . $stkd['unitcost'], "Unit Discount" => CUR . $stkd['disc'], "Amount" => CUR . $stkd['amt']);
        }
        // Comment ---------------------------------------------------------------
        $comment = array(array("<i>VAT Exempt Indicator : #</i>"), array($inv["comm"]));
        // Box for signature -----------------------------------------------------
        $sign = array(array("<b>Terms:</b> {$inv['terms']} days"), array(''), array("<b>Received in good order by:</b> ____________________"), array(''), array("                                      <b>Date:</b> ____________________"));
        // Totals ----------------------------------------------------------------
        if (!isset($showvat)) {
            $showvat = TRUE;
        }
        if ($showvat == TRUE) {
            $vat14 = AT14;
        } else {
            $vat14 = "";
        }
        $totals = array(array("1" => "<b>Subtotal:</b> ", "2" => CUR . "{$inv['subtot']}"), array("1" => "<b>Trade Discount:</b> ", "2" => CUR . "{$inv['discount']}"), array("1" => "<b>Delivery Charge:</b> ", "2" => CUR . "{$inv['delivery']}"), array("1" => "<b>VAT {$vat14}:</b> ", "2" => CUR . "{$inv['vat']}"), array("1" => "<b>Total Incl VAT:</b> ", "2" => CUR . "{$inv['total']}"));
        $totCols = array("1" => array("width" => 90), "2" => array("justification" => "right"));
        $ic = 0;
        while (++$ic * 22 < count($items)) {
        }
        // Draw the pages, determine by the amount of items how many pages
        // if items > 20 start a new page
        $items_print = array();
        for ($i = 0; $i < $ic; $i++) {
            if ($i) {
                $pdf->ezNewPage();
            }
            // Page number -------------------------------------------------------
            $pagenr = array(array("<b>Page number</b>"), array($i + 1));
            // Heading
            $heading_pos = drawTable(&$pdf, $heading, 0, 0, 520, 5);
            drawText(&$pdf, "<b>{$comp['compname']}</b>", 18, 0, $heading_pos['y'] / 2 + 6);
            drawText(&$pdf, "<b>Tax Invoice</b>", 20, $heading_pos['x'] - 120, $heading_pos['y'] / 2 + 9);
            $compinfo_pos = drawTable(&$pdf, $compinfo, 0, $heading_pos['y'], 320, 8);
            $date_pos = drawTable(&$pdf, $date, $compinfo_pos['x'], $heading_pos['y'], 100, 4);
            $pagenr_pos = drawTable(&$pdf, $pagenr, $date_pos['x'], $heading_pos['y'], 100, 4);
            $docinfo_pos = drawTable(&$pdf, $docinfo, $compinfo_pos['x'], $date_pos['y'], 200, 4);
            $invoice_to_pos = drawTable(&$pdf, $invoice_to, 0, $compinfo_pos['y'], 520, 2);
            drawText(&$pdf, "<b>Tax Invoice to:</b>", 12, 520 / 2 - 45, $invoice_to_pos['y'] - 7);
            $cusinfo_pos = drawTable(&$pdf, $cusinfo, 0, $invoice_to_pos['y'], 173, 8);
            $cuspaddr_pos = drawTable(&$pdf, $cuspaddr, $cusinfo_pos['x'], $invoice_to_pos['y'], 173, 8);
            $cusdaddr_pos = drawTable(&$pdf, $cusdaddr, $cuspaddr_pos['x'], $invoice_to_pos['y'], 174, 8);
            $regnos_pos = drawTable(&$pdf, $regnos, 0, $cusinfo_pos['y'], 520, 2);
            $items_start = $i * 22;
            if ($i) {
                $items_start++;
            }
            if ($items_start >= count($items) - 22) {
                $items_end = count($items) - 1;
            } else {
                $items_end = ($i + 1) * 22;
            }
            $items_print = array();
            for ($j = $items_start; $j <= $items_end; $j++) {
                $items_print[$j] = $items[$j];
            }
            $cols = array("Code" => array("width" => 80), "Description" => array("width" => 180), "Qty" => array("width" => 33), "Unit Price" => array("width" => 80, "justification" => "right"), "Unit Discount" => array("width" => 67, "justification" => "right"), "Amount" => array("width" => 80, "justification" => "right"));
            $items_pos = drawTable(&$pdf, $items_print, 0, $regnos_pos['y'] + 2, 520, 22, $cols, 1);
            $comment_pos = drawTable(&$pdf, $comment, 0, $items_pos['y'], 520, 2);
            $sign_pos = drawTable(&$pdf, $sign, 0, $comment_pos['y'], 320, 5);
            $totals_pos = drawTable(&$pdf, $totals, $sign_pos['x'], $comment_pos['y'], 200, 5, $totCols);
        }
        if ($curr_row < $num_rows) {
            $pdf->ezNewPage();
        }
    }
    return $pdf;
}
コード例 #14
0
ファイル: Update.php プロジェクト: Wicloz/UniversityWebsite
 public static function adminDeleteItem()
 {
     if (Users::isAdmin()) {
         $validation = new Validate();
         $validation->check($_POST, array('action' => array('name' => 'Action', 'required' => true, 'wildcard' => 'admin_item_delete'), 'table' => array('name' => 'Table Name', 'required' => true), 'id' => array('name' => 'Entry ID', 'required' => true)));
         if ($validation->passed()) {
             DB::instance()->delete(Input::get('table'), array("", "id", "=", Input::get('id')));
             if (Input::get('table') === Users::safeSid() . '_assignments') {
                 Calendar::deleteAssignment(Input::get('id'));
             }
             Notifications::addSuccess('Entry deleted!');
             Redirect::to('?page=home');
         } else {
             Notifications::addValidationFail($validation->getErrors());
         }
     } else {
         Redirect::error(403);
     }
 }
コード例 #15
0
function invNoteDetails($_GET)
{
    extract($_GET);
    global $set_mainFont;
    $showvat = TRUE;
    $pdf =& new Cezpdf();
    $pdf->selectFont($set_mainFont);
    // Validate
    require_lib("validate");
    $v = new Validate();
    $v->isOk($invid, "num", 1, 20, "Invalid invoice number.");
    $v->isOk($prd, "num", 1, 9, "Invalid period.");
    // Any errors?
    if ($v->isError()) {
        $err = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $err .= "<li class='err'>{$e['msg']}</li>";
        }
        $confirm = "<p><input type='button' onClick='javascript.history.back();' value='&laquo; Correct Submission'></p>";
        $OUTPUT = $confirm;
        require "../template.php";
    }
    // Invoice info
    db_conn($prd);
    $sql = "SELECT * FROM inv_notes WHERE noteid='{$invid}' AND DIV='" . USER_DIV . "'";
    $invRslt = db_exec($sql) or errDie("Unable to retrieve invoice info.");
    if (pg_num_rows($invRslt) < 1) {
        return "<li class='err'>Not found</li>";
    }
    $inv = pg_fetch_array($invRslt);
    db_conn("cubit");
    $sql = "SELECT symbol FROM currency WHERE fcid='{$inv['fcid']}'";
    $curRslt = db_exec($sql) or errDie("Unable to retrieve currency from Cubit.");
    $curr = pg_fetch_result($curRslt, 0);
    if (!$curr) {
        $curr = CUR;
    }
    // Check if stock was selected
    db_conn("cubit");
    $sql = "SELECT stkid FROM inv_items WHERE invid='{$invid}' AND DIV='" . USER_DIV . "'";
    $cRslt = db_exec($sql) or errDie("Unable to retrieve invoice info.");
    if (pg_num_rows($cRslt) < 1) {
        $error = "<li class='err'>Invoice number <b>{$invid}</b> has no items</li>";
        $OUTPUT = $error;
    }
    // Only needs to be blank, we're manually adding text
    $heading = array(array(""));
    // Company info ----------------------------------------------------------
    db_conn("cubit");
    $sql = "SELECT * FROM compinfo WHERE div='" . USER_DIV . "'";
    $ciRslt = db_exec($sql) or errDie("Unable to retrieve company info from Cubit.");
    $comp = pg_fetch_array($ciRslt);
    // Banking information ---------------------------------------------------
    //	$bnkData = qryBankAcct(getdSetting("BANK_DET"));
    $bnkData = qryBankAcct($inv['bankid']);
    $compinfo = array();
    $compinfo[] = array(pdf_lstr($comp["addr1"], 35), pdf_lstr($comp["paddr1"], 35));
    $compinfo[] = array(pdf_lstr($comp["addr2"], 35), pdf_lstr($comp["paddr2"], 35));
    $compinfo[] = array(pdf_lstr($comp["addr3"], 35), pdf_lstr($comp["paddr3"], 35));
    $compinfo[] = array(pdf_lstr($comp["addr4"], 35), "{$comp['postcode']}");
    $compinfo[] = array("<b>REG: </b>{$comp['regnum']}", "<b>{$bnkData['bankname']}</b>");
    $compinfo[] = array("<b>VAT REG: </b>{$comp['vatnum']}", "<b>Branch: </b>{$bnkData['branchname']}");
    $compinfo[] = array("<b>Tel:</b> {$comp['tel']}", "<b>Branch Code: </b>{$bnkData['branchcode']}");
    $compinfo[] = array("<b>Fax:</b> {$comp['fax']}", "<b>Acc Num: </b>{$bnkData['accnum']}");
    // Date ------------------------------------------------------------------
    $date = array(array("<b>Date</b>"), array($inv['odate']));
    // Document info ---------------------------------------------------------
    db_conn('cubit');
    $Sl = "SELECT * FROM cubit.settings WHERE constant='SALES'";
    $Ri = db_exec($Sl) or errDie("Unable to get settings.");
    $data = pg_fetch_array($Ri);
    if ($data['value'] == "Yes") {
        $sp = "<b>Sales Person: </b>{$inv['salespn']}";
    } else {
        $sp = "";
    }
    // Retrieve the customer information -------------------------------------
    db_conn("cubit");
    $sql = "SELECT * FROM customers WHERE cusnum='{$inv['cusnum']}'";
    $cusRslt = db_exec($sql) or errDie("Unable to retrieve customer information from Cubit.");
    $cusData = pg_fetch_array($cusRslt);
    $docinfo = array(array("<b>Credit Note No:</b> {$inv['notenum']}"), array("<b>Invoice No:</b> {$inv['invnum']}"), array("<b>Sales Order No:</b> {$inv['ordno']}"), array("{$sp}"));
    // Customer info ---------------------------------------------------------
    $invoice_to = array(array(""));
    $cusinfo = array(array("<b>{$inv['surname']}</b>"));
    $addr1 = explode("\n", $cusData["addr1"]);
    foreach ($addr1 as $addr) {
        $cusinfo[] = array($addr);
    }
    $cuspaddr = array(array("<b>Postal Address</b>"));
    $paddr = explode("\n", $cusData["paddr1"]);
    foreach ($paddr as $addr) {
        $cuspaddr[] = array($addr);
    }
    $cusdaddr = array(array("<b>Delivery Address:</b>"));
    // Temp
    //	$inv["branch"] = 0;
    if ($inv['branch'] == 0) {
        $branchname = "Head Office";
        $cusaddr = explode("\n", $cusData['addr1']);
    } else {
        $get_addr = "SELECT * FROM customer_branches WHERE id = '{$inv['branch']}' LIMIT 1";
        $run_addr = db_exec($get_addr);
        if (pg_numrows($run_addr) < 1) {
            $cusaddr = array();
            $branchname = "Head Office";
        } else {
            $barr = pg_fetch_array($run_addr);
            $cusaddr = explode("\n", $barr['branch_descrip']);
            $branchname = $barr['branch_name'];
            $cusData["del_addr1"] = $barr['branch_descrip'];
        }
    }
    $cusdaddr[] = array(pdf_lstr("Branch : {$branchname}", 30));
    $del_addr = explode("\n", $cusData["del_addr1"]);
    foreach ($del_addr as $addr) {
        $cusdaddr[] = array(pdf_lstr($addr, 30));
    }
    // Registration numbers --------------------------------------------------
    $regnos = array(array("<b>VAT No:</b>", "<b>Order No:</b>"), array("{$inv['cusvatno']}", "{$inv['cordno']}"));
    // Items display ---------------------------------------------------------
    $items = array();
    db_conn($prd);
    $sql = "SELECT * FROM inv_note_items WHERE noteid='{$invid}' AND DIV='" . USER_DIV . "'";
    $stkdRslt = db_exec($sql);
    $nsub = 0;
    while ($stkd = pg_fetch_array($stkdRslt)) {
        // Get warehouse
        db_conn("exten");
        $sql = "SELECT * FROM warehouses WHERE whid='{$stkd['whid']}' AND DIV='" . USER_DIV . "'";
        $whRslt = db_exec($sql);
        $wh = pg_fetch_array($whRslt);
        // Get stock in this warehouse
        db_conn("cubit");
        $sql = "SELECT * FROM stock WHERE stkid='{$stkd['stkid']}' AND DIV='" . USER_DIV . "'";
        $stkRslt = db_exec($sql);
        $stk = pg_fetch_array($stkRslt);
        $sp = "";
        // Check Tax Excempt
        db_conn("cubit");
        $sql = "SELECT zero FROM vatcodes WHERE id='{$stkd['vatcode']}'";
        $zRslt = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit.");
        $vatex = pg_fetch_result($zRslt, 0);
        if ($vatex == "Yes") {
            $ex = "#";
        } else {
            $ex = "";
        }
        $sql = "SELECT * FROM vatcodes WHERE id='{$stkd['vatcode']}'";
        //	print $sql;
        $runsql = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit.");
        if (pg_numrows($runsql) < 1) {
            //return "Invalid VAT code entered.";
        }
        $vd = pg_fetch_array($runsql);
        if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") {
            $showvat = FALSE;
        }
        $selamt = sprint($stkd['amt'] / $stkd['qty']);
        $nsub += sprint($stkd["amt"]);
        // keep track of discounts
        //$disc += $stkd['disc'];
        // Stock or non stock description?
        if (!empty($stkd["description"])) {
            $description = $stkd["description"];
        } else {
            $description = $stk["stkdes"];
        }
        $description = explode("\n", $description);
        $description = implode(" ", $description);
        $items[] = array("Stock Code" => makewidth($pdf, 80, 12, $stk["stkcod"]), "Description" => makewidth($pdf, 280, 12, $ex . $description), "Qty Returned" => $stkd['qty'], "Amount" => $stkd['amt']);
    }
    // Comment ---------------------------------------------------------------
    $comment = array(array("<i>VAT Exempt Indicator : #</i>"), array($inv["comm"]));
    // Box to sign in --------------------------------------------------------
    $sign = array(array("<i>Thank you for your support</i>"), array(''), array("<b>Received in good order by:</b> ____________________"), array(''), array("                                      <b>Date:</b> ____________________"));
    // Totals ----------------------------------------------------------------
    if (!isset($showvat)) {
        $showvat = TRUE;
    }
    if ($showvat == TRUE) {
        $vat14 = AT14;
    } else {
        $vat14 = "";
    }
    $totals = array(array("1" => "<b>Subtotal:</b> ", "2" => $curr . sprint($nsub, 2)), array("1" => "<b>Trade Discount:</b> ", "2" => $curr . "{$inv['traddisc']}"), array("1" => "<b>Delivery Charge:</b> ", "2" => $curr . "{$inv['delchrg']}"), array("1" => "<b>VAT {$vat14}:</b> ", "2" => $curr . "{$inv['vat']}"), array("1" => "<b>Total Incl VAT:</b> ", "2" => $curr . "{$inv['total']}"));
    $totCols = array("1" => array("width" => 90), "2" => array("justification" => "right"));
    $ic = 0;
    while (++$ic * 20 < count($items)) {
    }
    // Draw the pages, determine by the amount of items how many pages
    // if items > 20 start a new page
    $items_print = array();
    for ($i = 0; $i < $ic; $i++) {
        if ($i) {
            $pdf->ezNewPage();
        }
        // Page number -------------------------------------------------------
        $pagenr = array(array("<b>Page number</b>"), array($i + 1));
        // Heading
        $heading_pos = drawTable(&$pdf, $heading, 0, 0, 520, 5);
        drawText(&$pdf, "<b>{$comp['compname']}</b>", 18, 18, $heading_pos['y'] / 2 + 6);
        drawText(&$pdf, "<b>Tax Credit Note</b>", 18, $heading_pos['x'] - 140, $heading_pos['y'] / 2 + 9);
        // Should we display reprint on the invoice
        if ($type == "invnotereprint") {
            drawText(&$pdf, "<b>Reprint</b>", 12, $heading_pos['x'] - 70, $heading_pos['y'] / 2 + 22);
        }
        $compinfo_pos = drawTable(&$pdf, $compinfo, 0, $heading_pos['y'], 320, 8);
        $date_pos = drawTable(&$pdf, $date, $compinfo_pos['x'], $heading_pos['y'], 100, 4);
        $pagenr_pos = drawTable(&$pdf, $pagenr, $date_pos['x'], $heading_pos['y'], 100, 4);
        $docinfo_pos = drawTable(&$pdf, $docinfo, $compinfo_pos['x'], $date_pos['y'], 200, 4);
        $invoice_to_pos = drawTable(&$pdf, $invoice_to, 0, $compinfo_pos['y'], 520, 2);
        drawText(&$pdf, "<b>Credit Note to:</b>", 12, 520 / 2 - 45, $invoice_to_pos['y'] - 7);
        $cusinfo_pos = drawTable(&$pdf, $cusinfo, 0, $invoice_to_pos['y'], 173, 8);
        $cuspaddr_pos = drawTable(&$pdf, $cuspaddr, $cusinfo_pos['x'], $invoice_to_pos['y'], 173, 8);
        $cusdaddr_pos = drawTable(&$pdf, $cusdaddr, $cuspaddr_pos['x'], $invoice_to_pos['y'], 174, 8);
        $regnos_pos = drawTable(&$pdf, $regnos, 0, $cusinfo_pos['y'], 520, 2);
        $items_start = $i * 22;
        if ($i) {
            $items_start++;
        }
        if ($items_start >= count($items) - 22) {
            $items_end = count($items) - 1;
        } else {
            $items_end = ($i + 1) * 22;
        }
        $items_print = array();
        for ($j = $items_start; $j <= $items_end; $j++) {
            $items_print[$j] = $items[$j];
        }
        $cols = array("Stock Code" => array("width" => 80), "Description" => array("width" => 280), "Qty Returned" => array("width" => 80), "Amount" => array("width" => 80, "justification" => "right"));
        $items_pos = drawTable(&$pdf, $items_print, 0, $regnos_pos['y'] + 2, 520, 23, $cols, 1);
        $comment_pos = drawTable(&$pdf, $comment, 0, $items_pos['y'], 520, 2);
        $sign_pos = drawTable(&$pdf, $sign, 0, $comment_pos['y'], 320, 5);
        $totals_pos = drawTable(&$pdf, $totals, $sign_pos['x'], $comment_pos['y'], 200, 5, $totCols);
        $pdf->addText(20, 34, 6, 'Cubit Accounting');
    }
    $pdf->ezStream();
}