
--
-- Final view structure for view `view_unpost_ap_creditnote`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_ap_creditnote`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_ap_creditnote`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_ap_creditnote` AS select `e`.`supplierName` AS `supplier`,`a`.`ID` AS `creditnoteID`,`b`.`lineNo` AS `lineNo`,`c`.`projectID` AS `projectID`,`a`.`supplierInvoiceID` AS `supplierInvoiceID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`supplierID` AS `supplierID`,`c`.`supplierInvoiceNo` AS `supplierInvoiceNo`,if((`c`.`purchaseInvoiceCodeID` = 1),(select `cri`.`locationID` from (`comp_receive_item_detail` `crid` left join `comp_receive_item` `cri` on((`cri`.`ID` = `crid`.`receiveID`))) where (`crid`.`ID` = `g`.`receiveID`)),`c`.`locationID`) AS `locationID`,`b`.`umID` AS `umID`,`b`.`quantity` AS `quantity`,`b`.`itemID` AS `itemID`,concat('[',`d`.`itemCode`,']',`d`.`name`) AS `itemName`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,(select `item`.`inventoriesID` from `item` where (`item`.`ID` = `b`.`itemID`)) AS `drAccountID`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `crAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `drTaxAccountID`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `crTaxAccountID` from (((`comp_supplier_creditnote` `a` join (`comp_supplier_creditnote_detail` `b` left join `item` `d` on((`b`.`itemID` = `d`.`ID`)))) join (`comp_supplier_invoice` `c` left join `comp_supplier_invoice_detail` `g` on((`c`.`ID` = `g`.`invoiceID`)))) join `supplier` `e`) where ((`a`.`ID` = `b`.`creditnoteID`) and (`a`.`supplierInvoiceID` = `c`.`ID`) and (`e`.`ID` = `a`.`supplierID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `e`.`supplierName` AS `supplier`,`a`.`ID` AS `creditnoteID`,`b`.`lineNo` AS `lineNo`,`c`.`projectID` AS `projectID`,`a`.`supplierInvoiceID` AS `supplierInvoiceID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`supplierID` AS `supplierID`,`c`.`supplierInvoiceNo` AS `supplierInvoiceNo`,`c`.`locationID` AS `locationID`,`b`.`umID` AS `umID`,`b`.`quantity` AS `quantity`,NULL AS `itemID`,`b`.`itemdescription` AS `itemName`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,`b`.`accountNoID` AS `drAccountID`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `crAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `drTaxAccountID`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `crTaxAccountID` from (((`comp_supplier_creditnote` `a` join `comp_supplier_creditnote_charges` `b`) join `comp_supplier_invoice` `c`) join `supplier` `e`) where ((`a`.`ID` = `b`.`creditNoteID`) and (`a`.`supplierInvoiceID` = `c`.`ID`) and (`e`.`ID` = `a`.`supplierID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) */;

--
-- Final view structure for view `view_unpost_ap_debitnote`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_ap_debitnote`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_ap_debitnote`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_ap_debitnote` AS select `e`.`supplierName` AS `supplier`,`a`.`ID` AS `debitnoteID`,`b`.`lineNo` AS `lineNo`,`c`.`projectID` AS `projectID`,4 AS `typeID`,`b`.`ID` AS `typeDetailID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`supplierID` AS `supplierID`,`c`.`supplierInvoiceNo` AS `supplierInvoiceNo`,if((`c`.`purchaseInvoiceCodeID` = 1),(select `cri`.`locationID` from (`comp_receive_item_detail` `crid` left join `comp_receive_item` `cri` on((`cri`.`ID` = `crid`.`receiveID`))) where (`crid`.`ID` = `g`.`receiveID`)),`c`.`locationID`) AS `locationID`,`b`.`umID` AS `umID`,`b`.`quantity` AS `quantity`,`b`.`itemID` AS `itemID`,concat('[',`d`.`itemCode`,']',`b`.`itemdescription`) AS `itemName`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `drAccountID`,(select `item`.`inventoriesID` from `item` where (`item`.`ID` = `b`.`itemID`)) AS `crAccountID`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `drTaxAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `crTaxAccountID`,NULL AS `cogsAcctID`,NULL AS `inventoriesAcctID` from (((`comp_supplier_debitnote` `a` join (`comp_supplier_debitnote_detail` `b` left join `item` `d` on((`b`.`itemID` = `d`.`ID`)))) join (`comp_supplier_invoice` `c` left join `comp_supplier_invoice_detail` `g` on((`c`.`ID` = `g`.`invoiceID`)))) join `supplier` `e`) where ((`a`.`ID` = `b`.`debitnoteID`) and (`a`.`supplierID` = `e`.`ID`) and (`a`.`supplierInvoiceID` = `c`.`ID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `e`.`supplierName` AS `supplier`,`a`.`ID` AS `debitnoteID`,`b`.`lineNo` AS `lineNo`,`c`.`projectID` AS `projectID`,4 AS `typeID`,`b`.`ID` AS `typeDetailID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`supplierID` AS `supplierID`,`c`.`supplierInvoiceNo` AS `supplierInvoiceNo`,`c`.`locationID` AS `locationID`,`b`.`umID` AS `umID`,`b`.`quantity` AS `quantity`,NULL AS `itemID`,`b`.`itemdescription` AS `itemName`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `drAccountID`,`b`.`accountNoID` AS `crAccountID`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `drTaxAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `crTaxAccountID`,NULL AS `cogsAcctID`,NULL AS `inventoriesAcctID` from (((`comp_supplier_debitnote` `a` join `comp_supplier_debitnote_charges` `b`) join `comp_supplier_invoice` `c`) join `supplier` `e`) where ((`a`.`ID` = `b`.`debitNoteID`) and (`a`.`supplierID` = `e`.`ID`) and (`a`.`supplierInvoiceID` = `c`.`ID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) */;

--
-- Final view structure for view `view_unpost_ap_invoice`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_ap_invoice`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_ap_invoice`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_ap_invoice` AS select `d`.`supplierName` AS `supplier`,`a`.`ID` AS `invoiceID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`supplierID` AS `supplierID`,`b`.`lineNo` AS `lineNo`,`b`.`itemID` AS `itemID`,concat('[',`c`.`itemCode`,']',`b`.`itemname`) AS `itemName`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'unInvoiceAP'))) AS `drAccountID`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `crAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `drTaxAccountID`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `crTaxAccountID` from (((`comp_supplier_invoice` `a` left join `comp_supplier_invoice_detail` `b` on((`a`.`ID` = `b`.`invoiceID`))) left join `item` `c` on((`b`.`itemID` = `c`.`ID`))) join `supplier` `d` on((`d`.`ID` = `a`.`supplierID`))) where ((`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `d`.`supplierName` AS `supplier`,`a`.`ID` AS `invoiceID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`supplierID` AS `supplierID`,(`b`.`lineNo` + (select ifnull(max(`comp_supplier_invoice_detail`.`lineNo`),0) from `comp_supplier_invoice_detail` where (`comp_supplier_invoice_detail`.`invoiceID` = `a`.`ID`))) AS `lineNo`,NULL AS `itemID`,`b`.`chargeDescription` AS `itemname`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,`b`.`accountNoID` AS `drAccountID`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `crAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `drTaxAccountID`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `crTaxAccountID` from ((`comp_supplier_invoice` `a` join `comp_supplier_invoice_charges` `b` on((`a`.`ID` = `b`.`invoiceID`))) left join `supplier` `d` on((`d`.`ID` = `a`.`supplierID`))) where ((`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) */;

--
-- Final view structure for view `view_unpost_ar_creditnote`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_ar_creditnote`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_ar_creditnote`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_ar_creditnote` AS select `f`.`customerName` AS `customer`,`a`.`salesInvoiceID` AS `salesinvoiceID`,`a`.`ID` AS `creditnoteID`,`a`.`projectID` AS `projectID`,0 AS `typeID`,`b`.`ID` AS `typeDetailID`,concat(`a`.`formNo`,'[',convert(lpad(`a`.`serialNo`,8,'0') using latin1),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`customerID` AS `customerID`,if((`c`.`invoiceCodeID` = 1),(select `dord`.`locationID` from (`comp_delivery_detail` `ddet` left join `comp_delivery_order` `dord` on((`dord`.`ID` = `ddet`.`deliveryID`))) where (`ddet`.`ID` = `g`.`doID`)),`c`.`locationID`) AS `locationID`,concat(`c`.`formNo`,'[',convert(lpad(`c`.`serialNo`,8,'0') using latin1),']') AS `salesInvoiceNo`,`b`.`lineNo` AS `lineNo`,`b`.`itemID` AS `itemID`,`b`.`umID` AS `umID`,`b`.`quantity` AS `quantity`,concat('[',`d`.`itemCode`,']',`b`.`itemname`) AS `itemName`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,(select `item`.`incomeID` from `item` where (`item`.`ID` = `b`.`itemID`)) AS `drAccountID`,ifnull(`f`.`linkedAPAccountID`,`e`.`accountID`) AS `crAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `drTaxAccountID`,ifnull(`f`.`linkedAPAccountID`,`e`.`accountID`) AS `crTaxAccountID`,(select `item`.`cogsID` from `item` where (`item`.`ID` = `b`.`itemID`)) AS `cogsAcctID`,(select `item`.`inventoriesID` from `item` where (`item`.`ID` = `b`.`itemID`)) AS `inventoriesAcctID` from ((((((`comp_sales_creditnote` `a` left join `comp_sales_creditnote_detail` `b` on((`a`.`ID` = `b`.`creditnoteID`))) left join `item` `d` on((`b`.`itemID` = `d`.`ID`))) left join `comp_sales_invoice` `c` on((`c`.`ID` = `a`.`salesInvoiceID`))) left join `comp_sales_invoice_detail` `g` on((`c`.`ID` = `g`.`invoiceID`))) join `customer` `f`) join `comp_control_acct_setup` `e`) where ((`a`.`ID` = `b`.`creditnoteID`) and (`a`.`customerID` = `f`.`ID`) and (`e`.`companyID` = `a`.`companyID`) and (`e`.`accountCode` = 'rcvacct') and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `f`.`customerName` AS `customer`,`a`.`salesInvoiceID` AS `salesinvoiceID`,`a`.`ID` AS `creditnoteID`,`c`.`projectID` AS `projectID`,0 AS `typeID`,`b`.`ID` AS `typeDetailID`,concat(`a`.`formNo`,'[',convert(lpad(`a`.`serialNo`,8,'0') using latin1),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`customerID` AS `customerID`,`c`.`locationID` AS `locationID`,concat(`c`.`formNo`,'[',convert(lpad(`c`.`serialNo`,8,'0') using latin1),']') AS `salesInvoiceNo`,`b`.`lineNo` AS `lineNo`,NULL AS `itemID`,NULL AS `umID`,1 AS `quantity`,`b`.`chargeDescription` AS `itemName`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,`b`.`accountNoID` AS `drAccountID`,ifnull(`f`.`linkedAPAccountID`,`e`.`accountID`) AS `crAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `drTaxAccountID`,ifnull(`f`.`linkedAPAccountID`,`e`.`accountID`) AS `crTaxAccountID`,NULL AS `cogsAcctID`,NULL AS `inventoriesAcctID` from ((((`comp_sales_creditnote` `a` left join `comp_sales_invoice` `c` on((`c`.`ID` = `a`.`salesInvoiceID`))) join `customer` `f`) join `comp_control_acct_setup` `e`) join `comp_sales_creditnote_charges` `b`) where ((`a`.`ID` = `b`.`creditNoteID`) and (`a`.`customerID` = `f`.`ID`) and (`e`.`companyID` = `a`.`companyID`) and (`e`.`accountCode` = 'rcvacct') and (`a`.`ID` = `b`.`creditNoteID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) */;

--
-- Final view structure for view `view_unpost_ar_debitnote`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_ar_debitnote`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_ar_debitnote`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_ar_debitnote` AS select `f`.`customerName` AS `customer`,`a`.`salesInvoiceID` AS `salesinvoiceID`,`a`.`ID` AS `debitnoteID`,`c`.`projectID` AS `projectID`,3 AS `typeID`,`b`.`ID` AS `typeDetailID`,concat(`a`.`formNo`,'[',convert(lpad(`a`.`serialNo`,8,'0') using latin1),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`customerID` AS `customerID`,if((`c`.`invoiceCodeID` = 1),(select `do`.`locationID` from (`comp_delivery_detail` `ddet` left join `comp_delivery_order` `do` on((`do`.`ID` = `ddet`.`deliveryID`))) where (`ddet`.`ID` = `g`.`doID`)),`c`.`locationID`) AS `locationID`,concat(`c`.`formNo`,'[',convert(lpad(`c`.`serialNo`,8,'0') using latin1),']') AS `salesInvoiceNo`,`b`.`lineNo` AS `lineNo`,`b`.`itemID` AS `itemID`,`b`.`umID` AS `umID`,`b`.`quantity` AS `quantity`,concat('[',`d`.`itemCode`,']',`b`.`itemname`) AS `itemName`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,`c`.`currencyID` AS `currencyID`,ifnull(`f`.`linkedAPAccountID`,`e`.`accountID`) AS `drAccountID`,(select `item`.`incomeID` from `item` where (`item`.`ID` = `b`.`itemID`)) AS `crAccountID`,ifnull(`f`.`linkedAPAccountID`,`e`.`accountID`) AS `drTaxAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `crTaxAccountID`,`d`.`cogsID` AS `cogsAcctID`,`d`.`inventoriesID` AS `inventoriesAcctID` from ((((((`comp_sales_debitnote` `a` join `comp_sales_debitnote_detail` `b` on((`a`.`ID` = `b`.`debitnoteID`))) left join `item` `d` on((`b`.`itemID` = `d`.`ID`))) left join `comp_sales_invoice` `c` on((`c`.`ID` = `a`.`salesInvoiceID`))) left join `comp_sales_invoice_detail` `g` on((`c`.`ID` = `g`.`invoiceID`))) join `customer` `f`) join `comp_control_acct_setup` `e`) where ((`a`.`ID` = `b`.`debitnoteID`) and (`a`.`customerID` = `f`.`ID`) and (`e`.`companyID` = `a`.`companyID`) and (`e`.`accountCode` = 'rcvacct') and (`a`.`ID` = `b`.`debitnoteID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `f`.`customerName` AS `customer`,`a`.`salesInvoiceID` AS `salesinvoiceID`,`a`.`ID` AS `debitnoteID`,`c`.`projectID` AS `projectID`,0 AS `typeID`,`b`.`ID` AS `typeDetailID`,concat(`a`.`formNo`,'[',convert(lpad(`a`.`serialNo`,8,'0') using latin1),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`customerID` AS `customerID`,`c`.`locationID` AS `locationID`,concat(`c`.`formNo`,'[',convert(lpad(`c`.`serialNo`,8,'0') using latin1),']') AS `salesInvoiceNo`,`b`.`lineNo` AS `lineNo`,NULL AS `itemID`,NULL AS `umID`,1 AS `quantity`,`b`.`chargeDescription` AS `itemName`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,`c`.`currencyID` AS `currencyID`,ifnull(`f`.`linkedAPAccountID`,`e`.`accountID`) AS `drAccountID`,`b`.`accountNoID` AS `crAccountID`,ifnull(`f`.`linkedAPAccountID`,`e`.`accountID`) AS `drTaxAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `crTaxAccountID`,NULL AS `cogsAcctID`,NULL AS `inventoriesAcctID` from ((((`comp_sales_debitnote` `a` left join `comp_sales_invoice` `c` on((`c`.`ID` = `a`.`salesInvoiceID`))) join `customer` `f`) join `comp_control_acct_setup` `e`) join `comp_sales_debitnote_charges` `b`) where ((`a`.`ID` = `b`.`debitNoteID`) and (`a`.`customerID` = `f`.`ID`) and (`e`.`companyID` = `a`.`companyID`) and (`e`.`accountCode` = 'rcvacct') and (`a`.`ID` = `b`.`debitNoteID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) */;

--
-- Final view structure for view `view_unpost_ar_invoice`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_ar_invoice`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_ar_invoice`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_ar_invoice` AS select `a`.`projectID` AS `projectID`,`e`.`customerName` AS `customer`,`a`.`ID` AS `invoiceID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`customerID` AS `customerID`,`b`.`itemID` AS `itemID`,`b`.`lineNo` AS `lineNo`,concat('[',`c`.`itemCode`,']',`c`.`description`) AS `itemName`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,(select `customer`.`linkedAPAccountID` from `customer` where (`customer`.`ID` = `a`.`customerID`)) AS `drAccountID`,(select `item`.`incomeID` from `item` where (`item`.`ID` = `b`.`itemID`)) AS `crAccountID`,(select `customer`.`linkedAPAccountID` from `customer` where (`customer`.`ID` = `a`.`customerID`)) AS `drTaxAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `crTaxAccountID` from ((`comp_sales_invoice` `a` join (`comp_sales_invoice_detail` `b` left join `item` `c` on((`b`.`itemID` = `c`.`ID`)))) join `customer` `e`) where ((`a`.`ID` = `b`.`invoiceID`) and (`a`.`customerID` = `e`.`ID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `a`.`projectID` AS `projectID`,`e`.`customerName` AS `customer`,`a`.`ID` AS `invoiceID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`customerID` AS `customerID`,`b`.`itemID` AS `itemID`,`b`.`lineNo` AS `lineNo`,concat('[',`c`.`itemCode`,']',`c`.`description`) AS `itemName`,(select sum((`crid`.`unitPrice` * `crdc`.`qty`)) from (`comp_receive_item_detail` `crid` join `comp_receive_delivery_conn` `crdc`) where ((`crid`.`ID` = `crdc`.`receiveDetailID`) and (`crdc`.`deliveryDetailID` = `do`.`ID`))) AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,NULL AS `taxamount`,(select `item`.`cogsID` from `item` where (`item`.`ID` = `b`.`itemID`)) AS `drAccountID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'uninvoiceAR'))) AS `crAccountID`,NULL AS `drTaxAccountID`,NULL AS `crTaxAccountID` from ((`comp_sales_invoice` `a` join ((`comp_sales_invoice_detail` `b` left join `item` `c` on((`b`.`itemID` = `c`.`ID`))) left join `comp_delivery_detail` `do` on(((`do`.`invoiceID` = `b`.`invoiceID`) and (`do`.`itemID` = `b`.`itemID`) and (`do`.`umID` = `b`.`umID`))))) join `customer` `e`) where ((`a`.`ID` = `b`.`invoiceID`) and (`a`.`customerID` = `e`.`ID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0) and (`a`.`invoiceCodeID` <> 2)) union select `a`.`projectID` AS `projectID`,`e`.`customerName` AS `customer`,`a`.`ID` AS `invoiceID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`customerID` AS `customerID`,NULL AS `NULL`,`b`.`lineNo` AS `lineNo`,`b`.`chargeDescription` AS `chargedescription`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,(select `customer`.`linkedAPAccountID` from `customer` where (`customer`.`ID` = `a`.`customerID`)) AS `drAccountID`,`b`.`accountNoID` AS `crAccountID`,(select `customer`.`linkedAPAccountID` from `customer` where (`customer`.`ID` = `a`.`customerID`)) AS `drTaxAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `crTaxAccountID` from ((`comp_sales_invoice` `a` join `comp_sales_invoice_charges` `b`) join `customer` `e`) where ((`a`.`ID` = `b`.`invoiceID`) and (`e`.`ID` = `a`.`customerID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `a`.`projectID` AS `projectID`,`e`.`customerName` AS `customer`,`a`.`ID` AS `invoiceID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`customerID` AS `customerID`,NULL AS `NULL`,`b`.`lineNo` AS `lineNo`,'comission' AS `itemName`,((sum(`b`.`amountExcludedTax`) * `d`.`commisionRate`) / 100) AS `comissionAmount`,0 AS `taxID`,0 AS `taxAmount`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'commissionexp'))) AS `drAccountID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'commissionpay'))) AS `crAccountID`,NULL AS `drTaxAccountID`,NULL AS `crTaxAccountID` from (((`comp_sales_invoice` `a` join `comp_sales_invoice_detail` `b`) join `comp_sales_agent` `d`) join `customer` `e`) where ((`a`.`companyID` = `d`.`companyID`) and (`a`.`ID` = `b`.`invoiceID`) and (`a`.`agentID` = `d`.`ID`) and (`a`.`customerID` = `e`.`ID`) and (`a`.`agentID` > 0) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) group by `a`.`ID` union select `a`.`projectID` AS `projectID`,`e`.`customerName` AS `customer`,`a`.`ID` AS `invoiceID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`customerID` AS `customerID`,NULL AS `NULL`,`b`.`lineNo` AS `lineNo`,'wakaf' AS `itemName`,`b`.`amountExcludedTax` AS `amountExcludedtax`,0 AS `taxID`,0 AS `taxAmount`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'wakafExpense'))) AS `drAccountID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'wakafAcrual'))) AS `crAccountID`,NULL AS `drTaxAccountID`,NULL AS `crTaxAccountID` from ((((`comp_sales_invoice` `a` join `comp_sales_invoice_detail` `b`) join `wakaf_acrual` `c`) join `item` `d`) join `customer` `e`) where ((`a`.`ID` = `b`.`invoiceID`) and (`a`.`customerID` = `e`.`ID`) and (`a`.`companyID` = `c`.`companyID`) and (`b`.`itemID` = `d`.`ID`) and (`d`.`incomeID` = `c`.`salesAccountID`) and (`a`.`salesInvoiceDate` between `c`.`from` and `c`.`to`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) */;

--
-- Final view structure for view `view_unpost_ar_payment`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_ar_payment`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_ar_payment`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_ar_payment` AS select `a`.`ID` AS `paymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`customerID` AS `customerID`,NULL AS `purchaseInvoiceID`,`b`.`customerName` AS `customerName`,0 AS `lineNo`,NULL AS `paymentDetailID`,`a`.`referenceNo` AS `item`,`a`.`bankCharges` AS `amtPaid_amtAppl`,0 AS `discount_bankCharges`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'bankchargesAccount'))) AS `drAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankID`)) AS `crAccountID`,NULL AS `drDiscountAccountID`,NULL AS `crDiscountAccountID` from (`comp_receive_payment` `a` join `customer` `b`) where ((`a`.`customerID` = `b`.`ID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `a`.`ID` AS `paymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`customerID` AS `customerID`,`b`.`invoiceID` AS `invoiceID`,`e`.`customerName` AS `customerName`,`b`.`lineNo` AS `lineNo`,`b`.`ID` AS `paymentDetailID`,concat(concat(concat(`d`.`formNo`,'['),convert(lpad(`d`.`serialNo`,8,'0') using latin1)),']') AS `item`,(`b`.`amountApplied` - `b`.`discount`) AS `amtPaid_amtAppl`,`b`.`discount` AS `discount_bankCharges`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankID`)) AS `drAccountID`,(select `customer`.`linkedAPAccountID` from `customer` where (`customer`.`ID` = `a`.`customerID`)) AS `crAccountID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'saledisacct'))) AS `drDiscountAccountID`,(select `customer`.`linkedAPAccountID` from `customer` where (`customer`.`ID` = `a`.`customerID`)) AS `crDiscountAccountID` from (((`comp_receive_payment` `a` join (`comp_receive_payment_detail` `b` left join `comp_sales_invoice` `d` on((`d`.`ID` = `b`.`invoiceID`)))) join `comp_sales_invoice` `c`) join `customer` `e`) where ((`a`.`customerID` = `e`.`ID`) and (`a`.`ID` = `b`.`receivePaymentID`) and (`c`.`ID` = `b`.`invoiceID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `a`.`ID` AS `paymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`customerID` AS `customerID`,`b`.`historicalinvoiceID` AS `invoiceID`,`e`.`customerName` AS `customerName`,`b`.`ID` AS `lineNo`,`b`.`ID` AS `paymentDetailID`,concat(concat(concat(`d`.`formNo`,'['),convert(lpad(`d`.`serialNo`,8,'0') using latin1)),']') AS `item`,`b`.`amountApplied` AS `amtPaid_amtAppl`,NULL AS `discount_bankCharges`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankID`)) AS `drAccountID`,(select `customer`.`linkedAPAccountID` from `customer` where (`customer`.`ID` = `a`.`customerID`)) AS `crAccountID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'saledisacct'))) AS `drDiscountAccountID`,(select `customer`.`linkedAPAccountID` from `customer` where (`customer`.`ID` = `a`.`customerID`)) AS `crDiscountAccountID` from (((`comp_receive_payment` `a` join (`comp_receive_payment_detail_historical_invoice` `b` left join `comp_historical_customer_invoice` `d` on((`d`.`ID` = `b`.`historicalinvoiceID`)))) join `comp_historical_customer_invoice` `c`) join `customer` `e`) where ((`a`.`customerID` = `e`.`ID`) and (`a`.`ID` = `b`.`paymentID`) and (`c`.`ID` = `b`.`historicalinvoiceID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `a`.`ID` AS `paymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`customerID` AS `customerID`,`b`.`debitnoteID` AS `invoiceID`,`e`.`customerName` AS `customerName`,`b`.`ID` AS `lineNo`,`b`.`ID` AS `paymentDetailID`,concat(concat(concat(`d`.`formNo`,'['),convert(lpad(`d`.`serialNo`,8,'0') using latin1)),']') AS `item`,`b`.`amountApplied` AS `amtPaid_amtAppl`,NULL AS `discount_bankCharges`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankID`)) AS `drAccountID`,(select `customer`.`linkedAPAccountID` from `customer` where (`customer`.`ID` = `a`.`customerID`)) AS `crAccountID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'saledisacct'))) AS `drDiscountAccountID`,(select `customer`.`linkedAPAccountID` from `customer` where (`customer`.`ID` = `a`.`customerID`)) AS `crDiscountAccountID` from (((`comp_receive_payment` `a` join (`comp_receive_payment_detail_debitnote` `b` left join `comp_sales_debitnote` `d` on((`d`.`ID` = `b`.`debitnoteID`)))) join `comp_sales_debitnote` `c`) join `customer` `e`) where ((`a`.`customerID` = `e`.`ID`) and (`a`.`ID` = `b`.`paymentID`) and (`c`.`ID` = `b`.`debitnoteID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) */;

--
-- Final view structure for view `view_unpost_cash_purchase`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_cash_purchase`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_cash_purchase`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_cash_purchase` AS select `b`.`lineNo` AS `lineNo`,`b`.`quantity` AS `quantity`,`b`.`unitPrice` AS `unitPrice`,`b`.`itemID` AS `itemID`,`b`.`itemdescription` AS `itemdescription`,`b`.`umID` AS `umID`,`a`.`locationID` AS `locationID`,`a`.`ID` AS `othersPaymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`ID`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,NULL AS `supplierID`,NULL AS `purchaseInvoiceID`,`b`.`ID` AS `paymentDetailID`,NULL AS `supplierInvoiceNo`,`b`.`lineNo` AS `ID`,`b`.`itemname` AS `itemName`,`b`.`amountExcludedTax` AS `amountExcludedTax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxAmount`,`a`.`projectID` AS `projectID`,`c`.`itemTypeID` AS `itemTypeID`,if((`c`.`itemTypeID` = 23),`c`.`cogsID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'uninvoiceAP')))) AS `drAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankId`)) AS `crAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `drDiscountAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankId`)) AS `crDiscountAccountID` from ((`comp_payment_others` `a` join `comp_payment_others_with_item` `b`) left join `item` `c` on((`c`.`ID` = `b`.`itemID`))) where ((`a`.`ID` = `b`.`otherPaymentID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) */;

