What is meaning of field item_type_gl_account.direction in moqui? - moqui

When I query
select * from item_type_gl_account;
What is meaning of field item_type_gl_account.direction in moqui?
What is the meaning of O, I, E in item_type_gl_account.direction?
Please guide me the logic of value I, O, E in later accounting posting process logic steps.

The direction of the invoices.
I is for Purchase Invoices (Inward)
O is for Sales Invoices (Outward).
E is for either of the above.

Related

SQL Looking up prior record information

Here is my situation. I have a series of claims for a person. We occasionally get a duplicate claim which is given a DUP error code and and denied with zero dollar amount. What I am trying to do is look up the original claim units and billed amount. If the duplicate and the original claim are the same units and billed amount I intend to ignore it (or at least label it as NOT a potential re-bill). If the units and/or the billed amount are different, that claim will be labeled as a potential re-bill.
I've got a function that correctly finds the original claim primary key value and the base query runs in less than a second. However, when I try to link that dataset back to the tables it crushes my run time to the point of uselessness. What I don't understand is why does the function alone run so quickly but attempting to link it back bogs it down so much, we are talking about a dataset of 140ish claims over a year of activity.
If anyone could offer some insight or has a better way to accomplish this I would be obliged.
SELECT pre.*
--, st.unitsofservice as OrigUnits
--I only include the line above if the link to the servicetransaction table on the last line of the query is active
FROM
(
SELECT Sub.*--,
,dbo.cf_DuplicateServiceSTID(sub.servicetransactionid) as PaidSvc
--the line above is the function returning the primary key value for the original claim
FROM
(
SELECT Pre.servicetransactionID,
st.servicedate, st.individualid, st.agencyid, st.servicecode, st.placeofserviceid, st.unitsofservice,
dbo.sortmodifiers(st.modifiercodeid, st.modifiercodeid2, st.modifiercodeid3, st.modifiercodeid4) as Modifiers,
bd.billedamount,
a.upi,
b.name
FROM (select pmt.servicetransactionid
from pmtadjdetail pmt
where substring(pmt.reasoncodes,1,5) = 'DUP') Pre
JOIN servicetransaction st on pre.servicetransactionid = st.servicetransactionid
join billdetail bd on st.servicetransactionid = bd.servicetransactionid
join agency a on st.agencyid = a.agencyid
join business b on a.businessid = b.businessid
where st.servicedate between #StartDate and #EndDate
and st.agencyid = iif(#AgencyID is null, st.agencyid, #AgencyID)
) Sub
join individual i on sub.individualid = i.individualid
join enrollment e on sub.individualid = e.individualid
WHERE e.enrollmenttype <> 'p'
) Pre
--join servicetransaction st on pre.paidsvc = st.servicetransactionid
--If I remove the comment from the line above my run time increases to the point of uselessness

SQL Help. 2 tables joined, need information from 2 columns from one table.

I would like to extract information from 2 tables (joined).
SELECT B.INVOICE_NUMBER,
B.BILL_TO_NAME,
B.SHIP_TO_NAME //Need this some how joined, see comment on code below
FROM ADJUSTMENTS A,
INVOICE B,
CUSTOMER_LOCATION C,
CUSTOMER_NAME D
WHERE A.INVOICE_ID = B.INVOICE_ID
AND C.CUSTOMER_ID = D.CUSTOMER_ID
AND B.BILL_ID = C.ACCOUNT_NUMBER
//I want to add B.SHIP_ID = C.ACCOUNT_NUMBER as well,
//but I am unsure if it will work. Not sure how to extract information from
//two columns from the same table that is joined to one table.
I researched into sub-query, but that was returning to many rows so it errored out. I am a beginner to Oracle SQL, I've tried researching but not getting the solution. Any help is appreciated.
I can't tell 100% what you are wanting, but if b.bill_id and b.ship_id have 2 different account_number's and there is only one customer_location for each account_number, then you can probably add customer_location a second time with a different alias. If you need the customer_name record for the second customer_location then you will have to join that a second time as well. Perhaps:
SELECT b.invoice_number, b.bill_to_name, b.ship_to_name
FROM adjustments a, invoice b, customer_location c,
customer_location c2, customer_name d, customer_name d2
WHERE a.invoice_id = b.invoice_id
AND c.customer_id = d.customer_id
AND c2.customer_id = d2.customer_id
AND b.bill_id = c.account_number
AND b.ship_id = c2.account_number
Now your question is vague so it is hard to tell if this is what you are looking for. Watch for multiple rows per invoice invoice number if there is more than one customer_location record per account_number, and problem solve from there if needed. I hope this gets you closer to what you are looking for.

Counting values for multiple distinct rows in a SQL Query

I'm very new to SQL so please pardon my lack of knowledge. I'm also doing this for a class so please don't just give me the answer, I'd like to learn.
I have 3 tables of which are Contracts, PaymentTypes, InsuranceCompanies. I'm trying to join them and then display the number of contracts whose payment method is insurance, broken out by Insurance Company. I have done so, but it is not counting the amount of contracts per insurance company. It is instead counting how many InsuranceID's that are using Insurance and placing that into each Insurance Company count. Here is what I have for the SQL Query:
Select Distinct InsuranceCompanies.InsuranceCompany, Count (Contracts.InsuranceID) as 'Number of contracts'
from Contracts, PaymentTypes, InsuranceCompanies
where (Contracts.PaymentTypeID = 3) AND (PaymentTypes.PaymentTypeID = 3) AND (Contracts.PaymentTypeID = PaymentTypes.PaymentTypeID)
Group by InsuranceCompanies.InsuranceCompany
Here is what it outputs:
All Insurance 273
Best Insurance 273
Friendly Insurance 273
Insurance One 273
Safety Insurance 273
So my question is how can I have it count individual Insurance Companies then display it accordingly?
I took the answer given to me, applied all variables needed, and it functions perfectly! Here is the final working Query:
Select i.InsuranceCompany, Count(c.InsuranceID) as 'Number of contracts'
from Contracts c
join paymenttypes p on p.PaymentTypeID = c.PaymentTypeID
join insurancecompanies i on i.InsuranceID = c.InsuranceID
where c.PaymentTypeID = 3 AND p.PaymentTypeID = 3
Group by i.InsuranceCompany
Your query should look something like this, but as I'm missing parts of your structure I cannot fill in the part after on
Select i.InsuranceCompany, Count(c.InsuranceID) as 'Number of contracts'
from Contracts c
join paymenttypes p on p.PaymentTypeID = c.PaymentTypeID
join insurancecompanies i on i.InsuranceID = c.InsuranceID
where c.PaymentTypeID = 3 AND p.PaymentTypeID = 3
Group by i.InsuranceCompany
so read about table join

SQL Query Unique Equipment List

Thanks in advance for having a look. I have no idea on how to search for this.
Picture 2 test stations, each with a rack of equipment that must be kept calibrated. The equipment is identified by stationId, eqPartno, and eqLocation. Location instead of serial number so it is unit replaceable.
From 2 tables:
station_events (eventId is auto, recUpdated is auto)
"stationEventId","stationId","stationEvent","recUpdated"
1,"1","databaseCreation",2014-05-14 07:51:25 AM
2,"55","databaseCreation",2014-05-14 07:51:25 AM
3,"1","updateCal",2014-05-14 08:11:26 AM
4,"1","updateCal",2014-05-14 08:11:59 AM
5,"1","updateCal",2014-05-14 08:48:26 AM
equipment (equipmentId is auto, recUpdated is auto, linked by equipmentId)
"equipmentId","stationEventId","eqPartNo","eqLocation","eqCalExpires","eqRecUpdated"
1,1,"eq1","loc1",2000-01-31,2014-05-14 07:53:59 AM
2,1,"eq2","loc2",2000-02-22,2014-05-14 08:05:52 AM
3,3,"eq1","loc1",2014-04-04,2014-05-14 08:13:37 AM
4,4,"eq2","loc2",2014-04-05,2014-05-14 08:14:25 AM
5,5,"eq1","loc1",2014-04-05,2014-05-14 08:47:04 AM
The query is to form a view of station 1 equipment consisting of the latest record for each of the installed units to verify cal.
select e.* from equipment e
inner join station_events se on se.stationEventId=e.stationEventId
where se.stationId='1'
group by eqPartNo,eqLocation
The results look good.
"equipmentId","stationEventId","eqPartNo","eqLocation","eqCalExpires","eqRecUpdated"
5,5,"eq1","loc1",2014-04-05,2014-05-14 08:47:04 AM
4,4,"eq2","loc2",2014-04-05,2014-05-14 08:14:25 AM
Have I just created a lucky hack, or is this correct? I like this because we have calibration history as long as the view is guaranteed to describe all the latest equipment records.
Best Regards,
Jim Shedden
This is lucky one. You may insert an aggregate such MAX into your query
select e.equipmentId,
e.stationEventId,
e.eqPartNo,
e.eqLocation,
e.eqCalExpires,
MAX(e.eqRecUpdated) from equipment e
inner join station_events se on se.stationEventId=e.stationEventId
where se.stationId='1'
group by eqPartNo,eqLocation

Calculating Dates

I have this problem: List of customers with their next scheduled, reoccurring appointment, that is either yearly, monthly, or quarterly.
The tables\columns I have are:
customer
customer_ID
service
customer_ID
service_RecID
Resource
service_RecID
Recurrence_RecID
Date_Time_Start
Recurrence
Recurrence_RecID
RecurType
RecurInterval
DaysOfWeek
AbsDayNbr
SelectInterval
It is modeled such that when the schedule is setup, the date_start_time is the date of when the first reoccurring appointment took place. Ex.
Recurrence_RecID = 10
RecurType = m (could be y, or d as well for yearly or daily)
RecurInterval = 6 (if recurType = y, this would mean every 6 years)
Given that the system generates these nightly, how would I write a query to calculate the next scheduled appointment, for each customer? I originally thought of using the Resource.Date_Time_Start and just cycling through until a variable nextAppointment >= today(), but is it good practice to run loops in SQL?
If anymore info is needed, let me know. Thank you much!
Edit: I will make a sqlfiddle.
I would suggest using a sub-query as opposed to looping. More efficient that way. This may not be exact but something like...
SELECT
*
FROM
(
SELECT
customer.customer_id,
service.service_RecID,
Resource.Date_Time_Start,
Recurrence.Recurrence_RecID,
RecurType,
RecurInterval,
DaysOfWeek,
AbsDayNbr,
SelectInterval,
NextAppointmentDate=
CASE
WHEN RecurType='m' THEN DATEADD(MONTH,RecurInterval,Resource.Date_Time_Start)
WHEN RecurType='y' THEN DATEADD(YEAR,RecurInterval,Resource.Date_Time_Start)
ELSE
NULL
END
FROM
Recurrence
INNER JOIN Resource ON Resource.Recurrence_RecID=Recurrence.Recurrence_RecID
INNER JOIN service ON service.service_RecID=Resource.service_RecID
INNER JOIN customer ON customer.customer_ID=service.customerID
)AS X
WHERE
NextAppointmentDate>=GETDATE()
ORDER BY Fields...