Skip to content

Commit

Permalink
Move models into autoloaded classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jimwins committed Aug 30, 2018
1 parent 566d490 commit f5c82b5
Show file tree
Hide file tree
Showing 37 changed files with 146 additions and 139 deletions.
1 change: 0 additions & 1 deletion api/brand-add.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?
include '../scat.php';
include '../lib/catalog.php';

$name= $_REQUEST['name'];
$slug= $_REQUEST['slug'];
Expand Down
1 change: 0 additions & 1 deletion api/brand-list.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
require '../scat.php';
require '../lib/catalog.php';

$verbose= (int)$_REQUEST['verbose'];

Expand Down
1 change: 0 additions & 1 deletion api/brand-load.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
require '../scat.php';
require '../lib/catalog.php';

$id= (int)$_REQUEST['id'];

Expand Down
1 change: 0 additions & 1 deletion api/brand-merge.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?
include '../scat.php';
include '../lib/catalog.php';

$id= (int)$_REQUEST['id'];
$dest= (int)$_REQUEST['dest'];
Expand Down
1 change: 0 additions & 1 deletion api/brand-update.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?
include '../scat.php';
include '../lib/catalog.php';

$id= (int)$_REQUEST['id'];
$name= $_REQUEST['name'];
Expand Down
1 change: 0 additions & 1 deletion api/department-find.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
require '../scat.php';
require '../lib/catalog.php';

$parent= (int)$_REQUEST['parent'];

Expand Down
1 change: 0 additions & 1 deletion api/generate-slug.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
require '../scat.php';
require '../lib/catalog.php';

$brand_id= (int)$_REQUEST['brand'];
$name= $db->escape($_REQUEST['name']);
Expand Down
1 change: 0 additions & 1 deletion api/note-add.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?
include '../scat.php';
include '../lib/catalog.php';

$content= $_REQUEST['content'];
$kind= $_REQUEST['kind'];
Expand Down
1 change: 0 additions & 1 deletion api/note-count.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
require '../scat.php';
require '../lib/catalog.php';

$attach_id= (int)$_REQUEST['attach_id'];
if ($attach_id) {
Expand Down
1 change: 0 additions & 1 deletion api/note-find.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
require '../scat.php';
require '../lib/catalog.php';

$limit= (int)$_REQUEST['limit'];
if (!$limit) $limit= 100;
Expand Down
3 changes: 1 addition & 2 deletions api/note-update.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?
<?php
include '../scat.php';
include '../lib/catalog.php';

$id= (int)$_REQUEST['id'];
$content= $_REQUEST['content'];
Expand Down
1 change: 0 additions & 1 deletion api/product-add.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?
include '../scat.php';
include '../lib/catalog.php';

$name= $_REQUEST['name'];
$slug= $_REQUEST['slug'];
Expand Down
1 change: 0 additions & 1 deletion api/product-find.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?
include '../scat.php';
include '../lib/catalog.php';

$term= $_REQUEST['term'];

Expand Down
1 change: 0 additions & 1 deletion api/product-update.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?
include '../scat.php';
include '../lib/catalog.php';

$id= (int)$_REQUEST['id'];
$name= $_REQUEST['name'];
Expand Down
2 changes: 0 additions & 2 deletions api/till-count.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php
require '../scat.php';
require '../lib/txn.php';
require '../lib/catalog.php';

$count= $_REQUEST['count'];
if (empty($count))
Expand Down
1 change: 0 additions & 1 deletion api/till-withdraw.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
require '../scat.php';
require '../lib/txn.php';
require '../lib/catalog.php';

$reason= $_REQUEST['reason'];
if (!$reason)
Expand Down
1 change: 0 additions & 1 deletion catalog-brands.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?
require 'scat.php';
require 'lib/catalog.php';

head("Brands @ Scat", true);

Expand Down
1 change: 0 additions & 1 deletion catalog-department.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?
require 'scat.php';
require 'lib/catalog.php';

// XXX Use Knockout to make title dynamic
head("Department @ Scat", true);
Expand Down
1 change: 0 additions & 1 deletion catalog-departments.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?
require 'scat.php';
require 'lib/catalog.php';

$id= (int)$_REQUEST['id'];

Expand Down
1 change: 0 additions & 1 deletion catalog-product.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?
require 'scat.php';
require 'lib/catalog.php';

// XXX Use Knockout to make title dynamic
head("Product @ Scat", true);
Expand Down
1 change: 0 additions & 1 deletion catalog-search.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?
require 'scat.php';
require 'lib/catalog.php';

head("Search Catalog @ Scat", true);

Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"email": "jimw@trainedmonkey.com"
}
],
"autoload": {
"psr-4": {
"Scat\\" : "lib/Scat/"
}
},
"require": {
"moment/moment": "^2.17",
"components/jquery": "^3.1",
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function setActiveRow(row) {
fld.focus().select();
});

