Skip to content

Commit

Permalink
Merge branch 'jk_product_matrix'
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkelly committed Jun 12, 2013
2 parents bfe6e00 + 8cc0c3c commit 4f4cdf9
Show file tree
Hide file tree
Showing 50 changed files with 2,189 additions and 64 deletions.
2 changes: 1 addition & 1 deletion config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ encryption.default.key = this_is_the_encryption_key_change_it
nonce.key = this_should_be_random_and_secret_so_change_it
nonce.timelimit = 3600

version.name = 2013.1-beta1
version.name = 2013.1-beta2

debug.level = All
debug.error_reporting = E_ERROR
Expand Down
51 changes: 45 additions & 6 deletions include/class/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@ public static function get_all()

}

public static function count()
{
global $logger;
global $auth_session;

$sql = "SELECT
count(id) as count
FROM
".TB_PREFIX."invoices
WHERE
domain_id = :domain_id
";
$sth = dbQuery($sql, ':domain_id', $auth_session->domain_id);

return $sth;

}
function select_all($type='', $dir='DESC', $rp='25', $page='1', $having='')
{
global $config;
Expand Down Expand Up @@ -234,7 +251,7 @@ function select_all($type='', $dir='DESC', $rp='25', $page='1', $having='')
$sort = "id";
}