--
-- Final view structure for view `view_unpost_cash_sale`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_cash_sale`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_cash_sale`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_cash_sale` AS select `a`.`projectID` AS `projectID`,`a`.`paymentFrom` AS `customer`,`a`.`ID` AS `invoiceID`,5 AS `typeID`,`b`.`ID` AS `typeDetailID`,`a`.`locationID` AS `locationID`,`b`.`quantity` AS `quantity`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`b`.`itemID` AS `itemID`,`b`.`umID` AS `umID`,`b`.`lineNo` AS `lineNo`,`d`.`currencyID` AS `currencyID`,concat('[',`c`.`itemCode`,']',`c`.`description`) AS `itemName`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankID`)) AS `drAccountID`,`c`.`incomeID` AS `crAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankID`)) AS `drTaxAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `crTaxAccountID`,`c`.`cogsID` AS `cogsAcctID`,`c`.`inventoriesID` AS `inventoriesAcctID` from ((`comp_cash_sales` `a` join (`comp_cash_sales_detail` `b` left join `item` `c` on((`b`.`itemID` = `c`.`ID`)))) join `company` `d`) where ((`a`.`ID` = `b`.`invoiceID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0) and (`a`.`companyID` = `d`.`ID`)) */;

--
-- Final view structure for view `view_unpost_do`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_do`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_do`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_do` AS select `a`.`ID` AS `deliveryOrderID`,`a`.`customerID` AS `customerID`,NULL AS `projectID`,NULL AS `customer`,`a`.`ID` AS `invoiceID`,1 AS `typeID`,`b`.`ID` AS `typeDetailID`,`a`.`locationID` AS `locationID`,`b`.`quantitySent` AS `quantity`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`b`.`itemID` AS `itemID`,concat('[',`c`.`itemCode`,']',`c`.`description`) AS `itemName`,0 AS `amountExcludedtax`,NULL AS `taxid`,0 AS `taxamount`,NULL AS `drAccountID`,NULL AS `crAccountID`,NULL AS `drTaxAccountID`,NULL AS `crTaxAccountID`,if((`b`.`invoiceID` > 0),`c`.`cogsID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'unInvoiceAR')))) AS `cogsAcctID`,`c`.`inventoriesID` AS `inventoriesAcctID` from (`comp_delivery_order` `a` join (`comp_delivery_detail` `b` left join `item` `c` on((`b`.`itemID` = `c`.`ID`)))) where ((`a`.`ID` = `b`.`deliveryID`) and (`a`.`updateAble` = 1) and (`a`.`isDelete` = 0)) */;

