static GtkWidget * create_owner_widget (GNCOption *option, GncOwnerType type, GtkWidget *hbox) { GtkWidget *widget; GncOwner owner; switch (type) { case GNC_OWNER_CUSTOMER: gncOwnerInitCustomer (&owner, NULL); break; case GNC_OWNER_VENDOR: gncOwnerInitVendor (&owner, NULL); break; case GNC_OWNER_EMPLOYEE: gncOwnerInitEmployee (&owner, NULL); break; case GNC_OWNER_JOB: gncOwnerInitJob (&owner, NULL); break; default: return NULL; } widget = gnc_owner_select_create (NULL, hbox, gnc_get_current_book (), &owner); gnc_option_set_widget (option, widget); g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (gnc_option_changed_option_cb), option); return widget; }
gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner) { GncGUID *guid = NULL; QofBook *book; GncOwnerType type = GNC_OWNER_NONE; if (!lot || !owner) return FALSE; book = gnc_lot_get_book (lot); qof_instance_get (QOF_INSTANCE (lot), "owner-type", &type, "owner-guid", &guid, NULL); switch (type) { case GNC_OWNER_CUSTOMER: gncOwnerInitCustomer (owner, gncCustomerLookup (book, guid)); break; case GNC_OWNER_VENDOR: gncOwnerInitVendor (owner, gncVendorLookup (book, guid)); break; case GNC_OWNER_EMPLOYEE: gncOwnerInitEmployee (owner, gncEmployeeLookup (book, guid)); break; case GNC_OWNER_JOB: gncOwnerInitJob (owner, gncJobLookup (book, guid)); break; default: return FALSE; } return (owner->owner.undefined != NULL); }
gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GncGUID *guid) { if (!book || !owner || !type || !guid) return FALSE; if (0 == g_strcmp0(type, GNC_ID_CUSTOMER)) { GncCustomer *customer = gncCustomerLookup(book, guid); gncOwnerInitCustomer(owner, customer); return (NULL != customer); } else if (0 == g_strcmp0(type, GNC_ID_JOB)) { GncJob *job = gncJobLookup(book, guid); gncOwnerInitJob(owner, job); return (NULL != job); } else if (0 == g_strcmp0(type, GNC_ID_VENDOR)) { GncVendor *vendor = gncVendorLookup(book, guid); gncOwnerInitVendor(owner, vendor); return (NULL != vendor); } else if (0 == g_strcmp0(type, GNC_ID_EMPLOYEE)) { GncEmployee *employee = gncEmployeeLookup(book, guid); gncOwnerInitEmployee(owner, employee); return (NULL != employee); } return 0; }
void qofOwnerSetEntity (GncOwner *owner, QofInstance *ent) { if (!owner || !ent) { return; } if (0 == g_strcmp0(ent->e_type, GNC_ID_CUSTOMER)) { owner->type = GNC_OWNER_CUSTOMER; gncOwnerInitCustomer(owner, (GncCustomer*)ent); } else if (0 == g_strcmp0(ent->e_type, GNC_ID_JOB)) { owner->type = GNC_OWNER_JOB; gncOwnerInitJob(owner, (GncJob*)ent); } else if (0 == g_strcmp0(ent->e_type, GNC_ID_VENDOR)) { owner->type = GNC_OWNER_VENDOR; gncOwnerInitVendor(owner, (GncVendor*)ent); } else if (0 == g_strcmp0(ent->e_type, GNC_ID_EMPLOYEE)) { owner->type = GNC_OWNER_EMPLOYEE; gncOwnerInitEmployee(owner, (GncEmployee*)ent); } else { owner->type = GNC_OWNER_NONE; owner->owner.undefined = NULL; } }
static gboolean owner_type_handler (xmlNodePtr node, gpointer owner_pdata) { struct owner_pdata* pdata = static_cast<decltype (pdata)> (owner_pdata); char* txt = dom_tree_to_text (node); g_return_val_if_fail (txt, FALSE); if (!g_strcmp0 (txt, GNC_ID_CUSTOMER)) gncOwnerInitCustomer (pdata->owner, NULL); else if (!g_strcmp0 (txt, GNC_ID_JOB)) gncOwnerInitJob (pdata->owner, NULL); else if (!g_strcmp0 (txt, GNC_ID_VENDOR)) gncOwnerInitVendor (pdata->owner, NULL); else if (!g_strcmp0 (txt, GNC_ID_EMPLOYEE)) gncOwnerInitEmployee (pdata->owner, NULL); else { PWARN ("Unknown owner type: %s", txt); g_free (txt); return FALSE; } g_free (txt); return TRUE; }
static void setup( Fixture *fixture, gconstpointer pData ) { fixture->book = qof_book_new(); fixture->account = xaccMallocAccount(fixture->book); fixture->commodity = gnc_commodity_new(fixture->book, "foo", "bar", "xy", "xy", 100); xaccAccountSetCommodity(fixture->account, fixture->commodity); fixture->customer = gncCustomerCreate(fixture->book); gncOwnerInitCustomer(&fixture->owner, fixture->customer); }
static void gnc_plugin_business_init (GncPluginBusiness *plugin) { GncPluginBusinessPrivate *priv; priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin); priv->last_customer = gncOwnerNew (); gncOwnerInitCustomer (priv->last_customer, NULL); priv->last_vendor = gncOwnerNew (); gncOwnerInitVendor (priv->last_vendor, NULL); priv->last_employee = gncOwnerNew (); gncOwnerInitEmployee (priv->last_employee, NULL); }
static void gnc_plugin_page_owner_tree_cmd_new_invoice (GtkAction *action, GncPluginPageOwnerTree *page) { GncPluginPageOwnerTreePrivate *priv; GncOwner current_owner; ENTER("action %p, page %p", action, page); priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(page); switch (priv->owner_type) { case GNC_OWNER_NONE : case GNC_OWNER_UNDEFINED : gncOwnerInitUndefined(¤t_owner, NULL); break; case GNC_OWNER_CUSTOMER : { gncOwnerInitCustomer(¤t_owner, gncOwnerGetCustomer(gnc_plugin_page_owner_tree_get_current_owner (page)) ); break; } case GNC_OWNER_JOB : { gncOwnerInitJob(¤t_owner, gncOwnerGetJob(gnc_plugin_page_owner_tree_get_current_owner (page)) ); break; } case GNC_OWNER_VENDOR : { gncOwnerInitVendor(¤t_owner, gncOwnerGetVendor(gnc_plugin_page_owner_tree_get_current_owner (page)) ); break; } case GNC_OWNER_EMPLOYEE : { gncOwnerInitEmployee(¤t_owner, gncOwnerGetEmployee(gnc_plugin_page_owner_tree_get_current_owner (page)) ); break; } } if (gncOwnerGetType(¤t_owner) != GNC_OWNER_UNDEFINED) gnc_ui_invoice_new (¤t_owner, gnc_get_current_book()); LEAVE(" "); }
GtkWidget * gnc_invoice_select_create (GtkWidget *hbox, QofBook *book, const GncOwner *owner, GncInvoice *invoice, GtkWidget *label) { GtkWidget *edit; GncISI *isi; g_return_val_if_fail (hbox != NULL, NULL); g_return_val_if_fail (book != NULL, NULL); /* Note: it is legal to have no owner or invoice */ isi = g_new0(GncISI, 1); if (!isi) return NULL; if (owner) { gncOwnerCopy(owner, &isi->owner); isi->have_owner = TRUE; } else { gncOwnerInitCustomer(&isi->owner, NULL); } isi->book = book; isi->label = label; edit = gnc_general_search_new (GNC_INVOICE_MODULE_NAME, _("Select..."), TRUE, gnc_invoice_select_search_cb, isi, isi->book); if (!edit) { g_free(isi); return NULL; } gnc_general_search_set_selected (GNC_GENERAL_SEARCH (edit), invoice); gtk_box_pack_start (GTK_BOX (hbox), edit, FALSE, FALSE, 0); g_object_set_data_full(G_OBJECT(edit), "isi-state", isi, g_free); /* Set the label */ gnc_invoice_select_search_set_label(isi); return edit; }
/* Function to set the UI Value for a particular option */ static gboolean customer_set_value (GNCOption *option, gboolean use_default, GtkWidget *widget, SCM value) { GncOwner owner; GncCustomer *customer; if (!SWIG_IsPointer (value)) scm_misc_error("business_options:customer_set_value", "SCM is not a wrapped pointer.", value); customer = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncCustomer"), 1, 0); gncOwnerInitCustomer (&owner, customer); widget = gnc_option_get_gtk_widget (option); gnc_owner_set_owner (widget, &owner); return FALSE; }
static void payment_customer_cb (gpointer *cust_p, gpointer user_data) { struct _customer_select_window *sw = user_data; GncOwner owner; GncCustomer *cust; g_return_if_fail (cust_p && user_data); cust = *cust_p; if (!cust) return; gncOwnerInitCustomer (&owner, cust); gnc_ui_payment_new (&owner, sw->book); return; }
static void invoice_customer_cb (gpointer *cust_p, gpointer user_data) { struct _customer_select_window *sw = user_data; GncOwner owner; GncCustomer *cust; g_return_if_fail (cust_p && user_data); cust = *cust_p; if (!cust) return; gncOwnerInitCustomer (&owner, cust); gnc_invoice_search (NULL, &owner, sw->book); return; }
GNCSearchWindow * gnc_job_search_select (gpointer start, gpointer book) { GncJob *j = start; GncOwner owner, *ownerp; if (!book) return NULL; if (j) { ownerp = gncJobGetOwner (j); gncOwnerCopy (ownerp, &owner); } else gncOwnerInitCustomer (&owner, NULL); /* XXX */ return gnc_job_search (start, &owner, book); }
PaymentWindow * gnc_ui_payment_new_with_invoice (const GncOwner *owner, QofBook *book, GncInvoice *invoice) { GncOwner owner_def; if (!book) return NULL; if (owner) { /* Figure out the company */ gncOwnerCopy (gncOwnerGetEndOwner (owner), &owner_def); } else { gncOwnerInitCustomer (&owner_def, NULL); } return new_payment_window (&owner_def, book, invoice); }
JobWindow * gnc_ui_job_new (GncOwner *ownerp, QofBook *bookp) { JobWindow *jw; GncOwner owner; /* Make sure required options exist */ if (!bookp) return NULL; if (ownerp) { g_return_val_if_fail ((gncOwnerGetType (ownerp) == GNC_OWNER_CUSTOMER) || (gncOwnerGetType (ownerp) == GNC_OWNER_VENDOR), NULL); gncOwnerCopy (ownerp, &owner); } else gncOwnerInitCustomer (&owner, NULL); /* XXX */ jw = gnc_job_new_window (bookp, &owner, NULL); return jw; }
/*********************************************************************** * @todo Maybe invoice checking should be done in gnc_bi_import_fix_bis (...) * rather than in here? But that is more concerned with ensuring the csv is consistent. * @param GtkListStore *store * @param guint *n_invoices_created * @param guint *n_invoices_updated * @return void ***********************************************************************/ void gnc_bi_import_create_bis (GtkListStore * store, QofBook * book, guint * n_invoices_created, guint * n_invoices_updated, gchar * type, gchar * open_mode, GString * info) { gboolean valid; GtkTreeIter iter; gchar *id, *date_opened, *owner_id, *billing_id, *notes; gchar *date, *desc, *action, *account, *quantity, *price, *disc_type, *disc_how, *discount, *taxable, *taxincluded, *tax_table; gchar *date_posted, *due_date, *account_posted, *memo_posted, *accumulatesplits; guint dummy; GncInvoice *invoice; GncEntry *entry; gint day, month, year; gnc_numeric value; GncOwner *owner; Account *acc; enum update {YES = GTK_RESPONSE_YES, NO = GTK_RESPONSE_NO} update; GtkWidget *dialog; Timespec today; InvoiceWindow *iw; gchar *new_id = NULL; gint64 denom = 0; gnc_commodity *currency; // these arguments are needed g_return_if_fail (store && book); // logic of this function only works for bills or invoices g_return_if_fail ((g_ascii_strcasecmp (type, "INVOICE") == 0) || (g_ascii_strcasecmp (type, "BILL") == 0)); // allow to call this function without statistics if (!n_invoices_created) n_invoices_created = &dummy; if (!n_invoices_updated) n_invoices_updated = &dummy; *n_invoices_created = 0; *n_invoices_updated = 0; invoice = NULL; update = NO; valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); while (valid) { // Walk through the list, reading each row gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, ID, &id, DATE_OPENED, &date_opened, DATE_POSTED, &date_posted, // if autoposting requested DUE_DATE, &due_date, // if autoposting requested ACCOUNT_POSTED, &account_posted, // if autoposting requested MEMO_POSTED, &memo_posted, // if autoposting requested ACCU_SPLITS, &accumulatesplits, // if autoposting requested OWNER_ID, &owner_id, BILLING_ID, &billing_id, NOTES, ¬es, DATE, &date, DESC, &desc, ACTION, &action, ACCOUNT, &account, QUANTITY, &quantity, PRICE, &price, DISC_TYPE, &disc_type, DISC_HOW, &disc_how, DISCOUNT, &discount, TAXABLE, &taxable, TAXINCLUDED, &taxincluded, TAX_TABLE, &tax_table, -1); // TODO: Assign a new invoice number if one is absent. BUT we don't want to assign a new invoice for every line!! // so we'd have to flag this up somehow or add an option in the import GUI. The former implies that we make // an assumption about what the importer (person) wants to do. It seems reasonable that a CSV file full of items with // If an invoice exists then we add to it in this current schema. // no predefined invoice number is a new invoice that's in need of a new number. // This was not designed to satisfy the need for repeat invoices however, so maybe we need a another method for this, after all // It should be easier to copy an invoice with a new ID than to go through all this malarky. if (g_ascii_strcasecmp (type, "BILL") == 0) invoice = gnc_search_bill_on_id (book, id); else if (g_ascii_strcasecmp (type, "INVOICE") == 0) invoice = gnc_search_invoice_on_id (book, id); DEBUG( "Existing %s ID: %s\n", type, gncInvoiceGetID(invoice)); // If the search is empty then there is no existing invoice so make a new one if (invoice == NULL) { DEBUG( "Creating a new : %s\n", type ); // new invoice invoice = gncInvoiceCreate (book); /* Protect against thrashing the DB and trying to write the invoice * record prematurely */ gncInvoiceBeginEdit (invoice); gncInvoiceSetID (invoice, id); owner = gncOwnerNew (); if (g_ascii_strcasecmp (type, "BILL") == 0) gncOwnerInitVendor (owner, gnc_search_vendor_on_id (book, owner_id)); else if (g_ascii_strcasecmp (type, "INVOICE") == 0) gncOwnerInitCustomer (owner, gnc_search_customer_on_id (book, owner_id)); gncInvoiceSetOwner (invoice, owner); gncInvoiceSetCurrency (invoice, gncOwnerGetCurrency (owner)); // Set the invoice currency based on the owner if (strlen (date_opened) != 0) // If a date is specified in CSV { // FIXME: Must check for the return value of qof_scan_date! qof_scan_date (date_opened, &day, &month, &year); gncInvoiceSetDateOpened (invoice, gnc_dmy2timespec (day, month, year)); } else // If no date in CSV { time64 now = gnc_time (NULL); Timespec now_timespec; timespecFromTime64 (&now_timespec, now); gncInvoiceSetDateOpened (invoice, now_timespec); } gncInvoiceSetBillingID (invoice, billing_id ? billing_id : ""); gncInvoiceSetNotes (invoice, notes ? notes : ""); gncInvoiceSetActive (invoice, TRUE); //if (g_ascii_strcasecmp(type,"INVOICE"))gncInvoiceSetBillTo( invoice, billto ); (*n_invoices_created)++; update = YES; // open new bill / invoice in a tab, if requested if (g_ascii_strcasecmp(open_mode, "ALL") == 0 || (g_ascii_strcasecmp(open_mode, "NOT_POSTED") == 0 && strlen(date_posted) == 0)) { iw = gnc_ui_invoice_edit (invoice); gnc_plugin_page_invoice_new (iw); } gncInvoiceCommitEdit (invoice); } // I want to warn the user that an existing billvoice exists, but not every // time. // An import can contain many lines usually referring to the same invoice. // NB: Posted invoices are NEVER updated. else // if invoice exists { if (gncInvoiceIsPosted (invoice)) // Is it already posted? { valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter); continue; // If already posted then never import } if (update != YES) // Pop up a dialog to ask if updates are the expected action { dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_YES_NO, "%s", _("Are you sure you have bills/invoices to update?")); update = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); if (update == NO) { // Cleanup and leave g_free (id); g_free (date_opened); g_free (owner_id); g_free (billing_id); g_free (notes); g_free (date); g_free (desc); g_free (action); g_free (account); g_free (quantity); g_free (price); g_free (disc_type); g_free (disc_how); g_free (discount); g_free (taxable); g_free (taxincluded); g_free (tax_table); g_free (date_posted); g_free (due_date); g_free (account_posted); g_free (memo_posted); g_free (accumulatesplits); return; } } (*n_invoices_updated)++; } // add entry to invoice/bill entry = gncEntryCreate (book); gncEntryBeginEdit(entry); currency = gncInvoiceGetCurrency(invoice); if (currency) denom = gnc_commodity_get_fraction(currency); // FIXME: Must check for the return value of qof_scan_date! qof_scan_date (date, &day, &month, &year); { GDate *date = g_date_new_dmy(day, month, year); gncEntrySetDateGDate (entry, date); g_date_free (date); } timespecFromTime64 (&today, gnc_time (NULL)); // set today to the current date gncEntrySetDateEntered (entry, today); gncEntrySetDescription (entry, desc); gncEntrySetAction (entry, action); value = gnc_numeric_zero(); gnc_exp_parser_parse (quantity, &value, NULL); gncEntrySetQuantity (entry, value); acc = gnc_account_lookup_for_register (gnc_get_current_root_account (), account); if (g_ascii_strcasecmp (type, "BILL") == 0) { gncEntrySetBillAccount (entry, acc); value = gnc_numeric_zero(); gnc_exp_parser_parse (price, &value, NULL); gncEntrySetBillPrice (entry, value); gncEntrySetBillTaxable (entry, text2bool (taxable)); gncEntrySetBillTaxIncluded (entry, text2bool (taxincluded)); gncEntrySetBillTaxTable (entry, gncTaxTableLookupByName (book, tax_table)); gncEntryCommitEdit(entry); gncBillAddEntry (invoice, entry); } else if (g_ascii_strcasecmp (type, "INVOICE") == 0) { gncEntrySetNotes (entry, notes); gncEntrySetInvAccount (entry, acc); value = gnc_numeric_zero(); gnc_exp_parser_parse (price, &value, NULL); gncEntrySetInvPrice (entry, value); gncEntrySetInvTaxable (entry, text2bool (taxable)); gncEntrySetInvTaxIncluded (entry, text2bool (taxincluded)); gncEntrySetInvTaxTable (entry, gncTaxTableLookupByName (book, tax_table)); value = gnc_numeric_zero(); gnc_exp_parser_parse (discount, &value, NULL); gncEntrySetInvDiscount (entry, value); gncEntrySetInvDiscountType (entry, text2disc_type (disc_type)); gncEntrySetInvDiscountHow (entry, text2disc_how (disc_how)); gncEntryCommitEdit(entry); gncInvoiceAddEntry (invoice, entry); } valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter); // handle auto posting of invoices if (valid) gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, ID, &new_id, -1); if (g_strcmp0 (id, new_id) != 0) { // the next invoice id is different => try to autopost this invoice if (qof_scan_date (date_posted, &day, &month, &year)) { // autopost this invoice gboolean auto_pay; Timespec d1, d2; if (g_ascii_strcasecmp (type, "INVOICE") == 0) auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_INVOICE, GNC_PREF_AUTO_PAY); else auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_BILL, GNC_PREF_AUTO_PAY); d1 = gnc_dmy2timespec (day, month, year); // FIXME: Must check for the return value of qof_scan_date! qof_scan_date (due_date, &day, &month, &year); // obtains the due date, or leaves it at date_posted d2 = gnc_dmy2timespec (day, month, year); acc = gnc_account_lookup_for_register (gnc_get_current_root_account (), account_posted); gncInvoicePostToAccount (invoice, acc, &d1, &d2, memo_posted, text2bool (accumulatesplits), auto_pay); } } } // cleanup g_free (new_id); g_free (id); g_free (date_opened); g_free (owner_id); g_free (billing_id); g_free (notes); g_free (date); g_free (desc); g_free (action); g_free (account); g_free (quantity); g_free (price); g_free (disc_type); g_free (disc_how); g_free (discount); g_free (taxable); g_free (taxincluded); g_free (tax_table); g_free (date_posted); g_free (due_date); g_free (account_posted); g_free (memo_posted); g_free (accumulatesplits); }
static void load_owner( const GncSqlBackend* be, GncSqlRow* row, QofSetterFunc setter, gpointer pObject, const GncSqlColumnTableEntry* table_row ) { const GValue* val; gchar* buf; GncOwnerType type; GncGUID guid; QofBook* book; GncOwner owner; GncGUID* pGuid = NULL; g_return_if_fail( be != NULL ); g_return_if_fail( row != NULL ); g_return_if_fail( pObject != NULL ); g_return_if_fail( table_row != NULL ); book = be->primary_book; buf = g_strdup_printf( "%s_type", table_row->col_name ); val = gnc_sql_row_get_value_at_col_name( row, buf ); type = (GncOwnerType)gnc_sql_get_integer_value( val ); g_free( buf ); buf = g_strdup_printf( "%s_guid", table_row->col_name ); val = gnc_sql_row_get_value_at_col_name( row, buf ); g_free( buf ); if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) { string_to_guid( g_value_get_string( val ), &guid ); pGuid = &guid; } switch ( type ) { case GNC_OWNER_CUSTOMER: { GncCustomer *cust = NULL; if ( pGuid != NULL ) { cust = gncCustomerLookup( book, pGuid ); if ( cust == NULL ) { cust = gncCustomerCreate( book ); gncCustomerSetGUID( cust, &guid ); } } gncOwnerInitCustomer( &owner, cust ); break; } case GNC_OWNER_JOB: { GncJob *job = NULL; if ( pGuid != NULL ) { job = gncJobLookup( book, pGuid ); if ( job == NULL ) { job = gncJobCreate( book ); gncJobSetGUID( job, &guid ); } } gncOwnerInitJob( &owner, job ); break; } case GNC_OWNER_VENDOR: { GncVendor *vendor = NULL; if ( pGuid != NULL ) { vendor = gncVendorLookup( book, pGuid ); if ( vendor == NULL ) { vendor = gncVendorCreate( book ); gncVendorSetGUID( vendor, &guid ); } } gncOwnerInitVendor( &owner, vendor ); break; } case GNC_OWNER_EMPLOYEE: { GncEmployee *employee = NULL; if ( pGuid != NULL ) { employee = gncEmployeeLookup( book, pGuid ); if ( employee == NULL ) { employee = gncEmployeeCreate( book ); gncEmployeeSetGUID( employee, &guid ); } } gncOwnerInitEmployee( &owner, employee ); break; } default: PWARN("Invalid owner type: %d\n", type ); } if ( table_row->gobj_param_name != NULL ) { g_object_set( pObject, table_row->gobj_param_name, &owner, NULL ); } else { (*setter)( pObject, &owner ); } }
static gboolean owner_id_handler (xmlNodePtr node, gpointer owner_pdata) { struct owner_pdata* pdata = static_cast<decltype (pdata)> (owner_pdata); GncGUID* guid; guid = dom_tree_to_guid (node); g_return_val_if_fail (guid, FALSE); switch (gncOwnerGetType (pdata->owner)) { case GNC_OWNER_CUSTOMER: { GncCustomer* cust = gncCustomerLookup (pdata->book, guid); if (!cust) { cust = gncCustomerCreate (pdata->book); gncCustomerSetGUID (cust, guid); } gncOwnerInitCustomer (pdata->owner, cust); break; } case GNC_OWNER_JOB: { GncJob* job = gncJobLookup (pdata->book, guid); if (!job) { job = gncJobCreate (pdata->book); gncJobSetGUID (job, guid); } gncOwnerInitJob (pdata->owner, job); break; } case GNC_OWNER_VENDOR: { GncVendor* vendor = gncVendorLookup (pdata->book, guid); if (!vendor) { vendor = gncVendorCreate (pdata->book); gncVendorSetGUID (vendor, guid); } gncOwnerInitVendor (pdata->owner, vendor); break; } case GNC_OWNER_EMPLOYEE: { GncEmployee* employee = gncEmployeeLookup (pdata->book, guid); if (!employee) { employee = gncEmployeeCreate (pdata->book); gncEmployeeSetGUID (employee, guid); } gncOwnerInitEmployee (pdata->owner, employee); break; } default: PWARN ("Invalid owner type: %d\n", gncOwnerGetType (pdata->owner)); g_free (guid); return FALSE; } g_free (guid); return TRUE; }
static void gnc_plugin_business_cmd_test_init_data (GtkAction *action, GncMainWindowActionData *data) { QofBook *book = gnc_get_current_book(); GncCustomer *customer = gncCustomerCreate(book); GncAddress *address = gncCustomerGetAddr(customer); GncInvoice *invoice = gncInvoiceCreate(book); GncOwner *owner = gncOwnerNew(); GncJob *job = gncJobCreate(book); Account *root = gnc_book_get_root_account(book); Account *inc_acct = xaccMallocAccount(book); Account *bank_acct = xaccMallocAccount(book); Account *tax_acct = xaccMallocAccount(book); Account *ar_acct = xaccMallocAccount(book); Timespec now; // Create Customer gncCustomerSetID(customer, "000001"); gncCustomerSetName(customer, "Test Customer"); gncCustomerSetCurrency(customer, gnc_default_currency()); gncAddressSetName(address, "Contact Person"); gncAddressSetAddr1(address, "20 Customer Lane"); gncAddressSetAddr2(address, "Customer M/S"); gncAddressSetAddr3(address, "Addr3, XXX 12345"); // Create the Owner gncOwnerInitCustomer(owner, customer); // Create the Invoice timespecFromTime64(&now, time(NULL)); gncInvoiceSetID(invoice, "000012"); gncInvoiceSetOwner(invoice, owner); gncInvoiceSetDateOpened(invoice, now); gncInvoiceSetCurrency(invoice, gnc_default_currency()); // Create the Job gncJobSetID(job, "000025"); gncJobSetName(job, "Test Job"); gncJobSetReference(job, "Customer's ref#"); gncJobSetOwner(job, owner); // MODIFY THE OWNER gncOwnerInitJob(owner, job); // Create the A/R account xaccAccountSetType(ar_acct, ACCT_TYPE_RECEIVABLE); xaccAccountSetName(ar_acct, "A/R"); xaccAccountSetCommodity(ar_acct, gnc_default_currency()); gnc_account_append_child(root, ar_acct); // Create the Income account xaccAccountSetType(inc_acct, ACCT_TYPE_INCOME); xaccAccountSetName(inc_acct, "Income"); xaccAccountSetCommodity(inc_acct, gnc_default_currency()); gnc_account_append_child(root, inc_acct); // Create the Bank account xaccAccountSetType(bank_acct, ACCT_TYPE_BANK); xaccAccountSetName(bank_acct, "Bank"); xaccAccountSetCommodity(bank_acct, gnc_default_currency()); gnc_account_append_child(root, bank_acct); // Create the Tax account xaccAccountSetType(tax_acct, ACCT_TYPE_LIABILITY); xaccAccountSetName(tax_acct, "Tax-Holding"); xaccAccountSetCommodity(tax_acct, gnc_default_currency()); gnc_account_append_child(root, tax_acct); // Launch the invoice editor gnc_ui_invoice_edit (GTK_WINDOW (data->window), invoice); }