bill.com creating Invoice questions on tax & itemId - invoice

Writing an interface to bill.com for Invoice using Invoice.json (have some existing code for Payments -- Bill.json) that works. interface is here https://developer.bill.com/hc/en-us/articles/208196656-Invoice
When adding itemId to show "our" internal id - I get an error
-- the example shows -- "itemId" : "0ii01YCDSBIDTPTJbhcb",
-- the doc says -- Id of the item being billed on the invoice line item.
Now sure what I need to create here to get this to work and show "our" internal id
We have a tax total that we already calculated - is there any way that we can just add that tax total to show in the invoice? It seems more complicated than that.
Thanks

Found the answer with helped by folks at bill.com - Thank you!!!
Basically you need to create a bill.com "Item" object. https://developer.bill.com/hc/en-us/articles/208196666
To have your ow "Order Num" in the order field line item, create a new "Item" object and make the "description" field = to your order num. Use the return ID from the creation and assign it to invoiceLineItems.itemId (in the example "itemId" : "0ii01YCDSBIDTPTJbhcb",)
Tax object is also an "Item" object - created with the same interface above. Set the type = 6 (for sales Tax) and perform similar to above the create the item object. Use that returning ID and assign it to Invoice.itemSalesTax. This is the sales tax used for all the items in your invoiceLineItems area. Set taxable to true for those line items you want to be tax caclculated
The sales tax "Item" object creation will look like the following:
{
"entity" : "Item",
"name" : "My Tax",
"type" : "6",
"description" : "CA State",
"percentage" : 8,
}
Hope this helps someone else

Related

How to create and save data on the go in Grails?

I have 2 domain classes
Expenditure
class Expenditure {
Date date
Supplier supplier
String particular
BigDecimal amount
}
Supplier
class Supplier {
String name
String address
static hasMany = [expenditures: Expenditure]
}
What happening is that when I create a new expenditure, I will enter the supplier from the list of suppliers in the Supplier class. When the supplier is not exist, I will have to create it first and then select it when creating the expenditure.
What I want is that, when I enter the supplier it will be looked up, and when not found, it will be created on the go (when saving the expenditure instance) without me having to create it first in the Supplier table and then come back to Expenditure to complete the form.
How can I achieve this?
What I want is that, when I enter the supplier it will be looked up,
and when not found, it will be created on the go
One option you have is to do something like one of these...
Supplier.findOrCreateByName('some name goes here')
Supplier.findOrCreateByNameAndAddress('some name goes here', 'some address goes here')
There are also findOrSaveBy... counterparts but those only work if you are supplying enough search criteria to create a fully save-able instance.
I hope that helps.

Ruby: Insert record on both parent and children with id is set manually