var paymentMethods= <?=json_encode(\Payment::$methods)?>;
var paymentMethods= <?=json_encode(\Scat\Payment::$methods)?>;

function formatMethod(payment) {
if (payment.method() == 'discount' && payment.discount()) {
Expand Down
1 change: 0 additions & 1 deletion item.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?
require 'scat.php';
require 'lib/item.php';
require 'lib/catalog.php';

$code= $_GET['code'];
$id= (int)$_GET['id'];
Expand Down
9 changes: 9 additions & 0 deletions lib/Scat/Brand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Scat;

class Brand extends \Model {
public function products() {
return $this->has_many('Product');
}
}

18 changes: 18 additions & 0 deletions lib/Scat/Department.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace Scat;

class Department extends \Model {
public function parent() {
return $this->belongs_to('Department', 'parent_id');
}

public function departments() {
return $this->has_many('Department', 'parent_id');
}

public function products() {
return $this->has_many('Product');
}
}


7 changes: 4 additions & 3 deletions lib/giftcard.php → lib/Scat/GiftCard.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
namespace Scat;

include '../lib/php-barcode.php';
include dirname(__FILE__).'/../php-barcode.php';

class Giftcard extends Model implements JsonSerializable {
class Giftcard extends \Model implements \JsonSerializable {
public function card() {
return $self->id . $self->pin;
}
Expand Down Expand Up @@ -120,7 +121,7 @@ public function getPDF() {
}
}

class Giftcard_Txn extends Model {
class Giftcard_Txn extends \Model {
public function card() {
return $this->belongs_to('Giftcard', 'card_id');
}
Expand Down
24 changes: 24 additions & 0 deletions lib/Scat/Item.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?
namespace Scat;

class Item extends \Model {
/* XXX Legacy, should get from parent product */
public function brand() {
return $this->belongs_to('Brand', 'brand');
}

public function product() {
return $this->belongs_to('Product');
}

public function barcodes() {
return $this->has_many('Barcode', 'item');
}
}

class Barcode extends \Model {
public function item() {
return $this->belongs_to('Item', 'item');
}
}

12 changes: 12 additions & 0 deletions lib/Scat/Note.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace Scat;

class Note extends \Model {
public function person() {
return $this->belongs_to('Person');
}

public function parent() {
return $this->belongs_to('Note', 'parent_id');
}
}
21 changes: 21 additions & 0 deletions lib/Scat/Payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace Scat;

class Payment extends \Model {
public static $methods= array(
'cash' => "Cash",
'change' => "Change",
'credit' => "Credit Card",
'square' => "Square",
'stripe' => "Stripe",
'gift' => "Gift Card",
'check' => "Check",
'dwolla' => "Dwolla",
'paypal' => "PayPal",
'discount' => "Discount",
'bad' => "Bad Debt",
'donation' => "Donation",
'withdrawal' => "Withdrawal",
'internal' => "Internal",
);
}
25 changes: 25 additions & 0 deletions lib/Scat/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace Scat;

class Product extends \Model implements \JsonSerializable {
public function brand() {
return $this->belongs_to('Brand');
}

public function items() {
return $this->has_many('Item')
->select('item.*')
->select_expr('sale_price(item.retail_price,
item.discount_type,
item.discount)',
'sale_price')
->select_expr('(SELECT IFNULL(SUM(allocated),0)
FROM txn_line
WHERE txn_line.item = item.id)',
'stock');
}

public function jsonSerialize() {
return $this->asArray();
}
}
13 changes: 13 additions & 0 deletions lib/Scat/Txn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
namespace Scat;

/* XXX add relationships, but just using these raw for now */

class Txn extends \Model {
}

class TxnLine extends \Model {
}

class PriceOverride extends \Model {
}
Loading

0 comments on commit f5c82b5

Please sign in to comment.