45 #include <glib/gi18n.h>
46 #include <qofinstance-p.h>
51 #include "gnc-lot-p.h"
54 #include "TransactionP.h"
90 signed char is_closed;
91 #define LOT_CLOSED_UNKNOWN (-1)
97 #define GET_PRIVATE(o) \
98 (G_TYPE_INSTANCE_GET_PRIVATE((o), GNC_TYPE_LOT, LotPrivate))
100 #define gnc_lot_set_guid(L,G) qof_instance_set_guid(QOF_INSTANCE(L),&(G))
104 static void gnc_lot_set_invoice (
GNCLot* lot,
GncGUID *guid);
110 G_DEFINE_TYPE(
GNCLot, gnc_lot, QOF_TYPE_INSTANCE)
117 priv = GET_PRIVATE(lot);
118 priv->account = NULL;
120 priv->is_closed = LOT_CLOSED_UNKNOWN;
125 gnc_lot_dispose(GObject *lotp)
127 G_OBJECT_CLASS(gnc_lot_parent_class)->dispose(lotp);
131 gnc_lot_finalize(GObject* lotp)
133 G_OBJECT_CLASS(gnc_lot_parent_class)->finalize(lotp);
137 gnc_lot_get_property(GObject*
object, guint prop_id, GValue* value, GParamSpec* pspec)
145 g_return_if_fail(GNC_IS_LOT(
object));
147 lot = GNC_LOT(
object);
148 priv = GET_PRIVATE(lot);
152 g_value_set_int(value, priv->is_closed);
155 g_value_set_int(value, priv->marker);
159 qof_instance_get_kvp (QOF_INSTANCE (lot), key, value);
161 case PROP_OWNER_TYPE:
162 key = GNC_OWNER_ID
"/" GNC_OWNER_TYPE;
163 qof_instance_get_kvp (QOF_INSTANCE (lot), key, value);
165 case PROP_OWNER_GUID:
166 key = GNC_OWNER_ID
"/" GNC_OWNER_GUID;
167 qof_instance_get_kvp (QOF_INSTANCE (lot), key, value);
170 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
176 gnc_lot_set_property (GObject*
object,
186 g_return_if_fail(GNC_IS_LOT(
object));
188 lot = GNC_LOT(
object);
189 if (prop_id < PROP_RUNTIME_0)
190 g_assert (qof_instance_get_editlevel(lot));
192 priv = GET_PRIVATE(lot);
196 priv->is_closed = g_value_get_int(value);
199 priv->marker = g_value_get_int(value);
203 qof_instance_set_kvp (QOF_INSTANCE (lot), key, value);
205 case PROP_OWNER_TYPE:
206 key = GNC_OWNER_ID
"/" GNC_OWNER_TYPE;
207 qof_instance_set_kvp (QOF_INSTANCE (lot), key, value);
209 case PROP_OWNER_GUID:
210 key = GNC_OWNER_ID
"/" GNC_OWNER_GUID;
211 qof_instance_set_kvp (QOF_INSTANCE (lot), key, value);
214 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
220 gnc_lot_class_init(GNCLotClass* klass)
222 GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
224 gobject_class->dispose = gnc_lot_dispose;
225 gobject_class->finalize = gnc_lot_finalize;
226 gobject_class->get_property = gnc_lot_get_property;
227 gobject_class->set_property = gnc_lot_set_property;
229 g_type_class_add_private(klass,
sizeof(
LotPrivate));
231 g_object_class_install_property(
234 g_param_spec_int(
"is-closed",
236 "Indication of whether this lot is open "
237 "or closed to further changes.",
241 g_object_class_install_property(
244 g_param_spec_int(
"marker",
250 g_object_class_install_property(
253 g_param_spec_boxed(
"invoice",
254 "Invoice attached to lot",
255 "Used by GncInvoice",
259 g_object_class_install_property(
262 g_param_spec_int64(
"owner-type",
263 "Owning Entity Type of lot",
268 g_object_class_install_property(
271 g_param_spec_boxed(
"owner-guid",
272 "Owner attached to lot",
282 g_return_val_if_fail (book, NULL);
284 lot = g_object_new (GNC_TYPE_LOT, NULL);
297 ENTER (
"(lot=%p)", lot);
300 priv = GET_PRIVATE(lot);
301 for (node = priv->splits; node; node = node->next)
303 Split *s = node->data;
306 g_list_free (priv->splits);
308 priv->account = NULL;
309 priv->is_closed = TRUE;
311 g_object_unref (lot);
317 gnc_lot_destroy (
GNCLot *lot)
321 gnc_lot_begin_edit(lot);
322 qof_instance_set_destroying(lot, TRUE);
323 gnc_lot_commit_edit(lot);
329 gnc_lot_begin_edit (
GNCLot *lot)
336 PERR (
"Failed to commit: %d", errcode);
337 gnc_engine_signal_commit_error( errcode );
342 GNCLot* lot = GNC_LOT(inst);
350 gnc_lot_commit_edit (
GNCLot *lot)
362 if (!guid || !book)
return NULL;
368 gnc_lot_get_book (
GNCLot *lot)
379 if (!lot)
return TRUE;
380 priv = GET_PRIVATE(lot);
382 return priv->is_closed;
389 if (!lot)
return NULL;
390 priv = GET_PRIVATE(lot);
391 return priv->account;
400 priv = GET_PRIVATE(lot);
401 priv->account = account;
411 priv = GET_PRIVATE(lot);
412 priv->is_closed = LOT_CLOSED_UNKNOWN;
420 if (!lot)
return NULL;
421 priv = GET_PRIVATE(lot);
425 gint gnc_lot_count_splits (
const GNCLot *lot)
429 priv = GET_PRIVATE(lot);
430 return g_list_length (priv->splits);
439 if (!lot)
return NULL;
440 return kvp_frame_get_string (qof_instance_get_slots(QOF_INSTANCE (lot)),
445 gnc_lot_get_notes (
const GNCLot *lot)
447 if (!lot)
return NULL;
448 return kvp_frame_get_string (qof_instance_get_slots(QOF_INSTANCE (lot)),
453 gnc_lot_set_title (
GNCLot *lot,
const char *str)
457 qof_instance_set_dirty(QOF_INSTANCE(lot));
460 gnc_lot_commit_edit(lot);
464 gnc_lot_set_notes (
GNCLot *lot,
const char *str)
467 gnc_lot_begin_edit(lot);
468 qof_instance_set_dirty(QOF_INSTANCE(lot));
471 gnc_lot_commit_edit(lot);
483 if (!lot)
return zero;
485 priv = GET_PRIVATE(lot);
488 priv->is_closed = FALSE;
495 for (node = priv->splits; node; node = node->next)
497 Split *s = node->data;
499 baln = gnc_numeric_add_fixed (baln, amt);
506 priv->is_closed = TRUE;
510 priv->is_closed = FALSE;
530 if (lot == NULL)
return;
532 priv = GET_PRIVATE(lot);
544 for (node = priv->splits; node; node = node->next)
546 Split *s = node->data;
551 if ((ta == tb && source != target) ||
555 amt = gnc_numeric_add_fixed (amt, tmpval);
557 val = gnc_numeric_add_fixed (val, tmpval);
573 if (!lot || !split)
return;
574 priv = GET_PRIVATE(lot);
576 ENTER (
"(lot=%p, split=%p) %s amt=%s val=%s", lot, split,
580 gnc_lot_begin_edit(lot);
582 qof_instance_set_dirty(QOF_INSTANCE(lot));
583 if (NULL == priv->account)
587 else if (priv->account != acc)
589 PERR (
"splits from different accounts cannot "
590 "be added to this lot!\n"
591 "\tlot account=\'%s\', split account=\'%s\'\n",
593 gnc_lot_commit_edit(lot);
594 LEAVE(
"different accounts");
598 if (lot == split->lot)
600 gnc_lot_commit_edit(lot);
601 LEAVE(
"already in lot");
606 gnc_lot_remove_split (split->lot, split);
610 priv->splits = g_list_append (priv->splits, split);
613 priv->is_closed = LOT_CLOSED_UNKNOWN;
614 gnc_lot_commit_edit(lot);
617 LEAVE(
"added to lot");
624 if (!lot || !split)
return;
625 priv = GET_PRIVATE(lot);
627 ENTER (
"(lot=%p, split=%p)", lot, split);
628 gnc_lot_begin_edit(lot);
629 qof_instance_set_dirty(QOF_INSTANCE(lot));
630 priv->splits = g_list_remove (priv->splits, split);
632 priv->is_closed = LOT_CLOSED_UNKNOWN;
634 if (NULL == priv->splits)
636 xaccAccountRemoveLot (priv->account, lot);
637 priv->account = NULL;
639 gnc_lot_commit_edit(lot);
641 LEAVE(
"removed from lot");
651 if (!lot)
return NULL;
652 priv = GET_PRIVATE(lot);
653 if (! priv->splits)
return NULL;
654 priv->splits = g_list_sort (priv->splits, (GCompareFunc) xaccSplitOrderDateOnly);
655 return priv->splits->data;
665 if (!lot)
return NULL;
666 priv = GET_PRIVATE(lot);
667 if (! priv->splits)
return NULL;
668 priv->splits = g_list_sort (priv->splits, (GCompareFunc) xaccSplitOrderDateOnly);
670 for (node = priv->splits; node->next; node = node->next)
679 destroy_lot_on_book_close(
QofInstance *ent, gpointer data)
681 GNCLot* lot = GNC_LOT(ent);
683 gnc_lot_destroy(lot);
687 gnc_lot_book_end(
QofBook* book)
705 DI(.e_type = ) GNC_ID_LOT,
706 DI(.type_label = ) "Lot",
707 DI(.create = ) (gpointer)gnc_lot_new,
708 DI(.book_begin = ) NULL,
709 DI(.book_end = ) gnc_lot_book_end,
713 DI(.printable = ) NULL,
718 gboolean gnc_lot_register (
void)
723 LOT_TITLE, QOF_TYPE_STRING,
728 LOT_NOTES, QOF_TYPE_STRING,
733 QOF_PARAM_GUID, QOF_TYPE_GUID,
741 LOT_IS_CLOSED, QOF_TYPE_BOOLEAN,
745 LOT_BALANCE, QOF_TYPE_NUMERIC,
766 buff = g_strdup_printf (
"%s %" G_GINT64_FORMAT, _(
"Lot"),
id);
767 gnc_lot_set_title (lot, buff);
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
gchar * gnc_num_dbg_to_string(gnc_numeric n)
void qof_instance_get(const QofInstance *inst, const gchar *first_param,...)
Wrapper for g_object_get.
QofBook * qof_instance_get_book(gconstpointer)
gboolean qof_collection_is_dirty(const QofCollection *col)
QofInstance * qof_collection_lookup_entity(const QofCollection *, const GncGUID *)
QofBackendError
The errors that can be reported to the GUI & other front-end users.
void qof_instance_set(QofInstance *inst, const gchar *first_param,...)
Wrapper for g_object_set Group setting multiple parameters in a single begin/commit/rollback.
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_fcn, const QofParam *params)
void gnc_lot_add_split(GNCLot *lot, Split *split)
Split * xaccSplitGetGainsSourceSplit(const Split *split)
void xaccAccountInsertLot(Account *acc, GNCLot *lot)
Transaction * xaccSplitGetParent(const Split *split)
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
#define QOF_OBJECT_VERSION
gboolean qof_commit_edit(QofInstance *inst)
#define PERR(format, args...)
#define ENTER(format, args...)
void gnc_lot_set_closed_unknown(GNCLot *lot)
void qof_collection_foreach(const QofCollection *, QofInstanceForeachCB, gpointer user_data)
Split * gnc_lot_get_earliest_split(GNCLot *lot)
const char * gnc_lot_get_title(const GNCLot *lot)
Split * gnc_lot_get_latest_split(GNCLot *lot)
void qof_instance_init_data(QofInstance *, QofIdType, QofBook *)
gboolean qof_begin_edit(QofInstance *inst)
Account handling public routines.
SplitList * gnc_lot_get_split_list(const GNCLot *lot)
void gnc_lot_get_balance_before(const GNCLot *lot, const Split *split, gnc_numeric *amount, gnc_numeric *value)
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
void qof_collection_mark_clean(QofCollection *)
const GncGUID * qof_entity_get_guid(gconstpointer)
void xaccSplitSetLot(Split *split, GNCLot *lot)
GNCLot * gnc_lot_make_default(Account *acc)
gboolean gnc_lot_is_closed(GNCLot *lot)
gnc_numeric xaccSplitGetValue(const Split *split)
void xaccAccountBeginEdit(Account *acc)
Account * xaccSplitGetAccount(const Split *s)
struct KvpFrameImpl KvpFrame
#define LEAVE(format, args...)
void(* QofSetterFunc)(gpointer, gpointer)
int xaccTransOrder(const Transaction *ta, const Transaction *tb)
GNCNumericErrorCode gnc_numeric_check(gnc_numeric a)
QofCollection * qof_book_get_collection(const QofBook *, QofIdType)
Account * gnc_lot_get_account(const GNCLot *lot)
gboolean qof_object_register(const QofObject *object)
const char * xaccAccountGetName(const Account *acc)
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
API for Transactions and Splits (journal entries)
void xaccAccountCommitEdit(Account *acc)
Utilities to Automatically Compute Capital Gains/Losses.
void kvp_frame_set_string(KvpFrame *frame, const gchar *path, const gchar *str)
Store a copy of the string at the indicated path.
gnc_numeric gnc_lot_get_balance(GNCLot *lot)
const gchar * QofLogModule
gnc_numeric xaccSplitGetAmount(const Split *split)