فهرست منبع

More functionality added to the sample ourbiz, fluid2SquiLu modified to emit code with class fields with type annotation.

mingodad 13 سال پیش
والد
کامیت
5ae55813a3

+ 25 - 18
SquiLu-ourbiz/companies-uk.nut

@@ -4,16 +4,20 @@
  * Licensed under GPLv3, see http://www.gnu.org/licenses/gpl.html.
  * Licensed under GPLv3, see http://www.gnu.org/licenses/gpl.html.
  */
  */
  
  
+//start dummy nested scope to allow reload without complain about constants already defined 
+//also it hides from outer scope anything declared as local
+{
+ 
 local globals = getroottable();
 local globals = getroottable();
 
 
-function getCompaniesUkDBFileName(){
+local function getCompaniesUkDBFileName(){
 	if (globals.get("jniLog", false)) return APP_CODE_FOLDER + "/companies-uk-RG.db";
 	if (globals.get("jniLog", false)) return APP_CODE_FOLDER + "/companies-uk-RG.db";
 	if (globals.get("WIN32", false)) return APP_CODE_FOLDER + "/../../companies-uk/companies-uk-RG.db";
 	if (globals.get("WIN32", false)) return APP_CODE_FOLDER + "/../../companies-uk/companies-uk-RG.db";
 	return "/media/USBHD320/bo/uk/companies-uk-RG.db";
 	return "/media/USBHD320/bo/uk/companies-uk-RG.db";
 }
 }
 
 
 local companiesUkDB = null;
 local companiesUkDB = null;
-function getCompaniesUkDB(){
+local function getCompaniesUkDB(){
 	if(!companiesUkDB) {
 	if(!companiesUkDB) {
 		companiesUkDB = SQLite3(getCompaniesUkDBFileName());
 		companiesUkDB = SQLite3(getCompaniesUkDBFileName());
 		//companiesUkDB.exec_dml("PRAGMA cache_size = 4000;");
 		//companiesUkDB.exec_dml("PRAGMA cache_size = 4000;");
@@ -37,7 +41,7 @@ local function getCachedStmt(stmt_key, sql_or_func){
 }
 }
 
 
 
 
-function getCiaUkSearchList(search_str, search_post_code, search_sic_code,
+local function getCiaUkSearchList(search_str, search_post_code, search_sic_code,
 			search_origin_post_code, search_around_post_code , sic_street, page, limit){
 			search_origin_post_code, search_around_post_code , sic_street, page, limit){
 	local offset = page * limit;
 	local offset = page * limit;
 	local post_code_radius = strHasContent(search_around_post_code) ? search_around_post_code.tointeger() : 0;
 	local post_code_radius = strHasContent(search_around_post_code) ? search_around_post_code.tointeger() : 0;
@@ -182,34 +186,34 @@ limit ? offset ?
 	return  result;
 	return  result;
 }
 }
 
 
-function getOneDbNamedValuesFromStmt(stmt){
+local function getOneDbNamedValuesFromStmt(stmt){
 	local result;
 	local result;
 	if (stmt.step() == stmt.SQLITE_ROW) result = stmt.asTable();
 	if (stmt.step() == stmt.SQLITE_ROW) result = stmt.asTable();
 	stmt.reset();
 	stmt.reset();
 	return result || {};
 	return result || {};
 }
 }
 
 
-function getCiaUkById(id){
+local function getCiaUkById(id){
 	local stmt = getCachedStmt("getCiaUkById", "select * from company_view where id = ?");
 	local stmt = getCachedStmt("getCiaUkById", "select * from company_view where id = ?");
 	stmt.reset();
 	stmt.reset();
 	stmt.bind(1, id);
 	stmt.bind(1, id);
 	return getOneDbNamedValuesFromStmt(stmt);
 	return getOneDbNamedValuesFromStmt(stmt);
 }
 }
 
 
-function getCiaUkByIdSicCodes(id){
+local function getCiaUkByIdSicCodes(id){
 	local stmt = getCachedStmt("getCiaUkByIdSicCodes", "select sc.* from companies_sic_codes csc join sic_codes sc on csc.sic_code = sc.id where company_id = ?");	stmt.reset();
 	local stmt = getCachedStmt("getCiaUkByIdSicCodes", "select sc.* from companies_sic_codes csc join sic_codes sc on csc.sic_code = sc.id where company_id = ?");	stmt.reset();
 	stmt.bind(1, id);
 	stmt.bind(1, id);
 	return getDbListFromStmt(stmt);
 	return getDbListFromStmt(stmt);
 }
 }
 
 
-function getCiaUkByIdOldNames(id){
+local function getCiaUkByIdOldNames(id){
 	local stmt = getCachedStmt("getCiaUkByIdOldNames", "select condate, prev_name from companies_old_names where company_id = ?");
 	local stmt = getCachedStmt("getCiaUkByIdOldNames", "select condate, prev_name from companies_old_names where company_id = ?");
 	stmt.reset();
 	stmt.reset();
 	stmt.bind(1, id);
 	stmt.bind(1, id);
 	return getDbListFromStmt(stmt);
 	return getDbListFromStmt(stmt);
 }
 }
 
 
-function getDistances(search_origin_post_code, rows){
+local function getDistances(search_origin_post_code, rows){
 	if (rows.len() > 0){
 	if (rows.len() > 0){
 		local stmt = getCachedStmt("getDistances", [==[
 		local stmt = getCachedStmt("getDistances", [==[
 select
 select
@@ -235,7 +239,7 @@ and ref.post_code = ?
 	}
 	}
 }
 }
 
 
-function getEastinNorthingForPostCode(post_code){
+local function getEastinNorthingForPostCode(post_code){
 	local stmt = getCachedStmt("getEastinNorthingForPostCode", [=[
 	local stmt = getCachedStmt("getEastinNorthingForPostCode", [=[
 select easting, northing
 select easting, northing
 from post_codes
 from post_codes
@@ -251,11 +255,11 @@ where post_code = ?
 	return [easting, northing];
 	return [easting, northing];
 }
 }
 
 
-function toDeg(lat){
+local function toDeg(lat){
     return lat * 180.0 / math.PI;
     return lat * 180.0 / math.PI;
 }
 }
 
 
- function toRad(x) {
+ local function toRad(x) {
 	return x * math.PI / 180.0;
 	return x * math.PI / 180.0;
  }
  }
 
 
@@ -265,7 +269,7 @@ function toDeg(lat){
 // @param {OsGridRef} easting/northing to be converted to latitude/longitude
 // @param {OsGridRef} easting/northing to be converted to latitude/longitude
 // @return {LatLon} latitude/longitude (in OSGB36) of supplied grid reference
 // @return {LatLon} latitude/longitude (in OSGB36) of supplied grid reference
 //
 //
-function osGridToLatLong(easting, northing){
+local function osGridToLatLong(easting, northing){
   local E = easting.tofloat();
   local E = easting.tofloat();
   local N = northing.tofloat();
   local N = northing.tofloat();
 
 
@@ -334,7 +338,7 @@ function osGridToLatLong(easting, northing){
   //return lat, lon
   //return lat, lon
 }
 }
 
 
-function osGridToLatLongAdjusted(easting, northing){
+local function osGridToLatLongAdjusted(easting, northing){
 	local lat_long = osGridToLatLong(easting, northing)
 	local lat_long = osGridToLatLong(easting, northing)
 	//adjust lat, lon
 	//adjust lat, lon
 	lat_long[0] += 0.0024;
 	lat_long[0] += 0.0024;
@@ -342,12 +346,12 @@ function osGridToLatLongAdjusted(easting, northing){
 	return lat_long;
 	return lat_long;
 }
 }
 
 
-function getLatitudeLongitudeForPostCode(post_code){
+local function getLatitudeLongitudeForPostCode(post_code){
 	local easting_northing = getEastinNorthingForPostCode(post_code);
 	local easting_northing = getEastinNorthingForPostCode(post_code);
 	return osGridToLatLongAdjusted(easting_northing[0], easting_northing[1]);
 	return osGridToLatLongAdjusted(easting_northing[0], easting_northing[1]);
 }
 }
 
 
-function downloadChunked(host, file, extra_header=null){
+local function downloadChunked(host, file, extra_header=null){
 	local sock = socket.tcp();
 	local sock = socket.tcp();
 	sock.settimeout(1000);
 	sock.settimeout(1000);
 	sock.connect(host, 80);
 	sock.connect(host, 80);
@@ -376,7 +380,7 @@ function downloadChunked(host, file, extra_header=null){
 	return data.concat("\n");
 	return data.concat("\n");
 }
 }
 
 
-function getExtraCompanyDataOnNet(cnum){
+local function getExtraCompanyDataOnNet(cnum){
 	local mainHost = "wck2.companieshouse.gov.uk";
 	local mainHost = "wck2.companieshouse.gov.uk";
 
 
 	//get session
 	//get session
@@ -460,7 +464,7 @@ User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.11 (KHTML, like Gecko)
 	return data;
 	return data;
 }
 }
 
 
-function getExtraCompanyData(cid, cnum){
+local function getExtraCompanyData(cid, cnum){
 	local data;
 	local data;
 	local db = getCompaniesUkDB();
 	local db = getCompaniesUkDB();
 	local stmt = db.prepare("select data from company_extra_data where id = ?");
 	local stmt = db.prepare("select data from company_extra_data where id = ?");
@@ -570,4 +574,7 @@ add_uri_hanlders({
 		request.write_blob(mFile);
 		request.write_blob(mFile);
 		return true;
 		return true;
 	},
 	},
-});
+});
+
+} //end dummy nested scope
+ 

+ 14 - 8
SquiLu-ourbiz/fluid2SquiLu.nut

@@ -234,9 +234,11 @@ Write.Function <- function(t, ind){
 	Output(ind, "}\n\n");
 	Output(ind, "}\n\n");
 }
 }
 
 
+function getClassNameOrKey(t){return  t.attr.get("class", false) || t.key;}
+
 Write.Atributes <- function(t, ind, name){
 Write.Atributes <- function(t, ind, name){
 	local lname;
 	local lname;
-	local klass = t.attr.get("class", false) || t.key;
+	local klass = getClassNameOrKey(t);
 	if (klass.match("^Fl_")) lname = name;
 	if (klass.match("^Fl_")) lname = name;
 	else lname = name ;
 	else lname = name ;
 
 
@@ -571,12 +573,12 @@ FindMembers.Function <- function(t, list){
 		t.name = "__constructor()";
 		t.name = "__constructor()";
 		t.parent.constructor <- t.name;
 		t.parent.constructor <- t.name;
 	}
 	}
-	else 	list.push([ name, GetAccessMode(t, "public") ]);
+	else 	list.push([ name, GetAccessMode(t, "public"), getClassNameOrKey(t) ]);
 	FindMembers.group(t.body, list);
 	FindMembers.group(t.body, list);
 }
 }
 
 
 FindMembers["class"] <- function(t, list){
 FindMembers["class"] <- function(t, list){
-	list.push([ t.name, "public" ]);
+	list.push([ t.name, "public", t.attr.get("class", "null") ]);
 }
 }
 
 
 FindMembers.widget_class <- FindMembers["class"];
 FindMembers.widget_class <- FindMembers["class"];
@@ -586,13 +588,13 @@ FindMembers.widget <- function(t, list){
 		list.push([ t.name.match("^[%w_]+"), GetAccessMode(t, "public"), "{}" ]);
 		list.push([ t.name.match("^[%w_]+"), GetAccessMode(t, "public"), "{}" ]);
 	}
 	}
 	else if (t.name.match("^[%w_]+$")){
 	else if (t.name.match("^[%w_]+$")){
-		list.push([ t.name, GetAccessMode(t, "public") ]);
+		list.push([ t.name, GetAccessMode(t, "public") , getClassNameOrKey(t)]);
 	}
 	}
 	if (t.get("body", false)) FindMembers.group(t.body, list);
 	if (t.get("body", false)) FindMembers.group(t.body, list);
 }
 }
 
 
 FindMembers.decl <- function(t, list){
 FindMembers.decl <- function(t, list){
-	list.push([ t.name, GetAccessMode(t, "private") ]);
+	list.push([ t.name, GetAccessMode(t, "private"), getClassNameOrKey(t) ]);
 }
 }
 
 
 FindMembers.submenu <- function(t, list){
 FindMembers.submenu <- function(t, list){
@@ -603,7 +605,7 @@ FindMembers.submenu <- function(t, list){
 				//print("body", k2, v2);
 				//print("body", k2, v2);
 				if(type(v2) == "table"){
 				if(type(v2) == "table"){
 					//foreach(k3,v3 in v2) print("menuitem", k3,v3);
 					//foreach(k3,v3 in v2) print("menuitem", k3,v3);
-					if(v2.get("name", false)) list.push([ v2.name, GetAccessMode(t, "public") ]);
+					if(v2.get("name", false)) list.push([ v2.name, GetAccessMode(t, "public"), getClassNameOrKey(t)]);
 				}
 				}
 			}
 			}
 		}
 		}
@@ -611,7 +613,7 @@ FindMembers.submenu <- function(t, list){
 }
 }
 
 
 FindMembers.menuitem <- function(t, list){
 FindMembers.menuitem <- function(t, list){
-	list.push([ t.name, GetAccessMode(t, "public") ]);
+	list.push([ t.name, GetAccessMode(t, "public"), getClassNameOrKey(t) ]);
 }
 }
 
 
 function WriteVariables(ind, vars, type){
 function WriteVariables(ind, vars, type){
@@ -620,7 +622,11 @@ function WriteVariables(ind, vars, type){
 	Output(ind, "// Declaration of %s\n", type);
 	Output(ind, "// Declaration of %s\n", type);
 	foreach(i in vars) {
 	foreach(i in vars) {
 		if (defined.get(i[0], false)) {}
 		if (defined.get(i[0], false)) {}
-		else if (i[1] == "public") Output(ind, "%s = null;\n", i[0]);
+		else if (i[1] == "public") {
+			local type_name = i.get(2, false);
+			if(type_name) Output(ind, "%s : %s;\n", i[0], type_name);
+			else Output(ind, "%s = null;\n", i[0]);
+		}
 		else {
 		else {
 			local multi_decl = i[0].strip().split(';');
 			local multi_decl = i[0].strip().split(';');
 			if(multi_decl.len() > 1){
 			if(multi_decl.len() > 1){

+ 15 - 15
SquiLu-ourbiz/ourbiz-client.nut

@@ -696,9 +696,9 @@ class AppServer
     }
     }
 
 
     function get_product_for_edit(product_id, rec, prices_list, kit_list, kit_details){
     function get_product_for_edit(product_id, rec, prices_list, kit_list, kit_details){
-        local qs, js;
-        qs = format("/DB/GetOne?products=%d&product_for_edit=1", product_id);
-        _get_data("GET", qs, 0, js);
+        local buf = blob(0, 8192);
+        local qs = format("/DB/GetOne?products=%d&product_for_edit=1", product_id);
+        _get_data("GET", qs, 0, buf);
 
 
 /*
 /*
         JsonJSMN p;
         JsonJSMN p;
@@ -712,19 +712,19 @@ class AppServer
             parse_jsonObject2map(p, kit_details, js.c_str());
             parse_jsonObject2map(p, kit_details, js.c_str());
         }
         }
 */
 */
-        if(js[0] != '[') throw "Invalid sle encoded !";
+        if(buf[0] != '[') throw "Invalid sle encoded !";
         local start = 0;
         local start = 0;
-        local pos = sle2map(js, rec, start);
-        pos = sle2vecOfvec(js, prices_list, pos);
-        pos = sle2vecOfvec(js, kit_list, pos);
-        sle2map(js, kit_details, pos);
+        local pos = sle2map(buf, rec, start);
+        pos = sle2vecOfvec(buf, prices_list, pos);
+        pos = sle2vecOfvec(buf, kit_list, pos);
+        sle2map(buf, kit_details, pos);
         prices_list.remove(0); //remove header
         prices_list.remove(0); //remove header
         kit_list.remove(0); //remove header
         kit_list.remove(0); //remove header
     }
     }
     function get_product_aux_data(sales_tax_data, measure_units_data, warranty_data){
     function get_product_aux_data(sales_tax_data, measure_units_data, warranty_data){
-        local qs, js = blob(0, 8192);
-        qs = "/DB/GetOne?products=0&product_aux_data=1";
-        _get_data("GET", qs, 0, js);
+        local buf = blob(0, 8192);
+        local qs = "/DB/GetOne?products=0&product_aux_data=1";
+        _get_data("GET", qs, 0, buf);
 /*
 /*
         JsonJSMN p;
         JsonJSMN p;
         JsonJSMN::jsmntok_t tok;
         JsonJSMN::jsmntok_t tok;
@@ -736,11 +736,11 @@ class AppServer
             parse_jsonArray2Vector(p, warranty_data, js.c_str());
             parse_jsonArray2Vector(p, warranty_data, js.c_str());
         }
         }
 */
 */
-        if(js[0] != '[') throw "Invalid sle encoded !";
+        if(buf[0] != '[') throw "Invalid sle encoded !";
         local start = 0;
         local start = 0;
-        local pos = sle2vecOfvec(js, sales_tax_data, start);
-        pos = sle2vecOfvec(js,  measure_units_data, pos);
-        pos = sle2vecOfvec(js, warranty_data, pos);
+        local pos = sle2vecOfvec(buf, sales_tax_data, start);
+        pos = sle2vecOfvec(buf,  measure_units_data, pos);
+        pos = sle2vecOfvec(buf, warranty_data, pos);
         //now deleting header data
         //now deleting header data
         sales_tax_data.remove(0);
         sales_tax_data.remove(0);
         measure_units_data.remove(0);
         measure_units_data.remove(0);

+ 300 - 5
SquiLu-ourbiz/ourbiz-fltk.nut

@@ -220,10 +220,19 @@ class Fl_Image_Box extends Fl_Button {
 	}
 	}
 }
 }
 
 
-class My_Fl_Float_Input extends Fl_Float_Input {
+class My_Fl_Float_Input extends Fl_Float_Input_Fmt {
 	constructor(px, py, pw, ph, pl=""){
 	constructor(px, py, pw, ph, pl=""){
 		base.constructor(px, py, pw, ph, pl);
 		base.constructor(px, py, pw, ph, pl);
 	}
 	}
+	
+	function handle(event)
+	{
+		if(event == FL_KEYBOARD)
+		{
+			if(Fl.event_key() == FL_KP_Plus) return 0;
+		}
+		return base.handle(event);
+	}
 }
 }
 
 
 
 
@@ -2103,6 +2112,253 @@ function print_products_list(sender=null, udata=null)
 	}
 	}
 }
 }
 
 
+class OurProductPrices extends ProductPricesGroup
+{
+	_product_id = null;
+	_prices_for_calc_rec = null;
+
+	constructor()
+	{
+		base.constructor();
+		setup_grid(grid, this);
+		setDbActionControls(dbAction, btnDbAction);
+		dbUpdater()->table_name = "product_prices";
+		dbUpdater()->hasVersion = false;
+		local cols_info = [
+			"id|ID|0",
+			"quantity|Quantity|8|R|N",
+			"markup_pct|Markup|8|R|M",
+			"discount_pct|Discount|8|R|M",
+			"price|Price|8|R|M",
+			"mdate|MDate|12",
+			"cdate|CDate|12",
+		];
+		grid->set_cols(cols_info);
+
+		_product_id = 0;
+		db_product_prices_markup_pct.callback(on_change_prices);
+		db_product_prices_discount_pct.callback(on_change_prices);
+		db_product_prices_price.callback(on_change_prices);
+	}
+
+	function product_id(id, doLoadData=true)
+	{
+		if(doLoadData){
+			local cursor_wait = fl_cursor_wait();
+			grid->clear_data_rows();
+			appServer.product_prices_list(grid->_data, id);
+		}
+		grid->recalc_data();
+		dbAction->action(Fl_Choice_dbAction.e_insert);
+		_product_id = id;
+	}
+
+	function get_data_clear(){
+		grid->clear_data_rows();
+		return grid->_data;
+	}
+
+	function do_edit(id)
+	{
+		base.do_edit(id);
+		delayed_focus(db_product_prices_quantity);
+	}
+
+	function row_edit(id)
+	{
+		do_edit(id);
+		//if(found)
+	}
+
+	function get_widget_changed(uw)
+	{
+		base.get_widget_changed(uw);
+		uw.value_for_insert("product_id", _product_id);
+	}
+
+	function on_btnDbAction()
+	{
+		if(_product_id){ //nothing to do if it is 0
+			base.on_btnDbAction();
+			product_id(_product_id);
+		}
+	}
+
+	function on_change_prices(wdg, udata)
+	{
+		local input_fld_map = {
+				sell_markup = db_product_prices_markup_pct, 
+				discount_over_sales = db_product_prices_discount_over_sales,
+				sell_price2 = db_product_prices_price,
+			};
+		foreach(k,v in input_fld_map){
+			if(v == wdg) {
+				_record["trigger"] = k;
+				break;
+			}
+		}
+		appServer.do_dbaction(_record, "calc_price_by_quantity", "products", _product_id, 0);
+		
+		local  wfq = Widget_Fill_By_Map(_record);
+		wfq.set_widget_value_by_map(input_fld_map);	
+	}
+}
+
+class OurProductKit extends ProductKitGroup
+{
+	_products_list_window = null;
+	_kit_id = null;
+	_rec_details = null;
+
+	constructor()
+	{
+		base.constructor();
+		setup_grid(grid, this);
+		setDbActionControls(dbAction, btnDbAction);
+		dbUpdater()->table_name = "product_prices";
+		dbUpdater()->hasVersion = false;
+		local cols_info = [
+				"id|ID|0",
+				"product_id|Code|6|R",
+				"sell_description|Description|-1",
+				"quantity|Quantity|8|R|N",
+				"amount|Price|8|R|M",
+				"quantity_onhand|Onhand|8|R|N",
+			];
+		grid->set_cols(cols_info);
+		
+		local MydbUpdater = class extends DBUpdateByWidget {
+				_kit_id = null;
+				
+				constructor(akit_id)
+				{
+					base.constructor();
+					hasVersion = false;
+					hasMdate = false;
+					table_name = "product_kits";
+					_kit_id = 0;
+				}
+				function getWhereClause()
+				{
+					return " where kit_id=? and product_id=? ";
+				}
+
+				function bindWhereClause(stmt, lastParam)
+				{
+					stmt.bind(++lastParam, _kit_id);
+					stmt.bind(++lastParam, _edit_id);
+					return lastParam;
+				}
+			};
+		dbUpdater(new MydbUpdater(_kit_id));
+
+		db_product_kits_sell_description.callback(on_search_product_cb);
+		btnSearchProduct.callback(on_search_product_cb);
+		db_product_kits_product_id.callback(on_change_product_id);
+		btnKitPartOf.callback(on_part_of);
+	}
+
+	function product_id(id, doLoadData=true)
+	{
+		if(doLoadData){
+			local cursor_wait = fl_cursor_wait();
+			grid->clear_data_rows();
+			appServer.products_kit_list(grid->_data, id, btnKitPartOf->value());
+		}
+		grid->recalc_data();
+
+		_kit_id = id;
+		fill_kit_details(doLoadData);
+		dbAction->action(Fl_Choice_dbAction.e_insert);
+		on_Change_dbAction();
+	}
+
+	function get_data_clear(){
+		grid->clear_data_rows();
+		return grid->_data;
+	}
+
+	function do_edit(id)
+	{
+		base.do_edit(id);
+		appServer.products_kit_edit(_record, id);
+		fill_edit_form();
+		delayed_focus(db_product_kits_product_id);
+	}
+
+	function row_edit(id)
+	{
+		do_edit(id);
+	}
+
+	function fill_edit_form(asBlank=false)
+	{
+		local wfq = WidgetFillByMap(_record);
+		WFQ(product_kits, product_id);
+		WFQ(product_kits, quantity);
+		WFQ(product_kits, sell_description);
+		WFQ2(product_kits, product_price, sell_price);
+	}
+
+	function get_widget_changed(uw)
+	{
+		uw.value_for_insert("kit_id", _kit_id);
+		WGC(product_kits, product_id);
+		WGC(product_kits, quantity);
+	}
+
+	function fill_kit_details(doLoadData=true)
+	{
+		if(doLoadData){
+			appServer.get_record(_rec_details, "product_kits", 0, _kit_id, "&kit_details=1");
+		}
+		local wfq = WidgetFillByMap(_rec_details);
+		wfq.set_widget_value(kit_parts, "nproducts");
+		wfq.set_widget_value(kit_prices_sum, "amt_total");
+	}
+
+	function on_btnDbAction()
+	{
+		base.on_btnDbAction();
+		product_id(_kit_id);
+		fill_edit_form(true);
+		delayed_focus(db_product_kits_sell_description);
+	}
+
+	function on_change_product_id(sender, udata)
+	{
+		local id = db_product_kits_product_id->value().tointeger();
+		if(!id) return;
+		appServer.get_record(_record, "product_kits", 0, id, "&kit_product=1");
+		fill_edit_form();
+		delayed_focus(db_product_kits_quantity);
+	}
+
+	function validate_product_id(sender, aid)
+	{
+		db_product_kits_product_id->value(aid);
+		db_product_kits_product_id->set_changed();
+		on_change_product_id(sender, aid);
+	}
+
+	function on_search_product_cb(sender, udata)
+	{
+		show_create_owned(_products_list_window);
+		local search_str = db_product_kits_sell_description->value();
+		local doSearchLast = (search_str.len() == 1) && (search_str[0] == ' ');
+		_products_list_window->search_for_me(search_str, this, validate_product_id, 0, doSearchLast);
+	}
+
+	function on_part_of(sender, udata){
+		product_id(_kit_id);
+		if(btnKitPartOf->value()){
+			grpSearchEdit->hide();
+		} else {
+			grpSearchEdit->show();
+		}
+	}
+}
+
 class MyEditProductWindow extends EditProductWindow {
 class MyEditProductWindow extends EditProductWindow {
 	_ourBarChart = null;
 	_ourBarChart = null;
 	_ourHistory = null;
 	_ourHistory = null;
@@ -2136,23 +2392,43 @@ class MyEditProductWindow extends EditProductWindow {
 		choice->value(0);
 		choice->value(0);
 		choice.callback(on_history_cb);
 		choice.callback(on_history_cb);
 
 
-		_ourProductKit = new ProductKitGroup();
+		_ourProductKit = new ProductKitGroup(); //OurProductKit();
 		replace_widget_for(tabKit, _ourProductKit);
 		replace_widget_for(tabKit, _ourProductKit);
 		//_ourProductKit->btnShowChart.callback(on_show_chart_cb);
 		//_ourProductKit->btnShowChart.callback(on_show_chart_cb);
 
 
-		_ourProductPrices = new ProductPricesGroup();
+		_ourProductPrices = new ProductPricesGroup(); //OurProductPrices();
 		replace_widget_for(productPrices, _ourProductPrices);
 		replace_widget_for(productPrices, _ourProductPrices);
 
 
 		tabsMoreData.callback(tabsMoreData_cb);
 		tabsMoreData.callback(tabsMoreData_cb);
-
+		
+		db_products_buy_price.callback(on_change_prices);
+		db_products_buy_discount.callback(on_change_prices);
+		db_products_buy_other_costs.callback(on_change_prices);
+		db_products_sell_markup.callback(on_change_prices);
+		db_products_markup_to_discount.callback(on_change_prices);
+		db_products_sell_price.callback(on_change_prices);
+		db_products_sell_price2.callback(on_change_prices);
+		db_products_price_decimals.callback(on_change_prices);
+		
 		load_aux_data();
 		load_aux_data();
 	}
 	}
+	
+	function get_record_by_id(id : integer) {
+		local prices = [];
+		local kit = [];
+		local kit_details = {};
+		appServer.get_product_for_edit(dbUpdater()->edit_id, _record, 
+			prices /*ourProductPrices->get_data_clear()*/,
+			kit /*ourProductKit->get_data_clear()*/,
+			kit_details /*ourProductKit->_rec_details*/);
+	}
+	
 	function do_edit_delayed(udata)
 	function do_edit_delayed(udata)
 	{
 	{
 		base.do_edit_delayed(udata);
 		base.do_edit_delayed(udata);
 		delayed_focus(db_products_sell_description);
 		delayed_focus(db_products_sell_description);
 		local image_id = _record.get("image_id", false);
 		local image_id = _record.get("image_id", false);
-		if(image_id) button_show_db_image(btnImage, image_id.tointeger(), null, false, false);
+		if(image_id && image_id.len()) button_show_db_image(btnImage, image_id.tointeger(), null, false, false);
 		else {
 		else {
 			btnImage->hide();
 			btnImage->hide();
 			//btnImage->image(&jpegNophoto);
 			//btnImage->image(&jpegNophoto);
@@ -2206,6 +2482,25 @@ class MyEditProductWindow extends EditProductWindow {
 					query_limit, dbUpdater()->edit_id);
 					query_limit, dbUpdater()->edit_id);
 		tbl->set_new_data(data);
 		tbl->set_new_data(data);
 	}
 	}
+
+	function on_change_prices(sender, udata)
+	{
+		this = sender->window();
+		local prices_rec = {};
+		local price_fields = ["buy_price", "buy_discount", "buy_other_costs", "sell_markup", "sell_price",
+			"markup_to_discount", "sell_price2", "price_decimals"];
+		foreach(k in price_fields) {
+			//print(k, map.get(k, 0.0));
+			prices_rec[k] <- this["db_products_" + k].value();
+		}
+		
+		appServer.do_dbaction(prices_rec, "calc_product_price", "products", dbUpdater()->edit_id, 0);
+		
+		foreach(k in price_fields) {
+			//print(k, map.get(k, 0.0));
+			this["db_products_" + k].value(prices_rec[k]);
+		}
+	}
 }
 }
 
 
 class MyEditProductSalesWindow extends MyEditProductWindow {
 class MyEditProductSalesWindow extends MyEditProductWindow {

+ 16 - 13
SquiLu-ourbiz/ourbiz-gui.fl

@@ -2681,9 +2681,9 @@ widget_class EditEntityWindow {
 } 
 } 
 
 
 widget_class EditProductWindow {
 widget_class EditProductWindow {
-  label {Edit Products}
-  xywh {34 28 800 560} type Double hide resizable
-  class Edit_Base_Window
+  label {Edit Products} open
+  xywh {34 28 800 560} type Double resizable
+  class Edit_Base_Window visible
 } {
 } {
   Fl_Output db_products_id {
   Fl_Output db_products_id {
     macro_name {db products id}
     macro_name {db products id}
@@ -2706,11 +2706,11 @@ widget_class EditProductWindow {
     xywh {665 35 130 25} labeltype NO_LABEL labelsize 16 textsize 16
     xywh {665 35 130 25} labeltype NO_LABEL labelsize 16 textsize 16
     code0 {=add_input_field_to_map("$(1)", "$(2)", $(name));}
     code0 {=add_input_field_to_map("$(1)", "$(2)", $(name));}
   }
   }
-  Fl_Tabs tabs {
+  Fl_Tabs tabs {open
     xywh {5 35 790 520} selection_color 4 labelsize 16 labelcolor 7 resizable
     xywh {5 35 790 520} selection_color 4 labelsize 16 labelcolor 7 resizable
   } {
   } {
     Fl_Group tabMain {
     Fl_Group tabMain {
-      label Main
+      label Main selected
       xywh {5 60 790 495} color 246 labelsize 16 resizable
       xywh {5 60 790 495} color 246 labelsize 16 resizable
     } {
     } {
       Fl_Input db_products_reference_code {
       Fl_Input db_products_reference_code {
@@ -2939,7 +2939,7 @@ db_products_tags->wrap_mode(o->value(), 0);}
       }
       }
     }
     }
     Fl_Group tabPrices {
     Fl_Group tabPrices {
-      label Prices
+      label Prices open
       xywh {5 60 790 495} color 246 labelsize 16 hide
       xywh {5 60 790 495} color 246 labelsize 16 hide
     } {
     } {
       Fl_Group {} {
       Fl_Group {} {
@@ -2980,16 +2980,19 @@ db_products_tags->wrap_mode(o->value(), 0);}
           code1 {//o->decimal_places(-6);}
           code1 {//o->decimal_places(-6);}
           class Fl_Float_Input_Fmt
           class Fl_Float_Input_Fmt
         }
         }
-        Fl_Input markup_to_discount {
+        Fl_Input db_products_markup_to_discount {
           label {Margin %}
           label {Margin %}
+          macro_name {db products markup_to_discount}
           xywh {531 115 115 25} type Float labelsize 16 align 5 textsize 16
           xywh {531 115 115 25} type Float labelsize 16 align 5 textsize 16
-          code0 {//o->decimal_places(-6);}
+          code0 {=add_input_field_to_map("$(1)", "$(2)", $(name));}
+          code1 {o->decimal_places(-6);}
           class Fl_Float_Input_Fmt
           class Fl_Float_Input_Fmt
         }
         }
-        Fl_Input db_products_sell_price_ro {
+        Fl_Input db_products_sell_price2 {
           label {Sales $}
           label {Sales $}
-          dirty_name db_products_sell_price_ro
+          macro_name {db products sell_price2}
           xywh {658 115 115 25} type Float labelsize 16 align 5 textsize 16
           xywh {658 115 115 25} type Float labelsize 16 align 5 textsize 16
+          code0 {=add_input_field_to_map("$(1)", "$(2)", $(name));}
           class Fl_Float_Input_Fmt
           class Fl_Float_Input_Fmt
         }
         }
         Fl_Input db_products_price_decimals {
         Fl_Input db_products_price_decimals {
@@ -3204,9 +3207,9 @@ db_products_tags->wrap_mode(o->value(), 0);}
 } 
 } 
 
 
 widget_class EditOrderWindow {
 widget_class EditOrderWindow {
-  label {Edit Order} open selected
-  xywh {255 97 800 560} type Double labelsize 16 resizable
-  class Edit_Base_Window visible
+  label {Edit Order}
+  xywh {255 97 800 560} type Double labelsize 16 hide resizable
+  class Edit_Base_Window
 } {
 } {
   Fl_Group {} {open
   Fl_Group {} {open
     xywh {5 1 792 62}
     xywh {5 1 792 62}

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 450 - 450
SquiLu-ourbiz/ourbiz-gui.nut


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 685 - 111
SquiLu-ourbiz/ourbiz.nut


+ 2 - 2
SquiLu-ourbiz/s/ourbiz/app-base.js

@@ -1131,7 +1131,7 @@ dad.encodeSizeString = function(str){
 	return dad.stringBytesLength(str) + ':' + str;
 	return dad.stringBytesLength(str) + ':' + str;
 }
 }
 
 
-dad.getFormDataWithPrefix = function(form, prefix) {
+dad.getFormDataWithPrefix = function(form, prefix, doNotCheckOriginal) {
 	var prefix_len = prefix ? prefix.length : 0;
 	var prefix_len = prefix ? prefix.length : 0;
 	var fields = form.elements;
 	var fields = form.elements;
 	var values = [];
 	var values = [];
@@ -1156,7 +1156,7 @@ dad.getFormDataWithPrefix = function(form, prefix) {
 		else fld_value = fld.value;
 		else fld_value = fld.value;
 		if(prefix_len && fld.name.indexOf(prefix) != 0) continue;
 		if(prefix_len && fld.name.indexOf(prefix) != 0) continue;
 		var fld_name = prefix_len ? fld.name.substring(prefix_len) : fld.name;
 		var fld_name = prefix_len ? fld.name.substring(prefix_len) : fld.name;
-		if(original){
+		if(original && !doNotCheckOriginal){
 			if(original[fld_name] == fld_value) continue;
 			if(original[fld_name] == fld_value) continue;
 			if(fld_value == "" && original[fld_name] == null) continue;
 			if(fld_value == "" && original[fld_name] == null) continue;
 		}
 		}

+ 32 - 1
SquiLu-ourbiz/s/ourbiz/products.js

@@ -124,7 +124,7 @@ Jaml.register('ProductEditWindow', function(args) {
 							td(input({type: "text", name: "p_buy_other_costs", cls:"size9"})),
 							td(input({type: "text", name: "p_buy_other_costs", cls:"size9"})),
 							td(input({type: "text", name: "p_sell_markup", cls:"size9"})),
 							td(input({type: "text", name: "p_sell_markup", cls:"size9"})),
 							td(input({type: "text", name: "p_sell_margin", cls:"size9"})),
 							td(input({type: "text", name: "p_sell_margin", cls:"size9"})),
-							td(input({type: "text", name: "p_sell_price", cls:"size9"}))
+							td(input({type: "text", name: "p_sell_price2", cls:"size9"}))
 						),
 						),
 						tr(
 						tr(
 							td({rowspan:3, colspan:4},
 							td({rowspan:3, colspan:4},
@@ -221,6 +221,20 @@ function ProductEditWindowOnSubmit(btn) {
 	return dad.formOnSubmit(ProductEditWindowRefresh, this.form, "products")
 	return dad.formOnSubmit(ProductEditWindowRefresh, this.form, "products")
 }
 }
 
 
+function onProductEditCalcPrice(){
+	//alert(this.value)
+	var win = dad.getWindowForChild(this);
+	if(win && win.ud.ajaxCalcPrice) {
+		var form_prefix = "p_";
+		var values = dad.getFormDataWithPrefix(this.form, form_prefix, true);
+		values.push("__table__=products");
+		values.push("__id__=" + win.ud.edit_id);
+		values.push("__action__=calc_product_price");
+		values.push("trigger=" + this.name.substring(form_prefix.length));
+		win.ud.ajaxCalcPrice.post('/DB/Action', values.join('&'), "POST");
+	}	
+}
+
 Jaml.register('ProductsHistoryOptions', function(args) {
 Jaml.register('ProductsHistoryOptions', function(args) {
 	option({value:""}, "----");
 	option({value:""}, "----");
 	option(_tr("Sales by Date"));
 	option(_tr("Sales by Date"));
@@ -285,6 +299,12 @@ function newProductEditWindow(all_sales_buys){
 			dad.getImageForImg(img, img_id);
 			dad.getImageForImg(img, img_id);
 		}
 		}
 
 
+		var calc_fields_list = ["p_buy_price","p_buy_discount", "p_buy_other_costs", 
+			"p_sell_markup", "p_sell_margin", "p_sell_price",  "p_sell_price2"];
+		for(var i in calc_fields_list){
+			myform[calc_fields_list[i]].onchange = onProductEditCalcPrice;
+		}
+		
 		var btnRptProductsList = $("rptProductsList" + newId);
 		var btnRptProductsList = $("rptProductsList" + newId);
 		btnRptProductsList.onclick = function(){
 		btnRptProductsList.onclick = function(){
 			var url = '/DB/GetList?list=products&pdf=1';
 			var url = '/DB/GetList?list=products&pdf=1';
@@ -317,6 +337,17 @@ function newProductEditWindow(all_sales_buys){
 			}
 			}
 		}, myform.p_warranty_id);
 		}, myform.p_warranty_id);
 		if(ajaxAuxTables) ajaxAuxTables.post('/DB/GetList', 'list=warranty_types&short_list=1', "GET");
 		if(ajaxAuxTables) ajaxAuxTables.post('/DB/GetList', 'list=warranty_types&short_list=1', "GET");
+
+		win.ud.ajaxCalcPrice = new dad.Ajax(function(){
+			if(this.status == 200){
+				//retrieve result as an JavaScript object
+				var record = dad.parseSLEData2Object(this.responseText); 
+				var form = $(data.form_id);
+				dad.formFillByRecord(form, record, "p_");
+			} else {
+				alert("An error has occured making the request");
+			}
+		}, null, false);
 		
 		
 		var btn = $(btnAction_id);
 		var btn = $(btnAction_id);
 		btn.onclick = ProductEditWindowOnSubmit;
 		btn.onclick = ProductEditWindowOnSubmit;

+ 3 - 1
SquiLu-ourbiz/utils-fltk.nut

@@ -21,6 +21,7 @@ function setAppFont(fontName)
             {
             {
                 if( font.name.find(fontName) >= 0)
                 if( font.name.find(fontName) >= 0)
                 {
                 {
+		    //print(font.name);
                     if( font.attributes != 0 )
                     if( font.attributes != 0 )
                     {
                     {
                         if (( font.attributes & FL_BOLD) &&
                         if (( font.attributes & FL_BOLD) &&
@@ -113,7 +114,8 @@ Fl.visual(FL_RGB);
 Fl.option(Fl.OPTION_ARROW_FOCUS, true);
 Fl.option(Fl.OPTION_ARROW_FOCUS, true);
 fl_register_images();
 fl_register_images();
 /*
 /*
-setting font this way on linux makes Fl_Pack child misbehave
+//setting font this way on linux makes Fl_Pack child misbehave
+//also with this bad pdf right align
 setAppFont("erdana");
 setAppFont("erdana");
 */
 */
 Fl.add_focus_changing_handler(fltk_focus_changing);
 Fl.add_focus_changing_handler(fltk_focus_changing);

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است