In chart account table
glaccount nametext
1204005 BAH - Khay
2202013 Sales Tax Payable New
2019384 Generator
1848485 Vechicle
and in other table
this glaccount is in account table and this glaccount is unique values
acdocno glaccount docamount glnametxt
0600000307 1204005 363538 BAH - Khay
0600000307 2202013 56003 Sales Tax Payable New
0600000307 1201001 456023 Accounts Receivable
0600000307 1201001 456023 Accounts Receivable
0600000307 1206004 36482 Adv Income Tax -
except 1204005 all glacct is fixed only 1204005 is change when acdocno change
so how i get this glaccount amount i.e. 363538 in crystal report.. when i only drag field docamout then 456023 is displayed and i want this value 363538
current data in report
Acdocno Total Amount Bank Amount Bank Name
0600000307 456,023.00 456,023.00 Accounts Receivable
and i want
Acdocno Total Amount Bank Amount Bank Name
0600000307 456,023.00 363538 BAH - Khay
query which i tried
select distinct
acdocdtl.acdocno,
acdocdtl.docamount,glchaact.glnamestxt
from acdocdtl
inner join acdochdr
on
acdocdtl.acdocno =acdochdr.acdocno
and acdocdtl.cocode=acdochdr.cocode
left join glchaact
on acdocdtl.glacct = glchaact.glacct
and acdocdtl.chaact=glchaact.chaact
where acdocdtl.acdocno='0600000307'
how i done this
Related
Each department is supposed to have only one statement per monthly billing cycle.
My goal is to figure out how many departments have been hit with more than one billing statement (having a value greater than $0.00) within the same billing cycle.
CONTEXT:
My current query is set to check only departments that are supposed to be billed monthly.
Department table has a one-to-many relationship with Statement table (a department is expected to have one or more statements)
Statement table has a one-to-many relationship with Trans table (a statement is expected to have one or more transactions)
Each billing statement has its own statement_close_date
c.type=‘periodic’ refers to a bill that only occurs once per billing cycle
d.period=1 represents accounts that are billed monthly
s.status=‘closed’ represents only closed statements
d.exp_date represents billing expiration date
v.status=‘active’ and d.status=‘active’ are meant to ensure that only active departments are being queried.
I also tried searching between specific expire dates on a per account basis.
The problem with my query is that it outputs the total number of billing statement_close_dates with a value greater than $0.00, instead of only checking for multiple occurrences within a billing cycle.
How can this query be modified to only output departments with more than one instance of a bill consisting of a periodic type charge greater than $0.00 within each department’s billing cycle?
QUERY:
SELECT s.department_id, s.statement_id, COUNT(s.statement_close_date) AS sd,
t.trans_id, from_unixtime(s.statement_close_date)
FROM statement s
INNER JOIN trans t
ON t.statement_id=s.statement_id
INNER JOIN cde c
ON t.cde=c.cde
INNER JOIN department d
ON s.department_id=d.department_id
WHERE from_unixtime(s.statement_close_date) BETWEEN
DATE_SUB(from_unixtime(d.exp_date), INTERVAL 1 MONTH) AND
from_unixtime(d.exp_date)
AND d.period=‘1’
AND s.status='closed'
AND t.dollars>0
AND c.type='periodic'
GROUP BY s.statement_id DESC
HAVING sd>1
SAMPLE OUTPUT:
department_id statement_id sd trans_id statement_close_date
1719712 9351464 3 98403043 2018-09-24
1719709 9351463 2 98403026 2018-09-24
1719708 9351462 2 98403010 2018-09-24
1719665 9351457 3 97374764 2018-09-24
I have the tables invoice_header, invoice_rows and vat_codes from the billing software based on a MySQL database. I need to add my own table invoice_vat.
For each new invoice (or updated invoice) I need to store (or update) VAT rates, net amounts and VAT amounts into the table invoice_vat, groupped by the vat code.
I have several vate codes and rates. For example I have:
ABC tax rate 5%
DEF tax rate 10%
GHI tax rate 22% etc.
For each invoice I can sell together some products with ABC vat, some products with DEF vat and some other products with GHI vat. Usually we do not use more than 5 different vat rates in one invoice.
For example one of my invoice looks like:
product1, quantity 2pcs, unit_net_price 100.00, row_net_amount 200.00, vat ABC.
product2, quantity 3pcs, unit_net_price 50.00, row_net_amount 150.00, vat ABC.
product3, quantity 1pcs, unit_net_price 90.00, row_net_amount 90.00, vat DEF.
product4, quantity 4pcs, unit_net_price 25.00, row_net_amount 100.00, vat GHI.
For this invoice I need to store the values into the tables invoice_vat:
vat1_code ABC, vat1_rate 5, vat1_net_total_amount 350.00
vat2_code DEF, vat2_rate 10, vat2_net_total_amount 90.00
vat3_code GHI, vat3_rate 22, vat3_net_total_amount 100.00
vat4_code NIL, vat4_rate 0, vat4_net_total_amount 0.00
vat5_code NIL, vat5_rate 0, vat5_net_total_amount 0.00
I can do the following query:
SELECT invoice_rows.vat, sum(invoice_rows.row_net_amount) AS mysum
WHERE invoice_rows.id=655
group by invoice_rows.vat;
Now I need to store the values I get from the query, every time I make a new invoice or I revise/update an old invoice.
Should I use a trigger? How should look the trigger?
Giuseppe
Have table(s) that itemize the components of an invoice. Have another table that shows the invoice amounts as sent to the customer. For accounting and business and maybe legal reasons, this table should be "write once". That is, you should never change it, once it is finalized. At this point you are recording what you sent to the customer; it is not some scratch pad where things can be added/changed/deleted.
Note, in particular, if a item's price changes, or a VAT amount changes, then new computations would lead to an invoice that disagrees with what you sent the customer. Not good.
I have two tables, [Party] and [Invoice], in an Access database. I want to summarize all party balances. Here is my query so far:
select
Party.AccountCode,
Party.AccountDescription,
OpeningBalance+sum(invoiceAmount) as balance,
invoiceDate
from Party,Inovoice
where party.accountCode=Inovice.AccountCode
and invoiceDate>=01-01-2013
and invoiceDate<=30-06-2013
group by
Party.AccountCode,
Party.AccountDescription,
invoiceDate
This query returns the balance for only the two parties that appear in the [Invoice] table: TOM and JHONS. I want to display the balance for all 4 parties:
Use two queries. The first to calculate the total invoice amount and the second for the party balances
qrySumInvoiceAmounts:
SELECT
AccountCode
sum(invoiceAmount) as InvoiceBalance,
FROM Invoice
group by
AccountCode,
WHERE invoiceDate>= #01-01-2013#
and invoiceDate<= #30-06-2013#
qryPartyBalance:
SELECT
Party.AccountCode,
Party.AccountDescription,
OpeningBalance + InvoiceBalance,
from Party LEFT JOIN qrySumInvoiceAmounts
ON party.accountCode=qrySumInvoiceAmounts.AccountCode
I have the following db schema (i'm only mentioning the columns for each table necessary for the query in mind):
bills
-------
id
amount (decimal)
collection_case_id
collection_case
------------------
id
payments
----------
id
bill_id
amount (decimal)
type (char(2)) - "CH" stands for check payment, field used for polymorphism
check_payments
---------------
payment_id
For a set of collection cases, I need to get the total interest earned from check payments.
I am currently doing these calculations in memory after retrieving all the bill records for my set of collection case criteria. For each bill I simply add the sum of checks received - bill amount if sum of checks received is greater than bill amount.
for instance my total received query looks like this (collection cases 1 & 2):
select sum(payment.amount) as received
from bills bill
cross join payments payment inner join check_payments checkpayment
on
payment.id=checkpayment.payment_id
where payment.type='CH'
and payment.bill_id=bill.id
and (bill.collection_case_id in (1 , 2))
Not really sure if this is what you meant.
select IF(sum(payment.amount) > bill.amount, sum(payment.amount)-bill.amount, 0) as interest
from bills bill
cross join payments payment inner join check_payments checkpayment
on
payment.id=checkpayment.payment_id
where payment.type='CH'
and payment.bill_id=bill.id
and (bill.collection_case_id in (1 , 2))
i am creating a student management system, i have 3 tables, student, fees, student_fee, the fee table contains the amount of fees and the student_fee contains reference to student.studentid and fee.feeid, so that whenever a student paid their fees, the studentid, feeid and paid_date will be insert into the student_fee table. Fees can increase the next year, how can i still keep the old records of fees payment without losing and causing any problem to the account
Instead of doing an entire history table separately, just add a column into the student_fee_paid table for the amount of the payment... so you can still query from it directly for the entire history of a student and it will have the historical values all in one... ex:
Student Fee_ID DatePaid FeeAmount
X 1 1/1/2009 $25
X 1 1/1/2010 $25
X 1 1/1/2011 $30
X 1 1/1/2012 $35
Otherwise it will just grow to a larger task... If you have 30 different fees, and the fee schedule amount changes for some but not all, what then... You can keep your "Fee" table to reflect whatever the "Current" fee amount is, but as soon as its paid, stamp that amount immediately.... if rates change mid-year, yet another trouble / history consideration... don't worry about the otherwise minimal amount of data storage this will increase.
Create a history of fee payment table. StudentID, FeeID, DatePaid, AmountPaid
or Effectively Date your Fee table.
Copy the table fees and student_fee for archive purpose.
You can use the SELECT INTO command.
http://www.w3schools.com/sql/sql_select_into.asp