--
-- Final view structure for view `view_unpost_gst_transaction`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_gst_transaction`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_gst_transaction`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_gst_transaction` AS select `a`.`ID` AS `paymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,NULL AS `supplierID`,NULL AS `purchaseInvoiceID`,concat(`a`.`Description`,'[',`a`.`vendor_cust_name`,']') AS `supplierName`,0 AS `lineNo`,NULL AS `paymentDetailID`,NULL AS `supplierInvoiceNo`,`a`.`reference` AS `item`,`b`.`taxAmountDr` AS `amtPaid_amtAppl`,0 AS `discount_bankCharges`,`b`.`accountID` AS `drAccountID`,(select `comp_gst_transaction_detail`.`accountID` from `comp_gst_transaction_detail` where ((`comp_gst_transaction_detail`.`gstTransID` = `a`.`ID`) and (`comp_gst_transaction_detail`.`taxAmountCr` > 0))) AS `crAccountID`,NULL AS `drDiscountAccountID`,NULL AS `crDiscountAccountID` from (`comp_gst_transaction` `a` join `comp_gst_transaction_detail` `b`) where ((`a`.`ID` = `b`.`gstTransID`) and (`b`.`taxAmountDr` > 0) and (`a`.`updateAble` = 1) and (`a`.`isDelete` = 0)) */;

