diff --git a/config/config.ini b/config/config.ini
index 9366cef28..5302d1b4d 100644
--- a/config/config.ini
+++ b/config/config.ini
@@ -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
diff --git a/include/class/invoice.php b/include/class/invoice.php
index 1e95a556f..617954ea5 100644
--- a/include/class/invoice.php
+++ b/include/class/invoice.php
@@ -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;
@@ -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="";
@@ -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
@@ -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())));
diff --git a/include/class/product/attributes.php b/include/class/product/attributes.php
new file mode 100644
index 000000000..2fd2093bd
--- /dev/null
+++ b/include/class/product/attributes.php
@@ -0,0 +1,76 @@
+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;
+ }
+}
diff --git a/include/jquery/jquery.functions.js.tpl b/include/jquery/jquery.functions.js.tpl
index 48fb8c060..1c56b0a2f 100644
--- a/include/jquery/jquery.functions.js.tpl
+++ b/include/jquery/jquery.functions.js.tpl
@@ -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");
@@ -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']);
+ }
}
});
@@ -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() )");
@@ -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();
diff --git a/include/sql_patches.php b/include/sql_patches.php
index 3e003d3d4..be8f2b1c0 100644
--- a/include/sql_patches.php
+++ b/include/sql_patches.php
@@ -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` );
-*/
+ */
diff --git a/include/sql_queries.php b/include/sql_queries.php
index 86bc56637..ee5ea7035 100644
--- a/include/sql_queries.php
+++ b/include/sql_queries.php
@@ -672,8 +672,32 @@ function insertProductComplete($enabled=1,$visible=1,$description,
function insertProduct($enabled=1,$visible=1) {
global $auth_session;
+ global $logger;
(isset($_POST['enabled'])) ? $enabled = $_POST['enabled'] : $enabled = $enabled ;
+ //select all attribts
+ $sql = "select * from ".TB_PREFIX."products_attributes";
+ $sth = dbQuery($sql);
+ $attributes = $sth->fetchAll();
+
+ $logger->log('Attr: '.var_export($attributes,true), Zend_Log::INFO);
+ $attr = array();
+ foreach($attributes as $k=>$v)
+ {
+ $logger->log('Attr key: '.$k, Zend_Log::INFO);
+ $logger->log('Attr value: '.var_export($v,true), Zend_Log::INFO);
+ $logger->log('Attr set value: '.$k, Zend_Log::INFO);
+ if($_POST['attribute'.$v[id]] == 'true')
+ {
+ //$attr[$k]['attr_id'] = $v['id'];
+ $attr[$v['id']] = $_POST['attribute'.$v[id]];
+// $attr[$k]['a$v['id']] = $_POST['attribute'.$v[id]];
+ }
+
+ }
+ $logger->log('Attr array: '.var_export($attr,true), Zend_Log::INFO);
+ $notes_as_description = ($_POST['notes_as_description'] == 'true' ? 'Y' : NULL) ;
+ $show_description = ($_POST['show_description'] == 'true' ? 'Y' : NULL) ;
$sql = "INSERT into
".TB_PREFIX."products
@@ -690,7 +714,10 @@ function insertProduct($enabled=1,$visible=1) {
notes,
default_tax_id,
enabled,
- visible
+ visible,
+ attribute,
+ notes_as_description,
+ show_description
)
VALUES
(
@@ -706,7 +733,10 @@ function insertProduct($enabled=1,$visible=1) {
:notes,
:default_tax_id,
:enabled,
- :visible
+ :visible,
+ :attribute,
+ :notes_as_description,
+ :show_description
)";
return dbQuery($sql,
@@ -722,13 +752,33 @@ function insertProduct($enabled=1,$visible=1) {
':notes', "".$_POST['notes'],
':default_tax_id', $_POST['default_tax_id'],
':enabled', $enabled,
- ':visible', $visible
+ ':visible', $visible,
+ ':attribute', json_encode($attr),
+ ':notes_as_description', $notes_as_description,
+ ':show_description', $show_description
);
}
function updateProduct() {
+ //select all attribts
+ $sql = "select * from ".TB_PREFIX."products_attributes";
+ $sth = dbQuery($sql);
+ $attributes = $sth->fetchAll();
+
+ $attr = array();
+ foreach($attributes as $k=>$v)
+ {
+ if($_POST['attribute'.$v[id]] == 'true')
+ {
+ $attr[$v['id']] = $_POST['attribute'.$v[id]];
+ }
+
+ }
+ $notes_as_description = ($_POST['notes_as_description'] == 'true' ? 'Y' : NULL) ;
+ $show_description = ($_POST['show_description'] == 'true' ? 'Y' : NULL) ;
+
$sql = "UPDATE ".TB_PREFIX."products
SET
description = :description,
@@ -741,7 +791,10 @@ function updateProduct() {
custom_field4 = :custom_field4,
unit_price = :unit_price,
cost = :cost,
- reorder_level = :reorder_level
+ reorder_level = :reorder_level,
+ attribute = :attribute,
+ notes_as_description = :notes_as_description,
+ show_description = :show_description
WHERE
id = :id";
@@ -757,6 +810,9 @@ function updateProduct() {
':unit_price', $_POST[unit_price],
':cost', $_POST[cost],
':reorder_level', $_POST[reorder_level],
+ ':attribute', json_encode($attr),
+ ':notes_as_description', $notes_as_description,
+ ':show_description', $show_description,
':id', $_GET[id]
);
}
@@ -903,6 +959,27 @@ function getDefaultInventory() {
return $delete;
}
+function getDefaultProductAttributes() {
+ global $LANG;
+ global $dbh;
+
+ $sql = "SELECT value from ".TB_PREFIX."system_defaults s WHERE ( s.name = 'product_attributes')";
+ $sth = dbQuery($sql) or die(htmlsafe(end($dbh->errorInfo())));
+ $array = $sth->fetch();
+ $delete = $array['value']==1?$LANG['enabled']:$LANG['disabled'];
+ return $delete;
+}
+function getDefaultLargeDataset() {
+ global $LANG;
+ global $dbh;
+
+ $sql = "SELECT value from ".TB_PREFIX."system_defaults s WHERE ( s.name = 'large_dataset')";
+ $sth = dbQuery($sql) or die(htmlsafe(end($dbh->errorInfo())));
+ $array = $sth->fetch();
+ $delete = $array['value']==1?$LANG['enabled']:$LANG['disabled'];
+ return $delete;
+}
+
function getDefaultLanguage() {
global $LANG;
global $dbh;
@@ -2007,11 +2084,22 @@ function updateInvoice($invoice_id) {
);
}
-function insertInvoiceItem($invoice_id,$quantity,$product_id,$line_number,$line_item_tax_id,$description="", $unit_price="") {
+function insertInvoiceItem($invoice_id,$quantity,$product_id,$line_number,$line_item_tax_id,$description="", $unit_price="", $attribute="") {
global $logger;
global $LANG;
- //do taxes
+ //do taxes
+
+ $attr = array();
+ $logger->log('Line item attributes: '.var_export($attribute,true), Zend_Log::INFO);
+ foreach($attribute as $k=>$v)
+ {
+ if($attribute[$v] !== '')
+ {
+ $attr[$k] = $v;
+ }
+
+ }
$tax_total = getTaxesPerLineItem($line_item_tax_id,$quantity, $unit_price);
@@ -2048,7 +2136,8 @@ function insertInvoiceItem($invoice_id,$quantity,$product_id,$line_number,$line_
tax_amount,
gross_total,
description,
- total
+ total,
+ attribute
)
VALUES
(
@@ -2059,7 +2148,8 @@ function insertInvoiceItem($invoice_id,$quantity,$product_id,$line_number,$line_
:tax_amount,
:gross_total,
:description,
- :total
+ :total,
+ :attribute
)";
//echo $sql;
@@ -2073,7 +2163,8 @@ function insertInvoiceItem($invoice_id,$quantity,$product_id,$line_number,$line_
':tax_amount', $tax_total,
':gross_total', $gross_total,
':description', $description,
- ':total', $total
+ ':total', $total,
+ ':attribute',json_encode($attr)
);
invoice_item_tax(lastInsertId(),$line_item_tax_id,$unit_price,$quantity,"insert");
@@ -2194,13 +2285,24 @@ function invoice_item_tax($invoice_item_id,$line_item_tax_id,$unit_price,$quanti
//TODO fix this
return true;
}
-function updateInvoiceItem($id,$quantity,$product_id,$line_number,$line_item_tax_id,$description,$unit_price) {
+function updateInvoiceItem($id,$quantity,$product_id,$line_number,$line_item_tax_id,$description,$unit_price,$attribute="") {
global $logger;
global $LANG;
//$product = getProduct($product_id);
//$tax = getTaxRate($tax_id);
+ $attr = array();
+ $logger->log('Line item attributes: '.var_export($attribute,true), Zend_Log::INFO);
+ foreach($attribute as $k=>$v)
+ {
+ if($attribute[$v] !== '')
+ {
+ $attr[$k] = $v;
+ }
+
+ }
+
$tax_total = getTaxesPerLineItem($line_item_tax_id,$quantity, $unit_price);
$logger->log('Invoice: '.$invoice_id.' Tax '.$line_item_tax_id.' for line item '.$line_number.': '.$tax_total, Zend_Log::INFO);
@@ -2232,7 +2334,8 @@ function updateInvoiceItem($id,$quantity,$product_id,$line_number,$line_item_tax
tax_amount = :tax_amount,
gross_total = :gross_total,
description = :description,
- total = :total
+ total = :total,
+ attribute = :attribute
WHERE id = :id";
//echo $sql;
@@ -2245,6 +2348,7 @@ function updateInvoiceItem($id,$quantity,$product_id,$line_number,$line_item_tax
':gross_total', $gross_total,
':description', $description,
':total', $total,
+ ':attribute',json_encode($attr),
':id', $id
);
diff --git a/lang/en_GB/lang.php b/lang/en_GB/lang.php
index d6826d53c..a794056f3 100644
--- a/lang/en_GB/lang.php
+++ b/lang/en_GB/lang.php
@@ -124,6 +124,7 @@
$LANG['debtors_by_aging_periods'] = "Debtors by Aging periods";//1
$LANG['debtors_by_amount_owed'] = "Debtors by amount owed";//1
$LANG['debtors_by_amount_owing_customer'] = "Debtors by Amount Owing per Customer";//1
+$LANG['decimal'] = "Decimal";//1
$LANG['default_biller'] = "Default Biller";//1
$LANG['default_customer'] = "Default Customer";//1
$LANG['default_inv_template'] = "Default Invoice Template ";//1
@@ -187,6 +188,7 @@
$LANG['format_tooltip'] = "format";//1
$LANG['for'] = "for";//1
$LANG['forum'] = "Forum";//1
+$LANG['free'] = "Free";//1
$LANG['from'] = "From";//1
$LANG['fwrite_error'] = "Did you get fwrite errors?";//1
$LANG['get_help'] = "Get Help";//1
@@ -230,10 +232,10 @@
$LANG['help_invoice_create'] = "Creating invoices is easy. Once a biller and customer have been entered into Simple Invoices all you need to do is select an invoice type from the 'Invoice +' menu, fill in the details and click 'Save Invoice'.";//1
$LANG['help_invoice_custom_fields'] = "Need more fields in the invoice screen? Want your own fields like 'Purchase Order', 'Project name' etc..
Simple Invoices allows you to add whatever fields you want into the invoices. These are called 'custom fields', to edit or setup your own fields select Custom Fields from the Options menu.";//1
$LANG['help_invoice_types'] = "In Simple Invoices there are 2 types of invoices available
-An Itemised Invoice is an invoice that list many different items in the same invoice, with optional notes area for each line item - think accounting/legal firms or a grocery store invoice.
-
-A Total Invoice is an invoice that - think an invoice from a plumber that lists the actions and then has one price and the tax associated.
-";//1
+ An Itemised Invoice is an invoice that list many different items in the same invoice, with optional notes area for each line item - think accounting/legal firms or a grocery store invoice.
+
+ A Total Invoice is an invoice that - think an invoice from a plumber that lists the actions and then has one price and the tax associated.
+ ";//1
$LANG['help_logging'] = "To log actions performed in Simple Invoices enable this option. This creates a log in the database of what actions were performed.
Note: At the moment the only way to view the log is in the database, soon we'll incorparte a nice log viewer into Simple Invoices.";//1
$LANG['help_manage_custom_fields'] = "Custom Fields are special fields that you can label as whatever you need.
This page allows you to define up to 4 custom fields for each of the following: products, customers, billers, and invoices.
Once you define a label of one of the fields, this field will become available for use. Ie. if you edit 'Invoice :: Custom field 1' and set the label as 'Project name', the next time you create an invoice there'll be a new field in the invoice screen called 'Project name'";//1
$LANG['help_mysql4'] = "As you are using MySQL 4 or below as your database server some features of Simple Invoices have been disabled. Some sql queries in Simple Invoices have taken advantage of new features in MySQL 5, so things like the quick reports here on the start page, some debtors reports and a few other features of Simple Invoices have been disabled.";//1
@@ -297,7 +299,9 @@
$LANG['itemised'] = "Itemised";//1
$LANG['itemised_style'] = "Itemised style";//1
$LANG['language'] = "Language";//1
+$LANG['large_dataset'] = "Large dataset";//1
$LANG['license'] = "License";//1
+$LANG['list'] = "List";//1
$LANG['loading'] = "Loading";//1
$LANG['locale'] = "Locale";//1
$LANG['logging'] = "Logging";//1
@@ -355,6 +359,9 @@
$LANG['no_users'] = "There have been no users created. Click the 'Add User' button above to create one";//1
$LANG['none'] = "none";//1
$LANG['note'] = "Note";//1
+$LANG['note_attributes'] = "Note Attributes";//1
+$LANG['note_as_description'] = "Use note as line item description";//1
+$LANG['note_expand'] = "Show line item description by default";//1
$LANG['notes'] = "Notes";//1
$LANG['notes_opt'] = "Notes (optional)";//1
$LANG['number_of_taxes_per_line_item'] = "Number of taxes per line item";//1
@@ -413,6 +420,7 @@
$LANG['process_payment_via_eway'] = "Process Payment via Eway";//1
$LANG['processing'] = "Processing, please wait ...";//1
$LANG['product'] = "Product";//1
+$LANG['product_attributes'] = "Product Attributes";//1
$LANG['product_description'] = "Product Description";//1
$LANG['product_edit'] = "Edit Product";//1
$LANG['product_enabled'] = "Product Enabled";//1
@@ -420,6 +428,7 @@
$LANG['product_sales'] = "Product Sales";//1
$LANG['product_to_add'] = "Product to add";//1
$LANG['product_unit_price'] = "Product Unit Price";//1
+$LANG['product_values'] = "Product Values";//1
$LANG['products'] = "Products";//1
$LANG['products_by_customer'] = "Products by Customer";//1
$LANG['products_sold_customer_total'] = "Products Sold - Customer - Total";//1
@@ -558,12 +567,14 @@
$LANG['type'] = "Type";//1
$LANG['Unit_Cost'] = "Unit Cost";//1
$LANG['unit_price'] = "Unit Price";//1
+$LANG['unpaid_invoices'] = "Unpaid Invoices";//1
$LANG['upgrading_simple_invoices'] = "Upgrading Simple Invoices";//1
$LANG['user_add'] = "Add User";//1
$LANG['users'] = "Users";//1
$LANG['using_simple_invoices'] = "Using Simple Invoices";//1
$LANG['value'] = "Value";//1
$LANG['view'] = "View";//1
+$LANG['visible'] = "Visible";//1
$LANG['want_more_fields'] = "Want more fields";//1
$LANG['warning_eway'] = "Note: You are about to charge your customers credit card - make sure you know what you're doing!!";
$LANG['weeks'] = "weeks";//1
diff --git a/modules/customers/details.php b/modules/customers/details.php
index 3216fd8a4..9f2f4000d 100755
--- a/modules/customers/details.php
+++ b/modules/customers/details.php
@@ -42,10 +42,34 @@
$customFieldLabel = getCustomFieldLabels();
$invoices = getCustomerInvoices($customer_id);
+//$start = (isset($_POST['start'])) ? $_POST['start'] : "0" ;
+$dir = "DESC" ;
+$sort = "id" ;
+$rp = (isset($_POST['rp'])) ? $_POST['rp'] : "25" ;
+$having = 'money_owed' ;
+$page = (isset($_POST['page'])) ? $_POST['page'] : "1" ;
+
+//$sql = "SELECT * FROM ".TB_PREFIX."invoices LIMIT $start, $limit";
+$invoice_owing = new invoice();
+$invoice_owing->sort=$sort;
+$invoice_owing->query=$_REQUEST['query'];
+$invoice_owing->qtype=$_REQUEST['qtype'];
+
+$large_dataset = getDefaultLargeDataset();
+if($large_dataset == $LANG['enabled'])
+{
+ $sth = $invoice_owing->select_all('large_count', $dir, $rp, $page, $having);
+} else {
+ $sth = $invoice_owing->select_all('', $dir, $rp, $page, $having);
+
+}
+$invoices_owing = $sth->fetchAll(PDO::FETCH_ASSOC);
+
//$customFieldLabel = getCustomFieldLabels("biller");
$smarty -> assign("stuff",$stuff);
$smarty -> assign('customer',$customer);
$smarty -> assign('invoices',$invoices);
+$smarty -> assign('invoices_owing',$invoices_owing);
$smarty -> assign('customFieldLabel',$customFieldLabel);
$smarty -> assign('pageActive', 'customer');
diff --git a/modules/install/essential.php b/modules/install/essential.php
index 828d18e24..b37c1894e 100644
--- a/modules/install/essential.php
+++ b/modules/install/essential.php
@@ -8,7 +8,7 @@
//JSON import
$importjson = new importjson();
$importjson->file = "./databases/json/essential_data.json";
- //$importjson->debug = true;
+ //$importjson->debug = true;
$importjson->pattern_find = array('si_','DOMAIN-ID','LOCALE','LANGUAGE');
$importjson->pattern_replace = array(TB_PREFIX,'1','en_GB','en_GB');
//dbQuery($importjson->collate());
diff --git a/modules/invoices/details.php b/modules/invoices/details.php
index 243e16527..8da6fb5de 100755
--- a/modules/invoices/details.php
+++ b/modules/invoices/details.php
@@ -31,9 +31,95 @@
for($i=1;$i<=4;$i++) {
- $customFields[$i] = show_custom_field("invoice_cf$i",$invoice["custom_field$i"],"write",'',"details_screen",'','','');
+ $customFields[$i] = show_custom_field("invoice_cf$i",$invoice["custom_field$i"],"write",'',"details_screen",'','','');
}
+foreach($invoiceItems as $key=>$value)
+{
+ //get list of attributes
+ $prod = getProduct($value['product_id']);
+ $json_att = json_decode($prod['attribute']);
+ if($json_att !== null)
+ {
+ $html ="
";
+ foreach($json_att as $k=>$v)
+ {
+ if($v == 'true')
+ {
+ $attr_name_sql = sprintf('select
+ a.name as name, a.enabled as enabled, t.name type
+ from
+ si_products_attributes as a,
+ si_products_attribute_type as t
+ where
+ a.type_id = t.id
+ AND a.id = %d', $k);
+ $attr_name = dbQuery($attr_name_sql);
+ $attr_name = $attr_name->fetch();
+
+ $sql2 = sprintf('select
+ a.name as name,
+ v.id as id,
+ v.value as value,
+ v.enabled as enabled
+ from
+ si_products_attributes a,
+ si_products_values v
+ where
+ a.id = v.attribute_id
+ AND a.id = %d', $k);
+ $states2 = dbQuery($sql2);
+
+ if($attr_name['enabled'] =='1' AND $attr_name['type'] == 'list')
+ {
+ $html .= "
";
+ $invoiceItems[$key]['html'] = $html;
+ }
+}
+
+//var_dump($invoiceItems);
$smarty -> assign("invoice",$invoice);
$smarty -> assign("defaults",$defaults);
$smarty -> assign("invoiceItems",$invoiceItems);
diff --git a/modules/invoices/invoice.php b/modules/invoices/invoice.php
index 097dffcd8..0bc470c03 100755
--- a/modules/invoices/invoice.php
+++ b/modules/invoices/invoice.php
@@ -49,6 +49,16 @@
$show_custom_field[$i] = show_custom_field("invoice_cf$i",'',"write",'',"details_screen",'','','');
}
+$sql = "select CONCAT(a.id, '-', v.id) as id, CONCAT(a.name, '-',v.value) as display from ".TB_PREFIX."products_attributes a, ".TB_PREFIX."products_values v where a.id = v.attribute_id;";
+$sth = dbQuery($sql);
+$matrix = $sth->fetchAll();
+$smarty -> assign("matrix", $matrix);
+
+$sql_prod = "select product_id as PID, (select count(product_id) from ".TB_PREFIX."products_matrix where product_id = PID ) as count from ".TB_PREFIX."products_matrix ORDER BY count desc LIMIT 1;";
+$sth_prod = dbQuery($sql_prod);
+$number_of_products = $sth_prod->fetchAll();
+
+$smarty -> assign("number_of_attributes", $number_of_products['0']['count']);
$smarty -> assign("billers",$billers);
$smarty -> assign("customers",$customers);
$smarty -> assign("taxes",$taxes);
diff --git a/modules/invoices/product_ajax.php b/modules/invoices/product_ajax.php
index 05c1e5bd3..4f61295a4 100644
--- a/modules/invoices/product_ajax.php
+++ b/modules/invoices/product_ajax.php
@@ -1,27 +1,79 @@
rowCount() > 0)
{
$row = $states->fetch();
+ $json_att = json_decode($row['attribute']);
+ if($json_att !== null)
+ {
+ $html ="
";
+ foreach($json_att as $k=>$v)
+ {
+ if($v == 'true')
+ {
+ $attr_name_sql = sprintf('select
+ a.name as name, a.enabled as enabled, t.name type
+ from
+ si_products_attributes as a,
+ si_products_attribute_type as t
+ where
+ a.type_id = t.id
+ AND a.id = %d', $k);
+ $attr_name = dbQuery($attr_name_sql);
+ $attr_name = $attr_name->fetch();
+
+ $sql2 = sprintf('select a.name as name, v.id as id, v.value as value, v.enabled as enabled from si_products_attributes a, si_products_values v where a.id = v.attribute_id AND a.id = %d', $k);
+ $states2 = dbQuery($sql2);
+
+ if($attr_name['enabled'] =='1' AND $attr_name['type'] == 'list')
+ {
+ $html .= "