mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Abstract out the owner of Orders and Invoices into a GncOwner.
Create a general Owner Selection widget (sort of) by using gnc-general-select Update the order dialog to provide an OrderID, owner, start/end date, etc. Order-Dialog buttons still appear right-justified for some strange reason? git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6260 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
f1a1379750
commit
7b2f65cf8f
@ -20,6 +20,7 @@ libgncmod_business_core_la_SOURCES = \
|
||||
gncInvoice.c \
|
||||
gncJob.c \
|
||||
gncOrder.c \
|
||||
gncOwner.c \
|
||||
gncVendor.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
@ -31,8 +32,11 @@ noinst_HEADERS = \
|
||||
gncEmployeeP.h \
|
||||
gncEntry.h \
|
||||
gncEntryP.h \
|
||||
gncInvoice.h \
|
||||
gncJob.h \
|
||||
gncJobP.h \
|
||||
gncOrder.h \
|
||||
gncOwner.h \
|
||||
gncVendor.h \
|
||||
gncVendorP.h
|
||||
|
||||
|
@ -18,12 +18,11 @@
|
||||
#include "GNCIdP.h"
|
||||
|
||||
#include "gncBusiness.h"
|
||||
#include "gncCustomer.h"
|
||||
#include "gncVendor.h"
|
||||
#include "gncEntry.h"
|
||||
#include "gncEntryP.h"
|
||||
#include "gncInvoice.h"
|
||||
#include "gncInvoiceP.h"
|
||||
#include "gncOwner.h"
|
||||
|
||||
struct _gncInvoice {
|
||||
GNCBook *book;
|
||||
@ -32,11 +31,7 @@ struct _gncInvoice {
|
||||
char * id;
|
||||
char * notes;
|
||||
GList * entries;
|
||||
GncInvoiceType type;
|
||||
union {
|
||||
GncCustomer *customer;
|
||||
GncVendor * vendor;
|
||||
} owner;
|
||||
GncOwner owner;
|
||||
Timespec date_opened;
|
||||
Timespec date_due;
|
||||
Timespec date_closed;
|
||||
@ -72,12 +67,11 @@ static void remObj (GncInvoice *invoice);
|
||||
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
GncInvoice *gncInvoiceCreate (GNCBook *book, GncInvoiceType type)
|
||||
GncInvoice *gncInvoiceCreate (GNCBook *book)
|
||||
{
|
||||
GncInvoice *invoice;
|
||||
|
||||
if (!book) return NULL;
|
||||
if (type != GNC_INVOICE_CUSTOMER && type != GNC_INVOICE_VENDOR) return NULL;
|
||||
|
||||
invoice = g_new0 (GncInvoice, 1);
|
||||
invoice->book = book;
|
||||
@ -86,7 +80,6 @@ GncInvoice *gncInvoiceCreate (GNCBook *book, GncInvoiceType type)
|
||||
invoice->notes = CACHE_INSERT ("");
|
||||
|
||||
invoice->active = TRUE;
|
||||
invoice->type = type;
|
||||
|
||||
xaccGUIDNew (&invoice->guid, book);
|
||||
addObj (invoice);
|
||||
@ -125,19 +118,10 @@ void gncInvoiceSetID (GncInvoice *invoice, const char *id)
|
||||
invoice->dirty = TRUE;
|
||||
}
|
||||
|
||||
void gncInvoiceSetCustomer (GncInvoice *invoice, GncCustomer *customer)
|
||||
void gncInvoiceSetOwner (GncInvoice *invoice, GncOwner *owner)
|
||||
{
|
||||
if (!invoice) return;
|
||||
if (invoice->type != GNC_INVOICE_CUSTOMER) return;
|
||||
invoice->owner.customer = customer;
|
||||
invoice->dirty = TRUE;
|
||||
}
|
||||
|
||||
void gncInvoiceSetVendor (GncInvoice *invoice, GncVendor *vendor)
|
||||
{
|
||||
if (!invoice) return;
|
||||
if (invoice->type != GNC_INVOICE_VENDOR) return;
|
||||
invoice->owner.vendor = vendor;
|
||||
if (!invoice || !owner) return;
|
||||
gncOwnerCopy (owner, &invoice->owner);
|
||||
invoice->dirty = TRUE;
|
||||
}
|
||||
|
||||
@ -249,24 +233,10 @@ const char * gncInvoiceGetID (GncInvoice *invoice)
|
||||
return invoice->id;
|
||||
}
|
||||
|
||||
GncInvoiceType gncInvoiceGetType (GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return GNC_INVOICE_NONE;
|
||||
return invoice->type;
|
||||
}
|
||||
|
||||
GncCustomer * gncInvoiceGetCustomer (GncInvoice *invoice)
|
||||
GncOwner * gncInvoiceGetOwner (GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return NULL;
|
||||
if (invoice->type != GNC_INVOICE_CUSTOMER) return NULL;
|
||||
return invoice->owner.customer;
|
||||
}
|
||||
|
||||
GncVendor * gncInvoiceGetVendor (GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return NULL;
|
||||
if (invoice->type != GNC_INVOICE_VENDOR) return NULL;
|
||||
return invoice->owner.vendor;
|
||||
return &invoice->owner;
|
||||
}
|
||||
|
||||
Timespec gncInvoiceGetDateOpened (GncInvoice *invoice)
|
||||
@ -393,10 +363,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
||||
|
||||
/* Set Transaction Description (customer), Num (invoice ID), Currency */
|
||||
xaccTransSetDescription
|
||||
(txn,
|
||||
((gncInvoiceGetType (invoice) == GNC_INVOICE_CUSTOMER) ?
|
||||
gncCustomerGetName (gncInvoiceGetCustomer (invoice)) :
|
||||
gncVendorGetName (gncInvoiceGetVendor (invoice))));
|
||||
(txn, gncOwnerGetName (gncInvoiceGetOwner (invoice)));
|
||||
|
||||
xaccTransSetNum (txn, gncInvoiceGetID (invoice));
|
||||
xaccTransSetCurrency (txn, commonCommodity);
|
||||
|
@ -10,28 +10,19 @@
|
||||
struct _gncInvoice;
|
||||
typedef struct _gncInvoice GncInvoice;
|
||||
|
||||
typedef enum {
|
||||
GNC_INVOICE_NONE = 0,
|
||||
GNC_INVOICE_CUSTOMER = 1,
|
||||
GNC_INVOICE_VENDOR = 2
|
||||
} GncInvoiceType;
|
||||
|
||||
#include "gncCustomer.h"
|
||||
#include "gncVendor.h"
|
||||
#include "gncEntry.h"
|
||||
#include "gncOwner.h"
|
||||
|
||||
#define GNC_INVOICE_MODULE_NAME "gncInvoice"
|
||||
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
GncInvoice *gncInvoiceCreate (GNCBook *book, GncInvoiceType type);
|
||||
GncInvoice *gncInvoiceCreate (GNCBook *book);
|
||||
void gncInvoiceDestroy (GncInvoice *invoice);
|
||||
|
||||
/* Set Functions */
|
||||
|
||||
void gncInvoiceSetID (GncInvoice *invoice, const char *id);
|
||||
void gncInvoiceSetCustomer (GncInvoice *invoice, GncCustomer *customer);
|
||||
void gncInvoiceSetVendor (GncInvoice *invoice, GncVendor *vendor);
|
||||
void gncInvoiceSetDateOpened (GncInvoice *invoice, const Timespec *date);
|
||||
void gncInvoiceSetDateDue (GncInvoice *invoice, const Timespec *date);
|
||||
void gncInvoiceSetDateClosed (GncInvoice *invoice, const Timespec *date);
|
||||
@ -47,9 +38,7 @@ void gncInvoiceRemoveEntry (GncInvoice *invoice, GncEntry *entry);
|
||||
GNCBook * gncInvoiceGetBook (GncInvoice *invoice);
|
||||
const GUID * gncInvoiceGetGUID (GncInvoice *invoice);
|
||||
const char * gncInvoiceGetID (GncInvoice *invoice);
|
||||
GncInvoiceType gncInvoiceGetType (GncInvoice *invoice);
|
||||
GncCustomer * gncInvoiceGetCustomer (GncInvoice *invoice);
|
||||
GncVendor * gncInvoiceGetVendor (GncInvoice *invoice);
|
||||
GncOwner * gncInvoiceGetOwner (GncInvoice *invoice);
|
||||
Timespec gncInvoiceGetDateOpened (GncInvoice *invoice);
|
||||
Timespec gncInvoiceGetDateDue (GncInvoice *invoice);
|
||||
Timespec gncInvoiceGetDateClosed (GncInvoice *invoice);
|
||||
|
@ -16,12 +16,11 @@
|
||||
#include "GNCIdP.h"
|
||||
|
||||
#include "gncBusiness.h"
|
||||
#include "gncJob.h"
|
||||
#include "gncVendor.h"
|
||||
#include "gncEntry.h"
|
||||
#include "gncEntryP.h"
|
||||
#include "gncOrder.h"
|
||||
#include "gncOrderP.h"
|
||||
#include "gncOwner.h"
|
||||
|
||||
struct _gncOrder {
|
||||
GNCBook *book;
|
||||
@ -29,11 +28,7 @@ struct _gncOrder {
|
||||
GUID guid;
|
||||
char * id;
|
||||
char * notes;
|
||||
GncOrderType type;
|
||||
union {
|
||||
GncJob * job;
|
||||
GncVendor * vendor;
|
||||
} owner;
|
||||
GncOwner owner;
|
||||
GList * entries;
|
||||
Timespec opened;
|
||||
Timespec closed;
|
||||
@ -61,12 +56,11 @@ static void remObj (GncOrder *order);
|
||||
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
GncOrder *gncOrderCreate (GNCBook *book, GncOrderType type)
|
||||
GncOrder *gncOrderCreate (GNCBook *book)
|
||||
{
|
||||
GncOrder *order;
|
||||
|
||||
if (!book) return NULL;
|
||||
if (type != GNC_ORDER_SALES && type != GNC_ORDER_PURCHASE) return NULL;
|
||||
|
||||
order = g_new0 (GncOrder, 1);
|
||||
order->book = book;
|
||||
@ -75,7 +69,6 @@ GncOrder *gncOrderCreate (GNCBook *book, GncOrderType type)
|
||||
order->notes = CACHE_INSERT ("");
|
||||
|
||||
order->active = TRUE;
|
||||
order->type = type;
|
||||
|
||||
xaccGUIDNew (&order->guid, book);
|
||||
addObj (order);
|
||||
@ -116,20 +109,11 @@ void gncOrderSetID (GncOrder *order, const char *id)
|
||||
order->dirty = TRUE;
|
||||
}
|
||||
|
||||
void gncOrderSetJob (GncOrder *order, GncJob *job)
|
||||
void gncOrderSetOwner (GncOrder *order, GncOwner *owner)
|
||||
{
|
||||
if (!order) return;
|
||||
if (order->type != GNC_ORDER_SALES) return;
|
||||
order->owner.job = job;
|
||||
order->dirty = TRUE;
|
||||
}
|
||||
if (!order || !owner) return;
|
||||
|
||||
void gncOrderSetVendor (GncOrder *order, GncVendor *vendor)
|
||||
{
|
||||
if (!order) return;
|
||||
if (order->type != GNC_ORDER_PURCHASE) return;
|
||||
|
||||
order->owner.vendor = vendor;
|
||||
gncOwnerCopy (owner, &order->owner);
|
||||
order->dirty = TRUE;
|
||||
}
|
||||
|
||||
@ -212,24 +196,10 @@ const char * gncOrderGetID (GncOrder *order)
|
||||
return order->id;
|
||||
}
|
||||
|
||||
GncOrderType gncOrderGetType (GncOrder *order)
|
||||
{
|
||||
if (!order) return GNC_ORDER_NONE;
|
||||
return order->type;
|
||||
}
|
||||
|
||||
GncJob * gncOrderGetJob (GncOrder *order)
|
||||
GncOwner * gncOrderGetOwner (GncOrder *order)
|
||||
{
|
||||
if (!order) return NULL;
|
||||
if (order->type != GNC_ORDER_SALES) return NULL;
|
||||
return order->owner.job;
|
||||
}
|
||||
|
||||
GncVendor * gncOrderGetVendor (GncOrder *order)
|
||||
{
|
||||
if (!order) return NULL;
|
||||
if (order->type != GNC_ORDER_PURCHASE) return NULL;
|
||||
return order->owner.vendor;
|
||||
return &order->owner;
|
||||
}
|
||||
|
||||
Timespec gncOrderGetDateOpened (GncOrder *order)
|
||||
|
@ -9,29 +9,21 @@
|
||||
|
||||
typedef struct _gncOrder GncOrder;
|
||||
|
||||
typedef enum {
|
||||
GNC_ORDER_NONE = 0,
|
||||
GNC_ORDER_SALES = 1,
|
||||
GNC_ORDER_PURCHASE = 2
|
||||
} GncOrderType;
|
||||
|
||||
#include "gnc-book.h"
|
||||
#include "gncEntry.h"
|
||||
#include "gncJob.h"
|
||||
#include "gncVendor.h"
|
||||
#include "gncOwner.h"
|
||||
|
||||
#define GNC_ORDER_MODULE_NAME "gncOrder"
|
||||
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
GncOrder *gncOrderCreate (GNCBook *book, GncOrderType type);
|
||||
GncOrder *gncOrderCreate (GNCBook *book);
|
||||
void gncOrderDestroy (GncOrder *order);
|
||||
|
||||
/* Set Functions */
|
||||
|
||||
void gncOrderSetID (GncOrder *order, const char *id);
|
||||
void gncOrderSetJob (GncOrder *order, GncJob *job);
|
||||
void gncOrderSetVendor (GncOrder *order, GncVendor *vendor);
|
||||
void gncOrderSetOwner (GncOrder *order, GncOwner *owner);
|
||||
void gncOrderSetDateOpened (GncOrder *order, Timespec *date);
|
||||
void gncOrderSetDateClosed (GncOrder *order, Timespec *date);
|
||||
void gncOrderSetNotes (GncOrder *order, const char *notes);
|
||||
@ -46,9 +38,7 @@ void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry);
|
||||
GNCBook * gncOrderGetBook (GncOrder *order);
|
||||
const GUID * gncOrderGetGUID (GncOrder *order);
|
||||
const char * gncOrderGetID (GncOrder *order);
|
||||
GncOrderType gncOrderGetType (GncOrder *order);
|
||||
GncJob * gncOrderGetJob (GncOrder *order);
|
||||
GncVendor * gncOrderGetVendor (GncOrder *order);
|
||||
GncOwner * gncOrderGetOwner (GncOrder *order);
|
||||
Timespec gncOrderGetDateOpened (GncOrder *order);
|
||||
Timespec gncOrderGetDateClosed (GncOrder *order);
|
||||
const char * gncOrderGetNotes (GncOrder *order);
|
||||
|
100
src/business/business-core/gncOwner.c
Normal file
100
src/business/business-core/gncOwner.c
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* gncOwner.c -- Business Interface: Object OWNERs
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h> /* for memcpy() */
|
||||
|
||||
#include "gncOwner.h"
|
||||
|
||||
void gncOwnerInitUndefined (GncOwner *owner, gpointer obj)
|
||||
{
|
||||
if (!owner) return;
|
||||
owner->type = GNC_OWNER_UNDEFINED;
|
||||
owner->owner.undefined = obj;
|
||||
}
|
||||
|
||||
void gncOwnerInitCustomer (GncOwner *owner, GncCustomer *customer)
|
||||
{
|
||||
if (!owner) return;
|
||||
owner->type = GNC_OWNER_CUSTOMER;
|
||||
owner->owner.customer = customer;
|
||||
}
|
||||
|
||||
void gncOwnerInitJob (GncOwner *owner, GncJob *job)
|
||||
{
|
||||
if (!owner) return;
|
||||
owner->type = GNC_OWNER_JOB;
|
||||
owner->owner.job = job;
|
||||
}
|
||||
|
||||
void gncOwnerInitVendor (GncOwner *owner, GncVendor *vendor)
|
||||
{
|
||||
if (!owner) return;
|
||||
owner->type = GNC_OWNER_VENDOR;
|
||||
owner->owner.vendor = vendor;
|
||||
}
|
||||
|
||||
GncOwnerType gncOwnerGetType (GncOwner *owner)
|
||||
{
|
||||
if (!owner) return GNC_OWNER_NONE;
|
||||
return owner->type;
|
||||
}
|
||||
|
||||
gpointer gncOwnerGetUndefined (GncOwner *owner)
|
||||
{
|
||||
if (!owner) return NULL;
|
||||
if (owner->type != GNC_OWNER_UNDEFINED) return NULL;
|
||||
return owner->owner.undefined;
|
||||
}
|
||||
|
||||
GncCustomer * gncOwnerGetCustomer (GncOwner *owner)
|
||||
{
|
||||
if (!owner) return NULL;
|
||||
if (owner->type != GNC_OWNER_CUSTOMER) return NULL;
|
||||
return owner->owner.customer;
|
||||
}
|
||||
|
||||
GncJob * gncOwnerGetJob (GncOwner *owner)
|
||||
{
|
||||
if (!owner) return NULL;
|
||||
if (owner->type != GNC_OWNER_JOB) return NULL;
|
||||
return owner->owner.job;
|
||||
}
|
||||
|
||||
GncVendor * gncOwnerGetVendor (GncOwner *owner)
|
||||
{
|
||||
if (!owner) return NULL;
|
||||
if (owner->type != GNC_OWNER_VENDOR) return NULL;
|
||||
return owner->owner.vendor;
|
||||
}
|
||||
|
||||
void gncOwnerCopy (const GncOwner *src, GncOwner *dest)
|
||||
{
|
||||
if (!src || !dest) return;
|
||||
if (src == dest) return;
|
||||
memcpy (dest, src, sizeof (*dest));
|
||||
}
|
||||
|
||||
const char * gncOwnerGetName (GncOwner *owner)
|
||||
{
|
||||
if (!owner) return NULL;
|
||||
switch (owner->type) {
|
||||
case GNC_OWNER_NONE:
|
||||
case GNC_OWNER_UNDEFINED:
|
||||
default:
|
||||
return NULL;
|
||||
case GNC_OWNER_CUSTOMER:
|
||||
return gncCustomerGetName (owner->owner.customer);
|
||||
case GNC_OWNER_JOB:
|
||||
return gncJobGetName (owner->owner.job);
|
||||
case GNC_OWNER_VENDOR:
|
||||
return gncVendorGetName (owner->owner.vendor);
|
||||
}
|
||||
}
|
||||
|
||||
|
47
src/business/business-core/gncOwner.h
Normal file
47
src/business/business-core/gncOwner.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* gncOwner.h -- Business Interface: Object OWNERs
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
#ifndef GNC_OWNER_H_
|
||||
#define GNC_OWNER_H_
|
||||
|
||||
#include "gncCustomer.h"
|
||||
#include "gncJob.h"
|
||||
#include "gncVendor.h"
|
||||
|
||||
typedef enum {
|
||||
GNC_OWNER_NONE,
|
||||
GNC_OWNER_UNDEFINED,
|
||||
GNC_OWNER_CUSTOMER,
|
||||
GNC_OWNER_JOB,
|
||||
GNC_OWNER_VENDOR
|
||||
} GncOwnerType;
|
||||
|
||||
typedef struct gnc_owner_s {
|
||||
GncOwnerType type;
|
||||
union {
|
||||
gpointer undefined;
|
||||
GncCustomer * customer;
|
||||
GncJob * job;
|
||||
GncVendor * vendor;
|
||||
} owner;
|
||||
} GncOwner;
|
||||
|
||||
void gncOwnerInitUndefined (GncOwner *owner, gpointer obj);
|
||||
void gncOwnerInitCustomer (GncOwner *owner, GncCustomer *customer);
|
||||
void gncOwnerInitJob (GncOwner *owner, GncJob *job);
|
||||
void gncOwnerInitVendor (GncOwner *owner, GncVendor *vendor);
|
||||
|
||||
GncOwnerType gncOwnerGetType (GncOwner *owner);
|
||||
gpointer gncOwnerGetUndefined (GncOwner *owner);
|
||||
GncCustomer * gncOwnerGetCustomer (GncOwner *owner);
|
||||
GncJob * gncOwnerGetJob (GncOwner *owner);
|
||||
GncVendor * gncOwnerGetVendor (GncOwner *owner);
|
||||
|
||||
void gncOwnerCopy (const GncOwner *src, GncOwner *dest);
|
||||
|
||||
const char * gncOwnerGetName (GncOwner *owner);
|
||||
|
||||
#endif /* GNC_OWNER_H_ */
|
@ -24,6 +24,7 @@ AM_CFLAGS = \
|
||||
libgncmod_business_gnome_la_SOURCES = \
|
||||
businessmod-gnome.c \
|
||||
business-chooser.c \
|
||||
business-utils.c \
|
||||
dialog-customer.c \
|
||||
dialog-employee.c \
|
||||
dialog-job.c \
|
||||
@ -33,6 +34,7 @@ libgncmod_business_gnome_la_SOURCES = \
|
||||
|
||||
noinst_HEADERS = \
|
||||
business-chooser.h \
|
||||
business-utils.h \
|
||||
dialog-customer.h \
|
||||
dialog-employee.h \
|
||||
dialog-job.h \
|
||||
|
122
src/business/business-gnome/business-utils.c
Normal file
122
src/business/business-gnome/business-utils.c
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* business-utils.c -- General GUI Utilities for GNC Business Objects
|
||||
*
|
||||
* Written By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (C) 2001
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gnome.h>
|
||||
|
||||
#include "gncBusiness.h"
|
||||
#include "gncCustomer.h"
|
||||
#include "gncJob.h"
|
||||
#include "gncVendor.h"
|
||||
#include "gncOwner.h"
|
||||
|
||||
#include "business-utils.h"
|
||||
#include "dialog-customer.h"
|
||||
#include "dialog-job.h"
|
||||
#include "dialog-vendor.h"
|
||||
|
||||
static GtkWidget * gnc_owner_new (GtkWidget *label, GtkWidget *hbox,
|
||||
GNCBook *book, GncOwner *owner,
|
||||
GNCGeneralSelectType type)
|
||||
{
|
||||
GtkWidget *edit;
|
||||
GNCGeneralSelectNewSelectCB do_select = NULL;
|
||||
const GncBusinessObject *bus_obj;
|
||||
const char *type_name = NULL;
|
||||
|
||||
switch (owner->type) {
|
||||
case GNC_OWNER_NONE:
|
||||
case GNC_OWNER_UNDEFINED:
|
||||
return NULL;
|
||||
|
||||
case GNC_OWNER_CUSTOMER:
|
||||
if (type == GNC_GENERAL_SELECT_TYPE_SELECT)
|
||||
do_select = gnc_customer_edit_new_select;
|
||||
else
|
||||
do_select = gnc_customer_edit_new_edit;
|
||||
type_name = GNC_CUSTOMER_MODULE_NAME;
|
||||
break;
|
||||
|
||||
case GNC_OWNER_JOB:
|
||||
/* XXX: Jobs are funny things... */
|
||||
return NULL;
|
||||
|
||||
if (type == GNC_GENERAL_SELECT_TYPE_SELECT)
|
||||
; // do_select = gnc_job_edit_new_select;
|
||||
else
|
||||
; // do_select = gnc_job_edit_new_edit;
|
||||
type_name = GNC_JOB_MODULE_NAME;
|
||||
break;
|
||||
|
||||
case GNC_OWNER_VENDOR:
|
||||
if (type == GNC_GENERAL_SELECT_TYPE_SELECT)
|
||||
do_select = gnc_vendor_edit_new_select;
|
||||
else
|
||||
do_select = gnc_vendor_edit_new_edit;
|
||||
type_name = GNC_VENDOR_MODULE_NAME;
|
||||
break;
|
||||
|
||||
default:
|
||||
g_warning ("Unknown type");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bus_obj = gncBusinessLookup (type_name);
|
||||
if (!bus_obj) {
|
||||
g_warning ("Cannot find business object for name and printable()\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
edit = gnc_general_select_new (type, bus_obj->printable, do_select, book);
|
||||
if (!edit)
|
||||
return NULL;
|
||||
|
||||
gnc_general_select_set_selected (GNC_GENERAL_SELECT (edit),
|
||||
owner->owner.undefined);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);
|
||||
gtk_label_set_text (GTK_LABEL (label), gncBusinessGetTypeLabel (type_name));
|
||||
|
||||
return edit;
|
||||
}
|
||||
|
||||
|
||||
GtkWidget * gnc_owner_select_create (GtkWidget *label, GtkWidget *hbox,
|
||||
GNCBook *book, GncOwner *owner)
|
||||
{
|
||||
g_return_val_if_fail (label != NULL, NULL);
|
||||
g_return_val_if_fail (hbox != NULL, NULL);
|
||||
g_return_val_if_fail (book != NULL, NULL);
|
||||
g_return_val_if_fail (owner != NULL, NULL);
|
||||
|
||||
return gnc_owner_new (label, hbox, book, owner,
|
||||
GNC_GENERAL_SELECT_TYPE_SELECT);
|
||||
}
|
||||
|
||||
GtkWidget * gnc_owner_edit_create (GtkWidget *label, GtkWidget *hbox,
|
||||
GNCBook *book, GncOwner *owner)
|
||||
{
|
||||
g_return_val_if_fail (label != NULL, NULL);
|
||||
g_return_val_if_fail (hbox != NULL, NULL);
|
||||
g_return_val_if_fail (book != NULL, NULL);
|
||||
g_return_val_if_fail (owner != NULL, NULL);
|
||||
|
||||
return gnc_owner_new (label, hbox, book, owner,
|
||||
GNC_GENERAL_SELECT_TYPE_EDIT);
|
||||
}
|
||||
|
||||
void gnc_owner_get_owner (GtkWidget *widget, GncOwner *owner)
|
||||
{
|
||||
g_return_if_fail (widget != NULL);
|
||||
g_return_if_fail (owner != NULL);
|
||||
|
||||
/* We'll assume that the owner has the proper 'type' because we
|
||||
* can't change it here. Hopefully the caller has it set properly
|
||||
*/
|
||||
owner->owner.undefined =
|
||||
gnc_general_select_get_selected (GNC_GENERAL_SELECT (widget));
|
||||
}
|
23
src/business/business-gnome/business-utils.h
Normal file
23
src/business/business-gnome/business-utils.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* business-utils.h -- General GUI Utilities for GNC Business Objects
|
||||
*
|
||||
* Written By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (C) 2001
|
||||
*/
|
||||
|
||||
#ifndef GNC_BUSINESS_UTILS_H_
|
||||
#define GNC_BUSINESS_UTILS_H_
|
||||
|
||||
#include "gnc-general-select.h"
|
||||
#include "gnc-book.h"
|
||||
#include "gncOwner.h"
|
||||
|
||||
GtkWidget * gnc_owner_select_create (GtkWidget *label, GtkWidget *hbox,
|
||||
GNCBook *book, GncOwner *owner);
|
||||
|
||||
GtkWidget * gnc_owner_edit_create (GtkWidget *label, GtkWidget *hbox,
|
||||
GNCBook *book, GncOwner *owner);
|
||||
|
||||
void gnc_owner_get_owner (GtkWidget *widget, GncOwner *owner);
|
||||
|
||||
#endif /* GNC_BUSINESS_UTILS_H_ */
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "dialog-order.h"
|
||||
#include "business-chooser.h"
|
||||
#include "business-utils.h"
|
||||
|
||||
#define DIALOG_NEW_ORDER_CM_CLASS "dialog-new-order"
|
||||
#define DIALOG_EDIT_ORDER_CM_CLASS "dialog-edit-order"
|
||||
@ -42,6 +43,13 @@ struct _order_select_window {
|
||||
typedef struct _order_window {
|
||||
GtkWidget * dialog;
|
||||
|
||||
GtkWidget * id_entry;
|
||||
GtkWidget * owner_choice;
|
||||
GtkWidget * notes_text;
|
||||
GtkWidget * opened_date;
|
||||
GtkWidget * closed_date;
|
||||
GtkWidget * active_check;
|
||||
|
||||
GnucashRegister * reg;
|
||||
|
||||
OrderDialogType dialog_type;
|
||||
@ -63,9 +71,30 @@ ow_get_order (OrderWindow *ow)
|
||||
|
||||
static void gnc_ui_to_order (OrderWindow *ow, GncOrder *order)
|
||||
{
|
||||
/* Fill this in */
|
||||
Timespec ts;
|
||||
time_t tt;
|
||||
|
||||
// gncOrderCommitEdit (order);
|
||||
gnc_suspend_gui_refresh ();
|
||||
|
||||
gncOrderSetID (order, gtk_editable_get_chars
|
||||
(GTK_EDITABLE (ow->id_entry), 0, -1));
|
||||
gncOrderSetNotes (order, gtk_editable_get_chars
|
||||
(GTK_EDITABLE (ow->notes_text), 0, -1));
|
||||
|
||||
tt = gnome_date_edit_get_date (GNOME_DATE_EDIT (ow->opened_date));
|
||||
timespecFromTime_t (&ts, tt);
|
||||
gncOrderSetDateOpened (order, &ts);
|
||||
|
||||
tt = gnome_date_edit_get_date (GNOME_DATE_EDIT (ow->closed_date));
|
||||
timespecFromTime_t (&ts, tt);
|
||||
gncOrderSetDateClosed (order, &ts);
|
||||
|
||||
gncOrderSetActive (order, gtk_toggle_button_get_active
|
||||
(GTK_TOGGLE_BUTTON (ow->active_check)));
|
||||
|
||||
/* XXX: Set the owner? */
|
||||
|
||||
gncOrderCommitEdit (order);
|
||||
gnc_resume_gui_refresh ();
|
||||
}
|
||||
|
||||
@ -75,11 +104,21 @@ gnc_order_window_ok_cb (GtkWidget *widget, gpointer data)
|
||||
OrderWindow *ow = data;
|
||||
GncOrder *order;
|
||||
|
||||
{
|
||||
const char *res = gtk_entry_get_text (GTK_ENTRY (ow->id_entry));
|
||||
if (safe_strcmp (res, "") == 0) {
|
||||
gnc_error_dialog_parented (GTK_WINDOW (ow->dialog),
|
||||
_("The Order must be given an ID."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now save it off */
|
||||
{
|
||||
GncOrder *order = ow_get_order (ow);
|
||||
if (order) {
|
||||
gnc_ui_to_order (ow, order);
|
||||
|
||||
}
|
||||
ow->created_order = order;
|
||||
ow->order_guid = *xaccGUIDNULL ();
|
||||
@ -206,11 +245,11 @@ gnc_configure_register_colors (void)
|
||||
|
||||
static OrderWindow *
|
||||
gnc_order_new_window (GtkWidget *parent, GNCBook *bookp,
|
||||
GncOrder *order)
|
||||
GncOrder *order, GncOwner *owner)
|
||||
{
|
||||
OrderWindow *ow;
|
||||
GladeXML *xml;
|
||||
GtkWidget *vbox, *regWidget;
|
||||
GtkWidget *label, *hbox, *vbox, *regWidget;
|
||||
GncEntryLedger *entry_ledger;
|
||||
GnomeDialog *owd;
|
||||
GList *entries;
|
||||
@ -227,7 +266,18 @@ gnc_order_new_window (GtkWidget *parent, GNCBook *bookp,
|
||||
|
||||
gtk_object_set_data (GTK_OBJECT (ow->dialog), "dialog_info", ow);
|
||||
|
||||
/* Grab the widgets */
|
||||
ow->id_entry = glade_xml_get_widget (xml, "id_entry");
|
||||
ow->notes_text = glade_xml_get_widget (xml, "notes_text");
|
||||
ow->opened_date = glade_xml_get_widget (xml, "opened_date");
|
||||
ow->closed_date = glade_xml_get_widget (xml, "closed_date");
|
||||
ow->active_check = glade_xml_get_widget (xml, "active_check");
|
||||
|
||||
hbox = glade_xml_get_widget (xml, "owner_hbox");
|
||||
label = glade_xml_get_widget (xml, "owner_label");
|
||||
|
||||
/* default to ok */
|
||||
gnome_dialog_editable_enters (owd, GTK_EDITABLE (ow->id_entry));
|
||||
gnome_dialog_set_default (owd, 0);
|
||||
|
||||
/* Build the ledger */
|
||||
@ -265,6 +315,11 @@ gnc_order_new_window (GtkWidget *parent, GNCBook *bookp,
|
||||
if (order != NULL) {
|
||||
ow->dialog_type = EDIT_ORDER;
|
||||
ow->order_guid = *gncOrderGetGUID (order);
|
||||
owner = gncOrderGetOwner (order); /* Overwrite what was passed in */
|
||||
|
||||
ow->owner_choice = gnc_owner_edit_create (label, hbox, bookp, owner);
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (ow->id_entry), gncOrderGetID (order));
|
||||
|
||||
ow->component_id =
|
||||
gnc_register_gui_component (DIALOG_EDIT_ORDER_CM_CLASS,
|
||||
@ -273,11 +328,17 @@ gnc_order_new_window (GtkWidget *parent, GNCBook *bookp,
|
||||
ow);
|
||||
|
||||
} else {
|
||||
order = gncOrderCreate (bookp, GNC_ORDER_SALES); /* XXX */
|
||||
order = gncOrderCreate (bookp);
|
||||
ow->order_guid = *gncOrderGetGUID (order);
|
||||
gncOrderSetOwner (order, owner);
|
||||
|
||||
ow->owner_choice = gnc_owner_select_create (label, hbox, bookp, owner);
|
||||
|
||||
ow->dialog_type = NEW_ORDER;
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (ow->id_entry),
|
||||
g_strdup_printf ("%.6d", gncOrderNextID(bookp)));
|
||||
|
||||
ow->component_id =
|
||||
gnc_register_gui_component (DIALOG_NEW_ORDER_CM_CLASS,
|
||||
gnc_order_window_refresh_handler,
|
||||
@ -285,6 +346,39 @@ gnc_order_new_window (GtkWidget *parent, GNCBook *bookp,
|
||||
ow);
|
||||
}
|
||||
|
||||
/* We know that "order" (and "owner") exist now */
|
||||
{
|
||||
const char *string;
|
||||
Timespec ts, ts_zero = {0,0};
|
||||
time_t tt;
|
||||
gint pos = 0;
|
||||
|
||||
string = gncOrderGetNotes (order);
|
||||
gtk_editable_delete_text (GTK_EDITABLE (ow->notes_text), 0, -1);
|
||||
gtk_editable_insert_text (GTK_EDITABLE (ow->notes_text), string,
|
||||
strlen (string), &pos);
|
||||
|
||||
ts = gncOrderGetDateOpened (order);
|
||||
if (timespec_equal (&ts, &ts_zero)) {
|
||||
tt = time(NULL);
|
||||
} else {
|
||||
tt = ts.tv_sec; /* XXX */
|
||||
}
|
||||
gnome_date_edit_set_time (GNOME_DATE_EDIT (ow->opened_date), tt);
|
||||
|
||||
ts = gncOrderGetDateClosed (order);
|
||||
if (timespec_equal (&ts, &ts_zero)) {
|
||||
tt = time(NULL);
|
||||
} else {
|
||||
tt = ts.tv_sec; /* XXX */
|
||||
}
|
||||
gnome_date_edit_set_time (GNOME_DATE_EDIT (ow->closed_date), tt);
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ow->active_check),
|
||||
gncOrderGetActive (order));
|
||||
|
||||
}
|
||||
|
||||
gnc_gui_component_watch_entity_type (ow->component_id,
|
||||
GNC_ID_NONE,
|
||||
GNC_EVENT_MODIFY | GNC_EVENT_DESTROY);
|
||||
@ -302,11 +396,14 @@ gnc_order_new (GtkWidget *parent, GNCBook *bookp)
|
||||
{
|
||||
OrderWindow *ow;
|
||||
GncOrder *created_order = NULL;
|
||||
GncOwner owner;
|
||||
|
||||
gncOwnerInitCustomer (&owner, NULL);
|
||||
|
||||
/* Make sure required options exist */
|
||||
if (!bookp) return NULL;
|
||||
|
||||
ow = gnc_order_new_window (parent, bookp, NULL);
|
||||
ow = gnc_order_new_window (parent, bookp, NULL, &owner);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (ow->dialog), "close",
|
||||
GTK_SIGNAL_FUNC (gnc_order_on_close_cb),
|
||||
@ -323,10 +420,11 @@ void
|
||||
gnc_order_edit (GtkWidget *parent, GncOrder *order)
|
||||
{
|
||||
OrderWindow *ow;
|
||||
GncOwner owner;
|
||||
|
||||
if (!order) return;
|
||||
|
||||
ow = gnc_order_new_window (parent, gncOrderGetBook(order), order);
|
||||
ow = gnc_order_new_window (parent, gncOrderGetBook(order), order, NULL);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (ow->dialog), "close",
|
||||
GTK_SIGNAL_FUNC (gnc_order_on_close_cb),
|
||||
|
@ -96,11 +96,277 @@
|
||||
</child>
|
||||
|
||||
<widget>
|
||||
<class>Placeholder</class>
|
||||
</widget>
|
||||
<class>GtkFrame</class>
|
||||
<name>frame1</name>
|
||||
<label>Order Information</label>
|
||||
<label_xalign>0</label_xalign>
|
||||
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
|
||||
<child>
|
||||
<padding>3</padding>
|
||||
<expand>True</expand>
|
||||
<fill>True</fill>
|
||||
</child>
|
||||
|
||||
<widget>
|
||||
<class>Placeholder</class>
|
||||
<widget>
|
||||
<class>GtkHBox</class>
|
||||
<name>hbox1</name>
|
||||
<border_width>3</border_width>
|
||||
<homogeneous>False</homogeneous>
|
||||
<spacing>0</spacing>
|
||||
|
||||
<widget>
|
||||
<class>GtkVBox</class>
|
||||
<name>vbox2</name>
|
||||
<border_width>2</border_width>
|
||||
<homogeneous>True</homogeneous>
|
||||
<spacing>0</spacing>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>True</fill>
|
||||
</child>
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>label1</name>
|
||||
<label>Order ID</label>
|
||||
<justify>GTK_JUSTIFY_RIGHT</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>1</xalign>
|
||||
<yalign>0.5</yalign>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>owner_label</name>
|
||||
<label></label>
|
||||
<justify>GTK_JUSTIFY_RIGHT</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>1</xalign>
|
||||
<yalign>0.5</yalign>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>label2</name>
|
||||
<label></label>
|
||||
<justify>GTK_JUSTIFY_CENTER</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>0.5</xalign>
|
||||
<yalign>0.5</yalign>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
<pack>GTK_PACK_END</pack>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>label3</name>
|
||||
<label>Opened</label>
|
||||
<justify>GTK_JUSTIFY_RIGHT</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>1</xalign>
|
||||
<yalign>0.5</yalign>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>label4</name>
|
||||
<label>Closed</label>
|
||||
<justify>GTK_JUSTIFY_RIGHT</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>1</xalign>
|
||||
<yalign>0.5</yalign>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
</child>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkVBox</class>
|
||||
<name>vbox3</name>
|
||||
<border_width>2</border_width>
|
||||
<homogeneous>True</homogeneous>
|
||||
<spacing>0</spacing>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>True</fill>
|
||||
</child>
|
||||
|
||||
<widget>
|
||||
<class>GtkEntry</class>
|
||||
<name>id_entry</name>
|
||||
<can_focus>True</can_focus>
|
||||
<editable>True</editable>
|
||||
<text_visible>True</text_visible>
|
||||
<text_max_length>0</text_max_length>
|
||||
<text></text>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkHBox</class>
|
||||
<name>owner_hbox</name>
|
||||
<homogeneous>False</homogeneous>
|
||||
<spacing>0</spacing>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>True</expand>
|
||||
<fill>True</fill>
|
||||
</child>
|
||||
|
||||
<widget>
|
||||
<class>Placeholder</class>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkCheckButton</class>
|
||||
<name>active_check</name>
|
||||
<can_focus>True</can_focus>
|
||||
<label>Active</label>
|
||||
<active>False</active>
|
||||
<draw_indicator>True</draw_indicator>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
<pack>GTK_PACK_END</pack>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GnomeDateEdit</class>
|
||||
<name>opened_date</name>
|
||||
<show_time>False</show_time>
|
||||
<use_24_format>False</use_24_format>
|
||||
<week_start_monday>False</week_start_monday>
|
||||
<lower_hour>7</lower_hour>
|
||||
<upper_hour>19</upper_hour>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GnomeDateEdit</class>
|
||||
<name>closed_date</name>
|
||||
<show_time>False</show_time>
|
||||
<use_24_format>False</use_24_format>
|
||||
<week_start_monday>False</week_start_monday>
|
||||
<lower_hour>7</lower_hour>
|
||||
<upper_hour>19</upper_hour>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
</child>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkVBox</class>
|
||||
<name>vbox4</name>
|
||||
<border_width>4</border_width>
|
||||
<homogeneous>False</homogeneous>
|
||||
<spacing>0</spacing>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
</child>
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>label5</name>
|
||||
<label>Notes</label>
|
||||
<justify>GTK_JUSTIFY_RIGHT</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>0.5</xalign>
|
||||
<yalign>0.5</yalign>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
</child>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkVBox</class>
|
||||
<name>vbox5</name>
|
||||
<border_width>3</border_width>
|
||||
<homogeneous>False</homogeneous>
|
||||
<spacing>0</spacing>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>True</fill>
|
||||
</child>
|
||||
|
||||
<widget>
|
||||
<class>GtkScrolledWindow</class>
|
||||
<name>scrolledwindow1</name>
|
||||
<hscrollbar_policy>GTK_POLICY_NEVER</hscrollbar_policy>
|
||||
<vscrollbar_policy>GTK_POLICY_ALWAYS</vscrollbar_policy>
|
||||
<hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy>
|
||||
<vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>True</expand>
|
||||
<fill>True</fill>
|
||||
</child>
|
||||
|
||||
<widget>
|
||||
<class>GtkText</class>
|
||||
<name>notes_text</name>
|
||||
<can_focus>True</can_focus>
|
||||
<editable>True</editable>
|
||||
<text></text>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
|
@ -12,6 +12,9 @@
|
||||
|
||||
#include "Account.h"
|
||||
#include "gnc-ui-util.h"
|
||||
#include "combocell.h"
|
||||
#include "pricecell.h"
|
||||
#include "messages.h"
|
||||
|
||||
#include "gncEntry.h"
|
||||
#include "gncEntryLedger.h"
|
||||
@ -79,6 +82,54 @@ GncEntry * gnc_entry_ledger_get_current_entry (GncEntryLedger *ledger)
|
||||
ledger->table->current_cursor_loc.vcell_loc);
|
||||
}
|
||||
|
||||
static void gnc_entry_ledger_config_action (GncEntryLedger *ledger)
|
||||
{
|
||||
ComboCell *cell;
|
||||
|
||||
cell = (ComboCell *) gnc_table_layout_get_cell (ledger->table->layout,
|
||||
ENTRY_ACTN_CELL);
|
||||
if (!cell) return;
|
||||
|
||||
/* XXX: change this based on the ledger type */
|
||||
|
||||
gnc_combo_cell_add_menu_item (cell, _("Hours"));
|
||||
gnc_combo_cell_add_menu_item (cell, _("Project"));
|
||||
gnc_combo_cell_add_menu_item (cell, _("Material"));
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_entry_ledger_config_cells (GncEntryLedger *ledger)
|
||||
{
|
||||
/* the action cell */
|
||||
gnc_combo_cell_set_autosize
|
||||
((ComboCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_ACTN_CELL), TRUE);
|
||||
|
||||
/* Use 6 decimal places for all prices and quantities */
|
||||
gnc_price_cell_set_fraction
|
||||
((PriceCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_PRIC_CELL),
|
||||
1000000);
|
||||
|
||||
gnc_price_cell_set_fraction
|
||||
((PriceCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DISC_CELL),
|
||||
1000000);
|
||||
|
||||
gnc_price_cell_set_fraction
|
||||
((PriceCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_TAX_CELL),
|
||||
1000000);
|
||||
|
||||
gnc_price_cell_set_fraction
|
||||
((PriceCell *) gnc_table_layout_get_cell (ledger->table->layout,
|
||||
ENTRY_QTY_CELL),
|
||||
1000000);
|
||||
|
||||
/* add menu items for the action cell */
|
||||
gnc_entry_ledger_config_action (ledger);
|
||||
}
|
||||
|
||||
/* Create and return a new GncEntry Ledger */
|
||||
GncEntryLedger * gnc_entry_ledger_new (GNCBook *book, GncEntryLedgerType type)
|
||||
{
|
||||
@ -110,7 +161,7 @@ GncEntryLedger * gnc_entry_ledger_new (GNCBook *book, GncEntryLedgerType type)
|
||||
ledger->table = gnc_table_new (layout, model, control);
|
||||
}
|
||||
|
||||
/* config_cells? */
|
||||
gnc_entry_ledger_config_cells (ledger);
|
||||
|
||||
/* set up header */
|
||||
{
|
||||
|
@ -90,6 +90,32 @@ static void gnc_entry_ledger_cancel_cursor_changes (GncEntryLedger *ledger)
|
||||
gnc_table_refresh_gui (ledger->table, TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gnc_entry_ledger_auto_completion (GncEntryLedger *ledger,
|
||||
gncTableTraversalDir dir,
|
||||
VirtualLocation *p_new_virt_loc)
|
||||
{
|
||||
VirtualLocation new_virt_loc;
|
||||
GncEntry *entry;
|
||||
GncEntry *blank_entry;
|
||||
const char *cell_name;
|
||||
BasicCell *cell;
|
||||
|
||||
blank_entry = gncEntryLookup (ledger->book, &ledger->blank_entry_guid);
|
||||
|
||||
/* auto-completion is only triggered by a tab out */
|
||||
if (dir != GNC_TABLE_TRAVERSE_RIGHT)
|
||||
return FALSE;
|
||||
|
||||
entry = gnc_entry_ledger_get_current_entry (ledger);
|
||||
if (entry == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* No other autocompletion, yet */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean gnc_entry_ledger_traverse (VirtualLocation *p_new_virt_loc,
|
||||
gncTableTraversalDir dir,
|
||||
gpointer user_data)
|
||||
@ -225,8 +251,8 @@ static gboolean gnc_entry_ledger_traverse (VirtualLocation *p_new_virt_loc,
|
||||
if (!gnc_table_virtual_cell_out_of_bounds (ledger->table,
|
||||
virt_loc.vcell_loc))
|
||||
{
|
||||
// if (gnc_split_register_auto_completion (ledger, dir, p_new_virt_loc))
|
||||
// return FALSE;
|
||||
if (gnc_entry_ledger_auto_completion (ledger, dir, p_new_virt_loc))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* See if we are tabbing off the end of a blank entry */
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "Account.h"
|
||||
#include "gnc-ui-util.h"
|
||||
#include "recncell.h"
|
||||
#include "combocell.h"
|
||||
#include "messages.h"
|
||||
|
||||
#include "gncEntry.h"
|
||||
@ -21,8 +22,7 @@
|
||||
|
||||
|
||||
/* XXX: This should go elsewhere */
|
||||
const char *
|
||||
gnc_entry_ledger_type_string_getter (char flag)
|
||||
const char * gnc_entry_ledger_type_string_getter (char flag)
|
||||
{
|
||||
switch (flag) {
|
||||
case '0': return _("$");
|
||||
@ -34,8 +34,7 @@ gnc_entry_ledger_type_string_getter (char flag)
|
||||
};
|
||||
}
|
||||
|
||||
static void
|
||||
load_tax_type_cells (GncEntryLedger *ledger)
|
||||
static void load_tax_type_cells (GncEntryLedger *ledger)
|
||||
{
|
||||
RecnCell *cell;
|
||||
const char * s;
|
||||
@ -52,8 +51,7 @@ load_tax_type_cells (GncEntryLedger *ledger)
|
||||
gnc_recn_cell_set_string_getter (cell, gnc_entry_ledger_type_string_getter);
|
||||
}
|
||||
|
||||
static void
|
||||
load_discount_type_cells (GncEntryLedger *ledger)
|
||||
static void load_discount_type_cells (GncEntryLedger *ledger)
|
||||
{
|
||||
RecnCell *cell;
|
||||
const char * s;
|
||||
@ -70,6 +68,52 @@ load_discount_type_cells (GncEntryLedger *ledger)
|
||||
gnc_recn_cell_set_string_getter (cell, gnc_entry_ledger_type_string_getter);
|
||||
}
|
||||
|
||||
static void load_xfer_cell (ComboCell * cell, AccountGroup * grp)
|
||||
{
|
||||
GList *list;
|
||||
GList *node;
|
||||
|
||||
if (!grp) return;
|
||||
|
||||
/* Build the xfer menu out of account names. */
|
||||
|
||||
list = xaccGroupGetSubAccounts (grp);
|
||||
|
||||
for (node = list; node; node = node->next) {
|
||||
Account *account = node->data;
|
||||
char *name;
|
||||
|
||||
name = xaccAccountGetFullName (account, gnc_get_account_separator ());
|
||||
if (name != NULL) {
|
||||
gnc_combo_cell_add_menu_item (cell, name);
|
||||
g_free(name);
|
||||
}
|
||||
}
|
||||
|
||||
g_list_free (list);
|
||||
}
|
||||
|
||||
static void load_xfer_type_cells (GncEntryLedger *ledger)
|
||||
{
|
||||
AccountGroup *group;
|
||||
ComboCell *cell;
|
||||
|
||||
group = gnc_book_get_group (ledger->book);
|
||||
if (group == NULL)
|
||||
return;
|
||||
|
||||
cell = (ComboCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_ACCT_CELL);
|
||||
gnc_combo_cell_clear_menu (cell);
|
||||
load_xfer_cell (cell, group);
|
||||
|
||||
cell = (ComboCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_TAXACC_CELL);
|
||||
gnc_combo_cell_clear_menu (cell);
|
||||
load_xfer_cell (cell, group);
|
||||
}
|
||||
|
||||
/* XXX (FIXME): This should be in a config file! */
|
||||
/* Copy GncEntry information from the list to the rows of the Ledger. */
|
||||
void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
|
||||
{
|
||||
@ -88,6 +132,7 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
|
||||
/* Load up cells */
|
||||
load_discount_type_cells (ledger);
|
||||
load_tax_type_cells (ledger);
|
||||
load_xfer_type_cells (ledger);
|
||||
|
||||
blank_entry = gncEntryLookup (ledger->book, &(ledger->blank_entry_guid));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user