--
-- Final view structure for view `view_unpost_other_payment`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_other_payment`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_other_payment`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_other_payment` AS select `a`.`ID` AS `othersPaymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,NULL AS `supplierID`,NULL AS `purchaseInvoiceID`,`b`.`ID` AS `paymentDetailID`,NULL AS `supplierInvoiceNo`,`b`.`lineNo` AS `lineNo`,`b`.`itemdescription` AS `itemdescription`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,`b`.`accountID` AS `drAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankId`)) AS `crAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `drTaxAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankId`)) AS `crTaxAccountID` from (`comp_payment_others` `a` join `comp_payment_others_without_item` `b`) where ((`a`.`ID` = `b`.`otherPaymentID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `a`.`ID` AS `othersPaymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,NULL AS `supplierID`,NULL AS `purchaseInvoiceID`,`b`.`ID` AS `paymentDetailID`,NULL AS `supplierInvoiceNo`,`b`.`lineNo` AS `lineNo`,`b`.`itemdescription` AS `itemdescription`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,`b`.`accountID` AS `drAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankId`)) AS `crAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `drTaxAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankId`)) AS `crTaxAccountID` from (`comp_payment_others` `a` join `comp_payment_others_without_item` `b`) where ((`a`.`ID` = `b`.`otherPaymentID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0) and (`a`.`simplifiedTax` = 1) and ((select coalesce(sum(`comp_payment_others_without_item`.`taxAmount`),0) from `comp_payment_others_without_item` where ((`comp_payment_others_without_item`.`otherPaymentID` = `a`.`ID`) and (`comp_payment_others_without_item`.`lineNo` <= `b`.`lineNo`))) <= (select `c`.`MaxInputTaxClaim` from `comp_gst_preference` `c` where (`c`.`companyID` = `a`.`companyID`)))) union select `a`.`ID` AS `othersPaymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,NULL AS `supplierID`,NULL AS `purchaseInvoiceID`,`b`.`ID` AS `paymentDetailID`,NULL AS `supplierInvoiceNo`,`b`.`lineNo` AS `lineNo`,`b`.`itemdescription` AS `itemdescription`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,((select `c`.`MaxInputTaxClaim` from `comp_gst_preference` `c` where (`c`.`companyID` = `a`.`companyID`)) - (select coalesce(sum(`comp_payment_others_without_item`.`taxAmount`),0) from `comp_payment_others_without_item` where ((`comp_payment_others_without_item`.`otherPaymentID` = `a`.`ID`) and (`comp_payment_others_without_item`.`lineNo` < `b`.`lineNo`)))) AS `taxamount`,`b`.`accountID` AS `drAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankId`)) AS `crAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `drTaxAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankId`)) AS `crTaxAccountID` from (`comp_payment_others` `a` join `comp_payment_others_without_item` `b`) where ((`a`.`ID` = `b`.`otherPaymentID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0) and (`a`.`simplifiedTax` = 1) and ((select coalesce(sum(`comp_payment_others_without_item`.`taxAmount`),0) from `comp_payment_others_without_item` where ((`comp_payment_others_without_item`.`otherPaymentID` = `a`.`ID`) and (`comp_payment_others_without_item`.`lineNo` <= `b`.`lineNo`))) > (select `c`.`MaxInputTaxClaim` from `comp_gst_preference` `c` where (`c`.`companyID` = `a`.`companyID`))) and ((select coalesce(sum(`comp_payment_others_without_item`.`taxAmount`),0) from `comp_payment_others_without_item` where ((`comp_payment_others_without_item`.`otherPaymentID` = `a`.`ID`) and (`comp_payment_others_without_item`.`lineNo` < `b`.`lineNo`))) < (select `c`.`MaxInputTaxClaim` from `comp_gst_preference` `c` where (`c`.`companyID` = `a`.`companyID`)))) union select `a`.`ID` AS `othersPaymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,NULL AS `supplierID`,NULL AS `purchaseInvoiceID`,`b`.`ID` AS `paymentDetailID`,NULL AS `supplierInvoiceNo`,`b`.`lineNo` AS `lineNo`,`b`.`itemdescription` AS `itemdescription`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,(select (coalesce(sum(`comp_payment_others_without_item`.`taxAmount`),0) - (select `c`.`MaxInputTaxClaim` from `comp_gst_preference` `c` where (`c`.`companyID` = `a`.`companyID`))) from `comp_payment_others_without_item` where ((`comp_payment_others_without_item`.`otherPaymentID` = `a`.`ID`) and (`comp_payment_others_without_item`.`lineNo` <= `b`.`lineNo`))) AS `taxamount`,`b`.`accountID` AS `drAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankId`)) AS `crAccountID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'gstnoclaim'))) AS `drTaxAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankId`)) AS `crTaxAccountID` from (`comp_payment_others` `a` join `comp_payment_others_without_item` `b`) where ((`a`.`ID` = `b`.`otherPaymentID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0) and (`a`.`simplifiedTax` = 1) and ((select coalesce(sum(`comp_payment_others_without_item`.`taxAmount`),0) from `comp_payment_others_without_item` where ((`comp_payment_others_without_item`.`otherPaymentID` = `a`.`ID`) and (`comp_payment_others_without_item`.`lineNo` <= `b`.`lineNo`))) > (select `c`.`MaxInputTaxClaim` from `comp_gst_preference` `c` where (`c`.`companyID` = `a`.`companyID`))) and ((select coalesce(sum(`comp_payment_others_without_item`.`taxAmount`),0) from `comp_payment_others_without_item` where ((`comp_payment_others_without_item`.`otherPaymentID` = `a`.`ID`) and (`comp_payment_others_without_item`.`lineNo` < `b`.`lineNo`))) < (select `c`.`MaxInputTaxClaim` from `comp_gst_preference` `c` where (`c`.`companyID` = `a`.`companyID`)))) union select `a`.`ID` AS `othersPaymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,NULL AS `supplierID`,NULL AS `purchaseInvoiceID`,`b`.`ID` AS `paymentDetailID`,NULL AS `supplierInvoiceNo`,`b`.`lineNo` AS `lineNo`,`b`.`itemdescription` AS `itemdescription`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,(select (coalesce(sum(`comp_payment_others_without_item`.`taxAmount`),0) - (select `c`.`MaxInputTaxClaim` from `comp_gst_preference` `c` where (`c`.`companyID` = `a`.`companyID`))) from `comp_payment_others_without_item` where ((`comp_payment_others_without_item`.`otherPaymentID` = `a`.`ID`) and (`comp_payment_others_without_item`.`lineNo` <= `b`.`lineNo`))) AS `taxamount`,`b`.`accountID` AS `drAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankId`)) AS `crAccountID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'gstnoclaim'))) AS `drTaxAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankId`)) AS `crTaxAccountID` from (`comp_payment_others` `a` join `comp_payment_others_without_item` `b`) where ((`a`.`ID` = `b`.`otherPaymentID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0) and (`a`.`simplifiedTax` = 1) and ((select coalesce(sum(`comp_payment_others_without_item`.`taxAmount`),0) from `comp_payment_others_without_item` where ((`comp_payment_others_without_item`.`otherPaymentID` = `a`.`ID`) and (`comp_payment_others_without_item`.`lineNo` <= (`b`.`lineNo` + 1)))) > (select `c`.`MaxInputTaxClaim` from `comp_gst_preference` `c` where (`c`.`companyID` = `a`.`companyID`)))) */;

