extension=php_interbase.dll
extension=php_interbase.so
Note for Win32 / Win64 users For this extension of the Windows PATH system variable, the DLL files fbclient.dll or gds32.dll must be available. Although copying DLL files from the PHP directory to the Windows system folder also solves the problem (because the default system directory is in the PATH variable), this is not recommended. This extension requires the following files in the PATH variable: fbclient.dll or gds32.dll. |
apt-get install php5-firebird rpm –ihv php5-firebird yum install php70w-interbase zypper install php5-firebird
$db = 'localhost:example'; $username = 'SYSDBA'; $password = 'masterkey'; // $dbh = ibase_connect($db, $username, $password); $sql = 'SELECT login, email FROM users'; // $rc = ibase_query($dbh, $sql); // while ($row = ibase_fetch_object($rc)) { echo $row->email, "\n"; } // ibase_free_result($rc); // ibase_close($dbh);
Attention! Many ibase functions allow you not to pass the connection identifier (transaction, prepared request) into them. In this case, these functions use the identifier of the last established connection (started transaction). I do not recommend this, especially if your web application can use more than one connection. |
$sql = 'SELECT login, email FROM users WHERE id=?'; $id = 1; // $rc = ibase_query($dbh, $sql, $id); // if ($row = ibase_fetch_object($rc)) { echo $row->email, "\n"; } // ibase_free_result($rc);
$sql = 'SELECT login, email FROM users WHERE id=?'; // $sth = ibase_prepare($dbh, $sql); $id = 1; // $rc = ibase_execute($sth, $id); // if ($row = ibase_fetch_object($rc)) { echo $row->email, "\n"; } // ibase_free_result($rc); // ibase_free_query($sth);
$sql = 'INSERT INTO users(login, email) VALUES(?, ?)'; // $sth = ibase_prepare($dbh, $sql); $users = [["user1", "user1@gmail.com"], ["user2", "user2@gmail.com"]]; // foreach ($users as $user)) { ibase_execute($sth, $user[0], $user[1]); } // ibase_free_query($sth);
function fb_execute ($stmt, $data) { if (!is_array($data)) return ibase_execute($stmt, $data); array_unshift($data, $stmt); $rc = call_user_func_array('ibase_execute', $data); return $rc; }
Comment. The default transaction parameters are suitable for most cases. The fact is that the connection to the database, as well as all the resources associated with it, is a maximum until the end of the PHP script. Even if you use persistent connections, all associated resources will be released after calling the function ibase_close. Despite what has been said, I strongly recommend completing all allocated resources explicitly by calling the appropriate ibase_ functions. I strongly do not recommend using the functions ibase_commit_ret and ibase_rollback_ret, since it does not make sense. COMMIT RETAIN and ROLLBACK RETAIN were introduced in order to keep cursors open on desktop applications when a transaction is completed. |
$sql = 'INSERT INTO users(login, email) VALUES(?, ?)'; // $sth = ibase_prepare($dbh, $sql); $users = [["user1", "user1@gmail.com"], ["user2", "user2@gmail.com"]]; $trh = ibase_trans($dbh, IBASE_WRITE | IBASE_CONCURRENCY | IBASE_WAIT); try { // foreach ($users as $user)) { $r = ibase_execute($sth, $user[0], $user[1]); if ($r === false) { // , $err_msg = ibase_errmsg(); throw new \Exception($err_msg); } } ibase_commit($trh); } catch(\Exception $e) { ibase_rollback($trh); echo $e->getMessage(); } // ibase_free_query($sth);
Attention! ibase functions do not throw an exception in case of an error. Some functions return false if an error occurred. I draw your attention that the result must be compared with false by the strict comparison operator ===. Potentially, an error may occur in the call field of any ibase function. The error text can be found using the ibase_errmsg function. The error code can be obtained using the ibase_errcode function. |
extension=php_pdo.dll
Comment This step is optional for versions of PHP 5.3 and higher, since PDOs no longer require DLLs to work. |
extension=php_pdo.dll extension=php_pdo_firebird.dll
apt-get install php5-firebird rpm –ihv php5-firebird yum install php70w-firebird zypper install php5-firebird
$dsn = 'firebird:dbname=localhost:example;charset=utf8;'; $username = 'SYSDBA'; $password = 'masterkey'; try { // $dbh = new \PDO($dsn, $username, $password, [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]); $sql = 'SELECT login, email FROM users'; // $query = $dbh->query($sql); // while ($row = $query->fetch(\PDO::FETCH_OBJ)) { echo $row->email, "\n"; } $query->closeCursor(); // } catch (\PDOException $e) { echo $e->getMessage(); }
In order for PDO to use persistent connections, you must pass PDO :: ATTR_PERSISTENT => true to the PDO constructor in the property array. |
$dsn = 'firebird:dbname=localhost:example;charset=utf8;'; $username = 'SYSDBA'; $password = 'masterkey'; try { // $dbh = new \PDO($dsn, $username, $password, [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]); $sql = 'INSERT INTO users(login, email) VALUES(?, ?)'; $users = [ ["user1", "user1@gmail.com"], ["user2", "user2@gmail.com"] ]; // $query = $dbh->prepare($sql); // foreach ($users as $user)) { $query->execute($user); } } catch (\PDOException $e) { echo $e->getMessage(); }
$dsn = 'firebird:dbname=localhost:example;charset=utf8;'; $username = 'SYSDBA'; $password = 'masterkey'; try { // $dbh = new \PDO($dsn, $username, $password, [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]); $sql = 'INSERT INTO users(login, email) VALUES(:login, :email)'; $users = [ [":login" => "user1", ":email" => "user1@gmail.com"], [":login" => "user2", ":email" => "user2@gmail.com"] ]; // $query = $dbh->prepare($sql); // foreach ($users as $user)) { $query->execute($user); } } catch (\PDOException $e) { echo $e->getMessage(); }
Comment To support the named parameters, the PDO prepares the request and replaces parameters of the form: paramname with “?”, While maintaining an array of correspondences between the name of the parameter and the numbers of its positions in the request. For this reason, the EXECUTE BLOCK statement will not work if variables marked with a colon are used inside it. At the moment, there is no way to make the PDO work with the EXECUTE BLOCK operator otherwise, for example, to specify an alternative prefix of parameters, as is done in some access components. |
$dsn = 'firebird:dbname=localhost:example;charset=utf8;'; $username = 'SYSDBA'; $password = 'masterkey'; try { // $dbh = new \PDO($dsn, $username, $password, [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]); $sql = 'INSERT INTO users(login, email) VALUES(:login, :email)'; $users = [ ["user1", "user1@gmail.com"], ["user2", "user2@gmail.com"] ]; // $query = $dbh->prepare($sql); // foreach ($users as $user)) { $query->bindValue(":login", $user[0]); $query->bindValue(":email", $user[1]); $query->execute(); } } catch (\PDOException $e) { echo $e->getMessage(); }
Attention The numbering of unnamed parameters in the bindParam and bindValue methods starts with 1. |
$dsn = 'firebird:dbname=localhost:example;charset=utf8;'; $username = 'SYSDBA'; $password = 'masterkey'; try { // $dbh = new \PDO($dsn, $username, $password, [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]); $sql = 'INSERT INTO users(login, email) VALUES(?, ?)'; $users = [ ["user1", "user1@gmail.com"], ["user2", "user2@gmail.com"] ]; // $query = $dbh->prepare($sql); // foreach ($users as $user)) { $query->bindValue(1, $user[0]); $query->bindValue(2, $user[1]); $query->execute(); } } catch (\PDOException $e) { echo $e->getMessage(); }
$dsn = 'firebird:dbname=localhost:example;charset=utf8;'; $username = 'SYSDBA'; $password = 'masterkey'; try { // $dbh = new \PDO($dsn, $username, $password, [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]); // $dbh->beginTransaction(); // $users_stmt = $dbh->prepare('SELECT login, email FROM old_users'); $users_stmt->execute(); $users = $users_stmt->fetchAll(\PDO::FETCH_OBJECT); $users_stmt->closeCursor(); // $sql = 'INSERT INTO users(login, email) VALUES(?, ?)'; // $query = $dbh->prepare($sql); // foreach ($users as $user)) { $query->bindValue(1, $user->LOGIN); $query->bindValue(2, $user->EMAIL]); $query->execute(); } // $dbh->commit(); } catch (\PDOException $e) { // , if ($dbh && $dbh->inTransaction()) $dbh->rollback(); echo $e->getMessage(); }
$dbh = new \PDO($dsn, $username, $password); $dbh->setAttribute(\PDO::ATTR_AUTOCOMMIT, false); $dbh->exec("SET TRANSACTION READ ONLY ISOLATION LEVEL READ COMMITTED NO WAIT"); // // …. $dbh->exec("COMMIT"); $dbh->setAttribute(\PDO::ATTR_AUTOCOMMIT, true);
Opportunity | Firebird / Interbase extension | PDO |
---|---|---|
Programming paradigm | Functional | Object oriented |
Supported DB | Firebird, Interbase, Yaffil and other Interbase clones. | Any database for which there is a PDO driver, including Firebird. |
Work with query parameters | Only unnamed parameters are not very convenient to work, because a function with a variable number of arguments is used. | It is possible to work with both named and unnamed parameters. It is very convenient to work, however, some Firebird features (EXECUTE BLOCK statement) do not work. |
Error processing | Checking the result of the ibase_errmsg, ibase_errcode functions. An error may occur after calling any ibase function, and an exception will not be raised. | It is possible to set the mode in which any error will lead to the excitation of the exception. |
Transaction management | Allows you to set transaction parameters. | It does not give the opportunity to set the parameters of the transaction. There is a workaround through the execution of the SET TRANSACTION statement. |
Interbase / Firebird specific features | Service API (backup, restore, ..), . | , , SQL. |
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') === 'aa96f26c2b67226a324c27919f1eb05f21c248b987e6195cad9690d5c1ff713d53020a02ac8c217dbf90a7eacc9d141d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"
echo @php "%~dp0composer.phar" %*>composer.bat
composer global require "laravel/installer"
laravel new fbexample
… "repositories": [ { "type": "package", "package": { "version": "dev-master", "name": "sim1984/laravel-firebird", "source": { "url": "https://github.com/sim1984/laravel-firebird", "type": "git", "reference": "master" }, "autoload": { "classmap": [""] } } } ], …
"zofe/rapyd": "2.2.*", "sim1984/laravel-firebird": "dev-master"
composer update
php artisan vendor:publish
Zofe\Rapyd\RapydServiceProvider::class, Firebird\FirebirdServiceProvider::class,
'firebird' => [ 'driver' => 'firebird', 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '3050'), 'database' => env('DB_DATABASE', 'examples'), 'username' => env('DB_USERNAME', 'SYSDBA'), 'password' => env('DB_PASSWORD', 'masterkey'), 'charset' => env('DB_CHARSET', 'UTF8'), 'engine_version' => '3.0.0', ],
'default' => env('DB_CONNECTION', 'firebird'),
DB_CONNECTION=firebird DB_HOST=localhost DB_PORT=3050 DB_DATABASE=examples DB_USERNAME=SYSDBA DB_PASSWORD=masterkey
'fields' => [ 'attributes' => ['class' => 'form-control'], 'date' => [ 'format' => 'dmY', ], 'datetime' => [ 'format' => 'dmY H:i:s', 'store_as' => 'Ymd H:i:s', ], ],
php artisan make:model Customer
namespace App; use Firebird\Eloquent\Model; class Customer extends Model { /** * , * * @var string */ protected $table = 'CUSTOMER'; /** * * * @var string */ protected $primaryKey = 'CUSTOMER_ID'; /** * * * @var bool */ public $timestamps = false; /** * * @var string */ protected $sequence = 'GEN_CUSTOMER_ID'; }
namespace App; use Firebird\Eloquent\Model; class Product extends Model { /** * , * * @var string */ protected $table = 'PRODUCT'; /** * * * @var string */ protected $primaryKey = 'PRODUCT_ID'; /** * * * @var bool */ public $timestamps = false; /** * * @var string */ protected $sequence = 'GEN_PRODUCT_ID'; }
namespace App; use Firebird\Eloquent\Model; class Invoice extends Model { /** * , * * @var string */ protected $table = 'INVOICE'; /** * * * @var string */ protected $primaryKey = 'INVOICE_ID'; /** * * * @var bool */ public $timestamps = false; /** * * * @var string */ protected $sequence = 'GEN_INVOICE_ID'; /** * * * @return \App\Customer */ public function customer() { return $this->belongsTo('App\Customer', 'CUSTOMER_ID'); } /** * * @return \App\InvoiceLine[] */ public function lines() { return $this->hasMany('App\InvoiceLine', 'INVOICE_ID'); } /** * */ public function pay() { $connection = $this->getConnection(); $attributes = $this->attributes; $connection->executeProcedure('SP_PAY_FOR_INOVICE', [$attributes['INVOICE_ID']]); } }
namespace App; use Firebird\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; class InvoiceLine extends Model { /** * , * * @var string */ protected $table = 'INVOICE_LINE'; /** * * * @var string */ protected $primaryKey = 'INVOICE_LINE_ID'; /** * * * @var bool */ public $timestamps = false; /** * * * @var string */ protected $sequence = 'GEN_INVOICE_LINE_ID'; /** * * * @var array */ protected $appends = ['SUM_PRICE']; /** * * * @return \App\Product */ public function product() { return $this->belongsTo('App\Product', 'PRODUCT_ID'); } /** * * * @return double */ public function getSumPriceAttribute() { return $this->SALE_PRICE * $this->QUANTITY; } /** * * , .. * * @param \Illuminate\Database\Eloquent\Builder $query * @param array $options * @return bool */ protected function performInsert(Builder $query, array $options = []) { if ($this->fireModelEvent('creating') === false) { return false; } $connection = $this->getConnection(); $attributes = $this->attributes; $connection->executeProcedure('SP_ADD_INVOICE_LINE', [ $attributes['INVOICE_ID'], $attributes['PRODUCT_ID'], $attributes['QUANTITY'] ]); // We will go ahead and set the exists property to true, so that it is set when // the created event is fired, just in case the developer tries to update it // during the event. This will allow them to do so and run an update here. $this->exists = true; $this->wasRecentlyCreated = true; $this->fireModelEvent('created', false); return true; } /** * * , .. * * @param \Illuminate\Database\Eloquent\Builder $query * @param array $options * @return bool */ protected function performUpdate(Builder $query, array $options = []) { $dirty = $this->getDirty(); if (count($dirty) > 0) { // If the updating event returns false, we will cancel the update operation so // developers can hook Validation systems into their models and cancel this // operation if the model does not pass validation. Otherwise, we update. if ($this->fireModelEvent('updating') === false) { return false; } $connection = $this->getConnection(); $attributes = $this->attributes; $connection->executeProcedure('SP_EDIT_INVOICE_LINE', [ $attributes['INVOICE_LINE_ID'], $attributes['QUANTITY'] ]); $this->fireModelEvent('updated', false); } } /** * * , .. * * @return void */ protected function performDeleteOnModel() { $connection = $this->getConnection(); $attributes = $this->attributes; $connection->executeProcedure('SP_DELETE_INVOICE_LINE', [$attributes['INVOICE_LINE_ID']]); } }
$customers = DB::table('CUSTOMER')->get();
DB::table('users') ->join('contacts', function ($join) { $join->on('users.id', '=', 'contacts.user_id')->orOn(...); }) ->get();
$customers = Customer::all();
$customers = App\Customer::select() ->orderBy('name') ->take(20) ->get();
$lines = Invoice::find(1)->lines;
$flight = new Flight; $flight->name = $request->name; $flight->save();
$flight = App\Flight::find(1); $flight->name = 'New Flight Name'; $flight->save();
$flight = App\Flight::find(1); $flight->delete();
App\Flight::destroy(1);
DB::transaction(function () { // $line = new App\InvoiceLine(); $line->CUSTOMER_ID = 45; $line->PRODUCT_ID = 342; $line->QUANTITY = 10; $line->COST = 12.45; $line->save(); // $invoice = App\Invoice::find($line->CUSTOMER_ID); $invoice->INVOICE_SUM += $line->SUM_PRICE; $invoice->save(); });
Route::get('/', function () { return 'Hello World'; }); Route::post('foo/bar', function () { return 'Hello World'; });
Route::match(['get', 'post'], 'foo/bar', function () { return 'Hello World'; });
Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) { // });
/* * */ namespace App\Http\Controllers; use App\Http\Controllers\Controller; use App\Customer; class CustomerController extends Controller { /** * * * @return Response */ public function showCustomers() { // 20 // $customers = Customer::select() ->orderBy('NAME') ->take(20) ->get(); var_dump($customers); } }
Route::get('/customers', 'CustomerController@showCustomers');
/* * */ namespace App\Http\Controllers; use App\Http\Controllers\Controller; use App\Customer; class CustomerController extends Controller { /** * * * @return Response */ public function showCustomers() { // $filter = \DataFilter::source(new Customer); // $filter->add('NAME', '', 'text'); // $filter->submit(''); // $filter->reset(''); // $grid = \DataGrid::source($filter); // // , , $grid->add('NAME', '', true); $grid->add('ADDRESS', ''); $grid->add('ZIPCODE', ''); $grid->add('PHONE', ''); // , $grid->edit('/customer/edit', '', 'show|modify|delete'); // $grid->link('/customer/edit', " ", "TR"); // $grid->orderBy('NAME', 'asc'); // $grid->paginate(10); // customer return view('customer', compact('filter', 'grid')); } /** * , * * @return Response */ public function editCustomer() { if (\Input::get('do_delete') == 1) return "not the first"; // $edit = \DataEdit::source(new Customer()); // switch ($edit->status) { case 'create': $edit->label(' '); break; case 'modify': $edit->label(' '); break; case 'do_delete': $edit->label(' '); break; case 'show': $edit->label(' '); // $edit->link('customers', '', 'TR'); break; } // , // $edit->back('insert|update|do_delete', 'customers'); // , // $edit->add('NAME', '', 'text')->rule('required|max:60'); $edit->add('ADDRESS', '', 'textarea') ->attributes(['rows' => 3]) ->rule('max:250'); $edit->add('ZIPCODE', '', 'text')->rule('max:10'); $edit->add('PHONE', '', 'text')->rule('max:14'); // customer_edit return $edit->view('customer_edit', compact('edit')); } }
@extends('example') @section('title','') @section('body') <h1></h1> <p> {!! $filter !!} {!! $grid !!} </p> @stop
@extends('master') @section('title', ' Firebird') @section('body') <h1></h1> @if(Session::has('message')) <div class="alert alert-success"> {!! Session::get('message') !!} </div> @endif <p> Firebird.<br/> </p> @stop @section('content') @include('menu') @yield('body') @stop
<nav class="navbar main"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".main-collapse"> <span class="sr-only"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <div class="collapse navbar-collapse main-collapse"> <ul class="nav nav-tabs"> <li @if (Request::is('customer*')) class="active"@endif>{!! link_to("customers", "") !!}</li> <li @if (Request::is('product*')) class="active"@endif>{!! link_to("products", "") !!}</li> <li @if (Request::is('invoice*')) class="active"@endif>{!! link_to("invoices", " ") !!}</li> </ul> </div> </nav>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>@yield('title', ' Web Firebird')</title> <meta name="description" content="@yield('description', ' Web Firebird')" /> @section('meta', '') <link href="http://fonts.googleapis.com/css?family=Bitter" rel="stylesheet" type="text/css" /> <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"> {!! Rapyd::styles(true) !!} </head> <body> <div id="wrap"> <div class="container"> <br /> <div class="row"> <div class="col-sm-12"> @yield('content') </div> </div> </div> </div> <div id="footer"> </div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.pjax/1.9.6/jquery.pjax.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/riot/2.2.4/riot+compiler.min.js"></script> {!! Rapyd::scripts() !!} </body> </html>
@extends('example') @section('title', ' ') @section('body') <p> {!! $edit !!} </p> @stop
/* * */ namespace App\Http\Controllers; use App\Http\Controllers\Controller; use App\Product; class ProductController extends Controller { /** * * * @return Response */ public function showProducts() { // $filter = \DataFilter::source(new Product); // $filter->add('NAME', '', 'text'); $filter->submit(''); $filter->reset(''); // $grid = \DataGrid::source($filter); // // , , $grid->add('NAME', '', true); // 2 $grid->add('PRICE|number_format[2,., ]', ''); $grid->row(function($row) { // $row->cell('PRICE')->style("text-align: right"); }); // , $grid->edit('/product/edit', '', 'show|modify|delete'); // $grid->link('/product/edit', " ", "TR"); // $grid->orderBy('NAME', 'asc'); // $grid->paginate(10); // customer return view('product', compact('filter', 'grid')); } /** * , * * @return Response */ public function editProduct() { if (\Input::get('do_delete') == 1) return "not the first"; // $edit = \DataEdit::source(new Product()); // switch ($edit->status) { case 'create': $edit->label(' '); break; case 'modify': $edit->label(' '); break; case 'do_delete': $edit->label(' '); break; case 'show': $edit->label(' '); $edit->link('products', '', 'TR'); break; } // , // $edit->back('insert|update|do_delete', 'products'); // , // $edit->add('NAME', '', 'text')->rule('required|max:100'); $edit->add('PRICE', '', 'text')->rule('max:19'); $edit->add('DESCRIPTION', '', 'textarea') ->attributes(['rows' => 8]) ->rule('max:8192'); // product_edit return $edit->view('product_edit', compact('edit')); } }
/* * */ namespace App\Http\Controllers; use App\Http\Controllers\Controller; use App\Invoice; use App\Customer; use App\Product; use App\InvoiceLine; class InvoiceController extends Controller { /** * - * * @return Response */ public function showInvoices() { // // $invoices = Invoice::with('customer'); // $filter = \DataFilter::source($invoices); // $filter->add('INVOICE_DATE', '', 'daterange'); // $filter->add('customer.NAME', '', 'text'); $filter->submit(''); $filter->reset(''); // $grid = \DataGrid::source($filter); // // , , // , $grid->add('INVOICE_DATE|strtotime|date[dmY H:i:s]', '', true); // $grid->add('TOTAL_SALE|number_format[2,., ]', ''); $grid->add('customer.NAME', ''); // boolean / $grid->add('PAID', '') ->cell(function( $value, $row) { return $value ? '' : ''; }); // $grid->row(function($row) { // $row->cell('TOTAL_SALE')->style("text-align: right"); // if ($row->cell('PAID')->value == '') { $row->style("background-color: #ddffee;"); } }); // , $grid->edit('/invoice/edit', '', 'show|modify|delete'); // - $grid->link('/invoice/edit', " ", "TR"); // $grid->orderBy('INVOICE_DATE', 'desc'); // $grid->paginate(10); // customer return view('invoice', compact('filter', 'grid')); } /** * , * * @return Response */ public function editInvoice() { // , $error_msg = \Request::old('error_msg'); // $edit = \DataEdit::source(new Invoice()); // , if (($edit->model->PAID) && ($edit->status === 'modify')) { $edit->status = 'show'; $error_msg = ' . .'; } // , if (($edit->model->PAID) && ($edit->status === 'delete')) { $edit->status = 'show'; $error_msg = ' . .'; } // switch ($edit->status) { case 'create': $edit->label(' '); break; case 'modify': $edit->label(' '); break; case 'do_delete': $edit->label(' '); break; case 'show': $edit->label(''); $edit->link('invoices', '', 'TR'); // , if (!$edit->model->PAID) $edit->link('invoice/pay/' . $edit->model->INVOICE_ID, '', 'BL'); break; } // , // $edit->back('insert|update|do_delete', 'invoices'); // , // $edit->add('INVOICE_DATE', '', 'datetime') ->rule('required') ->insertValue(date('Ymd H:i:s')); // . // $edit->add('customer.NAME', '', 'autocomplete') ->rule('required') ->options(Customer::lists('NAME', 'CUSTOMER_ID')->all()); // , , $edit->add('TOTAL_SALE', '', 'text') ->mode('readonly') ->insertValue('0.00'); // $paidCheckbox = $edit->add('PAID', '', 'checkbox') ->insertValue('0') ->mode('readonly'); $paidCheckbox->checked_output = ''; $paidCheckbox->unchecked_output = ''; // $grid = $this->getInvoiceLineGrid($edit->model, $edit->status); // invoice_edit // return $edit->view('invoice_edit', compact('edit', 'grid', 'error_msg')); } /** * * * @return Response */ public function payInvoice($id) { try { // $invoice = Invoice::findOrFail($id); // $invoice->pay(); } catch (\Illuminate\Database\QueryException $e) { // , // $pos = strpos($e->getMessage(), 'E_INVOICE_ALREADY_PAYED'); if ($pos !== false) { // return redirect('invoice/edit?show=' . $id) ->withInput(['error_msg' => ' ']); } else throw $e; } // return redirect('invoice/edit?show=' . $id); } /** * * @param \App\Invoice $invoice * @param string $mode * @return \DataGrid */ private function getInvoiceLineGrid(Invoice $invoice, $mode) { // // $lines = InvoiceLine::with('product')->where('INVOICE_ID', $invoice->INVOICE_ID); // $grid = \DataGrid::source($lines); // // , , $grid->add('product.NAME', ''); $grid->add('QUANTITY', ''); $grid->add('SALE_PRICE|number_format[2,., ]', '')->style('min-width: 8em;'); $grid->add('SUM_PRICE|number_format[2,., ]', '')->style('min-width: 8em;'); // $grid->row(function($row) { $row->cell('QUANTITY')->style("text-align: right"); // $row->cell('SALE_PRICE')->style("text-align: right"); $row->cell('SUM_PRICE')->style("text-align: right"); }); if ($mode == 'modify') { // , $grid->edit('/invoice/editline', '', 'modify|delete'); // $grid->link('/invoice/editline?invoice_id=' . $invoice->INVOICE_ID, " ", "TR"); } return $grid; } /** * , * * @return Response */ public function editInvoiceLine() { if (\Input::get('do_delete') == 1) return "not the first"; $invoice_id = null; // $edit = \DataEdit::source(new InvoiceLine()); // switch ($edit->status) { case 'create': $edit->label(' '); $invoice_id = \Input::get('invoice_id'); break; case 'modify': $edit->label(' '); $invoice_id = $edit->model->INVOICE_ID; break; case 'delete': $invoice_id = $edit->model->INVOICE_ID; break; case 'do_delete': $edit->label(' '); $invoice_id = $edit->model->INVOICE_ID; break; } // url $base = str_replace(\Request::path(), '', strtok(\Request::fullUrl(), '?')); $back_url = $base . 'invoice/edit?modify=' . $invoice_id; // $edit->back('insert|update|do_delete', $back_url); $edit->back_url = $back_url; // $edit->add('INVOICE_ID', '', 'hidden') ->rule('required') ->insertValue($invoice_id) ->updateValue($invoice_id); // . // $edit->add('product.NAME', '', 'autocomplete') ->rule('required') ->options(Product::lists('NAME', 'PRODUCT_ID')->all()); // $edit->add('QUANTITY', '', 'text') ->rule('required'); // invoice_line_edit return $edit->view('invoice_line_edit', compact('edit')); } }
@extends('example') @section('title',' ') @section('body') <div class="container"> {!! $edit->header !!} @if($error_msg) <div class="alert alert-danger"> <strong>!</strong> {{ $error_msg }} </div> @endif {!! $edit->message !!} @if(!$edit->message) <div class="row"> <div class="col-sm-4"> {!! $edit->render('INVOICE_DATE') !!} {!! $edit->render('customer.NAME') !!} {!! $edit->render('TOTAL_SALE') !!} {!! $edit->render('PAID') !!} </div> </div> {!! $grid !!} @endif {!! $edit->footer !!} </div> @stop
// Route::get('/', 'InvoiceController@showInvoices'); Route::get('/customers', 'CustomerController@showCustomers'); Route::any('/customer/edit', 'CustomerController@editCustomer'); Route::get('/products', 'ProductController@showProducts'); Route::any('/product/edit', 'ProductController@editProduct'); Route::get('/invoices', 'InvoiceController@showInvoices'); Route::any('/invoice/edit', 'InvoiceController@editInvoice'); Route::any('/invoice/pay/{id}', 'InvoiceController@payInvoice'); Route::any('/invoice/editline', 'InvoiceController@editInvoiceLine');
Source: https://habr.com/ru/post/317458/
All Articles