|
|
@@ -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();
|