--
-- Final view structure for view `view_unpost_other_receive`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_other_receive`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_other_receive`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_other_receive` AS select `a`.`projectID` AS `projectID`,`a`.`receiveFrom` AS `receiveFrom`,`a`.`ID` AS `otherReceiveID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`b`.`lineNo` AS `lineNo`,`b`.`description` AS `itemdescription`,`b`.`amountExcludedTax` AS `amountExcludedtax`,`b`.`taxID` AS `taxid`,`b`.`taxAmount` AS `taxamount`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankID`)) AS `drAccountID`,`b`.`accountNoID` AS `crAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankID`)) AS `drTaxAccountID`,(select `tax_master`.`taxAccount` from `tax_master` where (`tax_master`.`ID` = `b`.`taxID`)) AS `crTaxAccountID` from (`comp_receive_payment_others` `a` join `comp_receive_payment_others_detail` `b`) where ((`a`.`ID` = `b`.`receivePaymentOthersID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) */;

--
-- Final view structure for view `view_unpost_payment`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_payment`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_payment`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_payment` AS select `a`.`ID` AS `paymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`supplierID` AS `supplierID`,NULL AS `purchaseInvoiceID`,`b`.`supplierName` AS `supplierName`,0 AS `lineNo`,NULL AS `paymentDetailID`,NULL AS `supplierInvoiceNo`,`a`.`referenceNo` AS `item`,`a`.`bankCharges` AS `amtPaid_amtAppl`,0 AS `discount_bankCharges`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'bankchargesAccount'))) AS `drAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankID`)) AS `crAccountID`,NULL AS `drDiscountAccountID`,NULL AS `crDiscountAccountID` from (`comp_payment` `a` join `supplier` `b`) where ((`a`.`supplierID` = `b`.`ID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `a`.`ID` AS `paymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`supplierID` AS `supplierID`,`b`.`purchaseInvoiceID` AS `purchaseInvoiceID`,`e`.`supplierName` AS `supplierName`,`b`.`lineNo` AS `lineNo`,`b`.`ID` AS `paymentDetailID`,`c`.`supplierInvoiceNo` AS `supplierInvoiceNo`,concat(concat(concat(`d`.`formNo`,'['),convert(lpad(`d`.`serialNo`,8,'0') using latin1)),']') AS `item`,(`b`.`amountApplied` - `b`.`discount`) AS `amtPaid_amtAppl`,`b`.`discount` AS `discount_bankCharges`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `drAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankID`)) AS `crAccountID`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `drDiscountAccountID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'payDisc'))) AS `crDiscountAccountID` from (((`comp_payment` `a` join (`comp_payment_detail` `b` left join `comp_supplier_invoice` `d` on((`d`.`ID` = `b`.`purchaseInvoiceID`)))) join `comp_supplier_invoice` `c`) join `supplier` `e`) where ((`a`.`supplierID` = `e`.`ID`) and (`a`.`ID` = `b`.`paymentID`) and (`c`.`ID` = `b`.`purchaseInvoiceID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `a`.`ID` AS `paymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`supplierID` AS `supplierID`,`b`.`historicalinvoiceID` AS `purchaseInvoiceID`,`e`.`supplierName` AS `supplierName`,`b`.`ID` AS `lineNo`,`b`.`ID` AS `paymentDetailID`,`c`.`supplierInvoiceNo` AS `supplierInvoiceNo`,concat(concat(concat(`d`.`formNo`,'['),convert(lpad(`d`.`serialNo`,8,'0') using latin1)),']') AS `item`,`b`.`amountApplied` AS `amtPaid_amtAppl`,NULL AS `discount_bankCharges`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `drAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankID`)) AS `crAccountID`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `drDiscountAccountID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'payDisc'))) AS `crDiscountAccountID` from (((`comp_payment` `a` join (`comp_payment_detail_historical_invoice` `b` left join `comp_historical_supplier_invoice` `d` on((`d`.`ID` = `b`.`historicalinvoiceID`)))) join `comp_historical_supplier_invoice` `c`) join `supplier` `e`) where ((`a`.`supplierID` = `e`.`ID`) and (`a`.`ID` = `b`.`paymentID`) and (`c`.`ID` = `b`.`historicalinvoiceID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) union select `a`.`ID` AS `paymentID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`a`.`companyID` AS `companyID`,`a`.`supplierID` AS `supplierID`,`b`.`creditnoteID` AS `purchaseInvoiceID`,`e`.`supplierName` AS `supplierName`,`b`.`ID` AS `lineNo`,`b`.`ID` AS `paymentDetailID`,`c`.`supplierInvoiceID` AS `supplierInvoiceNo`,concat(concat(concat(`d`.`formNo`,'['),convert(lpad(`d`.`serialNo`,8,'0') using latin1)),']') AS `item`,`b`.`amountApplied` AS `amtPaid_amtAppl`,NULL AS `discount_bankCharges`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `drAccountID`,(select `comp_bank`.`linkAccountID` from `comp_bank` where (`comp_bank`.`ID` = `a`.`bankID`)) AS `crAccountID`,(select `supplier`.`linkedAPAccountID` from `supplier` where (`supplier`.`ID` = `a`.`supplierID`)) AS `drDiscountAccountID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'payDisc'))) AS `crDiscountAccountID` from (((`comp_payment` `a` join (`comp_payment_detail_creditnote` `b` left join `comp_supplier_creditnote` `d` on((`d`.`ID` = `b`.`creditnoteID`)))) join `comp_supplier_creditnote` `c`) join `supplier` `e`) where ((`a`.`supplierID` = `e`.`ID`) and (`a`.`ID` = `b`.`paymentID`) and (`c`.`ID` = `b`.`creditnoteID`) and (`a`.`updateAble` = 1) and (`a`.`is_delete` = 0)) */;

--
-- Final view structure for view `view_unpost_receive_item`
--

/*!50001 DROP TABLE IF EXISTS `view_unpost_receive_item`*/;
/*!50001 DROP VIEW IF EXISTS `view_unpost_receive_item`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_unpost_receive_item` AS select `a`.`ID` AS `receiveID`,`a`.`companyID` AS `companyID`,`a`.`locationID` AS `locationID`,`a`.`deliveryDate` AS `transactionDate`,`a`.`supplierID` AS `supplierID`,concat(concat(concat(`a`.`formNo`,'['),convert(lpad(`a`.`serialNo`,8,'0') using latin1)),']') AS `formNo`,`b`.`lineNo` AS `lineNo`,`b`.`itemID` AS `itemID`,concat('[',`c`.`itemCode`,']',`c`.`name`) AS `itemName`,`a`.`exchangeRate` AS `exchangeRate`,`b`.`unitPrice` AS `unitPrice`,`b`.`quantityReceived` AS `quantityReceived`,`b`.`umID` AS `umID`,`b`.`amount` AS `amount`,ifnull((select `item`.`inventoriesID` from `item` where (`item`.`ID` = `b`.`itemID`)),(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'invAcct')))) AS `drAccountID`,(select `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where ((`comp_control_acct_setup`.`companyID` = `a`.`companyID`) and (`comp_control_acct_setup`.`accountCode` = 'unInvoiceAP'))) AS `crAccountID` from ((`comp_receive_item` `a` join `comp_receive_item_detail` `b`) join `item` `c`) where ((`a`.`updateAble` = 1) and (`a`.`ID` = `b`.`receiveID`) and (`b`.`itemID` = `c`.`ID`)) */;

--
-- Final view structure for view `view_wakaf_accrual`
--

/*!50001 DROP TABLE IF EXISTS `view_wakaf_accrual`*/;
/*!50001 DROP VIEW IF EXISTS `view_wakaf_accrual`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `view_wakaf_accrual` AS select `b`.`companyID` AS `companyID`,`b`.`acctID` AS `acctID`,`b`.`year` AS `year`,sum(`b`.`total`) AS `totalAmount` from (`company` `a` join `comp_acc_det` `b`) where ((`a`.`ID` = `b`.`companyID`) and `b`.`acctID` in (select distinct `comp_control_acct_setup`.`accountID` from `comp_control_acct_setup` where (`comp_control_acct_setup`.`accountCode` = 'wakafAcrual'))) group by `b`.`companyID`,`b`.`acctID`,`b`.`year` */;

--
-- Final view structure for view `view_wakaf_from_profit`
--

