Account Balance For Invoice Purposes Access 2010 - expression

I have created a new transactions table (tblTransactions) where I can log all my [Debits] (i.e. invoices) and [Credits] (i.e.payments). From this I can run a query with an an expression to get the Current Account Balance.
However, for invoicing purposes, if I pulled the Current Account Balance as described above, it wouldn't be the 'previous account balance' value I want to display to the customer on the invoice, because it's showing a value which includes the current invoice amount. I want the customer to see the previous balance PRIOR TO that invoice.
My current solution uses expressions in a query to calculate this 'previous account balance', but I don't know if could be done another way. Any suggestions on how this could be done better?
I couldn't post a picture of the query b/c I don't have enough reputation points.
Invoice fields I'm trying to populate:
Invoice Amount
Previous Account Balance (prior to this invoice)
Final Invoice Amount
Below are my calculations used in the query
Invoice Amount: Debit
Previous Account Balance: Format([Account Credits]-[Account Debits],"Currency")
Final Invoice Amount: Format([Invoice Amount]-[Previous Account Balance],"Currency")
Account Debits: Format(DSum("[Debit]","tblTransactions","ClientID =" & [ClientID])-[Debit],"Currency")
*This formula takes out the value of the current debit in the query
Account Credits: Format(DSum("[Credit]","tblTransactions","ClientID =" & [ClientID]),"Currency")

A solution "quick and dirty" is to find add a condition to your query excluding the record on which you are working (current invoice).
If you have an ID, you can add a WHERE condition to your DSUM, excluding the current record.
Let's assume IDTransact is ID field of tblTransactions, your WHERE condition should be
"ClientID =" & [ClientID] & "AND IDTransact <> " & CStr([IDTransact])
I assumed the ID is a long (autonumbering).
Hope this can help you.
Let me know.
Bye

Related

How to add filter on item collection to get the Sales rep(total Quantity and Total no of Orders) of those Sale Managers which are logged in

$collection = $this->_itemCollectionFactory->create()->getCollection();
$collection->getSelect()->columns(array('total_orders' => new \Zend_Db_Expr('COUNT(order_id)')))
->columns(array('total_qty' => new \Zend_Db_Expr('ROUND(SUM(qty_ordered))')))
->group('sku');
$collection->getSelect()->limit(3);
$collection->addFieldToFilter('store_id', 2);
Through this code i can get the total quantity and total number of orders of all sales rep. But i need only those total quantity and total orders which were done by the Sales Rep og Logged in Sale Manager.
As you mentioned in your question you only want to get the order info based on a certain sales rep. To do that you need to somehow find a unique identify for the currently logged in sales rep and add a filter for that .
For example:
$collection = $this->_itemCollectionFactory->create()->getCollection();
$collection->getSelect()->columns(array('total_orders' => new \Zend_Db_Expr('COUNT(order_id)')))
->columns(array('total_qty' => new \Zend_Db_Expr('ROUND(SUM(qty_ordered))')))
->group('sku');
$collection->getSelect()->limit(3);
$collection->addFieldToFilter('store_id', 2);
$collection->addFieldToFilter('sales_rep_identifier', $loggedInSalesRepIdentifier);
The label sales_rep_identifier and the value $loggedInSalesRepIdentifier are just examples, you may have to adjust the format in which the data is stored if it doesn't currently have a field to check natively what sales rep did it, and adjust the values there accordingly
If you're using some kind of prebuilt system then maybe there are other labels for the identifier you could use, without more information on the specific database structure it's impossible to answer exactly, but essentially you need to filter by the unique sales rep identifier, and if that doesn't exist now in the database it should somehow but added

By usecases 1.create customer 2.update(kyc) 3.Deposit 4 Fund transfer using 3 microservices Api validation

