// Copyright (c) 2003,2004,2005 Juraj Kolesár #include "lt.h" /* init {{{ *******************************************************************/ int lt_s_input_data_init(T_INPUT *input) { register int i; for (i=0;i<__LT_S_INPUT_PARAM_COUNT;i++) input->status[i] = false; SET_CELL(input->pk, "", "pk_s_inputs", 0); SET_CELL(input->code, "", "code", 10); SET_CELL(input->date, "", "date", 30); SET_CELL(input->letter, "", "letter", 15); SET_CELL(input->where, "", "", 15); SET_CELL(input->from, "", "", 15); input->items.table = NULL; return(__LT_OK); } /* }}} */ /* new {{{ ********************************************************************/ int lt_s_input_new(T_DB *tdb, T_INPUT *input) { // tdb_query_cell(tdb, input->code.value, "SELECT MAX(code) FROM s_inputs"); // str_inc(input->code.value); tdb_query(tdb, "INSERT INTO s_inputs (fk_a_letters, code, date) " "VALUES ('0', '', '00000000')"); tdb_query_lastid(tdb, input->pk.value); input->status[__LT_S_INPUT_PK] = true; return(__LT_OK); } /* }}} */ /* save {{{ ********************************************************************/ int lt_s_input_save(T_DB *tdb, T_INPUT *input) { tdb_query_cell(tdb, input->code.value, "SELECT MAX(code) FROM s_inputs"); str_inc(input->code.value); tdb_query(tdb, g_strdup_printf( "UPDATE s_inputs SET code = '%s',date = '%s' WHERE pk_s_inputs = '%s'", input->code.value, input->date.value, input->pk.value)); return(__LT_OK); } /* }}} */ /* remove blind {{{ ***********************************************************/ int lt_s_input_remove_blind(T_DB *tdb, T_INPUT *input) { tdb_query(tdb, g_strdup_printf( "DELETE FROM s_inputs WHERE pk_s_inputs = '%s'", input->pk.value)); return(__LT_OK); } /* }}} */ /* qs init {{{ ****************************************************************/ int lt_s_input_qs_init(T_INPUT *input, T_COLS **cols, T_QS *qs) { *cols = g_slist_append(*cols, &(input->pk)); *cols = g_slist_append(*cols, &(input->code)); *cols = g_slist_append(*cols, &(input->date)); *cols = g_slist_append(*cols, &(input->from)); *cols = g_slist_append(*cols, &(input->letter)); if (strlen(qs->columns) == 0) strcpy(qs->columns, "pk_s_inputs, code, date"); //tdb_qs_set_columns(qs, *cols); if (strlen(qs->from) == 0) strcpy(qs->from, "s_inputs"); return(__LT_OK); } /* }}} */ /* item add {{{ ***************************************************************/ int lt_s_input_item_add(T_INPUT *input, T_ITEM *item, int count) { T_ROW *row = NULL; row = g_slist_append(row, g_strdup_printf("%s", item->pk.value)); row = g_slist_append(row, g_strdup_printf("%s", item->name.value)); row = g_slist_append(row, g_strdup_printf("%i", count)); row = g_slist_append(row, g_strdup_printf("%s", item->messure.name)); row = g_slist_append(row, g_strdup_printf("%s", item->price.value)); row = g_slist_append(row, g_strdup_printf("%i", count * atoi(item->price.value))); input->items.table = g_list_append(input->items.table, row); input->items.table = g_list_last(input->items.table); return(__LT_OK); } /* }}} */ /* items set {{{ **************************************************************/lt_s_input_items_set(T_DB *tdb, T_INPUT *input) { T_TABLE *table = g_list_first(input->items.table); T_ROW *row; char *count; char *pk_item; char *price; while (table != NULL) { row = table->data; pk_item = row->data; row = g_slist_next(g_slist_next(row)); count = row->data; row = g_slist_next(g_slist_next(row)); price = row->data; tdb_query(tdb, g_strdup_printf( "INSERT INTO s_add (fk_s_inputs, fk_s_items, count, price) " "VALUES ('%s', '%s', '%s', '%s')", input->pk.value, pk_item, count, price)); table = g_list_next(table); } return(__LT_OK); } /* }}} */ /* items get {{{ **************************************************************/ int lt_s_input_items_get(T_DB *tdb, T_INPUT *input) { if (!(input->status[__LT_S_INPUT_ITEMS])) { tdb_table_fill(tdb, &(input->items), g_strdup_printf( "SELECT pk_s_add, name, count, messure, price, (count * price) " "FROM s_items " "INNER JOIN s_add ON pk_s_items=fk_s_items " "INNER JOIN s_messures ON pk_s_messures=fk_s_messures " "WHERE fk_s_inputs='%s'", input->pk.value)); input->status[__LT_S_INPUT_ITEMS] = true; } return(__LT_OK); } /* }}} */