if($type =="count")
if(substr($type,"count"))
{
//unset($limit);
$limit="";
Expand Down Expand Up @@ -342,20 +359,34 @@ function select_all($type='', $dir='DESC', $rp='25', $page='1', $having='')
iv.index_id as index_id,
b.name AS biller,
c.name AS customer,
(SELECT coalesce(SUM(ii.total), 0) FROM " .
DATE_FORMAT(date,'%Y-%m-%d') AS date,";


$sql .="(SELECT coalesce(SUM(ii.total), 0) FROM " .
TB_PREFIX . "invoice_items ii WHERE ii.invoice_id = iv.id) AS invoice_total,
(SELECT coalesce(SUM(ac_amount), 0) FROM " .
TB_PREFIX . "payment ap WHERE ap.ac_inv_id = iv.id) AS INV_PAID,
ROUND( (SELECT (coalesce(invoice_total,0) - coalesce(INV_PAID,0))) ,2) As owing,
DATE_FORMAT(date,'%Y-%m-%d') AS date,
(SELECT invoice_total - INV_PAID) As owing,
";

//only run aging for real query
if($type == '')
{
$sql .="
(SELECT IF((owing = 0 OR owing < 0), 0, DateDiff(now(), date))) AS Age,
(SELECT (CASE WHEN Age = 0 THEN ''
WHEN Age <= 14 THEN '0-14'
WHEN Age <= 30 THEN '15-30'
WHEN Age <= 60 THEN '31-60'
WHEN Age <= 90 THEN '61-90'
ELSE '90+' END)) AS aging,
iv.type_id As type_id,
ELSE '90+' END)) AS aging,";
} else {
$sql .="
(SELECT '') as Age,
(SELECT '') as aging,
";
}
$sql .="iv.type_id As type_id,
pf.pref_description AS preference,
pf.status AS status,
(SELECT CONCAT(pf.pref_inv_wording,' ',iv.index_id)) as index_name
Expand Down Expand Up @@ -408,6 +439,14 @@ public static function getInvoiceItems($id) {
$invoiceItem['tax_amount'] = $invoiceItem['tax_amount'];
$invoiceItem['gross_total'] = $invoiceItem['gross_total'];
$invoiceItem['total'] = $invoiceItem['total'];
$invoiceItem['attribute_decode'] = json_decode($invoiceItem['attribute'],true);
foreach ($invoiceItem['attribute_decode'] as $key => $value)
{
$invoiceItem['attribute_json'][$key]['name'] = product_attributes::getName($key);
$invoiceItem['attribute_json'][$key]['value'] = product_attributes::getValue($key,$value);
$invoiceItem['attribute_json'][$key]['type'] = product_attributes::getType($key);
$invoiceItem['attribute_json'][$key]['visible'] = product_attributes::getVisible($key);
}

$sql = "SELECT * FROM ".TB_PREFIX."products WHERE id = :id";
$tth = dbQuery($sql, ':id', $invoiceItem['product_id']) or die(htmlsafe(end($dbh->errorInfo())));
Expand Down
76 changes: 76 additions & 0 deletions include/class/product/attributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

class product_attributes
{
public function get($id)
{
$sql = "select * from ".TB_PREFIX."products_attributes where id = :id";
$sth = dbQuery($sql,':id',$id);
$attribute = $sth->fetch();

$sql2 = "select * from ".TB_PREFIX."products_attribute_type where id = :id";
$sth2 = dbQuery($sql2,':id',$attribute['type_id']);
$name = $sth2->fetch();
$attribute['type'] = $name['name'];

return $attribute;
}
public function getName($id)
{
$sql = "select * from ".TB_PREFIX."products_attributes where id = :id";
$sth = dbQuery($sql,':id',$id);
$attribute = $sth->fetch();
return $attribute['name'];
}
public function getType($id)
{
$sql = "select
t.name as type
from
".TB_PREFIX."products_attributes as a,
".TB_PREFIX."products_attribute_type as t
where
a.id = :id
and a.type_id = t.id";
$sth = dbQuery($sql,':id',$id);
$attribute = $sth->fetch();
return $attribute['type'];
}
public function getValue($attribute_id, $value_id)
{

$details = product_attributes::get($attribute_id);

if($details['type'] == 'list')
{
$sql = "select value from ".TB_PREFIX."products_values where id = :id";
$sth = dbQuery($sql,':id',$value_id);
$attribute = $sth->fetch();

return $attribute['value'];
} else {
return $value_id;
}

}
public function getVisible($id)
{
$sql = "select * from ".TB_PREFIX."products_attributes where id = :id";
$sth = dbQuery($sql,':id',$id);
$attribute = $sth->fetch();
if($attribute['visible'] =='1')
{
return true;
} else {
return false;
}

}
public function getAll()
{
$sql = "select * from ".TB_PREFIX."products_attributes";
$sth = dbQuery($sql);
$attributes = $sth->fetchAll();
return $attributes;
}
}
33 changes: 32 additions & 1 deletion include/jquery/jquery.functions.js.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@
$('#gmail_loading').show();
$.ajax({
type: 'GET',
url: './index.php?module=invoices&view=product_ajax&id='+product,
url: './index.php?module=invoices&view=product_ajax&id='+product+'&row='+row_number,
data: "id: "+product,
dataType: "json",
success: function(data){
$('#gmail_loading').hide();
/*$('#state').html(data);*/
/*if ( (quantity.length==0) || (quantity.value==null) ) */
$("#json_html"+row_number).remove();
if (quantity=="")
{
$("#quantity"+row_number).attr("value","1");
Expand All @@ -61,6 +62,30 @@
{
$("#tax_id\\["+row_number+"\\]\\[1\\]").val(data['default_tax_id_2']);
}
//do the product matric code
if (data['show_description'] =="Y")
{
$("tbody#row"+row_number+" tr.details").show();
} else {
$("tbody#row"+row_number+" tr.details").hide();
}
if($("#description"+row_number).val() == $("#description"+row_number).attr('rel') || $("#description"+row_number).val() =='{/literal}{$LANG.description}{literal}')
{
if (data['notes_as_description'] =="Y")
{
$("#description"+row_number).val(data['notes']);
$("#description"+row_number).attr('rel',data['notes']);
} else {
$("#description"+row_number).val('{/literal}{$LANG.description}{literal}');
$("#description"+row_number).attr('rel','{/literal}{$LANG.description}{literal}');
}
}
if (data['json_html'] !=="")
{
$("tbody#row"+row_number+" tr.details").before(data['json_html']);
}
}

});
Expand Down Expand Up @@ -188,6 +213,9 @@
clonedRow.find("#products"+rowID_old).attr("rel", rowID_new);
clonedRow.find("#products"+rowID_old).attr("id", "products"+rowID_new);
clonedRow.find("#products"+rowID_new).attr("name", "products"+rowID_new);
clonedRow.find("#products"+rowID_new).find('option:selected').removeAttr("selected");
clonedRow.find("#products"+rowID_new).prepend(new Option("", ""));
clonedRow.find("#products"+rowID_new).find('option:eq(0)').attr('selected', true)
clonedRow.find("#products"+rowID_new).removeClass("validate[required]");
//clonedRow.find("#products"+rowID_new).attr("onChange", "invoice_product_change_price($(this).val(), "+rowID_new+", jQuery('#quantity"+rowID_new+"').val() )");
Expand All @@ -201,12 +229,15 @@
$("#description"+rowID_new, clonedRow).attr("name", "description"+rowID_new);
$("#description"+rowID_new, clonedRow).attr("value","{/literal}{$LANG.description}{literal}");
$("#description"+rowID_new, clonedRow).css({ color: "#b2adad" });
$(".details",clonedRow).hide();

$("#tax_id\\["+rowID_old+"\\]\\[0\\]", clonedRow).attr("id", "tax_id["+rowID_new+"][0]");
$("#tax_id\\["+rowID_new+"\\]\\[0\\]", clonedRow).attr("name", "tax_id["+rowID_new+"][0]");
$("#tax_id\\["+rowID_old+"\\]\\[1\\]", clonedRow).attr("id", "tax_id["+rowID_new+"][1]");
$("#tax_id\\["+rowID_new+"\\]\\[1\\]", clonedRow).attr("name", "tax_id["+rowID_new+"][1]");

$("#json_html"+rowID_old, clonedRow).remove();

$('#itemtable').append(clonedRow);

$('#gmail_loading').hide();
Expand Down
102 changes: 101 additions & 1 deletion include/sql_patches.php
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,107 @@
$patch['253']['name'] = "Add PaymentsGateway API ID field";
$patch['253']['patch'] = "ALTER TABLE `".TB_PREFIX."biller` ADD `paymentsgateway_api_id` VARCHAR( 255 ) NULL AFTER `eway_customer_id`;";
$patch['253']['date'] = "20110918";

$patch['254']['name'] = "Product Matrix - update line items table";
$patch['254']['patch'] = "ALTER TABLE `".TB_PREFIX."invoice_items` ADD `attribute` VARCHAR( 255 ) NULL ;";
$patch['254']['date'] = "20130313";

$patch['255']['name'] = "Product Matrix - update line items table";
$patch['255']['patch'] = "
CREATE TABLE `".TB_PREFIX."products_attributes` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 255 ) NOT NULL,
`type_id` VARCHAR( 255 ) NOT NULL
) ENGINE = MYISAM ;";
$patch['255']['date'] = "20130313";

$patch['256']['name'] = "Product Matrix - update line items table";
$patch['256']['patch'] = "INSERT INTO `". TB_PREFIX ."products_attributes` (`id`, `name`, `type_id`) VALUES (NULL, 'Size','1'), (NULL,'Colour','1');";
$patch['256']['date'] = "20130313";

$patch['257']['name'] = "Product Matrix - update line items table";
$patch['257']['patch'] = "CREATE TABLE `". TB_PREFIX ."products_values` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`attribute_id` INT( 11 ) NOT NULL ,
`value` VARCHAR( 255 ) NOT NULL
) ENGINE = MYISAM ;";
$patch['257']['date'] = "20130313";