My database has a Product table with many ProductDetail. By some reason, I want to insert some product (each product with list of product details) with id setting manually.
Here is my code:
::Product.create({
id: attributes['product_id'],
product_details_attributes: attributes['product_details']
})
If I insert without insert product detail, everything works fine. My product record with have id manually. But when I insert product with product detail (id of product detail also manually), I meet some exception such as:
Cannot find product detail with id = 100 in product id = 10
It looks like ActiveRecord with search inside product with id = 10, and try to update all children for example with id = 100. (But it doesn't exist yet) so I meet that exception.
My question is: How can I insert both father and children table with id setting manually.
thanks

Grails: display linked table value in list.gsp instead of id

Let me preface this ask by indicating that this only applies to /list/ view and NOT other views. This is NOT about drop-down menus
I have two tables:
[Authors]
- id
- name
[Books]
- id
- title
- author
In the Books form (create/edit) I can get the "author" field to display an author's name (from Author table instead of id) without an issue, however, when I view the /list/ view, it displays the author's id instead of the name (correctly, since this is what's stored in the DB).
I have not been able to find a method to convert "id" to "name" in the /list/ view elsewhere and I haven't used grails in almost a year (yay rust). Thanks in advance for guidance.
Try this:
class Author {
String name
static mapping = {
id name: 'name'
}
}
If you're using static scaffolding, don't forget to regenerate the views for the Author and Book domain classes:
grails> generate-views com.yourPackage.Author
grails> generate-views com.yourPackage.Book

Insert new object with realtion to new objects with identity column

Customer class:
class Customer
{
int id;
int phone;
int fax;
PhoneNumber phone1;
PhoneNumber fax1;
}
Class PhoneNumber
{
int id;
int prefixid;
string number;
}
The PhoneNumber was auto-Generated by EF4, I've change the auto-generated names to phone1 and fax1
Both phonenumber id and customer id are identity columns in the DB.
Now I want to create a new Customer:
var newCustomer = Customer.CreateCustomer(0, CompanyID);
PhoneNumber fax = new PhoneNumber();
PhoneNumber phone = new PhoneNumber();
fax.Customers.Add(newCustomer);
phone.Customers.Add(newCustomer);
context.Customers.AddObject(newCustomer);
context.SaveChanges();
But now I get:
System.Data.UpdateException: {"Cannot
insert explicit value for identity
column in table 'PhoneNumber' when
IDENTITY_INSERT is set to OFF."}
Why isn't EF4 deal with the identity column of the related table as it should deal with a new entity ? How can I make this work ?
(EF4 Should've create 2 entiries in Phones table, get their identity and add it to the customer row of the new customer - at least that what I want to do)
I know I Can create 2 Phone records, and than create the customer one, but
a. I want it to be done in one act.
b. if cusotmer creation fails - I don't want empty records on the phones table...
Well these two things contradict each other:
Both phonenumber id and customer id are identity columns in the DB.
But then the error:
System.Data.UpdateException: {"Cannot insert explicit value for identity column in table 'PhoneNumber' when IDENTITY_INSERT is set to OFF."}
It may seem like this error is saying a duplicate identity is being set, but it's not - it's saying your trying to explicitly set the identity field.
What that is saying is that the ID column in PhoneNumber is not an identity field. Or at least EF does not think it is.
So i have four questions:
1) Have you confirmed the field is set to IDENTITY in the EDMX? Maybe something has overriden it?
2) What does the CreateCustomer method do? Does it just new up a Customer and set some properties? It should not touch the identity fields.
3) Have you setup the navigational properties/cardinalities properly on the EDMX? E.g 1 Customer .. 1-* Phone Numbers.
4) Try adding the Phone number to the Customer, not the other way around. It makes sense to add the "many" to the "one" - e.g Customer is the aggregate here:
var newCustomer = Customer.CreateCustomer(0, CompanyID);
newCustomer.phone1 = new PhoneNumber();
newCustomer.fax1 = new PhoneNumber();
context.Customers.AddObject(newCustomer);
context.SaveChanges();
I'd also suggest redesigning your model.
It's silly to have Customer with 1 Fax and 1 Phone Number, each with a property on there. It should be a Customer have many "PhoneNumber" entities.
You could use TPH on the PhoneNumber entity to discriminate between Fax and other types, and the above code would make much more sense:
var newCustomer = Customer.CreateCustomer(0, CompanyID);
newCustomer.Phones.Add(new FaxNumber());
newCustomer.Phones.Add(new MobileNumber());
context.SaveChanges();

drop down list in MVC

I am absolutely new to the MVC application.I want a dropdown list on my form I have done it this way
"<%= Html.DropDownList("Categories", (IEnumerable<SelectListItem>)ViewData["Categories"])%>"
I am sending the viewdata[Categories] from the controller class file.
this way
IList allCategories = _dropdownProvider.GetAllCategories();
ViewData["Categories"] = new SelectList(allCategories, "catid", "catname");
Now my requirement is that when the user selects a particular category from the dropdownlist its id should get inserted in the database,
The main problem is category id I want to insert the category id in the product table where the category Id is the foreign Key.
Please tell me how can I do this.
Normally you would do the following:-
On your view you would have...
Inherits="System.Web.Mvc.ViewPage<Product>" THIS IS A REFERENCE TO YOUR PRODUCT ENTITY
and in the page you can do this...
Category <%=Html.DropDownList("CatId") %>
you would also have the GET controller which defines the list
public ActionResult Add()
{
ViewData["CatId"] = new SelectList(allCategories, "catid", "catname");
then you can get the CatId from the product passed in to the Add method
e.g.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Add(Product product)
{
int catId = product.CatId
HTH. You ought to buy a book on the subject as MVC takes away alot of the pain of binding from you.
when you try to post the view, you'll have a "Categories" key in your querystring. you could convert it to long or the type you use in your table and set it to the product instance that you want to.
if this is not so clear, please send your code for a better explanation.
If i Understand right your question, the only thing you have to do, is inspect the POST for the "Categories" Key, and it will contain the selected value of the DropDownList.
var selectValue = System.Convert.ToInt16(Request.Form["name"]);
Or if you use ModelBinder and define a model that bind that value directly, you just have to Update the Model with
bool x = TryUpdateModel(YourModelNameHere);
This will automatically inspect the current ControllerĀ“s Value Provider and bind that value to the corresponding property in your model.
I recoment you to use the parameter FormCollection in your controller, and put a breakpoint, you can see all the values send within the POST. All that values are accessible through Request.Form["KEY"].

Resources