Переглянути джерело

More advance to a functional state.

mingodad 13 роки тому
батько
коміт
fccd7c9a52

Різницю між файлами не показано, бо вона завелика
+ 953 - 302
ext/sq_fltk.cpp


+ 0 - 9
ourbiz/edit-product-window.nut

@@ -1,12 +1,3 @@
-class Fl_Data_Table extends Flv_Table {
-	_forPrint = null;
-	
-	constructor(px, py, pw, ph, pl=""){
-		base.constructor(px, py, pw, ph, pl);
-		_forPrint=false;
-	}
-}
-
 class Flu_Tree_Browser extends Flv_Table {
 	_forPrint = null;
 	

+ 0 - 53
ourbiz/list-search-window.nut

@@ -1,12 +1,3 @@
-class Fl_Data_Table extends Flv_Table {
-	_forPrint = null;
-	
-	constructor(px, py, pw, ph, pl=""){
-		base.constructor(px, py, pw, ph, pl);
-		_forPrint=false;
-	}
-}
-
 class Fl_Box_ClearLabel extends Fl_Box {
 	constructor(px, py, pw, ph, pl=""){
 		base.constructor(px, py, pw, ph, pl);
@@ -217,47 +208,3 @@ function cb_btnInsert(sender, udata){
 	local win = pr.showChildWindow("Order Edit", EditOrderWindow);
 }
 }
-
-class EntitiesListSearch extends ListSearch {
-
-	constructor() {
-		base.constructor();
-		label(_tr("Entities List Search"));
-	}
-	function cb_btnInsert(sender, udata){
-		local pr = sender.parent_root();
-		local win = pr.showChildWindow("Entity Edit", EditEntitiesWindow);
-	}
-}
-
-class ProductsListSearch extends ListSearch {
-
-	constructor() {
-		base.constructor();
-		label(_tr("Products List Search"));
-	}
-	function cb_btnInsert(sender, udata){
-		local pr = sender.parent_root();
-		local win = pr.showChildWindow("Product Edit", EditProductWindow);
-	}
-}
-
-class OrdersListSearch extends ListSearch {
-
-	constructor() {
-		base.constructor();
-		label(_tr("Orders List Search"));
-	}
-	function cb_btnInsert(sender, udata){
-		local pr = sender.parent_root();
-		local win = pr.showChildWindow("Order Edit", EditOrderWindow);
-	}
-}
-
-class PaymentsListSearch extends ListSearch {
-
-	constructor() {
-		base.constructor();
-		label(_tr("Payments List Search"));
-	}
-}

+ 1 - 1
ourbiz/main-window.nut

@@ -320,7 +320,7 @@ function cb_btnGLTransactions(){print(__LINE__);}
 function cb_btnOrdersSum(){print(__LINE__);}
 function cb_btnSalesTaxRates(sender, udata){
 	local pr = sender.parent_root();
-	local win = pr.showChildWindow("Sales Tax Rates List/Edit", SalesTaxRatesEditWindow);
+	local win = pr.showChildWindow("Sales Tax Rates List/Edit", OurSalesTax);
 }
 function cb_btnOrderTypes(){print(__LINE__);}
 function cb_btnPaymentTypes(){print(__LINE__);}

+ 2 - 0
ourbiz/ourbiz-client.nut

@@ -846,6 +846,7 @@ class AppServer
     }
 };
 
+/*
 local data = [];
 local appServer = AppServer.getAppServer();
 appServer.credentials("mingote", "tr14pink");
@@ -869,3 +870,4 @@ function OurBizClientAtExit(){
 setatexithandler(OurBizClientAtExit);
 
 //print(OurBizClientAtExit, getatexithandler());
+*/

+ 375 - 4
ourbiz/ourbiz-fltk.nut

@@ -1,3 +1,8 @@
+dofile("ourbiz-client.nut");
+local appServer = AppServer.getAppServer();
+appServer.credentials("mingote", "tr14pink");
+appServer.connect("localhost", 8855);
+
 function _tr(str){ return str;}
 
 class MyBaseWindow extends Fl_Window {
@@ -17,15 +22,158 @@ class MyBaseWindow extends Fl_Window {
 		}
 		win->show();
 		return win;
-	}
+	}	
 }
 