$patch['258']['name'] = "Product Matrix - update line items table";
$patch['258']['patch'] = "INSERT INTO `". TB_PREFIX ."products_values` (`id`, `attribute_id`,`value`) VALUES (NULL,'1', 'S'), (NULL,'1', 'M'), (NULL,'1', 'L'), (NULL,'2', 'Red'), (NULL,'2', 'White');";
$patch['258']['date'] = "20130313";

$patch['259']['name'] = "Product Matrix - update line items table";
$patch['259']['patch'] = "CREATE TABLE `". TB_PREFIX ."products_matrix` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`product_id` INT( 11 ) NOT NULL ,
`attribute_id` INT( 11 ) NOT NULL
) ENGINE = MYISAM ;";
$patch['259']['date'] = "20130313";

$patch['260']['name'] = "Product Matrix - update line items table";
$patch['260']['patch'] =" ALTER TABLE `". TB_PREFIX ."products_matrix` ADD `product_attribute_number` INT( 11 ) NOT NULL AFTER `product_id` ;";
$patch['260']['date'] = "20130313";

$patch['261']['name'] = "Product Matrix - update line items table";
$patch['261']['patch'] =" INSERT INTO `". TB_PREFIX ."products_matrix` (`id`, `product_id`,`product_attribute_number`, `attribute_id`) VALUES (NULL,'1', '1', '1'), (NULL,'1', '2', '2'), (NULL,'2', '1', '2');";
$patch['261']['date'] = "20130313";

