PLSQL Dynamic Content:
DECLARE
CURSOR GRN_SALES_MASTER IS
SELECT TRCODE,
TRCODES,
SERIALNO,
GRN_RLOC,
GRN_MDATE,
--- SLCODE,
FUNC_DEALER_NAME_BN (SLCODE) SLCODE,
FUNC_DEALER_ADDRESS_BN (SLCODE ) ADDRESS,
FUNC_DELAR_BIN_NID(SLCODE) BIN,
GRN_ORDTYP,
ORDTYP,
GRN_FOR,
TENTATIVE_DNDATE,
DN_DATE,
FUNC_DEALER_PHONE (SLCODE) DL_MOBILE,
GRN_DELADD1,
GRN_DELADD2,
GRN_DELADD3,
GRN_DUEDT,
GRN_PARTI,
GRN_TRANSPORT,
GRN_CURRCD,
GRN_EMP,
GRN_COMP,
DN_NO,
NVL (DL_BALANCE, 0) DL_BALANCE,
DL_LAST_COLL,
DL_LAST_COLL_DT,
VR_NUMBER,
INVOICE_NUMBER,
NVL(RE_REF_NO,DN_NO ) RE_REF_NO
FROM GRNORDER_SALES_VW
WHERE SERIALNO = :P33_SERIALNO;
CURSOR GRN_DRIVER IS
SELECT SERIALNO,
DN_NO,
DN_DATE,
GRN_TRANSPORT,
TRANSPORT_NO,
--- TRANSPORT_NO || '-' || VEH_MODEL TRANSPORT,
--- TRANSPORT_NO || '-' || NVL(VEH_MODEL,GRN_TRANSPORT) TRANSPORT,
DECODE(VEH_MODEL,NULL, GRN_TRANSPORT,TRANSPORT_NO)TRANSPORT,
TRUCK_CAPACITY,
VR_NUMBER,
DRIVER_ID,
DRIVER_NM,
DRIVER_ADD,
DRIVER_PHONE,
NVL(VEH_MODEL,GRN_TRANSPORT) VEH_MODEL
FROM GRN_DRIVER_VW
WHERE SERIALNO = :P33_SERIALNO;
CURSOR CUSTOMER_LAST_BALANCCE IS
SELECT NVL(M.DL_BALANCE,0)-SUM(NVL (S_QTY, 0)*NVL(MRATE,0)) LAST_BALANCE
from GRN_SALES_MASTER M,GRN_SALES_DETAIL D
WHERE M.SERIALNO = D.SERIALNO
AND M.SERIALNO=:P33_SERIALNO
GROUP BY M.DL_BALANCE;
/*
CURSOR CUSTOMER_LAST_BALANCCE IS
SELECT NVL (SUM (M.DL_BALANCE), 0) - NVL (SUM (D.S_COST), 0) lAST_BALANCE
FROM GRN_SALES_MASTER M, GRN_SALES_DETAIL D
WHERE M.SERIALNO = D.SERIALNO AND M.SERIALNO = :P33_SERIALNO ;
*/
CURSOR GRN_SALES_DET IS
SELECT ROWNUM SL,
FYEAR,
SERIALNO,
GRN_RLOC,
GRN_SEQ,
ITEMCODE,
FUNC_ITEM_NAME_BN (ITEMCODE) ITEMCODE_BN,
NVL (S_QTY, 0) S_QTY,
NVL (B_QTY, 0) B_QTY,
NVL (A_QTY, 0) A_QTY,
MRATE,
NVL (A_QTY, 0) + NVL(B_QTY,0)+NVL (S_QTY, 0) TOTAL_QTY,
NVL(NVL (S_QTY, 0) + NVL (A_QTY, 0) + NVL(B_QTY,0),0)* NVL(MRATE,0) TOTAL_PRICE,
---ROUND(NVL(NVL(NVL(MRATE,0)/1.15,0)*NVL(15,0)/100,0),2) PER_VATE,
---ROUND(NVL(NVL(NVL(MRATE,0)/1.15,0)*NVL(15,0)/100,0),2)*NVL(NVL(NVL (S_QTY, 0) + NVL (A_QTY, 0) + NVL(B_QTY,0),0),0) TOTAL_VAT,
ROUND((( NVL (S_QTY, 0)*NVL(MRATE,0))/115)*15,4) TOTAL_VAT,
ROUND((( NVL (S_QTY, 0)*NVL(MRATE,0))/115)*15/(NVL (A_QTY, 0) + NVL(B_QTY,0)+NVL (S_QTY, 0)),4) PER_VATE,
NVL(NVL (A_QTY, 0) + NVL(B_QTY,0),0)* NVL(MRATE,0) TOTAL_DISCOUNT,
NVL(NVL(NVL (S_QTY, 0) + NVL (A_QTY, 0) + NVL(B_QTY,0),0)* NVL(MRATE,0),0)-NVL(NVL(NVL (A_QTY, 0) + NVL(B_QTY,0),0)* NVL(MRATE,0),0) PAY_AMOUNT,
--- S_COST,
---B_COST,
ROUND (V_COST,4) V_COST,
PROM_ITEM,
--- FUNC_ITEM_NAME_BN (PROM_ITEM) PROM_ITEM_BN,
FUNC_ITEM_NAME_BANGLA (PROM_ITEM) PROM_ITEM_BN,
NVL (PROM_QTY, 0) PROM_QTY,
PROM_RATE,
--- TOTAL_QTY,
NVL (CART_QTY, 0) CART_QTY
FROM GRN_SALES_DETAIL
WHERE SERIALNO = :P33_SERIALNO;
CURSOR GRN_SALES_DET_SUM IS
SELECT SERIALNO,
SUM (NVL (S_QTY, 0)) SALES_QTY,
SUM (NVL (B_QTY, 0)) BONUS_QTY,
SUM (NVL (A_QTY, 0)) ADD_QTY,
SUM(NVL (A_QTY, 0) + NVL(B_QTY,0)+NVL (S_QTY, 0)) TOTAL_QTY,
---SUM(ROUND(NVL(NVL(NVL(MRATE,0)/1.15,0)*NVL(15,0)/100,0),2)*NVL(NVL(NVL (S_QTY, 0) + NVL (A_QTY, 0) + NVL(B_QTY,0),0),0)) TOTAL_VAT,
SUM(ROUND((( NVL (S_QTY, 0)*NVL(MRATE,0))/115)*15,4)) TOTAL_VAT,
SUM(NVL(NVL (A_QTY, 0) + NVL(B_QTY,0),0)* NVL(MRATE,0) ) TOTAL_DISCOUNT,
SUM(NVL(NVL (S_QTY, 0) + NVL (A_QTY, 0) + NVL(B_QTY,0),0)* NVL(MRATE,0) ) TOTAL_PRICE,
SUM(NVL(NVL(NVL (S_QTY, 0) + NVL (A_QTY, 0) + NVL(B_QTY,0),0)* NVL(MRATE,0),0)-NVL(NVL(NVL (A_QTY, 0) + NVL(B_QTY,0),0)* NVL(MRATE,0),0) ) PAY_AMOUNT,
SUM (NVL (PROM_QTY, 0)) PROM_ITEM_QTY
FROM GRN_SALES_DETAIL
WHERE SERIALNO =:P33_SERIALNO
GROUP BY SERIALNO;
---DEALER LAST DATE---------
CURSOR DEALER_LAST_DATE IS
select MAX(SLS_PM_MDATE) SLS_PM_MDATE
from SLS_PAY_MASTER
where SLS_PM_SUB_SLCD=:P33_SLCODE
order by SLS_PM_MDATE desc;
----DEALER LAST COLLECTION ---------
CURSOR DEALER_LAST_COLLECTION IS
SELECT sum(AMT_CR) LAST_COLLECTION
FROM GL_SL A
WHERE
MDATE>(SELECT to_date(MAX(INV_ISM_MDATE)) FROM INV_ISSUE_MASTER WHERE INV_ISM_TRCODE IN ('IN','INU') AND INV_ISM_SLCODE=a.code and INV_ISM_MDATE<:P33_MDATE)
AND CODE=:P33_SLCODE
AND ACCCODE='220401';
/*
CURSOR DL_COLLECTION_BALANCE IS
SELECT SLS_PM_AMOUNT,
MAX(SLS_PM_MDATE) SLS_PM_MDATE
FROM SLS_PAY_MASTER
WHERE SLS_PM_SUB_SLCD ='SHAE03'
GROUP BY SLS_PM_AMOUNT
ORDER BY SLS_PM_MDATE DESC;
*/
BEGIN
HTP.P ('<div id="PrintMe">');
HTP.P ('<div>');
HTP.P ('<style>
footer {
font-size: 12px;
color: black;
text-align: center;
}
@media print {
footer {
position: fixed;
bottom: 0;
}
</style>');
FOR GRN IN GRN_SALES_MASTER
LOOP
FOR D IN GRN_DRIVER
LOOP
FOR B IN CUSTOMER_LAST_BALANCCE LOOP
FOR DT IN DEALER_LAST_DATE LOOP
FOR C IN DEALER_LAST_COLLECTION LOOP
--- FOR BL IN DL_COLLECTION_BALANCE LOOP
HTP.P (
'<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="width:1000px;">
<font size="4" > <p align="center"><strong>এস.</strong> <strong>এ.</strong> <strong>কে কনজ্যুমার প্রোডাক্টস লি.</strong></p></font>
</td>
</tr>
<tr>
<td style="width:974px;">
<p align="center"><strong> ফ্যাক্টরী:</strong> জগদীশপুর,ইটখোলা,মাধবপুর, হবিগঞ্জ -৩৩৩০</p>
</td>
<tr>
<td style="width:974px;">
<p align="center"><B> হেড অফিস</B>: বিজয় রাকিন সিটি, কমার্শিয়াল কমপ্লেক্স, লেভেল ১১, প্লট ১/২, ব্লক ডি, সেকশন ১৫, মিরপুর, ঢাকা ১২১৬</p>
</td>
</tr>');
htp.p('<p> </p>');
htp.p('<tr>
<td width="1068">
<p style="text-align: center;"><strong> </strong><u> <strong>বিক্রয়</strong></u> <strong><u>পত্র</u></strong><strong><u>/INVOICE</u></strong></p>
</td>
</tr>
</tbody>
</table>');
HTP.P('<table width="1062">
<tbody>
<tr>
<td style="text-align: right;" width="168">
<p>ইনভয়েস নং</p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="518">
<p>'
|| GRN.INVOICE_NUMBER
|| '</p>
</td>
<td style="text-align: right;" width="138">
<p>ইন:রেফা: নং</p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="215">
<p>'
|| GRN.RE_REF_NO
|| '</p>
</td>
</tr>
<tr>
<td style="text-align: right;" width="168">
<p>ডিস্ট্রিবিউটরের নাম</p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="518">
<p>'
|| GRN.SLCODE
|| '</p>
</td>
<td style="text-align: right;" width="138">
<p>তারিখ</p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="215">
<p>'
|| GRN.DN_DATE
|| '</p>
</td>
</tr>
<tr>
<td style="text-align: right;" width="168">
<p>ঠিকানা</p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="518">
<p>'
|| GRN.ADDRESS||'</p>
</td>
<td style="text-align: right;" width="138">
<p><strong>অর্ডার</strong> <strong>টাইপ</strong></p>
</td>
<td width="12">
<p><strong>:</strong></p>
</td>
<td width="215">
<p><strong>'
|| GRN.GRN_FOR
|| '</strong></p>
</td>
</tr>
<tr>
<td style="text-align: right;" width="168">
<p>মোবাইল নম্বর</p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="518">
<p>'
|| GRN.DL_MOBILE
|| '</p>
</td>
<td style="text-align: right;" width="150">
<p> বি.আই.এন/এন.আই.ডি.</p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="215">
<p> '
|| GRN.BIN
|| '</p>
</td>
</tr>
<tr>
<td style="text-align: right;" width="168">
<p>ট্রান্সপোর্ট</p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="518">
<p>'
|| D.TRANSPORT
|| '</p>
</td>
<td style="text-align: right;" width="138">
<p>বিস্তারিত</p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="215">
<font size="1"><p>'|| GRN.GRN_PARTI|| '</p></font>
</td>
</tr>
<tr>
<td style="text-align: right;" width="168">
<p>ড্রাইভার মোবাইল নম্বর</p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="518">
<p>'
|| D.DRIVER_PHONE
|| '</p>
</td>
<td style="text-align: right;" width="138">
<p>ড্রাইভারের নাম</p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="215">
<p>'
|| D.DRIVER_NM
|| '</p>
</td>
</tr>
<tr>
<td style="text-align: right;" width="168">
<p>কালেকশন তারিখ</p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="518">
<p>'||GRN.DL_LAST_COLL_DT||'</p>
</td>
<td style="text-align: right;" width="138">
<p>শেষ কালেকশন </p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="215">
<p>'||'৳'||TO_CHAR(GRN.DL_LAST_COLL,'999G999G999G999G990D00')||'</p>
</td>
</tr>
<tr>
<td style="text-align: right;" width="168">
<p> পূর্বের জের</p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="518">
<p>'
||'৳'|| TO_CHAR(GRN.DL_BALANCE,'999G999G999G999G990D00')
||'</p>
</td>
<td style="text-align: right;" width="138">
<p><strong>বর্তমান</strong> <strong>জের</strong></p>
</td>
<td width="12">
<p>:</p>
</td>
<td width="215">
<B><p>'||'৳'||TO_CHAR(B.LAST_BALANCE,'999G999G999G999G990D00')
||'</p></B>
</td>
</tr>
</tbody>
</table>');
END LOOP;
END LOOP;
END LOOP;
END LOOP;
END LOOP;
HTP.P('<table width="1098">
<table border="1" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td width="50">
<p style="text-align: center;">ক্রমিক নং</p>
</td>
<td style="text-align: center;" width="222">
<p>পণ্যের নাম</p>
</td>
<td style="text-align: center;" width="61">
<p>বিক্রয় পরিমাণ</p>
</td>
<td style="text-align: center;" width="56">
<p>বোনাস পরিমাণ</p>
</td>
<td style="text-align: center;" width="60">
<p>সমন্বয় পরিমাণ</p>
</td>
<td style="text-align: center;" width="56">
<p>মোট পরিমাণ</p>
</td>
<td style="text-align: center;" width="58">
<p>'||'৳'||'মূল্য </p>
</td>
<td style="text-align: center;" width="44">
<p>'||'৳'||'ভ্যাট পিস </p>
</td>
<td style="text-align: center;" width="49">
<p>'||'৳'||'ভ্যাট</p>
</td>
<td style="text-align: center;" width="80">
<p>'||'৳'||'ডিসকাউন্ট </p>
</td>
<td style="text-align: center;" width="57">
<p>'||'৳'||'মোট মূল্য</p>
</td>
<td style="text-align: center;" width="65">
<p>'||'৳'||'মোট পরিশোধ</p>
</td>
<td style="text-align: center;" width="180">
<p>প্রমোশনাল আইটেম</p>
</td>
<td style="text-align: center;" width="61">
<p>প্রমো. পরিমাণ</p>
</td>
</tr>');
FOR I IN GRN_SALES_DET LOOP
HTP.P('<tr>
<td style="text-align: center;" width="50">
<font size="1"><p>'||I.SL||'</p></font>
</td>
<td style="text-align: center;" width="222">
<font size="1"><p style="text-align: left;"> '
|| I.ITEMCODE_BN
|| '</p></font>
</td>
<td style="text-align: center;" width="61">
<font size="1"><p>'
|| I.S_QTY
|| '</p></font>
</td>
<td style="text-align: center;" width="56">
<font size="1"><p>'
|| I.B_QTY
|| '</p></font>
</td>
<td style="text-align: center;" width="60">
<font size="1"><p>'
|| I.A_QTY
|| '</p></font>
</td>
<td style="text-align: center;" width="56">
<font size="1"><p>'||I.TOTAL_QTY||'</p></font>
</td>
<td style="text-align: center;" width="58">
<font size="1"><p>'
|| I.MRATE
|| '</p></font>
</td>
<td style="text-align: center;" width="44">
<font size="1"><p>'
|| I.PER_VATE
|| ' </p></font>
</td>
<td style="text-align: center;" width="49">
<font size="1"><p>'
|| I.TOTAL_VAT
|| '</p></font>
</td>
<td style="text-align: center;" width="80">
<font size="1"><p>'
|| I.TOTAL_DISCOUNT
|| '</p></font>
</td>
<td style="text-align: center;" width="57">
<font size="1"><p>'
|| I.TOTAL_PRICE
|| '</p></font>
</td>
<td style="text-align: center;" width="65">
<font size="1"><p>'
|| I.PAY_AMOUNT
|| ' </p></font>
</td>
<td style="text-align: center;" width="180">
<font size="1"><p style="text-align: left;"> '
|| I.PROM_ITEM_BN
|| '</p></font>
</td>
<td style="text-align: center;" width="61">
<font size="1"><p>'
|| I.PROM_QTY
|| '</p></font>
</td>
</tr>');
END LOOP;
FOR S IN GRN_SALES_DET_SUM
LOOP
HTP.P('<tr>
<td style="text-align: center;" width="50">
<p>Total</p>
</td>
<td width="222">
<p> </p>
</td>
<td style="text-align: center;" width="61">
<p><strong>'
|| TO_CHAR(S.SALES_QTY ,'999G999G999G999G990D00')
|| '</strong></p>
</td>
<td style="text-align: center;" width="56">
<p><strong>'
|| TO_CHAR(S.BONUS_QTY,'999G999G999G999G990D00')
|| '</strong></p>
</td>
<td style="text-align: center;" width="60">
<p><strong>'
|| TO_CHAR(S.ADD_QTY ,'999G999G999G999G990D00')
|| '</strong></p>
</td>
<td style="text-align: center;" width="56">
<p><strong>'
|| TO_CHAR( S.TOTAL_QTY,'999G999G999G999G990D00')
|| '</strong></p>
</td>
<td style="text-align: center;" width="58">
<p><strong> </strong></p>
</td>
<td style="text-align: center;" width="44">
<p><strong> </strong></p>
</td>
<td style="text-align: center;" width="49">
<p><strong>'
|| TO_CHAR(S.TOTAL_VAT,'999G999G999G999G990D00')
|| '</strong></p>
</td>
<td style="text-align: center;" width="80">
<p><strong>'
|| TO_CHAR(S.TOTAL_DISCOUNT,'999G999G999G999G990D00')
|| '</strong></p>
</td>
<td style="text-align: center;" width="57">
<font size="2"><p><strong>'
|| TO_CHAR(S.TOTAL_PRICE,'999G999G999G999G990D00')
|| '</strong></p></font>
</td>
<td style="text-align: center;" width="65">
<font size="2"><p><strong>'
|| TO_CHAR(S.PAY_AMOUNT ,'999G999G999G999G990D00')
|| '</strong></p></font>
</td>
<td style="text-align: center;" width="180">
<p><strong> </strong></p>
</td>
<td style="text-align: center;" width="61">
<p><strong>'
|| S.PROM_ITEM_QTY
|| '</strong></p>
</td>
</tr>
</tbody>
</table>');
HTP.P ('<br>');
HTP.p (
'<p>In Word : ' || SPELL_OUT (S.PAY_AMOUNT) || '</p>');
HTP.P('<p> </p>
<p> </p>
<p> </p>
<table width="1068">
<tbody>
<tr>
<td width="291">
<p> </p>
</td>
<td width="91">
<p> </p>
</td>
<td width="310">
<p> </p>
</td>
<td width="91">
<p> </p>
</td>
<td width="285">
<p> </p>
</td>
</tr>');
HTP.P('<tr>
<td style="text-align: center;" width="291">
<div> <p style="border-top: 1px solid black;" align="center">প্রস্তুতকারীর স্বাক্ষর</p></div>
</td>
<td style="text-align: center;" width="91">
<p> </p>
</td>
<td style="text-align: center;" width="310">
<div> <p style="border-top: 1px solid black;" align="center">অনুমোদনকারীর স্বাক্ষর </p></div>
</td>
<td style="text-align: center;" width="91">
<p> </p>
</td>
<td style="text-align: center;" width="285">
<div> <p style="border-top: 1px solid black;" align="center"> ডিস্ট্রিবিউটরের স্বাক্ষর </p></div>
</td>
</tr>
</tbody>
</table>');
HTP.P ('<br>');
HTP.P ('<br>');
HTP.P (
'<p 1px solid black;" align="center">Maintain & Developed by SAK Consumer Products Ltd. | www.sakcpl.com</p>');
HTP.P ('<br>');
HTP.P ('</div>');
HTP.P ('</footer>');
HTP.P ('</div>');
HTP.P ('</div>');
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
HTP.P ('Report Problem. Contact with SAK Admin </br>');
HTP.P (DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
END;