-class Fl_Data_Table extends Flv_Table {
-	constructor(px, py, pw, ph, pl=""){
+class Fl_Data_Table extends Flv_Data_Table {
+	_forPrint = null;
+	_cols_info = null;
+	_data = null;
+
+	constructor(px, py, pw, ph, pl=null){
 		base.constructor(px, py, pw, ph, pl);
+		_forPrint=false;
+		_cols_info = [];
+		_data = [];
+	}
+	function fill_grid_from_table(tbl){
+		//SafeCursorWait cursor_wait;
+		row(-1);
+		clear_data_rows();
+		local key = format("%s_get_list", tbl);
+		appServer[key](_data);
+		recalc_data();
+	}
+
+	function clear_data_rows(){
+		_data.clear();
+	}
+	function recalc_data(){
+		rows(_data.size());
+		redraw();
+	}
+	function get_value(arow, acol){
+		if(acol < 0)
+		{
+		    if(arow < 0) return "#";
+		    return format("%d", arrow+1);
+		}
+		if(arow < 0) return _cols_info[acol].header;
+
+		local ci = _cols_info[acol];
+
+		local value = _data[arow][acol];
+
+		switch(ci.format)
+		{
+			case 'M': return math.number_format(value.size() ? value.tofloat() : 0, 2);
+			break;
+			case 'P': return math.number_format(value.size() ? value.tofloat() : 0, 3);
+			break;
+			case 'N': return math.number_format(value.size() ? value.tofloat() : 0, -6);
+			break;
+			case 'Z': //Empty when zero
+			case 'D': //Zero monetary //ZM':
+			{
+			    if(value == "0" || value == "") return "";
+			    else
+			    {
+				if(ci.format == 'Z') return math.number_format(value.tofloat(), -6);
+				else return math.number_format(value.tofloat(), 2);
+			    }
+			}
+			break;
+			case 'B': return (value == "1" ? "@-3+" : "");
+			break;
+			case '@': return value.replace("@", "@@"); //escape any @ 	{
+			break;
+		}
+		return value;
+	}
+	function handle(event){
+		local rc = base.handle(event);
+		return rc;
+	}
+	function set_cols(mycols){
+		_cols_info.clear();
+		for(local i=0, max_cols=mycols.size(); i < max_cols; ++i){
+		    local col_info = {};
+		    parse_field_header(mycols[i], col_info);
+		    _cols_info.push(col_info);
+		}
+		cols(_cols_info.size());
+		calc_cols();
+	}
+	function parse_field_header(str, col_info){
+		local ci = str.split("|");
+		local ci_size = ci.size();
+		local curr_ci = 0;
+		col_info.colname <- (ci_size > curr_ci++) ? ci[curr_ci-1] : "?";
+		col_info.header <- (ci_size > curr_ci++) ? ci[curr_ci-1] : "?";
+		col_info.width <- (ci_size > curr_ci++) ? ci[curr_ci-1].tofloat() : 10;
+		col_info.align <- (ci_size > curr_ci++) ? ci[curr_ci-1][0] : 'L';
+		col_info.format <- (ci_size > curr_ci++) ? ci[curr_ci-1][0] : '\0';
+		col_info.color <- (ci_size > curr_ci++) ? ci[curr_ci-1].tointeger() : 0;
+		col_info.bgcolor <- (ci_size > curr_ci++) ? ci[curr_ci-1].tointeger() : 0;
+	}
+	function calc_cols(){
+		calc_cols_width();
+		for(local k=0, len = cols(); k < len; ++k)
+		{
+		    local v = _cols_info[k];
+		    //v.header = _tr(v.header.c_str());
+		    local col_align;
+		    switch(v.align)
+		    {
+		    case 'C':
+			col_align = FL_ALIGN_CENTER;
+			break;
+		    case 'R':
+			col_align = FL_ALIGN_RIGHT;
+			break;
+		    default:
+			col_align = FL_ALIGN_LEFT;
+		    }
+		    local cs = col_style().get(k);
+		    cs.align(col_align);
+		    if(v.color) cs.foreground(v.color);
+		    if(v.bgcolor) cs.background(v.bgcolor);
+		}
+	}
+	function calc_cols_width(){
+		local grid_width, total_widths, char_width;
+		grid_width = w();
+		if(has_scrollbar()) grid_width -= scrollbar_width();
+		//char_width = self:labelsize() --fltk.fl_width('w')
+		//it seems that if not set the text font on fluid
+		//we get segfault here
+		Fl.fl_font(textfont(), textsize());
+		local gs = global_style();
+		gs.height(Fl.fl_height()+Fl.fl_descent());
+		char_width = Fl.fl_width("w");
+		draw_offset(char_width/3);
+		//print(grid_width, char_width)
+
+		total_widths = 0;
+		for(local k=0, len = cols(); k < len; ++k)
+		{
+		    local v = _cols_info[k].width;
+		    if(v > 0) total_widths += ((v * char_width) + 1);
+		}
+
+		for(local k=0, len = cols(); k < len; ++k)
+		{
+		    local v = _cols_info[k];
+		    local col_width = v.width;
+		    if( col_width < 0)	col_width = grid_width - total_widths;
+		    else col_width *= char_width;
+		    local cs = col_style().get(k);
+		    cs.width(col_width);
+		}
 	}
 }
 
+dofile("search-options.nut");
 dofile("utils-fltk.nut");
 dofile("base-report-A4.nut");
 dofile("invoice-A4.nut");
@@ -33,9 +181,232 @@ dofile("edit-product-window.nut");
 dofile("edit-entity-window.nut");
 dofile("edit-order-window.nut");
 dofile("list-search-window.nut");
+
+class MyListSearchWindow extends ListSearch {
+	_search_options = null;
+
+	constructor(){
+		base.constructor();
+		_search_options = OurBizSearchOptions();
+	}
+
+	function get_search_data(data){}
+	function fill_grid(){
+		//SafeCursorWait cursor_wait;
+		Fl.fl_cursor(FL_CURSOR_WAIT);
+		grid->clear_data_rows();
+		get_search_data(grid->_data);
+		grid->recalc_data();
+		Fl.fl_cursor(FL_CURSOR_DEFAULT);
+	}
+	function cb_btnSearch(sender, udata){
+		local pr = sender.parent_root();
+		pr->fill_grid();
+	}
+	
+	function create_search_by0(name, Klass, pack){
+		local sb = Klass(0,0,25,20, _tr(name));
+		sb->labelsize(pack->labelsize());
+		sb->w(Fl.fl_width(sb.label()) + Fl.fl_width("W"));
+		pack->add(sb);
+		return sb;
+	}
+	function create_search_by(name){
+		local sb = create_search_by0(name, Fl_Round_Button, pack_search_options);
+		sb->type(FL_RADIO_BUTTON);
+		return sb;
+	}
+	function create_search_by2(name){
+		local sb = create_search_by0(name, Fl_Check_Button, pack_search_options2);
+		return sb;
+	}
+}
+
+
 dofile("sales-tax-window.nut");
-dofile("main-window.nut");
 
+class OurSalesTax extends SalesTaxRatesEditWindow {
+	constructor(){
+		base.constructor();
+		local cols_info = [
+			"id|ID|0",
+			"rate1|V.A.T. %|8|R",
+			"rate2|R.E. %|8|R",
+			"description|Description|-1",
+			"is_active|Active|5|C|B",
+		];
+		grid->set_cols(cols_info);
+		fill_grid();
+	}
+	function fill_grid(){
+		//SafeCursorWait cursor_wait;
+		grid->clear_data_rows();
+		appServer.sales_tax_rates_get_list(grid->_data);
+		grid->recalc_data();
+	}
+}
+
+
+class EntitiesListSearch extends MyListSearchWindow {
+	_search_by_name = null;
+	_search_by_notes = null;
+	_search_by_phone = null;
+	_search_by_product = null;
+	_search_by_id = null;
+	_search_by_active = null;
+	
+	constructor() {
+		base.constructor();
+		label(_tr("Entities List Search"));
+		local cols_info = [
+			"id|ID|6|R",
+			"name|Name|-1",
+			"contact|Contact|12",
+			"phone|Phone|12",
+			"is_active|Active|0",
+			"image_id|image_id|0",
+		];
+		grid->set_cols(cols_info);
+		_search_by_name = create_search_by("Name");
+		_search_by_notes = create_search_by("Notes");
+		_search_by_phone = create_search_by("Phone");
+		_search_by_product = create_search_by("Product");
+		_search_by_id = create_search_by("ID");
+		_search_by_active = create_search_by2("Active");
+		_search_by_name->setonly();
+		_search_by_active->value(1);
+		fill_grid();
+	}
+	function fill_search_options(){
+		pack_search_options.add(Fl_Radio_Button());
+	}
+	function get_search_data(data){
+		_search_options.search_str = search_str.value();
+		_search_options.name = _search_by_name.value() == 1;
+		_search_options.notes = _search_by_notes.value() == 1;
+		_search_options.phone = _search_by_phone.value() == 1;
+		_search_options.product_id = _search_by_product.value() == 1;
+		_search_options.id = _search_by_id.value() == 1;
+		_search_options.active = _search_by_active.value() == 1;
+		appServer.entities_get_list(grid->_data, _search_options);
+	}
+	
+	function cb_btnInsert(sender, udata){
+		local pr = sender.parent_root();
+		local win = pr.showChildWindow("Entity Edit", EditEntitiesWindow);
+	}
+}
+
+class ProductsListSearch extends MyListSearchWindow {
+	_search_by_description = null;
+	_search_by_notes = null;
+	_search_by_reference = null;
+	_search_by_entities = null;
+	_search_by_id = null;
+	_search_by_active = null;
+	
+	constructor() {
+		base.constructor();
+		_search_options = OurBizSearchOptions();
+		label(_tr("Products List Search"));
+		local cols_info = [
+			"id|ID|6|R",
+			"reference_code|Reference|9",
+			"sell_description|Description|-1",
+			"kit|Kit|3|C",
+			"price_taxed|Price+V.A.T.|9|R|M",
+			"price|Price|0|R|M",
+			"quantity_onhand|Onhand|6|R|N",
+			"is_active|Active|5|C|B",
+			"price_date|Price Date|0",
+			"image_id|image_id|0",
+		];
+		grid->set_cols(cols_info);
+		_search_by_description = create_search_by("Description");
+		_search_by_notes = create_search_by("Notes");
+		_search_by_reference = create_search_by("Reference");
+		_search_by_entities = create_search_by("Entities");
+		_search_by_id = create_search_by("ID");
+		_search_by_active = create_search_by2("Active");
+		_search_by_description->setonly();
+		_search_by_active->value(1);
+		fill_grid();
+	}
+	
+	function get_search_data(data){
+		_search_options.search_str = search_str.value();
+		_search_options.description = _search_by_description.value() == 1;
+		_search_options.notes = _search_by_notes.value() == 1;
+		_search_options.reference = _search_by_reference.value() == 1;
+		_search_options.entities = _search_by_entities.value() == 1;
+		_search_options.id = _search_by_id.value() == 1;
+		_search_options.active = _search_by_active.value() == 1;
+		appServer.products_get_list(grid->_data, _search_options);
+	}
+
+	function cb_btnInsert(sender, udata){
+		local pr = sender.parent_root();
+		local win = pr.showChildWindow("Product Edit", EditProductWindow);
+	}
+}
+
+class OrdersListSearch extends MyListSearchWindow {
+	_search_by_entities = null;
+	_search_by_notes = null;
+	_search_by_products = null;
+	_search_by_date = null;
+	_search_by_total = null;
+	_search_wp = null;
+
+	constructor() {
+		base.constructor();
+		label(_tr("Orders List Search"));
+		local cols_info = [
+			"id|ID|6|R",
+			"order_date|Date|9",
+			"order_type_code|Type|4",
+			"series|Series|5",
+			"order_number|Number|7",
+			"entity_name|Entity|-1",
+			"total_amt|Total|8|R|M",
+			"payment_type_code|P.T.|4|C",
+		];
+		grid->set_cols(cols_info);
+		_search_by_entities = create_search_by("Entities");
+		_search_by_notes = create_search_by("Notes");
+		_search_by_products = create_search_by("Products");
+		_search_by_date = create_search_by("Date");
+		_search_by_total = create_search_by("Total");
+		_search_wp = create_search_by2("WP");
+		_search_by_entities->setonly();
+		fill_grid();
+	}
+	
+	function get_search_data(data){
+		_search_options.search_str = search_str.value();
+		_search_options.entities = _search_by_entities.value() == 1;
+		_search_options.notes = _search_by_notes.value() == 1;
+		_search_options.products = _search_by_products.value() == 1;
+		_search_options.date = _search_by_date.value() == 1;
+		_search_options.total = _search_by_total.value() == 1;
+		appServer.orders_get_list(grid->_data, _search_options);
+	}
+
+	function cb_btnInsert(sender, udata){
+		local pr = sender.parent_root();
+		local win = pr.showChildWindow("Order Edit", EditOrderWindow);
+	}
+}
+
+class PaymentsListSearch extends ListSearch {
+
+	constructor() {
+		base.constructor();
+		label(_tr("Payments List Search"));
+	}
+}
+
+dofile("main-window.nut");
 
 local win = new MainWindow(10, 50, 330, 320, "OURBIZ");
 //local win = new SalesTaxRatesEditWindow();

+ 59 - 2
ourbiz/ourbiz.nut

@@ -15,7 +15,9 @@ function getOurbizDB(){
 	//return checkCachedDB(APP_CODE_FOLDER + "/ourbiz.db");
 }
 
-dofile(APP_CODE_FOLDER + "/pdf-table.nut");
+if(AT_DEV_DBG || !globals.get("PdfSqlTable", false)) {
+	dofile(APP_CODE_FOLDER + "/pdf-table.nut");
+}
 
 function escape_sql_like_search_str(str){
     if (str && (str.len() > 0)){
@@ -534,7 +536,9 @@ db_ourbiz_tables.entities <- new DB_Entities();
 // orders
 //
 
-dofile(APP_CODE_FOLDER +"/pdf-order.nut");
+if(AT_DEV_DBG || !globals.get("PDF_Order", false)) {
+	dofile(APP_CODE_FOLDER + "/pdf-order.nut");
+}
 
 class My_PDF_Order extends PDF_Order {
 	_tr_map = null;
@@ -669,6 +673,21 @@ class CalcOrderLine
 		}
 	}
 
+	function clear_preserving_tax_flags2(withFullTax=false)
+	{
+		unit_weight = quantity = weight = price =
+                                              first_total = discount_pct =
+                                                      discount_amt = line_subtotal =
+                                                              sales_tax1_pct = sales_tax1_amt = sales_tax2_pct =
+                                                                      sales_tax2_amt = line_total = Decimal(0);
+		id = order_id = product_id = 0;
+		price_decimals = 2;
+		if(withFullTax){
+			use_sales_tax2 = true;
+			tax_exempt=false;
+		}
+	}
+
 	function dumpSLSArrayCalcNames(out_result)
 	{
 		//this list must match the dumpSLSArrayCalc order
@@ -719,6 +738,38 @@ class CalcOrderLine
 		}
 		line_total = round(line_subtotal + sales_tax1_amt + sales_tax2_amt, price_decimals);
 	}
+	
+	function calc2()
+	{
+		local num100 = Decimal(100);
+		first_total = quantity * price;
+		weight = unit_weight * quantity;
+		local round = math.broundf;
+		local saved_prec = Decimal.gctx.prec();
+		Decimal.gctx.prec(price_decimals);
+
+		discount_amt = first_total * (discount_pct/num100);
+		line_subtotal = first_total - discount_amt;
+
+		if(!tax_exempt)
+		{
+			sales_tax1_amt = line_subtotal * (sales_tax1_pct/num100);
+			if(use_sales_tax2)
+			{
+				sales_tax2_amt = line_subtotal * (sales_tax2_pct/num100);
+			}
+			else
+			{
+				sales_tax2_pct = 0.0;
+			}
+		}
+		else
+		{
+			sales_tax2_pct = sales_tax1_pct = 0.0;
+		}
+		line_total = line_subtotal + sales_tax1_amt + sales_tax2_amt;
+		Decimal.gctx.prec(saved_prec);
+	}
 }
 
 class  CalcOrderTotals
@@ -745,6 +796,12 @@ class  CalcOrderTotals
                                           sales_tax2_amt = total_amt = weight_total = 0.0;
 		lines_count = 0;
 	}