USE case :
Create customer
create a table with name customers having following columns : Id(Numeric), customer_id(varchar), customer_name(varchar), customer_mobileNo(Numeric), EmailId(Varchar) Account_Id(varchar), Amount(Numeric), address(varchar), is_KYC_DONE(Boolean), active(Boolean)
Make a post rest end point to insert data into the customer table and register 2 customers with default amount like 0.
API Validation be like customer_id, customer_name, account_id should be mandatory, Mobile number should be numeric, Email should be in right format, is_KYC_DONE and active should have default value of 0 and 1
Update KYC to true
Make a patch rest point to update kyc in table to true on basis of customer id.
Deposit
Make a post rest end point to deposit amount in above created table based on account id
Deposit should happen when kyc is done i.e true otherwise tranaction will be declined
Fund transfer
Make a post rest point to do amount transfer from one account to another.
payload should be like this :
transfer {
“Amount” :
withdraw {
“Account_id” : “”
},
Deposit {
“Account_id” : “”
}
}
Validation be like
Sufficent funds should be dere
for both withdraw and deposit accountId and amount should be mandatory.
if deposit fails then amount withdrawn from account should be rollbacked.
NOTE : Mke sure atmost once and at least once the transaction should happen.
There will 3 microservices
customer : will have create customer and update kyc end points
Deposit : will have deposit end point
fundtransfer : will have fundtransfer endpoint, withdraw happens from this microservice and for deposit call should go to deposit miroservice.
I am in the process of learning about microservices and there's one thing that I can't seem to figure out and I can't find any resources that give me a direct answer to this. The question is: Do microservices involve only business logic and

Fetch first charge of a customer in stripe

I am reading stripe documentation and I want to fetch the first charge of the a customer. Currently I am doing
charge_list = Stripe::Charge.list(
{
customer: "cus_xxx"
},
"sk_test_xxxxxx"
)
first_charge = charge_list.data.last
Since stripe api returns the charges list in sorted order with the most recent charges appearing first. But I don't think it is a good approach. Can anyone help me with how can I fetch the first charge by a customer or how can I sort the list with descending order of created date so that I could get the first object from the array.
It seems there is no reverse order sorting feature in stripe API.
Also remember the first charge may not be on the first page result set, so you have to iterate using #auto_paging_each.
A quick possible solution:
charge_list = Stripe::Charge.list(
{customer: "cus_xxx", limit: 100 }, # limit 100 to reduce request
"sk_test_xxxxxx")
first_charge = nil
charge_list.auto_paging_each {|c| first_charge = c }
You may want to persist the result somewhere since it is a heavy operation.
But the cleanest solution IMO would be to store all charge records into your DB and make subsequent queries against it.

Complicated Cube Query

I'm working on a fairly complicated view, which calculates the total cost of a guest's stayed based on data pulled from four different tables. The output however is not exactly what I want. My code is
CREATE OR REPLACE VIEW Price AS
SELECT UNIQUE
Booking.Booking_ID AS "Booking",
Booking.GuestID AS "Guest ID",
Room.Room_Price*(Booking.CheckOutDate-Booking.CheckInDate) AS "Room Price",
Add_Ons.Price AS "Add ons Price",
Room.Room_Price*(Booking.CheckOutDate-Booking.CheckInDate) + (Add_Ons.Price) AS "Total Price"
FROM Booking JOIN Room ON Room.Room_Num = Booking.Room_Num
JOIN Booking_Add_Ons ON Booking.Booking_ID = Booking_Add_Ons.Booking_ID
JOIN Add_ons ON Booking_Add_Ons.Add_On_ID = Add_Ons.Add_On_ID
ORDER BY Booking.Booking_ID;
Now, I'm trying to get this to return the total cost of all Addons, plus the cost of the hotel rooms as the total price, however it is returning the cost of the rooms + each of the addons on separate lines. As follows:
My question is, is it possible to use something like CUBE, or SUM to add up the rows, so that there is only one entry for each of the Bookings with the total price of all add-ons accounted for?

Selecting items that are not in another table or are not within a given date range

I'm working on a program that keeps a list of physical advertisement spots and their reservations (a date range). The program needs to be able to find "open spots" for ads within an ad category.
I have three tables: AdTypes, AdPlaces and Reservations. Currently, I'm implementing a query that searches for reservations where the dates don't collide with the date range the user selected, and returns the AdType items as a list. This method works if every AdType has had an reservation at some point, but it doesn't list AdTypes that are not found in the Reservations table.
The filtering is done in PreProcessQuery of an AdTypes query, as such:
query = query.Where(r => r.Reservations.Any(res => (res.Begindate > Begindate && Enddate < res.Enddate) || (res.Enddate < Begindate && Enddate > res.Begindate)));
How can I "extend" the query so that all those AdTypes that have no reservations would be listed alongside "expired" AdType reservations?
Maybe I'm mssing something, or not quite understanding what you want, but how can you expect see AdTypes that don't exist?
Is it that you want to see the AdTypes that don't have any reservations during the period you're testing for?
If so, I imagine you'd have to use the adType entity as the basis of your screen, not the Reservation entity (with a query based on AdType, not Reservation). That way you can produce a list of AdTypes that don't have any overlapping reservations.
Does that make any sense?

Resources