$patch['262']['name'] = "Add product attributes system preference";
$patch['262']['patch'] = "INSERT INTO ".TB_PREFIX."system_defaults (id, name ,value ,domain_id ,extension_id ) VALUES (NULL , 'product_attributes', '0', '1', '1');";
$patch['262']['date'] = "20130313";

$patch['263']['name'] = "Product Matrix - update line items table";
$patch['263']['patch'] = "ALTER TABLE `".TB_PREFIX."products` ADD `attribute` VARCHAR( 255 ) NULL ;";
$patch['263']['date'] = "20130313";


$patch['264']['name'] = "Product - use notes as default line item description";
$patch['264']['patch'] = "ALTER TABLE `".TB_PREFIX."products` ADD `notes_as_description` VARCHAR( 1 ) NULL ;";
$patch['264']['date'] = "20130314";


$patch['265']['name'] = "Product - expand/show line item description";
$patch['265']['patch'] = "ALTER TABLE `".TB_PREFIX."products` ADD `show_description` VARCHAR( 1 ) NULL ;";
$patch['265']['date'] = "20130314";

$patch['266']['name'] = "Product - expand/show line item description";
$patch['266']['patch'] = "CREATE TABLE `".TB_PREFIX."products_attribute_type` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$patch['266']['date'] = "20130322";

$patch['267']['name'] = "Product Matrix - insert attribute types";
$patch['267']['patch'] = "INSERT INTO `". TB_PREFIX ."products_attribute_type` (`id`, `name`) VALUES (NULL,'list'), (NULL,'decimal'), (NULL,'free');";
$patch['267']['date'] = "20130325";


$patch['268']['name'] = "Product Matrix - insert attribute types";
$patch['268']['patch'] = "ALTER TABLE `". TB_PREFIX ."products_attributes` ADD `enabled` VARCHAR( 1 ) NULL DEFAULT '1',
ADD `visible` VARCHAR( 1 ) NULL DEFAULT '1';";
$patch['268']['date'] = "20130327";

$patch['269']['name'] = "Product Matrix - insert attribute types";
$patch['269']['patch'] = "ALTER TABLE `". TB_PREFIX ."products_values` ADD `enabled` VARCHAR( 1 ) NULL DEFAULT '1';";
$patch['269']['date'] = "20130327";



$patch['270']['name'] = "Make Simple Invoices faster - add index";
$patch['270']['patch'] = "ALTER TABLE `".TB_PREFIX."payment` ADD INDEX(`ac_inv_id`);";
$patch['270']['date'] = "20100419";

$patch['271']['name'] = "Make Simple Invoices faster - add index";
$patch['271']['patch'] = "ALTER TABLE `".TB_PREFIX."payment` ADD INDEX(`ac_amount`);";
$patch['271']['date'] = "20100419";

$patch['272']['name'] = "Add product attributes system preference";
$patch['272']['patch'] = "INSERT INTO ".TB_PREFIX."system_defaults (id, name ,value ,domain_id ,extension_id ) VALUES (NULL , 'large_dataset', '0', '1', '1');";
$patch['272']['date'] = "20130313";
/*
/*
ALTER TABLE `si_system_defaults` ADD `new_id` INT( 11 ) NOT NULL FIRST; UPDATE `si_system_defaults` SET new_id = id; ALTER TABLE `si_system_defaults` DROP `id` ; ALTER TABLE `si_system_defaults` DROP INDEX `name` ; ALTER TABLE `si_system_defaults` CHANGE `new_id` `id` INT( 11 ) NOT NULL; ALTER TABLE `si_system_defaults` ADD PRIMARY KEY(`domain_id`,`id` );
*/
*/

0 comments on commit 4f4cdf9

Please sign in to comment.