Skip to content

Instantly share code, notes, and snippets.

View romaninsh's full-sized avatar
🚴‍♂️
Focusing

Romans Malinovskis romaninsh

🚴‍♂️
Focusing
View GitHub Profile
@romaninsh
romaninsh / Tabs.php
Created January 7, 2016 11:53
This is implementation of "Tabs" that also support icons in the tab
<?php
class Tabs extends View_Tabs_jUItabs {
function addTab($title,$name=null){
$container=$this->add('View_HtmlElement',$name);
$this->tab_template->set(array(
'url'=>'#'.$container->name,
'tab_id'=>$container->short_name,
@romaninsh
romaninsh / How to use on a page.php
Last active March 14, 2016 00:12
Model Union implementation in Agile Toolkit (draft version)
<?php
$tt->addTab('Debtor Report Level 1')->add('Grid')->setModel('Model_Report_Debtors',['contractor_id','amount','amount_sum'])->groupBy('contractor_id')
->owner->removeColumn('amount');//->addCondition('contractor_id','217716');
$tt->addTab('Debtor Report Drilldown on 217717 ')->add('Grid')->setModel('Model_Report_Debtors',['contractor_id','amount'])->addCondition('contractor_id','217717');
@romaninsh
romaninsh / Model_File.php
Last active February 19, 2016 13:06
FileStore for ATK (version 2.0) draft - You will need https://github.com/blueimp/jQuery-File-Upload and tpyo/amazon-s3-php-class
<?php
class Model_File extends LF_Model {
public $table = 'file';
public $storage = null;
public $local_copy = null;
function init(){
@romaninsh
romaninsh / agile-data.php
Last active July 20, 2016 06:15
What you write and what query Agile Data builds you.
<?php
// uses https://github.com/atk4/data
$c = new smbo\Model_Payment_Transfer($db);
$c->getRef('transfer_document_id')
->addFields(['other_side'=>'total_gross', 'other_account_currency'=>'account_currency','other_account'=>'account']);
$c->addCondition($c->expr('abs([total_gross])!=abs([other_side])'));
$c->addCondition($c->expr('[account_currency]=[other_account_currency]'));
$c->onlyFields([
'system_id','system','id','doc_date','ref_no','account','other_account','total_gross','other_side',

Example - Invoice Totals

This is a full demonstration of a basic system designed with Agile Data and Audit extension. The purpose of this example implement functionality of "Invoices" and "Lines". Each Invoice contains of multiple Lines and additionally have a few auto-fields that are calculated automatically. I used implementation without SQL Expression to keep code cross-compatible with any persistence engine.

Setting up tables

There are 2 basic tables at play. Table invoice contains:

id ref total
@romaninsh
romaninsh / notes.php
Created October 24, 2016 15:09
PHP Data Libraries
<?php
// This file contains comments that help you understand comparison
// criteria better: for "PHP Data Library comparison"
// http://socialcompare.com/en/comparison/php-data-access-libraries-orm-activerecord-persistence
// General Premise
// Data Access frameworks hide implementation detail of a specific database engine and allow you to work
@romaninsh
romaninsh / Controller_UniqueFields.php
Created October 26, 2016 13:33
Define Unique Fields in Domain Model with Agile Data
<?php
namespace smbo;
class Controller_UniqueFields {
use \atk4\core\InitializerTrait {
init as _init;
}
use \atk4\core\TrackableTrait;
use \atk4\core\AppScopeTrait;
<?php
namespace smbo\tests;
class VATRules extends TestCase
{
function complextest($is_invoice_basis, $is_invoice_locked, $is_purchase) {
if($is_invoice_basis) {
$this->app->system['is_invoice_basis'] = true;
}
<?php
namespace smbo\tests;
/**
* Tests usage of classes thorugh bridge
*/
class InvoiceTest extends TestCase
{
function testInvoiceCreation()
{
<?php
namespace smbo;
class Model_Report_Ledger2 extends UnionModel {
use \atk4\core\AppScopeTrait;
function init() {
parent::init();
$this->addInvoices();
$this->addPayments();