+	function clear2()
+	{
+		subtotal_amt = discount_amt = sales_tax1_amt =
+                                          sales_tax2_amt = total_amt = weight_total = Decimal(0);
+		lines_count = 0;
+	}
 
 	function dumpSLEFieldNames(out_result)
 	{

+ 3 - 1
ourbiz/sq-server-plugin.nut

@@ -813,7 +813,9 @@ function getExtraCompanyData(cid, cnum){
 	}
 }
 
-dofile(APP_CODE_FOLDER + "/ourbiz.nut");
+if(AT_DEV_DBG || !globals.get("ourbizDB", false)) {
+	dofile(APP_CODE_FOLDER + "/ourbiz.nut");
+}
 
 local uri_handlers = {
 	["/SQ/testParams"] = function(request){

+ 1 - 1
ourbiz/sq-server.nut

@@ -59,7 +59,7 @@ local mongoose_start_params = {
 		if(event == "MG_NEW_REQUEST"){
 			//debug_print("\n", request.get_option("num_threads"), request.get_conn_buf());
 			if(AT_DEV_DBG || !this.get("handle_request", false)) {
-				loadfile(APP_CODE_FOLDER + "/sq-server-plugin.nut")();
+				dofile(APP_CODE_FOLDER + "/sq-server-plugin.nut");
 			}
 			return handle_request(request);
 		}

Деякі файли не було показано, через те що забагато файлів було змінено